1 // Copyright (C) 2007-2014 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_Group.cxx
28 #include "SMESHDS_Group.hxx"
29 #include "SMESHDS_Mesh.hxx"
33 //=============================================================================
37 //=============================================================================
39 SMESHDS_Group::SMESHDS_Group (const int theID,
40 const SMESHDS_Mesh* theMesh,
41 const SMDSAbs_ElementType theType)
42 : SMESHDS_GroupBase(theID,theMesh,theType),
43 myGroup(theMesh,theType)
47 //=======================================================================
50 //=======================================================================
52 int SMESHDS_Group::Extent() const
54 return myGroup.Extent();
57 //=======================================================================
60 //=======================================================================
62 bool SMESHDS_Group::IsEmpty()
64 return myGroup.IsEmpty();
67 //=============================================================================
71 //=============================================================================
73 bool SMESHDS_Group::Contains (const int theID)
75 const SMDS_MeshElement* aElem = findInMesh (theID);
77 return myGroup.Contains(aElem);
81 //=======================================================================
84 //=======================================================================
86 bool SMESHDS_Group::Contains (const SMDS_MeshElement* elem)
89 return myGroup.Contains(elem);
93 //=============================================================================
97 //=============================================================================
99 bool SMESHDS_Group::Add (const int theID)
101 const SMDS_MeshElement* aElem = findInMesh (theID);
102 if (!aElem || myGroup.Contains(aElem))
105 if (myGroup.IsEmpty())
106 SetType( aElem->GetType() );
113 //=============================================================================
117 //=============================================================================
119 bool SMESHDS_Group::Remove (const int theID)
121 const SMDS_MeshElement* aElem = findInMesh (theID);
122 if (!aElem || !myGroup.Contains(aElem))
124 myGroup.Remove (aElem);
130 //======================================================================
133 //=======================================================================
135 void SMESHDS_Group::Clear()
141 // =====================
142 // class MyGroupIterator
143 // =====================
145 class MyGroupIterator: public SMDS_ElemIterator
147 const SMDS_MeshGroup& myGroup;
149 MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); }
150 bool more() { return myGroup.More(); }
151 const SMDS_MeshElement* next() { return myGroup.Next(); }
154 //=======================================================================
155 //function : GetElements
157 //=======================================================================
159 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements() const
161 return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup ));
164 //================================================================================
166 * \brief Return a value allowing to find out if a group has changed or not
168 //================================================================================
170 int SMESHDS_Group::GetTic() const
172 return myGroup.Tic();
175 //=======================================================================
178 //=======================================================================
180 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType)
182 if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) {
183 SMESHDS_GroupBase::SetType( theType );
184 myGroup.SetType ( theType );
187 SMESHDS_GroupBase::SetType( myGroup.GetType() );