Salome HOME
Merge from V5_1_main 14/05/2010
[modules/smesh.git] / src / SMESH_I / SMESH_MEDMesh_i.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 //  File   : SMESH_MEDMesh_i.cxx
25 //  Module : SMESH
26 //
27 #include "SMESH_MEDMesh_i.hxx"
28 #include "SMESH_Gen_i.hxx"
29 #include "SMESH_Mesh_i.hxx"
30
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESHDS_SubMesh.hxx"
33
34 #include <TopExp.hxx>
35 #include <TopExp_Explorer.hxx>
36 #include <TopoDS.hxx>
37 #include <TopoDS_Iterator.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include <TopoDS_CompSolid.hxx>
40 #include <TopoDS_Solid.hxx>
41 #include <TopoDS_Shell.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <TopoDS_Edge.hxx>
45 #include <TopoDS_Vertex.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopTools_MapOfShape.hxx>
48
49 #include "utilities.h"
50 #include "Utils_CorbaException.hxx"
51
52 #include "SMESH_MEDSupport_i.hxx"
53 #include "SMESH_MEDFamily_i.hxx"
54
55 # include "Utils_ORB_INIT.hxx"
56 # include "Utils_SINGLETON.hxx"
57 # include "Utils_ExceptHandlers.hxx"
58
59 extern "C"
60 {
61 #include <stdio.h>
62 }
63
64 using namespace std;
65
66 //=============================================================================
67 /*!
68  * Default constructor
69  */
70 //=============================================================================
71 // PN Est-ce un const ?
72 SMESH_MEDMesh_i::SMESH_MEDMesh_i()
73 {
74   BEGIN_OF("Default Constructor SMESH_MEDMesh_i");
75   END_OF("Default Constructor SMESH_MEDMesh_i");
76 }
77
78 //=============================================================================
79 /*!
80  * Destructor
81  */
82 //=============================================================================
83 SMESH_MEDMesh_i::~SMESH_MEDMesh_i()
84 {
85 }
86
87 //=============================================================================
88 /*!
89  * Constructor
90  */
91 //=============================================================================
92 SMESH_MEDMesh_i::SMESH_MEDMesh_i(::SMESH_Mesh_i * m_i):_meshId(""),
93                                                        _compte(false),
94                                                        _creeFamily(false),
95                                                        _famIdent(0),
96                                                        _indexElts(0),
97                                                        _indexEnts(0)
98 {
99   BEGIN_OF("Constructor SMESH_MEDMesh_i");
100
101   _mesh_i = m_i;
102   _meshDS = _mesh_i->GetImpl().GetMeshDS();
103
104   END_OF("Constructor SMESH_MEDMesh_i");
105 }
106
107 //=============================================================================
108 /*!
109  * CORBA: Accessor for Name
110  */
111 //=============================================================================
112 char *SMESH_MEDMesh_i::getName() throw(SALOME::SALOME_Exception)
113 {
114   if (_meshDS == NULL)
115     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
116                                  SALOME::INTERNAL_ERROR);
117
118   try
119   {
120     SMESH_Gen_i*             gen = SMESH_Gen_i::GetSMESHGen();
121     SALOMEDS::Study_var    study = gen->GetCurrentStudy();
122     SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, _mesh_i->_this());
123     if ( meshSO->_is_nil() )
124       return CORBA::string_dup("toto");
125
126     CORBA::String_var name = meshSO->GetName();
127     return CORBA::string_dup( name.in() );
128   }
129   catch(...)
130   {
131     MESSAGE("Exception en accedant au nom");
132     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
133                                  SALOME::INTERNAL_ERROR);
134   }
135   return 0;
136 }
137
138 //=============================================================================
139 /*!
140  * CORBA: Accessor for corbaindex cuisine interne 
141  */
142 //=============================================================================
143 CORBA::Long SMESH_MEDMesh_i::getCorbaIndex()throw(SALOME::SALOME_Exception)
144 {
145   MESSAGE("Non Implemente");
146   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
147 }
148
149 //=============================================================================
150 /*!
151  * CORBA: Accessor for Space Dimension
152  */
153 //=============================================================================
154 CORBA::Long SMESH_MEDMesh_i::getSpaceDimension()throw(SALOME::SALOME_Exception)
155 {
156   // PN : Il semblerait que la dimension soit fixee a 3
157   if (_mesh_i == 0)
158     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
159                                  SALOME::INTERNAL_ERROR);
160   return 3;
161 }
162
163 //=============================================================================
164 /*!
165  * CORBA: Accessor for Mesh Dimension
166  */
167 //=============================================================================
168 CORBA::Long SMESH_MEDMesh_i::getMeshDimension()throw(SALOME::SALOME_Exception)
169 {
170   if (_mesh_i == 0)
171     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
172                                  SALOME::INTERNAL_ERROR);
173   // PN : Il semblerait que la dimension soit fixee a 3
174   if (_mesh_i == 0)
175     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
176                                  SALOME::INTERNAL_ERROR);
177   return 3;
178 }
179 //=============================================================================
180 /*!
181  * CORBA: Accessor for the boolean _isAGrid
182  */
183 //=============================================================================
184 CORBA::Boolean SMESH_MEDMesh_i::getIsAGrid() throw (SALOME::SALOME_Exception)
185 {
186   MESSAGE("!!!!!! NOT YET IMPLEMENTED !!!!!!");
187
188   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
189
190   return false;
191 }
192 //=============================================================================
193 /*!
194  * CORBA: Accessor for the connectivities, to see if they exist
195  */
196 //=============================================================================
197 CORBA::Boolean
198 SMESH_MEDMesh_i::existConnectivity(SALOME_MED::medConnectivity connectivityType,
199                                    SALOME_MED::medEntityMesh entity)
200   throw (SALOME::SALOME_Exception)
201 {
202   MESSAGE("!!!!!! IMPLEMENTED BUT ONLY PARTIALLY !!!!!!");
203
204
205   return false;
206
207 }
208 //=============================================================================
209 /*!
210  * CORBA: Accessor for Coordinate
211  */
212 //=============================================================================
213 CORBA::Double SMESH_MEDMesh_i::getCoordinate(CORBA::Long Number, CORBA::Long Axis)
214   throw (SALOME::SALOME_Exception)
215 {
216   MESSAGE("!!!!!! NOT YET IMPLEMENTED !!!!");
217
218   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
219
220   return 0.0;
221 }
222 //=============================================================================
223 /*!
224  * CORBA: Accessor for Coordinates System
225  */
226 //=============================================================================
227 char *SMESH_MEDMesh_i::getCoordinatesSystem() throw(SALOME::SALOME_Exception)
228 {
229   if (_mesh_i == 0)
230     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
231                                  SALOME::INTERNAL_ERROR);
232   // PN : En dur. Non encore prevu
233   try
234   {
235     string systcoo = "CARTESIEN";
236     return CORBA::string_dup(systcoo.c_str());
237   }
238   catch(...)
239   {
240     MESSAGE("Exception en accedant au maillage");
241     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
242                                  SALOME::INTERNAL_ERROR);
243   }
244 }
245
246 //=============================================================================
247 /*!
248  * CORBA: Accessor for Coordinates
249  */
250 //=============================================================================
251 SALOME_MED::double_array * SMESH_MEDMesh_i::getCoordinates
252 (SALOME_MED::medModeSwitch typeSwitch) throw(SALOME::SALOME_Exception)
253 {
254   if (_mesh_i == 0)
255     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
256                                  SALOME::INTERNAL_ERROR);
257   SALOME_MED::double_array_var myseq = new SALOME_MED::double_array;
258   try
259   {
260     // PN  : En dur
261     int spaceDimension = 3;
262     int nbNodes = _meshDS->NbNodes();
263     SCRUTE(nbNodes);
264     myseq->length(nbNodes * spaceDimension);
265     int i = 0;
266
267     SMDS_NodeIteratorPtr itNodes=_meshDS->nodesIterator();
268     while(itNodes->more())
269     {
270       const SMDS_MeshNode* node = itNodes->next();
271
272       if (typeSwitch == SALOME_MED::MED_FULL_INTERLACE)
273       {
274         myseq[i * 3] = node->X();
275         myseq[i * 3 + 1] = node->Y();
276         myseq[i * 3 + 2] = node->Z();
277         SCRUTE(myseq[i * 3]);
278         SCRUTE(myseq[i * 3 + 1]);
279         SCRUTE(myseq[i * 3 + 2]);
280       }
281       else
282       {
283         ASSERT(typeSwitch == SALOME_MED::MED_NO_INTERLACE);
284         myseq[i] = node->X();
285         myseq[i + nbNodes] = node->Y();
286         myseq[i + (nbNodes * 2)] = node->Z();
287         SCRUTE(myseq[i]);
288         SCRUTE(myseq[i + nbNodes]);
289         SCRUTE(myseq[i + (nbNodes * 2)]);
290       }
291       i++;
292     }
293   }
294   catch(...)
295   {
296     MESSAGE("Exception en accedant aux coordonnees");
297     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
298                                  SALOME::INTERNAL_ERROR);
299   }
300   return myseq._retn();
301 }
302
303 //=============================================================================
304 /*!
305  * CORBA: Accessor for Coordinates Names
306  */
307 //=============================================================================
308 SALOME_MED::string_array *
309 SMESH_MEDMesh_i::getCoordinatesNames()throw(SALOME::SALOME_Exception)
310 {
311   if (_mesh_i == 0)
312     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
313                                  SALOME::INTERNAL_ERROR);
314   SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
315   try
316   {
317     // PN : en dur
318     int spaceDimension = 3;
319     myseq->length(spaceDimension);
320     myseq[0] = CORBA::string_dup("x");
321     myseq[1] = CORBA::string_dup("y");
322     myseq[2] = CORBA::string_dup("z");
323   }
324   catch(...)
325   {
326     MESSAGE("Exception en accedant aux noms des coordonnees");
327     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
328                                  SALOME::INTERNAL_ERROR);
329   }
330   return myseq._retn();
331
332 }
333
334 //=============================================================================
335 /*!
336  * CORBA: Accessor for Coordinates Units
337  */
338 //=============================================================================
339 SALOME_MED::string_array *
340 SMESH_MEDMesh_i::getCoordinatesUnits()throw(SALOME::SALOME_Exception)
341 {
342   if (_mesh_i == 0)
343     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
344                                  SALOME::INTERNAL_ERROR);
345   SALOME_MED::string_array_var myseq = new SALOME_MED::string_array;
346   try
347   {
348     // PN : en dur
349     int spaceDimension = 3;
350     myseq->length(spaceDimension);
351     myseq[0] = CORBA::string_dup("m");
352     myseq[1] = CORBA::string_dup("m");
353     myseq[2] = CORBA::string_dup("m");
354   }
355   catch(...)
356   {
357     MESSAGE("Exception en accedant aux unites des coordonnees");
358     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
359                                  SALOME::INTERNAL_ERROR);
360   }
361   return myseq._retn();
362 }
363
364 //=============================================================================
365 /*!
366  * CORBA: Accessor for Number of Nodes
367  */
368 //=============================================================================
369 CORBA::Long SMESH_MEDMesh_i::getNumberOfNodes()throw(SALOME::SALOME_Exception)
370 {
371   if (_mesh_i == 0)
372     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
373                                  SALOME::INTERNAL_ERROR);
374   try
375   {
376     return _meshDS->NbNodes();
377   }
378   catch(...)
379   {
380     MESSAGE("Exception en accedant au nombre de noeuds");
381     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
382                                  SALOME::INTERNAL_ERROR);
383   }
384 }
385
386 //=============================================================================
387 /*!
388  * CORBA: Accessor for number of Types
389  */
390 //=============================================================================
391 CORBA::Long SMESH_MEDMesh_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity)
392   throw(SALOME::SALOME_Exception)
393 {
394   if (_mesh_i == 0)
395     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
396                                  SALOME::INTERNAL_ERROR);
397   try
398   {
399     if (!_compte)
400       calculeNbElts();
401     int retour = 0;
402     if (_mapNbTypes.find(entity) != _mapNbTypes.end())
403       retour = _mapNbTypes[entity];
404     return retour;
405   }
406   catch(...)
407   {
408     MESSAGE("Exception en accedant au nombre de Types");
409     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
410                                  SALOME::INTERNAL_ERROR);
411   }
412 }
413
414 //=============================================================================
415 /*!
416  * CORBA: Accessor for existing geometry element types 
417  *        Not implemented for MED_ALL_ENTITIES
418  */
419 //=============================================================================
420 SALOME_MED::medGeometryElement_array *
421 SMESH_MEDMesh_i::getTypes(SALOME_MED::medEntityMesh entity) throw(SALOME::
422                                                                   SALOME_Exception)
423 {
424   if (_mesh_i == 0)
425     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
426                                  SALOME::INTERNAL_ERROR);
427   if (entity == SALOME_MED::MED_ALL_ENTITIES)
428     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",
429                                  SALOME::BAD_PARAM);
430   if (!_compte)
431     calculeNbElts();
432   SALOME_MED::medGeometryElement_array_var myseq =
433     new SALOME_MED::medGeometryElement_array;
434   try
435   {
436     if (_mapNbTypes.find(entity) == _mapNbTypes.end())
437       THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
438                                    SALOME::BAD_PARAM);
439     int nbTypes = _mapNbTypes[entity];
440
441     myseq->length(nbTypes);
442
443     if (_mapIndToVectTypes.find(entity) == _mapIndToVectTypes.end())
444       THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
445                                    SALOME::INTERNAL_ERROR);
446
447     int index = _mapIndToVectTypes[entity];
448     ASSERT(_TypesId[index].size() != 0);
449     int i = 0;
450     vector < SALOME_MED::medGeometryElement >::iterator it;
451     for (it = _TypesId[index].begin(); it != _TypesId[index].end(); it++)
452     {
453       myseq[i++] = *it;
454     };
455   }
456   catch(...)
457   {
458     MESSAGE("Exception en accedant aux differents types");
459     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
460                                  SALOME::INTERNAL_ERROR);
461   }
462   return myseq._retn();
463 }
464
465 //=============================================================================
466 /*!
467  * CORBA: Returns number of elements of type medGeometryElement
468  *        Not implemented for MED_ALL_ELEMENTS 
469  *        implemented for MED_ALL_ENTITIES
470  *
471  * Dans cette implementation, il n est pas prevu de tenir compte du entity
472  * qui ne doit pas pouvoir avoir deux valeurs differentes pour un geomElement 
473  */
474 //=============================================================================
475 CORBA::Long SMESH_MEDMesh_i::getNumberOfElements(SALOME_MED::
476                                                  medEntityMesh entity,
477                                                  SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
478 {
479   if (_mesh_i == 0)
480     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
481                                  SALOME::INTERNAL_ERROR);
482   if (geomElement == SALOME_MED::MED_ALL_ELEMENTS)
483     THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ELEMENTS",
484                                  SALOME::BAD_PARAM);
485   if (!_compte)
486     calculeNbElts();
487
488   try
489   {
490     int retour = 0;
491     if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
492     {
493       int index = _mapIndToSeqElts[geomElement];
494
495       retour = _seq_elemId[index]->length();
496     }
497     return retour;
498   }
499   catch(...)
500   {
501     MESSAGE("Exception en accedant au nombre d élements");
502     THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
503                                  SALOME::INTERNAL_ERROR);
504   }
505 }
506
507 //=============================================================================
508 /*!
509  * CORBA: Accessor for connectivities
510  */
511 //=============================================================================
512 SALOME_MED::long_array *
513 SMESH_MEDMesh_i::getConnectivity(SALOME_MED::medModeSwitch typeSwitch,
514                                  SALOME_MED::medConnectivity mode,
515                                  SALOME_MED::medEntityMesh entity,
516                                  SALOME_MED::medGeometryElement geomElement)
517   throw(SALOME::SALOME_Exception)
518 {
519   if (_mesh_i == 0)
520     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
521                                  SALOME::INTERNAL_ERROR);
522   if (mode != SALOME_MED::MED_NODAL)
523     THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
524   if (typeSwitch == SALOME_MED::MED_NO_INTERLACE)
525     THROW_SALOME_CORBA_EXCEPTION("Not Yet Implemented", SALOME::BAD_PARAM);
526   if (!_compte)
527     calculeNbElts();
528
529   // Faut-il renvoyer un pointeur vide ???
530   if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
531     THROW_SALOME_CORBA_EXCEPTION("No Such Element in the mesh",
532                                  SALOME::BAD_PARAM);
533
534   int index = _mapIndToSeqElts[geomElement];
535
536   return _seq_elemId[index]._retn();
537 }
538
539 //=============================================================================
540 /*!
541  * CORBA: Accessor for connectivities
542  */
543 //=============================================================================
544 SALOME_MED::long_array *
545 SMESH_MEDMesh_i::getConnectivityIndex(SALOME_MED::medConnectivity mode,
546                                       SALOME_MED::medEntityMesh entity)
547   throw(SALOME::SALOME_Exception)
548 {
549   MESSAGE("Pas Implemente dans SMESH");
550   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
551   return 0;
552 }
553
554 //=============================================================================
555 /*!
556  * CORBA: Find an element corresponding to the given connectivity
557  */
558 //=============================================================================
559 CORBA::Long
560 SMESH_MEDMesh_i::getElementNumber(SALOME_MED::medConnectivity mode,
561                                   SALOME_MED::medEntityMesh entity,
562                                   SALOME_MED::medGeometryElement type,
563                                   const SALOME_MED::long_array & connectivity)
564   throw(SALOME::SALOME_Exception)
565 {
566   const char *LOC = "getElementNumber ";
567   MESSAGE(LOC << "Pas Implemente dans SMESH");
568   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
569   return -1;
570 }
571
572 //=============================================================================
573 /*!
574  * CORBA: Accessor for Ascendant connectivities
575  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
576  */
577 //=============================================================================
578 SALOME_MED::long_array *
579 SMESH_MEDMesh_i::getReverseConnectivity(SALOME_MED::
580                                         medConnectivity mode) throw(SALOME::SALOME_Exception)
581 {
582   MESSAGE("Pas Implemente dans SMESH");
583   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
584   return 0;
585 }
586
587 //=============================================================================
588 /*!
589  * CORBA: Accessor for connectivities
590  */
591 //=============================================================================
592 SALOME_MED::long_array *
593 SMESH_MEDMesh_i::getReverseConnectivityIndex(SALOME_MED::
594                                              medConnectivity mode) throw(SALOME::SALOME_Exception)
595 {
596   MESSAGE("Pas Implemente dans SMESH");
597   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
598   return 0;
599 }
600
601 //=============================================================================
602 /*!
603  * CORBA: Returns number of families within the mesh
604  */
605 //=============================================================================
606 CORBA::Long SMESH_MEDMesh_i::getNumberOfFamilies(SALOME_MED::
607                                                  medEntityMesh entity) throw(SALOME::SALOME_Exception)
608 {
609   if (_creeFamily == false)
610     createFamilies();
611   if (_mesh_i == 0)
612     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
613                                  SALOME::INTERNAL_ERROR);
614   return _families.size();
615 }
616
617 //=============================================================================
618 /*!
619  * CORBA: Returns number of groups within the mesh
620  */
621 //=============================================================================
622 CORBA::Long SMESH_MEDMesh_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity)
623   throw(SALOME::SALOME_Exception)
624 {
625   if (_mesh_i == 0)
626     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
627                                  SALOME::INTERNAL_ERROR);
628   MESSAGE(" Pas d implementation des groupes dans SMESH");
629   return 0;
630 }
631
632 //=============================================================================
633 /*!
634  * CORBA: Returns references for families within the mesh
635  */
636 //=============================================================================
637 SALOME_MED::Family_array *
638 SMESH_MEDMesh_i::getFamilies(SALOME_MED::
639                              medEntityMesh entity) throw(SALOME::SALOME_Exception)
640 {
641   if (_creeFamily == false)
642     createFamilies();
643   if (_mesh_i == 0)
644     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
645                                  SALOME::INTERNAL_ERROR);
646   SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
647   int nbfam = _families.size();
648   myseq->length(nbfam);
649   int i = 0;
650   vector < SALOME_MED::FAMILY_ptr >::iterator it;
651   for (it = _families.begin(); it != _families.end(); it++)
652   {
653     myseq[i++] = *it;
654   };
655   return myseq._retn();
656 }
657
658 //=============================================================================
659 /*!
660  * CORBA: Returns references for family i within the mesh
661  */
662 //=============================================================================
663 SALOME_MED::FAMILY_ptr SMESH_MEDMesh_i::getFamily(SALOME_MED::
664                                                   medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
665 {
666   if (_creeFamily == false)
667     createFamilies();
668   if (_mesh_i == 0)
669     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
670                                  SALOME::INTERNAL_ERROR);
671
672   SCRUTE(_families[i]->getName());
673   MESSAGE(" SMESH_MEDMesh_i::getFamily " << i) return _families[i];
674 }
675
676 //=============================================================================
677 /*!
678  * CORBA: Returns references for groups within the mesh
679  */
680 //=============================================================================
681 SALOME_MED::Group_array *
682 SMESH_MEDMesh_i::getGroups(SALOME_MED::medEntityMesh entity) throw(SALOME::
683                                                                    SALOME_Exception)
684 {
685   if (_mesh_i == 0)
686     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
687                                  SALOME::INTERNAL_ERROR);
688   MESSAGE(" Pas d implementation des groupes dans SMESH");
689   THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
690 }
691
692 //=============================================================================
693 /*!
694  * CORBA: Returns references for group i within the mesh
695  */
696 //=============================================================================
697 SALOME_MED::GROUP_ptr SMESH_MEDMesh_i::getGroup(SALOME_MED::
698                                                 medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
699 {
700   if (_mesh_i == 0)
701     THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
702                                  SALOME::INTERNAL_ERROR);
703   MESSAGE(" Pas d implementation des groupes dans SMESH");
704   THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
705 }
706 //=============================================================================
707 /*!
708  * CORBA: Returns references for the global numbering index
709  */
710 //=============================================================================
711 SALOME_MED::long_array*
712 SMESH_MEDMesh_i::getGlobalNumberingIndex(SALOME_MED::medEntityMesh entity)
713   throw (SALOME::SALOME_Exception)
714 {
715   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
716
717   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
718
719   return NULL;
720 }
721 //=============================================================================
722 /*!
723  * CORBA: Returns references for the support of boundary elements of type
724  * entity
725  */
726 //=============================================================================
727 SALOME_MED::SUPPORT_ptr
728 SMESH_MEDMesh_i::getBoundaryElements(SALOME_MED::medEntityMesh entity)
729   throw (SALOME::SALOME_Exception)
730 {
731   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
732
733   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
734
735   return NULL;
736 }
737 //=============================================================================
738 /*!
739  * CORBA:  Method return a reference on a support define on all the element of
740  *         an entity.
741  */
742 //=============================================================================
743 SALOME_MED::SUPPORT_ptr
744 SMESH_MEDMesh_i::getSupportOnAll(SALOME_MED::medEntityMesh entity)
745   throw (SALOME::SALOME_Exception)
746 {
747   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
748
749   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
750
751   return NULL;
752 }
753 //=============================================================================
754 /*!
755  * CORBA: Returns references for the support of the skin of the support
756  * mySupport3D
757  */
758 //=============================================================================
759 SALOME_MED::SUPPORT_ptr
760 SMESH_MEDMesh_i::getSkin(SALOME_MED::SUPPORT_ptr mySupport3D)
761   throw (SALOME::SALOME_Exception)
762 {
763   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
764
765   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
766
767   return NULL;
768 }
769 //=============================================================================
770 /*!
771  * CORBA: 
772  */
773 //=============================================================================
774 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::
775                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
776 {
777   MESSAGE("Pas Implemente dans SMESH");
778   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
779   return 0;
780 }
781
782 //=============================================================================
783 /*!
784  * CORBA: 
785  */
786 //=============================================================================
787 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::
788                                                SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
789 {
790   MESSAGE("Pas Implemente dans SMESH");
791   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
792   return 0;
793 }
794
795 //=============================================================================
796 /*!
797  * CORBA: 
798  */
799 //=============================================================================
800 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::
801                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
802 {
803   MESSAGE("Pas Implemente dans SMESH");
804   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
805   return 0;
806 }
807
808 //=============================================================================
809 /*!
810  * CORBA: 
811  */
812 //=============================================================================
813 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::
814                                                  SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
815 {
816   MESSAGE("Pas Implemente dans SMESH");
817   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
818   return 0;
819 }
820
821 //=============================================================================
822 /*!
823  * CORBA: 
824  */
825 //=============================================================================
826 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::
827                                                      SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
828 {
829   MESSAGE("Pas Implemente dans SMESH");
830   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
831   return 0;
832 }
833
834 //=============================================================================
835 /*!
836  * CORBA: 
837  */
838 //=============================================================================
839 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::
840                                                         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
841 {
842   MESSAGE("Non Implemente");
843   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
844   return 0;
845 }
846
847 //=============================================================================
848 /*!
849  * CORBA: add the Mesh in the StudyManager 
850  * PN Pas Implemente
851  */
852 //=============================================================================
853 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
854                                  SALOME_MED::MESH_ptr myIor) throw(SALOME::SALOME_Exception)
855 {
856   BEGIN_OF("MED_Mesh_i::addInStudy");
857   if (_meshId != "")
858   {
859     MESSAGE("Mesh already in Study");
860     THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
861                                  SALOME::BAD_PARAM);
862   };
863
864   /*
865    * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
866    * 
867    * // Create SComponent labelled 'MED' if it doesn't already exit
868    * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
869    * if ( CORBA::is_nil(medfather) ) 
870    * {
871    * MESSAGE("Add Component MED");
872    * medfather = myBuilder->NewComponent("MED");
873    * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
874    * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
875    * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
876    * aName->SetValue("MED");
877    * 
878    * myBuilder->DefineComponentInstance(medfather,myIor);
879    * 
880    * } ;
881    * 
882    * MESSAGE("Add a mesh Object under MED");
883    * myBuilder->NewCommand();
884    * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
885    * 
886    * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
887    * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
888    * CORBA::ORB_var &orb = init(0,0);
889    * CORBA::String_var iorStr = orb->object_to_string(myIor);
890    * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.in());
891    * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
892    * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
893    * aIOR->SetValue(iorStr.c_str());
894    * 
895    * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
896    * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
897    * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
898    * aName->SetValue(_mesh_i->getName().c_str());
899    * 
900    * _meshId = newObj->GetID();
901    * myBuilder->CommitCommand();
902    * 
903    */
904   END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
905 }
906
907 //=============================================================================
908 /*!
909  * CORBA: write mesh in a med file
910  */
911 //=============================================================================
912 void SMESH_MEDMesh_i::write(CORBA::Long i, const char *driverMeshName)
913   throw(SALOME::SALOME_Exception)
914 {
915   MESSAGE("Non Implemente");
916   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
917 }
918
919 //=============================================================================
920 /*!
921  * CORBA: read mesh in a med file
922  */
923 //=============================================================================
924 void SMESH_MEDMesh_i::read(CORBA::Long i) throw(SALOME::SALOME_Exception)
925 {
926   MESSAGE("Non Implemente");
927   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
928 }
929
930 //=============================================================================
931 /*!
932  * CORBA : release driver
933  */
934 //=============================================================================
935 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i) throw(SALOME::SALOME_Exception)
936 {
937   MESSAGE("Non Implemente");
938   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
939 }
940
941 //=============================================================================
942 /*!
943  * CORBA : attach driver
944  */
945 //=============================================================================
946 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType,
947                                        const char *fileName, const char *meshName) throw(SALOME::SALOME_Exception)
948 {
949   MESSAGE("Non Implemente");
950   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
951   return 0;
952 }
953
954 //=============================================================================
955 /*!
956  * Calcule le Nb d'elements par entite geometrique
957  */
958 //=============================================================================
959 void SMESH_MEDMesh_i::calculeNbElts() throw(SALOME::SALOME_Exception)
960 {
961   if (!_compte)
962   {
963     _compte = true;
964
965     _mapNbTypes[SALOME_MED::MED_NODE] = 1;
966     // On compte les aretes MED_SEG2 ou MED_SEG3
967     // On range les elements dans  les vecteurs correspondants 
968
969     _mapIndToSeqElts[SALOME_MED::MED_SEG2] = _indexElts++;
970     _mapIndToSeqElts[SALOME_MED::MED_SEG3] = _indexElts++;
971     _mapIndToVectTypes[SALOME_MED::MED_EDGE] = _indexEnts++;
972
973     int trouveSeg2 = 0;
974     int trouveSeg3 = 0;
975     SALOME_MED::medGeometryElement medElement;
976
977     SMDS_EdgeIteratorPtr itEdges=_meshDS->edgesIterator();
978     while(itEdges->more())
979     {
980       const SMDS_MeshEdge* elem = itEdges->next();
981       int nb_of_nodes = elem->NbNodes();
982
983       switch (nb_of_nodes)
984       {
985       case 2:
986         {
987           medElement = SALOME_MED::MED_SEG2;
988           if (trouveSeg2 == 0)
989           {
990             trouveSeg2 = 1;
991             _TypesId[SALOME_MED::MED_EDGE].
992               push_back(SALOME_MED::MED_SEG2);
993           }
994           break;
995         }
996       case 3:
997         {
998           medElement = SALOME_MED::MED_SEG3;
999           if (trouveSeg3 == 0)
1000           {
1001             trouveSeg3 = 1;
1002             _TypesId[SALOME_MED::MED_EDGE].
1003               push_back(SALOME_MED::MED_SEG3);
1004           }
1005           break;
1006         }
1007       }
1008       int index = _mapIndToSeqElts[medElement];
1009       SCRUTE(index);
1010       // Traitement de l arete
1011
1012       int longueur = _seq_elemId[index]->length();
1013       _seq_elemId[index]->length(longueur + nb_of_nodes);
1014
1015       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1016
1017       for(int k=0; itn->more(); k++)
1018         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1019     }
1020
1021     _mapNbTypes[SALOME_MED::MED_EDGE] = trouveSeg2 + trouveSeg3;
1022
1023     // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
1024     // On range les elements dans  les vecteurs correspondants 
1025     int trouveTria3 = 0;
1026     int trouveTria6 = 0;
1027     int trouveQuad4 = 0;
1028
1029     _mapIndToSeqElts[SALOME_MED::MED_TRIA3] = _indexElts++;
1030     _mapIndToSeqElts[SALOME_MED::MED_TRIA6] = _indexElts++;
1031     _mapIndToSeqElts[SALOME_MED::MED_QUAD4] = _indexElts++;
1032     _mapIndToVectTypes[SALOME_MED::MED_FACE] = _indexEnts++;
1033
1034     SMDS_FaceIteratorPtr itFaces=_meshDS->facesIterator();
1035     while(itFaces->more())
1036     {
1037       const SMDS_MeshFace * elem = itFaces->next();
1038       int nb_of_nodes = elem->NbNodes();
1039
1040       switch (nb_of_nodes)
1041       {
1042       case 3:
1043         {
1044           medElement = SALOME_MED::MED_TRIA3;
1045           if (trouveTria3 == 0)
1046           {
1047             trouveTria3 = 1;
1048             _TypesId[SALOME_MED::MED_FACE].
1049               push_back(SALOME_MED::MED_TRIA3);
1050           }
1051           break;
1052         }
1053       case 4:
1054         {
1055           medElement = SALOME_MED::MED_QUAD4;
1056           if (trouveQuad4 == 0)
1057           {
1058             trouveQuad4 = 1;
1059             _TypesId[SALOME_MED::MED_FACE].
1060               push_back(SALOME_MED::MED_QUAD4);
1061           }
1062           break;
1063         }
1064       case 6:
1065         {
1066           medElement = SALOME_MED::MED_TRIA6;
1067           if (trouveTria6 == 0)
1068           {
1069             trouveTria6 = 1;
1070             _TypesId[SALOME_MED::MED_FACE].
1071               push_back(SALOME_MED::MED_TRIA6);
1072           }
1073           break;
1074         }
1075       }
1076       int index = _mapIndToSeqElts[medElement];
1077       SCRUTE(index);
1078
1079       // Traitement de la face
1080       // Attention La numérotation des noeuds Med commence a 1
1081
1082       int longueur = _seq_elemId[index]->length();
1083       _seq_elemId[index]->length(longueur + nb_of_nodes);
1084
1085       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1086
1087       for(int k=0; itn->more(); k++)
1088         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1089     } //itFaces
1090
1091     _mapNbTypes[SALOME_MED::MED_FACE] =
1092       trouveTria3 + trouveTria6 + trouveQuad4;
1093
1094     _mapIndToSeqElts[SALOME_MED::MED_HEXA8] = _indexElts++;
1095     _mapIndToVectTypes[SALOME_MED::MED_CELL] = _indexEnts++;
1096     int index = _mapIndToSeqElts[medElement];
1097
1098     int trouveHexa8 = 0;
1099
1100     SMDS_VolumeIteratorPtr itVolumes=_meshDS->volumesIterator();
1101     while(itVolumes->more())
1102     {
1103       const SMDS_MeshVolume * elem = itVolumes->next();
1104
1105       int nb_of_nodes = elem->NbNodes();
1106       medElement = SALOME_MED::MED_HEXA8;
1107       ASSERT(nb_of_nodes == 8);
1108
1109       if (trouveHexa8 == 0)
1110       {
1111         trouveHexa8 = 1;
1112         _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
1113       };
1114       // Traitement de la maille
1115       int longueur = _seq_elemId[index]->length();
1116       _seq_elemId[index]->length(longueur + nb_of_nodes);
1117
1118       SMDS_NodeIteratorPtr itn=_meshDS->nodesIterator();
1119       for(int k=0; itn->more(); k++)
1120         _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1121     }
1122
1123     _mapNbTypes[SALOME_MED::MED_CELL] = trouveHexa8;
1124     _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1125       =
1126       trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 +
1127       trouveSeg3;
1128   }// fin du _compte
1129 };
1130
1131 //=============================================================================
1132 /*!
1133  * Creation des familles
1134  */
1135 //=============================================================================
1136 void SMESH_MEDMesh_i::createFamilies() throw(SALOME::SALOME_Exception)
1137 {
1138   Unexpect aCatch(SALOME_SalomeException);
1139   string famDes = ("Je ne sais pas");
1140   string famName0 = "Famille_";
1141   string famName;
1142   char numero[10];
1143
1144   if (_creeFamily == false)
1145   {
1146     _creeFamily = true;
1147     //SMESH_subMesh_i *subMeshServant;
1148
1149     map < int, SMESH_subMesh_i * >::iterator it;
1150     for (it = _mesh_i->_mapSubMesh_i.begin();
1151          it != _mesh_i->_mapSubMesh_i.end(); it++)
1152     {
1153       SMESH_subMesh_i *submesh_i = (*it).second;
1154       int famIdent = (*it).first;
1155
1156       ASSERT(famIdent < 999999999);
1157       sprintf(numero, "%d\n", famIdent);
1158       famName = famName0 + numero;
1159
1160       SMESH_MEDFamily_i *famservant =
1161         new SMESH_MEDFamily_i(famIdent, submesh_i,
1162                               famName, famDes, SALOME_MED::MED_NODE);
1163 #ifdef WNT
1164       SALOME_MED::FAMILY_ptr famille = SALOME_MED::FAMILY::_nil();
1165       POA_SALOME_MED::FAMILY* servantbase = dynamic_cast<POA_SALOME_MED::FAMILY*>(famservant);
1166       if ( servantbase )
1167         famille = SALOME_MED::FAMILY::_narrow( servantbase->_this() );
1168 #else 
1169       SALOME_MED::FAMILY_ptr famille = 
1170         SALOME_MED::FAMILY::_narrow( famservant->POA_SALOME_MED::FAMILY::_this() );
1171 #endif
1172       _families.push_back(famille);
1173     }
1174   }
1175 };
1176 //=============================================================================
1177 /*!
1178  * Gives informations of the considered mesh.
1179  */
1180 //=============================================================================
1181 SALOME_MED::MESH::meshInfos * SMESH_MEDMesh_i::getMeshGlobal()
1182   throw (SALOME::SALOME_Exception)
1183 {
1184   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1185
1186   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1187
1188   return NULL;
1189 }
1190 //=============================================================================
1191 /*!
1192  * Gives informations on coordinates of the considered mesh.
1193  */
1194 //=============================================================================
1195 SALOME_MED::MESH::coordinateInfos * SMESH_MEDMesh_i::getCoordGlobal()
1196   throw (SALOME::SALOME_Exception)
1197 {
1198   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1199
1200   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1201
1202   return NULL;
1203 }
1204 //=============================================================================
1205 /*!
1206  * Gives informations on connectivities of the considered mesh for the entity
1207  * entity.
1208  */
1209 //=============================================================================
1210 SALOME_MED::MESH::connectivityInfos *
1211 SMESH_MEDMesh_i::getConnectGlobal(SALOME_MED::medEntityMesh entity)
1212   throw (SALOME::SALOME_Exception)
1213 {
1214   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1215
1216   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1217
1218   return NULL;
1219 }
1220 //=============================================================================
1221 /*!
1222  * Gives the type of the element number of entity entity
1223  */
1224 //=============================================================================
1225 SALOME_MED::medGeometryElement
1226 SMESH_MEDMesh_i::getElementType(SALOME_MED::medEntityMesh entity,
1227                                 CORBA::Long number)
1228   throw (SALOME::SALOME_Exception)
1229 {
1230   MESSAGE("!!!! NOT YET IMPLEMENTED !!!!!");
1231
1232   THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
1233
1234   return (SALOME_MED::medGeometryElement) 0;
1235 }