1 // File: Select3D_SensitiveGroup.cxx
2 // Created: Thu Apr 16 16:17:00 1998
3 // Author: Robert COUBLANC
4 // <rob@robox.paris1.matra-dtv.fr>
7 #include <Select3D_SensitiveGroup.ixx>
8 #include <Select3D_ListIteratorOfListOfSensitive.hxx>
9 #include <Precision.hxx>
11 //=======================================================================
14 //=======================================================================
15 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
16 const Standard_Boolean MatchAll):
17 Select3D_SensitiveEntity(OwnerId),
18 myMustMatchAll(MatchAll),
25 //=======================================================================
28 //=======================================================================
30 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
31 Select3D_ListOfSensitive& TheList,
32 const Standard_Boolean MatchAll):
33 Select3D_SensitiveEntity(OwnerId),
34 myMustMatchAll(MatchAll),
39 myList.Append(TheList);
42 //=======================================================================
44 //purpose : No control of entities inside
45 //=======================================================================
47 void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
50 //=======================================================================
53 //=======================================================================
55 void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
57 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
59 if(It.Value()==aSensitive) return;
61 myList.Append(aSensitive);
64 //=======================================================================
67 //=======================================================================
69 void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
71 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
73 if(It.Value()==aSensitive)
81 //=======================================================================
84 //=======================================================================
86 Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
88 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
90 if(It.Value()==aSensitive)
93 return Standard_False;
96 //=======================================================================
99 //=======================================================================
101 void Select3D_SensitiveGroup::Clear()
104 //=======================================================================
107 //=======================================================================
109 void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector)
111 Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj...
113 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
115 It.Value()->Project(aProjector);
119 //=======================================================================
122 //=======================================================================
124 void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
126 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
128 It.Value()->Areas(boxes);
132 //=======================================================================
133 //function : GetConnected
135 //=======================================================================
137 Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
139 Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
140 Select3D_ListOfSensitive LL;
141 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
143 LL.Append(It.Value()->GetConnected(aLocation));
149 //=======================================================================
150 //function : SetLocation
152 //=======================================================================
154 void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
156 if(aLoc.IsIdentity()) return;
158 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
160 It.Value()->SetLocation(aLoc);
164 if(aLoc == Location()) return;
166 Select3D_SensitiveEntity::SetLocation(aLoc);
167 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
169 if(It.Value()->HasLocation())
171 if(It.Value()->Location()!=aLoc)
172 It.Value()->SetLocation(It.Value()->Location()*aLoc);
175 It.Value()->SetLocation(aLoc);
179 //=======================================================================
180 //function : ResetLocation
182 //=======================================================================
184 void Select3D_SensitiveGroup::ResetLocation()
186 if(!HasLocation()) return;
187 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
189 if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
190 It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
192 It.Value()->ResetLocation();
194 Select3D_SensitiveEntity::ResetLocation();
197 //=======================================================================
200 //=======================================================================
202 Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
203 const Standard_Real Y,
204 const Standard_Real aTol,
209 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
211 if (It.Value()->Matches (X, Y, aTol, DMin))
213 myX = X; myY = Y; myLastTol = aTol;
214 // compute and validate the depth (will call ::ComputeDepth())
215 return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin);
220 SetLastDepth (ShortRealLast());
221 return Standard_False;
224 //=======================================================================
226 //purpose : si on doit tout matcher, on ne repond oui que si toutes
227 // les primitives repondent oui
228 //=======================================================================
229 Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
230 const Standard_Real YMin,
231 const Standard_Real XMax,
232 const Standard_Real YMax,
233 const Standard_Real aTol)
235 Standard_Boolean result(Standard_True);
237 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
239 if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
242 return Standard_True;
244 // ca ne matches pas..
248 return Standard_False;
250 result = Standard_False;
256 //=======================================================================
259 //=======================================================================
261 Standard_Boolean Select3D_SensitiveGroup::
262 Matches (const TColgp_Array1OfPnt2d& aPoly,
263 const Bnd_Box2d& aBox,
264 const Standard_Real aTol)
266 Standard_Boolean result(Standard_True);
268 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
270 if(It.Value()->Matches(aPoly, aBox, aTol))
273 return Standard_True;
278 return Standard_False;
280 result = Standard_False;
286 //=======================================================================
287 //function : ComputeDepth
288 //purpose : to optimise, the minimum depth for
289 // entities that answer YES to Matches(X,Y,...) is taken
290 // the test is started from mylastRank...
291 //=======================================================================
292 Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const
294 Standard_Integer currank = 0;
295 Standard_Real DMin, thedepth (Precision::Infinite());
296 for (Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
299 if (currank >= myLastRank)
301 // this recomputes and validates the depth for the entity
302 if (It.Value()->Matches (myX, myY, myLastTol, DMin))
304 It.Value()->ComputeDepth (EyeLine);
305 if (It.Value()->Depth() < thedepth)
307 // search for topmost entity
308 thedepth = It.Value()->Depth();
309 //myLastRank = currank; // can not do this here...
317 //=======================================================================
318 //function : MaxBoxes
320 //=======================================================================
322 Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
324 Standard_Integer nbboxes(0);
325 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
326 nbboxes+=It.Value()->MaxBoxes();
331 //=======================================================================
332 //function : SetLastPrj
334 //=======================================================================
336 void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj)
338 Select3D_SensitiveEntity::SetLastPrj(Prj);
339 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
340 It.Value()->SetLastPrj(Prj);
343 //=======================================================================
346 //=======================================================================
348 void Select3D_SensitiveGroup::Set
349 (const Handle(SelectBasics_EntityOwner)& TheOwnerId)
351 Select3D_SensitiveEntity::Set(TheOwnerId);
352 // set TheOwnerId for each element of sensitive group
353 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
354 It.Value()->Set(TheOwnerId);