Salome HOME
make GetMaxArea const
[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 "SMDS_MapIteratorOfExtendedMap.hxx"
35 #include "SMDS_MapOfMeshElement.hxx"
36
37 #include <TopExp.hxx>
38 #include <TopExp_Explorer.hxx>
39 #include <TopoDS.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopoDS_Compound.hxx>
42 #include <TopoDS_CompSolid.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <TopoDS_Shell.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Wire.hxx>
47 #include <TopoDS_Edge.hxx>
48 #include <TopoDS_Vertex.hxx>
49 #include <TopoDS_Shape.hxx>
50 #include <TopTools_MapOfShape.hxx>
51
52 #include "utilities.h"
53 #include "Utils_CorbaException.hxx"
54
55 #include "SMESH_MEDSupport_i.hxx"
56 #include "SMESH_MEDFamily_i.hxx"
57
58 # include "Utils_ORB_INIT.hxx"
59 # include "Utils_SINGLETON.hxx"
60 extern "C"
61 {
62 #include <stdio.h>
63 }
64
65
66 //=============================================================================
67 /*!
68  * Default constructor
69  */
70 //=============================================================================
71 // PN Est-ce un const ?
72 SMESH_MEDMesh_i::SMESH_MEDMesh_i()
73 {
74   BEGIN_OF("Default Constructor SMESH_MEDMesh_i");
75   END_OF("Default Constructor SMESH_MEDMesh_i");
76 }
77 //=============================================================================
78 /*!
79  * Destructor
80  */
81 //=============================================================================
82 SMESH_MEDMesh_i::~SMESH_MEDMesh_i()
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   _mesh_i = m_i;
98   _meshDS = _mesh_i->GetImpl().GetMeshDS();
99
100   BEGIN_OF("Constructor SMESH_MEDMesh_i");
101   END_OF("Constructor SMESH_MEDMesh_i");
102 }
103
104 //=============================================================================
105 /*!
106  * CORBA: Accessor for Name
107  */
108 //=============================================================================
109 char * SMESH_MEDMesh_i::getName()       
110   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  * CORBA: Accessor for corbaindex cuisine interne 
132  */
133 //=============================================================================
134 CORBA::Long SMESH_MEDMesh_i::getCorbaIndex() 
135   throw (SALOME::SALOME_Exception)
136 {
137   MESSAGE("Non Implemente");
138   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
139                                ,SALOME::BAD_PARAM);
140 }
141 //=============================================================================
142 /*!
143  * CORBA: Accessor for Space Dimension
144  */
145 //=============================================================================
146 CORBA::Long SMESH_MEDMesh_i::getSpaceDimension() 
147   throw (SALOME::SALOME_Exception)
148 {
149   // PN : Il semblerait que la dimension soit fixee a 3
150   if (_mesh_i == 0)
151     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
152                                  SALOME::INTERNAL_ERROR);
153   return 3;
154 }
155 //=============================================================================
156 /*!
157  * CORBA: Accessor for Mesh Dimension
158  */
159 //=============================================================================
160 CORBA::Long SMESH_MEDMesh_i::getMeshDimension()
161   throw (SALOME::SALOME_Exception)
162 {
163   if (_mesh_i == 0)
164     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
165                                  SALOME::INTERNAL_ERROR);
166   // PN : Il semblerait que la dimension soit fixee a 3
167   if (_mesh_i == 0)
168     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
169                                  SALOME::INTERNAL_ERROR);
170   return 3;
171 }
172 //=============================================================================
173 /*!
174  * CORBA: Accessor for Coordinates System
175  */
176 //=============================================================================
177 char * SMESH_MEDMesh_i::getCoordinateSystem()
178   throw (SALOME::SALOME_Exception)
179 {
180   if (_mesh_i == 0)
181     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
182                                  SALOME::INTERNAL_ERROR);
183   // PN : En dur. Non encore prevu
184   try
185     {
186       string systcoo="CARTESIEN";
187       return CORBA::string_dup(systcoo.c_str());
188     }
189   catch(...)
190     {
191       MESSAGE("Exception en accedant au maillage");
192       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
193                                    ,SALOME::INTERNAL_ERROR);
194     }
195 }
196 //=============================================================================
197 /*!
198  * CORBA: Accessor for Coordinates
199  */
200 //=============================================================================
201 Engines::double_array * SMESH_MEDMesh_i::getCoordinates(SALOME_MED::medModeSwitch typeSwitch)
202   throw (SALOME::SALOME_Exception)
203 {
204   if (_mesh_i == 0)
205     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
206                                  SALOME::INTERNAL_ERROR);
207   Engines::double_array_var myseq = new Engines::double_array;
208   try
209     {
210       // PN  : En dur
211       int spaceDimension=3;
212       int nbNodes=_meshDS->NbNodes();
213       SCRUTE(nbNodes);
214       myseq->length(nbNodes*spaceDimension);
215       int i = 0;
216       SMDS_MeshNodesIterator itNodes(_meshDS);
217       for (;itNodes.More();itNodes.Next()) 
218         {
219
220           const Handle(SMDS_MeshElement)& elem = itNodes.Value();
221           const Handle(SMDS_MeshNode)& node =_meshDS->GetNode(1,elem);
222
223           if (typeSwitch == SALOME_MED::MED_FULL_INTERLACE)
224             {
225               myseq[i*3]=node->X();
226               myseq[i*3+1]=node->Y();
227               myseq[i*3+2]=node->Z();
228               SCRUTE(myseq[i*3]);
229               SCRUTE(myseq[i*3+1]);
230               SCRUTE(myseq[i*3+2]);
231             }
232           else
233             {
234               ASSERT(typeSwitch == SALOME_MED::MED_NO_INTERLACE);
235               myseq[i]=node->X();
236               myseq[i+nbNodes]=node->Y();
237               myseq[i+(nbNodes*2)]=node->Z();
238               SCRUTE(myseq[i]);
239               SCRUTE(myseq[i+nbNodes]);
240               SCRUTE(myseq[i+(nbNodes*2)]);
241             }
242           i++;
243         }
244     }
245   catch(...)
246     {       
247       MESSAGE("Exception en accedant aux coordonnees");
248       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
249                                    ,SALOME::INTERNAL_ERROR);
250     }
251   return myseq._retn();
252 }
253 //=============================================================================
254 /*!
255  * CORBA: Accessor for Coordinates Names
256  */
257 //=============================================================================
258 Engines::string_array  * SMESH_MEDMesh_i::getCoordinatesNames() 
259   throw (SALOME::SALOME_Exception)
260 {
261   if (_mesh_i == 0)
262     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
263                                  SALOME::INTERNAL_ERROR);
264   Engines::string_array_var myseq = new Engines::string_array;
265   try
266     {
267       // PN : en dur
268       int spaceDimension=3;
269       myseq->length(spaceDimension);
270       myseq[0]=CORBA::string_dup("x");
271       myseq[1]=CORBA::string_dup("y");
272       myseq[2]=CORBA::string_dup("z");
273     }
274   catch(...)
275     {       
276       MESSAGE("Exception en accedant aux noms des coordonnees");
277       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
278                                    ,SALOME::INTERNAL_ERROR);
279     }
280   return myseq._retn();
281
282 }
283 //=============================================================================
284 /*!
285  * CORBA: Accessor for Coordinates Units
286  */
287 //=============================================================================
288 Engines::string_array *  SMESH_MEDMesh_i::getCoordinatesUnits()
289   throw (SALOME::SALOME_Exception)
290 {
291   if (_mesh_i == 0)
292     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
293                                  SALOME::INTERNAL_ERROR);
294   Engines::string_array_var myseq = new Engines::string_array;
295   try
296     {
297       // PN : en dur
298       int spaceDimension=3;
299       myseq->length(spaceDimension);
300       myseq[0]=CORBA::string_dup("m");
301       myseq[1]=CORBA::string_dup("m");
302       myseq[2]=CORBA::string_dup("m");
303     }
304   catch(...)
305     {       
306       MESSAGE("Exception en accedant aux unites des coordonnees");
307       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
308                                    ,SALOME::INTERNAL_ERROR);
309     }
310   return myseq._retn();
311 }
312 //=============================================================================
313 /*!
314  * CORBA: Accessor for Number of Nodes
315  */
316 //=============================================================================
317 CORBA::Long  SMESH_MEDMesh_i::getNumberOfNodes() 
318   throw (SALOME::SALOME_Exception)
319 {
320   if (_mesh_i == 0)
321     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
322                                  SALOME::INTERNAL_ERROR);
323   try
324     {
325       return _meshDS->NbNodes();
326     }
327   catch(...)
328     {       
329       MESSAGE("Exception en accedant au nombre de noeuds");
330       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
331                                    ,SALOME::INTERNAL_ERROR);
332     }
333 }
334 //=============================================================================
335 /*!
336  * CORBA: Accessor for number of Types
337  */
338 //=============================================================================
339 CORBA::Long SMESH_MEDMesh_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity) 
340   throw (SALOME::SALOME_Exception)
341 {
342   if (_mesh_i == 0)
343     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
344                                  SALOME::INTERNAL_ERROR);
345   try
346     {
347       if (! _compte)
348         calculeNbElts();
349       int retour = 0; 
350       if ( _mapNbTypes.find(entity)!=_mapNbTypes.end())
351         retour=_mapNbTypes[entity];
352       return retour;
353     }
354   catch(...)
355     {       
356       MESSAGE("Exception en accedant au nombre de Types");
357       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
358                                    ,SALOME::INTERNAL_ERROR);
359     }
360 }
361
362 //=============================================================================
363 /*!
364  * CORBA: Accessor for existing geometry element types 
365  *        Not implemented for MED_ALL_ENTITIES
366  */
367 //=============================================================================
368 SALOME_MED::medGeometryElement_array * SMESH_MEDMesh_i::getTypes (SALOME_MED::medEntityMesh entity) 
369   throw (SALOME::SALOME_Exception)
370 {
371   if (_mesh_i == 0)
372     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
373                                  SALOME::INTERNAL_ERROR);
374   if (entity ==SALOME_MED::MED_ALL_ENTITIES)
375     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",\
376                                  SALOME::BAD_PARAM);
377   if (! _compte)
378     calculeNbElts();
379   SALOME_MED::medGeometryElement_array_var myseq = 
380     new SALOME_MED::medGeometryElement_array;
381   try
382     {
383       if ( _mapNbTypes.find(entity) ==_mapNbTypes.end())
384         THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh"\
385                                      ,SALOME::BAD_PARAM);
386       int nbTypes=_mapNbTypes[entity];
387
388       myseq->length(nbTypes);
389                 
390       if ( _mapIndToVectTypes.find(entity) ==_mapIndToVectTypes.end())
391         THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh"\
392                                      ,SALOME::INTERNAL_ERROR);
393
394       int index=_mapIndToVectTypes[entity];
395       ASSERT( _TypesId[index].size()!=0);
396       int i=0;
397       vector<SALOME_MED::medGeometryElement>::iterator it;
398       for (it=_TypesId[index].begin();it!=_TypesId[index].end();it++)
399         {
400           myseq[i++]=*it;
401         };
402     }
403   catch(...)
404     {       
405       MESSAGE("Exception en accedant aux differents types");
406       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
407                                    ,SALOME::INTERNAL_ERROR);
408     }
409   return myseq._retn();
410 }
411 //=============================================================================
412 /*!
413  * CORBA: Returns number of elements of type medGeometryElement
414  *        Not implemented for MED_ALL_ELEMENTS 
415  *        implemented for MED_ALL_ENTITIES
416  *
417  * Dans cette implementation, il n est pas prevu de tenir compte du entity
418  * qui ne doit pas pouvoir avoir deux valeurs differentes pour un geomElement 
419  */
420 //=============================================================================
421 CORBA::Long SMESH_MEDMesh_i::getNumberOfElements(SALOME_MED::medEntityMesh entity, 
422                                                  SALOME_MED::medGeometryElement geomElement)
423   throw (SALOME::SALOME_Exception)
424 {
425   if (_mesh_i == 0)
426     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
427                                  SALOME::INTERNAL_ERROR);
428   if (geomElement == SALOME_MED::MED_ALL_ELEMENTS)
429     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ELEMENTS", \
430                                  SALOME::BAD_PARAM);
431   if (! _compte)
432     calculeNbElts();
433
434   try
435     {
436       int retour = 0; 
437       if ( _mapIndToSeqElts.find(geomElement)!=_mapIndToSeqElts.end())
438         { 
439           int index = _mapIndToSeqElts[geomElement];
440           retour=_seq_elemId[index]->length();
441         }
442       return retour;
443     }
444   catch(...)
445     {
446       MESSAGE("Exception en accedant au nombre d élements");
447       THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object"\
448                                    ,SALOME::INTERNAL_ERROR);
449     }
450 }
451 //=============================================================================
452 /*!
453  * CORBA: Accessor for connectivities
454  */
455 //=============================================================================
456 Engines::long_array *  SMESH_MEDMesh_i::getConnectivity(SALOME_MED::medModeSwitch typeSwitch,
457                                                         SALOME_MED::medConnectivity mode, 
458                                                         SALOME_MED::medEntityMesh entity, 
459                                                         SALOME_MED::medGeometryElement geomElement)
460   throw (SALOME::SALOME_Exception)
461 {
462   if (_mesh_i == 0)
463     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
464                                  SALOME::INTERNAL_ERROR);
465   if (mode != SALOME_MED::MED_NODAL)
466     THROW_SALOME_CORBA_EXCEPTION("Not Implemented",\
467                                  SALOME::BAD_PARAM);
468   if (typeSwitch == SALOME_MED::MED_NO_INTERLACE)
469     THROW_SALOME_CORBA_EXCEPTION("Not Yet Implemented",\
470                                  SALOME::BAD_PARAM);
471   if (! _compte)
472     calculeNbElts();
473
474   // Faut-il renvoyer un pointeur vide ???
475   if ( _mapIndToSeqElts.find(geomElement)!=_mapIndToSeqElts.end())
476     THROW_SALOME_CORBA_EXCEPTION("No Such Element in the mesh"\
477                                  ,SALOME::BAD_PARAM);
478
479   int index=_mapIndToSeqElts[geomElement];
480   return _seq_elemId[index]._retn();
481 }
482 //=============================================================================
483 /*!
484  * CORBA: Accessor for connectivities
485  */
486 //=============================================================================
487 Engines::long_array* SMESH_MEDMesh_i::getConnectivityIndex(SALOME_MED::medConnectivity mode, 
488                                                            SALOME_MED::medEntityMesh entity) 
489   throw (SALOME::SALOME_Exception)
490 {
491   MESSAGE("Pas Implemente dans SMESH");
492   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
493                                ,SALOME::BAD_PARAM);
494   return 0;
495 }
496 //=============================================================================
497 /*!
498  * CORBA: Find an element corresponding to the given connectivity
499  */
500 //=============================================================================
501 CORBA::Long SMESH_MEDMesh_i::getElementNumber(SALOME_MED::medConnectivity mode,
502                                               SALOME_MED::medEntityMesh entity,
503                                               SALOME_MED::medGeometryElement type,
504                                               const Engines::long_array & connectivity
505
506   throw (SALOME::SALOME_Exception)
507 {
508   const char * LOC = "getElementNumber ";
509   MESSAGE(LOC<<"Pas Implemente dans SMESH");
510   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
511                                ,SALOME::BAD_PARAM);
512   return -1;
513 }
514 //=============================================================================
515 /*!
516  * CORBA: Accessor for Ascendant connectivities
517  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
518  */
519 //=============================================================================
520 Engines::long_array* SMESH_MEDMesh_i::getReverseConnectivity(SALOME_MED::medConnectivity mode)
521   throw (SALOME::SALOME_Exception)
522 {
523   MESSAGE("Pas Implemente dans SMESH");
524   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
525                                ,SALOME::BAD_PARAM);
526   return 0;
527 }
528 //=============================================================================
529 /*!
530  * CORBA: Accessor for connectivities
531  */
532 //=============================================================================
533 Engines::long_array* SMESH_MEDMesh_i::getReverseConnectivityIndex(SALOME_MED::medConnectivity mode)
534   throw (SALOME::SALOME_Exception)
535 {
536   MESSAGE("Pas Implemente dans SMESH");
537   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
538                                ,SALOME::BAD_PARAM);
539   return 0;
540 }
541 //=============================================================================
542 /*!
543  * CORBA: Returns number of families within the mesh
544  */
545 //=============================================================================
546 CORBA::Long SMESH_MEDMesh_i::getNumberOfFamilies(SALOME_MED::medEntityMesh entity)
547   throw (SALOME::SALOME_Exception)
548 {
549   if (_creeFamily == false)
550     createFamilies();
551   if (_mesh_i == 0)
552     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
553                                  SALOME::INTERNAL_ERROR);
554   return _families.size();
555 }
556 //=============================================================================
557 /*!
558  * CORBA: Returns number of groups within the mesh
559  */
560 //=============================================================================
561 CORBA::Long SMESH_MEDMesh_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity) 
562   throw (SALOME::SALOME_Exception)
563 {
564   if (_mesh_i == 0)
565     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
566                                  SALOME::INTERNAL_ERROR);
567   MESSAGE(" Pas d implementation des groupes dans SMESH");
568   return 0;
569 }
570 //=============================================================================
571 /*!
572  * CORBA: Returns references for families within the mesh
573  */
574 //=============================================================================
575 SALOME_MED::Family_array * SMESH_MEDMesh_i::getFamilies(SALOME_MED::medEntityMesh entity) 
576   throw (SALOME::SALOME_Exception)
577 {
578   if (_creeFamily == false)
579     createFamilies();
580   if (_mesh_i == 0)
581     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
582                                  SALOME::INTERNAL_ERROR);
583   SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
584   int nbfam= _families.size();
585   myseq->length(nbfam);
586   int i = 0;
587   vector<SALOME_MED::FAMILY_ptr>::iterator it;
588   for (it=_families.begin();it!=_families.end();it++)
589     {
590       myseq[i++]=*it;
591     };
592   return myseq._retn();
593 }
594 //=============================================================================
595 /*!
596  * CORBA: Returns references for family i within the mesh
597  */
598 //=============================================================================
599 SALOME_MED::FAMILY_ptr SMESH_MEDMesh_i::getFamily(SALOME_MED::medEntityMesh entity,
600                                                   CORBA::Long i) 
601   throw (SALOME::SALOME_Exception)
602 {
603   if (_creeFamily == false)
604     createFamilies();
605   if (_mesh_i == 0)
606     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
607                                  SALOME::INTERNAL_ERROR);
608
609   SCRUTE(_families[i]->getName());
610   MESSAGE ( " SMESH_MEDMesh_i::getFamily " << i )
611   return _families[i];
612 }
613 //=============================================================================
614 /*!
615  * CORBA: Returns references for groups within the mesh
616  */
617 //=============================================================================
618 SALOME_MED::Group_array *  SMESH_MEDMesh_i::getGroups(SALOME_MED::medEntityMesh entity) 
619   throw (SALOME::SALOME_Exception)
620 {
621   if (_mesh_i == 0)
622     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
623                                  SALOME::INTERNAL_ERROR);
624   MESSAGE(" Pas d implementation des groupes dans SMESH");
625   THROW_SALOME_CORBA_EXCEPTION("No group implementation"\
626                                ,SALOME::BAD_PARAM);
627 }
628 //=============================================================================
629 /*!
630  * CORBA: Returns references for group i within the mesh
631  */
632 //=============================================================================
633 SALOME_MED::GROUP_ptr SMESH_MEDMesh_i::getGroup(SALOME_MED::medEntityMesh entity,
634                                                 CORBA::Long i) 
635   throw (SALOME::SALOME_Exception)
636 {
637   if (_mesh_i == 0)
638     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
639                                  SALOME::INTERNAL_ERROR);
640   MESSAGE(" Pas d implementation des groupes dans SMESH");
641   THROW_SALOME_CORBA_EXCEPTION("No group implementation"\
642                                ,SALOME::BAD_PARAM);
643 }
644 //=============================================================================
645 /*!
646  * CORBA: 
647  */
648 //=============================================================================
649 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::SUPPORT_ptr mySupport)
650   throw (SALOME::SALOME_Exception)
651 {
652   MESSAGE("Pas Implemente dans SMESH");
653   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
654                                ,SALOME::BAD_PARAM);
655   return 0;
656 }
657 //=============================================================================
658 /*!
659  * CORBA: 
660  */
661 //=============================================================================
662 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::SUPPORT_ptr mySupport)
663   throw (SALOME::SALOME_Exception)
664 {
665   MESSAGE("Pas Implemente dans SMESH");
666   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
667                                ,SALOME::BAD_PARAM);
668   return 0;
669 }
670 //=============================================================================
671 /*!
672  * CORBA: 
673  */
674 //=============================================================================
675 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::SUPPORT_ptr mySupport)
676   throw (SALOME::SALOME_Exception)
677 {
678   MESSAGE("Pas Implemente dans SMESH");
679   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
680                                ,SALOME::BAD_PARAM);
681   return 0;
682 }
683 //=============================================================================
684 /*!
685  * CORBA: 
686  */
687 //=============================================================================
688 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::SUPPORT_ptr mySupport)
689   throw (SALOME::SALOME_Exception)
690 {
691   MESSAGE("Pas Implemente dans SMESH");
692   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
693                                ,SALOME::BAD_PARAM);
694   return 0;
695 }
696 //=============================================================================
697 /*!
698  * CORBA: 
699  */
700 //=============================================================================
701 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::SUPPORT_ptr mySupport)
702   throw (SALOME::SALOME_Exception)
703 {
704   MESSAGE("Pas Implemente dans SMESH");
705   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
706                                ,SALOME::BAD_PARAM);
707   return 0;
708 }
709 //=============================================================================
710 /*!
711  * CORBA: 
712  */
713 //=============================================================================
714 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::SUPPORT_ptr mySupport)
715   throw (SALOME::SALOME_Exception)
716 {
717   MESSAGE("Non Implemente");
718   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
719                                ,SALOME::BAD_PARAM);
720   return 0;
721 }
722 //=============================================================================
723 /*!
724  * CORBA: add the Mesh in the StudyManager 
725  * PN Pas Implemente
726  */
727 //=============================================================================
728 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
729                                  SALOME_MED::MESH_ptr myIor)
730   throw (SALOME::SALOME_Exception)
731 {
732   BEGIN_OF("MED_Mesh_i::addInStudy");
733   if ( _meshId != "" )
734     {
735       MESSAGE("Mesh already in Study");
736       THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
737                                    SALOME::BAD_PARAM);
738     };
739
740   /*
741     SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
742
743     // Create SComponent labelled 'MED' if it doesn't already exit
744     SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
745     if ( CORBA::is_nil(medfather) ) 
746     {
747     MESSAGE("Add Component MED");
748     medfather = myBuilder->NewComponent("MED");
749     //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
750     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
751                       myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
752     aName->SetValue("MED");
753
754     myBuilder->DefineComponentInstance(medfather,myIor);
755
756     } ;
757
758     MESSAGE("Add a mesh Object under MED");
759     myBuilder->NewCommand();
760     SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
761
762     ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
763     ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
764     CORBA::ORB_var &orb = init(0,0);
765     string iorStr = orb->object_to_string(myIor);
766     //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.c_str());
767     SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
768                       myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
769     aIOR->SetValue(iorStr.c_str());
770
771     //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
772     SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
773                       myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
774     aName->SetValue(_mesh_i->getName().c_str());
775
776     _meshId = newObj->GetID();
777     myBuilder->CommitCommand();
778
779   */
780   END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
781 }
782 //=============================================================================
783 /*!
784  * CORBA: write mesh in a med file
785  */
786 //=============================================================================
787 void SMESH_MEDMesh_i::write(CORBA::Long i, const char* driverMeshName)       
788   throw (SALOME::SALOME_Exception)
789 {
790   MESSAGE("Non Implemente");
791   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
792                                ,SALOME::BAD_PARAM);
793 }
794 //=============================================================================
795 /*!
796  * CORBA: read mesh in a med file
797  */
798 //=============================================================================
799 void SMESH_MEDMesh_i::read(CORBA::Long i)            
800   throw (SALOME::SALOME_Exception)
801 {
802   MESSAGE("Non Implemente");
803   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
804                                ,SALOME::BAD_PARAM);
805 }
806 //=============================================================================
807 /*!
808  * CORBA : release driver
809  */
810 //=============================================================================
811 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i)        
812   throw (SALOME::SALOME_Exception)
813 {
814   MESSAGE("Non Implemente");
815   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
816                                ,SALOME::BAD_PARAM);
817 }
818 //=============================================================================
819 /*!
820  * CORBA : attach driver
821  */
822 //=============================================================================
823 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType, 
824                                        const char* fileName, const char* meshName)
825   throw (SALOME::SALOME_Exception)
826 {
827   MESSAGE("Non Implemente");
828   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method"\
829                                ,SALOME::BAD_PARAM);
830   return 0;
831 }
832 //=============================================================================
833 /*!
834  * Calcule le Nb d'elements par entite geometrique
835  */
836 //=============================================================================
837 void SMESH_MEDMesh_i::calculeNbElts()
838   throw (SALOME::SALOME_Exception)
839 {
840   if (! _compte)
841     {
842       _compte=true;
843
844       _mapNbTypes[SALOME_MED::MED_NODE]=1;
845       // On compte les aretes MED_SEG2 ou MED_SEG3
846       // On range les elements dans  les vecteurs correspondants 
847
848       _mapIndToSeqElts[SALOME_MED::MED_SEG2]=_indexElts++;
849       _mapIndToSeqElts[SALOME_MED::MED_SEG3]=_indexElts++;
850       _mapIndToVectTypes[SALOME_MED::MED_EDGE]=_indexEnts++;
851
852       int trouveSeg2=0; 
853       int trouveSeg3=0; 
854       SALOME_MED::medGeometryElement medElement;
855       SMDS_MeshEdgesIterator itEdges(_meshDS);
856       for (;itEdges.More();itEdges.Next()) 
857         {
858           const Handle(SMDS_MeshElement)& elem = itEdges.Value();
859           int nb_of_nodes = elem->NbNodes();
860
861           switch (nb_of_nodes) 
862             {
863             case 2 : 
864               {
865                 medElement=SALOME_MED::MED_SEG2;
866                 if (trouveSeg2==0)
867                   {
868                     trouveSeg2=1;
869                     _TypesId[SALOME_MED::MED_EDGE].push_back(SALOME_MED::MED_SEG2);
870
871                   }
872                 break;
873               }
874             case 3 : 
875               {
876                 medElement=SALOME_MED::MED_SEG3;
877                 if (trouveSeg3==0)
878                   {
879                     trouveSeg3=1;
880                     _TypesId[SALOME_MED::MED_EDGE].push_back(SALOME_MED::MED_SEG3);
881                   }
882                 break;
883               }
884             }
885           int index=_mapIndToSeqElts[medElement];
886           SCRUTE(index);
887           // Traitement de l arete
888           int longueur=_seq_elemId[index]->length();
889           _seq_elemId[index]->length(longueur + nb_of_nodes);
890
891           for (int k=0; k<nb_of_nodes; k++)
892             {
893               _seq_elemId[index][longueur+k]=elem->GetConnection(k+1) +1;
894             }
895         }
896
897       _mapNbTypes[SALOME_MED::MED_EDGE]=trouveSeg2 + trouveSeg3;
898
899       // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
900       // On range les elements dans  les vecteurs correspondants 
901       int trouveTria3=0; 
902       int trouveTria6=0; 
903       int trouveQuad4=0; 
904
905       _mapIndToSeqElts[SALOME_MED::MED_TRIA3]=_indexElts++;
906       _mapIndToSeqElts[SALOME_MED::MED_TRIA6]=_indexElts++;
907       _mapIndToSeqElts[SALOME_MED::MED_QUAD4]=_indexElts++;
908       _mapIndToVectTypes[SALOME_MED::MED_FACE]=_indexEnts++;
909
910       SMDS_MeshFacesIterator itFaces(_meshDS);
911       for (;itFaces.More();itFaces.Next()) 
912         {
913
914           const Handle(SMDS_MeshElement)& elem = itFaces.Value();
915           int nb_of_nodes = elem->NbNodes();
916
917           switch (nb_of_nodes) 
918             {
919             case 3 : 
920               {
921                 medElement=SALOME_MED::MED_TRIA3;
922                 if (trouveTria3==0)
923                   {
924                     trouveTria3=1;
925                     _TypesId[SALOME_MED::MED_FACE].push_back(SALOME_MED::MED_TRIA3);
926                   }
927                 break;
928               }
929             case 4 : 
930               {
931                 medElement=SALOME_MED::MED_QUAD4;
932                 if (trouveQuad4==0)
933                   {
934                     trouveQuad4=1;
935                     _TypesId[SALOME_MED::MED_FACE].push_back(SALOME_MED::MED_QUAD4);
936                   }
937                 break;
938               }
939             case 6 : 
940               {
941                 medElement=SALOME_MED::MED_TRIA6;
942                 if (trouveTria6==0)
943                   {
944                     trouveTria6=1;
945                     _TypesId[SALOME_MED::MED_FACE].push_back(SALOME_MED::MED_TRIA6);
946                   }
947                 break;
948               }
949             }
950           int index=_mapIndToSeqElts[medElement];
951           SCRUTE(index);
952
953           // Traitement de la face
954           // Attention La numérotation des noeuds Med commence a 1
955
956
957           int longueur = _seq_elemId[index]->length();
958           _seq_elemId[index]->length(longueur+nb_of_nodes);
959
960           for (int k=0; k<nb_of_nodes; k++)
961             {
962               _seq_elemId[index][longueur+k]=elem->GetConnection(k+1) +1;
963             }
964
965         }
966       _mapNbTypes[SALOME_MED::MED_FACE]=trouveTria3 + trouveTria6 + trouveQuad4;
967
968       _mapIndToSeqElts[SALOME_MED::MED_HEXA8]=_indexElts++;
969       _mapIndToVectTypes[SALOME_MED::MED_CELL]=_indexEnts++;
970       int index=_mapIndToSeqElts[medElement];
971
972       int trouveHexa8=0;
973       SMDS_MeshVolumesIterator itVolumes(_meshDS);
974       for (;itVolumes.More();itVolumes.Next()) 
975         {
976           const Handle(SMDS_MeshElement)& elem = itVolumes.Value();
977
978           int nb_of_nodes = elem->NbNodes();
979           medElement=SALOME_MED::MED_HEXA8;
980           ASSERT(nb_of_nodes=8);
981
982           if (trouveHexa8 == 0)
983             {
984               trouveHexa8=1;
985               _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
986             };
987           // Traitement de la maille
988           int longueur=_seq_elemId[index]->length();
989           _seq_elemId[index]->length(longueur+nb_of_nodes);
990
991           for (int k=0; k<nb_of_nodes; k++)
992             {
993               _seq_elemId[index][longueur+k]=elem->GetConnection(k+1) +1;
994             }
995
996         }
997
998       _mapNbTypes[SALOME_MED::MED_CELL]=trouveHexa8;
999       _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1000         =trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 + trouveSeg3 ;
1001     } /* fin du _compte */
1002 };
1003 //=============================================================================
1004 /*!
1005  * Creation des familles
1006  */
1007 //=============================================================================
1008 void SMESH_MEDMesh_i::createFamilies()
1009   throw (SALOME::SALOME_Exception)
1010 {
1011   string famDes=("Je ne sais pas");
1012   string famName0="Famille_";
1013   string famName;
1014   char numero[10];
1015
1016   if ( _creeFamily == false)
1017     {
1018       _creeFamily = true;
1019       SMESH_subMesh_i* subMeshServant;
1020
1021       map<int, SMESH_subMesh_i*>::iterator it;
1022       for (it = _mesh_i->_mapSubMesh_i.begin(); it !=  _mesh_i->_mapSubMesh_i.end(); it++) {
1023         SMESH_subMesh_i* submesh_i = (*it).second;
1024         int famIdent = (*it).first;
1025
1026         ASSERT (famIdent<999999999);
1027         sprintf(numero,"%d\n",famIdent);
1028         famName=famName0 + numero;
1029
1030         SMESH_MEDFamily_i * famservant= new SMESH_MEDFamily_i(famIdent, submesh_i,
1031                                                               famName, famDes, SALOME_MED::MED_NODE);
1032         SALOME_MED::FAMILY_ptr famille = 
1033           SALOME_MED::FAMILY::_narrow(famservant->POA_SALOME_MED::FAMILY::_this());
1034         _families.push_back(famille);
1035       }
1036     } /* fin du _compte */
1037 };
1038