From fa98d4668f8928f5e901a53ef2b852213bf8b443 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 21 Sep 2009 08:10:53 +0000 Subject: [PATCH] Singleton module defined --- src/CAM/CAM_Application.cxx | 43 +++++++++++--- src/CAM/CAM_Application.h | 9 ++- src/LightApp/LightApp_Application.cxx | 86 ++++++++++++++------------- 3 files changed, 87 insertions(+), 51 deletions(-) diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index b731d4c57..c4b3e72d5 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -146,7 +146,7 @@ void CAM_Application::modules( CAM_Application::ModuleList& out ) const out.clear(); for ( QList::const_iterator it = myModules.begin(); - it != myModules.end(); ++it ) + it != myModules.end(); ++it ) out.append( *it ); } @@ -166,14 +166,14 @@ void CAM_Application::modules( QStringList& lst, const bool loaded ) const if ( loaded ) { for ( QList::const_iterator it = myModules.begin(); - it != myModules.end(); ++it ) - lst.append( (*it)->moduleName() ); + it != myModules.end(); ++it ) + lst.append( (*it)->moduleName() ); } else { for ( ModuleInfoList::const_iterator it = myInfoList.begin(); - it != myInfoList.end(); ++it ) - lst.append( (*it).title ); + it != myInfoList.end(); ++it ) + lst.append( (*it).title ); } } @@ -224,6 +224,29 @@ void CAM_Application::addModule( CAM_Module* mod ) moduleAdded( mod ); } +/*! + \brief returns true if module is accessible for the current application. + If module is a singleton and current session has more then one application + then this module can't be accessible in this one. + */ +bool CAM_Application::isModuleAccessible(const QString& theModName) const +{ + for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it ) + { + if ((*it).name == theModName) { + return isModuleAccessible(it); + } + } + return true; +} +bool CAM_Application::isModuleAccessible(const ModuleInfoList::const_iterator& theIt) const +{ + int aAppsNb = SUIT_Session::session()->applications().size(); + if ((*theIt).isSingleton && (aAppsNb > 1)) + return false; + return true; +} + /*! \brief Load modules from the modules information list. @@ -233,15 +256,18 @@ 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 ); else { QString wrn = tr( "Can not load module %1" ).arg( (*it).title ); if ( desktop() && desktop()->isVisible() ) - SUIT_MessageBox::critical( desktop(), tr( "Loading modules" ), wrn ); + SUIT_MessageBox::critical( desktop(), tr( "Loading modules" ), wrn ); else - qWarning( qPrintable( wrn ) ); + qWarning( qPrintable( wrn ) ); } } } @@ -634,11 +660,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 5ce540555..d745d501b 100755 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -69,6 +69,8 @@ public: virtual void createEmptyStudy(); + virtual bool isModuleAccessible(const QString&) const; + protected: virtual SUIT_Study* createNewStudy(); virtual void updateCommandsStatus(); @@ -82,11 +84,12 @@ protected: QString moduleLibrary( const QString&, const bool = true ) const; private: - void readModuleList(); + typedef struct { QString name, title, internal, icon; bool isSingleton; } ModuleInfo; + typedef QList ModuleInfoList; private: - typedef struct { QString name, title, internal, icon; } ModuleInfo; - typedef QList ModuleInfoList; + void readModuleList(); + bool isModuleAccessible(const ModuleInfoList::const_iterator&) const; private: CAM_Module* myModule; //!< active module diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 1c4e5c28a..9af3c4b08 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -496,61 +496,65 @@ 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 = - new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk ); - - QMap iconMap; - moduleIconNames( iconMap ); - - const int iconSize = 20; - - QStringList::Iterator it; - for ( it = modList.begin(); it != modList.end(); ++it ) { - if ( !isLibExists( *it ) ) - 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 = Qtx::scaleIcon( icon, iconSize ); - - moduleAction->insertModule( *it, icon ); + LightApp_ModuleAction* moduleAction = + new LightApp_ModuleAction( tr( "APP_NAME" ), defIcon, desk ); + + QMap iconMap; + moduleIconNames( iconMap ); + + const int iconSize = 20; + + QStringList::Iterator it; + for ( it = modList.begin(); it != modList.end(); ++it ) + { + if ( !isLibExists( *it ) ) + continue; + QString modName = moduleName( *it ); + + if (!isModuleAccessible(modName)) + continue; + + QString iconName; + if ( iconMap.contains( *it ) ) + iconName = iconMap[*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 = Qtx::scaleIcon( icon, iconSize ); + + moduleAction->insertModule( *it, icon ); + } + + + connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), + this, SLOT( onModuleActivation( const QString& ) ) ); + registerAction( ModulesListId, moduleAction ); } - - connect( moduleAction, SIGNAL( moduleActivated( const QString& ) ), this, SLOT( onModuleActivation( const QString& ) ) ); - registerAction( ModulesListId, moduleAction ); - } - // New window int windowMenu = createMenu( tr( "MEN_DESK_WINDOW" ), -1, MenuWindowId, 100 ); int newWinMenu = createMenu( tr( "MEN_DESK_NEWWINDOW" ), windowMenu, -1, 0 ); -- 2.39.2