1 // SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
3 // Copyright (C) 2004 CEA
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License.
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : SMESHDS_Group.cxx
27 #include "SMESHDS_Group.hxx"
28 #include "SMESHDS_Mesh.hxx"
32 //=============================================================================
36 //=============================================================================
38 SMESHDS_Group::SMESHDS_Group (const int theID,
39 const SMESHDS_Mesh* theMesh,
40 const SMDSAbs_ElementType theType)
41 : SMESHDS_GroupBase(theID,theMesh,theType),
42 myGroup(theMesh,theType)
46 //=======================================================================
49 //=======================================================================
51 int SMESHDS_Group::Extent()
53 return myGroup.Extent();
56 //=======================================================================
59 //=======================================================================
61 bool SMESHDS_Group::IsEmpty()
63 return myGroup.IsEmpty();
66 //=============================================================================
70 //=============================================================================
72 bool SMESHDS_Group::Contains (const int theID)
74 const SMDS_MeshElement* aElem = findInMesh (theID);
76 return myGroup.Contains(aElem);
80 //=============================================================================
84 //=============================================================================
86 bool SMESHDS_Group::Add (const int theID)
88 const SMDS_MeshElement* aElem = findInMesh (theID);
89 if (!aElem || myGroup.Contains(aElem))
92 if (myGroup.IsEmpty())
93 SetType( aElem->GetType() );
100 //=============================================================================
104 //=============================================================================
106 bool SMESHDS_Group::Remove (const int theID)
108 const SMDS_MeshElement* aElem = findInMesh (theID);
109 if (!aElem || !myGroup.Contains(aElem))
111 myGroup.Remove (aElem);
116 //=======================================================================
119 //=======================================================================
121 void SMESHDS_Group::Clear()
127 // =====================
128 // class MyGroupIterator
129 // =====================
131 class MyGroupIterator: public SMDS_ElemIterator
133 const SMDS_MeshGroup& myGroup;
135 MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); }
136 bool more() { return myGroup.More(); }
137 const SMDS_MeshElement* next() { return myGroup.Next(); }
140 //=======================================================================
141 //function : GetElements
143 //=======================================================================
145 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements()
147 return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup ));
150 //=======================================================================
153 //=======================================================================
155 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType)
157 if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) {
158 SMESHDS_GroupBase::SetType( theType );
159 myGroup.SetType ( theType );
162 SMESHDS_GroupBase::SetType( myGroup.GetType() );