From 3ec0b9b36d93dcf3467037c810fc244a93c20dad Mon Sep 17 00:00:00 2001 From: jfa Date: Tue, 20 May 2008 07:28:29 +0000 Subject: [PATCH] NPAL19658: Deletion problem. Invalid actions were called by shortcuts. --- src/VISUGUI/VISU_msg_en.po | 3 + src/VISUGUI/VisuGUI.cxx | 176 ++++++++++++++++++++-------------- src/VISUGUI/VisuGUI_Tools.cxx | 133 ++++++++++++++----------- src/VISUGUI/VisuGUI_Tools.h | 4 +- 4 files changed, 187 insertions(+), 129 deletions(-) diff --git a/src/VISUGUI/VISU_msg_en.po b/src/VISUGUI/VISU_msg_en.po index 0c24c6ac..fabcb006 100644 --- a/src/VISUGUI/VISU_msg_en.po +++ b/src/VISUGUI/VISU_msg_en.po @@ -46,6 +46,9 @@ msgstr "No Available data in selection" msgid "WRN_EXTRA_MEMORY_REQUIRED" msgstr "Cache need more memory to build the presentation (%1 Mb).\nDo you want to enlarge the cache?" +msgid "WRN_NO_APPROPRIATE_SELECTION" +msgstr "No appropriate objects selected" + msgid "ERR_NO_MEMORY_TO_BUILD" msgstr "Please, free %1 Mb to make the cache enlarging possible\n(for example, try to delete some holders)" diff --git a/src/VISUGUI/VisuGUI.cxx b/src/VISUGUI/VisuGUI.cxx index ff97cbe2..37b579c7 100644 --- a/src/VISUGUI/VisuGUI.cxx +++ b/src/VISUGUI/VisuGUI.cxx @@ -17,7 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // @@ -1280,15 +1280,22 @@ VisuGUI int i = 0, nbSelected = aList.Extent(); if (nbSelected < 1) return; - std::vector anEntries(nbSelected); + std::vector anEntries (nbSelected); Handle(SALOME_InteractiveObject) anIO; for (SALOME_ListIteratorOfListIO it (aList); it.More(); it.Next()) { anIO = it.Value(); - if (anIO->hasEntry()) - anEntries[i++] = anIO->getEntry(); + if (anIO->hasEntry()) { + if (IsRemovable(anIO->getEntry(), this)) + anEntries[i++] = anIO->getEntry(); + } } nbSelected = i; - if (nbSelected < 1) return; + if (nbSelected < 1) { + SUIT_MessageBox::warn1(GetDesktop(this), + QObject::tr("WRN_VISU"), + QObject::tr("WRN_NO_APPROPRIATE_SELECTION"), + QObject::tr("BUT_OK")); + } // There is a transaction _PTR(StudyBuilder) aStudyBuilder = aCStudy->NewBuilder(); @@ -1321,7 +1328,8 @@ VisuGUI } } } - }else{ + } + else{ DeleteSObject(this, aCStudy, aSObject); UpdateObjBrowser(this, true, aSObject); } @@ -1629,73 +1637,98 @@ VisuGUI return; VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects(this); - if(aSelectionInfo.empty()) - return; - - VISU::TSelectionItem aSelectionItem = aSelectionInfo.front(); - _PTR(SObject) aSObject = aSelectionItem.myObjectInfo.mySObject; - if(!aSObject) + if (aSelectionInfo.empty()) return; - //TEST DU PARENT == VISU - _PTR(StudyBuilder) aBuilder = aCStudy->NewBuilder(); - _PTR(GenericAttribute) anAttr = aBuilder->FindOrCreateAttribute(aSObject, "AttributeName"); - if (anAttr) { - _PTR(AttributeName) aName (anAttr); - QString Name = VisuGUI_NameDlg::getName( GetDesktop( this ), aName->Value().c_str() ); - if (!Name.isEmpty()) { - QApplication::setOverrideCursor(Qt::waitCursor); + VisuGUI_Selection aSel (this); + aSel.init("", getApp()->selectionMgr()); + if (aSel.count() < 1) return; - // rename specific objects - if(VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase){ - switch(aBase->GetType()){ - case VISU::TCURVE: { // Curve object - if(VISU::Curve_i* aCurve = dynamic_cast(aBase)) - aCurve->SetName(Name.latin1(), true); - break; - } - case VISU::TTABLE: { // Table object - if(VISU::Table_i* aTable = dynamic_cast(aBase)) - aTable->SetName(Name.latin1(), true); - break; - } - case VISU::TPOINTMAP3D: { // Table object - if(VISU::PointMap3d_i* aTable3d = dynamic_cast(aBase)) { - aTable3d->SetTitle(Name); - aTable3d->UpdateActors(); - } - break; - } - case VISU::TCONTAINER: { // Container object - if(VISU::Container_i* aContainer = dynamic_cast(aBase)) - aContainer->SetName(Name.latin1(), true); - break; - } - default: { - }} - } - } + bool isAny = false; // is there any appropriate object selected + for (int i = 0; i < aSelectionInfo.size(); i++) { + VISU::TSelectionItem aSelectionItem = aSelectionInfo[i]; + VISU::TObjectInfo anObjectInfo = aSelectionItem.myObjectInfo; - if (!Name.isEmpty()) { - // rename the study object - Handle(SALOME_InteractiveObject) anIO = aSelectionItem.myIO; - aName->SetValue(Name.latin1()); // rename the SObject - anIO->setName(Name.latin1()); // rename the InteractiveObject - - ViewManagerList aViewManagerList; - getApp()->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList); - SUIT_ViewManager* aViewManager = aViewManagerList.first(); - for(; aViewManager; aViewManager = aViewManagerList.next()){ - if(Plot2d_ViewManager* aManager = dynamic_cast(aViewManager)){ - if(SPlot2d_Viewer* aViewer = dynamic_cast(aManager->getViewModel())) - aViewer->renameAll( anIO, Name.latin1() ); - } - } + _PTR(SObject) aSObject = anObjectInfo.mySObject; + if (!aSObject) + continue; - UpdateObjBrowser(this, false); + // Check, if the selected object can be renamed + QString aStr = aSel.param(i, "type" ).toString(); + if (aStr == "VISU::TSCALARMAP" || aStr == "VISU::TISOSURFACES" || + aStr == "VISU::TDEFORMEDSHAPE" || aStr == "VISU::TCUTPLANES" || + aStr == "VISU::TCUTLINES" || aStr == "VISU::TVECTORS" || + aStr == "VISU::TSTREAMLINES" || aStr == "VISU::TPLOT3D" || + aStr == "VISU::TSCALARMAPONDEFORMEDSHAPE" || aStr == "VISU::TCOLOREDPRS3DHOLDER" || + aStr == "VISU::TTABLE" || aStr == "VISU::TCURVE" || aStr == "VISU::TCONTAINER" || + aStr == "VISU::POINTMAP3D" || aStr == "VISU::TVIEW3D" || + aStr == "VISU::TMESH" || aStr == "VISU::TPOINTMAP3D") + { + _PTR(GenericAttribute) anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeName")) { + isAny = true; + _PTR(AttributeName) aName (anAttr); + QString Name = VisuGUI_NameDlg::getName( GetDesktop( this ), aName->Value().c_str() ); + if (!Name.isEmpty()) { + QApplication::setOverrideCursor(Qt::waitCursor); + + // rename specific objects + if (VISU::Base_i* aBase = anObjectInfo.myBase) { + switch (aBase->GetType()) { + case VISU::TCURVE: { // Curve object + if (VISU::Curve_i* aCurve = dynamic_cast(aBase)) + aCurve->SetName(Name.latin1(), true); + break; + } + case VISU::TTABLE: { // Table object + if (VISU::Table_i* aTable = dynamic_cast(aBase)) + aTable->SetName(Name.latin1(), true); + break; + } + case VISU::TPOINTMAP3D: { // Table object + if (VISU::PointMap3d_i* aTable3d = dynamic_cast(aBase)) { + aTable3d->SetTitle(Name); + aTable3d->UpdateActors(); + } + break; + } + case VISU::TCONTAINER: { // Container object + if (VISU::Container_i* aContainer = dynamic_cast(aBase)) + aContainer->SetName(Name.latin1(), true); + break; + } + default: { + }} + } + + // rename the study object + Handle(SALOME_InteractiveObject) anIO = aSelectionItem.myIO; + aName->SetValue(Name.latin1()); // rename the SObject + anIO->setName(Name.latin1()); // rename the InteractiveObject + + ViewManagerList aViewManagerList; + getApp()->viewManagers(SPlot2d_Viewer::Type(), aViewManagerList); + SUIT_ViewManager* aViewManager = aViewManagerList.first(); + for (; aViewManager; aViewManager = aViewManagerList.next()) { + if (Plot2d_ViewManager* aManager = dynamic_cast(aViewManager)) { + if (SPlot2d_Viewer* aViewer = dynamic_cast(aManager->getViewModel())) + aViewer->renameAll( anIO, Name.latin1() ); + } + } + + UpdateObjBrowser(this, false); + + QApplication::restoreOverrideCursor(); + } + } } + } // for - QApplication::restoreOverrideCursor(); + if (!isAny) { + SUIT_MessageBox::warn1(GetDesktop(this), + QObject::tr("WRN_VISU"), + QObject::tr("WRN_NO_APPROPRIATE_SELECTION"), + QObject::tr("BUT_OK")); } } @@ -2088,9 +2121,6 @@ VisuGUI SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr(); // Create actions - //createAction( VISU_IMPORT_FROM_FILE, "", QIconSet(), - // tr("MEN_IMPORT_FROM_FILE"), "", (CTRL + Key_I), aParent, false, - // this, SLOT(OnImportFromFile())); aPixmap = aResourceMgr->loadPixmap("VISU",tr("ICON_IMPORT_MED")); createAction( VISU_IMPORT_FROM_FILE, tr("IMPORT_FROM_FILE"), QIconSet(aPixmap), @@ -3016,6 +3046,9 @@ VisuGUI // Reset actions accelerator keys action(VISU_IMPORT_FROM_FILE)->setAccel(QKeySequence(CTRL + Key_I)); + action(VISU_DELETE_OBJS)->setEnabled(true); // Delete: Key_Delete + action(VISU_RENAME )->setEnabled(true); // Rename: Key_F2 + return true; } @@ -3028,7 +3061,10 @@ VisuGUI setToolShown( false ); // Unset actions accelerator keys - action(VISU_IMPORT_FROM_FILE)->setAccel(QKeySequence()); + action(VISU_IMPORT_FROM_FILE)->setAccel(QKeySequence()); // Import: CTRL + Key_I + + action(VISU_DELETE_OBJS)->setEnabled(false); // Delete: Key_Delete + action(VISU_RENAME )->setEnabled(false); // Rename: Key_F2 SalomeApp_Module::deactivateModule( theStudy ); return true; diff --git a/src/VISUGUI/VisuGUI_Tools.cxx b/src/VISUGUI/VisuGUI_Tools.cxx index 1284bd6d..878cfa2c 100644 --- a/src/VISUGUI/VisuGUI_Tools.cxx +++ b/src/VISUGUI/VisuGUI_Tools.cxx @@ -375,6 +375,79 @@ namespace VISU theSelectionMgr->setSelectedObjects(aNewListIO); } + /*! + * \brief Check, if the object can be deleted + * + * \param theEntry - entry of the object to check + * \param theModule - is used to access Study and VISU_Gen + * \retval bool - returns TRUE if the object is removable + */ + bool + IsRemovable (const std::string theEntry, + const SalomeApp_Module* theModule) + { + // asv : if selected object is a Save Point object selected in object browser - return false + if ( QString( theEntry.c_str() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) + return false; + + _PTR(Study) aStudy = GetCStudy(GetAppStudy(theModule)); + + _PTR(SObject) aSObject = aStudy->FindObjectID(theEntry); + VISU::Storable::TRestoringMap pMap; + if (aSObject) { + CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject); + if (!CORBA::is_nil(aCORBAObject)) { + VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject); + if (CORBA::is_nil(aRemovableObj)) { + // Not removable CORBA object + return false; + } + } else { + // Can be removed, if lays directly under VISU + // (first sub-level) or is a child of such an object + string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType(); + _PTR(GenericAttribute) anAttr; + _PTR(AttributeString) aComment; + + bool isUnderVISU = false; + _PTR(SObject) aFatherSObject = aSObject->GetFather(); + if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) { + // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete" + // popup item displaying in object browser popup + _PTR(AttributeName) aComment (anAttr); + aNAME = aComment->Value(); + QString aVisuTITLE = theModule->getApp()->moduleTitle(QString(aVisuNAME)); + if (!aVisuTITLE.compare(QString(aNAME))) { + isUnderVISU = true; + } + } + if (!isUnderVISU) { + // Not directly under VISU component, check father + aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject); + if (!CORBA::is_nil(aCORBAObject)) { + // Father has IOR + return false; + } + + isUnderVISU = false; + aFatherSObject = aFatherSObject->GetFather(); + if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) { + _PTR(AttributeString) aComment (anAttr); + aNAME = aComment->Value(); + if (aNAME == aVisuNAME) { + isUnderVISU = true; + } + } + if (!isUnderVISU) { + // Father is not directly under VISU component + return false; + } + } + } + } + return true; + } + /*! * \brief Check, if "Delete" popup-menu can be put on current selection * @@ -398,64 +471,8 @@ namespace VISU for (; anIter.More(); anIter.Next()) { Handle(SALOME_InteractiveObject) anIO = anIter.Value(); if (anIO->hasEntry()) { - - // asv : if selected object is a Save Point object selected in object browser - return false - if ( QString( anIO->getEntry() ).startsWith( QObject::tr( "SAVE_POINT_DEF_NAME" ) ) ) - return false; - - _PTR(SObject) aSObject = aStudy->FindObjectID(anIO->getEntry()); - VISU::Storable::TRestoringMap pMap; - if (aSObject) { - CORBA::Object_var aCORBAObject = VISU::ClientSObjectToObject(aSObject); - if (!CORBA::is_nil(aCORBAObject)) { - VISU::RemovableObject_var aRemovableObj = VISU::RemovableObject::_narrow(aCORBAObject); - if (CORBA::is_nil(aRemovableObj)) { - // Not removable CORBA object - return false; - } - } else { - // Can be removed, if lays directly under VISU - // (first sub-level) or is a child of such an object - string aNAME, aVisuNAME = GetVisuGen(theModule)->ComponentDataType(); - _PTR(GenericAttribute) anAttr; - _PTR(AttributeString) aComment; - - bool isUnderVISU = false; - _PTR(SObject) aFatherSObject = aSObject->GetFather(); - if (aFatherSObject->FindAttribute(anAttr, "AttributeName")) { - // mkr : 24.11.2006 : use AttributeName and module title for correct "Delete" - // popup item displaying in object browser popup - _PTR(AttributeName) aComment (anAttr); - aNAME = aComment->Value(); - QString aVisuTITLE = theModule->getApp()->moduleTitle(QString(aVisuNAME)); - if (!aVisuTITLE.compare(QString(aNAME))) { - isUnderVISU = true; - } - } - if (!isUnderVISU) { - // Not directly under VISU component, check father - aCORBAObject = VISU::ClientSObjectToObject(aFatherSObject); - if (!CORBA::is_nil(aCORBAObject)) { - // Father has IOR - return false; - } - - isUnderVISU = false; - aFatherSObject = aFatherSObject->GetFather(); - if (aFatherSObject->FindAttribute(anAttr, "AttributeString")) { - _PTR(AttributeString) aComment (anAttr); - aNAME = aComment->Value(); - if (aNAME == aVisuNAME) { - isUnderVISU = true; - } - } - if (!isUnderVISU) { - // Father is not directly under VISU component - return false; - } - } - } - } + if (!IsRemovable(anIO->getEntry(), theModule)) + return false; } } return true; diff --git a/src/VISUGUI/VisuGUI_Tools.h b/src/VISUGUI/VisuGUI_Tools.h index c3f7c242..6848c1b6 100644 --- a/src/VISUGUI/VisuGUI_Tools.h +++ b/src/VISUGUI/VisuGUI_Tools.h @@ -17,7 +17,7 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // // @@ -125,6 +125,8 @@ namespace VISU void Remove(LightApp_SelectionMgr* theSelectionMgr, const Handle(SALOME_InteractiveObject)& theIO); + bool IsRemovable (const std::string theEntry, + const SalomeApp_Module* theModule); bool IsRemovableSelected(const SalomeApp_Module* theModule); void DeleteSObject(VisuGUI* theModule, -- 2.39.2