Salome HOME
Merge branch 'V9_2_BR'
[modules/gui.git] / src / Session / SALOME_Session_Server.cxx
index ea144e9a96cb5e33c8361aa04a21094603f751d3..7e1c32f05a40fbab8db4e6a250019330fb5ff553 100755 (executable)
 //  Author : Paul RASCLE, EDF
 //  Module : SALOME
 
+#include <Container_init_python.hxx>
 #include <SALOME_NamingService.hxx>
 #include <SALOME_ModuleCatalog_impl.hxx>
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOME_Event.h>
 
-#include <Container_init_python.hxx>
 #include <ConnectionManager_i.hxx>
 #include <RegistryService.hxx>
 
@@ -46,6 +46,7 @@
 #include "Session_Session_i.hxx"
 
 #include <Qtx.h>
+#include <QtxMsgHandler.h>
 #include <QtxSplash.h>
 
 #ifdef USE_SALOME_STYLE
@@ -77,9 +78,6 @@
 #include <QWaitCondition>
 #include <QRegExp>
 #include <QTextStream>
-#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
-#include <QSurfaceFormat>
-#endif
 
 /*! - read arguments, define list of server to launch with their arguments.
  * - wait for naming service
  * - 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
+
+class SessionMsgHandler: public QtxMsgHandlerCallback
 {
-  switch ( type )
+public:
+  SessionMsgHandler() {}
+  void qtMessage(QtMsgType type, const QMessageLogContext& context, const QString& message)
   {
-  case QtDebugMsg:
+    switch ( type )
+    {
+    case QtDebugMsg:
 #ifdef QT_DEBUG_MESSAGE
-    MESSAGE( "Debug: " << qPrintable( QString(msg) ) );
+      MESSAGE( "Debug: " << qPrintable( message ) );
 #endif
-    break;
-  case QtWarningMsg:
-    MESSAGE( "Warning: " << qPrintable( QString(msg) ) );
-    break;
-  case QtFatalMsg:
-    MESSAGE( "Fatal: " << qPrintable( QString(msg) ) );
-    break;
+      break;
+    case QtWarningMsg:
+      MESSAGE( "Warning: " << qPrintable( message ) );
+      break;
+    case QtCriticalMsg:
+      MESSAGE( "Critical: " << qPrintable( message ) );
+      break;
+    case QtFatalMsg:
+      MESSAGE( "Fatal: " << qPrintable( message ) );
+      break;
+    case QtInfoMsg:
+    default:
+      MESSAGE( "Information: " << qPrintable( message ) );
+      break;
+    }
   }
-}
+};
 
 QString salomeVersion()
 {
@@ -262,25 +269,30 @@ public:
 
   virtual bool notify( QObject* receiver, QEvent* e )
   {
-
-    try {
-      return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
-    }
-    catch (std::exception& e) {
-      std::cerr << e.what()  << std::endl;
+    QString debug_exceptions = ::getenv("SALOME_DEBUG_EXCEPTIONS");
+    if ( debug_exceptions.length() > 0 ) {
+      return QApplication::notify( receiver, e );
     }
-    catch (CORBA::Exception& e) {
-      std::cerr << "Caught CORBA::Exception"  << std::endl;
-      CORBA::Any tmp;
-      tmp<<= e;
-      CORBA::TypeCode_var tc = tmp.type();
-      const char *p = tc->name();
-      std::cerr << "notify(): CORBA exception of the kind : " << p << " is caught" << std::endl;
-    }
-    catch (...) {
-      std::cerr << "Unknown exception caught in Qt handler: it's probably a bug in SALOME platform" << std::endl;
+    else {
+      try {
+        return myHandler ? myHandler->handle( receiver, e ) : QApplication::notify( receiver, e );
+      }
+      catch (std::exception& e) {
+        std::cerr << e.what()  << std::endl;
+      }
+      catch (CORBA::Exception& e) {
+        std::cerr << "Caught CORBA::Exception"  << std::endl;
+        CORBA::Any tmp;
+        tmp<<= e;
+        CORBA::TypeCode_var tc = tmp.type();
+        const char *p = tc->name();
+        std::cerr << "notify(): CORBA exception of the kind : " << p << " is caught" << std::endl;
+      }
+      catch (...) {
+        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
     }
-    return false;  // return false when exception is caught
   }
   SUIT_ExceptionHandler* handler() const { return myHandler; }
   void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
@@ -335,11 +347,8 @@ 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
+  SessionMsgHandler msgHandler;
+  qInstallMessageHandler(QtxMsgHandler);
 
 // TODO (QT5 PORTING) Below is a temporary solution, to allow compiling with Qt 5
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
@@ -371,12 +380,13 @@ int main( int argc, char **argv )
   }
   
 #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
-  // initialization of the X11 visual on Linux
-  QSurfaceFormat format;
-  format.setDepthBufferSize(16);
-  format.setStencilBufferSize(1);
-  format.setProfile(QSurfaceFormat::CompatibilityProfile);
-  QSurfaceFormat::setDefaultFormat(format);
+
+  // 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;