X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSUITApp%2FSUITApp.cxx;h=c3b31f35dab4cf0b2bec03ce7520a26b08951739;hb=5015bf4f1283a8ca5d6ab862f235322755cb7be9;hp=9fefe90f0813d8f3328eb86481459a7b9b49311f;hpb=1c889394b028b786898a995d38c07c8f3d564837;p=modules%2Fgui.git diff --git a/src/SUITApp/SUITApp.cxx b/src/SUITApp/SUITApp.cxx index 9fefe90f0..c3b31f35d 100644 --- a/src/SUITApp/SUITApp.cxx +++ b/src/SUITApp/SUITApp.cxx @@ -1,55 +1,59 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#if defined WIN32 -#ifdef SUIT_ENABLE_PYTHON -#undef SUIT_ENABLE_PYTHON -#endif - -#else //#if defined WIN32 - -#ifndef SUIT_ENABLE_PYTHON +//#ifdefined WIN32 +//#ifndef DISABLE_PYCONSOLE +//#define DISABLE_PYCONSOLE +//#endif +//#else //#if defined WIN32 +//#ifdef DISABLE_PYCONSOLE // NOTE: DO NOT DELETE THIS DEFINITION ON LINUX // or make sure Python is initialized in main() in any case // Otherwise, application based on light SALOME and using Python // are unlikely to work properly. -#define SUIT_ENABLE_PYTHON -#include +//#undef DISABLE_PYCONSOLE +//#include +//#endif +// +#ifndef DISABLE_PYCONSOLE +#include "SUITApp_init_python.hxx" #endif -#endif //#if defined WIN32 +//#endif //#if defined WIN32 +#include "GUI_version.h" #include "SUITApp_Application.h" - -#include -#include -#include -#include -#include - -#include +#include "SUIT_Desktop.h" +#include "SUIT_LicenseDlg.h" +#include "SUIT_ResourceMgr.h" +#include "SUIT_Session.h" +#ifdef USE_SALOME_STYLE +#include "Style_Salome.h" +#endif // USE_SALOME_STYLE +#include "QtxSplash.h" #include #include +#include #include #include #include @@ -62,84 +66,44 @@ static QString salomeVersion() { - QString path( ::getenv( "GUI_ROOT_DIR" ) ); - if ( !path.isEmpty() ) - path += QDir::separator(); - - path += QString( "bin/salome/VERSION" ); - - QFile vf( path ); - if ( !vf.open( QFile::ReadOnly ) ) - return QString(); - - QString line = vf.readLine( 1024 ); - vf.close(); - - if ( line.isEmpty() ) - return QString(); - - while ( !line.isEmpty() && line.at( line.length() - 1 ) == QChar( '\n' ) ) - line.remove( line.length() - 1, 1 ); - - QString ver; - int idx = line.lastIndexOf( ":" ); - if ( idx != -1 ) - ver = line.mid( idx + 1 ).trimmed(); - - return ver; + return GUI_VERSION_STR; } -static void MessageOutput( QtMsgType type, const char* msg ) +static QString getAppName( const QString& libName ) { - switch ( type ) - { - case QtDebugMsg: -#ifdef _DEBUG_ - printf( "Debug: %s\n", msg ); -#endif - break; - case QtWarningMsg: -#ifdef _DEBUG_ - printf( "Warning: %s\n", msg ); -#endif - break; - case QtFatalMsg: -#ifdef _DEBUG_ - printf( "Fatal: %s\n", msg ); -#endif - break; - default: - break; - } + QString appName = QFileInfo( libName ).baseName(); + if ( appName.startsWith( "lib" ) ) appName = appName.mid( 3 ); + return appName; } -/* XPM */ -static const char* pixmap_not_found_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #A80000", -" ", -" ", -" . . ", -" .+. .+. ", -" .+++. .+++. ", -" .+++.+++. ", -" .+++++. ", -" .+++. ", -" .+++++. ", -" .+++.+++. ", -" .+++. .+++. ", -" .+. .+. ", -" . . ", -" ", -" ", -" "}; +// static void MessageOutput( QtMsgType type, const char* msg ) +// { +// switch ( type ) +// { +// case QtDebugMsg: +// #ifdef _DEBUG_ +// printf( "Debug: %s\n", msg ); +// #endif +// break; +// case QtWarningMsg: +// #ifdef _DEBUG_ +// printf( "Warning: %s\n", msg ); +// #endif +// break; +// case QtFatalMsg: +// #ifdef _DEBUG_ +// printf( "Fatal: %s\n", msg ); +// #endif +// break; +// default: +// break; +// } +// } class SUITApp_Session: public SUIT_Session { public: - SUITApp_Session( bool theIniFormat ) : SUIT_Session(), myIniFormat ( theIniFormat ) {} + SUITApp_Session( bool theIniFormat, int argc, char** argv ) : SUIT_Session( argc, argv ), myIniFormat ( theIniFormat ) {} virtual ~SUITApp_Session() {} virtual SUIT_ResourceMgr* createResourceMgr( const QString& appName ) const @@ -159,8 +123,6 @@ public: if ( resMgr ) { - static QPixmap defaultPixmap( pixmap_not_found_xpm ); - resMgr->setDefaultPixmap( defaultPixmap ); resMgr->setOption( "translators", QString( "%P_msg_%L.qm|%P_icons.qm|%P_images.qm" ) ); } return resMgr; @@ -172,15 +134,15 @@ private: int main( int argc, char* argv[] ) { -#ifdef SUIT_ENABLE_PYTHON - // First of all initialize Python, as in complex multi-component applications - // someone else might initialize it some way unsuitable for light SALOME! - Py_SetProgramName( argv[0] ); - Py_Initialize(); // Initialize the interpreter - PySys_SetArgv( argc, argv ); - PyEval_InitThreads(); // Create (and acquire) the interpreter lock - PyEval_ReleaseLock(); // Let the others use Python API until we need it again -#endif + //#ifndef DISABLE_PYCONSOLE + // // First of all initialize Python, as in complex multi-component applications + // // someone else might initialize it some way unsuitable for light SALOME! + // Py_SetProgramName( argv[0] ); + // Py_Initialize(); // Initialize the interpreter + // PySys_SetArgv( argc, argv ); + // PyEval_InitThreads(); // Create (and acquire) the interpreter lock + // PyEval_ReleaseLock(); // Let the others use Python API until we need it again + //#endif //qInstallMsgHandler( MessageOutput ); @@ -189,7 +151,7 @@ int main( int argc, char* argv[] ) bool iniFormat = false; bool noSplash = false; bool useLicense = false; - for ( int i = 1; i < argc /*&& !noExceptHandling*/; i++ ) + for ( int i = 1; i < argc; i++ ) { if ( !strcmp( argv[i], "--noexcepthandling" ) ) noExceptHandling = true; @@ -197,13 +159,57 @@ int main( int argc, char* argv[] ) iniFormat = true; else if ( !strcmp( argv[i], "--nosplash") ) noSplash = true; - else if ( !strcmp( argv[i], "--uselicense" ) ) + else if ( !strcmp( argv[i], "--uselicense" ) ) useLicense = true; - else + else argList.append( QString( argv[i] ) ); } + // set "C" locale if requested via preferences + { + SUITApp_Session stmp( iniFormat, argc, argv ); + QApplication::setApplicationName( "salome" ); + SUIT_ResourceMgr* resMgr = stmp.createResourceMgr( "LightApp" ); + bool isCloc = resMgr->booleanValue( "language", "locale", true ); + 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 + + // add /plugins directory to the pluins search path for image plugins + QString qtdir = Qtx::qtDir( "plugins" ); + if ( !qtdir.isEmpty() ) + QApplication::addLibraryPath( qtdir ); + +// 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 + SUITApp_Application app( argc, argv ); + QString cfgAppName = getAppName( argList.isEmpty() ? QString() : argList.first() ); + // hard-coding for LightApp :( no other way to this for the moment + if ( cfgAppName == "LightApp" ) { + app.setOrganizationName( "salome" ); + app.setApplicationName( "salome" ); + app.setApplicationVersion( salomeVersion() ); + } int result = -1; @@ -212,12 +218,17 @@ int main( int argc, char* argv[] ) #ifdef WIN32 DWORD aLen=1024; - char aStr[1024]; + TCHAR aStr[1024]; HANDLE aToken=0; HANDLE hProcess = GetCurrentProcess(); OpenProcessToken(hProcess,TOKEN_QUERY,&aToken); - if( GetUserProfileDirectory( aToken, aStr, &aLen ) ) - env = aStr; + if( GetUserProfileDirectory( aToken, aStr, &aLen ) ) { +#ifdef UNICODE + env = QString::fromWCharArray(aStr); +#else + env = aStr; +#endif + } #else if ( ::getenv( "HOME" ) ) @@ -234,57 +245,65 @@ int main( int argc, char* argv[] ) if ( !argList.isEmpty() ) { - SUITApp_Session* aSession = new SUITApp_Session( iniFormat ); + SUITApp_Session aSession( iniFormat, argc, argv ); QtxSplash* splash = 0; - SUIT_ResourceMgr* resMgr = aSession->createResourceMgr( argList.first() ); + SUIT_ResourceMgr* resMgr = aSession.createResourceMgr( argList.first() ); if ( !noSplash ) { if ( resMgr ) { - resMgr->loadLanguage( false ); - - splash = QtxSplash::splash( QPixmap() ); - splash->readSettings( resMgr ); - if ( splash->pixmap().isNull() ) { - delete splash; - splash = 0; - } - else { - QString appName = QObject::tr( "APP_NAME" ).trimmed(); - QString appVersion = QObject::tr( "APP_VERSION" ).trimmed(); - if ( appVersion == "APP_VERSION" ) - { - if ( appName == "APP_NAME" || appName.toLower() == "salome" ) - appVersion = salomeVersion(); - else - appVersion = ""; - } - splash->setOption( "%A", appName ); - splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) ); - splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) ); - splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) ); - splash->show(); - QApplication::instance()->processEvents(); - } + resMgr->loadLanguage(); + + splash = QtxSplash::splash( QPixmap() ); + splash->readSettings( resMgr ); + if ( splash->pixmap().isNull() ) { + delete splash; + splash = 0; + } + else { + QString appName = QObject::tr( "APP_NAME" ).trimmed(); + QString appVersion = QObject::tr( "APP_VERSION" ).trimmed(); + if ( appVersion == "APP_VERSION" ) + { + if ( appName == "APP_NAME" || appName.toLower() == "salome" ) + appVersion = salomeVersion(); + else + appVersion = ""; + } + splash->setOption( "%A", appName ); + splash->setOption( "%V", QObject::tr( "ABOUT_VERSION" ).arg( appVersion ) ); + splash->setOption( "%L", QObject::tr( "ABOUT_LICENSE" ) ); + splash->setOption( "%C", QObject::tr( "ABOUT_COPYRIGHT" ) ); + splash->show(); + QApplication::instance()->processEvents(); + } } } - SUIT_Application* theApp = aSession->startApplication( argList.first() ); +#ifndef DISABLE_PYCONSOLE + //...Initialize python + int _argc = 1; + char* _argv[] = {(char*)""}; + SUIT_PYTHON::init_python(_argc,_argv); +#endif + + SUIT_Application* theApp = aSession.startApplication( argList.first() ); if ( theApp ) { +#ifdef USE_SALOME_STYLE Style_Salome::initialize( theApp->resourceMgr() ); if ( theApp->resourceMgr()->booleanValue( "Style", "use_salome_style", true ) ) - Style_Salome::apply(); + Style_Salome::apply(); +#endif // USE_SALOME_STYLE if ( !noExceptHandling ) - app.setHandler( aSession->handler() ); + app.setHandler( aSession.handler() ); if ( splash ) - splash->finish( theApp->desktop() ); + splash->finish( theApp->desktop() ); result = app.exec(); } - delete aSession; } return result;