Salome HOME
Fix PAL8562: rpath (rpath-link) option needs parameter - directory to search shared...
[modules/smesh.git] / src / SMESHDS / SMESHDS_Group.cxx
1 //  SMESH SMESHDS : idl implementation based on 'SMESH' unit's classes
2 //
3 //  Copyright (C) 2004  CEA
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.salome-platform.org or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMESHDS_Group.cxx
24 //  Module : SMESH
25 //  $Header$
26
27 #include "SMESHDS_Group.hxx"
28 #include "SMESHDS_Mesh.hxx"
29
30 using namespace std;
31
32 //=============================================================================
33 /*!
34  *  
35  */
36 //=============================================================================
37
38 SMESHDS_Group::SMESHDS_Group (const int                 theID,
39                               const SMESHDS_Mesh*       theMesh,
40                               const SMDSAbs_ElementType theType)
41      : SMESHDS_GroupBase(theID,theMesh,theType),
42        myGroup(theMesh,theType)
43 {
44 }
45
46 //=======================================================================
47 //function : Extent
48 //purpose  : 
49 //=======================================================================
50
51 int SMESHDS_Group::Extent()
52 {
53   return myGroup.Extent();
54 }
55
56 //=======================================================================
57 //function : IsEmpty
58 //purpose  : 
59 //=======================================================================
60
61 bool SMESHDS_Group::IsEmpty()
62 {
63   return myGroup.IsEmpty();
64 }
65
66 //=============================================================================
67 /*!
68  *  
69  */
70 //=============================================================================
71
72 bool SMESHDS_Group::Contains (const int theID)
73 {
74   const SMDS_MeshElement* aElem = findInMesh (theID);
75   if (aElem)
76     return myGroup.Contains(aElem);
77   return false;
78 }
79
80 //=============================================================================
81 /*!
82  *  
83  */
84 //=============================================================================
85
86 bool SMESHDS_Group::Add (const int theID)
87 {
88   const SMDS_MeshElement* aElem = findInMesh (theID);
89   if (!aElem || myGroup.Contains(aElem))
90     return false;
91
92   if (myGroup.IsEmpty())
93     SetType( aElem->GetType() );
94
95   myGroup.Add (aElem);
96   resetIterator();
97   return true;
98 }
99
100 //=============================================================================
101 /*!
102  *  
103  */
104 //=============================================================================
105
106 bool SMESHDS_Group::Remove (const int theID)
107 {
108   const SMDS_MeshElement* aElem = findInMesh (theID);
109   if (!aElem || !myGroup.Contains(aElem))
110     return false;
111   myGroup.Remove (aElem);
112   resetIterator();
113   return true;
114 }
115
116 //=======================================================================
117 //function : Clear
118 //purpose  : 
119 //=======================================================================
120
121 void SMESHDS_Group::Clear()
122 {
123   myGroup.Clear();
124   resetIterator();
125 }
126
127 // =====================
128 // class MyGroupIterator
129 // =====================
130
131 class MyGroupIterator: public SMDS_ElemIterator
132 {
133   const SMDS_MeshGroup& myGroup;
134  public:
135   MyGroupIterator(const SMDS_MeshGroup& group): myGroup(group) { myGroup.InitIterator(); }
136   bool more() { return myGroup.More(); }
137   const SMDS_MeshElement* next() { return myGroup.Next(); }
138 };
139    
140 //=======================================================================
141 //function : GetElements
142 //purpose  : 
143 //=======================================================================
144
145 SMDS_ElemIteratorPtr SMESHDS_Group::GetElements()
146 {
147   return SMDS_ElemIteratorPtr( new MyGroupIterator ( myGroup ));
148 }
149
150 //=======================================================================
151 //function : SetType
152 //purpose  : 
153 //=======================================================================
154
155 void SMESHDS_Group::SetType(SMDSAbs_ElementType theType)
156 {
157   if ( myGroup.IsEmpty() || GetType() == SMDSAbs_All ) {
158     SMESHDS_GroupBase::SetType( theType );
159     myGroup.SetType ( theType );
160   }
161   else
162     SMESHDS_GroupBase::SetType( myGroup.GetType() );
163 }
164