From: vsr Date: Thu, 6 Jul 2017 15:09:40 +0000 (+0300) Subject: 0023454: [CEA 2110] Display warning message only in debug mode X-Git-Tag: V8_4_0a1~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0b64aa0810631fb7d524ded17716e403f773da9e;p=modules%2Fgui.git 0023454: [CEA 2110] Display warning message only in debug mode - Change a way the availability of a module is checked during application start-up --- diff --git a/src/CAM/CAM_Application.cxx b/src/CAM/CAM_Application.cxx index 59a7f7ed8..ad4866492 100755 --- a/src/CAM/CAM_Application.cxx +++ b/src/CAM/CAM_Application.cxx @@ -125,6 +125,15 @@ CAM_Application::~CAM_Application() */ void CAM_Application::start() { + // check modules + for ( ModuleInfoList::iterator it = myInfoList.begin(); + it != myInfoList.end(); ++it ) + { + if ( (*it).status == stUnknown ) + (*it).status = checkModule( (*it).title ) ? stReady : stInaccessible; + } + + // auto-load modules if ( myAutoLoad ) loadModules(); @@ -396,11 +405,9 @@ bool CAM_Application::activateModule( const QString& modName ) if ( !modName.isEmpty() ) { CAM_Module* mod = module( modName ); - if ( !mod && !moduleLibrary( modName ).isEmpty() ) - { + if ( !mod ) mod = loadModule( modName ); - addModule( mod ); - } + addModule( mod ); if ( mod ) res = activateModule( mod ); @@ -565,6 +572,19 @@ void CAM_Application::setActiveStudy( SUIT_Study* study ) STD_Application::setActiveStudy( study ); } +/*! + \brief Check module availability. + + The method can be redefined in successors. Default implementation returns \c true. + + \param title module title + \return \c true if module is accessible; \c false otherwise +*/ +bool CAM_Application::checkModule( const QString& ) +{ + return true; +} + /*! \brief Callback function, called when the module is added to the application. @@ -636,6 +656,7 @@ bool CAM_Application::isModuleAccessible( const QString& title ) { bool found = false; bool blocked = false; + bool statusOK = false; QStringList somewhereLoaded; QList apps = SUIT_Session::session()->applications(); @@ -653,8 +674,9 @@ bool CAM_Application::isModuleAccessible( const QString& title ) { found = (*it).title == title; blocked = (*it).isSingleton && somewhereLoaded.contains((*it).title); + statusOK = (*it).status == stReady; } - return found && !blocked; + return found && statusOK && !blocked; } /*! @@ -669,7 +691,7 @@ QString CAM_Application::moduleLibrary( const QString& title, const bool full ) for ( ModuleInfoList::const_iterator it = myInfoList.begin(); it != myInfoList.end() && res.isEmpty(); ++it ) { if ( (*it).title == title ) - res = (*it).internal; + res = (*it).library; } if ( !res.isEmpty() && full ) res = SUIT_Tools::library( res ); @@ -755,12 +777,15 @@ void CAM_Application::readModuleList() if ( !moduleTitle( modName ).isEmpty() ) continue; // already added + if ( modName == "KERNEL" || modName == "GUI" ) + continue; // omit KERNEL and GUI modules + QString modTitle = resMgr->stringValue( *it, "name", QString() ); if ( modTitle.isEmpty() ) { printf( "****************************************************************\n" ); - printf( "* Warning: %s GUI resources are not found.\n", qPrintable(*it) ); - printf( "* %s GUI will not be available.\n", qPrintable(*it) ); + printf( " Warning: module %s is improperly configured!\n", qPrintable(*it) ); + printf( " Module %s will not be available in GUI mode!\n", qPrintable(*it) ); printf( "****************************************************************\n" ); continue; } @@ -789,17 +814,18 @@ void CAM_Application::readModuleList() else modLibrary = modName; - bool aIsSingleton = resMgr->booleanValue(*it, "singleton", false); - - QString ver = resMgr->stringValue(*it, "version", QString()); + bool aIsSingleton = resMgr->booleanValue( *it, "singleton", false ); + bool hasGui = resMgr->booleanValue( *it, "gui", true ); + QString version = resMgr->stringValue( *it, "version", QString() ); ModuleInfo inf; inf.name = modName; inf.title = modTitle; - inf.internal = modLibrary; + inf.status = hasGui ? stUnknown : stNoGui; + if ( hasGui ) inf.library = modLibrary; inf.icon = modIcon; inf.isSingleton = aIsSingleton; - inf.version = ver; + inf.version = version; myInfoList.append( inf ); } diff --git a/src/CAM/CAM_Application.h b/src/CAM/CAM_Application.h index c1d0bbeba..a37572c52 100755 --- a/src/CAM/CAM_Application.h +++ b/src/CAM/CAM_Application.h @@ -74,6 +74,7 @@ public: static QString moduleName( const QString& ); static QString moduleTitle( const QString& ); static QString moduleIcon( const QString& ); + static QString moduleLibrary( const QString&, const bool = true ); static bool isModuleAccessible( const QString& ); virtual void createEmptyStudy(); @@ -84,6 +85,7 @@ protected: virtual SUIT_Study* createNewStudy(); virtual void updateCommandsStatus(); + virtual bool checkModule( const QString& ); virtual void moduleAdded( CAM_Module* ); virtual void beforeCloseDoc( SUIT_Study* ); virtual void afterCloseDoc(); @@ -91,15 +93,18 @@ protected: virtual void setActiveStudy( SUIT_Study* ); - static QString moduleLibrary( const QString&, const bool = true ); - virtual bool abortAllOperations(); private: void readModuleList(); private: - typedef struct { QString name, title, internal, icon; bool isSingleton; QString version; } ModuleInfo; + enum { stUnknown = 0, stNoGui, stInaccessible, stReady }; + typedef struct { + QString name, title, icon, library, version; + bool isSingleton; + int status; + } ModuleInfo; typedef QList ModuleInfoList; private: diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 5f71544ba..38acfcc60 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -715,14 +715,11 @@ void LightApp_Application::createActions() QStringList::Iterator it; for ( it = modList.begin(); it != modList.end(); ++it ) { - if ( !isLibExists( *it ) ) + if ( !isModuleAccessible( *it ) ) continue; QString modName = moduleName( *it ); - if ( !isModuleAccessible( *it ) ) - continue; - QString iconName; if ( iconMap.contains( *it ) ) iconName = iconMap[*it]; @@ -731,12 +728,12 @@ void LightApp_Application::createActions() if ( icon.isNull() ) { icon = modIcon; - INFOS ( "\n****************************************************************" << std::endl - << "* Icon for " << (*it).toLatin1().constData() - << " not found. Using the default one." << std::endl - << "****************************************************************" << std::endl ); + INFOS( std::endl << + "****************************************************************" << std::endl << + " Warning: icon for " << qPrintable(*it) << " is not found!" << std::endl << + " Using the default icon." << std::endl << + "****************************************************************" << std::endl); } - icon = Qtx::scaleIcon( icon, iconSize ); moduleAction->insertModule( *it, icon ); @@ -2162,7 +2159,7 @@ LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const for ( QStringList::const_iterator it = modNameList.begin(); it != modNameList.end(); ++it ) { - if ( !app->isLibExists( *it ) || _prefs_->hasModule( *it ) ) + if ( !app->isModuleAccessible( *it ) || _prefs_->hasModule( *it ) ) continue; int modId = _prefs_->addPreference( *it ); @@ -3911,6 +3908,70 @@ void LightApp_Application::removeModuleAction( const QString& modName ) moduleAction->removeModule( modName ); } +bool LightApp_Application::checkModule( const QString& title ) +{ + if ( title.isEmpty() ) + return false; + + QString library = moduleLibrary( title, true ); + if ( library.isEmpty() ) + return false; + + QString name = moduleName( title ); + + bool isPyModule = library.contains( "SalomePyQtGUI" ) || library.contains( "SalomePyQtGUILight" ); + + QStringList paths; +#if defined(WIN32) + paths = QString( ::getenv( "PATH" ) ).split( ";", QString::SkipEmptyParts ); +#elif defined(__APPLE__) + paths = QString( ::getenv( "DYLD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); +#else + paths = QString( ::getenv( "LD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); +#endif + + bool isFound = false; + QStringList::const_iterator it; + for ( it = paths.begin(); it != paths.end() && !isFound; ++it ) + { + isFound = QFileInfo( Qtx::addSlash( *it ) + library ).exists(); + } + + if ( !isFound ) + { + INFOS( std::endl << + "****************************************************************" << std::endl << + " Warning: library " << qPrintable( library ) << " is not found!" << std::endl << + " Module " << qPrintable( title ) << " will not be available in GUI mode!" << std::endl << + "****************************************************************" << std::endl); + return false; + } + + if ( isPyModule ) + { + QString pyModule = QString( "%1GUI.py" ).arg( name ); + paths = QString( ::getenv( "PYTHONPATH" ) ).split( ":", QString::SkipEmptyParts ); + + isFound = false; + for ( it = paths.begin(); it != paths.end() && !isFound; ++it ) + { + isFound = QFileInfo( Qtx::addSlash( *it ) + pyModule ).exists(); + } + + if ( !isFound ) + { + INFOS( std::endl << + "****************************************************************" << std::endl << + " Warning: Python module " << qPrintable( pyModule ) << " is not found!" << std::endl << + " Module " << qPrintable( title ) << " will not be available in GUI mode!" << std::endl << + "****************************************************************" << std::endl); + return false; + } + } + + return true; +} + /*! Gets current windows. \param winMap - output current windows map. @@ -4473,94 +4534,6 @@ void LightApp_Application::onGroupAllWindow() wgStack->stack(); } -/*! - \return if the library of module exists - \param moduleTitle - title of module -*/ -bool LightApp_Application::isLibExists( const QString& moduleTitle ) const -{ - if( moduleTitle.isEmpty() ) - return false; - - QString lib = moduleLibrary( moduleTitle ); - - //abd: changed libSalomePyQtGUI to SalomePyQtGUI for WIN32 - bool isPythonModule = lib.contains("SalomePyQtGUI"); - bool isPythonLightModule = lib.contains("SalomePyQtGUILight"); - - QStringList paths; -#if defined(WIN32) - paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts ); -#elif defined(__APPLE__) - paths = QString(::getenv( "DYLD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts ); -#else - paths = QString(::getenv( "LD_LIBRARY_PATH" )).split( ":", QString::SkipEmptyParts ); -#endif - - bool isLibFound = false; - QStringList::const_iterator anIt = paths.begin(), aLast = paths.end(); - for( ; anIt!=aLast; anIt++ ) - { - QFileInfo inf( Qtx::addSlash( *anIt ) + lib ); - - if( inf.exists() ) - { - isLibFound = true; - break; - } - } - - if ( !isLibFound ) - { - INFOS( "\n****************************************************************" << std::endl - << "* Warning: library " << lib.toLatin1().constData() << " cannot be found" << std::endl - << "* Module " << moduleTitle.toLatin1().constData() << " will not be available in GUI mode" << std::endl - << "****************************************************************" << std::endl ); - } - else if ( !isPythonModule && !isPythonLightModule) - return true; - - if ( isPythonModule || isPythonLightModule) - { - QString pylib = moduleName( moduleTitle ) + QString(".py"); - QString pylibgui = moduleName( moduleTitle ) + QString("GUI.py"); - - // Check the python library -// #ifdef WIN32 -// paths = QString(::getenv( "PATH" )).split( ";", QString::SkipEmptyParts ); -// #else - paths = QString(::getenv( "PYTHONPATH" )).split( ":", QString::SkipEmptyParts ); -// #endif - bool isPyLib = false, isPyGuiLib = false; - QStringList::const_iterator anIt = paths.begin(), aLast = paths.end(); - for( ; anIt!=aLast; anIt++ ) - { - QFileInfo inf( Qtx::addSlash( *anIt ) + pylib ); - QFileInfo infgui( Qtx::addSlash( *anIt ) + pylibgui ); - - if(!isPythonLightModule) - if( !isPyLib && inf.exists() ) - isPyLib = true; - - if( !isPyGuiLib && infgui.exists() ) - isPyGuiLib = true; - - if ((isPyLib || isPythonLightModule ) && isPyGuiLib && isLibFound) - return true; - } - - printf( "\n****************************************************************\n" ); - printf( "* Warning: python library for %s cannot be found:\n", moduleTitle.toLatin1().constData() ); - if (!isPyLib) - printf( "* No module named %s\n", moduleName( moduleTitle ).toLatin1().constData() ); - if (!isPyGuiLib) - printf( "* No module named %s\n", (moduleName( moduleTitle ) + QString("GUI")).toLatin1().constData() ); - printf( "****************************************************************\n" ); - return true; - } - return false; -} - /*! \return default name for an active study */ diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index 4d26aef25..b7d2fb9ec 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -284,6 +284,8 @@ protected: void updateModuleActions(); void removeModuleAction( const QString& ); + bool checkModule( const QString& ); + void loadDockWindowsState(); void saveDockWindowsState(); @@ -298,8 +300,6 @@ protected: void currentViewManagers( QStringList& ) const; void moduleIconNames( QMap& ) const; - bool isLibExists( const QString& ) const; - QDockWidget* windowDock( QWidget* ) const; QByteArray dockWindowsState( const QMap&, const QMap& ) const; void dockWindowsState( const QByteArray&, QMap&, QMap& ) const;