From b413c471efb159b68969a3911d803ae3bcf55a28 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Tue, 20 Jul 2021 08:26:31 +0200 Subject: [PATCH] First version of working dummy application --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- .../CMakeLists.txt | 30 ++--- .../DummyApplication.cxx} | 14 +-- .../DummyApplication.h} | 16 +-- .../DummyDesktop.cxx} | 18 +-- .../DummyDesktop.h} | 12 +- .../resources/DummyApplication_images.ts} | 0 .../resources/DummyApplication_msg_en.ts} | 0 .../resources/DummyApplication_msg_fr.ts} | 0 .../resources/DummyApplication_msg_ja.ts} | 0 .../resources/icon_visibility_off.png | Bin .../resources/icon_visibility_on.png | Bin .../resources/view_sync.png | Bin src/Session/CMakeLists.txt | 4 +- src/Session/SALOME_Session_Server.cxx | 4 +- src/Session/salomeLight.cxx | 110 ++++++++++++++++++ 17 files changed, 161 insertions(+), 51 deletions(-) rename src/{LightApplication => DummyApplication}/CMakeLists.txt (76%) rename src/{LightApplication/LightApplication.cxx => DummyApplication/DummyApplication.cxx} (85%) rename src/{LightApplication/LightApplication.h => DummyApplication/DummyApplication.h} (84%) rename src/{LightApplication/LightDesktop.cxx => DummyApplication/DummyDesktop.cxx} (91%) rename src/{LightApplication/LightDesktop.h => DummyApplication/DummyDesktop.h} (90%) rename src/{LightApplication/resources/LightApplication_images.ts => DummyApplication/resources/DummyApplication_images.ts} (100%) rename src/{LightApplication/resources/LightApplication_msg_en.ts => DummyApplication/resources/DummyApplication_msg_en.ts} (100%) rename src/{LightApplication/resources/LightApplication_msg_fr.ts => DummyApplication/resources/DummyApplication_msg_fr.ts} (100%) rename src/{LightApplication/resources/LightApplication_msg_ja.ts => DummyApplication/resources/DummyApplication_msg_ja.ts} (100%) rename src/{LightApplication => DummyApplication}/resources/icon_visibility_off.png (100%) rename src/{LightApplication => DummyApplication}/resources/icon_visibility_on.png (100%) rename src/{LightApplication => DummyApplication}/resources/view_sync.png (100%) create mode 100644 src/Session/salomeLight.cxx diff --git a/CMakeLists.txt b/CMakeLists.txt index f0ad22d05..60d3beb2e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -318,7 +318,7 @@ INCLUDE(CMakePackageConfigHelpers) # They all have to be INSTALL'd with the option "EXPORT ${PROJECT_NAME}TargetGroup" SET(_${PROJECT_NAME}_exposed_targets CAM CASCatch DDS Event LightApp LogWindow ObjBrowser - QDS qtx SalomePrs SalomeStyle std SUITApp lightapplication suit ViewerTools ViewerData + QDS qtx SalomePrs SalomeStyle std SUITApp dummyapplication suit ViewerTools ViewerData ImageComposer ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 443ce10f4..d9ed20b52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,7 +41,7 @@ ADD_SUBDIRECTORY(ViewerData) ADD_SUBDIRECTORY(ViewerTools) ADD_SUBDIRECTORY(ImageComposer) ADD_SUBDIRECTORY(GUI_PY) -ADD_SUBDIRECTORY(LightApplication) +ADD_SUBDIRECTORY(DummyApplication) ## # SALOME object diff --git a/src/LightApplication/CMakeLists.txt b/src/DummyApplication/CMakeLists.txt similarity index 76% rename from src/LightApplication/CMakeLists.txt rename to src/DummyApplication/CMakeLists.txt index 5b69459d4..7161cb67f 100644 --- a/src/LightApplication/CMakeLists.txt +++ b/src/DummyApplication/CMakeLists.txt @@ -38,8 +38,8 @@ SET(_link_LIBRARIES ${PLATFORM_LIBS} ${QT_LIBRARIES} qtx ObjBrowser) # header files / to be processed by moc SET(_moc_HEADERS - LightApplication.h - LightDesktop.h + DummyApplication.h + DummyDesktop.h ) # header files / no moc processing @@ -47,16 +47,16 @@ SET(_other_HEADERS ) # header files / to install -SET(lightapplication_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) +SET(dummyapplication_HEADERS ${_moc_HEADERS} ${_other_HEADERS}) # --- resources --- # resource files / to be processed by lrelease SET(_ts_RESOURCES - resources/LightApplication_msg_en.ts - resources/LightApplication_msg_fr.ts - resources/LightApplication_msg_ja.ts - resources/LightApplication_images.ts + resources/DummyApplication_msg_en.ts + resources/DummyApplication_msg_fr.ts + resources/DummyApplication_msg_ja.ts + resources/DummyApplication_images.ts ) # resource files / static @@ -73,20 +73,20 @@ QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS}) # sources / static SET(_other_SOURCES - LightApplication.cxx - LightDesktop.cxx + DummyApplication.cxx + DummyDesktop.cxx ) # sources / to compile -SET(lightapplication_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) +SET(dummyapplication_SOURCES ${_other_SOURCES} ${_moc_SOURCES}) # --- rules --- -ADD_LIBRARY(lightapplication ${lightapplication_SOURCES}) -TARGET_LINK_LIBRARIES(lightapplication ${_link_LIBRARIES}) -INSTALL(TARGETS lightapplication EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +ADD_LIBRARY(dummyapplication ${dummyapplication_SOURCES}) +TARGET_LINK_LIBRARIES(dummyapplication ${_link_LIBRARIES}) +INSTALL(TARGETS dummyapplication EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) -INSTALL(FILES ${lightapplication_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) +INSTALL(FILES ${dummyapplication_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) QT_INSTALL_TS_RESOURCES("${_ts_RESOURCES}" "${SALOME_GUI_INSTALL_RES_DATA}") -INSTALL(FILES ${_other_RESOURCES} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) \ No newline at end of file +INSTALL(FILES ${_other_RESOURCES} DESTINATION ${SALOME_GUI_INSTALL_RES_DATA}) diff --git a/src/LightApplication/LightApplication.cxx b/src/DummyApplication/DummyApplication.cxx similarity index 85% rename from src/LightApplication/LightApplication.cxx rename to src/DummyApplication/DummyApplication.cxx index 3b3fa2498..86997e09b 100644 --- a/src/LightApplication/LightApplication.cxx +++ b/src/DummyApplication/DummyApplication.cxx @@ -20,22 +20,22 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include "LightApplication.h" -#include "LightDesktop.h" +#include "DummyApplication.h" +#include "DummyDesktop.h" /*! Default constructor */ -LightApplication::LightApplication() +DummyApplication::DummyApplication() : QObject( 0 ) { - myDesktop = new LightDesktop(); + myDesktop = new DummyDesktop(); } /*! Destructor */ -LightApplication::~LightApplication() +DummyApplication::~DummyApplication() { } @@ -43,7 +43,7 @@ LightApplication::~LightApplication() /*! Shows the application's main widget. For non GUI application must be redefined. */ -void LightApplication::start() +void DummyApplication::start() { myDesktop->show(); -} \ No newline at end of file +} diff --git a/src/LightApplication/LightApplication.h b/src/DummyApplication/DummyApplication.h similarity index 84% rename from src/LightApplication/LightApplication.h rename to src/DummyApplication/DummyApplication.h index fd9412529..92a1a7b8f 100644 --- a/src/LightApplication/LightApplication.h +++ b/src/DummyApplication/DummyApplication.h @@ -20,28 +20,28 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef LIGHTAPPLICATION_H -#define LIGHTAPPLICATION_H +#ifndef DUMMYAPPLICATION_H +#define DUMMYAPPLICATION_H -#include "LightDesktop.h" +#include "DummyDesktop.h" #include -class LightApplication : public QObject +class DummyApplication : public QObject { Q_OBJECT public: - LightApplication(); - virtual ~LightApplication(); + DummyApplication(); + virtual ~DummyApplication(); //! Shows the application's main widget. For non GUI application must be redefined. virtual void start(); private: - LightDesktop * myDesktop = 0; + DummyDesktop * myDesktop = 0; }; -#endif \ No newline at end of file +#endif diff --git a/src/LightApplication/LightDesktop.cxx b/src/DummyApplication/DummyDesktop.cxx similarity index 91% rename from src/LightApplication/LightDesktop.cxx rename to src/DummyApplication/DummyDesktop.cxx index 847d8d4b5..0b5a394a8 100644 --- a/src/LightApplication/LightDesktop.cxx +++ b/src/DummyApplication/DummyDesktop.cxx @@ -21,7 +21,7 @@ // #include // this include must be the first one as it includes Python.h -#include "LightDesktop.h" +#include "DummyDesktop.h" #include "utilities.h" @@ -54,7 +54,7 @@ /*! Constructor. */ -LightDesktop::LightDesktop() +DummyDesktop::DummyDesktop() : QtxMainWindow() { myMenuMgr = new QtxActionMenuMgr( this ); @@ -67,30 +67,30 @@ LightDesktop::LightDesktop() /*! Destructor. */ -LightDesktop::~LightDesktop() +DummyDesktop::~DummyDesktop() { } -void LightDesktop::createMenus() +void DummyDesktop::createMenus() { //QPushButton *mybutton = new QPushButton("Test", this); - //connect(mybutton, &QPushButton::released, this, &LightDesktop::RunScript); + //connect(mybutton, &QPushButton::released, this, &DummyDesktop::RunScript); //this->setCentralWidget(mybutton); QMenu *fileMenu = menuBar()->addMenu("File"); - fileMenu->addAction("Open File", this, &LightDesktop::RunScript, QKeySequence::Open); + fileMenu->addAction("Open File", this, &DummyDesktop::RunScript, QKeySequence::Open); fileMenu->addAction("Dummy", this, SLOT( Dummy()), QKeySequence::New); } -void LightDesktop::Dummy() +void DummyDesktop::Dummy() { QMessageBox msgBox; msgBox.setText("Dummy text"); msgBox.exec(); } -void LightDesktop::RunScript() +void DummyDesktop::RunScript() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Python File"), "/home/B61570/work_in_progress/salome2810", "Python Files (*.py)"); @@ -124,4 +124,4 @@ void LightDesktop::RunScript() //std::cerr << "i: " << i << std::endl; // Release GIL PyGILState_Release(gstate); -} \ No newline at end of file +} diff --git a/src/LightApplication/LightDesktop.h b/src/DummyApplication/DummyDesktop.h similarity index 90% rename from src/LightApplication/LightDesktop.h rename to src/DummyApplication/DummyDesktop.h index 394f39083..3225b4b65 100644 --- a/src/LightApplication/LightDesktop.h +++ b/src/DummyApplication/DummyDesktop.h @@ -19,8 +19,8 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef LIGHTDESKTOP_H -#define LIGHTDESKTOP_H +#ifndef DUMMYDESKTOP_H +#define DUMMYDESKTOP_H #include @@ -28,13 +28,13 @@ class QtxLogoMgr; class QtxActionMenuMgr; class QtxActionToolMgr; -class LightDesktop : public QtxMainWindow +class DummyDesktop : public QtxMainWindow { Q_OBJECT public: - LightDesktop(); - virtual ~LightDesktop(); + DummyDesktop(); + virtual ~DummyDesktop(); void RunScript(); void Dummy(); @@ -46,4 +46,4 @@ private: QtxLogoMgr* myLogoMgr; }; -#endif \ No newline at end of file +#endif diff --git a/src/LightApplication/resources/LightApplication_images.ts b/src/DummyApplication/resources/DummyApplication_images.ts similarity index 100% rename from src/LightApplication/resources/LightApplication_images.ts rename to src/DummyApplication/resources/DummyApplication_images.ts diff --git a/src/LightApplication/resources/LightApplication_msg_en.ts b/src/DummyApplication/resources/DummyApplication_msg_en.ts similarity index 100% rename from src/LightApplication/resources/LightApplication_msg_en.ts rename to src/DummyApplication/resources/DummyApplication_msg_en.ts diff --git a/src/LightApplication/resources/LightApplication_msg_fr.ts b/src/DummyApplication/resources/DummyApplication_msg_fr.ts similarity index 100% rename from src/LightApplication/resources/LightApplication_msg_fr.ts rename to src/DummyApplication/resources/DummyApplication_msg_fr.ts diff --git a/src/LightApplication/resources/LightApplication_msg_ja.ts b/src/DummyApplication/resources/DummyApplication_msg_ja.ts similarity index 100% rename from src/LightApplication/resources/LightApplication_msg_ja.ts rename to src/DummyApplication/resources/DummyApplication_msg_ja.ts diff --git a/src/LightApplication/resources/icon_visibility_off.png b/src/DummyApplication/resources/icon_visibility_off.png similarity index 100% rename from src/LightApplication/resources/icon_visibility_off.png rename to src/DummyApplication/resources/icon_visibility_off.png diff --git a/src/LightApplication/resources/icon_visibility_on.png b/src/DummyApplication/resources/icon_visibility_on.png similarity index 100% rename from src/LightApplication/resources/icon_visibility_on.png rename to src/DummyApplication/resources/icon_visibility_on.png diff --git a/src/LightApplication/resources/view_sync.png b/src/DummyApplication/resources/view_sync.png similarity index 100% rename from src/LightApplication/resources/view_sync.png rename to src/DummyApplication/resources/view_sync.png diff --git a/src/Session/CMakeLists.txt b/src/Session/CMakeLists.txt index c39457539..e6e342f69 100644 --- a/src/Session/CMakeLists.txt +++ b/src/Session/CMakeLists.txt @@ -35,7 +35,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/Event ${PROJECT_SOURCE_DIR}/src/Style - ${PROJECT_SOURCE_DIR}/src/LightApplication + ${PROJECT_SOURCE_DIR}/src/DummyApplication ${PROJECT_SOURCE_DIR}/src/STD ${PROJECT_SOURCE_DIR}/src/CAM ${PROJECT_SOURCE_DIR}/src/OBJECT @@ -69,7 +69,7 @@ SET(_link_LIBRARIES ${KERNEL_SalomeLauncher} ${KERNEL_Registry} ${KERNEL_SALOMEBasics} - qtx lightapplication suit Event SalomeStyle SalomeApp SalomeIDLGUI + qtx dummyapplication suit Event SalomeStyle SalomeApp SalomeIDLGUI ) # --- headers --- diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index f7ca70ebe..34122b747 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -56,7 +56,7 @@ #include "SUIT_Session.h" #include "SUIT_Tools.h" -#include "LightApplication.h" +#include "DummyApplication.h" #include #include CORBA_SERVER_HEADER(SALOME_Session) @@ -733,7 +733,7 @@ int AbstractGUIAppMain(int argc, char **argv) MESSAGE("creation SUIT_Application"); MESSAGE(NamingServiceImplementation::LibName ); //SUIT_Application *aGUIApp = aGUISession->startApplication(NamingServiceImplementation::LibName, 0, 0); - LightApplication *aGUIApp = new LightApplication(); + DummyApplication *aGUIApp = new DummyApplication(); aGUIApp->start(); if (aGUIApp) diff --git a/src/Session/salomeLight.cxx b/src/Session/salomeLight.cxx new file mode 100644 index 000000000..a273572b8 --- /dev/null +++ b/src/Session/salomeLight.cxx @@ -0,0 +1,110 @@ +// Copyright (C) 2021 CEA/DEN, EDF R&D +// +// 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. +// +// 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 +// + +#include +#include +#include + +#include +#include + +int main(int argc, char *argv[]) +{ + constexpr char MAIN_PROGRAM[] = "SALOME_Session_Server_No_Server"; + constexpr char NO_SERVER_ENV_VAR[] = "SALOME_EMB_SERVANT"; + constexpr char PYQT5_NOT_MASTER[] = "PYQT5_NOT_MASTER"; + const char *MODULES[]={"GUI"}; + const char *MODULES_PATH[]={"PYHELLO","GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","NETGENPLUGIN"}; +// #ifndef WIN32 +// const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","YACS","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"}; +// const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","YACS","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"}; +// #else +// const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","NETGENPLUGIN"}; +// const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","NETGENPLUGIN"}; +// #endif + constexpr char APPCONFIG[]="SalomeAppSLConfig"; + QProcessEnvironment pe(QProcessEnvironment::systemEnvironment()); + QStringList modulesPaths; + for(auto elt : MODULES_PATH) + { + QString elt_root_dir( QString("%1_ROOT_DIR").arg(elt) ); + if( !pe.contains(elt_root_dir) || pe.value(elt_root_dir).isEmpty() ) + { + std::cerr << elt_root_dir.toStdString() << " is not defined in your environment !" << std::endl; + return 1; + } + modulesPaths << QDir::fromNativeSeparators( QString("%1/share/salome/resources/%2").arg( pe.value(elt_root_dir) ).arg( QString(elt).toLower() ) ); + } + // fill LightAppConfig env var + QString appconfig_val( modulesPaths.join(QDir::listSeparator())); + pe.insert(APPCONFIG,appconfig_val); + //tells shutup to salome.salome_init invoked at shaper engine ignition + pe.insert(NO_SERVER_ENV_VAR,"1"); + pe.insert(PYQT5_NOT_MASTER,"1"); + //resource file retrieve + QString resfile; + { + QProcess proc; + proc.setProcessEnvironment(pe); + proc.setProgram("python3"); + proc.setArguments({"-c","from launchConfigureParser import userFile ; import sys ; sys.stdout.write(userFile(\"SalomeApp\",\"salome\"))"}); + proc.start(); + proc.waitForFinished(-1); + if(proc.exitStatus() != QProcess::NormalExit) + { + std::cerr << "Fail to retrieve resource file from launchConfigureParser python module !" << std::endl; + return 1; + } + QByteArray val(proc.readAllStandardOutput()); + resfile = QString::fromUtf8(val); + } + // + QProcess proc; + proc.setProcessEnvironment(pe); + proc.setProgram(MAIN_PROGRAM); + + QStringList args({"--with","Registry","(","--salome_session","theSession",")","--with","ModuleCatalog","(","-common"}); + QStringList catalogs; + for(std::size_t im = 0 ; im < sizeof(MODULES)/sizeof(decltype(MODULES[0])) ; ++im ) + { + QString root_dir = pe.value( QString("%1_ROOT_DIR").arg(MODULES[im]) ); + catalogs << QDir::toNativeSeparators( QString("%1/share/salome/resources/%2/%3Catalog.xml").arg(root_dir).arg(QString(MODULES[im]).toLower()).arg(MODULES[im]) ); + } + args << catalogs.join("::"); + args << ")" << "--hide-splash" << "--modules" << "(GUI)"; + args << "--with" << "SALOMEDS" << "(" << ")" << "--with" << "Container" << "(" << "FactoryServer" << ")"; + if( pe.contains("VERBOSE") ) + { + std::cout << "Overloaded env var :" << std::endl; + std::cout << " - " << NO_SERVER_ENV_VAR << std::endl; + std::cout << " - " << APPCONFIG << " = " << appconfig_val.toStdString() << std::endl; + std::cout << "Command launched :" << std::endl; + // Building string of command + std::string cmd = args.join(" ").toStdString(); + // Adding quotes around ( and ) as they are interpreted by bash + cmd = std::regex_replace(cmd, std::regex("\\("), "\"(\""); + cmd = std::regex_replace(cmd, std::regex("\\)"), "\")\""); + std::cout << MAIN_PROGRAM << " " << cmd << std::endl; + } + proc.setArguments(args); + proc.setProcessChannelMode( QProcess::ForwardedErrorChannel ); + proc.start(); + proc.waitForFinished(-1); + return proc.exitCode(); +} -- 2.39.2