Salome HOME
MEDMEM suppression
[modules/med.git] / src / MEDMEM_I / MEDMEM_GMesh_i.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //=============================================================================
24 // File      : MEDMEM_Mesh_i.cxx
25 // Project   : SALOME
26 // Author    : EDF 
27 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Mesh_i.cxx
28 //=============================================================================
29 //
30 #include <vector>
31
32 #include "utilities.h"
33 #include "Utils_CorbaException.hxx"
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
36
37 #include "MEDMEM_convert.hxx"
38 #include "MEDMEM_Mesh_i.hxx"
39 #include "MEDMEM_Support_i.hxx"
40 #include "MEDMEM_Family_i.hxx"
41 #include "MEDMEM_Group_i.hxx"
42 #include "MEDMEM_FieldTemplate_i.hxx"
43
44 #include "MEDMEM_Mesh.hxx"
45 #include "MEDMEM_Family.hxx"
46 #include "MEDMEM_Group.hxx"
47 #include "MEDMEM_CellModel.hxx"
48
49 #include "SenderFactory.hxx"
50 #include "MultiCommException.hxx"
51 using namespace MEDMEM;
52
53 // Initialisation des variables statiques
54 map < int, ::GMESH *> GMESH_i::meshMap ;
55 int GMESH_i::meshIndex = 0 ;
56
57
58
59 //=============================================================================
60 /*!
61  * Default constructor
62  */
63 //=============================================================================
64 GMESH_i::GMESH_i():
65   SALOMEMultiComm(),
66   SALOME::GenericObj_i(),
67   _mesh(constructConstMesh()),
68   _corbaIndex(MESH_i::meshIndex++),
69   _meshId("") 
70 {
71   MESH_i::meshMap[_corbaIndex]=_mesh;
72 }
73 //=============================================================================
74 /*!
75  * Destructor
76  */
77 //=============================================================================
78 GMESH_i::~GMESH_i()
79 {
80   if ( _mesh )
81     _mesh->removeReference();
82 }
83 //=============================================================================
84 /*!
85  * Constructor
86  */
87 //=============================================================================
88 GMESH_i::GMESH_i(::GMESH * const m ) :
89   SALOMEMultiComm(),
90   SALOME::GenericObj_i(),
91   _mesh(m),
92   _corbaIndex(MESH_i::meshIndex++),
93   _meshId("") 
94 {
95   if ( _mesh ) _mesh->addReference();
96   GMESH_i::meshMap[_corbaIndex]=_mesh;
97 }
98 //=============================================================================
99 /*!
100  * Copy Constructor 
101  */
102 //=============================================================================
103 //MESH_i::MESH_i(const MESH_i & m) :_mesh(m._mesh),
104 GMESH_i::GMESH_i( GMESH_i & m) :
105   SALOMEMultiComm(),
106   SALOME::GenericObj_i(),
107   _mesh(m._mesh),
108   _corbaIndex(MESH_i::meshIndex++),
109   _meshId("") 
110 {
111   if ( _mesh ) _mesh->addReference();
112   GMESH_i::meshMap[_corbaIndex]=_mesh;
113 }
114 //=============================================================================
115 /*!
116  * Internal Method in order to have a const ptr
117  */
118 //=============================================================================
119 ::GMESH * GMESH_i::constructConstMesh() const
120 {
121         ::MESH * const ptrMesh =new ::MESH();
122         return ptrMesh;
123 }
124 //=============================================================================
125 /*!
126  * CORBA: Accessor for Name
127  */
128 //=============================================================================
129 char * GMESH_i::getName()        
130 throw (SALOME::SALOME_Exception)
131 {
132         if (_mesh==NULL)
133                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
134                                              SALOME::INTERNAL_ERROR);
135
136         try
137         {
138                 return CORBA::string_dup(_mesh->getName().c_str());
139         }
140         catch (MEDEXCEPTION &ex)
141         {
142                 MESSAGE("Unable to acces the mesh name");
143                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
144         }
145 }
146 //=============================================================================
147 /*!
148  * CORBA: Accessor for corbaindex cuisine interne 
149  */
150 //=============================================================================
151 CORBA::Long GMESH_i::getCorbaIndex() 
152 throw (SALOME::SALOME_Exception)
153 {
154         if (_mesh==NULL)
155                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
156                                              SALOME::INTERNAL_ERROR);
157         return _corbaIndex;
158 }
159 //=============================================================================
160 /*!
161  * CORBA: Accessor for Space Dimension
162  */
163 //=============================================================================
164 CORBA::Long GMESH_i::getSpaceDimension() 
165 throw (SALOME::SALOME_Exception)
166 {
167         if (_mesh==NULL)
168                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
169                                              SALOME::INTERNAL_ERROR);
170         try
171         {
172                 return _mesh->getSpaceDimension();
173         }
174         catch (MEDEXCEPTION &ex)
175         {
176                 MESSAGE("Unable to acces the space dimension ");
177                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
178         }
179 }
180 //=============================================================================
181 /*!
182  * CORBA: Accessor for Mesh Dimension
183  */
184 //=============================================================================
185 CORBA::Long GMESH_i::getMeshDimension()
186 throw (SALOME::SALOME_Exception)
187 {
188         if (_mesh==NULL)
189                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
190                                              SALOME::INTERNAL_ERROR);
191         try
192         {
193                 return _mesh->getMeshDimension();
194         }
195         catch (MEDEXCEPTION &ex)
196         {
197                 MESSAGE("Unable to acces the mesh dimension ");
198                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
199         }
200 }
201 //=============================================================================
202 /*!
203  * CORBA: boolean indicating if mesh is a Grid
204  */
205 //=============================================================================
206 CORBA::Boolean GMESH_i::getIsAGrid()
207 throw (SALOME::SALOME_Exception)
208 {
209         if (_mesh==NULL)
210                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
211                                              SALOME::INTERNAL_ERROR);
212         try
213         {
214                 return _mesh->getIsAGrid();
215         }
216         catch (MEDEXCEPTION &ex)
217         {
218                 MESSAGE("Unable to acces mesh flag isAGrid");
219                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
220         }
221 }
222
223 //=============================================================================
224 /*!
225  * CORBA: Accessor for Coordinates System
226  */
227 //=============================================================================
228 char * GMESH_i::getCoordinatesSystem()
229 throw (SALOME::SALOME_Exception)
230 {
231         if (_mesh==NULL)
232                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
233                                              SALOME::INTERNAL_ERROR);
234
235         try
236         {
237                 return CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
238         }
239         catch (MEDEXCEPTION &ex)
240         {
241                 MESSAGE("Unable to acces the type of CoordinatesSystem");
242                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
243         }
244 }
245
246 //=============================================================================
247 /*!
248  * CORBA: Accessor for Coordinates Names
249  */
250 //=============================================================================
251 SALOME_TYPES::ListOfString  * GMESH_i::getCoordinatesNames() 
252 throw (SALOME::SALOME_Exception)
253 {
254         if (_mesh==NULL)
255                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
256                                              SALOME::INTERNAL_ERROR);
257         SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
258         try
259         {
260                 int spaceDimension=_mesh->getSpaceDimension();
261                 const string * coordinatesName =_mesh->getCoordinatesNames();
262                 myseq->length(spaceDimension);
263                 for (int i=0; i<spaceDimension; i++)
264                 {
265                         myseq[i]=CORBA::string_dup(coordinatesName[i].c_str());
266                 }
267         }
268         catch (MEDEXCEPTION &ex)
269         {       
270                 MESSAGE("Unable to acces the coordinates names");
271                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
272         }
273         return myseq._retn();
274
275 }
276 //=============================================================================
277 /*!
278  * CORBA: Accessor for Coordinates Units
279  */
280 //=============================================================================
281 SALOME_TYPES::ListOfString *  GMESH_i::getCoordinatesUnits()
282 throw (SALOME::SALOME_Exception)
283 {
284         if (_mesh==NULL)
285                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
286                                              SALOME::INTERNAL_ERROR);
287         SALOME_TYPES::ListOfString_var myseq = new SALOME_TYPES::ListOfString;
288         try
289         {
290                 int spaceDimension=_mesh->getSpaceDimension();
291                 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
292                 myseq->length(spaceDimension);
293                 for (int i=0; i<spaceDimension; i++)
294                 {
295                          myseq[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
296                 };
297         }
298         catch (MEDEXCEPTION &ex)
299         {       
300                 MESSAGE("Unable to acces the coordinates units");
301                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
302         }
303         return myseq._retn();
304 }
305 //=============================================================================
306 /*!
307  * CORBA: Accessor for Number of Nodes
308  */
309 //=============================================================================
310 CORBA::Long  GMESH_i::getNumberOfNodes() 
311 throw (SALOME::SALOME_Exception)
312 {
313         if (_mesh==NULL)
314                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
315                                              SALOME::INTERNAL_ERROR);
316         try
317         {
318                 return _mesh->getNumberOfNodes();
319         }
320         catch (MEDEXCEPTION &ex)
321         {       
322                 MESSAGE("Unable to acces number of nodes");
323                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
324         }
325 }
326 //=============================================================================
327 /*!
328  * CORBA: Accessor for number of Types
329  */
330 //=============================================================================
331 CORBA::Long GMESH_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity) 
332 throw (SALOME::SALOME_Exception)
333 {
334         if (_mesh==NULL)
335                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
336                                              SALOME::INTERNAL_ERROR);
337         try
338         {
339                 return _mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
340         }
341         catch (MEDEXCEPTION &ex)
342         {       
343                 MESSAGE("Unable to acces number of differents types");
344                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
345         }
346 }
347 //=============================================================================
348 /*!
349  * CORBA: Accessor for existing geometry element types
350  */
351 //=============================================================================
352 SALOME_MED::medGeometryElement GMESH_i::getElementType (SALOME_MED::medEntityMesh entity,
353                                                        CORBA::Long number)
354 throw (SALOME::SALOME_Exception)
355 {
356         if (_mesh==NULL)
357                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
358                                              SALOME::INTERNAL_ERROR);
359         try
360         {
361                 return _mesh->getElementType(convertIdlEntToMedEnt(entity),number);
362         }
363         catch (MEDEXCEPTION &ex)
364         {
365                 MESSAGE("Unable to acces number of differents element types");
366                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
367         }
368 }
369
370 //=============================================================================
371 /*!
372  * CORBA: Accessor for existing geometry element types 
373  *        Not implemented for MED_ALL_ENTITIES
374  */
375 //=============================================================================
376 SALOME_MED::medGeometryElement_array * GMESH_i::getTypes (SALOME_MED::medEntityMesh entity) 
377 throw (SALOME::SALOME_Exception)
378 {
379         if (_mesh==NULL)
380                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
381                                              SALOME::INTERNAL_ERROR);
382         if (entity ==SALOME_MED::MED_ALL_ENTITIES)
383                 THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",\
384                                              SALOME::BAD_PARAM);
385         SALOME_MED::medGeometryElement_array_var myseq = 
386                                         new SALOME_MED::medGeometryElement_array;
387         try
388         {
389                 int nbTypes=_mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
390                 const medGeometryElement * elemts  =_mesh->getTypes(
391                                        convertIdlEntToMedEnt(entity));
392                 myseq->length(nbTypes);
393                 for (int i=0; i<nbTypes; i++)
394                 {
395                         myseq[i]=convertMedEltToIdlElt(elemts[i]);
396                 };
397         }
398         catch (MEDEXCEPTION &ex)
399         {       
400                 MESSAGE("Unable to acces coordinates");
401                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
402         }
403         return myseq._retn();
404 }
405 //=============================================================================
406 /*!
407  * CORBA: Returns number of elements of type medGeometryElement
408  *        Not implemented for MED_ALL_ELEMENTS 
409 *         implemented for MED_ALL_ENTITIES
410  */
411 //=============================================================================
412 CORBA::Long GMESH_i::getNumberOfElements(SALOME_MED::medEntityMesh entity, 
413                                         SALOME_MED::medGeometryElement geomElement)
414 throw (SALOME::SALOME_Exception)
415 {
416         if (_mesh==NULL)
417                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
418                                              SALOME::INTERNAL_ERROR);
419         if (verifieParam(entity,geomElement)==false)
420                 THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
421                                              SALOME::BAD_PARAM);
422         
423         try
424         {
425 //           if ( geomElement == SALOME_MED::MED_POLYGON ||
426 //                geomElement == SALOME_MED::MED_POLYHEDRA )
427 //             return _mesh->getNumberOfElementsWithPoly(convertIdlEntToMedEnt(entity),
428 //                                                       convertIdlEltToMedElt(geomElement));
429 //           else
430             return _mesh->getNumberOfElements(convertIdlEntToMedEnt(entity),
431                                               convertIdlEltToMedElt(geomElement));
432         }
433         catch (MEDEXCEPTION &ex)
434         {
435                 MESSAGE("Unable to acces number of elements");
436                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
437         }
438 }
439
440 //=============================================================================
441 /*!
442  * CORBA: Returns number of families within the mesh
443  */
444 //=============================================================================
445 CORBA::Long GMESH_i::getNumberOfFamilies(SALOME_MED::medEntityMesh entity)
446 throw (SALOME::SALOME_Exception)
447 {
448         if (_mesh==NULL)
449                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
450                                              SALOME::INTERNAL_ERROR);
451         try
452         {
453                 return _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
454         }
455         catch (MEDEXCEPTION &ex)
456         {
457                 MESSAGE("Unable to acces number of families of the mesh");
458                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
459         }
460 }
461 //=============================================================================
462 /*!
463  * CORBA: Returns number of groups within the mesh
464  */
465 //=============================================================================
466 CORBA::Long GMESH_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity) 
467 throw (SALOME::SALOME_Exception)
468 {
469         if (_mesh==NULL)
470                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
471                                              SALOME::INTERNAL_ERROR);
472         try
473         {
474                 return _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
475         }
476         catch (MEDEXCEPTION &ex)
477         {
478                 MESSAGE("Unable to acces number of groups of the mesh");
479                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
480         }
481 }
482 //=============================================================================
483 /*!
484  * CORBA: Returns references for families within the mesh
485  */
486 //=============================================================================
487 SALOME_MED::Family_array * GMESH_i::getFamilies(SALOME_MED::medEntityMesh entity) 
488 throw (SALOME::SALOME_Exception)
489 {
490         if (_mesh==NULL)
491                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
492                                              SALOME::INTERNAL_ERROR);
493         SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
494         try
495         {
496                 int nbfam= _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
497                 myseq->length(nbfam);
498                 vector<FAMILY*> fam(nbfam);
499                 fam = _mesh->getFamilies(convertIdlEntToMedEnt(entity));
500                 for (int i=0;i<nbfam;i++)
501                 {
502                         FAMILY_i * f1=new FAMILY_i(fam[i]);
503                         myseq[i] = f1->_this();
504                 }
505         }
506         catch (MEDEXCEPTION &ex)
507         {
508                 MESSAGE("Unable to acces families of the mesh");
509                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
510         }
511         return myseq._retn();
512 }
513 //=============================================================================
514 /*!
515  * CORBA: Returns Coordinates global informations
516  */
517 //=============================================================================
518 SALOME_MED::GMESH::coordinateInfos *  GMESH_i::getCoordGlobal()
519 throw (SALOME::SALOME_Exception)
520 {
521         if (_mesh==NULL)
522                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
523                                              SALOME::INTERNAL_ERROR);
524         SALOME_MED::GMESH::coordinateInfos_var all = new SALOME_MED::GMESH::coordinateInfos;
525         try
526         {
527                 all->coordSystem = CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
528
529                 int spaceDimension=_mesh->getSpaceDimension();
530                 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
531                 const string * coordinatesName =_mesh->getCoordinatesNames();
532
533                 all->coordUnits.length(spaceDimension);
534                 all->coordNames.length(spaceDimension);
535                 for (int i=0; i<spaceDimension; i++)
536                 {
537                          all->coordUnits[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
538                          all->coordNames[i]=CORBA::string_dup(coordinatesName[i].c_str());
539                 }
540         }
541         catch (MEDEXCEPTION &ex)
542         {
543                 MESSAGE("Unable to acces coordinate information ");
544                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
545         }
546         return all._retn();
547 }
548
549 //=============================================================================
550 /*!
551  * CORBA: Returns references for family i within the mesh
552  */
553 //=============================================================================
554 SALOME_MED::FAMILY_ptr GMESH_i::getFamily(SALOME_MED::medEntityMesh entity,
555                                          CORBA::Long i) 
556 throw (SALOME::SALOME_Exception)
557 {
558         if (_mesh==NULL)
559                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
560                                              SALOME::INTERNAL_ERROR);
561         try
562         {
563                 const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i);
564                 FAMILY_i * f1=new FAMILY_i(fam);
565                 return f1->_this();
566         }
567         catch (MEDEXCEPTION &ex)
568         {
569                 MESSAGE("Unable to acces specified family of the mesh");
570                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
571         }
572
573 }
574 //=============================================================================
575 /*
576  * CORBA: Returns Mesh global informations
577  */
578 //=============================================================================
579 SALOME_MED::GMESH::meshInfos *  GMESH_i::getMeshGlobal()
580 throw (SALOME::SALOME_Exception)
581 {
582         if (_mesh==NULL)
583                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
584                                              SALOME::INTERNAL_ERROR);
585         SALOME_MED::GMESH::meshInfos_var all = new SALOME_MED::GMESH::meshInfos;
586         try
587         {
588                 all->name = CORBA::string_dup(_mesh->getName().c_str());
589                 all->spaceDimension = _mesh->getSpaceDimension();
590                 all->meshDimension  = _mesh->getMeshDimension();
591                 all->numberOfNodes  = _mesh->getNumberOfNodes();
592                 all->isAGrid        = _mesh->getIsAGrid();
593
594                 int nbFam= _mesh->getNumberOfFamilies(MED_NODE);
595                 all->famNode.length(nbFam);
596                 vector<FAMILY*> vNode (nbFam);
597                 vNode = _mesh->getFamilies(MED_NODE);
598                 for (int i=0;i<nbFam;i++)
599                 {
600                         FAMILY_i * f1=new FAMILY_i(vNode[i]);
601                         all->famNode[i] = f1->_this();
602                 }
603
604                 nbFam = _mesh->getNumberOfFamilies(MED_EDGE);
605                 all->famEdge.length(nbFam);
606                 vector<FAMILY*> vEdge (nbFam);
607                 vEdge = _mesh->getFamilies(MED_EDGE);
608                 for (int i=0;i<nbFam;i++)
609                 for (int i=0;i<nbFam;i++)
610                 {
611                         FAMILY_i * f1=new FAMILY_i(vEdge[i]);
612                         all->famEdge[i] = f1->_this();
613                 }
614
615                 nbFam = _mesh->getNumberOfFamilies(MED_FACE);
616                 all->famFace.length(nbFam);
617                 vector<FAMILY*> vFace (nbFam);
618                 vFace = _mesh->getFamilies(MED_FACE);
619                 for (int i=0;i<nbFam;i++)
620                 {
621                         FAMILY_i * f1=new FAMILY_i(vFace[i]);
622                         all->famFace[i] = f1->_this();
623                 }
624
625                 nbFam = _mesh->getNumberOfFamilies(MED_CELL);
626                 all->famCell.length(nbFam);
627                 vector<FAMILY*> vCell (nbFam);
628                 vCell = _mesh->getFamilies(MED_CELL);
629                 for (int i=0;i<nbFam;i++)
630                 {
631                         FAMILY_i * f1=new FAMILY_i(vCell[i]);
632                         all->famCell[i] = f1->_this();
633                 }
634
635                 int nbGroup = _mesh->getNumberOfGroups(MED_NODE);
636                 all->groupNode.length(nbGroup);
637                 vector<GROUP*> gNode (nbGroup);
638                 gNode = _mesh->getGroups(MED_NODE);
639                 for (int i=0;i<nbGroup;i++)
640                 {
641                         GROUP_i * f1=new GROUP_i(gNode[i]);
642                         all->groupNode[i] = f1->_this();
643                 }
644
645                 nbGroup = _mesh->getNumberOfGroups(MED_EDGE);
646                 all->groupEdge.length(nbGroup);
647                 vector<GROUP*> gEdge (nbGroup);
648                 gEdge = _mesh->getGroups(MED_EDGE);
649                 for (int i=0;i<nbGroup;i++)
650                 {
651                         GROUP_i * f1=new GROUP_i(gEdge[i]);
652                         all->groupEdge[i] = f1->_this();
653                 }
654                 nbGroup = _mesh->getNumberOfGroups(MED_FACE);
655                 all->groupFace.length(nbGroup);
656                 vector<GROUP*> gFace (nbGroup);
657                 gFace = _mesh->getGroups(MED_FACE);
658                 for (int i=0;i<nbGroup;i++)
659                 {
660                         GROUP_i * f1=new GROUP_i(gFace[i]);
661                         all->groupFace[i] = f1->_this();
662                 }
663
664                 nbGroup = _mesh->getNumberOfGroups(MED_CELL);
665                 all->groupCell.length(nbGroup);
666                 vector<GROUP*> gCell (nbGroup);
667                 gCell = _mesh->getGroups(MED_CELL);
668                 for (int i=0;i<nbGroup;i++)
669                 {
670                         GROUP_i * f1=new GROUP_i(gCell[i]);
671                         all->groupCell[i] = f1->_this();
672                 }
673
674         }
675         catch (MEDEXCEPTION &ex)
676         {
677                 MESSAGE("Unable to acces mesh");
678                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
679         }
680         return all._retn();
681 }
682 //=============================================================================
683  /*
684  * CORBA: Returns references for groups within the mesh
685  */
686 //=============================================================================
687 SALOME_MED::Group_array *  GMESH_i::getGroups(SALOME_MED::medEntityMesh entity) 
688 throw (SALOME::SALOME_Exception)
689 {
690         if (_mesh==NULL)
691                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
692                                              SALOME::INTERNAL_ERROR);
693         SALOME_MED::Group_array_var myseq = new SALOME_MED::Group_array;
694         try
695         {
696                 int nbgroups = _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
697                 myseq->length(nbgroups);
698                 vector<GROUP*> groups(nbgroups);
699                 groups = _mesh->getGroups(convertIdlEntToMedEnt(entity));
700                 for (int i=0;i<nbgroups;i++)
701                 {
702                         GROUP_i * f1=new GROUP_i(groups[i]);
703                         myseq[i] = f1->_this();
704                 }
705         }
706         catch (MEDEXCEPTION &ex)
707         {
708                 MESSAGE("Unable to acces number of groups of the mesh");
709                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
710         }
711         return myseq._retn();
712 }
713 //=============================================================================
714 /*!
715  * CORBA: Returns references for group i within the mesh
716  */
717 //=============================================================================
718 SALOME_MED::GROUP_ptr GMESH_i::getGroup(SALOME_MED::medEntityMesh entity,
719                                        CORBA::Long i) 
720 throw (SALOME::SALOME_Exception)
721 {
722         if (_mesh==NULL)
723                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
724                                               SALOME::INTERNAL_ERROR);
725         try
726         {
727                 const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i);
728                 GROUP_i * f1=new GROUP_i(grou);
729                 return f1->_this();
730         }
731         catch (MEDEXCEPTION &ex)
732         {
733                 MESSAGE("Unable to acces specified group of the mesh");
734                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
735         }
736 }
737 //=============================================================================
738 /*!
739  * CORBA:
740  */
741 //=============================================================================
742 SALOME_MED::SUPPORT_ptr GMESH_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
743 throw (SALOME::SALOME_Exception)
744 {
745         if (_mesh==NULL)
746                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
747                                               SALOME::INTERNAL_ERROR);
748         try
749         {
750                 SUPPORT * myNewSupport = _mesh->getBoundaryElements(convertIdlEntToMedEnt(entity));
751                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
752                 return mySupportI->_this();
753         }
754         catch (MEDEXCEPTION &ex)
755         {
756                 MESSAGE("Unable to get the volume ");
757                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
758         }
759 }
760
761 //=============================================================================
762 /*!
763  * CORBA:
764  */
765 //=============================================================================
766 SALOME_MED::SUPPORT_ptr GMESH_i::getSupportOnAll(SALOME_MED::medEntityMesh entity)
767 throw (SALOME::SALOME_Exception)
768 {
769         if (_mesh==NULL)
770                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
771                                               SALOME::INTERNAL_ERROR);
772         try
773         {
774           const SUPPORT * myNewSupport = _mesh->getSupportOnAll(convertIdlEntToMedEnt(entity));
775           SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
776           return mySupportI->_this();
777         }
778         catch (MEDEXCEPTION &ex)
779         {
780                 MESSAGE("Unable to get the support ");
781                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
782         }
783 }
784 //=============================================================================
785 /*!
786  * CORBA: 
787  */
788 //=============================================================================
789 SALOME_MED::FIELD_ptr GMESH_i::getVolume(SALOME_MED::SUPPORT_ptr mySupport)
790 throw (SALOME::SALOME_Exception)
791 {
792         if (_mesh==NULL)
793                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
794                                               SALOME::INTERNAL_ERROR); try
795         {
796                 int sup = mySupport->getCorbaIndex();
797                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
798                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
799                 ::FIELD<double>*f=_mesh->getVolume( myCppSupport);
800                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
801                 return medf->_this();
802         }
803         catch (MEDEXCEPTION &ex)
804         {
805                 MESSAGE("Unable to get the volume ");
806                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
807         }
808 }
809 //=============================================================================
810 /*!
811  * CORBA:
812  */
813 //=============================================================================
814 SALOME_MED::SUPPORT_ptr GMESH_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
815 throw (SALOME::SALOME_Exception)
816 {
817         if (_mesh==NULL)
818                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
819                                               SALOME::INTERNAL_ERROR);
820         try
821         {
822                 int sup = mySupport3D->getCorbaIndex();
823                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
824                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
825                 SUPPORT * myNewSupport = _mesh->getSkin(myCppSupport);
826                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
827                 return mySupportI->_this() ;
828         }
829         catch (MEDEXCEPTION &ex)
830         {
831                 MESSAGE("Unable to get the volume ");
832                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
833         }
834 }
835 //=============================================================================
836 /*!
837  * CORBA: 
838  */
839 //=============================================================================
840 SALOME_MED::FIELD_ptr GMESH_i::getArea(SALOME_MED::SUPPORT_ptr mySupport)
841 throw (SALOME::SALOME_Exception)
842 {
843         if (_mesh==NULL)
844                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
845                                               SALOME::INTERNAL_ERROR);
846         try
847         {
848                 int sup = mySupport->getCorbaIndex();
849                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
850                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
851                 ::FIELD<double>*f=_mesh->getArea( myCppSupport);
852                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
853                 return medf->_this();
854         }
855         catch (MEDEXCEPTION &ex)
856         {
857                 MESSAGE("Unable to get the area ");
858                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
859         }
860 }
861 //=============================================================================
862 /*!
863  * CORBA: 
864  */
865 //=============================================================================
866 SALOME_MED::FIELD_ptr GMESH_i::getLength(SALOME_MED::SUPPORT_ptr mySupport)
867 throw (SALOME::SALOME_Exception)
868 {
869         if (_mesh==NULL)
870                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
871                                               SALOME::INTERNAL_ERROR);
872         try
873         {
874                 int sup = mySupport->getCorbaIndex();
875                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
876                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
877                 ::FIELD<double>*f=_mesh->getLength( myCppSupport);
878                 FIELDTEMPLATE_I<double>  *medf = new FIELDTEMPLATE_I<double>(f);
879                 return medf->_this();
880         }
881         catch (MEDEXCEPTION &ex)
882         {
883                 MESSAGE("Unable to get the length ");
884                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
885         }
886 }
887 //=============================================================================
888 /*!
889  * CORBA: 
890  */
891 //=============================================================================
892 SALOME_MED::FIELD_ptr GMESH_i::getNormal(SALOME_MED::SUPPORT_ptr mySupport)
893 throw (SALOME::SALOME_Exception)
894 {
895         if (_mesh==NULL)
896                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
897                                               SALOME::INTERNAL_ERROR);
898         try
899         {
900                 int sup = mySupport->getCorbaIndex();
901                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
902                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
903                 ::FIELD<double>*f=_mesh->getNormal( myCppSupport);
904                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
905                 return medf->_this();
906         }
907         catch (MEDEXCEPTION &ex)
908         {
909                 MESSAGE("Unable to get the normal ");
910                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
911         }
912 }
913 //=============================================================================
914 /*!
915  * CORBA: 
916  */
917 //=============================================================================
918 SALOME_MED::FIELD_ptr GMESH_i::getBarycenter(SALOME_MED::SUPPORT_ptr mySupport)
919 throw (SALOME::SALOME_Exception)
920 {
921         if (_mesh==NULL)
922                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
923                                               SALOME::INTERNAL_ERROR);
924         try
925         {
926                 int sup = mySupport->getCorbaIndex();
927                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
928                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
929                 ::FIELD<double>*f=_mesh->getBarycenter( myCppSupport);
930                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
931                 return medf->_this();
932         }
933         catch (MEDEXCEPTION &ex)
934         {
935                 MESSAGE("Unable to get the barycenter ");
936                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
937         }
938 }
939 //=============================================================================
940 /*!
941  * CORBA: 
942  */
943 //=============================================================================
944 SALOME_MED::FIELD_ptr GMESH_i::getNeighbourhood(SALOME_MED::SUPPORT_ptr mySupport)
945 throw (SALOME::SALOME_Exception)
946 {
947         if (_mesh==NULL)
948                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
949                                               SALOME::INTERNAL_ERROR);
950         MESSAGE("Not Implemented");
951         return SALOME_MED::FIELD::_nil();
952 }
953 //=============================================================================
954 /*!
955  * CORBA: add the Mesh in the StudyManager 
956  */
957 //=============================================================================
958 void GMESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::GMESH_ptr myIor )
959 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
960 {
961         if ( _meshId != "" )
962         {
963                 MESSAGE("Mesh already in Study");
964                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
965                                  SALOME::BAD_PARAM);
966         };
967
968         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
969         SALOMEDS::GenericAttribute_var anAttr;
970         SALOMEDS::AttributeName_var    aName;
971         SALOMEDS::AttributeIOR_var     aIOR;
972
973         // Find SComponent labelled 'MED'
974         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
975         myBuilder->NewCommand();
976         if ( CORBA::is_nil(medfather) ) 
977           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
978
979         // Create SObject labelled 'MESH' if it doesn't already exit
980 //      SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
981 //      if ( CORBA::is_nil(medmeshfather) ) 
982 //      {
983 //              MESSAGE("Add Object MEDMESH");
984 //              medmeshfather = myBuilder->NewObject(medfather);
985 //              //medmeshfather.Name = "MEDMESH" ;
986 //                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
987 //                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
988 //                 aName->SetValue("MEDMESH");
989
990 //      } ;
991
992         string aPath = "/Med/MEDMESH";
993         SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
994         if ( CORBA::is_nil(medmeshfather) ) 
995           {
996             MESSAGE("Add Object MEDMESH");
997
998             myBuilder->AddDirectory( aPath.c_str() );
999             medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
1000           } ;
1001
1002         aPath += "/" + _mesh->getName();
1003         SALOMEDS::SObject_var meshSO = myStudy->FindObjectByPath( aPath.c_str());
1004         bool alreadyPublished = ! CORBA::is_nil( meshSO );
1005         if ( !alreadyPublished ) {
1006           MESSAGE("Add a mesh Object under MED/MEDMESH");
1007           meshSO = myBuilder->NewObject(medmeshfather);
1008
1009           anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeName");
1010           aName = SALOMEDS::AttributeName::_narrow(anAttr);
1011           aName->SetValue(_mesh->getName().c_str());
1012         }
1013
1014         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1015         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1016         CORBA::ORB_var &orb = init(0,0);
1017         string iorStr = orb->object_to_string(myIor);
1018         anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeIOR");
1019         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1020         aIOR->SetValue(iorStr.c_str());
1021         _meshId = meshSO->GetID();
1022         myBuilder->CommitCommand();
1023
1024         // register the Corba pointer: increase the referrence count
1025         MESSAGE("Registering of the Corba Mesh pointer");
1026         Register();
1027
1028 }
1029 //=============================================================================
1030 /*!
1031  * CORBA: add the Mesh in the StudyManager
1032  */
1033 //=============================================================================
1034 void GMESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::GMESH_ptr myIor,const string & fileName )
1035 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1036 {
1037         if ( _meshId != "" )
1038         {
1039                 MESSAGE("Mesh already in Study");
1040                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1041                                  SALOME::BAD_PARAM);
1042         };
1043
1044         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1045         SALOMEDS::GenericAttribute_var anAttr;
1046         SALOMEDS::AttributeName_var    aName;
1047         SALOMEDS::AttributeIOR_var     aIOR;
1048         SALOMEDS::AttributeComment_var aComment;
1049
1050         // Find SComponent labelled 'Med'
1051         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1052         if ( CORBA::is_nil(medfather) )
1053           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1054
1055         // Create SObject labelled 'MESH' if it doesn't already exit
1056         SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1057         if ( CORBA::is_nil(medmeshfather) )
1058         {
1059                 MESSAGE("Add Object MEDMESH");
1060                 medmeshfather = myBuilder->NewObject(medfather);
1061                 //medmeshfather.Name = "MEDMESH" ;
1062                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1063                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1064                 aName->SetValue("MEDMESH");
1065
1066         } ;
1067
1068         MESSAGE("Add a mesh Object under MED/MEDMESH");
1069         myBuilder->NewCommand();
1070         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
1071
1072         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1073         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1074         CORBA::ORB_var &orb = init(0,0);
1075         CORBA::String_var iorStr = orb->object_to_string(myIor);
1076         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1077         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1078         aIOR->SetValue(iorStr.in());
1079         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1080         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1081         aName->SetValue(_mesh->getName().c_str());
1082         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
1083         aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
1084         aComment->SetValue(fileName.c_str());
1085         _meshId = newObj->GetID();
1086         myBuilder->CommitCommand();
1087
1088         // register the Corba pointer: increase the referrence count
1089         MESSAGE("Registering of the Corba Mesh pointer");
1090         Register();
1091
1092 }
1093 //=============================================================================
1094
1095 //=============================================================================
1096 /*!
1097  * CORBA: write mesh in a med file
1098  */
1099 //=============================================================================
1100 void GMESH_i::write(CORBA::Long i, const char* driverMeshName)        
1101 throw (SALOME::SALOME_Exception)
1102 {
1103         if (_mesh==NULL)
1104                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1105                                              SALOME::INTERNAL_ERROR);
1106         try
1107         {
1108                 _mesh->write(i);
1109         }
1110         catch (MEDEXCEPTION &ex)
1111         {
1112                 MESSAGE("Unable to write the mesh ");
1113                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1114         }
1115 }
1116 //=============================================================================
1117 /*!
1118  * CORBA: read mesh in a med file
1119  */
1120 //=============================================================================
1121 void GMESH_i::read(CORBA::Long i)             
1122 throw (SALOME::SALOME_Exception)
1123 {
1124         if (_mesh==NULL)
1125                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1126                                              SALOME::INTERNAL_ERROR);
1127         try
1128         {
1129                 _mesh->read(i);
1130         }
1131         catch (MEDEXCEPTION &ex)
1132         {
1133                 MESSAGE("Unable to read the mesh ");
1134                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1135         }
1136 }
1137 //=============================================================================
1138 /*!
1139  * CORBA : release driver
1140  */
1141 //=============================================================================
1142 void GMESH_i::rmDriver(CORBA::Long i)         
1143 throw (SALOME::SALOME_Exception)
1144 {
1145         if (_mesh==NULL)
1146                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1147                                              SALOME::INTERNAL_ERROR);
1148         try
1149         {
1150                 _mesh->rmDriver();
1151         }
1152         catch (MEDEXCEPTION &ex)
1153         {
1154                 MESSAGE("Unable to unlink the mesh from the driver ");
1155                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1156                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
1157                                                 ,SALOME::INTERNAL_ERROR);
1158         }
1159 }
1160 //=============================================================================
1161 /*!
1162  * CORBA : attach driver
1163  */
1164 //=============================================================================
1165 CORBA::Long GMESH_i::addDriver(SALOME_MED::medDriverTypes driverType, 
1166                               const char* fileName, const char* meshName)
1167 throw (SALOME::SALOME_Exception)
1168 {
1169         if (_mesh==NULL)
1170                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1171                                              SALOME::INTERNAL_ERROR);
1172         try
1173         {
1174                 int drivernum=_mesh->addDriver(
1175                                         convertIdlDriverToMedDriver(driverType),
1176                                         fileName,
1177                                         meshName);
1178                 return drivernum;
1179         }
1180         catch (MEDEXCEPTION &ex)
1181         {
1182                 MESSAGE("Unable to link the mesh to the driver ");
1183                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1184         }
1185 }
1186
1187 //=============================================================================
1188 /*!
1189  * CORBA : Test if this and other aggregate the same MESH using the MESH::operator==
1190  */
1191 //=============================================================================
1192 CORBA::Boolean GMESH_i::areEquals(SALOME_MED::GMESH_ptr other)
1193 {
1194   PortableServer::ServantBase *baseServ;
1195   try {
1196     baseServ=_default_POA()->reference_to_servant(other);
1197   }
1198   catch(...){
1199     baseServ=0;
1200   }
1201   if(baseServ)
1202     {
1203      baseServ->_remove_ref();
1204      GMESH_i *otherServ=dynamic_cast<GMESH_i *>(baseServ);
1205      return *_mesh==*otherServ->_mesh;
1206     }
1207   return false;
1208 }
1209
1210 //================================================================================
1211 /*!
1212  * \brief Converts this GMESH into MESH
1213  */
1214 //================================================================================
1215
1216 SALOME_MED::MESH_ptr GMESH_i::convertInMESH() throw (SALOME::SALOME_Exception)
1217 {
1218   if (_mesh==NULL)
1219     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",SALOME::INTERNAL_ERROR);
1220
1221   const MESH* mesh = _mesh->convertInMESH();
1222   MESH_i* mesh_i = new MESH_i( const_cast< MESH*> ( mesh ));
1223   return mesh_i->_this();
1224 }
1225