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