1 // Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
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: Roman NIKOLAEV
21 #include "vtkJSONReader.h"
22 #include "vtkJSONParser.h"
24 #include <vtkObjectFactory.h>
26 #include <vtkInformationVector.h>
27 #include <vtkInformation.h>
28 #include <vtkStreamingDemandDrivenPipeline.h>
29 #include <vtkVariantArray.h>
30 #include <vtkStringArray.h>
31 #include <vtkStringToNumeric.h>
36 vtkStandardNewMacro(vtkJSONReader);
38 //---------------------------------------------------
39 vtkJSONReader::vtkJSONReader()
41 this->SetNumberOfInputPorts(0);
42 this->SetNumberOfOutputPorts(1);
43 this->FileName = NULL;
44 this->Parser = vtkJSONParser::New();
47 //---------------------------------------------------
48 vtkJSONReader::~vtkJSONReader()
50 this->SetFileName(NULL);
51 this->Parser->Delete();
54 //---------------------------------------------------
55 int vtkJSONReader::CanReadFile(const char* fname)
60 //---------------------------------------------------
61 void vtkJSONReader::PrintSelf(ostream& os, vtkIndent indent)
63 this->Superclass::PrintSelf(os, indent);
64 os << indent << "FileName: "
65 << (this->FileName ? this->FileName : "(none)") << endl;
66 os << indent << "Parser: "<<this->Parser << endl;
69 //---------------------------------------------------
70 int vtkJSONReader::RequestData(vtkInformation*,
71 vtkInformationVector**,
72 vtkInformationVector* outputVector)
74 vtkTable* const output_table = vtkTable::GetData(outputVector);
76 vtkInformation* const outInfo = outputVector->GetInformationObject(0);
77 if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) &&
78 outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
83 // If the filename is not defined
84 if (!this->FileName && !this->Parser)
89 this->Parser->SetFileName(this->FileName);
91 return this->Parser->Parse(output_table);
92 } catch(vtkJSONException e) {
93 std::cout<<e.what()<<std::endl;