Salome HOME
5aead9ab6a57981d8be23a8126b45c63c69aa09b
[modules/paravis.git] / src / Plugins / ParaGEOMCorba / plugin / ParaGEOMCorbaModule / vtkParaGEOMCorbaSource.cxx
1 // Copyright (C) 2010-2021  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 "vtkParaGEOMCorbaSource.h"
21
22 #include "vtkMultiBlockDataSet.h"
23 #include "vtkUnstructuredGrid.h"
24 //
25 #include "vtkStreamingDemandDrivenPipeline.h"
26 #include "vtkInformationVector.h"
27 #include "vtkObjectFactory.h"
28 #include "vtkInformation.h"
29
30 #include <SALOME_LifeCycleCORBA.hxx>
31 #include <SALOME_NamingService.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include "vtkPolyData.h"
34 #include "GEOM_Gen.hh"
35 #include "GEOM_Client.hxx"
36 #include "OCC2VTK_Tools.h"
37
38 #include <algorithm>
39
40 //----------------------------------------------
41 vtkStandardNewMacro(vtkParaGEOMCorbaSource)
42
43 void *vtkParaGEOMCorbaSource::Orb=0;
44
45 //----------------------------------------------
46 vtkParaGEOMCorbaSource::vtkParaGEOMCorbaSource():Deflection(0.0)
47 {
48   if(!Orb) {
49     CORBA::ORB_var *OrbC=new CORBA::ORB_var;
50     int argc=0;
51     *OrbC=CORBA::ORB_init(argc,0);
52     this->Orb=OrbC;
53   }
54   this->SetNumberOfInputPorts(0);
55   this->SetNumberOfOutputPorts(1);
56 }
57
58 //----------------------------------------------
59 vtkParaGEOMCorbaSource::~vtkParaGEOMCorbaSource() {
60 }
61
62 //----------------------------------------------
63 const char* vtkParaGEOMCorbaSource::GetIORCorba()
64 {
65   return &IOR[0];
66 }
67
68 //----------------------------------------------
69 void vtkParaGEOMCorbaSource::SetIORCorba(char *ior) {
70   if(!ior)
71     return;
72   if(ior[0]=='\0')
73     return;
74   int length=strlen(ior);
75   IOR.resize(length+1);
76   std::copy(ior,ior+length+1,&IOR[0]);
77   this->Modified();
78 }
79
80 //----------------------------------------------
81 int vtkParaGEOMCorbaSource::ProcessRequest(vtkInformation* request,
82     vtkInformationVector** inputVector,
83     vtkInformationVector* outputVector) {
84   // generate the data
85   if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA())) {
86     return this->RequestData(request, inputVector, outputVector);
87   }
88   return this->Superclass::ProcessRequest(request, inputVector, outputVector);
89 }
90
91 //----------------------------------------------
92 int vtkParaGEOMCorbaSource::FillOutputPortInformation(int vtkNotUsed(port), vtkInformation* info) {
93   info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
94   return 1;
95 }
96
97 //----------------------------------------------
98 int vtkParaGEOMCorbaSource::RequestData(vtkInformation* /*request*/, vtkInformationVector** /*inInfo*/, vtkInformationVector* outputVector) {
99   vtkInformation *outInfo=outputVector->GetInformationObject(0);
100   vtkMultiBlockDataSet *ret0=vtkMultiBlockDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
101   /*double reqTS = 0; // todo: unused
102   if(outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
103     reqTS = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
104   */
105   try {
106     //Client request on ORB.
107     CORBA::ORB_var *OrbC=(CORBA::ORB_var *)this->Orb;
108     CORBA::Object_var obj=(*OrbC)->string_to_object(&IOR[0]);
109     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow(obj);
110     
111     if(!CORBA::is_nil(geomObj)) {
112       SALOME_NamingService ns(*OrbC);
113       SALOME_LifeCycleCORBA aLCC(&ns);
114       Engines::EngineComponent_var aComponent = aLCC.FindOrLoad_Component("FactoryServer","GEOM");
115       GEOM::GEOM_Gen_var geomGen = GEOM::GEOM_Gen::_narrow(aComponent);
116       if ( !CORBA::is_nil( geomGen ) ) {
117         TopoDS_Shape aTopoDSShape = GEOM_Client::get_client().GetShape( geomGen, geomObj );
118         
119         if ( !aTopoDSShape.IsNull() ) {
120           vtkPolyData *ret=GEOM::GetVTKData(aTopoDSShape, this->Deflection);
121           if(!ret) {
122             vtkErrorMacro("On geom object CORBA fetching an error occurs !");
123             return 0;
124           }
125           ret0->SetBlock(0,ret);
126           ret->Delete();
127           return 1;
128         }
129       }
130     }
131     vtkErrorMacro("Unrecognized CORBA reference!");
132   }
133   catch(CORBA::Exception& ex) {
134     vtkErrorMacro("On fetching object error occurs");
135   }
136   return 0;
137 }
138
139 //----------------------------------------------
140 void vtkParaGEOMCorbaSource::PrintSelf(ostream& os, vtkIndent indent) {
141   this->Superclass::PrintSelf( os, indent );
142   os << "Deflection: " << this->Deflection << "\n";
143 }
144