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;
78 //=============================================================================
82 //=============================================================================
84 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
87 : SALOME::GenericObj_i( thePOA )
89 INFOS("SMESH_Mesh_i");
92 _id = myIdGenerator++;
94 thePOA->activate_object( this );
97 //=============================================================================
101 //=============================================================================
103 SMESH_Mesh_i::~SMESH_Mesh_i()
105 INFOS("~SMESH_Mesh_i");
106 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
107 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
108 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
111 // this method is colled from destructor of group (PAL6331)
112 //_impl->RemoveGroup( aGroup->GetLocalID() );
120 //=============================================================================
124 * Associates <this> mesh with <theShape> and puts a reference
125 * to <theShape> into the current study;
126 * the previous shape is substituted by the new one.
128 //=============================================================================
130 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
131 throw (SALOME::SALOME_Exception)
133 Unexpect aCatch(SALOME_SalomeException);
135 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
137 catch(SALOME_Exception & S_ex) {
138 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
142 //=======================================================================
143 //function : GetShapeToMesh
145 //=======================================================================
147 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
148 throw (SALOME::SALOME_Exception)
150 Unexpect aCatch(SALOME_SalomeException);
151 GEOM::GEOM_Object_var aShapeObj;
153 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
155 aShapeObj = _gen_i->ShapeToGeomObject( S );
157 catch(SALOME_Exception & S_ex) {
158 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
160 return aShapeObj._retn();
163 //=============================================================================
167 //=============================================================================
169 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
171 SMESH::DriverMED_ReadStatus res;
174 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
175 res = SMESH::DRS_OK; break;
176 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
177 res = SMESH::DRS_EMPTY; break;
178 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
179 res = SMESH::DRS_WARN_RENUMBER; break;
180 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
181 res = SMESH::DRS_WARN_SKIP_ELEM; break;
182 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
184 res = SMESH::DRS_FAIL; break;
189 //=============================================================================
193 * Imports mesh data from MED file
195 //=============================================================================
197 SMESH::DriverMED_ReadStatus
198 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
199 throw ( SALOME::SALOME_Exception )
201 Unexpect aCatch(SALOME_SalomeException);
204 status = importMEDFile( theFileName, theMeshName );
206 catch( SALOME_Exception& S_ex ) {
207 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
210 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
213 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
214 if ( !aStudy->_is_nil() ) {
215 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
216 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
217 for (; it != _mapGroups.end(); it++ ) {
218 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
219 _gen_i->PublishGroup( aStudy, _this(), aGroup,
220 GEOM::GEOM_Object::_nil(), aGroup->GetName());
223 return ConvertDriverMEDReadStatus(status);
226 //=============================================================================
230 * Imports mesh data from MED file
232 //=============================================================================
234 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
235 throw ( SALOME::SALOME_Exception )
237 // Read mesh with name = <theMeshName> into SMESH_Mesh
238 _impl->UNVToMesh( theFileName );
240 CreateGroupServants();
242 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
243 if ( !aStudy->_is_nil() ) {
244 // publishing of the groups in the study (sub-meshes are out of scope of UNV import)
245 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
246 for (; it != _mapGroups.end(); it++ ) {
247 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
248 _gen_i->PublishGroup( aStudy, _this(), aGroup,
249 GEOM::GEOM_Object::_nil(), aGroup->GetName());
255 //=============================================================================
259 * Imports mesh data from STL file
261 //=============================================================================
262 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
263 throw ( SALOME::SALOME_Exception )
265 // Read mesh with name = <theMeshName> into SMESH_Mesh
266 _impl->STLToMesh( theFileName );
271 //=============================================================================
275 * Imports mesh data from MED file
277 //=============================================================================
279 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
281 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
282 int status = _impl->MEDToMesh( theFileName, theMeshName );
283 CreateGroupServants();
288 //=============================================================================
292 //=============================================================================
294 static SMESH::Hypothesis_Status ConvertHypothesisStatus
295 (SMESH_Hypothesis::Hypothesis_Status theStatus)
297 SMESH::Hypothesis_Status res;
300 case SMESH_Hypothesis::HYP_OK:
301 res = SMESH::HYP_OK; break;
302 case SMESH_Hypothesis::HYP_MISSING:
303 res = SMESH::HYP_MISSING; break;
304 case SMESH_Hypothesis::HYP_CONCURENT:
305 res = SMESH::HYP_CONCURENT; break;
306 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
307 res = SMESH::HYP_BAD_PARAMETER; break;
308 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
309 res = SMESH::HYP_INCOMPATIBLE; break;
310 case SMESH_Hypothesis::HYP_NOTCONFORM:
311 res = SMESH::HYP_NOTCONFORM; break;
312 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
313 res = SMESH::HYP_ALREADY_EXIST; break;
314 case SMESH_Hypothesis::HYP_BAD_DIM:
315 res = SMESH::HYP_BAD_DIM; break;
316 case SMESH_Hypothesis::HYP_BAD_SUBSHAPE:
317 res = SMESH::HYP_BAD_SUBSHAPE; break;
319 res = SMESH::HYP_UNKNOWN_FATAL;
324 //=============================================================================
328 * calls internal addHypothesis() and then adds a reference to <anHyp> under
329 * the SObject actually having a reference to <aSubShape>.
330 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
332 //=============================================================================
334 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
335 SMESH::SMESH_Hypothesis_ptr anHyp)
336 throw(SALOME::SALOME_Exception)
338 Unexpect aCatch(SALOME_SalomeException);
339 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
341 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
342 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
343 aSubShapeObject, anHyp );
345 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
347 // Update Python script
348 TPythonDump() << "status = " << _this() << ".AddHypothesis( "
349 << aSubShapeObject << ", " << anHyp << " )";
351 return ConvertHypothesisStatus(status);
354 //=============================================================================
358 //=============================================================================
360 SMESH_Hypothesis::Hypothesis_Status
361 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
362 SMESH::SMESH_Hypothesis_ptr anHyp)
364 if(MYDEBUG) MESSAGE("addHypothesis");
366 if (CORBA::is_nil(aSubShapeObject))
367 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
370 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
371 if (CORBA::is_nil(myHyp))
372 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
375 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
378 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
379 int hypId = myHyp->GetId();
380 status = _impl->AddHypothesis(myLocSubShape, hypId);
381 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
382 _mapHypo[hypId] = SMESH::SMESH_Hypothesis::_duplicate( myHyp );
383 // assure there is a corresponding submesh
384 if ( !_impl->IsMainShape( myLocSubShape )) {
385 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
386 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
387 createSubMesh( aSubShapeObject );
391 catch(SALOME_Exception & S_ex)
393 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
398 //=============================================================================
402 //=============================================================================
404 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
405 SMESH::SMESH_Hypothesis_ptr anHyp)
406 throw(SALOME::SALOME_Exception)
408 Unexpect aCatch(SALOME_SalomeException);
409 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
411 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
412 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
413 aSubShapeObject, anHyp );
415 // Update Python script
416 TPythonDump() << "status = " << _this() << ".RemoveHypothesis( "
417 << aSubShapeObject << ", " << anHyp << " )";
419 return ConvertHypothesisStatus(status);
422 //=============================================================================
426 //=============================================================================
428 SMESH_Hypothesis::Hypothesis_Status SMESH_Mesh_i::removeHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
429 SMESH::SMESH_Hypothesis_ptr anHyp)
431 if(MYDEBUG) MESSAGE("removeHypothesis()");
432 // **** proposer liste de subShape (selection multiple)
434 if (CORBA::is_nil(aSubShapeObject))
435 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
438 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
439 if (CORBA::is_nil(myHyp))
440 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
443 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
446 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
447 int hypId = myHyp->GetId();
448 status = _impl->RemoveHypothesis(myLocSubShape, hypId);
449 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
450 _mapHypo.erase( hypId );
452 catch(SALOME_Exception & S_ex)
454 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
459 //=============================================================================
463 //=============================================================================
465 SMESH::ListOfHypothesis *
466 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Object_ptr aSubShapeObject)
467 throw(SALOME::SALOME_Exception)
469 Unexpect aCatch(SALOME_SalomeException);
470 if (MYDEBUG) MESSAGE("GetHypothesisList");
471 if (CORBA::is_nil(aSubShapeObject))
472 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
475 SMESH::ListOfHypothesis_var aList = new SMESH::ListOfHypothesis();
478 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
479 const list<const SMESHDS_Hypothesis*>& aLocalList = _impl->GetHypothesisList( myLocSubShape );
480 int i = 0, n = aLocalList.size();
483 for ( list<const SMESHDS_Hypothesis*>::const_iterator anIt = aLocalList.begin(); i < n && anIt != aLocalList.end(); anIt++ ) {
484 SMESHDS_Hypothesis* aHyp = (SMESHDS_Hypothesis*)(*anIt);
485 if ( _mapHypo.find( aHyp->GetID() ) != _mapHypo.end() )
486 aList[i++] = SMESH::SMESH_Hypothesis::_narrow( _mapHypo[aHyp->GetID()] );
491 catch(SALOME_Exception & S_ex) {
492 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
495 return aList._retn();
498 //=============================================================================
502 //=============================================================================
503 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShapeObject,
504 const char* theName )
505 throw(SALOME::SALOME_Exception)
507 Unexpect aCatch(SALOME_SalomeException);
508 MESSAGE("SMESH_Mesh_i::GetSubMesh");
509 if (CORBA::is_nil(aSubShapeObject))
510 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
513 SMESH::SMESH_subMesh_var subMesh;
514 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(_this());
516 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(aSubShapeObject);
518 //Get or Create the SMESH_subMesh object implementation
520 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
521 subMesh = getSubMesh( subMeshId );
523 // create a new subMesh object servant if there is none for the shape
524 if ( subMesh->_is_nil() )
525 subMesh = createSubMesh( aSubShapeObject );
527 if ( _gen_i->CanPublishInStudy( subMesh )) {
528 SALOMEDS::SObject_var aSO =
529 _gen_i->PublishSubMesh(_gen_i->GetCurrentStudy(), aMesh,
530 subMesh, aSubShapeObject, theName );
531 if ( !aSO->_is_nil()) {
532 // Update Python script
533 TPythonDump() << aSO << " = " << _this() << ".GetSubMesh( "
534 << aSubShapeObject << ", '" << theName << "' )";
538 catch(SALOME_Exception & S_ex) {
539 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
541 return subMesh._retn();
544 //=============================================================================
548 //=============================================================================
550 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
551 throw (SALOME::SALOME_Exception)
553 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
554 if ( theSubMesh->_is_nil() )
557 GEOM::GEOM_Object_var aSubShapeObject;
558 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
559 if ( !aStudy->_is_nil() ) {
560 // Remove submesh's SObject
561 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
562 if ( !anSO->_is_nil() ) {
563 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
564 SALOMEDS::SObject_var anObj, aRef;
565 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
566 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
568 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
570 // Update Python script
571 TPythonDump() << _this() << ".RemoveSubMesh( " << anSO << " )";
575 removeSubMesh( theSubMesh, aSubShapeObject.in() );
578 //=============================================================================
582 //=============================================================================
583 #define CASE2STRING(enum) case SMESH::enum: return "SMESH."#enum;
584 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
586 switch (theElemType) {
591 CASE2STRING( VOLUME );
597 //=============================================================================
601 //=============================================================================
603 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
604 const char* theName )
605 throw(SALOME::SALOME_Exception)
607 Unexpect aCatch(SALOME_SalomeException);
608 SMESH::SMESH_Group_var aNewGroup =
609 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
611 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
612 SALOMEDS::SObject_var aSO =
613 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
614 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
615 if ( !aSO->_is_nil()) {
616 // Update Python script
617 TPythonDump() << aSO << " = " << _this() << ".CreateGroup( "
618 << ElementTypeString(theElemType) << ", '" << theName << "' )";
621 return aNewGroup._retn();
625 //=============================================================================
629 //=============================================================================
630 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
632 GEOM::GEOM_Object_ptr theGeomObj)
633 throw(SALOME::SALOME_Exception)
635 Unexpect aCatch(SALOME_SalomeException);
636 SMESH::SMESH_GroupOnGeom_var aNewGroup;
638 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
639 if ( !aShape.IsNull() ) {
640 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
641 ( createGroup( theElemType, theName, aShape ));
642 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
643 SALOMEDS::SObject_var aSO =
644 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
645 aNewGroup, theGeomObj, theName);
646 if ( !aSO->_is_nil()) {
647 // Update Python script
648 TPythonDump() << aSO << " = " << _this() << ".CreateGroupFromGEOM("
649 << ElementTypeString(theElemType) << ", '" << theName << "', "
650 << theGeomObj << " )";
655 return aNewGroup._retn();
658 //=============================================================================
662 //=============================================================================
664 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
665 throw (SALOME::SALOME_Exception)
667 if ( theGroup->_is_nil() )
670 SMESH_GroupBase_i* aGroup =
671 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
675 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
676 if ( !aStudy->_is_nil() ) {
677 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
679 if ( !aGroupSO->_is_nil() ) {
680 // Update Python script
681 TPythonDump() << _this() << ".RemoveGroup( " << aGroupSO << " )";
683 // Remove group's SObject
684 aStudy->NewBuilder()->RemoveObject( aGroupSO );
688 // Remove the group from SMESH data structures
689 removeGroup( aGroup->GetLocalID() );
692 //=============================================================================
693 /*! RemoveGroupWithContents
694 * Remove group with its contents
696 //=============================================================================
697 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
698 throw (SALOME::SALOME_Exception)
700 if ( theGroup->_is_nil() )
703 SMESH_GroupBase_i* aGroup =
704 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
708 SMESH::long_array_var anIds = aGroup->GetListOfID();
709 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
711 // Update Python script
712 TPythonDump() << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
715 if ( aGroup->GetType() == SMESH::NODE )
716 aMeshEditor->RemoveNodes( anIds );
718 aMeshEditor->RemoveElements( anIds );
721 RemoveGroup( theGroup );
723 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
724 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
725 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
728 //=============================================================================
730 * New group is created. All mesh elements that are
731 * present in initial groups are added to the new one
733 //=============================================================================
734 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
735 SMESH::SMESH_GroupBase_ptr theGroup2,
736 const char* theName )
737 throw (SALOME::SALOME_Exception)
741 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
742 theGroup1->GetType() != theGroup2->GetType() )
743 return SMESH::SMESH_Group::_nil();
746 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
747 if ( aResGrp->_is_nil() )
748 return SMESH::SMESH_Group::_nil();
750 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
751 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
753 TColStd_MapOfInteger aResMap;
755 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
756 aResMap.Add( anIds1[ i1 ] );
758 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
759 aResMap.Add( anIds2[ i2 ] );
761 SMESH::long_array_var aResIds = new SMESH::long_array;
762 aResIds->length( aResMap.Extent() );
765 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
766 for( ; anIter.More(); anIter.Next() )
767 aResIds[ resI++ ] = anIter.Key();
769 aResGrp->Add( aResIds );
771 // Clear python lines, created by CreateGroup() and Add()
772 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
773 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
774 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
776 // Update Python script
777 TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
778 << theGroup1 << ", " << theGroup2 << ", '"
781 return aResGrp._retn();
785 return SMESH::SMESH_Group::_nil();
789 //=============================================================================
791 * New group is created. All mesh elements that are
792 * present in both initial groups are added to the new one.
794 //=============================================================================
795 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
796 SMESH::SMESH_GroupBase_ptr theGroup2,
797 const char* theName )
798 throw (SALOME::SALOME_Exception)
800 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
801 theGroup1->GetType() != theGroup2->GetType() )
802 return SMESH::SMESH_Group::_nil();
804 // Create Intersection
805 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
806 if ( aResGrp->_is_nil() )
809 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
810 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
812 TColStd_MapOfInteger aMap1;
814 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
815 aMap1.Add( anIds1[ i1 ] );
817 TColStd_SequenceOfInteger aSeq;
819 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
820 if ( aMap1.Contains( anIds2[ i2 ] ) )
821 aSeq.Append( anIds2[ i2 ] );
823 SMESH::long_array_var aResIds = new SMESH::long_array;
824 aResIds->length( aSeq.Length() );
826 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
827 aResIds[ resI ] = aSeq( resI + 1 );
829 aResGrp->Add( aResIds );
831 // Clear python lines, created by CreateGroup() and Add()
832 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
833 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
834 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
836 // Update Python script
837 TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
838 << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
840 return aResGrp._retn();
843 //=============================================================================
845 * New group is created. All mesh elements that are present in
846 * main group but do not present in tool group are added to the new one
848 //=============================================================================
849 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
850 SMESH::SMESH_GroupBase_ptr theGroup2,
851 const char* theName )
852 throw (SALOME::SALOME_Exception)
854 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
855 theGroup1->GetType() != theGroup2->GetType() )
856 return SMESH::SMESH_Group::_nil();
859 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
860 if ( aResGrp->_is_nil() )
863 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
864 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
866 TColStd_MapOfInteger aMap2;
868 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
869 aMap2.Add( anIds2[ i2 ] );
872 TColStd_SequenceOfInteger aSeq;
873 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
874 if ( !aMap2.Contains( anIds1[ i1 ] ) )
875 aSeq.Append( anIds1[ i1 ] );
877 SMESH::long_array_var aResIds = new SMESH::long_array;
878 aResIds->length( aSeq.Length() );
880 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
881 aResIds[ resI ] = aSeq( resI + 1 );
883 aResGrp->Add( aResIds );
885 // Clear python lines, created by CreateGroup() and Add()
886 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
887 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
888 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
890 // Update Python script
891 TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
892 << theGroup1 << ", " << theGroup2 << ", '"
895 return aResGrp._retn();
898 //=============================================================================
902 //=============================================================================
904 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
906 if(MYDEBUG) MESSAGE( "createSubMesh" );
907 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
909 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
910 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
911 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
912 SMESH::SMESH_subMesh_var subMesh
913 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
915 _mapSubMesh[subMeshId] = mySubMesh;
916 _mapSubMesh_i[subMeshId] = subMeshServant;
917 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
919 // register CORBA object for persistence
920 int nextId = _gen_i->RegisterObject( subMesh );
921 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
923 return subMesh._retn();
926 //=======================================================================
927 //function : getSubMesh
929 //=======================================================================
931 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
933 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
934 if ( it == _mapSubMeshIor.end() )
935 return SMESH::SMESH_subMesh::_nil();
937 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
941 //=============================================================================
945 //=============================================================================
947 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
948 GEOM::GEOM_Object_ptr theSubShapeObject )
950 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
951 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
955 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
956 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
957 removeHypothesis( theSubShapeObject, aHypList[i] );
960 catch( const SALOME::SALOME_Exception& ) {
961 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
964 int subMeshId = theSubMesh->GetId();
966 _mapSubMesh.erase(subMeshId);
967 _mapSubMesh_i.erase(subMeshId);
968 _mapSubMeshIor.erase(subMeshId);
969 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
972 //=============================================================================
976 //=============================================================================
978 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
980 const TopoDS_Shape& theShape )
983 SMESH::SMESH_GroupBase_var aGroup;
984 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
985 SMESH_GroupBase_i* aGroupImpl;
986 if ( !theShape.IsNull() )
987 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
989 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
991 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
992 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
993 aGroupImpl->Register();
994 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
996 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
997 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
999 // register CORBA object for persistence
1000 int nextId = _gen_i->RegisterObject( aGroup );
1001 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1003 return aGroup._retn();
1006 //=============================================================================
1008 * SMESH_Mesh_i::removeGroup
1010 * Should be called by ~SMESH_Group_i()
1012 //=============================================================================
1014 void SMESH_Mesh_i::removeGroup( const int theId )
1016 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1017 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1018 _mapGroups.erase( theId );
1019 _impl->RemoveGroup( theId );
1024 //=============================================================================
1028 //=============================================================================
1030 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1031 throw(SALOME::SALOME_Exception)
1033 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1035 SMESH::log_array_var aLog;
1037 list < SMESHDS_Command * >logDS = _impl->GetLog();
1038 aLog = new SMESH::log_array;
1040 int lg = logDS.size();
1043 list < SMESHDS_Command * >::iterator its = logDS.begin();
1044 while(its != logDS.end()){
1045 SMESHDS_Command *com = *its;
1046 int comType = com->GetType();
1048 int lgcom = com->GetNumber();
1050 const list < int >&intList = com->GetIndexes();
1051 int inum = intList.size();
1053 list < int >::const_iterator ii = intList.begin();
1054 const list < double >&coordList = com->GetCoords();
1055 int rnum = coordList.size();
1057 list < double >::const_iterator ir = coordList.begin();
1058 aLog[indexLog].commandType = comType;
1059 aLog[indexLog].number = lgcom;
1060 aLog[indexLog].coords.length(rnum);
1061 aLog[indexLog].indexes.length(inum);
1062 for(int i = 0; i < rnum; i++){
1063 aLog[indexLog].coords[i] = *ir;
1064 //MESSAGE(" "<<i<<" "<<ir.Value());
1067 for(int i = 0; i < inum; i++){
1068 aLog[indexLog].indexes[i] = *ii;
1069 //MESSAGE(" "<<i<<" "<<ii.Value());
1078 catch(SALOME_Exception & S_ex){
1079 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1081 return aLog._retn();
1085 //=============================================================================
1089 //=============================================================================
1091 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1093 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1097 //=============================================================================
1101 //=============================================================================
1103 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1105 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1109 //=============================================================================
1113 //=============================================================================
1115 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1120 //=============================================================================
1124 //=============================================================================
1126 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1128 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1132 //=============================================================================
1136 //=============================================================================
1138 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1140 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1145 //=============================================================================
1149 //=============================================================================
1151 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1153 // Create MeshEditor
1154 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1155 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1157 // Update Python script
1158 TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
1160 return aMesh._retn();
1163 //=============================================================================
1165 * Export in different formats
1167 //=============================================================================
1169 CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
1171 return _impl->HasDuplicatedGroupNamesMED();
1174 static void PrepareForWriting (const char* file)
1176 TCollection_AsciiString aFullName ((char*)file);
1177 OSD_Path aPath (aFullName);
1178 OSD_File aFile (aPath);
1179 if (aFile.Exists()) {
1180 // existing filesystem node
1181 if (aFile.KindOfFile() == OSD_FILE) {
1182 if (aFile.IsWriteable()) {
1185 if (aFile.Failed()) {
1186 TCollection_AsciiString msg ("File ");
1187 msg += aFullName + " cannot be replaced.";
1188 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1191 TCollection_AsciiString msg ("File ");
1192 msg += aFullName + " cannot be overwritten.";
1193 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1196 TCollection_AsciiString msg ("Location ");
1197 msg += aFullName + " is not a file.";
1198 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1201 // nonexisting file; check if it can be created
1203 aFile.Build(OSD_WriteOnly, OSD_Protection());
1204 if (aFile.Failed()) {
1205 TCollection_AsciiString msg ("You cannot create the file ");
1206 msg += aFullName + ". Check the directory existance and access rights.";
1207 THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
1215 void SMESH_Mesh_i::ExportToMED (const char* file,
1216 CORBA::Boolean auto_groups,
1217 SMESH::MED_VERSION theVersion)
1218 throw(SALOME::SALOME_Exception)
1220 Unexpect aCatch(SALOME_SalomeException);
1222 // Update Python script
1223 TPythonDump() << _this() << ".ExportToMED( '"
1224 << file << "', " << auto_groups << ", " << theVersion << " )";
1227 PrepareForWriting(file);
1228 char* aMeshName = "Mesh";
1229 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1230 if ( !aStudy->_is_nil() ) {
1231 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1232 if ( !aMeshSO->_is_nil() ) {
1233 aMeshName = aMeshSO->GetName();
1235 //SCRUTE(aMeshName);
1236 //SCRUTE(aMeshSO->GetID());
1238 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1239 if ( !aStudy->GetProperties()->IsLocked() )
1241 SALOMEDS::GenericAttribute_var anAttr;
1242 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1243 SALOMEDS::AttributeExternalFileDef_var aFileName;
1244 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1245 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1246 ASSERT(!aFileName->_is_nil());
1247 aFileName->SetValue(file);
1248 SALOMEDS::AttributeFileType_var aFileType;
1249 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1250 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1251 ASSERT(!aFileType->_is_nil());
1252 aFileType->SetValue("FICHIERMED");
1256 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1259 void SMESH_Mesh_i::ExportMED (const char* file,
1260 CORBA::Boolean auto_groups)
1261 throw(SALOME::SALOME_Exception)
1263 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1266 void SMESH_Mesh_i::ExportDAT (const char *file)
1267 throw(SALOME::SALOME_Exception)
1269 Unexpect aCatch(SALOME_SalomeException);
1271 // Update Python script
1272 TPythonDump() << _this() << ".ExportDAT( '" << file << "' )";
1275 PrepareForWriting(file);
1276 _impl->ExportDAT(file);
1279 void SMESH_Mesh_i::ExportUNV (const char *file)
1280 throw(SALOME::SALOME_Exception)
1282 Unexpect aCatch(SALOME_SalomeException);
1284 // Update Python script
1285 TPythonDump() << _this() << ".ExportUNV( '" << file << "' )";
1288 PrepareForWriting(file);
1289 _impl->ExportUNV(file);
1292 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1293 throw(SALOME::SALOME_Exception)
1295 Unexpect aCatch(SALOME_SalomeException);
1297 // Update Python script
1298 TPythonDump() << _this() << ".ExportSTL( '" << file << "', " << isascii << " )";
1301 PrepareForWriting(file);
1302 _impl->ExportSTL(file, isascii);
1305 //=============================================================================
1309 //=============================================================================
1311 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1313 Unexpect aCatch(SALOME_SalomeException);
1314 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1315 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1316 return aMesh._retn();
1319 //=============================================================================
1323 //=============================================================================
1324 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1326 Unexpect aCatch(SALOME_SalomeException);
1327 return _impl->NbNodes();
1330 //=============================================================================
1334 //=============================================================================
1335 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1337 Unexpect aCatch(SALOME_SalomeException);
1338 return NbEdges() + NbFaces() + NbVolumes();
1341 //=============================================================================
1345 //=============================================================================
1346 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1348 Unexpect aCatch(SALOME_SalomeException);
1349 return _impl->NbEdges();
1352 CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
1353 throw(SALOME::SALOME_Exception)
1355 Unexpect aCatch(SALOME_SalomeException);
1356 return _impl->NbEdges( (::SMESH_Mesh::ElementOrder) order);
1359 //=============================================================================
1363 //=============================================================================
1364 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1366 Unexpect aCatch(SALOME_SalomeException);
1367 return _impl->NbFaces();
1370 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1372 Unexpect aCatch(SALOME_SalomeException);
1373 return _impl->NbTriangles();
1376 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1378 Unexpect aCatch(SALOME_SalomeException);
1379 return _impl->NbQuadrangles();
1382 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1384 Unexpect aCatch(SALOME_SalomeException);
1385 return _impl->NbPolygons();
1388 CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
1389 throw(SALOME::SALOME_Exception)
1391 Unexpect aCatch(SALOME_SalomeException);
1392 return _impl->NbFaces( (::SMESH_Mesh::ElementOrder) order);
1395 CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
1396 throw(SALOME::SALOME_Exception)
1398 Unexpect aCatch(SALOME_SalomeException);
1399 return _impl->NbTriangles( (::SMESH_Mesh::ElementOrder) order);
1402 CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
1403 throw(SALOME::SALOME_Exception)
1405 Unexpect aCatch(SALOME_SalomeException);
1406 return _impl->NbQuadrangles( (::SMESH_Mesh::ElementOrder) order);
1409 //=============================================================================
1413 //=============================================================================
1414 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1416 Unexpect aCatch(SALOME_SalomeException);
1417 return _impl->NbVolumes();
1420 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1422 Unexpect aCatch(SALOME_SalomeException);
1423 return _impl->NbTetras();
1426 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1428 Unexpect aCatch(SALOME_SalomeException);
1429 return _impl->NbHexas();
1432 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1434 Unexpect aCatch(SALOME_SalomeException);
1435 return _impl->NbPyramids();
1438 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1440 Unexpect aCatch(SALOME_SalomeException);
1441 return _impl->NbPrisms();
1444 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1446 Unexpect aCatch(SALOME_SalomeException);
1447 return _impl->NbPolyhedrons();
1450 CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
1451 throw(SALOME::SALOME_Exception)
1453 Unexpect aCatch(SALOME_SalomeException);
1454 return _impl->NbVolumes( (::SMESH_Mesh::ElementOrder) order);
1457 CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
1458 throw(SALOME::SALOME_Exception)
1460 Unexpect aCatch(SALOME_SalomeException);
1461 return _impl->NbTetras( (::SMESH_Mesh::ElementOrder) order);
1464 CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
1465 throw(SALOME::SALOME_Exception)
1467 Unexpect aCatch(SALOME_SalomeException);
1468 return _impl->NbHexas( (::SMESH_Mesh::ElementOrder) order);
1471 CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
1472 throw(SALOME::SALOME_Exception)
1474 Unexpect aCatch(SALOME_SalomeException);
1475 return _impl->NbPyramids( (::SMESH_Mesh::ElementOrder) order);
1478 CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
1479 throw(SALOME::SALOME_Exception)
1481 Unexpect aCatch(SALOME_SalomeException);
1482 return _impl->NbPrisms( (::SMESH_Mesh::ElementOrder) order);
1485 //=============================================================================
1489 //=============================================================================
1490 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1492 Unexpect aCatch(SALOME_SalomeException);
1493 return _impl->NbSubMesh();
1496 //=============================================================================
1500 //=============================================================================
1501 char* SMESH_Mesh_i::Dump()
1503 std::ostringstream os;
1505 return CORBA::string_dup( os.str().c_str() );
1508 //=============================================================================
1512 //=============================================================================
1513 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1515 SMESH::long_array_var aResult = new SMESH::long_array();
1516 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1517 int aMinId = aSMESHDS_Mesh->MinElementID();
1518 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1520 aResult->length(aMaxId - aMinId + 1);
1522 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1525 return aResult._retn();
1528 //=============================================================================
1532 //=============================================================================
1534 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1535 throw (SALOME::SALOME_Exception)
1537 Unexpect aCatch(SALOME_SalomeException);
1538 MESSAGE("SMESH_Mesh_i::GetElementsId");
1539 SMESH::long_array_var aResult = new SMESH::long_array();
1540 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1542 if ( aSMESHDS_Mesh == NULL )
1543 return aResult._retn();
1545 long nbElements = NbElements();
1546 aResult->length( nbElements );
1547 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1548 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1549 aResult[i] = anIt->next()->GetID();
1551 return aResult._retn();
1555 //=============================================================================
1559 //=============================================================================
1561 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1562 throw (SALOME::SALOME_Exception)
1564 Unexpect aCatch(SALOME_SalomeException);
1565 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1566 SMESH::long_array_var aResult = new SMESH::long_array();
1567 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1569 if ( aSMESHDS_Mesh == NULL )
1570 return aResult._retn();
1572 long nbElements = NbElements();
1574 // No sense in returning ids of elements along with ids of nodes:
1575 // when theElemType == SMESH::ALL, return node ids only if
1576 // there are no elements
1577 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1578 return GetNodesId();
1580 aResult->length( nbElements );
1584 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1585 while ( i < nbElements && anIt->more() ) {
1586 const SMDS_MeshElement* anElem = anIt->next();
1587 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1588 aResult[i++] = anElem->GetID();
1591 aResult->length( i );
1593 return aResult._retn();
1596 //=============================================================================
1600 //=============================================================================
1602 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1603 throw (SALOME::SALOME_Exception)
1605 Unexpect aCatch(SALOME_SalomeException);
1606 MESSAGE("SMESH_subMesh_i::GetNodesId");
1607 SMESH::long_array_var aResult = new SMESH::long_array();
1608 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1610 if ( aSMESHDS_Mesh == NULL )
1611 return aResult._retn();
1613 long nbNodes = NbNodes();
1614 aResult->length( nbNodes );
1615 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1616 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1617 aResult[i] = anIt->next()->GetID();
1619 return aResult._retn();
1622 //=============================================================================
1626 //=============================================================================
1628 SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
1629 throw (SALOME::SALOME_Exception)
1631 return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
1634 //=============================================================================
1638 //=============================================================================
1640 CORBA::Long SMESH_Mesh_i::GetMeshPtr()
1642 return (CORBA::Long)_impl;
1646 void SMESH_Mesh_i::CreateGroupServants()
1648 // Create group servants, if any groups were imported
1649 list<int> aGroupIds = _impl->GetGroupIds();
1650 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
1651 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
1653 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1654 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1655 aGroupImpl->Register();
1656 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1658 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
1659 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
1661 // register CORBA object for persistence
1662 int nextId = _gen_i->RegisterObject( aGroup );
1663 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);