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