Salome HOME
Copyright update 2022
[modules/paravis.git] / src / Plugins / ParaMEDCorba / plugin / ParaMEDMEM2VTK / VTKMEDCouplingMeshClient.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 "VTKMEDCouplingMeshClient.hxx"
21 #include "VTKMEDCouplingUMeshClient.hxx"
22 #include "VTKMEDCouplingCMeshClient.hxx"
23 #include "VTKMEDCouplingCurveLinearMeshClient.hxx"
24
25 #include "vtkErrorCode.h"
26 #include "vtkUnstructuredGrid.h"
27 #include "vtkRectilinearGrid.h"
28 #include "vtkStructuredGrid.h"
29
30 #include <vector>
31 #include <string>
32
33 //vtkErrorMacro("Cannot call Start() twice before calling Finish().");
34 void ParaMEDMEM2VTK::FillMEDCouplingMeshInstanceFrom(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr, vtkDataSet *ret)
35 {
36   SALOME_MED::MEDCouplingUMeshCorbaInterface_var umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
37   if(!CORBA::is_nil(umeshPtr))
38     {
39       vtkUnstructuredGrid *ret1=vtkUnstructuredGrid::SafeDownCast(ret);
40       if(!ret1)
41         {
42           vtkErrorWithObjectMacro(ret,"Internal error in ParaMEDCorba plugin : mismatch between VTK type and CORBA type UMesh !");
43           return ;
44         }
45       bool dummy;//VTK bug
46       ParaMEDMEM2VTK::FillMEDCouplingUMeshInstanceFrom(umeshPtr,ret1,dummy);//VTK bug
47       return ;
48     }
49   SALOME_MED::MEDCouplingCMeshCorbaInterface_var cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
50   if(!CORBA::is_nil(cmeshPtr))
51     {
52       vtkRectilinearGrid *ret1=vtkRectilinearGrid::SafeDownCast(ret);
53       if(!ret1)
54         {
55           vtkErrorWithObjectMacro(ret,"Internal error in ParaMEDCorba plugin : mismatch between VTK type and CORBA type CMesh !");
56           return ;
57         }
58       ParaMEDMEM2VTK::FillMEDCouplingCMeshInstanceFrom(cmeshPtr,ret1);
59       return ;
60     }
61   SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_var clmeshPtr=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtr);
62   if(!CORBA::is_nil(clmeshPtr))
63     {
64       vtkStructuredGrid *ret1=vtkStructuredGrid::SafeDownCast(ret);
65       if(!ret1)
66         {
67           vtkErrorWithObjectMacro(ret,"Internal error in ParaMEDCorba plugin : mismatch between VTK type and CORBA type CurveLinearMesh !");
68           return ;
69         }
70       ParaMEDMEM2VTK::FillMEDCouplingCurveLinearMeshInstanceFrom(clmeshPtr,ret1);
71       return ;
72     }
73   vtkErrorWithObjectMacro(ret,"Error : CORBA mesh type ! Mesh type not managed !");
74 }
75
76 vtkDataSet *ParaMEDMEM2VTK::BuildFromMEDCouplingMeshInstance(SALOME_MED::MEDCouplingMeshCorbaInterface_ptr meshPtr, bool& isPolyh)
77 {
78   SALOME_MED::MEDCouplingUMeshCorbaInterface_var umeshPtr=SALOME_MED::MEDCouplingUMeshCorbaInterface::_narrow(meshPtr);
79   if(!CORBA::is_nil(umeshPtr))
80     {
81       vtkUnstructuredGrid *ret1=vtkUnstructuredGrid::New();
82       ParaMEDMEM2VTK::FillMEDCouplingUMeshInstanceFrom(umeshPtr,ret1,isPolyh);
83       return ret1;
84     }
85   SALOME_MED::MEDCouplingCMeshCorbaInterface_var cmeshPtr=SALOME_MED::MEDCouplingCMeshCorbaInterface::_narrow(meshPtr);
86   if(!CORBA::is_nil(cmeshPtr))
87     {
88       vtkRectilinearGrid *ret1=vtkRectilinearGrid::New();
89       ParaMEDMEM2VTK::FillMEDCouplingCMeshInstanceFrom(cmeshPtr,ret1);
90       return ret1;
91     }
92   SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface_var clmeshPtr=SALOME_MED::MEDCouplingCurveLinearMeshCorbaInterface::_narrow(meshPtr);
93   if(!CORBA::is_nil(clmeshPtr))
94     {
95       vtkStructuredGrid *ret1=vtkStructuredGrid::New();
96       ParaMEDMEM2VTK::FillMEDCouplingCurveLinearMeshInstanceFrom(clmeshPtr,ret1);
97       return ret1;
98     }
99   vtkOutputWindowDisplayErrorText("Error : CORBA mesh type ! Mesh type not managed #2 !");
100   return 0;
101 }