Salome HOME
90126cb7dd88d4cbdcf36c8b73d8ed83ab538963
[modules/med.git] / src / MEDMEM_I / MEDMEM_convert.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //=============================================================================
24 // File      : MEDMEM_convert.cxx
25 // Created   : mer fév 20 15:47:57 CET 2002
26 // Author    : EDF
27 // Project   : SALOME
28 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_convert.cxx
29 //=============================================================================
30 //
31 #include "utilities.h"
32 #include "Utils_CorbaException.hxx"
33
34 #include "MEDMEM_convert.hxx"
35
36
37 SALOME_MED::medGeometryElement convertMedEltToIdlElt(medGeometryElement element) 
38 throw (SALOME::SALOME_Exception)
39 {
40   switch (element)
41     {
42     case MED_NONE    :  return SALOME_MED::MED_NONE;
43     case MED_POINT1  :  return SALOME_MED::MED_POINT1;
44     case MED_SEG2    :  return SALOME_MED::MED_SEG2;
45     case MED_SEG3    :  return SALOME_MED::MED_SEG3;
46     case MED_TRIA3   :  return SALOME_MED::MED_TRIA3;
47     case MED_QUAD4   :  return SALOME_MED::MED_QUAD4;
48     case MED_TRIA6   :  return SALOME_MED::MED_TRIA6;
49     case MED_QUAD8   :  return SALOME_MED::MED_QUAD8;
50     case MED_TETRA4  :  return SALOME_MED::MED_TETRA4;
51     case MED_PYRA5   :  return SALOME_MED::MED_PYRA5;
52     case MED_PENTA6  :  return SALOME_MED::MED_PENTA6;
53     case MED_HEXA8   :  return SALOME_MED::MED_HEXA8;
54     case MED_TETRA10 :  return SALOME_MED::MED_TETRA10;
55     case MED_PYRA13  :  return SALOME_MED::MED_PYRA13;
56     case MED_PENTA15 :  return SALOME_MED::MED_PENTA15;
57     case MED_HEXA20  :  return SALOME_MED::MED_HEXA20;
58     case MED_POLYGON      :  return SALOME_MED::MED_POLYGON;
59     case MED_POLYHEDRA    :  return SALOME_MED::MED_POLYHEDRA;
60     case MED_ALL_ELEMENTS :  return SALOME_MED::MED_ALL_ELEMENTS;
61     default :
62         { MESSAGE("Unknown Geometry Element");
63           THROW_SALOME_CORBA_EXCEPTION("Unknown Geometry Element",
64                                         SALOME::INTERNAL_ERROR);
65         } 
66    }
67 }
68
69 medGeometryElement convertIdlEltToMedElt(SALOME_MED::medGeometryElement element) 
70 throw (SALOME::SALOME_Exception)
71 {
72
73   SCRUTE(element);
74
75   switch (element)
76     {
77     case SALOME_MED::MED_NONE     :  return MED_NONE;
78     case SALOME_MED::MED_POINT1   :  return MED_POINT1;
79     case SALOME_MED::MED_SEG2     :  return MED_SEG2;
80     case SALOME_MED::MED_SEG3     :  return MED_SEG3;
81     case SALOME_MED::MED_TRIA3    :  return MED_TRIA3;
82     case SALOME_MED::MED_QUAD4    :  return MED_QUAD4;
83     case SALOME_MED::MED_TRIA6    :  return MED_TRIA6;
84     case SALOME_MED::MED_QUAD8    :  return MED_QUAD8;
85     case SALOME_MED::MED_TETRA4   :  return MED_TETRA4;
86     case SALOME_MED::MED_PYRA5    :  return MED_PYRA5;
87     case SALOME_MED::MED_PENTA6   :  return MED_PENTA6;
88     case SALOME_MED::MED_HEXA8    :  return MED_HEXA8;
89     case SALOME_MED::MED_TETRA10  :  return MED_TETRA10;
90     case SALOME_MED::MED_PYRA13   :  return MED_PYRA13;
91     case SALOME_MED::MED_PENTA15  :  return MED_PENTA15;
92     case SALOME_MED::MED_HEXA20   :  return MED_HEXA20;
93     case SALOME_MED::MED_POLYGON      :  return MED_POLYGON;
94     case SALOME_MED::MED_POLYHEDRA    :  return MED_POLYHEDRA;
95     case SALOME_MED::MED_ALL_ELEMENTS :  return MED_ALL_ELEMENTS;
96     default :
97         { MESSAGE("unknown Geometry Element");
98           THROW_SALOME_CORBA_EXCEPTION("Unknown Geometry Element",
99                                         SALOME::INTERNAL_ERROR);
100         } 
101    }
102 }
103
104 SALOME_MED::medEntityMesh convertMedEntToIdlEnt(medEntityMesh entity)
105 throw (SALOME::SALOME_Exception)
106 {
107   switch (entity)
108     {
109     case MED_CELL    :  return SALOME_MED::MED_CELL;
110     case MED_FACE    :  return SALOME_MED::MED_FACE;
111     case MED_EDGE    :  return SALOME_MED::MED_EDGE;
112     case MED_NODE    :  return SALOME_MED::MED_NODE;
113     case MED_ALL_ENTITIES : return SALOME_MED::MED_ALL_ENTITIES;
114     default :
115         { MESSAGE("Unknown entity element");
116           THROW_SALOME_CORBA_EXCEPTION("Unknown Entity Element",
117                                         SALOME::INTERNAL_ERROR);
118         } 
119    }
120 }
121
122 medEntityMesh convertIdlEntToMedEnt(SALOME_MED::medEntityMesh entity)
123 throw (SALOME::SALOME_Exception)
124 {
125   switch (entity)
126     {
127     case SALOME_MED::MED_CELL    :  return MED_CELL; 
128     case SALOME_MED::MED_FACE    :  return MED_FACE;
129     case SALOME_MED::MED_EDGE    :  return MED_EDGE;
130     case SALOME_MED::MED_NODE    :  return MED_NODE;
131     case SALOME_MED::MED_ALL_ENTITIES : return MED_ALL_ENTITIES;
132     default :
133         { MESSAGE("Unknown Entity Element");
134           THROW_SALOME_CORBA_EXCEPTION("Unknown Entity Element",
135                                         SALOME::INTERNAL_ERROR);
136         } 
137    }
138 }
139
140 medModeSwitch convertIdlModeToMedMode(SALOME_MED::medModeSwitch mode)
141 throw (SALOME::SALOME_Exception)
142 {
143   switch (mode)
144     {
145     case SALOME_MED::MED_FULL_INTERLACE       : return MED_FULL_INTERLACE; 
146     case SALOME_MED::MED_NO_INTERLACE         : return MED_NO_INTERLACE; 
147     case SALOME_MED::MED_NO_INTERLACE_BY_TYPE : return MED_NO_INTERLACE_BY_TYPE; 
148     default :
149         { MESSAGE("Unknown interlace mode");
150           THROW_SALOME_CORBA_EXCEPTION("Unknown interlace mode",
151                                         SALOME::INTERNAL_ERROR);
152         } 
153    }
154 }
155
156 SALOME_MED::medModeSwitch convertMedModeToIdlMode(medModeSwitch mode)
157 throw (SALOME::SALOME_Exception)
158 {
159   switch (mode)
160     {
161     case MED_FULL_INTERLACE       :  return SALOME_MED::MED_FULL_INTERLACE; 
162     case MED_NO_INTERLACE         :  return SALOME_MED::MED_NO_INTERLACE; 
163     case MED_NO_INTERLACE_BY_TYPE :  return SALOME_MED::MED_NO_INTERLACE_BY_TYPE; 
164     default :
165         { MESSAGE("Unknown interlace mode");
166           THROW_SALOME_CORBA_EXCEPTION("Unknown interlace mode",
167                                         SALOME::INTERNAL_ERROR);
168         } 
169    }
170 }
171 SALOME_MED::medConnectivity convertMedConnToIdlConn(medConnectivity connectivite)
172 throw (SALOME::SALOME_Exception)
173 {
174   switch (connectivite)
175     {
176     case MED_NODAL       :  return SALOME_MED::MED_NODAL; 
177     case MED_DESCENDING  :  return SALOME_MED::MED_DESCENDING; 
178     default :
179         { MESSAGE("Unknown connectivity type");
180           THROW_SALOME_CORBA_EXCEPTION("Unknown connectivity type",
181                                         SALOME::INTERNAL_ERROR);
182         } 
183    }
184 }
185 medConnectivity convertIdlConnToMedConn(SALOME_MED::medConnectivity connectivite)
186 throw (SALOME::SALOME_Exception)
187 {
188   switch (connectivite)
189     {
190     case SALOME_MED::MED_NODAL       :  return MED_NODAL; 
191     case SALOME_MED::MED_DESCENDING  :  return MED_DESCENDING; 
192     default :
193         { MESSAGE("Unknown connectivity type");
194           THROW_SALOME_CORBA_EXCEPTION("Unknown connectivity type",
195                                         SALOME::INTERNAL_ERROR);
196         } 
197    }
198 }
199 SALOME_MED::medDriverTypes convertMedDriverToIdlDriver(MEDMEM::driverTypes driverType)
200 throw (SALOME::SALOME_Exception)
201 {
202   switch (driverType)
203     {
204     case MEDMEM::MED_DRIVER  :  return SALOME_MED::MED_DRIVER; 
205     case MEDMEM::VTK_DRIVER  :  return SALOME_MED::VTK_DRIVER; 
206     case MEDMEM::NO_DRIVER   :  return SALOME_MED::NO_DRIVER;
207     default :
208         { MESSAGE("Unknown driver type");
209           THROW_SALOME_CORBA_EXCEPTION("Unknown driver type",
210                                         SALOME::INTERNAL_ERROR);
211         } 
212    }
213 }
214
215 MEDMEM::driverTypes convertIdlDriverToMedDriver(SALOME_MED::medDriverTypes driverType)
216 throw (SALOME::SALOME_Exception)
217 {
218   switch (driverType)
219     {
220     case SALOME_MED::MED_DRIVER  :  return MEDMEM::MED_DRIVER; 
221     case SALOME_MED::VTK_DRIVER  :  return MEDMEM::VTK_DRIVER; 
222     case SALOME_MED::NO_DRIVER   :  return MEDMEM::NO_DRIVER;
223     default :
224         { MESSAGE("Unknown driver type");
225           THROW_SALOME_CORBA_EXCEPTION("Unknown driver type",
226                                         SALOME::INTERNAL_ERROR);
227         } 
228    }
229 }
230 bool verifieParam (SALOME_MED::medEntityMesh entity,SALOME_MED::medGeometryElement geomElement)
231 throw (SALOME::SALOME_Exception)
232 {
233   SCRUTE(entity);
234   SCRUTE(geomElement);
235   bool coherent=false;
236   switch (entity)
237    { 
238     case SALOME_MED::MED_FACE :
239        {
240          switch (geomElement)
241            {
242            case SALOME_MED::MED_TRIA3    : coherent=true;
243            case SALOME_MED::MED_QUAD4    : coherent=true;
244            case SALOME_MED::MED_TRIA6    : coherent=true;
245            case SALOME_MED::MED_QUAD8    : coherent=true;
246            case SALOME_MED::MED_POLYGON  : coherent=true;
247            }
248          break;
249        }
250     case SALOME_MED::MED_CELL :
251        {
252          switch (geomElement)
253            {
254            case SALOME_MED::MED_POINT1   : coherent=true;
255            case SALOME_MED::MED_SEG2     : coherent=true;
256            case SALOME_MED::MED_SEG3     : coherent=true;
257            case SALOME_MED::MED_TRIA3    : coherent=true;
258            case SALOME_MED::MED_TRIA6    : coherent=true;
259            case SALOME_MED::MED_QUAD4    : coherent=true;
260            case SALOME_MED::MED_QUAD8    : coherent=true;
261            case SALOME_MED::MED_TETRA4   : coherent=true;
262            case SALOME_MED::MED_TETRA10  : coherent=true;
263            case SALOME_MED::MED_HEXA8    : coherent=true;
264            case SALOME_MED::MED_HEXA20   : coherent=true;
265            case SALOME_MED::MED_PENTA6   : coherent=true;
266            case SALOME_MED::MED_PENTA15  : coherent=true;
267            case SALOME_MED::MED_PYRA5    : coherent=true;
268            case SALOME_MED::MED_PYRA13   : coherent=true;
269            case SALOME_MED::MED_POLYGON  : coherent=true;
270            case SALOME_MED::MED_POLYHEDRA: coherent=true;
271            }
272          break;
273        }
274     case SALOME_MED::MED_EDGE :
275        {
276          switch (geomElement)
277            {
278            case SALOME_MED::MED_SEG2     : coherent=true;
279            case SALOME_MED::MED_SEG3     : coherent=true;
280            }
281          break;
282        }         
283     case SALOME_MED::MED_NODE :
284        {
285          switch (geomElement)
286            {
287            case SALOME_MED::MED_POINT1   : coherent=true;
288            }
289          break;
290        }
291     case SALOME_MED::MED_ALL_ENTITIES :
292        {
293          switch (geomElement)
294            {
295            case SALOME_MED::MED_NONE     : coherent=true;
296            }
297          break;
298        }
299     default :
300         { MESSAGE("Unknown geometric entity");
301           THROW_SALOME_CORBA_EXCEPTION("Unknown geometric entity",
302                                         SALOME::INTERNAL_ERROR);
303         } 
304          break;
305     } 
306
307      switch (geomElement)
308      {
309            case SALOME_MED::MED_ALL_ELEMENTS     : coherent=true;
310      }
311     return coherent;
312 }