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 if (anOwner == anInteractive->GlobalSelOwner())
189 myObjects.ChangeFind (anInteractive)->SetHilightStatus (Standard_False);
192 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
194 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
195 myMainPM->Unhighlight (anObj);
196 anObj->ClearSelected();
200 //=======================================================================
201 //function : unhighlightGlobal
203 //=======================================================================
204 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj) const
211 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
212 if (aGlobOwner.IsNull())
214 myMainPM->Unhighlight (theObj);
218 if (aGlobOwner->IsAutoHilight())
220 aGlobOwner->Unhilight (myMainPM);
224 myMainPM->Unhighlight (theObj);
225 theObj->ClearSelected();
229 //=======================================================================
230 //function : turnOnSubintensity
232 //=======================================================================
233 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
234 const Standard_Integer theDispMode,
235 const Standard_Boolean theIsDisplayedOnly) const
237 // the only differ with selection highlight is color, so sync transparency values
238 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
239 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
241 if (theObject.IsNull())
243 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
245 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
246 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
249 aStatus->SubIntensityOn();
250 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
255 Handle(AIS_GlobalStatus) aStatus;
256 if (!myObjects.Find (theObject, aStatus))
259 if (aStatus->GraphicStatus() != AIS_DS_Displayed && theIsDisplayedOnly)
262 aStatus->SubIntensityOn();
263 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
267 //=======================================================================
268 //function : highlightWithSubintensity
270 //=======================================================================
271 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
272 const Standard_Integer theMode) const
274 // the only differ with selection highlight is color, so
275 // sync transparency values
276 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
278 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
281 //=======================================================================
282 //function : highlightWithSubintensity
284 //=======================================================================
285 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
286 const Standard_Integer theMode) const
288 // the only differ with selection highlight is color, so
289 // sync transparency values
290 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
292 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
295 //=======================================================================
296 //function : isSlowHiStyle
298 //=======================================================================
299 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
300 const Handle(V3d_Viewer)& theViewer) const
302 if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
304 const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
305 return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
306 || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
308 return Standard_False;
311 //=======================================================================
314 //=======================================================================
315 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
316 const Standard_Integer theYPix,
317 const Handle(V3d_View)& theView,
318 const Standard_Boolean theToRedrawOnUpdate)
320 if (theView->Viewer() != myMainVwr)
322 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
326 myCurHighlighted = 0;
327 myDetectedSeq.Clear();
328 myLastActiveView = theView.get();
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 myLastActiveView = theView.get();
500 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
501 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
503 const Handle(SelectMgr_EntityOwner)& aCurOwner = myMainSel->Picked (aPickIter);
504 if (aCurOwner.IsNull() || !aCurOwner->HasSelectable() || !myFilters->IsOk (aCurOwner))
507 mySelection->Select (aCurOwner);
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 myLastActiveView = theView.get();
540 myMainSel->Pick (thePolyline, theView);
541 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
543 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
544 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
547 mySelection->Select (anOwner);
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())
571 Graphic3d_Vec2i aMousePos (-1, -1);
572 if (myMainSel->GetManager().GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Point)
574 aMousePos.SetValues ((Standard_Integer )myMainSel->GetManager().GetMousePosition().X(),
575 (Standard_Integer )myMainSel->GetManager().GetMousePosition().Y());
577 if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
579 return AIS_SOP_NothingSelected;
584 clearDynamicHighlight();
586 if (!myLastPicked->IsSelected()
587 || myLastPicked->IsForcedHilight()
590 SetSelected (myLastPicked, Standard_False);
593 UpdateCurrentViewer();
599 ClearSelected (toUpdateViewer);
602 Standard_Integer aSelNum = NbSelected();
604 return (aSelNum == 0) ? AIS_SOP_NothingSelected
605 : (aSelNum == 1) ? AIS_SOP_OneSelected
606 : AIS_SOP_SeveralSelected;
609 //=======================================================================
610 //function : ShiftSelect
612 //=======================================================================
613 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
617 clearDynamicHighlight();
619 if (!myLastPicked.IsNull())
621 AddOrRemoveSelected (myLastPicked, toUpdateViewer);
624 Standard_Integer aSelNum = NbSelected();
626 return (aSelNum == 0) ? AIS_SOP_NothingSelected
627 : (aSelNum == 1) ? AIS_SOP_OneSelected
628 : AIS_SOP_SeveralSelected;
631 //=======================================================================
632 //function : ShiftSelect
634 //=======================================================================
635 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
636 const Standard_Integer theYPMin,
637 const Standard_Integer theXPMax,
638 const Standard_Integer theYPMax,
639 const Handle(V3d_View)& theView,
640 const Standard_Boolean toUpdateViewer)
642 if (theView->Viewer() != myMainVwr)
644 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
647 myLastActiveView = theView.get();
650 UnhilightSelected (Standard_False);
652 myMainSel->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
653 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
655 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
656 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
659 mySelection->Select (anOwner);
664 HilightSelected (toUpdateViewer);
667 Standard_Integer aSelNum = NbSelected();
669 return (aSelNum == 0) ? AIS_SOP_NothingSelected
670 : (aSelNum == 1) ? AIS_SOP_OneSelected
671 : AIS_SOP_SeveralSelected;
675 //=======================================================================
676 //function : ShiftSelect
678 //=======================================================================
679 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
680 const Handle(V3d_View)& theView,
681 const Standard_Boolean toUpdateViewer)
683 if (theView->Viewer() != myMainVwr)
685 throw Standard_ProgramError ("AIS_InteractiveContext::ShiftSelect() - invalid argument");
688 myLastActiveView = theView.get();
691 UnhilightSelected (Standard_False);
693 myMainSel->Pick (thePolyline, theView);
694 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
696 const Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aPickIter);
697 if (anOwner.IsNull() || !anOwner->HasSelectable() || !myFilters->IsOk (anOwner))
700 mySelection->Select (anOwner);
705 HilightSelected (toUpdateViewer);
708 Standard_Integer aSelNum = NbSelected();
710 return (aSelNum == 0) ? AIS_SOP_NothingSelected
711 : (aSelNum == 1) ? AIS_SOP_OneSelected
712 : AIS_SOP_SeveralSelected;
715 //=======================================================================
716 //function : HilightSelected
718 //=======================================================================
719 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
721 // In case of selection without using local context
722 clearDynamicHighlight();
723 AIS_MapOfObjSelectedOwners anObjOwnerMap;
724 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
726 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
727 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
728 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObj, anOwner);
729 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind(anObj);
730 if (anOwner == anObj->GlobalSelOwner())
732 aState->SetHilightStatus (Standard_True);
733 aState->SetHilightStyle (anObjSelStyle);
735 if (!anOwner->IsAutoHilight())
737 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
738 if (anObjOwnerMap.Find (anObj, aSeq))
740 aSeq->Append (anOwner);
744 aSeq = new SelectMgr_SequenceOfOwner();
745 aSeq->Append (anOwner);
746 anObjOwnerMap.Bind (anObj, aSeq);
751 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, aState->DisplayMode());
752 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
756 if (!anObjOwnerMap.IsEmpty())
758 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
760 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
762 anObjOwnerMap.Clear();
765 if (theToUpdateViewer)
766 UpdateCurrentViewer();
769 //=======================================================================
770 //function : UnhilightSelected
772 //=======================================================================
773 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
775 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
777 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
778 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
779 if (anOwner == anObj->GlobalSelOwner())
781 myObjects.ChangeFind (anObj)->SetHilightStatus (Standard_False);
784 anOwner->Unhilight (myMainPM);
787 if (theToUpdateViewer)
788 UpdateCurrentViewer();
792 //=======================================================================
793 //function : ClearSelected
795 //=======================================================================
796 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
798 if (NbSelected() == 0)
803 unhighlightSelected();
806 mySelection->Clear();
809 clearDynamicHighlight();
812 if (theToUpdateViewer)
813 UpdateCurrentViewer();
816 //=======================================================================
817 //function : SetSelected
818 //purpose : Sets the whole object as selected and highlights it with selection color
819 //=======================================================================
820 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
821 const Standard_Boolean theToUpdateViewer)
823 if (theObject.IsNull())
828 if (!myObjects.IsBound (theObject))
833 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
834 if (anOwner.IsNull())
839 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
840 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
842 Handle(Prs3d_Drawer) aCustomStyle;
843 if (HighlightStyle (theObject, aCustomStyle))
845 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
847 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
853 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
855 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
856 if (!myFilters->IsOk (aSelOwner))
861 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
864 Unhilight (aSelectable, Standard_False);
866 if (aSelOwner == aSelectable->GlobalSelOwner())
868 myObjects.ChangeFind (aSelectable)->SetHilightStatus (Standard_False);
872 // added to avoid untimely viewer update...
873 mySelection->ClearAndSelect (anOwner);
877 Handle(Prs3d_Drawer) aCustomStyle;
878 if (HighlightStyle (theObject, aCustomStyle))
880 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
882 HilightWithColor (theObject, anObjSelStyle, Standard_False);
887 HilightWithColor (theObject, anObjSelStyle, Standard_False);
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))
926 unhighlightSelected();
929 mySelection->ClearAndSelect (theOwner);
932 Handle(Prs3d_Drawer) aCustomStyle;
933 if (!HighlightStyle (theOwner, aCustomStyle) ||
934 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
936 highlightSelected (theOwner);
940 if (myAutoHilight && theOwner == anObject->GlobalSelOwner())
942 Handle(AIS_GlobalStatus)& aState = myObjects.ChangeFind (anObject);
943 aState->SetHilightStatus (Standard_True);
944 aState->SetHilightStyle (anObjSelStyle);
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 const Standard_Boolean isGlobal = anObj->GlobalSelOwner() == theOwner;
994 Handle(AIS_GlobalStatus)& aStatus = myObjects.ChangeFind (anObj);
995 if (theOwner->IsSelected())
997 highlightSelected (theOwner);
1000 aStatus->SetHilightStatus (Standard_True);
1001 aStatus->SetHilightStyle (getSelStyle (anObj, theOwner));
1006 if (theOwner->IsAutoHilight())
1008 theOwner->Unhilight (myMainPM);
1012 anObj->ClearSelected();
1014 aStatus->SetHilightStatus (Standard_False);
1015 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
1019 if (theToUpdateViewer)
1020 UpdateCurrentViewer();
1023 // =======================================================================
1024 // function : SetSelectedState
1026 // =======================================================================
1027 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
1028 const Standard_Boolean theIsSelected)
1030 if (theEntity.IsNull())
1032 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
1035 if (!theEntity->HasSelectable()
1036 || mySelection->IsSelected (theEntity) == theIsSelected)
1041 if (theEntity->IsAutoHilight())
1043 AddOrRemoveSelected (theEntity, false);
1049 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
1050 theEntity->SetSelected (true);
1051 return aSelStatus == AIS_SS_Added;
1055 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
1056 theEntity->SetSelected (false);
1057 return aSelStatus == AIS_SS_Removed;
1061 //=======================================================================
1062 //function : IsSelected
1064 //=======================================================================
1065 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
1067 if (theObj.IsNull())
1069 return Standard_False;
1072 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1073 if (aStatus == NULL)
1075 return Standard_False;
1078 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1079 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
1080 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1082 if (aModeIter.Value() == aGlobalSelMode)
1084 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1086 return aGlobOwner->IsSelected();
1088 return Standard_False;
1091 return Standard_False;
1094 //=======================================================================
1095 //function : FirstSelectedObject
1097 //=======================================================================
1098 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
1100 return !mySelection->Objects().IsEmpty()
1101 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1102 : Handle(AIS_InteractiveObject)();
1105 //=======================================================================
1106 //function : HasSelectedShape
1108 //=======================================================================
1109 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1111 if (!mySelection->More())
1112 return Standard_False;
1114 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1115 return !anOwner.IsNull() && anOwner->HasShape();
1118 //=======================================================================
1119 //function : SelectedShape
1121 //=======================================================================
1122 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1124 if (!mySelection->More())
1125 return TopoDS_Shape();
1127 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1128 if (anOwner.IsNull() || !anOwner->HasSelectable())
1129 return TopoDS_Shape();
1131 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
1134 //=======================================================================
1135 //function : EntityOwners
1137 //=======================================================================
1138 void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
1139 const Handle(AIS_InteractiveObject)& theIObj,
1140 const Standard_Integer theMode) const
1142 if (theIObj.IsNull())
1147 TColStd_ListOfInteger aModes;
1150 ActivatedModes (theIObj, aModes);
1154 aModes.Append (theMode);
1157 if (theOwners.IsNull())
1159 theOwners = new SelectMgr_IndexedMapOfOwner();
1162 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
1164 const int aMode = anItr.Value();
1165 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1171 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
1173 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1175 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
1177 theOwners->Add (aOwner);
1184 //=======================================================================
1185 //function : HasDetectedShape
1187 //=======================================================================
1188 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1190 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1191 return !anOwner.IsNull()
1192 && anOwner->HasShape();
1195 //=======================================================================
1196 //function : DetectedShape
1198 //=======================================================================
1199 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
1201 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1202 return anOwner->Shape();
1205 //=======================================================================
1206 //function : HilightNextDetected
1208 //=======================================================================
1209 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1210 const Standard_Boolean theToRedrawImmediate)
1212 myMainPM->ClearImmediateDraw();
1213 if (myDetectedSeq.IsEmpty())
1218 if (++myCurHighlighted > myDetectedSeq.Upper())
1220 myCurHighlighted = myDetectedSeq.Lower();
1222 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1223 if (anOwner.IsNull())
1228 highlightWithColor (anOwner, theView->Viewer());
1229 myLastPicked = anOwner;
1231 if (theToRedrawImmediate)
1233 myMainPM->RedrawImmediate (theView->Viewer());
1234 myMainVwr->RedrawImmediate();
1237 return myCurHighlighted;
1240 //=======================================================================
1241 //function : HilightPreviousDetected
1243 //=======================================================================
1244 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1245 const Standard_Boolean theToRedrawImmediate)
1247 myMainPM->ClearImmediateDraw();
1248 if (myDetectedSeq.IsEmpty())
1253 if (--myCurHighlighted < myDetectedSeq.Lower())
1255 myCurHighlighted = myDetectedSeq.Upper();
1257 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1258 if (anOwner.IsNull())
1263 highlightWithColor (anOwner, theView->Viewer());
1264 myLastPicked = anOwner;
1266 if (theToRedrawImmediate)
1268 myMainPM->RedrawImmediate (theView->Viewer());
1269 myMainVwr->RedrawImmediate();
1272 return myCurHighlighted;
1275 //=======================================================================
1276 //function : DetectedCurrentOwner
1278 //=======================================================================
1279 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1281 return MoreDetected()
1282 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1283 : Handle(SelectMgr_EntityOwner)();
1286 //=======================================================================
1287 //function : DetectedCurrentShape
1289 //=======================================================================
1290 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1292 Standard_DISABLE_DEPRECATION_WARNINGS
1293 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1294 Standard_ENABLE_DEPRECATION_WARNINGS
1295 return !aCurrentShape.IsNull()
1296 ? aCurrentShape->Shape()
1297 : AIS_InteractiveContext_myDummyShape;
1300 //=======================================================================
1301 //function : DetectedCurrentObject
1303 //=======================================================================
1304 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1306 return MoreDetected()
1307 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1308 : Handle(AIS_InteractiveObject)();