-// 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
// 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 <Basics_OCCTVersion.hxx>
-
-#include <Container_init_python.hxx>
#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>
#include "Session_Session_i.hxx"
#include <Qtx.h>
+#include <QtxMsgHandler.h>
#include <QtxSplash.h>
+#ifdef USE_SALOME_STYLE
#include <Style_Salome.h>
+#endif // USE_SALOME_STYLE
#include "GUI_version.h"
#include <SUIT_Tools.h>
#include CORBA_SERVER_HEADER(SALOME_Session)
#include CORBA_SERVER_HEADER(SALOMEDS)
+#ifdef WIN32
+#define sleep _sleep
+#endif
+
+#include <time.h>
+
#include <QDir>
#include <QFile>
#include <QApplication>
* - get session state
*/
-void MessageOutput( QtMsgType type, const char* msg )
+class SessionMsgHandler: public QtxMsgHandlerCallback
{
- switch ( type )
+public:
+ SessionMsgHandler() {}
+ void qtMessage(QtMsgType type, const QMessageLogContext& context, const QString& message)
{
- case QtDebugMsg:
- //MESSAGE( "Debug: " << msg );
- break;
- case QtWarningMsg:
- MESSAGE( "Warning: " << msg );
- break;
- case QtFatalMsg:
- MESSAGE( "Fatal: " << msg );
- break;
+ switch ( type )
+ {
+ case QtDebugMsg:
+#ifdef QT_DEBUG_MESSAGE
+ MESSAGE( "Debug: " << qPrintable( message ) );
+#endif
+ 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()
{
// for backward compatibility we also check files prepended with "." with lower priority
QRegExp exp( QString( "\\.?%1rc\\.([a-zA-Z0-9.]+)" ).arg( myExtAppName ) );
#endif
- QRegExp vers_exp( "^([0-9]+)([A-Z]|RC)?([0-9]*)", Qt::CaseInsensitive );
-
QString fname = QFileInfo( _fname ).fileName();
- if( exp.exactMatch( fname ) ) {
- QStringList vers = exp.cap( 1 ).split( ".", QString::SkipEmptyParts );
- int major=0, minor=0;
- int release = 0, dev1 = 0, dev2 = 0;
- if ( vers.count() > 0 ) major = vers[0].toInt();
- if ( vers.count() > 1 ) minor = vers[1].toInt();
- if ( vers.count() > 2 ) {
- if ( vers_exp.indexIn( vers[2] ) != -1 ) {
- release = vers_exp.cap( 1 ).toInt();
- QString tag = vers_exp.cap( 2 ).toLower();
- if ( !tag.isEmpty() ) {
- if ( tag == "rc" ) // release candidate
- dev1 = 49; // 'rc'=49
- else // a, b, c, ...
- dev1 = (int)( tag[ 0 ].toLatin1() ) - (int)( QChar('a').toLatin1() ) + 1; // 'a'=1, 'b'=2, ..., 'z'=26
- }
- if ( !vers_exp.cap( 3 ).isEmpty() )
- dev2 = vers_exp.cap( 3 ).toInt();
- }
- }
-
- int dev = dev1*100+dev2;
- id = major;
- id*=100; id+=minor;
- id*=100; id+=release;
- id*=10000;
- if ( dev > 0 ) id-=dev;
+ if ( exp.exactMatch( fname ) ) {
+ long fid = Qtx::versionToId( exp.cap( 1 ) );
+ if ( fid > 0 ) id = fid;
}
}
return id;
class SALOME_Session : public SUIT_Session
{
public:
- SALOME_Session() : SUIT_Session() {}
+ SALOME_Session( int argc, char** argv ) : SUIT_Session( argc, argv ) {}
virtual ~SALOME_Session() {}
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() ),
: QApplication( argc, argv ),
#endif
myHandler ( 0 ) {}
-#endif
virtual bool notify( QObject* receiver, QEvent* e )
{
-#if OCC_VERSION_LARGE < 0x06010100
- // Disable GUI user actions while python command is executed
- if (SUIT_Session::IsPythonExecuted()) {
- // Disable mouse and keyboard events
- QEvent::Type aType = e->type();
- if (aType == QEvent::MouseButtonPress || aType == QEvent::MouseButtonRelease ||
- aType == QEvent::MouseButtonDblClick || aType == QEvent::MouseMove ||
- aType == QEvent::Wheel || aType == QEvent::ContextMenu ||
- aType == QEvent::KeyPress || aType == QEvent::KeyRelease ||
- aType == QEvent::Accel || aType == QEvent::AccelOverride)
- return false;
- }
-#endif
-
-#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 );
+ QString debug_exceptions = ::getenv("SALOME_DEBUG_EXCEPTIONS");
+ if ( debug_exceptions.length() > 0 ) {
+ return 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;
+ 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
-#endif
}
SUIT_ExceptionHandler* handler() const { return myHandler; }
void setHandler( SUIT_ExceptionHandler* h ) { myHandler = h; }
int main( int argc, char **argv )
{
// Install Qt debug messages handler
- qInstallMsgHandler( MessageOutput );
+ 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)
//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"));
}
-
- // add $QTDIR/plugins to the pluins search path for image plugins
- QString qtdir( ::getenv( "QTDIR" ) );
- if ( !qtdir.isEmpty() )
- QApplication::addLibraryPath( QDir( qtdir ).absoluteFilePath( "plugins" ) );
+#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 s;
+ SALOME_Session stmp( argc, argv );
QApplication::setApplicationName( "salome" );
- SUIT_ResourceMgr* resMgr = s.createResourceMgr( "SalomeApp" );
+ SUIT_ResourceMgr* resMgr = stmp.createResourceMgr( "SalomeApp" );
bool isCloc = resMgr->booleanValue( "language", "locale", true );
- if ( isCloc ) {
+ if ( isCloc ) {
QLocale::setDefault( QLocale::c() );
}
else {
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!
_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 );
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
- aGUISession = new SALOME_Session();
+ aGUISession = new SALOME_Session( argc, argv );
// Load SalomeApp dynamic library
MESSAGE( "creation SUIT_Application" );
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
}
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
abort(); //abort program to avoid deadlock in destructors or atexit when shutdown has been interrupted
}
- PyGILState_Ensure();
- //Destroy orb from python (for chasing memory leaks)
+ //Destroy orb from python (for chasing memory leaks)
//PyRun_SimpleString("from omniORB import CORBA");
//PyRun_SimpleString("orb=CORBA.ORB_init([''], CORBA.ORB_ID)");
//PyRun_SimpleString("orb.destroy()");
- Py_Finalize();
+
+ // Destroy the ORB:
+ sleep(2);
+ //std::cout << "@@@@@ Explicitely destroying the ORB (hoping to kill omniORB threads ...)\n";
+ ORB_INIT * init = SINGLETON_<ORB_INIT>::Instance();
+ if (init)
+ init->explicit_destroy();
+ //std::cout << "@@@@@ ORB destroyed\n";
+
+ // After ORB destruction
+ if(Py_IsInitialized())
+ {
+ PyGILState_Ensure();
+ //std::cout << "@@@@@ About to PyFinalize\n";
+ Py_Finalize();
+ //std::cout << "@@@@@ DONE PyFinalize\n";
+ }
if ( shutdownAll )
- killOmniNames();
+ {
+ //std::cout << "@@@@@ About to kill omni\n";
+ killOmniNames();
+ //std::cout << "@@@@@ DONE kill omni\n";
+ }
MESSAGE( "Salome_Session_Server:endofserver" );
return result;