1 // Created on: 1997-01-29
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
19 #include <AIS_GlobalStatus.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
23 #include <AIS_MapOfInteractive.hxx>
24 #include <AIS_Selection.hxx>
25 #include <AIS_Shape.hxx>
26 #include <AIS_StatusOfDetection.hxx>
27 #include <AIS_StatusOfPick.hxx>
28 #include <Aspect_Grid.hxx>
29 #include <Prs3d_BasicAspect.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Prs3d_Presentation.hxx>
32 #include <Quantity_Color.hxx>
33 #include <Select3D_SensitiveEntity.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <SelectMgr_Filter.hxx>
36 #include <SelectMgr_OrFilter.hxx>
37 #include <SelectMgr_Selection.hxx>
38 #include <SelectMgr_SelectionManager.hxx>
39 #include <Standard_Transient.hxx>
40 #include <StdSelect_BRepOwner.hxx>
41 #include <StdSelect_ViewerSelector3d.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <TCollection_ExtendedString.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <TopLoc_Location.hxx>
46 #include <V3d_AmbientLight.hxx>
47 #include <V3d_DirectionalLight.hxx>
48 #include <V3d_Light.hxx>
49 #include <V3d_PositionalLight.hxx>
50 #include <V3d_SpotLight.hxx>
51 #include <V3d_View.hxx>
52 #include <V3d_Viewer.hxx>
54 typedef NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > AIS_MapOfObjSelectedOwners;
58 TopoDS_Shape AIS_InteractiveContext_myDummyShape;
61 //=======================================================================
62 //function : highlightWithColor
64 //=======================================================================
65 void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
66 const Handle(V3d_Viewer)& theViewer)
68 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
74 const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
75 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
77 myMainPM->BeginImmediateDraw();
78 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
79 myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
82 //=======================================================================
83 //function : highlightSelected
85 //=======================================================================
86 void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
88 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
94 if (!theOwner->IsAutoHilight())
96 SelectMgr_SequenceOfOwner aSeq;
97 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
99 if (aSelIter.Value()->IsSameSelectable (anObj))
101 aSeq.Append (aSelIter.Value());
104 anObj->HilightSelected (myMainPM, aSeq);
108 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
109 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
110 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
114 //=======================================================================
115 //function : highlightGlobal
117 //=======================================================================
118 void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
119 const Handle(Prs3d_Drawer)& theStyle,
120 const Standard_Integer theDispMode) const
127 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
128 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
130 if (aGlobOwner.IsNull())
132 myMainPM->Color (theObj, theStyle, aHiMode);
136 if (!aGlobOwner->IsAutoHilight())
138 SelectMgr_SequenceOfOwner aSeq;
139 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
141 if (aSelIter.Value()->IsSameSelectable (theObj))
143 aSeq.Append (aSelIter.Value());
146 theObj->HilightSelected (myMainPM, aSeq);
150 aGlobOwner->HilightWithColor (myMainPM, theStyle, aHiMode);
154 //=======================================================================
155 //function : unhighlightSelected
157 //=======================================================================
158 void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
160 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
161 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
163 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
164 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
165 Handle(AIS_GlobalStatus) aStatus;
166 if (!myObjects.Find (anInteractive, aStatus))
171 if (anOwner->IsAutoHilight())
173 anOwner->Unhilight (myMainPM);
174 if (theIsToHilightSubIntensity)
176 if (aStatus->IsSubIntensityOn())
178 const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode());
179 highlightWithSubintensity (anOwner, aHiMode);
185 anObjToClear.Add (anInteractive);
187 anOwner->SetSelected (Standard_False);
188 if (anOwner == anInteractive->GlobalSelOwner())
190 myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False);
193 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
195 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
196 myMainPM->Unhighlight (anObj);
197 anObj->ClearSelected();
201 //=======================================================================
202 //function : unhighlightGlobal
204 //=======================================================================
205 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const
212 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
213 if (aGlobOwner.IsNull())
215 myMainPM->Unhighlight (theObj);
219 if (aGlobOwner->IsAutoHilight())
221 aGlobOwner->Unhilight (myMainPM);
225 myMainPM->Unhighlight (theObj);
226 theObj->ClearSelected();
230 //=======================================================================
231 //function : turnOnSubintensity
233 //=======================================================================
234 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
235 const Standard_Integer theDispMode,
236 const Standard_Boolean theIsDisplayedOnly) const
238 // the only differ with selection highlight is color, so sync transparency values
239 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
240 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
242 if (theObject.IsNull())
244 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
246 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
247 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
250 aStatus->SubIntensityOn();
251 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
256 Handle(AIS_GlobalStatus) aStatus;
257 if (!myObjects.Find (theObject, aStatus))
260 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
263 aStatus->SubIntensityOn();
264 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
268 //=======================================================================
269 //function : highlightWithSubintensity
271 //=======================================================================
272 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
273 const Standard_Integer theMode) const
275 // the only differ with selection highlight is color, so
276 // sync transparency values
277 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
279 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
282 //=======================================================================
283 //function : highlightWithSubintensity
285 //=======================================================================
286 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
287 const Standard_Integer theMode) const
289 // the only differ with selection highlight is color, so
290 // sync transparency values
291 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
293 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
296 //=======================================================================
297 //function : isSlowHiStyle
299 //=======================================================================
300 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
301 const Handle(V3d_Viewer)& theViewer) const
303 if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
305 const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
306 return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
307 || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
309 return Standard_False;
312 //=======================================================================
315 //=======================================================================
316 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
317 const Standard_Integer theYPix,
318 const Handle(V3d_View)& theView,
319 const Standard_Boolean theToRedrawOnUpdate)
321 if (theView->Viewer() != myMainVwr)
323 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
327 myCurHighlighted = 0;
328 myDetectedSeq.Clear();
331 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
332 Standard_Boolean toUpdateViewer = Standard_False;
334 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
335 myMainSel->Pick (theXPix, theYPix, theView);
337 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
338 // (the objects must be AIS_Shapes)
339 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
340 Standard_Integer aNewDetected = 0;
341 Standard_Boolean toIgnoreDetTop = Standard_False;
342 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
344 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
346 || !myFilters->IsOk (anOwner))
348 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
350 toIgnoreDetTop = Standard_True;
358 aNewDetected = aDetIter;
361 myDetectedSeq.Append (aDetIter);
364 if (aNewDetected >= 1)
366 myCurHighlighted = myDetectedSeq.Lower();
368 // Does nothing if previously detected object is equal to the current one.
369 // However in advanced selection modes the owners comparison
370 // is not effective because in that case only one owner manage the
371 // selection in current selection mode. It is necessary to check the current detected
372 // entity and hilight it only if the detected entity is not the same as
373 // previous detected (IsForcedHilight call)
374 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
375 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
377 return myLastPicked->IsSelected()
379 : AIS_SOD_OnlyOneDetected;
382 // Previously detected object is unhilighted if it is not selected or hilighted
383 // with selection color if it is selected. Such highlighting with selection color
384 // is needed only if myToHilightSelected flag is true. In this case previously detected
385 // object has been already highlighted with myHilightColor during previous MoveTo()
386 // method call. As result it is necessary to rehighligt it with mySelectionColor.
387 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
389 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
391 theView->Viewer()->Invalidate();
394 clearDynamicHighlight();
395 toUpdateViewer = Standard_True;
398 // initialize myLastPicked field with currently detected object
399 myLastPicked = aNewPickedOwner;
401 // highlight detected object if it is not selected or myToHilightSelected flag is true
402 if (myLastPicked->HasSelectable())
405 && (!myLastPicked->IsSelected()
406 || myToHilightSelected))
408 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
410 theView->Viewer()->Invalidate();
413 highlightWithColor (myLastPicked, theView->Viewer());
414 toUpdateViewer = Standard_True;
417 aStatus = myLastPicked->IsSelected()
419 : AIS_SOD_OnlyOneDetected;
424 // previously detected object is unhilighted if it is not selected or hilighted
425 // with selection color if it is selected
426 aStatus = AIS_SOD_Nothing;
428 && !myLastPicked.IsNull()
429 && myLastPicked->HasSelectable())
431 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
433 theView->Viewer()->Invalidate();
436 clearDynamicHighlight();
437 toUpdateViewer = Standard_True;
440 myLastPicked.Nullify();
444 && theToRedrawOnUpdate)
446 if (theView->ComputedMode())
448 theView->Viewer()->Update();
452 if (theView->IsInvalidated())
454 theView->Viewer()->Redraw();
458 theView->Viewer()->RedrawImmediate();
466 //=======================================================================
467 //function : AddSelect
469 //=======================================================================
470 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
472 mySelection->AddSelect (theObject);
474 Standard_Integer aSelNum = NbSelected();
475 return (aSelNum == 0) ? AIS_SOP_NothingSelected
476 : (aSelNum == 1) ? AIS_SOP_OneSelected
477 : AIS_SOP_SeveralSelected;
480 //=======================================================================
483 //=======================================================================
484 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
485 const Standard_Integer theYPMin,
486 const Standard_Integer theXPMax,
487 const Standard_Integer theYPMax,
488 const Handle(V3d_View)& theView,
489 const Standard_Boolean toUpdateViewer)
491 if (theView->Viewer() != myMainVwr)
493 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
496 // all objects detected by the selector are taken, previous current objects are emptied,
497 // new objects are put...
498 ClearSelected (Standard_False);
499 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
500 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
502 const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter);
503 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
506 mySelection->Select (aCurOwner);
507 aCurOwner->SetSelected (Standard_True);
512 HilightSelected (toUpdateViewer);
515 Standard_Integer aSelNum = NbSelected();
517 return (aSelNum == 0) ? AIS_SOP_NothingSelected
518 : (aSelNum == 1) ? AIS_SOP_OneSelected
519 : AIS_SOP_SeveralSelected;
523 //=======================================================================
525 //purpose : Selection by polyline
526 //=======================================================================
527 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
528 const Handle(V3d_View)& theView,
529 const Standard_Boolean toUpdateViewer)
531 if (theView->Viewer() != myMainVwr)
533 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
536 // all objects detected by the selector are taken, previous current objects are emptied,
537 // new objects are put...
538 ClearSelected (Standard_False);
539 myMainSel->Pick (thePolyline, theView);
540 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
542 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
543 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
546 mySelection->Select (anOwner);
547 anOwner->SetSelected (Standard_True);
552 HilightSelected (toUpdateViewer);
555 Standard_Integer aSelNum = NbSelected();
557 return (aSelNum == 0) ? AIS_SOP_NothingSelected
558 : (aSelNum == 1) ? AIS_SOP_OneSelected
559 : AIS_SOP_SeveralSelected;
563 //=======================================================================
566 //=======================================================================
567 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
569 if (!myLastPicked.IsNull())
573 clearDynamicHighlight();
575 if (!myLastPicked->IsSelected()
576 || myLastPicked->IsForcedHilight()
579 SetSelected (myLastPicked, Standard_False);
582 UpdateCurrentViewer();
588 ClearSelected (toUpdateViewer);
591 Standard_Integer aSelNum = NbSelected();
593 return (aSelNum == 0) ? AIS_SOP_NothingSelected
594 : (aSelNum == 1) ? AIS_SOP_OneSelected
595 : AIS_SOP_SeveralSelected;
598 //=======================================================================
599 //function : ShiftSelect
601 //=======================================================================
602 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
606 clearDynamicHighlight();
608 if (!myLastPicked.IsNull())
610 AddOrRemoveSelected (myLastPicked, toUpdateViewer);
613 Standard_Integer aSelNum = NbSelected();
615 return (aSelNum == 0) ? AIS_SOP_NothingSelected
616 : (aSelNum == 1) ? AIS_SOP_OneSelected
617 : AIS_SOP_SeveralSelected;
620 //=======================================================================
621 //function : ShiftSelect
623 //=======================================================================
624 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
625 const Standard_Integer theYPMin,
626 const Standard_Integer theXPMax,
627 const Standard_Integer theYPMax,
628 const Handle(V3d_View)& theView,
629 const Standard_Boolean toUpdateViewer)
631 if (theView->Viewer() != myMainVwr)
633 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
638 UnhilightSelected (Standard_False);
640 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
641 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
643 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
644 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
647 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
648 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
653 HilightSelected (toUpdateViewer);
656 Standard_Integer aSelNum = NbSelected();
658 return (aSelNum == 0) ? AIS_SOP_NothingSelected
659 : (aSelNum == 1) ? AIS_SOP_OneSelected
660 : AIS_SOP_SeveralSelected;
664 //=======================================================================
665 //function : ShiftSelect
667 //=======================================================================
668 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
669 const Handle(V3d_View)& theView,
670 const Standard_Boolean toUpdateViewer)
672 if (theView->Viewer() != myMainVwr)
674 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
679 UnhilightSelected (Standard_False);
681 myMainSel->Pick (thePolyline, theView);
682 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
684 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
685 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
688 AIS_SelectStatus aSelStatus = mySelection->Select (anOwner);
689 anOwner->SetSelected (aSelStatus == AIS_SS_Added);
694 HilightSelected (toUpdateViewer);
697 Standard_Integer aSelNum = NbSelected();
699 return (aSelNum == 0) ? AIS_SOP_NothingSelected
700 : (aSelNum == 1) ? AIS_SOP_OneSelected
701 : AIS_SOP_SeveralSelected;
704 //=======================================================================
705 //function : HilightSelected
707 //=======================================================================
708 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
710 // In case of selection without using local context
711 clearDynamicHighlight();
712 AIS_MapOfObjSelectedOwners anObjOwnerMap;
713 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
715 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
716 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
717 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
718 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
719 if (anOwner == anObj->GlobalSelOwner())
721 aState->SetHilightStatus (Standard_True);
722 aState->SetHilightStyle (anObjSelStyle);
724 anOwner->SetSelected (Standard_True);
725 if (!anOwner->IsAutoHilight())
727 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
728 if (anObjOwnerMap.Find (anObj, aSeq))
730 aSeq->Append (anOwner);
734 aSeq = new SelectMgr_SequenceOfOwner();
735 aSeq->Append (anOwner);
736 anObjOwnerMap.Bind (anObj, aSeq);
741 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
742 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
746 if (!anObjOwnerMap.IsEmpty())
748 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
750 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
752 anObjOwnerMap.Clear();
755 if (theToUpdateViewer)
756 UpdateCurrentViewer();
759 //=======================================================================
760 //function : UnhilightSelected
762 //=======================================================================
763 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
765 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
767 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
768 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
769 if (anOwner == anObj->GlobalSelOwner())
771 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
774 anOwner->SetSelected (Standard_False);
775 anOwner->Unhilight (myMainPM);
778 if (theToUpdateViewer)
779 UpdateCurrentViewer();
783 //=======================================================================
784 //function : ClearSelected
786 //=======================================================================
787 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
789 if (NbSelected() == 0)
794 unhighlightSelected();
798 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
800 aSelIter.Value()->SetSelected (Standard_False);
804 mySelection->Clear();
807 clearDynamicHighlight();
810 if (theToUpdateViewer)
811 UpdateCurrentViewer();
814 //=======================================================================
815 //function : SetSelected
816 //purpose : Sets the whole object as selected and highlights it with selection color
817 //=======================================================================
818 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
819 const Standard_Boolean theToUpdateViewer)
821 if (theObject.IsNull())
826 if (!myObjects.IsBound (theObject))
828 Display (theObject, Standard_False);
831 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
832 if (anOwner.IsNull())
837 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
838 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
840 Handle(Prs3d_Drawer) aCustomStyle;
841 if (HighlightStyle (theObject, aCustomStyle))
843 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
845 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
851 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
853 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
854 if (!myFilters->IsOk (aSelOwner))
859 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
862 Unhilight (aSelectable, Standard_False);
864 aSelOwner->SetSelected (Standard_False);
865 if (aSelOwner == aSelectable->GlobalSelOwner())
867 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
871 // added to avoid untimely viewer update...
872 mySelection->ClearAndSelect (anOwner);
876 Handle(Prs3d_Drawer) aCustomStyle;
877 if (HighlightStyle (theObject, aCustomStyle))
879 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
881 HilightWithColor (theObject, anObjSelStyle, Standard_False);
886 HilightWithColor (theObject, anObjSelStyle, Standard_False);
889 anOwner->SetSelected (Standard_True);
891 if (theToUpdateViewer)
892 UpdateCurrentViewer();
895 //=======================================================================
896 //function : SetSelected
897 //purpose : Sets the whole object as selected and highlights it with selection color
898 //=======================================================================
899 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
900 const Standard_Boolean theToUpdateViewer)
902 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
905 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
906 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
907 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
909 Handle(Prs3d_Drawer) aCustomStyle;
910 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
912 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
914 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
915 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
921 if (!myObjects.IsBound (anObject))
922 Display (anObject, Standard_False);
926 unhighlightSelected();
929 mySelection->ClearAndSelect (theOwner);
932 Handle(Prs3d_Drawer) aCustomStyle;
933 if (!HighlightStyle (theOwner, aCustomStyle) ||
934 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
936 theOwner->SetSelected (Standard_True);
937 highlightSelected (theOwner);
941 theOwner->SetSelected (Standard_True);
942 if (myAutoHilight && theOwner == anObject->GlobalSelOwner())
944 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
945 aState->SetHilightStatus (Standard_True);
946 aState->SetHilightStyle (anObjSelStyle);
949 if (theToUpdateViewer)
950 UpdateCurrentViewer();
953 //=======================================================================
954 //function : AddOrRemoveSelected
955 //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
956 // Since this method makes sence only for neutral point selection of a whole object,
957 // if 0 selection of the object is empty this method simply does nothing.
958 //=======================================================================
959 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
960 const Standard_Boolean theToUpdateViewer)
962 if (theObject.IsNull()
963 || !myObjects.IsBound (theObject))
968 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
969 if (!anOwner.IsNull()
970 && anOwner->HasSelectable())
972 AddOrRemoveSelected (anOwner, theToUpdateViewer);
976 //=======================================================================
977 //function : AddOrRemoveSelected
978 //purpose : Allows to highlight or unhighlight the owner given depending on
979 // its selection status
980 //=======================================================================
981 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
982 const Standard_Boolean theToUpdateViewer)
984 if (theOwner.IsNull() || !theOwner->HasSelectable())
987 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
990 AIS_SelectStatus aSelStat = mySelection->Select (theOwner);
991 theOwner->SetSelected (aSelStat == AIS_SS_Added);
995 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
996 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
997 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
998 if (theOwner->IsSelected())
1000 highlightSelected (theOwner);
1003 aStatus->SetHilightStatus (Standard_True);
1004 aStatus->SetHilightStyle (getSelStyle (anObj, theOwner));
1009 if (theOwner->IsAutoHilight())
1011 theOwner->Unhilight (myMainPM);
1015 anObj->ClearSelected();
1017 aStatus->SetHilightStatus (Standard_False);
1018 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
1022 if (theToUpdateViewer)
1023 UpdateCurrentViewer();
1027 //=======================================================================
1028 //function : IsSelected
1030 //=======================================================================
1031 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
1033 if (theObj.IsNull())
1035 return Standard_False;
1038 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1039 if (aStatus == NULL)
1041 return Standard_False;
1044 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1045 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
1046 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1048 if (aModeIter.Value() == aGlobalSelMode)
1050 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1052 return aGlobOwner->IsSelected();
1054 return Standard_False;
1057 return Standard_False;
1060 //=======================================================================
1061 //function : FirstSelectedObject
1063 //=======================================================================
1064 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
1066 return !mySelection->Objects().IsEmpty()
1067 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1068 : Handle(AIS_InteractiveObject)();
1071 //=======================================================================
1072 //function : HasSelectedShape
1074 //=======================================================================
1075 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1077 if (!mySelection->More())
1078 return Standard_False;
1080 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1081 return !anOwner.IsNull() && anOwner->HasShape();
1084 //=======================================================================
1085 //function : SelectedShape
1087 //=======================================================================
1088 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1090 if (!mySelection->More())
1091 return TopoDS_Shape();
1093 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1094 if (anOwner.IsNull() || !anOwner->HasSelectable())
1095 return TopoDS_Shape();
1097 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
1100 //=======================================================================
1101 //function : EntityOwners
1103 //=======================================================================
1104 void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
1105 const Handle(AIS_InteractiveObject)& theIObj,
1106 const Standard_Integer theMode) const
1108 if (theIObj.IsNull())
1113 TColStd_ListOfInteger aModes;
1116 ActivatedModes (theIObj, aModes);
1120 aModes.Append (theMode);
1123 if (theOwners.IsNull())
1125 theOwners = new SelectMgr_IndexedMapOfOwner();
1128 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
1130 const int aMode = anItr.Value();
1131 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1137 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
1139 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1141 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
1143 theOwners->Add (aOwner);
1150 //=======================================================================
1151 //function : HasDetectedShape
1153 //=======================================================================
1154 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1156 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1157 return !anOwner.IsNull()
1158 && anOwner->HasShape();
1161 //=======================================================================
1162 //function : DetectedShape
1164 //=======================================================================
1165 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
1167 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1168 return anOwner->Shape();
1171 //=======================================================================
1172 //function : HilightNextDetected
1174 //=======================================================================
1175 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1176 const Standard_Boolean theToRedrawImmediate)
1178 myMainPM->ClearImmediateDraw();
1179 if (myDetectedSeq.IsEmpty())
1184 if (++myCurHighlighted > myDetectedSeq.Upper())
1186 myCurHighlighted = myDetectedSeq.Lower();
1188 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1189 if (anOwner.IsNull())
1194 highlightWithColor (anOwner, theView->Viewer());
1195 myLastPicked = anOwner;
1197 if (theToRedrawImmediate)
1199 myMainPM->RedrawImmediate (theView->Viewer());
1200 myMainVwr->RedrawImmediate();
1203 return myCurHighlighted;
1206 //=======================================================================
1207 //function : HilightPreviousDetected
1209 //=======================================================================
1210 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1211 const Standard_Boolean theToRedrawImmediate)
1213 myMainPM->ClearImmediateDraw();
1214 if (myDetectedSeq.IsEmpty())
1219 if (--myCurHighlighted < myDetectedSeq.Lower())
1221 myCurHighlighted = myDetectedSeq.Upper();
1223 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1224 if (anOwner.IsNull())
1229 highlightWithColor (anOwner, theView->Viewer());
1230 myLastPicked = anOwner;
1232 if (theToRedrawImmediate)
1234 myMainPM->RedrawImmediate (theView->Viewer());
1235 myMainVwr->RedrawImmediate();
1238 return myCurHighlighted;
1241 //=======================================================================
1242 //function : DetectedCurrentOwner
1244 //=======================================================================
1245 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1247 return MoreDetected()
1248 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1249 : Handle(SelectMgr_EntityOwner)();
1252 //=======================================================================
1253 //function : DetectedCurrentShape
1255 //=======================================================================
1256 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1258 Standard_DISABLE_DEPRECATION_WARNINGS
1259 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1260 Standard_ENABLE_DEPRECATION_WARNINGS
1261 return !aCurrentShape.IsNull()
1262 ? aCurrentShape->Shape()
1263 : AIS_InteractiveContext_myDummyShape;
1266 //=======================================================================
1267 //function : DetectedCurrentObject
1269 //=======================================================================
1270 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1272 return MoreDetected()
1273 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1274 : Handle(AIS_InteractiveObject)();