Salome HOME
9b3352a6439d26874b372e7eeb976f39a58748be
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_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_Mesh_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_subMesh_i.hxx"
32 #include "SMESH_MEDMesh_i.hxx"
33 #include "SMESH_Group_i.hxx"
34
35 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
38
39 #include "SALOME_NamingService.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "OpUtil.hxx"
42
43 #include "TCollection_AsciiString.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49
50 #include <string>
51 #include <iostream>
52
53
54 //**** SMESHDS en champ
55
56 int SMESH_Mesh_i::myIdGenerator = 0;
57
58 //=============================================================================
59 /*!
60  *  
61  */
62 //=============================================================================
63
64 SMESH_Mesh_i::SMESH_Mesh_i()
65      : SALOME::GenericObj_i( PortableServer::POA::_nil() )
66 {
67         MESSAGE("SMESH_Mesh_i: default constructor, not for use");
68         ASSERT(0);
69 }
70
71 //=============================================================================
72 /*!
73  *  Constructor
74  */
75 //=============================================================================
76
77 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
78                             SMESH_Gen_i*            gen_i,
79                             CORBA::Long studyId )
80 : SALOME::GenericObj_i( thePOA )
81 {
82   MESSAGE("SMESH_Mesh_i");
83   _gen_i = gen_i;
84   _id = myIdGenerator++;
85   _studyId = studyId;
86   thePOA->activate_object( this );
87 }
88 /*
89 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
90                            CORBA::Long studyId, 
91                            int localId)
92 {
93   MESSAGE("SMESH_Mesh_i");
94   _gen_i = gen_i;
95   _id = localId;
96   _studyId = studyId;
97 }
98 */
99 //=============================================================================
100 /*!
101  *  Destructor
102  */
103 //=============================================================================
104
105 SMESH_Mesh_i::~SMESH_Mesh_i()
106 {
107   MESSAGE("~SMESH_Mesh_i");
108   map<int, SMESH::SMESH_Group_ptr>::iterator it;
109   for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
110     SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
111     if ( aGroup ) {
112       _impl->RemoveGroup( aGroup->GetLocalID() );
113       aGroup->Destroy();
114     }
115   }
116   _mapGroups.clear();
117 }
118
119 //=============================================================================
120 /*!
121  *  SetShape
122  *
123  *  Associates <this> mesh with <theShape> and puts a reference  
124  *  to <theShape> into the current study; 
125  *  the previous shape is substituted by the new one.
126  */
127 //=============================================================================
128
129 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Shape_ptr theShape )
130     throw (SALOME::SALOME_Exception)
131 {
132   Unexpect aCatch(SALOME_SalomeException);
133   try {
134     setShape( theShape );
135   }
136   catch(SALOME_Exception & S_ex) {
137     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
138   }  
139
140   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
141   if ( aStudy->_is_nil() ) 
142     return;
143
144   // Create a reference to <theShape> 
145   SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
146   SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( theShape ) );
147   
148   SALOMEDS::SObject_var          anObj, aRef;
149   SALOMEDS::GenericAttribute_var anAttr;
150   SALOMEDS::AttributeIOR_var     anIOR;
151   SALOMEDS::StudyBuilder_var     aBuilder = aStudy->NewBuilder();
152   long                           aTag = SMESH_Gen_i::GetRefOnShapeTag();      
153   
154   if ( aMeshSO->FindSubObject( aTag, anObj ) ) {
155     if ( anObj->ReferencedObject( aRef ) ) {
156       if ( strcmp( aRef->GetID(), aShapeSO->GetID() ) == 0 ) {
157         // Setting the same shape twice forbidden
158         return;
159       }
160     }
161   }
162   else {
163     anObj = aBuilder->NewObjectToTag( aMeshSO, aTag );
164   }
165   aBuilder->Addreference( anObj, aShapeSO );
166 }
167
168 //=============================================================================
169 /*!
170  *  setShape
171  *
172  *  Sets shape to the mesh implementation
173  */
174 //=============================================================================
175
176 bool SMESH_Mesh_i::setShape( GEOM::GEOM_Shape_ptr theShape )
177 {
178   TopoDS_Shape aLocShape  = _gen_i->GetShapeReader()->GetShape( SMESH_Gen_i::GetGeomEngine(), theShape );
179   _impl->ShapeToMesh( aLocShape );
180   return true;
181 }
182
183 //=============================================================================
184 /*!
185  *  
186  */
187 //=============================================================================
188
189 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
190 {
191   SMESH::DriverMED_ReadStatus res;
192   switch (theStatus)
193   {
194   case DriverMED_R_SMESHDS_Mesh::DRS_OK:
195     res = SMESH::DRS_OK; break;
196   case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
197     res = SMESH::DRS_EMPTY; break;
198   case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
199     res = SMESH::DRS_WARN_RENUMBER; break;
200   case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
201     res = SMESH::DRS_WARN_SKIP_ELEM; break;
202   case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
203   default:
204     res = SMESH::DRS_FAIL; break;
205   }
206   return res;
207 }
208
209 //=============================================================================
210 /*!
211  *  ImportMEDFile
212  *
213  *  Imports mesh data from MED file
214  */
215 //=============================================================================
216
217 SMESH::DriverMED_ReadStatus
218   SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
219      throw ( SALOME::SALOME_Exception )
220 {
221   Unexpect aCatch(SALOME_SalomeException);
222   int status;
223   try {
224     status = importMEDFile( theFileName, theMeshName );
225   }
226   catch( SALOME_Exception& S_ex ) {
227     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
228   }  
229   catch ( ... ) {
230     THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
231   }
232
233   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
234   if ( aStudy->_is_nil() ) 
235     return ConvertDriverMEDReadStatus(status);
236   
237   // publishing of the groups in the study (sub-meshes are out of scope of MED import)
238   map<int, SMESH::SMESH_Group_ptr>::iterator it = _mapGroups.begin();
239   for (; it != _mapGroups.end(); it++ ) {
240     SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_duplicate( it->second );
241     if ( _gen_i->CanPublishInStudy( aGroup ) )
242       _gen_i->PublishInStudy( aStudy, 
243                               SALOMEDS::SObject::_nil(),
244                               aGroup,
245                               aGroup->GetName() );
246   }
247   return ConvertDriverMEDReadStatus(status);
248 }
249
250 //=============================================================================
251 /*!
252  *  importMEDFile
253  *
254  *  Imports mesh data from MED file
255  */
256 //=============================================================================
257
258 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
259 {
260   // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
261   int status = _impl->MEDToMesh( theFileName, theMeshName );
262
263   // Create group servants, if any groups were imported
264   list<int> aGroupIds = _impl->GetGroupIds();
265   for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
266     SMESH_Group_i* aGroupImpl     = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
267     SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
268     _mapGroups[*it]               = SMESH::SMESH_Group::_duplicate( aGroup );
269
270     // register CORBA object for persistence
271     StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
272     string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
273     int nextId = myStudyContext->addObject( iorString );
274     MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
275   }
276
277   return status;
278 }
279
280 //=============================================================================
281 /*!
282  *  
283  */
284 //=============================================================================
285
286 static SMESH::Hypothesis_Status ConvertHypothesisStatus
287                          (SMESH_Hypothesis::Hypothesis_Status theStatus)
288 {
289   SMESH::Hypothesis_Status res;
290   switch (theStatus)
291   {
292   case SMESH_Hypothesis::HYP_OK:
293     res = SMESH::HYP_OK; break;
294   case SMESH_Hypothesis::HYP_MISSING:
295     res = SMESH::HYP_MISSING; break;
296   case SMESH_Hypothesis::HYP_CONCURENT:
297     res = SMESH::HYP_CONCURENT; break;
298   case SMESH_Hypothesis::HYP_BAD_PARAMETER:
299     res = SMESH::HYP_BAD_PARAMETER; break;
300   case SMESH_Hypothesis::HYP_INCOMPATIBLE:
301     res = SMESH::HYP_INCOMPATIBLE; break;
302   case SMESH_Hypothesis::HYP_NOTCONFORM:
303     res = SMESH::HYP_NOTCONFORM; break;
304   case SMESH_Hypothesis::HYP_ALREADY_EXIST:
305     res = SMESH::HYP_ALREADY_EXIST; break;
306   case SMESH_Hypothesis::HYP_BAD_DIM:
307     res = SMESH::HYP_BAD_DIM; break;
308   default:
309     res = SMESH::HYP_UNKNOWN_FATAL;
310   }
311   return res;
312 }
313
314 //=============================================================================
315 /*!
316  *  AddHypothesis
317  *
318  *  calls internal addHypothesis() and then adds a reference to <anHyp> under 
319  *  the SObject actually having a reference to <aSubShape>.
320  *  NB: For this method to work, it is necessary to add a reference to sub-shape first.
321  */
322 //=============================================================================
323
324 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
325                                                      SMESH::SMESH_Hypothesis_ptr anHyp)
326   throw(SALOME::SALOME_Exception)
327 {
328   Unexpect aCatch(SALOME_SalomeException);
329   SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShape, anHyp );
330
331   if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
332     SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
333
334     if ( !aStudy->_is_nil() ) {
335       // Detect whether <aSubShape> refers to this mesh or its sub-mesh
336       SALOMEDS::GenericAttribute_var anAttr;
337       SALOMEDS::AttributeIOR_var     anIOR;
338       SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
339       SALOMEDS::SObject_var aMorSM, aRef;
340       CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
341       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
342
343       for ( it->InitEx( true ); it->More(); it->Next() ) {
344         SALOMEDS::SObject_var anObj = it->Value();
345         if ( anObj->ReferencedObject( aRef ) ) {
346           if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
347             anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
348             if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
349               aMorSM = anObj->GetFather();
350               break;
351             }
352           }
353         }
354       }
355
356       bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
357       SALOMEDS::SObject_var aHypSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp   ) ) ) );
358       if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
359         //Find or Create Applied Hypothesis root
360         SALOMEDS::SObject_var             AHR;
361         SALOMEDS::AttributeName_var       aName;
362         SALOMEDS::AttributeSelectable_var aSelAttr;
363         SALOMEDS::AttributePixMap_var     aPixmap;
364         SALOMEDS::StudyBuilder_var        aBuilder = aStudy->NewBuilder();
365         long                              aTag = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
366
367         if ( !aMorSM->FindSubObject( aTag, AHR ) ) {
368           AHR      = aBuilder->NewObjectToTag( aMorSM, aTag );
369           anAttr   = aBuilder->FindOrCreateAttribute( AHR, "AttributeName" );
370           aName    = SALOMEDS::AttributeName::_narrow( anAttr );
371           aName    ->SetValue( aIsAlgo ? "Applied algorithms" : "Applied hypotheses" );
372           anAttr   = aBuilder->FindOrCreateAttribute( AHR, "AttributeSelectable" );
373           aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr );
374           aSelAttr ->SetSelectable( false );
375           anAttr   = aBuilder->FindOrCreateAttribute( AHR, "AttributePixMap" );
376           aPixmap  = SALOMEDS::AttributePixMap::_narrow( anAttr );
377           aPixmap  ->SetPixMap( aIsAlgo ? "ICON_SMESH_TREE_ALGO" : "ICON_SMESH_TREE_HYPO" );
378         }
379
380         SALOMEDS::SObject_var SO = aBuilder->NewObject( AHR );
381         aBuilder->Addreference( SO, aHypSO );
382       }
383     }
384   }
385
386   return ConvertHypothesisStatus(status);
387 }
388
389 //=============================================================================
390 /*!
391  *  
392  */
393 //=============================================================================
394
395 SMESH_Hypothesis::Hypothesis_Status
396   SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
397                               SMESH::SMESH_Hypothesis_ptr anHyp)
398 {
399         MESSAGE("addHypothesis");
400         // **** proposer liste de subShape (selection multiple)
401
402         GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
403         if (CORBA::is_nil(mySubShape))
404                 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
405                         SALOME::BAD_PARAM);
406
407         SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
408         if (CORBA::is_nil(myHyp))
409                 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
410                         SALOME::BAD_PARAM);
411
412         SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
413         try
414         {
415                 TopoDS_Shape myLocSubShape =
416                         _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
417                 int hypId = myHyp->GetId();
418                 status = _impl->AddHypothesis(myLocSubShape, hypId);
419                 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
420                   _mapHypo[hypId] = myHyp;
421         }
422         catch(SALOME_Exception & S_ex)
423         {
424                 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
425         }
426         return status;
427 }
428
429 //=============================================================================
430 /*!
431  *  
432  */
433 //=============================================================================
434
435 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
436                                                         SMESH::SMESH_Hypothesis_ptr anHyp)
437      throw(SALOME::SALOME_Exception)
438 {
439   Unexpect aCatch(SALOME_SalomeException);
440   SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShape, anHyp );
441
442   if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
443     SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
444
445     if ( !aStudy->_is_nil() ) {
446       // Detect whether <aSubShape> refers to this mesh or its sub-mesh
447       SALOMEDS::GenericAttribute_var anAttr;
448       SALOMEDS::AttributeIOR_var     anIOR;
449       SALOMEDS::SObject_var aMeshSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
450       if ( aMeshSO->_is_nil() )
451         return SMESH::HYP_UNKNOWN_FATAL;
452
453       SALOMEDS::SObject_var aMorSM, aRef;
454       CORBA::String_var aShapeIOR    = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
455       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( aMeshSO );
456
457       for ( it->InitEx( true ); it->More(); it->Next() ) {
458         SALOMEDS::SObject_var anObj = it->Value();
459         if ( anObj->ReferencedObject( aRef ) ) {
460           if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
461             anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
462             if ( strcmp( anIOR->Value(), aShapeIOR ) == 0 ) {
463               aMorSM = anObj->GetFather();
464               break;
465             }
466           }
467         }
468       }
469
470       bool aIsAlgo = !SMESH::SMESH_Algo::_narrow( anHyp )->_is_nil();
471       SALOMEDS::SObject_var aHypSO  = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) ) ) );
472       if ( !aMorSM->_is_nil() && !aHypSO->_is_nil() ) {
473         // Remove a refernce to hypothesis or algorithm
474         SALOMEDS::SObject_var             AHR;
475         SALOMEDS::AttributeName_var       aName;
476         SALOMEDS::AttributeSelectable_var aSelAttr;
477         SALOMEDS::AttributePixMap_var     aPixmap;
478         SALOMEDS::StudyBuilder_var        aBuilder = aStudy->NewBuilder();
479         CORBA::String_var                 aHypIOR  = CORBA::string_dup( SMESH_Gen_i::GetORB()->object_to_string( anHyp ) );
480         long                              aTag     = aIsAlgo ? SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() : SMESH_Gen_i::GetRefOnAppliedHypothesisTag();
481
482         if ( aMorSM->FindSubObject( aTag, AHR ) ) {
483           SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator( AHR );
484           for ( ; it->More(); it->Next() ) {
485             SALOMEDS::SObject_var anObj = it->Value();
486             if ( anObj->ReferencedObject( aRef ) ) {
487               if ( aRef->FindAttribute( anAttr, "AttributeIOR" ) ) {
488                 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
489                 if ( strcmp( anIOR->Value(), aHypIOR ) == 0 ) {
490                   aBuilder->RemoveObject( anObj );
491                   break;
492                 }
493               }
494             }
495           }
496         }
497       }
498     }
499   }
500
501   return ConvertHypothesisStatus(status);
502 }
503
504
505 //=============================================================================
506 /*!
507  *  
508  */
509 //=============================================================================
510
511 SMESH_Hypothesis::Hypothesis_Status
512   SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
513                                  SMESH::SMESH_Hypothesis_ptr anHyp)
514 {
515         MESSAGE("removeHypothesis()");
516         // **** proposer liste de subShape (selection multiple)
517
518         GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
519         if (CORBA::is_nil(mySubShape))
520                 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
521                         SALOME::BAD_PARAM);
522
523         SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
524         if (CORBA::is_nil(myHyp))
525           THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
526                         SALOME::BAD_PARAM);
527
528         SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
529         try
530         {
531                 TopoDS_Shape myLocSubShape =
532                         _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
533                 int hypId = myHyp->GetId();
534                 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
535                 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
536                   _mapHypo.erase( hypId );
537         }
538         catch(SALOME_Exception & S_ex)
539         {
540                 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
541         }
542         return status;
543 }
544
545 //=============================================================================
546 /*!
547  *  
548  */
549 //=============================================================================
550
551 SMESH::ListOfHypothesis *
552         SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
553 throw(SALOME::SALOME_Exception)
554 {
555   Unexpect aCatch(SALOME_SalomeException);
556   MESSAGE("GetHypothesisList");
557   GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
558   if (CORBA::is_nil(mySubShape))
559     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
560                                  SALOME::BAD_PARAM);
561   
562   SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
563
564   try {
565     TopoDS_Shape myLocSubShape
566       = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
567     
568     const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
569     int i = 0, n = aLocalList.size();
570     aList->length( n );
571
572     for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
573       SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
574       if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
575         aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
576     }
577
578     aList->length( i );
579   }
580   catch(SALOME_Exception & S_ex) {
581     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
582   }
583   
584   return aList._retn();
585 }
586
587 //=============================================================================
588 /*!
589  *  
590  */
591 //=============================================================================
592 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Shape_ptr aSubShape,
593                                                   const char*          theName ) 
594      throw(SALOME::SALOME_Exception)
595 {
596   Unexpect aCatch(SALOME_SalomeException);
597   MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
598   GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
599   if (CORBA::is_nil(mySubShape))
600     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
601                                  SALOME::BAD_PARAM);
602   
603   int subMeshId = 0;
604   try {
605     TopoDS_Shape myLocSubShape
606       = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), mySubShape);
607     
608     //Get or Create the SMESH_subMesh object implementation
609     
610     ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
611     subMeshId = mySubMesh->GetId();
612     
613     // create a new subMesh object servant if there is none for the shape
614     
615     if (_mapSubMesh.find(subMeshId) == _mapSubMesh.end()) {
616       SMESH::SMESH_subMesh_var subMesh = createSubMesh( aSubShape );
617       if ( _gen_i->CanPublishInStudy( subMesh ) ) {
618         SALOMEDS::SObject_var aSubmeshSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(), 
619                                                                    SALOMEDS::SObject::_nil(),
620                                                                    subMesh,
621                                                                    theName );
622           
623         // Add reference to <aSubShape> to the study
624         SALOMEDS::Study_var aStudy = _gen_i->GetCurrentStudy();
625         SALOMEDS::SObject_var aShapeSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( aSubShape ) );
626         if ( !aSubmeshSO->_is_nil() && !aShapeSO->_is_nil() ) {
627           MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): adding shape reference..." )
628           SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
629           SALOMEDS::SObject_var SO = aBuilder->NewObjectToTag( aSubmeshSO, SMESH_Gen_i::GetRefOnShapeTag() );
630           aBuilder->Addreference( SO, aShapeSO );
631           MESSAGE( "********** SMESH_Mesh_i::GetSubMesh(): shape reference added" )
632         }
633       }
634     }
635   }
636   catch(SALOME_Exception & S_ex) {
637     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
638   }
639     
640   ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
641   return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
642 }
643
644
645 //=============================================================================
646 /*!
647  *  
648  */
649 //=============================================================================
650
651 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
652      throw (SALOME::SALOME_Exception)
653 {
654   MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
655   if ( theSubMesh->_is_nil() )
656     return;
657
658   GEOM::GEOM_Shape_var aSubShape;
659   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
660   if ( !aStudy->_is_nil() )  {
661     // Remove submesh's SObject
662     SALOMEDS::SObject_var anSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theSubMesh ) ) ) );
663     if ( !anSO->_is_nil() ) {
664       long aTag = SMESH_Gen_i::GetRefOnShapeTag(); 
665       SALOMEDS::SObject_var anObj, aRef;
666       if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
667         aSubShape = GEOM::GEOM_Shape::_narrow( aRef->GetObject() );
668
669       aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
670     }
671   }
672
673   removeSubMesh( theSubMesh, aSubShape.in() );
674 }
675
676
677 //=============================================================================
678 /*!
679  *  
680  */
681 //=============================================================================
682
683 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
684                                                   const char*        theName )
685      throw(SALOME::SALOME_Exception)
686 {
687   Unexpect aCatch(SALOME_SalomeException);
688   SMESH::SMESH_Group_var aNewGroup = createGroup( theElemType, theName );
689
690   // Groups should be put under separate roots according to their type (nodes, edges, faces, volumes)
691   if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
692     SALOMEDS::SObject_var aGroupSO = _gen_i->PublishInStudy( _gen_i->GetCurrentStudy(), 
693                                                              SALOMEDS::SObject::_nil(),
694                                                              aNewGroup,
695                                                              theName );
696   }
697
698   return aNewGroup._retn();
699 }
700
701
702 //=============================================================================
703 /*!
704  *  
705  */
706 //=============================================================================
707
708 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_Group_ptr theGroup )
709     throw (SALOME::SALOME_Exception)
710 {
711   if ( theGroup->_is_nil() )
712     return;
713
714   SMESH_Group_i* aGroup = dynamic_cast<SMESH_Group_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
715   if ( !aGroup )
716     return;
717
718   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
719   if ( !aStudy->_is_nil() )  {
720     // Remove group's SObject
721     SALOMEDS::SObject_var aGroupSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( theGroup ) ) ) );
722     if ( !aGroupSO->_is_nil() )
723       aStudy->NewBuilder()->RemoveObject( aGroupSO );
724   }
725
726   // Remove the group from SMESH data structures
727   removeGroup( aGroup->GetLocalID() );
728 }
729
730
731 //=============================================================================
732 /*!
733  *  
734  */
735 //=============================================================================
736
737 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Shape_ptr theSubShape ) {
738  
739   TopoDS_Shape myLocSubShape = _gen_i->GetShapeReader()->GetShape(SMESH_Gen_i::GetGeomEngine(), theSubShape);
740
741   ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
742   int subMeshId = mySubMesh->GetId();
743   SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
744   SMESH::SMESH_subMesh_var subMesh
745     = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
746
747   _mapSubMesh[subMeshId] = mySubMesh;
748   _mapSubMesh_i[subMeshId] = subMeshServant;
749   _mapSubMeshIor[subMeshId]
750     = SMESH::SMESH_subMesh::_duplicate(subMesh);
751
752   // register CORBA object for persistence
753   StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
754   string iorString = SMESH_Gen_i::GetORB()->object_to_string( subMesh );
755   int nextId = myStudyContext->addObject( iorString );
756   MESSAGE( "Add submesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
757
758   return subMesh._retn(); 
759 }
760
761
762 //=============================================================================
763 /*!
764  *  
765  */
766 //=============================================================================
767
768 void SMESH_Mesh_i::removeSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh, GEOM::GEOM_Shape_ptr theSubShape )
769 {
770   MESSAGE("SMESH_Mesh_i::removeSubMesh()");
771   if ( theSubMesh->_is_nil() || theSubShape->_is_nil() )
772     return;
773
774   try {
775     SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShape );
776     for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
777       removeHypothesis( theSubShape, aHypList[i] );
778     }
779   }
780   catch( const SALOME::SALOME_Exception& ) {
781     MESSAGE("SMESH_Mesh_i::removeSubMesh(): exception caught!");
782   }
783
784   int subMeshId = theSubMesh->GetId();
785
786   _mapSubMesh.erase(subMeshId);
787   _mapSubMesh_i.erase(subMeshId);
788   _mapSubMeshIor.erase(subMeshId);
789   MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
790 }
791
792 //=============================================================================
793 /*!
794  *  
795  */
796 //=============================================================================
797
798 SMESH::SMESH_Group_ptr SMESH_Mesh_i::createGroup( SMESH::ElementType theElemType, const char* theName )
799 {
800   int anId;
801   SMESH::SMESH_Group_var aGroup;
802   if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId ) ) {
803     SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
804     aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
805     _mapGroups[anId] = SMESH::SMESH_Group::_duplicate( aGroup );
806
807     // register CORBA object for persistence
808     StudyContext* myStudyContext = _gen_i->GetCurrentStudyContext();
809     string iorString = SMESH_Gen_i::GetORB()->object_to_string( aGroup );
810     int nextId = myStudyContext->addObject( iorString );
811     MESSAGE( "Add group to map with id = "<< nextId << " and IOR = " << iorString.c_str() );
812   }
813   return aGroup._retn();
814 }
815
816
817 //=============================================================================
818 /*!
819  * SMESH_Mesh_i::removeGroup
820  *
821  * Should be called by ~SMESH_Group_i() 
822  */
823 //=============================================================================
824
825 void SMESH_Mesh_i::removeGroup( const int theId )
826 {
827   MESSAGE("SMESH_Mesh_i::removeGroup()" );  
828   if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
829     _mapGroups.erase( theId );
830     _impl->RemoveGroup( theId );
831   }
832 }
833
834
835 //=============================================================================
836 /*!
837  *  
838  */
839 //=============================================================================
840
841 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
842 throw(SALOME::SALOME_Exception)
843 {
844         MESSAGE("SMESH_Mesh_i::GetLog");
845
846         SMESH::log_array_var aLog;
847         try
848         {
849                 list < SMESHDS_Command * >logDS = _impl->GetLog();
850                 aLog = new SMESH::log_array;
851                 int indexLog = 0;
852                 int lg = logDS.size();
853                 SCRUTE(lg);
854                 aLog->length(lg);
855                 list < SMESHDS_Command * >::iterator its = logDS.begin();
856                 while (its != logDS.end())
857                 {
858                         SMESHDS_Command *com = *its;
859                         int comType = com->GetType();
860                         //SCRUTE(comType);
861                         int lgcom = com->GetNumber();
862                         //SCRUTE(lgcom);
863                         const list < int >&intList = com->GetIndexes();
864                         int inum = intList.size();
865                         //SCRUTE(inum);
866                         list < int >::const_iterator ii = intList.begin();
867                         const list < double >&coordList = com->GetCoords();
868                         int rnum = coordList.size();
869                         //SCRUTE(rnum);
870                         list < double >::const_iterator ir = coordList.begin();
871                         aLog[indexLog].commandType = comType;
872                         aLog[indexLog].number = lgcom;
873                         aLog[indexLog].coords.length(rnum);
874                         aLog[indexLog].indexes.length(inum);
875                         for (int i = 0; i < rnum; i++)
876                         {
877                                 aLog[indexLog].coords[i] = *ir;
878                                 //MESSAGE(" "<<i<<" "<<ir.Value());
879                                 ir++;
880                         }
881                         for (int i = 0; i < inum; i++)
882                         {
883                                 aLog[indexLog].indexes[i] = *ii;
884                                 //MESSAGE(" "<<i<<" "<<ii.Value());
885                                 ii++;
886                         }
887                         indexLog++;
888                         its++;
889                 }
890                 if (clearAfterGet)
891                         _impl->ClearLog();
892         }
893         catch(SALOME_Exception & S_ex)
894         {
895                 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
896         }
897         return aLog._retn();
898 }
899
900 //  SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
901 //    throw (SALOME::SALOME_Exception)
902 //  {
903 //    MESSAGE("SMESH_Mesh_i::GetLog");
904
905 //    SMESH::string_array_var aLog;
906 //    try
907 //      {
908 //        const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
909 //        aLog = new SMESH::string_array;
910 //        int logSize = 0;
911 //        int indexLog = 0;
912 //        int lg = logDS.Extent();
913 //        SCRUTE(lg);
914 //        SMESHDS_ListIteratorOfListOfCommand its(logDS);
915 //        while(its.More())
916 //        {
917 //      Handle(SMESHDS_Command) com = its.Value();
918 //      int comType = com->GetType();
919 //      SCRUTE(comType);
920 //      int lgcom = com->GetNumber();
921 //      SCRUTE(lgcom);
922 //      logSize += lgcom;
923 //      aLog->length(logSize);
924 //      SCRUTE(logSize);
925 //      const TColStd_ListOfInteger& intList = com->GetIndexes();
926 //      TColStd_ListIteratorOfListOfInteger ii(intList);
927 //      const TColStd_ListOfReal& coordList = com->GetCoords();
928 //      TColStd_ListIteratorOfListOfReal ir(coordList);
929 //      for (int icom = 1; icom <= lgcom; icom++)
930 //        {
931 //          ostringstream S;
932 //          switch (comType)
933 //            {
934 //            case SMESHDS_AddNode:
935 //          S << "AddNode " << ii.Value(); ii.Next();
936 //          S << " " << ir.Value(); ir.Next(); 
937 //          S << " " << ir.Value(); ir.Next();
938 //          S << " " << ir.Value(); ir.Next();
939 //          break;
940 //            case SMESHDS_AddEdge:
941 //          S << "AddEdge " << ii.Value(); ii.Next();
942 //          S << " " << ii.Value(); ii.Next();
943 //          S << " " << ii.Value(); ii.Next();
944 //          break;
945 //            case SMESHDS_AddTriangle:
946 //          S << "AddFace " << ii.Value(); ii.Next();
947 //          S << " " << ii.Value(); ii.Next();
948 //          S << " " << ii.Value(); ii.Next();
949 //          S << " " << ii.Value(); ii.Next();
950 //          break;
951 //            case SMESHDS_AddQuadrangle:
952 //          S << "AddFace " << ii.Value(); ii.Next();
953 //          S << " " << ii.Value(); ii.Next();
954 //          S << " " << ii.Value(); ii.Next();
955 //          S << " " << ii.Value(); ii.Next();
956 //          S << " " << ii.Value(); ii.Next();
957 //          break;
958 //            case SMESHDS_AddTetrahedron:
959 //          S << "AddVolume " << ii.Value(); ii.Next();
960 //          S << " " << ii.Value(); ii.Next();
961 //          S << " " << ii.Value(); ii.Next();
962 //          S << " " << ii.Value(); ii.Next();
963 //          S << " " << ii.Value(); ii.Next();
964 //          break;
965 //            case SMESHDS_AddPyramid:
966 //          S << "AddVolume " << ii.Value(); ii.Next();
967 //          S << " " << ii.Value(); ii.Next();
968 //          S << " " << ii.Value(); ii.Next();
969 //          S << " " << ii.Value(); ii.Next();
970 //          S << " " << ii.Value(); ii.Next();
971 //          S << " " << ii.Value(); ii.Next();
972 //          break;
973 //            case SMESHDS_AddPrism:
974 //          S << "AddVolume " << ii.Value(); ii.Next();
975 //          S << " " << ii.Value(); ii.Next();
976 //          S << " " << ii.Value(); ii.Next();
977 //          S << " " << ii.Value(); ii.Next();
978 //          S << " " << ii.Value(); ii.Next();
979 //          S << " " << ii.Value(); ii.Next();
980 //          S << " " << ii.Value(); ii.Next();
981 //          break;
982 //            case SMESHDS_AddHexahedron:
983 //          S << "AddVolume " << ii.Value(); ii.Next();
984 //          S << " " << ii.Value(); ii.Next();
985 //          S << " " << ii.Value(); ii.Next();
986 //          S << " " << ii.Value(); ii.Next();
987 //          S << " " << ii.Value(); ii.Next();
988 //          S << " " << ii.Value(); ii.Next();
989 //          S << " " << ii.Value(); ii.Next();
990 //          S << " " << ii.Value(); ii.Next();
991 //          S << " " << ii.Value(); ii.Next();
992 //          break;
993 //            case SMESHDS_RemoveNode:
994 //          S << "RemoveNode " << ii.Value(); ii.Next();
995 //          break;
996 //            case SMESHDS_RemoveElement:
997 //          S << "RemoveElement " << ii.Value(); ii.Next();
998 //          break;
999 //            default:
1000 //          ASSERT(0);
1001 //          break;
1002 //            }
1003 //          string ch = S.str();
1004 //          SCRUTE(ch);
1005 //          aLog[indexLog++] = CORBA::string_dup(ch.c_str());
1006 //        }
1007 //      its.Next();
1008 //        }
1009 //        if (clearAfterGet) _impl->ClearLog();
1010 //      }
1011 //    catch (SALOME_Exception& S_ex)
1012 //      {
1013 //        THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1014 //      }
1015 //    return aLog._retn();
1016 //  }
1017
1018 //=============================================================================
1019 /*!
1020  *  
1021  */
1022 //=============================================================================
1023
1024 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1025 {
1026         MESSAGE("SMESH_Mesh_i::ClearLog");
1027         // ****
1028 }
1029
1030 //=============================================================================
1031 /*!
1032  *  
1033  */
1034 //=============================================================================
1035
1036 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1037 {
1038         MESSAGE("SMESH_Mesh_i::GetId");
1039         return _id;
1040 }
1041
1042 //=============================================================================
1043 /*!
1044  *  
1045  */
1046 //=============================================================================
1047
1048 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1049 {
1050         return _studyId;
1051 }
1052
1053 //=============================================================================
1054 /*!
1055  *  
1056  */
1057 //=============================================================================
1058
1059 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1060 {
1061         MESSAGE("SMESH_Mesh_i::SetImpl");
1062         _impl = impl;
1063 }
1064
1065 //=============================================================================
1066 /*!
1067  *  
1068  */
1069 //=============================================================================
1070
1071 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1072 {
1073         MESSAGE("SMESH_Mesh_i::GetImpl()");
1074         return *_impl;
1075 }
1076
1077
1078 //=============================================================================
1079 /*!
1080  *  
1081  */
1082 //=============================================================================
1083
1084 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1085 {
1086         SMESH_MeshEditor_i *aMeshEditor =
1087                 new SMESH_MeshEditor_i(_impl->GetMeshDS());
1088         SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1089         return aMesh._retn();
1090 }
1091
1092 //=============================================================================
1093 /*!
1094  *  
1095  */
1096 //=============================================================================
1097
1098 void SMESH_Mesh_i::ExportMED(const char *file, CORBA::Boolean auto_groups) throw(SALOME::SALOME_Exception)
1099 {
1100   Unexpect aCatch(SALOME_SalomeException);
1101   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1102   if ( aStudy->_is_nil() ) 
1103     return;
1104
1105   char* aMeshName = NULL;
1106   SALOMEDS::SObject_var aMeshSO = SALOMEDS::SObject::_narrow( aStudy->FindObjectIOR( ( SMESH_Gen_i::GetORB()->object_to_string( _this() ) ) ) );
1107   if ( !aMeshSO->_is_nil() )
1108     {
1109       aMeshName = aMeshSO->GetName();
1110       //SCRUTE(file);
1111       //SCRUTE(aMeshName);
1112       //SCRUTE(aMeshSO->GetID());
1113       SALOMEDS::GenericAttribute_var anAttr;
1114       SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1115       SALOMEDS::AttributeExternalFileDef_var aFileName;
1116       anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1117       aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1118       ASSERT(!aFileName->_is_nil());
1119       aFileName->SetValue(file);
1120       SALOMEDS::AttributeFileType_var aFileType;
1121       anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1122       aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1123       ASSERT(!aFileType->_is_nil());
1124       aFileType->SetValue("FICHIERMED");
1125     }
1126   _impl->ExportMED( file, aMeshName, auto_groups );
1127 }
1128
1129 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
1130 {
1131   Unexpect aCatch(SALOME_SalomeException);
1132         _impl->ExportDAT(file);
1133 }
1134 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
1135 {
1136   Unexpect aCatch(SALOME_SalomeException);
1137         _impl->ExportUNV(file);
1138 }
1139
1140 //=============================================================================
1141 /*!
1142  *  
1143  */
1144 //=============================================================================
1145
1146 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1147 {
1148   Unexpect aCatch(SALOME_SalomeException);
1149         SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1150         SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1151         return aMesh._retn();
1152 }
1153
1154 //=============================================================================
1155 /*!
1156  *  
1157  */
1158 //=============================================================================
1159 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1160 {
1161   Unexpect aCatch(SALOME_SalomeException);
1162         return _impl->NbNodes();
1163 }
1164
1165 //=============================================================================
1166 /*!
1167  *  
1168  */
1169 //=============================================================================
1170 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1171 {
1172   Unexpect aCatch(SALOME_SalomeException);
1173         return _impl->NbEdges();
1174 }
1175
1176 //=============================================================================
1177 /*!
1178  *  
1179  */
1180 //=============================================================================
1181 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1182 {
1183   Unexpect aCatch(SALOME_SalomeException);
1184         return _impl->NbFaces();
1185 }
1186
1187 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1188 {
1189   Unexpect aCatch(SALOME_SalomeException);
1190         return _impl->NbTriangles();
1191 }
1192
1193 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1194 {
1195   Unexpect aCatch(SALOME_SalomeException);
1196         return _impl->NbQuadrangles();
1197 }
1198
1199 //=============================================================================
1200 /*!
1201  *  
1202  */
1203 //=============================================================================
1204 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1205 {
1206   Unexpect aCatch(SALOME_SalomeException);
1207         return _impl->NbVolumes();
1208 }
1209
1210 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1211 {
1212   Unexpect aCatch(SALOME_SalomeException);
1213         return _impl->NbTetras();
1214 }
1215
1216 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1217 {
1218   Unexpect aCatch(SALOME_SalomeException);
1219         return _impl->NbHexas();
1220 }
1221
1222 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1223 {
1224   Unexpect aCatch(SALOME_SalomeException);
1225         return _impl->NbPyramids();
1226 }
1227
1228 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1229 {
1230   Unexpect aCatch(SALOME_SalomeException);
1231         return _impl->NbPrisms();
1232 }
1233
1234 //=============================================================================
1235 /*!
1236  *  
1237  */
1238 //=============================================================================
1239 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1240 {
1241   Unexpect aCatch(SALOME_SalomeException);
1242         return _impl->NbSubMesh();
1243 }
1244
1245 //=============================================================================
1246 /*!
1247  *  
1248  */
1249 //=============================================================================
1250 char* SMESH_Mesh_i::Dump()
1251 {
1252   std::ostringstream os;
1253   _impl->Dump( os );
1254   return CORBA::string_dup( os.str().c_str() );
1255 }