Salome HOME
Addition of MEDFileUMesh.__getitem__ in python bindings to ease fetch of MEDCouplingU...
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderCommon.i
index 3b44ba2183613c50e738073676d5b31e3d383b92..f9143b5a8d3efb8d93f9ffb5b45b6f32cd145578 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -95,7 +95,9 @@ using namespace ParaMEDMEM;
 %newobject ParaMEDMEM::MEDFileMesh::computeAllFamilyIdsInUse;
 %newobject ParaMEDMEM::MEDFileStructuredMesh::getImplicitFaceMesh;
 %newobject ParaMEDMEM::MEDFileUMesh::New;
+%newobject ParaMEDMEM::MEDFileUMesh::LoadPartOf;
 %newobject ParaMEDMEM::MEDFileUMesh::getCoords;
+%newobject ParaMEDMEM::MEDFileUMesh::getPartDefAtLevel;
 %newobject ParaMEDMEM::MEDFileUMesh::getGroup;
 %newobject ParaMEDMEM::MEDFileUMesh::getGroups;
 %newobject ParaMEDMEM::MEDFileUMesh::getFamily;
@@ -109,6 +111,8 @@ using namespace ParaMEDMEM;
 %newobject ParaMEDMEM::MEDFileUMesh::extractFamilyFieldOnGeoType;
 %newobject ParaMEDMEM::MEDFileUMesh::extractNumberFieldOnGeoType;
 %newobject ParaMEDMEM::MEDFileUMesh::zipCoords;
+%newobject ParaMEDMEM::MEDFileUMesh::buildExtrudedMesh;
+%newobject ParaMEDMEM::MEDFileUMesh::__getitem__;
 %newobject ParaMEDMEM::MEDFileCMesh::New;
 %newobject ParaMEDMEM::MEDFileCurveLinearMesh::New;
 %newobject ParaMEDMEM::MEDFileMeshMultiTS::New;
@@ -122,6 +126,7 @@ using namespace ParaMEDMEM;
 %newobject ParaMEDMEM::MEDFileMeshes::__iter__;
 
 %newobject ParaMEDMEM::MEDFileFields::New;
+%newobject ParaMEDMEM::MEDFileFields::LoadPartOf;
 %newobject ParaMEDMEM::MEDFileFields::deepCpy;
 %newobject ParaMEDMEM::MEDFileFields::shallowCpy;
 %newobject ParaMEDMEM::MEDFileFields::getFieldWithName;
@@ -603,6 +608,13 @@ namespace ParaMEDMEM
            PyList_SetItem(res,1,PyString_FromString(what.c_str()));
            return res;
          }
+
+         void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<const DataArrayInt *> grps;
+           convertFromPyObjVectorOfObj<const ParaMEDMEM::DataArrayInt *>(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",grps);
+           self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum);
+         }
          
          PyObject *areFamsEqual(const MEDFileMesh *other) const throw(INTERP_KERNEL::Exception)
          {
@@ -663,6 +675,14 @@ namespace ParaMEDMEM
              tmp->incrRef();
            return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
          }
+
+         PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+         {
+           const DataArrayInt *tmp=self->getRevNumberFieldAtLevel(meshDimRelToMaxExt);
+           if(tmp)
+             tmp->incrRef();
+           return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+         }
          
          PyObject *getNameFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
          {
@@ -726,6 +746,7 @@ namespace ParaMEDMEM
     static MEDFileUMesh *New();
     ~MEDFileUMesh();
     int getSpaceDimension() const throw(INTERP_KERNEL::Exception);
+    int getRelativeLevOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception);
     //
     std::vector<int> getGrpNonEmptyLevels(const std::string& grp) const throw(INTERP_KERNEL::Exception);
     std::vector<int> getGrpNonEmptyLevelsExt(const std::string& grp) const throw(INTERP_KERNEL::Exception);
@@ -737,17 +758,10 @@ namespace ParaMEDMEM
     std::vector<int> getFamsNonEmptyLevelsExt(const std::vector<std::string>& fams) const throw(INTERP_KERNEL::Exception);
     std::vector<std::string> getGroupsOnSpecifiedLev(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getGroup(int meshDimRelToMaxExt, const std::string& grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getGroupArr(int meshDimRelToMaxExt, const std::string& grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getGroups(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getGroupsArr(int meshDimRelToMaxExt, const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getFamily(int meshDimRelToMaxExt, const std::string& fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getFamilyArr(int meshDimRelToMaxExt, const std::string& fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getFamilies(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getFamiliesArr(int meshDimRelToMaxExt, const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getNodeGroupArr(const std::string& grp, bool renum=false) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *getNodeGroupsArr(const std::vector<std::string>& grps, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getNodeFamilyArr(const std::string& fam, bool renum=false) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *getNodeFamiliesArr(const std::vector<std::string>& fams, bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getMeshAtLevel(int meshDimRelToMaxExt, bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getLevel0Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
     MEDCouplingUMesh *getLevelM1Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
@@ -755,6 +769,7 @@ namespace ParaMEDMEM
     MEDCouplingUMesh *getLevelM3Mesh(bool renum=false) const throw(INTERP_KERNEL::Exception);
     void forceComputationOfParts() const throw(INTERP_KERNEL::Exception);
     //
+    int getNumberOfCellsAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception);
     void setFamilyNameAttachedOnId(int id, const std::string& newFamName) throw(INTERP_KERNEL::Exception);
     void setCoords(DataArrayDouble *coords) throw(INTERP_KERNEL::Exception);
     void eraseGroupsAtLevel(int meshDimRelToMaxExt) throw(INTERP_KERNEL::Exception);
@@ -767,6 +782,7 @@ namespace ParaMEDMEM
     DataArrayInt *zipCoords() throw(INTERP_KERNEL::Exception);
     DataArrayInt *extractFamilyFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception);
     DataArrayInt *extractNumberFieldOnGeoType(INTERP_KERNEL::NormalizedCellType gt) const throw(INTERP_KERNEL::Exception);
+    MEDFileUMesh *buildExtrudedMesh(const MEDCouplingUMesh *m1D, int policy) const throw(INTERP_KERNEL::Exception);
     %extend
        { 
          MEDFileUMesh(const std::string& fileName, const std::string& mName, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception)
@@ -783,20 +799,111 @@ namespace ParaMEDMEM
          {
            return MEDFileUMesh::New();
          }
-         
-         PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+
+         // serialization
+         static PyObject *___new___(PyObject *cls, PyObject *args) throw(INTERP_KERNEL::Exception)
          {
-           const DataArrayInt *tmp=self->getRevNumberFieldAtLevel(meshDimRelToMaxExt);
-           if(tmp)
-             tmp->incrRef();
-           return SWIG_NewPointerObj(SWIG_as_voidptr(tmp),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 );
+           return NewMethWrapCallInitOnlyIfEmptyDictInInput(cls,args,"MEDFileUMesh");
          }
-         
-         void setGroupsAtLevel(int meshDimRelToMaxExt, PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
+
+         static MEDFileUMesh *LoadPartOf(const std::string& fileName, const std::string& mName, PyObject *types, const std::vector<int>& slicPerTyp, int dt=-1, int it=-1, MEDFileMeshReadSelector *mrs=0) throw(INTERP_KERNEL::Exception)
          {
-           std::vector<const DataArrayInt *> grps;
-           convertFromPyObjVectorOfObj<const ParaMEDMEM::DataArrayInt *>(li,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",grps);
-           self->setGroupsAtLevel(meshDimRelToMaxExt,grps,renum);
+           std::vector<int> typesCpp1;
+           convertPyToNewIntArr3(types,typesCpp1);
+           std::size_t sz(typesCpp1.size());
+           std::vector<INTERP_KERNEL::NormalizedCellType> typesCpp2(sz);
+           for(std::size_t ii=0;ii<sz;ii++)
+             typesCpp2[ii]=(INTERP_KERNEL::NormalizedCellType)typesCpp1[ii];
+           return MEDFileUMesh::LoadPartOf(fileName,mName,typesCpp2,slicPerTyp,dt,it,mrs);
+         }
+
+         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;
+         }
+
+         PyObject *__getstate__() throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<double> a0;
+           std::vector<int> a1;
+           std::vector<std::string> a2;
+           std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a3;
+           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a4;
+           self->serialize(a0,a1,a2,a3,a4);
+           PyObject *ret(PyTuple_New(5));
+           PyTuple_SetItem(ret,0,convertDblArrToPyList2(a0));
+           PyTuple_SetItem(ret,1,convertIntArrToPyList2(a1));
+           int sz(a2.size());
+           PyObject *ret2(PyList_New(sz));
+           for(int i=0;i<sz;i++)
+             PyList_SetItem(ret2,i,PyString_FromString(a2[i].c_str()));
+           PyTuple_SetItem(ret,2,ret2);
+           sz=a3.size();
+           PyObject *ret3(PyList_New(sz));
+           for(int i=0;i<sz;i++)
+             {
+               DataArrayInt *elt(a3[i]);
+               if(elt)
+                 elt->incrRef();
+               PyList_SetItem(ret3,i,SWIG_NewPointerObj(SWIG_as_voidptr(elt),SWIGTYPE_p_ParaMEDMEM__DataArrayInt, SWIG_POINTER_OWN | 0 ));
+             }
+           PyTuple_SetItem(ret,3,ret3);
+           DataArrayDouble *ret4(a4);
+           if(ret4)
+             ret4->incrRef();
+           PyTuple_SetItem(ret,4,SWIG_NewPointerObj(SWIG_as_voidptr(ret4),SWIGTYPE_p_ParaMEDMEM__DataArrayDouble, SWIG_POINTER_OWN | 0 ));
+           return ret;
+         }
+
+         void __setstate__(PyObject *inp) throw(INTERP_KERNEL::Exception)
+         {
+           static const char MSG[]="MEDFileUMesh.__setstate__ : expected input is a tuple of size 4 !";
+           if(!PyTuple_Check(inp))
+             throw INTERP_KERNEL::Exception(MSG);
+           int sz(PyTuple_Size(inp));
+           if(sz!=5)
+             throw INTERP_KERNEL::Exception(MSG);
+           std::vector<double> a0;
+           std::vector<int> a1;
+           std::vector<std::string> a2;
+           std::vector< MEDCouplingAutoRefCountObjectPtr<DataArrayInt> > a3;
+           MEDCouplingAutoRefCountObjectPtr<DataArrayDouble> a4;
+           //
+           PyObject *a0py(PyTuple_GetItem(inp,0)),*a1py(PyTuple_GetItem(inp,1)),*a2py(PyTuple_GetItem(inp,2));
+           int tmp(-1);
+           fillArrayWithPyListDbl3(a0py,tmp,a0);
+           convertPyToNewIntArr3(a1py,a1);
+           fillStringVector(a2py,a2);
+           //
+           PyObject *b0py(PyTuple_GetItem(inp,3)),*b1py(PyTuple_GetItem(inp,4));
+           void *argp(0);
+           int status(SWIG_ConvertPtr(b1py,&argp,SWIGTYPE_p_ParaMEDMEM__DataArrayDouble,0|0));
+           if(!SWIG_IsOK(status))
+             throw INTERP_KERNEL::Exception(MSG);
+           a4=reinterpret_cast<DataArrayDouble *>(argp);
+           if((DataArrayDouble *)a4)
+             a4->incrRef();
+           {
+             std::vector< DataArrayInt * > a3Tmp;
+             convertFromPyObjVectorOfObj<ParaMEDMEM::DataArrayInt *>(b0py,SWIGTYPE_p_ParaMEDMEM__DataArrayInt,"DataArrayInt",a3Tmp);
+             std::size_t sz(a3Tmp.size());
+             a3.resize(sz);
+             for(std::size_t i=0;i<sz;i++)
+               {
+                 a3[i]=a3Tmp[i];
+                 if(a3Tmp[i])
+                   a3Tmp[i]->incrRef();
+               }
+             self->unserialize(a0,a1,a2,a3,a4);
+           }
+         }
+
+         MEDCouplingUMesh *__getitem__(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
+         {
+           return self->getMeshAtLevel(meshDimRelToMaxExt,false);
          }
 
          void setMeshes(PyObject *li, bool renum=false) throw(INTERP_KERNEL::Exception)
@@ -828,6 +935,14 @@ namespace ParaMEDMEM
            return ret;
          }
 
+         PartDefinition *getPartDefAtLevel(int meshDimRelToMaxExt, INTERP_KERNEL::NormalizedCellType gt=INTERP_KERNEL::NORM_ERROR) const throw(INTERP_KERNEL::Exception)
+         {
+           const PartDefinition *ret(self->getPartDefAtLevel(meshDimRelToMaxExt,gt));
+           if(ret)
+             ret->incrRef();
+           return const_cast<PartDefinition *>(ret);
+         }
+
          PyObject *duplicateNodesOnM1Group(const std::string& grpNameM1) throw(INTERP_KERNEL::Exception)
          {
            DataArrayInt *ret0=0,*ret1=0,*ret2=0;
@@ -1255,6 +1370,7 @@ namespace ParaMEDMEM
     bool isDealingTS(int iteration, int order) const throw(INTERP_KERNEL::Exception);
     void setInfo(const std::vector<std::string>& infos) throw(INTERP_KERNEL::Exception);
     const std::vector<std::string>& getInfo() const throw(INTERP_KERNEL::Exception);
+    bool presenceOfMultiDiscPerGeoType() const throw(INTERP_KERNEL::Exception);
     void setTime(int iteration, int order, double val) throw(INTERP_KERNEL::Exception);
     virtual MEDFileAnyTypeField1TS *shallowCpy() const throw(INTERP_KERNEL::Exception);
     MEDFileAnyTypeField1TS *deepCpy() const throw(INTERP_KERNEL::Exception);
@@ -1371,6 +1487,16 @@ namespace ParaMEDMEM
           PyList_SetItem(retPy,i,convertMEDFileField1TS(ret[i].retn(), SWIG_POINTER_OWN | 0 ));
         return retPy;
       }
+
+      PyObject *splitMultiDiscrPerGeoTypes() const throw(INTERP_KERNEL::Exception)
+      {
+        std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeField1TS > > ret=self->splitMultiDiscrPerGeoTypes();
+        std::size_t sz=ret.size();
+        PyObject *retPy=PyList_New(sz);
+        for(std::size_t i=0;i<sz;i++)
+          PyList_SetItem(retPy,i,convertMEDFileField1TS(ret[i].retn(), SWIG_POINTER_OWN | 0 ));
+        return retPy;
+      }
     }
   };
 
@@ -1649,6 +1775,7 @@ namespace ParaMEDMEM
     std::string getMeshName() const throw(INTERP_KERNEL::Exception);
     void setMeshName(const std::string& newMeshName) throw(INTERP_KERNEL::Exception);
     const std::vector<std::string>& getInfo() const throw(INTERP_KERNEL::Exception);
+    bool presenceOfMultiDiscPerGeoType() const throw(INTERP_KERNEL::Exception);
     int getNumberOfComponents() const throw(INTERP_KERNEL::Exception);
     int getNumberOfTS() const throw(INTERP_KERNEL::Exception);
     void eraseEmptyTS() throw(INTERP_KERNEL::Exception);
@@ -1924,6 +2051,16 @@ namespace ParaMEDMEM
         return retPy;
       }
 
+      PyObject *splitMultiDiscrPerGeoTypes() const throw(INTERP_KERNEL::Exception)
+      {
+        std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileAnyTypeFieldMultiTS > > ret=self->splitMultiDiscrPerGeoTypes();
+        std::size_t sz=ret.size();
+        PyObject *retPy=PyList_New(sz);
+        for(std::size_t i=0;i<sz;i++)
+          PyList_SetItem(retPy,i,convertMEDFileFieldMultiTS(ret[i].retn(), SWIG_POINTER_OWN | 0 ));
+        return retPy;
+      }
+
       void pushBackTimeSteps(PyObject *li) throw(INTERP_KERNEL::Exception)
       {
         std::vector<MEDFileAnyTypeField1TS *> tmp;
@@ -2232,6 +2369,7 @@ namespace ParaMEDMEM
   public:
     static MEDFileFields *New() throw(INTERP_KERNEL::Exception);
     static MEDFileFields *New(const std::string& fileName, bool loadAll=true) throw(INTERP_KERNEL::Exception);
+    static MEDFileFields *LoadPartOf(const std::string& fileName, bool loadAll=true, const MEDFileMeshes *ms=0) throw(INTERP_KERNEL::Exception);
     MEDFileFields *deepCpy() const throw(INTERP_KERNEL::Exception);
     MEDFileFields *shallowCpy() const throw(INTERP_KERNEL::Exception);
     void loadArrays() throw(INTERP_KERNEL::Exception);
@@ -2841,7 +2979,7 @@ namespace ParaMEDMEM
   {
   public:
     static SauvReader* New(const std::string& fileName) throw(INTERP_KERNEL::Exception);
-    MEDFileData * loadInMEDFileDS(bool keep2DOri=false) throw(INTERP_KERNEL::Exception);
+    MEDFileData * loadInMEDFileDS() throw(INTERP_KERNEL::Exception);
     %extend
     {
       SauvReader(const std::string& fileName) throw(INTERP_KERNEL::Exception)