From 261242f8ba9f4786d7e64b7e2c46a3dd6bbaef1f Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Dec 2009 17:45:13 +0000 Subject: [PATCH] Merge from BR_PARAVIS_DEV 17/12/2009 --- src/CAM/CAM_Application.cxx | 22 +++++ src/CAM/CAM_Application.h | 3 +- src/LightApp/LightApp_Application.cxx | 63 ++++++++++--- src/LightApp/LightApp_Application.h | 6 ++ src/SalomeApp/SalomeApp_Application.cxx | 115 ++++++++++++++++++++++++ src/SalomeApp/SalomeApp_Application.h | 9 +- src/SalomeApp/SalomeApp_VisualState.cxx | 3 +- 7 files changed, 207 insertions(+), 14 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 980031237..fadf36800 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -238,6 +238,9 @@ void CAM_Application::loadModules() { for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it ) { + if (!isModuleAccessible((*it).name)) { + continue; + } CAM_Module* mod = loadModule( (*it).title ); if ( mod ) addModule( mod ); @@ -513,6 +516,22 @@ QString CAM_Application::moduleIcon( const QString& name ) const return res; } +/*! + \brief Returns \c true if module is accessible for the current application. + Singleton module can be loaded only in one application object. In other application + objects this module will be unavailable. + */ +bool CAM_Application::isModuleAccessible( const QString& name ) const +{ + int aAppsNb = SUIT_Session::session()->applications().count(); + for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it ) + { + if ( (*it).name == name ) + return (*it).isSingleton && (aAppsNb > 1); + } + return false; +} + /*! \brief Get module library name by its title (user name). \param title module title (user name) @@ -643,11 +662,14 @@ void CAM_Application::readModuleList() else modLibrary = modName; + bool aIsSingleton = resMgr->booleanValue(*it, "singleton", false); + ModuleInfo inf; inf.name = modName; inf.title = modTitle; inf.internal = modLibrary; inf.icon = modIcon; + inf.isSingleton = aIsSingleton; myInfoList.append( inf ); } diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index e04876078..14dc92813 100755 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -66,6 +66,7 @@ public: QString moduleName( const QString& ) const; QString moduleTitle( const QString& ) const; QString moduleIcon( const QString& ) const; + bool isModuleAccessible( const QString& ) const; virtual void createEmptyStudy(); @@ -86,7 +87,7 @@ private: void readModuleList(); private: - typedef struct { QString name, title, internal, icon; } ModuleInfo; + typedef struct { QString name, title, internal, icon; bool isSingleton; } ModuleInfo; typedef QList ModuleInfoList; private: diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index c08d3db60..ca407cac2 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -503,20 +503,20 @@ void LightApp_Application::createActions() static QtxMRUAction* mru = new QtxMRUAction( tr( "TOT_DESK_MRU" ), tr( "MEN_DESK_MRU" ), 0 ); connect( mru, SIGNAL( activated( const QString& ) ), this, SLOT( onMRUActivated( const QString& ) ) ); registerAction( MRUId, mru ); - + // default icon for neutral point ('SALOME' module) QPixmap defIcon = resMgr->loadPixmap( "LightApp", tr( "APP_DEFAULT_ICO" ), false ); if ( defIcon.isNull() ) defIcon = QPixmap( imageEmptyIcon ); - + //! default icon for any module QPixmap modIcon = resMgr->loadPixmap( "LightApp", tr( "APP_MODULE_ICO" ), false ); if ( modIcon.isNull() ) modIcon = QPixmap( imageEmptyIcon ); - + QStringList modList; modules( modList, false ); - + if ( modList.count() > 1 ) { LightApp_ModuleAction* moduleAction = @@ -532,20 +532,24 @@ void LightApp_Application::createActions() { if ( !isLibExists( *it ) ) continue; + + QString modName = moduleName( *it ); + + if (!isModuleAccessible(modName)) + continue; QString iconName; if ( iconMap.contains( *it ) ) iconName = iconMap[*it]; - QString modName = moduleName( *it ); - QPixmap icon = resMgr->loadPixmap( modName, iconName, false ); if ( icon.isNull() ) { icon = modIcon; INFOS ( "****************************************************************" << std::endl - << "* Icon for " << (*it).toLatin1().constData() << " not found. Using the default one." << std::endl - << "****************************************************************" << std::endl ); + << "* Icon for " << (*it).toLatin1().constData() + << " not found. Using the default one." << std::endl + << "****************************************************************" << std::endl ); } icon = Qtx::scaleIcon( icon, iconSize ); @@ -553,8 +557,8 @@ void LightApp_Application::createActions() moduleAction->insertModule( *it, icon ); } - - connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), this, SLOT( onModuleActivation( const QString& ) ) ); + connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), + this, SLOT( onModuleActivation( const QString& ) ) ); registerAction( ModulesListId, moduleAction ); } @@ -3130,3 +3134,42 @@ bool LightApp_Application::openAction( const int choice, const QString& aName ) return res; } + +QStringList LightApp_Application::viewManagersTypes() const +{ + QStringList aTypesList; +#ifndef DISABLE_GLVIEWER + aTypesList< aMgrList; + viewManagers( aMgrList ); + foreach (SUIT_ViewManager* aMgr, aMgrList) { + if (aTypesList.contains(aMgr->getType())) + removeViewManager(aMgr); + } +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 652c0528b..b36d155a4 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -148,6 +148,12 @@ public: virtual void updateDesktopTitle(); + //! Returns list of view manager types which are supported by this application + QStringList viewManagersTypes() const; + + //! Removes ViewManagers only of known type + virtual void clearKnownViewManagers(); + signals: void studyOpened(); void studySaved(); diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 573f9e374..ba3d16744 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 ); + + createExtraActions(); } /*! @@ -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 ) { + _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,93 @@ SalomeApp_NoteBookDlg* SalomeApp_Application::getNoteBook() const return myNoteBook; } +/*! + * Define extra actions defined in module definition XML file. + * Additional popup items sections can be defined by parameter "popupitems". + * Supported attributes: + * title - title of menu item, + * attributelocalid - AttributeLocalId defined for selected data item where menu command has to be applied, + * method - method which has to be called when menu item is selected + * Example: + *
+ * + *
+ *
+ * + * + * + *
+ */ +void SalomeApp_Application::createExtraActions() +{ + 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; + } + } + } +} + +/*! + * Called when extra action is selected + */ +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..491d0c10a 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -155,9 +155,14 @@ private slots: void onCatalogGen(); void onRegDisplay(); void onOpenWith(); + void onExtAction(); - private: - SalomeApp_NoteBookDlg* myNoteBook; +private: + void createExtraActions(); + +private: + SalomeApp_NoteBookDlg* myNoteBook; + QMap myExtActions; // Map }; #ifdef WIN32 diff --git a/src/SalomeApp/SalomeApp_VisualState.cxx b/src/SalomeApp/SalomeApp_VisualState.cxx index 6b27a16ae..a642bd2df 100644 --- a/src/SalomeApp/SalomeApp_VisualState.cxx +++ b/src/SalomeApp/SalomeApp_VisualState.cxx @@ -199,7 +199,8 @@ void SalomeApp_VisualState::restoreState(int savePoint) qApp->installEventFilter( this ); //Remove all already existent veiwers and their views - myApp->clearViewManagers(); + //myApp->clearViewManagers(); + myApp->clearKnownViewManagers(); //Restore the viewers and view windows int nbViewers = ip->nbValues( "AP_VIEWERS_LIST" ); -- 2.39.2