1 // Copyright (C) 2010-2015 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 #include <SUIT_Session.h>
25 #include <PyInterp_Utils.h>
27 class PVViewer_EngineWrapper::Private
30 PyObjWrapper pvserverEngine;
33 PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL;
35 PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance()
38 instance = new PVViewer_EngineWrapper();
42 PVViewer_EngineWrapper::PVViewer_EngineWrapper()
46 const char* code = "import PVSERVER_utils as pa;__enginePVSERVER=pa.getEngine()";
47 int ret = PyRun_SimpleString(const_cast<char*>(code));
50 throw SALOME_Exception("Unable to retrieve PVSERVER engine!");
52 // Now get the reference to __engine and save the pointer.
53 PyObject* main_module = PyImport_AddModule((char*)"__main__");
54 PyObject* global_dict = PyModule_GetDict(main_module);
55 PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePVSERVER"));
56 myData->pvserverEngine = tmp;
59 PVViewer_EngineWrapper::~PVViewer_EngineWrapper()
64 bool PVViewer_EngineWrapper::GetGUIConnected()
67 PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("GetGUIConnected"), NULL));
71 throw SALOME_Exception("Unable to invoke PVSERVER engine!");
73 return PyObject_IsTrue(obj);
76 void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected)
80 PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("SetGUIConnected"),
81 (char *)"i", (int)isConnected ) );
85 throw SALOME_Exception("Unable to invoke PVSERVER service!");
89 std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port)
92 PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("FindOrStartPVServer"),
93 (char *)"i", port ) );
97 throw SALOME_Exception("Unable to invoke PVSERVER service!");
99 char * s = PyString_AsString(obj);
101 return std::string(s);
104 void PVViewer_EngineWrapper::PutPythonTraceStringToEngine(const char * str)
107 PyObjWrapper obj(PyObject_CallMethod(myData->pvserverEngine, (char*)("PutPythonTraceStringToEngine"),
112 throw SALOME_Exception("Unable to invoke PVSERVER service!");