Salome HOME
Fixup reload
[modules/paravis.git] / src / Plugins / MEDReader / plugin / MEDReaderIO / vtkFileSeriesGroupReader.cxx
1 #include "vtkFileSeriesGroupReader.h"
2
3 #include <vtkInformation.h>
4 #include <vtkInformationVector.h>
5 #include <vtkMultiBlockDataSet.h>
6 #include <vtkObjectFactory.h>
7 #include <vtkSmartPointer.h>
8 #include <vtkStreamingDemandDrivenPipeline.h>
9
10 #include "vtkMEDReader.h"
11
12 #include <vector>
13 #include <string>
14
15 vtkStandardNewMacro(vtkFileSeriesGroupReader);
16
17 //=============================================================================
18 struct vtkFileSeriesGroupReaderInternals
19 {
20   std::vector<std::string> FileNames;
21 };
22
23 //=============================================================================
24 vtkFileSeriesGroupReader::vtkFileSeriesGroupReader()
25   : Internals(new vtkFileSeriesGroupReaderInternals())
26 {
27   this->SetNumberOfInputPorts(0);
28   this->SetNumberOfOutputPorts(1);
29 }
30
31 //-----------------------------------------------------------------------------
32 vtkFileSeriesGroupReader::~vtkFileSeriesGroupReader() = default;
33
34 //----------------------------------------------------------------------------
35 void vtkFileSeriesGroupReader::AddFileName(const char* name)
36 {
37   // Make sure the reader always has a filename set
38   this->ReaderSetFileName(name);
39
40   this->AddFileNameInternal(name);
41   this->Modified();
42 }
43
44 //----------------------------------------------------------------------------
45 void vtkFileSeriesGroupReader::RemoveAllFileNames()
46 {
47   this->RemoveAllFileNamesInternal();
48   this->Modified();
49 }
50
51 //----------------------------------------------------------------------------
52 void vtkFileSeriesGroupReader::RemoveAllFileNamesInternal()
53 {
54   this->Internals->FileNames.clear();
55 }
56
57 //----------------------------------------------------------------------------
58 void vtkFileSeriesGroupReader::AddFileNameInternal(const char* name)
59 {
60   this->Internals->FileNames.emplace_back(name);
61 }
62
63 //----------------------------------------------------------------------------
64 unsigned int vtkFileSeriesGroupReader::GetNumberOfFileNames()
65 {
66   return static_cast<unsigned int>(this->Internals->FileNames.size());
67 }
68
69 //----------------------------------------------------------------------------
70 const char* vtkFileSeriesGroupReader::GetFileName(unsigned int idx)
71 {
72   if (idx >= this->Internals->FileNames.size())
73   {
74     return nullptr;
75   }
76   return this->Internals->FileNames[idx].c_str();
77 }
78
79 //----------------------------------------------------------------------------
80 int vtkFileSeriesGroupReader::CanReadFile(const char* filename)
81 {
82   if (!this->Reader)
83   {
84     return 0;
85   }
86
87   return this->ReaderCanReadFile(filename);
88 }
89
90 //----------------------------------------------------------------------------
91 int vtkFileSeriesGroupReader::RequestInformation(
92   vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
93 {
94   return this->Reader->ProcessRequest(request, inputVector, outputVector);
95 }
96
97 //----------------------------------------------------------------------------
98 int vtkFileSeriesGroupReader::RequestData(vtkInformation* vtkNotUsed(request),
99   vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
100 {
101   auto output = vtkMultiBlockDataSet::GetData(outputVector, 0);
102   output->SetNumberOfBlocks(this->GetNumberOfFileNames());
103
104   vtkInformation* info = outputVector->GetInformationObject(0);
105   double time = info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
106
107   for (unsigned int i = 0; i < this->GetNumberOfFileNames(); i++)
108   {
109     this->ReaderSetFileName(this->GetFileName(i));
110     vtkMEDReader::SafeDownCast(this->Reader)->Reload();
111     this->Reader->UpdateTimeStep(time);
112     vtkDataObject* outputReader = this->Reader->GetOutputDataObject(0);
113     vtkSmartPointer<vtkDataObject> outputLeaf = vtkSmartPointer<vtkDataObject>::Take(outputReader->NewInstance());
114     outputLeaf->DeepCopy(outputReader);
115     output->SetBlock(i, outputLeaf);
116   }
117
118   return 1;
119 }
120  
121 //------------------------------------------------------------------------------
122 int vtkFileSeriesGroupReader::FillOutputPortInformation(
123   int vtkNotUsed(port), vtkInformation* info)
124 {
125   info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
126   return 1;
127 }
128
129 //-----------------------------------------------------------------------------
130 void vtkFileSeriesGroupReader::PrintSelf(ostream& os, vtkIndent indent)
131 {
132   this->Superclass::PrintSelf(os, indent);
133
134   os << indent << "MetaFileName: " << (this->_MetaFileName ? this->_MetaFileName : "(none)")
135      << endl;
136 }