]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Fixed problem: it's impossible to delete main object if its subshape have been used...
authorepa <epa@opencascade.com>
Thu, 7 Dec 2006 11:42:23 +0000 (11:42 +0000)
committerepa <epa@opencascade.com>
Thu, 7 Dec 2006 11:42:23 +0000 (11:42 +0000)
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h

index 4efbfbbad598f31f00f9fc3c39dac89795f1c80c..26e8a3776faf14f36078bda40dfd0da4e11347f5 100644 (file)
@@ -309,23 +309,12 @@ void GEOMToolsGUI::OnEditDelete()
           _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeom));
           for ( it->InitEx( true ); it->More(); it->Next() ) {
              _PTR(SObject) chobj (it->Value());
-             CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(chobj);
-             GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
-             if( CORBA::is_nil(geomObj) ) 
-                continue;
-             GEOM::ListOfGO_var list = geomObj->GetDependency();
-             if( list->length() > 1 )
-               for(int i = 0; i < list->length(); i++ ){
-                 CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject(obj);
-                 GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
-                if( list[i]->_is_equivalent( geomObj_rem ) ){
-                   SUIT_MessageBox::warn1 ( app->desktop(),
-                                           QObject::tr("WRN_WARNING"),
-                                           QObject::tr("DEP_OBJECT"),
-                                           QObject::tr("BUT_OK") );
-                  return;
-               }
-              }
+            if(CheckSubObjectInUse(chobj, obj, aStudy)) return;
+            //check subobjects
+            for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
+              _PTR(SObject) child (it->Value());
+              if(CheckSubObjectInUse( chobj, child, aStudy)) return;
+            }
           }
 
           RemoveObjectWithChildren(obj, aStudy, views, disp);
@@ -681,6 +670,39 @@ void GEOMToolsGUI::RemoveObjectWithChildren(_PTR(SObject) obj,
   }
 }
 
+//=====================================================================================
+// function : CheckSubObjectInUse
+// purpose  : to be used by OnEditDelete() method
+//=====================================================================================
+bool GEOMToolsGUI::CheckSubObjectInUse(_PTR(SObject) checkobj,
+                                      _PTR(SObject) remobj,
+                                       _PTR(Study) aStudy)
+{
+  CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(checkobj);
+  GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
+  if( CORBA::is_nil(geomObj) ) 
+    return false;
+
+  GEOM::ListOfGO_var list = geomObj->GetDependency();
+  if( list->length() > 1 )
+    for(int i = 0; i < list->length(); i++ ){
+      CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject(remobj);
+      GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
+      if( list[i]->_is_equivalent( geomObj_rem ) ){
+       SalomeApp_Application* app =
+         dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
+
+       SUIT_MessageBox::warn1 ( app->desktop(),
+                                QObject::tr("WRN_WARNING"),
+                                QObject::tr("DEP_OBJECT"),
+                                QObject::tr("BUT_OK") );
+       return true;
+      }
+    }
+
+  return false;
+}
+
 //=====================================================================================
 // EXPORTED METHODS
 //=====================================================================================
index f5829ecfd924025e4d89d2d6a00c9af023fe90d9..2486bfa9339548a96266ad040de4cad79c200230 100644 (file)
@@ -89,6 +89,12 @@ private:
                                _PTR(Study) aStudy,
                                QPtrList<SALOME_View> views,
                                GEOM_Displayer* disp);
+
+  //checks if the object passed as the first argument depends on the second arguments
+  bool CheckSubObjectInUse(_PTR(SObject) checkobj,
+                          _PTR(SObject) remobj,
+                          _PTR(Study) aStudy);
+    
 };
 
 #endif