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