From f083385e63057d61078215120151ab34d6827b1a Mon Sep 17 00:00:00 2001 From: ageay Date: Fri, 13 Jul 2012 17:34:52 +0000 Subject: [PATCH] MEDFileField1TS::setMeshName MEDFileFieldMultiTS::setMeshName, MEDFileData::changeMeshName, MEDFileData::changeMeshNames --- src/MEDLoader/MEDFileData.cxx | 20 +++++++ src/MEDLoader/MEDFileData.hxx | 3 + src/MEDLoader/MEDFileField.cxx | 77 ++++++++++++++++++++++++++ src/MEDLoader/MEDFileField.hxx | 9 ++- src/MEDLoader/MEDFileMesh.cxx | 45 +++++++++++++++ src/MEDLoader/MEDFileMesh.hxx | 4 ++ src/MEDLoader/Swig/MEDLoaderCommon.i | 29 ++++++++++ src/MEDLoader/Swig/MEDLoaderTypemaps.i | 39 ++++++++++++- 8 files changed, 224 insertions(+), 2 deletions(-) diff --git a/src/MEDLoader/MEDFileData.cxx b/src/MEDLoader/MEDFileData.cxx index f82a56dac..0e8131a04 100644 --- a/src/MEDLoader/MEDFileData.cxx +++ b/src/MEDLoader/MEDFileData.cxx @@ -96,6 +96,26 @@ std::string MEDFileData::simpleRepr() const return oss.str(); } +bool MEDFileData::changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + MEDFileFields *fields=_fields; + if(fields) + ret=fields->changeMeshNames(modifTab) || ret; + MEDFileMeshes *meshes=_meshes; + if(meshes) + ret=meshes->changeNames(modifTab) || ret; + return ret; +} + +bool MEDFileData::changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception) +{ + std::string oldName(oldMeshName); + std::vector< std::pair > v(1); + v[0].first=oldName; v[0].second=newMeshName; + return changeMeshNames(v); +} + MEDFileData::MEDFileData() { } diff --git a/src/MEDLoader/MEDFileData.hxx b/src/MEDLoader/MEDFileData.hxx index b7a4a5c7a..a6e9f0b71 100644 --- a/src/MEDLoader/MEDFileData.hxx +++ b/src/MEDLoader/MEDFileData.hxx @@ -42,6 +42,9 @@ namespace ParaMEDMEM int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; // + bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); + bool changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception); + // void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); private: MEDFileData(); diff --git a/src/MEDLoader/MEDFileField.cxx b/src/MEDLoader/MEDFileField.cxx index b25aac5d2..dbdff70f1 100644 --- a/src/MEDLoader/MEDFileField.cxx +++ b/src/MEDLoader/MEDFileField.cxx @@ -1439,6 +1439,19 @@ std::vector MEDFileFieldPerMesh::getLocsReallyUsedMulti() const return ret; } +bool MEDFileFieldPerMesh::changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + for(std::vector< std::pair >::const_iterator it=modifTab.begin();it!=modifTab.end();it++) + { + if((*it).first==_mesh_name) + { + _mesh_name=(*it).second; + return true; + } + } + return false; +} + void MEDFileFieldPerMesh::changePflsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception) { for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMeshPerType > >::iterator it=_field_pm_pt.begin();it!=_field_pm_pt.end();it++) @@ -2689,6 +2702,26 @@ std::string MEDFileField1TSWithoutDAS::getMeshName() const throw(INTERP_KERNEL:: return _field_per_mesh[0]->getMeshName(); } +void MEDFileField1TSWithoutDAS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception) +{ + std::string oldName(getMeshName()); + std::vector< std::pair > v(1); + v[0].first=oldName; v[0].second=newMeshName; + changeMeshNames(v); +} + +bool MEDFileField1TSWithoutDAS::changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr< MEDFileFieldPerMesh > >::iterator it=_field_per_mesh.begin();it!=_field_per_mesh.end();it++) + { + MEDFileFieldPerMesh *cur(*it); + if(cur) + ret=cur->changeMeshNames(modifTab) || ret; + } + return ret; +} + int MEDFileField1TSWithoutDAS::getMeshIteration() const throw(INTERP_KERNEL::Exception) { if(_field_per_mesh.empty()) @@ -3639,6 +3672,26 @@ std::string MEDFileFieldMultiTSWithoutDAS::getMeshName() const throw(INTERP_KERN return _time_steps[0]->getMeshName(); } +void MEDFileFieldMultiTSWithoutDAS::setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception) +{ + std::string oldName(getMeshName()); + std::vector< std::pair > v(1); + v[0].first=oldName; v[0].second=newMeshName; + changeMeshNames(v); +} + +bool MEDFileFieldMultiTSWithoutDAS::changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_time_steps.begin();it!=_time_steps.end();it++) + { + MEDFileField1TSWithoutDAS *cur(*it); + if(cur) + ret=cur->changeMeshNames(modifTab) || ret; + } + return ret; +} + std::string MEDFileFieldMultiTSWithoutDAS::getDtUnit() const throw(INTERP_KERNEL::Exception) { if(_time_steps.empty()) @@ -4376,6 +4429,18 @@ std::vector MEDFileFields::getFieldsNames() const throw(INTERP_KERN return ret; } +std::vector MEDFileFields::getMeshesNames() const throw(INTERP_KERNEL::Exception) +{ + std::vector ret; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::const_iterator it=_fields.begin();it!=_fields.end();it++) + { + const MEDFileFieldMultiTSWithoutDAS *cur(*it); + if(cur) + ret.push_back(cur->getMeshName()); + } + return ret; +} + std::string MEDFileFields::simpleRepr() const { std::ostringstream oss; @@ -4584,6 +4649,18 @@ void MEDFileFields::destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception) _fields.erase(_fields.begin()+i); } +bool MEDFileFields::changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_fields.begin();it!=_fields.end();it++) + { + MEDFileFieldMultiTSWithoutDAS *cur(*it); + if(cur) + ret=cur->changeMeshNames(modifTab) || ret; + } + return ret; +} + MEDFileFieldMultiTS *MEDFileFields::getFieldAtPos(int i) const throw(INTERP_KERNEL::Exception) { if(i<0 || i>=(int)_fields.size()) diff --git a/src/MEDLoader/MEDFileField.hxx b/src/MEDLoader/MEDFileField.hxx index a9b8c32ba..676aa0630 100644 --- a/src/MEDLoader/MEDFileField.hxx +++ b/src/MEDLoader/MEDFileField.hxx @@ -225,6 +225,7 @@ namespace ParaMEDMEM std::vector getLocsReallyUsed() const; std::vector getPflsReallyUsedMulti() const; std::vector getLocsReallyUsedMulti() const; + bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); void changePflsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); void changeLocsRefsNamesGen(const std::vector< std::pair, std::string > >& mapOfModif) throw(INTERP_KERNEL::Exception); MEDCouplingFieldDouble *getFieldOnMeshAtLevel(TypeOfField type, const MEDFileFieldGlobsReal *glob, const MEDCouplingMesh *mesh, bool& isPfl) const throw(INTERP_KERNEL::Exception); @@ -385,6 +386,8 @@ namespace ParaMEDMEM void simpleRepr(int bkOffset, std::ostream& oss, int f1tsId) const; const std::string& getDtUnit() const { return _dt_unit; } std::string getMeshName() const throw(INTERP_KERNEL::Exception); + void setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception); + bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); int getMeshIteration() const throw(INTERP_KERNEL::Exception); int getMeshOrder() const throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const; @@ -503,6 +506,8 @@ namespace ParaMEDMEM void simpleRepr(int bkOffset, std::ostream& oss, int fmtsId) const; std::vector< std::pair > getTimeSteps(std::vector& ret1) const throw(INTERP_KERNEL::Exception); std::string getMeshName() const throw(INTERP_KERNEL::Exception); + void setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception); + bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); const std::vector& getInfo() const throw(INTERP_KERNEL::Exception); DataArrayDouble *getUndergroundDataArray(int iteration, int order) const throw(INTERP_KERNEL::Exception); DataArrayDouble *getUndergroundDataArrayExt(int iteration, int order, std::vector< std::pair,std::pair > >& entries) const throw(INTERP_KERNEL::Exception); @@ -528,7 +533,7 @@ namespace ParaMEDMEM std::vector _infos; //! only useable on reading. 0 is for float, 1 for int32, 2 for int64 mutable int _field_type; - std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; + std::vector< MEDCouplingAutoRefCountObjectPtr > _time_steps; }; class MEDFileFieldMultiTSIterator; @@ -601,6 +606,7 @@ namespace ParaMEDMEM void writeLL(med_idt fid) const throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; std::vector getFieldsNames() const throw(INTERP_KERNEL::Exception); + std::vector getMeshesNames() const throw(INTERP_KERNEL::Exception); std::string simpleRepr() const; void simpleRepr(int bkOffset, std::ostream& oss) const; // @@ -611,6 +617,7 @@ namespace ParaMEDMEM MEDFileFieldMultiTS *getFieldWithName(const char *fieldName) const throw(INTERP_KERNEL::Exception); MEDFileFieldsIterator *iterator() throw(INTERP_KERNEL::Exception); void destroyFieldAtPos(int i) throw(INTERP_KERNEL::Exception); + bool changeMeshNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); private: int getPosFromFieldName(const char *fieldName) const throw(INTERP_KERNEL::Exception); std::vector getPflsReallyUsed() const; diff --git a/src/MEDLoader/MEDFileMesh.cxx b/src/MEDLoader/MEDFileMesh.cxx index eed45cc2b..33e661914 100644 --- a/src/MEDLoader/MEDFileMesh.cxx +++ b/src/MEDLoader/MEDFileMesh.cxx @@ -174,6 +174,19 @@ void MEDFileMesh::clearNonDiscrAttributes() const } +bool MEDFileMesh::changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + for(std::vector< std::pair >::const_iterator it=modifTab.begin();it!=modifTab.end();it++) + { + if((*it).first==_name) + { + _name=(*it).second; + return true; + } + } + return false; +} + void MEDFileMesh::copyFamGrpMapsFrom(const MEDFileMesh& other) { _groups=other._groups; @@ -2814,6 +2827,26 @@ const char *MEDFileMeshMultiTS::getName() const throw(INTERP_KERNEL::Exception) return _mesh_one_ts[0]->getName(); } +void MEDFileMeshMultiTS::setName(const char *newMeshName) throw(INTERP_KERNEL::Exception) +{ + std::string oldName(getName()); + std::vector< std::pair > v(1); + v[0].first=oldName; v[0].second=newMeshName; + changeNames(v); +} + +bool MEDFileMeshMultiTS::changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_mesh_one_ts.begin();it!=_mesh_one_ts.end();it++) + { + MEDFileMesh *cur(*it); + if(cur) + ret=cur->changeNames(modifTab) || ret; + } + return ret; +} + MEDFileMesh *MEDFileMeshMultiTS::getOneTimeStep() const throw(INTERP_KERNEL::Exception) { if(_mesh_one_ts.empty()) @@ -2974,6 +3007,18 @@ std::vector MEDFileMeshes::getMeshesNames() const throw(INTERP_KERN return ret; } +bool MEDFileMeshes::changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception) +{ + bool ret=false; + for(std::vector< MEDCouplingAutoRefCountObjectPtr >::iterator it=_meshes.begin();it!=_meshes.end();it++) + { + MEDFileMeshMultiTS *cur(*it); + if(cur) + ret=cur->changeNames(modifTab) || ret; + } + return ret; +} + void MEDFileMeshes::resize(int newSize) throw(INTERP_KERNEL::Exception) { _meshes.resize(newSize); diff --git a/src/MEDLoader/MEDFileMesh.hxx b/src/MEDLoader/MEDFileMesh.hxx index 8483b1be0..5ec7c4dcc 100644 --- a/src/MEDLoader/MEDFileMesh.hxx +++ b/src/MEDLoader/MEDFileMesh.hxx @@ -36,6 +36,7 @@ namespace ParaMEDMEM virtual bool isEqual(const MEDFileMesh *other, double eps, std::string& what) const; virtual void clearNonDiscrAttributes() const; void setName(const char *name) { _name=name; } + bool changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); const char *getName() const { return _name.c_str(); } void setUnivName(const char *name) { _univ_name=name; } const char *getUnivName() const { return _univ_name.c_str(); } @@ -270,6 +271,8 @@ namespace ParaMEDMEM static MEDFileMeshMultiTS *New(const char *fileName) throw(INTERP_KERNEL::Exception); static MEDFileMeshMultiTS *New(const char *fileName, const char *mName) throw(INTERP_KERNEL::Exception); const char *getName() const throw(INTERP_KERNEL::Exception); + void setName(const char *newMeshName) throw(INTERP_KERNEL::Exception); + bool changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); MEDFileMesh *getOneTimeStep() const throw(INTERP_KERNEL::Exception); void write(med_idt fid) const throw(INTERP_KERNEL::Exception); void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); @@ -299,6 +302,7 @@ namespace ParaMEDMEM MEDFileMesh *getMeshAtPos(int i) const throw(INTERP_KERNEL::Exception); MEDFileMesh *getMeshWithName(const char *mname) const throw(INTERP_KERNEL::Exception); std::vector getMeshesNames() const throw(INTERP_KERNEL::Exception); + bool changeNames(const std::vector< std::pair >& modifTab) throw(INTERP_KERNEL::Exception); // void resize(int newSize) throw(INTERP_KERNEL::Exception); void pushMesh(MEDFileMesh *mesh) throw(INTERP_KERNEL::Exception); diff --git a/src/MEDLoader/Swig/MEDLoaderCommon.i b/src/MEDLoader/Swig/MEDLoaderCommon.i index c6d62dec8..e6aca8aea 100644 --- a/src/MEDLoader/Swig/MEDLoaderCommon.i +++ b/src/MEDLoader/Swig/MEDLoaderCommon.i @@ -887,6 +887,7 @@ namespace ParaMEDMEM std::string getName(); void setName(const char *name); std::string getMeshName(); + void setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception); int getNumberOfComponents() const; bool isDealingTS(int iteration, int order) const; const std::vector& getInfo() const; @@ -1035,6 +1036,12 @@ namespace ParaMEDMEM PyTuple_SetItem(ret,1,elt); return ret; } + + bool changeMeshNames(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > modifTab=convertVecPairStStFromPy(li); + return self->changeMeshNames(modifTab); + } } }; @@ -1103,6 +1110,7 @@ namespace ParaMEDMEM std::string getName() const; void setName(const char *name); std::string getMeshName() const throw(INTERP_KERNEL::Exception); + void setMeshName(const char *newMeshName) throw(INTERP_KERNEL::Exception); const std::vector& getInfo() const; %extend { @@ -1356,6 +1364,12 @@ namespace ParaMEDMEM throw INTERP_KERNEL::Exception("MEDFileFieldMultiTSWithoutDAS::eraseTimeStepIds : unexpected input array type recognized !"); } } + + bool changeMeshNames(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > modifTab=convertVecPairStStFromPy(li); + return self->changeMeshNames(modifTab); + } } }; @@ -1498,6 +1512,7 @@ namespace ParaMEDMEM void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); int getNumberOfFields() const; std::vector getFieldsNames() const throw(INTERP_KERNEL::Exception); + std::vector getMeshesNames() const throw(INTERP_KERNEL::Exception); // void resize(int newSize) throw(INTERP_KERNEL::Exception); void pushField(MEDFileFieldMultiTS *field) throw(INTERP_KERNEL::Exception); @@ -1546,6 +1561,12 @@ namespace ParaMEDMEM { return self->iterator(); } + + bool changeMeshNames(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > modifTab=convertVecPairStStFromPy(li); + return self->changeMeshNames(modifTab); + } } }; @@ -1559,6 +1580,8 @@ namespace ParaMEDMEM int getNumberOfFields() const throw(INTERP_KERNEL::Exception); int getNumberOfMeshes() const throw(INTERP_KERNEL::Exception); // + bool changeMeshName(const char *oldMeshName, const char *newMeshName) throw(INTERP_KERNEL::Exception); + // void write(const char *fileName, int mode) const throw(INTERP_KERNEL::Exception); %extend { @@ -1592,6 +1615,12 @@ namespace ParaMEDMEM ret->incrRef(); return ret; } + + bool changeMeshNames(PyObject *li) throw(INTERP_KERNEL::Exception) + { + std::vector< std::pair > modifTab=convertVecPairStStFromPy(li); + return self->changeMeshNames(modifTab); + } } }; diff --git a/src/MEDLoader/Swig/MEDLoaderTypemaps.i b/src/MEDLoader/Swig/MEDLoaderTypemaps.i index d9c2717cd..c452c6f51 100644 --- a/src/MEDLoader/Swig/MEDLoaderTypemaps.i +++ b/src/MEDLoader/Swig/MEDLoaderTypemaps.i @@ -175,10 +175,47 @@ PyObject *convertVecPairVecStToPy(const std::vector< std::pair > convertVecPairStStFromPy(PyObject *pyLi) +{ + std::vector< std::pair > ret; + const char *msg="convertVecPairStStFromPy : Expecting PyList of Tuples of size 2 ! The first elt in tuple is one string and the 2nd one a string !"; + if(PyList_Check(pyLi)) + { + int size=PyList_Size(pyLi); + ret.resize(size); + for(int i=0;i p; + int size2=PyTuple_Size(o); + if(size2!=2) + throw INTERP_KERNEL::Exception(msg); + PyObject *o0=PyTuple_GetItem(o,0); + if(PyString_Check(o0)) + p.second=std::string(PyString_AsString(o0)); + else + throw INTERP_KERNEL::Exception(msg); + PyObject *o1=PyTuple_GetItem(o,1); + if(PyString_Check(o1)) + p.second=std::string(PyString_AsString(o1)); + else + throw INTERP_KERNEL::Exception(msg); + ret[i]=p; + } + else + throw INTERP_KERNEL::Exception(msg); + } + return ret; + } + throw INTERP_KERNEL::Exception(msg); +} + std::vector< std::pair, std::string > > convertVecPairVecStFromPy(PyObject *pyLi) { std::vector< std::pair, std::string > > ret; - const char *msg="convertVecPairVecStFromPy : Expecting PyList of Tuples of size 2 ! The first elt in tupe is a list of strings and the 2nd one a string !"; + const char *msg="convertVecPairVecStFromPy : Expecting PyList of Tuples of size 2 ! The first elt in tuple is a list of strings and the 2nd one a string !"; if(PyList_Check(pyLi)) { int size=PyList_Size(pyLi); -- 2.39.2