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