From: ageay Date: Wed, 26 Jun 2013 11:57:19 +0000 (+0000) Subject: convertTo X-Git-Tag: B4CMakeModifs~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=02d69a4963b686e91129a296dce09cfadcbe9bd5;p=modules%2Fmed.git convertTo --- diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index 6342343ac..780d69bb6 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -7139,6 +7139,26 @@ void MEDFileAnyTypeFieldMultiTSWithoutSDA::appendFieldProfile(const MEDCouplingF _time_steps.push_back(obj); } +void MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration(int i, MEDCouplingAutoRefCountObjectPtr ts) throw(INTERP_KERNEL::Exception) +{ + int sz=(int)_time_steps.size(); + if(i<0 || i>=sz) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element at place #" << i << " should be in [0," << sz << ") !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + const MEDFileAnyTypeField1TSWithoutSDA *tsPtr(ts); + if(tsPtr) + { + if(tsPtr->getNumberOfComponents()!=(int)_infos.size()) + { + std::ostringstream oss; oss << "MEDFileAnyTypeFieldMultiTSWithoutSDA::setIteration : trying to set element with " << tsPtr->getNumberOfComponents() << " components ! Should be " << _infos.size() << " !"; + throw INTERP_KERNEL::Exception(oss.str().c_str()); + } + } + _time_steps[i]=ts; +} + //= MEDFileFieldMultiTSWithoutSDA MEDFileFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::New(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception) @@ -7215,16 +7235,22 @@ std::vector< std::vector > MEDFileFieldMultiTSWithoutSDA::get MEDFileIntFieldMultiTSWithoutSDA *MEDFileFieldMultiTSWithoutSDA::convertToInt() const throw(INTERP_KERNEL::Exception) { - /*MEDCouplingAutoRefCountObjectPtr ret(new MEDFileIntFieldMultiTSWithoutSDA); + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileIntFieldMultiTSWithoutSDA); ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this); - ret->deepCpyLeavesFrom(*this); - const DataArrayDouble *arr(_arr); - if(arr) + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++) { - MEDCouplingAutoRefCountObjectPtr arr2(arr->convertToIntArr()); - ret->setArray(arr2); + const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it); + if(eltToConv) + { + const MEDFileField1TSWithoutSDA *eltToConvC=dynamic_cast(eltToConv); + if(!eltToConvC) + throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type FLOAT64 !"); + MEDCouplingAutoRefCountObjectPtr elt=eltToConvC->convertToInt(); + ret->setIteration(i,elt); + } } - return ret.retn();*/ + return ret.retn(); } //= MEDFileAnyTypeFieldMultiTS @@ -7401,6 +7427,26 @@ MEDFileAnyTypeFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::createNe return new MEDFileIntFieldMultiTSWithoutSDA; } +MEDFileFieldMultiTSWithoutSDA *MEDFileIntFieldMultiTSWithoutSDA::convertToDouble() const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret(new MEDFileFieldMultiTSWithoutSDA); + ret->MEDFileAnyTypeFieldMultiTSWithoutSDA::operator =(*this); + int i=0; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_time_steps.begin();it!=_time_steps.end();it++,i++) + { + const MEDFileAnyTypeField1TSWithoutSDA *eltToConv(*it); + if(eltToConv) + { + const MEDFileIntField1TSWithoutSDA *eltToConvC=dynamic_cast(eltToConv); + if(!eltToConvC) + throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTSWithoutSDA::convertToInt : presence of an invalid 1TS type ! Should be of type INT32 !"); + MEDCouplingAutoRefCountObjectPtr elt=eltToConvC->convertToDouble(); + ret->setIteration(i,elt); + } + } + return ret.retn(); +} + //= MEDFileAnyTypeFieldMultiTS /*! @@ -8274,6 +8320,35 @@ MEDFileIntFieldMultiTS *MEDFileIntFieldMultiTS::New(const MEDFileIntFieldMultiTS return new MEDFileIntFieldMultiTS(other,shallowCopyOfContent); } +/*! + * This method performs a copy with datatype modification ( int32->float64 ) of \a this. The globals information are copied + * following the given input policy. + * + * \param [in] deepCpyGlobs - a boolean that indicates the behaviour concerning globals (profiles and localizations) + * By default (true) the globals are deeply copied. + * \return MEDFileFieldMultiTS * - a new object that is the result of the conversion of \a this to float64 field. + */ +MEDFileFieldMultiTS *MEDFileIntFieldMultiTS::convertToDouble(bool deepCpyGlobs) const throw(INTERP_KERNEL::Exception) +{ + MEDCouplingAutoRefCountObjectPtr ret; + const MEDFileAnyTypeFieldMultiTSWithoutSDA *content(_content); + if(content) + { + const MEDFileIntFieldMultiTSWithoutSDA *contc=dynamic_cast(content); + if(!contc) + throw INTERP_KERNEL::Exception("MEDFileIntFieldMultiTS::convertToInt : the content inside this is not INT32 ! This is incoherent !"); + MEDCouplingAutoRefCountObjectPtr newc(contc->convertToDouble()); + ret=static_cast(MEDFileAnyTypeFieldMultiTS::BuildNewInstanceFromContent((MEDFileFieldMultiTSWithoutSDA *)newc,getFileName())); + } + else + ret=MEDFileFieldMultiTS::New(); + if(deepCpyGlobs) + ret->deepCpyGlobs(*this); + else + ret->shallowCpyGlobs(*this); + return ret.retn(); +} + MEDFileAnyTypeFieldMultiTS *MEDFileIntFieldMultiTS::shallowCpy() const throw(INTERP_KERNEL::Exception) { return new MEDFileIntFieldMultiTS(*this); diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index dcb0253aa..ad1f8970c 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -809,6 +809,7 @@ namespace ParaMEDMEM std::vector getLocsReallyUsedMulti2() const; void changePflsRefsNamesGen2(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); void changeLocsRefsNamesGen2(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); + void setIteration(int i, MEDCouplingAutoRefCountObjectPtr ts) throw(INTERP_KERNEL::Exception); protected: virtual med_field_type getMEDFileFieldType() const = 0; void copyTinyInfoFrom(const MEDCouplingFieldDouble *field, const DataArray *arr) throw(INTERP_KERNEL::Exception); @@ -850,6 +851,7 @@ namespace ParaMEDMEM const char *getTypeStr() const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeFieldMultiTSWithoutSDA *shallowCpy() const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeFieldMultiTSWithoutSDA *createNew() const throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTSWithoutSDA *convertToDouble() const throw(INTERP_KERNEL::Exception); protected: MEDFileIntFieldMultiTSWithoutSDA(const char *fieldName); MEDFileIntFieldMultiTSWithoutSDA(med_idt fid, const char *fieldName, med_field_type fieldTyp, const std::vector& infos, int nbOfStep, const std::string& dtunit) throw(INTERP_KERNEL::Exception); @@ -989,6 +991,7 @@ std::vector< std::vector > getFieldSplitedByType2(int iterati MEDFileAnyTypeFieldMultiTS *shallowCpy() const throw(INTERP_KERNEL::Exception); void checkCoherencyOfType(const MEDFileAnyTypeField1TS *f1ts) const throw(INTERP_KERNEL::Exception); MEDFileAnyTypeField1TS *getTimeStepAtPos(int pos) const throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *convertToDouble(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); // MEDCouplingFieldDouble *getFieldAtLevel(TypeOfField type, int iteration, int order, int meshDimRelToMax, DataArrayInt* &arrOut, int renumPol=0) const throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldAtTopLevel(TypeOfField type, int iteration, int order, DataArrayInt* &arrOut, int renumPol=0) const throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index 7b6c5d3ca..b4589c03e 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -132,8 +132,10 @@ using namespace ParaMEDMEM; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldOnMeshAtLevel; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getFieldAtLevelOld; %newobject ParaMEDMEM::MEDFileFieldMultiTS::getUndergroundDataArray; +%newobject ParaMEDMEM::MEDFileFieldMultiTS::convertToInt; %newobject ParaMEDMEM::MEDFileIntFieldMultiTS::New; %newobject ParaMEDMEM::MEDFileIntFieldMultiTS::getUndergroundDataArray; +%newobject ParaMEDMEM::MEDFileIntFieldMultiTS::convertToDouble; %newobject ParaMEDMEM::MEDFileAnyTypeField1TS::New; %newobject ParaMEDMEM::MEDFileAnyTypeField1TS::shallowCpy; @@ -1790,6 +1792,7 @@ namespace ParaMEDMEM // void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field) throw(INTERP_KERNEL::Exception); void appendFieldProfile(const MEDCouplingFieldDouble *field, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + MEDFileIntFieldMultiTS *convertToInt(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); %extend { MEDFileFieldMultiTS() @@ -1920,6 +1923,7 @@ namespace ParaMEDMEM // void appendFieldNoProfileSBT(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals) throw(INTERP_KERNEL::Exception); void appendFieldProfile(const MEDCouplingFieldDouble *field, const DataArrayInt *arrOfVals, const MEDFileMesh *mesh, int meshDimRelToMax, const DataArrayInt *profile) throw(INTERP_KERNEL::Exception); + MEDFileFieldMultiTS *convertToDouble(bool deepCpyGlobs=true) const throw(INTERP_KERNEL::Exception); %extend { MEDFileIntFieldMultiTS()