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 AIS_NListOfEntityOwner anOwners;
89 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
95 if (!theOwner->IsAutoHilight())
97 SelectMgr_SequenceOfOwner aSeq;
98 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
100 if (aSelIter.Value()->IsSameSelectable (anObj))
102 anOwners.Append (aSelIter.Value());
108 anOwners.Append (theOwner);
110 highlightOwners (anOwners);
113 //=======================================================================
114 //function : highlightGlobal
116 //=======================================================================
117 void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
118 const Handle(Prs3d_Drawer)& theStyle,
119 const Standard_Integer theDispMode)
126 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
127 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
129 if (aGlobOwner.IsNull())
131 myMainPM->Color (theObj, theStyle, aHiMode);
135 AIS_NListOfEntityOwner anOwners;
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 anOwners.Append (aSelIter.Value());
149 anOwners.Append (aGlobOwner);
151 highlightOwners (anOwners);
154 //=======================================================================
155 //function : unhighlightSelected
157 //=======================================================================
158 void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
160 unhighlightOwners (mySelection->Objects(), theIsToHilightSubIntensity);
163 //=======================================================================
164 //function : unhighlightOwners
166 //=======================================================================
167 void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& theOwners,
168 const Standard_Boolean theIsToHilightSubIntensity)
170 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
171 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
173 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
174 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
175 Handle(AIS_GlobalStatus) aStatus;
176 if (!myObjects.Find (anInteractive, aStatus))
181 if (anOwner->IsAutoHilight())
183 anOwner->Unhilight (myMainPM);
184 if (theIsToHilightSubIntensity)
186 if (aStatus->IsSubIntensityOn())
188 const Standard_Integer aHiMode = getHilightMode (anInteractive, aStatus->HilightStyle(), aStatus->DisplayMode());
189 highlightWithSubintensity (anOwner, aHiMode);
195 anObjToClear.Add (anInteractive);
197 if (anOwner == anInteractive->GlobalSelOwner())
199 aStatus->SetHilightStatus (Standard_False);
202 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
204 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
205 myMainPM->Unhighlight (anObj);
206 anObj->ClearSelected();
210 //=======================================================================
211 //function : unhighlightGlobal
213 //=======================================================================
214 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj)
221 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
222 if (aGlobOwner.IsNull())
224 myMainPM->Unhighlight (theObj);
228 AIS_NListOfEntityOwner anOwners;
229 anOwners.Append (aGlobOwner);
230 unhighlightOwners (anOwners);
233 //=======================================================================
234 //function : turnOnSubintensity
236 //=======================================================================
237 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
238 const Standard_Integer theDispMode,
239 const Standard_Boolean theIsDisplayedOnly) const
241 // the only differ with selection highlight is color, so sync transparency values
242 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
243 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
245 if (theObject.IsNull())
247 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
249 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
250 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
253 aStatus->SubIntensityOn();
254 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
259 Handle(AIS_GlobalStatus) aStatus;
260 if (!myObjects.Find (theObject, aStatus))
263 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
266 aStatus->SubIntensityOn();
267 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
271 //=======================================================================
272 //function : highlightWithSubintensity
274 //=======================================================================
275 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
276 const Standard_Integer theMode) const
278 // the only differ with selection highlight is color, so
279 // sync transparency values
280 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
282 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
285 //=======================================================================
286 //function : highlightWithSubintensity
288 //=======================================================================
289 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
290 const Standard_Integer theMode) const
292 // the only differ with selection highlight is color, so
293 // sync transparency values
294 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
296 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
299 //=======================================================================
300 //function : isSlowHiStyle
302 //=======================================================================
303 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
304 const Handle(V3d_Viewer)& theViewer) const
306 if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
308 const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
309 return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
310 || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
312 return Standard_False;
315 //=======================================================================
318 //=======================================================================
319 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
320 const Standard_Integer theYPix,
321 const Handle(V3d_View)& theView,
322 const Standard_Boolean theToRedrawOnUpdate)
324 if (theView->Viewer() != myMainVwr)
326 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
330 myCurHighlighted = 0;
331 myDetectedSeq.Clear();
332 myLastActiveView = theView.get();
335 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
336 Standard_Boolean toUpdateViewer = Standard_False;
338 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
339 myMainSel->Pick (theXPix, theYPix, theView);
341 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
342 // (the objects must be AIS_Shapes)
343 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
344 Standard_Integer aNewDetected = 0;
345 Standard_Boolean toIgnoreDetTop = Standard_False;
346 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
348 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
350 || !myFilters->IsOk (anOwner))
352 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
354 toIgnoreDetTop = Standard_True;
362 aNewDetected = aDetIter;
365 myDetectedSeq.Append (aDetIter);
368 if (aNewDetected >= 1)
370 myCurHighlighted = myDetectedSeq.Lower();
372 // Does nothing if previously detected object is equal to the current one.
373 // However in advanced selection modes the owners comparison
374 // is not effective because in that case only one owner manage the
375 // selection in current selection mode. It is necessary to check the current detected
376 // entity and hilight it only if the detected entity is not the same as
377 // previous detected (IsForcedHilight call)
378 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
379 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
381 return myLastPicked->IsSelected()
383 : AIS_SOD_OnlyOneDetected;
386 // Previously detected object is unhilighted if it is not selected or hilighted
387 // with selection color if it is selected. Such highlighting with selection color
388 // is needed only if myToHilightSelected flag is true. In this case previously detected
389 // object has been already highlighted with myHilightColor during previous MoveTo()
390 // method call. As result it is necessary to rehighligt it with mySelectionColor.
391 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
393 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
395 theView->Viewer()->Invalidate();
398 clearDynamicHighlight();
399 toUpdateViewer = Standard_True;
402 // initialize myLastPicked field with currently detected object
403 myLastPicked = aNewPickedOwner;
405 // highlight detected object if it is not selected or myToHilightSelected flag is true
406 if (myLastPicked->HasSelectable())
409 && (!myLastPicked->IsSelected()
410 || myToHilightSelected))
412 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
414 theView->Viewer()->Invalidate();
417 highlightWithColor (myLastPicked, theView->Viewer());
418 toUpdateViewer = Standard_True;
421 aStatus = myLastPicked->IsSelected()
423 : AIS_SOD_OnlyOneDetected;
428 // previously detected object is unhilighted if it is not selected or hilighted
429 // with selection color if it is selected
430 aStatus = AIS_SOD_Nothing;
432 && !myLastPicked.IsNull()
433 && myLastPicked->HasSelectable())
435 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
437 theView->Viewer()->Invalidate();
440 clearDynamicHighlight();
441 toUpdateViewer = Standard_True;
444 myLastPicked.Nullify();
448 && theToRedrawOnUpdate)
450 if (theView->ComputedMode())
452 theView->Viewer()->Update();
456 if (theView->IsInvalidated())
458 theView->Viewer()->Redraw();
462 theView->Viewer()->RedrawImmediate();
470 //=======================================================================
471 //function : AddSelect
473 //=======================================================================
474 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
476 mySelection->AddSelect (theObject);
478 Standard_Integer aSelNum = NbSelected();
479 return (aSelNum == 0) ? AIS_SOP_NothingSelected
480 : (aSelNum == 1) ? AIS_SOP_OneSelected
481 : AIS_SOP_SeveralSelected;
484 //=======================================================================
487 //=======================================================================
488 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
489 const Standard_Integer theYPMin,
490 const Standard_Integer theXPMax,
491 const Standard_Integer theYPMax,
492 const Handle(V3d_View)& theView,
493 const Standard_Boolean toUpdateViewer)
495 if (theView->Viewer() != myMainVwr)
497 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
500 // all objects detected by the selector are taken, previous current objects are emptied,
501 // new objects are put...
502 ClearSelected (Standard_False);
503 myLastActiveView = theView.get();
504 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
505 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
507 const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter);
508 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
511 mySelection->Select (aCurOwner);
516 HilightSelected (toUpdateViewer);
519 Standard_Integer aSelNum = NbSelected();
521 return (aSelNum == 0) ? AIS_SOP_NothingSelected
522 : (aSelNum == 1) ? AIS_SOP_OneSelected
523 : AIS_SOP_SeveralSelected;
527 //=======================================================================
529 //purpose : Selection by polyline
530 //=======================================================================
531 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
532 const Handle(V3d_View)& theView,
533 const Standard_Boolean toUpdateViewer)
535 if (theView->Viewer() != myMainVwr)
537 throw Standard_ProgramError ("AIS_InteractiveContext::Select() - invalid argument");
540 // all objects detected by the selector are taken, previous current objects are emptied,
541 // new objects are put...
542 ClearSelected (Standard_False);
543 myLastActiveView = theView.get();
544 myMainSel->Pick (thePolyline, theView);
545 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
547 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
548 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
551 mySelection->Select (anOwner);
556 HilightSelected (toUpdateViewer);
559 Standard_Integer aSelNum = NbSelected();
561 return (aSelNum == 0) ? AIS_SOP_NothingSelected
562 : (aSelNum == 1) ? AIS_SOP_OneSelected
563 : AIS_SOP_SeveralSelected;
567 //=======================================================================
570 //=======================================================================
571 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
573 if (!myLastPicked.IsNull())
575 Graphic3d_Vec2i aMousePos (-1, -1);
576 if (myMainSel->GetManager().GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Point)
578 aMousePos.SetValues ((Standard_Integer )myMainSel->GetManager().GetMousePosition().X(),
579 (Standard_Integer )myMainSel->GetManager().GetMousePosition().Y());
581 if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
583 return AIS_SOP_NothingSelected;
588 clearDynamicHighlight();
590 if (!myLastPicked->IsSelected()
591 || myLastPicked->IsForcedHilight()
594 SetSelected (myLastPicked, Standard_False);
597 UpdateCurrentViewer();
603 ClearSelected (toUpdateViewer);
606 Standard_Integer aSelNum = NbSelected();
608 return (aSelNum == 0) ? AIS_SOP_NothingSelected
609 : (aSelNum == 1) ? AIS_SOP_OneSelected
610 : AIS_SOP_SeveralSelected;
613 //=======================================================================
614 //function : ShiftSelect
616 //=======================================================================
617 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
621 clearDynamicHighlight();
623 if (!myLastPicked.IsNull())
625 AddOrRemoveSelected (myLastPicked, toUpdateViewer);
628 Standard_Integer aSelNum = NbSelected();
630 return (aSelNum == 0) ? AIS_SOP_NothingSelected
631 : (aSelNum == 1) ? AIS_SOP_OneSelected
632 : AIS_SOP_SeveralSelected;
635 //=======================================================================
636 //function : ShiftSelect
638 //=======================================================================
639 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
640 const Standard_Integer theYPMin,
641 const Standard_Integer theXPMax,
642 const Standard_Integer theYPMax,
643 const Handle(V3d_View)& theView,
644 const Standard_Boolean toUpdateViewer)
646 if (theView->Viewer() != myMainVwr)
648 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
651 myLastActiveView = theView.get();
654 UnhilightSelected (Standard_False);
656 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
657 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
659 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
660 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
663 mySelection->Select (anOwner);
668 HilightSelected (toUpdateViewer);
671 Standard_Integer aSelNum = NbSelected();
673 return (aSelNum == 0) ? AIS_SOP_NothingSelected
674 : (aSelNum == 1) ? AIS_SOP_OneSelected
675 : AIS_SOP_SeveralSelected;
679 //=======================================================================
680 //function : ShiftSelect
682 //=======================================================================
683 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
684 const Handle(V3d_View)& theView,
685 const Standard_Boolean toUpdateViewer)
687 if (theView->Viewer() != myMainVwr)
689 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
692 myLastActiveView = theView.get();
695 UnhilightSelected (Standard_False);
697 myMainSel->Pick (thePolyline, theView);
698 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
700 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
701 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
704 mySelection->Select (anOwner);
709 HilightSelected (toUpdateViewer);
712 Standard_Integer aSelNum = NbSelected();
714 return (aSelNum == 0) ? AIS_SOP_NothingSelected
715 : (aSelNum == 1) ? AIS_SOP_OneSelected
716 : AIS_SOP_SeveralSelected;
719 //=======================================================================
720 //function : HilightSelected
722 //=======================================================================
723 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
725 // In case of selection without using local context
726 clearDynamicHighlight();
728 highlightOwners (mySelection->Objects());
730 if (theToUpdateViewer)
731 UpdateCurrentViewer();
734 //=======================================================================
735 //function : highlightOwners
737 //=======================================================================
738 void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners)
740 AIS_MapOfObjSelectedOwners anObjOwnerMap;
741 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
743 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
744 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
748 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
749 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
750 if (anOwner == anObj->GlobalSelOwner())
752 aState->SetHilightStatus (Standard_True);
753 aState->SetHilightStyle (anObjSelStyle);
755 if (!anOwner->IsAutoHilight())
757 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
758 if (anObjOwnerMap.Find (anObj, aSeq))
760 aSeq->Append (anOwner);
764 aSeq = new SelectMgr_SequenceOfOwner();
765 aSeq->Append (anOwner);
766 anObjOwnerMap.Bind (anObj, aSeq);
771 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
772 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
776 if (!anObjOwnerMap.IsEmpty())
778 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
780 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
782 anObjOwnerMap.Clear();
786 //=======================================================================
787 //function : UnhilightSelected
789 //=======================================================================
790 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
792 unhighlightSelected();
794 if (theToUpdateViewer)
795 UpdateCurrentViewer();
799 //=======================================================================
800 //function : ClearSelected
802 //=======================================================================
803 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
805 if (NbSelected() == 0)
810 unhighlightSelected();
813 mySelection->Clear();
816 clearDynamicHighlight();
819 if (theToUpdateViewer)
820 UpdateCurrentViewer();
823 //=======================================================================
824 //function : SetSelected
825 //purpose : Sets the whole object as selected and highlights it with selection color
826 //=======================================================================
827 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
828 const Standard_Boolean theToUpdateViewer)
830 if (theObject.IsNull())
835 if (!myObjects.IsBound (theObject))
840 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
841 if (anOwner.IsNull())
846 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
847 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
849 Handle(Prs3d_Drawer) aCustomStyle;
850 if (HighlightStyle (theObject, aCustomStyle))
852 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
854 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
860 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
862 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
863 if (!myFilters->IsOk (aSelOwner))
868 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
871 Unhilight (aSelectable, Standard_False);
873 if (aSelOwner == aSelectable->GlobalSelOwner())
875 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
879 // added to avoid untimely viewer update...
880 mySelection->ClearAndSelect (anOwner);
884 Handle(Prs3d_Drawer) aCustomStyle;
885 if (HighlightStyle (theObject, aCustomStyle))
887 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
889 HilightWithColor (theObject, anObjSelStyle, Standard_False);
894 HilightWithColor (theObject, anObjSelStyle, Standard_False);
898 if (theToUpdateViewer)
899 UpdateCurrentViewer();
902 //=======================================================================
903 //function : SetSelected
904 //purpose : Sets the whole object as selected and highlights it with selection color
905 //=======================================================================
906 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
907 const Standard_Boolean theToUpdateViewer)
909 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
912 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
913 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
914 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
916 Handle(Prs3d_Drawer) aCustomStyle;
917 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
919 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
921 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
922 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
928 if (!myObjects.IsBound (anObject))
933 unhighlightSelected();
936 mySelection->ClearAndSelect (theOwner);
939 Handle(Prs3d_Drawer) aCustomStyle;
940 if (!HighlightStyle (theOwner, aCustomStyle) ||
941 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
943 highlightSelected (theOwner);
947 if (theToUpdateViewer)
948 UpdateCurrentViewer();
951 //=======================================================================
952 //function : AddOrRemoveSelected
953 //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
954 // Since this method makes sence only for neutral point selection of a whole object,
955 // if 0 selection of the object is empty this method simply does nothing.
956 //=======================================================================
957 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
958 const Standard_Boolean theToUpdateViewer)
960 if (theObject.IsNull()
961 || !myObjects.IsBound (theObject))
966 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
967 if (!anOwner.IsNull()
968 && anOwner->HasSelectable())
970 AddOrRemoveSelected (anOwner, theToUpdateViewer);
974 //=======================================================================
975 //function : AddOrRemoveSelected
976 //purpose : Allows to highlight or unhighlight the owner given depending on
977 // its selection status
978 //=======================================================================
979 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
980 const Standard_Boolean theToUpdateViewer)
982 if (theOwner.IsNull() || !theOwner->HasSelectable())
985 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
988 mySelection->Select (theOwner);
992 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
993 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
994 if (theOwner->IsSelected())
996 highlightSelected (theOwner);
1000 AIS_NListOfEntityOwner anOwners;
1001 anOwners.Append (theOwner);
1002 unhighlightOwners (anOwners);
1004 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
1008 if (theToUpdateViewer)
1009 UpdateCurrentViewer();
1012 // =======================================================================
1013 // function : SetSelectedState
1015 // =======================================================================
1016 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
1017 const Standard_Boolean theIsSelected)
1019 if (theEntity.IsNull())
1021 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
1024 if (!theEntity->HasSelectable()
1025 || mySelection->IsSelected (theEntity) == theIsSelected)
1030 if (theEntity->IsAutoHilight())
1032 AddOrRemoveSelected (theEntity, false);
1038 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
1039 theEntity->SetSelected (true);
1040 return aSelStatus == AIS_SS_Added;
1044 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
1045 theEntity->SetSelected (false);
1046 return aSelStatus == AIS_SS_Removed;
1050 //=======================================================================
1051 //function : IsSelected
1053 //=======================================================================
1054 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
1056 if (theObj.IsNull())
1058 return Standard_False;
1061 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1062 if (aStatus == NULL)
1064 return Standard_False;
1067 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1068 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
1069 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1071 if (aModeIter.Value() == aGlobalSelMode)
1073 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1075 return aGlobOwner->IsSelected();
1077 return Standard_False;
1080 return Standard_False;
1083 //=======================================================================
1084 //function : FirstSelectedObject
1086 //=======================================================================
1087 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
1089 return !mySelection->Objects().IsEmpty()
1090 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1091 : Handle(AIS_InteractiveObject)();
1094 //=======================================================================
1095 //function : HasSelectedShape
1097 //=======================================================================
1098 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1100 if (!mySelection->More())
1101 return Standard_False;
1103 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1104 return !anOwner.IsNull() && anOwner->HasShape();
1107 //=======================================================================
1108 //function : SelectedShape
1110 //=======================================================================
1111 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1113 if (!mySelection->More())
1114 return TopoDS_Shape();
1116 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1117 if (anOwner.IsNull() || !anOwner->HasSelectable())
1118 return TopoDS_Shape();
1120 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
1123 //=======================================================================
1124 //function : EntityOwners
1126 //=======================================================================
1127 void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
1128 const Handle(AIS_InteractiveObject)& theIObj,
1129 const Standard_Integer theMode) const
1131 if (theIObj.IsNull())
1136 TColStd_ListOfInteger aModes;
1139 ActivatedModes (theIObj, aModes);
1143 aModes.Append (theMode);
1146 if (theOwners.IsNull())
1148 theOwners = new SelectMgr_IndexedMapOfOwner();
1151 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
1153 const int aMode = anItr.Value();
1154 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1160 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
1162 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1164 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
1166 theOwners->Add (aOwner);
1173 //=======================================================================
1174 //function : HasDetectedShape
1176 //=======================================================================
1177 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1179 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1180 return !anOwner.IsNull()
1181 && anOwner->HasShape();
1184 //=======================================================================
1185 //function : DetectedShape
1187 //=======================================================================
1188 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
1190 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1191 return anOwner->Shape();
1194 //=======================================================================
1195 //function : HilightNextDetected
1197 //=======================================================================
1198 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1199 const Standard_Boolean theToRedrawImmediate)
1201 myMainPM->ClearImmediateDraw();
1202 if (myDetectedSeq.IsEmpty())
1207 if (++myCurHighlighted > myDetectedSeq.Upper())
1209 myCurHighlighted = myDetectedSeq.Lower();
1211 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1212 if (anOwner.IsNull())
1217 highlightWithColor (anOwner, theView->Viewer());
1218 myLastPicked = anOwner;
1220 if (theToRedrawImmediate)
1222 myMainPM->RedrawImmediate (theView->Viewer());
1223 myMainVwr->RedrawImmediate();
1226 return myCurHighlighted;
1229 //=======================================================================
1230 //function : HilightPreviousDetected
1232 //=======================================================================
1233 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1234 const Standard_Boolean theToRedrawImmediate)
1236 myMainPM->ClearImmediateDraw();
1237 if (myDetectedSeq.IsEmpty())
1242 if (--myCurHighlighted < myDetectedSeq.Lower())
1244 myCurHighlighted = myDetectedSeq.Upper();
1246 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1247 if (anOwner.IsNull())
1252 highlightWithColor (anOwner, theView->Viewer());
1253 myLastPicked = anOwner;
1255 if (theToRedrawImmediate)
1257 myMainPM->RedrawImmediate (theView->Viewer());
1258 myMainVwr->RedrawImmediate();
1261 return myCurHighlighted;
1264 //=======================================================================
1265 //function : DetectedCurrentOwner
1267 //=======================================================================
1268 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1270 return MoreDetected()
1271 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1272 : Handle(SelectMgr_EntityOwner)();
1275 //=======================================================================
1276 //function : DetectedCurrentShape
1278 //=======================================================================
1279 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1281 Standard_DISABLE_DEPRECATION_WARNINGS
1282 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1283 Standard_ENABLE_DEPRECATION_WARNINGS
1284 return !aCurrentShape.IsNull()
1285 ? aCurrentShape->Shape()
1286 : AIS_InteractiveContext_myDummyShape;
1289 //=======================================================================
1290 //function : DetectedCurrentObject
1292 //=======================================================================
1293 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1295 return MoreDetected()
1296 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1297 : Handle(AIS_InteractiveObject)();