Salome HOME
make GetMaxArea const
[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 #include "SMDS_MapIteratorOfExtendedMap.hxx"
35
36 #include "SMESH_subMesh.hxx"
37 #include "SMESH_Mesh_i.hxx"
38 #include "SMESH_subMesh_i.hxx"
39
40 //=============================================================================
41 /*!
42  * Default constructor
43  */
44 //=============================================================================
45 SMESH_MEDSupport_i::SMESH_MEDSupport_i()
46 {
47   BEGIN_OF("Default Constructor SMESH_MEDSupport_i");
48   END_OF("Default Constructor SMESH_MEDSupport_i");
49 }
50
51 //=============================================================================
52 /*!
53  * Constructor
54  */
55 //=============================================================================
56 SMESH_MEDSupport_i::SMESH_MEDSupport_i(SMESH_subMesh_i* sm,
57                                        string name, 
58                                        string description,
59                                        SALOME_MED::medEntityMesh entity) :
60   _subMesh_i(sm),               
61   _name(name),
62   _description(description),
63   _entity(entity),
64   _seqNumber(false),
65   _seqLength(0)
66 {
67   BEGIN_OF("Constructor SMESH_MEDSupport_i");
68
69   _meshDS = _subMesh_i->_mesh_i->GetImpl().GetMeshDS();
70
71   int subMeshId = _subMesh_i->GetId();
72
73   MESSAGE ( " subMeshId " << subMeshId )
74   if (_subMesh_i->_mesh_i->_mapSubMesh.find(subMeshId) != _subMesh_i->_mesh_i->_mapSubMesh.end()) {
75     ::SMESH_subMesh* subMesh = _subMesh_i->_mesh_i->_mapSubMesh[subMeshId];
76     
77     _subMeshDS = subMesh->GetSubMeshDS();
78   }
79
80   if ( _entity == SALOME_MED::MED_NODE) 
81     {
82       _numberOfGeometricType = 1 ;
83       _geometricType         = new SALOME_MED::medGeometryElement[1] ;
84       _geometricType[0]      = SALOME_MED::MED_NONE ;
85     }
86   else
87     {
88       MESSAGE("Pas implemente dans cette version");
89       THROW_SALOME_CORBA_EXCEPTION("Seules les familles de noeuds sont implementees ", \
90                                    SALOME::BAD_PARAM);
91     }
92
93   END_OF("Constructor SMESH_MEDSupport_i");
94 }
95 //=============================================================================
96 /*!
97  * Constructor
98  */
99 //=============================================================================
100 SMESH_MEDSupport_i::SMESH_MEDSupport_i(const SMESH_MEDSupport_i &s) :
101   _subMesh_i(s._subMesh_i),
102   _name(s._name),
103   _description(s._description),
104   _entity(s._entity),
105   _seqNumber(false),
106   _seqLength(0)
107 {
108   BEGIN_OF("Constructor SMESH_MEDSupport_i");
109
110   _meshDS = _subMesh_i->_mesh_i->GetImpl().GetMeshDS();
111
112   int subMeshId = _subMesh_i->GetId();
113   if (_subMesh_i->_mesh_i->_mapSubMesh.find(subMeshId) != _subMesh_i->_mesh_i->_mapSubMesh.end()) {
114     ::SMESH_subMesh* subMesh = _subMesh_i->_mesh_i->_mapSubMesh[subMeshId];
115     _subMeshDS = subMesh->GetSubMeshDS();
116   }
117
118   END_OF("Constructor SMESH_MEDSupport_i");
119 }
120 //=============================================================================
121 /*!
122  * Destructor
123  */
124 //=============================================================================
125
126 SMESH_MEDSupport_i::~SMESH_MEDSupport_i()
127 {
128 }
129 //=============================================================================
130 /*!
131  * CORBA: Accessor for Corba Index 
132  */
133 //=============================================================================
134
135 CORBA::Long SMESH_MEDSupport_i::getCorbaIndex()
136   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 ", \
143                                SALOME::BAD_PARAM);
144
145 }
146
147 //=============================================================================
148 /*!
149  * CORBA: Accessor for Name 
150  */
151 //=============================================================================
152
153 char * SMESH_MEDSupport_i::getName()    
154   throw (SALOME::SALOME_Exception)
155 {
156   if (_subMeshDS.IsNull())
157     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
158                                  SALOME::INTERNAL_ERROR);
159   return CORBA::string_dup(_name.c_str());
160
161 }
162
163 //=============================================================================
164 /*!
165  * CORBA: Accessor for Description 
166  */
167 //=============================================================================
168
169 char*  SMESH_MEDSupport_i::getDescription()
170   throw (SALOME::SALOME_Exception)
171 {
172   if (_subMeshDS.IsNull())
173     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
174                                  SALOME::INTERNAL_ERROR);
175   return CORBA::string_dup(_description.c_str());
176 }
177
178 //=============================================================================
179 /*!
180  * CORBA: Accessor for Mesh 
181  */
182 //=============================================================================
183
184 SALOME_MED::MESH_ptr SMESH_MEDSupport_i::getMesh()
185   throw (SALOME::SALOME_Exception)
186 {
187   if (_subMeshDS.IsNull())
188     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
189                                  SALOME::INTERNAL_ERROR);
190   
191   return _subMesh_i->_mesh_i->GetMEDMesh();
192 }
193
194 //=============================================================================
195 /*!
196  * CORBA: boolean indicating if support concerns all elements 
197  */
198 //=============================================================================
199
200 CORBA::Boolean SMESH_MEDSupport_i::isOnAllElements()
201   throw (SALOME::SALOME_Exception)
202 {
203   if (_subMeshDS.IsNull())
204     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
205                                  SALOME::INTERNAL_ERROR);
206   if (_seqNumber == false)
207   {
208     if (_entity != SALOME_MED::MED_NONE)
209     {
210         int i = 0;
211         const SMDS_MapOfMeshElement& myNodesMap = _subMeshDS->GetNodes();
212         for (SMDS_MapIteratorOfExtendedMap it(myNodesMap); it.More(); it.Next())
213         {
214                 const Handle(SMDS_MeshElement)& elem = myNodesMap.FindID(it.Key()->GetID());
215                 const Handle(SMDS_MeshNode)& node = _meshDS->GetNode(1,elem);
216                 i ++;
217         }
218         _seqLength=i;
219         _seqNumber=true;
220     }
221     else
222     {
223       MESSAGE("Only Node Families are implemented ");
224       THROW_SALOME_CORBA_EXCEPTION("Not implemented Yet ", \
225                                    SALOME::BAD_PARAM);
226     }
227    }
228   try
229     {
230      if (_seqLength == _meshDS->NbNodes())
231        _isOnAllElements=true;
232      else
233        _isOnAllElements=false;
234   }
235   catch(...)
236   {
237       MESSAGE("unable to acces related Mesh");
238       THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
239                                    SALOME::INTERNAL_ERROR);
240    };
241   return _isOnAllElements;
242 }
243
244 //=============================================================================
245 /*!
246  * CORBA: Accessor for type of support's entity 
247  */
248 //=============================================================================
249
250 SALOME_MED::medEntityMesh SMESH_MEDSupport_i::getEntity() 
251   throw (SALOME::SALOME_Exception)
252 {
253   if (_subMeshDS.IsNull())
254     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
255                                  SALOME::INTERNAL_ERROR);
256   return _entity;
257 }
258
259 //=============================================================================
260 /*!
261  * CORBA: Accessor for types of geometry elements 
262  */
263 //=============================================================================
264
265 SALOME_MED::medGeometryElement_array * SMESH_MEDSupport_i::getTypes() 
266   throw (SALOME::SALOME_Exception)
267 {
268   if (_subMeshDS.IsNull())
269     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
270                                  SALOME::INTERNAL_ERROR);
271   SALOME_MED::medGeometryElement_array_var myseq = new SALOME_MED::medGeometryElement_array;
272   try
273     {
274       int mySeqLength = _numberOfGeometricType;
275       myseq->length(mySeqLength);
276       for (int i=0;i<mySeqLength;i++)
277         {
278           myseq[i]=_geometricType[i];
279         }
280     }
281   catch(...)
282     {
283       MESSAGE("Exception lors de la recherche des differents types");
284       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support Types", \
285                                    SALOME::INTERNAL_ERROR);
286     }
287   return myseq._retn();
288 }
289
290 //=============================================================================
291 /*!
292  * CORBA: Number of different types of geometry elements
293  *        existing in the support
294  */
295 //=============================================================================
296 CORBA::Long SMESH_MEDSupport_i::getNumberOfElements(SALOME_MED::medGeometryElement geomElement) 
297   throw (SALOME::SALOME_Exception)
298 {
299   if (_subMeshDS.IsNull())
300     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
301                                  SALOME::INTERNAL_ERROR);
302   return  _numberOfGeometricType;
303
304 }
305
306 //=============================================================================
307 /*!
308  * CORBA: get Nodes 
309  */
310 //=============================================================================
311
312 Engines::long_array *  SMESH_MEDSupport_i::getNumber(SALOME_MED::medGeometryElement geomElement) 
313   throw (SALOME::SALOME_Exception)
314 {
315   if (_subMeshDS.IsNull())
316     THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
317                                  SALOME::INTERNAL_ERROR);
318
319
320   // A changer s'il ne s agit plus seulement de famille de noeuds
321   if (geomElement != SALOME_MED::MED_NONE)
322     THROW_SALOME_CORBA_EXCEPTION("Not implemented", \
323                                  SALOME::BAD_PARAM);
324
325   Engines::long_array_var myseq= new Engines::long_array;
326
327   int i =0;
328   const SMDS_MapOfMeshElement& myNodesMap = _subMeshDS->GetNodes();
329   for (SMDS_MapIteratorOfExtendedMap it(myNodesMap); it.More(); it.Next())
330     {
331       const Handle(SMDS_MeshElement)& elem = myNodesMap.FindID(it.Key()->GetID());
332       const Handle(SMDS_MeshNode)& node = _meshDS->GetNode(1,elem);
333       myseq->length(i+1);
334       myseq[i]=node->GetID();
335 SCRUTE(node->GetID());
336 SCRUTE(myseq[i]);
337       i++;
338     };
339
340 SCRUTE(myseq->length());
341 MESSAGE("yyyyy");
342   return myseq._retn();
343         
344 }
345 //=============================================================================
346 /*!
347  * CORBA: Global Nodes Index (optionnaly designed by the user)
348  * CORBA:  ??????????????????????????????
349  */
350 //=============================================================================
351
352 Engines::long_array *  SMESH_MEDSupport_i::getNumberIndex()
353   throw (SALOME::SALOME_Exception)
354 {
355   MESSAGE("Not implemented for SMESH_i");
356   THROW_SALOME_CORBA_EXCEPTION("Not Implemented", \
357                                SALOME::BAD_PARAM);
358   return 0;
359 }
360
361 //=============================================================================
362 /*!
363  * CORBA: Array containing indexes for elements included in the support  
364  */
365 //=============================================================================
366
367 CORBA::Long SMESH_MEDSupport_i::getNumberOfGaussPoints(SALOME_MED::medGeometryElement geomElement)
368   throw (SALOME::SALOME_Exception)
369 {
370   MESSAGE("Not implemented for SMESH_i");
371   return 0;
372 }
373