Salome HOME
9f3fe859ffaf5d0ddf4a5b2b7169e92815ce1716
[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 /*!
748  * CORBA: Returns references for the support of the skin of the support
749  * mySupport3D
750  */
751 //=============================================================================
752 SALOME_MED::SUPPORT_ptr
753 SMESH_MEDMesh_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
754   throw (SALOME::SALOME_Exception)
755 {
756   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
757
758   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
759
760   return NULL;
761 }
762 //=============================================================================
763 /*!
764  * CORBA: 
765  */
766 //=============================================================================
767 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::
768         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
769 {
770         MESSAGE("Pas Implemente dans SMESH");
771         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
772         return 0;
773 }
774
775 //=============================================================================
776 /*!
777  * CORBA: 
778  */
779 //=============================================================================
780 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::
781         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
782 {
783         MESSAGE("Pas Implemente dans SMESH");
784         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
785         return 0;
786 }
787
788 //=============================================================================
789 /*!
790  * CORBA: 
791  */
792 //=============================================================================
793 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::
794         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
795 {
796         MESSAGE("Pas Implemente dans SMESH");
797         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
798         return 0;
799 }
800
801 //=============================================================================
802 /*!
803  * CORBA: 
804  */
805 //=============================================================================
806 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::
807         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
808 {
809         MESSAGE("Pas Implemente dans SMESH");
810         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
811         return 0;
812 }
813
814 //=============================================================================
815 /*!
816  * CORBA: 
817  */
818 //=============================================================================
819 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::
820         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
821 {
822         MESSAGE("Pas Implemente dans SMESH");
823         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
824         return 0;
825 }
826
827 //=============================================================================
828 /*!
829  * CORBA: 
830  */
831 //=============================================================================
832 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::
833         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
834 {
835         MESSAGE("Non Implemente");
836         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
837         return 0;
838 }
839
840 //=============================================================================
841 /*!
842  * CORBA: add the Mesh in the StudyManager 
843  * PN Pas Implemente
844  */
845 //=============================================================================
846 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
847         SALOME_MED::MESH_ptr myIor) throw(SALOME::SALOME_Exception)
848 {
849         BEGIN_OF("MED_Mesh_i::addInStudy");
850         if (_meshId != "")
851         {
852                 MESSAGE("Mesh already in Study");
853                 THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
854                         SALOME::BAD_PARAM);
855         };
856
857         /*
858          * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
859          * 
860          * // Create SComponent labelled 'MED' if it doesn't already exit
861          * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
862          * if ( CORBA::is_nil(medfather) ) 
863          * {
864          * MESSAGE("Add Component MED");
865          * medfather = myBuilder->NewComponent("MED");
866          * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
867          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
868          * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
869          * aName->SetValue("MED");
870          * 
871          * myBuilder->DefineComponentInstance(medfather,myIor);
872          * 
873          * } ;
874          * 
875          * MESSAGE("Add a mesh Object under MED");
876          * myBuilder->NewCommand();
877          * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
878          * 
879          * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
880          * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
881          * CORBA::ORB_var &orb = init(0,0);
882          * CORBA::String_var iorStr = orb->object_to_string(myIor);
883          * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.in());
884          * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
885          * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
886          * aIOR->SetValue(iorStr.c_str());
887          * 
888          * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
889          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
890          * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
891          * aName->SetValue(_mesh_i->getName().c_str());
892          * 
893          * _meshId = newObj->GetID();
894          * myBuilder->CommitCommand();
895          * 
896          */
897         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
898 }
899
900 //=============================================================================
901 /*!
902  * CORBA: write mesh in a med file
903  */
904 //=============================================================================
905 void SMESH_MEDMesh_i::write(CORBA::Long i, const char *driverMeshName)
906 throw(SALOME::SALOME_Exception)
907 {
908         MESSAGE("Non Implemente");
909         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
910 }
911
912 //=============================================================================
913 /*!
914  * CORBA: read mesh in a med file
915  */
916 //=============================================================================
917 void SMESH_MEDMesh_i::read(CORBA::Long i) throw(SALOME::SALOME_Exception)
918 {
919         MESSAGE("Non Implemente");
920         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
921 }
922
923 //=============================================================================
924 /*!
925  * CORBA : release driver
926  */
927 //=============================================================================
928 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i) throw(SALOME::SALOME_Exception)
929 {
930         MESSAGE("Non Implemente");
931         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
932 }
933
934 //=============================================================================
935 /*!
936  * CORBA : attach driver
937  */
938 //=============================================================================
939 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType,
940         const char *fileName, const char *meshName) throw(SALOME::SALOME_Exception)
941 {
942         MESSAGE("Non Implemente");
943         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
944         return 0;
945 }
946
947 //=============================================================================
948 /*!
949  * Calcule le Nb d'elements par entite geometrique
950  */
951 //=============================================================================
952 void SMESH_MEDMesh_i::calculeNbElts() throw(SALOME::SALOME_Exception)
953 {
954         if (!_compte)
955         {
956                 _compte = true;
957
958                 _mapNbTypes[SALOME_MED::MED_NODE] = 1;
959                 // On compte les aretes MED_SEG2 ou MED_SEG3
960                 // On range les elements dans  les vecteurs correspondants 
961
962                 _mapIndToSeqElts[SALOME_MED::MED_SEG2] = _indexElts++;
963                 _mapIndToSeqElts[SALOME_MED::MED_SEG3] = _indexElts++;
964                 _mapIndToVectTypes[SALOME_MED::MED_EDGE] = _indexEnts++;
965
966                 int trouveSeg2 = 0;
967                 int trouveSeg3 = 0;
968                 SALOME_MED::medGeometryElement medElement;
969
970                 SMDS_EdgeIteratorPtr itEdges=_meshDS->edgesIterator();
971                 while(itEdges->more())
972                 {
973                         const SMDS_MeshEdge* elem = itEdges->next();
974                         int nb_of_nodes = elem->NbNodes();
975
976                         switch (nb_of_nodes)
977                         {
978                         case 2:
979                         {
980                                 medElement = SALOME_MED::MED_SEG2;
981                                 if (trouveSeg2 == 0)
982                                 {
983                                         trouveSeg2 = 1;
984                                         _TypesId[SALOME_MED::MED_EDGE].
985                                                 push_back(SALOME_MED::MED_SEG2);
986                                 }
987                                 break;
988                         }
989                         case 3:
990                         {
991                                 medElement = SALOME_MED::MED_SEG3;
992                                 if (trouveSeg3 == 0)
993                                 {
994                                         trouveSeg3 = 1;
995                                         _TypesId[SALOME_MED::MED_EDGE].
996                                                 push_back(SALOME_MED::MED_SEG3);
997                                 }
998                                 break;
999                         }
1000                         }
1001                         int index = _mapIndToSeqElts[medElement];
1002                         SCRUTE(index);
1003                         // Traitement de l arete
1004
1005                         int longueur = _seq_elemId[index]->length();
1006                         _seq_elemId[index]->length(longueur + nb_of_nodes);
1007
1008                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1009
1010                         for(int k=0; itn->more(); k++)
1011                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1012                 }
1013
1014                 _mapNbTypes[SALOME_MED::MED_EDGE] = trouveSeg2 + trouveSeg3;
1015
1016                 // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
1017                 // On range les elements dans  les vecteurs correspondants 
1018                 int trouveTria3 = 0;
1019                 int trouveTria6 = 0;
1020                 int trouveQuad4 = 0;
1021
1022                 _mapIndToSeqElts[SALOME_MED::MED_TRIA3] = _indexElts++;
1023                 _mapIndToSeqElts[SALOME_MED::MED_TRIA6] = _indexElts++;
1024                 _mapIndToSeqElts[SALOME_MED::MED_QUAD4] = _indexElts++;
1025                 _mapIndToVectTypes[SALOME_MED::MED_FACE] = _indexEnts++;
1026
1027                 SMDS_FaceIteratorPtr itFaces=_meshDS->facesIterator();
1028                 while(itFaces->more())
1029                 {
1030                         const SMDS_MeshFace * elem = itFaces->next();
1031                         int nb_of_nodes = elem->NbNodes();
1032
1033                         switch (nb_of_nodes)
1034                         {
1035                         case 3:
1036                         {
1037                                 medElement = SALOME_MED::MED_TRIA3;
1038                                 if (trouveTria3 == 0)
1039                                 {
1040                                         trouveTria3 = 1;
1041                                         _TypesId[SALOME_MED::MED_FACE].
1042                                                 push_back(SALOME_MED::MED_TRIA3);
1043                                 }
1044                                 break;
1045                         }
1046                         case 4:
1047                         {
1048                                 medElement = SALOME_MED::MED_QUAD4;
1049                                 if (trouveQuad4 == 0)
1050                                 {
1051                                         trouveQuad4 = 1;
1052                                         _TypesId[SALOME_MED::MED_FACE].
1053                                                 push_back(SALOME_MED::MED_QUAD4);
1054                                 }
1055                                 break;
1056                         }
1057                         case 6:
1058                         {
1059                                 medElement = SALOME_MED::MED_TRIA6;
1060                                 if (trouveTria6 == 0)
1061                                 {
1062                                         trouveTria6 = 1;
1063                                         _TypesId[SALOME_MED::MED_FACE].
1064                                                 push_back(SALOME_MED::MED_TRIA6);
1065                                 }
1066                                 break;
1067                         }
1068                         }
1069                         int index = _mapIndToSeqElts[medElement];
1070                         SCRUTE(index);
1071
1072                         // Traitement de la face
1073                         // Attention La numérotation des noeuds Med commence a 1
1074
1075                         int longueur = _seq_elemId[index]->length();
1076                         _seq_elemId[index]->length(longueur + nb_of_nodes);
1077
1078                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1079
1080                         for(int k=0; itn->more(); k++)
1081                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1082                 } //itFaces
1083
1084                 _mapNbTypes[SALOME_MED::MED_FACE] =
1085                         trouveTria3 + trouveTria6 + trouveQuad4;
1086
1087                 _mapIndToSeqElts[SALOME_MED::MED_HEXA8] = _indexElts++;
1088                 _mapIndToVectTypes[SALOME_MED::MED_CELL] = _indexEnts++;
1089                 int index = _mapIndToSeqElts[medElement];
1090
1091                 int trouveHexa8 = 0;
1092
1093                 SMDS_VolumeIteratorPtr itVolumes=_meshDS->volumesIterator();
1094                 while(itVolumes->more())
1095                 {
1096                         const SMDS_MeshVolume * elem = itVolumes->next();
1097
1098                         int nb_of_nodes = elem->NbNodes();
1099                         medElement = SALOME_MED::MED_HEXA8;
1100                         ASSERT(nb_of_nodes == 8);
1101
1102                         if (trouveHexa8 == 0)
1103                         {
1104                                 trouveHexa8 = 1;
1105                                 _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
1106                         };
1107                         // Traitement de la maille
1108                         int longueur = _seq_elemId[index]->length();
1109                         _seq_elemId[index]->length(longueur + nb_of_nodes);
1110
1111                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1112                         for(int k=0; itn->more(); k++)
1113                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1114                 }
1115
1116                 _mapNbTypes[SALOME_MED::MED_CELL] = trouveHexa8;
1117                 _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1118                         =
1119                         trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 +
1120                         trouveSeg3;
1121         }// fin du _compte
1122 };
1123
1124 //=============================================================================
1125 /*!
1126  * Creation des familles
1127  */
1128 //=============================================================================
1129 void SMESH_MEDMesh_i::createFamilies() throw(SALOME::SALOME_Exception)
1130 {
1131   Unexpect aCatch(SALOME_SalomeException);
1132         string famDes = ("Je ne sais pas");
1133         string famName0 = "Famille_";
1134         string famName;
1135         char numero[10];
1136
1137         if (_creeFamily == false)
1138         {
1139                 _creeFamily = true;
1140                 //SMESH_subMesh_i *subMeshServant;
1141
1142                 map < int, SMESH_subMesh_i * >::iterator it;
1143                 for (it = _mesh_i->_mapSubMesh_i.begin();
1144                         it != _mesh_i->_mapSubMesh_i.end(); it++)
1145                 {
1146                         SMESH_subMesh_i *submesh_i = (*it).second;
1147                         int famIdent = (*it).first;
1148
1149                         ASSERT(famIdent < 999999999);
1150                         sprintf(numero, "%d\n", famIdent);
1151                         famName = famName0 + numero;
1152
1153                         SMESH_MEDFamily_i *famservant =
1154                                 new SMESH_MEDFamily_i(famIdent, submesh_i,
1155                                 famName, famDes, SALOME_MED::MED_NODE);
1156 #ifdef WNT
1157       SALOME_MED::FAMILY_ptr famille = SALOME_MED::FAMILY::_nil();
1158       POA_SALOME_MED::FAMILY* servantbase = dynamic_cast<POA_SALOME_MED::FAMILY*>(famservant);
1159       if ( servantbase )
1160         famille = SALOME_MED::FAMILY::_narrow( servantbase->_this() );
1161 #else 
1162                 SALOME_MED::FAMILY_ptr famille = 
1163         SALOME_MED::FAMILY::_narrow( famservant->POA_SALOME_MED::FAMILY::_this() );
1164 #endif
1165                         _families.push_back(famille);
1166                 }
1167         }
1168 };
1169 //=============================================================================
1170 /*!
1171  * Gives informations of the considered mesh.
1172  */
1173 //=============================================================================
1174 SALOME_MED::MESH::meshInfos * SMESH_MEDMesh_i::getMeshGlobal()
1175   throw (SALOME::SALOME_Exception)
1176 {
1177   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1178
1179   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1180
1181   return NULL;
1182 }
1183 //=============================================================================
1184 /*!
1185  * Gives informations on coordinates of the considered mesh.
1186  */
1187 //=============================================================================
1188 SALOME_MED::MESH::coordinateInfos * SMESH_MEDMesh_i::getCoordGlobal()
1189   throw (SALOME::SALOME_Exception)
1190 {
1191   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1192
1193   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1194
1195   return NULL;
1196 }
1197 //=============================================================================
1198 /*!
1199  * Gives informations on connectivities of the considered mesh for the entity
1200  * entity.
1201  */
1202 //=============================================================================
1203 SALOME_MED::MESH::connectivityInfos *
1204 SMESH_MEDMesh_i::getConnectGlobal(SALOME_MED::medEntityMesh entity)
1205   throw (SALOME::SALOME_Exception)
1206 {
1207   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1208
1209   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1210
1211   return NULL;
1212 }
1213 //=============================================================================
1214 /*!
1215  * Gives the type of the element number of entity entity
1216  */
1217 //=============================================================================
1218 SALOME_MED::medGeometryElement
1219 SMESH_MEDMesh_i::getElementType(SALOME_MED::medEntityMesh entity,
1220                                 CORBA::Long number)
1221   throw (SALOME::SALOME_Exception)
1222 {
1223   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1224
1225   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1226
1227   return (SALOME_MED::medGeometryElement) 0;
1228 }