1 // Copyright (C) 2010-2014 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: Adrien Bruneton (CEA)
21 #include "PVViewer_EngineWrapper.h"
22 #include <Utils_SALOME_Exception.hxx>
24 PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL;
26 PVViewer_EngineWrapper::PVViewer_EngineWrapper() :
29 // const char * cmd = "import PARAVIS_utils;e=";
31 const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()";
32 int ret = PyRun_SimpleString(const_cast<char*>(code));
35 throw SALOME_Exception("Unable to retrieve PARAVIS engine!");
37 // Now get the reference to __engine and save the pointer.
38 PyObject* main_module = PyImport_AddModule((char*)"__main__");
39 PyObject* global_dict = PyModule_GetDict(main_module);
40 PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS"));
45 PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance()
48 instance = new PVViewer_EngineWrapper();
52 bool PVViewer_EngineWrapper::GetGUIConnected()
55 PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL));
59 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
61 return PyObject_IsTrue(obj);
64 void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected)
68 PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"),
69 (char *)"i", (int)isConnected ) );
73 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
77 std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port)
81 PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"),
82 (char *)"i", port ) );
86 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
88 char * s = PyString_AsString(obj);
90 return std::string(s);