Salome HOME
update
[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 /*!
168  * CORBA: Accessor for Coordinates System
169  */
170 //=============================================================================
171 char *SMESH_MEDMesh_i::getCoordinateSystem() throw(SALOME::SALOME_Exception)
172 {
173         if (_mesh_i == 0)
174                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
175                         SALOME::INTERNAL_ERROR);
176         // PN : En dur. Non encore prevu
177         try
178         {
179                 string systcoo = "CARTESIEN";
180                 return CORBA::string_dup(systcoo.c_str());
181         }
182         catch(...)
183         {
184                 MESSAGE("Exception en accedant au maillage");
185                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
186                         SALOME::INTERNAL_ERROR);
187         }
188 }
189
190 //=============================================================================
191 /*!
192  * CORBA: Accessor for Coordinates
193  */
194 //=============================================================================
195 Engines::double_array * SMESH_MEDMesh_i::getCoordinates(
196         SALOME_MED::medModeSwitch typeSwitch) throw(SALOME::SALOME_Exception)
197 {
198         if (_mesh_i == 0)
199                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
200                         SALOME::INTERNAL_ERROR);
201         Engines::double_array_var myseq = new Engines::double_array;
202         try
203         {
204                 // PN  : En dur
205                 int spaceDimension = 3;
206                 int nbNodes = _meshDS->NbNodes();
207                 SCRUTE(nbNodes);
208                 myseq->length(nbNodes * spaceDimension);
209                 int i = 0;
210
211                 SMDS_Iterator<const SMDS_MeshNode *> * itNodes=_meshDS->nodesIterator();
212                 while(itNodes->more())
213                 {
214                         const SMDS_MeshNode* node = itNodes->next();
215
216                         if (typeSwitch == SALOME_MED::MED_FULL_INTERLACE)
217                         {
218                                 myseq[i * 3] = node->X();
219                                 myseq[i * 3 + 1] = node->Y();
220                                 myseq[i * 3 + 2] = node->Z();
221                                 SCRUTE(myseq[i * 3]);
222                                 SCRUTE(myseq[i * 3 + 1]);
223                                 SCRUTE(myseq[i * 3 + 2]);
224                         }
225                         else
226                         {
227                                 ASSERT(typeSwitch == SALOME_MED::MED_NO_INTERLACE);
228                                 myseq[i] = node->X();
229                                 myseq[i + nbNodes] = node->Y();
230                                 myseq[i + (nbNodes * 2)] = node->Z();
231                                 SCRUTE(myseq[i]);
232                                 SCRUTE(myseq[i + nbNodes]);
233                                 SCRUTE(myseq[i + (nbNodes * 2)]);
234                         }
235                         i++;
236                 }
237                 delete itNodes;
238         }
239         catch(...)
240         {
241                 MESSAGE("Exception en accedant aux coordonnees");
242                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
243                         SALOME::INTERNAL_ERROR);
244         }
245         return myseq._retn();
246 }
247
248 //=============================================================================
249 /*!
250  * CORBA: Accessor for Coordinates Names
251  */
252 //=============================================================================
253 Engines::string_array *
254         SMESH_MEDMesh_i::getCoordinatesNames()throw(SALOME::SALOME_Exception)
255 {
256         if (_mesh_i == 0)
257                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
258                         SALOME::INTERNAL_ERROR);
259         Engines::string_array_var myseq = new Engines::string_array;
260         try
261         {
262                 // PN : en dur
263                 int spaceDimension = 3;
264                 myseq->length(spaceDimension);
265                 myseq[0] = CORBA::string_dup("x");
266                 myseq[1] = CORBA::string_dup("y");
267                 myseq[2] = CORBA::string_dup("z");
268         }
269         catch(...)
270         {
271                 MESSAGE("Exception en accedant aux noms des coordonnees");
272                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
273                         SALOME::INTERNAL_ERROR);
274         }
275         return myseq._retn();
276
277 }
278
279 //=============================================================================
280 /*!
281  * CORBA: Accessor for Coordinates Units
282  */
283 //=============================================================================
284 Engines::string_array *
285         SMESH_MEDMesh_i::getCoordinatesUnits()throw(SALOME::SALOME_Exception)
286 {
287         if (_mesh_i == 0)
288                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
289                         SALOME::INTERNAL_ERROR);
290         Engines::string_array_var myseq = new Engines::string_array;
291         try
292         {
293                 // PN : en dur
294                 int spaceDimension = 3;
295                 myseq->length(spaceDimension);
296                 myseq[0] = CORBA::string_dup("m");
297                 myseq[1] = CORBA::string_dup("m");
298                 myseq[2] = CORBA::string_dup("m");
299         }
300         catch(...)
301         {
302                 MESSAGE("Exception en accedant aux unites des coordonnees");
303                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
304                         SALOME::INTERNAL_ERROR);
305         }
306         return myseq._retn();
307 }
308
309 //=============================================================================
310 /*!
311  * CORBA: Accessor for Number of Nodes
312  */
313 //=============================================================================
314 CORBA::Long SMESH_MEDMesh_i::getNumberOfNodes()throw(SALOME::SALOME_Exception)
315 {
316         if (_mesh_i == 0)
317                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
318                         SALOME::INTERNAL_ERROR);
319         try
320         {
321                 return _meshDS->NbNodes();
322         }
323         catch(...)
324         {
325                 MESSAGE("Exception en accedant au nombre de noeuds");
326                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
327                         SALOME::INTERNAL_ERROR);
328         }
329 }
330
331 //=============================================================================
332 /*!
333  * CORBA: Accessor for number of Types
334  */
335 //=============================================================================
336 CORBA::Long SMESH_MEDMesh_i::getNumberOfTypes(SALOME_MED::medEntityMesh entity)
337 throw(SALOME::SALOME_Exception)
338 {
339         if (_mesh_i == 0)
340                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
341                         SALOME::INTERNAL_ERROR);
342         try
343         {
344                 if (!_compte)
345                         calculeNbElts();
346                 int retour = 0;
347                 if (_mapNbTypes.find(entity) != _mapNbTypes.end())
348                         retour = _mapNbTypes[entity];
349                 return retour;
350         }
351         catch(...)
352         {
353                 MESSAGE("Exception en accedant au nombre de Types");
354                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
355                         SALOME::INTERNAL_ERROR);
356         }
357 }
358
359 //=============================================================================
360 /*!
361  * CORBA: Accessor for existing geometry element types 
362  *        Not implemented for MED_ALL_ENTITIES
363  */
364 //=============================================================================
365 SALOME_MED::medGeometryElement_array *
366         SMESH_MEDMesh_i::getTypes(SALOME_MED::medEntityMesh entity) throw(SALOME::
367         SALOME_Exception)
368 {
369         if (_mesh_i == 0)
370                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
371                         SALOME::INTERNAL_ERROR);
372         if (entity == SALOME_MED::MED_ALL_ENTITIES)
373                 THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ENTITIES",
374                         SALOME::BAD_PARAM);
375         if (!_compte)
376                 calculeNbElts();
377         SALOME_MED::medGeometryElement_array_var myseq =
378                 new SALOME_MED::medGeometryElement_array;
379         try
380         {
381                 if (_mapNbTypes.find(entity) == _mapNbTypes.end())
382                         THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
383                                 SALOME::BAD_PARAM);
384                 int nbTypes = _mapNbTypes[entity];
385
386                 myseq->length(nbTypes);
387
388                 if (_mapIndToVectTypes.find(entity) == _mapIndToVectTypes.end())
389                         THROW_SALOME_CORBA_EXCEPTION("No Such Entity in the mesh",
390                                 SALOME::INTERNAL_ERROR);
391
392                 int index = _mapIndToVectTypes[entity];
393                 ASSERT(_TypesId[index].size() != 0);
394                 int i = 0;
395                 vector < SALOME_MED::medGeometryElement >::iterator it;
396                 for (it = _TypesId[index].begin(); it != _TypesId[index].end(); it++)
397                 {
398                         myseq[i++] = *it;
399                 };
400         }
401         catch(...)
402         {
403                 MESSAGE("Exception en accedant aux differents types");
404                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
405                         SALOME::INTERNAL_ERROR);
406         }
407         return myseq._retn();
408 }
409
410 //=============================================================================
411 /*!
412  * CORBA: Returns number of elements of type medGeometryElement
413  *        Not implemented for MED_ALL_ELEMENTS 
414  *        implemented for MED_ALL_ENTITIES
415  *
416  * Dans cette implementation, il n est pas prevu de tenir compte du entity
417  * qui ne doit pas pouvoir avoir deux valeurs differentes pour un geomElement 
418  */
419 //=============================================================================
420 CORBA::Long SMESH_MEDMesh_i::getNumberOfElements(SALOME_MED::
421         medEntityMesh entity,
422         SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
423 {
424         if (_mesh_i == 0)
425                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
426                         SALOME::INTERNAL_ERROR);
427         if (geomElement == SALOME_MED::MED_ALL_ELEMENTS)
428                 THROW_SALOME_CORBA_EXCEPTION("Not implemented for MED_ALL_ELEMENTS",
429                         SALOME::BAD_PARAM);
430         if (!_compte)
431                 calculeNbElts();
432
433         try
434         {
435                 int retour = 0;
436                 if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
437                 {
438                         int index = _mapIndToSeqElts[geomElement];
439                         retour = _seq_elemId[index]->length();
440                 }
441                 return retour;
442         }
443         catch(...)
444         {
445                 MESSAGE("Exception en accedant au nombre d élements");
446                 THROW_SALOME_CORBA_EXCEPTION("Unable to acces Mesh C++ Object",
447                         SALOME::INTERNAL_ERROR);
448         }
449 }
450
451 //=============================================================================
452 /*!
453  * CORBA: Accessor for connectivities
454  */
455 //=============================================================================
456 Engines::long_array *
457         SMESH_MEDMesh_i::getConnectivity(SALOME_MED::medModeSwitch typeSwitch,
458         SALOME_MED::medConnectivity mode, SALOME_MED::medEntityMesh entity,
459         SALOME_MED::medGeometryElement geomElement) throw(SALOME::SALOME_Exception)
460 {
461         if (_mesh_i == 0)
462                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
463                         SALOME::INTERNAL_ERROR);
464         if (mode != SALOME_MED::MED_NODAL)
465                 THROW_SALOME_CORBA_EXCEPTION("Not Implemented", SALOME::BAD_PARAM);
466         if (typeSwitch == SALOME_MED::MED_NO_INTERLACE)
467                 THROW_SALOME_CORBA_EXCEPTION("Not Yet Implemented", SALOME::BAD_PARAM);
468         if (!_compte)
469                 calculeNbElts();
470
471         // Faut-il renvoyer un pointeur vide ???
472         if (_mapIndToSeqElts.find(geomElement) != _mapIndToSeqElts.end())
473                 THROW_SALOME_CORBA_EXCEPTION("No Such Element in the mesh",
474                         SALOME::BAD_PARAM);
475
476         int index = _mapIndToSeqElts[geomElement];
477         return _seq_elemId[index]._retn();
478 }
479
480 //=============================================================================
481 /*!
482  * CORBA: Accessor for connectivities
483  */
484 //=============================================================================
485 Engines::long_array *
486         SMESH_MEDMesh_i::getConnectivityIndex(SALOME_MED::medConnectivity mode,
487         SALOME_MED::medEntityMesh entity) throw(SALOME::SALOME_Exception)
488 {
489         MESSAGE("Pas Implemente dans SMESH");
490         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
491         return 0;
492 }
493
494 //=============================================================================
495 /*!
496  * CORBA: Find an element corresponding to the given connectivity
497  */
498 //=============================================================================
499 CORBA::Long SMESH_MEDMesh_i::getElementNumber(SALOME_MED::medConnectivity mode,
500         SALOME_MED::medEntityMesh entity,
501         SALOME_MED::medGeometryElement type,
502         const Engines::long_array & connectivity)throw(SALOME::SALOME_Exception)
503 {
504         const char *LOC = "getElementNumber ";
505         MESSAGE(LOC << "Pas Implemente dans SMESH");
506         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
507         return -1;
508 }
509
510 //=============================================================================
511 /*!
512  * CORBA: Accessor for Ascendant connectivities
513  * not implemented for MED_ALL_ENTITIES and MED_MAILLE
514  */
515 //=============================================================================
516 Engines::long_array *
517         SMESH_MEDMesh_i::getReverseConnectivity(SALOME_MED::
518         medConnectivity mode) throw(SALOME::SALOME_Exception)
519 {
520         MESSAGE("Pas Implemente dans SMESH");
521         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
522         return 0;
523 }
524
525 //=============================================================================
526 /*!
527  * CORBA: Accessor for connectivities
528  */
529 //=============================================================================
530 Engines::long_array *
531         SMESH_MEDMesh_i::getReverseConnectivityIndex(SALOME_MED::
532         medConnectivity mode) 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: Returns number of families within the mesh
542  */
543 //=============================================================================
544 CORBA::Long SMESH_MEDMesh_i::getNumberOfFamilies(SALOME_MED::
545         medEntityMesh entity) throw(SALOME::SALOME_Exception)
546 {
547         if (_creeFamily == false)
548                 createFamilies();
549         if (_mesh_i == 0)
550                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
551                         SALOME::INTERNAL_ERROR);
552         return _families.size();
553 }
554
555 //=============================================================================
556 /*!
557  * CORBA: Returns number of groups within the mesh
558  */
559 //=============================================================================
560 CORBA::Long SMESH_MEDMesh_i::getNumberOfGroups(SALOME_MED::medEntityMesh entity)
561 throw(SALOME::SALOME_Exception)
562 {
563         if (_mesh_i == 0)
564                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
565                         SALOME::INTERNAL_ERROR);
566         MESSAGE(" Pas d implementation des groupes dans SMESH");
567         return 0;
568 }
569
570 //=============================================================================
571 /*!
572  * CORBA: Returns references for families within the mesh
573  */
574 //=============================================================================
575 SALOME_MED::Family_array *
576         SMESH_MEDMesh_i::getFamilies(SALOME_MED::
577         medEntityMesh entity) throw(SALOME::SALOME_Exception)
578 {
579         if (_creeFamily == false)
580                 createFamilies();
581         if (_mesh_i == 0)
582                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
583                         SALOME::INTERNAL_ERROR);
584         SALOME_MED::Family_array_var myseq = new SALOME_MED::Family_array;
585         int nbfam = _families.size();
586         myseq->length(nbfam);
587         int i = 0;
588         vector < SALOME_MED::FAMILY_ptr >::iterator it;
589         for (it = _families.begin(); it != _families.end(); it++)
590         {
591                 myseq[i++] = *it;
592         };
593         return myseq._retn();
594 }
595
596 //=============================================================================
597 /*!
598  * CORBA: Returns references for family i within the mesh
599  */
600 //=============================================================================
601 SALOME_MED::FAMILY_ptr SMESH_MEDMesh_i::getFamily(SALOME_MED::
602         medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
603 {
604         if (_creeFamily == false)
605                 createFamilies();
606         if (_mesh_i == 0)
607                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
608                         SALOME::INTERNAL_ERROR);
609
610         SCRUTE(_families[i]->getName());
611         MESSAGE(" SMESH_MEDMesh_i::getFamily " << i) return _families[i];
612 }
613
614 //=============================================================================
615 /*!
616  * CORBA: Returns references for groups within the mesh
617  */
618 //=============================================================================
619 SALOME_MED::Group_array *
620         SMESH_MEDMesh_i::getGroups(SALOME_MED::medEntityMesh entity) throw(SALOME::
621         SALOME_Exception)
622 {
623         if (_mesh_i == 0)
624                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
625                         SALOME::INTERNAL_ERROR);
626         MESSAGE(" Pas d implementation des groupes dans SMESH");
627         THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
628 }
629
630 //=============================================================================
631 /*!
632  * CORBA: Returns references for group i within the mesh
633  */
634 //=============================================================================
635 SALOME_MED::GROUP_ptr SMESH_MEDMesh_i::getGroup(SALOME_MED::
636         medEntityMesh entity, CORBA::Long i) throw(SALOME::SALOME_Exception)
637 {
638         if (_mesh_i == 0)
639                 THROW_SALOME_CORBA_EXCEPTION("No associated Mesh",
640                         SALOME::INTERNAL_ERROR);
641         MESSAGE(" Pas d implementation des groupes dans SMESH");
642         THROW_SALOME_CORBA_EXCEPTION("No group implementation", SALOME::BAD_PARAM);
643 }
644
645 //=============================================================================
646 /*!
647  * CORBA: 
648  */
649 //=============================================================================
650 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getVolume(SALOME_MED::
651         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
652 {
653         MESSAGE("Pas Implemente dans SMESH");
654         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
655         return 0;
656 }
657
658 //=============================================================================
659 /*!
660  * CORBA: 
661  */
662 //=============================================================================
663 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getArea(SALOME_MED::
664         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
665 {
666         MESSAGE("Pas Implemente dans SMESH");
667         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
668         return 0;
669 }
670
671 //=============================================================================
672 /*!
673  * CORBA: 
674  */
675 //=============================================================================
676 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getLength(SALOME_MED::
677         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
678 {
679         MESSAGE("Pas Implemente dans SMESH");
680         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
681         return 0;
682 }
683
684 //=============================================================================
685 /*!
686  * CORBA: 
687  */
688 //=============================================================================
689 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNormal(SALOME_MED::
690         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
691 {
692         MESSAGE("Pas Implemente dans SMESH");
693         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
694         return 0;
695 }
696
697 //=============================================================================
698 /*!
699  * CORBA: 
700  */
701 //=============================================================================
702 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getBarycenter(SALOME_MED::
703         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
704 {
705         MESSAGE("Pas Implemente dans SMESH");
706         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
707         return 0;
708 }
709
710 //=============================================================================
711 /*!
712  * CORBA: 
713  */
714 //=============================================================================
715 SALOME_MED::FIELD_ptr SMESH_MEDMesh_i::getNeighbourhood(SALOME_MED::
716         SUPPORT_ptr mySupport) throw(SALOME::SALOME_Exception)
717 {
718         MESSAGE("Non Implemente");
719         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
720         return 0;
721 }
722
723 //=============================================================================
724 /*!
725  * CORBA: add the Mesh in the StudyManager 
726  * PN Pas Implemente
727  */
728 //=============================================================================
729 void SMESH_MEDMesh_i::addInStudy(SALOMEDS::Study_ptr myStudy,
730         SALOME_MED::MESH_ptr myIor) throw(SALOME::SALOME_Exception)
731 {
732         BEGIN_OF("MED_Mesh_i::addInStudy");
733         if (_meshId != "")
734         {
735                 MESSAGE("Mesh already in Study");
736                 THROW_SALOME_CORBA_EXCEPTION("Mesh already in Study",
737                         SALOME::BAD_PARAM);
738         };
739
740         /*
741          * SALOMEDS::StudyBuilder_var myBuilder = myStudy->NewBuilder();
742          * 
743          * // Create SComponent labelled 'MED' if it doesn't already exit
744          * SALOMEDS::SComponent_var medfather = myStudy->FindComponent("MED");
745          * if ( CORBA::is_nil(medfather) ) 
746          * {
747          * MESSAGE("Add Component MED");
748          * medfather = myBuilder->NewComponent("MED");
749          * //myBuilder->AddAttribute (medfather,SALOMEDS::Name,"MED");
750          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
751          * myBuilder->FindOrCreateAttribute(medfather, "AttributeName"));
752          * aName->SetValue("MED");
753          * 
754          * myBuilder->DefineComponentInstance(medfather,myIor);
755          * 
756          * } ;
757          * 
758          * MESSAGE("Add a mesh Object under MED");
759          * myBuilder->NewCommand();
760          * SALOMEDS::SObject_var newObj = myBuilder->NewObject(medfather);
761          * 
762          * ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
763          * ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting()) ;
764          * CORBA::ORB_var &orb = init(0,0);
765          * string iorStr = orb->object_to_string(myIor);
766          * //myBuilder->AddAttribute(newObj,SALOMEDS::IOR,iorStr.c_str());
767          * SALOMEDS::AttributeIOR_var aIOR = SALOMEDS::AttributeIOR::_narrow(
768          * myBuilder->FindOrCreateAttribute(newObj, "AttributeIOR"));
769          * aIOR->SetValue(iorStr.c_str());
770          * 
771          * //myBuilder->AddAttribute(newObj,SALOMEDS::Name,_mesh_i->getName().c_str());
772          * SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(
773          * myBuilder->FindOrCreateAttribute(newObj, "AttributeName"));
774          * aName->SetValue(_mesh_i->getName().c_str());
775          * 
776          * _meshId = newObj->GetID();
777          * myBuilder->CommitCommand();
778          * 
779          */
780         END_OF("Mesh_i::addInStudy(SALOMEDS::Study_ptr myStudy)");
781 }
782
783 //=============================================================================
784 /*!
785  * CORBA: write mesh in a med file
786  */
787 //=============================================================================
788 void SMESH_MEDMesh_i::write(CORBA::Long i, const char *driverMeshName)
789 throw(SALOME::SALOME_Exception)
790 {
791         MESSAGE("Non Implemente");
792         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
793 }
794
795 //=============================================================================
796 /*!
797  * CORBA: read mesh in a med file
798  */
799 //=============================================================================
800 void SMESH_MEDMesh_i::read(CORBA::Long i) throw(SALOME::SALOME_Exception)
801 {
802         MESSAGE("Non Implemente");
803         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
804 }
805
806 //=============================================================================
807 /*!
808  * CORBA : release driver
809  */
810 //=============================================================================
811 void SMESH_MEDMesh_i::rmDriver(CORBA::Long i) throw(SALOME::SALOME_Exception)
812 {
813         MESSAGE("Non Implemente");
814         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
815 }
816
817 //=============================================================================
818 /*!
819  * CORBA : attach driver
820  */
821 //=============================================================================
822 CORBA::Long SMESH_MEDMesh_i::addDriver(SALOME_MED::medDriverTypes driverType,
823         const char *fileName, const char *meshName) throw(SALOME::SALOME_Exception)
824 {
825         MESSAGE("Non Implemente");
826         THROW_SALOME_CORBA_EXCEPTION("Unimplemented Method", SALOME::BAD_PARAM);
827         return 0;
828 }
829
830 //=============================================================================
831 /*!
832  * Calcule le Nb d'elements par entite geometrique
833  */
834 //=============================================================================
835 void SMESH_MEDMesh_i::calculeNbElts() throw(SALOME::SALOME_Exception)
836 {
837         if (!_compte)
838         {
839                 _compte = true;
840
841                 _mapNbTypes[SALOME_MED::MED_NODE] = 1;
842                 // On compte les aretes MED_SEG2 ou MED_SEG3
843                 // On range les elements dans  les vecteurs correspondants 
844
845                 _mapIndToSeqElts[SALOME_MED::MED_SEG2] = _indexElts++;
846                 _mapIndToSeqElts[SALOME_MED::MED_SEG3] = _indexElts++;
847                 _mapIndToVectTypes[SALOME_MED::MED_EDGE] = _indexEnts++;
848
849                 int trouveSeg2 = 0;
850                 int trouveSeg3 = 0;
851                 SALOME_MED::medGeometryElement medElement;
852
853                 SMDS_Iterator<const SMDS_MeshEdge*> * itEdges=_meshDS->edgesIterator();
854                 while(itEdges->more())
855                 {
856                         const SMDS_MeshEdge* elem = itEdges->next();
857                         int nb_of_nodes = elem->NbNodes();
858
859                         switch (nb_of_nodes)
860                         {
861                         case 2:
862                         {
863                                 medElement = SALOME_MED::MED_SEG2;
864                                 if (trouveSeg2 == 0)
865                                 {
866                                         trouveSeg2 = 1;
867                                         _TypesId[SALOME_MED::MED_EDGE].
868                                                 push_back(SALOME_MED::MED_SEG2);
869                                 }
870                                 break;
871                         }
872                         case 3:
873                         {
874                                 medElement = SALOME_MED::MED_SEG3;
875                                 if (trouveSeg3 == 0)
876                                 {
877                                         trouveSeg3 = 1;
878                                         _TypesId[SALOME_MED::MED_EDGE].
879                                                 push_back(SALOME_MED::MED_SEG3);
880                                 }
881                                 break;
882                         }
883                         }
884                         int index = _mapIndToSeqElts[medElement];
885                         SCRUTE(index);
886                         // Traitement de l arete
887                         int longueur = _seq_elemId[index]->length();
888                         _seq_elemId[index]->length(longueur + nb_of_nodes);
889
890                         SMDS_Iterator<const SMDS_MeshNode*> * itn=_meshDS->nodesIterator();
891
892                         for(int k=0; itn->more(); k++)
893                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
894                         delete itn;
895                 }
896                 delete itEdges;
897
898                 _mapNbTypes[SALOME_MED::MED_EDGE] = trouveSeg2 + trouveSeg3;
899
900                 // On compte les faces MED_TRIA3, MED_HEXA8, MED_TRIA6
901                 // On range les elements dans  les vecteurs correspondants 
902                 int trouveTria3 = 0;
903                 int trouveTria6 = 0;
904                 int trouveQuad4 = 0;
905
906                 _mapIndToSeqElts[SALOME_MED::MED_TRIA3] = _indexElts++;
907                 _mapIndToSeqElts[SALOME_MED::MED_TRIA6] = _indexElts++;
908                 _mapIndToSeqElts[SALOME_MED::MED_QUAD4] = _indexElts++;
909                 _mapIndToVectTypes[SALOME_MED::MED_FACE] = _indexEnts++;
910
911                 SMDS_Iterator<const SMDS_MeshFace*> * itFaces=_meshDS->facesIterator();
912                 while(itFaces->more())
913                 {
914                         const SMDS_MeshFace * elem = itFaces->next();
915                         int nb_of_nodes = elem->NbNodes();
916
917                         switch (nb_of_nodes)
918                         {
919                         case 3:
920                         {
921                                 medElement = SALOME_MED::MED_TRIA3;
922                                 if (trouveTria3 == 0)
923                                 {
924                                         trouveTria3 = 1;
925                                         _TypesId[SALOME_MED::MED_FACE].
926                                                 push_back(SALOME_MED::MED_TRIA3);
927                                 }
928                                 break;
929                         }
930                         case 4:
931                         {
932                                 medElement = SALOME_MED::MED_QUAD4;
933                                 if (trouveQuad4 == 0)
934                                 {
935                                         trouveQuad4 = 1;
936                                         _TypesId[SALOME_MED::MED_FACE].
937                                                 push_back(SALOME_MED::MED_QUAD4);
938                                 }
939                                 break;
940                         }
941                         case 6:
942                         {
943                                 medElement = SALOME_MED::MED_TRIA6;
944                                 if (trouveTria6 == 0)
945                                 {
946                                         trouveTria6 = 1;
947                                         _TypesId[SALOME_MED::MED_FACE].
948                                                 push_back(SALOME_MED::MED_TRIA6);
949                                 }
950                                 break;
951                         }
952                         }
953                         int index = _mapIndToSeqElts[medElement];
954                         SCRUTE(index);
955
956                         // Traitement de la face
957                         // Attention La numérotation des noeuds Med commence a 1
958
959                         int longueur = _seq_elemId[index]->length();
960                         _seq_elemId[index]->length(longueur + nb_of_nodes);
961
962                         SMDS_Iterator<const SMDS_MeshNode*> * itn=_meshDS->nodesIterator();
963
964                         for(int k=0; itn->more(); k++)
965                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
966                         delete itn;
967                 } //itFaces
968                 delete itFaces;
969
970                 _mapNbTypes[SALOME_MED::MED_FACE] =
971                         trouveTria3 + trouveTria6 + trouveQuad4;
972
973                 _mapIndToSeqElts[SALOME_MED::MED_HEXA8] = _indexElts++;
974                 _mapIndToVectTypes[SALOME_MED::MED_CELL] = _indexEnts++;
975                 int index = _mapIndToSeqElts[medElement];
976
977                 int trouveHexa8 = 0;
978
979                 SMDS_Iterator<const SMDS_MeshVolume*> * itVolumes=_meshDS->volumesIterator();
980                 while(itVolumes->more())
981                 {
982                         const SMDS_MeshVolume * elem = itVolumes->next();
983
984                         int nb_of_nodes = elem->NbNodes();
985                         medElement = SALOME_MED::MED_HEXA8;
986                         ASSERT(nb_of_nodes = 8);
987
988                         if (trouveHexa8 == 0)
989                         {
990                                 trouveHexa8 = 1;
991                                 _TypesId[SALOME_MED::MED_CELL].push_back(SALOME_MED::MED_HEXA8);
992                         };
993                         // Traitement de la maille
994                         int longueur = _seq_elemId[index]->length();
995                         _seq_elemId[index]->length(longueur + nb_of_nodes);
996
997                         SMDS_Iterator<const SMDS_MeshNode*> * itn=_meshDS->nodesIterator();
998                         for(int k=0; itn->more(); k++)
999                                 _seq_elemId[index][longueur + k] = itn->next()->GetID()+1;
1000                         delete itn;
1001                 }
1002                 delete itVolumes;
1003
1004                 _mapNbTypes[SALOME_MED::MED_CELL] = trouveHexa8;
1005                 _mapNbTypes[SALOME_MED::MED_ALL_ENTITIES]
1006                         =
1007                         trouveHexa8 + trouveTria3 + trouveTria6 + trouveQuad4 + trouveSeg2 +
1008                         trouveSeg3;
1009         }// fin du _compte
1010 };
1011
1012 //=============================================================================
1013 /*!
1014  * Creation des familles
1015  */
1016 //=============================================================================
1017 void SMESH_MEDMesh_i::createFamilies() throw(SALOME::SALOME_Exception)
1018 {
1019         string famDes = ("Je ne sais pas");
1020         string famName0 = "Famille_";
1021         string famName;
1022         char numero[10];
1023
1024         if (_creeFamily == false)
1025         {
1026                 _creeFamily = true;
1027                 SMESH_subMesh_i *subMeshServant;
1028
1029                 map < int, SMESH_subMesh_i * >::iterator it;
1030                 for (it = _mesh_i->_mapSubMesh_i.begin();
1031                         it != _mesh_i->_mapSubMesh_i.end(); it++)
1032                 {
1033                         SMESH_subMesh_i *submesh_i = (*it).second;
1034                         int famIdent = (*it).first;
1035
1036                         ASSERT(famIdent < 999999999);
1037                         sprintf(numero, "%d\n", famIdent);
1038                         famName = famName0 + numero;
1039
1040                         SMESH_MEDFamily_i *famservant =
1041                                 new SMESH_MEDFamily_i(famIdent, submesh_i,
1042                                 famName, famDes, SALOME_MED::MED_NODE);
1043                         SALOME_MED::FAMILY_ptr famille =
1044                                 SALOME_MED::FAMILY::_narrow(famservant->
1045                                 POA_SALOME_MED::FAMILY::_this());
1046                         _families.push_back(famille);
1047                 }
1048         }
1049 };