1 // SMESH SMDS : implementaion of Salome mesh data structure
3 // Copyright (C) 2003 OPEN CASCADE
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.opencascade.org or email : webmaster@opencascade.org
23 // File : SMDS_MeshGroup.cxx
24 // Author : Jean-Michel BOULCOURT
28 #include "SMDS_MeshGroup.ixx"
29 #include "SMDS_ListIteratorOfListOfMeshGroup.hxx"
31 //=======================================================================
32 //function : SMDS_MeshGroup
34 //=======================================================================
36 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_Mesh)& aMesh)
37 :myMesh(aMesh),myType(SMDSAbs_All)
41 //=======================================================================
42 //function : SMDS_MeshGroup
44 //=======================================================================
46 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_MeshGroup)& parent)
47 :myMesh(parent->myMesh),myType(SMDSAbs_All),myParent(parent)
51 //=======================================================================
52 //function : AddSubGroup
54 //=======================================================================
56 Handle(SMDS_MeshGroup) SMDS_MeshGroup::AddSubGroup()
58 Handle(SMDS_MeshGroup) subgroup = new SMDS_MeshGroup(this);
59 if (!subgroup.IsNull()) {
60 myChildren.Append(subgroup);
65 //=======================================================================
66 //function : RemoveSubGroup
68 //=======================================================================
70 Standard_Boolean SMDS_MeshGroup::RemoveSubGroup(const Handle(SMDS_MeshGroup)& aGroup)
72 Standard_Boolean found = Standard_False;
74 SMDS_ListIteratorOfListOfMeshGroup itgroup(myChildren);
75 for (;itgroup.More() && !found; itgroup.Next()) {
76 Handle(SMDS_MeshGroup) subgroup;
77 subgroup = itgroup.Value();
78 if (subgroup == aGroup) {
79 found = Standard_True;
80 myChildren.Remove(itgroup);
87 //=======================================================================
88 //function : RemoveFromParent
90 //=======================================================================
92 Standard_Boolean SMDS_MeshGroup::RemoveFromParent()
94 if (myParent.IsNull())
95 return Standard_False;
97 return (myParent->RemoveSubGroup(this));
101 //=======================================================================
104 //=======================================================================
106 void SMDS_MeshGroup::Clear()
109 myType = SMDSAbs_All;
112 //=======================================================================
115 //=======================================================================
117 Standard_Boolean SMDS_MeshGroup::IsEmpty() const
119 return myElements.IsEmpty();
122 //=======================================================================
125 //=======================================================================
127 Standard_Integer SMDS_MeshGroup::Extent() const
129 return myElements.Extent();
132 //=======================================================================
135 //=======================================================================
137 void SMDS_MeshGroup::Add(const Handle(SMDS_MeshElement)& ME)
139 // the type of the group is determined by the first element added
140 if (myElements.IsEmpty()) {
141 myType = ME->GetType();
144 if (ME->GetType() != myType) {
145 Standard_TypeMismatch::Raise("SMDS_MeshGroup::Add");
152 //=======================================================================
155 //=======================================================================
157 void SMDS_MeshGroup::Remove(const Handle(SMDS_MeshElement)& ME)
159 myElements.Remove(ME);
160 if (myElements.IsEmpty())
161 myType = SMDSAbs_All;
164 //=======================================================================
167 //=======================================================================
169 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
174 //=======================================================================
175 //function : Contains
177 //=======================================================================
179 Standard_Boolean SMDS_MeshGroup::Contains(const Handle(SMDS_MeshElement)& ME) const
181 return myElements.Contains(ME);