#include "PVViewer_EngineWrapper.h"
#include <Utils_SALOME_Exception.hxx>
-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<char*>(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 <SalomeApp_Application.h>
+#include <SUIT_Session.h>
+PVViewer_EngineWrapper * PVViewer_EngineWrapper::instance = NULL;
PVViewer_EngineWrapper * PVViewer_EngineWrapper::GetInstance()
{
return instance;
}
+static SalomeApp_Application* getApplication()
+{
+ if ( SUIT_Session::session() )
+ return dynamic_cast<SalomeApp_Application*>( 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<char*>(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);
+//}
#ifndef PVVIEWERENGINEWRAPPER_H_
#define PVVIEWERENGINEWRAPPER_H_
-#include <PyInterp_Utils.h>
+//#include <PyInterp_Utils.h>
#include <string>
+#include <SALOMEconfig.h>
+#include <SALOME_LifeCycleCORBA.hxx>
+#include <SALOMEDS_SObject.hxx>
+#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();
virtual ~PVViewer_EngineWrapper() {}
static PVViewer_EngineWrapper * instance;
- PyObjWrapper paravisEngine;
+ Engines::EngineComponent_var _component;
+
+ //PyObjWrapper paravisEngine;
};
#endif /* PVVIEWERENGINEWRAPPER_H_ */