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