]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Management of extra popup menus (from XML) PARAVIS_29092009
authorvsv <vsv@opencascade.com>
Mon, 28 Sep 2009 10:23:45 +0000 (10:23 +0000)
committervsv <vsv@opencascade.com>
Mon, 28 Sep 2009 10:23:45 +0000 (10:23 +0000)
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Application.h

index dddb815f43e991dd100f28b377bd3ffab2bf2b95..2452f6a4b1866290298b20ed8bee1c5e9bb66c39 100644 (file)
@@ -302,6 +302,8 @@ void SalomeApp_Application::createActions()
   createMenu( CatalogGenId, toolsMenu, 10, -1 );
   createMenu( RegDisplayId, toolsMenu, 10, -1 );
   createMenu( separator(), toolsMenu, -1, 15, -1 );
+
+  fillExtActions();
 }
 
 /*!
@@ -1182,6 +1184,29 @@ void SalomeApp_Application::contextMenuPopup( const QString& type, QMenu* thePop
   if (aList.Extent() != 1)
     return;
   Handle(SALOME_InteractiveObject) aIObj = aList.First();
+
+  // add extra popup menu (defined in XML)
+  if (myExtActions.size() > 0) {
+    // Use only first selected object
+    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(activeStudy());
+    if(study == NULL) return;
+    
+    _PTR(Study) stdDS = study->studyDS();
+    if(stdDS) { 
+      _PTR(SObject) aSO = stdDS->FindObjectID(aIObj->getEntry());
+      if( aSO ) {
+        _PTR( GenericAttribute ) anAttr;
+        if ( aSO->FindAttribute( anAttr, "AttributeLocalID" ) ) {
+          _PTR(AttributeLocalID) aAttrID = anAttr;
+          long aId = aAttrID->Value();
+          if (myExtActions.contains(aId)) {
+            thePopup->addAction(myExtActions[aId]);
+          }
+        }
+      }
+    }
+  }
+
   // check if item is a "GUI state" item (also a first level object)
   QString entry( aIObj->getEntry() );
   if ( entry.startsWith( tr( "SAVE_POINT_DEF_NAME" ) ) )
@@ -1499,3 +1524,73 @@ SalomeApp_NoteBookDlg* SalomeApp_Application::getNoteBook() const
   return myNoteBook;
 }
 
+void SalomeApp_Application::fillExtActions()
+{
+  myExtActions.clear();
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+
+  QStringList aModules;
+  modules(aModules, false);
+  foreach(QString aModile, aModules) {
+    QString aModName = moduleName(aModile);
+    QString aSectionStr = resMgr->stringValue(aModName, "popupitems", QString());
+    if (!aSectionStr.isNull()) {
+      QStringList aSections = aSectionStr.split(':');
+      foreach(QString aSection, aSections) {
+        QString aTitle = resMgr->stringValue(aSection, "title", QString());
+        int aId = resMgr->integerValue(aSection, "attributelocalid", -1);
+        QString aSlot = resMgr->stringValue(aSection, "method", QString());
+        if (aTitle.isNull() || aSlot.isNull() || (aId == -1))
+          continue;
+        
+        QString aModuleName = resMgr->stringValue(aSection, "module", QString());
+        if (aModuleName.isNull())
+          aModuleName = aModName;
+        
+        QAction* aAction = new QAction(aTitle, this);
+        QStringList aData;
+        aData<<aModuleName<<aSlot;
+        aAction->setData(aData);
+        connect(aAction, SIGNAL(triggered()), this, SLOT(onExtAction()));
+        myExtActions[aId] = aAction;
+      }
+    }
+  }
+}
+
+void SalomeApp_Application::onExtAction()
+{
+  QAction* aAction = ::qobject_cast<QAction*>(sender());
+  if (!aAction)
+    return;
+
+  QVariant aData = aAction->data();
+  QStringList aDataList = aData.value<QStringList>();
+  if (aDataList.size() != 2)
+    return;
+
+  LightApp_SelectionMgr* aSelectionMgr = selectionMgr();
+  SALOME_ListIO aListIO;
+  aSelectionMgr->selectedObjects(aListIO);
+  const Handle(SALOME_InteractiveObject)& anIO = aListIO.First();
+  if (aListIO.Extent() < 1)
+    return;
+  if (!anIO->hasEntry()) 
+    return;
+  
+  QString aEntry(anIO->getEntry());
+
+  QApplication::setOverrideCursor( Qt::WaitCursor );
+  QString aModuleTitle = moduleTitle(aDataList[0]);
+  activateModule(aModuleTitle);
+  QApplication::restoreOverrideCursor();
+
+  QCoreApplication::processEvents();
+
+  CAM_Module* aModule = activeModule();
+  if (!aModule)
+    return;
+
+  if (!QMetaObject::invokeMethod(aModule, qPrintable(aDataList[1]), Q_ARG(QString, aEntry)))
+    printf("Error: Can't Invoke method %s\n", qPrintable(aDataList[1]));
+}
index 3f18e68067473e948c30b132ccdfd585d141527e..5bfd986f9d997f28fe3e8d8bb677364a9019e026 100644 (file)
@@ -155,9 +155,16 @@ private slots:
   void                                onCatalogGen();
   void                                onRegDisplay();
   void                                onOpenWith();
+  void                                onExtAction();
 
  private:
   SalomeApp_NoteBookDlg*             myNoteBook;
+
+
+ private:
+  void fillExtActions();
+
+  QMap<long, QAction*> myExtActions; // Map <AttributeLocalID, QAction>
 };
 
 #ifdef WIN32