]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
Correct bug when reading a MED file with a mesh having the same name than a field...
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Nov 2014 17:05:59 +0000 (18:05 +0100)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 20 Nov 2014 17:05:59 +0000 (18:05 +0100)
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx

index f9df2d33974bacfe112dee019db869aff28bb8e5..8c14fccc0f20aafecba412b076dc173304982b9b 100644 (file)
@@ -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;i<ms->getNumberOfMeshes();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<ParaMEDMEM::DataArrayDouble> 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<std::string> 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<ParaMEDMEM::MEDFileFields> ret(ParaMEDMEM::MEDFileFields::New());
index d184aa5791c53e016431d25d055ea4790508272b..4e557b59ed57ea3147f7412a327e749b007420d6 100644 (file)
@@ -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<std::string> SplitFieldNameIntoParts(const std::string& fullFieldName, char sep);
 private:
   // 1st : timesteps, 2nd : meshName, 3rd : common support