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