b311480e |
1 | // Created on: 1996-10-30 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // Modified by rob Thu Apr 02 1998 |
18 | // - use of optimisation in SelectMgr_ViewerSelector |
19 | // -> Best management in detected entities... |
20 | |
7fd59977 |
21 | #include <AIS_LocalContext.jxx> |
22 | #include <StdSelect_BRepOwner.hxx> |
bc677575 |
23 | #include <TColStd_ListOfInteger.hxx> |
24 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
7fd59977 |
25 | #include <TColStd_MapOfTransient.hxx> |
26 | #include <TColStd_MapIteratorOfMapOfTransient.hxx> |
27 | #include <Prs3d_Presentation.hxx> |
28 | #include <Prs3d_Drawer.hxx> |
29 | #include <Prs3d_ShadingAspect.hxx> |
30 | #include <AIS_LocalStatus.hxx> |
b8ddfc2f |
31 | #include <Graphic3d_ArrayOfTriangles.hxx> |
7fd59977 |
32 | #include <Graphic3d_Group.hxx> |
33 | #include <Select3D_SensitiveTriangulation.hxx> |
f751596e |
34 | #include <StdSelect_ViewerSelector3d.hxx> |
7fd59977 |
35 | #include <SelectBasics_SensitiveEntity.hxx> |
36 | #include <TCollection_AsciiString.hxx> |
e3a6386d |
37 | #include <NCollection_Map.hxx> |
a272ed94 |
38 | #include <Visual3d_View.hxx> |
e3a6386d |
39 | |
7fd59977 |
40 | #include <SelectMgr_Selection.hxx> |
e3a6386d |
41 | #include <SelectMgr_SequenceOfOwner.hxx> |
7fd59977 |
42 | #include <OSD_Environment.hxx> |
7fd59977 |
43 | |
44 | #include <Geom_Transformation.hxx> |
45 | #include <AIS_Selection.hxx> |
679ecdee |
46 | #include <Aspect_Grid.hxx> |
7fd59977 |
47 | #include <AIS_Shape.hxx> |
7fd59977 |
48 | |
49 | static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO) |
50 | { |
51 | return IO->HasHilightMode() ? IO->HilightMode():0; |
52 | } |
53 | |
54 | //================================================== |
679ecdee |
55 | // Function: MoveTo |
7fd59977 |
56 | // Purpose : |
57 | //================================================== |
679ecdee |
58 | AIS_StatusOfDetection AIS_LocalContext::MoveTo (const Standard_Integer theXpix, |
59 | const Standard_Integer theYpix, |
60 | const Handle(V3d_View)& theView, |
61 | const Standard_Boolean theToRedrawImmediate) |
7fd59977 |
62 | { |
679ecdee |
63 | // check that ViewerSelector gives |
64 | if (theView->Viewer() != myCTX->CurrentViewer()) |
65 | { |
66 | return AIS_SOD_Error; |
67 | } |
68 | |
69 | myAISCurDetected = 0; |
70 | myAISDetectedSeq.Clear(); |
71 | |
72 | myCurDetected = 0; |
73 | myDetectedSeq.Clear(); |
a272ed94 |
74 | myFilters->SetDisabledObjects (theView->View()->HiddenObjects()); |
679ecdee |
75 | myMainVS->Pick (theXpix, theYpix, theView); |
76 | |
77 | const Standard_Integer aDetectedNb = myMainVS->NbPicked(); |
78 | for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter) |
79 | { |
80 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (aDetIter); |
81 | if (anOwner.IsNull() |
82 | || !myFilters->IsOk (anOwner)) |
83 | { |
84 | continue; |
7fd59977 |
85 | } |
679ecdee |
86 | |
57ad5cbd |
87 | myDetectedSeq.Append (aDetIter); // normally they are already arranged in correct order... |
679ecdee |
88 | Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
57ad5cbd |
89 | if (!anObj.IsNull()) |
679ecdee |
90 | { |
91 | myAISDetectedSeq.Append (anObj); |
7fd59977 |
92 | } |
679ecdee |
93 | } |
7fd59977 |
94 | |
679ecdee |
95 | // result of courses.. |
96 | if (aDetectedNb == 0 || myDetectedSeq.IsEmpty()) |
97 | { |
98 | if (mylastindex != 0 && mylastindex <= myMapOfOwner.Extent()) |
99 | { |
63d907e7 |
100 | myMainPM->ClearImmediateDraw(); |
679ecdee |
101 | Unhilight (myMapOfOwner (mylastindex), theView); |
102 | if (theToRedrawImmediate) |
103 | { |
104 | theView->RedrawImmediate(); |
7fd59977 |
105 | } |
7fd59977 |
106 | } |
679ecdee |
107 | |
108 | mylastindex = 0; |
109 | return aDetectedNb == 0 |
110 | ? AIS_SOD_Nothing |
111 | : AIS_SOD_AllBad; |
112 | } |
113 | |
114 | // all owners detected by the selector are passed to the |
115 | // filters and correct ones are preserved... |
116 | myCurDetected = 1; |
117 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected)); |
118 | manageDetected (anOwner, theView, theToRedrawImmediate); |
119 | if (myDetectedSeq.Length() == 1) |
120 | { |
121 | return aDetectedNb == 1 |
122 | ? AIS_SOD_OnlyOneDetected |
123 | : AIS_SOD_OnlyOneGood; |
124 | } |
125 | else |
126 | { |
127 | return AIS_SOD_SeveralGood; |
7fd59977 |
128 | } |
7fd59977 |
129 | } |
130 | |
c398b00e |
131 | //======================================================================= |
132 | //function : Select |
133 | //purpose : |
134 | //======================================================================= |
135 | AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Boolean toUpdateViewer) |
7fd59977 |
136 | { |
c398b00e |
137 | if (myAutoHilight) |
138 | { |
139 | UnhilightPicked (Standard_False); |
140 | } |
7fd59977 |
141 | |
c398b00e |
142 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
143 | |
144 | Standard_Integer aDetIndex = DetectedIndex(); |
145 | if (aDetIndex <= 0) |
146 | { |
147 | ClearSelected (toUpdateViewer); |
148 | return (AIS_Selection::Extent() == 0) ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
7fd59977 |
149 | } |
150 | |
c398b00e |
151 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); |
7fd59977 |
152 | |
c398b00e |
153 | ClearSelected (Standard_False); |
154 | |
155 | if (!anOwner->IsSelected()) // anOwner is not selected |
156 | { |
157 | anOwner->SetSelected (Standard_True); |
158 | AIS_Selection::Select (anOwner); |
7fd59977 |
159 | } |
c398b00e |
160 | |
679ecdee |
161 | if (myAutoHilight) |
162 | { |
7fd59977 |
163 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
679ecdee |
164 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
165 | { |
c398b00e |
166 | Unhilight (anOwner, aViewer->ActiveView()); |
7fd59977 |
167 | } |
168 | |
679ecdee |
169 | // advanced selection highlighting mechanism |
c398b00e |
170 | if (!anOwner->IsAutoHilight() && anOwner->HasSelectable()) |
679ecdee |
171 | { |
c398b00e |
172 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable()); |
679ecdee |
173 | UpdateSelected (anIO, Standard_False); |
174 | } |
175 | |
c398b00e |
176 | if (toUpdateViewer) |
679ecdee |
177 | { |
178 | myCTX->CurrentViewer()->Update(); |
179 | } |
7fd59977 |
180 | } |
c398b00e |
181 | |
182 | return (AIS_Selection::Extent() == 1) ? AIS_SOP_OneSelected : AIS_SOP_SeveralSelected; |
7fd59977 |
183 | } |
c398b00e |
184 | |
185 | //======================================================================= |
186 | //function : Select |
187 | //purpose : |
188 | //======================================================================= |
189 | AIS_StatusOfPick AIS_LocalContext::Select (const Standard_Integer theXPMin, |
190 | const Standard_Integer theYPMin, |
191 | const Standard_Integer theXPMax, |
192 | const Standard_Integer theYPMax, |
193 | const Handle(V3d_View)& theView, |
194 | const Standard_Boolean toUpdateViewer) |
7fd59977 |
195 | { |
c398b00e |
196 | if (theView->Viewer() == myCTX->CurrentViewer()) |
197 | { |
198 | myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); |
199 | if (myAutoHilight) |
200 | { |
201 | UnhilightPicked (Standard_False); |
202 | } |
203 | |
204 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
205 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
206 | |
7fd59977 |
207 | myMainVS->Init(); |
c398b00e |
208 | if (!myMainVS->More()) |
209 | { |
210 | ClearSelected (toUpdateViewer); |
211 | mylastindex = 0; |
212 | return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
7fd59977 |
213 | } |
214 | |
c398b00e |
215 | ClearSelected (Standard_False); |
216 | |
217 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
218 | { |
219 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
220 | if (myFilters->IsOk (anOwner)) |
221 | { |
222 | // it can be helpful to classify this owner immediately... |
223 | if (!anOwner->IsSelected()) |
224 | { |
225 | anOwner->SetSelected (Standard_True); |
226 | AIS_Selection::Select (anOwner); |
227 | } |
7fd59977 |
228 | } |
229 | } |
c398b00e |
230 | |
231 | if (myAutoHilight) |
232 | { |
233 | HilightPicked (toUpdateViewer); |
234 | } |
7fd59977 |
235 | } |
7fd59977 |
236 | |
c398b00e |
237 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
7fd59977 |
238 | |
c398b00e |
239 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
240 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
241 | : AIS_SOP_Error; |
242 | } |
7fd59977 |
243 | |
244 | //================================================== |
c398b00e |
245 | // Function: Select |
246 | // Purpose : Selection by polyline |
7fd59977 |
247 | //================================================== |
c398b00e |
248 | AIS_StatusOfPick AIS_LocalContext::Select (const TColgp_Array1OfPnt2d& thePolyline, |
249 | const Handle(V3d_View)& theView, |
250 | const Standard_Boolean toUpdateViewer) |
7fd59977 |
251 | { |
c398b00e |
252 | if (theView->Viewer() == myCTX->CurrentViewer()) |
253 | { |
254 | myMainVS->Pick (thePolyline, theView); |
7fd59977 |
255 | |
c398b00e |
256 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
257 | |
258 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
259 | myMainVS->Init(); |
260 | if (!myMainVS->More()) |
261 | { |
262 | // Nothing is selected clear selection. |
263 | ClearSelected (toUpdateViewer); |
264 | mylastindex = 0; |
265 | |
266 | // Return state to know if something was unselected |
267 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
268 | } |
269 | |
270 | if (myAutoHilight) |
271 | { |
272 | UnhilightPicked (Standard_False); |
273 | } |
274 | |
275 | // Clear previous selection without update to process this selection |
276 | ClearSelected (Standard_False); |
277 | |
278 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
279 | { |
280 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
281 | if (myFilters->IsOk (anOwner)) |
282 | { |
283 | // it can be helpful to classify this owner immediately... |
284 | if (!anOwner->IsSelected()) |
285 | { |
286 | AIS_Selection::AddSelect (anOwner); |
287 | anOwner->SetSelected (Standard_True); |
288 | } |
289 | } |
290 | } |
291 | |
292 | if (myAutoHilight) |
293 | { |
294 | HilightPicked (toUpdateViewer); |
295 | } |
296 | } |
297 | |
298 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
299 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
300 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
301 | : AIS_SOP_Error; |
302 | } |
303 | |
304 | //======================================================================= |
305 | //function : ShiftSelect |
306 | //purpose : |
307 | //======================================================================= |
308 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Boolean toUpdateViewer) |
309 | { |
310 | Standard_Integer aDetIndex = DetectedIndex(); |
311 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
312 | |
313 | if(aDetIndex > 0) |
314 | { |
315 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
316 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
317 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (aDetIndex); |
318 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
319 | AIS_Selection::Select (anOwner); |
320 | anOwner->SetSelected (toSelect); |
7fd59977 |
321 | |
679ecdee |
322 | if(myAutoHilight) |
323 | { |
63d907e7 |
324 | myMainPM->ClearImmediateDraw(); |
7fd59977 |
325 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
679ecdee |
326 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
327 | { |
c398b00e |
328 | Unhilight (anOwner, aViewer->ActiveView()); |
679ecdee |
329 | } |
330 | |
331 | // advanced selection highlighting mechanism |
c398b00e |
332 | if (!anOwner->IsAutoHilight() && anOwner->HasSelectable()) |
679ecdee |
333 | { |
c398b00e |
334 | Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable()); |
679ecdee |
335 | UpdateSelected (anIO, Standard_False); |
7fd59977 |
336 | } |
337 | |
c398b00e |
338 | if (toUpdateViewer) |
679ecdee |
339 | { |
7fd59977 |
340 | myCTX->CurrentViewer()->Update(); |
679ecdee |
341 | } |
7fd59977 |
342 | } |
c398b00e |
343 | |
7fd59977 |
344 | Standard_Integer NS = AIS_Selection::Extent(); |
345 | if( NS == 1 ) return AIS_SOP_OneSelected; |
346 | else if( NS > 1 ) return AIS_SOP_SeveralSelected; |
c398b00e |
347 | return aSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
7fd59977 |
348 | } |
349 | return AIS_SOP_Error; |
350 | } |
c398b00e |
351 | |
352 | //======================================================================= |
353 | //function : ShiftSelect |
354 | //purpose : |
355 | //======================================================================= |
356 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const Standard_Integer theXPMin, |
357 | const Standard_Integer theYPMin, |
358 | const Standard_Integer theXPMax, |
359 | const Standard_Integer theYPMax, |
360 | const Handle(V3d_View)& theView, |
361 | const Standard_Boolean toUpdateViewer) |
7fd59977 |
362 | { |
679ecdee |
363 | myMainPM->ClearImmediateDraw(); |
364 | |
c398b00e |
365 | if (theView->Viewer() == myCTX->CurrentViewer()) |
366 | { |
367 | myMainVS->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView); |
368 | |
369 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
370 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
371 | |
7fd59977 |
372 | myMainVS->Init(); |
c398b00e |
373 | if (!myMainVS->More()) |
374 | { |
375 | // Nothing is selected clear selection, but don't clear the selection |
376 | // as it is shift selection and previous selection matters. |
377 | // Return state to know if something was unselected |
378 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
379 | } |
7fd59977 |
380 | |
c398b00e |
381 | if (myAutoHilight) |
382 | { |
383 | UnhilightPicked (Standard_False); |
384 | } |
7fd59977 |
385 | |
c398b00e |
386 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
387 | { |
388 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
389 | if(myFilters->IsOk (anOwner)) |
390 | { |
391 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
392 | AIS_Selection::Select (anOwner); |
393 | anOwner->SetSelected (toSelect); |
7fd59977 |
394 | } |
395 | } |
c398b00e |
396 | |
397 | if (myAutoHilight) |
398 | { |
399 | HilightPicked (toUpdateViewer); |
400 | } |
7fd59977 |
401 | } |
c398b00e |
402 | |
403 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
404 | |
405 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
406 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
407 | : AIS_SOP_Error; |
7fd59977 |
408 | } |
409 | |
410 | //================================================== |
411 | // Function: Select |
412 | // Purpose : Selection by polyline |
413 | //================================================== |
c398b00e |
414 | AIS_StatusOfPick AIS_LocalContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline, |
415 | const Handle(V3d_View)& theView, |
416 | const Standard_Boolean toUpdateViewer) |
7fd59977 |
417 | { |
c398b00e |
418 | if (theView->Viewer() == myCTX->CurrentViewer()) |
419 | { |
420 | myMainVS->Pick (thePolyline, theView); |
421 | |
422 | AIS_Selection::SetCurrentSelection (mySelName.ToCString()); |
423 | |
424 | Standard_Integer aLastSelNum = AIS_Selection::Extent(); |
7fd59977 |
425 | myMainVS->Init(); |
c398b00e |
426 | if(!myMainVS->More()) |
427 | { |
428 | // Nothing is selected clear selection, but don't clear the selection |
429 | // as it is shift selection and previous selection matters. |
430 | // Return state to know if something was unselected |
431 | return aLastSelNum == 0 ? AIS_SOP_NothingSelected : AIS_SOP_Removed; |
7fd59977 |
432 | } |
433 | |
c398b00e |
434 | if (myAutoHilight) |
435 | { |
436 | UnhilightPicked (Standard_False); |
7fd59977 |
437 | } |
438 | |
c398b00e |
439 | for (myMainVS->Init(); myMainVS->More(); myMainVS->Next()) |
440 | { |
441 | const Handle(SelectMgr_EntityOwner)& anOwner = myMainVS->Picked(); |
442 | if (myFilters->IsOk (anOwner)) |
443 | { |
444 | Standard_Boolean toSelect = anOwner->IsSelected() ? Standard_False : Standard_True; |
445 | AIS_Selection::Select (anOwner); |
446 | anOwner->SetSelected (toSelect); |
447 | } |
448 | } |
449 | if (myAutoHilight) |
450 | { |
451 | HilightPicked (toUpdateViewer); |
452 | } |
7fd59977 |
453 | } |
7fd59977 |
454 | |
c398b00e |
455 | Standard_Integer aSelNum = AIS_Selection::Extent(); |
456 | |
457 | return (aSelNum == 1) ? AIS_SOP_OneSelected |
458 | : (aSelNum > 1) ? AIS_SOP_SeveralSelected |
459 | : AIS_SOP_Error; |
7fd59977 |
460 | } |
461 | |
462 | //================================================== |
679ecdee |
463 | // Function: Hilight |
7fd59977 |
464 | // Purpose : |
465 | //================================================== |
679ecdee |
466 | void AIS_LocalContext::Hilight (const Handle(SelectMgr_EntityOwner)& theOwner, |
467 | const Handle(V3d_View)& theView) |
7fd59977 |
468 | { |
679ecdee |
469 | if (theView.IsNull()) |
470 | { |
471 | return; |
472 | } |
7fd59977 |
473 | |
679ecdee |
474 | const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable())); |
475 | myMainPM->BeginImmediateDraw(); |
476 | theOwner->HilightWithColor (myMainPM, myCTX->HilightColor(), aHilightMode); |
477 | myMainPM->EndImmediateDraw (theView); |
7fd59977 |
478 | } |
479 | |
480 | //================================================== |
679ecdee |
481 | // Function: Unhilight |
7fd59977 |
482 | // Purpose : |
483 | //================================================== |
679ecdee |
484 | void AIS_LocalContext::Unhilight (const Handle(SelectMgr_EntityOwner)& theOwner, |
485 | const Handle(V3d_View)& theView) |
7fd59977 |
486 | { |
679ecdee |
487 | if (theView.IsNull()) |
488 | { |
489 | return; |
490 | } |
7fd59977 |
491 | |
679ecdee |
492 | const Standard_Integer aHilightMode = GetHiMod (Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable())); |
493 | if (IsSelected (theOwner)) |
7fd59977 |
494 | { |
679ecdee |
495 | if (theOwner->IsAutoHilight()) |
496 | { |
497 | theOwner->HilightWithColor (myMainPM, myCTX->SelectionColor(), aHilightMode); |
498 | } |
499 | } |
500 | else |
501 | { |
502 | theOwner->Unhilight (myMainPM, aHilightMode); |
7fd59977 |
503 | } |
7fd59977 |
504 | } |
505 | |
506 | //======================================================================= |
507 | //function : HilightPicked |
508 | //purpose : |
509 | //======================================================================= |
510 | void AIS_LocalContext::HilightPicked(const Standard_Boolean updateviewer) |
511 | { |
7fd59977 |
512 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
7fd59977 |
513 | if( Sel.IsNull() ) return; |
7fd59977 |
514 | |
e3a6386d |
515 | typedef NCollection_DataMap <Handle(SelectMgr_SelectableObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > SelectMgr_DataMapOfObjectOwners; |
7fd59977 |
516 | SelectMgr_DataMapOfObjectOwners aMap; |
e3a6386d |
517 | |
518 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
7fd59977 |
519 | |
81bba717 |
520 | // to avoid problems when there is a loop searching for selected objects... |
7fd59977 |
521 | const AIS_NListTransient& Obj = Sel->Objects(); |
522 | AIS_NListTransient::Iterator anIter( Obj ); |
523 | for(; anIter.More(); anIter.Next()) |
524 | { |
525 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
7fd59977 |
526 | if(!Tr.IsNull()){ |
527 | const Handle(SelectMgr_EntityOwner)& Ownr = |
528 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
529 | Handle(AIS_InteractiveObject) IO; |
530 | if(Ownr->HasSelectable()){ |
531 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
532 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
533 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
534 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
7fd59977 |
535 | } |
7fd59977 |
536 | } |
7fd59977 |
537 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
538 | Standard_Integer HM = GetHiMod(*((Handle(AIS_InteractiveObject)*)&SO)); |
539 | if ( Ownr->IsAutoHilight() ) |
540 | Ownr->HilightWithColor(PM,myCTX->SelectionColor(),HM); |
541 | else if ( aMap.IsBound (SO) ) |
e3a6386d |
542 | aMap(SO)->Append ( Ownr ); |
7fd59977 |
543 | else { |
e3a6386d |
544 | NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq = new SelectMgr_SequenceOfOwner; |
545 | aSeq->Append ( Ownr ); |
7fd59977 |
546 | aMap.Bind ( SO, aSeq ); |
547 | } |
548 | } |
549 | } |
550 | |
e3a6386d |
551 | for ( SelectMgr_DataMapOfObjectOwners::Iterator aMapIter(aMap); |
7fd59977 |
552 | aMapIter.More(); aMapIter.Next() ) |
e3a6386d |
553 | { |
554 | aMapIter.Key()->HilightSelected (myMainPM, *aMapIter.Value()); |
555 | } |
7fd59977 |
556 | |
679ecdee |
557 | if (updateviewer) |
558 | { |
559 | myCTX->CurrentViewer()->Update(); |
7fd59977 |
560 | } |
561 | } |
562 | |
563 | //================================================== |
564 | // Function: |
565 | // Purpose : |
566 | //================================================== |
679ecdee |
567 | void AIS_LocalContext::UnhilightPicked (const Standard_Boolean updateviewer) |
7fd59977 |
568 | { |
679ecdee |
569 | myMainPM->ClearImmediateDraw(); |
570 | |
7fd59977 |
571 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
7fd59977 |
572 | if( Sel.IsNull() ) return; |
7fd59977 |
573 | Handle (PrsMgr_PresentationManager3d) PM = myMainPM; |
e3a6386d |
574 | NCollection_Map<Handle(SelectMgr_SelectableObject)> anObjMap; |
7fd59977 |
575 | |
7fd59977 |
576 | const AIS_NListTransient& Obj = Sel->Objects(); |
577 | AIS_NListTransient::Iterator anIter( Obj ); |
578 | for(; anIter.More(); anIter.Next()){ |
579 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
7fd59977 |
580 | if(!Tr.IsNull()){ |
581 | const Handle(SelectMgr_EntityOwner)& Ownr = |
582 | *((const Handle(SelectMgr_EntityOwner)*) &Tr); |
583 | Standard_Integer HM(0); |
584 | if(Ownr->HasSelectable()){ |
7fd59977 |
585 | Handle(SelectMgr_SelectableObject) SO = Ownr->Selectable(); |
586 | Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&SO); |
e3a6386d |
587 | anObjMap.Add (IO); |
7fd59977 |
588 | |
e3a6386d |
589 | HM = GetHiMod(IO); |
7fd59977 |
590 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(Ownr); |
591 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
7fd59977 |
592 | } |
7fd59977 |
593 | } |
594 | Ownr->Unhilight(PM,HM); |
595 | } |
596 | } |
597 | |
e3a6386d |
598 | for (NCollection_Map<Handle(SelectMgr_SelectableObject)>::Iterator anIter1 ( anObjMap ); |
7fd59977 |
599 | anIter1.More(); anIter1.Next() ) |
e3a6386d |
600 | { |
7fd59977 |
601 | if ( !anIter1.Key()->IsAutoHilight() ) |
602 | anIter1.Key()->ClearSelected(); |
e3a6386d |
603 | } |
7fd59977 |
604 | |
bcf50875 |
605 | if(updateviewer) |
7fd59977 |
606 | myCTX->CurrentViewer()->Update(); |
7fd59977 |
607 | } |
608 | |
609 | //======================================================================= |
610 | //function : IsSelected |
611 | //purpose : |
612 | //======================================================================= |
613 | Standard_Boolean AIS_LocalContext::IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const |
614 | { |
615 | return (!FindSelectedOwnerFromIO(anIObj).IsNull()); |
616 | } |
617 | |
618 | //======================================================================= |
619 | //function : IsSelected |
620 | //purpose : |
621 | //======================================================================= |
622 | |
c398b00e |
623 | Standard_Boolean AIS_LocalContext::IsSelected (const Handle(SelectMgr_EntityOwner)& theOwner) const |
7fd59977 |
624 | { |
c398b00e |
625 | return !theOwner.IsNull() && theOwner->IsSelected(); |
7fd59977 |
626 | } |
627 | |
628 | //================================================== |
629 | // Function: |
630 | // Purpose : |
631 | //================================================== |
632 | void AIS_LocalContext:: |
633 | InitSelected() |
634 | { |
635 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
636 | AIS_Selection::CurrentSelection()->Init(); |
637 | } |
638 | |
639 | //================================================== |
640 | // Function: |
641 | // Purpose : |
642 | //================================================== |
643 | Standard_Boolean AIS_LocalContext:: |
644 | MoreSelected() const |
645 | { |
646 | return AIS_Selection::CurrentSelection()->More(); |
647 | } |
648 | |
649 | //================================================== |
650 | // Function: |
651 | // Purpose : |
652 | //================================================== |
653 | void AIS_LocalContext:: |
654 | NextSelected() |
655 | { |
656 | AIS_Selection::CurrentSelection()->Next(); |
657 | } |
658 | |
659 | //================================================== |
660 | // Function: |
661 | // Purpose : |
662 | //================================================== |
663 | Standard_Boolean AIS_LocalContext:: |
664 | HasShape() const |
665 | { |
666 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
667 | if( Tr.IsNull() ) return Standard_False; |
668 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
669 | Handle(StdSelect_BRepOwner) BRO = Handle(StdSelect_BRepOwner)::DownCast(EO); |
670 | if(BRO.IsNull()) return Standard_False; |
671 | Standard_Boolean hasshape = BRO->HasShape(); |
672 | Standard_Boolean comes = BRO->ComesFromDecomposition(); |
673 | return (hasshape&&comes); |
674 | } |
675 | |
51023771 |
676 | //================================================================ |
677 | // Function : HasSelectedShape |
678 | // Purpose : Checks if there is a selected shape regardless of its decomposition status |
679 | //================================================================ |
680 | Standard_Boolean AIS_LocalContext::HasSelectedShape() const |
681 | { |
682 | if (AIS_Selection::CurrentSelection()->Extent() == 0) |
683 | return Standard_False; |
684 | |
685 | Handle(Standard_Transient) aCurSelection = AIS_Selection::CurrentSelection()->Value(); |
686 | if (aCurSelection.IsNull()) |
687 | return Standard_False; |
688 | |
689 | Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aCurSelection); |
690 | Handle(StdSelect_BRepOwner) aBrepOwner = Handle(StdSelect_BRepOwner)::DownCast (anOwner); |
691 | if (aBrepOwner.IsNull()) |
692 | { |
693 | return Standard_False; |
694 | } |
695 | return aBrepOwner->HasShape(); |
696 | } |
697 | |
7fd59977 |
698 | //================================================== |
699 | // Function: |
700 | // Purpose : |
701 | //================================================== |
0717ddc1 |
702 | TopoDS_Shape AIS_LocalContext::SelectedShape() const |
7fd59977 |
703 | { |
d8110103 |
704 | Handle(Standard_Transient) aTr = AIS_Selection::CurrentSelection()->Value(); |
705 | Handle(SelectMgr_EntityOwner) anEO = *((Handle(SelectMgr_EntityOwner)*)&aTr); |
706 | Handle(StdSelect_BRepOwner) aBRO = Handle(StdSelect_BRepOwner)::DownCast(anEO); |
707 | if( aBRO.IsNull() ) |
7fd59977 |
708 | { |
d8110103 |
709 | return TopoDS_Shape(); |
7fd59977 |
710 | } |
51023771 |
711 | |
d8110103 |
712 | return aBRO->Shape().Located (aBRO->Location() * aBRO->Shape().Location()); |
7fd59977 |
713 | } |
714 | |
715 | //================================================== |
716 | // Function: |
717 | // Purpose : |
718 | //================================================== |
719 | Handle(AIS_InteractiveObject) AIS_LocalContext:: |
720 | SelectedInteractive() const |
721 | { |
722 | Handle(AIS_InteractiveObject) IO; |
723 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
724 | if( !Tr.IsNull() ) { |
725 | Handle(SelectMgr_EntityOwner) EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
726 | Handle(SelectMgr_SelectableObject) SO; |
727 | if(EO->HasSelectable()){ |
728 | SO = EO->Selectable(); |
729 | IO = *((Handle(AIS_InteractiveObject)*)&SO); |
730 | } |
731 | } |
732 | return IO; |
733 | } |
734 | //================================================== |
735 | // Function: |
736 | // Purpose : |
737 | //================================================== |
738 | Handle(SelectMgr_EntityOwner) AIS_LocalContext:: |
739 | SelectedOwner() const |
740 | { |
741 | Handle(SelectMgr_EntityOwner) EO; |
742 | Handle(Standard_Transient) Tr = AIS_Selection::CurrentSelection()->Value(); |
743 | if( !Tr.IsNull() ) |
744 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
745 | return EO; |
746 | } |
747 | |
748 | //================================================== |
749 | // Function: |
750 | // Purpose : |
751 | //================================================== |
752 | Standard_Boolean AIS_LocalContext:: |
753 | HasApplicative() const |
754 | { |
755 | Handle(AIS_InteractiveObject) IO = SelectedInteractive(); |
756 | if( IO.IsNull() ) return Standard_False; |
757 | return IO->HasOwner(); |
758 | } |
759 | |
760 | //================================================== |
761 | // Function: |
762 | // Purpose : |
763 | //================================================== |
764 | const Handle(Standard_Transient)& AIS_LocalContext:: |
765 | SelectedApplicative() const |
766 | { |
767 | return SelectedInteractive()->GetOwner(); |
768 | } |
769 | |
770 | |
771 | |
772 | //======================================================================= |
773 | //function : UpdateSelection |
81bba717 |
774 | //purpose : should disappear... |
7fd59977 |
775 | //======================================================================= |
776 | void AIS_LocalContext::UpdateSelected(const Standard_Boolean updateviewer) |
777 | { |
778 | UnhilightPicked(Standard_False); |
779 | HilightPicked(updateviewer); |
780 | } |
781 | |
782 | //================================================================ |
783 | // Function : UpdateSelected |
784 | // Purpose : Part of advanced selection mechanism. |
785 | // Highlightes or clears selection presentation for the given IO |
786 | //================================================================ |
787 | void AIS_LocalContext::UpdateSelected(const Handle(AIS_InteractiveObject)& anobj, |
788 | const Standard_Boolean updateviewer) |
789 | { |
790 | if (anobj.IsNull() || anobj->IsAutoHilight()) |
791 | return; |
792 | |
793 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
794 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
795 | |
796 | SelectMgr_SequenceOfOwner aSeq; |
797 | for ( Sel->Init(); Sel->More(); Sel->Next() ){ |
798 | Handle(SelectMgr_EntityOwner) aOwner = Handle(SelectMgr_EntityOwner)::DownCast(Sel->Value()); |
799 | |
800 | if ( !aOwner.IsNull() && aOwner->HasSelectable() && aOwner->Selectable() == anobj ) |
801 | aSeq.Append( aOwner ); |
802 | } |
803 | |
804 | if ( aSeq.Length() ) |
805 | anobj->HilightSelected( myMainPM, aSeq ); |
806 | else |
807 | anobj->ClearSelected(); |
808 | |
809 | if(updateviewer){ |
810 | myCTX->CurrentViewer()->Update(); |
811 | } |
812 | } |
813 | |
814 | //================================================== |
815 | // Function: ClearSelected |
816 | // Purpose : |
817 | //================================================== |
c398b00e |
818 | void AIS_LocalContext::ClearSelected (const Standard_Boolean updateviewer) |
7fd59977 |
819 | { |
820 | UnhilightPicked(updateviewer); |
821 | AIS_Selection::SetCurrentSelection(mySelName.ToCString()); |
822 | |
823 | Handle(AIS_Selection) Sel = AIS_Selection::CurrentSelection(); |
7fd59977 |
824 | const AIS_NListTransient& Obj = Sel->Objects(); |
825 | AIS_NListTransient::Iterator anIter( Obj ); |
826 | for(; anIter.More(); anIter.Next()){ |
827 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
c398b00e |
828 | if(!Tr.IsNull()) |
829 | { |
830 | (*((const Handle(SelectMgr_EntityOwner)*)&Tr))->SetSelected (Standard_False); |
7fd59977 |
831 | } |
832 | } |
833 | AIS_Selection::Select(); |
834 | mylastindex = 0; |
835 | } |
836 | |
fb4b684a |
837 | //================================================== |
bc677575 |
838 | // Function: ClearOutdatedSelection |
fb4b684a |
839 | // Purpose : |
840 | //================================================== |
bc677575 |
841 | void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObject)& theIO, |
842 | const Standard_Boolean toClearDeactivated) |
fb4b684a |
843 | { |
bc677575 |
844 | // 1. Collect selectable entities |
845 | SelectMgr_IndexedMapOfOwner aValidOwners; |
846 | |
847 | const TColStd_ListOfInteger& aModes = SelectionModes (theIO); |
848 | |
849 | TColStd_ListIteratorOfListOfInteger aModeIter (aModes); |
850 | for (; aModeIter.More(); aModeIter.Next()) |
851 | { |
852 | int aMode = aModeIter.Value(); |
853 | if (!theIO->HasSelection(aMode)) |
854 | { |
855 | continue; |
856 | } |
857 | |
f751596e |
858 | if (toClearDeactivated && !mySM->IsActivated(theIO, aMode, myMainVS)) |
bc677575 |
859 | { |
860 | continue; |
861 | } |
862 | |
863 | Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode); |
864 | for (aSelection->Init(); aSelection->More(); aSelection->Next()) |
865 | { |
f751596e |
866 | Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive(); |
bc677575 |
867 | if (anEntity.IsNull()) |
868 | { |
869 | continue; |
870 | } |
871 | |
872 | Handle(SelectMgr_EntityOwner) anOwner = |
873 | Handle(SelectMgr_EntityOwner)::DownCast (anEntity->OwnerId()); |
874 | |
875 | if (anOwner.IsNull()) |
876 | { |
877 | continue; |
878 | } |
879 | |
880 | aValidOwners.Add(anOwner); |
881 | } |
882 | } |
883 | |
884 | // 2. Refresh context's detection and selection and keep only active owners |
fb4b684a |
885 | // Keep last detected object for lastindex initialization. |
886 | Handle(SelectMgr_EntityOwner) aLastPicked = myMainVS->OnePicked(); |
887 | |
bc677575 |
888 | // Remove entity owners from detected sequences |
889 | for (Standard_Integer anIdx = 1; anIdx <= myDetectedSeq.Length(); ++anIdx) |
fb4b684a |
890 | { |
bc677575 |
891 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (anIdx)); |
892 | if (anOwner.IsNull() || anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner)) |
fb4b684a |
893 | { |
bc677575 |
894 | continue; |
895 | } |
896 | |
897 | myDetectedSeq.Remove (anIdx--); |
898 | |
899 | if (anIdx < myCurDetected) |
900 | { |
901 | myCurDetected--; |
fb4b684a |
902 | } |
903 | } |
bc677575 |
904 | myCurDetected = Max (myCurDetected, 1); |
fb4b684a |
905 | |
bc677575 |
906 | Standard_Boolean isAISRemainsDetected = Standard_False; |
fb4b684a |
907 | |
c070aa39 |
908 | // 3. AIS_Selection : remove entity owners from AIS_Selection |
bc677575 |
909 | const Handle(V3d_Viewer)& aViewer = myCTX->CurrentViewer(); |
fb4b684a |
910 | Handle(AIS_Selection) aSelection = AIS_Selection::Selection (mySelName.ToCString()); |
911 | AIS_NListTransient::Iterator anIter (aSelection->Objects()); |
912 | AIS_NListTransient aRemoveEntites; |
913 | for (; anIter.More(); anIter.Next()) |
914 | { |
915 | Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (anIter.Value()); |
916 | if (anOwner.IsNull() || anOwner->Selectable() != theIO) |
917 | { |
918 | continue; |
919 | } |
920 | |
bc677575 |
921 | if (aValidOwners.Contains (anOwner)) |
922 | { |
923 | isAISRemainsDetected = Standard_True; |
924 | } |
c070aa39 |
925 | else |
fb4b684a |
926 | { |
c070aa39 |
927 | aRemoveEntites.Append (anOwner); |
928 | anOwner->SetSelected (Standard_False); |
929 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
930 | { |
931 | Unhilight (anOwner, aViewer->ActiveView()); |
932 | } |
fb4b684a |
933 | } |
934 | } |
935 | AIS_NListTransient::Iterator anIterRemove (aRemoveEntites); |
936 | for (; anIterRemove.More(); anIterRemove.Next()) |
937 | { |
938 | aSelection->Select (anIterRemove.Value()); |
939 | } |
940 | |
c070aa39 |
941 | // 4. AIS_LocalContext - myMapOfOwner : remove entity owners from myMapOfOwner |
fb4b684a |
942 | SelectMgr_IndexedMapOfOwner anOwnersToKeep; |
fb4b684a |
943 | for (Standard_Integer anIdx = 1; anIdx <= myMapOfOwner.Extent(); anIdx++) |
944 | { |
945 | Handle(SelectMgr_EntityOwner) anOwner = myMapOfOwner (anIdx); |
946 | if (anOwner.IsNull()) |
947 | { |
948 | continue; |
949 | } |
950 | |
bc677575 |
951 | if (anOwner->Selectable() != theIO || aValidOwners.Contains (anOwner)) |
fb4b684a |
952 | { |
953 | anOwnersToKeep.Add (anOwner); |
954 | } |
955 | else |
956 | { |
957 | for (aViewer->InitActiveViews(); aViewer->MoreActiveViews(); aViewer->NextActiveViews()) |
958 | { |
959 | Unhilight (anOwner, aViewer->ActiveView()); |
960 | } |
961 | } |
962 | } |
963 | myMapOfOwner.Clear(); |
964 | myMapOfOwner.Assign (anOwnersToKeep); |
965 | mylastindex = myMapOfOwner.FindIndex (aLastPicked); |
63d907e7 |
966 | if (!IsValidIndex (mylastindex)) |
967 | { |
968 | myMainPM->ClearImmediateDraw(); |
969 | } |
fb4b684a |
970 | |
bc677575 |
971 | if (!isAISRemainsDetected) |
fb4b684a |
972 | { |
bc677575 |
973 | // Remove the interactive object from detected sequences |
974 | for (Standard_Integer anIdx = 1; anIdx <= myAISDetectedSeq.Length(); ++anIdx) |
975 | { |
976 | Handle(AIS_InteractiveObject) aDetectedIO = myAISDetectedSeq.Value (anIdx); |
977 | if (aDetectedIO.IsNull() || aDetectedIO != theIO) |
978 | { |
979 | continue; |
980 | } |
981 | |
982 | myAISDetectedSeq.Remove (anIdx--); |
983 | |
984 | if (anIdx < myAISCurDetected) |
985 | { |
986 | myAISCurDetected--; |
987 | } |
988 | } |
989 | myAISCurDetected = Max (myAISCurDetected, 1); |
fb4b684a |
990 | } |
991 | } |
7fd59977 |
992 | |
993 | //======================================================================= |
994 | //function : SetSelected |
995 | //purpose : |
996 | //======================================================================= |
997 | void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj, |
998 | const Standard_Boolean updateviewer) |
999 | { |
1000 | if(!IsValidForSelection(anIObj)) return; |
1001 | UnhilightPicked(Standard_False); |
1002 | |
81bba717 |
1003 | //1st case, owner already <anIObj> as owner |
1004 | // and not separated is found... |
7fd59977 |
1005 | |
1006 | Handle(AIS_Selection) sel = AIS_Selection::Selection(mySelName.ToCString()); |
1007 | //Standard_Boolean found(Standard_False); |
1008 | Handle(Standard_Transient) Tr; |
1009 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromIO(anIObj); |
1010 | if(EO.IsNull()){ |
81bba717 |
1011 | //check if in selection number 0 there is an owner that can be triturated... |
7fd59977 |
1012 | if(anIObj->HasSelection(0)){ |
1013 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
1014 | SIOBJ->Init(); |
1015 | if(SIOBJ->More()){ |
f751596e |
1016 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId(); |
7fd59977 |
1017 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
1018 | } |
1019 | } |
1020 | if(EO.IsNull()) |
1021 | EO = new SelectMgr_EntityOwner(anIObj); |
1022 | } |
1023 | |
1024 | ClearSelected(Standard_False); |
c398b00e |
1025 | |
7fd59977 |
1026 | AIS_Selection::Select(EO); |
c398b00e |
1027 | EO->SetSelected (Standard_True); |
1028 | |
7fd59977 |
1029 | HilightPicked(updateviewer); |
1030 | } |
1031 | |
1032 | //======================================================================= |
1033 | //function : AddOrRemoveSelected |
1034 | //purpose : |
1035 | //======================================================================= |
1036 | |
1037 | void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj, |
1038 | const Standard_Boolean updateviewer) |
1039 | { |
1040 | if(!IsValidForSelection(anIObj)) return; |
1041 | UnhilightPicked(Standard_False); |
81bba717 |
1042 | // first check if it is selected... |
7fd59977 |
1043 | Handle(SelectMgr_EntityOwner) EO; |
1044 | |
1045 | EO = FindSelectedOwnerFromIO(anIObj); |
c398b00e |
1046 | |
1047 | if (EO.IsNull()) |
1048 | { |
1049 | if(anIObj->HasSelection(0)) |
1050 | { |
7fd59977 |
1051 | const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0); |
1052 | SIOBJ->Init(); |
f751596e |
1053 | if(SIOBJ->More()){ |
1054 | Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId(); |
1055 | EO = *((Handle(SelectMgr_EntityOwner)*)&BO); |
7fd59977 |
1056 | } |
1057 | } |
c398b00e |
1058 | if(EO.IsNull()) |
1059 | { |
7fd59977 |
1060 | EO = new SelectMgr_EntityOwner(anIObj); |
c398b00e |
1061 | } |
7fd59977 |
1062 | } |
1063 | |
1064 | // cout<<"AIS_LocalContext::AddOrRemoveSelected : Selection = "<<mySelName<<endl; |
1065 | const Handle(AIS_Selection)& S = AIS_Selection::Selection(mySelName.ToCString()); |
c398b00e |
1066 | |
1067 | if (!S.IsNull()) |
1068 | { |
7fd59977 |
1069 | AIS_SelectStatus aStatus = S->Select(EO); |
c398b00e |
1070 | EO->SetSelected (aStatus == AIS_SS_Added); |
7fd59977 |
1071 | } |
c398b00e |
1072 | |
7fd59977 |
1073 | HilightPicked(updateviewer); |
1074 | } |
1075 | |
1076 | //======================================================================= |
1077 | //function : AddOrRemoveSelected |
81bba717 |
1078 | //purpose : To check... |
7fd59977 |
1079 | //======================================================================= |
1080 | void AIS_LocalContext::AddOrRemoveSelected(const TopoDS_Shape& Sh, |
1081 | const Standard_Boolean updateviewer) |
1082 | { |
c398b00e |
1083 | UnhilightPicked (Standard_False); |
7fd59977 |
1084 | Handle(SelectMgr_EntityOwner) EO = FindSelectedOwnerFromShape(Sh); |
c398b00e |
1085 | if (!EO.IsNull()) |
1086 | { |
7fd59977 |
1087 | AIS_Selection::Selection(mySelName.ToCString())->Select(EO); |
c398b00e |
1088 | EO->SetSelected (Standard_True); |
7fd59977 |
1089 | } |
c398b00e |
1090 | HilightPicked (updateviewer); |
7fd59977 |
1091 | } |
1092 | |
c398b00e |
1093 | void AIS_LocalContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner, |
1094 | const Standard_Boolean toUpdateViewer) |
1095 | { |
7fd59977 |
1096 | if(myAutoHilight) |
c398b00e |
1097 | { |
1098 | UnhilightPicked (Standard_False); |
1099 | } |
7fd59977 |
1100 | |
c398b00e |
1101 | Standard_Boolean toSelect = theOwner->IsSelected() ? Standard_False : Standard_True; |
1102 | |
1103 | AIS_Selection::Selection (mySelName.ToCString())->Select (theOwner); |
1104 | theOwner->SetSelected (toSelect); |
7fd59977 |
1105 | |
7fd59977 |
1106 | if(myAutoHilight) |
c398b00e |
1107 | { |
1108 | HilightPicked (toUpdateViewer); |
1109 | } |
7fd59977 |
1110 | } |
1111 | |
1112 | //================================================== |
679ecdee |
1113 | // Function: manageDetected |
7fd59977 |
1114 | // Purpose : |
1115 | //================================================== |
679ecdee |
1116 | void AIS_LocalContext::manageDetected (const Handle(SelectMgr_EntityOwner)& thePickOwner, |
1117 | const Handle(V3d_View)& theView, |
1118 | const Standard_Boolean theToRedrawImmediate) |
7fd59977 |
1119 | { |
679ecdee |
1120 | if (thePickOwner.IsNull()) |
1121 | { |
63d907e7 |
1122 | myMainPM->ClearImmediateDraw(); |
679ecdee |
1123 | if (theToRedrawImmediate) |
1124 | { |
1125 | theView->RedrawImmediate(); |
1126 | } |
1127 | return; |
1128 | } |
7fd59977 |
1129 | |
679ecdee |
1130 | if (!myFilters->IsOk (thePickOwner)) |
1131 | { |
1132 | if (mylastindex != 0) |
1133 | { |
1134 | mylastgood = mylastindex; |
1135 | } |
1136 | if (theToRedrawImmediate) |
1137 | { |
1138 | theView->RedrawImmediate(); |
1139 | } |
1140 | return; |
1141 | } |
7fd59977 |
1142 | |
679ecdee |
1143 | //======================================================================================================= |
1144 | // 2 cases : a- object is in the map of picks: |
1145 | // 1. this is the same index as the last detected: -> Do nothing |
1146 | // 2. otherwise : |
1147 | // - if lastindex = 0 (no object was detected at the last step) |
1148 | // the object presentation is highlighted and lastindex = index(objet) |
1149 | // - othrwise : |
1150 | // the presentation of the object corresponding to lastindex is "unhighlighted" |
1151 | // it is removed if the object is not visualized but only active |
1152 | // then the presentation of the detected object is highlighted and lastindex = index(objet) |
1153 | // b- the object is not in the map of picked objects |
1154 | // - if lastindex != 0 (object detected at the last step) it is unhighlighted ... |
1155 | // if the object was decomposed, presentation is created for the detected shape and the couple |
1156 | // (Proprietaire,Prs)is added in the map. |
1157 | // otherwise the couple(proprietaire, NullPrs) is placed in the map and the interactive object |
1158 | // itself is highlighted. |
1159 | // |
1160 | //======================================================================================================= |
1161 | |
1162 | const Standard_Integer aNewIndex = myMapOfOwner.Contains (thePickOwner) |
1163 | ? myMapOfOwner.FindIndex (thePickOwner) |
1164 | : myMapOfOwner.Add (thePickOwner); |
1165 | |
1166 | // For the advanced mesh selection mode the owner indices comparison |
1167 | // is not effective because in that case only one owner manage the |
1168 | // selection in current selection mode. It is necessary to check the current detected |
1169 | // entity and hilight it only if the detected entity is not the same as |
1170 | // previous detected (IsForcedHilight call) |
1171 | if (aNewIndex != mylastindex |
1172 | || thePickOwner->IsForcedHilight()) |
1173 | { |
63d907e7 |
1174 | myMainPM->ClearImmediateDraw(); |
679ecdee |
1175 | if (mylastindex != 0 |
1176 | && mylastindex <= myMapOfOwner.Extent()) |
1177 | { |
1178 | const Handle(SelectMgr_EntityOwner)& aLastOwner = myMapOfOwner (mylastindex); |
1179 | Unhilight (aLastOwner, theView); |
1180 | } |
7fd59977 |
1181 | |
679ecdee |
1182 | if (myAutoHilight) |
1183 | { |
c398b00e |
1184 | if (!thePickOwner->IsSelected() || myCTX->ToHilightSelected()) |
679ecdee |
1185 | { |
1186 | Hilight (thePickOwner, theView); |
7fd59977 |
1187 | } |
679ecdee |
1188 | if (theToRedrawImmediate) |
1189 | { |
1190 | theView->RedrawImmediate(); |
7fd59977 |
1191 | } |
7fd59977 |
1192 | } |
679ecdee |
1193 | |
1194 | mylastindex = aNewIndex; |
7fd59977 |
1195 | } |
1196 | |
63d907e7 |
1197 | if (mylastindex != 0) |
679ecdee |
1198 | { |
1199 | mylastgood = mylastindex; |
1200 | } |
7fd59977 |
1201 | } |
1202 | |
7fd59977 |
1203 | //======================================================================= |
1204 | //function : HasDetectedShape |
1205 | //purpose : |
1206 | //======================================================================= |
1207 | |
1208 | Standard_Boolean AIS_LocalContext::HasDetectedShape() const |
1209 | { |
1210 | if(mylastindex==0) return Standard_False; |
1211 | return IsShape(mylastindex); |
1212 | } |
1213 | |
1214 | //======================================================================= |
1215 | //function : DetectedShape |
1216 | //purpose : |
1217 | //======================================================================= |
1218 | |
1219 | const TopoDS_Shape& |
1220 | AIS_LocalContext::DetectedShape() const |
1221 | { |
1222 | static TopoDS_Shape bidsh; |
1223 | if(mylastindex != 0) |
1224 | { |
1225 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner(mylastindex)); |
1226 | if(BROwnr.IsNull()) return bidsh; |
1227 | return BROwnr->Shape(); |
1228 | } |
1229 | return bidsh; |
1230 | } |
1231 | |
1232 | //======================================================================= |
1233 | //function : DetectedInteractive |
1234 | //purpose : |
1235 | //======================================================================= |
1236 | |
1237 | Handle(AIS_InteractiveObject) |
1238 | AIS_LocalContext::DetectedInteractive() const |
1239 | { |
1240 | Handle(AIS_InteractiveObject) Iobj; |
1241 | if(IsValidIndex(mylastindex)){ |
1242 | Handle(SelectMgr_SelectableObject) SO = myMapOfOwner.FindKey(mylastindex)->Selectable(); |
1243 | Iobj = *((Handle(AIS_InteractiveObject)*) &SO); |
1244 | } |
1245 | return Iobj; |
1246 | } |
1247 | //======================================================================= |
1248 | //function : DetectedInteractive |
1249 | //purpose : |
1250 | //======================================================================= |
1251 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::DetectedOwner() const |
1252 | { |
1253 | Handle(SelectMgr_EntityOwner) bid; |
1254 | if(!IsValidIndex(mylastindex)) return bid; |
1255 | return myMapOfOwner.FindKey(mylastindex); |
1256 | } |
1257 | |
1258 | |
1259 | //======================================================================= |
1260 | //function : ComesFromDecomposition |
1261 | //purpose : |
1262 | //======================================================================= |
1263 | |
1264 | Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer PickedIndex) const |
1265 | { |
1266 | const Handle(SelectMgr_EntityOwner)& OWN = myMapOfOwner.FindKey(PickedIndex); |
1267 | Handle(SelectMgr_SelectableObject) aSel = OWN->Selectable(); |
81bba717 |
1268 | if (myActiveObjects.IsBound (aSel)) { // debug of jmi |
7fd59977 |
1269 | const Handle(AIS_LocalStatus)& Stat = myActiveObjects(aSel); |
1270 | return Stat->Decomposed(); |
1271 | } |
1272 | return Standard_False; |
1273 | } |
1274 | |
7fd59977 |
1275 | //======================================================================= |
1276 | //function : DisplaySensitive |
1277 | //purpose : |
1278 | //======================================================================= |
1279 | |
1280 | void AIS_LocalContext::DisplaySensitive(const Handle(V3d_View)& aviou) |
1281 | { |
1282 | myMainVS->DisplaySensitive(aviou); |
1283 | } |
1284 | |
1285 | //======================================================================= |
1286 | //function : ClearSensitive |
1287 | //purpose : |
1288 | //======================================================================= |
1289 | |
1290 | void AIS_LocalContext::ClearSensitive(const Handle(V3d_View)& aviou) |
1291 | { |
1292 | myMainVS->ClearSensitive(aviou); |
1293 | } |
1294 | |
1295 | |
1296 | //======================================================================= |
1297 | //function : IsShape |
1298 | //purpose : |
1299 | //======================================================================= |
1300 | Standard_Boolean AIS_LocalContext::IsShape(const Standard_Integer Index) const |
1301 | { |
1302 | |
1303 | if(Handle(StdSelect_BRepOwner)::DownCast(myMapOfOwner.FindKey(Index)).IsNull()) |
1304 | return Standard_False; |
1305 | return |
1306 | ComesFromDecomposition(Index); |
1307 | } |
1308 | |
1309 | Standard_Boolean AIS_LocalContext::IsValidForSelection(const Handle(AIS_InteractiveObject)& anIObj) const |
1310 | { |
1311 | |
7fd59977 |
1312 | // Shape was not transfered from AIS_Shape to EntityOwner |
1313 | Handle(AIS_Shape) shape = Handle(AIS_Shape)::DownCast(anIObj); |
1314 | if( !shape.IsNull() ) |
1315 | return myFilters->IsOk(new StdSelect_BRepOwner(shape->Shape(),shape)); |
7fd59977 |
1316 | return myFilters->IsOk(new SelectMgr_EntityOwner(anIObj)); |
1317 | } |
1318 | |
1319 | |
1320 | //======================================================================= |
1321 | //function : HilightNextDetected |
679ecdee |
1322 | //purpose : |
7fd59977 |
1323 | //======================================================================= |
679ecdee |
1324 | Standard_Integer AIS_LocalContext::HilightNextDetected (const Handle(V3d_View)& theView, |
1325 | const Standard_Boolean theToRedrawImmediate) |
7fd59977 |
1326 | { |
81bba717 |
1327 | // go to the next owner |
679ecdee |
1328 | if (myDetectedSeq.IsEmpty()) |
1329 | { |
1330 | return 0; |
1331 | } |
7fd59977 |
1332 | |
679ecdee |
1333 | const Standard_Integer aLen = myDetectedSeq.Length(); |
1334 | if (++myCurDetected > aLen) |
1335 | { |
7fd59977 |
1336 | myCurDetected = 1; |
7fd59977 |
1337 | } |
bc677575 |
1338 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected)); |
679ecdee |
1339 | if (anOwner.IsNull()) |
1340 | { |
1341 | return 0; |
1342 | } |
1343 | manageDetected (anOwner, theView, theToRedrawImmediate); |
7fd59977 |
1344 | return myCurDetected; |
1345 | } |
1346 | |
1347 | //======================================================================= |
1348 | //function : HilightPreviousDetected |
679ecdee |
1349 | //purpose : |
7fd59977 |
1350 | //======================================================================= |
679ecdee |
1351 | Standard_Integer AIS_LocalContext::HilightPreviousDetected (const Handle(V3d_View)& theView, |
1352 | const Standard_Boolean theToRedrawImmediate) |
7fd59977 |
1353 | { |
679ecdee |
1354 | if (myDetectedSeq.IsEmpty()) |
1355 | { |
1356 | return 0; |
1357 | } |
7fd59977 |
1358 | |
4ca4bbe8 |
1359 | const Standard_Integer aLen = myDetectedSeq.Length(); |
679ecdee |
1360 | if (--myCurDetected < 1) |
1361 | { |
4ca4bbe8 |
1362 | myCurDetected = aLen; |
679ecdee |
1363 | } |
bc677575 |
1364 | Handle(SelectMgr_EntityOwner) anOwner = myMainVS->Picked (myDetectedSeq (myCurDetected)); |
679ecdee |
1365 | if (anOwner.IsNull()) |
1366 | { |
1367 | return 0; |
7fd59977 |
1368 | } |
1369 | |
679ecdee |
1370 | manageDetected (anOwner, theView, theToRedrawImmediate); |
7fd59977 |
1371 | return myCurDetected; |
1372 | } |
1373 | |
1374 | //======================================================================= |
1375 | //function : UnhilightLastDetected |
679ecdee |
1376 | //purpose : |
7fd59977 |
1377 | //======================================================================= |
679ecdee |
1378 | Standard_Boolean AIS_LocalContext::UnhilightLastDetected (const Handle(V3d_View)& theView) |
7fd59977 |
1379 | { |
679ecdee |
1380 | if (!IsValidIndex (mylastindex)) |
1381 | { |
1382 | return Standard_False; |
7fd59977 |
1383 | } |
7fd59977 |
1384 | |
679ecdee |
1385 | myMainPM->BeginImmediateDraw(); |
1386 | const Handle(SelectMgr_EntityOwner)& anOwner = myMapOfOwner (mylastindex); |
1387 | const Standard_Integer aHilightMode = anOwner->HasSelectable() |
1388 | ? GetHiMod (Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable())) |
1389 | : 0; |
7fd59977 |
1390 | |
679ecdee |
1391 | myMapOfOwner (mylastindex)->Unhilight (myMainPM, aHilightMode); |
1392 | myMainPM->EndImmediateDraw (theView); |
1393 | mylastindex = 0; |
1394 | return Standard_True; |
7fd59977 |
1395 | } |
1396 | |
1397 | //======================================================================= |
1398 | //function : FindSelectedOwnerFromIO |
81bba717 |
1399 | //purpose : it is checked if one of the selected owners really presents IObj |
7fd59977 |
1400 | //======================================================================= |
1401 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromIO |
1402 | (const Handle(AIS_InteractiveObject)& anIObj) const |
1403 | { |
1404 | Handle(SelectMgr_EntityOwner) EO,bid; |
1405 | if (anIObj.IsNull()) return EO; |
1406 | |
1407 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
1408 | if(Sel.IsNull()) { |
0797d9d3 |
1409 | #ifdef OCCT_DEBUG |
7fd59977 |
1410 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection " |
1411 | <<mySelName<<" Nulle "<<endl; |
1412 | #endif |
1413 | return EO; |
1414 | } |
1415 | Standard_Boolean found(Standard_False); |
7fd59977 |
1416 | const AIS_NListTransient& Obj = Sel->Objects(); |
1417 | AIS_NListTransient::Iterator anIter( Obj ); |
1418 | for(; anIter.More(); anIter.Next()){ |
1419 | const Handle(Standard_Transient)& Tr = anIter.Value(); |
7fd59977 |
1420 | if(!Tr.IsNull()){ |
1421 | EO = *((Handle(SelectMgr_EntityOwner)*)&Tr); |
1422 | if(EO->HasSelectable()){ |
1423 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
1424 | if(BROwnr.IsNull() || !BROwnr->ComesFromDecomposition()){ |
1425 | if (anIObj == EO->Selectable()){ |
1426 | found =Standard_True; |
1427 | break; |
1428 | } |
1429 | } |
1430 | } |
1431 | } |
1432 | } |
1433 | if(found) return EO; |
1434 | return bid; |
1435 | } |
1436 | |
1437 | //======================================================================= |
1438 | //function : FindSelectedOwnerFromShape |
81bba717 |
1439 | //purpose : it is checked if one of the selected owners really presents IObj |
7fd59977 |
1440 | //======================================================================= |
1441 | Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const TopoDS_Shape& sh) const |
1442 | { |
7fd59977 |
1443 | Handle(SelectMgr_EntityOwner) EO, bid; |
7fd59977 |
1444 | if (sh.IsNull()) return EO; |
1445 | |
1446 | Handle(AIS_Selection) Sel = AIS_Selection::Selection(mySelName.ToCString()); |
1447 | if(Sel.IsNull()) { |
0797d9d3 |
1448 | #ifdef OCCT_DEBUG |
7fd59977 |
1449 | cout<<"\t\tAIS_LocalCOntext::FindSelectedOwnerFromShape : Selection "<<mySelName<<" Nulle "<<endl; |
1450 | #endif |
1451 | return EO; |
1452 | } |
1453 | |
1454 | Standard_Boolean found(Standard_False); |
1455 | |
7fd59977 |
1456 | if (!found) { |
f751596e |
1457 | NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (myMainVS->ActiveOwners()); |
1458 | for (; anOwnersIt.More(); anOwnersIt.Next()) { |
1459 | EO = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value()); |
7fd59977 |
1460 | Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO); |
1461 | if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) { |
1462 | found = Standard_True; |
1463 | break; |
1464 | } |
1465 | } |
1466 | } |
7fd59977 |
1467 | |
1468 | if(found) return EO; |
1469 | return bid; |
1470 | } |
1471 | |
7fd59977 |
1472 | //======================================================================= |
1473 | //function : AIS_LocalContext::InitDetected |
1474 | //purpose : |
1475 | //======================================================================= |
7fd59977 |
1476 | void AIS_LocalContext::InitDetected() |
1477 | { |
1478 | myAISCurDetected = myAISDetectedSeq.Length()? 1 : 0; |
1479 | } |
1480 | |
1481 | //======================================================================= |
1482 | //function : AIS_LocalContext::MoreDetected |
1483 | //purpose : |
1484 | //======================================================================= |
7fd59977 |
1485 | Standard_Boolean AIS_LocalContext::MoreDetected() const |
1486 | { |
1487 | return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()); |
1488 | } |
1489 | |
7fd59977 |
1490 | //======================================================================= |
1491 | //function : AIS_LocalContext::NextDetected |
1492 | //purpose : |
1493 | //======================================================================= |
7fd59977 |
1494 | void AIS_LocalContext::NextDetected() |
1495 | { |
57ad5cbd |
1496 | myAISCurDetected++; |
7fd59977 |
1497 | } |
1498 | |
1499 | //======================================================================= |
1500 | //function : DetectedCurrentShape |
1501 | //purpose : |
1502 | //======================================================================= |
7fd59977 |
1503 | const TopoDS_Shape& AIS_LocalContext::DetectedCurrentShape() const |
1504 | { |
57ad5cbd |
1505 | static TopoDS_Shape aDummyShape; |
7fd59977 |
1506 | |
57ad5cbd |
1507 | Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject()); |
1508 | |
1509 | if (aCurrentShape.IsNull()) |
1510 | { |
1511 | return aDummyShape; |
1512 | } |
1513 | |
1514 | return aCurrentShape->Shape(); |
1515 | } |
7fd59977 |
1516 | //======================================================================= |
1517 | //function : DetectedCurrentObject |
1518 | //purpose : |
1519 | //======================================================================= |
7fd59977 |
1520 | Handle(AIS_InteractiveObject) AIS_LocalContext::DetectedCurrentObject() const |
1521 | { |
57ad5cbd |
1522 | return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL; |
7fd59977 |
1523 | } |