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