Salome HOME
9d0ff02d8a13ef2a8e70b77433048abd4d37f802
[modules/paravis.git] / src / Plugins / ParaSMESHCorba / vtkParaSMESHCorbaSource.cxx
1 // Copyright (C) 2010-2016  CEA/DEN, EDF R&D
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
20 #include "vtkParaSMESHCorbaSource.h"
21
22 #include <SALOME_LifeCycleCORBA.hxx>
23
24 #include "vtkStreamingDemandDrivenPipeline.h"
25 #include "vtkInformationVector.h"
26 #include "vtkInformation.h"
27 #include "vtkMultiBlockDataSet.h"
28 #include "vtkObjectFactory.h"
29 #include "vtkUnstructuredGridReader.h"
30
31 #include "SMDS_UnstructuredGrid.hxx"
32 #include "SMESH_Mesh.hh"
33
34 #include <algorithm>
35
36 vtkStandardNewMacro(vtkParaSMESHCorbaSource);
37
38 void *vtkParaSMESHCorbaSource::Orb=0;
39
40 //----------------------------------------------
41 vtkParaSMESHCorbaSource::vtkParaSMESHCorbaSource() {
42   if(!Orb) {
43     CORBA::ORB_var *OrbC=new CORBA::ORB_var;
44     int argc=0;
45     *OrbC=CORBA::ORB_init(argc,0);
46     this->Orb=OrbC;
47   }
48   this->SetNumberOfInputPorts(0);
49   this->SetNumberOfOutputPorts(1);
50 }
51
52 //----------------------------------------------
53 vtkParaSMESHCorbaSource::~vtkParaSMESHCorbaSource() {
54   
55 }
56
57 //----------------------------------------------
58 const char* vtkParaSMESHCorbaSource::GetIORCorba()
59 {
60   return &IOR[0];
61 }
62
63 //----------------------------------------------
64 void vtkParaSMESHCorbaSource::SetIORCorba(char *ior) {
65   if(!ior)
66     return;
67   if(ior[0]=='\0')
68     return;
69   int length=strlen(ior);
70   IOR.resize(length+1);
71   std::copy(ior,ior+length+1,&IOR[0]);
72   this->Modified();
73 }
74
75 //----------------------------------------------
76 int vtkParaSMESHCorbaSource::ProcessRequest(vtkInformation* request,
77     vtkInformationVector** inputVector,
78     vtkInformationVector* outputVector) {
79   // generate the data
80   if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
81     return this->RequestData(request, inputVector, outputVector);
82   }
83   return this->Superclass::ProcessRequest(request, inputVector, outputVector);
84 }
85
86 //----------------------------------------------
87 int vtkParaSMESHCorbaSource::FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info) { 
88   info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
89   return 1;
90 }
91
92 //----------------------------------------------
93 int vtkParaSMESHCorbaSource::RequestData(vtkInformation* request, vtkInformationVector** inInfo, vtkInformationVector* outputVector) {
94   vtkInformation *outInfo=outputVector->GetInformationObject(0);
95   vtkMultiBlockDataSet *ret0=vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
96   double reqTS = 0;
97   if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
98     reqTS = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
99
100   try {
101     CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
102     CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
103     SMESH::SMESH_Mesh_var meshObj = SMESH::SMESH_Mesh::_narrow(obj);
104     if(!CORBA::is_nil(meshObj)) {
105       SALOMEDS::TMPFile*  SeqFile = meshObj->GetVtkUgStream();
106       int aSize = SeqFile->length();
107       char* buf = (char*)SeqFile->NP_data();
108       vtkUnstructuredGridReader* aReader = vtkUnstructuredGridReader::New();
109       aReader->ReadFromInputStringOn();
110       aReader->SetBinaryInputString(buf, aSize);
111       aReader->Update();
112       vtkUnstructuredGrid* ret = vtkUnstructuredGrid::New();
113       ret->ShallowCopy(aReader->GetOutput());
114       aReader->Delete();
115       if(!ret) {
116         vtkErrorMacro("On smesh object CORBA fetching an error occurs !");
117         return 0;
118       }
119
120       ret0->SetBlock(0, ret);
121       ret->Delete();
122       return 1;
123     }
124     
125     vtkErrorMacro("Unrecognized CORBA reference!");
126   }
127   catch(CORBA::Exception&) {
128     vtkErrorMacro("On fetching object error occurs");
129   }
130   return 0;
131 }
132
133
134