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