From: rnv Date: Thu, 21 Feb 2019 08:46:02 +0000 (+0300) Subject: Run SALOME with UNICODE path. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=772e85aefc5c506d6f7d6174273c1dba7ca1dd75;p=modules%2Fgui.git Run SALOME with UNICODE path. --- diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index a12208c73..4972d64e2 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/HelpBrowser.cxx b/src/HelpBrowser/HelpBrowser.cxx index 9848af0ba..03cb8f5f3 100644 --- a/src/HelpBrowser/HelpBrowser.cxx +++ b/src/HelpBrowser/HelpBrowser.cxx @@ -261,7 +261,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/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 21cc6176f..9f5f38e45 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 957af1f87..cc14d57a9 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 c249d8a67..d32e73fb8 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() + 3]; QStringList args = QApplication::arguments(); diff --git a/src/PVViewer/PVViewer_ViewManager.cxx b/src/PVViewer/PVViewer_ViewManager.cxx index 29eddef95..647ea96d9 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 e976086b1..8170e34a2 100755 --- 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 164b46c04..19b1c3d8f 100755 --- 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 c5cd1d74e..748032a35 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 6a2c7dbac..7c5765cc2 100755 --- 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 366e70aed..9d13282e0 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 7e1c32f05..fcb5509f0 100755 --- 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 133fc45ef..7551a91bf 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 29446ccb7..7c6d9c337 100755 --- 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 d299db78e..c6ab4c6c6 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 60e9b0fd1..fa51ad060 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 84f3dd8e6..2423e46bb 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 );