Salome HOME
Merging with the MAN_SALOME2 branch
[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 = tab[elt1 ] - 1 ;
520                 }
521 SCRUTE(entity);
522 SCRUTE(geomElement);
523 SCRUTE(nbelements);
524                 myseq->length(nbelements);
525                 const int * numbers=_mesh->getConnectivity(convertIdlModeToMedMode(typeSwitch),
526                                                      convertIdlConnToMedConn(mode),
527                                                      convertIdlEntToMedEnt(entity),
528                                                      convertIdlEltToMedElt(geomElement));
529                 for (int i=0;i<nbelements;i++)
530                 {
531                         myseq[i]=numbers[i];
532                 }
533         }
534         catch (MEDEXCEPTION &ex)
535         {
536                 MESSAGE("Unable to acces connectivities");
537                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
538         }
539         return myseq._retn();
540 }
541 //=============================================================================
542 /*!
543  * CORBA: Accessor for connectivities
544  */
545 //=============================================================================
546 SALOME_MED::long_array* MESH_i::getConnectivityIndex(SALOME_MED::medConnectivity mode, 
547                                                   SALOME_MED::medEntityMesh entity) 
548 throw (SALOME::SALOME_Exception)
549 {
550         if (_mesh==NULL)
551                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
552                                              SALOME::INTERNAL_ERROR);
553         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
554         try
555         {
556                 int nbelements = _mesh->getNumberOfElements(
557                                         convertIdlEntToMedEnt(entity),
558                                         MED_ALL_ELEMENTS);
559                 myseq->length(nbelements);
560                 const int * numbers=_mesh->getConnectivityIndex(convertIdlConnToMedConn(mode),
561                                                           convertIdlEntToMedEnt(entity));
562                 for (int i=0;i<nbelements;i++)
563                 {
564                         myseq[i]=numbers[i];
565                 }
566         }
567         catch (MEDEXCEPTION &ex)
568         {
569                 MESSAGE("Unable to acces connectivities index");
570                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
571         }
572         return myseq._retn();
573 }
574 //=============================================================================
575 /*!
576  * CORBA: Accessor for connectivities
577  */
578 //=============================================================================
579 SALOME_MED::long_array* MESH_i::getGlobalNumberingIndex( SALOME_MED::medEntityMesh entity)
580 throw (SALOME::SALOME_Exception)
581 {
582         if (_mesh==NULL)
583                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
584                                              SALOME::INTERNAL_ERROR);
585         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
586         try
587         {
588                 int nbelements = _mesh->getNumberOfTypes( convertIdlEntToMedEnt(entity)) + 1;
589                 myseq->length(nbelements);
590                 const int * numbers=_mesh->getGlobalNumberingIndex( convertIdlEntToMedEnt(entity));
591                 for (int i=0;i<nbelements;i++)
592                 {
593                         myseq[i]=numbers[i];
594                 }
595         }
596         catch (MEDEXCEPTION &ex)
597         {
598                 MESSAGE("Unable to acces global index");
599                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
600         }
601         return myseq._retn();
602 }
603
604 //=============================================================================
605 /*!
606  * CORBA: get global element number in connectivity array
607  * not implemented for MED_NODE and MED_ALL_ENTITIES,
608  * MED_NONE and MED_ALL_ELEMENTS.
609  */
610 //=============================================================================
611 CORBA::Long MESH_i::getElementNumber(SALOME_MED::medConnectivity mode,
612                                      SALOME_MED::medEntityMesh entity,
613                                      SALOME_MED::medGeometryElement type,
614                                      const SALOME_MED::long_array& connectivity)
615   throw (SALOME::SALOME_Exception)
616 {
617   if (_mesh==NULL)
618     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", SALOME::INTERNAL_ERROR);
619   int numberOfValue = connectivity.length() ;
620   int * myConnectivity = new int[numberOfValue] ;
621   for (int i=0; i<numberOfValue; i++)
622     myConnectivity[i]=connectivity[i] ;
623
624   int result ;
625   try {
626     result = _mesh->getElementNumber(convertIdlConnToMedConn(mode),
627                                      convertIdlEntToMedEnt(entity),
628                                      convertIdlEltToMedElt(type),
629                                      myConnectivity) ;
630   }
631   catch (MEDEXCEPTION &ex) {
632     THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
633   }
634   return result ;
635 }
636 //=============================================================================
637 /*!
638  * CORBA: Accessor for Ascendant connectivities
639  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
640  */
641 //=============================================================================
642 SALOME_MED::long_array* MESH_i::getReverseConnectivity(SALOME_MED::medConnectivity mode)
643 throw (SALOME::SALOME_Exception)
644 {
645         if (_mesh==NULL)
646                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
647                                              SALOME::INTERNAL_ERROR);
648         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
649         try
650         {
651                 int nbelements; 
652                 if ( mode == SALOME_MED::MED_DESCENDING)
653                 {
654                    nbelements =(_mesh->getNumberOfNodes())+1;
655                 }
656                 else
657                 {
658                    nbelements = _mesh->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS);
659                 }
660                 SCRUTE(nbelements);
661                 myseq->length(nbelements);
662                 const int * numbers=_mesh->getReverseConnectivity(convertIdlConnToMedConn(mode));
663                 for (int i=0;i<nbelements;i++)
664                 {
665                         myseq[i]=numbers[i];
666                 }
667         }
668         catch (MEDEXCEPTION &ex)
669         {
670                 MESSAGE("Unable to acces reverse connectivities");
671                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
672         }
673         return myseq._retn();
674 }
675 //=============================================================================
676 /*!
677  * CORBA: Accessor for connectivities
678  */
679 //=============================================================================
680 SALOME_MED::long_array* MESH_i::getReverseConnectivityIndex(SALOME_MED::medConnectivity mode)
681 throw (SALOME::SALOME_Exception)
682 {
683         if (_mesh==NULL)
684                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
685                                              SALOME::INTERNAL_ERROR);
686         SALOME_MED::long_array_var myseq= new SALOME_MED::long_array;
687         try
688         {
689                 int nbelements; 
690                 if ( mode == SALOME_MED::MED_DESCENDING)
691                 {
692                    nbelements =_mesh->getNumberOfNodes();
693                 }
694                 else
695                 {
696                    int dim=_mesh->getMeshDimension();
697                    if ( dim == 3)       
698                         nbelements = _mesh->getNumberOfElements(MED_FACE,MED_ALL_ELEMENTS);
699                    else
700                    if (dim == 2)        
701                         nbelements = _mesh->getNumberOfElements(MED_EDGE,MED_ALL_ELEMENTS);
702                    else
703                         THROW_SALOME_CORBA_EXCEPTION("Pb ", \
704                                              SALOME::INTERNAL_ERROR);
705                 }
706
707                 myseq->length(nbelements);
708                 const int * numbers=_mesh->getReverseConnectivityIndex(convertIdlConnToMedConn(mode));
709                 for (int i=0;i<nbelements;i++)
710                 {
711                         myseq[i]=numbers[i];
712                 }
713         }
714         catch (MEDEXCEPTION &ex)
715         {
716                 MESSAGE("Unable to acces reverse connectivities index");
717                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
718         }
719         return myseq._retn();
720 }
721 //=============================================================================
722 /*!
723  * CORBA: Returns number of families within the mesh
724  */
725 //=============================================================================
726 CORBA::Long MESH_i::getNumberOfFamilies(SALOME_MED::medEntityMesh entity)
727 throw (SALOME::SALOME_Exception)
728 {
729         if (_mesh==NULL)
730                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
731                                              SALOME::INTERNAL_ERROR);
732         try
733         {
734                 return _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
735         }
736         catch (MEDEXCEPTION &ex)
737         {
738                 MESSAGE("Unable to acces number of families of the mesh");
739                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
740         }
741 }
742 //=============================================================================
743 /*!
744  * CORBA: Returns number of groups within the mesh
745  */
746 //=============================================================================
747 CORBA::Long MESH_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity) 
748 throw (SALOME::SALOME_Exception)
749 {
750         if (_mesh==NULL)
751                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
752                                              SALOME::INTERNAL_ERROR);
753         try
754         {
755                 return _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
756         }
757         catch (MEDEXCEPTION &ex)
758         {
759                 MESSAGE("Unable to acces number of groups of the mesh");
760                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
761         }
762 }
763 //=============================================================================
764 /*!
765  * CORBA: Returns references for families within the mesh
766  */
767 //=============================================================================
768 SALOME_MED::Family_array * MESH_i::getFamilies(SALOME_MED::medEntityMesh entity) 
769 throw (SALOME::SALOME_Exception)
770 {
771         if (_mesh==NULL)
772                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
773                                              SALOME::INTERNAL_ERROR);
774         SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
775         try
776         {
777                 int nbfam= _mesh->getNumberOfFamilies(convertIdlEntToMedEnt(entity));
778                 myseq->length(nbfam);
779                 vector<FAMILY*> fam(nbfam);
780                 fam = _mesh->getFamilies(convertIdlEntToMedEnt(entity));
781                 for (int i=0;i<nbfam;i++)
782                 {
783                         FAMILY_i * f1=new FAMILY_i(fam[i]);
784                         SALOME_MED::FAMILY_ptr f2 =
785                                         f1->POA_SALOME_MED::FAMILY::_this();
786                         f1->_remove_ref();
787                         myseq[i] = f2;
788                 }
789         }
790         catch (MEDEXCEPTION &ex)
791         {
792                 MESSAGE("Unable to acces families of the mesh");
793                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
794         }
795         return myseq._retn();
796 }
797 //=============================================================================
798 /*!
799  * CORBA: Returns Coordinates global informations
800  */
801 //=============================================================================
802 SALOME_MED::MESH::coordinateInfos *  MESH_i::getCoordGlobal()
803 throw (SALOME::SALOME_Exception)
804 {
805         if (_mesh==NULL)
806                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
807                                              SALOME::INTERNAL_ERROR);
808         SALOME_MED::MESH::coordinateInfos_var all = new SALOME_MED::MESH::coordinateInfos;
809         try
810         {
811                 all->coordSystem = CORBA::string_dup(_mesh->getCoordinatesSystem().c_str());
812
813                 int spaceDimension=_mesh->getSpaceDimension();
814                 const string * coordinatesUnits =_mesh->getCoordinatesUnits();
815                 const string * coordinatesName =_mesh->getCoordinatesNames();
816
817                 all->coordUnits.length(spaceDimension);
818                 all->coordNames.length(spaceDimension);
819                 for (int i=0; i<spaceDimension; i++)
820                 {
821                          all->coordUnits[i]=CORBA::string_dup(coordinatesUnits[i].c_str());
822                          all->coordNames[i]=CORBA::string_dup(coordinatesName[i].c_str());
823                 }
824         }
825         catch (MEDEXCEPTION &ex)
826         {
827                 MESSAGE("Unable to acces coordinate information ");
828                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
829         }
830         return all._retn();
831 }
832 //=============================================================================
833 /*!
834  * CORBA: Returns connectivity global informations
835  */
836 //=============================================================================
837 SALOME_MED::MESH::connectivityInfos * MESH_i::getConnectGlobal
838                         (SALOME_MED::medEntityMesh entity)
839 throw (SALOME::SALOME_Exception)
840 {
841         if (_mesh==NULL)
842                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
843                                              SALOME::INTERNAL_ERROR);
844         SALOME_MED::MESH::connectivityInfos_var all=new SALOME_MED::MESH::connectivityInfos;
845         try
846         {
847                 all->numberOfNodes  = _mesh->getNumberOfNodes();
848
849                 int nbTypes=_mesh->getNumberOfTypes(convertIdlEntToMedEnt(entity));
850                 const medGeometryElement * elemts  =_mesh->getTypes(
851                                        convertIdlEntToMedEnt(entity));
852                 all->meshTypes.length(nbTypes);
853                 all->numberOfElements.length(nbTypes);
854                 for (int i=0; i<nbTypes; i++)
855                 {
856                         all->meshTypes[i]=convertMedEltToIdlElt(elemts[i]);
857                         all->numberOfElements[i]=_mesh->getNumberOfElements(
858                                        convertIdlEntToMedEnt(entity),elemts[i]);
859                 }
860         }
861         catch (MEDEXCEPTION &ex)
862         {
863                 MESSAGE("Unable to acces connectivities informations");
864                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
865         }
866         return all._retn();
867 }
868
869 //=============================================================================
870 /*!
871  * CORBA: Returns references for family i within the mesh
872  */
873 //=============================================================================
874 SALOME_MED::FAMILY_ptr MESH_i::getFamily(SALOME_MED::medEntityMesh entity,
875                                          CORBA::Long i) 
876 throw (SALOME::SALOME_Exception)
877 {
878         if (_mesh==NULL)
879                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
880                                              SALOME::INTERNAL_ERROR);
881         try
882         {
883                 const FAMILY * fam = _mesh->getFamily(convertIdlEntToMedEnt(entity),i);
884                 FAMILY_i * f1=new FAMILY_i(fam);
885                 SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
886                 f1->_remove_ref();
887                 return (SALOME_MED::FAMILY::_duplicate(f2));
888         }
889         catch (MEDEXCEPTION &ex)
890         {
891                 MESSAGE("Unable to acces specified family of the mesh");
892                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
893         }
894
895 }
896 //=============================================================================
897 /*
898  * CORBA: Returns Mesh global informations
899  */
900 //=============================================================================
901 SALOME_MED::MESH::meshInfos *  MESH_i::getMeshGlobal()
902 throw (SALOME::SALOME_Exception)
903 {
904         if (_mesh==NULL)
905                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
906                                              SALOME::INTERNAL_ERROR);
907         SALOME_MED::MESH::meshInfos_var all = new SALOME_MED::MESH::meshInfos;
908         try
909         {
910                 all->name = CORBA::string_dup(_mesh->getName().c_str());
911                 all->spaceDimension = _mesh->getSpaceDimension();
912                 all->meshDimension  = _mesh->getMeshDimension();
913                 all->numberOfNodes  = _mesh->getNumberOfNodes();
914                 all->isAGrid        = _mesh->getIsAGrid();
915
916                 int nbFam= _mesh->getNumberOfFamilies(MED_NODE);
917                 all->famNode.length(nbFam);
918                 vector<FAMILY*> vNode (nbFam);
919                 vNode = _mesh->getFamilies(MED_NODE);
920                 for (int i=0;i<nbFam;i++)
921                 {
922                         FAMILY_i * f1=new FAMILY_i(vNode[i]);
923                         SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
924                         f1->_remove_ref();
925                         all->famNode[i] = f2;
926                 }
927
928                 nbFam = _mesh->getNumberOfFamilies(MED_EDGE);
929                 all->famEdge.length(nbFam);
930                 vector<FAMILY*> vEdge (nbFam);
931                 vEdge = _mesh->getFamilies(MED_EDGE);
932                 for (int i=0;i<nbFam;i++)
933                 for (int i=0;i<nbFam;i++)
934                 {
935                         FAMILY_i * f1=new FAMILY_i(vEdge[i]);
936                         SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
937                         f1->_remove_ref();
938                         all->famEdge[i] = f2;
939                 }
940
941                 nbFam = _mesh->getNumberOfFamilies(MED_FACE);
942                 all->famFace.length(nbFam);
943                 vector<FAMILY*> vFace (nbFam);
944                 vFace = _mesh->getFamilies(MED_FACE);
945                 for (int i=0;i<nbFam;i++)
946                 {
947                         FAMILY_i * f1=new FAMILY_i(vFace[i]);
948                         SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
949                         f1->_remove_ref();
950                         all->famFace[i] = f2;
951                 }
952
953                 nbFam = _mesh->getNumberOfFamilies(MED_CELL);
954                 all->famCell.length(nbFam);
955                 vector<FAMILY*> vCell (nbFam);
956                 vCell = _mesh->getFamilies(MED_CELL);
957                 for (int i=0;i<nbFam;i++)
958                 {
959                         FAMILY_i * f1=new FAMILY_i(vCell[i]);
960                         SALOME_MED::FAMILY_ptr f2 = f1->POA_SALOME_MED::FAMILY::_this();
961                         f1->_remove_ref();
962                         all->famCell[i] = f2;
963                 }
964
965                 int nbGroup = _mesh->getNumberOfGroups(MED_NODE);
966                 all->groupNode.length(nbGroup);
967                 vector<GROUP*> gNode (nbGroup);
968                 gNode = _mesh->getGroups(MED_NODE);
969                 for (int i=0;i<nbGroup;i++)
970                 {
971                         GROUP_i * f1=new GROUP_i(gNode[i]);
972                         SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
973                         f1->_remove_ref();
974                         all->groupNode[i] = f2;
975                 }
976
977                 nbGroup = _mesh->getNumberOfGroups(MED_EDGE);
978                 all->groupEdge.length(nbGroup);
979                 vector<GROUP*> gEdge (nbGroup);
980                 gEdge = _mesh->getGroups(MED_EDGE);
981                 for (int i=0;i<nbGroup;i++)
982                 {
983                         GROUP_i * f1=new GROUP_i(gEdge[i]);
984                         SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
985                         f1->_remove_ref();
986                         all->groupEdge[i] = f2;
987                 }
988                 nbGroup = _mesh->getNumberOfGroups(MED_FACE);
989                 all->groupFace.length(nbGroup);
990                 vector<GROUP*> gFace (nbGroup);
991                 gFace = _mesh->getGroups(MED_FACE);
992                 for (int i=0;i<nbGroup;i++)
993                 {
994                         GROUP_i * f1=new GROUP_i(gFace[i]);
995                         SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
996                         f1->_remove_ref();
997                         all->groupFace[i] = f2;
998                 }
999
1000                 nbGroup = _mesh->getNumberOfGroups(MED_CELL);
1001                 all->groupCell.length(nbGroup);
1002                 vector<GROUP*> gCell (nbGroup);
1003                 gCell = _mesh->getGroups(MED_CELL);
1004                 for (int i=0;i<nbGroup;i++)
1005                 {
1006                         GROUP_i * f1=new GROUP_i(gCell[i]);
1007                         SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
1008                         f1->_remove_ref();
1009                         all->groupCell[i] = f2;
1010                 }
1011
1012         }
1013         catch (MEDEXCEPTION &ex)
1014         {
1015                 MESSAGE("Unable to acces mesh");
1016                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1017         }
1018         return all._retn();
1019 }
1020 //=============================================================================
1021  /*
1022  * CORBA: Returns references for groups within the mesh
1023  */
1024 //=============================================================================
1025 SALOME_MED::Group_array *  MESH_i::getGroups(SALOME_MED::medEntityMesh entity) 
1026 throw (SALOME::SALOME_Exception)
1027 {
1028         if (_mesh==NULL)
1029                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1030                                              SALOME::INTERNAL_ERROR);
1031         SALOME_MED::Group_array_var myseq = new SALOME_MED::Group_array;
1032         try
1033         {
1034                 int nbgroups = _mesh->getNumberOfGroups(convertIdlEntToMedEnt(entity));
1035                 myseq->length(nbgroups);
1036                 vector<GROUP*> groups(nbgroups);
1037                 groups = _mesh->getGroups(convertIdlEntToMedEnt(entity));
1038                 for (int i=0;i<nbgroups;i++)
1039                 {
1040                         GROUP_i * f1=new GROUP_i(groups[i]);
1041                         SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
1042                         f1->_remove_ref();
1043                         myseq[i] = f2;
1044                 }
1045         }
1046         catch (MEDEXCEPTION &ex)
1047         {
1048                 MESSAGE("Unable to acces number of groups of the mesh");
1049                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1050         }
1051         return myseq._retn();
1052 }
1053 //=============================================================================
1054 /*!
1055  * CORBA: Returns references for group i within the mesh
1056  */
1057 //=============================================================================
1058 SALOME_MED::GROUP_ptr MESH_i::getGroup(SALOME_MED::medEntityMesh entity,
1059                                        CORBA::Long i) 
1060 throw (SALOME::SALOME_Exception)
1061 {
1062         if (_mesh==NULL)
1063                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1064                                               SALOME::INTERNAL_ERROR);
1065         try
1066         {
1067                 const GROUP * grou = _mesh->getGroup(convertIdlEntToMedEnt(entity),i);
1068                 GROUP_i * f1=new GROUP_i(grou);
1069                 SALOME_MED::GROUP_ptr f2 = f1->POA_SALOME_MED::GROUP::_this();
1070                 f1->_remove_ref();
1071                 return (SALOME_MED::GROUP::_duplicate(f2));
1072         }
1073         catch (MEDEXCEPTION &ex)
1074         {
1075                 MESSAGE("Unable to acces specified group of the mesh");
1076                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1077         }
1078 }
1079 //=============================================================================
1080 /*!
1081  * CORBA:
1082  */
1083 //=============================================================================
1084 SALOME_MED::SUPPORT_ptr MESH_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
1085 throw (SALOME::SALOME_Exception)
1086 {
1087         if (_mesh==NULL)
1088                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1089                                               SALOME::INTERNAL_ERROR);
1090         try
1091         {
1092                 SUPPORT * myNewSupport = _mesh->getBoundaryElements(convertIdlEntToMedEnt(entity));
1093                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
1094                 SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this() ;
1095                 return (SALOME_MED::SUPPORT::_duplicate(mySupportIOR));
1096         }
1097         catch (MEDEXCEPTION &ex)
1098         {
1099                 MESSAGE("Unable to get the volume ");
1100                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1101         }
1102 }
1103 //=============================================================================
1104 /*!
1105  * CORBA: 
1106  */
1107 //=============================================================================
1108 SALOME_MED::FIELD_ptr MESH_i::getVolume(SALOME_MED::SUPPORT_ptr mySupport)
1109 throw (SALOME::SALOME_Exception)
1110 {
1111         if (_mesh==NULL)
1112                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1113                                               SALOME::INTERNAL_ERROR); try
1114         {
1115                 int sup = mySupport->getCorbaIndex();
1116                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1117                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1118                 ::FIELD<double>*f=_mesh->getVolume( myCppSupport);
1119                 FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
1120                 POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
1121                     new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
1122                 SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
1123                 f1->_remove_ref();
1124                 return (SALOME_MED::FIELD::_duplicate(f2));
1125         }
1126         catch (MEDEXCEPTION &ex)
1127         {
1128                 MESSAGE("Unable to get the volume ");
1129                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1130         }
1131 }
1132 //=============================================================================
1133 /*!
1134  * CORBA:
1135  */
1136 //=============================================================================
1137 SALOME_MED::SUPPORT_ptr MESH_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
1138 throw (SALOME::SALOME_Exception)
1139 {
1140         if (_mesh==NULL)
1141                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1142                                               SALOME::INTERNAL_ERROR);
1143         try
1144         {
1145                 int sup = mySupport3D->getCorbaIndex();
1146                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1147                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1148                 SUPPORT * myNewSupport = _mesh->getSkin(myCppSupport);
1149                 SUPPORT_i * mySupportI = new SUPPORT_i(myNewSupport);
1150                 SALOME_MED::SUPPORT_ptr mySupportIOR = mySupportI->_this() ;
1151                 return (SALOME_MED::SUPPORT::_duplicate(mySupportIOR));
1152         }
1153         catch (MEDEXCEPTION &ex)
1154         {
1155                 MESSAGE("Unable to get the volume ");
1156                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1157         }
1158 }
1159 //=============================================================================
1160 /*!
1161  * CORBA: 
1162  */
1163 //=============================================================================
1164 SALOME_MED::FIELD_ptr MESH_i::getArea(SALOME_MED::SUPPORT_ptr mySupport)
1165 throw (SALOME::SALOME_Exception)
1166 {
1167         if (_mesh==NULL)
1168                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1169                                               SALOME::INTERNAL_ERROR);
1170         try
1171         {
1172                 int sup = mySupport->getCorbaIndex();
1173                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1174                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1175                 ::FIELD<double>*f=_mesh->getArea( myCppSupport);
1176                 FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
1177                 POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
1178                     new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
1179                 SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
1180                 f1->_remove_ref();
1181                 return (SALOME_MED::FIELD::_duplicate(f2));
1182         }
1183         catch (MEDEXCEPTION &ex)
1184         {
1185                 MESSAGE("Unable to get the area ");
1186                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1187         }
1188 }
1189 //=============================================================================
1190 /*!
1191  * CORBA: 
1192  */
1193 //=============================================================================
1194 SALOME_MED::FIELD_ptr MESH_i::getLength(SALOME_MED::SUPPORT_ptr mySupport)
1195 throw (SALOME::SALOME_Exception)
1196 {
1197         if (_mesh==NULL)
1198                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1199                                               SALOME::INTERNAL_ERROR);
1200         try
1201         {
1202                 int sup = mySupport->getCorbaIndex();
1203                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1204                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1205                 ::FIELD<double>*f=_mesh->getLength( myCppSupport);
1206                 FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
1207                 POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
1208                     new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
1209                 SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
1210                 f1->_remove_ref();
1211                 return (SALOME_MED::FIELD::_duplicate(f2));
1212         }
1213         catch (MEDEXCEPTION &ex)
1214         {
1215                 MESSAGE("Unable to get the length ");
1216                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1217         }
1218 }
1219 //=============================================================================
1220 /*!
1221  * CORBA: 
1222  */
1223 //=============================================================================
1224 SALOME_MED::FIELD_ptr MESH_i::getNormal(SALOME_MED::SUPPORT_ptr mySupport)
1225 throw (SALOME::SALOME_Exception)
1226 {
1227         if (_mesh==NULL)
1228                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1229                                               SALOME::INTERNAL_ERROR);
1230         try
1231         {
1232                 int sup = mySupport->getCorbaIndex();
1233                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1234                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1235                 ::FIELD<double>*f=_mesh->getNormal( myCppSupport);
1236                 FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
1237                 POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
1238                     new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
1239                 SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
1240                 f1->_remove_ref();
1241                 return (SALOME_MED::FIELD::_duplicate(f2));
1242         }
1243         catch (MEDEXCEPTION &ex)
1244         {
1245                 MESSAGE("Unable to get the normal ");
1246                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1247         }
1248 }
1249 //=============================================================================
1250 /*!
1251  * CORBA: 
1252  */
1253 //=============================================================================
1254 SALOME_MED::FIELD_ptr MESH_i::getBarycenter(SALOME_MED::SUPPORT_ptr mySupport)
1255 throw (SALOME::SALOME_Exception)
1256 {
1257         if (_mesh==NULL)
1258                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1259                                               SALOME::INTERNAL_ERROR);
1260         try
1261         {
1262                 int sup = mySupport->getCorbaIndex();
1263                 ASSERT(SUPPORT_i::supportMap.find(sup)!=SUPPORT_i::supportMap.end());
1264                 const SUPPORT * myCppSupport=SUPPORT_i::supportMap[sup];
1265                 ::FIELD<double>*f=_mesh->getBarycenter( myCppSupport);
1266                 FIELDDOUBLE_i * medf = new FIELDDOUBLE_i(mySupport,f);
1267                 POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i> * f1 = 
1268                     new POA_SALOME_MED::FIELDDOUBLE_tie<FIELDDOUBLE_i>(medf,true);
1269                 SALOME_MED::FIELDDOUBLE_ptr f2 = f1->_this();
1270                 f1->_remove_ref();
1271                 return (SALOME_MED::FIELD::_duplicate(f2));
1272         }
1273         catch (MEDEXCEPTION &ex)
1274         {
1275                 MESSAGE("Unable to get the barycenter ");
1276                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1277         }
1278 }
1279 //=============================================================================
1280 /*!
1281  * CORBA: 
1282  */
1283 //=============================================================================
1284 SALOME_MED::FIELD_ptr MESH_i::getNeighbourhood(SALOME_MED::SUPPORT_ptr mySupport)
1285 throw (SALOME::SALOME_Exception)
1286 {
1287         if (_mesh==NULL)
1288                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1289                                               SALOME::INTERNAL_ERROR);
1290         MESSAGE("Not Implemented");
1291 }
1292 //=============================================================================
1293 /*!
1294  * CORBA: add the Mesh in the StudyManager 
1295  */
1296 //=============================================================================
1297 void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor )
1298 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1299 {
1300         BEGIN_OF("MED_Mesh_i::addInStudy");
1301         if ( _meshId != "" )
1302         {
1303                 MESSAGE("Mesh already in Study");
1304                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1305                                  SALOME::BAD_PARAM);
1306         };
1307
1308         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1309         SALOMEDS::GenericAttribute_var anAttr;
1310         SALOMEDS::AttributeName_var    aName;
1311         SALOMEDS::AttributeIOR_var     aIOR;
1312
1313         // Find SComponent labelled 'MED'
1314         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1315         myBuilder->NewCommand();
1316         if ( CORBA::is_nil(medfather) ) 
1317           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1318
1319         // Create SObject labelled 'MESH' if it doesn't already exit
1320         SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1321         if ( CORBA::is_nil(medmeshfather) ) 
1322         {
1323                 MESSAGE("Add Object MEDMESH");
1324                 medmeshfather = myBuilder->NewObject(medfather);
1325                 //medmeshfather.Name = "MEDMESH" ;
1326                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1327                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1328                 aName->SetValue("MEDMESH");
1329
1330         } ;
1331
1332         MESSAGE("Add a mesh Object under MED/MEDMESH");
1333         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
1334
1335         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1336         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1337         CORBA::ORB_var &orb = init(0,0);
1338         string iorStr = orb->object_to_string(myIor);
1339         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1340         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1341         aIOR->SetValue(iorStr.c_str());
1342         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1343         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1344         aName->SetValue(_mesh->getName().c_str());
1345         _meshId = newObj->GetID();
1346         myBuilder->CommitCommand();
1347
1348         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
1349 }
1350 //=============================================================================
1351 /*!
1352  * CORBA: add the Mesh in the StudyManager
1353  */
1354 //=============================================================================
1355 void MESH_i::addInStudy(SALOMEDS::Study_ptr myStudy,SALOME_MED::MESH_ptr myIor,const string & fileName )
1356 throw (SALOME::SALOME_Exception,SALOMEDS::StudyBuilder::LockProtection)
1357 {
1358         BEGIN_OF("MED_Mesh_i::addInStudy");
1359         if ( _meshId != "" )
1360         {
1361                 MESSAGE("Mesh already in Study");
1362                     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study", \
1363                                  SALOME::BAD_PARAM);
1364         };
1365
1366         SALOMEDS::StudyBuilder_var     myBuilder = myStudy->NewBuilder();
1367         SALOMEDS::GenericAttribute_var anAttr;
1368         SALOMEDS::AttributeName_var    aName;
1369         SALOMEDS::AttributeIOR_var     aIOR;
1370         SALOMEDS::AttributeComment_var aComment;
1371
1372         // Find SComponent labelled 'Med'
1373         SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
1374         if ( CORBA::is_nil(medfather) )
1375           THROW_SALOME_CORBA_EXCEPTION("SComponent labelled 'Med' not Found",SALOME::INTERNAL_ERROR);
1376
1377         // Create SObject labelled 'MESH' if it doesn't already exit
1378         SALOMEDS::SObject_var medmeshfather = myStudy->FindObject("MEDMESH");
1379         if ( CORBA::is_nil(medmeshfather) )
1380         {
1381                 MESSAGE("Add Object MEDMESH");
1382                 medmeshfather = myBuilder->NewObject(medfather);
1383                 //medmeshfather.Name = "MEDMESH" ;
1384                 anAttr = myBuilder->FindOrCreateAttribute(medmeshfather, "AttributeName");
1385                 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1386                 aName->SetValue("MEDMESH");
1387
1388         } ;
1389
1390         MESSAGE("Add a mesh Object under MED/MEDMESH");
1391         myBuilder->NewCommand();
1392         SALOMEDS::SObject_var newObj = myBuilder->NewObject(medmeshfather);
1393
1394         ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
1395         ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
1396         CORBA::ORB_var &orb = init(0,0);
1397         string iorStr = orb->object_to_string(myIor);
1398         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR");
1399         aIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1400         aIOR->SetValue(iorStr.c_str());
1401         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeName");
1402         aName = SALOMEDS::AttributeName::_narrow(anAttr);
1403         aName->SetValue(_mesh->getName().c_str());
1404         anAttr = myBuilder->FindOrCreateAttribute(newObj, "AttributeComment");
1405         aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
1406         aComment->SetValue(fileName.c_str());
1407         _meshId = newObj->GetID();
1408         myBuilder->CommitCommand();
1409
1410         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
1411 }
1412 //=============================================================================
1413
1414 //=============================================================================
1415 /*!
1416  * CORBA: write mesh in a med file
1417  */
1418 //=============================================================================
1419 void MESH_i::write(CORBA::Long i, const char* driverMeshName)        
1420 throw (SALOME::SALOME_Exception)
1421 {
1422         if (_mesh==NULL)
1423                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1424                                              SALOME::INTERNAL_ERROR);
1425         try
1426         {
1427                 _mesh->write(i,driverMeshName);
1428         }
1429         catch (MEDEXCEPTION &ex)
1430         {
1431                 MESSAGE("Unable to write the mesh ");
1432                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1433         }
1434 }
1435 //=============================================================================
1436 /*!
1437  * CORBA: read mesh in a med file
1438  */
1439 //=============================================================================
1440 void MESH_i::read(CORBA::Long i)             
1441 throw (SALOME::SALOME_Exception)
1442 {
1443         if (_mesh==NULL)
1444                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1445                                              SALOME::INTERNAL_ERROR);
1446         try
1447         {
1448                 _mesh->read(i);
1449         }
1450         catch (MEDEXCEPTION &ex)
1451         {
1452                 MESSAGE("Unable to read the mesh ");
1453                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1454         }
1455 }
1456 //=============================================================================
1457 /*!
1458  * CORBA : release driver
1459  */
1460 //=============================================================================
1461 void MESH_i::rmDriver(CORBA::Long i)         
1462 throw (SALOME::SALOME_Exception)
1463 {
1464         if (_mesh==NULL)
1465                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1466                                              SALOME::INTERNAL_ERROR);
1467         try
1468         {
1469                 _mesh->rmDriver();
1470         }
1471         catch (MEDEXCEPTION &ex)
1472         {
1473                 MESSAGE("Unable to unlink the mesh from the driver ");
1474                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1475                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Support C++ Object"\
1476                                                 ,SALOME::INTERNAL_ERROR);
1477         }
1478 }
1479 //=============================================================================
1480 /*!
1481  * CORBA : attach driver
1482  */
1483 //=============================================================================
1484 CORBA::Long MESH_i::addDriver(SALOME_MED::medDriverTypes driverType, 
1485                               const char* fileName, const char* meshName)
1486 throw (SALOME::SALOME_Exception)
1487 {
1488         if (_mesh==NULL)
1489                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh", \
1490                                              SALOME::INTERNAL_ERROR);
1491         try
1492         {
1493                 int drivernum=_mesh->addDriver(
1494                                         convertIdlDriverToMedDriver(driverType),
1495                                         fileName,
1496                                         meshName);
1497                 return drivernum;
1498         }
1499         catch (MEDEXCEPTION &ex)
1500         {
1501                 MESSAGE("Unable to link the mesh to the driver ");
1502                 THROW_SALOME_CORBA_EXCEPTION(ex.what(), SALOME::INTERNAL_ERROR);
1503         }
1504 }
1505