Salome HOME
54250: Wrong group contents after SplitQuad()
[modules/smesh.git] / src / SMDS / SMDS_MeshGroup.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMDS : implementaion of Salome mesh data structure
24 //  File   : SMDS_MeshGroup.cxx
25 //  Author : Jean-Michel BOULCOURT
26 //  Module : SMESH
27 //
28 #ifdef _MSC_VER
29 #pragma warning(disable:4786)
30 #endif
31
32 #include "SMDS_MeshGroup.hxx"
33 #include "utilities.h"
34
35 using namespace std;
36
37 //=======================================================================
38 //function : SMDS_MeshGroup
39 //purpose  : 
40 //=======================================================================
41
42 SMDS_MeshGroup::SMDS_MeshGroup(const SMDS_Mesh * theMesh,
43                                const SMDSAbs_ElementType theType)
44   :myMesh(theMesh),myType(theType), myParent(NULL), myTic(0)
45 {
46 }
47
48 //=======================================================================
49 //function : SMDS_MeshGroup
50 //purpose  : 
51 //=======================================================================
52
53 SMDS_MeshGroup::SMDS_MeshGroup(SMDS_MeshGroup * theParent,
54                                const SMDSAbs_ElementType theType)
55         :myMesh(theParent->myMesh),myType(theType), myParent(theParent)
56 {
57 }
58
59 //=======================================================================
60 //function : AddSubGroup
61 //purpose  : 
62 //=======================================================================
63
64 const SMDS_MeshGroup *SMDS_MeshGroup::AddSubGroup
65                 (const SMDSAbs_ElementType theType)
66 {
67         const SMDS_MeshGroup * subgroup = new SMDS_MeshGroup(this,theType);
68         myChildren.insert(myChildren.end(),subgroup);
69         return subgroup;
70 }
71
72 //=======================================================================
73 //function : RemoveSubGroup
74 //purpose  : 
75 //=======================================================================
76
77 bool SMDS_MeshGroup::RemoveSubGroup(const SMDS_MeshGroup * theGroup)
78 {
79         bool found = false;     
80         list<const SMDS_MeshGroup*>::iterator itgroup;
81         for(itgroup=myChildren.begin(); itgroup!=myChildren.end(); itgroup++)
82         {
83                 const SMDS_MeshGroup* subgroup=*itgroup;
84                 if (subgroup == theGroup)
85                 {
86                         found = true;
87                         myChildren.erase(itgroup);
88                 }
89         }
90
91         return found;
92 }
93
94 //=======================================================================
95 //function : RemoveFromParent
96 //purpose  : 
97 //=======================================================================
98
99 bool SMDS_MeshGroup::RemoveFromParent()
100 {
101         
102         if (myParent==NULL) return false;
103         else
104         {
105                 return (myParent->RemoveSubGroup(this));
106         }
107 }
108 //=======================================================================
109 //function : Clear
110 //purpose  : 
111 //=======================================================================
112
113 void SMDS_MeshGroup::Clear()
114 {
115   myElements.clear();
116   myType = SMDSAbs_All;
117   ++myTic;
118 }
119
120 //=======================================================================
121 //function : Add
122 //purpose  : 
123 //=======================================================================
124
125 bool SMDS_MeshGroup::Add(const SMDS_MeshElement * theElem)
126 {
127   // the type of the group is determined by the first element added
128   if (myElements.empty()) {
129     myType = theElem->GetType();
130   }
131   else if (theElem->GetType() != myType) {
132     MESSAGE("SMDS_MeshGroup::Add : Type Mismatch "<<theElem->GetType()<<"!="<<myType);
133     return false;
134   }
135         
136   myElements.insert(myElements.end(), theElem);
137   ++myTic;
138
139   return true;
140 }
141
142 //=======================================================================
143 //function : Remove
144 //purpose  : 
145 //=======================================================================
146
147 bool SMDS_MeshGroup::Remove(const SMDS_MeshElement * theElem)
148 {
149   set<const SMDS_MeshElement *>::iterator found = myElements.find(theElem);
150   if ( found != myElements.end() ) {
151     myElements.erase(found);
152     if (myElements.empty()) myType = SMDSAbs_All;
153     ++myTic;
154     return true;
155   }
156   return false;
157 }
158
159 //=======================================================================
160 //function : Contains
161 //purpose  : 
162 //=======================================================================
163
164 bool SMDS_MeshGroup::Contains(const SMDS_MeshElement * theElem) const
165 {
166   return myElements.find(theElem) != myElements.end();
167 }
168
169 //=======================================================================
170 //function : SetType
171 //purpose  : 
172 //=======================================================================
173
174 void SMDS_MeshGroup::SetType(const SMDSAbs_ElementType theType)
175 {
176   if (IsEmpty())
177     myType = theType;
178 }