Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESH_I / SMESH_MEDMesh_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_MEDMesh_i.cxx
25 //  Module : SMESH
26
27 using namespace std;
28 #include "SMESH_MEDMesh_i.hxx"
29 #include "SMESH_Mesh_i.hxx"
30
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33
34 #include <TopExp.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <TopoDS.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TopoDS_CompSolid.hxx>
40 #include <TopoDS_Solid.hxx>
41 #include <TopoDS_Shell.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopTools_MapOfShape.hxx>
48
49 #include "utilities.h"
50 #include "Utils_CorbaException.hxx"
51
52 #include "SMESH_MEDSupport_i.hxx"
53 #include "SMESH_MEDFamily_i.hxx"
54
55 # include "Utils_ORB_INIT.hxx"
56 # include "Utils_SINGLETON.hxx"
57 # include "Utils_ExceptHandlers.hxx"
58
59 extern "C"
60 {
61 #include <stdio.h>
62 }
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: Returns references for the support of the skin of the support
732  * mySupport3D
733  */
734 //=============================================================================
735 SALOME_MED::SUPPORT_ptr
736 SMESH_MEDMesh_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
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: 
748  */
749 //=============================================================================
750 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::
751         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
752 {
753         MESSAGE("Pas Implemente dans SMESH");
754         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
755         return 0;
756 }
757
758 //=============================================================================
759 /*!
760  * CORBA: 
761  */
762 //=============================================================================
763 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::
764         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
765 {
766         MESSAGE("Pas Implemente dans SMESH");
767         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
768         return 0;
769 }
770
771 //=============================================================================
772 /*!
773  * CORBA: 
774  */
775 //=============================================================================
776 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::
777         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
778 {
779         MESSAGE("Pas Implemente dans SMESH");
780         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
781         return 0;
782 }
783
784 //=============================================================================
785 /*!
786  * CORBA: 
787  */
788 //=============================================================================
789 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::
790         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
791 {
792         MESSAGE("Pas Implemente dans SMESH");
793         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
794         return 0;
795 }
796
797 //=============================================================================
798 /*!
799  * CORBA: 
800  */
801 //=============================================================================
802 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::
803         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
804 {
805         MESSAGE("Pas Implemente dans SMESH");
806         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
807         return 0;
808 }
809
810 //=============================================================================
811 /*!
812  * CORBA: 
813  */
814 //=============================================================================
815 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::
816         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
817 {
818         MESSAGE("Non Implemente");
819         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
820         return 0;
821 }
822
823 //=============================================================================
824 /*!
825  * CORBA: add the Mesh in the StudyManager 
826  * PN Pas Implemente
827  */
828 //=============================================================================
829 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
830         SALOME_MED::MESH_ptr myIor) throw(SALOME::SALOME_Exception)
831 {
832         BEGIN_OF("MED_Mesh_i::addInStudy");
833         if (_meshId != "")
834         {
835                 MESSAGE("Mesh already in Study");
836                 THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
837                         SALOME::BAD_PARAM);
838         };
839
840         /*
841          * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
842          * 
843          * // Create SComponent labelled 'MED' if it doesn't already exit
844          * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
845          * if ( CORBA::is_nil(medfather) ) 
846          * {
847          * MESSAGE("Add Component MED");
848          * medfather = myBuilder->NewComponent("MED");
849          * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
850          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
851          * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
852          * aName->SetValue("MED");
853          * 
854          * myBuilder->DefineComponentInstance(medfather,myIor);
855          * 
856          * } ;
857          * 
858          * MESSAGE("Add a mesh Object under MED");
859          * myBuilder->NewCommand();
860          * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
861          * 
862          * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
863          * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
864          * CORBA::ORB_var &orb = init(0,0);
865          * string iorStr = orb->object_to_string(myIor);
866          * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.c_str());
867          * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
868          * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
869          * aIOR->SetValue(iorStr.c_str());
870          * 
871          * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
872          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
873          * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
874          * aName->SetValue(_mesh_i->getName().c_str());
875          * 
876          * _meshId = newObj->GetID();
877          * myBuilder->CommitCommand();
878          * 
879          */
880         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
881 }
882
883 //=============================================================================
884 /*!
885  * CORBA: write mesh in a med file
886  */
887 //=============================================================================
888 void SMESH_MEDMesh_i::write(CORBA::Long i, const char *driverMeshName)
889 throw(SALOME::SALOME_Exception)
890 {
891         MESSAGE("Non Implemente");
892         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
893 }
894
895 //=============================================================================
896 /*!
897  * CORBA: read mesh in a med file
898  */
899 //=============================================================================
900 void SMESH_MEDMesh_i::read(CORBA::Long i) throw(SALOME::SALOME_Exception)
901 {
902         MESSAGE("Non Implemente");
903         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
904 }
905
906 //=============================================================================
907 /*!
908  * CORBA : release driver
909  */
910 //=============================================================================
911 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i) throw(SALOME::SALOME_Exception)
912 {
913         MESSAGE("Non Implemente");
914         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
915 }
916
917 //=============================================================================
918 /*!
919  * CORBA : attach driver
920  */
921 //=============================================================================
922 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType,
923         const char *fileName, const char *meshName) throw(SALOME::SALOME_Exception)
924 {
925         MESSAGE("Non Implemente");
926         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
927         return 0;
928 }
929
930 //=============================================================================
931 /*!
932  * Calcule le Nb d'elements par entite geometrique
933  */
934 //=============================================================================
935 void SMESH_MEDMesh_i::calculeNbElts() throw(SALOME::SALOME_Exception)
936 {
937         if (!_compte)
938         {
939                 _compte = true;
940
941                 _mapNbTypes[SALOME_MED::MED_NODE] = 1;
942                 // On compte les aretes MED_SEG2 ou MED_SEG3
943                 // On range les elements dans  les vecteurs correspondants 
944
945                 _mapIndToSeqElts[SALOME_MED::MED_SEG2] = _indexElts++;
946                 _mapIndToSeqElts[SALOME_MED::MED_SEG3] = _indexElts++;
947                 _mapIndToVectTypes[SALOME_MED::MED_EDGE] = _indexEnts++;
948
949                 int trouveSeg2 = 0;
950                 int trouveSeg3 = 0;
951                 SALOME_MED::medGeometryElement medElement;
952
953                 SMDS_EdgeIteratorPtr itEdges=_meshDS->edgesIterator();
954                 while(itEdges->more())
955                 {
956                         const SMDS_MeshEdge* elem = itEdges->next();
957                         int nb_of_nodes = elem->NbNodes();
958
959                         switch (nb_of_nodes)
960                         {
961                         case 2:
962                         {
963                                 medElement = SALOME_MED::MED_SEG2;
964                                 if (trouveSeg2 == 0)
965                                 {
966                                         trouveSeg2 = 1;
967                                         _TypesId[SALOME_MED::MED_EDGE].
968                                                 push_back(SALOME_MED::MED_SEG2);
969                                 }
970                                 break;
971                         }
972                         case 3:
973                         {
974                                 medElement = SALOME_MED::MED_SEG3;
975                                 if (trouveSeg3 == 0)
976                                 {
977                                         trouveSeg3 = 1;
978                                         _TypesId[SALOME_MED::MED_EDGE].
979                                                 push_back(SALOME_MED::MED_SEG3);
980                                 }
981                                 break;
982                         }
983                         }
984                         int index = _mapIndToSeqElts[medElement];
985                         SCRUTE(index);
986                         // Traitement de l arete
987
988                         int longueur = _seq_elemId[index]->length();
989                         _seq_elemId[index]->length(longueur + nb_of_nodes);
990
991                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
992
993                         for(int k=0; itn->more(); k++)
994                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
995                 }
996
997                 _mapNbTypes[SALOME_MED::MED_EDGE] = trouveSeg2 + trouveSeg3;
998
999                 // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
1000                 // On range les elements dans  les vecteurs correspondants 
1001                 int trouveTria3 = 0;
1002                 int trouveTria6 = 0;
1003                 int trouveQuad4 = 0;
1004
1005                 _mapIndToSeqElts[SALOME_MED::MED_TRIA3] = _indexElts++;
1006                 _mapIndToSeqElts[SALOME_MED::MED_TRIA6] = _indexElts++;
1007                 _mapIndToSeqElts[SALOME_MED::MED_QUAD4] = _indexElts++;
1008                 _mapIndToVectTypes[SALOME_MED::MED_FACE] = _indexEnts++;
1009
1010                 SMDS_FaceIteratorPtr itFaces=_meshDS->facesIterator();
1011                 while(itFaces->more())
1012                 {
1013                         const SMDS_MeshFace * elem = itFaces->next();
1014                         int nb_of_nodes = elem->NbNodes();
1015
1016                         switch (nb_of_nodes)
1017                         {
1018                         case 3:
1019                         {
1020                                 medElement = SALOME_MED::MED_TRIA3;
1021                                 if (trouveTria3 == 0)
1022                                 {
1023                                         trouveTria3 = 1;
1024                                         _TypesId[SALOME_MED::MED_FACE].
1025                                                 push_back(SALOME_MED::MED_TRIA3);
1026                                 }
1027                                 break;
1028                         }
1029                         case 4:
1030                         {
1031                                 medElement = SALOME_MED::MED_QUAD4;
1032                                 if (trouveQuad4 == 0)
1033                                 {
1034                                         trouveQuad4 = 1;
1035                                         _TypesId[SALOME_MED::MED_FACE].
1036                                                 push_back(SALOME_MED::MED_QUAD4);
1037                                 }
1038                                 break;
1039                         }
1040                         case 6:
1041                         {
1042                                 medElement = SALOME_MED::MED_TRIA6;
1043                                 if (trouveTria6 == 0)
1044                                 {
1045                                         trouveTria6 = 1;
1046                                         _TypesId[SALOME_MED::MED_FACE].
1047                                                 push_back(SALOME_MED::MED_TRIA6);
1048                                 }
1049                                 break;
1050                         }
1051                         }
1052                         int index = _mapIndToSeqElts[medElement];
1053                         SCRUTE(index);
1054
1055                         // Traitement de la face
1056                         // Attention La numérotation des noeuds Med commence a 1
1057
1058                         int longueur = _seq_elemId[index]->length();
1059                         _seq_elemId[index]->length(longueur + nb_of_nodes);
1060
1061                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1062
1063                         for(int k=0; itn->more(); k++)
1064                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1065                 } //itFaces
1066
1067                 _mapNbTypes[SALOME_MED::MED_FACE] =
1068                         trouveTria3 + trouveTria6 + trouveQuad4;
1069
1070                 _mapIndToSeqElts[SALOME_MED::MED_HEXA8] = _indexElts++;
1071                 _mapIndToVectTypes[SALOME_MED::MED_CELL] = _indexEnts++;
1072                 int index = _mapIndToSeqElts[medElement];
1073
1074                 int trouveHexa8 = 0;
1075
1076                 SMDS_VolumeIteratorPtr itVolumes=_meshDS->volumesIterator();
1077                 while(itVolumes->more())
1078                 {
1079                         const SMDS_MeshVolume * elem = itVolumes->next();
1080
1081                         int nb_of_nodes = elem->NbNodes();
1082                         medElement = SALOME_MED::MED_HEXA8;
1083                         ASSERT(nb_of_nodes = 8);
1084
1085                         if (trouveHexa8 == 0)
1086                         {
1087                                 trouveHexa8 = 1;
1088                                 _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
1089                         };
1090                         // Traitement de la maille
1091                         int longueur = _seq_elemId[index]->length();
1092                         _seq_elemId[index]->length(longueur + nb_of_nodes);
1093
1094                         SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1095                         for(int k=0; itn->more(); k++)
1096                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1097                 }
1098
1099                 _mapNbTypes[SALOME_MED::MED_CELL] = trouveHexa8;
1100                 _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1101                         =
1102                         trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 +
1103                         trouveSeg3;
1104         }// fin du _compte
1105 };
1106
1107 //=============================================================================
1108 /*!
1109  * Creation des familles
1110  */
1111 //=============================================================================
1112 void SMESH_MEDMesh_i::createFamilies() throw(SALOME::SALOME_Exception)
1113 {
1114   Unexpect aCatch(SALOME_SalomeException);
1115         string famDes = ("Je ne sais pas");
1116         string famName0 = "Famille_";
1117         string famName;
1118         char numero[10];
1119
1120         if (_creeFamily == false)
1121         {
1122                 _creeFamily = true;
1123                 SMESH_subMesh_i *subMeshServant;
1124
1125                 map < int, SMESH_subMesh_i * >::iterator it;
1126                 for (it = _mesh_i->_mapSubMesh_i.begin();
1127                         it != _mesh_i->_mapSubMesh_i.end(); it++)
1128                 {
1129                         SMESH_subMesh_i *submesh_i = (*it).second;
1130                         int famIdent = (*it).first;
1131
1132                         ASSERT(famIdent < 999999999);
1133                         sprintf(numero, "%d\n", famIdent);
1134                         famName = famName0 + numero;
1135
1136                         SMESH_MEDFamily_i *famservant =
1137                                 new SMESH_MEDFamily_i(famIdent, submesh_i,
1138                                 famName, famDes, SALOME_MED::MED_NODE);
1139                         SALOME_MED::FAMILY_ptr famille =
1140                                 SALOME_MED::FAMILY::_narrow(famservant->
1141                                 POA_SALOME_MED::FAMILY::_this());
1142                         _families.push_back(famille);
1143                 }
1144         }
1145 };
1146 //=============================================================================
1147 /*!
1148  * Gives informations of the considered mesh.
1149  */
1150 //=============================================================================
1151 SALOME_MED::MESH::meshInfos * SMESH_MEDMesh_i::getMeshGlobal()
1152   throw (SALOME::SALOME_Exception)
1153 {
1154   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1155
1156   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1157
1158   return NULL;
1159 }
1160 //=============================================================================
1161 /*!
1162  * Gives informations on coordinates of the considered mesh.
1163  */
1164 //=============================================================================
1165 SALOME_MED::MESH::coordinateInfos * SMESH_MEDMesh_i::getCoordGlobal()
1166   throw (SALOME::SALOME_Exception)
1167 {
1168   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1169
1170   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1171
1172   return NULL;
1173 }
1174 //=============================================================================
1175 /*!
1176  * Gives informations on connectivities of the considered mesh for the entity
1177  * entity.
1178  */
1179 //=============================================================================
1180 SALOME_MED::MESH::connectivityInfos *
1181 SMESH_MEDMesh_i::getConnectGlobal(SALOME_MED::medEntityMesh entity)
1182   throw (SALOME::SALOME_Exception)
1183 {
1184   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1185
1186   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1187
1188   return NULL;
1189 }
1190 //=============================================================================
1191 /*!
1192  * Gives the type of the element number of entity entity
1193  */
1194 //=============================================================================
1195 SALOME_MED::medGeometryElement
1196 SMESH_MEDMesh_i::getElementType(SALOME_MED::medEntityMesh entity,
1197                                 CORBA::Long number)
1198   throw (SALOME::SALOME_Exception)
1199 {
1200   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1201
1202   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1203
1204   return (SALOME_MED::medGeometryElement) 0;
1205 }