From: DUC ANH HOANG Date: Wed, 31 May 2023 08:33:50 +0000 (+0200) Subject: SalomeApprc_tool updating tool X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9aeb1c3c2a592a467bdba8b4ebcc2055d5e909fb;p=modules%2Fgui.git SalomeApprc_tool updating tool --- diff --git a/src/SalomeApprc_tool/.vscode/settings.json b/src/SalomeApprc_tool/.vscode/settings.json new file mode 100644 index 000000000..8ec289435 --- /dev/null +++ b/src/SalomeApprc_tool/.vscode/settings.json @@ -0,0 +1,62 @@ +{ + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "strstream": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "set": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "cfenv": "cpp", + "cinttypes": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/src/SalomeApprc_tool/CMakeLists.txt b/src/SalomeApprc_tool/CMakeLists.txt new file mode 100644 index 000000000..cde321b79 --- /dev/null +++ b/src/SalomeApprc_tool/CMakeLists.txt @@ -0,0 +1,70 @@ +# Copyright (C) 2012-2022 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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 +# + +# Common CMake macros +# =================== +SET(CONFIGURATION_ROOT_DIR $ENV{CONFIGURATION_ROOT_DIR} CACHE PATH "Path to the Salome CMake configuration files") +IF(EXISTS ${CONFIGURATION_ROOT_DIR}) + LIST(APPEND CMAKE_MODULE_PATH "${CONFIGURATION_ROOT_DIR}/cmake") + INCLUDE(SalomeMacros NO_POLICY_SCOPE) +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} +) +# additional preprocessor / compiler flags +ADD_DEFINITIONS(${QT_DEFINITIONS} ${PYTHON_DEFINITIONS}) + +# libraries to link to +SET(_link_LIBRARIES ${QT_LIBRARIES} ${PYTHON_LIBRARIES} qtx suit) + +## --- headers --- +# +# header files / to be processed by moc +SET(_moc_HEADERS + SalomeApprc_utils.h +) +# +# header files / to install +SET(SalomeApprc_tool_HEADERS ${_moc_HEADERS}) + +# sources / moc wrappings +QT5_WRAP_CPP(_moc_SOURCES SalomeApprc_tool.cxx 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) + diff --git a/src/SalomeApprc_tool/SalomeApprc_tool.cxx b/src/SalomeApprc_tool/SalomeApprc_tool.cxx new file mode 100644 index 000000000..99003945f --- /dev/null +++ b/src/SalomeApprc_tool/SalomeApprc_tool.cxx @@ -0,0 +1,51 @@ +#include "SalomeApprc_utils.h" + +QDir salomeappdir(getenv("SALOME_APPLICATION_DIR")); +SUIT_ResourceMgr ResMgr("SalomeApp"); + +int main(int argc, char** argv) +{ + QString salome_version; + if (QString::compare(salomeappdir.dirName(), ".") == 0) + { + qWarning() << "SALOME_APPLICATION_DIR must not be empty!!"; + return 1; + } + if (argc >2) + { + qWarning() << "Too many arguments!! This function accept only one arg for the version name"; + return 1; + } + else if (argc < 2) + { + qInfo() << "Enter the salome version:"; + bool ok_input = false; + while(!ok_input) + { + QTextStream in (stdin); + salome_version = in.readLine(); + if (!salome_version.contains(" ")) + ok_input = true; + else + qWarning() << "The version string must not contain a blank space. Please re-enter the salome version"; + } + } + else + { + salome_version = (QString)argv[1]; + } + + QApplication *app = new QApplication(argc, argv); + app->setOrganizationName("salome"); + ResMgr.setVersion(salome_version); + + QString salomemodules(getenv("SALOME_MODULES")); + if(salomemodules.isEmpty()) + AddComponents_from_salomeappdir(); + else + AddComponents_from_salomemodules(salomemodules); + ResMgr.setCurrentFormat("xml"); + ResMgr.save(); + delete(app); + return 0; +} diff --git a/src/SalomeApprc_tool/SalomeApprc_utils.cxx b/src/SalomeApprc_tool/SalomeApprc_utils.cxx new file mode 100644 index 000000000..b481ecaeb --- /dev/null +++ b/src/SalomeApprc_tool/SalomeApprc_utils.cxx @@ -0,0 +1,110 @@ +#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 new file mode 100644 index 000000000..9970af319 --- /dev/null +++ b/src/SalomeApprc_tool/SalomeApprc_utils.h @@ -0,0 +1,18 @@ +#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);