Salome HOME
Remove Opencascade dependencies
[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.hxx"
29 #include "utilities.h"
30 //=======================================================================
31 //function : SMDS_MeshGroup
32 //purpose  : 
33 //=======================================================================
34
35 SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * aMesh)
36         :myMesh(aMesh),myType(SMDSAbs_All), myParent(NULL)
37 {
38 }
39
40 //=======================================================================
41 //function : SMDS_MeshGroup
42 //purpose  : 
43 //=======================================================================
44
45 SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * parent)
46         :myMesh(parent->myMesh),myType(SMDSAbs_All), myParent(parent)
47 {
48 }
49
50 //=======================================================================
51 //function : AddSubGroup
52 //purpose  : 
53 //=======================================================================
54
55 const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup()
56 {
57         const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this);
58         myChildren.insert(myChildren.end(),subgroup);
59         return subgroup;
60 }
61
62 //=======================================================================
63 //function : RemoveSubGroup
64 //purpose  : 
65 //=======================================================================
66
67 bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * aGroup)
68 {
69         bool found = false;     
70         list<const SMDS_MeshGroup*>::iterator itgroup;
71         for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++)
72         {
73                 const SMDS_MeshGroup* subgroup=*itgroup;
74                 if (subgroup == aGroup)
75                 {
76                         found = true;
77                         myChildren.erase(itgroup);
78                 }
79         }
80
81         return found;
82 }
83
84 //=======================================================================
85 //function : RemoveFromParent
86 //purpose  : 
87 //=======================================================================
88
89 bool SMDS_MeshGroup::RemoveFromParent()
90 {
91         
92         if (myParent==NULL) return false;
93         else
94         {
95                 return (myParent->RemoveSubGroup(this));
96         }
97 }
98 //=======================================================================
99 //function : Clear
100 //purpose  : 
101 //=======================================================================
102
103 void SMDS_MeshGroup::Clear()
104 {
105         myElements.clear();
106         myType = SMDSAbs_All;
107 }
108
109 //=======================================================================
110 //function : IsEmpty
111 //purpose  : 
112 //=======================================================================
113
114 bool SMDS_MeshGroup::IsEmpty() const
115 {
116         return myElements.empty();
117 }
118
119 //=======================================================================
120 //function : Extent
121 //purpose  : 
122 //=======================================================================
123
124 int SMDS_MeshGroup::Extent() const
125 {
126         return myElements.size();
127 }
128
129 //=======================================================================
130 //function : Add
131 //purpose  : 
132 //=======================================================================
133
134 void SMDS_MeshGroup::Add(const SMDS_MeshElement * ME)
135 {
136         // the type of the group is determined by the first element added
137         if (myElements.empty()) myType = ME->GetType();
138         else if (ME->GetType() != myType)
139                 MESSAGE("SMDS_MeshGroup::Add : Type Mismatch");
140         
141         myElements.insert(ME);
142 }
143
144 //=======================================================================
145 //function : Remove
146 //purpose  : 
147 //=======================================================================
148
149 void SMDS_MeshGroup::Remove(const SMDS_MeshElement * ME)
150 {
151         myElements.erase(ME);
152         if (myElements.empty()) myType = SMDSAbs_All;
153 }
154
155 //=======================================================================
156 //function : Type
157 //purpose  : 
158 //=======================================================================
159
160 SMDSAbs_ElementType SMDS_MeshGroup::Type() const
161 {
162         return myType;
163 }
164
165 //=======================================================================
166 //function : Contains
167 //purpose  : 
168 //=======================================================================
169
170 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * ME) const
171 {
172         return myElements.find(ME)!=myElements.end();
173 }