]> SALOME platform Git repositories - modules/paravis.git/blob - src/Plugins/JSONReader/ParaViewPlugin/vtkJSONReader.cxx
Salome HOME
Porting to PV50
[modules/paravis.git] / src / Plugins / JSONReader / ParaViewPlugin / vtkJSONReader.cxx
1 //  Copyright (C) 2015 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author: Roman NIKOLAEV
20
21 #include "vtkJSONReader.h"
22 #include "vtkJSONParser.h"
23
24 #include <vtkObjectFactory.h>
25 #include <vtkTable.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>
32
33 #include <stdexcept>
34 #include <sstream>
35
36 vtkStandardNewMacro(vtkJSONReader);
37
38 //---------------------------------------------------
39 vtkJSONReader::vtkJSONReader()
40 {
41   this->SetNumberOfInputPorts(0);
42   this->SetNumberOfOutputPorts(1);
43   this->FileName = NULL;
44   this->Parser = vtkJSONParser::New();
45 }
46
47 //---------------------------------------------------
48 vtkJSONReader::~vtkJSONReader()
49 {
50   this->SetFileName(NULL);
51   this->Parser->Delete();
52 }
53
54 //---------------------------------------------------
55 int vtkJSONReader::CanReadFile(const char* fname)
56 {
57   return 1;
58 }
59
60 //---------------------------------------------------
61 void vtkJSONReader::PrintSelf(ostream& os, vtkIndent indent)
62 {
63   this->Superclass::PrintSelf(os, indent);
64   os << indent << "FileName: " 
65       << (this->FileName ? this->FileName : "(none)") << endl;
66   os << indent << "Parser: "<<this->Parser << endl;
67 }
68
69 //---------------------------------------------------
70 int vtkJSONReader::RequestData(vtkInformation*, 
71     vtkInformationVector**,
72     vtkInformationVector* outputVector)
73 {
74   vtkTable* const output_table = vtkTable::GetData(outputVector);
75
76   vtkInformation* const outInfo = outputVector->GetInformationObject(0);
77   if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) &&
78   outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()) > 0)
79   {
80    return 1;
81   }
82
83  // If the filename is not defined
84  if (!this->FileName && !this->Parser)
85    {
86      return 1;
87    }
88
89  this->Parser->SetFileName(this->FileName);
90  try{
91    return this->Parser->Parse(output_table);
92  } catch(vtkJSONException e) {
93    std::cout<<e.what()<<std::endl;
94    return 1;
95  }
96 }