1 // Copyright (C) 2011-2016 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Guillaume Boulant (EDF)
21 #include "XmedConsoleDriver.hxx"
22 #include "Utils_SALOME_Exception.hxx"
23 #include "MEDModule.hxx"
24 #include "MEDCommandsHistoryManager_i.hxx"
25 #include "MEDFactoryClient.hxx"
26 #include CORBA_CLIENT_HEADER(MED_Gen)
27 #include CORBA_CLIENT_HEADER(MEDCommandsHistoryManager)
29 XmedConsoleDriver::XmedConsoleDriver(MEDModule* salomeModule)
31 _salomeModule = salomeModule;
32 bool forcePythonConsole = true;
33 _pyConsole = _salomeModule->getApp()->pythonConsole(forcePythonConsole);
35 const char * msg = "The python console can't be obtained from the SALOME application";
36 throw SALOME_Exception(msg);
38 _importXmedDone = false;
42 * This function sends instructions to the python console to setup the
43 * environment for med operations (in particular, it imports the medcalc
44 * commands). Even if the function is called twice, then the
45 * instructions are sent once.
47 void XmedConsoleDriver::setup() {
49 if ( !_importXmedDone ) {
51 #ifndef DISABLE_PVVIEWER
52 // start PVServer and show render view
53 commands+="import pvsimple as pvs";
55 //commands+="pvs.ShowParaviewView()";
57 commands += "import medcalc";
58 commands += "medcalc.medconsole.setConsoleGlobals(globals())";
59 commands += "import MEDCALC";
61 commands += "from medcalc.medconsole import saveWorkspace, cleanWorkspace";
62 commands += "from medcalc.medconsole import putInWorkspace, removeFromWorkspace";
63 commands += "from medcalc.medconsole import accessField";
64 commands += "from medcalc.medconsole import getEnvironment, ls, la";
67 _importXmedDone = true;
72 * This function sends the specified list of commands to the console.
74 void XmedConsoleDriver::exec(const QStringList& commands) {
75 MEDCALC::MEDCommandsHistoryManager_ptr history = MEDFactoryClient::getCommandsHistoryManager();
77 QStringListIterator it(commands);
79 while (it.hasNext()) {
80 const QString& command = it.next();
81 _pyConsole->exec(command);
82 // store command in history
83 history->addCommand(command.toStdString().c_str());