Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / ParaSMESHCorba / plugin / ParaSMESHCorbaModule / vtkParaSMESHCorbaSource.cxx
1 // Copyright (C) 2010-2022  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   /* todo: unused
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