From 3b18f0eabf967cc4505d6f44a054818e48d8f674 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 5 Apr 2007 10:38:47 +0000 Subject: [PATCH] PAL13554: Redesign options of runSalome. --- src/SUIT/SUIT_ResourceMgr.cxx | 24 +++++++++-- src/SalomeApp/SalomeApp_Application.cxx | 53 +++++++++++++++++-------- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/SUIT/SUIT_ResourceMgr.cxx b/src/SUIT/SUIT_ResourceMgr.cxx index 018b6acf1..9eee0d593 100755 --- a/src/SUIT/SUIT_ResourceMgr.cxx +++ b/src/SUIT/SUIT_ResourceMgr.cxx @@ -20,6 +20,8 @@ #include #include +#include +#include /*! Constructor @@ -70,15 +72,31 @@ QString SUIT_ResourceMgr::loadDoc( const QString& prefix, const QString& id ) co */ QString SUIT_ResourceMgr::userFileName( const QString& appName, const bool for_load ) const { - QString pathName = QtxResourceMgr::userFileName( appName ); + QString pathName; + + // Try config file, given in arguments + for (int i = 1; i < qApp->argc(); i++) { + QRegExp rx ("--resources=(.+)"); + if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 1 ) { + QString file = rx.capturedTexts()[1]; + QFileInfo fi (file); + pathName = fi.absFilePath(); + } + } + + if (!pathName.isEmpty()) + return pathName; + + // QtxResourceMgr::userFileName() + '.' + version() + pathName = QtxResourceMgr::userFileName( appName ); if ( !version().isEmpty() ) pathName += QString( "." ) + version(); - if( !QFileInfo( pathName ).exists() && for_load ) + if ( !QFileInfo( pathName ).exists() && for_load ) { QString newName = findAppropriateUserFile( pathName ); - if( !newName.isEmpty() ) + if ( !newName.isEmpty() ) pathName = newName; } diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index eea9a19a0..3bb85faa3 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -158,38 +158,57 @@ void SalomeApp_Application::start() static bool isFirst = true; if ( isFirst ) { isFirst = false; + QString hdffile; QStringList pyfiles; + for (int i = 1; i < qApp->argc(); i++) { - QRegExp rx("--test=(.+)"); - if ( rx.search( QString(qApp->argv()[i]) ) >= 0 && rx.capturedTexts().count() > 0 ) { - QStringList files = QStringList::split(",",rx.capturedTexts()[1],false); - for (uint j = 0; j < files.count(); j++ ) { - QFileInfo fi( files[j] ); - QString extension = fi.extension( false ).lower(); - if ( extension == "hdf" && fi.exists() ) - hdffile = fi.absFilePath(); - else if ( extension == "py" || extension == "" ) - pyfiles.append( fi.baseName( true ) ); - } + QRegExp rxs ("--study-hdf=(.+)"); + if ( rxs.search( QString(qApp->argv()[i]) ) >= 0 && rxs.capturedTexts().count() > 1 ) { + QString file = rxs.capturedTexts()[1]; + QFileInfo fi ( file ); + QString extension = fi.extension( false ).lower(); + if ( extension == "hdf" && fi.exists() ) + hdffile = fi.absFilePath(); + } + else { + QRegExp rxp ("--pyscript=(.+)"); + if ( rxp.search( QString(qApp->argv()[i]) ) >= 0 && rxp.capturedTexts().count() > 1 ) { + QStringList files = QStringList::split(",",rxp.capturedTexts()[1],false); + pyfiles += files; + } } } + if ( !hdffile.isEmpty() ) // open hdf file given as parameter onOpenDoc( hdffile ); else if ( pyfiles.count() > 0 ) // create new study onNewDoc(); - // import python scripts + + // import/execute python scripts if ( pyfiles.count() > 0 && activeStudy() ) { SalomeApp_Study* appStudy = dynamic_cast( activeStudy() ); if ( appStudy ) { _PTR(Study) aStudy = appStudy->studyDS(); if ( !aStudy->GetProperties()->IsLocked() ) { - for ( uint i = 0; i < pyfiles.count(); i++ ) { - QString command = QString( "import %1" ).arg( pyfiles[i] ); + for (uint j = 0; j < pyfiles.count(); j++ ) { + QFileInfo fi ( pyfiles[j] ); PythonConsole* pyConsole = pythonConsole(); - if ( pyConsole ) - pyConsole->exec( command ); - } + if ( pyConsole ) { + QString extension = fi.extension( false ).lower(); + if ( extension == "py" && fi.exists() ) { + // execute python script + QString command = QString( "execfile(\"%1\")" ).arg( fi.absFilePath() ); + pyConsole->exec( command ); + } + else { + // import python module + QString command = QString( "import %1" ).arg( pyfiles[j] ); + //QString command = QString( "import %1" ).arg( fi.baseName( true ) ); + pyConsole->exec( command ); + } + } + } } } } -- 2.39.2