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