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)* aStatusPtr = myObjects.ChangeSeek (anInteractive);
181 if (anOwner->IsAutoHilight())
183 anOwner->Unhilight (myMainPM);
184 if (theIsToHilightSubIntensity)
186 if ((*aStatusPtr)->IsSubIntensityOn())
188 const Standard_Integer aHiMode = getHilightMode (anInteractive, (*aStatusPtr)->HilightStyle(), (*aStatusPtr)->DisplayMode());
189 highlightWithSubintensity (anOwner, aHiMode);
195 anObjToClear.Add (anInteractive);
197 if (anOwner == anInteractive->GlobalSelOwner())
199 (*aStatusPtr)->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)* aStatusPtr = myObjects.ChangeSeek (anObj);
754 if (anOwner == anObj->GlobalSelOwner())
756 (*aStatusPtr)->SetHilightStatus (Standard_True);
757 (*aStatusPtr)->SetHilightStyle (anObjSelStyle);
759 if (!anOwner->IsAutoHilight())
761 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
762 if (anObjOwnerMap.Find (anObj, aSeq))
764 aSeq->Append (anOwner);
768 aSeq = new SelectMgr_SequenceOfOwner();
769 aSeq->Append (anOwner);
770 anObjOwnerMap.Bind (anObj, aSeq);
775 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, (*aStatusPtr)->DisplayMode());
776 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
780 if (!anObjOwnerMap.IsEmpty())
782 for (AIS_MapOfObjSelectedOwners::Iterator anIter (anObjOwnerMap); anIter.More(); anIter.Next())
784 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
786 anObjOwnerMap.Clear();
790 //=======================================================================
791 //function : UnhilightSelected
793 //=======================================================================
794 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
796 unhighlightSelected();
798 if (theToUpdateViewer)
799 UpdateCurrentViewer();
803 //=======================================================================
804 //function : ClearSelected
806 //=======================================================================
807 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
809 if (NbSelected() == 0)
814 unhighlightSelected();
817 mySelection->Clear();
820 clearDynamicHighlight();
823 if (theToUpdateViewer)
824 UpdateCurrentViewer();
827 //=======================================================================
828 //function : SetSelected
829 //purpose : Sets the whole object as selected and highlights it with selection color
830 //=======================================================================
831 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
832 const Standard_Boolean theToUpdateViewer)
834 if (theObject.IsNull())
839 if (!myObjects.IsBound (theObject))
844 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
845 if (anOwner.IsNull())
850 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
851 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
853 Handle(Prs3d_Drawer) aCustomStyle;
854 if (HighlightStyle (theObject, aCustomStyle))
856 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
858 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
864 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
866 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
867 if (!myFilters->IsOk (aSelOwner))
872 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
875 Unhilight (aSelectable, Standard_False);
877 if (aSelOwner == aSelectable->GlobalSelOwner())
879 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (aSelectable))
881 (*aStatusPtr)->SetHilightStatus (Standard_False);
886 // added to avoid untimely viewer update...
887 mySelection->ClearAndSelect (anOwner);
891 Handle(Prs3d_Drawer) aCustomStyle;
892 if (HighlightStyle (theObject, aCustomStyle))
894 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
896 HilightWithColor (theObject, anObjSelStyle, Standard_False);
901 HilightWithColor (theObject, anObjSelStyle, Standard_False);
905 if (theToUpdateViewer)
906 UpdateCurrentViewer();
909 //=======================================================================
910 //function : SetSelected
911 //purpose : Sets the whole object as selected and highlights it with selection color
912 //=======================================================================
913 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
914 const Standard_Boolean theToUpdateViewer)
916 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
919 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
920 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
921 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
923 Handle(Prs3d_Drawer) aCustomStyle;
924 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
926 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
928 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
929 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
935 if (!myObjects.IsBound (anObject))
940 unhighlightSelected();
943 mySelection->ClearAndSelect (theOwner);
946 Handle(Prs3d_Drawer) aCustomStyle;
947 if (!HighlightStyle (theOwner, aCustomStyle) ||
948 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
950 highlightSelected (theOwner);
954 if (theToUpdateViewer)
955 UpdateCurrentViewer();
958 //=======================================================================
959 //function : AddOrRemoveSelected
960 //purpose : Adds or removes current object from AIS selection and highlights/unhighlights it.
961 // Since this method makes sence only for neutral point selection of a whole object,
962 // if 0 selection of the object is empty this method simply does nothing.
963 //=======================================================================
964 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
965 const Standard_Boolean theToUpdateViewer)
967 if (theObject.IsNull()
968 || !myObjects.IsBound (theObject))
973 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
974 if (!anOwner.IsNull()
975 && anOwner->HasSelectable())
977 AddOrRemoveSelected (anOwner, theToUpdateViewer);
981 //=======================================================================
982 //function : AddOrRemoveSelected
983 //purpose : Allows to highlight or unhighlight the owner given depending on
984 // its selection status
985 //=======================================================================
986 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
987 const Standard_Boolean theToUpdateViewer)
989 if (theOwner.IsNull() || !theOwner->HasSelectable())
992 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
995 mySelection->Select (theOwner);
999 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1000 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
1006 if (theOwner->IsSelected())
1008 highlightSelected (theOwner);
1012 AIS_NListOfEntityOwner anOwners;
1013 anOwners.Append (theOwner);
1014 unhighlightOwners (anOwners);
1016 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
1020 if (theToUpdateViewer)
1021 UpdateCurrentViewer();
1024 // =======================================================================
1025 // function : SetSelectedState
1027 // =======================================================================
1028 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
1029 const Standard_Boolean theIsSelected)
1031 if (theEntity.IsNull())
1033 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
1036 if (!theEntity->HasSelectable()
1037 || mySelection->IsSelected (theEntity) == theIsSelected)
1042 if (theEntity->IsAutoHilight())
1044 AddOrRemoveSelected (theEntity, false);
1050 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
1051 theEntity->SetSelected (true);
1052 return aSelStatus == AIS_SS_Added;
1056 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
1057 theEntity->SetSelected (false);
1058 return aSelStatus == AIS_SS_Removed;
1062 //=======================================================================
1063 //function : IsSelected
1065 //=======================================================================
1066 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
1068 if (theObj.IsNull())
1070 return Standard_False;
1073 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
1074 if (aStatus == NULL)
1076 return Standard_False;
1079 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
1080 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
1081 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
1083 if (aModeIter.Value() == aGlobalSelMode)
1085 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
1087 return aGlobOwner->IsSelected();
1089 return Standard_False;
1092 return Standard_False;
1095 //=======================================================================
1096 //function : FirstSelectedObject
1098 //=======================================================================
1099 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
1101 return !mySelection->Objects().IsEmpty()
1102 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
1103 : Handle(AIS_InteractiveObject)();
1106 //=======================================================================
1107 //function : HasSelectedShape
1109 //=======================================================================
1110 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
1112 if (!mySelection->More())
1113 return Standard_False;
1115 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1116 return !anOwner.IsNull() && anOwner->HasShape();
1119 //=======================================================================
1120 //function : SelectedShape
1122 //=======================================================================
1123 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
1125 if (!mySelection->More())
1126 return TopoDS_Shape();
1128 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
1129 if (anOwner.IsNull() || !anOwner->HasSelectable())
1130 return TopoDS_Shape();
1132 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
1135 //=======================================================================
1136 //function : EntityOwners
1138 //=======================================================================
1139 void AIS_InteractiveContext::EntityOwners(Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
1140 const Handle(AIS_InteractiveObject)& theIObj,
1141 const Standard_Integer theMode) const
1143 if (theIObj.IsNull())
1148 TColStd_ListOfInteger aModes;
1151 ActivatedModes (theIObj, aModes);
1155 aModes.Append (theMode);
1158 if (theOwners.IsNull())
1160 theOwners = new SelectMgr_IndexedMapOfOwner();
1163 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
1165 const int aMode = anItr.Value();
1166 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
1172 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
1174 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
1176 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
1178 theOwners->Add (aOwner);
1185 //=======================================================================
1186 //function : HasDetectedShape
1188 //=======================================================================
1189 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
1191 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1192 return !anOwner.IsNull()
1193 && anOwner->HasShape();
1196 //=======================================================================
1197 //function : DetectedShape
1199 //=======================================================================
1200 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
1202 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
1203 return anOwner->Shape();
1206 //=======================================================================
1207 //function : HilightNextDetected
1209 //=======================================================================
1210 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1211 const Standard_Boolean theToRedrawImmediate)
1213 myMainPM->ClearImmediateDraw();
1214 if (myDetectedSeq.IsEmpty())
1219 if (++myCurHighlighted > myDetectedSeq.Upper())
1221 myCurHighlighted = myDetectedSeq.Lower();
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 : HilightPreviousDetected
1244 //=======================================================================
1245 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1246 const Standard_Boolean theToRedrawImmediate)
1248 myMainPM->ClearImmediateDraw();
1249 if (myDetectedSeq.IsEmpty())
1254 if (--myCurHighlighted < myDetectedSeq.Lower())
1256 myCurHighlighted = myDetectedSeq.Upper();
1258 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
1259 if (anOwner.IsNull())
1264 highlightWithColor (anOwner, theView->Viewer());
1265 myLastPicked = anOwner;
1267 if (theToRedrawImmediate)
1269 myMainPM->RedrawImmediate (theView->Viewer());
1270 myMainVwr->RedrawImmediate();
1273 return myCurHighlighted;
1276 //=======================================================================
1277 //function : DetectedCurrentOwner
1279 //=======================================================================
1280 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
1282 return MoreDetected()
1283 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
1284 : Handle(SelectMgr_EntityOwner)();
1287 //=======================================================================
1288 //function : DetectedCurrentShape
1290 //=======================================================================
1291 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1293 Standard_DISABLE_DEPRECATION_WARNINGS
1294 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1295 Standard_ENABLE_DEPRECATION_WARNINGS
1296 return !aCurrentShape.IsNull()
1297 ? aCurrentShape->Shape()
1298 : AIS_InteractiveContext_myDummyShape;
1301 //=======================================================================
1302 //function : DetectedCurrentObject
1304 //=======================================================================
1305 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1307 return MoreDetected()
1308 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
1309 : Handle(AIS_InteractiveObject)();