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