From 48e4c7ce1280a1fa3f96e8c64b7bc31d5fcf801e Mon Sep 17 00:00:00 2001 From: ageay Date: Mon, 16 Sep 2013 15:26:22 +0000 Subject: [PATCH] MEDCouplingMeshClient::New in swig --- .../Client/MEDCouplingClient.i | 68 +++++++++++++++++++ .../MEDCouplingCorbaSwigTestServ.py | 5 +- .../TestMEDCouplingCorbaClt.py | 3 +- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i index 842590f42..ce5383f4d 100644 --- a/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i +++ b/src/MEDCouplingCorba_Swig/Client/MEDCouplingClient.i @@ -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: diff --git a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py index 81904317f..916079b79 100644 --- a/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py +++ b/src/MEDCouplingCorba_Swig/MEDCouplingCorbaSwigTestServ.py @@ -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() diff --git a/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py b/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py index dcad42675..c62011d94 100644 --- a/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py +++ b/src/MEDCouplingCorba_Swig/TestMEDCouplingCorbaClt.py @@ -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() -- 2.39.2