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