1 // Created on: 1998-04-16
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Select3D_SensitiveGroup.ixx>
18 #include <Select3D_ListIteratorOfListOfSensitive.hxx>
19 #include <Precision.hxx>
21 //=======================================================================
24 //=======================================================================
25 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
26 const Standard_Boolean MatchAll):
27 Select3D_SensitiveEntity(OwnerId),
28 myMustMatchAll(MatchAll)
32 //=======================================================================
35 //=======================================================================
37 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
38 Select3D_ListOfSensitive& TheList,
39 const Standard_Boolean MatchAll):
40 Select3D_SensitiveEntity(OwnerId),
41 myMustMatchAll(MatchAll)
43 myList.Append(TheList);
46 //=======================================================================
48 //purpose : No control of entities inside
49 //=======================================================================
51 void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
54 //=======================================================================
57 //=======================================================================
59 void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
61 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
63 if(It.Value()==aSensitive) return;
65 myList.Append(aSensitive);
68 //=======================================================================
71 //=======================================================================
73 void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
75 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
77 if(It.Value()==aSensitive)
85 //=======================================================================
88 //=======================================================================
90 Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
92 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
94 if(It.Value()==aSensitive)
97 return Standard_False;
100 //=======================================================================
103 //=======================================================================
105 void Select3D_SensitiveGroup::Clear()
108 //=======================================================================
111 //=======================================================================
113 void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector)
115 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
117 It.Value()->Project(aProjector);
121 //=======================================================================
124 //=======================================================================
126 void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
128 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
130 It.Value()->Areas(boxes);
134 //=======================================================================
135 //function : GetConnected
137 //=======================================================================
139 Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
141 Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
142 Select3D_ListOfSensitive LL;
143 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
145 LL.Append(It.Value()->GetConnected(aLocation));
151 //=======================================================================
152 //function : SetLocation
154 //=======================================================================
156 void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
158 if(aLoc.IsIdentity()) return;
160 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
162 It.Value()->SetLocation(aLoc);
166 if(aLoc == Location()) return;
168 Select3D_SensitiveEntity::SetLocation(aLoc);
169 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
171 if(It.Value()->HasLocation())
173 if(It.Value()->Location()!=aLoc)
174 It.Value()->SetLocation(It.Value()->Location()*aLoc);
177 It.Value()->SetLocation(aLoc);
181 //=======================================================================
182 //function : ResetLocation
184 //=======================================================================
186 void Select3D_SensitiveGroup::ResetLocation()
188 if(!HasLocation()) return;
189 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
191 if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
192 It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
194 It.Value()->ResetLocation();
196 Select3D_SensitiveEntity::ResetLocation();
199 //=======================================================================
202 //=======================================================================
204 Standard_Boolean Select3D_SensitiveGroup::Matches (const SelectBasics_PickArgs& thePickArgs,
205 Standard_Real& theMatchDMin,
206 Standard_Real& theMatchDepth)
208 theMatchDMin = RealLast();
209 theMatchDepth = RealLast();
210 Standard_Real aChildDMin, aChildDepth;
211 Standard_Boolean isMatched = Standard_False;
213 Select3D_ListIteratorOfListOfSensitive anIt (myList);
214 for (; anIt.More(); anIt.Next())
216 Handle(SelectBasics_SensitiveEntity)& aChild = anIt.Value();
217 if (!aChild->Matches (thePickArgs, aChildDMin, aChildDepth))
224 theMatchDMin = aChildDMin;
225 isMatched = Standard_True;
228 theMatchDepth = Min (aChildDepth, theMatchDepth);
234 //=======================================================================
236 //purpose : si on doit tout matcher, on ne repond oui que si toutes
237 // les primitives repondent oui
238 //=======================================================================
239 Standard_Boolean Select3D_SensitiveGroup::Matches(const Standard_Real XMin,
240 const Standard_Real YMin,
241 const Standard_Real XMax,
242 const Standard_Real YMax,
243 const Standard_Real aTol)
245 Standard_Boolean result(Standard_True);
247 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
249 if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
252 return Standard_True;
254 // ca ne matches pas..
258 return Standard_False;
260 result = Standard_False;
266 //=======================================================================
269 //=======================================================================
271 Standard_Boolean Select3D_SensitiveGroup::
272 Matches (const TColgp_Array1OfPnt2d& aPoly,
273 const Bnd_Box2d& aBox,
274 const Standard_Real aTol)
276 Standard_Boolean result(Standard_True);
278 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
280 if(It.Value()->Matches(aPoly, aBox, aTol))
283 return Standard_True;
288 return Standard_False;
290 result = Standard_False;
296 //=======================================================================
297 //function : MaxBoxes
299 //=======================================================================
301 Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
303 Standard_Integer nbboxes(0);
304 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
305 nbboxes+=It.Value()->MaxBoxes();
310 //=======================================================================
313 //=======================================================================
315 void Select3D_SensitiveGroup::Set
316 (const Handle(SelectBasics_EntityOwner)& TheOwnerId)
318 Select3D_SensitiveEntity::Set(TheOwnerId);
319 // set TheOwnerId for each element of sensitive group
320 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
321 It.Value()->Set(TheOwnerId);