From: akl Date: Wed, 10 Jul 2013 12:14:17 +0000 (+0000) Subject: Correct deletion of folders with sub-objects in the Object Browser. X-Git-Tag: BR_hydro_v_0_3_1~158 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7b119929a6b1585d28b2368a832db8f4db8e31c4;p=modules%2Fgeom.git Correct deletion of folders with sub-objects in the Object Browser. --- diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 23a357629..777b479c9 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -257,6 +257,37 @@ static bool inUse( _PTR(Study) study, const QString& component, const QMap& geomObjList, + QMap& folderList ) { + if ( !theSO ) return; + _PTR(Study) aStudy = theSO->GetStudy(); + if ( !aStudy ) return; + _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder(); + + bool isFolder = false; + _PTR(GenericAttribute) anAttr; + if ( theSO->FindAttribute(anAttr, "AttributeLocalID") ) { + _PTR(AttributeLocalID) aLocalID( anAttr ); + isFolder = aLocalID->Value() == 999; + } + QString anEntry = theSO->GetID().c_str(); + QString aName = theSO->GetName().c_str(); + if ( isFolder ) { + folderList.insert( anEntry, aName ); + _PTR(UseCaseIterator) ucit ( aUseCaseBuilder->GetUseCaseIterator( theSO ) ); + for ( ucit->Init( false ); ucit->More(); ucit->Next() ) { + getGeomChildrenAndFolders( ucit->Value(), geomObjList, folderList ); + } + } else { + geomObjList.insert( anEntry, aName ); + } +} + //======================================================================= // function : GEOMToolsGUI() // purpose : Constructor @@ -441,6 +472,7 @@ void GEOMToolsGUI::OnEditDelete() return; _PTR(Study) aStudy = appStudy->studyDS(); + _PTR(UseCaseBuilder) aUseCaseBuilder = aStudy->GetUseCaseBuilder(); // check if study is locked if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) { @@ -457,6 +489,7 @@ void GEOMToolsGUI::OnEditDelete() // check each selected object: if belongs to GEOM, if not reference... QMap toBeDeleted; QMap allDeleted; + QMap toBeDelFolders; bool isComponentSelected = false; for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) { @@ -494,11 +527,12 @@ void GEOMToolsGUI::OnEditDelete() isComponentSelected = true; continue; } - toBeDeleted.insert( entry, aName ); + // all sub-objects of folder have to be deleted + getGeomChildrenAndFolders( obj, toBeDeleted, toBeDelFolders ); allDeleted.insert( entry, aName ); // skip GEOM component // browse through all children recursively - _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) ); - for ( it->InitEx( true ); it->More(); it->Next() ) { + _PTR(UseCaseIterator) it ( aUseCaseBuilder->GetUseCaseIterator( obj ) ); + for ( it->Init( true ); it->More(); it->Next() ) { _PTR(SObject) child( it->Value() ); if ( child && child->ReferencedObject( refobj ) ) continue; // skip references @@ -545,6 +579,8 @@ void GEOMToolsGUI::OnEditDelete() removeObjectWithChildren( child, aStudy, views, disp ); // remove object from study aStudyBuilder->RemoveObjectWithChildren( child ); + // remove object from use case tree + aUseCaseBuilder->Remove( child ); } } else { @@ -565,6 +601,18 @@ void GEOMToolsGUI::OnEditDelete() removeObjectWithChildren( obj, aStudy, views, disp ); // remove objects from study aStudyBuilder->RemoveObjectWithChildren( obj ); + // remove object from use case tree + aUseCaseBuilder->Remove( obj ); + } + // ... and then delete all folders + for ( it = toBeDelFolders.begin(); it != toBeDelFolders.end(); ++it ) { + _PTR(SObject) obj ( aStudy->FindObjectID( it.key().toLatin1().data() ) ); + // remove object from GEOM engine + removeObjectWithChildren( obj, aStudy, views, disp ); + // remove objects from study + aStudyBuilder->RemoveObjectWithChildren( obj ); + // remove object from use case tree + aUseCaseBuilder->Remove( obj ); } } @@ -936,6 +984,7 @@ void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj, { // iterate through all children of obj for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) { + // for (_PTR(UseCaseIterator) it (aStudy->GetUseCaseBuilder()->GetUseCaseIterator(obj)); it->More(); it->Next()) { _PTR(SObject) child (it->Value()); removeObjectWithChildren(child, aStudy, views, disp); }