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 );
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);
543 catch(SALOME_Exception & S_ex) {
544 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
546 return subMesh._retn();
549 //=============================================================================
553 //=============================================================================
555 void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh )
556 throw (SALOME::SALOME_Exception)
558 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh");
559 if ( theSubMesh->_is_nil() )
562 GEOM::GEOM_Object_var aSubShapeObject;
563 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
564 if ( !aStudy->_is_nil() ) {
565 // Remove submesh's SObject
566 SALOMEDS::SObject_var anSO = _gen_i->ObjectToSObject( aStudy, theSubMesh );
567 if ( !anSO->_is_nil() ) {
568 long aTag = SMESH_Gen_i::GetRefOnShapeTag();
569 SALOMEDS::SObject_var anObj, aRef;
570 if ( anSO->FindSubObject( aTag, anObj ) && anObj->ReferencedObject( aRef ) )
571 aSubShapeObject = GEOM::GEOM_Object::_narrow( aRef->GetObject() );
573 aStudy->NewBuilder()->RemoveObjectWithChildren( anSO );
575 // Update Python script
576 TCollection_AsciiString aStr;
577 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveSubMesh(";
578 aStr += anSO->GetID();
581 SMESH_Gen_i::AddToCurrentPyScript(aStr);
585 removeSubMesh( theSubMesh, aSubShapeObject.in() );
588 //=============================================================================
592 //=============================================================================
593 inline TCollection_AsciiString ElementTypeString (SMESH::ElementType theElemType)
595 TCollection_AsciiString aStr;
596 switch (theElemType) {
610 aStr = "SMESH.VOLUME";
618 //=============================================================================
622 //=============================================================================
624 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateGroup( SMESH::ElementType theElemType,
625 const char* theName )
626 throw(SALOME::SALOME_Exception)
628 Unexpect aCatch(SALOME_SalomeException);
629 SMESH::SMESH_Group_var aNewGroup =
630 SMESH::SMESH_Group::_narrow( createGroup( theElemType, theName ));
632 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
633 SALOMEDS::SObject_var aSO =
634 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
635 aNewGroup, GEOM::GEOM_Object::_nil(), theName);
637 // Update Python script
638 TCollection_AsciiString aStr (aSO->GetID());
640 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroup(";
641 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\")";
643 SMESH_Gen_i::AddToCurrentPyScript(aStr);
646 return aNewGroup._retn();
650 //=============================================================================
654 //=============================================================================
655 SMESH::SMESH_GroupOnGeom_ptr SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType,
657 GEOM::GEOM_Object_ptr theGeomObj)
658 throw(SALOME::SALOME_Exception)
660 Unexpect aCatch(SALOME_SalomeException);
661 SMESH::SMESH_GroupOnGeom_var aNewGroup;
663 TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj );
664 if ( !aShape.IsNull() ) {
665 aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow
666 ( createGroup( theElemType, theName, aShape ));
667 if ( _gen_i->CanPublishInStudy( aNewGroup ) ) {
668 SALOMEDS::SObject_var aSO =
669 _gen_i->PublishGroup(_gen_i->GetCurrentStudy(), _this(),
670 aNewGroup, theGeomObj, theName);
672 // Update Python script
673 TCollection_AsciiString aStr (aSO->GetID());
675 SMESH_Gen_i::AddObject(aStr, _this()) += ".CreateGroupFromGEOM(";
676 aStr += ElementTypeString(theElemType) + ", \"" + (char*)theName + "\", ";
677 SMESH_Gen_i::AddObject(aStr, theGeomObj) += ")";
679 SMESH_Gen_i::AddToCurrentPyScript(aStr);
683 return aNewGroup._retn();
686 //=============================================================================
690 //=============================================================================
692 void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup )
693 throw (SALOME::SALOME_Exception)
695 if ( theGroup->_is_nil() )
698 SMESH_GroupBase_i* aGroup =
699 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
703 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
704 if ( !aStudy->_is_nil() ) {
705 SALOMEDS::SObject_var aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
707 if ( !aGroupSO->_is_nil() ) {
708 // Update Python script
709 TCollection_AsciiString aStr;
710 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroup(";
711 aStr += aGroupSO->GetID();
714 SMESH_Gen_i::AddToCurrentPyScript(aStr);
716 // Remove group's SObject
717 aStudy->NewBuilder()->RemoveObject( aGroupSO );
721 // Remove the group from SMESH data structures
722 removeGroup( aGroup->GetLocalID() );
725 //=============================================================================
726 /*! RemoveGroupWithContents
727 * Remove group with its contents
729 //=============================================================================
730 void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
731 throw (SALOME::SALOME_Exception)
733 if ( theGroup->_is_nil() )
736 SMESH_GroupBase_i* aGroup =
737 dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
741 SMESH::long_array_var anIds = aGroup->GetListOfID();
742 SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
744 // Update Python script
745 TCollection_AsciiString aStr;
746 SMESH_Gen_i::AddObject(aStr, _this()) += ".RemoveGroupWithContents(";
747 SMESH_Gen_i::AddObject(aStr, theGroup) += ")";
749 SMESH_Gen_i::AddToCurrentPyScript(aStr);
752 if ( aGroup->GetType() == SMESH::NODE )
753 aMeshEditor->RemoveNodes( anIds );
755 aMeshEditor->RemoveElements( anIds );
758 RemoveGroup( theGroup );
760 // Clear python lines, created by RemoveNodes/Elements() and RemoveGroup()
761 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
762 _gen_i->RemoveLastFromPythonScript(_gen_i->GetCurrentStudy()->StudyId());
765 //=============================================================================
767 * New group is created. All mesh elements that are
768 * present in initial groups are added to the new one
770 //=============================================================================
771 SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
772 SMESH::SMESH_GroupBase_ptr theGroup2,
773 const char* theName )
774 throw (SALOME::SALOME_Exception)
778 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
779 theGroup1->GetType() != theGroup2->GetType() )
780 return SMESH::SMESH_Group::_nil();
783 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
784 if ( aResGrp->_is_nil() )
785 return SMESH::SMESH_Group::_nil();
787 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
788 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
790 TColStd_MapOfInteger aResMap;
792 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
793 aResMap.Add( anIds1[ i1 ] );
795 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
796 aResMap.Add( anIds2[ i2 ] );
798 SMESH::long_array_var aResIds = new SMESH::long_array;
799 aResIds->length( aResMap.Extent() );
802 TColStd_MapIteratorOfMapOfInteger anIter( aResMap );
803 for( ; anIter.More(); anIter.Next() )
804 aResIds[ resI++ ] = anIter.Key();
806 aResGrp->Add( aResIds );
808 // Clear python lines, created by CreateGroup() and Add()
809 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
810 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
811 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
813 // Update Python script
814 TCollection_AsciiString aStr;
815 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
816 SMESH_Gen_i::AddObject(aStr, _this()) += ".UnionGroups(";
817 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
818 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
819 aStr += TCollection_AsciiString((char*)theName) + "\")";
821 SMESH_Gen_i::AddToCurrentPyScript(aStr);
823 return aResGrp._retn();
827 return SMESH::SMESH_Group::_nil();
831 //=============================================================================
833 * New group is created. All mesh elements that are
834 * present in both initial groups are added to the new one.
836 //=============================================================================
837 SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
838 SMESH::SMESH_GroupBase_ptr theGroup2,
839 const char* theName )
840 throw (SALOME::SALOME_Exception)
842 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
843 theGroup1->GetType() != theGroup2->GetType() )
844 return SMESH::SMESH_Group::_nil();
846 // Create Intersection
847 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
848 if ( aResGrp->_is_nil() )
851 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
852 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
854 TColStd_MapOfInteger aMap1;
856 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
857 aMap1.Add( anIds1[ i1 ] );
859 TColStd_SequenceOfInteger aSeq;
861 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
862 if ( aMap1.Contains( anIds2[ i2 ] ) )
863 aSeq.Append( anIds2[ i2 ] );
865 SMESH::long_array_var aResIds = new SMESH::long_array;
866 aResIds->length( aSeq.Length() );
868 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
869 aResIds[ resI ] = aSeq( resI + 1 );
871 aResGrp->Add( aResIds );
873 // Clear python lines, created by CreateGroup() and Add()
874 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
875 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
876 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
878 // Update Python script
879 TCollection_AsciiString aStr;
880 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
881 SMESH_Gen_i::AddObject(aStr, _this()) += ".IntersectGroups(";
882 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
883 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
884 aStr += TCollection_AsciiString((char*)theName) + "\")";
886 SMESH_Gen_i::AddToCurrentPyScript(aStr);
888 return aResGrp._retn();
891 //=============================================================================
893 * New group is created. All mesh elements that are present in
894 * main group but do not present in tool group are added to the new one
896 //=============================================================================
897 SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
898 SMESH::SMESH_GroupBase_ptr theGroup2,
899 const char* theName )
900 throw (SALOME::SALOME_Exception)
902 if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
903 theGroup1->GetType() != theGroup2->GetType() )
904 return SMESH::SMESH_Group::_nil();
907 SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
908 if ( aResGrp->_is_nil() )
911 SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
912 SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
914 TColStd_MapOfInteger aMap2;
916 for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
917 aMap2.Add( anIds2[ i2 ] );
920 TColStd_SequenceOfInteger aSeq;
921 for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
922 if ( !aMap2.Contains( anIds1[ i1 ] ) )
923 aSeq.Append( anIds1[ i1 ] );
925 SMESH::long_array_var aResIds = new SMESH::long_array;
926 aResIds->length( aSeq.Length() );
928 for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
929 aResIds[ resI ] = aSeq( resI + 1 );
931 aResGrp->Add( aResIds );
933 // Clear python lines, created by CreateGroup() and Add()
934 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
935 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
936 _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
938 // Update Python script
939 TCollection_AsciiString aStr;
940 SMESH_Gen_i::AddObject(aStr, aResGrp) += " = ";
941 SMESH_Gen_i::AddObject(aStr, _this()) += ".CutGroups(";
942 SMESH_Gen_i::AddObject(aStr, theGroup1) += ", ";
943 SMESH_Gen_i::AddObject(aStr, theGroup2) += ", \"";
944 aStr += TCollection_AsciiString((char*)theName) + "\")";
946 SMESH_Gen_i::AddToCurrentPyScript(aStr);
948 return aResGrp._retn();
951 //=============================================================================
955 //=============================================================================
957 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
959 if(MYDEBUG) MESSAGE( "createSubMesh" );
960 TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
962 ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
963 int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
964 SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
965 SMESH::SMESH_subMesh_var subMesh
966 = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
968 _mapSubMesh[subMeshId] = mySubMesh;
969 _mapSubMesh_i[subMeshId] = subMeshServant;
970 _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
972 // register CORBA object for persistence
973 int nextId = _gen_i->RegisterObject( subMesh );
974 if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
976 return subMesh._retn();
979 //=======================================================================
980 //function : getSubMesh
982 //=======================================================================
984 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
986 map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
987 if ( it == _mapSubMeshIor.end() )
988 return SMESH::SMESH_subMesh::_nil();
990 return SMESH::SMESH_subMesh::_duplicate( (*it).second );
994 //=============================================================================
998 //=============================================================================
1000 void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
1001 GEOM::GEOM_Object_ptr theSubShapeObject )
1003 MESSAGE("SMESH_Mesh_i::removeSubMesh()");
1004 if ( theSubMesh->_is_nil() || theSubShapeObject->_is_nil() )
1008 SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
1009 for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
1010 removeHypothesis( theSubShapeObject, aHypList[i] );
1013 catch( const SALOME::SALOME_Exception& ) {
1014 INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
1017 int subMeshId = theSubMesh->GetId();
1019 _mapSubMesh.erase(subMeshId);
1020 _mapSubMesh_i.erase(subMeshId);
1021 _mapSubMeshIor.erase(subMeshId);
1022 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
1025 //=============================================================================
1029 //=============================================================================
1031 SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
1032 const char* theName,
1033 const TopoDS_Shape& theShape )
1036 SMESH::SMESH_GroupBase_var aGroup;
1037 if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape )) {
1038 SMESH_GroupBase_i* aGroupImpl;
1039 if ( !theShape.IsNull() )
1040 aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
1042 aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
1044 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1045 SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
1046 aGroupImpl->Register();
1047 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
1049 aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
1050 _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
1052 // register CORBA object for persistence
1053 int nextId = _gen_i->RegisterObject( aGroup );
1054 if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
1056 return aGroup._retn();
1059 //=============================================================================
1061 * SMESH_Mesh_i::removeGroup
1063 * Should be called by ~SMESH_Group_i()
1065 //=============================================================================
1067 void SMESH_Mesh_i::removeGroup( const int theId )
1069 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
1070 if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
1071 _mapGroups.erase( theId );
1072 _impl->RemoveGroup( theId );
1077 //=============================================================================
1081 //=============================================================================
1083 SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
1084 throw(SALOME::SALOME_Exception)
1086 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
1088 SMESH::log_array_var aLog;
1090 list < SMESHDS_Command * >logDS = _impl->GetLog();
1091 aLog = new SMESH::log_array;
1093 int lg = logDS.size();
1096 list < SMESHDS_Command * >::iterator its = logDS.begin();
1097 while(its != logDS.end()){
1098 SMESHDS_Command *com = *its;
1099 int comType = com->GetType();
1101 int lgcom = com->GetNumber();
1103 const list < int >&intList = com->GetIndexes();
1104 int inum = intList.size();
1106 list < int >::const_iterator ii = intList.begin();
1107 const list < double >&coordList = com->GetCoords();
1108 int rnum = coordList.size();
1110 list < double >::const_iterator ir = coordList.begin();
1111 aLog[indexLog].commandType = comType;
1112 aLog[indexLog].number = lgcom;
1113 aLog[indexLog].coords.length(rnum);
1114 aLog[indexLog].indexes.length(inum);
1115 for(int i = 0; i < rnum; i++){
1116 aLog[indexLog].coords[i] = *ir;
1117 //MESSAGE(" "<<i<<" "<<ir.Value());
1120 for(int i = 0; i < inum; i++){
1121 aLog[indexLog].indexes[i] = *ii;
1122 //MESSAGE(" "<<i<<" "<<ii.Value());
1131 catch(SALOME_Exception & S_ex){
1132 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1134 return aLog._retn();
1138 //=============================================================================
1142 //=============================================================================
1144 void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
1146 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
1150 //=============================================================================
1154 //=============================================================================
1156 CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
1158 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
1162 //=============================================================================
1166 //=============================================================================
1168 CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
1173 //=============================================================================
1177 //=============================================================================
1179 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
1181 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
1185 //=============================================================================
1189 //=============================================================================
1191 ::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
1193 if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
1198 //=============================================================================
1202 //=============================================================================
1204 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
1206 // Update Python script
1207 TCollection_AsciiString aStr ("mesh_editor = ");
1208 SMESH_Gen_i::AddObject(aStr, _this()) += ".GetMeshEditor()";
1210 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1212 // Create MeshEditor
1213 SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( _impl );
1214 SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
1215 return aMesh._retn();
1218 //=============================================================================
1220 * Export in different formats
1222 //=============================================================================
1224 void SMESH_Mesh_i::ExportToMED (const char* file,
1225 CORBA::Boolean auto_groups,
1226 SMESH::MED_VERSION theVersion)
1227 throw(SALOME::SALOME_Exception)
1229 Unexpect aCatch(SALOME_SalomeException);
1231 // Update Python script
1232 TCollection_AsciiString aStr;
1233 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1234 aStr += TCollection_AsciiString((char*)file) + "\", ";
1235 aStr += TCollection_AsciiString((int)auto_groups) + ", ";
1236 switch (theVersion) {
1237 case SMESH::MED_V2_1:
1238 aStr += "SMESH.MED_V2_1)";
1240 case SMESH::MED_V2_2:
1241 aStr += "SMESH.MED_V2_2)";
1244 aStr += TCollection_AsciiString(theVersion) + ")";
1248 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1251 char* aMeshName = "Mesh";
1252 SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
1253 if ( !aStudy->_is_nil() ) {
1254 SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
1255 if ( !aMeshSO->_is_nil() ) {
1256 aMeshName = aMeshSO->GetName();
1258 //SCRUTE(aMeshName);
1259 //SCRUTE(aMeshSO->GetID());
1261 // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
1262 if ( !aStudy->GetProperties()->IsLocked() )
1264 SALOMEDS::GenericAttribute_var anAttr;
1265 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1266 SALOMEDS::AttributeExternalFileDef_var aFileName;
1267 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
1268 aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
1269 ASSERT(!aFileName->_is_nil());
1270 aFileName->SetValue(file);
1271 SALOMEDS::AttributeFileType_var aFileType;
1272 anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
1273 aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
1274 ASSERT(!aFileType->_is_nil());
1275 aFileType->SetValue("FICHIERMED");
1279 _impl->ExportMED( file, aMeshName, auto_groups, theVersion );
1282 void SMESH_Mesh_i::ExportMED (const char* file,
1283 CORBA::Boolean auto_groups)
1284 throw(SALOME::SALOME_Exception)
1286 ExportToMED(file,auto_groups,SMESH::MED_V2_1);
1289 void SMESH_Mesh_i::ExportDAT (const char *file)
1290 throw(SALOME::SALOME_Exception)
1292 Unexpect aCatch(SALOME_SalomeException);
1294 // Update Python script
1295 TCollection_AsciiString aStr;
1296 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportDAT(\"";
1297 aStr += TCollection_AsciiString((char*)file) + "\")";
1299 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1302 _impl->ExportDAT(file);
1305 void SMESH_Mesh_i::ExportUNV (const char *file)
1306 throw(SALOME::SALOME_Exception)
1308 Unexpect aCatch(SALOME_SalomeException);
1310 // Update Python script
1311 TCollection_AsciiString aStr;
1312 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportUNV(\"";
1313 aStr += TCollection_AsciiString((char*)file) + "\")";
1315 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1318 _impl->ExportUNV(file);
1321 void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
1322 throw(SALOME::SALOME_Exception)
1324 Unexpect aCatch(SALOME_SalomeException);
1326 // Update Python script
1327 TCollection_AsciiString aStr;
1328 SMESH_Gen_i::AddObject(aStr, _this()) += ".ExportToMED(\"";
1329 aStr += TCollection_AsciiString((char*)file) + "\", ";
1330 aStr += TCollection_AsciiString((int)isascii) + ")";
1332 SMESH_Gen_i::AddToCurrentPyScript(aStr);
1335 _impl->ExportSTL(file, isascii);
1338 //=============================================================================
1342 //=============================================================================
1344 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
1346 Unexpect aCatch(SALOME_SalomeException);
1347 SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
1348 SALOME_MED::MESH_var aMesh = aMedMesh->_this();
1349 return aMesh._retn();
1352 //=============================================================================
1356 //=============================================================================
1357 CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
1359 Unexpect aCatch(SALOME_SalomeException);
1360 return _impl->NbNodes();
1363 //=============================================================================
1367 //=============================================================================
1368 CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
1370 Unexpect aCatch(SALOME_SalomeException);
1371 return NbEdges() + NbFaces() + NbVolumes();
1374 //=============================================================================
1378 //=============================================================================
1379 CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
1381 Unexpect aCatch(SALOME_SalomeException);
1382 return _impl->NbEdges();
1385 //=============================================================================
1389 //=============================================================================
1390 CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
1392 Unexpect aCatch(SALOME_SalomeException);
1393 return _impl->NbFaces();
1396 CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
1398 Unexpect aCatch(SALOME_SalomeException);
1399 return _impl->NbTriangles();
1402 CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
1404 Unexpect aCatch(SALOME_SalomeException);
1405 return _impl->NbQuadrangles();
1408 CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
1410 Unexpect aCatch(SALOME_SalomeException);
1411 return _impl->NbPolygons();
1414 //=============================================================================
1418 //=============================================================================
1419 CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
1421 Unexpect aCatch(SALOME_SalomeException);
1422 return _impl->NbVolumes();
1425 CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
1427 Unexpect aCatch(SALOME_SalomeException);
1428 return _impl->NbTetras();
1431 CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
1433 Unexpect aCatch(SALOME_SalomeException);
1434 return _impl->NbHexas();
1437 CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
1439 Unexpect aCatch(SALOME_SalomeException);
1440 return _impl->NbPyramids();
1443 CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
1445 Unexpect aCatch(SALOME_SalomeException);
1446 return _impl->NbPrisms();
1449 CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
1451 Unexpect aCatch(SALOME_SalomeException);
1452 return _impl->NbPolyhedrons();
1455 //=============================================================================
1459 //=============================================================================
1460 CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
1462 Unexpect aCatch(SALOME_SalomeException);
1463 return _impl->NbSubMesh();
1466 //=============================================================================
1470 //=============================================================================
1471 char* SMESH_Mesh_i::Dump()
1473 std::ostringstream os;
1475 return CORBA::string_dup( os.str().c_str() );
1478 //=============================================================================
1482 //=============================================================================
1483 SMESH::long_array* SMESH_Mesh_i::GetIDs()
1485 SMESH::long_array_var aResult = new SMESH::long_array();
1486 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1487 int aMinId = aSMESHDS_Mesh->MinElementID();
1488 int aMaxId = aSMESHDS_Mesh->MaxElementID();
1490 aResult->length(aMaxId - aMinId + 1);
1492 for (int i = 0, id = aMinId; id <= aMaxId; id++ )
1495 return aResult._retn();
1498 //=============================================================================
1502 //=============================================================================
1504 SMESH::long_array* SMESH_Mesh_i::GetElementsId()
1505 throw (SALOME::SALOME_Exception)
1507 Unexpect aCatch(SALOME_SalomeException);
1508 MESSAGE("SMESH_Mesh_i::GetElementsId");
1509 SMESH::long_array_var aResult = new SMESH::long_array();
1510 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1512 if ( aSMESHDS_Mesh == NULL )
1513 return aResult._retn();
1515 long nbElements = NbElements();
1516 aResult->length( nbElements );
1517 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1518 for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
1519 aResult[i] = anIt->next()->GetID();
1521 return aResult._retn();
1525 //=============================================================================
1529 //=============================================================================
1531 SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
1532 throw (SALOME::SALOME_Exception)
1534 Unexpect aCatch(SALOME_SalomeException);
1535 MESSAGE("SMESH_subMesh_i::GetElementsByType");
1536 SMESH::long_array_var aResult = new SMESH::long_array();
1537 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1539 if ( aSMESHDS_Mesh == NULL )
1540 return aResult._retn();
1542 long nbElements = NbElements();
1544 // No sense in returning ids of elements along with ids of nodes:
1545 // when theElemType == SMESH::ALL, return node ids only if
1546 // there are no elements
1547 if ( theElemType == SMESH::NODE || theElemType == SMESH::ALL && nbElements == 0 )
1548 return GetNodesId();
1550 aResult->length( nbElements );
1554 SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
1555 while ( i < nbElements && anIt->more() ) {
1556 const SMDS_MeshElement* anElem = anIt->next();
1557 if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
1558 aResult[i++] = anElem->GetID();
1561 aResult->length( i );
1563 return aResult._retn();
1566 //=============================================================================
1570 //=============================================================================
1572 SMESH::long_array* SMESH_Mesh_i::GetNodesId()
1573 throw (SALOME::SALOME_Exception)
1575 Unexpect aCatch(SALOME_SalomeException);
1576 MESSAGE("SMESH_subMesh_i::GetNodesId");
1577 SMESH::long_array_var aResult = new SMESH::long_array();
1578 SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
1580 if ( aSMESHDS_Mesh == NULL )
1581 return aResult._retn();
1583 long nbNodes = NbNodes();
1584 aResult->length( nbNodes );
1585 SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator();
1586 for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
1587 aResult[i] = anIt->next()->GetID();
1589 return aResult._retn();