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