]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
PVViewer_EnginWrapper is now implemented using CORBA dynamic invokation
authorabn <adrien.bruneton@cea.fr>
Mon, 13 Oct 2014 11:48:16 +0000 (13:48 +0200)
committerabn <adrien.bruneton@cea.fr>
Mon, 13 Oct 2014 11:48:16 +0000 (13:48 +0200)
mechanism rather than relying on Python.

src/PVViewer/PVViewer_EngineWrapper.cxx
src/PVViewer/PVViewer_EngineWrapper.h
src/PVViewer/PVViewer_GUIElements.cxx
src/SalomeApp/SalomeApp_PyInterp.cxx
src/Session/SALOME_Session_Server.cxx

index 708d6bc9f7b075834cd7d0a9f9bf9deddc7d7172..24f026f31e44d552b656b0774cf48ec6b48dbf27 100644 (file)
 #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()
 {
@@ -49,43 +33,123 @@ 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);
+//}
index 328e120c81bc9b37487c5b9b1a154a421a8bf3d5..b0c5f4db1f44e7954094f8994b12eb17797fd5ea 100644 (file)
 #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();
@@ -42,7 +53,9 @@ private:
   virtual ~PVViewer_EngineWrapper() {}
 
   static PVViewer_EngineWrapper * instance;
-  PyObjWrapper paravisEngine;
+  Engines::EngineComponent_var _component;
+
+  //PyObjWrapper paravisEngine;
 };
 
 #endif /* PVVIEWERENGINEWRAPPER_H_ */
index 57e1c158212368ad9e6bdb50db8884f5effa629f..ff139e682c2cff50d2983a86526ccdd9238db051 100644 (file)
@@ -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);
index 1107c03a36c6f8aee88052f18fac9233800efd5d..ad228cb3ec5f8d352ff4ad1da8365405b1ac567b 100755 (executable)
@@ -78,7 +78,7 @@ int SalomeApp_PyInterp::beforeRun()
     if (ret)
       return ret;
   }
-  return true;
+  return PyConsole_EnhInterp::beforeRun();
 }
 
 void SalomeApp_PyInterp::initStudy()
index 65284c93d644cf0f2b84c1f852b844b010d9e782..4d34b5e5822f4c08160cc49bb2b8ca8d13929900 100755 (executable)
@@ -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();