Salome HOME
fix indentation
[modules/smesh.git] / src / SMESH_I / SMESH_MEDMesh_i.cxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 //  File   : SMESH_MEDMesh_i.cxx
24 //  Module : SMESH
25 //
26 #include "SMESH_MEDMesh_i.hxx"
27 #include "SMESH_Mesh_i.hxx"
28
29 #include "SMESHDS_Mesh.hxx"
30 #include "SMESHDS_SubMesh.hxx"
31
32 #include <TopExp.hxx>
33 #include <TopExp_Explorer.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Iterator.hxx>
36 #include <TopoDS_Compound.hxx>
37 #include <TopoDS_CompSolid.hxx>
38 #include <TopoDS_Solid.hxx>
39 #include <TopoDS_Shell.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Wire.hxx>
42 #include <TopoDS_Edge.hxx>
43 #include <TopoDS_Vertex.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopTools_MapOfShape.hxx>
46
47 #include "utilities.h"
48 #include "Utils_CorbaException.hxx"
49
50 #include "SMESH_MEDSupport_i.hxx"
51 #include "SMESH_MEDFamily_i.hxx"
52
53 # include "Utils_ORB_INIT.hxx"
54 # include "Utils_SINGLETON.hxx"
55 # include "Utils_ExceptHandlers.hxx"
56
57 extern "C"
58 {
59 #include <stdio.h>
60 }
61
62 using namespace std;
63
64 //=============================================================================
65 /*!
66  * Default constructor
67  */
68 //=============================================================================
69 // PN Est-ce un const ?
70 SMESH_MEDMesh_i::SMESH_MEDMesh_i()
71 {
72   BEGIN_OF("Default Constructor SMESH_MEDMesh_i");
73   END_OF("Default Constructor SMESH_MEDMesh_i");
74 }
75
76 //=============================================================================
77 /*!
78  * Destructor
79  */
80 //=============================================================================
81 SMESH_MEDMesh_i::~SMESH_MEDMesh_i()
82 {
83 }
84
85 //=============================================================================
86 /*!
87  * Constructor
88  */
89 //=============================================================================
90 SMESH_MEDMesh_i::SMESH_MEDMesh_i(::SMESH_Mesh_i * m_i):_meshId(""),
91                                                        _compte(false),
92                                                        _creeFamily(false),
93                                                        _famIdent(0),
94                                                        _indexElts(0),
95                                                        _indexEnts(0)
96 {
97   BEGIN_OF("Constructor SMESH_MEDMesh_i");
98
99   _mesh_i = m_i;
100   _meshDS = _mesh_i->GetImpl().GetMeshDS();
101
102   END_OF("Constructor SMESH_MEDMesh_i");
103 }
104
105 //=============================================================================
106 /*!
107  * CORBA: Accessor for Name
108  */
109 //=============================================================================
110 char *SMESH_MEDMesh_i::getName() throw(SALOME::SALOME_Exception)
111 {
112   if (_meshDS == NULL)
113     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
114                                  SALOME::INTERNAL_ERROR);
115
116   try
117   {
118     // A COMPLETER PAR LE NOM DU MAILLAGE
119     //return CORBA::string_dup(_mesh_i->getName().c_str());
120     return CORBA::string_dup("toto");
121   }
122   catch(...)
123   {
124     MESSAGE("Exception en accedant au nom");
125     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
126                                  SALOME::INTERNAL_ERROR);
127   }
128 }
129
130 //=============================================================================
131 /*!
132  * CORBA: Accessor for corbaindex cuisine interne 
133  */
134 //=============================================================================
135 CORBA::Long SMESH_MEDMesh_i::getCorbaIndex()throw(SALOME::SALOME_Exception)
136 {
137   MESSAGE("Non Implemente");
138   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
139 }
140
141 //=============================================================================
142 /*!
143  * CORBA: Accessor for Space Dimension
144  */
145 //=============================================================================
146 CORBA::Long SMESH_MEDMesh_i::getSpaceDimension()throw(SALOME::SALOME_Exception)
147 {
148   // PN : Il semblerait que la dimension soit fixee a 3
149   if (_mesh_i == 0)
150     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
151                                  SALOME::INTERNAL_ERROR);
152   return 3;
153 }
154
155 //=============================================================================
156 /*!
157  * CORBA: Accessor for Mesh Dimension
158  */
159 //=============================================================================
160 CORBA::Long SMESH_MEDMesh_i::getMeshDimension()throw(SALOME::SALOME_Exception)
161 {
162   if (_mesh_i == 0)
163     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
164                                  SALOME::INTERNAL_ERROR);
165   // PN : Il semblerait que la dimension soit fixee a 3
166   if (_mesh_i == 0)
167     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
168                                  SALOME::INTERNAL_ERROR);
169   return 3;
170 }
171 //=============================================================================
172 /*!
173  * CORBA: Accessor for the boolean _isAGrid
174  */
175 //=============================================================================
176 CORBA::Boolean SMESH_MEDMesh_i::getIsAGrid() throw (SALOME::SALOME_Exception)
177 {
178   MESSAGE("!!!!!! NOT YET IMPLEMENTED !!!!!!");
179
180   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
181
182   return false;
183 }
184 //=============================================================================
185 /*!
186  * CORBA: Accessor for the connectivities, to see if they exist
187  */
188 //=============================================================================
189 CORBA::Boolean
190 SMESH_MEDMesh_i::existConnectivity(SALOME_MED::medConnectivity connectivityType,
191                                    SALOME_MED::medEntityMesh entity)
192   throw (SALOME::SALOME_Exception)
193 {
194   MESSAGE("!!!!!! IMPLEMENTED BUT ONLY PARTIALLY !!!!!!");
195
196
197   return false;
198
199 }
200 //=============================================================================
201 /*!
202  * CORBA: Accessor for Coordinate
203  */
204 //=============================================================================
205 CORBA::Double SMESH_MEDMesh_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
206   throw (SALOME::SALOME_Exception)
207 {
208   MESSAGE("!!!!!! NOT YET IMPLEMENTED !!!!");
209
210   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
211
212   return 0.0;
213 }
214 //=============================================================================
215 /*!
216  * CORBA: Accessor for Coordinates System
217  */
218 //=============================================================================
219 char *SMESH_MEDMesh_i::getCoordinatesSystem() throw(SALOME::SALOME_Exception)
220 {
221   if (_mesh_i == 0)
222     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
223                                  SALOME::INTERNAL_ERROR);
224   // PN : En dur. Non encore prevu
225   try
226   {
227     string systcoo = "CARTESIEN";
228     return CORBA::string_dup(systcoo.c_str());
229   }
230   catch(...)
231   {
232     MESSAGE("Exception en accedant au maillage");
233     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
234                                  SALOME::INTERNAL_ERROR);
235   }
236 }
237
238 //=============================================================================
239 /*!
240  * CORBA: Accessor for Coordinates
241  */
242 //=============================================================================
243 SALOME_MED::double_array * SMESH_MEDMesh_i::getCoordinates(
244                                                            SALOME_MED::medModeSwitch typeSwitch) throw(SALOME::SALOME_Exception)
245 {
246   if (_mesh_i == 0)
247     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
248                                  SALOME::INTERNAL_ERROR);
249   SALOME_MED::double_array_var myseq = new SALOME_MED::double_array;
250   try
251   {
252     // PN  : En dur
253     int spaceDimension = 3;
254     int nbNodes = _meshDS->NbNodes();
255     SCRUTE(nbNodes);
256     myseq->length(nbNodes * spaceDimension);
257     int i = 0;
258
259     SMDS_NodeIteratorPtr itNodes=_meshDS->nodesIterator();
260     while(itNodes->more())
261     {
262       const SMDS_MeshNode* node = itNodes->next();
263
264       if (typeSwitch == SALOME_MED::MED_FULL_INTERLACE)
265       {
266         myseq[i * 3] = node->X();
267         myseq[i * 3 + 1] = node->Y();
268         myseq[i * 3 + 2] = node->Z();
269         SCRUTE(myseq[i * 3]);
270         SCRUTE(myseq[i * 3 + 1]);
271         SCRUTE(myseq[i * 3 + 2]);
272       }
273       else
274       {
275         ASSERT(typeSwitch == SALOME_MED::MED_NO_INTERLACE);
276         myseq[i] = node->X();
277         myseq[i + nbNodes] = node->Y();
278         myseq[i + (nbNodes * 2)] = node->Z();
279         SCRUTE(myseq[i]);
280         SCRUTE(myseq[i + nbNodes]);
281         SCRUTE(myseq[i + (nbNodes * 2)]);
282       }
283       i++;
284     }
285   }
286   catch(...)
287   {
288     MESSAGE("Exception en accedant aux coordonnees");
289     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
290                                  SALOME::INTERNAL_ERROR);
291   }
292   return myseq._retn();
293 }
294
295 //=============================================================================
296 /*!
297  * CORBA: Accessor for Coordinates Names
298  */
299 //=============================================================================
300 SALOME_MED::string_array *
301 SMESH_MEDMesh_i::getCoordinatesNames()throw(SALOME::SALOME_Exception)
302 {
303   if (_mesh_i == 0)
304     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
305                                  SALOME::INTERNAL_ERROR);
306   SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
307   try
308   {
309     // PN : en dur
310     int spaceDimension = 3;
311     myseq->length(spaceDimension);
312     myseq[0] = CORBA::string_dup("x");
313     myseq[1] = CORBA::string_dup("y");
314     myseq[2] = CORBA::string_dup("z");
315   }
316   catch(...)
317   {
318     MESSAGE("Exception en accedant aux noms des coordonnees");
319     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
320                                  SALOME::INTERNAL_ERROR);
321   }
322   return myseq._retn();
323
324 }
325
326 //=============================================================================
327 /*!
328  * CORBA: Accessor for Coordinates Units
329  */
330 //=============================================================================
331 SALOME_MED::string_array *
332 SMESH_MEDMesh_i::getCoordinatesUnits()throw(SALOME::SALOME_Exception)
333 {
334   if (_mesh_i == 0)
335     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
336                                  SALOME::INTERNAL_ERROR);
337   SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
338   try
339   {
340     // PN : en dur
341     int spaceDimension = 3;
342     myseq->length(spaceDimension);
343     myseq[0] = CORBA::string_dup("m");
344     myseq[1] = CORBA::string_dup("m");
345     myseq[2] = CORBA::string_dup("m");
346   }
347   catch(...)
348   {
349     MESSAGE("Exception en accedant aux unites des coordonnees");
350     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
351                                  SALOME::INTERNAL_ERROR);
352   }
353   return myseq._retn();
354 }
355
356 //=============================================================================
357 /*!
358  * CORBA: Accessor for Number of Nodes
359  */
360 //=============================================================================
361 CORBA::Long SMESH_MEDMesh_i::getNumberOfNodes()throw(SALOME::SALOME_Exception)
362 {
363   if (_mesh_i == 0)
364     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
365                                  SALOME::INTERNAL_ERROR);
366   try
367   {
368     return _meshDS->NbNodes();
369   }
370   catch(...)
371   {
372     MESSAGE("Exception en accedant au nombre de noeuds");
373     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
374                                  SALOME::INTERNAL_ERROR);
375   }
376 }
377
378 //=============================================================================
379 /*!
380  * CORBA: Accessor for number of Types
381  */
382 //=============================================================================
383 CORBA::Long SMESH_MEDMesh_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity)
384   throw(SALOME::SALOME_Exception)
385 {
386   if (_mesh_i == 0)
387     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
388                                  SALOME::INTERNAL_ERROR);
389   try
390   {
391     if (!_compte)
392       calculeNbElts();
393     int retour = 0;
394     if (_mapNbTypes.find(entity) != _mapNbTypes.end())
395       retour = _mapNbTypes[entity];
396     return retour;
397   }
398   catch(...)
399   {
400     MESSAGE("Exception en accedant au nombre de Types");
401     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
402                                  SALOME::INTERNAL_ERROR);
403   }
404 }
405
406 //=============================================================================
407 /*!
408  * CORBA: Accessor for existing geometry element types 
409  *        Not implemented for MED_ALL_ENTITIES
410  */
411 //=============================================================================
412 SALOME_MED::medGeometryElement_array *
413 SMESH_MEDMesh_i::getTypes(SALOME_MED::medEntityMesh entity) throw(SALOME::
414                                                                   SALOME_Exception)
415 {
416   if (_mesh_i == 0)
417     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
418                                  SALOME::INTERNAL_ERROR);
419   if (entity == SALOME_MED::MED_ALL_ENTITIES)
420     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",
421                                  SALOME::BAD_PARAM);
422   if (!_compte)
423     calculeNbElts();
424   SALOME_MED::medGeometryElement_array_var myseq =
425     new SALOME_MED::medGeometryElement_array;
426   try
427   {
428     if (_mapNbTypes.find(entity) == _mapNbTypes.end())
429       THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
430                                    SALOME::BAD_PARAM);
431     int nbTypes = _mapNbTypes[entity];
432
433     myseq->length(nbTypes);
434
435     if (_mapIndToVectTypes.find(entity) == _mapIndToVectTypes.end())
436       THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
437                                    SALOME::INTERNAL_ERROR);
438
439     int index = _mapIndToVectTypes[entity];
440     ASSERT(_TypesId[index].size() != 0);
441     int i = 0;
442     vector < SALOME_MED::medGeometryElement >::iterator it;
443     for (it = _TypesId[index].begin(); it != _TypesId[index].end(); it++)
444     {
445       myseq[i++] = *it;
446     };
447   }
448   catch(...)
449   {
450     MESSAGE("Exception en accedant aux differents types");
451     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
452                                  SALOME::INTERNAL_ERROR);
453   }
454   return myseq._retn();
455 }
456
457 //=============================================================================
458 /*!
459  * CORBA: Returns number of elements of type medGeometryElement
460  *        Not implemented for MED_ALL_ELEMENTS 
461  *        implemented for MED_ALL_ENTITIES
462  *
463  * Dans cette implementation, il n est pas prevu de tenir compte du entity
464  * qui ne doit pas pouvoir avoir deux valeurs differentes pour un geomElement 
465  */
466 //=============================================================================
467 CORBA::Long SMESH_MEDMesh_i::getNumberOfElements(SALOME_MED::
468                                                  medEntityMesh entity,
469                                                  SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
470 {
471   if (_mesh_i == 0)
472     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
473                                  SALOME::INTERNAL_ERROR);
474   if (geomElement == SALOME_MED::MED_ALL_ELEMENTS)
475     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ELEMENTS",
476                                  SALOME::BAD_PARAM);
477   if (!_compte)
478     calculeNbElts();
479
480   try
481   {
482     int retour = 0;
483     if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
484     {
485       int index = _mapIndToSeqElts[geomElement];
486
487       retour = _seq_elemId[index]->length();
488     }
489     return retour;
490   }
491   catch(...)
492   {
493     MESSAGE("Exception en accedant au nombre d élements");
494     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
495                                  SALOME::INTERNAL_ERROR);
496   }
497 }
498
499 //=============================================================================
500 /*!
501  * CORBA: Accessor for connectivities
502  */
503 //=============================================================================
504 SALOME_MED::long_array *
505 SMESH_MEDMesh_i::getConnectivity(SALOME_MED::medModeSwitch typeSwitch,
506                                  SALOME_MED::medConnectivity mode,
507                                  SALOME_MED::medEntityMesh entity,
508                                  SALOME_MED::medGeometryElement geomElement)
509   throw(SALOME::SALOME_Exception)
510 {
511   if (_mesh_i == 0)
512     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
513                                  SALOME::INTERNAL_ERROR);
514   if (mode != SALOME_MED::MED_NODAL)
515     THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
516   if (typeSwitch == SALOME_MED::MED_NO_INTERLACE)
517     THROW_SALOME_CORBA_EXCEPTION("Not Yet Implemented", SALOME::BAD_PARAM);
518   if (!_compte)
519     calculeNbElts();
520
521   // Faut-il renvoyer un pointeur vide ???
522   if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
523     THROW_SALOME_CORBA_EXCEPTION("No Such Element in the mesh",
524                                  SALOME::BAD_PARAM);
525
526   int index = _mapIndToSeqElts[geomElement];
527
528   return _seq_elemId[index]._retn();
529 }
530
531 //=============================================================================
532 /*!
533  * CORBA: Accessor for connectivities
534  */
535 //=============================================================================
536 SALOME_MED::long_array *
537 SMESH_MEDMesh_i::getConnectivityIndex(SALOME_MED::medConnectivity mode,
538                                       SALOME_MED::medEntityMesh entity)
539   throw(SALOME::SALOME_Exception)
540 {
541   MESSAGE("Pas Implemente dans SMESH");
542   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
543   return 0;
544 }
545
546 //=============================================================================
547 /*!
548  * CORBA: Find an element corresponding to the given connectivity
549  */
550 //=============================================================================
551 CORBA::Long
552 SMESH_MEDMesh_i::getElementNumber(SALOME_MED::medConnectivity mode,
553                                   SALOME_MED::medEntityMesh entity,
554                                   SALOME_MED::medGeometryElement type,
555                                   const SALOME_MED::long_array & connectivity)
556   throw(SALOME::SALOME_Exception)
557 {
558   const char *LOC = "getElementNumber ";
559   MESSAGE(LOC << "Pas Implemente dans SMESH");
560   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
561   return -1;
562 }
563
564 //=============================================================================
565 /*!
566  * CORBA: Accessor for Ascendant connectivities
567  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
568  */
569 //=============================================================================
570 SALOME_MED::long_array *
571 SMESH_MEDMesh_i::getReverseConnectivity(SALOME_MED::
572                                         medConnectivity mode) throw(SALOME::SALOME_Exception)
573 {
574   MESSAGE("Pas Implemente dans SMESH");
575   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
576   return 0;
577 }
578
579 //=============================================================================
580 /*!
581  * CORBA: Accessor for connectivities
582  */
583 //=============================================================================
584 SALOME_MED::long_array *
585 SMESH_MEDMesh_i::getReverseConnectivityIndex(SALOME_MED::
586                                              medConnectivity mode) throw(SALOME::SALOME_Exception)
587 {
588   MESSAGE("Pas Implemente dans SMESH");
589   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
590   return 0;
591 }
592
593 //=============================================================================
594 /*!
595  * CORBA: Returns number of families within the mesh
596  */
597 //=============================================================================
598 CORBA::Long SMESH_MEDMesh_i::getNumberOfFamilies(SALOME_MED::
599                                                  medEntityMesh entity) throw(SALOME::SALOME_Exception)
600 {
601   if (_creeFamily == false)
602     createFamilies();
603   if (_mesh_i == 0)
604     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
605                                  SALOME::INTERNAL_ERROR);
606   return _families.size();
607 }
608
609 //=============================================================================
610 /*!
611  * CORBA: Returns number of groups within the mesh
612  */
613 //=============================================================================
614 CORBA::Long SMESH_MEDMesh_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity)
615   throw(SALOME::SALOME_Exception)
616 {
617   if (_mesh_i == 0)
618     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
619                                  SALOME::INTERNAL_ERROR);
620   MESSAGE(" Pas d implementation des groupes dans SMESH");
621   return 0;
622 }
623
624 //=============================================================================
625 /*!
626  * CORBA: Returns references for families within the mesh
627  */
628 //=============================================================================
629 SALOME_MED::Family_array *
630 SMESH_MEDMesh_i::getFamilies(SALOME_MED::
631                              medEntityMesh entity) throw(SALOME::SALOME_Exception)
632 {
633   if (_creeFamily == false)
634     createFamilies();
635   if (_mesh_i == 0)
636     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
637                                  SALOME::INTERNAL_ERROR);
638   SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
639   int nbfam = _families.size();
640   myseq->length(nbfam);
641   int i = 0;
642   vector < SALOME_MED::FAMILY_ptr >::iterator it;
643   for (it = _families.begin(); it != _families.end(); it++)
644   {
645     myseq[i++] = *it;
646   };
647   return myseq._retn();
648 }
649
650 //=============================================================================
651 /*!
652  * CORBA: Returns references for family i within the mesh
653  */
654 //=============================================================================
655 SALOME_MED::FAMILY_ptr SMESH_MEDMesh_i::getFamily(SALOME_MED::
656                                                   medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
657 {
658   if (_creeFamily == false)
659     createFamilies();
660   if (_mesh_i == 0)
661     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
662                                  SALOME::INTERNAL_ERROR);
663
664   SCRUTE(_families[i]->getName());
665   MESSAGE(" SMESH_MEDMesh_i::getFamily " << i) return _families[i];
666 }
667
668 //=============================================================================
669 /*!
670  * CORBA: Returns references for groups within the mesh
671  */
672 //=============================================================================
673 SALOME_MED::Group_array *
674 SMESH_MEDMesh_i::getGroups(SALOME_MED::medEntityMesh entity) throw(SALOME::
675                                                                    SALOME_Exception)
676 {
677   if (_mesh_i == 0)
678     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
679                                  SALOME::INTERNAL_ERROR);
680   MESSAGE(" Pas d implementation des groupes dans SMESH");
681   THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
682 }
683
684 //=============================================================================
685 /*!
686  * CORBA: Returns references for group i within the mesh
687  */
688 //=============================================================================
689 SALOME_MED::GROUP_ptr SMESH_MEDMesh_i::getGroup(SALOME_MED::
690                                                 medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
691 {
692   if (_mesh_i == 0)
693     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
694                                  SALOME::INTERNAL_ERROR);
695   MESSAGE(" Pas d implementation des groupes dans SMESH");
696   THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
697 }
698 //=============================================================================
699 /*!
700  * CORBA: Returns references for the global numbering index
701  */
702 //=============================================================================
703 SALOME_MED::long_array*
704 SMESH_MEDMesh_i::getGlobalNumberingIndex(SALOME_MED::medEntityMesh entity)
705   throw (SALOME::SALOME_Exception)
706 {
707   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
708
709   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
710
711   return NULL;
712 }
713 //=============================================================================
714 /*!
715  * CORBA: Returns references for the support of boundary elements of type
716  * entity
717  */
718 //=============================================================================
719 SALOME_MED::SUPPORT_ptr
720 SMESH_MEDMesh_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
721   throw (SALOME::SALOME_Exception)
722 {
723   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
724
725   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
726
727   return NULL;
728 }
729 //=============================================================================
730 /*!
731  * CORBA:  Method return a reference on a support define on all the element of
732  *         an entity.
733  */
734 //=============================================================================
735 SALOME_MED::SUPPORT_ptr
736 SMESH_MEDMesh_i::getSupportOnAll(SALOME_MED::medEntityMesh entity)
737   throw (SALOME::SALOME_Exception)
738 {
739   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
740
741   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
742
743   return NULL;
744 }
745 //=============================================================================
746 /*!
747  * CORBA: Returns references for the support of the skin of the support
748  * mySupport3D
749  */
750 //=============================================================================
751 SALOME_MED::SUPPORT_ptr
752 SMESH_MEDMesh_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
753   throw (SALOME::SALOME_Exception)
754 {
755   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
756
757   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
758
759   return NULL;
760 }
761 //=============================================================================
762 /*!
763  * CORBA: 
764  */
765 //=============================================================================
766 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::
767                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
768 {
769   MESSAGE("Pas Implemente dans SMESH");
770   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
771   return 0;
772 }
773
774 //=============================================================================
775 /*!
776  * CORBA: 
777  */
778 //=============================================================================
779 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::
780                                                SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
781 {
782   MESSAGE("Pas Implemente dans SMESH");
783   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
784   return 0;
785 }
786
787 //=============================================================================
788 /*!
789  * CORBA: 
790  */
791 //=============================================================================
792 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::
793                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
794 {
795   MESSAGE("Pas Implemente dans SMESH");
796   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
797   return 0;
798 }
799
800 //=============================================================================
801 /*!
802  * CORBA: 
803  */
804 //=============================================================================
805 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::
806                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
807 {
808   MESSAGE("Pas Implemente dans SMESH");
809   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
810   return 0;
811 }
812
813 //=============================================================================
814 /*!
815  * CORBA: 
816  */
817 //=============================================================================
818 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::
819                                                      SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
820 {
821   MESSAGE("Pas Implemente dans SMESH");
822   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
823   return 0;
824 }
825
826 //=============================================================================
827 /*!
828  * CORBA: 
829  */
830 //=============================================================================
831 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::
832                                                         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
833 {
834   MESSAGE("Non Implemente");
835   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
836   return 0;
837 }
838
839 //=============================================================================
840 /*!
841  * CORBA: add the Mesh in the StudyManager 
842  * PN Pas Implemente
843  */
844 //=============================================================================
845 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
846                                  SALOME_MED::MESH_ptr myIor) throw(SALOME::SALOME_Exception)
847 {
848   BEGIN_OF("MED_Mesh_i::addInStudy");
849   if (_meshId != "")
850   {
851     MESSAGE("Mesh already in Study");
852     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
853                                  SALOME::BAD_PARAM);
854   };
855
856   /*
857    * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
858    * 
859    * // Create SComponent labelled 'MED' if it doesn't already exit
860    * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
861    * if ( CORBA::is_nil(medfather) ) 
862    * {
863    * MESSAGE("Add Component MED");
864    * medfather = myBuilder->NewComponent("MED");
865    * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
866    * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
867    * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
868    * aName->SetValue("MED");
869    * 
870    * myBuilder->DefineComponentInstance(medfather,myIor);
871    * 
872    * } ;
873    * 
874    * MESSAGE("Add a mesh Object under MED");
875    * myBuilder->NewCommand();
876    * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
877    * 
878    * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
879    * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
880    * CORBA::ORB_var &orb = init(0,0);
881    * CORBA::String_var iorStr = orb->object_to_string(myIor);
882    * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.in());
883    * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
884    * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
885    * aIOR->SetValue(iorStr.c_str());
886    * 
887    * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
888    * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
889    * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
890    * aName->SetValue(_mesh_i->getName().c_str());
891    * 
892    * _meshId = newObj->GetID();
893    * myBuilder->CommitCommand();
894    * 
895    */
896   END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
897 }
898
899 //=============================================================================
900 /*!
901  * CORBA: write mesh in a med file
902  */
903 //=============================================================================
904 void SMESH_MEDMesh_i::write(CORBA::Long i, const char *driverMeshName)
905   throw(SALOME::SALOME_Exception)
906 {
907   MESSAGE("Non Implemente");
908   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
909 }
910
911 //=============================================================================
912 /*!
913  * CORBA: read mesh in a med file
914  */
915 //=============================================================================
916 void SMESH_MEDMesh_i::read(CORBA::Long i) throw(SALOME::SALOME_Exception)
917 {
918   MESSAGE("Non Implemente");
919   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
920 }
921
922 //=============================================================================
923 /*!
924  * CORBA : release driver
925  */
926 //=============================================================================
927 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i) throw(SALOME::SALOME_Exception)
928 {
929   MESSAGE("Non Implemente");
930   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
931 }
932
933 //=============================================================================
934 /*!
935  * CORBA : attach driver
936  */
937 //=============================================================================
938 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType,
939                                        const char *fileName, const char *meshName) throw(SALOME::SALOME_Exception)
940 {
941   MESSAGE("Non Implemente");
942   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
943   return 0;
944 }
945
946 //=============================================================================
947 /*!
948  * Calcule le Nb d'elements par entite geometrique
949  */
950 //=============================================================================
951 void SMESH_MEDMesh_i::calculeNbElts() throw(SALOME::SALOME_Exception)
952 {
953   if (!_compte)
954   {
955     _compte = true;
956
957     _mapNbTypes[SALOME_MED::MED_NODE] = 1;
958     // On compte les aretes MED_SEG2 ou MED_SEG3
959     // On range les elements dans  les vecteurs correspondants 
960
961     _mapIndToSeqElts[SALOME_MED::MED_SEG2] = _indexElts++;
962     _mapIndToSeqElts[SALOME_MED::MED_SEG3] = _indexElts++;
963     _mapIndToVectTypes[SALOME_MED::MED_EDGE] = _indexEnts++;
964
965     int trouveSeg2 = 0;
966     int trouveSeg3 = 0;
967     SALOME_MED::medGeometryElement medElement;
968
969     SMDS_EdgeIteratorPtr itEdges=_meshDS->edgesIterator();
970     while(itEdges->more())
971     {
972       const SMDS_MeshEdge* elem = itEdges->next();
973       int nb_of_nodes = elem->NbNodes();
974
975       switch (nb_of_nodes)
976       {
977       case 2:
978         {
979           medElement = SALOME_MED::MED_SEG2;
980           if (trouveSeg2 == 0)
981           {
982             trouveSeg2 = 1;
983             _TypesId[SALOME_MED::MED_EDGE].
984               push_back(SALOME_MED::MED_SEG2);
985           }
986           break;
987         }
988       case 3:
989         {
990           medElement = SALOME_MED::MED_SEG3;
991           if (trouveSeg3 == 0)
992           {
993             trouveSeg3 = 1;
994             _TypesId[SALOME_MED::MED_EDGE].
995               push_back(SALOME_MED::MED_SEG3);
996           }
997           break;
998         }
999       }
1000       int index = _mapIndToSeqElts[medElement];
1001       SCRUTE(index);
1002       // Traitement de l arete
1003
1004       int longueur = _seq_elemId[index]->length();
1005       _seq_elemId[index]->length(longueur + nb_of_nodes);
1006
1007       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1008
1009       for(int k=0; itn->more(); k++)
1010         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1011     }
1012
1013     _mapNbTypes[SALOME_MED::MED_EDGE] = trouveSeg2 + trouveSeg3;
1014
1015     // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
1016     // On range les elements dans  les vecteurs correspondants 
1017     int trouveTria3 = 0;
1018     int trouveTria6 = 0;
1019     int trouveQuad4 = 0;
1020
1021     _mapIndToSeqElts[SALOME_MED::MED_TRIA3] = _indexElts++;
1022     _mapIndToSeqElts[SALOME_MED::MED_TRIA6] = _indexElts++;
1023     _mapIndToSeqElts[SALOME_MED::MED_QUAD4] = _indexElts++;
1024     _mapIndToVectTypes[SALOME_MED::MED_FACE] = _indexEnts++;
1025
1026     SMDS_FaceIteratorPtr itFaces=_meshDS->facesIterator();
1027     while(itFaces->more())
1028     {
1029       const SMDS_MeshFace * elem = itFaces->next();
1030       int nb_of_nodes = elem->NbNodes();
1031
1032       switch (nb_of_nodes)
1033       {
1034       case 3:
1035         {
1036           medElement = SALOME_MED::MED_TRIA3;
1037           if (trouveTria3 == 0)
1038           {
1039             trouveTria3 = 1;
1040             _TypesId[SALOME_MED::MED_FACE].
1041               push_back(SALOME_MED::MED_TRIA3);
1042           }
1043           break;
1044         }
1045       case 4:
1046         {
1047           medElement = SALOME_MED::MED_QUAD4;
1048           if (trouveQuad4 == 0)
1049           {
1050             trouveQuad4 = 1;
1051             _TypesId[SALOME_MED::MED_FACE].
1052               push_back(SALOME_MED::MED_QUAD4);
1053           }
1054           break;
1055         }
1056       case 6:
1057         {
1058           medElement = SALOME_MED::MED_TRIA6;
1059           if (trouveTria6 == 0)
1060           {
1061             trouveTria6 = 1;
1062             _TypesId[SALOME_MED::MED_FACE].
1063               push_back(SALOME_MED::MED_TRIA6);
1064           }
1065           break;
1066         }
1067       }
1068       int index = _mapIndToSeqElts[medElement];
1069       SCRUTE(index);
1070
1071       // Traitement de la face
1072       // Attention La numérotation des noeuds Med commence a 1
1073
1074       int longueur = _seq_elemId[index]->length();
1075       _seq_elemId[index]->length(longueur + nb_of_nodes);
1076
1077       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1078
1079       for(int k=0; itn->more(); k++)
1080         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1081     } //itFaces
1082
1083     _mapNbTypes[SALOME_MED::MED_FACE] =
1084       trouveTria3 + trouveTria6 + trouveQuad4;
1085
1086     _mapIndToSeqElts[SALOME_MED::MED_HEXA8] = _indexElts++;
1087     _mapIndToVectTypes[SALOME_MED::MED_CELL] = _indexEnts++;
1088     int index = _mapIndToSeqElts[medElement];
1089
1090     int trouveHexa8 = 0;
1091
1092     SMDS_VolumeIteratorPtr itVolumes=_meshDS->volumesIterator();
1093     while(itVolumes->more())
1094     {
1095       const SMDS_MeshVolume * elem = itVolumes->next();
1096
1097       int nb_of_nodes = elem->NbNodes();
1098       medElement = SALOME_MED::MED_HEXA8;
1099       ASSERT(nb_of_nodes == 8);
1100
1101       if (trouveHexa8 == 0)
1102       {
1103         trouveHexa8 = 1;
1104         _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
1105       };
1106       // Traitement de la maille
1107       int longueur = _seq_elemId[index]->length();
1108       _seq_elemId[index]->length(longueur + nb_of_nodes);
1109
1110       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1111       for(int k=0; itn->more(); k++)
1112         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1113     }
1114
1115     _mapNbTypes[SALOME_MED::MED_CELL] = trouveHexa8;
1116     _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1117       =
1118       trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 +
1119       trouveSeg3;
1120   }// fin du _compte
1121 };
1122
1123 //=============================================================================
1124 /*!
1125  * Creation des familles
1126  */
1127 //=============================================================================
1128 void SMESH_MEDMesh_i::createFamilies() throw(SALOME::SALOME_Exception)
1129 {
1130   Unexpect aCatch(SALOME_SalomeException);
1131   string famDes = ("Je ne sais pas");
1132   string famName0 = "Famille_";
1133   string famName;
1134   char numero[10];
1135
1136   if (_creeFamily == false)
1137   {
1138     _creeFamily = true;
1139     //SMESH_subMesh_i *subMeshServant;
1140
1141     map < int, SMESH_subMesh_i * >::iterator it;
1142     for (it = _mesh_i->_mapSubMesh_i.begin();
1143          it != _mesh_i->_mapSubMesh_i.end(); it++)
1144     {
1145       SMESH_subMesh_i *submesh_i = (*it).second;
1146       int famIdent = (*it).first;
1147
1148       ASSERT(famIdent < 999999999);
1149       sprintf(numero, "%d\n", famIdent);
1150       famName = famName0 + numero;
1151
1152       SMESH_MEDFamily_i *famservant =
1153         new SMESH_MEDFamily_i(famIdent, submesh_i,
1154                               famName, famDes, SALOME_MED::MED_NODE);
1155 #ifdef WNT
1156       SALOME_MED::FAMILY_ptr famille = SALOME_MED::FAMILY::_nil();
1157       POA_SALOME_MED::FAMILY* servantbase = dynamic_cast<POA_SALOME_MED::FAMILY*>(famservant);
1158       if ( servantbase )
1159         famille = SALOME_MED::FAMILY::_narrow( servantbase->_this() );
1160 #else 
1161       SALOME_MED::FAMILY_ptr famille = 
1162         SALOME_MED::FAMILY::_narrow( famservant->POA_SALOME_MED::FAMILY::_this() );
1163 #endif
1164       _families.push_back(famille);
1165     }
1166   }
1167 };
1168 //=============================================================================
1169 /*!
1170  * Gives informations of the considered mesh.
1171  */
1172 //=============================================================================
1173 SALOME_MED::MESH::meshInfos * SMESH_MEDMesh_i::getMeshGlobal()
1174   throw (SALOME::SALOME_Exception)
1175 {
1176   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1177
1178   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1179
1180   return NULL;
1181 }
1182 //=============================================================================
1183 /*!
1184  * Gives informations on coordinates of the considered mesh.
1185  */
1186 //=============================================================================
1187 SALOME_MED::MESH::coordinateInfos * SMESH_MEDMesh_i::getCoordGlobal()
1188   throw (SALOME::SALOME_Exception)
1189 {
1190   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1191
1192   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1193
1194   return NULL;
1195 }
1196 //=============================================================================
1197 /*!
1198  * Gives informations on connectivities of the considered mesh for the entity
1199  * entity.
1200  */
1201 //=============================================================================
1202 SALOME_MED::MESH::connectivityInfos *
1203 SMESH_MEDMesh_i::getConnectGlobal(SALOME_MED::medEntityMesh entity)
1204   throw (SALOME::SALOME_Exception)
1205 {
1206   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1207
1208   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1209
1210   return NULL;
1211 }
1212 //=============================================================================
1213 /*!
1214  * Gives the type of the element number of entity entity
1215  */
1216 //=============================================================================
1217 SALOME_MED::medGeometryElement
1218 SMESH_MEDMesh_i::getElementType(SALOME_MED::medEntityMesh entity,
1219                                 CORBA::Long number)
1220   throw (SALOME::SALOME_Exception)
1221 {
1222   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1223
1224   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1225
1226   return (SALOME_MED::medGeometryElement) 0;
1227 }