From c9a923f96c3a003d18148a0e6add86a8458caf3c Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 10 Apr 2013 11:01:20 +0000 Subject: [PATCH] MEDCouplingFieldDouble.__getitem__ on components --- src/MEDCoupling_Swig/MEDCouplingCommon.i | 52 +++++++++++++++++++++- src/MEDCoupling_Swig/MEDCouplingMemArray.i | 3 -- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/MEDCoupling_Swig/MEDCouplingCommon.i b/src/MEDCoupling_Swig/MEDCouplingCommon.i index a75fb9b67..a8c98fc41 100644 --- a/src/MEDCoupling_Swig/MEDCouplingCommon.i +++ b/src/MEDCoupling_Swig/MEDCouplingCommon.i @@ -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 multiVal; + std::pair > 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 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 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 v2(nbOfComp); + for(int i=0;isetArray(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) diff --git a/src/MEDCoupling_Swig/MEDCouplingMemArray.i b/src/MEDCoupling_Swig/MEDCouplingMemArray.i index 2c3e1944c..e2b5417ea 100644 --- a/src/MEDCoupling_Swig/MEDCouplingMemArray.i +++ b/src/MEDCoupling_Swig/MEDCouplingMemArray.i @@ -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& 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& 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& 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); -- 2.39.2