]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
Implementation "21042: EDF 1600 ALL: Rename objects in the OB" issue.
authorrnv <rnv@opencascade.com>
Tue, 5 Apr 2011 09:24:16 +0000 (09:24 +0000)
committerrnv <rnv@opencascade.com>
Tue, 5 Apr 2011 09:24:16 +0000 (09:24 +0000)
src/GEOMGUI/GeometryGUI.cxx
src/GEOMGUI/GeometryGUI.h
src/GEOMGUI/GeometryGUI_Operations.h
src/GEOMToolsGUI/GEOMToolsGUI.cxx
src/GEOMToolsGUI/GEOMToolsGUI.h
src/GEOMToolsGUI/GEOMToolsGUI_1.cxx

index 4ecb5452027d650a8d6be3d31f290c2046ff44a9..5d15de5e29e0dae8bcd0f172c1663bd6f2f07d23 100644 (file)
@@ -54,6 +54,7 @@
 #include <SVTK_ViewModel.h>
 
 #include <SalomeApp_Application.h>
+#include <SalomeApp_DataObject.h>
 #include <SalomeApp_Study.h>
 
 #include <LightApp_SelectionMgr.h>
@@ -352,8 +353,7 @@ void GeometryGUI::OnGUIEvent( int id )
   // if current viewframe is not of OCC and not of VTK type - return immediately
   // fix for IPAL8958 - allow some commands to execute even when NO viewer is active (rename for example)
   QList<int> NotViewerDependentCommands;
-  NotViewerDependentCommands << GEOMOp::OpRename
-                             << GEOMOp::OpDelete
+  NotViewerDependentCommands << GEOMOp::OpDelete
                              << GEOMOp::OpShow
                              << GEOMOp::OpShowOnly
                              << GEOMOp::OpShowChildren
@@ -403,7 +403,6 @@ void GeometryGUI::OnGUIEvent( int id )
   case GEOMOp::OpUnpublishObject:  // POPUP MENU - UNPUBLISH
   case GEOMOp::OpPublishObject:    // ROOT GEOM OBJECT - POPUP MENU - PUBLISH
   case GEOMOp::OpPointMarker:      // POPUP MENU - POINT MARKER
-  case GEOMOp::OpRename:           // POPUP MENU - RENAME
     libName = "GEOMToolsGUI";
     break;
   case GEOMOp::OpDisplayMode:      // MENU VIEW - WIREFRAME/SHADING
@@ -776,7 +775,6 @@ void GeometryGUI::initialize( CAM_Application* app )
   createGeomAction( GEOMOp::OpShowOnly,         "DISPLAY_ONLY" );
   createGeomAction( GEOMOp::OpHide,             "ERASE" );
 
-  createGeomAction( GEOMOp::OpRename,           "POP_RENAME", "", Qt::Key_F2 );
   createGeomAction( GEOMOp::OpWireframe,        "POP_WIREFRAME", "", 0, true );
   createGeomAction( GEOMOp::OpShading,          "POP_SHADING", "", 0, true );
   createGeomAction( GEOMOp::OpVectors,          "POP_VECTORS", "", 0, true );
@@ -1100,8 +1098,6 @@ void GeometryGUI::initialize( CAM_Application* app )
 
   QtxPopupMgr* mgr = popupMgr();
 
-  mgr->insert( action(  GEOMOp::OpRename ), -1, -1 );  // rename
-  mgr->setRule( action( GEOMOp::OpRename ), QString("$type in {'Shape' 'Group'} and selcount=1"), QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpDelete ), -1, -1 );  // delete
   mgr->setRule( action( GEOMOp::OpDelete ), QString("$type in {'Shape' 'Group'} and selcount>0"), QtxPopupMgr::VisibleRule );
   mgr->insert( action(  GEOMOp::OpGroupCreatePopup ), -1, -1 ); // create group
@@ -1240,7 +1236,6 @@ bool GeometryGUI::activateModule( SUIT_Study* study )
   action(GEOMOp::OpImport)->setEnabled( true ); // Import: CTRL + Key_I
   action(GEOMOp::OpExport)->setEnabled( true ); // Export: CTRL + Key_E
   action(GEOMOp::OpDelete)->setEnabled( true ); // Delete: Key_Delete
-  action(GEOMOp::OpRename)->setEnabled( true ); // Rename: Key_F2
 
   GUIMap::Iterator it;
   for ( it = myGUIMap.begin(); it != myGUIMap.end(); ++it )
@@ -1330,7 +1325,6 @@ bool GeometryGUI::deactivateModule( SUIT_Study* study )
   action(GEOMOp::OpImport)->setEnabled( false ); // Import: CTRL + Key_I
   action(GEOMOp::OpExport)->setEnabled( false ); // Export: CTRL + Key_E
   action(GEOMOp::OpDelete)->setEnabled( false ); // Delete: Key_Delete
-  action(GEOMOp::OpRename)->setEnabled( false ); // Rename: Key_F2
 
   qDeleteAll(myOCCSelectors);
   myOCCSelectors.clear();
@@ -1955,3 +1949,45 @@ void GeometryGUI::onViewAboutToShow()
     a->setEnabled(false);
   }
 }
+
+/*!
+  Rename object by entry.
+  \param entry entry of the object
+  \param name new name of the object
+  \brief Return \c true if rename operation finished successfully, \c false otherwise.
+*/
+bool GeometryGUI::renameObject( const QString& entry, const QString& name) {
+  
+  bool appRes = SalomeApp_Module::renameObject(entry,name);
+  if( !appRes )
+    return false;
+  
+  bool result = false;
+  
+  SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
+  SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0; 
+
+  if(!appStudy)
+    return result;
+
+  _PTR(Study) aStudy = appStudy->studyDS();
+
+  if(!aStudy)
+    return result;
+
+  _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
+  _PTR(GenericAttribute) anAttr;
+  if ( obj ) {
+    if ( obj->FindAttribute(anAttr, "AttributeName") ) {
+      _PTR(AttributeName) aName (anAttr);
+      
+      GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
+      if (!CORBA::is_nil(anObj)) {
+       aName->SetValue( name.toLatin1().data() ); // rename the SObject
+       anObj->SetName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
+       result = true;
+      }
+    }
+  }
+  return result;
+}
index 2688dcc5518b118ad18dfc3c6d616d8fd74b586e..3899253f0293d26f7300f4535804c7c322f26d54 100644 (file)
@@ -124,6 +124,8 @@ public:
   gp_Ax3                      GetWorkingPlane()            { return myWorkingPlane; }
   void                        ActiveWorkingPlane();
 
+  virtual bool                renameObject( const QString&, const QString& );
+
   virtual void                windows( QMap<int, int>& ) const;
   virtual void                viewManagers( QStringList& ) const;
 
index 4d86e9bdd1f0b3f76e4e513bc91ca80e2b90fcdb..24da14bedcc48efec47d27cef6ceccc9b9840674 100644 (file)
@@ -50,7 +50,6 @@ namespace GEOMOp {
     OpPointMarker       = 1210,   // POPUP MENU - POINT MARKER
     OpShowChildren      = 1250,   // POPUP MENU - SHOW CHILDREN
     OpHideChildren      = 1251,   // POPUP MENU - HIDE CHILDREN
-    OpRename            = 1252,   // POPUP MENU - RENAME
     OpUnpublishObject   = 1253,   // POPUP MENU - UNPUBLISH
     OpPublishObject     = 1254,   // GEOM ROOT OBJECT - POPUP MENU - PUBLISH
 
index cbde99ce1d9f6f8d71c2c121e51a966d38bf2759..f32ee08969e5d2865734e9f5066d014a5eeb96a8 100644 (file)
@@ -322,9 +322,6 @@ bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
   case GEOMOp::OpSelectAll:      // POPUP - SELECT ONLY - SELECT ALL
     OnSelectOnly( GEOM_ALLOBJECTS );
     break;
-  case GEOMOp::OpRename:         // POPUP - RENAME
-    OnRename();
-    break;
   case GEOMOp::OpDeflection:     // POPUP - DEFLECTION ANGLE
     OnDeflection();
     break;
index 25516496a86f8425a6ac3f0b24c5874043f1212e..5cff2ef4591d330ed17980e8ee01af5a6eab4aa0 100644 (file)
@@ -60,8 +60,6 @@ private:
   bool         Export();
 
   void         OnEditDelete();
-
-  void         OnRename();
   void         OnCheckGeometry();
 
   // Popup commands
index 8f434de962ab40c58fdf272d2d96c48847e4f2ec..278e4785fb0fb5224d7a86408fa64b39298b6f7e 100644 (file)
 // VTK includes
 #include <vtkRenderer.h>
 
-void GEOMToolsGUI::OnRename()
-{
-  SALOME_ListIO selected;
-  SalomeApp_Application* app =
-    dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
-  if ( app ) {
-    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
-    SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
-    if ( aSelMgr && appStudy ) {
-      aSelMgr->selectedObjects( selected );
-      if ( !selected.IsEmpty() ) {
-        _PTR(Study) aStudy = appStudy->studyDS();
-
-        bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
-        if ( aLocked ) {
-          SUIT_MessageBox::warning ( app->desktop(),
-                                     QObject::tr("WRN_WARNING"),
-                                     QObject::tr("WRN_STUDY_LOCKED") );
-          return;
-        }
-
-        bool isAny = false; // is there any appropriate object selected
-        for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
-          Handle(SALOME_InteractiveObject) IObject = It.Value();
-
-          _PTR(SObject) obj ( aStudy->FindObjectID(IObject->getEntry()) );
-          _PTR(GenericAttribute) anAttr;
-          if ( obj ) {
-            if ( obj->FindAttribute(anAttr, "AttributeName") ) {
-              _PTR(AttributeName) aName (anAttr);
-
-              GEOM::GEOM_Object_var anObj =
-                GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
-              if (!CORBA::is_nil(anObj)) {
-                isAny = true;
-                QString newName = LightApp_NameDlg::getName( app->desktop(), aName->Value().c_str() );
-                if (!newName.isEmpty()) {
-                  aName->SetValue( newName.toLatin1().data() ); // rename the SObject
-                  IObject->setName( newName.toLatin1().data() );// rename the InteractiveObject
-                  anObj->SetName( newName.toLatin1().data() );  // Rename the corresponding GEOM_Object
-                  (dynamic_cast<SalomeApp_Module*>(app->activeModule()))->updateObjBrowser( false );
-                }
-              } // if ( anObj )
-            } // if ( name attribute )
-          } // if ( obj )
-        } // iterator
-
-        if (!isAny) {
-          SUIT_MessageBox::warning( app->desktop(),
-                                    QObject::tr("WRN_WARNING"),
-                                    QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
-          return;
-        }
-      }
-    }
-  }
-
-  app->updateActions(); //SRN: To update a Save button in the toolbar
-}
 
 void GEOMToolsGUI::OnCheckGeometry()
 {