Salome HOME
Bug PAL7444 - display mesh takes a lot of more memory in 2.1.0 than in 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 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_subMesh_i.hxx"
31 #include "SMESH_MEDMesh_i.hxx"
32 #include "SMESH_Group_i.hxx"
33 #include "SMESH_Filter_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 <TColStd_MapOfInteger.hxx>
51 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
52 #include <TColStd_SequenceOfInteger.hxx>
53
54 #include <string>
55 #include <iostream>
56 #include <sstream>
57
58 #ifdef _DEBUG_
59 static int MYDEBUG = 0;
60 #else
61 static int MYDEBUG = 0;
62 #endif
63
64 using namespace std;
65
66 int SMESH_Mesh_i::myIdGenerator = 0;
67
68 //=============================================================================
69 /*!
70  *  Constructor
71  */
72 //=============================================================================
73
74 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
75                             SMESH_Gen_i*            gen_i,
76                             CORBA::Long studyId )
77 : SALOME::GenericObj_i( thePOA )
78 {
79   INFOS("SMESH_Mesh_i; this = "<<this);
80   _impl = NULL;
81   _gen_i = gen_i;
82   _id = myIdGenerator++;
83   _studyId = studyId;
84   thePOA->activate_object( this );
85 }
86
87 //=============================================================================
88 /*!
89  *  Destructor
90  */
91 //=============================================================================
92
93 SMESH_Mesh_i::~SMESH_Mesh_i()
94 {
95   INFOS("~SMESH_Mesh_i; this = "<<this);
96   map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
97   for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
98     SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
99     if ( aGroup ) {
100
101       // this method is colled from destructor of group (PAL6331)
102       //_impl->RemoveGroup( aGroup->GetLocalID() );
103       
104       aGroup->Destroy();
105     }
106   }
107   _mapGroups.clear();
108 }
109
110 //=============================================================================
111 /*!
112  *  SetShape
113  *
114  *  Associates <this> mesh with <theShape> and puts a reference  
115  *  to <theShape> into the current study; 
116  *  the previous shape is substituted by the new one.
117  */
118 //=============================================================================
119
120 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
121     throw (SALOME::SALOME_Exception)
122 {
123   Unexpect aCatch(SALOME_SalomeException);
124   try {
125     _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
126   }
127   catch(SALOME_Exception & S_ex) {
128     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
129   }
130 }
131
132 //=======================================================================
133 //function : GetShapeToMesh
134 //purpose  : 
135 //=======================================================================
136
137 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
138     throw (SALOME::SALOME_Exception)
139 {
140   Unexpect aCatch(SALOME_SalomeException);
141   GEOM::GEOM_Object_var aShapeObj;
142   try {
143     TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
144     if ( !S.IsNull() )
145       aShapeObj = _gen_i->ShapeToGeomObject( S );
146   }
147   catch(SALOME_Exception & S_ex) {
148     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
149   }
150   return aShapeObj._retn();
151 }
152
153 //=============================================================================
154 /*!
155  *  
156  */
157 //=============================================================================
158
159 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
160 {
161   SMESH::DriverMED_ReadStatus res;
162   switch (theStatus)
163   {
164   case DriverMED_R_SMESHDS_Mesh::DRS_OK:
165     res = SMESH::DRS_OK; break;
166   case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
167     res = SMESH::DRS_EMPTY; break;
168   case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
169     res = SMESH::DRS_WARN_RENUMBER; break;
170   case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
171     res = SMESH::DRS_WARN_SKIP_ELEM; break;
172   case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
173   default:
174     res = SMESH::DRS_FAIL; break;
175   }
176   return res;
177 }
178
179 //=============================================================================
180 /*!
181  *  ImportMEDFile
182  *
183  *  Imports mesh data from MED file
184  */
185 //=============================================================================
186
187 SMESH::DriverMED_ReadStatus
188 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
189   throw ( SALOME::SALOME_Exception )
190 {
191   Unexpect aCatch(SALOME_SalomeException);
192   int status;
193   try {
194     status = importMEDFile( theFileName, theMeshName );
195   }
196   catch( SALOME_Exception& S_ex ) {
197     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
198   }  
199   catch ( ... ) {
200     THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
201   }
202
203   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
204   if ( !aStudy->_is_nil() ) {
205     // publishing of the groups in the study (sub-meshes are out of scope of MED import)
206     map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
207     for (; it != _mapGroups.end(); it++ ) {
208       SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
209       _gen_i->PublishGroup( aStudy, _this(), aGroup,
210                            GEOM::GEOM_Object::_nil(), aGroup->GetName());
211     }
212   }
213   return ConvertDriverMEDReadStatus(status);
214 }
215
216 //=============================================================================
217 /*!
218  *  ImportUNVFile
219  *
220  *  Imports mesh data from MED file
221  */
222 //=============================================================================
223
224 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
225   throw ( SALOME::SALOME_Exception )
226 {
227   // Read mesh with name = <theMeshName> into SMESH_Mesh
228   _impl->UNVToMesh( theFileName );
229
230   return 1;
231 }
232
233 //=============================================================================
234 /*!
235  *  ImportSTLFile
236  *
237  *  Imports mesh data from STL file
238  */
239 //=============================================================================
240 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
241   throw ( SALOME::SALOME_Exception )
242 {
243   // Read mesh with name = <theMeshName> into SMESH_Mesh
244   _impl->STLToMesh( theFileName );
245
246   return 1;
247 }
248
249 //=============================================================================
250 /*!
251  *  importMEDFile
252  *
253  *  Imports mesh data from MED file
254  */
255 //=============================================================================
256
257 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
258 {
259   // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
260   int status = _impl->MEDToMesh( theFileName, theMeshName );
261
262   // Create group servants, if any groups were imported
263   list<int> aGroupIds = _impl->GetGroupIds();
264   for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
265     SMESH_Group_i* aGroupImpl     = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
266
267     // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
268     SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
269     aGroupImpl->Register();
270     // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
271
272     SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
273     _mapGroups[*it]               = SMESH::SMESH_Group::_duplicate( aGroup );
274
275     // register CORBA object for persistence
276     int nextId = _gen_i->RegisterObject( aGroup );
277     if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
278   }
279
280   return status;
281 }
282
283 //=============================================================================
284 /*!
285  *  
286  */
287 //=============================================================================
288
289 static SMESH::Hypothesis_Status ConvertHypothesisStatus
290                          (SMESH_Hypothesis::Hypothesis_Status theStatus)
291 {
292   SMESH::Hypothesis_Status res;
293   switch (theStatus)
294   {
295   case SMESH_Hypothesis::HYP_OK:
296     res = SMESH::HYP_OK; break;
297   case SMESH_Hypothesis::HYP_MISSING:
298     res = SMESH::HYP_MISSING; break;
299   case SMESH_Hypothesis::HYP_CONCURENT:
300     res = SMESH::HYP_CONCURENT; break;
301   case SMESH_Hypothesis::HYP_BAD_PARAMETER:
302     res = SMESH::HYP_BAD_PARAMETER; break;
303   case SMESH_Hypothesis::HYP_INCOMPATIBLE:
304     res = SMESH::HYP_INCOMPATIBLE; break;
305   case SMESH_Hypothesis::HYP_NOTCONFORM:
306     res = SMESH::HYP_NOTCONFORM; break;
307   case SMESH_Hypothesis::HYP_ALREADY_EXIST:
308     res = SMESH::HYP_ALREADY_EXIST; break;
309   case SMESH_Hypothesis::HYP_BAD_DIM:
310     res = SMESH::HYP_BAD_DIM; break;
311   default:
312     res = SMESH::HYP_UNKNOWN_FATAL;
313   }
314   return res;
315 }
316
317 //=============================================================================
318 /*!
319  *  AddHypothesis
320  *
321  *  calls internal addHypothesis() and then adds a reference to <anHyp> under 
322  *  the SObject actually having a reference to <aSubShape>.
323  *  NB: For this method to work, it is necessary to add a reference to sub-shape first.
324  */
325 //=============================================================================
326
327 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
328                                                      SMESH::SMESH_Hypothesis_ptr anHyp)
329   throw(SALOME::SALOME_Exception)
330 {
331   Unexpect aCatch(SALOME_SalomeException);
332   SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
333
334   if ( !SMESH_Hypothesis::IsStatusFatal(status) )
335     _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
336                                  aSubShapeObject, anHyp );
337
338   if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
339
340   return ConvertHypothesisStatus(status);
341 }
342
343 //=============================================================================
344 /*!
345  *  
346  */
347 //=============================================================================
348
349 SMESH_Hypothesis::Hypothesis_Status
350   SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr       aSubShapeObject,
351                               SMESH::SMESH_Hypothesis_ptr anHyp)
352 {
353   if(MYDEBUG) MESSAGE("addHypothesis");
354
355   if (CORBA::is_nil(aSubShapeObject))
356     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
357                                  SALOME::BAD_PARAM);
358
359   SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
360   if (CORBA::is_nil(myHyp))
361     THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
362                                  SALOME::BAD_PARAM);
363
364   SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
365   try
366   {
367     TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
368     int hypId = myHyp->GetId();
369     status = _impl->AddHypothesis(myLocSubShape, hypId);
370     if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
371       _mapHypo[hypId] = myHyp;
372       // assure there is a corresponding submesh
373       if ( !_impl->IsMainShape( myLocSubShape )) {
374         int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
375         if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
376           createSubMesh( aSubShapeObject );
377       }
378     }
379   }
380   catch(SALOME_Exception & S_ex)
381   {
382     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
383   }
384   return status;
385 }
386
387 //=============================================================================
388 /*!
389  *  
390  */
391 //=============================================================================
392
393 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
394                                                         SMESH::SMESH_Hypothesis_ptr anHyp)
395      throw(SALOME::SALOME_Exception)
396 {
397   Unexpect aCatch(SALOME_SalomeException);
398   SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
399
400   if ( !SMESH_Hypothesis::IsStatusFatal(status) )
401     _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
402                                       aSubShapeObject, anHyp );
403
404   return ConvertHypothesisStatus(status);
405 }
406
407 //=============================================================================
408 /*!
409  *  
410  */
411 //=============================================================================
412
413 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
414                                  SMESH::SMESH_Hypothesis_ptr anHyp)
415 {
416         if(MYDEBUG) MESSAGE("removeHypothesis()");
417         // **** proposer liste de subShape (selection multiple)
418
419         if (CORBA::is_nil(aSubShapeObject))
420                 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
421                         SALOME::BAD_PARAM);
422
423         SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
424         if (CORBA::is_nil(myHyp))
425           THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
426                         SALOME::BAD_PARAM);
427
428         SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
429         try
430         {
431                 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
432                 int hypId = myHyp->GetId();
433                 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
434                 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
435                   _mapHypo.erase( hypId );
436         }
437         catch(SALOME_Exception & S_ex)
438         {
439                 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
440         }
441         return status;
442 }
443
444 //=============================================================================
445 /*!
446  *  
447  */
448 //=============================================================================
449
450 SMESH::ListOfHypothesis *
451         SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
452 throw(SALOME::SALOME_Exception)
453 {
454   Unexpect aCatch(SALOME_SalomeException);
455   if (MYDEBUG) MESSAGE("GetHypothesisList");
456   if (CORBA::is_nil(aSubShapeObject))
457     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
458                                  SALOME::BAD_PARAM);
459   
460   SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
461
462   try {
463     TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
464     const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
465     int i = 0, n = aLocalList.size();
466     aList->length( n );
467
468     for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
469       SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
470       if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
471         aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
472     }
473
474     aList->length( i );
475   }
476   catch(SALOME_Exception & S_ex) {
477     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
478   }
479   
480   return aList._retn();
481 }
482
483 //=============================================================================
484 /*!
485  *  
486  */
487 //=============================================================================
488 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
489                                                   const char*           theName ) 
490      throw(SALOME::SALOME_Exception)
491 {
492   Unexpect aCatch(SALOME_SalomeException);
493   MESSAGE("SMESH_Mesh_i::GetSubMesh");
494   if (CORBA::is_nil(aSubShapeObject))
495     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
496                                  SALOME::BAD_PARAM);
497   
498   SMESH::SMESH_subMesh_var subMesh;
499   SMESH::SMESH_Mesh_var    aMesh = SMESH::SMESH_Mesh::_narrow(_this());
500   try {
501     TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
502     
503     //Get or Create the SMESH_subMesh object implementation
504     
505     int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
506     subMesh = getSubMesh( subMeshId );
507
508     // create a new subMesh object servant if there is none for the shape
509     if ( subMesh->_is_nil() )
510       subMesh = createSubMesh( aSubShapeObject );
511
512     if ( _gen_i->CanPublishInStudy( subMesh ))
513       _gen_i->PublishSubMesh (_gen_i->GetCurrentStudy(), aMesh,
514                               subMesh, aSubShapeObject, theName );
515   }
516   catch(SALOME_Exception & S_ex) {
517     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
518   }
519   return subMesh._retn();
520 }
521
522 //=============================================================================
523 /*!
524  *  
525  */
526 //=============================================================================
527
528 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
529      throw (SALOME::SALOME_Exception)
530 {
531   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
532   if ( theSubMesh->_is_nil() )
533     return;
534
535   GEOM::GEOM_Object_var aSubShapeObject;
536   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
537   if ( !aStudy->_is_nil() )  {
538     // Remove submesh's SObject
539     SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
540     if ( !anSO->_is_nil() ) {
541       long aTag = SMESH_Gen_i::GetRefOnShapeTag(); 
542       SALOMEDS::SObject_var anObj, aRef;
543       if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
544         aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
545
546       aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
547     }
548   }
549
550   removeSubMesh( theSubMesh, aSubShapeObject.in() );
551 }
552
553
554 //=============================================================================
555 /*!
556  *  
557  */
558 //=============================================================================
559
560 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
561                                                  const char*         theName )
562      throw(SALOME::SALOME_Exception)
563 {
564   Unexpect aCatch(SALOME_SalomeException);
565   SMESH::SMESH_Group_var aNewGroup =
566     SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
567
568   _gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(),
569                        aNewGroup, GEOM::GEOM_Object::_nil(), theName);
570
571   return aNewGroup._retn();
572 }
573
574
575 //=============================================================================
576 /*!
577  *  
578  */
579 //=============================================================================
580 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM( SMESH::ElementType    theElemType,
581                                                                const char*           theName,
582                                                                GEOM::GEOM_Object_ptr theGeomObj)
583      throw(SALOME::SALOME_Exception)
584 {
585   Unexpect aCatch(SALOME_SalomeException);
586   SMESH::SMESH_GroupOnGeom_var aNewGroup;
587
588   TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
589   if ( !aShape.IsNull() ) {
590     aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
591       ( createGroup( theElemType, theName, aShape ));
592     if ( _gen_i->CanPublishInStudy( aNewGroup ) )
593       _gen_i->PublishGroup( _gen_i->GetCurrentStudy(), _this(), 
594                            aNewGroup, theGeomObj, theName );
595   }
596
597   return aNewGroup._retn();
598 }
599 //=============================================================================
600 /*!
601  *  
602  */
603 //=============================================================================
604
605 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
606      throw (SALOME::SALOME_Exception)
607 {
608   if ( theGroup->_is_nil() )
609     return;
610
611   SMESH_GroupBase_i* aGroup =
612     dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
613   if ( !aGroup )
614     return;
615
616   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
617   if ( !aStudy->_is_nil() )  {
618     // Remove group's SObject
619     SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
620     if ( !aGroupSO->_is_nil() )
621       aStudy->NewBuilder()->RemoveObject( aGroupSO );
622   }
623
624   // Remove the group from SMESH data structures
625   removeGroup( aGroup->GetLocalID() );
626 }
627
628 //=============================================================================
629 /*! RemoveGroupWithContents
630  *  Remove group with its contents
631  */ 
632 //=============================================================================
633 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
634   throw (SALOME::SALOME_Exception)
635 {
636   if ( theGroup->_is_nil() )
637     return;
638
639   SMESH_GroupBase_i* aGroup =
640     dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
641   if ( !aGroup )
642     return;
643   
644   SMESH::long_array_var anIds = aGroup->GetListOfID();
645   SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
646     
647   if ( aGroup->GetType() == SMESH::NODE )
648     aMeshEditor->RemoveNodes( anIds );
649   else
650     aMeshEditor->RemoveElements( anIds );
651   
652   RemoveGroup( theGroup );
653 }
654
655 //=============================================================================
656 /*! UnionGroups
657  *  New group is created. All mesh elements that are 
658  *  present in initial groups are added to the new one
659  */
660 //=============================================================================
661 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
662                                                   SMESH::SMESH_GroupBase_ptr theGroup2, 
663                                                   const char* theName )
664   throw (SALOME::SALOME_Exception)
665 {
666   try
667   {
668     SMESH::SMESH_Group_var aResGrp;
669
670     if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
671          theGroup1->GetType() != theGroup2->GetType() )
672       return SMESH::SMESH_Group::_nil();
673
674     aResGrp = CreateGroup( theGroup1->GetType(), theName );
675     if ( aResGrp->_is_nil() )
676       return SMESH::SMESH_Group::_nil();
677
678     SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
679     SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
680
681     TColStd_MapOfInteger aResMap;
682
683     for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
684       aResMap.Add( anIds1[ i1 ] );
685
686     for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
687       aResMap.Add( anIds2[ i2 ] );
688
689     SMESH::long_array_var aResIds = new SMESH::long_array;
690     aResIds->length( aResMap.Extent() );
691
692     int resI = 0;
693     TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
694     for( ; anIter.More(); anIter.Next() )
695       aResIds[ resI++ ] = anIter.Key();
696
697     aResGrp->Add( aResIds );
698
699     return aResGrp._retn();
700   }
701   catch( ... )
702   {
703     return SMESH::SMESH_Group::_nil();
704   }
705 }
706   
707 //=============================================================================
708 /*! IntersectGroups
709  *  New group is created. All mesh elements that are 
710  *  present in both initial groups are added to the new one.
711  */
712 //=============================================================================
713 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
714                                                       SMESH::SMESH_GroupBase_ptr theGroup2, 
715                                                       const char* theName )
716   throw (SALOME::SALOME_Exception)
717 {
718   SMESH::SMESH_Group_var aResGrp;
719   
720   if ( theGroup1->_is_nil() || theGroup2->_is_nil() || 
721        theGroup1->GetType() != theGroup2->GetType() )
722     return aResGrp;
723   
724   aResGrp = CreateGroup( theGroup1->GetType(), theName );
725   if ( aResGrp->_is_nil() )
726     return aResGrp;
727   
728   SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
729   SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
730   
731   TColStd_MapOfInteger aMap1;
732   
733   for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
734     aMap1.Add( anIds1[ i1 ] );
735
736   TColStd_SequenceOfInteger aSeq;
737
738   for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
739     if ( aMap1.Contains( anIds2[ i2 ] ) )
740       aSeq.Append( anIds2[ i2 ] );
741   
742   SMESH::long_array_var aResIds = new SMESH::long_array;
743   aResIds->length( aSeq.Length() );
744   
745   for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
746     aResIds[ resI ] = aSeq( resI + 1 );
747   
748   aResGrp->Add( aResIds );
749   
750   return aResGrp._retn();
751 }
752
753 //=============================================================================
754 /*! CutGroups
755  *  New group is created. All mesh elements that are present in 
756  *  main group but do not present in tool group are added to the new one 
757  */
758 //=============================================================================
759 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1, 
760                                                 SMESH::SMESH_GroupBase_ptr theGroup2, 
761                                                 const char* theName )
762   throw (SALOME::SALOME_Exception)
763 {
764   SMESH::SMESH_Group_var aResGrp;
765   
766   if ( theGroup1->_is_nil() || theGroup2->_is_nil() || 
767        theGroup1->GetType() != theGroup2->GetType() )
768     return aResGrp;
769   
770   aResGrp = CreateGroup( theGroup1->GetType(), theName );
771   if ( aResGrp->_is_nil() )
772     return aResGrp;
773   
774   SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
775   SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
776   
777   TColStd_MapOfInteger aMap2;
778   
779   for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
780     aMap2.Add( anIds2[ i2 ] );
781
782
783   TColStd_SequenceOfInteger aSeq;
784   for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
785     if ( !aMap2.Contains( anIds1[ i1 ] ) )
786       aSeq.Append( anIds1[ i1 ] );
787
788   SMESH::long_array_var aResIds = new SMESH::long_array;
789   aResIds->length( aSeq.Length() );
790
791   for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
792     aResIds[ resI ] = aSeq( resI + 1 );  
793   
794   aResGrp->Add( aResIds );
795   
796   return aResGrp._retn();
797 }
798
799 //=============================================================================
800 /*!
801  *  
802  */
803 //=============================================================================
804
805 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
806 {
807   if(MYDEBUG) MESSAGE( "createSubMesh" );
808   TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
809
810   ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
811   int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
812   SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
813   SMESH::SMESH_subMesh_var subMesh
814     = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
815
816   _mapSubMesh[subMeshId] = mySubMesh;
817   _mapSubMesh_i[subMeshId] = subMeshServant;
818   _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
819
820   // register CORBA object for persistence
821   int nextId = _gen_i->RegisterObject( subMesh );
822   if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
823
824   return subMesh._retn(); 
825 }
826
827 //=======================================================================
828 //function : getSubMesh
829 //purpose  : 
830 //=======================================================================
831
832 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
833 {
834   map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
835   if ( it == _mapSubMeshIor.end() )
836     return SMESH::SMESH_subMesh::_nil();
837
838   return SMESH::SMESH_subMesh::_duplicate( (*it).second );
839 }
840
841
842 //=============================================================================
843 /*!
844  *  
845  */
846 //=============================================================================
847
848 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
849                                   GEOM::GEOM_Object_ptr    theSubShapeObject )
850 {
851   MESSAGE("SMESH_Mesh_i::removeSubMesh()");
852   if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
853     return;
854
855   try {
856     SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
857     for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
858       removeHypothesis( theSubShapeObject, aHypList[i] );
859     }
860   }
861   catch( const SALOME::SALOME_Exception& ) {
862     INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
863   }
864
865   int subMeshId = theSubMesh->GetId();
866
867   _mapSubMesh.erase(subMeshId);
868   _mapSubMesh_i.erase(subMeshId);
869   _mapSubMeshIor.erase(subMeshId);
870   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
871 }
872
873 //=============================================================================
874 /*!
875  *  
876  */
877 //=============================================================================
878
879 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
880                                                       const char*         theName,
881                                                       const TopoDS_Shape& theShape )
882 {
883   int anId;
884   SMESH::SMESH_GroupBase_var aGroup;
885   if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
886     SMESH_GroupBase_i* aGroupImpl;
887     if ( !theShape.IsNull() )
888       aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
889     else
890       aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
891
892     // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
893     SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
894     aGroupImpl->Register();
895     // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
896
897     aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
898     _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
899
900     // register CORBA object for persistence
901     int nextId = _gen_i->RegisterObject( aGroup );
902     if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
903   }
904   return aGroup._retn();
905 }
906
907 //=============================================================================
908 /*!
909  * SMESH_Mesh_i::removeGroup
910  *
911  * Should be called by ~SMESH_Group_i() 
912  */
913 //=============================================================================
914
915 void SMESH_Mesh_i::removeGroup( const int theId )
916 {
917   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );  
918   if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
919     _mapGroups.erase( theId );
920     _impl->RemoveGroup( theId );
921   }
922 }
923
924
925 //=============================================================================
926 /*!
927  *  
928  */
929 //=============================================================================
930
931 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
932 throw(SALOME::SALOME_Exception)
933 {
934   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
935   
936   SMESH::log_array_var aLog;
937   try{
938     list < SMESHDS_Command * >logDS = _impl->GetLog();
939     aLog = new SMESH::log_array;
940     int indexLog = 0;
941     int lg = logDS.size();
942     SCRUTE(lg);
943     aLog->length(lg);
944     list < SMESHDS_Command * >::iterator its = logDS.begin();
945     while(its != logDS.end()){
946       SMESHDS_Command *com = *its;
947       int comType = com->GetType();
948       //SCRUTE(comType);
949       int lgcom = com->GetNumber();
950       //SCRUTE(lgcom);
951       const list < int >&intList = com->GetIndexes();
952       int inum = intList.size();
953       //SCRUTE(inum);
954       list < int >::const_iterator ii = intList.begin();
955       const list < double >&coordList = com->GetCoords();
956       int rnum = coordList.size();
957       //SCRUTE(rnum);
958       list < double >::const_iterator ir = coordList.begin();
959       aLog[indexLog].commandType = comType;
960       aLog[indexLog].number = lgcom;
961       aLog[indexLog].coords.length(rnum);
962       aLog[indexLog].indexes.length(inum);
963       for(int i = 0; i < rnum; i++){
964         aLog[indexLog].coords[i] = *ir;
965         //MESSAGE(" "<<i<<" "<<ir.Value());
966         ir++;
967       }
968       for(int i = 0; i < inum; i++){
969         aLog[indexLog].indexes[i] = *ii;
970         //MESSAGE(" "<<i<<" "<<ii.Value());
971         ii++;
972       }
973       indexLog++;
974       its++;
975     }
976     if(clearAfterGet)
977       _impl->ClearLog();
978   }
979   catch(SALOME_Exception & S_ex){
980     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
981   }
982   return aLog._retn();
983 }
984
985
986 //=============================================================================
987 /*!
988  *  
989  */
990 //=============================================================================
991
992 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
993 {
994   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
995   // ****
996 }
997
998 //=============================================================================
999 /*!
1000  *  
1001  */
1002 //=============================================================================
1003
1004 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1005 {
1006   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1007   return _id;
1008 }
1009
1010 //=============================================================================
1011 /*!
1012  *  
1013  */
1014 //=============================================================================
1015
1016 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1017 {
1018   return _studyId;
1019 }
1020
1021 //=============================================================================
1022 /*!
1023  *  
1024  */
1025 //=============================================================================
1026
1027 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1028 {
1029   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1030   _impl = impl;
1031 }
1032
1033 //=============================================================================
1034 /*!
1035  *  
1036  */
1037 //=============================================================================
1038
1039 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1040 {
1041   if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1042   return *_impl;
1043 }
1044
1045
1046 //=============================================================================
1047 /*!
1048  *  
1049  */
1050 //=============================================================================
1051
1052 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1053 {
1054         SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1055         SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1056         return aMesh._retn();
1057 }
1058
1059 //=============================================================================
1060 /*!
1061  *  
1062  */
1063 //=============================================================================
1064
1065 void SMESH_Mesh_i::ExportToMED( const char* file, 
1066                                 CORBA::Boolean auto_groups, 
1067                                 SMESH::MED_VERSION theVersion )
1068   throw(SALOME::SALOME_Exception)
1069 {
1070   Unexpect aCatch(SALOME_SalomeException);
1071   
1072   char* aMeshName = "Mesh";
1073   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1074   if ( !aStudy->_is_nil() ) {
1075     SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1076     if ( !aMeshSO->_is_nil() ) {
1077       aMeshName = aMeshSO->GetName();
1078       //SCRUTE(file);
1079       //SCRUTE(aMeshName);
1080       //SCRUTE(aMeshSO->GetID());
1081       
1082       // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes 
1083       if ( !aStudy->GetProperties()->IsLocked() ) 
1084         {
1085         SALOMEDS::GenericAttribute_var anAttr;
1086         SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1087         SALOMEDS::AttributeExternalFileDef_var aFileName;
1088         anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1089         aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1090         ASSERT(!aFileName->_is_nil());
1091         aFileName->SetValue(file);
1092         SALOMEDS::AttributeFileType_var aFileType;
1093         anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1094         aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1095         ASSERT(!aFileType->_is_nil());
1096         aFileType->SetValue("FICHIERMED");
1097         }
1098     }
1099   }
1100   _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1101 }
1102
1103 void SMESH_Mesh_i::ExportMED( const char* file, 
1104                               CORBA::Boolean auto_groups)
1105   throw(SALOME::SALOME_Exception)
1106 {
1107   ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1108 }
1109
1110 void SMESH_Mesh_i::ExportDAT(const char *file) throw(SALOME::SALOME_Exception)
1111 {
1112   Unexpect aCatch(SALOME_SalomeException);
1113   _impl->ExportDAT(file);
1114 }
1115 void SMESH_Mesh_i::ExportUNV(const char *file) throw(SALOME::SALOME_Exception)
1116 {
1117   Unexpect aCatch(SALOME_SalomeException);
1118   _impl->ExportUNV(file);
1119 }
1120
1121 void SMESH_Mesh_i::ExportSTL(const char *file, const bool isascii) throw(SALOME::SALOME_Exception)
1122 {
1123   Unexpect aCatch(SALOME_SalomeException);
1124   _impl->ExportSTL(file, isascii);
1125 }
1126
1127 //=============================================================================
1128 /*!
1129  *  
1130  */
1131 //=============================================================================
1132
1133 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1134 {
1135   Unexpect aCatch(SALOME_SalomeException);
1136   SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1137   SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1138   return aMesh._retn();
1139 }
1140
1141 //=============================================================================
1142 /*!
1143  *  
1144  */
1145 //=============================================================================
1146 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1147 {
1148   Unexpect aCatch(SALOME_SalomeException);
1149   return _impl->NbNodes();
1150 }
1151
1152 //=============================================================================
1153 /*!
1154  *  
1155  */
1156 //=============================================================================
1157 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1158 {
1159   Unexpect aCatch(SALOME_SalomeException);
1160   return NbEdges() + NbFaces() + NbVolumes();
1161 }
1162   
1163 //=============================================================================
1164 /*!
1165  *  
1166  */
1167 //=============================================================================
1168 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1169 {
1170   Unexpect aCatch(SALOME_SalomeException);
1171   return _impl->NbEdges();
1172 }
1173
1174 //=============================================================================
1175 /*!
1176  *  
1177  */
1178 //=============================================================================
1179 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1180 {
1181   Unexpect aCatch(SALOME_SalomeException);
1182   return _impl->NbFaces();
1183 }
1184
1185 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1186 {
1187   Unexpect aCatch(SALOME_SalomeException);
1188   return _impl->NbTriangles();
1189 }
1190
1191 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1192 {
1193   Unexpect aCatch(SALOME_SalomeException);
1194   return _impl->NbQuadrangles();
1195 }
1196
1197 //=============================================================================
1198 /*!
1199  *  
1200  */
1201 //=============================================================================
1202 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1203 {
1204   Unexpect aCatch(SALOME_SalomeException);
1205   return _impl->NbVolumes();
1206 }
1207
1208 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1209 {
1210   Unexpect aCatch(SALOME_SalomeException);
1211   return _impl->NbTetras();
1212 }
1213
1214 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1215 {
1216   Unexpect aCatch(SALOME_SalomeException);
1217   return _impl->NbHexas();
1218 }
1219
1220 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1221 {
1222   Unexpect aCatch(SALOME_SalomeException);
1223   return _impl->NbPyramids();
1224 }
1225
1226 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1227 {
1228   Unexpect aCatch(SALOME_SalomeException);
1229   return _impl->NbPrisms();
1230 }
1231
1232 //=============================================================================
1233 /*!
1234  *  
1235  */
1236 //=============================================================================
1237 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1238 {
1239   Unexpect aCatch(SALOME_SalomeException);
1240   return _impl->NbSubMesh();
1241 }
1242
1243 //=============================================================================
1244 /*!
1245  *  
1246  */
1247 //=============================================================================
1248 char* SMESH_Mesh_i::Dump()
1249 {
1250   std::ostringstream os;
1251   _impl->Dump( os );
1252   return CORBA::string_dup( os.str().c_str() );
1253 }
1254
1255 //=============================================================================
1256 /*!
1257  *  
1258  */
1259 //=============================================================================
1260 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1261 {
1262   SMESH::long_array_var aResult = new SMESH::long_array();
1263   SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1264   int aMinId = aSMESHDS_Mesh->MinElementID();
1265   int aMaxId =  aSMESHDS_Mesh->MaxElementID();
1266
1267   aResult->length(aMaxId - aMinId + 1);
1268   
1269   for (int i = 0, id = aMinId; id <= aMaxId; id++  )
1270     aResult[i++] = id;
1271   
1272   return aResult._retn();
1273 }
1274
1275 //=============================================================================
1276 /*!
1277  *  
1278  */
1279 //=============================================================================
1280   
1281 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1282      throw (SALOME::SALOME_Exception)
1283 {
1284   Unexpect aCatch(SALOME_SalomeException);
1285   MESSAGE("SMESH_Mesh_i::GetElementsId");
1286   SMESH::long_array_var aResult = new SMESH::long_array();
1287   SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1288
1289   if ( aSMESHDS_Mesh == NULL )
1290     return aResult._retn();
1291
1292   long nbElements = NbElements();
1293   aResult->length( nbElements );
1294   SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1295   for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1296     aResult[i] = anIt->next()->GetID();
1297
1298   return aResult._retn();
1299 }
1300
1301
1302 //=============================================================================
1303 /*!
1304  *  
1305  */
1306 //=============================================================================
1307
1308 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1309     throw (SALOME::SALOME_Exception)
1310 {
1311   Unexpect aCatch(SALOME_SalomeException);
1312   MESSAGE("SMESH_subMesh_i::GetElementsByType");
1313   SMESH::long_array_var aResult = new SMESH::long_array();
1314   SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1315
1316   if ( aSMESHDS_Mesh == NULL )
1317     return aResult._retn();
1318
1319   long nbElements = NbElements();
1320
1321   // No sense in returning ids of elements along with ids of nodes:
1322   // when theElemType == SMESH::ALL, return node ids only if
1323   // there are no elements
1324   if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1325     return GetNodesId();
1326
1327   aResult->length( nbElements );
1328
1329   int i = 0;
1330
1331   SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1332   while ( i < nbElements && anIt->more() ) {
1333     const SMDS_MeshElement* anElem = anIt->next();
1334     if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1335       aResult[i++] = anElem->GetID();
1336   }
1337
1338   aResult->length( i );
1339
1340   return aResult._retn();
1341 }
1342
1343 //=============================================================================
1344 /*!
1345  *  
1346  */
1347 //=============================================================================
1348   
1349 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1350   throw (SALOME::SALOME_Exception)
1351 {
1352   Unexpect aCatch(SALOME_SalomeException);
1353   MESSAGE("SMESH_subMesh_i::GetNodesId");
1354   SMESH::long_array_var aResult = new SMESH::long_array();
1355   SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1356
1357   if ( aSMESHDS_Mesh == NULL )
1358     return aResult._retn();
1359
1360   long nbNodes = NbNodes();
1361   aResult->length( nbNodes );
1362   SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1363   for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1364     aResult[i] = anIt->next()->GetID();
1365
1366   return aResult._retn();
1367 }
1368