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"
35 #include "Utils_CorbaException.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37 #include "utilities.h"
39 #include "SALOME_NamingService.hxx"
40 #include "Utils_SINGLETON.hxx"
43 #include "TCollection_AsciiString.hxx"
44 #include "SMESHDS_Command.hxx"
45 #include "SMESHDS_CommandType.hxx"
46 #include "SMESH_MeshEditor_i.hxx"
47 #include "SMESH_Gen_i.hxx"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
50 #include <TColStd_MapOfInteger.hxx>
51 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
52 #include <TColStd_SequenceOfInteger.hxx>
59 static int MYDEBUG = 0;
61 static int MYDEBUG = 0;
66 int SMESH_Mesh_i::myIdGenerator = 0;
68 //=============================================================================
72 //=============================================================================
74 SMESH_Mesh_i::SMESH_Mesh_i( PortableServer::POA_ptr thePOA,
77 : SALOME::GenericObj_i( thePOA )
79 INFOS("SMESH_Mesh_i");
81 _id = myIdGenerator++;
83 thePOA->activate_object( this );
86 //=============================================================================
90 //=============================================================================
92 SMESH_Mesh_i::~SMESH_Mesh_i()
94 INFOS("~SMESH_Mesh_i");
95 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it;
96 for ( it = _mapGroups.begin(); it != _mapGroups.end(); it++ ) {
97 SMESH_GroupBase_i* aGroup = dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( it->second ).in() );
100 // this method is colled from destructor of group (PAL6331)
101 //_impl->RemoveGroup( aGroup->GetLocalID() );
109 //=============================================================================
113 * Associates <this> mesh with <theShape> and puts a reference
114 * to <theShape> into the current study;
115 * the previous shape is substituted by the new one.
117 //=============================================================================
119 void SMESH_Mesh_i::SetShape( GEOM::GEOM_Object_ptr theShapeObject )
120 throw (SALOME::SALOME_Exception)
122 Unexpect aCatch(SALOME_SalomeException);
124 _impl->ShapeToMesh( _gen_i->GeomObjectToShape( theShapeObject ));
126 catch(SALOME_Exception & S_ex) {
127 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
131 //=======================================================================
132 //function : GetShapeToMesh
134 //=======================================================================
136 GEOM::GEOM_Object_ptr SMESH_Mesh_i::GetShapeToMesh()
137 throw (SALOME::SALOME_Exception)
139 Unexpect aCatch(SALOME_SalomeException);
140 GEOM::GEOM_Object_var aShapeObj;
142 TopoDS_Shape S = _impl->GetMeshDS()->ShapeToMesh();
144 aShapeObj = _gen_i->ShapeToGeomObject( S );
146 catch(SALOME_Exception & S_ex) {
147 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
149 return aShapeObj._retn();
152 //=============================================================================
156 //=============================================================================
158 static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
160 SMESH::DriverMED_ReadStatus res;
163 case DriverMED_R_SMESHDS_Mesh::DRS_OK:
164 res = SMESH::DRS_OK; break;
165 case DriverMED_R_SMESHDS_Mesh::DRS_EMPTY:
166 res = SMESH::DRS_EMPTY; break;
167 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_RENUMBER:
168 res = SMESH::DRS_WARN_RENUMBER; break;
169 case DriverMED_R_SMESHDS_Mesh::DRS_WARN_SKIP_ELEM:
170 res = SMESH::DRS_WARN_SKIP_ELEM; break;
171 case DriverMED_R_SMESHDS_Mesh::DRS_FAIL:
173 res = SMESH::DRS_FAIL; break;
178 //=============================================================================
182 * Imports mesh data from MED file
184 //=============================================================================
186 SMESH::DriverMED_ReadStatus
187 SMESH_Mesh_i::ImportMEDFile( const char* theFileName, const char* theMeshName )
188 throw ( SALOME::SALOME_Exception )
190 Unexpect aCatch(SALOME_SalomeException);
193 status = importMEDFile( theFileName, theMeshName );
195 catch( SALOME_Exception& S_ex ) {
196 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
199 THROW_SALOME_CORBA_EXCEPTION("ImportMEDFile(): unknown exception", SALOME::BAD_PARAM);
202 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
203 if ( !aStudy->_is_nil() ) {
204 // publishing of the groups in the study (sub-meshes are out of scope of MED import)
205 map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
206 for (; it != _mapGroups.end(); it++ ) {
207 SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_duplicate( it->second );
208 _gen_i->PublishGroup( aStudy, _this(), aGroup,
209 GEOM::GEOM_Object::_nil(), aGroup->GetName());
212 return ConvertDriverMEDReadStatus(status);
215 //=============================================================================
219 * Imports mesh data from MED file
221 //=============================================================================
223 int SMESH_Mesh_i::ImportUNVFile( const char* theFileName )
224 throw ( SALOME::SALOME_Exception )
226 // Read mesh with name = <theMeshName> into SMESH_Mesh
227 _impl->UNVToMesh( theFileName );
232 //=============================================================================
236 * Imports mesh data from STL file
238 //=============================================================================
239 int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
240 throw ( SALOME::SALOME_Exception )
242 // Read mesh with name = <theMeshName> into SMESH_Mesh
243 _impl->STLToMesh( theFileName );
248 //=============================================================================
252 * Imports mesh data from MED file
254 //=============================================================================
256 int SMESH_Mesh_i::importMEDFile( const char* theFileName, const char* theMeshName )
258 // Read mesh with name = <theMeshName> and all its groups into SMESH_Mesh
259 int status = _impl->MEDToMesh( theFileName, theMeshName );
261 // Create group servants, if any groups were imported
262 list<int> aGroupIds = _impl->GetGroupIds();
263 for ( list<int>::iterator it = aGroupIds.begin(); it != aGroupIds.end(); it++ ) {
264 SMESH_Group_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, *it );
266 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
267 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
268 aGroupImpl->Register();
269 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
271 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
272 _mapGroups[*it] = SMESH::SMESH_Group::_duplicate( aGroup );
274 // register CORBA object for persistence
275 int nextId = _gen_i->RegisterObject( aGroup );
276 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
282 //=============================================================================
286 //=============================================================================
288 static SMESH::Hypothesis_Status ConvertHypothesisStatus
289 (SMESH_Hypothesis::Hypothesis_Status theStatus)
291 SMESH::Hypothesis_Status res;
294 case SMESH_Hypothesis::HYP_OK:
295 res = SMESH::HYP_OK; break;
296 case SMESH_Hypothesis::HYP_MISSING:
297 res = SMESH::HYP_MISSING; break;
298 case SMESH_Hypothesis::HYP_CONCURENT:
299 res = SMESH::HYP_CONCURENT; break;
300 case SMESH_Hypothesis::HYP_BAD_PARAMETER:
301 res = SMESH::HYP_BAD_PARAMETER; break;
302 case SMESH_Hypothesis::HYP_INCOMPATIBLE:
303 res = SMESH::HYP_INCOMPATIBLE; break;
304 case SMESH_Hypothesis::HYP_NOTCONFORM:
305 res = SMESH::HYP_NOTCONFORM; break;
306 case SMESH_Hypothesis::HYP_ALREADY_EXIST:
307 res = SMESH::HYP_ALREADY_EXIST; break;
308 case SMESH_Hypothesis::HYP_BAD_DIM:
309 res = SMESH::HYP_BAD_DIM; break;
311 res = SMESH::HYP_UNKNOWN_FATAL;
316 //=============================================================================
320 * calls internal addHypothesis() and then adds a reference to <anHyp> under
321 * the SObject actually having a reference to <aSubShape>.
322 * NB: For this method to work, it is necessary to add a reference to sub-shape first.
324 //=============================================================================
326 SMESH::Hypothesis_Status SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
327 SMESH::SMESH_Hypothesis_ptr anHyp)
328 throw(SALOME::SALOME_Exception)
330 Unexpect aCatch(SALOME_SalomeException);
331 SMESH_Hypothesis::Hypothesis_Status status = addHypothesis( aSubShapeObject, anHyp );
333 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
334 _gen_i->AddHypothesisToShape(_gen_i->GetCurrentStudy(), _this(),
335 aSubShapeObject, anHyp );
337 if(MYDEBUG) MESSAGE( " AddHypothesis(): status = " << status );
339 // Update Python script
340 TCollection_AsciiString aStr ("status = ");
341 SMESH_Gen_i::AddObject(aStr, _this()) += ".AddHypothesis(";
342 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
343 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
345 SMESH_Gen_i::AddToCurrentPyScript(aStr);
347 return ConvertHypothesisStatus(status);
350 //=============================================================================
354 //=============================================================================
356 SMESH_Hypothesis::Hypothesis_Status
357 SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
358 SMESH::SMESH_Hypothesis_ptr anHyp)
360 if(MYDEBUG) MESSAGE("addHypothesis");
362 if (CORBA::is_nil(aSubShapeObject))
363 THROW_SALOME_CORBA_EXCEPTION("bad subShape reference",
366 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
367 if (CORBA::is_nil(myHyp))
368 THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference",
371 SMESH_Hypothesis::Hypothesis_Status status = SMESH_Hypothesis::HYP_OK;
374 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape( aSubShapeObject);
375 int hypId = myHyp->GetId();
376 status = _impl->AddHypothesis(myLocSubShape, hypId);
377 if ( !SMESH_Hypothesis::IsStatusFatal(status) ) {
378 _mapHypo[hypId] = myHyp;
379 // assure there is a corresponding submesh
380 if ( !_impl->IsMainShape( myLocSubShape )) {
381 int shapeId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
382 if ( _mapSubMesh_i.find( shapeId ) == _mapSubMesh_i.end() )
383 createSubMesh( aSubShapeObject );
387 catch(SALOME_Exception & S_ex)
389 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
394 //=============================================================================
398 //=============================================================================
400 SMESH::Hypothesis_Status SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Object_ptr aSubShapeObject,
401 SMESH::SMESH_Hypothesis_ptr anHyp)
402 throw(SALOME::SALOME_Exception)
404 Unexpect aCatch(SALOME_SalomeException);
405 SMESH_Hypothesis::Hypothesis_Status status = removeHypothesis( aSubShapeObject, anHyp );
407 if ( !SMESH_Hypothesis::IsStatusFatal(status) )
408 _gen_i->RemoveHypothesisFromShape(_gen_i->GetCurrentStudy(), _this(),
409 aSubShapeObject, anHyp );
411 // Update Python script
412 TCollection_AsciiString aStr ("status = ");
413 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveHypothesis(";
414 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", ";
415 SMESH_Gen_i::AddObject(aStr, anHyp) += ")";
417 SMESH_Gen_i::AddToCurrentPyScript(aStr);
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 TCollection_AsciiString aStr (aSO->GetID());
535 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetSubMesh(";
536 SMESH_Gen_i::AddObject(aStr, aSubShapeObject) += ", \"";
537 aStr += (char*)theName;
540 SMESH_Gen_i::AddToCurrentPyScript(aStr);
544 catch(SALOME_Exception & S_ex) {
545 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
547 return subMesh._retn();
550 //=============================================================================
554 //=============================================================================
556 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
557 throw (SALOME::SALOME_Exception)
559 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
560 if ( theSubMesh->_is_nil() )
563 GEOM::GEOM_Object_var aSubShapeObject;
564 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
565 if ( !aStudy->_is_nil() ) {
566 // Remove submesh's SObject
567 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
568 if ( !anSO->_is_nil() ) {
569 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
570 SALOMEDS::SObject_var anObj, aRef;
571 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
572 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
574 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
576 // Update Python script
577 TCollection_AsciiString aStr;
578 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveSubMesh(";
579 aStr += anSO->GetID();
582 SMESH_Gen_i::AddToCurrentPyScript(aStr);
586 removeSubMesh( theSubMesh, aSubShapeObject.in() );
589 //=============================================================================
593 //=============================================================================
594 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
596 TCollection_AsciiString aStr;
597 switch (theElemType) {
611 aStr = "SMESH.VOLUME";
619 //=============================================================================
623 //=============================================================================
625 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
626 const char* theName )
627 throw(SALOME::SALOME_Exception)
629 Unexpect aCatch(SALOME_SalomeException);
630 SMESH::SMESH_Group_var aNewGroup =
631 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
633 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
634 SALOMEDS::SObject_var aSO =
635 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
636 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
637 if ( !aSO->_is_nil()) {
638 // Update Python script
639 TCollection_AsciiString aStr (aSO->GetID());
641 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroup(";
642 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\")";
644 SMESH_Gen_i::AddToCurrentPyScript(aStr);
648 return aNewGroup._retn();
652 //=============================================================================
656 //=============================================================================
657 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
659 GEOM::GEOM_Object_ptr theGeomObj)
660 throw(SALOME::SALOME_Exception)
662 Unexpect aCatch(SALOME_SalomeException);
663 SMESH::SMESH_GroupOnGeom_var aNewGroup;
665 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
666 if ( !aShape.IsNull() ) {
667 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
668 ( createGroup( theElemType, theName, aShape ));
669 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
670 SALOMEDS::SObject_var aSO =
671 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
672 aNewGroup, theGeomObj, theName);
673 if ( !aSO->_is_nil()) {
674 // Update Python script
675 TCollection_AsciiString aStr (aSO->GetID());
677 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroupFromGEOM(";
678 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\", ";
679 SMESH_Gen_i::AddObject(aStr, theGeomObj) += ")";
681 SMESH_Gen_i::AddToCurrentPyScript(aStr);
686 return aNewGroup._retn();
689 //=============================================================================
693 //=============================================================================
695 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
696 throw (SALOME::SALOME_Exception)
698 if ( theGroup->_is_nil() )
701 SMESH_GroupBase_i* aGroup =
702 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
706 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
707 if ( !aStudy->_is_nil() ) {
708 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
710 if ( !aGroupSO->_is_nil() ) {
711 // Update Python script
712 TCollection_AsciiString aStr;
713 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroup(";
714 aStr += aGroupSO->GetID();
717 SMESH_Gen_i::AddToCurrentPyScript(aStr);
719 // Remove group's SObject
720 aStudy->NewBuilder()->RemoveObject( aGroupSO );
724 // Remove the group from SMESH data structures
725 removeGroup( aGroup->GetLocalID() );
728 //=============================================================================
729 /*! RemoveGroupWithContents
730 * Remove group with its contents
732 //=============================================================================
733 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
734 throw (SALOME::SALOME_Exception)
736 if ( theGroup->_is_nil() )
739 SMESH_GroupBase_i* aGroup =
740 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
744 SMESH::long_array_var anIds = aGroup->GetListOfID();
745 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
747 // Update Python script
748 TCollection_AsciiString aStr;
749 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroupWithContents(";
750 SMESH_Gen_i::AddObject(aStr, theGroup) += ")";
752 SMESH_Gen_i::AddToCurrentPyScript(aStr);
755 if ( aGroup->GetType() == SMESH::NODE )
756 aMeshEditor->RemoveNodes( anIds );
758 aMeshEditor->RemoveElements( anIds );
761 RemoveGroup( theGroup );
763 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
764 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
765 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
768 //=============================================================================
770 * New group is created. All mesh elements that are
771 * present in initial groups are added to the new one
773 //=============================================================================
774 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
775 SMESH::SMESH_GroupBase_ptr theGroup2,
776 const char* theName )
777 throw (SALOME::SALOME_Exception)
781 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
782 theGroup1->GetType() != theGroup2->GetType() )
783 return SMESH::SMESH_Group::_nil();
786 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
787 if ( aResGrp->_is_nil() )
788 return SMESH::SMESH_Group::_nil();
790 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
791 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
793 TColStd_MapOfInteger aResMap;
795 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
796 aResMap.Add( anIds1[ i1 ] );
798 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
799 aResMap.Add( anIds2[ i2 ] );
801 SMESH::long_array_var aResIds = new SMESH::long_array;
802 aResIds->length( aResMap.Extent() );
805 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
806 for( ; anIter.More(); anIter.Next() )
807 aResIds[ resI++ ] = anIter.Key();
809 aResGrp->Add( aResIds );
811 // Clear python lines, created by CreateGroup() and Add()
812 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
813 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
814 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
816 // Update Python script
817 TCollection_AsciiString aStr;
818 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
819 SMESH_Gen_i::AddObject(aStr, _this()) += ".UnionGroups(";
820 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
821 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
822 aStr += TCollection_AsciiString((char*)theName) + "\")";
824 SMESH_Gen_i::AddToCurrentPyScript(aStr);
826 return aResGrp._retn();
830 return SMESH::SMESH_Group::_nil();
834 //=============================================================================
836 * New group is created. All mesh elements that are
837 * present in both initial groups are added to the new one.
839 //=============================================================================
840 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
841 SMESH::SMESH_GroupBase_ptr theGroup2,
842 const char* theName )
843 throw (SALOME::SALOME_Exception)
845 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
846 theGroup1->GetType() != theGroup2->GetType() )
847 return SMESH::SMESH_Group::_nil();
849 // Create Intersection
850 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
851 if ( aResGrp->_is_nil() )
854 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
855 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
857 TColStd_MapOfInteger aMap1;
859 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
860 aMap1.Add( anIds1[ i1 ] );
862 TColStd_SequenceOfInteger aSeq;
864 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
865 if ( aMap1.Contains( anIds2[ i2 ] ) )
866 aSeq.Append( anIds2[ i2 ] );
868 SMESH::long_array_var aResIds = new SMESH::long_array;
869 aResIds->length( aSeq.Length() );
871 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
872 aResIds[ resI ] = aSeq( resI + 1 );
874 aResGrp->Add( aResIds );
876 // Clear python lines, created by CreateGroup() and Add()
877 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
878 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
879 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
881 // Update Python script
882 TCollection_AsciiString aStr;
883 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
884 SMESH_Gen_i::AddObject(aStr, _this()) += ".IntersectGroups(";
885 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
886 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
887 aStr += TCollection_AsciiString((char*)theName) + "\")";
889 SMESH_Gen_i::AddToCurrentPyScript(aStr);
891 return aResGrp._retn();
894 //=============================================================================
896 * New group is created. All mesh elements that are present in
897 * main group but do not present in tool group are added to the new one
899 //=============================================================================
900 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
901 SMESH::SMESH_GroupBase_ptr theGroup2,
902 const char* theName )
903 throw (SALOME::SALOME_Exception)
905 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
906 theGroup1->GetType() != theGroup2->GetType() )
907 return SMESH::SMESH_Group::_nil();
910 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
911 if ( aResGrp->_is_nil() )
914 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
915 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
917 TColStd_MapOfInteger aMap2;
919 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
920 aMap2.Add( anIds2[ i2 ] );
923 TColStd_SequenceOfInteger aSeq;
924 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
925 if ( !aMap2.Contains( anIds1[ i1 ] ) )
926 aSeq.Append( anIds1[ i1 ] );
928 SMESH::long_array_var aResIds = new SMESH::long_array;
929 aResIds->length( aSeq.Length() );
931 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
932 aResIds[ resI ] = aSeq( resI + 1 );
934 aResGrp->Add( aResIds );
936 // Clear python lines, created by CreateGroup() and Add()
937 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
938 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
939 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
941 // Update Python script
942 TCollection_AsciiString aStr;
943 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
944 SMESH_Gen_i::AddObject(aStr, _this()) += ".CutGroups(";
945 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
946 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
947 aStr += TCollection_AsciiString((char*)theName) + "\")";
949 SMESH_Gen_i::AddToCurrentPyScript(aStr);
951 return aResGrp._retn();
954 //=============================================================================
958 //=============================================================================
960 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
962 if(MYDEBUG) MESSAGE( "createSubMesh" );
963 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
965 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
966 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
967 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
968 SMESH::SMESH_subMesh_var subMesh
969 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
971 _mapSubMesh[subMeshId] = mySubMesh;
972 _mapSubMesh_i[subMeshId] = subMeshServant;
973 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
975 // register CORBA object for persistence
976 int nextId = _gen_i->RegisterObject( subMesh );
977 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
979 return subMesh._retn();
982 //=======================================================================
983 //function : getSubMesh
985 //=======================================================================
987 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
989 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
990 if ( it == _mapSubMeshIor.end() )
991 return SMESH::SMESH_subMesh::_nil();
993 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
997 //=============================================================================
1001 //=============================================================================
1003 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1004 GEOM::GEOM_Object_ptr theSubShapeObject )
1006 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1007 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1011 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1012 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1013 removeHypothesis( theSubShapeObject, aHypList[i] );
1016 catch( const SALOME::SALOME_Exception& ) {
1017 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1020 int subMeshId = theSubMesh->GetId();
1022 _mapSubMesh.erase(subMeshId);
1023 _mapSubMesh_i.erase(subMeshId);
1024 _mapSubMeshIor.erase(subMeshId);
1025 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1028 //=============================================================================
1032 //=============================================================================
1034 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1035 const char* theName,
1036 const TopoDS_Shape& theShape )
1039 SMESH::SMESH_GroupBase_var aGroup;
1040 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1041 SMESH_GroupBase_i* aGroupImpl;
1042 if ( !theShape.IsNull() )
1043 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1045 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1047 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1048 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1049 aGroupImpl->Register();
1050 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1052 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1053 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1055 // register CORBA object for persistence
1056 int nextId = _gen_i->RegisterObject( aGroup );
1057 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1059 return aGroup._retn();
1062 //=============================================================================
1064 * SMESH_Mesh_i::removeGroup
1066 * Should be called by ~SMESH_Group_i()
1068 //=============================================================================
1070 void SMESH_Mesh_i::removeGroup( const int theId )
1072 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1073 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1074 _mapGroups.erase( theId );
1075 _impl->RemoveGroup( theId );
1080 //=============================================================================
1084 //=============================================================================
1086 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1087 throw(SALOME::SALOME_Exception)
1089 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1091 SMESH::log_array_var aLog;
1093 list < SMESHDS_Command * >logDS = _impl->GetLog();
1094 aLog = new SMESH::log_array;
1096 int lg = logDS.size();
1099 list < SMESHDS_Command * >::iterator its = logDS.begin();
1100 while(its != logDS.end()){
1101 SMESHDS_Command *com = *its;
1102 int comType = com->GetType();
1104 int lgcom = com->GetNumber();
1106 const list < int >&intList = com->GetIndexes();
1107 int inum = intList.size();
1109 list < int >::const_iterator ii = intList.begin();
1110 const list < double >&coordList = com->GetCoords();
1111 int rnum = coordList.size();
1113 list < double >::const_iterator ir = coordList.begin();
1114 aLog[indexLog].commandType = comType;
1115 aLog[indexLog].number = lgcom;
1116 aLog[indexLog].coords.length(rnum);
1117 aLog[indexLog].indexes.length(inum);
1118 for(int i = 0; i < rnum; i++){
1119 aLog[indexLog].coords[i] = *ir;
1120 //MESSAGE(" "<<i<<" "<<ir.Value());
1123 for(int i = 0; i < inum; i++){
1124 aLog[indexLog].indexes[i] = *ii;
1125 //MESSAGE(" "<<i<<" "<<ii.Value());
1134 catch(SALOME_Exception & S_ex){
1135 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1137 return aLog._retn();
1141 //=============================================================================
1145 //=============================================================================
1147 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1149 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1153 //=============================================================================
1157 //=============================================================================
1159 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1161 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1165 //=============================================================================
1169 //=============================================================================
1171 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1176 //=============================================================================
1180 //=============================================================================
1182 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1184 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1188 //=============================================================================
1192 //=============================================================================
1194 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1196 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1201 //=============================================================================
1205 //=============================================================================
1207 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1209 // Update Python script
1210 TCollection_AsciiString aStr ("mesh_editor = ");
1211 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()";
1213 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1215 // Create MeshEditor
1216 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1217 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1218 return aMesh._retn();
1221 //=============================================================================
1223 * Export in different formats
1225 //=============================================================================
1227 void SMESH_Mesh_i::ExportToMED (const char* file,
1228 CORBA::Boolean auto_groups,
1229 SMESH::MED_VERSION theVersion)
1230 throw(SALOME::SALOME_Exception)
1232 Unexpect aCatch(SALOME_SalomeException);
1234 // Update Python script
1235 TCollection_AsciiString aStr;
1236 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1237 aStr += TCollection_AsciiString((char*)file) + "\", ";
1238 aStr += TCollection_AsciiString((int)auto_groups) + ", ";
1239 switch (theVersion) {
1240 case SMESH::MED_V2_1:
1241 aStr += "SMESH.MED_V2_1)";
1243 case SMESH::MED_V2_2:
1244 aStr += "SMESH.MED_V2_2)";
1247 aStr += TCollection_AsciiString(theVersion) + ")";
1251 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1254 char* aMeshName = "Mesh";
1255 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1256 if ( !aStudy->_is_nil() ) {
1257 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1258 if ( !aMeshSO->_is_nil() ) {
1259 aMeshName = aMeshSO->GetName();
1261 //SCRUTE(aMeshName);
1262 //SCRUTE(aMeshSO->GetID());
1264 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1265 if ( !aStudy->GetProperties()->IsLocked() )
1267 SALOMEDS::GenericAttribute_var anAttr;
1268 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1269 SALOMEDS::AttributeExternalFileDef_var aFileName;
1270 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1271 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1272 ASSERT(!aFileName->_is_nil());
1273 aFileName->SetValue(file);
1274 SALOMEDS::AttributeFileType_var aFileType;
1275 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1276 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1277 ASSERT(!aFileType->_is_nil());
1278 aFileType->SetValue("FICHIERMED");
1282 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1285 void SMESH_Mesh_i::ExportMED (const char* file,
1286 CORBA::Boolean auto_groups)
1287 throw(SALOME::SALOME_Exception)
1289 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1292 void SMESH_Mesh_i::ExportDAT (const char *file)
1293 throw(SALOME::SALOME_Exception)
1295 Unexpect aCatch(SALOME_SalomeException);
1297 // Update Python script
1298 TCollection_AsciiString aStr;
1299 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportDAT(\"";
1300 aStr += TCollection_AsciiString((char*)file) + "\")";
1302 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1305 _impl->ExportDAT(file);
1308 void SMESH_Mesh_i::ExportUNV (const char *file)
1309 throw(SALOME::SALOME_Exception)
1311 Unexpect aCatch(SALOME_SalomeException);
1313 // Update Python script
1314 TCollection_AsciiString aStr;
1315 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportUNV(\"";
1316 aStr += TCollection_AsciiString((char*)file) + "\")";
1318 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1321 _impl->ExportUNV(file);
1324 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1325 throw(SALOME::SALOME_Exception)
1327 Unexpect aCatch(SALOME_SalomeException);
1329 // Update Python script
1330 TCollection_AsciiString aStr;
1331 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1332 aStr += TCollection_AsciiString((char*)file) + "\", ";
1333 aStr += TCollection_AsciiString((int)isascii) + ")";
1335 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1338 _impl->ExportSTL(file, isascii);
1341 //=============================================================================
1345 //=============================================================================
1347 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1349 Unexpect aCatch(SALOME_SalomeException);
1350 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1351 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1352 return aMesh._retn();
1355 //=============================================================================
1359 //=============================================================================
1360 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1362 Unexpect aCatch(SALOME_SalomeException);
1363 return _impl->NbNodes();
1366 //=============================================================================
1370 //=============================================================================
1371 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1373 Unexpect aCatch(SALOME_SalomeException);
1374 return NbEdges() + NbFaces() + NbVolumes();
1377 //=============================================================================
1381 //=============================================================================
1382 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1384 Unexpect aCatch(SALOME_SalomeException);
1385 return _impl->NbEdges();
1388 //=============================================================================
1392 //=============================================================================
1393 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1395 Unexpect aCatch(SALOME_SalomeException);
1396 return _impl->NbFaces();
1399 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1401 Unexpect aCatch(SALOME_SalomeException);
1402 return _impl->NbTriangles();
1405 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1407 Unexpect aCatch(SALOME_SalomeException);
1408 return _impl->NbQuadrangles();
1411 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1413 Unexpect aCatch(SALOME_SalomeException);
1414 return _impl->NbPolygons();
1417 //=============================================================================
1421 //=============================================================================
1422 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1424 Unexpect aCatch(SALOME_SalomeException);
1425 return _impl->NbVolumes();
1428 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1430 Unexpect aCatch(SALOME_SalomeException);
1431 return _impl->NbTetras();
1434 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1436 Unexpect aCatch(SALOME_SalomeException);
1437 return _impl->NbHexas();
1440 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1442 Unexpect aCatch(SALOME_SalomeException);
1443 return _impl->NbPyramids();
1446 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1448 Unexpect aCatch(SALOME_SalomeException);
1449 return _impl->NbPrisms();
1452 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1454 Unexpect aCatch(SALOME_SalomeException);
1455 return _impl->NbPolyhedrons();
1458 //=============================================================================
1462 //=============================================================================
1463 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1465 Unexpect aCatch(SALOME_SalomeException);
1466 return _impl->NbSubMesh();
1469 //=============================================================================
1473 //=============================================================================
1474 char* SMESH_Mesh_i::Dump()
1476 std::ostringstream os;
1478 return CORBA::string_dup( os.str().c_str() );
1481 //=============================================================================
1485 //=============================================================================
1486 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1488 SMESH::long_array_var aResult = new SMESH::long_array();
1489 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1490 int aMinId = aSMESHDS_Mesh->MinElementID();
1491 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1493 aResult->length(aMaxId - aMinId + 1);
1495 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1498 return aResult._retn();
1501 //=============================================================================
1505 //=============================================================================
1507 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1508 throw (SALOME::SALOME_Exception)
1510 Unexpect aCatch(SALOME_SalomeException);
1511 MESSAGE("SMESH_Mesh_i::GetElementsId");
1512 SMESH::long_array_var aResult = new SMESH::long_array();
1513 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1515 if ( aSMESHDS_Mesh == NULL )
1516 return aResult._retn();
1518 long nbElements = NbElements();
1519 aResult->length( nbElements );
1520 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1521 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1522 aResult[i] = anIt->next()->GetID();
1524 return aResult._retn();
1528 //=============================================================================
1532 //=============================================================================
1534 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1535 throw (SALOME::SALOME_Exception)
1537 Unexpect aCatch(SALOME_SalomeException);
1538 MESSAGE("SMESH_subMesh_i::GetElementsByType");
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();
1547 // No sense in returning ids of elements along with ids of nodes:
1548 // when theElemType == SMESH::ALL, return node ids only if
1549 // there are no elements
1550 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1551 return GetNodesId();
1553 aResult->length( nbElements );
1557 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1558 while ( i < nbElements && anIt->more() ) {
1559 const SMDS_MeshElement* anElem = anIt->next();
1560 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1561 aResult[i++] = anElem->GetID();
1564 aResult->length( i );
1566 return aResult._retn();
1569 //=============================================================================
1573 //=============================================================================
1575 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1576 throw (SALOME::SALOME_Exception)
1578 Unexpect aCatch(SALOME_SalomeException);
1579 MESSAGE("SMESH_subMesh_i::GetNodesId");
1580 SMESH::long_array_var aResult = new SMESH::long_array();
1581 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1583 if ( aSMESHDS_Mesh == NULL )
1584 return aResult._retn();
1586 long nbNodes = NbNodes();
1587 aResult->length( nbNodes );
1588 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1589 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1590 aResult[i] = anIt->next()->GetID();
1592 return aResult._retn();