]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
On the road for pickelization of MEDCouplingMesh.
authorAnthony Geay <anthony.geay@edf.fr>
Tue, 10 Mar 2015 08:04:51 +0000 (09:04 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 10 Mar 2015 08:04:51 +0000 (09:04 +0100)
src/MEDCoupling_Swig/MEDCoupling.i
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingFinalize.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i

index 02eb0c7680e76ee358fa6110116e664620b414be..42c77253b4bd9e190e71331cc5056f4a3b746570 100644 (file)
@@ -107,6 +107,9 @@ def ParaMEDMEMDenseMatrixIadd(self,*args):
 def ParaMEDMEMDenseMatrixIsub(self,*args):
     import _MEDCoupling
     return _MEDCoupling.DenseMatrix____isub___(self, self, *args)
+def ParaMEDMEMMEDCouplingUMeshnew(cls,*args):
+    import _MEDCoupling
+    return _MEDCoupling.MEDCouplingUMesh____new___(cls,args)
 %}
 
 %include "MEDCouplingFinalize.i"
index 6c161e3ecd522b1182942e457f1534320806c7f2..08654c59d0c878422fdb1be1ef49129158080e7f 100644 (file)
@@ -611,7 +611,7 @@ namespace ParaMEDMEM
            PyList_SetItem(res,2,SWIG_From_int(tmp2));
            return res;
          }
-
+         
          int getCellContainingPoint(PyObject *p, double eps) const throw(INTERP_KERNEL::Exception)
          {
            double val;
@@ -1013,6 +1013,60 @@ namespace ParaMEDMEM
            std::vector<std::string> littleStrings;
            self->resizeForUnserialization(tinyInfo,a1,a2,littleStrings);
          }
+
+         PyObject *__getstate__() const throw(INTERP_KERNEL::Exception)
+         {
+           PyObject *ret0(ParaMEDMEM_MEDCouplingMesh_getTinySerializationInformation(self));
+           PyObject *ret1(ParaMEDMEM_MEDCouplingMesh_serialize(self));
+           PyObject *ret(PyTuple_New(2));
+           PyTuple_SetItem(ret,0,ret0);
+           PyTuple_SetItem(ret,1,ret1);
+           return ret;
+         }
+
+         void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+         {
+           static const char MSG[]="MEDCouplingMesh.__setstate__ : expected input is a tuple of size 2 !";
+           if(!PyTuple_Check(inp))
+             throw INTERP_KERNEL::Exception(MSG);
+           int sz(PyTuple_Size(inp));
+           if(sz!=2)
+             throw INTERP_KERNEL::Exception(MSG);
+           PyObject *elt0(PyTuple_GetItem(inp,0));
+           PyObject *elt1(PyTuple_GetItem(inp,1));
+           std::vector<double> a0;
+           std::vector<int> a1;
+           std::vector<std::string> a2;
+           DataArrayInt *b0(0);
+           DataArrayDouble *b1(0);
+           {
+             if(!PyTuple_Check(elt0) && PyTuple_Size(elt0)!=3)
+               throw INTERP_KERNEL::Exception(MSG);
+             PyObject *a0py(PyTuple_GetItem(elt0,0)),*a1py(PyTuple_GetItem(elt0,1)),*a2py(PyTuple_GetItem(elt0,2));
+             int tmp(-1);
+             fillArrayWithPyListDbl3(a0py,tmp,a0);
+             convertPyToNewIntArr3(a1py,a1);
+             fillStringVector(a2py,a2);
+           }
+           {
+             if(!PyTuple_Check(elt1) && PyTuple_Size(elt1)!=2)
+               throw INTERP_KERNEL::Exception(MSG);
+             PyObject *b0py(PyTuple_GetItem(elt1,0)),*b1py(PyTuple_GetItem(elt1,1));
+             void *argp(0);
+             int status(SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,0|0));
+             if(!SWIG_IsOK(status))
+               throw INTERP_KERNEL::Exception(MSG);
+             b0=reinterpret_cast<DataArrayInt *>(argp);
+             status=SWIG_ConvertPtr(b0py,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0);
+             if(!SWIG_IsOK(status))
+               throw INTERP_KERNEL::Exception(MSG);
+             b1=reinterpret_cast<DataArrayDouble *>(argp);
+           }
+           //
+           std::vector<std::string> uselessVector;
+           self->resizeForUnserialization(a1,b0,b1,uselessVector);
+           self->unserialization(a0,a1,b0,b1,a2);
+         }
          
          static MEDCouplingMesh *MergeMeshes(PyObject *li) throw(INTERP_KERNEL::Exception)
          {
@@ -1741,6 +1795,43 @@ namespace ParaMEDMEM
       {
         return MEDCouplingUMesh::New(meshName,meshDim);
       }
+
+      // serialization
+      static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
+      {
+        static const char MSG[]="MEDCouplingUMesh.__new__ : the args in input is expected to be a tuple !";
+        if(!PyTuple_Check(args))
+          throw INTERP_KERNEL::Exception(MSG);
+        PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
+        PyObject *obj(PyDict_GetItemString(builtinsd,"object"));//borrowed
+        PyObject *selfMeth(PyObject_GetAttrString(obj,"__new__"));
+        //
+        PyObject *tmp0(PyTuple_New(1));
+        PyTuple_SetItem(tmp0,0,cls); Py_XINCREF(cls);
+        PyObject *instance(PyObject_CallObject(selfMeth,tmp0));
+        Py_DECREF(tmp0);
+        Py_DECREF(selfMeth);
+        PyObject *initMeth(PyObject_GetAttrString(instance,"__init__"));
+        int sz(PyTuple_Size(args));
+        
+        if(PyTuple_Size(args)==2 && PyDict_Size(PyTuple_GetItem(args,1))==0 )
+          {// NOT general case. only true if in unpickeling context ! call __init__. Because for all other cases, __init__ is called right after __new__ !
+            PyObject *tmp3(PyTuple_New(0));
+            PyObject *tmp2(PyObject_CallObject(initMeth,tmp3));
+            Py_XDECREF(tmp2);
+            Py_DECREF(tmp3);
+          }
+        Py_DECREF(initMeth);
+        return instance;
+      }
+
+      PyObject *__getnewargs__() throw(INTERP_KERNEL::Exception)
+      {// put an empty dict in input to say to __new__ to call __init__...
+        PyObject *ret(PyTuple_New(1));
+        PyObject *ret0(PyDict_New());
+        PyTuple_SetItem(ret,0,ret0);
+        return ret;
+      }
       
       std::string __str__() const throw(INTERP_KERNEL::Exception)
       {
index 12502f150fbb1ae57cbb448b6e6a35f8c7dbe7af..89a6769b91f3051d61661c023a868ae189bb7d06 100644 (file)
@@ -53,6 +53,8 @@ DataArrayIntTuple.__imod__=ParaMEDMEMDataArrayIntTupleImod
 DenseMatrix.__iadd__=ParaMEDMEMDenseMatrixIadd
 DenseMatrix.__isub__=ParaMEDMEMDenseMatrixIsub
 
+MEDCouplingUMesh.__new__=classmethod(ParaMEDMEMMEDCouplingUMeshnew)
+
 del ParaMEDMEMDataArrayDoublenew
 del ParaMEDMEMDataArrayDoubleIadd
 del ParaMEDMEMDataArrayDoubleIsub
index ef598e15644e446a27c3ae13fc388499ce703eda..cbf759e945755fe6064eab5c4539f43502cd33de 100644 (file)
@@ -2213,7 +2213,7 @@ namespace ParaMEDMEM
       // serialization
       static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
       {
-        static const char MSG[]="DataArrayDouble.__new__ : the args in input is expected to be a tuple of size 2 !";
+        static const char MSG[]="DataArrayDouble.__new__ : the args in input is expected to be a tuple !";
         if(!PyTuple_Check(args))
           throw INTERP_KERNEL::Exception(MSG);
         PyObject *builtinsd(PyEval_GetBuiltins());//borrowed
@@ -4570,7 +4570,7 @@ namespace ParaMEDMEM
       // serialization
       static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
       {
-        static const char MSG[]="DataArrayInt.__new__ : the args in input is expected to be a tuple of size 2 !";
+        static const char MSG[]="DataArrayInt.__new__ : the args in input is expected to be a tuple !";
         if(!PyTuple_Check(args))
           throw INTERP_KERNEL::Exception(MSG);
         PyObject *builtinsd(PyEval_GetBuiltins());//borrowed