Salome HOME
0023454: [CEA 2110] Display warning message only in debug mode
[modules/gui.git] / src / CAM / CAM_Application.cxx
index f6bdc96886ec8f8a79b61d0faa29d838225889d6..ad486649262dbb5009e8241de90a26bdf5fa33f3 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -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();
 
@@ -335,7 +344,7 @@ CAM_Module* CAM_Application::loadModule( const QString& modName, const bool show
     getVersion = (GET_VERSION_FUNC)::GetProcAddress( modLib, GET_VERSION_NAME );
   }
 #else
-  void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY );
+  void* modLib = dlopen( libName.toLatin1(), RTLD_LAZY | RTLD_GLOBAL );
   if ( !modLib )
     err = QString( "Can not load library %1. %2" ).arg( libName ).arg( dlerror() );
   else
@@ -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<SUIT_Application*> 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;
     }
@@ -771,8 +796,10 @@ void CAM_Application::readModuleList()
     if ( !modLibrary.isEmpty() )
     {
       modLibrary = SUIT_Tools::file( modLibrary.trimmed() );
-#ifdef WIN32
+#if defined(WIN32)
       QString libExt = QString( "dll" );
+#elif defined(__APPLE__)
+      QString libExt = QString( "dylib" );
 #else
       QString libExt = QString( "so" );
 #endif
@@ -787,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 );
   }
 
@@ -863,3 +891,20 @@ CAM_Application::ModuleShortInfoList CAM_Application::getVersionInfo()
   }  
   return info;
 }
+
+/*!
+  \brief Abort active operations if there are any
+  Iterates through all modules and asks each of them if there are pending operations that cannot be aborted.
+  \return \c false if some operation cannot be aborted
+*/
+bool CAM_Application::abortAllOperations()
+{
+  bool aborted = true;
+  for ( QList<CAM_Module*>::const_iterator it = myModules.begin(); it != myModules.end() && aborted; ++it )
+  {
+    aborted = (*it)->abortAllOperations();
+  }
+  return aborted;
+}