]> SALOME platform Git repositories - modules/paravis.git/commitdiff
Salome HOME
Solving bug during loadState of a MEDReader instance. Bug MANTIS #22546. Bug CEA... V7_4_0b1
authorgeay <anthony.geay@cea.fr>
Wed, 9 Apr 2014 08:43:41 +0000 (10:43 +0200)
committergeay <anthony.geay@cea.fr>
Wed, 9 Apr 2014 08:43:41 +0000 (10:43 +0200)
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.cxx
src/Plugins/MEDReader/IO/MEDFileFieldRepresentationTree.hxx
src/Plugins/MEDReader/IO/vtkMEDReader.cxx

index 8a059714ca644b31696f5fc387ade115066ce8d5..f3b575f24427e0f8c43933a4f824ea4f528b74d5 100644 (file)
@@ -234,12 +234,10 @@ std::string MEDFileFieldRepresentationLeavesArrays::getZeName() const
   return _ze_full_name;
 }
 
-void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const
+void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const
 {
   vtkIdType refId(sil->AddChild(root,edge));
   names.push_back(_ze_name);
-  std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name;
-  _ze_full_name=oss3.str();
   //
   if(MEDFileFieldRepresentationTree::IsFieldMeshRegardingInfo(((operator->())->getInfo())))
     {
@@ -248,6 +246,12 @@ void MEDFileFieldRepresentationLeavesArrays::feedSIL(vtkMutableDirectedGraph* si
     }
 }
 
+void MEDFileFieldRepresentationLeavesArrays::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const
+{
+  std::ostringstream oss3; oss3 << tsName << "/" << meshName << "/" << comSupStr << "/" << _ze_name;
+  _ze_full_name=oss3.str();
+}
+
 bool MEDFileFieldRepresentationLeavesArrays::getStatus() const
 {
   return _activated;
@@ -469,15 +473,21 @@ int MEDFileFieldRepresentationLeaves::getNumberOfTS() const
   return _arrays[0]->getNumberOfTS();
 }
 
+void MEDFileFieldRepresentationLeaves::computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const
+{
+  for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
+    (*it).computeFullNameInLeaves(tsName,meshName,comSupStr);
+}
+
 /*!
  * \param [in] ms is the meshes pointer. It can be used only for information of geometric types. No special processing will be requested on ms.
  */
-void MEDFileFieldRepresentationLeaves::feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const
+void MEDFileFieldRepresentationLeaves::feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const
 {
   vtkIdType root2(sil->AddChild(root,edge));
   names.push_back(std::string("Arrs"));
   for(std::vector<MEDFileFieldRepresentationLeavesArrays>::const_iterator it=_arrays.begin();it!=_arrays.end();it++)
-    (*it).feedSIL(sil,root2,edge,tsName,meshName,comSupStr,names);
+    (*it).feedSIL(sil,root2,edge,names);
   //
   vtkIdType root3(sil->AddChild(root,edge));
   names.push_back(std::string("InfoOnGeoType"));
@@ -884,6 +894,28 @@ void MEDFileFieldRepresentationTree::assignIds() const
       for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++)
         (*it2).setId(zeId);
 }
+
+void MEDFileFieldRepresentationTree::computeFullNameInLeaves() const
+{
+   std::size_t it0Cnt(0);
+   for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++,it0Cnt++)
+     {
+       std::ostringstream oss; oss << MEDFileFieldRepresentationLeavesArrays::TS_STR << it0Cnt;
+       std::string tsName(oss.str());
+       for(std::vector< std::vector< MEDFileFieldRepresentationLeaves > >::const_iterator it1=(*it0).begin();it1!=(*it0).end();it1++)
+         {
+           std::string meshName((*it1)[0].getMeshName());
+           std::size_t it2Cnt(0);
+           for(std::vector< MEDFileFieldRepresentationLeaves >::const_iterator it2=(*it1).begin();it2!=(*it1).end();it2++,it2Cnt++)
+             {
+               std::ostringstream oss2; oss2 << MEDFileFieldRepresentationLeavesArrays::COM_SUP_STR << it2Cnt;
+               std::string comSupStr(oss2.str());
+               (*it2).computeFullNameInLeaves(tsName,meshName,comSupStr);
+             }
+         }
+     }
+}
+
 void MEDFileFieldRepresentationTree::activateTheFirst() const
 {
   for(std::vector< std::vector< std::vector< MEDFileFieldRepresentationLeaves > > >::const_iterator it0=_data_structure.begin();it0!=_data_structure.end();it0++)
@@ -938,7 +970,7 @@ void MEDFileFieldRepresentationTree::feedSIL(vtkMutableDirectedGraph* sil, vtkId
               std::string comSupStr(oss2.str());
               vtkIdType typeId2(sil->AddChild(typeId1,edge));
               names.push_back(comSupStr);
-              (*it2).feedSIL(_ms,sil,typeId2,edge,tsName,meshName,comSupStr,names);
+              (*it2).feedSIL(_ms,meshName,sil,typeId2,edge,names);
             } 
         }
     }
@@ -1157,6 +1189,7 @@ void MEDFileFieldRepresentationTree::loadMainStructureOfFile(const char *fileNam
     }
   this->removeEmptyLeaves();
   this->assignIds();
+  this->computeFullNameInLeaves();
 }
 
 void MEDFileFieldRepresentationTree::removeEmptyLeaves()
index ed589887ff697870e5731f7e8655b19afea676a9..4df798d682477b96532e3f8017f4be004cdd2476 100644 (file)
@@ -67,7 +67,8 @@ public:
   MEDFileFieldRepresentationLeavesArrays& operator=(const MEDFileFieldRepresentationLeavesArrays& other);
   int getId() const;
   void setId(int& id) const;
-  void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& comSupStr, std::vector<std::string>& names) const;
+  void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
+  void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
   bool getStatus() const;
   bool setStatus(bool status) const;
   std::string getZeName() const;
@@ -101,7 +102,8 @@ public:
   std::string getMeshName() const;
   int getNumberOfArrays() const;
   int getNumberOfTS() const;
-  void feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, const std::string& tsName, const std::string& meshName, const std::string& compSupStr, std::vector<std::string>& names) const;
+  void feedSIL(const ParaMEDMEM::MEDFileMeshes *ms, const std::string& meshName, vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
+  void computeFullNameInLeaves(const std::string& tsName, const std::string& meshName, const std::string& comSupStr) const;
   bool containId(int id) const;
   bool containZeName(const char *name, int& id) const;
   bool isActivated() const;
@@ -130,6 +132,7 @@ public:
   int getNumberOfLeavesArrays() const;
   void assignIds() const;
   void activateTheFirst() const;
+  void computeFullNameInLeaves() const;
   void feedSIL(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
   std::string feedSILForFamsAndGrps(vtkMutableDirectedGraph* sil, vtkIdType root, vtkVariantArray *edge, std::vector<std::string>& names) const;
   std::string getNameOf(int id) const;
index b15d931bc2f90f0c6b56898b7db0844e8268f588..70adeab5e7ce2d5868450e43687bf8faa116229f 100644 (file)
 #include <sstream>
 #include <algorithm>
 
+/*!
+ * This class stores properties in loading state mode (pvsm) when the MED file has not been read yet.
+ * The file is not read beacause FileName has not been informed yet ! So this class stores properties of vtkMEDReader instance that 
+ * owns it and wait the vtkMEDReader::SetFileName to apply properties afterwards.
+ */
+class PropertyKeeper
+{
+public:
+  PropertyKeeper(vtkMEDReader *master):_master(master),IsGVActivated(false),GVValue(0),IsCMActivated(false),CMValue(0) { }
+  void assignPropertiesIfNeeded();
+  bool arePropertiesOnTreeToSetAfter() const;
+  //
+  void pushFieldStatusEntry(const char* name, int status);
+  void pushGenerateVectorsValue(int value);
+  void pushChangeModeValue(int value);
+  void pushTimesFlagsStatusEntry(const char* name, int status);
+protected:
+  // pool of pairs to assign in SetFieldsStatus if needed. The use case is the load using pvsm.
+  std::vector< std::pair<std::string,int> > SetFieldsStatusPairs;
+  // generate vector
+  bool IsGVActivated;
+  int GVValue;
+  // change mode
+  bool IsCMActivated;
+  int CMValue;
+  //
+  std::vector< std::pair<std::string,int> > TimesFlagsStatusPairs;
+  vtkMEDReader *_master;
+};
+
+void PropertyKeeper::assignPropertiesIfNeeded()
+{
+  if(!this->SetFieldsStatusPairs.empty())
+    {
+      for(std::vector< std::pair<std::string,int> >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end();it++)
+        _master->SetFieldsStatus((*it).first.c_str(),(*it).second);
+      this->SetFieldsStatusPairs.clear();
+    }
+  if(!this->TimesFlagsStatusPairs.empty())
+    {
+      for(std::vector< std::pair<std::string,int> >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end();it++)
+        _master->SetTimesFlagsStatus((*it).first.c_str(),(*it).second);
+      this->TimesFlagsStatusPairs.clear();
+    }
+  if(this->IsGVActivated)
+    {
+      _master->GenerateVectors(this->GVValue);
+      this->IsGVActivated=false;
+    }
+  if(this->IsCMActivated)
+    {
+      _master->ChangeMode(this->CMValue);
+      this->IsCMActivated=false;
+    }
+}
+
+void PropertyKeeper::pushFieldStatusEntry(const char* name, int status)
+{
+  bool found(false);
+  for(std::vector< std::pair<std::string,int> >::const_iterator it=this->SetFieldsStatusPairs.begin();it!=this->SetFieldsStatusPairs.end() && !found;it++)
+    found=(*it).first==name;
+  if(!found)
+    this->SetFieldsStatusPairs.push_back(std::pair<std::string,int>(name,status));
+}
+
+void PropertyKeeper::pushTimesFlagsStatusEntry(const char* name, int status)
+{
+  bool found(false);
+  for(std::vector< std::pair<std::string,int> >::const_iterator it=this->TimesFlagsStatusPairs.begin();it!=this->TimesFlagsStatusPairs.end() && !found;it++)
+    found=(*it).first==name;
+  if(!found)
+    this->TimesFlagsStatusPairs.push_back(std::pair<std::string,int>(name,status));
+}
+
+void PropertyKeeper::pushGenerateVectorsValue(int value)
+{
+  this->IsGVActivated=true;
+  this->GVValue=value;
+}
+
+void PropertyKeeper::pushChangeModeValue(int value)
+{
+  this->IsCMActivated=true;
+  this->CMValue=value;
+}
+
+bool PropertyKeeper::arePropertiesOnTreeToSetAfter() const
+{
+  return !SetFieldsStatusPairs.empty();
+}
+
 class vtkMEDReader::vtkMEDReaderInternal
 {
 
 public:
-  vtkMEDReaderInternal():TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2)
+  vtkMEDReaderInternal(vtkMEDReader *master):TK(0),IsMEDOrSauv(true),IsStdOrMode(false),GenerateVect(false),SIL(0),LastLev0(-1),FirstCall0(2),PK(master)
   {
   }
   
@@ -88,13 +179,15 @@ public:
   vtkMutableDirectedGraph* SIL;
   // store the lev0 id in Tree corresponding to the TIME_STEPS in the pipeline.
   int LastLev0;
+  // The property keeper is usable only in pvsm mode.
+  PropertyKeeper PK;
 private:
   unsigned char FirstCall0;
 };
 
 vtkStandardNewMacro(vtkMEDReader);
 
-vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal)
+vtkMEDReader::vtkMEDReader():Internal(new vtkMEDReaderInternal(this))
 {
   this->SetNumberOfInputPorts(0);
   this->SetNumberOfOutputPorts(1);
@@ -112,12 +205,18 @@ void vtkMEDReader::Reload(int a)
   std::cerr << "vtkMEDReader::Reload" << a << std::endl;
   std::string fName((const char *)this->GetFileName());
   delete this->Internal;
-  this->Internal=new vtkMEDReaderInternal;
+  this->Internal=new vtkMEDReaderInternal(this);
   this->SetFileName(fName.c_str());
 }
 
 void vtkMEDReader::GenerateVectors(int val)
 {
+  if(this->Internal->FileName.empty())
+    {//pvsm mode
+      this->Internal->PK.pushGenerateVectorsValue(val);
+      return ;
+    }
+  //not pvsm mode (general case)
   bool val2((bool)val);
   if(val2!=this->Internal->GenerateVect)
     {
@@ -128,6 +227,12 @@ void vtkMEDReader::GenerateVectors(int val)
 
 void vtkMEDReader::ChangeMode(int newMode)
 {
+  if(this->Internal->FileName.empty())
+    {//pvsm mode
+      this->Internal->PK.pushChangeModeValue(newMode);
+      return ;
+    }
+  //not pvsm mode (general case)
   this->Internal->IsStdOrMode=newMode!=0;
   //std::cerr << "vtkMEDReader::ChangeMode : " << this->Internal->IsStdOrMode << std::endl;
   this->Modified();
@@ -153,10 +258,12 @@ void vtkMEDReader::SetFileName(const char *fname)
       if(this->Internal->Tree.getNumberOfLeavesArrays()==0)
         {
           this->Internal->Tree.loadMainStructureOfFile(this->Internal->FileName.c_str(),this->Internal->IsMEDOrSauv);
-          this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client.
+          if(!this->Internal->PK.arePropertiesOnTreeToSetAfter())
+            this->Internal->Tree.activateTheFirst();//This line manually initialize the status of server (this) with the remote client.
           this->Internal->TK.setMaxNumberOfTimeSteps(this->Internal->Tree.getMaxNumberOfTimeSteps());
         }
       this->Modified();
+      this->Internal->PK.assignPropertiesIfNeeded();
     }
   catch(INTERP_KERNEL::Exception& e)
     {
@@ -230,10 +337,27 @@ int vtkMEDReader::RequestData(vtkInformation *request, vtkInformationVector **in
 void vtkMEDReader::SetFieldsStatus(const char* name, int status)
 {
   //std::cerr << "vtkMEDReader::SetFieldsStatus(" << name << "," << status << ") called !" << std::endl;
-  this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status);
-  if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1))
-    if(!this->Internal->PluginStart0())
-      this->Modified();
+  if(this->Internal->FileName.empty())
+    {//pvsm mode
+      this->Internal->PK.pushFieldStatusEntry(name,status);
+      return ;
+    }
+  //not pvsm mode (general case)
+  try
+    {
+      this->Internal->Tree.changeStatusOfAndUpdateToHaveCoherentVTKDataSet(this->Internal->Tree.getIdHavingZeName(name),status);
+      if(std::string(name)==GetFieldsTreeArrayName(GetNumberOfFieldsTreeArrays()-1))
+        if(!this->Internal->PluginStart0())
+          this->Modified();
+    }
+  catch(INTERP_KERNEL::Exception& e)
+    {
+      if(!this->Internal->FileName.empty())
+        {
+          std::cerr << "vtkMEDReader::SetFieldsStatus error : " << e.what() << " *** WITH STATUS=" << status << endl;
+          return ;
+        }
+    }
 }
 
 int vtkMEDReader::GetNumberOfFieldsTreeArrays()
@@ -261,6 +385,12 @@ int vtkMEDReader::GetFieldsTreeArrayStatus(const char *name)
 
 void vtkMEDReader::SetTimesFlagsStatus(const char *name, int status)
 {
+  if(this->Internal->FileName.empty())
+    {//pvsm mode
+      this->Internal->PK.pushTimesFlagsStatusEntry(name,status);
+      return ;
+    }
+  //not pvsm mode (general case)
   int pos(0);
   std::istringstream iss(name); iss >> pos;
   this->Internal->TK.getTimesFlagArray()[pos].first=(bool)status;