Salome HOME
Update copyright
[modules/smesh.git] / src / SMESH_I / SMESH_MEDSupport_i.cxx
1 // Copyright (C) 2007-2011  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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 //  File   : SMESH_MEDSupport_i.cxx
25 //  Module : SMESH
26 //
27 #include "SMESH_MEDSupport_i.hxx"
28 #include "utilities.h"
29 #include "Utils_CorbaException.hxx"
30 #include "Utils_ExceptHandlers.hxx"
31
32 #include <TopoDS_Iterator.hxx>
33 #include "SMESHDS_Mesh.hxx"
34
35 #include "SMESH_subMesh.hxx"
36 #include "SMESH_Mesh_i.hxx"
37 #include "SMESH_subMesh_i.hxx"
38
39 using namespace std;
40
41
42 //=============================================================================
43 /*!
44  * Default constructor
45  */
46 //=============================================================================
47 SMESH_MEDSupport_i::SMESH_MEDSupport_i()
48 {
49         BEGIN_OF("Default Constructor SMESH_MEDSupport_i");
50         END_OF("Default Constructor SMESH_MEDSupport_i");
51 }
52
53 //=============================================================================
54 /*!
55  * Constructor
56  */
57 //=============================================================================
58 SMESH_MEDSupport_i::SMESH_MEDSupport_i(SMESH_subMesh_i * sm, string name,
59         string description, SALOME_MED::medEntityMesh entity)
60         :_subMesh_i(sm), _name(name), _description(description), _entity(entity),
61         _seqNumber(false), _seqLength(0)
62 {
63         BEGIN_OF("Constructor SMESH_MEDSupport_i");
64
65         _meshDS = _subMesh_i->_mesh_i->GetImpl().GetMeshDS();
66
67         int subMeshId = _subMesh_i->GetId();
68
69         MESSAGE(" subMeshId " << subMeshId)
70
71         if (_subMesh_i->_mesh_i->_mapSubMesh.find(subMeshId) !=
72                 _subMesh_i->_mesh_i->_mapSubMesh.end())
73         {
74                 ::SMESH_subMesh * subMesh = _subMesh_i->_mesh_i->_mapSubMesh[subMeshId];
75                 _subMeshDS = subMesh->GetSubMeshDS();
76         }
77
78         if (_entity == SALOME_MED::MED_NODE)
79         {
80                 _numberOfGeometricType = 1;
81                 _geometricType = new SALOME_MED::medGeometryElement[1];
82                 _geometricType[0] = SALOME_MED::MED_NONE;
83         }
84         else
85         {
86                 MESSAGE("Pas implemente dans cette version");
87                 THROW_SALOME_CORBA_EXCEPTION
88                         ("Seules les familles de noeuds sont implementees ",
89                         SALOME::BAD_PARAM);
90         }
91
92         END_OF("Constructor SMESH_MEDSupport_i");
93 }
94
95 //=============================================================================
96 /*!
97  * Constructor
98  */
99 //=============================================================================
100 SMESH_MEDSupport_i::
101 SMESH_MEDSupport_i(const SMESH_MEDSupport_i & s):_subMesh_i(s._subMesh_i),
102 _name(s._name), _description(s._description), _entity(s._entity),
103 _seqNumber(false), _seqLength(0)
104 {
105         BEGIN_OF("Constructor SMESH_MEDSupport_i");
106
107         _meshDS = _subMesh_i->_mesh_i->GetImpl().GetMeshDS();
108
109         int subMeshId = _subMesh_i->GetId();
110         if (_subMesh_i->_mesh_i->_mapSubMesh.find(subMeshId) !=
111                 _subMesh_i->_mesh_i->_mapSubMesh.end())
112         {
113                 ::SMESH_subMesh * subMesh = _subMesh_i->_mesh_i->_mapSubMesh[subMeshId];
114                 _subMeshDS = subMesh->GetSubMeshDS();
115         }
116
117         END_OF("Constructor SMESH_MEDSupport_i");
118 }
119
120 //=============================================================================
121 /*!
122  * Destructor
123  */
124 //=============================================================================
125
126 SMESH_MEDSupport_i::~SMESH_MEDSupport_i()
127 {
128 }
129
130 //=============================================================================
131 /*!
132  * CORBA: Accessor for Corba Index 
133  */
134 //=============================================================================
135
136 CORBA::Long SMESH_MEDSupport_i::getCorbaIndex()throw(SALOME::SALOME_Exception)
137 {
138         if (_subMeshDS == NULL)
139                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
140                         SALOME::INTERNAL_ERROR);
141         MESSAGE("Not implemented for SMESH_i");
142         THROW_SALOME_CORBA_EXCEPTION("Not Implemented ", SALOME::BAD_PARAM);
143
144 }
145
146 //=============================================================================
147 /*!
148  * CORBA: Accessor for Name 
149  */
150 //=============================================================================
151
152 char *SMESH_MEDSupport_i::getName() throw(SALOME::SALOME_Exception)
153 {
154         if (_subMeshDS==NULL)
155                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
156                         SALOME::INTERNAL_ERROR);
157         return CORBA::string_dup(_name.c_str());
158
159 }
160
161 //=============================================================================
162 /*!
163  * CORBA: Accessor for Description 
164  */
165 //=============================================================================
166
167 char *SMESH_MEDSupport_i::getDescription() throw(SALOME::SALOME_Exception)
168 {
169         if (_subMeshDS==NULL)
170                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
171                         SALOME::INTERNAL_ERROR);
172         return CORBA::string_dup(_description.c_str());
173 }
174
175 //=============================================================================
176 /*!
177  * CORBA: Accessor for Mesh 
178  */
179 //=============================================================================
180
181 SALOME_MED::GMESH_ptr SMESH_MEDSupport_i::getMesh()throw(SALOME::
182         SALOME_Exception)
183 {
184         if (_subMeshDS==NULL)
185                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
186                         SALOME::INTERNAL_ERROR);
187
188         return _subMesh_i->_mesh_i->GetMEDMesh();
189 }
190
191 //=============================================================================
192 /*!
193  * CORBA: boolean indicating if support concerns all elements 
194  */
195 //=============================================================================
196
197 CORBA::Boolean SMESH_MEDSupport_i::isOnAllElements()throw(SALOME::
198         SALOME_Exception)
199 {
200         if (_subMeshDS==NULL)
201                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
202                         SALOME::INTERNAL_ERROR);
203         if (_seqNumber == false)
204         {
205                 if (_entity != SALOME_MED::MED_NONE)
206                 {
207                         _seqLength = _subMeshDS->NbNodes();
208                         _seqNumber = true;
209                 }
210                 else
211                 {
212                         MESSAGE("Only Node Families are implemented ");
213                         THROW_SALOME_CORBA_EXCEPTION("Not implemented Yet ",
214                                 SALOME::BAD_PARAM);
215                 }
216         }
217         try
218         {
219                 _isOnAllElements = (_seqLength == _meshDS->NbNodes());
220         }
221         catch(...)
222         {
223                 MESSAGE("unable to acces related Mesh");
224                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
225                         SALOME::INTERNAL_ERROR);
226         };
227         return _isOnAllElements;
228 }
229
230 //=============================================================================
231 /*!
232  * CORBA: Accessor for type of support's entity 
233  */
234 //=============================================================================
235
236 SALOME_MED::medEntityMesh SMESH_MEDSupport_i::getEntity()throw(SALOME::
237         SALOME_Exception)
238 {
239         if (_subMeshDS==NULL)
240                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
241                         SALOME::INTERNAL_ERROR);
242         return _entity;
243 }
244
245 //=============================================================================
246 /*!
247  * CORBA: Accessor for types of geometry elements 
248  */
249 //=============================================================================
250
251 SALOME_MED::medGeometryElement_array *
252         SMESH_MEDSupport_i::getTypes()throw(SALOME::SALOME_Exception)
253 {
254         if (_subMeshDS==NULL)
255                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
256                         SALOME::INTERNAL_ERROR);
257         SALOME_MED::medGeometryElement_array_var myseq =
258                 new SALOME_MED::medGeometryElement_array;
259         try
260         {
261                 int mySeqLength = _numberOfGeometricType;
262                 myseq->length(mySeqLength);
263                 for (int i = 0; i < mySeqLength; i++)
264                 {
265                         myseq[i] = _geometricType[i];
266                 }
267         }
268         catch(...)
269         {
270                 MESSAGE("Exception lors de la recherche des differents types");
271                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support Types",
272                         SALOME::INTERNAL_ERROR);
273         }
274         return myseq._retn();
275 }
276
277 //=============================================================================
278 /*!
279  * CORBA: Number of different types of geometry elements
280  *        existing in the support
281  */
282 //=============================================================================
283 CORBA::Long SMESH_MEDSupport_i::getNumberOfElements(SALOME_MED::
284         medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
285 {
286         if (_subMeshDS==NULL)
287                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
288                         SALOME::INTERNAL_ERROR);
289         return _numberOfGeometricType;
290
291 }
292
293 //=============================================================================
294 /*!
295  * CORBA: get Nodes 
296  */
297 //=============================================================================
298
299 SALOME_TYPES::ListOfLong * SMESH_MEDSupport_i::getNumber(
300         SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
301 {
302   Unexpect aCatch(SALOME_SalomeException);
303         if (_subMeshDS==NULL)
304                 THROW_SALOME_CORBA_EXCEPTION("No associated Support",
305                         SALOME::INTERNAL_ERROR);
306
307         // A changer s'il ne s agit plus seulement de famille de noeuds
308         if (geomElement != SALOME_MED::MED_NONE)
309                 THROW_SALOME_CORBA_EXCEPTION("Not implemented", SALOME::BAD_PARAM);
310
311         SALOME_TYPES::ListOfLong_var myseq = new SALOME_TYPES::ListOfLong;
312
313         int i = 0;
314         myseq->length(_subMeshDS->NbNodes());
315
316         SMDS_NodeIteratorPtr it = _subMeshDS->GetNodes();
317         while(it->more())
318         {
319                 myseq[i] = it->next()->GetID();
320                 i++;
321         };
322
323         SCRUTE(myseq->length());
324         MESSAGE("End of SMESH_MEDSupport_i::getNumber");
325         return myseq._retn();
326
327 }
328
329 //=============================================================================
330 /*!
331  * CORBA: get Nodes from file
332  */
333 //=============================================================================
334
335 SALOME_TYPES::ListOfLong * SMESH_MEDSupport_i::getNumberFromFile(
336         SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
337 {
338   return getNumber(geomElement);
339 }
340
341 //=============================================================================
342 /*!
343  * CORBA: Global Nodes Index (optionnaly designed by the user)
344  * CORBA:  ??????????????????????????????
345  */
346 //=============================================================================
347
348 SALOME_TYPES::ListOfLong *
349         SMESH_MEDSupport_i::getNumberIndex()throw(SALOME::SALOME_Exception)
350 {
351         MESSAGE("Not implemented for SMESH_i");
352         THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
353         return NULL;
354 }
355 //=============================================================================
356 /*!
357  * CORBA: Array containing indexes for elements included in the support  
358  */
359 //=============================================================================
360
361 CORBA::Long SMESH_MEDSupport_i::getNumberOfGaussPoint(SALOME_MED::
362         medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
363 {
364         MESSAGE("Not implemented for SMESH_i");
365         return 0;
366 }
367 //=============================================================================
368 /*!
369  * Gives the number of types of elements included in the support 
370  */
371 //=============================================================================
372 CORBA::Long SMESH_MEDSupport_i::getNumberOfTypes()
373   throw (SALOME::SALOME_Exception)
374 {
375   MESSAGE("!!! NOT YET IMPLEMENTED !!!!");
376   THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
377   return 0;
378 }
379 //=============================================================================
380 /*!
381  * Gives CORBA: Array containing the numbers of Gauss point of elements
382  * included in the support 
383  */
384 //=============================================================================
385 SALOME_TYPES::ListOfLong* SMESH_MEDSupport_i::getNumbersOfGaussPoint()
386   throw (SALOME::SALOME_Exception)
387 {
388   MESSAGE("!!! NOT YET IMPLEMENTED !!!!");
389   THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
390   return NULL;
391 }
392 //=============================================================================
393 /*!
394  * build the object which will contain all the boundary elements of the mesh.
395  */
396 //=============================================================================
397 void SMESH_MEDSupport_i::getBoundaryElements()
398   throw (SALOME::SALOME_Exception)
399 {
400   MESSAGE("!!! NOT YET IMPLEMENTED !!!!");
401   THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
402 }
403 //=============================================================================
404 /*!
405  * Gives information on the support
406  */
407 //=============================================================================
408 SALOME_MED::SUPPORT::supportInfos * SMESH_MEDSupport_i::getSupportGlobal()
409   throw (SALOME::SALOME_Exception)
410 {
411   MESSAGE("!!! NOT YET IMPLEMENTED !!!!");
412   THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
413   return NULL;
414 }