1 // Created on: 1996-10-17
2 // Created by: Odile OLIVIER
3 // Copyright (c) 1996-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.
22 #include <Select3D_SensitiveWire.ixx>
23 #include <SelectBasics_BasicTool.hxx>
24 #include <Select3D_SensitiveEntity.hxx>
25 #include <Select3D_SensitiveEntitySequence.hxx>
26 #include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
27 #include <SelectBasics_ListOfBox2d.hxx>
28 #include <Precision.hxx>
30 #include <Bnd_Box2d.hxx>
33 //static Standard_Boolean debugmode=Standard_False;
35 //=====================================================
37 // Purpose :Constructor
38 //=====================================================
40 Select3D_SensitiveWire::
41 Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
42 const Standard_Integer /*MaxRect*/):
43 Select3D_SensitiveEntity(OwnerId),
47 //=====================================================
50 //=====================================================
52 void Select3D_SensitiveWire
53 ::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
55 if(!aSensitive.IsNull())
56 mysensitive.Append(aSensitive);
59 //=======================================================================
60 //function : SetLocation
62 //=======================================================================
64 void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc)
67 // evitons les problemes...
68 if(aLoc.IsIdentity()) return;
71 if(aLoc == Location()) return;
73 Select3D_SensitiveEntity::SetLocation(aLoc);
74 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
75 if(mysensitive(i)->HasLocation()){
76 if(mysensitive(i)->Location()!=aLoc)
77 mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
80 mysensitive(i)->SetLocation(aLoc);
85 //=======================================================================
86 //function : ResetLocation
88 //=======================================================================
90 void Select3D_SensitiveWire::ResetLocation()
92 if(!HasLocation()) return;
93 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
94 if(mysensitive(i)->HasLocation() && mysensitive(i)->Location()!=Location())
95 mysensitive(i)->SetLocation(mysensitive(i)->Location()*Location().Inverted());
97 mysensitive(i)->ResetLocation();
100 Select3D_SensitiveEntity::ResetLocation();
103 //=====================================================
104 // Function : Project
106 //=====================================================
107 void Select3D_SensitiveWire
108 ::Project(const Handle(Select3D_Projector)& aProj)
110 for(Standard_Integer i=1; i<=mysensitive.Length(); i++)
111 mysensitive(i)->Project(aProj);
112 Select3D_SensitiveEntity::Project(aProj);
115 //=====================================================
118 //=====================================================
120 void Select3D_SensitiveWire
121 ::Areas(SelectBasics_ListOfBox2d& theareas)
123 Bnd_Box2d BB; // en attendant un nouveau champ rob-18-jun-97
124 SelectBasics_ListOfBox2d BidL;
126 for (i=1; i<=mysensitive.Length(); i++)
127 mysensitive.Value(i)->Areas(BidL);
129 for(SelectBasics_ListIteratorOfListOfBox2d it(BidL);it.More();it.Next())
135 //=====================================================
136 // Function : Matches
138 //=====================================================
139 Standard_Boolean Select3D_SensitiveWire
140 ::Matches(const Standard_Real X,
141 const Standard_Real Y,
142 const Standard_Real aTol,
147 DMin = Precision::Infinite();
148 Standard_Boolean IsTouched = Standard_False;
149 for (i=1; i<=mysensitive.Length(); i++)
151 if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur))
153 IsTouched = Standard_True;
162 return Standard_False;
164 // compute and validate the depth (::Depth()) along the eyeline
165 return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
168 //=====================================================
169 // Function : Matches
171 //=====================================================
173 Standard_Boolean Select3D_SensitiveWire::
174 Matches (const Standard_Real XMin,
175 const Standard_Real YMin,
176 const Standard_Real XMax,
177 const Standard_Real YMax,
178 const Standard_Real aTol)
181 for (i=1; i<=mysensitive.Length(); i++)
183 if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol)))
184 return Standard_False;
186 return Standard_True;
189 //=======================================================================
192 //=======================================================================
194 Standard_Boolean Select3D_SensitiveWire::
195 Matches (const TColgp_Array1OfPnt2d& aPoly,
196 const Bnd_Box2d& aBox,
197 const Standard_Real aTol)
200 for (i=1; i<=mysensitive.Length(); i++)
202 if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol)))
203 return Standard_False;
205 return Standard_True;
209 //=====================================================
210 // Function : MaxBoxes
212 //=====================================================
214 Standard_Integer Select3D_SensitiveWire::
220 //=======================================================================
221 //function : GetConnected
223 //=======================================================================
225 Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
227 Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
228 for(Standard_Integer i=1;i<=mysensitive.Length();i++)
229 SWIR->Add(mysensitive(i)->GetConnected(aLoc));
232 SWIR->SetLocation(Location()*aLoc);
234 SWIR->SetLocation(aLoc);
239 //=======================================================================
242 //=======================================================================
244 void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
246 S<<"\tSensitiveWire 3D :"<<endl;;
248 S<<"\t\tExisting Location"<<endl;
249 S<<"\t\tComposed Of "<<mysensitive.Length()<<" Sensitive Entities"<<endl;
251 for(Standard_Integer i=1;i<= mysensitive.Length();i++){
252 S<<"Sensitive #"<<i<<" : "<<endl;
253 mysensitive(i)->Dump(S,FullDump);}
255 S<<"\tEnd Of Sensitive Wire"<<endl;
259 //=======================================================================
260 //function : ComputeDepth
262 //=======================================================================
264 Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
267 if(myDetectedIndex==-1)
268 // should be never called...
269 return Precision::Infinite();
270 return mysensitive(myDetectedIndex)->ComputeDepth(EyeLine);
274 //=======================================================================
275 //function : SetLastPrj
277 //=======================================================================
279 void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj)
281 Select3D_SensitiveEntity::SetLastPrj(Prj);
282 for(Standard_Integer i=1;i<=mysensitive.Length();i++)
283 mysensitive(i)->SetLastPrj(Prj);
287 //=======================================================================
288 //function : GetEdges
289 //purpose : returns the sensitive edges stored in this wire
290 //=======================================================================
292 void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
295 theEdges.Append(mysensitive);
298 //=============================================================================
299 // Function : GetLastDetected
301 //=============================================================================
303 Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
305 Handle(Select3D_SensitiveEntity) aRes;
307 if ( myDetectedIndex >= 1 && myDetectedIndex <= mysensitive.Length() )
308 aRes = mysensitive.Value( myDetectedIndex );
313 //=======================================================================
316 //=======================================================================
318 void Select3D_SensitiveWire::Set(const Handle_SelectBasics_EntityOwner &TheOwnerId)
320 Select3D_SensitiveEntity::Set(TheOwnerId);
322 // Set TheOwnerId for each element of sensitive wire
323 for (Standard_Integer i = 1; i <= mysensitive.Length(); ++i)
325 mysensitive.Value(i)->Set(TheOwnerId);