Salome HOME
23418: [OCC] Mesh: Minimization of memory usage of SMESH
[modules/smesh.git] / src / SMESHDS / SMESHDS_Group.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 //  File   : SMESHDS_Group.cxx
23 //  Module : SMESH
24 //
25
26 #include "SMESHDS_Group.hxx"
27 #include "SMESHDS_Mesh.hxx"
28
29 //=============================================================================
30 /*!
31  *  
32  */
33 //=============================================================================
34
35 SMESHDS_Group::SMESHDS_Group (const int                 theID,
36                               const SMESHDS_Mesh*       theMesh,
37                               const SMDSAbs_ElementType theType)
38   : SMESHDS_GroupBase(theID,theMesh,theType),
39     myGroup(theMesh,theType)
40 {
41 }
42
43 //=======================================================================
44 //function : Extent
45 //purpose  : 
46 //=======================================================================
47
48 int SMESHDS_Group::Extent() const
49 {
50   return myGroup.Extent();
51 }
52
53 //=======================================================================
54 //function : IsEmpty
55 //purpose  : 
56 //=======================================================================
57
58 bool SMESHDS_Group::IsEmpty()
59 {
60   return myGroup.IsEmpty();
61 }
62
63 //=============================================================================
64 /*!
65  *  
66  */
67 //=============================================================================
68
69 bool SMESHDS_Group::Contains (const int theID)
70 {
71   const SMDS_MeshElement* aElem = findInMesh (theID);
72   if (aElem)
73     return myGroup.Contains(aElem);
74   return false;
75 }
76
77 //=======================================================================
78 //function : Contains
79 //purpose  : 
80 //=======================================================================
81
82 bool SMESHDS_Group::Contains (const SMDS_MeshElement* elem)
83 {
84   if (elem)
85     return myGroup.Contains(elem);
86   return false;
87 }
88
89 //=============================================================================
90 /*!
91  *  
92  */
93 //=============================================================================
94
95 bool SMESHDS_Group::Add (const int theID)
96 {
97   return Add( findInMesh( theID ));
98 }
99
100 //=============================================================================
101 /*!
102  *  
103  */
104 //=============================================================================
105
106 bool SMESHDS_Group::Add (const SMDS_MeshElement* aElem )
107 {
108   if (!aElem || myGroup.Contains(aElem))
109     return false;
110
111   if (myGroup.IsEmpty())
112     SetType( aElem->GetType() );
113
114   myGroup.Add (aElem);
115   resetIterator();
116   return true;
117 }
118
119 //=============================================================================
120 /*!
121  *  
122  */
123 //=============================================================================
124
125 bool SMESHDS_Group::Remove (const int theID)
126 {
127   const SMDS_MeshElement* aElem = findInMesh (theID);
128   if (!aElem || !myGroup.Contains(aElem))
129     return false;
130   myGroup.Remove (aElem);
131   resetIterator();
132   return true;
133 }
134
135
136 //======================================================================
137 //function : Clear
138 //purpose  : 
139 //=======================================================================
140
141 void SMESHDS_Group::Clear()
142 {
143   myGroup.Clear();
144   resetIterator();
145 }
146   
147 //=======================================================================
148 //function : GetElements
149 //purpose  : 
150 //=======================================================================
151
152 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements() const
153 {
154   return myGroup.GetElements();
155 }
156
157 //================================================================================
158 /*!
159  * \brief Return a value allowing to find out if a group has changed or not
160  */
161 //================================================================================
162
163 int SMESHDS_Group::GetTic() const
164 {
165   return myGroup.Tic();
166 }
167
168 //=======================================================================
169 //function : SetType
170 //purpose  : 
171 //=======================================================================
172
173 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType)
174 {
175   if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All )
176   {
177     SMESHDS_GroupBase::SetType( theType );
178     myGroup.SetType ( theType );
179   }
180   else
181   {
182     SMESHDS_GroupBase::SetType( myGroup.GetType() );
183   }
184 }
185