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