From: jfa Date: Thu, 21 Apr 2005 12:36:11 +0000 (+0000) Subject: Debug deletion of objects from study X-Git-Tag: V2_2_0_VISU_improvement_2005-05-27~49 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9e6c572b85d81ca6d921fff6ac1b8863587e5ae0;p=modules%2Fvisu.git Debug deletion of objects from study --- diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index 733e68d8..d7420315 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -870,49 +870,64 @@ bool VisuGUI::SetSettings(QAD_Desktop* parent) return true; } +//===================================================================================== +// function : DisplayPrsObject() +// purpose : is used by slots DisplayPrs() and DisplayManyPrs() +//===================================================================================== +inline void DisplayPrsObject (CORBA::Object_ptr theObject, + Handle(SALOME_InteractiveObject)& theIO) +{ + if (CORBA::is_nil(theObject)) return; + + // is it Prs3d object ? + VISU::Prs3d_i* aPrsObject = + dynamic_cast(VISU::GetServant(theObject).in()); + if (aPrsObject) { + if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Prs3d object"); + VisuGUI::UpdateViewer(aPrsObject); + if (VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame()) { + vf->getRenderer()->ResetCameraClippingRange(); + vf->Repaint(); + vf->highlight(theIO, 1); + } + return; + } + // is it Curve ? + VISU::Curve_i* aCurve = + dynamic_cast(VISU::GetServant(theObject).in()); + if (aCurve) { + if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Curve object"); + VisuGUI::PlotCurve(aCurve, VISU::eDisplay); + return; + } + // is it Container ? + VISU::Container_i* aContainer = + dynamic_cast(VISU::GetServant(theObject).in()); + if (aContainer) { + if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Container object"); + VisuGUI::PlotContainer(aContainer, VISU::eDisplay); + return; + } + // is it Table ? + VISU::Table_i* aTable = + dynamic_cast(VISU::GetServant(theObject).in()); + if (aTable) { + if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Table object"); + VisuGUI::PlotTable(aTable, VISU::eDisplay); + return; + } +} + //===================================================================================== // function : DisplayPrs() // purpose : //===================================================================================== -void VisuGUI::DisplayPrs() { +void VisuGUI::DisplayPrs() +{ if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs"); Handle(SALOME_InteractiveObject) anIO; CORBA::Object_var anObject = GetSelectedObj(&anIO); - if ( !CORBA::is_nil( anObject ) ) { - // is it Prs3d object ? - VISU::Prs3d_i* aPrsObject = dynamic_cast(VISU::GetServant(anObject).in()); - if(aPrsObject){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Prs3d object"); - UpdateViewer(aPrsObject); - if (VTKViewer_ViewFrame* vf = GetVtkViewFrame()) { - vf->getRenderer()->ResetCameraClippingRange(); - vf->Repaint(); - vf->highlight(anIO, 1); - } - return; - } - // is it Curve ? - VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(anObject).in()); - if(aCurve){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Curve object"); - PlotCurve(aCurve, VISU::eDisplay ); - return; - } - // is it Container ? - VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(anObject).in()); - if(aContainer){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Container object"); - PlotContainer(aContainer, VISU::eDisplay ); - return; - } - // is it Table ? - VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(anObject).in()); - if(aTable){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayPrs : Table object"); - PlotTable(aTable, VISU::eDisplay ); - return; - } - } + DisplayPrsObject(anObject, anIO); } //===================================================================================== @@ -994,52 +1009,17 @@ void VisuGUI::ErasePrs() { void VisuGUI::DisplayManyPrs() { if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs"); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() ); + SALOME_Selection* Sel = SALOME_Selection::Selection + (QAD_Application::getDesktop()->getActiveStudy()->getSelection()); + SALOME_ListIteratorOfListIO It ( Sel->StoredIObjects() ); for ( ; It.More(); It.Next() ) { Handle(SALOME_InteractiveObject)& anIO = It.Value(); if ( anIO->hasEntry() ) { SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( anIO->getEntry() ); - VISU::Storable::TRestoringMap pMap; - if( !aSObject->_is_nil() ) { + if ( !aSObject->_is_nil() ) { CORBA::Object_var aCORBAObject = VISU::SObjectToObject(aSObject); - if ( !CORBA::is_nil( aCORBAObject ) ) { - // is it Prs3d object ? - VISU::Prs3d_i* aPrsObject = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aPrsObject){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Prs3d object"); - UpdateViewer(aPrsObject); - VTKViewer_ViewFrame* vf = GetVtkViewFrame(); - if (vf) { - vf->getRenderer()->ResetCameraClippingRange(); - vf->Repaint(); - vf->highlight(anIO, 1); - } - continue; - } - // is it Curve ? - VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aCurve){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs: Curve object"); - PlotCurve(aCurve, VISU::eDisplay ); - continue; - } - // is it Container ? - VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aContainer){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Container object"); - PlotContainer(aContainer, VISU::eDisplay ); - continue; - } - // is it Table ? - VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aTable){ - if(MYDEBUG) MESSAGE("VisuGUI::DisplayManyPrs : Table object"); - PlotTable(aTable, VISU::eDisplay ); - continue; - } - } + DisplayPrsObject(aCORBAObject, anIO); } } } @@ -1124,9 +1104,10 @@ void VisuGUI::DisplayOnlyManyPrs() { void VisuGUI::EraseManyPrs() { if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs"); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); + SALOME_Selection* Sel = SALOME_Selection::Selection + (QAD_Application::getDesktop()->getActiveStudy()->getSelection()); SALOME_ListIO LIO; LIO = Sel->StoredIObjects(); - SALOME_ListIteratorOfListIO It( LIO ); + SALOME_ListIteratorOfListIO It ( LIO ); for ( ; It.More(); It.Next() ) { Handle(SALOME_InteractiveObject)& anIO = It.Value(); if ( anIO->hasEntry() ) { @@ -1135,40 +1116,7 @@ void VisuGUI::EraseManyPrs() VISU::Storable::TRestoringMap pMap; if( !aSObject->_is_nil() ) { CORBA::Object_var aCORBAObject = VISU::SObjectToObject(aSObject); - if ( !CORBA::is_nil( aCORBAObject ) ) { - // is it Prs3d object ? - VISU::Prs3d_i* aPrsObject = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aPrsObject){ - if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Prs3d object"); - ErasePrs(aPrsObject); - VTKViewer_ViewFrame* vf = GetVtkViewFrame(); - if (vf) { - vf->Repaint(); - } - continue; - } - // is it Curve ? - VISU::Curve_i* aCurve = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aCurve){ - if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Curve object"); - PlotCurve(aCurve, VISU::eErase ); - continue; - } - // is it Container ? - VISU::Container_i* aContainer = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aContainer){ - if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Container object"); - PlotContainer(aContainer, VISU::eErase ); - continue; - } - // is it Table ? - VISU::Table_i* aTable = dynamic_cast(VISU::GetServant(aCORBAObject).in()); - if(aTable){ - if(MYDEBUG) MESSAGE("VisuGUI::EraseManyPrs : Table object"); - PlotTable(aTable, VISU::eErase ); - continue; - } - } + ::ErasePrs(aCORBAObject); } } } @@ -1905,66 +1853,70 @@ void VisuGUI::CreateTable() } } - -/*! - * Slot : deletes SObject with all subobjects - */ -void VisuGUI::DeleteObject() { - MESSAGE("VisuGUI::DeleteObject()"); - - SALOMEDS::Study_var aStudy = GetStudyDocument(); - if (checkLock(aStudy)) return; - - SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); - if (aSel->IObjectCount() != 1) return; - - Handle(SALOME_InteractiveObject) anIO = aSel->firstIObject(); - if (!anIO->hasEntry()) return; - - SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry()); - if (aSObject->_is_nil()) return; - - SALOMEDS::ChildIterator_var aChildIter = aStudy->NewChildIterator(aSObject); +//===================================================================================== +// function : DeleteSObject() +// purpose : is used by slots DeleteObject() and DeleteManyObjects() +//===================================================================================== +inline void DeleteSObject (SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject) +{ + SALOMEDS::ChildIterator_var aChildIter = theStudy->NewChildIterator(theSObject); for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); ::ErasePrs(aChildObj); } - CORBA::Object_var anObj = VISU::SObjectToObject(aSObject); - - // There is a transaction - SALOMEDS::StudyBuilder_var aStudyBuilder = VisuGUI::NewBuilder(); - aStudyBuilder->NewCommand(); - + CORBA::Object_var anObj = VISU::SObjectToObject(theSObject); if (!CORBA::is_nil(anObj)) { - MESSAGE("VisuGUI::DeleteObject() : !CORBA::is_nil(anObj)"); - VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj); if (!CORBA::is_nil(aRemovableObject)) { - MESSAGE("VisuGUI::DeleteObject() : !CORBA::is_nil(aRemovableObject)"); aRemovableObject->RemoveFromStudy(); } } else { - aStudyBuilder->RemoveObjectWithChildren(aSObject); + // Remove aSObject together with all its sub-objects + VISU::RemoveFromStudy(theSObject, + false, // remove not only IOR attribute, but Object With Children + false); // not Destroy() sub-objects } +} - aStudyBuilder->CommitCommand(); +/*! + * Slot : deletes SObject with all subobjects + */ +void VisuGUI::DeleteObject() { + SALOMEDS::Study_var aStudy = GetStudyDocument(); + if (checkLock(aStudy)) return; - GetActiveStudy()->unHighlightAll(); - GetActiveStudy()->updateObjBrowser(true); + SALOME_Selection* aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection()); + if (aSel->IObjectCount() == 1) { + Handle(SALOME_InteractiveObject) anIO = aSel->firstIObject(); + if (anIO->hasEntry()) { + SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(anIO->getEntry()); + if (!aSObject->_is_nil()) { + // There is a transaction + SALOMEDS::StudyBuilder_var aStudyBuilder = VisuGUI::NewBuilder(); + aStudyBuilder->NewCommand(); + + DeleteSObject(aStudy, aSObject); + + aStudyBuilder->CommitCommand(); + + GetActiveStudy()->unHighlightAll(); + GetActiveStudy()->updateObjBrowser(true); + } + } + } } /*! * Slot : deletes all selected SObjects with all subobjects */ void VisuGUI::DeleteManyObjects() { - MESSAGE("VisuGUI::DeleteManyObjects()"); - SALOMEDS::Study_var aStudy = GetStudyDocument(); if (checkLock(aStudy)) return; - SALOME_Selection* aSel = SALOME_Selection::Selection( GetActiveStudy()->getSelection() ); + SALOME_Selection* aSel = SALOME_Selection::Selection(GetActiveStudy()->getSelection()); int i, nbSelected = aSel->IObjectCount(); if (nbSelected < 1) return; @@ -1976,6 +1928,7 @@ void VisuGUI::DeleteManyObjects() { entries[i++] = anIO->getEntry(); } nbSelected = i; + if (nbSelected < 1) return; // There is a transaction SALOMEDS::StudyBuilder_var aStudyBuilder = VisuGUI::NewBuilder(); @@ -1983,26 +1936,8 @@ void VisuGUI::DeleteManyObjects() { for (i = 0; i < nbSelected; i++) { SALOMEDS::SObject_var aSObject = aStudy->FindObjectID(entries[i]); - if (aSObject->_is_nil()) continue; - - SALOMEDS::ChildIterator_var aChildIter = aStudy->NewChildIterator(aSObject); - for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { - SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); - CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); - ::ErasePrs(aChildObj); - } - - CORBA::Object_var anObj = VISU::SObjectToObject(aSObject); - if (!CORBA::is_nil(anObj)) { - MESSAGE("VisuGUI::DeleteManyObjects() : !CORBA::is_nil(anObj)"); - - VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(anObj); - if (!CORBA::is_nil(aRemovableObject)) { - MESSAGE("VisuGUI::DeleteManyObjects() : !CORBA::is_nil(aRemovableObject)"); - aRemovableObject->RemoveFromStudy(); - } - } else { - aStudyBuilder->RemoveObjectWithChildren(aSObject); + if (!aSObject->_is_nil()) { + DeleteSObject(aStudy, aSObject); } } diff --git a/src/VISU_I/VISU_Result_i.cc b/src/VISU_I/VISU_Result_i.cc index 30c13e22..5b79dc1d 100644 --- a/src/VISU_I/VISU_Result_i.cc +++ b/src/VISU_I/VISU_Result_i.cc @@ -85,16 +85,41 @@ VISU::Result_var VISU::FindResult(SALOMEDS::SObject_ptr theSObject){ return aResult; } -void VISU::RemoveFromStudy (SALOMEDS::SObject_ptr theSObject, int theIsAttrOnly) +void VISU::RemoveFromStudy (SALOMEDS::SObject_ptr theSObject, + bool theIsAttrOnly, bool theDestroySubObjects) { - if (!theSObject->_is_nil()) { - SALOMEDS::Study_var aStudy = theSObject->GetStudy(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - if (theIsAttrOnly) - aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR"); - else - aStudyBuilder->RemoveObjectWithChildren(theSObject); + if (theSObject->_is_nil()) return; + + SALOMEDS::Study_var aStudyDocument = theSObject->GetStudy(); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder(); + + if (theIsAttrOnly) { + aStudyBuilder->RemoveAttribute(theSObject,"AttributeIOR"); + return; } + + // Remove possible sub-objects + SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(theSObject); + for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { + SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); + CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); + if (CORBA::is_nil(aChildObj)) continue; + + VISU::RemovableObject_var aRemovableObject = VISU::RemovableObject::_narrow(aChildObj); + if (CORBA::is_nil(aRemovableObject)) continue; + + aRemovableObject->RemoveFromStudy(); + + // Destroy + if (theDestroySubObjects) { + VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aRemovableObject); + if (CORBA::is_nil(aPrs3d)) continue; + aPrs3d->Destroy(); + } + } + + // Remove the SObject itself + aStudyBuilder->RemoveObjectWithChildren(theSObject); } QString GenerateName(const char* theName){ @@ -157,22 +182,7 @@ VISU::Result_i::Result_i(SALOMEDS::Study_ptr theStudy, const TSourceId& aSourceI void VISU::Result_i::RemoveFromStudy() { - // Remove presentations - SALOMEDS::Study_var aStudyDocument = mySObject->GetStudy(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder(); - SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(mySObject); - for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { - SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); - CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); - if (CORBA::is_nil(aChildObj)) continue; - - VISU::Prs3d_var aPrs3d = VISU::Prs3d::_narrow(aChildObj); - if (CORBA::is_nil(aPrs3d)) continue; - - aPrs3d->RemoveFromStudy(); - } - - // Remove the result itself + // Remove the result with all presentations and other possible sub-objects VISU::RemoveFromStudy(mySObject,false); } diff --git a/src/VISU_I/VISU_Result_i.hh b/src/VISU_I/VISU_Result_i.hh index da77676f..f1135951 100644 --- a/src/VISU_I/VISU_Result_i.hh +++ b/src/VISU_I/VISU_Result_i.hh @@ -97,6 +97,8 @@ namespace VISU{ }; Result_var FindResult(SALOMEDS::SObject_ptr theSObject); - void RemoveFromStudy(SALOMEDS::SObject_ptr theSObject, int theIsAttrOnly = true); + void RemoveFromStudy(SALOMEDS::SObject_ptr theSObject, + bool theIsAttrOnly = true, + bool theDestroySubObjects = false); } #endif diff --git a/src/VISU_I/VISU_Table_i.cc b/src/VISU_I/VISU_Table_i.cc index a54fe6de..8496739a 100644 --- a/src/VISU_I/VISU_Table_i.cc +++ b/src/VISU_I/VISU_Table_i.cc @@ -253,23 +253,8 @@ const char* VISU::Table_i::GetTableTitle() void VISU::Table_i::RemoveFromStudy() { - // Remove presentations - SALOMEDS::Study_var aStudyDocument = mySObj->GetStudy(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudyDocument->NewBuilder(); - SALOMEDS::ChildIterator_var aChildIter = aStudyDocument->NewChildIterator(mySObj); - for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { - SALOMEDS::SObject_var aChildSObject = aChildIter->Value(); - CORBA::Object_var aChildObj = VISU::SObjectToObject(aChildSObject); - if (CORBA::is_nil(aChildObj)) continue; - - VISU::RemovableObject_ptr aCurve = VISU::Curve::_narrow(aChildObj); - if (CORBA::is_nil(aCurve)) continue; - - aCurve->RemoveFromStudy(); - } - - // Remove the table itself - VISU::RemoveFromStudy(mySObj,false); + // Remove the table with all curves + VISU::RemoveFromStudy(mySObj, false); } //---------------------------------------------------------------- diff --git a/src/VISU_I/VISU_ViewManager_i.cc b/src/VISU_I/VISU_ViewManager_i.cc index 140c3ff2..3220ef83 100644 --- a/src/VISU_I/VISU_ViewManager_i.cc +++ b/src/VISU_I/VISU_ViewManager_i.cc @@ -1696,13 +1696,14 @@ namespace VISU{ TEvent(Result_ptr theResult): myResult(theResult) {} virtual void Execute() { - myResult->RemoveFromStudy(); - - //update Object browser if (QAD_Desktop* aDesktop = QAD_Application::getDesktop()) { if (Result_i* aResult = dynamic_cast(GetServant(myResult).in())) { SALOMEDS::SObject_var aSObject = aResult->GetSObject(); SALOMEDS::Study_var aStudyDocument = aSObject->GetStudy(); + VISU::RemoveFromStudy(aSObject, + false, // not only attribute + true); // destroy sub-objects + if (QAD_Study* aStudy = aDesktop->findStudy(aStudyDocument)) aStudy->updateObjBrowser(); }