Commit | Line | Data |
---|---|---|
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 | 31 | Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId, |
ac04d101 | 32 | const Standard_Boolean MatchAll): |
7fd59977 | 33 | Select3D_SensitiveEntity(OwnerId), |
34 | myMustMatchAll(MatchAll), | |
35 | myLastRank(0), | |
36 | myX(0.), | |
37 | myY(0.) | |
38 | { | |
39 | } | |
40 | ||
ac04d101 SA |
41 | //======================================================================= |
42 | //function : Creation | |
43 | //purpose : | |
44 | //======================================================================= | |
7fd59977 | 45 | |
ac04d101 SA |
46 | Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId, |
47 | Select3D_ListOfSensitive& TheList, | |
48 | const Standard_Boolean MatchAll): | |
7fd59977 | 49 | Select3D_SensitiveEntity(OwnerId), |
50 | myMustMatchAll(MatchAll), | |
51 | myLastRank(0), | |
52 | myX(0.), | |
53 | myY(0.) | |
54 | { | |
55 | myList.Append(TheList); | |
56 | } | |
57 | ||
58 | //======================================================================= | |
59 | //function : Add | |
60 | //purpose : No control of entities inside | |
61 | //======================================================================= | |
ac04d101 | 62 | |
7fd59977 | 63 | void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL) |
64 | {myList.Append(LL);} | |
65 | ||
66 | //======================================================================= | |
67 | //function : Add | |
68 | //purpose : | |
69 | //======================================================================= | |
ac04d101 | 70 | |
7fd59977 | 71 | void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive) |
72 | { | |
ac04d101 SA |
73 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
74 | { | |
7fd59977 | 75 | if(It.Value()==aSensitive) return; |
76 | } | |
77 | myList.Append(aSensitive); | |
78 | } | |
79 | ||
80 | //======================================================================= | |
81 | //function : Remove | |
82 | //purpose : | |
83 | //======================================================================= | |
ac04d101 | 84 | |
7fd59977 | 85 | void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive) |
86 | { | |
ac04d101 SA |
87 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
88 | { | |
89 | if(It.Value()==aSensitive) | |
90 | { | |
7fd59977 | 91 | myList.Remove(It); |
92 | return; | |
93 | } | |
94 | } | |
95 | } | |
96 | ||
97 | //======================================================================= | |
98 | //function : IsIn | |
99 | //purpose : | |
100 | //======================================================================= | |
ac04d101 | 101 | |
7fd59977 | 102 | Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const |
103 | { | |
ac04d101 SA |
104 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
105 | { | |
7fd59977 | 106 | if(It.Value()==aSensitive) |
107 | return Standard_True; | |
108 | } | |
109 | return Standard_False; | |
7fd59977 | 110 | } |
ac04d101 | 111 | |
7fd59977 | 112 | //======================================================================= |
113 | //function : Clear | |
114 | //purpose : | |
115 | //======================================================================= | |
ac04d101 | 116 | |
7fd59977 | 117 | void Select3D_SensitiveGroup::Clear() |
118 | {myList.Clear();} | |
119 | ||
120 | //======================================================================= | |
121 | //function : Project | |
122 | //purpose : | |
123 | //======================================================================= | |
124 | ||
4bf18dff | 125 | void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector) |
7fd59977 | 126 | { |
127 | Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj... | |
4bf18dff | 128 | |
ac04d101 SA |
129 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
130 | { | |
7fd59977 | 131 | It.Value()->Project(aProjector); |
132 | } | |
133 | } | |
134 | ||
135 | //======================================================================= | |
136 | //function : Areas | |
137 | //purpose : | |
138 | //======================================================================= | |
139 | ||
140 | void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes) | |
141 | { | |
ac04d101 SA |
142 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
143 | { | |
7fd59977 | 144 | It.Value()->Areas(boxes); |
145 | } | |
146 | } | |
147 | ||
148 | //======================================================================= | |
149 | //function : GetConnected | |
150 | //purpose : | |
151 | //======================================================================= | |
152 | ||
153 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation) | |
154 | { | |
155 | Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll); | |
156 | Select3D_ListOfSensitive LL; | |
ac04d101 SA |
157 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
158 | { | |
7fd59977 | 159 | LL.Append(It.Value()->GetConnected(aLocation)); |
160 | } | |
161 | newgroup->Add(LL); | |
162 | return newgroup; | |
163 | } | |
164 | ||
165 | //======================================================================= | |
166 | //function : SetLocation | |
167 | //purpose : | |
168 | //======================================================================= | |
169 | ||
170 | void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc) | |
171 | { | |
172 | if(aLoc.IsIdentity()) return; | |
173 | ||
ac04d101 SA |
174 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
175 | { | |
176 | It.Value()->SetLocation(aLoc); | |
177 | } | |
178 | ||
7fd59977 | 179 | if(HasLocation()) |
180 | if(aLoc == Location()) return; | |
181 | ||
182 | Select3D_SensitiveEntity::SetLocation(aLoc); | |
ac04d101 SA |
183 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
184 | { | |
185 | if(It.Value()->HasLocation()) | |
186 | { | |
187 | if(It.Value()->Location()!=aLoc) | |
188 | It.Value()->SetLocation(It.Value()->Location()*aLoc); | |
7fd59977 | 189 | } |
190 | else | |
191 | It.Value()->SetLocation(aLoc); | |
7fd59977 | 192 | } |
193 | } | |
194 | ||
195 | //======================================================================= | |
196 | //function : ResetLocation | |
197 | //purpose : | |
198 | //======================================================================= | |
ac04d101 | 199 | |
7fd59977 | 200 | void Select3D_SensitiveGroup::ResetLocation() |
201 | { | |
202 | if(!HasLocation()) return; | |
ac04d101 SA |
203 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) |
204 | { | |
7fd59977 | 205 | if(It.Value()->HasLocation() && It.Value()->Location()!=Location()) |
206 | It.Value()->SetLocation(It.Value()->Location()*Location().Inverted()); | |
207 | else | |
208 | It.Value()->ResetLocation(); | |
7fd59977 | 209 | } |
210 | Select3D_SensitiveEntity::ResetLocation(); | |
211 | } | |
212 | ||
213 | //======================================================================= | |
214 | //function : Matches | |
215 | //purpose : | |
216 | //======================================================================= | |
ac04d101 SA |
217 | |
218 | Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X, | |
219 | const Standard_Real Y, | |
220 | const Standard_Real aTol, | |
221 | Standard_Real& DMin) | |
7fd59977 | 222 | { |
223 | myLastRank = 0; | |
224 | myLastTol = aTol; | |
225 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ | |
226 | myLastRank++; | |
4bf18dff | 227 | if (It.Value()->Matches (X, Y, aTol, DMin)) |
228 | { | |
229 | myX = X; myY = Y; myLastTol = aTol; | |
230 | // compute and validate the depth (will call ::ComputeDepth()) | |
231 | return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin); | |
7fd59977 | 232 | } |
233 | } | |
4bf18dff | 234 | // no match |
235 | myLastRank = 0; | |
236 | SetLastDepth (ShortRealLast()); | |
7fd59977 | 237 | return Standard_False; |
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 |
245 | Standard_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 | ||
277 | Standard_Boolean Select3D_SensitiveGroup:: | |
278 | Matches (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 | //======================================================================= |
303 | //function : ComputeDepth | |
81bba717 | 304 | //purpose : to optimise, the minimum depth for |
305 | // entities that answer YES to Matches(X,Y,...) is taken | |
306 | // the test is started from mylastRank... | |
7fd59977 | 307 | //======================================================================= |
308 | Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const | |
309 | { | |
4bf18dff | 310 | Standard_Integer currank = 0; |
311 | Standard_Real DMin, thedepth (Precision::Infinite()); | |
312 | for (Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) | |
313 | { | |
7fd59977 | 314 | currank++; |
4bf18dff | 315 | if (currank >= myLastRank) |
316 | { | |
317 | // this recomputes and validates the depth for the entity | |
318 | if (It.Value()->Matches (myX, myY, myLastTol, DMin)) | |
319 | { | |
320 | It.Value()->ComputeDepth (EyeLine); | |
321 | if (It.Value()->Depth() < thedepth) | |
322 | { | |
323 | // search for topmost entity | |
324 | thedepth = It.Value()->Depth(); | |
325 | //myLastRank = currank; // can not do this here... | |
326 | } | |
7fd59977 | 327 | } |
328 | } | |
7fd59977 | 329 | } |
330 | return thedepth; | |
331 | } | |
332 | ||
333 | //======================================================================= | |
334 | //function : MaxBoxes | |
335 | //purpose : | |
336 | //======================================================================= | |
ac04d101 | 337 | |
7fd59977 | 338 | Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const |
339 | { | |
340 | Standard_Integer nbboxes(0); | |
341 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){ | |
342 | nbboxes+=It.Value()->MaxBoxes(); | |
343 | } | |
344 | return nbboxes; | |
345 | } | |
346 | ||
ac04d101 SA |
347 | //======================================================================= |
348 | //function : SetLastPrj | |
349 | //purpose : | |
350 | //======================================================================= | |
351 | ||
4bf18dff | 352 | void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj) |
7fd59977 | 353 | { |
354 | Select3D_SensitiveEntity::SetLastPrj(Prj); | |
355 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) | |
356 | It.Value()->SetLastPrj(Prj); | |
357 | } | |
ac04d101 SA |
358 | |
359 | //======================================================================= | |
360 | //function : Set | |
361 | //purpose : | |
362 | //======================================================================= | |
363 | ||
364 | void Select3D_SensitiveGroup::Set | |
365 | (const Handle(SelectBasics_EntityOwner)& TheOwnerId) | |
366 | { | |
367 | Select3D_SensitiveEntity::Set(TheOwnerId); | |
368 | // set TheOwnerId for each element of sensitive group | |
369 | for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()) | |
370 | It.Value()->Set(TheOwnerId); | |
371 | } |