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
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.
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.
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.
23 #include <Select3D_SensitiveGroup.ixx>
24 #include <Select3D_ListIteratorOfListOfSensitive.hxx>
25 #include <Precision.hxx>
27 //=======================================================================
30 //=======================================================================
31 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
32 const Standard_Boolean MatchAll):
33 Select3D_SensitiveEntity(OwnerId),
34 myMustMatchAll(MatchAll)
38 //=======================================================================
41 //=======================================================================
43 Select3D_SensitiveGroup::Select3D_SensitiveGroup(const Handle(SelectBasics_EntityOwner)& OwnerId,
44 Select3D_ListOfSensitive& TheList,
45 const Standard_Boolean MatchAll):
46 Select3D_SensitiveEntity(OwnerId),
47 myMustMatchAll(MatchAll)
49 myList.Append(TheList);
52 //=======================================================================
54 //purpose : No control of entities inside
55 //=======================================================================
57 void Select3D_SensitiveGroup::Add(Select3D_ListOfSensitive& LL)
60 //=======================================================================
63 //=======================================================================
65 void Select3D_SensitiveGroup::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
67 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
69 if(It.Value()==aSensitive) return;
71 myList.Append(aSensitive);
74 //=======================================================================
77 //=======================================================================
79 void Select3D_SensitiveGroup::Remove(const Handle(Select3D_SensitiveEntity)& aSensitive)
81 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
83 if(It.Value()==aSensitive)
91 //=======================================================================
94 //=======================================================================
96 Standard_Boolean Select3D_SensitiveGroup::IsIn(const Handle(Select3D_SensitiveEntity)& aSensitive) const
98 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
100 if(It.Value()==aSensitive)
101 return Standard_True;
103 return Standard_False;
106 //=======================================================================
109 //=======================================================================
111 void Select3D_SensitiveGroup::Clear()
114 //=======================================================================
117 //=======================================================================
119 void Select3D_SensitiveGroup::Project(const Handle(Select3D_Projector)& aProjector)
121 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
123 It.Value()->Project(aProjector);
127 //=======================================================================
130 //=======================================================================
132 void Select3D_SensitiveGroup::Areas(SelectBasics_ListOfBox2d& boxes)
134 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
136 It.Value()->Areas(boxes);
140 //=======================================================================
141 //function : GetConnected
143 //=======================================================================
145 Handle(Select3D_SensitiveEntity) Select3D_SensitiveGroup::GetConnected(const TopLoc_Location& aLocation)
147 Handle(Select3D_SensitiveGroup) newgroup = new Select3D_SensitiveGroup(myOwnerId,myMustMatchAll);
148 Select3D_ListOfSensitive LL;
149 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
151 LL.Append(It.Value()->GetConnected(aLocation));
157 //=======================================================================
158 //function : SetLocation
160 //=======================================================================
162 void Select3D_SensitiveGroup::SetLocation(const TopLoc_Location& aLoc)
164 if(aLoc.IsIdentity()) return;
166 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
168 It.Value()->SetLocation(aLoc);
172 if(aLoc == Location()) return;
174 Select3D_SensitiveEntity::SetLocation(aLoc);
175 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
177 if(It.Value()->HasLocation())
179 if(It.Value()->Location()!=aLoc)
180 It.Value()->SetLocation(It.Value()->Location()*aLoc);
183 It.Value()->SetLocation(aLoc);
187 //=======================================================================
188 //function : ResetLocation
190 //=======================================================================
192 void Select3D_SensitiveGroup::ResetLocation()
194 if(!HasLocation()) return;
195 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
197 if(It.Value()->HasLocation() && It.Value()->Location()!=Location())
198 It.Value()->SetLocation(It.Value()->Location()*Location().Inverted());
200 It.Value()->ResetLocation();
202 Select3D_SensitiveEntity::ResetLocation();
205 //=======================================================================
208 //=======================================================================
210 Standard_Boolean Select3D_SensitiveGroup::Matches (const SelectBasics_PickArgs& thePickArgs,
211 Standard_Real& theMatchDMin,
212 Standard_Real& theMatchDepth)
214 theMatchDMin = RealLast();
215 theMatchDepth = RealLast();
216 Standard_Real aChildDMin, aChildDepth;
217 Standard_Boolean isMatched = Standard_False;
219 Select3D_ListIteratorOfListOfSensitive anIt (myList);
220 for (; anIt.More(); anIt.Next())
222 Handle(SelectBasics_SensitiveEntity)& aChild = anIt.Value();
223 if (!aChild->Matches (thePickArgs, aChildDMin, aChildDepth))
230 theMatchDMin = aChildDMin;
231 isMatched = Standard_True;
234 theMatchDepth = Min (aChildDepth, theMatchDepth);
240 //=======================================================================
242 //purpose : si on doit tout matcher, on ne repond oui que si toutes
243 // les primitives repondent oui
244 //=======================================================================
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)
251 Standard_Boolean result(Standard_True);
253 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
255 if(It.Value()->Matches(XMin,YMin,XMax,YMax,aTol))
258 return Standard_True;
260 // ca ne matches pas..
264 return Standard_False;
266 result = Standard_False;
272 //=======================================================================
275 //=======================================================================
277 Standard_Boolean Select3D_SensitiveGroup::
278 Matches (const TColgp_Array1OfPnt2d& aPoly,
279 const Bnd_Box2d& aBox,
280 const Standard_Real aTol)
282 Standard_Boolean result(Standard_True);
284 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next())
286 if(It.Value()->Matches(aPoly, aBox, aTol))
289 return Standard_True;
294 return Standard_False;
296 result = Standard_False;
302 //=======================================================================
303 //function : MaxBoxes
305 //=======================================================================
307 Standard_Integer Select3D_SensitiveGroup::MaxBoxes() const
309 Standard_Integer nbboxes(0);
310 for(Select3D_ListIteratorOfListOfSensitive It(myList);It.More();It.Next()){
311 nbboxes+=It.Value()->MaxBoxes();
316 //=======================================================================
319 //=======================================================================
321 void Select3D_SensitiveGroup::Set
322 (const Handle(SelectBasics_EntityOwner)& TheOwnerId)
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);