1 // File: Select3D_SensitiveWire.cxx
2 // Created: Thu Oct 17 10:19:25 1996
3 // Author: Odile OLIVIER
4 // <odl@sacadox.paris1.matra-dtv.fr>
5 //Copyright: Matra Datavision 1996
7 #include <Select3D_SensitiveWire.ixx>
8 #include <SelectBasics_BasicTool.hxx>
9 #include <Select3D_SensitiveEntity.hxx>
10 #include <Select3D_SensitiveEntitySequence.hxx>
11 #include <SelectBasics_ListIteratorOfListOfBox2d.hxx>
12 #include <SelectBasics_ListOfBox2d.hxx>
13 #include <Precision.hxx>
15 #include <Bnd_Box2d.hxx>
18 //static Standard_Boolean debugmode=Standard_False;
20 //=====================================================
22 // Purpose :Constructor
23 //=====================================================
25 Select3D_SensitiveWire::
26 Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId,
27 const Standard_Integer MaxRect):
28 Select3D_SensitiveEntity(OwnerId),
33 //=====================================================
36 //=====================================================
38 void Select3D_SensitiveWire
39 ::Add(const Handle(Select3D_SensitiveEntity)& aSensitive)
41 if(!aSensitive.IsNull())
42 mysensitive.Append(aSensitive);
45 //=======================================================================
46 //function : SetLocation
48 //=======================================================================
50 void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc)
53 // evitons les problemes...
54 if(aLoc.IsIdentity()) return;
57 if(aLoc == Location()) return;
59 Select3D_SensitiveEntity::SetLocation(aLoc);
60 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
61 if(mysensitive(i)->HasLocation()){
62 if(mysensitive(i)->Location()!=aLoc)
63 mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc);
66 mysensitive(i)->SetLocation(aLoc);
71 //=======================================================================
72 //function : ResetLocation
74 //=======================================================================
76 void Select3D_SensitiveWire::ResetLocation()
78 if(!HasLocation()) return;
79 for(Standard_Integer i=1;i<=mysensitive.Length();i++){
80 if(mysensitive(i)->HasLocation() && mysensitive(i)->Location()!=Location())
81 mysensitive(i)->SetLocation(mysensitive(i)->Location()*Location().Inverted());
83 mysensitive(i)->ResetLocation();
86 Select3D_SensitiveEntity::ResetLocation();
89 //=====================================================
92 //=====================================================
93 void Select3D_SensitiveWire
94 ::Project(const Handle(Select3D_Projector)& aProj)
96 for(Standard_Integer i=1; i<=mysensitive.Length(); i++)
97 mysensitive(i)->Project(aProj);
98 Select3D_SensitiveEntity::Project(aProj);
101 //=====================================================
104 //=====================================================
106 void Select3D_SensitiveWire
107 ::Areas(SelectBasics_ListOfBox2d& theareas)
109 Bnd_Box2d BB; // en attendant un nouveau champ rob-18-jun-97
110 SelectBasics_ListOfBox2d BidL;
112 for (i=1; i<=mysensitive.Length(); i++)
113 mysensitive.Value(i)->Areas(BidL);
115 for(SelectBasics_ListIteratorOfListOfBox2d it(BidL);it.More();it.Next())
121 //=====================================================
122 // Function : Matches
124 //=====================================================
125 Standard_Boolean Select3D_SensitiveWire
126 ::Matches(const Standard_Real X,
127 const Standard_Real Y,
128 const Standard_Real aTol,
133 DMin = Precision::Infinite();
134 Standard_Boolean IsTouched = Standard_False;
135 for (i=1; i<=mysensitive.Length(); i++)
137 if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur))
139 IsTouched = Standard_True;
148 return Standard_False;
150 // compute and validate the depth (::Depth()) along the eyeline
151 return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
154 //=====================================================
155 // Function : Matches
157 //=====================================================
159 Standard_Boolean Select3D_SensitiveWire::
160 Matches (const Standard_Real XMin,
161 const Standard_Real YMin,
162 const Standard_Real XMax,
163 const Standard_Real YMax,
164 const Standard_Real aTol)
167 for (i=1; i<=mysensitive.Length(); i++)
169 if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol)))
170 return Standard_False;
172 return Standard_True;
175 //=======================================================================
178 //=======================================================================
180 Standard_Boolean Select3D_SensitiveWire::
181 Matches (const TColgp_Array1OfPnt2d& aPoly,
182 const Bnd_Box2d& aBox,
183 const Standard_Real aTol)
186 for (i=1; i<=mysensitive.Length(); i++)
188 if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol)))
189 return Standard_False;
191 return Standard_True;
195 //=====================================================
196 // Function : MaxBoxes
198 //=====================================================
200 Standard_Integer Select3D_SensitiveWire::
206 //=======================================================================
207 //function : GetConnected
209 //=======================================================================
211 Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc)
213 Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId);
214 for(Standard_Integer i=1;i<=mysensitive.Length();i++)
215 SWIR->Add(mysensitive(i)->GetConnected(aLoc));
218 SWIR->SetLocation(Location()*aLoc);
220 SWIR->SetLocation(aLoc);
225 //=======================================================================
228 //=======================================================================
230 void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
232 S<<"\tSensitiveWire 3D :"<<endl;;
234 S<<"\t\tExisting Location"<<endl;
235 S<<"\t\tComposed Of "<<mysensitive.Length()<<" Sensitive Entities"<<endl;
237 for(Standard_Integer i=1;i<= mysensitive.Length();i++){
238 S<<"Sensitive #"<<i<<" : "<<endl;
239 mysensitive(i)->Dump(S,FullDump);}
241 S<<"\tEnd Of Sensitive Wire"<<endl;
245 //=======================================================================
246 //function : ComputeDepth
248 //=======================================================================
250 Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const
253 if(myDetectedIndex==-1)
254 // should be never called...
255 return Precision::Infinite();
256 return mysensitive(myDetectedIndex)->ComputeDepth(EyeLine);
260 //=======================================================================
261 //function : SetLastPrj
263 //=======================================================================
265 void Select3D_SensitiveWire::SetLastPrj(const Handle(Select3D_Projector)& Prj)
267 Select3D_SensitiveEntity::SetLastPrj(Prj);
268 for(Standard_Integer i=1;i<=mysensitive.Length();i++)
269 mysensitive(i)->SetLastPrj(Prj);
273 //=======================================================================
274 //function : GetEdges
275 //purpose : returns the sensitive edges stored in this wire
276 //=======================================================================
278 void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges )
281 theEdges.Append(mysensitive);
284 //=============================================================================
285 // Function : GetLastDetected
287 //=============================================================================
289 Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const
291 Handle(Select3D_SensitiveEntity) aRes;
293 if ( myDetectedIndex >= 1 && myDetectedIndex <= mysensitive.Length() )
294 aRes = mysensitive.Value( myDetectedIndex );
299 //=======================================================================
302 //=======================================================================
304 void Select3D_SensitiveWire::Set(const Handle_SelectBasics_EntityOwner &TheOwnerId)
306 Select3D_SensitiveEntity::Set(TheOwnerId);
308 // Set TheOwnerId for each element of sensitive wire
309 for (Standard_Integer i = 1; i <= mysensitive.Length(); ++i)
311 mysensitive.Value(i)->Set(TheOwnerId);