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 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
12 const Standard_Boolean MatchAll):
13 Select3D_SensitiveEntity(OwnerId),
14 myMustMatchAll(MatchAll),
21 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
22 Select3D_ListOfSensitive& TheList,
23 const Standard_Boolean MatchAll):
25 Select3D_SensitiveEntity(OwnerId),
26 myMustMatchAll(MatchAll),
31 myList.Append(TheList);
34 //=======================================================================
36 //purpose : No control of entities inside
37 //=======================================================================
38 void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
41 //=======================================================================
44 //=======================================================================
45 void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
47 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
48 if(It.Value()==aSensitive) return;
50 myList.Append(aSensitive);
53 //=======================================================================
56 //=======================================================================
57 void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
59 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
60 if(It.Value()==aSensitive){
67 //=======================================================================
70 //=======================================================================
71 Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
73 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
74 if(It.Value()==aSensitive)
77 return Standard_False;
80 //=======================================================================
83 //=======================================================================
84 void Select3D_SensitiveGroup::Clear()
87 //=======================================================================
90 //=======================================================================
92 void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector)
94 Select3D_SensitiveEntity::Project(aProjector); // to set the field last proj...
96 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
97 It.Value()->Project(aProjector);
101 //=======================================================================
104 //=======================================================================
106 void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
108 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
109 It.Value()->Areas(boxes);
113 //=======================================================================
114 //function : GetConnected
116 //=======================================================================
118 Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
120 Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
121 Select3D_ListOfSensitive LL;
122 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
123 LL.Append(It.Value()->GetConnected(aLocation));
129 //=======================================================================
130 //function : SetLocation
132 //=======================================================================
134 void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
136 if(aLoc.IsIdentity()) return;
139 if(aLoc == Location()) return;
141 Select3D_SensitiveEntity::SetLocation(aLoc);
142 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
143 if(It.Value()->HasLocation()){
144 if(It.Value()->Location()!=aLoc)
145 It.Value()->SetLocation(It.Value()->Location()*aLoc);
148 It.Value()->SetLocation(aLoc);
153 //=======================================================================
154 //function : ResetLocation
156 //=======================================================================
157 void Select3D_SensitiveGroup::ResetLocation()
159 if(!HasLocation()) return;
160 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
161 if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
162 It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
164 It.Value()->ResetLocation();
167 Select3D_SensitiveEntity::ResetLocation();
170 //=======================================================================
173 //=======================================================================
174 Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real X,
175 const Standard_Real Y,
176 const Standard_Real aTol,
181 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
183 if (It.Value()->Matches (X, Y, aTol, DMin))
185 myX = X; myY = Y; myLastTol = aTol;
186 // compute and validate the depth (will call ::ComputeDepth())
187 return Select3D_SensitiveEntity::Matches (X, Y, aTol, DMin);
192 SetLastDepth (ShortRealLast());
193 return Standard_False;
196 //=======================================================================
198 //purpose : si on doit tout matcher, on ne repond oui que si toutes
199 // les primitives repondent oui
200 //=======================================================================
201 Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
202 const Standard_Real YMin,
203 const Standard_Real XMax,
204 const Standard_Real YMax,
205 const Standard_Real aTol)
207 Standard_Boolean result(Standard_True);
209 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
210 if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol)){
212 return Standard_True;
214 // ca ne matches pas..
217 return Standard_False;
219 result = Standard_False;
225 //=======================================================================
228 //=======================================================================
230 Standard_Boolean Select3D_SensitiveGroup::
231 Matches (const TColgp_Array1OfPnt2d& aPoly,
232 const Bnd_Box2d& aBox,
233 const Standard_Real aTol)
235 Standard_Boolean result(Standard_True);
237 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
238 if(It.Value()->Matches(aPoly, aBox, aTol)){
240 return Standard_True;
244 return Standard_False;
246 result = Standard_False;
253 //=======================================================================
254 //function : ComputeDepth
255 //purpose : pour optimiser, on prend le min des profondeurs pour
256 // les entites qui repondent OUI a Matches(X,Y,...)
257 // on commence le test a partir de mylastRank...
258 //=======================================================================
259 Standard_Real Select3D_SensitiveGroup::ComputeDepth(const gp_Lin& EyeLine) const
261 Standard_Integer currank = 0;
262 Standard_Real DMin, thedepth (Precision::Infinite());
263 for (Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
266 if (currank >= myLastRank)
268 // this recomputes and validates the depth for the entity
269 if (It.Value()->Matches (myX, myY, myLastTol, DMin))
271 It.Value()->ComputeDepth (EyeLine);
272 if (It.Value()->Depth() < thedepth)
274 // search for topmost entity
275 thedepth = It.Value()->Depth();
276 //myLastRank = currank; // can not do this here...
284 //=======================================================================
285 //function : MaxBoxes
287 //=======================================================================
288 Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
290 Standard_Integer nbboxes(0);
291 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
292 nbboxes+=It.Value()->MaxBoxes();
297 void Select3D_SensitiveGroup::SetLastPrj(const Handle(Select3D_Projector)& Prj)
299 Select3D_SensitiveEntity::SetLastPrj(Prj);
300 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
301 It.Value()->SetLastPrj(Prj);