]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
MEDCouplingFieldDouble.__getitem__ on components
authorageay <ageay>
Wed, 10 Apr 2013 11:01:20 +0000 (11:01 +0000)
committerageay <ageay>
Wed, 10 Apr 2013 11:01:20 +0000 (11:01 +0000)
src/MEDCoupling_Swig/MEDCouplingCommon.i
src/MEDCoupling_Swig/MEDCouplingMemArray.i

index a75fb9b6750faa1453f1ffdd5843a7b973390065..a8c98fc41301dc4ab37bb284f301afb2fcc2e7b5 100644 (file)
@@ -3290,7 +3290,57 @@ namespace ParaMEDMEM
 
       MEDCouplingFieldDouble *__getitem__(PyObject *li) const throw(INTERP_KERNEL::Exception)
       {
-        return ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,li);
+        const char msg[]="MEDCouplingFieldDouble::__getitem__ : invalid call  Available API are : \n-myField[dataArrayInt]\n-myField[slice]\n-myField[pythonListOfCellIds]\n-myField[integer]\n-myField[dataArrayInt,1]\n-myField[slice,1]\n-myField[pythonListOfCellIds,1]\n-myField[integer,1]\n";
+        if(PyTuple_Check(li))
+          {
+            Py_ssize_t sz=PyTuple_Size(li);
+            if(sz!=2)
+              throw INTERP_KERNEL::Exception(msg);
+            PyObject *elt0=PyTuple_GetItem(li,0),*elt1=PyTuple_GetItem(li,1);
+            int sw;
+            int singleVal;
+            std::vector<int> multiVal;
+            std::pair<int, std::pair<int,int> > slic;
+            ParaMEDMEM::DataArrayInt *daIntTyypp=0;
+            if(!self->getArray())
+              throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array set on field to deduce number of components !");
+            try
+              { convertObjToPossibleCpp2(elt1,self->getArray()->getNumberOfComponents(),sw,singleVal,multiVal,slic,daIntTyypp); }
+            catch(INTERP_KERNEL::Exception& e)
+              { std::ostringstream oss; oss << "MEDCouplingFieldDouble::__getitem__ : invalid type in 2nd parameter (compo) !" << e.what(); throw INTERP_KERNEL::Exception(oss.str().c_str()); }
+            MEDCouplingAutoRefCountObjectPtr<MEDCouplingFieldDouble> ret0=ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,elt0);
+            DataArrayDouble *ret0Arr=ret0->getArray();
+            if(!ret0Arr)
+              throw INTERP_KERNEL::Exception("MEDCouplingFieldDouble::__getitem__ : no array exists to apply restriction on component on it !");
+            switch(sw)
+              {
+              case 1:
+                {
+                  std::vector<int> v2(1,singleVal);
+                  ret0->setArray(ret0Arr->keepSelectedComponents(v2));
+                  return ret0.retn();
+                }
+              case 2:
+                {
+                  ret0->setArray(ret0Arr->keepSelectedComponents(multiVal));
+                  return ret0.retn();
+                }
+              case 3:
+                {
+                  int nbOfComp=(slic.second.first-1-slic.first)/slic.second.second+1;
+                  std::vector<int> v2(nbOfComp);
+                  for(int i=0;i<nbOfComp;i++)
+                    v2[i]=slic.first+i*slic.second.second;
+                  ret0->setArray(ret0Arr->keepSelectedComponents(v2));
+                  return ret0.retn();
+                }
+              default:
+                throw INTERP_KERNEL::Exception(msg);
+              }
+            
+          }
+        else
+          return ParaMEDMEM_MEDCouplingFieldDouble_buildSubPart(self,li);
       }
 
       PyObject *getMaxValue2() const throw(INTERP_KERNEL::Exception)
index 2c3e1944c38cea00c0eb299f49831cb39e9b4d3f..e2b5417ea12fc65a31c97926529adaff85a1072b 100644 (file)
@@ -123,7 +123,6 @@ namespace ParaMEDMEM
     void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception);
     void transpose() throw(INTERP_KERNEL::Exception);
     DataArrayDouble *changeNbOfComponents(int newNbOfComp, double dftValue) const throw(INTERP_KERNEL::Exception);
-    DataArrayDouble *keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception);
     void meldWith(const DataArrayDouble *other) throw(INTERP_KERNEL::Exception);
     DataArrayDouble *duplicateEachTupleNTimes(int nbTimes) const throw(INTERP_KERNEL::Exception);
     DataArrayDouble *getDifferentValues(double prec, int limitTupleId=-1) const throw(INTERP_KERNEL::Exception);
@@ -2123,7 +2122,6 @@ namespace ParaMEDMEM
     void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception);
     void transpose() throw(INTERP_KERNEL::Exception);
     DataArrayInt *changeNbOfComponents(int newNbOfComp, int dftValue) const throw(INTERP_KERNEL::Exception);
-    DataArrayInt *keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception);
     void meldWith(const DataArrayInt *other) throw(INTERP_KERNEL::Exception);
     void setPartOfValues1(const DataArrayInt *a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp, bool strictCompoCompare=true) throw(INTERP_KERNEL::Exception);
     void setPartOfValuesSimple1(int a, int bgTuples, int endTuples, int stepTuples, int bgComp, int endComp, int stepComp) throw(INTERP_KERNEL::Exception);
@@ -4424,7 +4422,6 @@ namespace ParaMEDMEM
     void rearrange(int newNbOfCompo) throw(INTERP_KERNEL::Exception);
     DataArrayChar *substr(int tupleIdBg, int tupleIdEnd=-1) const throw(INTERP_KERNEL::Exception);
     DataArrayChar *changeNbOfComponents(int newNbOfComp, char dftValue) const throw(INTERP_KERNEL::Exception);
-    DataArrayChar *keepSelectedComponents(const std::vector<int>& compoIds) const throw(INTERP_KERNEL::Exception);
     void meldWith(const DataArrayChar *other) throw(INTERP_KERNEL::Exception);
     void setPartOfValuesAdv(const DataArrayChar *a, const DataArrayChar *tuplesSelec) throw(INTERP_KERNEL::Exception);
     char back() const throw(INTERP_KERNEL::Exception);