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