Salome HOME
cherry-pick between a669 and 19a96 of V7_main
[tools/medcoupling.git] / src / MEDLoader / Swig / MEDLoaderCommon.i
index a5ee0a00679045af4da1ca645e89708c148566a8..b6e033ce893dad0831b2b801dbbd40552ac2dfe2 100644 (file)
@@ -624,6 +624,26 @@ namespace ParaMEDMEM
            return res;
          }
 
+         PyObject *getAllGeoTypes() const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<INTERP_KERNEL::NormalizedCellType> result(self->getAllGeoTypes());
+           std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator iL=result.begin();
+           PyObject *res=PyList_New(result.size());
+           for(int i=0;iL!=result.end(); i++, iL++)
+             PyList_SetItem(res,i,PyInt_FromLong(*iL));
+           return res;
+         }
+
+         PyObject *getGeoTypesAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
+         {
+           std::vector<INTERP_KERNEL::NormalizedCellType> result(self->getGeoTypesAtLevel(meshDimRelToMax));
+           std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator iL=result.begin();
+           PyObject *res=PyList_New(result.size());
+           for(int i=0;iL!=result.end(); i++, iL++)
+             PyList_SetItem(res,i,PyInt_FromLong(*iL));
+           return res;
+         }
+
          PyObject *getFamilyFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
          {
            const DataArrayInt *tmp=self->getFamilyFieldAtLevel(meshDimRelToMaxExt);
@@ -759,16 +779,6 @@ namespace ParaMEDMEM
          {
            return MEDFileUMesh::New();
          }
-
-         PyObject *getGeoTypesAtLevel(int meshDimRelToMax) const throw(INTERP_KERNEL::Exception)
-         {
-           std::vector<INTERP_KERNEL::NormalizedCellType> result(self->getGeoTypesAtLevel(meshDimRelToMax));
-           std::vector<INTERP_KERNEL::NormalizedCellType>::const_iterator iL=result.begin();
-           PyObject *res=PyList_New(result.size());
-           for(int i=0;iL!=result.end(); i++, iL++)
-             PyList_SetItem(res,i,PyInt_FromLong(*iL));
-           return res;
-         }
          
          PyObject *getRevNumberFieldAtLevel(int meshDimRelToMaxExt) const throw(INTERP_KERNEL::Exception)
          {
@@ -1016,7 +1026,7 @@ namespace ParaMEDMEM
          {
            if(PyInt_Check(obj))
              {
-               MEDFileMesh *ret=self->getMeshAtPos((int)PyInt_AS_LONG(obj));
+               MEDFileMesh *ret=self->getMeshAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfMeshes()));
                if(ret)
                  ret->incrRef();
                return ret;
@@ -1216,6 +1226,7 @@ namespace ParaMEDMEM
     void loadArrays() throw(INTERP_KERNEL::Exception);
     void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
     void unloadArrays() throw(INTERP_KERNEL::Exception);
+    void unloadArraysWithoutDataLoss() throw(INTERP_KERNEL::Exception);
     int getDimension() const throw(INTERP_KERNEL::Exception);
     int getIteration() const throw(INTERP_KERNEL::Exception);
     int getOrder() const throw(INTERP_KERNEL::Exception);
@@ -1632,6 +1643,7 @@ namespace ParaMEDMEM
     void loadArrays() throw(INTERP_KERNEL::Exception);
     void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
     void unloadArrays() throw(INTERP_KERNEL::Exception);
+    void unloadArraysWithoutDataLoss() throw(INTERP_KERNEL::Exception);
     //
     virtual MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception);
     MEDFileAnyTypeField1TS *getTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
@@ -1798,12 +1810,8 @@ namespace ParaMEDMEM
           {
             Py_ssize_t strt=2,stp=2,step=2;
             PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
-            if(PySlice_GetIndices(oC,self->getNumberOfTS(),&strt,&stp,&step)==0)
-              {
-                self->eraseTimeStepIds2(strt,stp,step);
-              }
-            else
-              throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
+            GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__delitem__ : error in input slice !");
+            self->eraseTimeStepIds2(strt,stp,step);
           }
         else
           {
@@ -1868,10 +1876,8 @@ namespace ParaMEDMEM
           {
             Py_ssize_t strt=2,stp=2,step=2;
             PySliceObject *oC=reinterpret_cast<PySliceObject *>(elt0);
-            if(PySlice_GetIndices(oC,self->getNumberOfTS(),&strt,&stp,&step)==0)
-              return convertMEDFileFieldMultiTS(self->buildSubPartSlice(strt,stp,step),SWIG_POINTER_OWN | 0);
-            else
-              throw INTERP_KERNEL::Exception("MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
+            GetIndicesOfSlice(oC,self->getNumberOfTS(),&strt,&stp,&step,"MEDFileAnyTypeFieldMultiTS.__getitem__ : error in input slice !");
+            return convertMEDFileFieldMultiTS(self->buildSubPartSlice(strt,stp,step),SWIG_POINTER_OWN | 0);
           }
         else
           return convertMEDFileField1TS(self->getTimeStepAtPos(MEDFileAnyTypeFieldMultiTSgetitemSingleTS__(self,elt0)),SWIG_POINTER_OWN | 0);
@@ -2216,6 +2222,7 @@ namespace ParaMEDMEM
     void loadArrays() throw(INTERP_KERNEL::Exception);
     void loadArraysIfNecessary() throw(INTERP_KERNEL::Exception);
     void unloadArrays() throw(INTERP_KERNEL::Exception);
+    void unloadArraysWithoutDataLoss() throw(INTERP_KERNEL::Exception);
     void write(const std::string& fileName, int mode) const throw(INTERP_KERNEL::Exception);
     int getNumberOfFields() const;
     std::vector<std::string> getFieldsNames() const throw(INTERP_KERNEL::Exception);
@@ -2229,6 +2236,7 @@ namespace ParaMEDMEM
     MEDFileAnyTypeFieldMultiTS *getFieldWithName(const std::string& fieldName) const throw(INTERP_KERNEL::Exception);
     MEDFileFields *partOfThisLyingOnSpecifiedMeshName(const std::string& meshName) const throw(INTERP_KERNEL::Exception);
     void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception);
+    bool removeFieldsWithoutAnyTimeStep() throw(INTERP_KERNEL::Exception);
     %extend
        {
          MEDFileFields()
@@ -2364,10 +2372,8 @@ namespace ParaMEDMEM
              {
                Py_ssize_t strt=2,stp=2,step=2;
                PySliceObject *oC=reinterpret_cast<PySliceObject *>(elts);
-               if(PySlice_GetIndices(oC,self->getNumberOfFields(),&strt,&stp,&step)==0)
-                 self->destroyFieldsAtPos2(strt,stp,step);
-               else
-                 throw INTERP_KERNEL::Exception("MEDFileFields.__delitem__ : error in input slice !");
+               GetIndicesOfSlice(oC,self->getNumberOfFields(),&strt,&stp,&step,"MEDFileFields.__delitem__ : error in input slice !");
+               self->destroyFieldsAtPos2(strt,stp,step);
              }
            else
              {
@@ -2484,6 +2490,7 @@ namespace ParaMEDMEM
     double getDoubleValue(int iteration, int order) const throw(INTERP_KERNEL::Exception);
     int getPosOfTimeStep(int iteration, int order) const throw(INTERP_KERNEL::Exception);
     int getPosGivenTime(double time, double eps=1e-8) const throw(INTERP_KERNEL::Exception);
+    int getNumberOfTS() const throw(INTERP_KERNEL::Exception);
     %extend
     {
       MEDFileParameterMultiTS()
@@ -2554,7 +2561,7 @@ namespace ParaMEDMEM
       {
         if(elt0 && PyInt_Check(elt0))
           {//fmts[3]
-            int pos=PyInt_AS_LONG(elt0);
+            int pos=InterpreteNegativeInt(PyInt_AS_LONG(elt0),self->getNumberOfTS());
             return pos;
           }
         else if(elt0 && PyTuple_Check(elt0))
@@ -2698,7 +2705,7 @@ namespace ParaMEDMEM
       {
         if(PyInt_Check(obj))
           {
-            MEDFileParameterMultiTS *ret=self->getParamAtPos((int)PyInt_AS_LONG(obj));
+            MEDFileParameterMultiTS *ret=self->getParamAtPos(InterpreteNegativeInt((int)PyInt_AS_LONG(obj),self->getNumberOfParams()));
             if(ret)
               ret->incrRef();
             return ret;
@@ -2925,6 +2932,16 @@ namespace ParaMEDMEM
         PyTuple_SetItem(ret,1,ret1Py);
         return ret;
       }
+
+      PyObject *getGeoTypes() const throw(INTERP_KERNEL::Exception)
+      {
+        std::vector< INTERP_KERNEL::NormalizedCellType > result(self->getGeoTypes());
+        std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator iL(result.begin());
+        PyObject *res(PyList_New(result.size()));
+        for(int i=0;iL!=result.end(); i++, iL++)
+          PyList_SetItem(res,i,PyInt_FromLong(*iL));
+        return res;
+      }
     }
   };
 
@@ -3019,7 +3036,21 @@ namespace ParaMEDMEM
     static MEDFileFastCellSupportComparator *New(const MEDFileMeshStruct *m, const MEDFileAnyTypeFieldMultiTS *ref) throw(INTERP_KERNEL::Exception);
     MEDMeshMultiLev *buildFromScratchDataSetSupport(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
     bool isDataSetSupportEqualToThePreviousOne(int timeStepId, const MEDFileFieldGlobsReal *globs) const throw(INTERP_KERNEL::Exception);
+    int getNumberOfTS() const throw(INTERP_KERNEL::Exception);
   protected:
     ~MEDFileFastCellSupportComparator();
+  public:
+    %extend
+    {
+      PyObject *getGeoTypesAt(int timeStepId, const MEDFileMesh *m) const throw(INTERP_KERNEL::Exception)
+      {
+        std::vector< INTERP_KERNEL::NormalizedCellType > result(self->getGeoTypesAt(timeStepId,m));
+        std::vector< INTERP_KERNEL::NormalizedCellType >::const_iterator iL(result.begin());
+        PyObject *res(PyList_New(result.size()));
+        for(int i=0;iL!=result.end(); i++, iL++)
+          PyList_SetItem(res,i,PyInt_FromLong(*iL));
+        return res;
+      }
+    }
   };
 }