Salome HOME
Merge branch 'abn/port_pv42' into abn/rearch
[modules/paravis.git] / src / Plugins / MEDReader / IO / vtkExtractGroup.cxx
index 280e4d8837cca2e87c4eabf075225287b63e5995..785ff9e54b33b0cdd2ffc6e04b305fec8fb2e67e 100644 (file)
@@ -3,7 +3,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -58,8 +58,6 @@
 
 vtkStandardNewMacro(vtkExtractGroup);
 
-vtkCxxSetObjectMacro(vtkExtractGroup, SIL, vtkMutableDirectedGraph);
-
 ///////////////////
 
 class ExtractGroupStatus
@@ -111,12 +109,14 @@ class vtkExtractGroup::vtkExtractGroupInternal
 public:
   void loadFrom(vtkMutableDirectedGraph *sil);
   int getNumberOfEntries() const;
+  const char *getMeshName() const;
   const char *getKeyOfEntry(int i) const;
   bool getStatusOfEntryStr(const char *entry) const;
   void setStatusOfEntryStr(const char *entry, bool status);
   void printMySelf(std::ostream& os) const;
   std::set<int> getIdsToKeep() const;
   int getIdOfFamily(const std::string& famName) const;
+  static bool IsInformationOK(vtkInformation *info);
 private:
   std::map<std::string,int> computeFamStrIdMap() const;
   const ExtractGroupStatus& getEntry(const char *entry) const;
@@ -124,6 +124,7 @@ private:
 private:
   std::vector<ExtractGroupGrp> _groups;
   std::vector<ExtractGroupFam> _fams;
+  std::string _mesh_name;
 };
 
 const char ExtractGroupGrp::START[]="GRP_";
@@ -158,6 +159,32 @@ bool ExtractGroupGrp::isSameAs(const ExtractGroupGrp& other) const
     return false;
 }
 
+bool vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(vtkInformation *info)
+{
+  if(!info->Has(vtkDataObject::SIL()))
+    return false;
+  vtkMutableDirectedGraph *sil(vtkMutableDirectedGraph::SafeDownCast(info->Get(vtkDataObject::SIL())));
+  if(!sil)
+    return false;
+  int idNames(0);
+  vtkAbstractArray *verticesNames(sil->GetVertexData()->GetAbstractArray("Names",idNames));
+  vtkStringArray *verticesNames2(vtkStringArray::SafeDownCast(verticesNames));
+  if(!verticesNames2)
+    return false;
+  for(int i=0;i<verticesNames2->GetNumberOfValues();i++)
+    {
+      vtkStdString &st(verticesNames2->GetValue(i));
+      if(st=="MeshesFamsGrps")
+        return true;
+    }
+  return false;
+}
+
+const char *vtkExtractGroup::vtkExtractGroupInternal::getMeshName() const
+{
+  return this->_mesh_name.c_str();
+}
+
 void vtkExtractGroup::vtkExtractGroupInternal::loadFrom(vtkMutableDirectedGraph *sil)
 {
   std::vector<ExtractGroupGrp> oldGrps(_groups); _groups.clear();
@@ -185,6 +212,7 @@ void vtkExtractGroup::vtkExtractGroupInternal::loadFrom(vtkMutableDirectedGraph
     {
       vtkIdType id1(it0->Next());
       std::string meshName((const char *)verticesNames2->GetValue(id1));
+      this->_mesh_name=meshName;
       vtkAdjacentVertexIterator *it1(vtkAdjacentVertexIterator::New());
       sil->GetAdjacentVertices(id1,it1);
       vtkIdType idZeGrps(it1->Next());//zeGroups
@@ -397,6 +425,7 @@ void vtkExtractGroup::SetInsideOut(int val)
 
 int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
 {
+  vtkUnstructuredGridAlgorithm::RequestInformation(request,inputVector,outputVector);
   try
     {
       //std::cerr << "########################################## vtkExtractGroup::RequestInformation ##########################################" << std::endl;
@@ -406,7 +435,7 @@ int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationV
       vtkExecutive *exe(GetExecutive());
       vtkAlgorithm *alg(this);
       vtkInformation *infoOnSIL(alg->GetOutputInformation(0));
-      while(!infoOnSIL->Has(vtkDataObject::SIL()))// skipping vtkPVPostFilter
+      while(!vtkExtractGroup::vtkExtractGroupInternal::IsInformationOK(infoOnSIL))// skipping vtkPVPostFilter
        {
          if(exe->GetNumberOfInputConnections(0)<1)
            {
@@ -431,6 +460,16 @@ int vtkExtractGroup::RequestInformation(vtkInformation *request, vtkInformationV
   return 1;
 }
 
+/*!
+ * Do not use vtkCxxSetObjectMacro macro because input mdg comes from an already managed in the pipeline just a ref on it.
+ */
+void vtkExtractGroup::SetSIL(vtkMutableDirectedGraph *mdg)
+{
+  if(this->SIL==mdg)
+    return ;
+  this->SIL=mdg;
+}
+
 template<class CellPointExtractor>
 vtkDataSet *FilterFamilies(vtkDataSet *input, const std::set<int>& idsToKeep, bool insideOut, const char *arrNameOfFamilyField,
                            const char *associationForThreshold, bool& catchAll, bool& catchSmth)
@@ -582,7 +621,7 @@ int vtkExtractGroup::RequestData(vtkInformation *request, vtkInformationVector *
        }
       else
        {
-         vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(tryOnCell,idsToKeep,this->InsideOut,
+         vtkDataSet *tryOnNode(FilterFamilies<PointExtractor>(input,idsToKeep,this->InsideOut,
                                                               MEDFileFieldRepresentationLeavesArrays::FAMILY_ID_NODE_NAME,"vtkDataObject::FIELD_ASSOCIATION_POINTS",catchAll,catchSmth));
          if(tryOnNode)
            {
@@ -649,3 +688,8 @@ void vtkExtractGroup::SetGroupsFlagsStatus(const char *name, int status)
      this->Modified();
   //this->Internal->printMySelf(std::cerr);
 }
+
+const char *vtkExtractGroup::GetMeshName()
+{
+  return this->Internal->getMeshName();
+}