Salome HOME
NRI : First integration.
[modules/smesh.git] / src / SMDS / SMDS_MeshGroup.cxx
1 using namespace std;
2 // File:        SMDS_MeshGroup.cxx
3 // Created:     Mon Jun  3 12:15:55 2002
4 // Author:      Jean-Michel BOULCOURT
5 //              <jmb@localhost.localdomain>
6
7
8 #include "SMDS_MeshGroup.ixx"
9 #include "SMDS_ListIteratorOfListOfMeshGroup.hxx"
10
11 //=======================================================================
12 //function : SMDS_MeshGroup
13 //purpose  : 
14 //=======================================================================
15
16 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_Mesh)& aMesh)
17   :myMesh(aMesh),myType(SMDSAbs_All)
18 {
19 }
20
21 //=======================================================================
22 //function : SMDS_MeshGroup
23 //purpose  : 
24 //=======================================================================
25
26 SMDS_MeshGroup::SMDS_MeshGroup(const Handle(SMDS_MeshGroup)& parent)
27   :myMesh(parent->myMesh),myType(SMDSAbs_All),myParent(parent)
28 {
29 }
30
31 //=======================================================================
32 //function : AddSubGroup
33 //purpose  : 
34 //=======================================================================
35
36 Handle(SMDS_MeshGroup) SMDS_MeshGroup::AddSubGroup()
37 {
38   Handle(SMDS_MeshGroup) subgroup = new SMDS_MeshGroup(this);
39   if (!subgroup.IsNull()) {
40     myChildren.Append(subgroup);
41   }
42   return subgroup;
43 }
44
45 //=======================================================================
46 //function : RemoveSubGroup
47 //purpose  : 
48 //=======================================================================
49
50 Standard_Boolean SMDS_MeshGroup::RemoveSubGroup(const Handle(SMDS_MeshGroup)& aGroup)
51 {
52   Standard_Boolean found = Standard_False;
53
54   SMDS_ListIteratorOfListOfMeshGroup itgroup(myChildren);
55   for (;itgroup.More() && !found; itgroup.Next()) {
56     Handle(SMDS_MeshGroup) subgroup;
57     subgroup = itgroup.Value();
58     if (subgroup == aGroup) {
59       found = Standard_True;
60       myChildren.Remove(itgroup);
61     }
62   }
63
64   return found;
65 }
66
67 //=======================================================================
68 //function : RemoveFromParent
69 //purpose  : 
70 //=======================================================================
71
72 Standard_Boolean SMDS_MeshGroup::RemoveFromParent()
73 {
74   if (myParent.IsNull())
75     return Standard_False;
76
77   return (myParent->RemoveSubGroup(this));
78
79 }
80
81 //=======================================================================
82 //function : Clear
83 //purpose  : 
84 //=======================================================================
85
86 void SMDS_MeshGroup::Clear()
87 {
88   myElements.Clear();
89   myType = SMDSAbs_All;
90 }
91
92 //=======================================================================
93 //function : IsEmpty
94 //purpose  : 
95 //=======================================================================
96
97 Standard_Boolean SMDS_MeshGroup::IsEmpty() const
98 {
99   return myElements.IsEmpty();
100 }
101
102 //=======================================================================
103 //function : Extent
104 //purpose  : 
105 //=======================================================================
106
107 Standard_Integer SMDS_MeshGroup::Extent() const
108 {
109   return myElements.Extent();
110 }
111
112 //=======================================================================
113 //function : Add
114 //purpose  : 
115 //=======================================================================
116
117 void SMDS_MeshGroup::Add(const Handle(SMDS_MeshElement)& ME)
118 {
119   // the type of the group is determined by the first element added
120   if (myElements.IsEmpty()) {
121     myType = ME->GetType();
122   }
123
124   if (ME->GetType() != myType) { 
125     Standard_TypeMismatch::Raise("SMDS_MeshGroup::Add");
126   }
127
128   myElements.Add(ME);
129 }
130
131
132 //=======================================================================
133 //function : Remove
134 //purpose  : 
135 //=======================================================================
136
137 void SMDS_MeshGroup::Remove(const Handle(SMDS_MeshElement)& ME)
138 {
139   myElements.Remove(ME);
140   if (myElements.IsEmpty())
141     myType = SMDSAbs_All;
142 }
143
144 //=======================================================================
145 //function : Type
146 //purpose  : 
147 //=======================================================================
148
149 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
150 {
151   return myType;
152 }
153
154 //=======================================================================
155 //function : Contains
156 //purpose  : 
157 //=======================================================================
158
159 Standard_Boolean SMDS_MeshGroup::Contains(const Handle(SMDS_MeshElement)& ME) const
160 {
161   return myElements.Contains(ME);
162 }