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