From 539d6194edde2a96b1d6b402590410dd9f575c04 Mon Sep 17 00:00:00 2001 From: abn Date: Mon, 13 Oct 2014 13:48:16 +0200 Subject: [PATCH] PVViewer_EnginWrapper is now implemented using CORBA dynamic invokation mechanism rather than relying on Python. --- src/PVViewer/PVViewer_EngineWrapper.cxx | 158 +++++++++++++++++------- src/PVViewer/PVViewer_EngineWrapper.h | 19 ++- src/PVViewer/PVViewer_GUIElements.cxx | 2 + src/SalomeApp/SalomeApp_PyInterp.cxx | 2 +- src/Session/SALOME_Session_Server.cxx | 6 +- 5 files changed, 134 insertions(+), 53 deletions(-) diff --git a/src/PVViewer/PVViewer_EngineWrapper.cxx b/src/PVViewer/PVViewer_EngineWrapper.cxx index 708d6bc9f..24f026f31 100644 --- a/src/PVViewer/PVViewer_EngineWrapper.cxx +++ b/src/PVViewer/PVViewer_EngineWrapper.cxx @@ -21,26 +21,10 @@ #include "PVViewer_EngineWrapper.h" #include -PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL; - -PVViewer_EngineWrapper::PVViewer_EngineWrapper() : - paravisEngine(NULL) -{ -// const char * cmd = "import PARAVIS_utils;e="; - PyLockWrapper lock; - const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()"; - int ret = PyRun_SimpleString(const_cast(code)); - - if (ret == -1) - throw SALOME_Exception("Unable to retrieve PARAVIS engine!"); - - // Now get the reference to __engine and save the pointer. - PyObject* main_module = PyImport_AddModule((char*)"__main__"); - PyObject* global_dict = PyModule_GetDict(main_module); - PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS")); - paravisEngine = tmp; -} +#include +#include +PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL; PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance() { @@ -49,43 +33,123 @@ PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance() return instance; } +static SalomeApp_Application* getApplication() +{ + if ( SUIT_Session::session() ) + return dynamic_cast( SUIT_Session::session()->activeApplication() ); + return 0; +} + +PVViewer_EngineWrapper::PVViewer_EngineWrapper() +// : paravisEngine(NULL) +{ + _component = getApplication()->lcc()->FindOrLoad_Component( "FactoryServer", "PARAVIS" ); +} + bool PVViewer_EngineWrapper::GetGUIConnected() { - PyLockWrapper lock; - PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL)); - if (!obj) - { - PyErr_Print(); - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - } - return PyObject_IsTrue(obj); + CORBA::Request_var req = _component->_request("GetGUIConnected"); + req->set_return_type(CORBA::_tc_boolean); + req->invoke(); + CORBA::Exception *exc =req->env()->exception(); + if( exc ) + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); + CORBA::Any & ret = req->return_value(); + CORBA::Boolean bo; + + if (ret >>= bo) + return bool(bo); + else + throw SALOME_Exception("Unable to convert engine result!"); } void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected) { - PyLockWrapper lock; - - PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"), - (char *)"i", (int)isConnected ) ); - if (!obj) - { - PyErr_Print(); - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - } + CORBA::Request_var req = _component->_request("SetGUIConnected"); + CORBA::Boolean arg = isConnected; + req->add_in_arg() <<= arg; + req->set_return_type(CORBA::_tc_void); + req->invoke(); + CORBA::Exception *exc =req->env()->exception(); + if( exc ) + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); } std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port) { - PyLockWrapper lock; - - PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"), - (char *)"i", port ) ); - if (!obj) - { - PyErr_Print(); - throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - } - char * s = PyString_AsString(obj); + CORBA::Request_var req = _component->_request("FindOrStartPVServer"); + CORBA::Long arg = port; + req->add_in_arg() <<= arg; + req->set_return_type(CORBA::_tc_string); + req->invoke(); + CORBA::Exception *exc =req->env()->exception(); + if( exc ) + throw SALOME_Exception("Unable to invoke PARAVIS engine!"); - return std::string(s); + const char* ret; + if(req->return_value() >>= ret) + return std::string(ret); + else + throw SALOME_Exception("Unable to convert engine result!"); } + +//PVViewer_EngineWrapper::PVViewer_EngineWrapper() : +// paravisEngine(NULL) +//{ +//// const char * cmd = "import PARAVIS_utils;e="; +// PyLockWrapper lock; +// const char* code = "import PARAVIS_utils as pa;__enginePARAVIS=pa.getEngine()"; +// int ret = PyRun_SimpleString(const_cast(code)); +// +// if (ret == -1) +// throw SALOME_Exception("Unable to retrieve PARAVIS engine!"); +// +// // Now get the reference to __engine and save the pointer. +// PyObject* main_module = PyImport_AddModule((char*)"__main__"); +// PyObject* global_dict = PyModule_GetDict(main_module); +// PyObjWrapper tmp(PyDict_GetItemString(global_dict, "__enginePARAVIS")); +// paravisEngine = tmp; +//} +// +// +// +//bool PVViewer_EngineWrapper::GetGUIConnected() +//{ +// PyLockWrapper lock; +// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("GetGUIConnected"), NULL)); +// if (!obj) +// { +// PyErr_Print(); +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); +// } +// return PyObject_IsTrue(obj); +//} +// +//void PVViewer_EngineWrapper::SetGUIConnected(bool isConnected) +//{ +// PyLockWrapper lock; +// +// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("SetGUIConnected"), +// (char *)"i", (int)isConnected ) ); +// if (!obj) +// { +// PyErr_Print(); +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); +// } +//} +// +//std::string PVViewer_EngineWrapper::FindOrStartPVServer(int port) +//{ +// PyLockWrapper lock; +// +// PyObjWrapper obj(PyObject_CallMethod(paravisEngine, (char*)("FindOrStartPVServer"), +// (char *)"i", port ) ); +// if (!obj) +// { +// PyErr_Print(); +// throw SALOME_Exception("Unable to invoke PARAVIS engine!"); +// } +// char * s = PyString_AsString(obj); +// +// return std::string(s); +//} diff --git a/src/PVViewer/PVViewer_EngineWrapper.h b/src/PVViewer/PVViewer_EngineWrapper.h index 328e120c8..b0c5f4db1 100644 --- a/src/PVViewer/PVViewer_EngineWrapper.h +++ b/src/PVViewer/PVViewer_EngineWrapper.h @@ -21,16 +21,27 @@ #ifndef PVVIEWERENGINEWRAPPER_H_ #define PVVIEWERENGINEWRAPPER_H_ -#include +//#include #include +#include +#include +#include +#include CORBA_SERVER_HEADER(SALOME_ModuleCatalog) +#include CORBA_SERVER_HEADER(SALOMEDS) + + /*! * Class facilitating the access to the PARAVIS engine without having to link - * to it. + * to it. Documentation of the method is found in the PARAVIS module (in the idl directory). + * + * (Two implementations are provided: one with CORBA dynamic invokation from C++, one using + * Python - see commented elements in the .cxx file) */ class PVViewer_EngineWrapper { public: + //! Returns the unique instance of the engine. static PVViewer_EngineWrapper * GetInstance(); bool GetGUIConnected(); @@ -42,7 +53,9 @@ private: virtual ~PVViewer_EngineWrapper() {} static PVViewer_EngineWrapper * instance; - PyObjWrapper paravisEngine; + Engines::EngineComponent_var _component; + + //PyObjWrapper paravisEngine; }; #endif /* PVVIEWERENGINEWRAPPER_H_ */ diff --git a/src/PVViewer/PVViewer_GUIElements.cxx b/src/PVViewer/PVViewer_GUIElements.cxx index 57e1c1582..ff139e682 100644 --- a/src/PVViewer/PVViewer_GUIElements.cxx +++ b/src/PVViewer/PVViewer_GUIElements.cxx @@ -36,7 +36,9 @@ PVViewer_GUIElements::PVViewer_GUIElements(SUIT_Desktop* desk) : sourcesMenu(0) { propertiesPanel = new pqPropertiesPanel(desk); + propertiesPanel->hide(); pipelineBrowserWidget = new pqPipelineBrowserWidget(desk); + pipelineBrowserWidget->hide(); sourcesMenu = new QMenu(desk); pqParaViewMenuBuilders::buildSourcesMenu(*sourcesMenu, desk); diff --git a/src/SalomeApp/SalomeApp_PyInterp.cxx b/src/SalomeApp/SalomeApp_PyInterp.cxx index 1107c03a3..ad228cb3e 100755 --- a/src/SalomeApp/SalomeApp_PyInterp.cxx +++ b/src/SalomeApp/SalomeApp_PyInterp.cxx @@ -78,7 +78,7 @@ int SalomeApp_PyInterp::beforeRun() if (ret) return ret; } - return true; + return PyConsole_EnhInterp::beforeRun(); } void SalomeApp_PyInterp::initStudy() diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 65284c93d..4d34b5e58 100755 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -653,9 +653,11 @@ int main( int argc, char **argv ) init->explicit_destroy(); // After ORB destruction - PyGILState_Ensure(); if(Py_IsInitialized()) - Py_Finalize(); + { + PyGILState_Ensure(); + Py_Finalize(); + } if ( shutdownAll ) killOmniNames(); -- 2.39.2