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