From: rnv Date: Thu, 21 Feb 2019 08:46:02 +0000 (+0300) Subject: Run SALOME with UNICODE path. X-Git-Tag: V9_3_0b1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c52efafc8ece99fbf8b2d1b541dcaf53c3ee7d9c;p=modules%2Fgui.git Run SALOME with UNICODE path. --- diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index e402bf849..8fabfd1dd 100644 --- a/src/GLViewer/GLViewer_Widget.cxx +++ b/src/GLViewer/GLViewer_Widget.cxx @@ -265,7 +265,7 @@ void GLViewer_Widget::initializeGL() //get image QImage buf; - QString aPicturePath = getenv("GLViewer__Background_Picture"); + QString aPicturePath = Qtx::getenv("GLViewer__Background_Picture"); if ( !aPicturePath.isEmpty() && buf.load( aPicturePath ) ) { // Load first image from file diff --git a/src/HelpBrowser/CMakeLists.txt b/src/HelpBrowser/CMakeLists.txt index d17f18cfd..ca8d71c26 100644 --- a/src/HelpBrowser/CMakeLists.txt +++ b/src/HelpBrowser/CMakeLists.txt @@ -79,3 +79,4 @@ SET(HelpBrowser_SOURCES ADD_EXECUTABLE(HelpBrowser ${HelpBrowser_SOURCES}) TARGET_LINK_LIBRARIES(HelpBrowser ${_link_LIBRARIES}) INSTALL(TARGETS HelpBrowser EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS}) +INSTALL(FILES qt.conf DESTINATION ${SALOME_INSTALL_BINS}) diff --git a/src/HelpBrowser/HelpBrowser.cxx b/src/HelpBrowser/HelpBrowser.cxx index e737aa029..72023e1f6 100644 --- a/src/HelpBrowser/HelpBrowser.cxx +++ b/src/HelpBrowser/HelpBrowser.cxx @@ -40,6 +40,11 @@ #include +#ifdef WIN32 +#include +#endif + + namespace { void printHelp() @@ -152,6 +157,16 @@ int main( int argc, char **argv ) } } +#if defined(WIN32) && defined(UNICODE) + LPWSTR *szArglist = NULL; + int nArgs; + int i; + szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); + helpfile = QString::fromWCharArray(szArglist[nArgs-1]); + // Free memory allocated for CommandLineToArgvW arguments. + LocalFree(szArglist); +#endif + // Show help and exit if '--help' or '-h' option has been specified via command line if ( showHelp ) { @@ -262,7 +277,7 @@ int main( int argc, char **argv ) // Load file specified via command line if ( helpfile.isEmpty() ) { - QString docdir = qgetenv( "DOCUMENTATION_ROOT_DIR" ); + QString docdir = Qtx::getenv( "DOCUMENTATION_ROOT_DIR" ); if ( !docdir.isEmpty() ) helpfile = QDir::toNativeSeparators( QString( "%1/index.html" ).arg( docdir ) ); } diff --git a/src/HelpBrowser/HelpBrowser.qrc b/src/HelpBrowser/HelpBrowser.qrc index 6fde55835..d5aca3371 100644 --- a/src/HelpBrowser/HelpBrowser.qrc +++ b/src/HelpBrowser/HelpBrowser.qrc @@ -1,6 +1,5 @@ COPYING - qt.conf diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 106f4c04d..c084037b2 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -659,7 +659,7 @@ void LightApp_Application::createActions() QString modName = moduleName( aModule ); // module name if ( modName.isEmpty() ) modName = aModule; // for KERNEL and GUI QString rootDir = QString( "%1_ROOT_DIR" ).arg( modName ); // module root dir env variable - QString modDir = getenv( rootDir.toUtf8().constData() ); // module root dir path + QString modDir = Qtx::getenv( rootDir.toUtf8().constData() ); // module root dir path QString docSection; if (resMgr->hasValue( modName, "documentation" ) ) docSection = resMgr->stringValue(modName, "documentation"); @@ -1283,7 +1283,7 @@ void LightApp_Application::onHelpContextModule( const QString& component, QFileInfo fi( url ); if ( fi.isRelative() && !component.isEmpty() ) { - QString rootDir = getenv( (component + "_ROOT_DIR").toLatin1().constData() ); + QString rootDir = Qtx::getenv( (component + "_ROOT_DIR").toLatin1().constData() ); if ( !rootDir.isEmpty() ) { path = (QStringList() << rootDir << "share" << "doc" << "salome" << "gui" << component << url).join( QDir::separator() ); @@ -3969,11 +3969,11 @@ bool LightApp_Application::checkModule( const QString& title ) QStringList paths; #if defined(WIN32) - paths = QString( ::getenv( "PATH" ) ).split( ";", QString::SkipEmptyParts ); + paths = QString( Qtx::getenv( "PATH" ) ).split( ";", QString::SkipEmptyParts ); #elif defined(__APPLE__) - paths = QString( ::getenv( "DYLD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); + paths = QString( Qtx::getenv( "DYLD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); #else - paths = QString( ::getenv( "LD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); + paths = QString( Qtx::getenv( "LD_LIBRARY_PATH" ) ).split( ":", QString::SkipEmptyParts ); #endif bool isFound = false; diff --git a/src/LightApp/LightApp_Driver.cxx b/src/LightApp/LightApp_Driver.cxx index 7b8d79807..fe8fc099d 100644 --- a/src/LightApp/LightApp_Driver.cxx +++ b/src/LightApp/LightApp_Driver.cxx @@ -33,6 +33,8 @@ #include #include +#include + #ifdef WIN32 #include #endif diff --git a/src/PVViewer/PVViewer_Core.cxx b/src/PVViewer/PVViewer_Core.cxx index e629e392b..e59820f0d 100644 --- a/src/PVViewer/PVViewer_Core.cxx +++ b/src/PVViewer/PVViewer_Core.cxx @@ -25,6 +25,8 @@ #include "PVViewer_Behaviors.h" #include "PVViewer_Core.h" +#include + #include #include #include @@ -64,7 +66,7 @@ bool PVViewer_Core::ParaviewInitApp(QMainWindow * aDesktop) // Obtain command-line arguments int argc = 0; char** argv = 0; - QString aOptions = getenv("PARAVIEW_OPTIONS"); + QString aOptions = Qtx::getenv("PARAVIEW_OPTIONS"); QStringList aOptList = aOptions.split(":", QString::SkipEmptyParts); argv = new char*[aOptList.size() + 4]; // add one, MPI requires argv[argc] = 0! for (int i =0; i< aOptList.size() + 4; i++) diff --git a/src/PVViewer/PVViewer_ViewManager.cxx b/src/PVViewer/PVViewer_ViewManager.cxx index d4a7a1953..a9b283ceb 100644 --- a/src/PVViewer/PVViewer_ViewManager.cxx +++ b/src/PVViewer/PVViewer_ViewManager.cxx @@ -95,7 +95,7 @@ bool PVViewer_ViewManager::ConnectToExternalPVServer(QMainWindow* desktop) std::stringstream msg; // Try to connect to the external PVServer - gives priority to an externally specified URL: - QString serverUrlEnv = getenv("PARAVIEW_PVSERVER_URL"); + QString serverUrlEnv = Qtx::getenv("PARAVIEW_PVSERVER_URL"); std::string serverUrl; if (!serverUrlEnv.isEmpty()) { diff --git a/src/Qtx/Qtx.cxx b/src/Qtx/Qtx.cxx index 2cfdeca70..30fda906e 100644 --- a/src/Qtx/Qtx.cxx +++ b/src/Qtx/Qtx.cxx @@ -47,6 +47,13 @@ #include #include +#ifdef WIN32 +#include +#define MAX_VALUE_SIZE 32767 // Limit according to http://msdn.microsoft.com/en-us/library/ms683188.aspx +#endif + +#include + #define BICOLOR_CHANGE_HUE /*! @@ -484,18 +491,18 @@ QString Qtx::library( const QString& str ) */ QString Qtx::tmpDir() { - const char* tmpdir = ::getenv( "TEMP" ); - if ( !tmpdir ) - tmpdir = ::getenv ( "TMP" ); - if ( !tmpdir ) + QString tmpdir = getenv( "TEMP" ); + if ( tmpdir.isEmpty() ) + tmpdir = getenv ( "TMP" ); + if ( tmpdir.isEmpty() ) { #ifdef WIN32 - tmpdir = "C:\\"; + tmpdir = QString("C:\\"); #else - tmpdir = "/tmp"; + tmpdir = QString("/tmp"); #endif } - return QString( tmpdir ); + return tmpdir; } /*! @@ -746,8 +753,8 @@ QString Qtx::makeEnvVarSubst( const QString& str, const SubstMode mode ) break; QString newStr; - if ( ::getenv( envName.toUtf8() ) || mode == Always ) - newStr = QString( ::getenv( envName.toUtf8() ) ); + if ( getenv( envName ).isEmpty() || mode == Always ) + newStr = QString( getenv( envName ) ); if ( newStr.isNull() ) { @@ -2113,10 +2120,12 @@ long Qtx::versionToId( const QString& version ) QString Qtx::qtDir( const QString& context ) { - const char* vars[] = { "QT5_ROOT_DIR", "QT4_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" }; + + QStringList vars = { "QT5_ROOT_DIR", "QT4_ROOT_DIR", "QT_ROOT_DIR", "QTDIR" }; QString qtPath; - for (uint i = 0; i < sizeof(vars)/sizeof(vars[0]) && qtPath.isEmpty(); i++ ) - qtPath = qgetenv( vars[i] ); + for (uint i = 0; i < vars.length() && qtPath.isEmpty(); i++ ) { + qtPath = getenv(vars[i]); + } if ( !qtPath.isEmpty() && !context.isEmpty() ) qtPath = QDir( qtPath ).absoluteFilePath( context ); return qtPath; @@ -2133,6 +2142,36 @@ QFont Qtx::stringToFont( const QString& fontDescription ) return font; } +QString Qtx::getenv(const QString & envVar) +{ + QString value; +#ifndef WIN32 + value = qgetenv(envVar.toLocal8Bit().constData()); +#else + LPTSTR buff = new TCHAR[MAX_VALUE_SIZE]; +#ifdef UNICODE + LPTSTR anEnvVar = new TCHAR[envVar.length() + 1]; + anEnvVar[envVar.toWCharArray(anEnvVar)] = '\0'; +#else + const TCHAR* anEnvVar = envVar.toLocal8Bit(buff).constData(); +#endif + const DWORD ret = GetEnvironmentVariable(anEnvVar, buff, MAX_VALUE_SIZE); + buff[ret] = '\0'; + if (ret > 0) { +#ifdef UNICODE + value = QString::fromWCharArray(buff); +#else + value = QString::fromLocal8Bit(buff); +#endif + } + delete buff; +#ifdef UNICODE + delete anEnvVar; +#endif +#endif + return value; +} + #if !defined WIN32 && !defined __APPLE__ #include diff --git a/src/Qtx/Qtx.h b/src/Qtx/Qtx.h index b0d108149..25d4010c8 100644 --- a/src/Qtx/Qtx.h +++ b/src/Qtx/Qtx.h @@ -279,6 +279,8 @@ public: static QFont stringToFont( const QString& fontDescription ); + static QString getenv( const QString& envVar ); + #ifndef WIN32 static void* getDisplay(); static Qt::HANDLE getVisual(); diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index a88923ad2..4fa61bf0f 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -462,8 +462,9 @@ QString QtxResourceMgr::Resources::makeSubstitution( const QString& str, const Q QString newStr = constants.value( envName, QString() ); // Then we check for environment variable - if ( newStr.isEmpty() && ::getenv( envName.toLatin1() ) ) - newStr = QString( ::getenv( envName.toLatin1() ) ); + QString tmpValue = Qtx::getenv( envName ); + if ( newStr.isEmpty() && !tmpValue.isEmpty() ) + newStr = tmpValue; if ( newStr.isEmpty() ) { @@ -1251,8 +1252,9 @@ QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTem envVar = envVar.arg( appName ); QString dirs; - if ( ::getenv( envVar.toLatin1() ) ) - dirs = ::getenv( envVar.toLatin1() ); + QString tmpValue = Qtx::getenv( envVar ); + if ( !tmpValue.isEmpty() ) + dirs = tmpValue; #ifdef WIN32 QString dirsep = ";"; // for Windows: ";" is used as directories separator #else diff --git a/src/SUIT/SUIT_LicenseDlg.cxx b/src/SUIT/SUIT_LicenseDlg.cxx index 166dd66c9..efd266adc 100644 --- a/src/SUIT/SUIT_LicenseDlg.cxx +++ b/src/SUIT/SUIT_LicenseDlg.cxx @@ -32,6 +32,8 @@ #include +#include + #ifdef WIN32 #include #endif @@ -47,10 +49,7 @@ SUIT_LicenseDlg::SUIT_LicenseDlg( bool firstShow, QWidget* parent, const char* n { setObjectName( name ); setModal( modal ); - QString env; - if ( ::getenv( "SALOME_LICENSE_FILE" ) ) - env = ::getenv( "SALOME_LICENSE_FILE" ); - + QString env = Qtx::getenv( "SALOME_LICENSE_FILE" ); QFile file( env ); // Read the text from a file if ( !file.exists() || !file.open( QIODevice::ReadOnly ) ) diff --git a/src/SVTK/SVTK_RecorderDlg.cxx b/src/SVTK/SVTK_RecorderDlg.cxx index d01dbe362..b8816ad77 100644 --- a/src/SVTK/SVTK_RecorderDlg.cxx +++ b/src/SVTK/SVTK_RecorderDlg.cxx @@ -25,6 +25,8 @@ #include #include +#include + #include #include @@ -173,7 +175,7 @@ bool SVTK_RecorderDlg::onBrowseFile() aFilter.append( tr( "FLT_AVI_FILES" ) ); aFilter.append( tr( "FLT_ALL_FILES" ) ); - QString aFileName = SUIT_FileDlg::getFileName( this, getenv( "HOME" ), aFilter, + QString aFileName = SUIT_FileDlg::getFileName( this, Qtx::getenv( "HOME" ), aFilter, tr( "FILE_NAME" ), false ); if( aFileName.isNull() ) diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 82481ceaf..a8e0b7e8b 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -67,6 +67,9 @@ #ifdef WIN32 #define sleep _sleep +#include +#include +#include #endif #include @@ -79,6 +82,8 @@ #include #include +#include + /*! - read arguments, define list of server to launch with their arguments. * - wait for naming service * - create and run a thread for launch of all servers @@ -397,7 +402,7 @@ int main( int argc, char **argv ) _qappl.setApplicationVersion( salomeVersion() ); // Add application library path (to search style plugin etc...) - QString path = QDir::toNativeSeparators( SUIT_Tools::addSlash( QString( ::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) ); + QString path = QDir::toNativeSeparators( SUIT_Tools::addSlash( QString( Qtx::getenv( "GUI_ROOT_DIR" ) ) ) + QString( "bin/salome" ) ); _qappl.addLibraryPath( path ); bool isGUI = isFound( "GUI", argc, argv ); @@ -442,7 +447,9 @@ int main( int argc, char **argv ) SALOME_NamingService* _NS = 0; GetInterfaceThread* guiThread = 0; Session_ServerLauncher* myServerLauncher = 0; - +#if defined(WIN32) && defined(UNICODE) + char** new_argv = NULL; +#endif try { // ...initialize Python (only once) int _argc = 1; @@ -499,7 +506,21 @@ int main( int argc, char **argv ) // ...lock mutex to block embedded servers launching thread until wait( mutex ) _GUIMutex.lock(); // ...create launcher +#if defined(WIN32) && defined(UNICODE) + LPWSTR *szArglist = NULL; + int nArgs; + int i; + szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); + new_argv = new char*[nArgs]; + for (i = 0; i < nArgs; i++) { + new_argv[i] = (char*) Kernel_Utils::utf8_encode(szArglist[i]); + } + // Free memory allocated for CommandLineToArgvW arguments. + LocalFree(szArglist); + myServerLauncher = new Session_ServerLauncher(nArgs, new_argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted); +#else myServerLauncher = new Session_ServerLauncher( argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch, &_SessionMutex, &_SessionStarted ); +#endif // ...block this thread until launcher is ready _ServerLaunch.wait( &_GUIMutex ); @@ -656,6 +677,9 @@ int main( int argc, char **argv ) delete guiThread; delete myServerLauncher; delete _NS; +#if defined(WIN32) && defined(UNICODE) + delete[] new_argv; +#endif try { orb->shutdown(0); diff --git a/src/Style/Style_ResourceMgr.cxx b/src/Style/Style_ResourceMgr.cxx index 54480c066..8ef1f897c 100644 --- a/src/Style/Style_ResourceMgr.cxx +++ b/src/Style/Style_ResourceMgr.cxx @@ -43,8 +43,9 @@ Style_ResourceMgr::Style_ResourceMgr() : QtxResourceMgr( "SalomeStyle", "%1Config" ) { - if ( dirList().isEmpty() && ::getenv( "GUI_ROOT_DIR" ) ) - setDirList( QStringList() << Qtx::addSlash( ::getenv( "GUI_ROOT_DIR" ) ) + "share/salome/resources/gui" ); + QString gui_root = Qtx::getenv( "GUI_ROOT_DIR" ); + if ( dirList().isEmpty() && !gui_root.isEmpty() ) + setDirList( QStringList() << Qtx::addSlash( gui_root ) + "share/salome/resources/gui" ); setCurrentFormat( "xml" ); } diff --git a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx index 615a94537..fa216da4e 100644 --- a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx +++ b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx @@ -43,6 +43,8 @@ #include #include +#include + #include #include #include @@ -399,8 +401,9 @@ void ToolsGUI_CatalogGeneratorDlg::onApply() } else { QString command = ""; - if ( getenv("KERNEL_ROOT_DIR") ) - command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile; + QString kernel_root = Qtx::getenv("KERNEL_ROOT_DIR"); + if ( !kernel_root.isEmpty() ) + command = kernel_root + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile; else { SUIT_MessageBox::critical( this, tr("TOOLS_ERR_ERROR"), diff --git a/src/VTKViewer/VTKViewer_OpenGLHelper.cxx b/src/VTKViewer/VTKViewer_OpenGLHelper.cxx index dec97b0ee..fe9ae203a 100644 --- a/src/VTKViewer/VTKViewer_OpenGLHelper.cxx +++ b/src/VTKViewer/VTKViewer_OpenGLHelper.cxx @@ -22,6 +22,7 @@ #include "VTKViewer_OpenGLHelper.h" +#include #ifndef WIN32 # ifndef GLX_GLXEXT_LEGACY @@ -219,8 +220,12 @@ namespace GUI_OPENGL { char* readFromFile( std::string fileName ) { +#if defined(WIN32) && defined(UNICODE) + const wchar_t* wFileName = Kernel_Utils::utf8_decode( fileName.c_str() ); + FILE* file = _wfopen( wFileName, L"r" ); +#else FILE* file = fopen( fileName.c_str(), "r" ); - +#endif char* content = NULL; int count = 0; diff --git a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx index a704c0d63..885e73a6c 100644 --- a/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx +++ b/src/VTKViewer/VTKViewer_OpenGLRenderer.cxx @@ -41,6 +41,8 @@ #include #include +#include + vtkStandardNewMacro(VTKViewer_OpenGLRenderer); VTKViewer_OpenGLRenderer::VTKViewer_OpenGLRenderer() @@ -74,7 +76,13 @@ void VTKViewer_OpenGLRenderer::Clear(void) { if (this->BackgroundProgram == 0) { - std::string filePath = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Background"; +#if defined(WIN32) && defined(UNICODE) + std::wstring wFilePath = std::wstring( _wgetenv(L"GUI_ROOT_DIR") ) + L"/share/salome/resources/gui/Background"; + std::string filePath = Kernel_Utils::utf8_encode_s( wFilePath ); +#else + std::string filePath = std::string(getenv("GUI_ROOT_DIR")) + "/share/salome/resources/gui/Background"; +#endif + if (!this->OpenGLHelper.CreateShaderProgram (filePath, this->BackgroundProgram, this->BackgroundVertexShader, diff --git a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx index 1e91624cb..959948f68 100644 --- a/src/VTKViewer/VTKViewer_PolyDataMapper.cxx +++ b/src/VTKViewer/VTKViewer_PolyDataMapper.cxx @@ -42,6 +42,8 @@ #include #include +#include + #ifndef WIN32 # ifndef GLX_GLXEXT_LEGACY # define GLX_GLXEXT_LEGACY @@ -157,7 +159,12 @@ VTKViewer_PolyDataMapper::~VTKViewer_PolyDataMapper() int VTKViewer_PolyDataMapper::InitShader() { #ifdef VTK_OPENGL2 +#if defined(WIN32) && defined(UNICODE) + std::wstring wFilePath = std::wstring(_wgetenv(L"GUI_ROOT_DIR")) + L"/share/salome/resources/gui/Point"; + std::string filePath = Kernel_Utils::utf8_encode_s(wFilePath.c_str()); +#else std::string filePath = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Point"; +#endif if( !this->OpenGLHelper.CreateShaderProgram(filePath, this->PointProgram, this->VertexShader, this->FragmentShader) ) return false; @@ -174,9 +181,14 @@ int VTKViewer_PolyDataMapper::InitShader() this->OpenGLHelper.vglUseProgramObjectARB( current_program ); this->OpenGLHelper.vglGenVertexArraysARB(1, &this->VertexArrayObject); +#else +#if defined(WIN32) && defined(UNICODE) + std::wstring wFilePath = std::wstring(_wgetenv( L"GUI_ROOT_DIR" ) ) + L"/share/salome/resources/gui/Vertex_Program_ARB.txt"; + std::string fileName = Kernel_Utils::utf8_encode( wFilePath.c_str() ); #else std::string fileName = std::string( getenv( "GUI_ROOT_DIR") ) + "/share/salome/resources/gui/Vertex_Program_ARB.txt"; +#endif char* shader = GUI_OPENGL::readFromFile( fileName );