From 02aab3a5b3529674f5d3edf2dc5f6dab61d20c29 Mon Sep 17 00:00:00 2001 From: epa Date: Thu, 7 Dec 2006 11:42:23 +0000 Subject: [PATCH] Fixed problem: it's impossible to delete main object if its subshape have been used for annother geometrical object creation --- src/GEOMToolsGUI/GEOMToolsGUI.cxx | 56 +++++++++++++++++++++---------- src/GEOMToolsGUI/GEOMToolsGUI.h | 6 ++++ 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.cxx b/src/GEOMToolsGUI/GEOMToolsGUI.cxx index 4efbfbbad..26e8a3776 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.cxx +++ b/src/GEOMToolsGUI/GEOMToolsGUI.cxx @@ -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 //===================================================================================== diff --git a/src/GEOMToolsGUI/GEOMToolsGUI.h b/src/GEOMToolsGUI/GEOMToolsGUI.h index f5829ecfd..2486bfa93 100644 --- a/src/GEOMToolsGUI/GEOMToolsGUI.h +++ b/src/GEOMToolsGUI/GEOMToolsGUI.h @@ -89,6 +89,12 @@ private: _PTR(Study) aStudy, QPtrList 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 -- 2.39.2