| 663 | } |
| 664 | |
| 665 | void LinkedScene::writeAttribute( const Name &name, const Object *attribute, double time ) |
| 666 | { |
| 667 | if ( m_readOnly ) |
| 668 | { |
| 669 | throw Exception( "No write access to scene file!" ); |
| 670 | } |
| 671 | |
| 672 | if ( name == linkAttribute ) |
| 673 | { |
| 674 | bool firstTime = !m_mainScene->hasAttribute( fileNameLinkAttribute ); |
| 675 | |
| 676 | if ( firstTime ) |
| 677 | { |
| 678 | // if it's the first time, we better check if this level already has objects, tags or children |
| 679 | // and raise exceptions to prevent weird configurations... |
| 680 | if ( m_mainScene->hasObject() ) |
| 681 | { |
| 682 | throw Exception( "Links to external scenes cannot be created on locations where there's already an object saved!" ); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | // we are creating a link! |
| 687 | const CompoundData *d = runTimeCast< const CompoundData >(attribute); |
| 688 | if ( !d ) |
| 689 | { |
| 690 | throw Exception( "SceneInterface:link attribute must be of type CompoundData!" ); |
| 691 | } |
| 692 | |
| 693 | // open the linked scene |
| 694 | int linkDepth; |
| 695 | ConstDoubleDataPtr timeData = d->member< const DoubleData >( g_time ); |
| 696 | const StringData *fileName = d->member< const StringData >( g_fileName ); |
| 697 | const InternedStringVectorData *sceneRoot = d->member< const InternedStringVectorData >( g_root ); |
| 698 | m_linkedScene = expandLink( fileName, sceneRoot, linkDepth ); |
| 699 | if ( !m_linkedScene ) |
| 700 | { |
| 701 | throw Exception( "Trying to store a broken link!" ); |
| 702 | } |
| 703 | m_rootLinkDepth = linkDepth; |
| 704 | |
| 705 | // check for child name clashes: |
| 706 | NameList mainSceneChildren; |
| 707 | NameList linkedSceneChildren; |
| 708 | |
| 709 | m_mainScene->childNames( mainSceneChildren ); |
| 710 | m_linkedScene->childNames( linkedSceneChildren ); |
| 711 | std::sort( mainSceneChildren.begin(), mainSceneChildren.end() ); |
| 712 | std::sort( linkedSceneChildren.begin(), linkedSceneChildren.end() ); |
| 713 | |
| 714 | std::set<Name> intersection; |
| 715 | std::set_intersection(mainSceneChildren.begin(),mainSceneChildren.end(),linkedSceneChildren.begin(),linkedSceneChildren.end(), std::inserter(intersection,intersection.begin()) ); |
| 716 | |
| 717 | if( intersection.size() ) |
| 718 | { |
| 719 | std::string intersectionString; |
| 720 | for( std::set<Name>::iterator it = intersection.begin(); it != intersection.end(); ++it ) |
| 721 | { |
| 722 | intersectionString += " " + it->string(); |
no test coverage detected