1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Mesh_i.cxx
25 // Author : Paul RASCLE, EDF
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 #include "SMESH_PythonDump.hxx"
36 #include "Utils_CorbaException.hxx"
37 #include "Utils_ExceptHandlers.hxx"
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "Utils_SINGLETON.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"
51 #include <OSD_Path.hxx>
52 #include <OSD_File.hxx>
53 #include <OSD_Directory.hxx>
54 #include <OSD_Protection.hxx>
55 #include <TColStd_MapOfInteger.hxx>
56 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
57 #include <TColStd_SequenceOfInteger.hxx>
58 #include "TCollection_AsciiString.hxx"
66 static int MYDEBUG = 0;
68 static int MYDEBUG = 0;
72 using SMESH::TPythonDump;
74 int SMESH_Mesh_i::myIdGenerator = 0;
76 //=============================================================================
80 //=============================================================================
82 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
85 : SALOME::GenericObj_i( thePOA )
87 INFOS("SMESH_Mesh_i");
90 _id = myIdGenerator++;
92 thePOA->activate_object( this );
95 //=============================================================================
99 //=============================================================================
101 SMESH_Mesh_i::~SMESH_Mesh_i()
103 INFOS("~SMESH_Mesh_i");
104 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
105 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
106 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
109 // this method is colled from destructor of group (PAL6331)
110 //_impl->RemoveGroup( aGroup->GetLocalID() );
118 //=============================================================================
122 * Associates <this> mesh with <theShape> and puts a reference
123 * to <theShape> into the current study;
124 * the previous shape is substituted by the new one.
126 //=============================================================================
128 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
129 throw (SALOME::SALOME_Exception)
131 Unexpect aCatch(SALOME_SalomeException);
133 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
135 catch(SALOME_Exception & S_ex) {
136 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
140 //=======================================================================
141 //function : GetShapeToMesh
143 //=======================================================================
145 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
146 throw (SALOME::SALOME_Exception)
148 Unexpect aCatch(SALOME_SalomeException);
149 GEOM::GEOM_Object_var aShapeObj;
151 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
153 aShapeObj = _gen_i->ShapeToGeomObject( S );
155 catch(SALOME_Exception & S_ex) {
156 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
158 return aShapeObj._retn();
161 //=============================================================================
165 //=============================================================================
167 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
169 SMESH::DriverMED_ReadStatus res;
172 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
173 res = SMESH::DRS_OK; break;
174 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
175 res = SMESH::DRS_EMPTY; break;
176 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
177 res = SMESH::DRS_WARN_RENUMBER; break;
178 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
179 res = SMESH::DRS_WARN_SKIP_ELEM; break;
180 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
182 res = SMESH::DRS_FAIL; break;
187 //=============================================================================
191 * Imports mesh data from MED file
193 //=============================================================================
195 SMESH::DriverMED_ReadStatus
196 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
197 throw ( SALOME::SALOME_Exception )
199 Unexpect aCatch(SALOME_SalomeException);
202 status = importMEDFile( theFileName, theMeshName );
204 catch( SALOME_Exception& S_ex ) {
205 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
208 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
211 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
212 if ( !aStudy->_is_nil() ) {
213 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
214 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
215 for (; it != _mapGroups.end(); it++ ) {
216 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
217 _gen_i->PublishGroup( aStudy, _this(), aGroup,
218 GEOM::GEOM_Object::_nil(), aGroup->GetName());
221 return ConvertDriverMEDReadStatus(status);
224 //=============================================================================
228 * Imports mesh data from MED file
230 //=============================================================================
232 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
233 throw ( SALOME::SALOME_Exception )
235 // Read mesh with name = <theMeshName> into SMESH_Mesh
236 _impl->UNVToMesh( theFileName );
241 //=============================================================================
245 * Imports mesh data from STL file
247 //=============================================================================
248 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
249 throw ( SALOME::SALOME_Exception )
251 // Read mesh with name = <theMeshName> into SMESH_Mesh
252 _impl->STLToMesh( theFileName );
257 //=============================================================================
261 * Imports mesh data from MED file
263 //=============================================================================
265 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
267 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
268 int status = _impl->MEDToMesh( theFileName, theMeshName );
270 // Create group servants, if any groups were imported
271 list<int> aGroupIds = _impl->GetGroupIds();
272 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
273 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
275 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
276 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
277 aGroupImpl->Register();
278 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
280 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
281 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
283 // register CORBA object for persistence
284 int nextId = _gen_i->RegisterObject( aGroup );
285 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
291 //=============================================================================
295 //=============================================================================
297 static SMESH::Hypothesis_Status ConvertHypothesisStatus
298 (SMESH_Hypothesis::Hypothesis_Status theStatus)
300 SMESH::Hypothesis_Status res;
303 case SMESH_Hypothesis::HYP_OK:
304 res = SMESH::HYP_OK; break;
305 case SMESH_Hypothesis::HYP_MISSING:
306 res = SMESH::HYP_MISSING; break;
307 case SMESH_Hypothesis::HYP_CONCURENT:
308 res = SMESH::HYP_CONCURENT; break;
309 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
310 res = SMESH::HYP_BAD_PARAMETER; break;
311 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
312 res = SMESH::HYP_INCOMPATIBLE; break;
313 case SMESH_Hypothesis::HYP_NOTCONFORM:
314 res = SMESH::HYP_NOTCONFORM; break;
315 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
316 res = SMESH::HYP_ALREADY_EXIST; break;
317 case SMESH_Hypothesis::HYP_BAD_DIM:
318 res = SMESH::HYP_BAD_DIM; break;
319 case SMESH_Hypothesis::HYP_BAD_SUBSHAPE:
320 res = SMESH::HYP_BAD_SUBSHAPE; break;
322 res = SMESH::HYP_UNKNOWN_FATAL;
327 //=============================================================================
331 * calls internal addHypothesis() and then adds a reference to <anHyp> under
332 * the SObject actually having a reference to <aSubShape>.
333 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
335 //=============================================================================
337 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
338 SMESH::SMESH_Hypothesis_ptr anHyp)
339 throw(SALOME::SALOME_Exception)
341 Unexpect aCatch(SALOME_SalomeException);
342 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
344 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
345 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
346 aSubShapeObject, anHyp );
348 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
350 // Update Python script
351 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
352 << aSubShapeObject << ", " << anHyp << " )";
354 return ConvertHypothesisStatus(status);
357 //=============================================================================
361 //=============================================================================
363 SMESH_Hypothesis::Hypothesis_Status
364 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
365 SMESH::SMESH_Hypothesis_ptr anHyp)
367 if(MYDEBUG) MESSAGE("addHypothesis");
369 if (CORBA::is_nil(aSubShapeObject))
370 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
373 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
374 if (CORBA::is_nil(myHyp))
375 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
378 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
381 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
382 int hypId = myHyp->GetId();
383 status = _impl->AddHypothesis(myLocSubShape, hypId);
384 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
385 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
386 // assure there is a corresponding submesh
387 if ( !_impl->IsMainShape( myLocSubShape )) {
388 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
389 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
390 createSubMesh( aSubShapeObject );
394 catch(SALOME_Exception & S_ex)
396 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
401 //=============================================================================
405 //=============================================================================
407 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
408 SMESH::SMESH_Hypothesis_ptr anHyp)
409 throw(SALOME::SALOME_Exception)
411 Unexpect aCatch(SALOME_SalomeException);
412 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
414 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
415 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
416 aSubShapeObject, anHyp );
418 // Update Python script
419 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
420 << aSubShapeObject << ", " << anHyp << " )";
422 return ConvertHypothesisStatus(status);
425 //=============================================================================
429 //=============================================================================
431 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
432 SMESH::SMESH_Hypothesis_ptr anHyp)
434 if(MYDEBUG) MESSAGE("removeHypothesis()");
435 // **** proposer liste de subShape (selection multiple)
437 if (CORBA::is_nil(aSubShapeObject))
438 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
441 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
442 if (CORBA::is_nil(myHyp))
443 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
446 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
449 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
450 int hypId = myHyp->GetId();
451 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
452 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
453 _mapHypo.erase( hypId );
455 catch(SALOME_Exception & S_ex)
457 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
462 //=============================================================================
466 //=============================================================================
468 SMESH::ListOfHypothesis *
469 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
470 throw(SALOME::SALOME_Exception)
472 Unexpect aCatch(SALOME_SalomeException);
473 if (MYDEBUG) MESSAGE("GetHypothesisList");
474 if (CORBA::is_nil(aSubShapeObject))
475 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
478 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
481 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
482 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
483 int i = 0, n = aLocalList.size();
486 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
487 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
488 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
489 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
494 catch(SALOME_Exception & S_ex) {
495 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
498 return aList._retn();
501 //=============================================================================
505 //=============================================================================
506 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
507 const char* theName )
508 throw(SALOME::SALOME_Exception)
510 Unexpect aCatch(SALOME_SalomeException);
511 MESSAGE("SMESH_Mesh_i::GetSubMesh");
512 if (CORBA::is_nil(aSubShapeObject))
513 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
516 SMESH::SMESH_subMesh_var subMesh;
517 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
519 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
521 //Get or Create the SMESH_subMesh object implementation
523 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
524 subMesh = getSubMesh( subMeshId );
526 // create a new subMesh object servant if there is none for the shape
527 if ( subMesh->_is_nil() )
528 subMesh = createSubMesh( aSubShapeObject );
530 if ( _gen_i->CanPublishInStudy( subMesh )) {
531 SALOMEDS::SObject_var aSO =
532 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
533 subMesh, aSubShapeObject, theName );
534 if ( !aSO->_is_nil()) {
535 // Update Python script
536 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
537 << aSubShapeObject << ", '" << theName << "' )";
541 catch(SALOME_Exception & S_ex) {
542 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
544 return subMesh._retn();
547 //=============================================================================
551 //=============================================================================
553 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
554 throw (SALOME::SALOME_Exception)
556 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
557 if ( theSubMesh->_is_nil() )
560 GEOM::GEOM_Object_var aSubShapeObject;
561 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
562 if ( !aStudy->_is_nil() ) {
563 // Remove submesh's SObject
564 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
565 if ( !anSO->_is_nil() ) {
566 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
567 SALOMEDS::SObject_var anObj, aRef;
568 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
569 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
571 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
573 // Update Python script
574 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
578 removeSubMesh( theSubMesh, aSubShapeObject.in() );
581 //=============================================================================
585 //=============================================================================
586 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
587 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
589 switch (theElemType) {
594 CASE2STRING( VOLUME );
600 //=============================================================================
604 //=============================================================================
606 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
607 const char* theName )
608 throw(SALOME::SALOME_Exception)
610 Unexpect aCatch(SALOME_SalomeException);
611 SMESH::SMESH_Group_var aNewGroup =
612 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
614 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
615 SALOMEDS::SObject_var aSO =
616 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
617 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
618 if ( !aSO->_is_nil()) {
619 // Update Python script
620 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
621 << ElementTypeString(theElemType) << ", '" << theName << "' )";
624 return aNewGroup._retn();
628 //=============================================================================
632 //=============================================================================
633 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
635 GEOM::GEOM_Object_ptr theGeomObj)
636 throw(SALOME::SALOME_Exception)
638 Unexpect aCatch(SALOME_SalomeException);
639 SMESH::SMESH_GroupOnGeom_var aNewGroup;
641 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
642 if ( !aShape.IsNull() ) {
643 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
644 ( createGroup( theElemType, theName, aShape ));
645 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
646 SALOMEDS::SObject_var aSO =
647 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
648 aNewGroup, theGeomObj, theName);
649 if ( !aSO->_is_nil()) {
650 // Update Python script
651 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
652 << ElementTypeString(theElemType) << ", '" << theName << "', "
653 << theGeomObj << " )";
658 return aNewGroup._retn();
661 //=============================================================================
665 //=============================================================================
667 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
668 throw (SALOME::SALOME_Exception)
670 if ( theGroup->_is_nil() )
673 SMESH_GroupBase_i* aGroup =
674 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
678 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
679 if ( !aStudy->_is_nil() ) {
680 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
682 if ( !aGroupSO->_is_nil() ) {
683 // Update Python script
684 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
686 // Remove group's SObject
687 aStudy->NewBuilder()->RemoveObject( aGroupSO );
691 // Remove the group from SMESH data structures
692 removeGroup( aGroup->GetLocalID() );
695 //=============================================================================
696 /*! RemoveGroupWithContents
697 * Remove group with its contents
699 //=============================================================================
700 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
701 throw (SALOME::SALOME_Exception)
703 if ( theGroup->_is_nil() )
706 SMESH_GroupBase_i* aGroup =
707 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
711 SMESH::long_array_var anIds = aGroup->GetListOfID();
712 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
714 // Update Python script
715 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
718 if ( aGroup->GetType() == SMESH::NODE )
719 aMeshEditor->RemoveNodes( anIds );
721 aMeshEditor->RemoveElements( anIds );
724 RemoveGroup( theGroup );
726 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
727 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
728 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
731 //=============================================================================
733 * New group is created. All mesh elements that are
734 * present in initial groups are added to the new one
736 //=============================================================================
737 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
738 SMESH::SMESH_GroupBase_ptr theGroup2,
739 const char* theName )
740 throw (SALOME::SALOME_Exception)
744 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
745 theGroup1->GetType() != theGroup2->GetType() )
746 return SMESH::SMESH_Group::_nil();
749 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
750 if ( aResGrp->_is_nil() )
751 return SMESH::SMESH_Group::_nil();
753 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
754 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
756 TColStd_MapOfInteger aResMap;
758 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
759 aResMap.Add( anIds1[ i1 ] );
761 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
762 aResMap.Add( anIds2[ i2 ] );
764 SMESH::long_array_var aResIds = new SMESH::long_array;
765 aResIds->length( aResMap.Extent() );
768 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
769 for( ; anIter.More(); anIter.Next() )
770 aResIds[ resI++ ] = anIter.Key();
772 aResGrp->Add( aResIds );
774 // Clear python lines, created by CreateGroup() and Add()
775 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
776 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
777 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
779 // Update Python script
780 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
781 << theGroup1 << ", " << theGroup2 << ", '"
784 return aResGrp._retn();
788 return SMESH::SMESH_Group::_nil();
792 //=============================================================================
794 * New group is created. All mesh elements that are
795 * present in both initial groups are added to the new one.
797 //=============================================================================
798 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
799 SMESH::SMESH_GroupBase_ptr theGroup2,
800 const char* theName )
801 throw (SALOME::SALOME_Exception)
803 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
804 theGroup1->GetType() != theGroup2->GetType() )
805 return SMESH::SMESH_Group::_nil();
807 // Create Intersection
808 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
809 if ( aResGrp->_is_nil() )
812 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
813 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
815 TColStd_MapOfInteger aMap1;
817 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
818 aMap1.Add( anIds1[ i1 ] );
820 TColStd_SequenceOfInteger aSeq;
822 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
823 if ( aMap1.Contains( anIds2[ i2 ] ) )
824 aSeq.Append( anIds2[ i2 ] );
826 SMESH::long_array_var aResIds = new SMESH::long_array;
827 aResIds->length( aSeq.Length() );
829 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
830 aResIds[ resI ] = aSeq( resI + 1 );
832 aResGrp->Add( aResIds );
834 // Clear python lines, created by CreateGroup() and Add()
835 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
836 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
837 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
839 // Update Python script
840 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
841 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
843 return aResGrp._retn();
846 //=============================================================================
848 * New group is created. All mesh elements that are present in
849 * main group but do not present in tool group are added to the new one
851 //=============================================================================
852 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
853 SMESH::SMESH_GroupBase_ptr theGroup2,
854 const char* theName )
855 throw (SALOME::SALOME_Exception)
857 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
858 theGroup1->GetType() != theGroup2->GetType() )
859 return SMESH::SMESH_Group::_nil();
862 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
863 if ( aResGrp->_is_nil() )
866 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
867 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
869 TColStd_MapOfInteger aMap2;
871 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
872 aMap2.Add( anIds2[ i2 ] );
875 TColStd_SequenceOfInteger aSeq;
876 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
877 if ( !aMap2.Contains( anIds1[ i1 ] ) )
878 aSeq.Append( anIds1[ i1 ] );
880 SMESH::long_array_var aResIds = new SMESH::long_array;
881 aResIds->length( aSeq.Length() );
883 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
884 aResIds[ resI ] = aSeq( resI + 1 );
886 aResGrp->Add( aResIds );
888 // Clear python lines, created by CreateGroup() and Add()
889 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
890 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
891 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
893 // Update Python script
894 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
895 << theGroup1 << ", " << theGroup2 << ", '"
898 return aResGrp._retn();
901 //=============================================================================
905 //=============================================================================
907 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
909 if(MYDEBUG) MESSAGE( "createSubMesh" );
910 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
912 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
913 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
914 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
915 SMESH::SMESH_subMesh_var subMesh
916 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
918 _mapSubMesh[subMeshId] = mySubMesh;
919 _mapSubMesh_i[subMeshId] = subMeshServant;
920 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
922 // register CORBA object for persistence
923 int nextId = _gen_i->RegisterObject( subMesh );
924 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
926 return subMesh._retn();
929 //=======================================================================
930 //function : getSubMesh
932 //=======================================================================
934 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
936 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
937 if ( it == _mapSubMeshIor.end() )
938 return SMESH::SMESH_subMesh::_nil();
940 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
944 //=============================================================================
948 //=============================================================================
950 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
951 GEOM::GEOM_Object_ptr theSubShapeObject )
953 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
954 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
958 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
959 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
960 removeHypothesis( theSubShapeObject, aHypList[i] );
963 catch( const SALOME::SALOME_Exception& ) {
964 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
967 int subMeshId = theSubMesh->GetId();
969 _mapSubMesh.erase(subMeshId);
970 _mapSubMesh_i.erase(subMeshId);
971 _mapSubMeshIor.erase(subMeshId);
972 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
975 //=============================================================================
979 //=============================================================================
981 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
983 const TopoDS_Shape& theShape )
986 SMESH::SMESH_GroupBase_var aGroup;
987 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
988 SMESH_GroupBase_i* aGroupImpl;
989 if ( !theShape.IsNull() )
990 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
992 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
994 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
995 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
996 aGroupImpl->Register();
997 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
999 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1000 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1002 // register CORBA object for persistence
1003 int nextId = _gen_i->RegisterObject( aGroup );
1004 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1006 return aGroup._retn();
1009 //=============================================================================
1011 * SMESH_Mesh_i::removeGroup
1013 * Should be called by ~SMESH_Group_i()
1015 //=============================================================================
1017 void SMESH_Mesh_i::removeGroup( const int theId )
1019 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1020 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1021 _mapGroups.erase( theId );
1022 _impl->RemoveGroup( theId );
1027 //=============================================================================
1031 //=============================================================================
1033 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1034 throw(SALOME::SALOME_Exception)
1036 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1038 SMESH::log_array_var aLog;
1040 list < SMESHDS_Command * >logDS = _impl->GetLog();
1041 aLog = new SMESH::log_array;
1043 int lg = logDS.size();
1046 list < SMESHDS_Command * >::iterator its = logDS.begin();
1047 while(its != logDS.end()){
1048 SMESHDS_Command *com = *its;
1049 int comType = com->GetType();
1051 int lgcom = com->GetNumber();
1053 const list < int >&intList = com->GetIndexes();
1054 int inum = intList.size();
1056 list < int >::const_iterator ii = intList.begin();
1057 const list < double >&coordList = com->GetCoords();
1058 int rnum = coordList.size();
1060 list < double >::const_iterator ir = coordList.begin();
1061 aLog[indexLog].commandType = comType;
1062 aLog[indexLog].number = lgcom;
1063 aLog[indexLog].coords.length(rnum);
1064 aLog[indexLog].indexes.length(inum);
1065 for(int i = 0; i < rnum; i++){
1066 aLog[indexLog].coords[i] = *ir;
1067 //MESSAGE(" "<<i<<" "<<ir.Value());
1070 for(int i = 0; i < inum; i++){
1071 aLog[indexLog].indexes[i] = *ii;
1072 //MESSAGE(" "<<i<<" "<<ii.Value());
1081 catch(SALOME_Exception & S_ex){
1082 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1084 return aLog._retn();
1088 //=============================================================================
1092 //=============================================================================
1094 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1096 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1100 //=============================================================================
1104 //=============================================================================
1106 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1108 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1112 //=============================================================================
1116 //=============================================================================
1118 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1123 //=============================================================================
1127 //=============================================================================
1129 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1131 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1135 //=============================================================================
1139 //=============================================================================
1141 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1143 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1148 //=============================================================================
1152 //=============================================================================
1154 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1156 // Create MeshEditor
1157 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1158 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1160 // Update Python script
1161 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1163 return aMesh._retn();
1166 //=============================================================================
1168 * Export in different formats
1170 //=============================================================================
1172 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1174 return _impl->HasDuplicatedGroupNamesMED();
1177 static void PrepareForWriting (const char* file)
1179 TCollection_AsciiString aFullName ((char*)file);
1180 OSD_Path aPath (aFullName);
1181 OSD_File aFile (aPath);
1182 if (aFile.Exists()) {
1183 // existing filesystem node
1184 if (aFile.KindOfFile() == OSD_FILE) {
1185 if (aFile.IsWriteable()) {
1188 if (aFile.Failed()) {
1189 TCollection_AsciiString msg ("File ");
1190 msg += aFullName + " cannot be replaced.";
1191 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1194 TCollection_AsciiString msg ("File ");
1195 msg += aFullName + " cannot be overwritten.";
1196 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1199 TCollection_AsciiString msg ("Location ");
1200 msg += aFullName + " is not a file.";
1201 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1204 // nonexisting file; check if it can be created
1206 aFile.Build(OSD_WriteOnly, OSD_Protection());
1207 if (aFile.Failed()) {
1208 TCollection_AsciiString msg ("You cannot create the file ");
1209 msg += aFullName + ". Check the directory existance and access rights.";
1210 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1218 void SMESH_Mesh_i::ExportToMED (const char* file,
1219 CORBA::Boolean auto_groups,
1220 SMESH::MED_VERSION theVersion)
1221 throw(SALOME::SALOME_Exception)
1223 Unexpect aCatch(SALOME_SalomeException);
1225 // Update Python script
1226 TPythonDump() << _this() << ".ExportToMED( '"
1227 << file << "', " << auto_groups << ", " << theVersion << " )";
1230 PrepareForWriting(file);
1231 char* aMeshName = "Mesh";
1232 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1233 if ( !aStudy->_is_nil() ) {
1234 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1235 if ( !aMeshSO->_is_nil() ) {
1236 aMeshName = aMeshSO->GetName();
1238 //SCRUTE(aMeshName);
1239 //SCRUTE(aMeshSO->GetID());
1241 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1242 if ( !aStudy->GetProperties()->IsLocked() )
1244 SALOMEDS::GenericAttribute_var anAttr;
1245 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1246 SALOMEDS::AttributeExternalFileDef_var aFileName;
1247 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1248 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1249 ASSERT(!aFileName->_is_nil());
1250 aFileName->SetValue(file);
1251 SALOMEDS::AttributeFileType_var aFileType;
1252 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1253 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1254 ASSERT(!aFileType->_is_nil());
1255 aFileType->SetValue("FICHIERMED");
1259 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1262 void SMESH_Mesh_i::ExportMED (const char* file,
1263 CORBA::Boolean auto_groups)
1264 throw(SALOME::SALOME_Exception)
1266 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1269 void SMESH_Mesh_i::ExportDAT (const char *file)
1270 throw(SALOME::SALOME_Exception)
1272 Unexpect aCatch(SALOME_SalomeException);
1274 // Update Python script
1275 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1278 PrepareForWriting(file);
1279 _impl->ExportDAT(file);
1282 void SMESH_Mesh_i::ExportUNV (const char *file)
1283 throw(SALOME::SALOME_Exception)
1285 Unexpect aCatch(SALOME_SalomeException);
1287 // Update Python script
1288 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1291 PrepareForWriting(file);
1292 _impl->ExportUNV(file);
1295 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1296 throw(SALOME::SALOME_Exception)
1298 Unexpect aCatch(SALOME_SalomeException);
1300 // Update Python script
1301 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1304 PrepareForWriting(file);
1305 _impl->ExportSTL(file, isascii);
1308 //=============================================================================
1312 //=============================================================================
1314 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1316 Unexpect aCatch(SALOME_SalomeException);
1317 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1318 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1319 return aMesh._retn();
1322 //=============================================================================
1326 //=============================================================================
1327 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1329 Unexpect aCatch(SALOME_SalomeException);
1330 return _impl->NbNodes();
1333 //=============================================================================
1337 //=============================================================================
1338 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1340 Unexpect aCatch(SALOME_SalomeException);
1341 return NbEdges() + NbFaces() + NbVolumes();
1344 //=============================================================================
1348 //=============================================================================
1349 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1351 Unexpect aCatch(SALOME_SalomeException);
1352 return _impl->NbEdges();
1355 //=============================================================================
1359 //=============================================================================
1360 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1362 Unexpect aCatch(SALOME_SalomeException);
1363 return _impl->NbFaces();
1366 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1368 Unexpect aCatch(SALOME_SalomeException);
1369 return _impl->NbTriangles();
1372 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1374 Unexpect aCatch(SALOME_SalomeException);
1375 return _impl->NbQuadrangles();
1378 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1380 Unexpect aCatch(SALOME_SalomeException);
1381 return _impl->NbPolygons();
1384 //=============================================================================
1388 //=============================================================================
1389 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1391 Unexpect aCatch(SALOME_SalomeException);
1392 return _impl->NbVolumes();
1395 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1397 Unexpect aCatch(SALOME_SalomeException);
1398 return _impl->NbTetras();
1401 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1403 Unexpect aCatch(SALOME_SalomeException);
1404 return _impl->NbHexas();
1407 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1409 Unexpect aCatch(SALOME_SalomeException);
1410 return _impl->NbPyramids();
1413 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1415 Unexpect aCatch(SALOME_SalomeException);
1416 return _impl->NbPrisms();
1419 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1421 Unexpect aCatch(SALOME_SalomeException);
1422 return _impl->NbPolyhedrons();
1425 //=============================================================================
1429 //=============================================================================
1430 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1432 Unexpect aCatch(SALOME_SalomeException);
1433 return _impl->NbSubMesh();
1436 //=============================================================================
1440 //=============================================================================
1441 char* SMESH_Mesh_i::Dump()
1443 std::ostringstream os;
1445 return CORBA::string_dup( os.str().c_str() );
1448 //=============================================================================
1452 //=============================================================================
1453 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1455 SMESH::long_array_var aResult = new SMESH::long_array();
1456 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1457 int aMinId = aSMESHDS_Mesh->MinElementID();
1458 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1460 aResult->length(aMaxId - aMinId + 1);
1462 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1465 return aResult._retn();
1468 //=============================================================================
1472 //=============================================================================
1474 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1475 throw (SALOME::SALOME_Exception)
1477 Unexpect aCatch(SALOME_SalomeException);
1478 MESSAGE("SMESH_Mesh_i::GetElementsId");
1479 SMESH::long_array_var aResult = new SMESH::long_array();
1480 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1482 if ( aSMESHDS_Mesh == NULL )
1483 return aResult._retn();
1485 long nbElements = NbElements();
1486 aResult->length( nbElements );
1487 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1488 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1489 aResult[i] = anIt->next()->GetID();
1491 return aResult._retn();
1495 //=============================================================================
1499 //=============================================================================
1501 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1502 throw (SALOME::SALOME_Exception)
1504 Unexpect aCatch(SALOME_SalomeException);
1505 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1506 SMESH::long_array_var aResult = new SMESH::long_array();
1507 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1509 if ( aSMESHDS_Mesh == NULL )
1510 return aResult._retn();
1512 long nbElements = NbElements();
1514 // No sense in returning ids of elements along with ids of nodes:
1515 // when theElemType == SMESH::ALL, return node ids only if
1516 // there are no elements
1517 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1518 return GetNodesId();
1520 aResult->length( nbElements );
1524 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1525 while ( i < nbElements && anIt->more() ) {
1526 const SMDS_MeshElement* anElem = anIt->next();
1527 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1528 aResult[i++] = anElem->GetID();
1531 aResult->length( i );
1533 return aResult._retn();
1536 //=============================================================================
1540 //=============================================================================
1542 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1543 throw (SALOME::SALOME_Exception)
1545 Unexpect aCatch(SALOME_SalomeException);
1546 MESSAGE("SMESH_subMesh_i::GetNodesId");
1547 SMESH::long_array_var aResult = new SMESH::long_array();
1548 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1550 if ( aSMESHDS_Mesh == NULL )
1551 return aResult._retn();
1553 long nbNodes = NbNodes();
1554 aResult->length( nbNodes );
1555 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1556 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1557 aResult[i] = anIt->next()->GetID();
1559 return aResult._retn();
1562 //=============================================================================
1566 //=============================================================================
1568 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1569 throw (SALOME::SALOME_Exception)
1571 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1574 //=============================================================================
1578 //=============================================================================
1580 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1582 return (CORBA::Long)_impl;