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