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 #include <SalomeApp_Application.h>
25 #include <SUIT_Session.h>
27 PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL;
29 PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance()
32 instance = new PVViewer_EngineWrapper();
36 static SalomeApp_Application* getApplication()
38 if ( SUIT_Session::session() )
39 return dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
43 PVViewer_EngineWrapper::PVViewer_EngineWrapper()
44 // : paravisEngine(NULL)
46 _component = getApplication()->lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" );
49 bool PVViewer_EngineWrapper::GetGUIConnected()
51 CORBA::Request_var req = _component->_request("GetGUIConnected");
52 req->set_return_type(CORBA::_tc_boolean);
54 CORBA::Exception *exc =req->env()->exception();
56 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
57 CORBA::Any & ret = req->return_value();
63 throw SALOME_Exception("Unable to convert engine result!");
66 void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected)
68 CORBA::Request_var req = _component->_request("SetGUIConnected");
69 CORBA::Boolean arg = isConnected;
70 req->add_in_arg() <<= arg;
71 req->set_return_type(CORBA::_tc_void);
73 CORBA::Exception *exc =req->env()->exception();
75 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
78 std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port)
80 CORBA::Request_var req = _component->_request("FindOrStartPVServer");
81 CORBA::Long arg = port;
82 req->add_in_arg() <<= arg;
83 req->set_return_type(CORBA::_tc_string);
85 CORBA::Exception *exc =req->env()->exception();
87 throw SALOME_Exception("Unable to invoke PARAVIS engine!");
90 if(req->return_value() >>= ret)
91 return std::string(ret);
93 throw SALOME_Exception("Unable to convert engine result!");
96 //PVViewer_EngineWrapper::PVViewer_EngineWrapper() :
97 // paravisEngine(NULL)
99 //// const char * cmd = "import PARAVIS_utils;e=";
100 // PyLockWrapper lock;
101 // const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()";
102 // int ret = PyRun_SimpleString(const_cast<char*>(code));
105 // throw SALOME_Exception("Unable to retrieve PARAVIS engine!");
107 // // Now get the reference to __engine and save the pointer.
108 // PyObject* main_module = PyImport_AddModule((char*)"__main__");
109 // PyObject* global_dict = PyModule_GetDict(main_module);
110 // PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS"));
111 // paravisEngine = tmp;
116 //bool PVViewer_EngineWrapper::GetGUIConnected()
118 // PyLockWrapper lock;
119 // PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL));
123 // throw SALOME_Exception("Unable to invoke PARAVIS engine!");
125 // return PyObject_IsTrue(obj);
128 //void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected)
130 // PyLockWrapper lock;
132 // PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"),
133 // (char *)"i", (int)isConnected ) );
137 // throw SALOME_Exception("Unable to invoke PARAVIS engine!");
141 //std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port)
143 // PyLockWrapper lock;
145 // PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"),
146 // (char *)"i", port ) );
150 // throw SALOME_Exception("Unable to invoke PARAVIS engine!");
152 // char * s = PyString_AsString(obj);
154 // return std::string(s);