Salome HOME
Copyright update 2022
[modules/gui.git] / src / Session / salome2810.cxx
1 // Copyright (C) 2021-2022  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <QProcessEnvironment>
21 #include <QDir>
22 #include <QProcess>
23
24 #include <iostream>
25
26 int main(int argc, char *argv[])
27 {
28   constexpr char MAIN_PROGRAM[] = "SALOME_Session_Server_No_Server";
29   constexpr char PYQT5_NOT_MASTER[] = "PYQT5_NOT_MASTER";
30 #ifndef WIN32
31   const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","YACS","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
32   const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","YACS","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
33 #else
34   const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","NETGENPLUGIN"};
35   const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","NETGENPLUGIN"};
36 #endif
37   constexpr char APPCONFIG[]="SalomeAppSLConfig";
38   QProcessEnvironment pe(QProcessEnvironment::systemEnvironment());
39   QStringList modulesPaths;
40   for(auto elt : MODULES_PATH)
41   {
42     QString elt_root_dir( QString("%1_ROOT_DIR").arg(elt) );
43     if( !pe.contains(elt_root_dir) || pe.value(elt_root_dir).isEmpty() )
44     {
45       std::cerr << elt_root_dir.toStdString() << " is not defined in your environment !" << std::endl;
46       return 1;
47     }
48     modulesPaths << QDir::fromNativeSeparators( QString("%1/share/salome/resources/%2").arg( pe.value(elt_root_dir) ).arg( QString(elt).toLower() ) );
49   }
50   // fill LightAppConfig env var
51   QString appconfig_val( modulesPaths.join(QDir::listSeparator()));
52   pe.insert(APPCONFIG,appconfig_val);
53   //tells shutup to salome.salome_init invoked at shaper engine ignition
54   pe.insert(PYQT5_NOT_MASTER,"1");
55   //resource file retrieve
56   QString resfile;
57   {
58     QProcess proc;
59     proc.setProcessEnvironment(pe);
60     proc.setProgram("python3");
61     proc.setArguments({"-c","from launchConfigureParser import userFile ; import sys ; sys.stdout.write(userFile(\"SalomeApp\",\"salome\"))"});
62     proc.start();
63     proc.waitForFinished(-1);
64     if(proc.exitStatus() != QProcess::NormalExit)
65     {
66       std::cerr << "Fail to retrieve resource file from launchConfigureParser python module !" << std::endl;
67       return 1;
68     }
69     QByteArray val(proc.readAllStandardOutput());
70     resfile = QString::fromUtf8(val);
71   }
72   //
73   QProcess proc;
74   proc.setProcessEnvironment(pe);
75   proc.setProgram(MAIN_PROGRAM);
76
77   QStringList args({"--with","Registry","(","--salome_session","theSession",")","--with","ModuleCatalog","(","-common"});
78   QStringList catalogs;
79   for(std::size_t im = 0 ; im < sizeof(MODULES)/sizeof(decltype(MODULES[0])) ; ++im )
80   {
81     QString root_dir = pe.value( QString("%1_ROOT_DIR").arg(MODULES[im]) );
82     catalogs << QDir::toNativeSeparators( QString("%1/share/salome/resources/%2/%3Catalog.xml").arg(root_dir).arg(QString(MODULES[im]).toLower()).arg(MODULES[im]) );
83   }
84   args << catalogs.join("::");
85   args << ")";
86   args << "--with" << "SALOMEDS" <<  "(" << ")" << "--with" << "Container" << "(" << "FactoryServer" << ")" << "--with" << "SalomeAppEngine" << "(" << ")" << "CPP";
87   args << QString("--resources=%1").arg(resfile) << "--modules" << "(SHAPER:GEOM:SMESH:YACS)";
88   if( pe.contains("VERBOSE") )
89   {
90     std::cout << "Overloaded env var :" << std::endl;
91     std::cout << " - " << APPCONFIG << " = " << appconfig_val.toStdString() << std::endl;
92     std::cout << "Command launched :" << std::endl;
93     std::cout << MAIN_PROGRAM << " " << args.join(" ").toStdString() << std::endl;
94   }
95   proc.setArguments(args);
96   proc.setProcessChannelMode( QProcess::ForwardedErrorChannel );
97   proc.start();
98   proc.waitForFinished(-1);
99   return proc.exitCode();
100 }