From: vsr Date: Mon, 25 Jan 2010 06:41:36 +0000 (+0000) Subject: Improve modules management (for singleton modules like PARAVIS) X-Git-Tag: PARAVIS_29012010~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5f4119773f69394ef670b1bd1511d7941c967b72;p=modules%2Fgui.git Improve modules management (for singleton modules like PARAVIS) --- diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 22a406965..3dfe8dbf6 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -238,7 +238,7 @@ void CAM_Application::loadModules() { for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end(); ++it ) { - if (!isModuleAccessible((*it).name)) { + if ( !isModuleAccessible( (*it).title ) ) { continue; } CAM_Module* mod = loadModule( (*it).title ); @@ -273,6 +273,11 @@ CAM_Module* CAM_Application::loadModule( const QString& modName, const bool show return 0; } + if ( !isModuleAccessible( modName ) ) { + qWarning( qPrintable( tr( "Module \"%1\" cannot be loaded in this application." ).arg( modName ) ) ); + return 0; + } + QString libName = moduleLibrary( modName ); if ( libName.isEmpty() ) { @@ -520,16 +525,30 @@ QString CAM_Application::moduleIcon( const QString& name ) const \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. + \param title module title (user name) + \return \c true if module is accessible (can be loaded) or \c false otherwise */ -bool CAM_Application::isModuleAccessible( const QString& name ) const +bool CAM_Application::isModuleAccessible( const QString& title ) const { bool found = false; bool blocked = false; - int aAppsNb = SUIT_Session::session()->applications().count(); + + QStringList somewhereLoaded; + QList apps = SUIT_Session::session()->applications(); + foreach( SUIT_Application* app, apps ) { + CAM_Application* camApp = dynamic_cast( app ); + if ( !camApp ) continue; + QStringList loaded; + camApp->modules( loaded, true ); + foreach( QString lm, loaded ) { + if ( !somewhereLoaded.contains( lm ) ) somewhereLoaded << lm; + } + } + for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end() && !found; ++it ) { - found = (*it).name == name; - if ( found ) blocked = (*it).isSingleton && (aAppsNb > 1); + found = (*it).title == title; + blocked = (*it).isSingleton && somewhereLoaded.contains((*it).title); } return found && !blocked; } diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 46d71f48f..119329bf0 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -543,7 +543,7 @@ void LightApp_Application::createActions() QStringList modList; modules( modList, false ); - + if ( modList.count() > 1 ) { LightApp_ModuleAction* moduleAction = @@ -562,7 +562,7 @@ void LightApp_Application::createActions() QString modName = moduleName( *it ); - if (!isModuleAccessible(modName)) + if ( !isModuleAccessible( *it ) ) continue; QString iconName; @@ -2525,8 +2525,17 @@ void LightApp_Application::afterCloseDoc() void LightApp_Application::updateModuleActions() { QString modName; - if ( activeModule() ) + if ( activeModule() ) { modName = activeModule()->moduleName(); + if ( !isModuleAccessible( modName ) ) { + QList apps = SUIT_Session::session()->applications(); + foreach( SUIT_Application* app, apps ) { + LightApp_Application* lapp = dynamic_cast( app ); + if ( lapp && lapp != this ) + lapp->removeModuleAction( modName ); + } + } + } LightApp_ModuleAction* moduleAction = qobject_cast( action( ModulesListId ) ); @@ -2534,6 +2543,14 @@ void LightApp_Application::updateModuleActions() moduleAction->setActiveModule( modName ); } +void LightApp_Application::removeModuleAction( const QString& modName ) +{ + LightApp_ModuleAction* moduleAction = + qobject_cast( action( ModulesListId ) ); + if ( moduleAction ) + moduleAction->removeModule( modName ); +} + /*! Gets current windows. \param winMap - output current windows map. diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index b36d155a4..27d0852af 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -230,6 +230,7 @@ protected: void updateWindows(); void updateViewManagers(); void updateModuleActions(); + void removeModuleAction( const QString& ); void loadDockWindowsState(); void saveDockWindowsState();