From: Anthony Geay Date: Thu, 20 Nov 2014 17:05:59 +0000 (+0100) Subject: Correct bug when reading a MED file with a mesh having the same name than a field... X-Git-Tag: V7_5_1b1~7^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9dc6ad34884f6fe57daa2b1b32335c1e9259b373;p=modules%2Fparavis.git Correct bug when reading a MED file with a mesh having the same name than a field in the same file. --- diff --git a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx index f9df2d33..8c14fccc 100644 --- a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx +++ b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx @@ -1387,6 +1387,8 @@ void MEDFileFieldRepresentationTree::printMySelf(std::ostream& os) const void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret) { + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::AppendFieldFromMeshes : internal error ! NULL ret !"); for(int i=0;igetNumberOfMeshes();i++) { MEDFileMesh *mm(ms->getMeshAtPos(i)); @@ -1407,7 +1409,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); arr->iota(); f->setArray(arr); - f->setName(mm->getName()); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); f1tsMultiLev->setFieldNoProfileSBT(f); } } @@ -1422,7 +1424,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr arr(ParaMEDMEM::DataArrayDouble::New()); arr->alloc(m->getNumberOfNodes()); arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); arr->iota(); f->setArray(arr); - f->setName(mm->getName()); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); f1tsMultiLev->setFieldNoProfileSBT(f); } else @@ -1438,7 +1440,7 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED arr->setInfoOnComponent(0,std::string(COMPO_STR_TO_LOCATE_MESH_DA)); arr->iota(); f->setArray(arr); - f->setName(mm->getName()); + f->setName(BuildAUniqueArrayNameForMesh(mm->getName(),ret)); f1tsMultiLev->setFieldNoProfileSBT(f); } // @@ -1448,6 +1450,20 @@ void MEDFileFieldRepresentationTree::AppendFieldFromMeshes(const ParaMEDMEM::MED } } +std::string MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret) +{ + static const char KEY_STR_TO_AVOID_COLLIDE[]="MESH@"; + if(!ret) + throw INTERP_KERNEL::Exception("MEDFileFieldRepresentationTree::BuildAUniqueArrayNameForMesh : internal error ! NULL ret !"); + std::vector fieldNamesAlreadyExisting(ret->getFieldsNames()); + if(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),meshName)==fieldNamesAlreadyExisting.end()) + return meshName; + std::string tmpName(KEY_STR_TO_AVOID_COLLIDE); tmpName+=meshName; + while(std::find(fieldNamesAlreadyExisting.begin(),fieldNamesAlreadyExisting.end(),tmpName)!=fieldNamesAlreadyExisting.end()) + tmpName=std::string(KEY_STR_TO_AVOID_COLLIDE)+tmpName; + return tmpName; +} + ParaMEDMEM::MEDFileFields *MEDFileFieldRepresentationTree::BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms) { ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr ret(ParaMEDMEM::MEDFileFields::New()); diff --git a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx index d184aa57..4e557b59 100644 --- a/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx +++ b/src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx @@ -163,6 +163,7 @@ private: const MEDFileFieldRepresentationLeaves& getTheSingleActivated(int& lev0, int& lev1, int& lev2) const; static ParaMEDMEM::MEDFileFields *BuildFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms); static void AppendFieldFromMeshes(const ParaMEDMEM::MEDFileMeshes *ms, ParaMEDMEM::MEDFileFields *ret); + static std::string BuildAUniqueArrayNameForMesh(const std::string& meshName, const ParaMEDMEM::MEDFileFields *ret); static std::vector SplitFieldNameIntoParts(const std::string& fullFieldName, char sep); private: // 1st : timesteps, 2nd : meshName, 3rd : common support