7fd59977 |
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 |
6 | |
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> |
14 | |
15 | #include <Bnd_Box2d.hxx> |
16 | #include <ElCLib.hxx> |
17 | |
18 | //static Standard_Boolean debugmode=Standard_False; |
19 | |
20 | //===================================================== |
21 | // Function : Create |
22 | // Purpose :Constructor |
23 | //===================================================== |
24 | |
25 | |
26 | Select3D_SensitiveWire:: |
27 | Select3D_SensitiveWire(const Handle(SelectBasics_EntityOwner)& OwnerId, |
28 | const Standard_Integer MaxRect): |
29 | Select3D_SensitiveEntity(OwnerId), |
30 | mymaxrect(MaxRect), |
31 | myDetectedIndex(-1) |
32 | {} |
33 | |
34 | //===================================================== |
35 | // Function : Add |
36 | // Purpose : |
37 | //===================================================== |
38 | void Select3D_SensitiveWire |
39 | ::Add(const Handle(Select3D_SensitiveEntity)& aSensitive) |
40 | { |
41 | if ( !aSensitive .IsNull()) { |
42 | if(!HasLocation()) |
43 | mysensitive.Append(aSensitive); |
44 | else |
45 | mysensitive.Append(aSensitive->GetConnected(Location())); |
46 | |
47 | } |
48 | } |
49 | |
50 | //======================================================================= |
51 | //function : SetLocation |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | void Select3D_SensitiveWire::SetLocation(const TopLoc_Location& aLoc) |
56 | { |
57 | |
58 | // evitons les problemes... |
59 | if(aLoc.IsIdentity()) return; |
60 | |
61 | if(HasLocation()) |
62 | if(aLoc == Location()) return; |
63 | |
64 | Select3D_SensitiveEntity::SetLocation(aLoc); |
65 | for(Standard_Integer i=1;i<=mysensitive.Length();i++){ |
66 | if(mysensitive(i)->HasLocation()){ |
67 | if(mysensitive(i)->Location()!=aLoc) |
68 | mysensitive(i)->SetLocation(mysensitive(i)->Location()*aLoc); |
69 | } |
70 | else |
71 | mysensitive(i)->SetLocation(aLoc); |
72 | |
73 | } |
74 | } |
75 | //======================================================================= |
76 | //function : ResetLocation |
77 | //purpose : |
78 | //======================================================================= |
79 | |
80 | void Select3D_SensitiveWire::ResetLocation() |
81 | { |
82 | if(!HasLocation()) return; |
83 | for(Standard_Integer i=1;i<=mysensitive.Length();i++){ |
84 | if(mysensitive(i)->HasLocation() && mysensitive(i)->Location()!=Location()) |
85 | mysensitive(i)->SetLocation(mysensitive(i)->Location()*Location().Inverted()); |
86 | else |
87 | mysensitive(i)->ResetLocation(); |
88 | |
89 | } |
90 | Select3D_SensitiveEntity::ResetLocation(); |
91 | } |
92 | //===================================================== |
93 | // Function : Project |
94 | // Purpose : |
95 | //===================================================== |
96 | void Select3D_SensitiveWire |
97 | ::Project(const Select3D_Projector& aProj) |
98 | { |
99 | for ( Standard_Integer i=1; i<=mysensitive.Length(); i++) |
100 | mysensitive(i)->Project(aProj); |
101 | Select3D_SensitiveEntity::Project(aProj); |
102 | } |
103 | |
104 | //===================================================== |
105 | // Function : Areas |
106 | // Purpose : |
107 | //===================================================== |
108 | void Select3D_SensitiveWire |
109 | ::Areas(SelectBasics_ListOfBox2d& theareas) |
110 | { |
111 | Bnd_Box2d BB; // en attendant un nouveau champ rob-18-jun-97 |
112 | SelectBasics_ListOfBox2d BidL; |
113 | Standard_Integer i; |
114 | for (i=1; i<=mysensitive.Length(); i++) |
115 | mysensitive.Value(i)->Areas(BidL); |
116 | |
117 | for(SelectBasics_ListIteratorOfListOfBox2d it(BidL);it.More();it.Next()) |
118 | BB.Add(it.Value()); |
119 | |
120 | theareas.Append(BB); |
121 | |
122 | } |
123 | |
124 | //===================================================== |
125 | // Function : Matches |
126 | // Purpose : |
127 | //===================================================== |
128 | Standard_Boolean Select3D_SensitiveWire |
129 | ::Matches(const Standard_Real X, |
130 | const Standard_Real Y, |
131 | const Standard_Real aTol, |
132 | Standard_Real& DMin) |
133 | { |
134 | Standard_Integer i; |
135 | Standard_Real Dcur; |
136 | DMin = Precision::Infinite(); |
137 | Standard_Boolean IsTouched = Standard_False; |
138 | for (i=1; i<=mysensitive.Length(); i++) { |
139 | if (mysensitive.Value(i)->Matches(X,Y,aTol,Dcur)) { |
140 | IsTouched = Standard_True; |
141 | if(Dcur<=DMin){ |
142 | myDetectedIndex = i; |
143 | DMin = Dcur; |
144 | } |
145 | } |
146 | } |
147 | // Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); |
148 | |
149 | return IsTouched; |
150 | } |
151 | |
152 | //===================================================== |
153 | // Function : Matches |
154 | // Purpose : |
155 | //===================================================== |
156 | Standard_Boolean Select3D_SensitiveWire:: |
157 | Matches (const Standard_Real XMin, |
158 | const Standard_Real YMin, |
159 | const Standard_Real XMax, |
160 | const Standard_Real YMax, |
161 | const Standard_Real aTol) |
162 | { |
163 | Standard_Integer i; |
164 | for (i=1; i<=mysensitive.Length(); i++) { |
165 | if (!(mysensitive.Value(i)->Matches(XMin,YMin,XMax,YMax,aTol))) |
166 | return Standard_False; |
167 | } |
168 | return Standard_True; |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : Matches |
173 | //purpose : |
174 | //======================================================================= |
175 | |
176 | Standard_Boolean Select3D_SensitiveWire:: |
177 | Matches (const TColgp_Array1OfPnt2d& aPoly, |
178 | const Bnd_Box2d& aBox, |
179 | const Standard_Real aTol) |
180 | { |
181 | Standard_Integer i; |
182 | for (i=1; i<=mysensitive.Length(); i++) { |
183 | if (!(mysensitive.Value(i)->Matches(aPoly, aBox, aTol))) |
184 | return Standard_False; |
185 | } |
186 | return Standard_True; |
187 | } |
188 | |
189 | |
190 | //===================================================== |
191 | // Function : MaxBoxes |
192 | // Purpose : |
193 | //===================================================== |
194 | Standard_Integer Select3D_SensitiveWire:: |
195 | MaxBoxes () const |
196 | { |
197 | return 1; |
198 | } |
199 | |
200 | //======================================================================= |
201 | //function : GetConnected |
202 | //purpose : |
203 | //======================================================================= |
204 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetConnected(const TopLoc_Location& aLoc) |
205 | { |
206 | Handle(Select3D_SensitiveWire) SWIR = new Select3D_SensitiveWire(myOwnerId); |
207 | for(Standard_Integer i=1;i<=mysensitive.Length();i++) |
208 | SWIR->Add(mysensitive(i)); |
209 | |
210 | if(HasLocation()) |
211 | SWIR->SetLocation(Location()*aLoc); |
212 | else |
213 | SWIR->SetLocation(aLoc); |
214 | return SWIR; |
215 | } |
216 | |
217 | |
218 | //======================================================================= |
219 | //function : Dump |
220 | //purpose : |
221 | //======================================================================= |
222 | |
223 | void Select3D_SensitiveWire::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const |
224 | { |
225 | S<<"\tSensitiveWire 3D :"<<endl;; |
226 | if(HasLocation()) |
227 | S<<"\t\tExisting Location"<<endl; |
228 | S<<"\t\tComposed Of "<<mysensitive.Length()<<" Sensitive Entities"<<endl; |
229 | |
230 | for(Standard_Integer i=1;i<= mysensitive.Length();i++){ |
231 | S<<"Sensitive #"<<i<<" : "<<endl; |
232 | mysensitive(i)->Dump(S,FullDump);} |
233 | |
234 | S<<"\tEnd Of Sensitive Wire"<<endl; |
235 | |
236 | } |
237 | |
238 | //======================================================================= |
239 | //function : ComputeDepth |
240 | //purpose : |
241 | //======================================================================= |
242 | Standard_Real Select3D_SensitiveWire::ComputeDepth(const gp_Lin& EyeLine) const |
243 | { |
244 | |
245 | if(myDetectedIndex==-1) |
246 | // should be never called... |
247 | return Precision::Infinite(); |
248 | return mysensitive(myDetectedIndex)->ComputeDepth(EyeLine); |
249 | |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : SetLastPrj |
254 | //purpose : |
255 | //======================================================================= |
256 | void Select3D_SensitiveWire::SetLastPrj(const Select3D_Projector& Prj) |
257 | { |
258 | Select3D_SensitiveEntity::SetLastPrj(Prj); |
259 | for(Standard_Integer i=1;i<=mysensitive.Length();i++) |
260 | mysensitive(i)->SetLastPrj(Prj); |
261 | |
262 | } |
263 | |
264 | //======================================================================= |
265 | //function : GetEdges |
266 | //purpose : returns the sensitive edges stored in this wire |
267 | //======================================================================= |
268 | void Select3D_SensitiveWire::GetEdges( Select3D_SensitiveEntitySequence& theEdges ) |
269 | { |
270 | theEdges.Clear(); |
271 | theEdges.Append(mysensitive); |
272 | } |
273 | |
274 | //============================================================================= |
275 | // Function : GetLastDetected |
276 | // Purpose : |
277 | //============================================================================= |
278 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveWire::GetLastDetected() const |
279 | { |
280 | Handle(Select3D_SensitiveEntity) aRes; |
281 | |
282 | if ( myDetectedIndex >= 1 && myDetectedIndex <= mysensitive.Length() ) |
283 | aRes = mysensitive.Value( myDetectedIndex ); |
284 | |
285 | return aRes; |
286 | } |