1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
23 // File : SMESHDS_GroupOnGeom.cxx
26 #include "SMESHDS_GroupOnGeom.hxx"
27 #include "SMESHDS_Mesh.hxx"
28 #include "utilities.h"
32 //=============================================================================
36 //=============================================================================
38 SMESHDS_GroupOnGeom::SMESHDS_GroupOnGeom (const int theID,
39 const SMESHDS_Mesh* theMesh,
40 const SMDSAbs_ElementType theType,
41 const TopoDS_Shape& theShape)
42 : SMESHDS_GroupBase(theID,theMesh,theType)
47 void SMESHDS_GroupOnGeom::SetShape( const TopoDS_Shape& theShape)
49 SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>( GetMesh() );
50 mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
54 // =====================
55 // class MyGroupIterator
56 // =====================
58 class MyIterator: public SMDS_ElemIterator
60 SMDSAbs_ElementType myType;
61 SMDS_ElemIteratorPtr myElemIt;
62 SMDS_NodeIteratorPtr myNodeIt;
63 const SMDS_MeshElement* myElem;
65 MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
66 : myType(type), myElem(0)
69 if ( myType == SMDSAbs_Node )
70 myNodeIt = subMesh->GetNodes();
72 myElemIt = subMesh->GetElements();
78 if ( myType == SMDSAbs_Node && myNodeIt )
79 return myNodeIt->more();
80 return ( myElem != 0 );
82 const SMDS_MeshElement* next()
84 if ( myType == SMDSAbs_Node && myNodeIt )
85 return myNodeIt->next();
86 const SMDS_MeshElement* res = myElem;
88 while ( myElemIt && myElemIt->more() ) {
89 myElem = myElemIt->next();
90 if ( myElem && myElem->GetType() == myType )
99 //=======================================================================
100 //function : GetElements
102 //=======================================================================
104 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements()
106 return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
109 //=======================================================================
110 //function : Contains
112 //=======================================================================
114 bool SMESHDS_GroupOnGeom::Contains (const int theID)
116 return mySubMesh->Contains( findInMesh( theID ));
119 //=======================================================================
120 //function : Contains
122 //=======================================================================
124 bool SMESHDS_GroupOnGeom::Contains (const SMDS_MeshElement* elem)
126 return mySubMesh->Contains( elem );