0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Select3D / Select3D_SensitiveGroup.cxx
CommitLineData
b311480e 1// Created on: 1998-04-16
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23#include <Select3D_SensitiveGroup.ixx>
24#include <Select3D_ListIteratorOfListOfSensitive.hxx>
25#include <Precision.hxx>
26
ac04d101
SA
27//=======================================================================
28//function : Creation
29//purpose :
30//=======================================================================
7fd59977 31Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
ac04d101 32 const Standard_Boolean MatchAll):
7fd59977 33Select3D_SensitiveEntity(OwnerId),
4269bd1b 34myMustMatchAll(MatchAll)
7fd59977 35{
36}
37
ac04d101
SA
38//=======================================================================
39//function : Creation
40//purpose :
41//=======================================================================
7fd59977 42
ac04d101
SA
43Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
44 Select3D_ListOfSensitive& TheList,
45 const Standard_Boolean MatchAll):
7fd59977 46Select3D_SensitiveEntity(OwnerId),
4269bd1b 47myMustMatchAll(MatchAll)
7fd59977 48{
49 myList.Append(TheList);
50}
51
52//=======================================================================
53//function : Add
54//purpose : No control of entities inside
55//=======================================================================
ac04d101 56
7fd59977 57void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
58{myList.Append(LL);}
59
60//=======================================================================
61//function : Add
62//purpose :
63//=======================================================================
ac04d101 64
7fd59977 65void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
66{
ac04d101
SA
67 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
68 {
7fd59977 69 if(It.Value()==aSensitive) return;
70 }
71 myList.Append(aSensitive);
72}
73
74//=======================================================================
75//function : Remove
76//purpose :
77//=======================================================================
ac04d101 78
7fd59977 79void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
80{
ac04d101
SA
81 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
82 {
83 if(It.Value()==aSensitive)
84 {
7fd59977 85 myList.Remove(It);
86 return;
87 }
88 }
89}
90
91//=======================================================================
92//function : IsIn
93//purpose :
94//=======================================================================
ac04d101 95
7fd59977 96Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
97{
ac04d101
SA
98 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
99 {
7fd59977 100 if(It.Value()==aSensitive)
101 return Standard_True;
102 }
103 return Standard_False;
7fd59977 104}
ac04d101 105
7fd59977 106//=======================================================================
107//function : Clear
108//purpose :
109//=======================================================================
ac04d101 110
7fd59977 111void Select3D_SensitiveGroup::Clear()
112{myList.Clear();}
113
114//=======================================================================
115//function : Project
116//purpose :
117//=======================================================================
118
4bf18dff 119void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector)
7fd59977 120{
ac04d101
SA
121 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
122 {
7fd59977 123 It.Value()->Project(aProjector);
124 }
125}
126
127//=======================================================================
128//function : Areas
129//purpose :
130//=======================================================================
131
132void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
133{
ac04d101
SA
134 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
135 {
7fd59977 136 It.Value()->Areas(boxes);
137 }
138}
139
140//=======================================================================
141//function : GetConnected
142//purpose :
143//=======================================================================
144
145Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
146{
147 Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
148 Select3D_ListOfSensitive LL;
ac04d101
SA
149 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
150 {
7fd59977 151 LL.Append(It.Value()->GetConnected(aLocation));
152 }
153 newgroup->Add(LL);
154 return newgroup;
155}
156
157//=======================================================================
158//function : SetLocation
159//purpose :
160//=======================================================================
161
162void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
163{
164 if(aLoc.IsIdentity()) return;
165
ac04d101
SA
166 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
167 {
168 It.Value()->SetLocation(aLoc);
169 }
170
7fd59977 171 if(HasLocation())
172 if(aLoc == Location()) return;
173
174 Select3D_SensitiveEntity::SetLocation(aLoc);
ac04d101
SA
175 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
176 {
177 if(It.Value()->HasLocation())
178 {
179 if(It.Value()->Location()!=aLoc)
180 It.Value()->SetLocation(It.Value()->Location()*aLoc);
7fd59977 181 }
182 else
183 It.Value()->SetLocation(aLoc);
7fd59977 184 }
185}
186
187//=======================================================================
188//function : ResetLocation
189//purpose :
190//=======================================================================
ac04d101 191
7fd59977 192void Select3D_SensitiveGroup::ResetLocation()
193{
194 if(!HasLocation()) return;
ac04d101
SA
195 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
196 {
7fd59977 197 if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
198 It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
199 else
200 It.Value()->ResetLocation();
7fd59977 201 }
202 Select3D_SensitiveEntity::ResetLocation();
203}
204
205//=======================================================================
206//function : Matches
207//purpose :
208//=======================================================================
ac04d101 209
4269bd1b 210Standard_Boolean Select3D_SensitiveGroup::Matches (const SelectBasics_PickArgs& thePickArgs,
211 Standard_Real& theMatchDMin,
212 Standard_Real& theMatchDepth)
7fd59977 213{
4269bd1b 214 theMatchDMin = RealLast();
215 theMatchDepth = RealLast();
216 Standard_Real aChildDMin, aChildDepth;
217 Standard_Boolean isMatched = Standard_False;
218
219 Select3D_ListIteratorOfListOfSensitive anIt (myList);
220 for (; anIt.More(); anIt.Next())
221 {
222 Handle(SelectBasics_SensitiveEntity)& aChild = anIt.Value();
223 if (!aChild->Matches (thePickArgs, aChildDMin, aChildDepth))
224 {
225 continue;
226 }
227
228 if (!isMatched)
4bf18dff 229 {
4269bd1b 230 theMatchDMin = aChildDMin;
231 isMatched = Standard_True;
7fd59977 232 }
4269bd1b 233
234 theMatchDepth = Min (aChildDepth, theMatchDepth);
7fd59977 235 }
4269bd1b 236
237 return isMatched;
7fd59977 238}
239
240//=======================================================================
241//function : Matches
242//purpose : si on doit tout matcher, on ne repond oui que si toutes
243// les primitives repondent oui
244//=======================================================================
ac04d101
SA
245Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
246 const Standard_Real YMin,
247 const Standard_Real XMax,
248 const Standard_Real YMax,
249 const Standard_Real aTol)
7fd59977 250{
251 Standard_Boolean result(Standard_True);
252
ac04d101
SA
253 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
254 {
255 if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
256 {
7fd59977 257 if(!myMustMatchAll)
ac04d101 258 return Standard_True;
7fd59977 259 }
260 // ca ne matches pas..
ac04d101
SA
261 else
262 {
263 if(myMustMatchAll)
264 return Standard_False;
265 else
266 result = Standard_False;
7fd59977 267 }
268 }
269 return result;
270}
271
272//=======================================================================
273//function : Matches
274//purpose :
275//=======================================================================
276
277Standard_Boolean Select3D_SensitiveGroup::
278Matches (const TColgp_Array1OfPnt2d& aPoly,
ac04d101
SA
279 const Bnd_Box2d& aBox,
280 const Standard_Real aTol)
7fd59977 281{
282 Standard_Boolean result(Standard_True);
283
ac04d101
SA
284 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
285 {
286 if(It.Value()->Matches(aPoly, aBox, aTol))
287 {
288 if(!myMustMatchAll)
289 return Standard_True;
7fd59977 290 }
ac04d101
SA
291 else
292 {
293 if(myMustMatchAll)
294 return Standard_False;
295 else
296 result = Standard_False;
7fd59977 297 }
298 }
299 return result;
300}
301
7fd59977 302//=======================================================================
7fd59977 303//function : MaxBoxes
304//purpose :
305//=======================================================================
ac04d101 306
7fd59977 307Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
308{
309 Standard_Integer nbboxes(0);
310 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
311 nbboxes+=It.Value()->MaxBoxes();
312 }
313 return nbboxes;
314}
315
ac04d101 316//=======================================================================
ac04d101
SA
317//function : Set
318//purpose :
319//=======================================================================
320
321void Select3D_SensitiveGroup::Set
322 (const Handle(SelectBasics_EntityOwner)& TheOwnerId)
323{
324 Select3D_SensitiveEntity::Set(TheOwnerId);
325 // set TheOwnerId for each element of sensitive group
326 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
327 It.Value()->Set(TheOwnerId);
328}