Salome HOME
Redesign SALOME documentation
[modules/gui.git] / src / LightApp / LightApp_Application.cxx
index 307579e473a23ccb0f1419a1224b8597c9c3f868..7e0661fb6d767acdd9ef9bd0be2050016a62f02c 100644 (file)
@@ -246,6 +246,14 @@ int LightApp_Application::lastStudyId = 0;
 //since the 'toolbar marker' is not unique, find index of first occurrence of the
 //'toolbar marker' in the array and check that next string is name of the toolbar
 
+void LightAppCleanUpAppResources()
+{
+  if ( LightApp_Application::_prefs_ ) {
+    delete LightApp_Application::_prefs_;
+    LightApp_Application::_prefs_ = 0;
+  }
+}
+
 namespace
 {
   int getToolbarMarkerIndex( QByteArray input, const QStringList& aFlags ) {
@@ -439,6 +447,7 @@ LightApp_Application::~LightApp_Application()
   savePreferences();
   delete mySelMgr;
   delete myScreenHelper;
+  myPrefs = 0;
 }
 
 /*!Start application.*/
@@ -586,7 +595,7 @@ void LightApp_Application::createActions()
   // Preferences
   createAction( PreferencesId, tr( "TOT_DESK_PREFERENCES" ), QIcon(),
                 tr( "MEN_DESK_PREFERENCES" ), tr( "PRP_DESK_PREFERENCES" ),
-                Qt::CTRL+Qt::Key_R, desk, false, this, SLOT( onPreferences() ) );
+                Qt::CTRL+Qt::Key_P, desk, false, this, SLOT( onPreferences() ) );
 
   // Help menu:
 
@@ -594,13 +603,47 @@ void LightApp_Application::createActions()
 
   int helpMenu = createMenu( tr( "MEN_DESK_HELP" ), -1, -1, 1000 );
   createMenu( separator(), helpMenu, -1, 10 );
+  
+  // Site && forum
+  int id = LightApp_Application::UserID + FIRST_HELP_ID;
+
+  QString site = tr ( "SALOME_SITE" );
+  QAction* as = createAction( id, site,
+                             resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ),
+                             site, site,
+                             0, desk, false, this, SLOT( onHelpOnline() ) );
+  as->setData( "salome-platform.org" );
+  createMenu( as, helpMenu, -1, 0 );
+  id++;
+
+  QString forum = tr ( "SALOME_FORUM" );
+
+  QAction* af = createAction( helpMenu, forum,
+                             resMgr->loadPixmap( "LightApp", tr( "ICON_WWW" ), false ),
+                             forum, forum,
+                             0, desk, false, this, SLOT( onHelpOnline() ) );
+  af->setData( "salome-platform.org/forum" );
+  createMenu( af, helpMenu, -1, 0 );
+  id++;
+
+  createMenu( separator(), helpMenu, -1, 0 );
+
+  // YouTube channel
+  QString video = tr ( "SALOME_VIDEO_TUTORIALS" );
+  QAction* av = createAction( helpMenu, video,
+                             resMgr->loadPixmap( "LightApp", tr( "ICON_LIFE_RIGN" ), false ),
+                             video, video,
+                             0, desk, false, this, SLOT( onHelpOnline() ) );
+  av->setData( "not-created-yet.com" );
+  createMenu( av, helpMenu, -1, 0 );
+  id++;
+
+
   QStringList aModuleList;
   modules( aModuleList, false );
   aModuleList.prepend( "GUI" );
   aModuleList.prepend( "KERNEL" );
 
-  int id = LightApp_Application::UserID + FIRST_HELP_ID;
-
   QString aModule;
   foreach( aModule, aModuleList ) {
     if ( aModule.isEmpty() )                                         // module title (user name)
@@ -715,14 +758,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 +771,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 );
@@ -1091,16 +1131,23 @@ public:
               const QString&        theApp,
               const QString&        theParams,
               const QString&        theHelpFile,
-              const QString&        theContext = QString() )
+              const QString&        theContext = QString(),
+             //For the external browser always specify 'file://' protocol,
+             //because some WEB browsers (for example Mozilla Firefox) can't open local file without protocol.
+             const QString&        theProtocol = QString("file://"),
+             const bool            isFile = true)
     : myApp( theApp ),
       myParams( theParams ),
       myContext( theContext ),
       myStatus(0),
       myLApp( app )
   {
-    //For the external browser always specify 'file://' protocol,
-    //because some WEB browsers (for example Mozilla Firefox) can't open local file without protocol.
-    myHelpFile = QString("file://%1").arg( QFileInfo( theHelpFile ).canonicalFilePath() );
+    QString path_begin = theProtocol+"%1";
+    QString path_end = theHelpFile;
+    if( isFile ) {
+      path_end = QFileInfo( theHelpFile ).canonicalFilePath();
+    }
+    myHelpFile = path_begin.arg( path_end );
   }
 
   virtual void run()
@@ -1255,6 +1302,57 @@ void LightApp_Application::onHelpContextModule( const QString& theComponentName,
   }
 }
 
+/*!
+  SLOT: Displays help contents for choosen module
+*/
+void LightApp_Application::onHelpOnline()
+{
+  const QAction* a = (QAction*) sender();
+  QString url = a->data().toString();
+  if ( url.isEmpty() ) return;
+
+  SUIT_ResourceMgr* resMgr = resourceMgr();
+  QString platform;
+#ifdef WIN32
+  platform = "winapplication";
+#else
+  platform = "application";
+#endif
+  QString anApp = resMgr->stringValue("ExternalBrowser", platform);
+#ifdef WIN32
+  QString quote("\"");
+  anApp.prepend( quote );
+  anApp.append( quote );
+#endif
+  QString aParams = resMgr->stringValue("ExternalBrowser", "parameters");
+#if DISABLE_QTXWEBBROWSER
+  bool useExtBrowser = true;
+#else  
+  bool useExtBrowser = resMgr->booleanValue("ExternalBrowser", "use_external_browser", false );
+#endif
+  
+  if( useExtBrowser ) {
+    if ( !anApp.isEmpty() ) {
+      RunBrowser* rs = new RunBrowser( this, anApp, aParams, url, "", "http://", false );
+      rs->start();
+    }
+    else {
+      if ( SUIT_MessageBox::question( desktop(), tr( "WRN_WARNING" ), tr( "DEFINE_EXTERNAL_BROWSER" ),
+                                      SUIT_MessageBox::Yes | SUIT_MessageBox::No,
+                                      SUIT_MessageBox::Yes ) == SUIT_MessageBox::Yes )
+
+        showPreferences( tr( "PREF_APP" ) );
+    }
+  }
+  else {
+    QStringList parameters;
+    parameters << QString( "--language=%1" ).arg( resMgr->stringValue( "language", "language" ) );
+    parameters << QString( "--add=%1" ).arg( QApplication::instance()->applicationPid() );
+    parameters << "http://" + url;
+    QProcess::startDetached( "HelpBrowser", parameters );
+  }
+}
+
 /*!
   Sets enable or disable some actions on selection changed.
 */
@@ -1584,7 +1682,6 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
                            resMgr->booleanValue( "3DViewer", "relative_size", vm->trihedronRelative() ));
     vm->setInteractionStyle( resMgr->integerValue( "3DViewer", "navigation_mode", vm->interactionStyle() ) );
     vm->setProjectionType( resMgr->integerValue( "OCCViewer", "projection_mode", vm->projectionType() ) );
-  #if OCC_VERSION_LARGE > 0x06090000
     vm->setStereoType( resMgr->integerValue( "OCCViewer", "stereo_type", vm->stereoType() ) );
     vm->setAnaglyphFilter( resMgr->integerValue( "OCCViewer", "anaglyph_filter", vm->anaglyphFilter() ) );
     vm->setStereographicFocus( resMgr->integerValue( "OCCViewer", "focus_type", vm->stereographicFocusType() ),
@@ -1595,7 +1692,6 @@ SUIT_ViewManager* LightApp_Application::createViewManager( const QString& vmType
     vm->setReverseStereo( resMgr->booleanValue( "OCCViewer", "reverse_stereo", vm->isReverseStereo() ) );
     vm->setVSync( resMgr->booleanValue( "OCCViewer", "enable_vsync", vm->isVSync() ) );
     vm->setQuadBufferSupport( resMgr->booleanValue( "OCCViewer", "enable_quad_buffer_support", vm->isQuadBufferSupport() ) );
-  #endif
     vm->setZoomingStyle( resMgr->integerValue( "3DViewer", "zooming_mode", vm->zoomingStyle() ) );
     vm->enablePreselection( resMgr->booleanValue( "OCCViewer", "enable_preselection", vm->isPreselectionEnabled() ) );
     vm->enableSelection(    resMgr->booleanValue( "OCCViewer", "enable_selection",    vm->isSelectionEnabled() ) );
@@ -2133,6 +2229,7 @@ LightApp_Preferences* LightApp_Application::preferences( const bool crt ) const
   {
     _prefs_ = new LightApp_Preferences( resourceMgr() );
     that->createPreferences( _prefs_ );
+    qAddPostRoutine( LightAppCleanUpAppResources );
   }
 
   that->myPrefs = _prefs_;
@@ -2162,7 +2259,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 );
@@ -2414,7 +2511,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   anIndicesList << 0                       << 1;
   pref->setItemProperty( "strings", aValuesList,   occProjMode );
   pref->setItemProperty( "indexes", anIndicesList, occProjMode );
-#if OCC_VERSION_LARGE > 0x06090000
+
   // .... -> Stereo group
   int stereoGroup = pref->addPreference( tr( "PREF_GROUP_STEREO" ), occGroup);
   pref->setItemProperty( "columns", 2, stereoGroup );
@@ -2485,7 +2582,7 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   // .... -> Enable quad-buffer support
   pref->addPreference( tr( "PREF_ENABLE_QUAD_BUFFER_SUPPORT" ), stereoGroup,
                        LightApp_Preferences::Bool, "OCCViewer", "enable_quad_buffer_support" );
-#endif
+
   // ... "Background" group <<start>>
   int bgGroup = pref->addPreference( tr( "PREF_VIEWER_BACKGROUND" ), occGroup );
   //  pref->setItemProperty( "columns", 2, bgGroup );
@@ -2932,6 +3029,20 @@ void LightApp_Application::createPreferences( LightApp_Preferences* pref )
   pref->addPreference( tr( "PREF_PY_LINE_NUMBS_AREA" ), pyDispGroup,
     LightApp_Preferences::Bool, "PyEditor", "LineNumberArea" );
   // ... "Display settings" group <<end>>
+
+  // ... "Editor settings" group <<start>>
+  int pyEditGroup = pref->addPreference( tr( "PREF_GROUP_PY_EDITOR" ), pyeditTab );
+  // ... -> navigation mode
+  int pyCompletion = pref->addPreference( tr( "PREF_PY_COMPLETION_MODE" ), pyEditGroup,
+                                          LightApp_Preferences::Selector, "PyEditor", "CompletionPolicy" );
+  aValuesList.clear();
+  anIndicesList.clear();
+  aValuesList   << tr("PREF_PY_NONE") << tr("PREF_PY_AUTO") << tr("PREF_PY_MANUAL") << tr("PREF_PY_ALWAYS");
+  anIndicesList << 0                  << 1                  << 2                    << 3                   ;
+  pref->setItemProperty( "strings", aValuesList, pyCompletion );
+  pref->setItemProperty( "indexes", anIndicesList, pyCompletion );
+  // ... "Editor settings" group <<end>>
+
   // ... "Tab settings" group <<start>>
   int pyTabGroup = pref->addPreference( tr( "PREF_GROUP_PY_TAB" ), pyeditTab );
   pref->setItemProperty( "columns", 2, pyTabGroup );
@@ -3246,7 +3357,7 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
     }
   }
 #endif
-#if OCC_VERSION_LARGE > 0x06090000
+
 #ifndef DISABLE_OCCVIEWER
   if ( sec == QString( "OCCViewer" ) && param == QString( "stereo_type" ) )
   {
@@ -3383,7 +3494,7 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
     }
   }
 #endif
-#endif
+
   if ( sec == QString( "3DViewer" ) && param == QString( "zooming_mode" ) )
   {
     int mode = resMgr->integerValue( "3DViewer", "zooming_mode", 0 );
@@ -3672,10 +3783,15 @@ void LightApp_Application::preferencesChanged( const QString& sec, const QString
   }
   if ( sec == "desktop" && param == "opaque_resize" ) {
     bool opaqueResize = resMgr->booleanValue( "desktop", "opaque_resize", false );
-    QMainWindow::DockOptions dopts = desktop()->dockOptions();
-    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
-    else                dopts &= ~QMainWindow::AnimatedDocks;
-    desktop()->setDockOptions( dopts );
+    // RNV: This code has been commented, because clearing of the QMainWindow::AnimatedDocks option
+    //      leads to strange behaviour of the dockable windows (at least at qt-5.6.1):
+    //      any dockable window can't be docked to the another area, except initial area.
+    //      It is possible to move window to another area, but it always returns to the initial area.
+    //
+    //    QMainWindow::DockOptions dopts = desktop()->dockOptions();
+    //    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
+    //     else                dopts &= ~QMainWindow::AnimatedDocks;
+    //    desktop()->setDockOptions( dopts );
     desktop()->setOpaqueResize( opaqueResize );
     if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
       dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
@@ -3743,10 +3859,10 @@ void LightApp_Application::loadPreferences()
   if ( desktop() ) {
     desktop()->retrieveGeometry( aResMgr->stringValue( "desktop", "geometry" ) );
     bool opaqueResize = aResMgr->booleanValue( "desktop", "opaque_resize", false );
-    QMainWindow::DockOptions dopts = desktop()->dockOptions();
-    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
-    else                dopts &= ~QMainWindow::AnimatedDocks;
-    desktop()->setDockOptions( dopts );
+    //    QMainWindow::DockOptions dopts = desktop()->dockOptions();
+    //    if ( opaqueResize ) dopts |= QMainWindow::AnimatedDocks;
+    //    else                dopts &= ~QMainWindow::AnimatedDocks;
+    //    desktop()->setDockOptions( dopts );
     desktop()->setOpaqueResize( opaqueResize );
     if ( dynamic_cast<STD_TabDesktop*>( desktop() ) )
       dynamic_cast<STD_TabDesktop*>( desktop() )->workstack()->setOpaqueResize( opaqueResize );
@@ -3892,6 +4008,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.
@@ -4454,94 +4634,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
 */