From 68735d1585d8ee32128923af3725cda413d14ab9 Mon Sep 17 00:00:00 2001 From: DUC ANH HOANG Date: Thu, 20 Jul 2023 01:47:52 +0200 Subject: [PATCH] update SalomeApprc with SALOME_APPLICATION_DIR --- CMakeLists.txt | 1 + src/CMakeLists.txt | 1 + src/LightApp/CMakeLists.txt | 4 +- src/LightApp/LightApp_Application.cxx | 15 +++ src/LightApp/LightApp_Application.h | 1 + src/SalomeApprc_tool/SalomeApprc_utils.cxx | 110 ------------------ src/SalomeApprc_tool/SalomeApprc_utils.h | 18 --- .../.vscode/settings.json | 0 .../CMakeLists.txt | 27 ++--- .../SalomeApprc_tool.cxx | 0 src/SalomeApprc_utils/SalomeApprc_utils.cxx | 77 ++++++++++++ src/SalomeApprc_utils/SalomeApprc_utils.h | 18 +++ 12 files changed, 127 insertions(+), 145 deletions(-) delete mode 100644 src/SalomeApprc_tool/SalomeApprc_utils.cxx delete mode 100644 src/SalomeApprc_tool/SalomeApprc_utils.h rename src/{SalomeApprc_tool => SalomeApprc_utils}/.vscode/settings.json (100%) rename src/{SalomeApprc_tool => SalomeApprc_utils}/CMakeLists.txt (69%) rename src/{SalomeApprc_tool => SalomeApprc_utils}/SalomeApprc_tool.cxx (100%) create mode 100644 src/SalomeApprc_utils/SalomeApprc_utils.cxx create mode 100644 src/SalomeApprc_utils/SalomeApprc_utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b9b4a03f1..1077203a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -323,6 +323,7 @@ SET(_${PROJECT_NAME}_exposed_targets CAM CASCatch DDS Event LightApp LogWindow ObjBrowser QDS qtx SalomePrs SalomeStyle std SUITApp suit ViewerTools ViewerData ImageComposer + SalomeApprc_utils ) IF(SALOME_USE_OCCVIEWER OR SALOME_USE_VTKVIEWER OR SALOME_USE_GLVIEWER) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5f768494..0e9f2cef6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,7 @@ ADD_SUBDIRECTORY(ViewerData) ADD_SUBDIRECTORY(ViewerTools) ADD_SUBDIRECTORY(ImageComposer) ADD_SUBDIRECTORY(GUI_PY) +ADD_SUBDIRECTORY(SalomeApprc_utils) ## # SALOME object diff --git a/src/LightApp/CMakeLists.txt b/src/LightApp/CMakeLists.txt index 1dd89a2e8..9f00d3949 100644 --- a/src/LightApp/CMakeLists.txt +++ b/src/LightApp/CMakeLists.txt @@ -38,6 +38,7 @@ INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/src/STD ${PROJECT_SOURCE_DIR}/src/SUIT ${PROJECT_SOURCE_DIR}/src/Style + ${PROJECT_SOURCE_DIR}/src/SalomeApprc_utils ) IF(SALOME_USE_SALOMEOBJECT) INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/OBJECT) @@ -100,7 +101,8 @@ SET(_link_LIBRARIES ${OpenCASCADE_FoundationClasses_LIBRARIES} ${QT_LIBRARIES} ${HDF5_LIBRARIES} - CASCatch qtx suit std SalomeStyle SalomePrs CAM LogWindow ObjBrowser Event + CASCatch qtx suit std SalomeStyle SalomePrs CAM LogWindow ObjBrowser Event + SalomeApprc_utils ${KERNEL_SalomeHDFPersist} ${KERNEL_SALOMELocalTrace} ${GRAPHVIZ_LIBRARIES} ) diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 9db7595f5..44b057ce6 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -98,6 +98,7 @@ #include #include +#include #ifndef DISABLE_GLVIEWER #include @@ -883,6 +884,8 @@ void LightApp_Application::customize() // b. here we add custom modules (manually added by the user) if ( HAS_SALOME_ON_DEMAND ) { + // Update SalomeApprc.X.X.X with SALOME_APPLICATION_DIR + updateSalomeApprc(); QStringList modList = resourceMgr()->stringValue( "launch", "user_modules" ).split( ";", QString::SkipEmptyParts ); foreach ( QString aModule, modList ) addUserModule( aModule, resourceMgr()->stringValue( "user_modules", aModule ) ); @@ -893,6 +896,18 @@ void LightApp_Application::customize() } } +void LightApp_Application::updateSalomeApprc() +{ + SUIT_ResourceMgr* resMgr = resourceMgr(); + auto extRootDir = getenv(salomeAppDir); + + QString salomemodules(getenv("SALOME_MODULES")); + if(salomemodules.isEmpty()) + AddComponents_from_salomeappdir( QDir(extRootDir), resMgr ); + else + AddComponents_from_salomemodules(salomemodules, QDir(extRootDir), resMgr); +} + /*!On module activation action.*/ void LightApp_Application::onModuleActivation( const QString& modTitle ) { diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index a45ef0c8b..170c3b933 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -337,6 +337,7 @@ private: QList findToolBars( const QStringList& names = QStringList() ); void createHelpItems( const QString& ); void removeHelpItems( const QString& ); + void updateSalomeApprc(); QByteArray processState(QByteArray& input, const bool processWin, diff --git a/src/SalomeApprc_tool/SalomeApprc_utils.cxx b/src/SalomeApprc_tool/SalomeApprc_utils.cxx deleted file mode 100644 index b481ecaeb..000000000 --- a/src/SalomeApprc_tool/SalomeApprc_utils.cxx +++ /dev/null @@ -1,110 +0,0 @@ -#include "SalomeApprc_utils.h" - -QString 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; -} - -void AddComponents_from_salomeappdir() -{ - QFileInfoList salomexd_list = salomeappdir.entryInfoList(QStringList() << "*.salomexd",QDir::Files); - - foreach(QFileInfo filename, salomexd_list) - { - QFile file( filename.filePath() ); - if ( !file.open( QFile::ReadOnly ) ) - { - qWarning() << "file " << filename.fileName() << " is not accessible"; - continue; - } - - QJsonDocument document = QJsonDocument::fromJson( file.readAll() ); - if ( document.isNull() ) - { - qWarning() << "invalid json file. Filename: " << filename.fileName(); - continue; - } - QJsonObject root = document.object(); - QJsonValue components = root.value( "components"); - AddComponents_from_extmodule(components); - } -} - -void AddComponents_from_extmodule(const QJsonValue & components ) -{ - QString root(salomeappdir.path() + "/__SALOME_EXT__"); - if ( components.isArray() ) - { - foreach ( auto comp, components.toArray()) - { - AddGuiComponent(comp.toString(), root); - } - } - else - { - QJsonObject compObj = components.toObject(); - foreach ( QString key, compObj.keys() ) - { - if ( QString::compare(key, ITERACTIVE_EXTCOMPONENT_KEY) == 0 ) - { - foreach (auto comp, compObj.value(key).toArray() ) - AddGuiComponent(comp.toString(), root); - } - } - } -} - -void AddComponents_from_salomemodules(const QString & salomemodules) -{ - QRegularExpression sep(":|,"); - QStringList components_list = salomemodules.split(sep,QString::SkipEmptyParts); - foreach (QString comp, components_list) - { - QString comp_root_dir = getenv(comp + "_ROOT_DIR"); - - qWarning() << comp; - qWarning() << comp_root_dir; - if (comp_root_dir.isEmpty()) - comp_root_dir = salomeappdir.path() + "/__SALOME_EXT__"; - AddGuiComponent(comp, comp_root_dir); - } - - -} -void AddGuiComponent(const QString& comp, const QString& CompRoot) -{ - QStringList CompsResMgr = ResMgr.stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts); - if (!CompsResMgr.contains(comp)) - { - ResMgr.setValue( "user_modules", comp, CompRoot ); - } - - CompsResMgr << comp; - CompsResMgr.removeDuplicates(); - ResMgr.setValue( "launch", "user_modules", CompsResMgr.join( ";" ) ); -} \ No newline at end of file diff --git a/src/SalomeApprc_tool/SalomeApprc_utils.h b/src/SalomeApprc_tool/SalomeApprc_utils.h deleted file mode 100644 index 9970af319..000000000 --- a/src/SalomeApprc_tool/SalomeApprc_utils.h +++ /dev/null @@ -1,18 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include - -extern QDir salomeappdir; -const QString ITERACTIVE_EXTCOMPONENT_KEY("salome_interactive"); -extern SUIT_ResourceMgr ResMgr; - -QString getenv(const QString & envVar); -void AddComponents_from_extmodule (const QJsonValue & components ); -void AddComponents_from_salomeappdir(); -void AddComponents_from_salomemodules(const QString & salomemodules); -void AddGuiComponent(const QString& comp, const QString& CompRoot); diff --git a/src/SalomeApprc_tool/.vscode/settings.json b/src/SalomeApprc_utils/.vscode/settings.json similarity index 100% rename from src/SalomeApprc_tool/.vscode/settings.json rename to src/SalomeApprc_utils/.vscode/settings.json diff --git a/src/SalomeApprc_tool/CMakeLists.txt b/src/SalomeApprc_utils/CMakeLists.txt similarity index 69% rename from src/SalomeApprc_tool/CMakeLists.txt rename to src/SalomeApprc_utils/CMakeLists.txt index cde321b79..a3cb30024 100644 --- a/src/SalomeApprc_tool/CMakeLists.txt +++ b/src/SalomeApprc_utils/CMakeLists.txt @@ -27,27 +27,19 @@ ELSE() MESSAGE(FATAL_ERROR "We absolutely need the Salome CMake configuration files, please define CONFIGURATION_ROOT_DIR !") ENDIF() -SET(GUI_ROOT_DIR $ENV{GUI_ROOT_DIR} CACHE PATH "Path to the Salome CMake GUI files") -IF(EXISTS ${GUI_ROOT_DIR}) - SET(GUI_INCLUDE_DIRS ${GUI_ROOT_DIR}/include/salome) - LINK_DIRECTORIES(${GUI_ROOT_DIR}/lib/salome) -ELSE() - MESSAGE(FATAL_ERROR "We absolutely need the GUI installation, please define GUI_ROOT_DIR !") -ENDIF() - FIND_PACKAGE(SalomeQt5) # additional include directories INCLUDE_DIRECTORIES( ${QT_INCLUDES} - ${PYTHON_INCLUDE_DIRS} - ${GUI_INCLUDE_DIRS} + ${PROJECT_SOURCE_DIR}/src/Qtx + ${PROJECT_SOURCE_DIR}/src/SUIT ) # additional preprocessor / compiler flags ADD_DEFINITIONS(${QT_DEFINITIONS} ${PYTHON_DEFINITIONS}) # libraries to link to -SET(_link_LIBRARIES ${QT_LIBRARIES} ${PYTHON_LIBRARIES} qtx suit) +SET(_link_LIBRARIES ${QT_LIBRARIES} qtx suit) ## --- headers --- # @@ -57,14 +49,17 @@ SET(_moc_HEADERS ) # # header files / to install -SET(SalomeApprc_tool_HEADERS ${_moc_HEADERS}) +SET(SalomeApprc_utils_HEADERS ${_moc_HEADERS}) # sources / moc wrappings -QT5_WRAP_CPP(_moc_SOURCES SalomeApprc_tool.cxx SalomeApprc_utils.cxx) +QT5_WRAP_CPP(_moc_SOURCES SalomeApprc_utils.cxx) # --- rules --- -ADD_EXECUTABLE(SalomeApprc_tool SalomeApprc_tool.cxx SalomeApprc_utils.cxx) -TARGET_LINK_LIBRARIES(SalomeApprc_tool ${_link_LIBRARIES}) -INSTALL(TARGETS SalomeApprc_tool DESTINATION bin) +ADD_LIBRARY(SalomeApprc_utils SalomeApprc_utils.cxx) + +TARGET_LINK_LIBRARIES(SalomeApprc_utils ${_link_LIBRARIES}) +INSTALL(TARGETS SalomeApprc_utils EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +#INSTALL(TARGETS suit EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS}) +INSTALL(FILES ${SalomeApprc_utils_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS}) diff --git a/src/SalomeApprc_tool/SalomeApprc_tool.cxx b/src/SalomeApprc_utils/SalomeApprc_tool.cxx similarity index 100% rename from src/SalomeApprc_tool/SalomeApprc_tool.cxx rename to src/SalomeApprc_utils/SalomeApprc_tool.cxx diff --git a/src/SalomeApprc_utils/SalomeApprc_utils.cxx b/src/SalomeApprc_utils/SalomeApprc_utils.cxx new file mode 100644 index 000000000..0b153aa24 --- /dev/null +++ b/src/SalomeApprc_utils/SalomeApprc_utils.cxx @@ -0,0 +1,77 @@ +#include "SalomeApprc_utils.h" + +void AddComponents_from_salomeappdir(const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr) +{ + QFileInfoList salomexd_list = salomeappdir.entryInfoList(QStringList() << "*.salomexd",QDir::Files); + foreach(QFileInfo filename, salomexd_list) + { + QFile file( filename.filePath() ); + if ( !file.open( QFile::ReadOnly ) ) + { + qWarning() << "file " << filename.fileName() << " is not accessible"; + continue; + } + + QJsonDocument document = QJsonDocument::fromJson( file.readAll() ); + if ( document.isNull() ) + { + qWarning() << "invalid json file. Filename: " << filename.fileName(); + continue; + } + QJsonObject salomexd_dict = document.object(); + QJsonValue components = salomexd_dict.value( "components"); + + QString root(salomeappdir.path() + "/__SALOME_EXT__"); + if ( components.isArray() ) + { + // In the case that we have a list of components. We consider that all of them are GUI module + foreach ( auto comp, components.toArray()) + { + AddGuiComponent(comp.toString(), root, ResMgr); + } + } + else + { + // In the case that we have a dict of several component group + QJsonObject compObj = components.toObject(); + foreach ( QString key, compObj.keys() ) + { + if ( QString::compare(key, ITERACTIVE_EXTCOMPONENT_KEY) == 0 ) + { + foreach (auto comp, compObj.value(key).toArray() ) + AddGuiComponent(comp.toString(), root, ResMgr); + } + } + } + } +} + +void AddComponents_from_salomemodules(const QString& salomemodules, const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr) +{ + QRegularExpression sep(":|,"); + QStringList components_list = salomemodules.split(sep,QString::SkipEmptyParts); + foreach (QString comp, components_list) + { + QString comp_root_dir = Qtx::getenv(comp + "_ROOT_DIR"); + + qWarning() << comp; + qWarning() << comp_root_dir; + if (comp_root_dir.isEmpty()) + comp_root_dir = salomeappdir.path() + "/__SALOME_EXT__"; + AddGuiComponent(comp, comp_root_dir, ResMgr); + } + + +} +void AddGuiComponent(const QString& comp, const QString& CompRoot, SUIT_ResourceMgr* ResMgr) +{ + QStringList CompsResMgr = ResMgr->stringValue("launch", "user_modules").split(";", QString::SkipEmptyParts); + if (!CompsResMgr.contains(comp)) + { + ResMgr->setValue( "user_modules", comp, CompRoot ); + } + + CompsResMgr << comp; + CompsResMgr.removeDuplicates(); + ResMgr->setValue( "launch", "user_modules", CompsResMgr.join( ";" ) ); +} \ No newline at end of file diff --git a/src/SalomeApprc_utils/SalomeApprc_utils.h b/src/SalomeApprc_utils/SalomeApprc_utils.h new file mode 100644 index 000000000..c1dbcd7e8 --- /dev/null +++ b/src/SalomeApprc_utils/SalomeApprc_utils.h @@ -0,0 +1,18 @@ +#ifndef SALOMEAPPRC_UTILS_H +#define SALOMEAPPRC_UTILS_H + +#include +#include +#include +#include + +#include +#include + +const QString ITERACTIVE_EXTCOMPONENT_KEY("salome_interactive"); + +void AddComponents_from_salomeappdir(const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr); +void AddComponents_from_salomemodules(const QString& salomemodules, const QDir& salomeappdir, SUIT_ResourceMgr* ResMgr); +void AddGuiComponent(const QString& comp, const QString& CompRoot, SUIT_ResourceMgr* ResMgr ); + +#endif \ No newline at end of file -- 2.39.2