Salome HOME
sources v1.2
[modules/smesh.git] / src / SMDS / SMDS_MeshGroup.cxx
1 //  SMESH SMDS : implementaion of Salome mesh data structure
2 //
3 //  Copyright (C) 2003  OPEN CASCADE
4 // 
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. 
9 // 
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. 
14 // 
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 
18 // 
19 //  See http://www.opencascade.org or email : webmaster@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMDS_MeshGroup.cxx
24 //  Author : Jean-Michel BOULCOURT
25 //  Module : SMESH
26
27 using namespace std;
28 #include "SMDS_MeshGroup.ixx"
29 #include "SMDS_ListIteratorOfListOfMeshGroup.hxx"
30
31 //=======================================================================
32 //function : SMDS_MeshGroup
33 //purpose  : 
34 //=======================================================================
35
36 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_Mesh)& aMesh)
37   :myMesh(aMesh),myType(SMDSAbs_All)
38 {
39 }
40
41 //=======================================================================
42 //function : SMDS_MeshGroup
43 //purpose  : 
44 //=======================================================================
45
46 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_MeshGroup)& parent)
47   :myMesh(parent->myMesh),myType(SMDSAbs_All),myParent(parent)
48 {
49 }
50
51 //=======================================================================
52 //function : AddSubGroup
53 //purpose  : 
54 //=======================================================================
55
56 Handle(SMDS_MeshGroup) SMDS_MeshGroup::AddSubGroup()
57 {
58   Handle(SMDS_MeshGroup) subgroup = new SMDS_MeshGroup(this);
59   if (!subgroup.IsNull()) {
60     myChildren.Append(subgroup);
61   }
62   return subgroup;
63 }
64
65 //=======================================================================
66 //function : RemoveSubGroup
67 //purpose  : 
68 //=======================================================================
69
70 Standard_Boolean SMDS_MeshGroup::RemoveSubGroup(const Handle(SMDS_MeshGroup)& aGroup)
71 {
72   Standard_Boolean found = Standard_False;
73
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);
81     }
82   }
83
84   return found;
85 }
86
87 //=======================================================================
88 //function : RemoveFromParent
89 //purpose  : 
90 //=======================================================================
91
92 Standard_Boolean SMDS_MeshGroup::RemoveFromParent()
93 {
94   if (myParent.IsNull())
95     return Standard_False;
96
97   return (myParent->RemoveSubGroup(this));
98
99 }
100
101 //=======================================================================
102 //function : Clear
103 //purpose  : 
104 //=======================================================================
105
106 void SMDS_MeshGroup::Clear()
107 {
108   myElements.Clear();
109   myType = SMDSAbs_All;
110 }
111
112 //=======================================================================
113 //function : IsEmpty
114 //purpose  : 
115 //=======================================================================
116
117 Standard_Boolean SMDS_MeshGroup::IsEmpty() const
118 {
119   return myElements.IsEmpty();
120 }
121
122 //=======================================================================
123 //function : Extent
124 //purpose  : 
125 //=======================================================================
126
127 Standard_Integer SMDS_MeshGroup::Extent() const
128 {
129   return myElements.Extent();
130 }
131
132 //=======================================================================
133 //function : Add
134 //purpose  : 
135 //=======================================================================
136
137 void SMDS_MeshGroup::Add(const Handle(SMDS_MeshElement)& ME)
138 {
139   // the type of the group is determined by the first element added
140   if (myElements.IsEmpty()) {
141     myType = ME->GetType();
142   }
143
144   if (ME->GetType() != myType) { 
145     Standard_TypeMismatch::Raise("SMDS_MeshGroup::Add");
146   }
147
148   myElements.Add(ME);
149 }
150
151
152 //=======================================================================
153 //function : Remove
154 //purpose  : 
155 //=======================================================================
156
157 void SMDS_MeshGroup::Remove(const Handle(SMDS_MeshElement)& ME)
158 {
159   myElements.Remove(ME);
160   if (myElements.IsEmpty())
161     myType = SMDSAbs_All;
162 }
163
164 //=======================================================================
165 //function : Type
166 //purpose  : 
167 //=======================================================================
168
169 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
170 {
171   return myType;
172 }
173
174 //=======================================================================
175 //function : Contains
176 //purpose  : 
177 //=======================================================================
178
179 Standard_Boolean SMDS_MeshGroup::Contains(const Handle(SMDS_MeshElement)& ME) const
180 {
181   return myElements.Contains(ME);
182 }