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_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 //=======================================================================
83 //=======================================================================
85 bool SMESHDS_Group::Contains (const SMDS_MeshElement* elem)
88 return myGroup.Contains(elem);
92 //=============================================================================
96 //=============================================================================
98 bool SMESHDS_Group::Add (const int theID)
100 const SMDS_MeshElement* aElem = findInMesh (theID);
101 if (!aElem || myGroup.Contains(aElem))
104 if (myGroup.IsEmpty())
105 SetType( aElem->GetType() );
112 //=============================================================================
116 //=============================================================================
118 bool SMESHDS_Group::Remove (const int theID)
120 const SMDS_MeshElement* aElem = findInMesh (theID);
121 if (!aElem || !myGroup.Contains(aElem))
123 myGroup.Remove (aElem);
129 //======================================================================
132 //=======================================================================
134 void SMESHDS_Group::Clear()
140 // =====================
141 // class MyGroupIterator
142 // =====================
144 class MyGroupIterator: public SMDS_ElemIterator
146 const SMDS_MeshGroup& myGroup;
148 MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); }
149 bool more() { return myGroup.More(); }
150 const SMDS_MeshElement* next() { return myGroup.Next(); }
153 //=======================================================================
154 //function : GetElements
156 //=======================================================================
158 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements()
160 return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup ));
163 //=======================================================================
166 //=======================================================================
168 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType)
170 if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) {
171 SMESHDS_GroupBase::SetType( theType );
172 myGroup.SetType ( theType );
175 SMESHDS_GroupBase::SetType( myGroup.GetType() );