1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
24 // File : SMESHDS_GroupOnGeom.cxx
27 #include "SMESHDS_GroupOnGeom.hxx"
28 #include "SMESHDS_Mesh.hxx"
29 #include "utilities.h"
33 //=============================================================================
37 //=============================================================================
39 SMESHDS_GroupOnGeom::SMESHDS_GroupOnGeom (const int theID,
40 const SMESHDS_Mesh* theMesh,
41 const SMDSAbs_ElementType theType,
42 const TopoDS_Shape& theShape)
43 : SMESHDS_GroupBase(theID,theMesh,theType)
48 void SMESHDS_GroupOnGeom::SetShape( const TopoDS_Shape& theShape)
50 SMESHDS_Mesh* aMesh = const_cast<SMESHDS_Mesh*>( GetMesh() );
51 mySubMesh = aMesh->MeshElements( aMesh->AddCompoundSubmesh( theShape ));
55 // =====================
56 // class MyGroupIterator
57 // =====================
59 class MyIterator: public SMDS_ElemIterator
61 SMDSAbs_ElementType myType;
62 SMDS_ElemIteratorPtr myElemIt;
63 SMDS_NodeIteratorPtr myNodeIt;
64 const SMDS_MeshElement* myElem;
66 MyIterator(SMDSAbs_ElementType type, const SMESHDS_SubMesh* subMesh)
67 : myType(type), myElem(0)
70 if ( myType == SMDSAbs_Node )
71 myNodeIt = subMesh->GetNodes();
73 myElemIt = subMesh->GetElements();
80 if ( myType == SMDSAbs_Node && myNodeIt )
81 return myNodeIt->more();
82 return ( myElem != 0 );
84 const SMDS_MeshElement* next()
86 if ( myType == SMDSAbs_Node && myNodeIt )
87 return myNodeIt->next();
88 const SMDS_MeshElement* res = myElem;
90 while ( myElemIt && myElemIt->more() ) {
91 myElem = myElemIt->next();
92 if ( myElem && myElem->GetType() == myType )
101 //=======================================================================
102 //function : GetElements
104 //=======================================================================
106 SMDS_ElemIteratorPtr SMESHDS_GroupOnGeom::GetElements() const
108 return SMDS_ElemIteratorPtr( new MyIterator ( GetType(), mySubMesh ));
111 //=======================================================================
112 //function : Contains
114 //=======================================================================
116 bool SMESHDS_GroupOnGeom::Contains (const int theID)
118 return mySubMesh->Contains( findInMesh( theID ));
121 //=======================================================================
122 //function : Contains
124 //=======================================================================
126 bool SMESHDS_GroupOnGeom::Contains (const SMDS_MeshElement* elem)
128 return mySubMesh->Contains( elem );
131 //================================================================================
133 * \brief Return a value allowing to find out if a group has changed or not
135 //================================================================================
137 int SMESHDS_GroupOnGeom::GetTic() const
139 return GetMesh()->GetMTime();