]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
MEDCouplingMeshClient::New in swig
authorageay <ageay>
Mon, 16 Sep 2013 15:26:22 +0000 (15:26 +0000)
committerageay <ageay>
Mon, 16 Sep 2013 15:26:22 +0000 (15:26 +0000)
src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i
src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py
src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py

index 842590f429cf0005bf4ff5eccd306b496cb6b30a..ce5383f4d6eebd79c46a8beafe066630aeb1a753 100644 (file)
@@ -188,6 +188,74 @@ namespace ParaMEDMEM
       }
   };
 
+  class MEDCouplingMeshClient
+  {
+  public:
+    %extend
+      {
+        static MEDCouplingMesh *New(PyObject *meshPtr) throw(INTERP_KERNEL::Exception)
+        {
+          PyObject* pdict=PyDict_New();
+          PyDict_SetItemString(pdict,"__builtins__",PyEval_GetBuiltins());
+          PyRun_String("import MEDCouplingCorbaServant_idl",Py_single_input,pdict, pdict);
+          PyRun_String("import CORBA",Py_single_input,pdict, pdict);
+          PyRun_String("orbTmp15634=CORBA.ORB_init([''])", Py_single_input,pdict, pdict);
+          PyObject *orbPython=PyDict_GetItemString(pdict,"orbTmp15634");
+          // Ask omniORBpy to transform SUPPORT (python Corba) ptr to IOR string
+          PyObject *iorMesh=PyObject_CallMethod(orbPython,(char*)"object_to_string",(char*)"O",meshPtr);
+          if(!iorMesh)
+            throw INTERP_KERNEL::Exception("Error : the input parameter of MEDCouplingMeshClient.New appears to differ from CORBA reference ! Expecting a MeshCorbaInterface CORBA reference !");
+          char *ior=PyString_AsString(iorMesh);
+          int argc=0;
+          CORBA::ORB_var orb=CORBA::ORB_init(argc,0);
+          CORBA::Object_var meshPtrCpp=orb->string_to_object(ior);
+          SALOME_MED::MEDCouplingUMeshCorbaInterface_var meshPtrCppC1=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC1))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCouplingUMeshClient::New(meshPtrCppC1);
+            }
+          SALOME_MED::MEDCouplingCMeshCorbaInterface_var meshPtrCppC2=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC2))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCouplingCMeshClient::New(meshPtrCppC2);
+            }
+          SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_var meshPtrCppC3=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC3))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCouplingCurveLinearMeshClient::New(meshPtrCppC3);
+            }
+          SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface_var meshPtrCppC4=SALOME_MED::MEDCoupling1SGTUMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC4))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCoupling1SGTUMeshClient::New(meshPtrCppC4);
+            }
+          SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface_var meshPtrCppC5=SALOME_MED::MEDCoupling1DGTUMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC5))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCoupling1DGTUMeshClient::New(meshPtrCppC5);
+            }
+          SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface_var meshPtrCppC6=SALOME_MED::MEDCouplingExtrudedMeshCorbaInterface::_narrow(meshPtrCpp);
+          if(!CORBA::is_nil(meshPtrCppC6))
+            {
+              Py_DECREF(pdict);
+              Py_DECREF(iorMesh);
+              return MEDCouplingExtrudedMeshClient::New(meshPtrCppC6);
+            }
+          throw INTERP_KERNEL::Exception("Error input corba pointer is not a managed mesh type !");
+        } 
+      }
+  };
+
   class MEDCouplingUMeshClient
   {
   public:
index 81904317fa6bf2fc67b2c2496704049ddf7b8aac..916079b79260da17b705074c40cd17df2084dbba 100644 (file)
@@ -38,8 +38,11 @@ class MEDCouplingMeshFieldFactoryComponentPy(MEDCouplingCorbaServantTest_idl._0_
         self._orb.shutdown(0)
 
     def get1DMesh(self):
+        import SALOME_MED
         mesh=self._test.build1DMesh()
-        return MEDCouplingUMeshServant._this(mesh)
+        ret=MEDCouplingUMeshServant._this(mesh)
+        assert isinstance(ret,SALOME_MED._objref_MEDCouplingUMeshCorbaInterface)
+        return ret
     
     def get2DMesh(self):
         mesh=self._test.build2DMesh()
index dcad42675037ee2089c135fd277a923a56c58c18..c62011d94e3101d6f276e0e98d4e45f17f8a2982 100644 (file)
@@ -34,8 +34,9 @@ class MEDCouplingCorbaServBasicsTestClt(unittest.TestCase):
     def testContentOfFetched1DMesh(self):
         meshPtr=self._objC.get1DMesh();
         self.assertEqual("1DMeshForCorba",meshPtr.getName());
-        _mesh_from_distant=MEDCouplingUMeshClient.New(meshPtr);
+        _mesh_from_distant=MEDCouplingMeshClient.New(meshPtr);
         meshPtr.UnRegister();
+        self.assertTrue(isinstance(_mesh_from_distant,MEDCouplingUMesh))
         self.assertTrue(_mesh_from_distant.getSpaceDimension()==3);
         self.assertTrue(_mesh_from_distant.getMeshDimension()==1);
         test=MEDCouplingCorbaSwigTest.MEDCouplingCorbaServBasicsTest()