Salome HOME
Redesign SALOME documentation: update link to youtube channel
[modules/gui.git] / src / Session / SALOME_Session_Server.cxx
index 7e1fbe5f44136516d910becbff68af9472bdeaf8..241423b8f0282d5cdb85371b26a6aaf63bdf1aa9 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  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
 #include <ConnectionManager_i.hxx>
 #include <RegistryService.hxx>
 
-#ifdef ENABLE_TESTRECORDER
-  #include <TestApplication.h>
-#endif
-
 #include <OpUtil.hxx>
 #include <Utils_ORB_INIT.hxx>
 #include <Utils_SINGLETON.hxx>
@@ -52,7 +48,9 @@
 #include <Qtx.h>
 #include <QtxSplash.h>
 
+#ifdef USE_SALOME_STYLE
 #include <Style_Salome.h>
+#endif // USE_SALOME_STYLE
 
 #include "GUI_version.h"
 #include <SUIT_Tools.h>
  * - stop Session ( must be idle )
  * - get session state
  */
-
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 void MessageOutput( QtMsgType type, const char* msg )
+#else
+void MessageOutput( QtMsgType type, const QMessageLogContext &context, const QString &msg )
+#endif
 {
   switch ( type )
   {
   case QtDebugMsg:
-    //MESSAGE( "Debug: " << msg );
+#ifdef QT_DEBUG_MESSAGE
+    MESSAGE( "Debug: " << qPrintable( QString(msg) ) );
+#endif
     break;
   case QtWarningMsg:
-    MESSAGE( "Warning: " << msg );
+    MESSAGE( "Warning: " << qPrintable( QString(msg) ) );
     break;
   case QtFatalMsg:
-    MESSAGE( "Fatal: " << msg );
+    MESSAGE( "Fatal: " << qPrintable( QString(msg) ) );
     break;
   }
 }
@@ -210,8 +213,8 @@ protected:
 #endif
       QString fname = QFileInfo( _fname ).fileName();
       if ( exp.exactMatch( fname ) ) {
-       long fid = Qtx::versionToId( exp.cap( 1 ) );
-       if ( fid > 0 ) id = fid;
+        long fid = Qtx::versionToId( exp.cap( 1 ) );
+        if ( fid > 0 ) id = fid;
       }
     }
     return id;
@@ -240,18 +243,12 @@ public:
   }
 };
 
-#ifdef ENABLE_TESTRECORDER
-  class SALOME_QApplication : public TestApplication
-#else
-  class SALOME_QApplication : public QApplication
-#endif
+class SALOME_QApplication : public QApplication
 {
 public:
-#ifdef ENABLE_TESTRECORDER
-  SALOME_QApplication( int& argc, char** argv ) : TestApplication( argc, argv ), myHandler ( 0 ) {}
-#else
   SALOME_QApplication( int& argc, char** argv )
-#ifndef WIN32
+// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
+#if !defined(WIN32) && !defined(__APPLE__) && (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
   // san: Opening an X display and choosing a visual most suitable for 3D visualization
   // in order to make SALOME viewers work with non-native X servers
   : QApplication( (Display*)Qtx::getDisplay(), argc, argv, Qtx::getVisual() ),
@@ -259,15 +256,10 @@ public:
   : QApplication( argc, argv ), 
 #endif
     myHandler ( 0 ) {}
-#endif
 
   virtual bool notify( QObject* receiver, QEvent* e )
   {
 
-#ifdef ENABLE_TESTRECORDER
-    return myHandler ? myHandler->handle( receiver, e ) :
-      TestApplication::notify( receiver, e );
-#else
     try {
       return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
     }
@@ -286,7 +278,6 @@ public:
       std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl;
     }
     return false;  // return false when exception is caught
-#endif
   }
   SUIT_ExceptionHandler* handler() const { return myHandler; }
   void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
@@ -341,20 +332,27 @@ void shutdownServers( SALOME_NamingService* theNS )
 int main( int argc, char **argv )
 {
   // Install Qt debug messages handler
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
   qInstallMsgHandler( MessageOutput );
+#else
+  qInstallMessageHandler( MessageOutput );
+#endif
 
+// TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
+#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
   //Set a "native" graphic system in case if application runs on the remote host
   QString remote(getenv("REMOTEHOST"));
   QString client(getenv("SSH_CLIENT"));
   if(remote.length() > 0 || client.length() > 0 ) {
     QApplication::setGraphicsSystem(QLatin1String("native"));
   }
-  
+#endif
+
   // add <qtdir>/plugins dir to the pluins search path for image plugins
   QString qtdir = Qtx::qtDir( "plugins" );
   if ( !qtdir.isEmpty() )
     QApplication::addLibraryPath( qtdir );
-
+  
   // set "C" locale if requested via preferences
   {
     SALOME_Session stmp( argc, argv );
@@ -368,6 +366,16 @@ int main( int argc, char **argv )
       QLocale::setDefault( QLocale::system() );
     }
   }
+  
+#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
+
+  // RNV: setup the default format:
+  // QSurfaceFormat should be set before creation of QApplication,  
+  // so to avoid conflicts beetween SALOME and ParaView QSurfaceFormats we should merge theirs formats
+  // (see void Qtx::initDefaultSurfaceFormat()) and set the resultant format here.
+  Qtx::initDefaultSurfaceFormat(); 
+
+#endif
 
   // Create Qt application instance;
   // this should be done the very first!
@@ -377,7 +385,7 @@ int main( int argc, char **argv )
   _qappl.setApplicationVersion( salomeVersion() );
 
   // Add application library path (to search style plugin etc...)
-  QString path = QDir::convertSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) );
+  QString path = QDir::toNativeSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) );
   _qappl.addLibraryPath( path );
 
   bool isGUI    = isFound( "GUI",    argc, argv );
@@ -552,8 +560,8 @@ int main( int argc, char **argv )
       SALOME::StatSession stat = session->GetStatSession();
       shutdownSession = stat.state == SALOME::shutdown;
       if ( shutdownSession ) {
-       _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
-       break;
+        _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later
+        break;
       }
 
       // SUIT_Session creation
@@ -564,9 +572,11 @@ int main( int argc, char **argv )
       SUIT_Application* aGUIApp = aGUISession->startApplication( "SalomeApp", 0, 0 );
       if ( aGUIApp )
       {
+#ifdef USE_SALOME_STYLE
         Style_Salome::initialize( aGUIApp->resourceMgr() );
         if ( aGUIApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) )
           Style_Salome::apply();
+#endif // USE_SALOME_STYLE
 
         if ( !isFound( "noexcepthandler", argc, argv ) )
           _qappl.setHandler( aGUISession->handler() ); // after loading SalomeApp application
@@ -589,10 +599,15 @@ int main( int argc, char **argv )
         }
         else {
           // desktop might be closed from:
-          // - StopSesion() /temporarily/ or
-          // - Shutdown() /permanently/
+          // - StopSesion() (temporarily) or
+          // - Shutdown() (permanently)
           stat = session->GetStatSession();
           shutdownSession = stat.state == SALOME::shutdown;
+          // normally "shutdown standalone servers" flag should be false here, if we come from
+          // StopSesion() or from Shutdown();
+          // but we also have to check if somebody explicitly programmatically closed session,
+          // asking to kill servers also
+          shutdownAll = aGUISession->exitFlags();
         }
         if ( shutdownAll || shutdownSession ) {
           _SessionMutex.lock(); // lock mutex before leaving loop - it will be unlocked later