Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / MEDMEM_I / MEDMEM_Mesh_i.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //=============================================================================
23 // File      : MEDMEM_Mesh_i.cxx
24 // Project   : SALOME
25 // Author    : EDF 
26 // $Header: /export/home/PAL/MED_SRC/src/MEDMEM_I/MEDMEM_Mesh_i.cxx
27 //=============================================================================
28 //
29 #include <vector>
30
31 #include "utilities.h"
32 #include "Utils_CorbaException.hxx"
33 #include "Utils_ORB_INIT.hxx"
34 #include "Utils_SINGLETON.hxx"
35
36 #include "MEDMEM_convert.hxx"
37 #include "MEDMEM_Mesh_i.hxx"
38 #include "MEDMEM_Support_i.hxx"
39 #include "MEDMEM_Family_i.hxx"
40 #include "MEDMEM_Group_i.hxx"
41 #include "MEDMEM_FieldTemplate_i.hxx"
42
43 #include "MEDMEM_Mesh.hxx"
44 #include "MEDMEM_Family.hxx"
45 #include "MEDMEM_Group.hxx"
46 #include "MEDMEM_CellModel.hxx"
47
48 #include "SenderFactory.hxx"
49 #include "MultiCommException.hxx"
50 using namespace MEDMEM;
51
52 // Initialisation des variables statiques
53 map < int, ::MESH *> MESH_i::meshMap ;
54 int MESH_i::meshIndex = 0 ;
55
56
57
58 //=============================================================================
59 /*!
60  * Default constructor
61  */
62 //=============================================================================
63 MESH_i::MESH_i(): _mesh(constructConstMesh()),
64                   _corbaIndex(MESH_i::meshIndex++),
65                   _meshId("") 
66 {
67   const char* LOC = "Default Constructor MESH_i";
68   BEGIN_OF(LOC);
69         MESH_i::meshMap[_corbaIndex]=_mesh;
70   END_OF(LOC);
71 }
72 //=============================================================================
73 /*!
74  * Destructor
75  */
76 //=============================================================================
77 MESH_i::~MESH_i()
78 {
79 }
80 //=============================================================================
81 /*!
82  * Constructor
83  */
84 //=============================================================================
85 MESH_i::MESH_i(::MESH * const m ) :_mesh(m),
86                         _corbaIndex(MESH_i::meshIndex++),
87                         _meshId("") 
88 {
89   const char* LOC = "Constructor MESH_i(::MESH * const m )";
90   BEGIN_OF(LOC);
91         MESH_i::meshMap[_corbaIndex]=_mesh;
92         SCRUTE(_mesh);
93
94   END_OF(LOC);
95 }
96 //=============================================================================
97 /*!
98  * Copy Constructor 
99  */
100 //=============================================================================
101 //MESH_i::MESH_i(const MESH_i & m) :_mesh(m._mesh),
102 MESH_i::MESH_i( MESH_i & m) :_mesh(m._mesh),
103                              _corbaIndex(MESH_i::meshIndex++),
104                              _meshId("") 
105 {
106   const char* LOC = "Constructor MESH_i";
107   BEGIN_OF(LOC);
108         MESH_i::meshMap[_corbaIndex]=_mesh;
109   END_OF(LOC);
110 }
111 //=============================================================================
112 /*!
113  * Internal Method in order to have a const ptr
114  */
115 //=============================================================================
116 ::MESH * MESH_i::constructConstMesh() const
117 {
118         ::MESH * const ptrMesh =new ::MESH();
119         return ptrMesh;
120 }
121 //=============================================================================
122 /*!
123  * CORBA: Accessor for Name
124  */
125 //=============================================================================
126 char * MESH_i::getName()        
127 throw (SALOME::SALOME_Exception)
128 {
129         if (_mesh==NULL)
130                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
131                                              SALOME::INTERNAL_ERROR);
132
133         try
134         {
135                 return CORBA::string_dup(_mesh->getName().c_str());
136         }
137         catch (MEDEXCEPTION &ex)
138         {
139                 MESSAGE("Unable to acces the mesh name");
140                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
141         }
142 }
143 //=============================================================================
144 /*!
145  * CORBA: Accessor for corbaindex cuisine interne 
146  */
147 //=============================================================================
148 CORBA::Long MESH_i::getCorbaIndex() 
149 throw (SALOME::SALOME_Exception)
150 {
151         if (_mesh==NULL)
152                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
153                                              SALOME::INTERNAL_ERROR);
154         return _corbaIndex;
155 }
156 //=============================================================================
157 /*!
158  * CORBA: Accessor for Space Dimension
159  */
160 //=============================================================================
161 CORBA::Long MESH_i::getSpaceDimension() 
162 throw (SALOME::SALOME_Exception)
163 {
164         if (_mesh==NULL)
165                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
166                                              SALOME::INTERNAL_ERROR);
167         try
168         {
169                 return _mesh->getSpaceDimension();
170         }
171         catch (MEDEXCEPTION &ex)
172         {
173                 MESSAGE("Unable to acces the space dimension ");
174                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
175         }
176 }
177 //=============================================================================
178 /*!
179  * CORBA: Accessor for Mesh Dimension
180  */
181 //=============================================================================
182 CORBA::Long MESH_i::getMeshDimension()
183 throw (SALOME::SALOME_Exception)
184 {
185         if (_mesh==NULL)
186                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
187                                              SALOME::INTERNAL_ERROR);
188         try
189         {
190                 return _mesh->getMeshDimension();
191         }
192         catch (MEDEXCEPTION &ex)
193         {
194                 MESSAGE("Unable to acces the mesh dimension ");
195                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
196         }
197 }
198 //=============================================================================
199 /*!
200  * CORBA: boolean indicating if mesh is a Grid
201  */
202 //=============================================================================
203 CORBA::Boolean MESH_i::getIsAGrid()
204 throw (SALOME::SALOME_Exception)
205 {
206         if (_mesh==NULL)
207                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
208                                              SALOME::INTERNAL_ERROR);
209         try
210         {
211                 return _mesh->getIsAGrid();
212         }
213         catch (MEDEXCEPTION &ex)
214         {
215                 MESSAGE("Unable to acces mesh flag isAGrid");
216                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
217         }
218 }
219 //=============================================================================
220 /*!
221  * CORBA: boolean indicating if connectivity exists
222  */
223 //=============================================================================
224 CORBA::Boolean MESH_i::existConnectivity
225                        (SALOME_MED::medConnectivity connectivityType,
226                         SALOME_MED::medEntityMesh entity)
227 throw (SALOME::SALOME_Exception)
228 {
229         if (_mesh==NULL)
230                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
231                                              SALOME::INTERNAL_ERROR);
232         try
233         {
234                 return _mesh->existConnectivity(connectivityType,
235                                                 convertIdlEntToMedEnt(entity));        }
236         catch (MEDEXCEPTION &ex)
237         {
238                 MESSAGE("Unable to acces mesh flag existConnectivity");
239                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
240         }
241 }
242
243 //=============================================================================
244 /*!
245  * CORBA: Accessor for Coordinates System
246  */
247 //=============================================================================
248 char * MESH_i::getCoordinatesSystem()
249 throw (SALOME::SALOME_Exception)
250 {
251         if (_mesh==NULL)
252                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
253                                              SALOME::INTERNAL_ERROR);
254
255         try
256         {
257                 return CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
258         }
259         catch (MEDEXCEPTION &ex)
260         {
261                 MESSAGE("Unable to acces the type of CoordinatesSystem");
262                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
263         }
264 }
265 //=============================================================================
266 /*!
267  * CORBA: Accessor for a specific coordinate
268  */
269 //=============================================================================
270 CORBA::Double MESH_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
271 throw (SALOME::SALOME_Exception)
272 {
273         if (_mesh==NULL)
274                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
275                                              SALOME::INTERNAL_ERROR);
276         try
277         {
278                  return _mesh->getCoordinate(Number,Axis);
279         }
280         catch (MEDEXCEPTION &ex)
281         {
282                 MESSAGE("Unable to acces this coordinate");
283                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
284         }
285 }
286 //=============================================================================
287 /*!
288  * CORBA: Accessor for Coordinates
289  */
290 //=============================================================================
291 SALOME_MED::double_array * MESH_i::getCoordinates(SALOME_MED::medModeSwitch typeSwitch)
292 throw (SALOME::SALOME_Exception)
293 {
294         if (_mesh==NULL)
295                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
296                                              SALOME::INTERNAL_ERROR);
297         SALOME_MED::double_array_var myseq = new SALOME_MED::double_array;
298         try
299         {
300                 int spaceDimension=_mesh->getSpaceDimension();
301                 int nbNodes=_mesh->getNumberOfNodes();
302                 const double * coordinates =_mesh->getCoordinates(
303                                        convertIdlModeToMedMode(typeSwitch));
304
305                 myseq->length(nbNodes*spaceDimension);
306                 for (int i=0; i<nbNodes*spaceDimension; i++)
307                 {
308                         myseq[i]=coordinates[i];
309                 };
310         }
311         catch (MEDEXCEPTION &ex)
312         {       
313                 MESSAGE("Unable to acces the coordinates");
314                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
315         }
316         return myseq._retn();
317 }
318 //=============================================================================
319 /*!
320  * CORBA: 2nd Accessor for Coordinates
321  */
322 //=============================================================================
323 SALOME::SenderDouble_ptr MESH_i::getSenderForCoordinates(SALOME_MED::medModeSwitch typeSwitch)
324     throw (SALOME::SALOME_Exception)
325 {
326   if (_mesh==NULL)
327     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
328                                  SALOME::INTERNAL_ERROR);
329   SALOME::SenderDouble_ptr ret;
330   try
331     {
332       int spaceDimension=_mesh->getSpaceDimension();
333       int nbNodes=_mesh->getNumberOfNodes();
334       const double * coordinates =_mesh->getCoordinates(convertIdlModeToMedMode(typeSwitch));
335       ret=SenderFactory::buildSender(*this,coordinates,nbNodes*spaceDimension);
336     }
337   catch (MEDEXCEPTION &ex)
338     {       
339       MESSAGE("Unable to acces the coordinates");
340       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
341     }
342   catch(MultiCommException &ex2)
343     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
344   return ret;
345 }
346 //=============================================================================
347 /*!
348  * CORBA: Accessor for Coordinates Names
349  */
350 //=============================================================================
351 SALOME_MED::string_array  * MESH_i::getCoordinatesNames() 
352 throw (SALOME::SALOME_Exception)
353 {
354         if (_mesh==NULL)
355                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
356                                              SALOME::INTERNAL_ERROR);
357         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
358         try
359         {
360                 int spaceDimension=_mesh->getSpaceDimension();
361                 const string * coordinatesName =_mesh->getCoordinatesNames();
362                 myseq->length(spaceDimension);
363                 for (int i=0; i<spaceDimension; i++)
364                 {
365                         myseq[i]=CORBA::string_dup(coordinatesName[i].c_str());
366                 }
367         }
368         catch (MEDEXCEPTION &ex)
369         {       
370                 MESSAGE("Unable to acces the coordinates names");
371                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
372         }
373         return myseq._retn();
374
375 }
376 //=============================================================================
377 /*!
378  * CORBA: Accessor for Coordinates Units
379  */
380 //=============================================================================
381 SALOME_MED::string_array *  MESH_i::getCoordinatesUnits()
382 throw (SALOME::SALOME_Exception)
383 {
384         if (_mesh==NULL)
385                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
386                                              SALOME::INTERNAL_ERROR);
387         SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
388         try
389         {
390                 int spaceDimension=_mesh->getSpaceDimension();
391                 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
392                 myseq->length(spaceDimension);
393                 for (int i=0; i<spaceDimension; i++)
394                 {
395                          myseq[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
396                 };
397         }
398         catch (MEDEXCEPTION &ex)
399         {       
400                 MESSAGE("Unable to acces the coordinates units");
401                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
402         }
403         return myseq._retn();
404 }
405 //=============================================================================
406 /*!
407  * CORBA: Accessor for Number of Nodes
408  */
409 //=============================================================================
410 CORBA::Long  MESH_i::getNumberOfNodes() 
411 throw (SALOME::SALOME_Exception)
412 {
413         if (_mesh==NULL)
414                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
415                                              SALOME::INTERNAL_ERROR);
416         try
417         {
418                 return _mesh->getNumberOfNodes();
419         }
420         catch (MEDEXCEPTION &ex)
421         {       
422                 MESSAGE("Unable to acces number of nodes");
423                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
424         }
425 }
426 //=============================================================================
427 /*!
428  * CORBA: Accessor for number of Types
429  */
430 //=============================================================================
431 CORBA::Long MESH_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity) 
432 throw (SALOME::SALOME_Exception)
433 {
434         if (_mesh==NULL)
435                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
436                                              SALOME::INTERNAL_ERROR);
437         try
438         {
439                 return _mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
440         }
441         catch (MEDEXCEPTION &ex)
442         {       
443                 MESSAGE("Unable to acces number of differents types");
444                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
445         }
446 }
447 //=============================================================================
448 /*!
449  * CORBA: Accessor for existing geometry element types
450  */
451 //=============================================================================
452 SALOME_MED::medGeometryElement MESH_i::getElementType (SALOME_MED::medEntityMesh entity,
453                                                        CORBA::Long number)
454 throw (SALOME::SALOME_Exception)
455 {
456         if (_mesh==NULL)
457                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
458                                              SALOME::INTERNAL_ERROR);
459         try
460         {
461                 return _mesh->getElementType(convertIdlEntToMedEnt(entity),number);
462         }
463         catch (MEDEXCEPTION &ex)
464         {
465                 MESSAGE("Unable to acces number of differents element types");
466                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
467         }
468 }
469
470 //=============================================================================
471 /*!
472  * CORBA: Accessor for existing geometry element types 
473  *        Not implemented for MED_ALL_ENTITIES
474  */
475 //=============================================================================
476 SALOME_MED::medGeometryElement_array * MESH_i::getTypes (SALOME_MED::medEntityMesh entity) 
477 throw (SALOME::SALOME_Exception)
478 {
479         if (_mesh==NULL)
480                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
481                                              SALOME::INTERNAL_ERROR);
482         if (entity ==SALOME_MED::MED_ALL_ENTITIES)
483                 THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",\
484                                              SALOME::BAD_PARAM);
485         SALOME_MED::medGeometryElement_array_var myseq = 
486                                         new SALOME_MED::medGeometryElement_array;
487         try
488         {
489                 int nbTypes=_mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
490                 const medGeometryElement * elemts  =_mesh->getTypes(
491                                        convertIdlEntToMedEnt(entity));
492                 myseq->length(nbTypes);
493                 for (int i=0; i<nbTypes; i++)
494                 {
495                         myseq[i]=convertMedEltToIdlElt(elemts[i]);
496                 };
497         }
498         catch (MEDEXCEPTION &ex)
499         {       
500                 MESSAGE("Unable to acces coordinates");
501                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
502         }
503         return myseq._retn();
504 }
505 //=============================================================================
506 /*!
507  * CORBA: Returns number of elements of type medGeometryElement
508  *        Not implemented for MED_ALL_ELEMENTS 
509 *         implemented for MED_ALL_ENTITIES
510  */
511 //=============================================================================
512 CORBA::Long MESH_i::getNumberOfElements(SALOME_MED::medEntityMesh entity, 
513                                         SALOME_MED::medGeometryElement geomElement)
514 throw (SALOME::SALOME_Exception)
515 {
516         if (_mesh==NULL)
517                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
518                                              SALOME::INTERNAL_ERROR);
519         if (verifieParam(entity,geomElement)==false)
520                 THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
521                                              SALOME::BAD_PARAM);
522         
523         try
524         {
525 //           if ( geomElement == SALOME_MED::MED_POLYGON ||
526 //                geomElement == SALOME_MED::MED_POLYHEDRA )
527 //             return _mesh->getNumberOfElementsWithPoly(convertIdlEntToMedEnt(entity),
528 //                                                       convertIdlEltToMedElt(geomElement));
529 //           else
530             return _mesh->getNumberOfElements(convertIdlEntToMedEnt(entity),
531                                               convertIdlEltToMedElt(geomElement));
532         }
533         catch (MEDEXCEPTION &ex)
534         {
535                 MESSAGE("Unable to acces number of elements");
536                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
537         }
538 }
539 //=============================================================================
540 /*!
541  * CORBA: Accessor for connectivities
542  */
543 //=============================================================================
544 SALOME_MED::long_array *  MESH_i::getConnectivity(SALOME_MED::medModeSwitch typeSwitch,
545                                                SALOME_MED::medConnectivity mode, 
546                                                SALOME_MED::medEntityMesh entity, 
547                                                SALOME_MED::medGeometryElement geomElement)
548 throw (SALOME::SALOME_Exception)
549 {
550         if (_mesh==NULL)
551                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
552                                              SALOME::INTERNAL_ERROR);
553         if (verifieParam(entity,geomElement)==false)
554                 THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
555                                              SALOME::BAD_PARAM);
556         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
557         try
558         {
559                 int nbelements; 
560                 int elt1 = _mesh->getNumberOfElements(
561                                         convertIdlEntToMedEnt(entity),
562                                         convertIdlEltToMedElt(geomElement));
563 SCRUTE(elt1);
564                 if ( mode == SALOME_MED::MED_DESCENDING)
565                 {
566 MESSAGE("MED_DESCENDING");
567                   int elt2 =(_mesh->getCellsTypes(MED_CELL))->getNumberOfConstituents(1);
568                    //int elt2 =(_mesh->getTypes(convertIdlEltToMedElt(geomElement)))->getNumberOfConstituents(1);
569                    nbelements= elt2 * elt1;
570 SCRUTE(elt2);
571                 }
572                 else
573                 {
574 MESSAGE("MED_NODAL");
575 //                      const int * tab=_mesh->getConnectivityIndex(
576 //                              convertIdlConnToMedConn(mode),
577 //                              convertIdlEntToMedEnt(entity));
578                         nbelements = _mesh->getConnectivityLength
579                           (convertIdlModeToMedMode(typeSwitch),
580                            convertIdlConnToMedConn(mode),
581                            convertIdlEntToMedEnt(entity),
582                            convertIdlEltToMedElt(geomElement));
583                         //nbelements = elt1*(convertIdlEltToMedElt(geomElement)%100);
584                         //                      nbelements = tab[elt1 ] - 1 ;
585                 }
586 SCRUTE(entity);
587 SCRUTE(geomElement);
588 SCRUTE(nbelements);
589                 myseq->length(nbelements);
590                 const int * numbers=_mesh->getConnectivity(convertIdlModeToMedMode(typeSwitch),
591                                                      convertIdlConnToMedConn(mode),
592                                                      convertIdlEntToMedEnt(entity),
593                                                      convertIdlEltToMedElt(geomElement));
594                 for (int i=0;i<nbelements;i++)
595                 {
596                         myseq[i]=numbers[i];
597                 }
598         }
599         catch (MEDEXCEPTION &ex)
600         {
601                 MESSAGE("Unable to acces connectivities");
602                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
603         }
604         return myseq._retn();
605 }
606 //=============================================================================
607 /*!
608  * CORBA: 2nd Accessor for connectivities
609  */
610 //=============================================================================
611 SALOME::SenderInt_ptr MESH_i::getSenderForConnectivity(SALOME_MED::medModeSwitch typeSwitch,
612                                                SALOME_MED::medConnectivity mode, 
613                                                SALOME_MED::medEntityMesh entity, 
614                                                SALOME_MED::medGeometryElement geomElement)
615 throw (SALOME::SALOME_Exception)
616 {
617   if (_mesh==NULL)
618     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
619                                  SALOME::INTERNAL_ERROR);
620   if (verifieParam(entity,geomElement)==false)
621     THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
622                                  SALOME::BAD_PARAM);
623   SALOME::SenderInt_ptr ret;
624   try
625     {
626       int nbelements=_mesh->getConnectivityLength(convertIdlModeToMedMode(typeSwitch),
627                                                  convertIdlConnToMedConn(mode),
628                                                  convertIdlEntToMedEnt(entity),
629                                                  convertIdlEltToMedElt(geomElement));
630       const int * numbers=_mesh->getConnectivity(convertIdlModeToMedMode(typeSwitch),
631                                                  convertIdlConnToMedConn(mode),
632                                                  convertIdlEntToMedEnt(entity),
633                                                  convertIdlEltToMedElt(geomElement));
634       ret=SenderFactory::buildSender(*this,numbers,nbelements);
635     }
636   catch (MEDEXCEPTION &ex)
637     {
638       MESSAGE("Unable to acces connectivities");
639       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
640     }
641   catch(MultiCommException &ex2)
642     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
643   return ret;
644 }
645
646 //=======================================================================
647 //function : getSenderForPolygonsConnectivity
648 //purpose  : 
649 //=======================================================================
650
651 SALOME::SenderInt_ptr MESH_i::getSenderForPolygonsConnectivity(SALOME_MED::medConnectivity mode,
652                                                                SALOME_MED::medEntityMesh entity)
653   throw (SALOME::SALOME_Exception)
654 {
655   if (_mesh==NULL)
656     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
657                                  SALOME::INTERNAL_ERROR);
658   if (verifieParam(entity,SALOME_MED::MED_POLYGON)==false)
659     THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
660                                  SALOME::BAD_PARAM);
661   SALOME::SenderInt_ptr ret;
662   try
663     {
664       int nbelements = _mesh->getPolygonsConnectivityLength(convertIdlConnToMedConn(mode),
665                                                             convertIdlEntToMedEnt(entity));
666       const int * numbers=_mesh->getPolygonsConnectivity (convertIdlConnToMedConn(mode),
667                                                           convertIdlEntToMedEnt(entity));
668       ret=SenderFactory::buildSender(*this,numbers,nbelements);
669     }
670   catch (MEDEXCEPTION &ex)
671     {
672       MESSAGE("Unable to acces connectivities");
673       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
674     }
675   catch(MultiCommException &ex2)
676     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
677   return ret;
678 }
679
680 //=======================================================================
681 //function : getSenderForPolygonsConnectivityIndex
682 //purpose  : 
683 //=======================================================================
684
685 SALOME::SenderInt_ptr MESH_i::getSenderForPolygonsConnectivityIndex(SALOME_MED::medConnectivity mode,
686                                                             SALOME_MED::medEntityMesh entity)
687       throw (SALOME::SALOME_Exception)
688 {
689   if (_mesh==NULL)
690     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
691                                  SALOME::INTERNAL_ERROR);
692   if (verifieParam(entity,SALOME_MED::MED_POLYGON)==false)
693     THROW_SALOME_CORBA_EXCEPTION("parameters don't match",\
694                                  SALOME::BAD_PARAM);
695   SALOME::SenderInt_ptr ret;
696   try
697     {
698       int nbelements = _mesh->getNumberOfPolygons(entity) + 1;
699       const int * numbers=_mesh->getPolygonsConnectivityIndex (convertIdlConnToMedConn(mode),
700                                                                convertIdlEntToMedEnt(entity));
701       ret=SenderFactory::buildSender(*this,numbers,nbelements);
702     }
703   catch (MEDEXCEPTION &ex)
704     {
705       MESSAGE("Unable to acces connectivities");
706       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
707     }
708   catch(MultiCommException &ex2)
709     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
710   return ret;
711 }
712
713 //=======================================================================
714 //function : getSenderForPolyhedronConnectivity
715 //purpose  : 
716 //=======================================================================
717
718 SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronConnectivity(SALOME_MED::medConnectivity mode)
719     throw (SALOME::SALOME_Exception)
720 {
721   if (_mesh==NULL)
722     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
723                                  SALOME::INTERNAL_ERROR);
724   SALOME::SenderInt_ptr ret;
725   try
726     {
727       int nbelements = _mesh->getPolyhedronConnectivityLength(convertIdlConnToMedConn(mode));
728       const int * numbers=_mesh->getPolyhedronConnectivity( convertIdlConnToMedConn(mode) );
729       ret=SenderFactory::buildSender(*this,numbers,nbelements);
730     }
731   catch (MEDEXCEPTION &ex)
732     {
733       MESSAGE("Unable to acces connectivities");
734       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
735     }
736   catch(MultiCommException &ex2)
737     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
738   return ret;
739 }
740
741 //=======================================================================
742 //function : getSenderForPolyhedronIndex
743 //purpose  : 
744 //=======================================================================
745
746 SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronIndex(SALOME_MED::medConnectivity mode)
747     throw (SALOME::SALOME_Exception)
748 {
749   if (_mesh==NULL)
750     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
751                                  SALOME::INTERNAL_ERROR);
752   SALOME::SenderInt_ptr ret;
753   try
754     {
755       int nbelements = _mesh->getNumberOfPolyhedron() + 1;
756       const int * numbers = _mesh->getPolyhedronIndex( convertIdlConnToMedConn( mode ) );
757       ret=SenderFactory::buildSender(*this,numbers,nbelements);
758     }
759   catch (MEDEXCEPTION &ex)
760     {
761       MESSAGE("Unable to acces connectivities");
762       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
763     }
764   catch(MultiCommException &ex2)
765     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
766   return ret;
767 }
768
769 //=======================================================================
770 //function : getSenderForPolyhedronFacesIndex
771 //purpose  : 
772 //=======================================================================
773
774 SALOME::SenderInt_ptr MESH_i::getSenderForPolyhedronFacesIndex()
775     throw (SALOME::SALOME_Exception)
776 {
777   if (_mesh==NULL)
778     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
779                                  SALOME::INTERNAL_ERROR);
780   SALOME::SenderInt_ptr ret;
781   try
782     {
783       int nbelements = _mesh->getNumberOfPolyhedronFaces() + 1;
784       const int * numbers=_mesh->getPolyhedronFacesIndex();
785       ret=SenderFactory::buildSender(*this,numbers,nbelements);
786     }
787   catch (MEDEXCEPTION &ex)
788     {
789       MESSAGE("Unable to acces connectivities");
790       THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
791     }
792   catch(MultiCommException &ex2)
793     THROW_SALOME_CORBA_EXCEPTION(ex2.what(),SALOME::INTERNAL_ERROR);
794   return ret;
795 }
796
797 //=============================================================================
798 /*!
799  * CORBA: Accessor for connectivities
800  */
801 //=============================================================================
802 SALOME_MED::long_array* MESH_i::getConnectivityIndex(SALOME_MED::medConnectivity mode, 
803                                                   SALOME_MED::medEntityMesh entity) 
804 throw (SALOME::SALOME_Exception)
805 {
806         if (_mesh==NULL)
807                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
808                                              SALOME::INTERNAL_ERROR);
809         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
810         try
811         {
812                 int nbelements = _mesh->getNumberOfElements(
813                                         convertIdlEntToMedEnt(entity),
814                                         MED_ALL_ELEMENTS) + 1;
815                 myseq->length(nbelements);
816                 const int * numbers=_mesh->getConnectivityIndex(convertIdlConnToMedConn(mode),
817                                                           convertIdlEntToMedEnt(entity));
818                 for (int i=0;i<nbelements;i++)
819                 {
820                         myseq[i]=numbers[i];
821                 }
822         }
823         catch (MEDEXCEPTION &ex)
824         {
825                 MESSAGE("Unable to acces connectivities index");
826                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
827         }
828         return myseq._retn();
829 }
830 //=============================================================================
831 /*!
832  * CORBA: Accessor for connectivities
833  */
834 //=============================================================================
835 SALOME_MED::long_array* MESH_i::getGlobalNumberingIndex( SALOME_MED::medEntityMesh entity)
836 throw (SALOME::SALOME_Exception)
837 {
838         if (_mesh==NULL)
839                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
840                                              SALOME::INTERNAL_ERROR);
841         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
842         try
843         {
844                 int nbelements = _mesh->getNumberOfTypes( convertIdlEntToMedEnt(entity)) + 1;
845                 myseq->length(nbelements);
846                 const int * numbers=_mesh->getGlobalNumberingIndex( convertIdlEntToMedEnt(entity));
847                 for (int i=0;i<nbelements;i++)
848                 {
849                         myseq[i]=numbers[i];
850                 }
851         }
852         catch (MEDEXCEPTION &ex)
853         {
854                 MESSAGE("Unable to acces global index");
855                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
856         }
857         return myseq._retn();
858 }
859
860 //=============================================================================
861 /*!
862  * CORBA: get global element number in connectivity array
863  * not implemented for MED_NODE and MED_ALL_ENTITIES,
864  * MED_NONE and MED_ALL_ELEMENTS.
865  */
866 //=============================================================================
867 CORBA::Long MESH_i::getElementNumber(SALOME_MED::medConnectivity mode,
868                                      SALOME_MED::medEntityMesh entity,
869                                      SALOME_MED::medGeometryElement type,
870                                      const SALOME_MED::long_array& connectivity)
871   throw (SALOME::SALOME_Exception)
872 {
873   if (_mesh==NULL)
874     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
875   int numberOfValue = connectivity.length() ;
876   int * myConnectivity = new int[numberOfValue] ;
877   for (int i=0; i<numberOfValue; i++)
878     myConnectivity[i]=connectivity[i] ;
879
880   int result ;
881   try {
882     result = _mesh->getElementNumber(convertIdlConnToMedConn(mode),
883                                      convertIdlEntToMedEnt(entity),
884                                      convertIdlEltToMedElt(type),
885                                      myConnectivity) ;
886   }
887   catch (MEDEXCEPTION &ex) {
888     THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
889   }
890   return result ;
891 }
892 //=============================================================================
893 /*!
894  * CORBA: Accessor for Ascendant connectivities
895  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
896  */
897 //=============================================================================
898 SALOME_MED::long_array* MESH_i::getReverseConnectivity(SALOME_MED::medConnectivity mode)
899 throw (SALOME::SALOME_Exception)
900 {
901         if (_mesh==NULL)
902                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
903                                              SALOME::INTERNAL_ERROR);
904         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
905         try
906         {
907                 int nbelements=_mesh->getReverseConnectivityLength(convertIdlConnToMedConn(mode));
908                 SCRUTE(nbelements);
909                 myseq->length(nbelements);
910                 const int * numbers=_mesh->getReverseConnectivity(convertIdlConnToMedConn(mode));
911                 for (int i=0;i<nbelements;i++)
912                 {
913                         myseq[i]=numbers[i];
914                 }
915         }
916         catch (MEDEXCEPTION &ex)
917         {
918                 MESSAGE("Unable to acces reverse connectivities");
919                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
920         }
921         return myseq._retn();
922 }
923 //=============================================================================
924 /*!
925  * CORBA: Accessor for connectivities
926  */
927 //=============================================================================
928 SALOME_MED::long_array* MESH_i::getReverseConnectivityIndex(SALOME_MED::medConnectivity mode)
929 throw (SALOME::SALOME_Exception)
930 {
931         if (_mesh==NULL)
932                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
933                                              SALOME::INTERNAL_ERROR);
934         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
935         try
936         {
937                 int nbelements=_mesh->getReverseConnectivityIndexLength(convertIdlConnToMedConn(mode));
938                 myseq->length(nbelements);
939                 const int * numbers=_mesh->getReverseConnectivityIndex(convertIdlConnToMedConn(mode));
940                 for (int i=0;i<nbelements;i++)
941                 {
942                         myseq[i]=numbers[i];
943                 }
944         }
945         catch (MEDEXCEPTION &ex)
946         {
947                 MESSAGE("Unable to acces reverse connectivities index");
948                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
949         }
950         return myseq._retn();
951 }
952 //=============================================================================
953 /*!
954  * CORBA: Returns number of families within the mesh
955  */
956 //=============================================================================
957 CORBA::Long MESH_i::getNumberOfFamilies(SALOME_MED::medEntityMesh entity)
958 throw (SALOME::SALOME_Exception)
959 {
960         if (_mesh==NULL)
961                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
962                                              SALOME::INTERNAL_ERROR);
963         try
964         {
965                 return _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
966         }
967         catch (MEDEXCEPTION &ex)
968         {
969                 MESSAGE("Unable to acces number of families of the mesh");
970                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
971         }
972 }
973 //=============================================================================
974 /*!
975  * CORBA: Returns number of groups within the mesh
976  */
977 //=============================================================================
978 CORBA::Long MESH_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity) 
979 throw (SALOME::SALOME_Exception)
980 {
981         if (_mesh==NULL)
982                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
983                                              SALOME::INTERNAL_ERROR);
984         try
985         {
986                 return _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
987         }
988         catch (MEDEXCEPTION &ex)
989         {
990                 MESSAGE("Unable to acces number of groups of the mesh");
991                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
992         }
993 }
994 //=============================================================================
995 /*!
996  * CORBA: Returns references for families within the mesh
997  */
998 //=============================================================================
999 SALOME_MED::Family_array * MESH_i::getFamilies(SALOME_MED::medEntityMesh entity) 
1000 throw (SALOME::SALOME_Exception)
1001 {
1002         if (_mesh==NULL)
1003                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1004                                              SALOME::INTERNAL_ERROR);
1005         SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
1006         try
1007         {
1008                 int nbfam= _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
1009                 myseq->length(nbfam);
1010                 vector<FAMILY*> fam(nbfam);
1011                 fam = _mesh->getFamilies(convertIdlEntToMedEnt(entity));
1012                 for (int i=0;i<nbfam;i++)
1013                 {
1014                         FAMILY_i * f1=new FAMILY_i(fam[i]);
1015                         myseq[i] = f1->_this();
1016                 }
1017         }
1018         catch (MEDEXCEPTION &ex)
1019         {
1020                 MESSAGE("Unable to acces families of the mesh");
1021                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1022         }
1023         return myseq._retn();
1024 }
1025 //=============================================================================
1026 /*!
1027  * CORBA: Returns Coordinates global informations
1028  */
1029 //=============================================================================
1030 SALOME_MED::MESH::coordinateInfos *  MESH_i::getCoordGlobal()
1031 throw (SALOME::SALOME_Exception)
1032 {
1033         if (_mesh==NULL)
1034                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1035                                              SALOME::INTERNAL_ERROR);
1036         SALOME_MED::MESH::coordinateInfos_var all = new SALOME_MED::MESH::coordinateInfos;
1037         try
1038         {
1039                 all->coordSystem = CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
1040
1041                 int spaceDimension=_mesh->getSpaceDimension();
1042                 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
1043                 const string * coordinatesName =_mesh->getCoordinatesNames();
1044
1045                 all->coordUnits.length(spaceDimension);
1046                 all->coordNames.length(spaceDimension);
1047                 for (int i=0; i<spaceDimension; i++)
1048                 {
1049                          all->coordUnits[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
1050                          all->coordNames[i]=CORBA::string_dup(coordinatesName[i].c_str());
1051                 }
1052         }
1053         catch (MEDEXCEPTION &ex)
1054         {
1055                 MESSAGE("Unable to acces coordinate information ");
1056                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1057         }
1058         return all._retn();
1059 }
1060 //=============================================================================
1061 /*!
1062  * CORBA: Returns connectivity global informations
1063  */
1064 //=============================================================================
1065 SALOME_MED::MESH::connectivityInfos * MESH_i::getConnectGlobal (SALOME_MED::medEntityMesh entity)
1066   throw (SALOME::SALOME_Exception)
1067 {
1068   if (_mesh==NULL)
1069     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1070                                  SALOME::INTERNAL_ERROR);
1071   SALOME_MED::MESH::connectivityInfos_var all=new SALOME_MED::MESH::connectivityInfos;
1072   try
1073   {
1074     MED_EN::medEntityMesh anEntity = convertIdlEntToMedEnt(entity);
1075     all->numberOfNodes  = _mesh->getNumberOfNodes();
1076
1077     int nbTypes=_mesh->getNumberOfTypesWithPoly(anEntity);
1078     medGeometryElement * types =_mesh->getTypesWithPoly(anEntity);
1079     all->meshTypes.length(nbTypes);
1080     all->numberOfElements.length(nbTypes);
1081     all->nodalConnectivityLength.length(nbTypes);
1082     all->entityDimension=_mesh->getConnectivityptr()->getEntityDimension();
1083     for (int i=0; i<nbTypes; i++)
1084     {
1085       all->meshTypes[i]=convertMedEltToIdlElt(types[i]);
1086       all->numberOfElements[i]=_mesh->getNumberOfElementsWithPoly(anEntity,types[i]);
1087       switch ( types[i] )
1088       {
1089       case MED_EN::MED_POLYGON:
1090         all->nodalConnectivityLength[i]=
1091           _mesh->getPolygonsConnectivityLength(MED_EN::MED_NODAL,anEntity);
1092         break;
1093       case MED_EN::MED_POLYHEDRA:
1094         all->nodalConnectivityLength[i]=
1095           _mesh->getPolyhedronConnectivityLength(MED_EN::MED_NODAL);
1096         break;
1097       default:
1098         all->nodalConnectivityLength[i]=
1099           _mesh->getConnectivityLength(MED_EN::MED_FULL_INTERLACE,MED_EN::MED_NODAL,
1100                                        anEntity,types[i]);
1101       }
1102     }
1103     delete [] types;
1104   }
1105   catch (MEDEXCEPTION &ex)
1106   {
1107     MESSAGE("Unable to acces connectivities informations");
1108     THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1109   }
1110   return all._retn();
1111 }
1112
1113 //=============================================================================
1114 /*!
1115  * CORBA: Returns references for family i within the mesh
1116  */
1117 //=============================================================================
1118 SALOME_MED::FAMILY_ptr MESH_i::getFamily(SALOME_MED::medEntityMesh entity,
1119                                          CORBA::Long i) 
1120 throw (SALOME::SALOME_Exception)
1121 {
1122         if (_mesh==NULL)
1123                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1124                                              SALOME::INTERNAL_ERROR);
1125         try
1126         {
1127                 const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i);
1128                 FAMILY_i * f1=new FAMILY_i(fam);
1129                 return f1->_this();
1130         }
1131         catch (MEDEXCEPTION &ex)
1132         {
1133                 MESSAGE("Unable to acces specified family of the mesh");
1134                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1135         }
1136
1137 }
1138 //=============================================================================
1139 /*
1140  * CORBA: Returns Mesh global informations
1141  */
1142 //=============================================================================
1143 SALOME_MED::MESH::meshInfos *  MESH_i::getMeshGlobal()
1144 throw (SALOME::SALOME_Exception)
1145 {
1146         if (_mesh==NULL)
1147                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1148                                              SALOME::INTERNAL_ERROR);
1149         SALOME_MED::MESH::meshInfos_var all = new SALOME_MED::MESH::meshInfos;
1150         try
1151         {
1152                 all->name = CORBA::string_dup(_mesh->getName().c_str());
1153                 all->spaceDimension = _mesh->getSpaceDimension();
1154                 all->meshDimension  = _mesh->getMeshDimension();
1155                 all->numberOfNodes  = _mesh->getNumberOfNodes();
1156                 all->isAGrid        = _mesh->getIsAGrid();
1157
1158                 int nbFam= _mesh->getNumberOfFamilies(MED_NODE);
1159                 all->famNode.length(nbFam);
1160                 vector<FAMILY*> vNode (nbFam);
1161                 vNode = _mesh->getFamilies(MED_NODE);
1162                 for (int i=0;i<nbFam;i++)
1163                 {
1164                         FAMILY_i * f1=new FAMILY_i(vNode[i]);
1165                         all->famNode[i] = f1->_this();
1166                 }
1167
1168                 nbFam = _mesh->getNumberOfFamilies(MED_EDGE);
1169                 all->famEdge.length(nbFam);
1170                 vector<FAMILY*> vEdge (nbFam);
1171                 vEdge = _mesh->getFamilies(MED_EDGE);
1172                 for (int i=0;i<nbFam;i++)
1173                 for (int i=0;i<nbFam;i++)
1174                 {
1175                         FAMILY_i * f1=new FAMILY_i(vEdge[i]);
1176                         all->famEdge[i] = f1->_this();
1177                 }
1178
1179                 nbFam = _mesh->getNumberOfFamilies(MED_FACE);
1180                 all->famFace.length(nbFam);
1181                 vector<FAMILY*> vFace (nbFam);
1182                 vFace = _mesh->getFamilies(MED_FACE);
1183                 for (int i=0;i<nbFam;i++)
1184                 {
1185                         FAMILY_i * f1=new FAMILY_i(vFace[i]);
1186                         all->famFace[i] = f1->_this();
1187                 }
1188
1189                 nbFam = _mesh->getNumberOfFamilies(MED_CELL);
1190                 all->famCell.length(nbFam);
1191                 vector<FAMILY*> vCell (nbFam);
1192                 vCell = _mesh->getFamilies(MED_CELL);
1193                 for (int i=0;i<nbFam;i++)
1194                 {
1195                         FAMILY_i * f1=new FAMILY_i(vCell[i]);
1196                         all->famCell[i] = f1->_this();
1197                 }
1198
1199                 int nbGroup = _mesh->getNumberOfGroups(MED_NODE);
1200                 all->groupNode.length(nbGroup);
1201                 vector<GROUP*> gNode (nbGroup);
1202                 gNode = _mesh->getGroups(MED_NODE);
1203                 for (int i=0;i<nbGroup;i++)
1204                 {
1205                         GROUP_i * f1=new GROUP_i(gNode[i]);
1206                         all->groupNode[i] = f1->_this();
1207                 }
1208
1209                 nbGroup = _mesh->getNumberOfGroups(MED_EDGE);
1210                 all->groupEdge.length(nbGroup);
1211                 vector<GROUP*> gEdge (nbGroup);
1212                 gEdge = _mesh->getGroups(MED_EDGE);
1213                 for (int i=0;i<nbGroup;i++)
1214                 {
1215                         GROUP_i * f1=new GROUP_i(gEdge[i]);
1216                         all->groupEdge[i] = f1->_this();
1217                 }
1218                 nbGroup = _mesh->getNumberOfGroups(MED_FACE);
1219                 all->groupFace.length(nbGroup);
1220                 vector<GROUP*> gFace (nbGroup);
1221                 gFace = _mesh->getGroups(MED_FACE);
1222                 for (int i=0;i<nbGroup;i++)
1223                 {
1224                         GROUP_i * f1=new GROUP_i(gFace[i]);
1225                         all->groupFace[i] = f1->_this();
1226                 }
1227
1228                 nbGroup = _mesh->getNumberOfGroups(MED_CELL);
1229                 all->groupCell.length(nbGroup);
1230                 vector<GROUP*> gCell (nbGroup);
1231                 gCell = _mesh->getGroups(MED_CELL);
1232                 for (int i=0;i<nbGroup;i++)
1233                 {
1234                         GROUP_i * f1=new GROUP_i(gCell[i]);
1235                         all->groupCell[i] = f1->_this();
1236                 }
1237
1238         }
1239         catch (MEDEXCEPTION &ex)
1240         {
1241                 MESSAGE("Unable to acces mesh");
1242                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1243         }
1244         return all._retn();
1245 }
1246 //=============================================================================
1247  /*
1248  * CORBA: Returns references for groups within the mesh
1249  */
1250 //=============================================================================
1251 SALOME_MED::Group_array *  MESH_i::getGroups(SALOME_MED::medEntityMesh entity) 
1252 throw (SALOME::SALOME_Exception)
1253 {
1254         if (_mesh==NULL)
1255                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1256                                              SALOME::INTERNAL_ERROR);
1257         SALOME_MED::Group_array_var myseq = new SALOME_MED::Group_array;
1258         try
1259         {
1260                 int nbgroups = _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
1261                 myseq->length(nbgroups);
1262                 vector<GROUP*> groups(nbgroups);
1263                 groups = _mesh->getGroups(convertIdlEntToMedEnt(entity));
1264                 for (int i=0;i<nbgroups;i++)
1265                 {
1266                         GROUP_i * f1=new GROUP_i(groups[i]);
1267                         myseq[i] = f1->_this();
1268                 }
1269         }
1270         catch (MEDEXCEPTION &ex)
1271         {
1272                 MESSAGE("Unable to acces number of groups of the mesh");
1273                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1274         }
1275         return myseq._retn();
1276 }
1277 //=============================================================================
1278 /*!
1279  * CORBA: Returns references for group i within the mesh
1280  */
1281 //=============================================================================
1282 SALOME_MED::GROUP_ptr MESH_i::getGroup(SALOME_MED::medEntityMesh entity,
1283                                        CORBA::Long i) 
1284 throw (SALOME::SALOME_Exception)
1285 {
1286         if (_mesh==NULL)
1287                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1288                                               SALOME::INTERNAL_ERROR);
1289         try
1290         {
1291                 const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i);
1292                 GROUP_i * f1=new GROUP_i(grou);
1293                 return f1->_this();
1294         }
1295         catch (MEDEXCEPTION &ex)
1296         {
1297                 MESSAGE("Unable to acces specified group of the mesh");
1298                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1299         }
1300 }
1301 //=============================================================================
1302 /*!
1303  * CORBA:
1304  */
1305 //=============================================================================
1306 SALOME_MED::SUPPORT_ptr MESH_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
1307 throw (SALOME::SALOME_Exception)
1308 {
1309         if (_mesh==NULL)
1310                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1311                                               SALOME::INTERNAL_ERROR);
1312         try
1313         {
1314                 SUPPORT * myNewSupport = _mesh->getBoundaryElements(convertIdlEntToMedEnt(entity));
1315                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
1316                 return mySupportI->_this();
1317         }
1318         catch (MEDEXCEPTION &ex)
1319         {
1320                 MESSAGE("Unable to get the volume ");
1321                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1322         }
1323 }
1324
1325 //=============================================================================
1326 /*!
1327  * CORBA:
1328  */
1329 //=============================================================================
1330 SALOME_MED::SUPPORT_ptr MESH_i::getSupportOnAll(SALOME_MED::medEntityMesh entity)
1331 throw (SALOME::SALOME_Exception)
1332 {
1333         if (_mesh==NULL)
1334                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1335                                               SALOME::INTERNAL_ERROR);
1336         try
1337         {
1338                 SUPPORT * myNewSupport = _mesh->getSupportOnAll(convertIdlEntToMedEnt(entity));
1339                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
1340                 return mySupportI->_this();
1341         }
1342         catch (MEDEXCEPTION &ex)
1343         {
1344                 MESSAGE("Unable to get the support ");
1345                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1346         }
1347 }
1348 //=============================================================================
1349 /*!
1350  * CORBA: 
1351  */
1352 //=============================================================================
1353 SALOME_MED::FIELD_ptr MESH_i::getVolume(SALOME_MED::SUPPORT_ptr mySupport)
1354 throw (SALOME::SALOME_Exception)
1355 {
1356         if (_mesh==NULL)
1357                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1358                                               SALOME::INTERNAL_ERROR); try
1359         {
1360                 int sup = mySupport->getCorbaIndex();
1361                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1362                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1363                 ::FIELD<double>*f=_mesh->getVolume( myCppSupport);
1364                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
1365                 return medf->_this();
1366         }
1367         catch (MEDEXCEPTION &ex)
1368         {
1369                 MESSAGE("Unable to get the volume ");
1370                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1371         }
1372 }
1373 //=============================================================================
1374 /*!
1375  * CORBA:
1376  */
1377 //=============================================================================
1378 SALOME_MED::SUPPORT_ptr MESH_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
1379 throw (SALOME::SALOME_Exception)
1380 {
1381         if (_mesh==NULL)
1382                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1383                                               SALOME::INTERNAL_ERROR);
1384         try
1385         {
1386                 int sup = mySupport3D->getCorbaIndex();
1387                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1388                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1389                 SUPPORT * myNewSupport = _mesh->getSkin(myCppSupport);
1390                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
1391                 return mySupportI->_this() ;
1392         }
1393         catch (MEDEXCEPTION &ex)
1394         {
1395                 MESSAGE("Unable to get the volume ");
1396                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1397         }
1398 }
1399 //=============================================================================
1400 /*!
1401  * CORBA: 
1402  */
1403 //=============================================================================
1404 SALOME_MED::FIELD_ptr MESH_i::getArea(SALOME_MED::SUPPORT_ptr mySupport)
1405 throw (SALOME::SALOME_Exception)
1406 {
1407         if (_mesh==NULL)
1408                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1409                                               SALOME::INTERNAL_ERROR);
1410         try
1411         {
1412                 int sup = mySupport->getCorbaIndex();
1413                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1414                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1415                 ::FIELD<double>*f=_mesh->getArea( myCppSupport);
1416                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
1417                 return medf->_this();
1418         }
1419         catch (MEDEXCEPTION &ex)
1420         {
1421                 MESSAGE("Unable to get the area ");
1422                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1423         }
1424 }
1425 //=============================================================================
1426 /*!
1427  * CORBA: 
1428  */
1429 //=============================================================================
1430 SALOME_MED::FIELD_ptr MESH_i::getLength(SALOME_MED::SUPPORT_ptr mySupport)
1431 throw (SALOME::SALOME_Exception)
1432 {
1433         if (_mesh==NULL)
1434                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1435                                               SALOME::INTERNAL_ERROR);
1436         try
1437         {
1438                 int sup = mySupport->getCorbaIndex();
1439                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1440                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1441                 ::FIELD<double>*f=_mesh->getLength( myCppSupport);
1442                 FIELDTEMPLATE_I<double>  *medf = new FIELDTEMPLATE_I<double>(f);
1443                 return medf->_this();
1444         }
1445         catch (MEDEXCEPTION &ex)
1446         {
1447                 MESSAGE("Unable to get the length ");
1448                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1449         }
1450 }
1451 //=============================================================================
1452 /*!
1453  * CORBA: 
1454  */
1455 //=============================================================================
1456 SALOME_MED::FIELD_ptr MESH_i::getNormal(SALOME_MED::SUPPORT_ptr mySupport)
1457 throw (SALOME::SALOME_Exception)
1458 {
1459         if (_mesh==NULL)
1460                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1461                                               SALOME::INTERNAL_ERROR);
1462         try
1463         {
1464                 int sup = mySupport->getCorbaIndex();
1465                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1466                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1467                 ::FIELD<double>*f=_mesh->getNormal( myCppSupport);
1468                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
1469                 return medf->_this();
1470         }
1471         catch (MEDEXCEPTION &ex)
1472         {
1473                 MESSAGE("Unable to get the normal ");
1474                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1475         }
1476 }
1477 //=============================================================================
1478 /*!
1479  * CORBA: 
1480  */
1481 //=============================================================================
1482 SALOME_MED::FIELD_ptr MESH_i::getBarycenter(SALOME_MED::SUPPORT_ptr mySupport)
1483 throw (SALOME::SALOME_Exception)
1484 {
1485         if (_mesh==NULL)
1486                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1487                                               SALOME::INTERNAL_ERROR);
1488         try
1489         {
1490                 int sup = mySupport->getCorbaIndex();
1491                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1492                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1493                 ::FIELD<double>*f=_mesh->getBarycenter( myCppSupport);
1494                 FIELDTEMPLATE_I<double> *medf = new FIELDTEMPLATE_I<double>(f);
1495                 return medf->_this();
1496         }
1497         catch (MEDEXCEPTION &ex)
1498         {
1499                 MESSAGE("Unable to get the barycenter ");
1500                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1501         }
1502 }
1503 //=============================================================================
1504 /*!
1505  * CORBA: 
1506  */
1507 //=============================================================================
1508 SALOME_MED::FIELD_ptr MESH_i::getNeighbourhood(SALOME_MED::SUPPORT_ptr mySupport)
1509 throw (SALOME::SALOME_Exception)
1510 {
1511         if (_mesh==NULL)
1512                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1513                                               SALOME::INTERNAL_ERROR);
1514         MESSAGE("Not Implemented");
1515         return SALOME_MED::FIELD::_nil();
1516 }
1517 //=============================================================================
1518 /*!
1519  * CORBA: add the Mesh in the StudyManager 
1520  */
1521 //=============================================================================
1522 void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor )
1523 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1524 {
1525   const char* LOC = "MED_Mesh_i::addInStudy";
1526   BEGIN_OF(LOC);
1527         if ( _meshId != "" )
1528         {
1529                 MESSAGE("Mesh already in Study");
1530                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1531                                  SALOME::BAD_PARAM);
1532         };
1533
1534         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1535         SALOMEDS::GenericAttribute_var anAttr;
1536         SALOMEDS::AttributeName_var    aName;
1537         SALOMEDS::AttributeIOR_var     aIOR;
1538
1539         // Find SComponent labelled 'MED'
1540         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1541         myBuilder->NewCommand();
1542         if ( CORBA::is_nil(medfather) ) 
1543           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1544
1545         // Create SObject labelled 'MESH' if it doesn't already exit
1546 //      SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1547 //      if ( CORBA::is_nil(medmeshfather) ) 
1548 //      {
1549 //              MESSAGE("Add Object MEDMESH");
1550 //              medmeshfather = myBuilder->NewObject(medfather);
1551 //              //medmeshfather.Name = "MEDMESH" ;
1552 //                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1553 //                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1554 //                 aName->SetValue("MEDMESH");
1555
1556 //      } ;
1557
1558         string aPath = "/Med/MEDMESH";
1559         SALOMEDS::SObject_var medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
1560         if ( CORBA::is_nil(medmeshfather) ) 
1561           {
1562             MESSAGE("Add Object MEDMESH");
1563
1564             myBuilder->AddDirectory( aPath.c_str() );
1565             medmeshfather = myStudy->FindObjectByPath( aPath.c_str() );
1566           } ;
1567
1568         aPath += "/" + _mesh->getName();
1569         SALOMEDS::SObject_var meshSO = myStudy->FindObjectByPath( aPath.c_str());
1570         bool alreadyPublished = ! CORBA::is_nil( meshSO );
1571         if ( !alreadyPublished ) {
1572           MESSAGE("Add a mesh Object under MED/MEDMESH");
1573           meshSO = myBuilder->NewObject(medmeshfather);
1574
1575           anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeName");
1576           aName = SALOMEDS::AttributeName::_narrow(anAttr);
1577           aName->SetValue(_mesh->getName().c_str());
1578         }
1579
1580         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1581         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1582         CORBA::ORB_var &orb = init(0,0);
1583         string iorStr = orb->object_to_string(myIor);
1584         anAttr = myBuilder->FindOrCreateAttribute(meshSO, "AttributeIOR");
1585         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1586         aIOR->SetValue(iorStr.c_str());
1587         _meshId = meshSO->GetID();
1588         myBuilder->CommitCommand();
1589
1590         // register the Corba pointer: increase the referrence count
1591         MESSAGE("Registering of the Corba Mesh pointer");
1592         Register();
1593
1594   END_OF(LOC);
1595 }
1596 //=============================================================================
1597 /*!
1598  * CORBA: add the Mesh in the StudyManager
1599  */
1600 //=============================================================================
1601 void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor,const string & fileName )
1602 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1603 {
1604   const char* LOC = "MED_Mesh_i::addInStudy";
1605   BEGIN_OF(LOC);
1606         if ( _meshId != "" )
1607         {
1608                 MESSAGE("Mesh already in Study");
1609                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1610                                  SALOME::BAD_PARAM);
1611         };
1612
1613         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1614         SALOMEDS::GenericAttribute_var anAttr;
1615         SALOMEDS::AttributeName_var    aName;
1616         SALOMEDS::AttributeIOR_var     aIOR;
1617         SALOMEDS::AttributeComment_var aComment;
1618
1619         // Find SComponent labelled 'Med'
1620         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1621         if ( CORBA::is_nil(medfather) )
1622           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1623
1624         // Create SObject labelled 'MESH' if it doesn't already exit
1625         SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1626         if ( CORBA::is_nil(medmeshfather) )
1627         {
1628                 MESSAGE("Add Object MEDMESH");
1629                 medmeshfather = myBuilder->NewObject(medfather);
1630                 //medmeshfather.Name = "MEDMESH" ;
1631                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1632                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1633                 aName->SetValue("MEDMESH");
1634
1635         } ;
1636
1637         MESSAGE("Add a mesh Object under MED/MEDMESH");
1638         myBuilder->NewCommand();
1639         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
1640
1641         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1642         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1643         CORBA::ORB_var &orb = init(0,0);
1644         CORBA::String_var iorStr = orb->object_to_string(myIor);
1645         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1646         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1647         aIOR->SetValue(iorStr.in());
1648         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1649         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1650         aName->SetValue(_mesh->getName().c_str());
1651         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
1652         aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
1653         aComment->SetValue(fileName.c_str());
1654         _meshId = newObj->GetID();
1655         myBuilder->CommitCommand();
1656
1657         // register the Corba pointer: increase the referrence count
1658         MESSAGE("Registering of the Corba Mesh pointer");
1659         Register();
1660
1661   END_OF(LOC);
1662 }
1663 //=============================================================================
1664
1665 //=============================================================================
1666 /*!
1667  * CORBA: write mesh in a med file
1668  */
1669 //=============================================================================
1670 void MESH_i::write(CORBA::Long i, const char* driverMeshName)        
1671 throw (SALOME::SALOME_Exception)
1672 {
1673         if (_mesh==NULL)
1674                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1675                                              SALOME::INTERNAL_ERROR);
1676         try
1677         {
1678                 _mesh->write(i,driverMeshName);
1679         }
1680         catch (MEDEXCEPTION &ex)
1681         {
1682                 MESSAGE("Unable to write the mesh ");
1683                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1684         }
1685 }
1686 //=============================================================================
1687 /*!
1688  * CORBA: read mesh in a med file
1689  */
1690 //=============================================================================
1691 void MESH_i::read(CORBA::Long i)             
1692 throw (SALOME::SALOME_Exception)
1693 {
1694         if (_mesh==NULL)
1695                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1696                                              SALOME::INTERNAL_ERROR);
1697         try
1698         {
1699                 _mesh->read(i);
1700         }
1701         catch (MEDEXCEPTION &ex)
1702         {
1703                 MESSAGE("Unable to read the mesh ");
1704                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1705         }
1706 }
1707 //=============================================================================
1708 /*!
1709  * CORBA : release driver
1710  */
1711 //=============================================================================
1712 void MESH_i::rmDriver(CORBA::Long i)         
1713 throw (SALOME::SALOME_Exception)
1714 {
1715         if (_mesh==NULL)
1716                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1717                                              SALOME::INTERNAL_ERROR);
1718         try
1719         {
1720                 _mesh->rmDriver();
1721         }
1722         catch (MEDEXCEPTION &ex)
1723         {
1724                 MESSAGE("Unable to unlink the mesh from the driver ");
1725                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1726                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
1727                                                 ,SALOME::INTERNAL_ERROR);
1728         }
1729 }
1730 //=============================================================================
1731 /*!
1732  * CORBA : attach driver
1733  */
1734 //=============================================================================
1735 CORBA::Long MESH_i::addDriver(SALOME_MED::medDriverTypes driverType, 
1736                               const char* fileName, const char* meshName)
1737 throw (SALOME::SALOME_Exception)
1738 {
1739         if (_mesh==NULL)
1740                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1741                                              SALOME::INTERNAL_ERROR);
1742         try
1743         {
1744                 int drivernum=_mesh->addDriver(
1745                                         convertIdlDriverToMedDriver(driverType),
1746                                         fileName,
1747                                         meshName);
1748                 return drivernum;
1749         }
1750         catch (MEDEXCEPTION &ex)
1751         {
1752                 MESSAGE("Unable to link the mesh to the driver ");
1753                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1754         }
1755 }
1756
1757 //=============================================================================
1758 /*!
1759  * CORBA : Test if this and other aggregate the same MESH using the MESH::operator==
1760  */
1761 //=============================================================================
1762 CORBA::Boolean MESH_i::areEquals(SALOME_MED::MESH_ptr other)
1763 {
1764   PortableServer::ServantBase *baseServ;
1765   try {
1766     baseServ=_default_POA()->reference_to_servant(other);
1767   }
1768   catch(...){
1769     baseServ=0;
1770   }
1771   if(baseServ)
1772     {
1773      baseServ->_remove_ref();
1774      MESH_i *otherServ=dynamic_cast<MESH_i *>(baseServ);
1775      return *_mesh==*otherServ->_mesh;
1776     }
1777   return false;
1778 }