1 // Copyright (C) 2010-2021 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #include "vtkPVMetaDataInformation.h"
23 #include "vtkAlgorithm.h"
24 #include "vtkAlgorithmOutput.h"
25 #include "vtkClientServerStream.h"
26 #include "vtkExecutive.h"
27 #include "vtkDataObject.h"
28 #include "vtkGenericDataObjectReader.h"
29 #include "vtkGenericDataObjectWriter.h"
30 #include "vtkInformationDataObjectMetaDataKey.h"
31 #include "vtkInformation.h"
32 #include "vtkObjectFactory.h"
34 #include "vtkMEDReader.h"
36 vtkStandardNewMacro(vtkPVMetaDataInformation)
37 vtkCxxSetObjectMacro(vtkPVMetaDataInformation, InformationData, vtkDataObject)
39 //----------------------------------------------------------------------------
40 vtkPVMetaDataInformation::vtkPVMetaDataInformation()
42 this->InformationData = NULL;
45 //----------------------------------------------------------------------------
46 vtkPVMetaDataInformation::~vtkPVMetaDataInformation()
48 this->SetInformationData(NULL);
51 //----------------------------------------------------------------------------
52 void vtkPVMetaDataInformation::CopyFromObject(vtkObject* obj)
54 this->SetInformationData(NULL);
56 vtkAlgorithmOutput* algOutput = vtkAlgorithmOutput::SafeDownCast(obj);
59 vtkAlgorithm* alg = vtkAlgorithm::SafeDownCast(obj);
62 algOutput = alg->GetOutputPort(0);
68 vtkErrorMacro("Information can only be gathered from a vtkAlgorithmOutput.");
72 vtkAlgorithm* reader = algOutput->GetProducer();
73 vtkInformation* info = reader->GetExecutive()->GetOutputInformation(
74 algOutput->GetIndex());
76 if (info && info->Has(vtkMEDReader::META_DATA()))
78 this->SetInformationData(vtkDataObject::SafeDownCast(info->Get(vtkMEDReader::META_DATA())));
82 //----------------------------------------------------------------------------
83 void vtkPVMetaDataInformation::CopyToStream(vtkClientServerStream* css)
86 if (!this->InformationData)
88 *css << vtkClientServerStream::Reply
89 << vtkClientServerStream::InsertArray(
90 static_cast<unsigned char*>(NULL), 0)
91 << vtkClientServerStream::End;
95 vtkDataObject* clone = this->InformationData->NewInstance();
96 clone->ShallowCopy(this->InformationData);
98 vtkGenericDataObjectWriter* writer = vtkGenericDataObjectWriter::New();
99 writer->SetFileTypeToBinary();
100 writer->WriteToOutputStringOn();
101 writer->SetInputData(clone);
104 *css << vtkClientServerStream::Reply
105 << vtkClientServerStream::InsertArray(
106 writer->GetBinaryOutputString(),
107 writer->GetOutputStringLength())
108 << vtkClientServerStream::End;
109 writer->RemoveAllInputs();
114 //----------------------------------------------------------------------------
115 void vtkPVMetaDataInformation::CopyFromStream(const vtkClientServerStream* css)
117 this->SetInformationData(0);
118 vtkTypeUInt32 length;
119 if (css->GetArgumentLength(0, 0, &length) && length > 0)
121 unsigned char* raw_data = new unsigned char[length];
122 css->GetArgument(0, 0, raw_data, length);
123 vtkGenericDataObjectReader* reader = vtkGenericDataObjectReader::New();
124 reader->SetBinaryInputString(reinterpret_cast<const char*>(raw_data), length);
125 reader->ReadFromInputStringOn();
128 this->SetInformationData(reader->GetOutput());
133 void vtkPVMetaDataInformation::AddInformation(vtkPVInformation*)
137 //----------------------------------------------------------------------------
138 void vtkPVMetaDataInformation::PrintSelf(ostream& os, vtkIndent indent)
140 this->Superclass::PrintSelf(os, indent);
141 os << indent << "InformationData: " << this->InformationData << endl;