Salome HOME
Copyright update 2021
[modules/gui.git] / src / Session / salome2810.cxx
1 // Copyright (C) 2021  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 NO_SERVER_ENV_VAR[] = "SALOME_EMB_SERVANT";
30   const char *MODULES[]={"SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","HEXOTICPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
31   const char *MODULES_PATH[]={"GUI","SHAPER","SHAPERSTUDY","GEOM","SMESH","HYBRIDPLUGIN","GHS3DPLUGIN","BLSURFPLUGIN","GMSHPLUGIN","HEXABLOCKPLUGIN","GHS3DPRLPLUGIN","NETGENPLUGIN"};
32   constexpr char APPCONFIG[]="SalomeAppSLConfig";
33   QProcessEnvironment pe(QProcessEnvironment::systemEnvironment());
34   QStringList modulesPaths;
35   for(auto elt : MODULES_PATH)
36   {
37     QString elt_root_dir( QString("%1_ROOT_DIR").arg(elt) );
38     if( !pe.contains(elt_root_dir) || pe.value(elt_root_dir).isEmpty() )
39     {
40       std::cerr << elt_root_dir.toStdString() << " is not defined in your environment !" << std::endl;
41       return 1;
42     }
43     modulesPaths << QDir::fromNativeSeparators( QString("%1/share/salome/resources/%2").arg( pe.value(elt_root_dir) ).arg( QString(elt).toLower() ) );
44   }
45   // fill LightAppConfig env var
46   QString appconfig_val( modulesPaths.join(":"));
47   pe.insert(APPCONFIG,appconfig_val);
48   //tells shutup to salome.salome_init invoked at shaper engine ignition
49   pe.insert(NO_SERVER_ENV_VAR,"1");
50   //resource file retrieve
51   QString resfile;
52   {
53     QProcess proc;
54     proc.setProcessEnvironment(pe);
55     proc.setProgram("python3");
56     proc.setArguments({"-c","from launchConfigureParser import userFile ; import sys ; sys.stdout.write(userFile(\"SalomeApp\",\"salome\"))"});
57     proc.start();
58     proc.waitForFinished(-1);
59     if(proc.exitStatus() != QProcess::NormalExit)
60     {
61       std::cerr << "Fail to retrieve resource file from launchConfigureParser python module !" << std::endl;
62       return 1;
63     }
64     QByteArray val(proc.readAllStandardOutput());
65     resfile = QString::fromUtf8(val);
66   }
67   //
68   QProcess proc;
69   proc.setProcessEnvironment(pe);
70   proc.setProgram(MAIN_PROGRAM);
71
72   QStringList args({"--with","Registry","(","--salome_session","theSession",")","--with","ModuleCatalog","(","-common"});
73   QStringList catalogs;
74   for(std::size_t im = 0 ; im < sizeof(MODULES)/sizeof(decltype(MODULES[0])) ; ++im )
75   {
76     QString root_dir = pe.value( QString("%1_ROOT_DIR").arg(MODULES[im]) );
77     catalogs << QDir::toNativeSeparators( QString("%1/share/salome/resources/%2/%3Catalog.xml").arg(root_dir).arg(QString(MODULES[im]).toLower()).arg(MODULES[im]) );
78   }
79   args << catalogs.join("::");
80   args << ")";
81   args << "--with" << "SALOMEDS" <<  "(" << ")" << "--with" << "Container" << "(" << "FactoryServer" << ")" << "--with" << "SalomeAppEngine" << "(" << ")" << "CPP";
82   args << QString("--resources=%1").arg(resfile) << "--modules" << "(SHAPER:GEOM:SMESH)";
83   if( pe.contains("VERBOSE") )
84   {
85     std::cout << "Overloaded env var :" << std::endl;
86     std::cout << " - " << NO_SERVER_ENV_VAR << std::endl;
87     std::cout << " - " << APPCONFIG << " = " << appconfig_val.toStdString() << std::endl;
88     std::cout << "Command launched :" << std::endl;
89     std::cout << MAIN_PROGRAM << " " << args.join(" ").toStdString() << std::endl;
90   }
91   proc.setArguments(args);
92   proc.setProcessChannelMode( QProcess::ForwardedErrorChannel );
93   proc.start();
94   proc.waitForFinished(-1);
95   return proc.exitCode();
96 }