From 6d04ff2913b2587cf2a120376bfe24d003bbddd3 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 28 Sep 2009 10:23:45 +0000 Subject: [PATCH] Management of extra popup menus (from XML) --- src/SalomeApp/SalomeApp_Application.cxx | 95 +++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Application.h | 7 ++ 2 files changed, 102 insertions(+) diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index dddb815f4..2452f6a4b 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -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(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<setData(aData); + connect(aAction, SIGNAL(triggered()), this, SLOT(onExtAction())); + myExtActions[aId] = aAction; + } + } + } +} + +void SalomeApp_Application::onExtAction() +{ + QAction* aAction = ::qobject_cast(sender()); + if (!aAction) + return; + + QVariant aData = aAction->data(); + QStringList aDataList = aData.value(); + 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])); +} diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 3f18e6806..5bfd986f9 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -155,9 +155,16 @@ private slots: void onCatalogGen(); void onRegDisplay(); void onOpenWith(); + void onExtAction(); private: SalomeApp_NoteBookDlg* myNoteBook; + + + private: + void fillExtActions(); + + QMap myExtActions; // Map }; #ifdef WIN32 -- 2.39.2