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