1 // Created on: 1997-01-17
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.
17 #include <AIS_InteractiveContext.hxx>
19 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
20 #include <AIS_ConnectedInteractive.hxx>
21 #include <AIS_GlobalStatus.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_MultipleConnectedInteractive.hxx>
24 #include <Graphic3d_AspectFillArea3d.hxx>
25 #include <Precision.hxx>
26 #include <Prs3d_BasicAspect.hxx>
27 #include <Prs3d_DatumAspect.hxx>
28 #include <Prs3d_IsoAspect.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_PlaneAspect.hxx>
31 #include <Prs3d_PointAspect.hxx>
32 #include <Prs3d_ShadingAspect.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <SelectMgr_SelectionManager.hxx>
35 #include <TColStd_ListIteratorOfListOfInteger.hxx>
36 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
37 #include <TopLoc_Location.hxx>
38 #include <V3d_View.hxx>
39 #include <V3d_Viewer.hxx>
41 #include <AIS_Shape.hxx>
42 #include <StdSelect_BRepOwner.hxx>
43 #include <TopoDS_Shape.hxx>
45 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
49 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
50 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
52 //! Initialize default highlighting attributes.
53 static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
54 const Quantity_Color& theColor)
56 theDrawer->SetMethod (Aspect_TOHM_COLOR);
57 theDrawer->SetDisplayMode (0);
58 theDrawer->SetColor (theColor);
60 theDrawer->SetupOwnShadingAspect();
61 theDrawer->SetupOwnPointAspect();
62 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
63 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
64 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
65 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
66 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
67 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
68 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
69 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
70 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
71 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
72 theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
74 theDrawer->ShadingAspect()->SetColor (theColor);
75 theDrawer->WireAspect()->SetColor (theColor);
76 theDrawer->LineAspect()->SetColor (theColor);
77 theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
78 theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
79 theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
80 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
81 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
82 theDrawer->PointAspect()->SetColor (theColor);
83 for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_None; ++aPartIter)
85 if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
87 aLineAsp->SetColor (theColor);
91 theDrawer->WireAspect()->SetWidth (2.0);
92 theDrawer->LineAspect()->SetWidth (2.0);
93 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
94 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
95 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
96 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
97 theDrawer->PointAspect()->SetScale (2.0);
99 // the triangulation should be computed using main presentation attributes,
100 // and should not be overridden by highlighting
101 theDrawer->SetAutoTriangulation (Standard_False);
105 //=======================================================================
106 //function : AIS_InteractiveContext
108 //=======================================================================
110 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
111 myMainPM (new PrsMgr_PresentationManager (MainViewer->StructureManager())),
112 myMainVwr(MainViewer),
113 myMainSel(new StdSelect_ViewerSelector3d()),
114 myToHilightSelected(Standard_True),
115 mySelection(new AIS_Selection()),
116 myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)),
117 myDefaultDrawer(new Prs3d_Drawer()),
120 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
121 myAutoHilight(Standard_True),
122 myIsAutoActivateSelMode(Standard_True)
124 mgrSelector = new SelectMgr_SelectionManager (myMainSel);
126 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
127 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
128 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
129 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
130 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
131 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
133 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
134 myDefaultDrawer->SetDisplayMode(0);
136 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
137 aStyle->Link (myDefaultDrawer);
138 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
139 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
142 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
143 aStyle->Link (myDefaultDrawer);
144 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
145 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
148 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
149 aStyle->Link (myDefaultDrawer);
150 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
151 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
154 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
155 aStyle->Link (myDefaultDrawer);
156 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
157 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
160 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
161 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
162 aStyle->SetMethod(Aspect_TOHM_COLOR);
163 aStyle->SetColor (Quantity_NOC_GRAY40);
169 //=======================================================================
170 //function : ~AIS_InteractiveContext
172 //=======================================================================
173 AIS_InteractiveContext::~AIS_InteractiveContext()
175 // clear the current selection
176 mySelection->Clear();
177 mgrSelector.Nullify();
179 Handle(AIS_InteractiveContext) aNullContext;
180 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
182 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
183 anObj->SetContext (aNullContext);
184 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
186 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
191 //=======================================================================
192 //function : LastActiveView
194 //=======================================================================
195 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
197 if (myLastActiveView == NULL
198 || myMainVwr.IsNull())
200 return Handle(V3d_View)();
203 // as a precaution - check that myLastActiveView pointer is a valid active View
204 for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
206 if (aViewIter.Value() == myLastActiveView)
208 return aViewIter.Value();
211 return Handle(V3d_View)();
214 //=======================================================================
215 //function : UpdateCurrentViewer
217 //=======================================================================
219 void AIS_InteractiveContext::UpdateCurrentViewer()
221 if (!myMainVwr.IsNull())
225 //=======================================================================
226 //function : DisplayedObjects
228 //=======================================================================
229 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
231 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
233 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
235 theListOfIO.Append (anObjIter.Key());
240 //=======================================================================
241 //function : DisplayedObjects
243 //=======================================================================
244 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
245 const Standard_Integer theSign,
246 AIS_ListOfInteractive& theListOfIO) const
248 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Displayed, theListOfIO);
251 //=======================================================================
252 //function : ErasedObjects
254 //=======================================================================
255 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
257 ObjectsByDisplayStatus (PrsMgr_DisplayStatus_Erased, theListOfIO);
260 //=======================================================================
261 //function : ErasedObjects
263 //=======================================================================
264 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
265 const Standard_Integer theSign,
266 AIS_ListOfInteractive& theListOfIO) const
268 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Erased, theListOfIO);
271 //=======================================================================
272 //function : ObjectsByDisplayStatus
274 //=======================================================================
275 void AIS_InteractiveContext::ObjectsByDisplayStatus (const PrsMgr_DisplayStatus theStatus,
276 AIS_ListOfInteractive& theListOfIO) const
278 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
280 if (anObjIter.Key()->DisplayStatus() == theStatus)
282 theListOfIO.Append (anObjIter.Key());
287 //=======================================================================
288 //function : ObjectsByDisplayStatus
290 //=======================================================================
291 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
292 const Standard_Integer theSign,
293 const PrsMgr_DisplayStatus theStatus,
294 AIS_ListOfInteractive& theListOfIO) const
296 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
298 if (theStatus != PrsMgr_DisplayStatus_None
299 && anObjIter.Key()->DisplayStatus() != theStatus)
303 else if (anObjIter.Key()->Type() != theKind)
309 || anObjIter.Key()->Signature() == theSign)
311 theListOfIO.Append (anObjIter.Key());
316 //=======================================================================
317 //function : ObjectsInside
319 //=======================================================================
320 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
321 const AIS_KindOfInteractive theKind,
322 const Standard_Integer theSign) const
324 if (theKind == AIS_KindOfInteractive_None
327 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
329 theListOfIO.Append (anObjIter.Key());
334 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
336 if (anObjIter.Key()->Type() != theKind)
342 || anObjIter.Key()->Signature() == theSign)
344 theListOfIO.Append (anObjIter.Key());
349 //=======================================================================
350 //function : ObjectsForView
352 //=======================================================================
353 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
354 const Handle(V3d_View)& theView,
355 const Standard_Boolean theIsVisibleInView,
356 const PrsMgr_DisplayStatus theStatus) const
358 Handle(Graphic3d_CView) aViewImpl = theView->View();
359 const Standard_Integer aViewId = aViewImpl->Identification();
360 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
362 if (theStatus != PrsMgr_DisplayStatus_None
363 && anObjIter.Key()->DisplayStatus() != theStatus)
365 theListOfIO.Append (anObjIter.Key());
369 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
370 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
371 if (isVisible == theIsVisibleInView)
373 theListOfIO.Append (anObjIter.Key());
378 //=======================================================================
381 //=======================================================================
382 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
383 const Standard_Boolean theToUpdateViewer)
385 if (theIObj.IsNull())
390 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
391 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
392 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
395 //=======================================================================
396 //function : SetViewAffinity
398 //=======================================================================
399 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
400 const Handle(V3d_View)& theView,
401 const Standard_Boolean theIsVisible)
404 || !myObjects.IsBound (theIObj))
409 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
410 Handle(Graphic3d_CView) aViewImpl = theView->View();
411 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
414 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
418 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
422 //=======================================================================
425 //=======================================================================
426 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
427 const Standard_Integer theDispMode,
428 const Standard_Integer theSelectionMode,
429 const Standard_Boolean theToUpdateViewer,
430 const PrsMgr_DisplayStatus theDispStatus)
432 if (theIObj.IsNull())
437 if (theDispStatus == PrsMgr_DisplayStatus_Erased)
439 Erase (theIObj, theToUpdateViewer);
440 Load (theIObj, theSelectionMode);
441 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
443 (*aStatusPtr)->SetDisplayMode (theDispMode);
448 setContextToObject (theIObj);
449 if (!myObjects.IsBound (theIObj))
451 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
452 myMainVwr->StructureManager()->RegisterObject (theIObj);
453 myMainPM->Display(theIObj, theDispMode);
454 if (theSelectionMode != -1)
456 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
457 if (!mgrSelector->Contains (anObj))
459 mgrSelector->Load (theIObj);
461 mgrSelector->Activate (theIObj, theSelectionMode);
466 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
468 // Mark the presentation modes hidden of interactive object different from aDispMode.
469 // Then make sure aDispMode is displayed and maybe highlighted.
470 // Finally, activate selection mode <SelMode> if not yet activated.
471 const Standard_Integer anOldMode = aStatus->DisplayMode();
472 if (anOldMode != theDispMode)
474 if(myMainPM->IsHighlighted (theIObj, anOldMode))
476 unhighlightGlobal (theIObj);
478 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
481 aStatus->SetDisplayMode (theDispMode);
483 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Displayed);
484 myMainPM->Display (theIObj, theDispMode);
485 if (aStatus->IsHilighted())
487 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
489 if (theSelectionMode != -1)
491 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
492 if (!mgrSelector->Contains (anObj))
494 mgrSelector->Load (theIObj);
496 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
498 aStatus->AddSelectionMode (theSelectionMode);
499 mgrSelector->Activate (theIObj, theSelectionMode);
504 if (theToUpdateViewer)
510 //=======================================================================
513 //=======================================================================
514 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
515 const Standard_Integer theSelMode)
517 if (theIObj.IsNull())
522 setContextToObject (theIObj);
523 if (!myObjects.IsBound (theIObj))
525 Standard_Integer aDispMode, aHiMod, aSelModeDef;
526 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
527 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
528 myMainVwr->StructureManager()->RegisterObject (theIObj);
531 // Register theIObj in the selection manager to prepare further activation of selection
532 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
533 if (!mgrSelector->Contains (anObj))
535 mgrSelector->Load (theIObj);
539 //=======================================================================
542 //=======================================================================
543 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
544 const Standard_Boolean theToUpdateViewer)
546 if (theIObj.IsNull())
551 if (!theIObj->IsAutoHilight())
553 theIObj->ClearSelected();
556 EraseGlobal (theIObj, Standard_False);
557 if (theToUpdateViewer)
563 //=======================================================================
564 //function : EraseAll
566 //=======================================================================
567 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
569 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
571 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
573 Erase (anObjIter.Key(), Standard_False);
577 if (theToUpdateViewer)
583 //=======================================================================
584 //function : DisplayAll
586 //=======================================================================
587 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
589 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
591 const PrsMgr_DisplayStatus aStatus = anObjIter.Key()->DisplayStatus();
592 if (aStatus == PrsMgr_DisplayStatus_Erased)
594 Display (anObjIter.Key(), Standard_False);
598 if (theToUpdateViewer)
604 //=======================================================================
605 //function : DisplaySelected
607 //=======================================================================
608 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
610 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
612 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
613 Display (anObj, Standard_False);
616 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
622 //=======================================================================
623 //function : EraseSelected
625 //=======================================================================
626 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
628 Standard_Boolean isFound = Standard_False;
629 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
631 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
632 Erase (anObj, Standard_False);
633 isFound = Standard_True;
636 if (isFound && theToUpdateViewer)
642 //=======================================================================
643 //function : DisplayStatus
645 //=======================================================================
646 PrsMgr_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
648 if (theIObj.IsNull())
650 return PrsMgr_DisplayStatus_None;
652 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
653 return aStatus != NULL ? theIObj->DisplayStatus() : PrsMgr_DisplayStatus_None;
656 //=======================================================================
659 //=======================================================================
660 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
661 const Standard_Boolean theToUpdateViewer)
663 if (theIObj.IsNull())
668 if (theIObj->HasInteractiveContext())
670 if (theIObj->myCTXPtr != this)
672 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
674 theIObj->SetContext (Handle(AIS_InteractiveContext)());
676 ClearGlobal (theIObj, theToUpdateViewer);
679 //=======================================================================
680 //function : RemoveAll
682 //=======================================================================
683 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
685 AIS_ListOfInteractive aList;
686 ObjectsInside (aList);
687 for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next())
689 Remove (aListIterator.Value(), Standard_False);
692 if (theToUpdateViewer)
698 //=======================================================================
699 //function : HilightWithColor
701 //=======================================================================
702 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
703 const Handle(Prs3d_Drawer)& theStyle,
704 const Standard_Boolean theIsToUpdate)
709 setContextToObject (theObj);
710 if (!myObjects.IsBound (theObj))
713 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
714 aStatus->SetHilightStatus (Standard_True);
716 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
718 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
719 aStatus->SetHilightStyle (theStyle);
726 //=======================================================================
727 //function : Unhilight
729 //=======================================================================
730 void AIS_InteractiveContext::Unhilight (const Handle(AIS_InteractiveObject)& theObj,
731 const Standard_Boolean theToUpdateViewer)
733 Handle(AIS_GlobalStatus)* aStatus = !theObj.IsNull() ? myObjects.ChangeSeek (theObj) : NULL;
739 (*aStatus)->SetHilightStatus (Standard_False);
740 (*aStatus)->SetHilightStyle (Handle(Prs3d_Drawer)());
741 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
743 unhighlightGlobal (theObj);
746 if (theToUpdateViewer)
752 //=======================================================================
753 //function : IsHilighted
754 //purpose : Returns true if the objects global status is set to highlighted.
755 //=======================================================================
756 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
758 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
759 return aStatus != NULL
760 && (*aStatus)->IsHilighted();
763 //=======================================================================
764 //function : IsHilighted
765 //purpose : Returns true if the owner is highlighted with selection style.
766 //=======================================================================
767 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
769 if (theOwner.IsNull() || !theOwner->HasSelectable())
770 return Standard_False;
772 const Handle(AIS_InteractiveObject) anObj =
773 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
775 if (anObj->GlobalSelOwner() == theOwner)
777 if (!myObjects.IsBound (anObj))
778 return Standard_False;
780 return myObjects (anObj)->IsHilighted();
783 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
784 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
785 return theOwner->IsHilighted (myMainPM, aHiMode);
788 //=======================================================================
789 //function : HighlightStyle
791 //=======================================================================
792 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
793 Handle(Prs3d_Drawer)& theStyle) const
795 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
797 && (*aStatus)->IsHilighted())
799 theStyle = (*aStatus)->HilightStyle();
800 return Standard_True;
804 return Standard_False;
807 //=======================================================================
808 //function : HighlightStyle
810 //=======================================================================
811 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
812 Handle(Prs3d_Drawer)& theStyle) const
814 if (theOwner.IsNull() || !theOwner->HasSelectable())
815 return Standard_False;
817 if (IsHilighted (theOwner))
819 const Handle(AIS_InteractiveObject) anObj =
820 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
821 if (anObj->GlobalSelOwner() == theOwner)
823 theStyle = myObjects (anObj)->HilightStyle();
827 // since part selection style is not stored in global status,
828 // check if the object has own selection style. If not, it can
829 // only be highlighted with default selection style (because
830 // sub-intensity does not modify any selection states)
831 theStyle = getSelStyle (anObj, theOwner);
833 return Standard_True;
838 return Standard_False;
842 //=======================================================================
843 //function : IsDisplayed
845 //=======================================================================
847 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
849 if(theObj.IsNull()) return Standard_False;
851 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
852 return aStatus != NULL
853 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed;
856 //=======================================================================
857 //function : IsDisplayed
859 //=======================================================================
860 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
861 const Standard_Integer theMode) const
863 if (theIObj.IsNull())
865 return Standard_False;
868 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
869 return aStatus != NULL
870 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
871 && (*aStatus)->DisplayMode() == theMode;
874 //=======================================================================
875 //function : DisplayPriority
877 //=======================================================================
878 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
880 if (theIObj.IsNull())
885 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
887 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
888 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
890 Standard_Integer aDispMode = theIObj->HasDisplayMode()
891 ? theIObj->DisplayMode()
892 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
893 ? myDefaultDrawer->DisplayMode()
895 return myMainPM->DisplayPriority (theIObj, aDispMode);
900 //=======================================================================
901 //function : SetDisplayPriority
903 //=======================================================================
904 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
905 const Standard_Integer thePriority)
907 if (theIObj.IsNull())
912 setContextToObject (theIObj);
913 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
915 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
916 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
918 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
919 ? theIObj->DisplayMode()
920 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
921 ? myDefaultDrawer->DisplayMode()
923 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
927 //=======================================================================
928 //function : Redisplay
930 //=======================================================================
931 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
932 const Standard_Boolean theToUpdateViewer,
933 const Standard_Boolean theAllModes)
935 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
936 RecomputeSelectionOnly (theIObj);
939 //=======================================================================
940 //function : Redisplay
942 //=======================================================================
943 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
944 const Standard_Integer /*theSign*/,
945 const Standard_Boolean theToUpdateViewer)
947 Standard_Boolean isRedisplayed = Standard_False;
948 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
950 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
951 if (anObj->Type() != theKOI)
956 Redisplay (anObj, Standard_False);
957 isRedisplayed = anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
961 if (theToUpdateViewer
968 //=======================================================================
969 //function : RecomputePrsOnly
971 //=======================================================================
972 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
973 const Standard_Boolean theToUpdateViewer,
974 const Standard_Boolean theAllModes)
976 if (theIObj.IsNull())
981 theIObj->SetToUpdate();
982 theIObj->UpdatePresentations (theAllModes);
983 if (!theToUpdateViewer)
988 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
990 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
995 //=======================================================================
996 //function : RecomputeSelectionOnly
998 //=======================================================================
999 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1006 mgrSelector->RecomputeSelection (theIO);
1008 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1010 || theIO->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1015 TColStd_ListOfInteger aModes;
1016 ActivatedModes (theIO, aModes);
1017 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1018 for (; aModesIter.More(); aModesIter.Next())
1020 mgrSelector->Activate (theIO, aModesIter.Value());
1024 //=======================================================================
1027 //=======================================================================
1028 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1029 const Standard_Boolean theUpdateViewer)
1031 if (theIObj.IsNull())
1036 theIObj->UpdatePresentations();
1037 mgrSelector->Update(theIObj);
1039 if (theUpdateViewer)
1041 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1043 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1045 myMainVwr->Update();
1050 //=======================================================================
1051 //function : SetLocation
1053 //=======================================================================
1054 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1055 const TopLoc_Location& theLoc)
1057 if (theIObj.IsNull())
1062 if (theIObj->HasTransformation()
1063 && theLoc.IsIdentity())
1065 theIObj->ResetTransformation();
1066 mgrSelector->Update (theIObj, Standard_False);
1069 else if (theLoc.IsIdentity())
1074 // first reset the previous location to properly clean everything...
1075 if (theIObj->HasTransformation())
1077 theIObj->ResetTransformation();
1080 theIObj->SetLocalTransformation (theLoc.Transformation());
1082 mgrSelector->Update (theIObj, Standard_False);
1084 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1085 // to its highlight structure immediately
1086 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1088 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1089 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1095 //=======================================================================
1096 //function : ResetLocation
1098 //=======================================================================
1099 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1101 if (theIObj.IsNull())
1106 theIObj->ResetTransformation();
1107 mgrSelector->Update (theIObj, Standard_False);
1110 //=======================================================================
1111 //function : HasLocation
1113 //=======================================================================
1114 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1116 return !theIObj.IsNull()
1117 && theIObj->HasTransformation();
1120 //=======================================================================
1121 //function : Location
1123 //=======================================================================
1124 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1126 return theIObj->Transformation();
1129 //=======================================================================
1130 //function : SetDeviationCoefficient
1132 //=======================================================================
1133 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1135 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1138 //=======================================================================
1139 //function : SetDeviationAngle
1141 //=======================================================================
1142 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1144 myDefaultDrawer->SetDeviationAngle (theAngle);
1147 //=======================================================================
1148 //function : DeviationAngle
1149 //purpose : Gets deviationAngle
1150 //=======================================================================
1151 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1153 return myDefaultDrawer->DeviationAngle();
1156 //=======================================================================
1157 //function : DeviationCoefficient
1159 //=======================================================================
1160 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1162 return myDefaultDrawer->DeviationCoefficient();
1165 //=======================================================================
1166 //function : SetDisplayMode
1168 //=======================================================================
1169 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1170 const Standard_Boolean theToUpdateViewer)
1172 if (theMode == myDefaultDrawer->DisplayMode())
1177 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1179 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1180 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1181 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1182 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1185 || anObj->HasDisplayMode()
1186 || !anObj->AcceptDisplayMode (theMode))
1191 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1192 aStatus->SetDisplayMode (theMode);
1194 if (anObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1196 myMainPM->Display (anObj, theMode);
1197 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1199 myMainPM->BeginImmediateDraw();
1200 unhighlightGlobal (anObj);
1201 myMainPM->EndImmediateDraw (myMainVwr);
1203 if (aStatus->IsSubIntensityOn())
1205 highlightWithSubintensity (anObj, theMode);
1207 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1211 myDefaultDrawer->SetDisplayMode (theMode);
1212 if (theToUpdateViewer)
1214 myMainVwr->Update();
1218 //=======================================================================
1219 //function : SetDisplayMode
1221 //=======================================================================
1222 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1223 const Standard_Integer theMode,
1224 const Standard_Boolean theToUpdateViewer)
1226 setContextToObject (theIObj);
1227 if (!myObjects.IsBound (theIObj))
1229 theIObj->SetDisplayMode (theMode);
1232 else if (!theIObj->AcceptDisplayMode (theMode))
1237 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1238 if (theIObj->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1240 aStatus->SetDisplayMode (theMode);
1241 theIObj->SetDisplayMode (theMode);
1245 // erase presentations for all display modes different from <aMode>
1246 const Standard_Integer anOldMode = aStatus->DisplayMode();
1247 if (anOldMode != theMode)
1249 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1251 unhighlightGlobal (theIObj);
1253 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1256 aStatus->SetDisplayMode (theMode);
1258 myMainPM->Display (theIObj, theMode);
1259 if (aStatus->IsHilighted())
1261 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1263 if (aStatus->IsSubIntensityOn())
1265 highlightWithSubintensity (theIObj, theMode);
1268 if (theToUpdateViewer)
1270 myMainVwr->Update();
1272 theIObj->SetDisplayMode (theMode);
1275 //=======================================================================
1276 //function : UnsetDisplayMode
1278 //=======================================================================
1279 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1280 const Standard_Boolean theToUpdateViewer)
1282 if (theIObj.IsNull()
1283 || !theIObj->HasDisplayMode())
1288 if (!myObjects.IsBound (theIObj))
1290 theIObj->UnsetDisplayMode();
1294 const Standard_Integer anOldMode = theIObj->DisplayMode();
1295 if (myDefaultDrawer->DisplayMode() == anOldMode)
1300 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1301 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1303 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1305 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1307 unhighlightGlobal (theIObj);
1309 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1310 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1311 if (aStatus->IsHilighted())
1313 highlightSelected (theIObj->GlobalSelOwner());
1315 if (aStatus->IsSubIntensityOn())
1317 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1320 if (theToUpdateViewer)
1322 myMainVwr->Update();
1326 theIObj->UnsetDisplayMode();
1329 //=======================================================================
1330 //function : SetCurrentFacingModel
1332 //=======================================================================
1333 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1334 const Aspect_TypeOfFacingModel theModel)
1336 if (!theIObj.IsNull())
1338 theIObj->SetCurrentFacingModel (theModel);
1342 //=======================================================================
1343 //function : SetColor
1345 //=======================================================================
1346 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1347 const Quantity_Color& theColor,
1348 const Standard_Boolean theToUpdateViewer)
1350 if (theIObj.IsNull())
1355 setContextToObject (theIObj);
1356 theIObj->SetColor (theColor);
1357 theIObj->UpdatePresentations();
1358 if (theToUpdateViewer)
1360 UpdateCurrentViewer();
1364 //=======================================================================
1365 //function : SetIsoOnTriangulation
1367 //=======================================================================
1368 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1369 const Handle(AIS_InteractiveObject)& theObject)
1371 if (theObject.IsNull())
1376 theObject->SetIsoOnTriangulation (theIsEnabled);
1379 //=======================================================================
1380 //function : SetDeviationCoefficient
1382 //=======================================================================
1383 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1384 const Standard_Real theCoefficient,
1385 const Standard_Boolean theToUpdateViewer)
1387 if (theIObj.IsNull())
1392 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1393 setContextToObject (theIObj);
1394 if (theIObj->Type() != AIS_KindOfInteractive_Object
1395 && theIObj->Type() != AIS_KindOfInteractive_Shape)
1399 else if (theIObj->Signature() != 0)
1404 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1405 aShape->SetOwnDeviationCoefficient (theCoefficient);
1406 aShape->UpdatePresentations();
1407 if (theToUpdateViewer)
1409 UpdateCurrentViewer();
1413 //=======================================================================
1414 //function : SetDeviationAngle
1416 //=======================================================================
1417 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1418 const Standard_Real theAngle,
1419 const Standard_Boolean theToUpdateViewer)
1421 if (theIObj.IsNull())
1426 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1427 setContextToObject (theIObj);
1428 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1432 else if (theIObj->Signature() != 0)
1437 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1438 aShape->SetOwnDeviationAngle (theAngle);
1439 aShape->UpdatePresentations();
1440 if (theToUpdateViewer)
1442 UpdateCurrentViewer();
1446 //=======================================================================
1447 //function : SetAngleAndDeviation
1449 //=======================================================================
1450 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1451 const Standard_Real theAngle,
1452 const Standard_Boolean theToUpdateViewer)
1454 if (theIObj.IsNull())
1459 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1460 setContextToObject (theIObj);
1461 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1465 if (theIObj->Signature() != 0)
1470 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1471 aShape->SetAngleAndDeviation (theAngle);
1472 aShape->UpdatePresentations();
1473 if (theToUpdateViewer)
1475 UpdateCurrentViewer();
1479 //=======================================================================
1480 //function : UnsetColor
1482 //=======================================================================
1483 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1484 const Standard_Boolean theToUpdateViewer)
1486 if (theIObj.IsNull())
1491 theIObj->UnsetColor();
1492 theIObj->UpdatePresentations();
1493 if (theToUpdateViewer)
1495 UpdateCurrentViewer();
1499 //=======================================================================
1500 //function : HasColor
1502 //=======================================================================
1503 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1505 return theIObj->HasColor();
1508 //=======================================================================
1511 //=======================================================================
1512 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1513 Quantity_Color& theColor) const
1515 theIObj->Color (theColor);
1518 //=======================================================================
1521 //=======================================================================
1522 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1524 return theIObj->Width();
1527 //=======================================================================
1528 //function : SetWidth
1530 //=======================================================================
1531 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1532 const Standard_Real theWidth,
1533 const Standard_Boolean theToUpdateViewer)
1535 if (theIObj.IsNull())
1540 setContextToObject (theIObj);
1541 theIObj->SetWidth (theWidth);
1542 theIObj->UpdatePresentations();
1543 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1545 if (myLastPicked->IsAutoHilight())
1547 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1548 myLastPicked->HilightWithColor (myMainPM,
1549 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1554 theIObj->HilightOwnerWithColor (myMainPM,
1555 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1559 if (theToUpdateViewer)
1561 UpdateCurrentViewer();
1565 //=======================================================================
1566 //function : UnsetWidth
1568 //=======================================================================
1569 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1570 const Standard_Boolean theToUpdateViewer)
1572 if (theIObj.IsNull())
1577 theIObj->UnsetWidth();
1578 theIObj->UpdatePresentations();
1579 if (theToUpdateViewer)
1581 UpdateCurrentViewer();
1585 //=======================================================================
1586 //function : SetMaterial
1588 //=======================================================================
1589 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1590 const Graphic3d_MaterialAspect& theMaterial,
1591 const Standard_Boolean theToUpdateViewer)
1593 if (theIObj.IsNull())
1598 setContextToObject (theIObj);
1599 theIObj->SetMaterial (theMaterial);
1600 theIObj->UpdatePresentations();
1601 if (theToUpdateViewer)
1603 UpdateCurrentViewer();
1607 //=======================================================================
1608 //function : UnsetMaterial
1610 //=======================================================================
1611 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1612 const Standard_Boolean theToUpdateViewer)
1614 if (theIObj.IsNull())
1618 theIObj->UnsetMaterial();
1619 theIObj->UpdatePresentations();
1620 if (theToUpdateViewer)
1622 UpdateCurrentViewer();
1626 //=======================================================================
1627 //function : SetTransparency
1629 //=======================================================================
1630 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1631 const Standard_Real theValue,
1632 const Standard_Boolean theToUpdateViewer)
1634 if (theIObj.IsNull())
1639 setContextToObject (theIObj);
1640 if (!theIObj->IsTransparent()
1641 && theValue <= 0.005)
1646 if (theValue <= 0.005)
1648 UnsetTransparency (theIObj, theToUpdateViewer);
1652 theIObj->SetTransparency (theValue);
1653 theIObj->UpdatePresentations();
1654 if (theToUpdateViewer)
1656 UpdateCurrentViewer();
1660 //=======================================================================
1661 //function : UnsetTransparency
1663 //=======================================================================
1664 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1665 const Standard_Boolean theToUpdateViewer)
1667 if (theIObj.IsNull())
1672 theIObj->UnsetTransparency();
1673 theIObj->UpdatePresentations();
1674 if (theToUpdateViewer)
1676 UpdateCurrentViewer();
1680 //=======================================================================
1681 //function : SetSelectedAspect
1683 //=======================================================================
1684 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1685 const Standard_Boolean theToUpdateViewer)
1687 Standard_DISABLE_DEPRECATION_WARNINGS
1688 Standard_Boolean isFound = Standard_False;
1689 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1691 isFound = Standard_True;
1692 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1693 anObj->SetAspect (theAspect);
1695 Standard_ENABLE_DEPRECATION_WARNINGS
1697 if (isFound && theToUpdateViewer)
1699 myMainVwr->Update();
1703 //=======================================================================
1704 //function : SetLocalAttributes
1706 //=======================================================================
1707 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1708 const Handle(Prs3d_Drawer)& theDrawer,
1709 const Standard_Boolean theToUpdateViewer)
1711 if (theIObj.IsNull())
1716 setContextToObject (theIObj);
1717 theIObj->SetAttributes (theDrawer);
1718 Update (theIObj, theToUpdateViewer);
1721 //=======================================================================
1722 //function : UnsetLocalAttributes
1724 //=======================================================================
1725 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1726 const Standard_Boolean theToUpdateViewer)
1728 if (theIObj.IsNull())
1733 setContextToObject (theIObj);
1734 theIObj->UnsetAttributes();
1735 Update (theIObj, theToUpdateViewer);
1738 //=======================================================================
1741 //=======================================================================
1742 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1743 TCollection_ExtendedString& theStatus) const
1746 if (theIObj.IsNull()
1747 || !myObjects.IsBound (theIObj))
1752 theStatus += "\t ____________________________________________";
1753 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1754 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1755 switch (theIObj->DisplayStatus())
1757 case PrsMgr_DisplayStatus_Displayed:
1759 theStatus += "\t| -->Displayed\n";
1762 case PrsMgr_DisplayStatus_Erased:
1764 theStatus += "\t| -->Erased\n";
1771 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1772 theStatus += "\t|\t Mode ";
1773 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1776 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1778 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1779 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1781 theStatus += "\t\t Mode ";
1782 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1785 theStatus += "\t ____________________________________________";
1788 //=======================================================================
1789 //function : GetDefModes
1791 //=======================================================================
1792 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1793 Standard_Integer& theDispMode,
1794 Standard_Integer& theHiMode,
1795 Standard_Integer& theSelMode) const
1797 if (theIObj.IsNull())
1802 theDispMode = theIObj->HasDisplayMode()
1803 ? theIObj->DisplayMode()
1804 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1805 ? myDefaultDrawer->DisplayMode()
1807 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1808 theSelMode = theIObj->GlobalSelectionMode();
1811 //=======================================================================
1812 //function : EraseGlobal
1814 //=======================================================================
1815 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1816 const Standard_Boolean theToUpdateviewer)
1818 Handle(AIS_GlobalStatus) aStatus;
1819 if (theIObj.IsNull()
1820 || !myObjects.Find (theIObj, aStatus)
1821 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased)
1826 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1827 unselectOwners (theIObj);
1828 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1830 if (!myLastPicked.IsNull()
1831 && myLastPicked->IsSameSelectable (theIObj))
1833 clearDynamicHighlight();
1836 // make sure highlighting presentations are properly erased
1837 theIObj->ErasePresentations (false);
1839 if (IsSelected (theIObj)
1840 && aStatus->DisplayMode() != aDispMode)
1842 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1845 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1847 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1849 aStatus->ClearSelectionModes();
1850 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Erased);
1852 if (theToUpdateviewer)
1854 myMainVwr->Update();
1858 //=======================================================================
1859 //function : unselectOwners
1861 //=======================================================================
1862 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
1864 SelectMgr_SequenceOfOwner aSeq;
1865 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1867 if (aSelIter.Value()->IsSameSelectable (theObject))
1869 aSeq.Append (aSelIter.Value());
1872 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1874 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
1878 //=======================================================================
1879 //function : ClearGlobal
1881 //=======================================================================
1882 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1883 const Standard_Boolean theToUpdateviewer)
1885 Handle(AIS_GlobalStatus) aStatus;
1886 if (theIObj.IsNull()
1887 || !myObjects.Find (theIObj, aStatus))
1889 // for cases when reference shape of connected interactives was not displayed
1890 // but its selection primitives were calculated
1891 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1892 mgrSelector->Remove (anObj);
1896 unselectOwners (theIObj);
1898 myMainPM->Erase (theIObj, -1);
1899 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
1901 // Object removes from Detected sequence
1902 Standard_DISABLE_DEPRECATION_WARNINGS
1903 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
1905 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
1906 Handle(AIS_InteractiveObject) anObj;
1907 if (!aPicked.IsNull())
1909 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
1913 && anObj == theIObj)
1915 myDetectedSeq.Remove (aDetIter);
1916 if (myCurDetected == aDetIter)
1918 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
1920 if (myCurHighlighted == aDetIter)
1922 myCurHighlighted = 0;
1930 Standard_ENABLE_DEPRECATION_WARNINGS
1932 // remove IO from the selection manager to avoid memory leaks
1933 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1934 mgrSelector->Remove (anObj);
1936 setObjectStatus (theIObj, PrsMgr_DisplayStatus_None, -1, -1);
1937 myMainVwr->StructureManager()->UnregisterObject (theIObj);
1939 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
1941 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
1944 if (!myLastPicked.IsNull())
1946 if (myLastPicked->IsSameSelectable (theIObj))
1948 clearDynamicHighlight();
1949 myLastPicked.Nullify();
1953 if (theToUpdateviewer
1954 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1956 myMainVwr->Update();
1960 //=======================================================================
1961 //function : ClearGlobalPrs
1963 //=======================================================================
1964 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
1965 const Standard_Integer theMode,
1966 const Standard_Boolean theToUpdateViewer)
1968 const Handle(AIS_GlobalStatus)* aStatus = !theIObj.IsNull() ? myObjects.Seek (theIObj) : NULL;
1969 if (aStatus == NULL)
1974 if ((*aStatus)->DisplayMode() == theMode)
1976 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1977 if (aDispMode == theMode
1978 && myMainPM->IsHighlighted (theIObj, theMode))
1980 unhighlightGlobal (theIObj);
1983 myMainPM->Erase (theIObj, theMode);
1986 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
1987 && theToUpdateViewer)
1989 myMainVwr->Update();
1993 //=======================================================================
1994 //function : ClearDetected
1996 //=======================================================================
1997 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2000 myCurHighlighted = 0;
2001 myDetectedSeq.Clear();
2002 Standard_Boolean toUpdate = Standard_False;
2003 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2005 toUpdate = Standard_True;
2006 clearDynamicHighlight();
2008 myLastPicked.Nullify();
2009 myMainSel->ClearPicked();
2010 if (toUpdate && theToRedrawImmediate)
2012 myMainVwr->RedrawImmediate();
2017 //=======================================================================
2018 //function : DrawHiddenLine
2020 //=======================================================================
2021 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2023 return myDefaultDrawer->DrawHiddenLine();
2026 //=======================================================================
2027 //function : EnableDrawHiddenLine
2029 //=======================================================================
2030 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2032 myDefaultDrawer->EnableDrawHiddenLine();
2035 //=======================================================================
2036 //function : DisableDrawHiddenLine
2038 //=======================================================================
2039 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2041 myDefaultDrawer->DisableDrawHiddenLine();
2044 //=======================================================================
2045 //function : HiddenLineAspect
2047 //=======================================================================
2048 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2050 return myDefaultDrawer->HiddenLineAspect();
2053 //=======================================================================
2054 //function : SetHiddenLineAspect
2056 //=======================================================================
2057 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2059 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2062 //=======================================================================
2063 //function : SetIsoNumber
2065 //=======================================================================
2066 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2067 const AIS_TypeOfIso theType)
2072 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2075 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2078 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2079 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2084 //=======================================================================
2085 //function : IsoNumber
2087 //=======================================================================
2088 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2092 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2093 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2094 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2095 ? myDefaultDrawer->UIsoAspect()->Number()
2101 //=======================================================================
2102 //function : IsoOnPlane
2104 //=======================================================================
2105 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2107 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2110 //=======================================================================
2111 //function : IsoOnPlane
2113 //=======================================================================
2114 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2116 return myDefaultDrawer->IsoOnPlane();
2119 //=======================================================================
2120 //function : IsoOnTriangulation
2122 //=======================================================================
2123 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2125 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2128 //=======================================================================
2129 //function : IsoOnTriangulation
2131 //=======================================================================
2132 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2134 return myDefaultDrawer->IsoOnTriangulation();
2137 //=======================================================================
2138 //function : SetPixelTolerance
2140 //=======================================================================
2141 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2143 myMainSel->SetPixelTolerance (thePrecision);
2146 //=======================================================================
2147 //function : PixelTolerance
2149 //=======================================================================
2150 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2152 return myMainSel->PixelTolerance();
2155 //=======================================================================
2156 //function : SetSelectionSensitivity
2157 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2158 //=======================================================================
2159 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2160 const Standard_Integer theMode,
2161 const Standard_Integer theNewSensitivity)
2163 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2166 //=======================================================================
2167 //function : InitAttributes
2169 //=======================================================================
2170 void AIS_InteractiveContext::InitAttributes()
2172 Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Brass);
2173 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2175 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2176 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2177 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2178 aLineAspect->SetWidth (1.0);
2179 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2181 // tolerance to 2 pixels...
2182 SetPixelTolerance (2);
2184 // Customizing the drawer for trihedrons and planes...
2185 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2186 const Standard_Real aLength = 100.0;
2187 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2188 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2189 aTrihAspect->LineAspect(Prs3d_DatumParts_XAxis)->SetColor (aColor);
2190 aTrihAspect->LineAspect(Prs3d_DatumParts_YAxis)->SetColor (aColor);
2191 aTrihAspect->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor (aColor);
2193 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2194 const Standard_Real aPlaneLength = 200.0;
2195 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2196 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2199 //=======================================================================
2200 //function : TrihedronSize
2202 //=======================================================================
2203 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2205 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
2208 //=======================================================================
2209 //function : SetTrihedronSize
2211 //=======================================================================
2212 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2213 const Standard_Boolean /*updateviewer*/)
2215 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2216 Redisplay (AIS_KindOfInteractive_Datum, 3, Standard_False);
2217 Redisplay (AIS_KindOfInteractive_Datum, 4, Standard_True);
2220 //=======================================================================
2221 //function : SetPlaneSize
2223 //=======================================================================
2224 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2225 const Standard_Real theValY,
2226 const Standard_Boolean theToUpdateViewer)
2228 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2229 Redisplay (AIS_KindOfInteractive_Datum, 7, theToUpdateViewer);
2232 //=======================================================================
2233 //function : SetPlaneSize
2235 //=======================================================================
2236 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2237 const Standard_Boolean theToUpdateViewer)
2239 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2242 //=======================================================================
2243 //function : PlaneSize
2245 //=======================================================================
2246 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2247 Standard_Real& theY) const
2249 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2250 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2251 return (Abs (theX - theY) <= Precision::Confusion());
2254 //=======================================================================
2255 //function : SetZLayer
2257 //=======================================================================
2258 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2259 const Graphic3d_ZLayerId theLayerId)
2261 if (theIObj.IsNull())
2264 theIObj->SetZLayer (theLayerId);
2267 //=======================================================================
2268 //function : GetZLayer
2270 //=======================================================================
2271 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2273 return !theIObj.IsNull()
2275 : Graphic3d_ZLayerId_UNKNOWN;
2278 //=======================================================================
2279 //function : RebuildSelectionStructs
2280 //purpose : Rebuilds 1st level of BVH selection forcibly
2281 //=======================================================================
2282 void AIS_InteractiveContext::RebuildSelectionStructs()
2284 myMainSel->RebuildObjectsTree (Standard_True);
2287 //=======================================================================
2288 //function : Disconnect
2289 //purpose : Disconnects selectable object from an assembly and updates selection structures
2290 //=======================================================================
2291 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2292 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2294 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2296 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2297 theObj->Disconnect (theObjToDisconnect);
2298 if (!myObjects.IsBound (theObjToDisconnect))
2300 // connected presentation might contain displayed presentations
2301 myMainPM->Erase (theObjToDisconnect, -1);
2302 theObjToDisconnect->ErasePresentations (true);
2305 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2306 mgrSelector->Remove (anObj);
2308 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2310 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2311 theObj->Disconnect();
2312 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2313 mgrSelector->Remove (anObj);
2319 //=======================================================================
2320 //function : FitSelected
2321 //purpose : Fits the view corresponding to the bounds of selected objects
2322 //=======================================================================
2323 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2325 FitSelected (theView, 0.01, Standard_True);
2328 //=======================================================================
2329 //function : BoundingBoxOfSelection
2331 //=======================================================================
2332 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
2334 Bnd_Box aBndSelected;
2335 AIS_MapOfObjectOwners anObjectOwnerMap;
2336 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2338 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2339 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2340 if (anObj->IsInfinite())
2345 if (anOwner == anObj->GlobalSelOwner())
2348 anObj->BoundingBox (aTmpBnd);
2349 aBndSelected.Add (aTmpBnd);
2353 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2354 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2356 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2357 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2360 anOwnerMap->Add (anOwner);
2364 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2366 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2367 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2368 aBndSelected.Add (aTmpBox);
2371 return aBndSelected;
2374 //=======================================================================
2375 //function : FitSelected
2376 //purpose : Fits the view corresponding to the bounds of selected objects
2377 //=======================================================================
2378 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2379 const Standard_Real theMargin,
2380 const Standard_Boolean theToUpdate)
2382 Bnd_Box aBndSelected = BoundingBoxOfSelection();
2383 if (!aBndSelected.IsVoid())
2385 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2389 //=======================================================================
2390 //function : SetTransformPersistence
2392 //=======================================================================
2393 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2394 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2396 theObject->SetTransformPersistence (theTrsfPers);
2397 if (!myObjects.IsBound (theObject))
2402 mgrSelector->UpdateSelection (theObject);
2404 const Graphic3d_ZLayerId aLayerId = theObject->ZLayer();
2405 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2406 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2408 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2409 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2413 //=======================================================================
2414 //function : GravityPoint
2416 //=======================================================================
2417 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2419 return theView->GravityPoint();
2422 //=======================================================================
2423 //function : setObjectStatus
2425 //=======================================================================
2426 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2427 const PrsMgr_DisplayStatus theStatus,
2428 const Standard_Integer theDispMode,
2429 const Standard_Integer theSelectionMode)
2431 theIObj->SetDisplayStatus (theStatus);
2432 if (theStatus != PrsMgr_DisplayStatus_None)
2434 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus();
2435 aStatus->SetDisplayMode (theDispMode);
2436 if (theSelectionMode != -1)
2438 aStatus->AddSelectionMode (theSelectionMode);
2440 myObjects.Bind (theIObj, aStatus);
2444 myObjects.UnBind (theIObj);
2447 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2449 Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2450 if (aChild.IsNull())
2455 setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
2459 //=======================================================================
2460 //function : highlightWithColor
2462 //=======================================================================
2463 void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
2464 const Handle(V3d_Viewer)& theViewer)
2466 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2472 const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
2473 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
2475 myMainPM->BeginImmediateDraw();
2476 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
2477 myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
2480 //=======================================================================
2481 //function : highlightSelected
2483 //=======================================================================
2484 void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
2486 AIS_NListOfEntityOwner anOwners;
2487 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2493 if (!theOwner->IsAutoHilight())
2495 SelectMgr_SequenceOfOwner aSeq;
2496 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2498 if (aSelIter.Value()->IsSameSelectable (anObj))
2500 anOwners.Append (aSelIter.Value());
2506 anOwners.Append (theOwner);
2508 highlightOwners (anOwners, Handle(Prs3d_Drawer)());
2511 //=======================================================================
2512 //function : highlightGlobal
2514 //=======================================================================
2515 void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
2516 const Handle(Prs3d_Drawer)& theStyle,
2517 const Standard_Integer theDispMode)
2519 if (theObj.IsNull())
2524 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
2525 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2527 if (aGlobOwner.IsNull())
2529 myMainPM->Color (theObj, theStyle, aHiMode);
2533 AIS_NListOfEntityOwner anOwners;
2534 if (!aGlobOwner->IsAutoHilight())
2536 SelectMgr_SequenceOfOwner aSeq;
2537 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2539 if (aSelIter.Value()->IsSameSelectable (theObj))
2541 anOwners.Append (aSelIter.Value());
2547 anOwners.Append (aGlobOwner);
2549 highlightOwners (anOwners, theStyle);
2552 //=======================================================================
2553 //function : unhighlightSelected
2555 //=======================================================================
2556 void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
2558 unhighlightOwners (mySelection->Objects(), theIsToHilightSubIntensity);
2561 //=======================================================================
2562 //function : unhighlightOwners
2564 //=======================================================================
2565 void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& theOwners,
2566 const Standard_Boolean theIsToHilightSubIntensity)
2568 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
2569 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
2571 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
2572 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
2573 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anInteractive);
2579 if (anOwner->IsAutoHilight())
2581 anOwner->Unhilight (myMainPM);
2582 if (theIsToHilightSubIntensity)
2584 if ((*aStatusPtr)->IsSubIntensityOn())
2586 const Standard_Integer aHiMode = getHilightMode (anInteractive, (*aStatusPtr)->HilightStyle(), (*aStatusPtr)->DisplayMode());
2587 highlightWithSubintensity (anOwner, aHiMode);
2593 anObjToClear.Add (anInteractive);
2595 if (anOwner == anInteractive->GlobalSelOwner())
2597 (*aStatusPtr)->SetHilightStatus (Standard_False);
2599 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
2601 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
2603 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
2604 myMainPM->Unhighlight (anObj);
2605 anObj->ClearSelected();
2609 //=======================================================================
2610 //function : unhighlightGlobal
2612 //=======================================================================
2613 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj)
2615 if (theObj.IsNull())
2620 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2621 if (aGlobOwner.IsNull())
2623 myMainPM->Unhighlight (theObj);
2627 AIS_NListOfEntityOwner anOwners;
2628 anOwners.Append (aGlobOwner);
2629 unhighlightOwners (anOwners);
2632 //=======================================================================
2633 //function : turnOnSubintensity
2635 //=======================================================================
2636 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2637 const Standard_Integer theDispMode,
2638 const Standard_Boolean theIsDisplayedOnly) const
2640 // the only differ with selection highlight is color, so sync transparency values
2641 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
2642 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2644 if (theObject.IsNull())
2646 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
2648 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
2649 if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2654 aStatus->SetSubIntensity (true);
2655 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2660 Handle(AIS_GlobalStatus) aStatus;
2661 if (!myObjects.Find (theObject, aStatus))
2666 if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2671 aStatus->SetSubIntensity (true);
2672 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2676 //=======================================================================
2677 //function : highlightWithSubintensity
2679 //=======================================================================
2680 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2681 const Standard_Integer theMode) const
2683 // the only differ with selection highlight is color, so
2684 // sync transparency values
2685 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2687 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2690 //=======================================================================
2691 //function : highlightWithSubintensity
2693 //=======================================================================
2694 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
2695 const Standard_Integer theMode) const
2697 // the only differ with selection highlight is color, so
2698 // sync transparency values
2699 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2701 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2704 //=======================================================================
2705 //function : isSlowHiStyle
2707 //=======================================================================
2708 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
2709 const Handle(V3d_Viewer)& theViewer) const
2711 if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
2713 const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
2714 return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
2715 || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
2717 return Standard_False;
2720 //=======================================================================
2723 //=======================================================================
2724 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
2725 const Standard_Integer theYPix,
2726 const Handle(V3d_View)& theView,
2727 const Standard_Boolean theToRedrawOnUpdate)
2729 if (theView->Viewer() != myMainVwr)
2731 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2735 myCurHighlighted = 0;
2736 myDetectedSeq.Clear();
2737 myLastActiveView = theView.get();
2740 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
2741 Standard_Boolean toUpdateViewer = Standard_False;
2743 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
2744 myMainSel->Pick (theXPix, theYPix, theView);
2746 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
2747 // (the objects must be AIS_Shapes)
2748 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
2749 Standard_Integer aNewDetected = 0;
2750 Standard_Boolean toIgnoreDetTop = Standard_False;
2751 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
2753 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
2754 if (anOwner.IsNull()
2755 || !myFilters->IsOk (anOwner))
2757 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
2759 toIgnoreDetTop = Standard_True;
2764 if (aNewDetected < 1
2767 aNewDetected = aDetIter;
2770 myDetectedSeq.Append (aDetIter);
2773 if (aNewDetected >= 1)
2775 myCurHighlighted = myDetectedSeq.Lower();
2777 // Does nothing if previously detected object is equal to the current one.
2778 // However in advanced selection modes the owners comparison
2779 // is not effective because in that case only one owner manage the
2780 // selection in current selection mode. It is necessary to check the current detected
2781 // entity and hilight it only if the detected entity is not the same as
2782 // previous detected (IsForcedHilight call)
2783 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
2784 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
2786 return myLastPicked->IsSelected()
2788 : AIS_SOD_OnlyOneDetected;
2791 // Previously detected object is unhilighted if it is not selected or hilighted
2792 // with selection color if it is selected. Such highlighting with selection color
2793 // is needed only if myToHilightSelected flag is true. In this case previously detected
2794 // object has been already highlighted with myHilightColor during previous MoveTo()
2795 // method call. As result it is necessary to rehighligt it with mySelectionColor.
2796 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2798 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2800 theView->Viewer()->Invalidate();
2803 clearDynamicHighlight();
2804 toUpdateViewer = Standard_True;
2807 // initialize myLastPicked field with currently detected object
2808 myLastPicked = aNewPickedOwner;
2810 // highlight detected object if it is not selected or myToHilightSelected flag is true
2811 if (myLastPicked->HasSelectable())
2814 && (!myLastPicked->IsSelected()
2815 || myToHilightSelected))
2817 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2819 theView->Viewer()->Invalidate();
2822 highlightWithColor (myLastPicked, theView->Viewer());
2823 toUpdateViewer = Standard_True;
2826 aStatus = myLastPicked->IsSelected()
2828 : AIS_SOD_OnlyOneDetected;
2833 // previously detected object is unhilighted if it is not selected or hilighted
2834 // with selection color if it is selected
2835 aStatus = AIS_SOD_Nothing;
2837 && !myLastPicked.IsNull()
2838 && myLastPicked->HasSelectable())
2840 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2842 theView->Viewer()->Invalidate();
2845 clearDynamicHighlight();
2846 toUpdateViewer = Standard_True;
2849 myLastPicked.Nullify();
2853 && theToRedrawOnUpdate)
2855 if (theView->ComputedMode())
2857 theView->Viewer()->Update();
2861 if (theView->IsInvalidated())
2863 theView->Viewer()->Redraw();
2867 theView->Viewer()->RedrawImmediate();
2875 //=======================================================================
2876 //function : AddSelect
2878 //=======================================================================
2879 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
2881 mySelection->AddSelect (theObject);
2883 Standard_Integer aSelNum = NbSelected();
2884 return (aSelNum == 0) ? AIS_SOP_NothingSelected
2885 : (aSelNum == 1) ? AIS_SOP_OneSelected
2886 : AIS_SOP_SeveralSelected;
2889 //=======================================================================
2890 //function : SelectRectangle
2892 //=======================================================================
2893 AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i& thePntMin,
2894 const Graphic3d_Vec2i& thePntMax,
2895 const Handle(V3d_View)& theView,
2896 const AIS_SelectionScheme theSelScheme)
2898 if (theView->Viewer() != myMainVwr)
2900 throw Standard_ProgramError ("AIS_InteractiveContext::SelectRectangle() - invalid argument");
2903 myLastActiveView = theView.get();
2904 myMainSel->Pick (thePntMin.x(), thePntMin.y(), thePntMax.x(), thePntMax.y(), theView);
2906 AIS_NArray1OfEntityOwner aPickedOwners;
2907 if (myMainSel->NbPicked() > 0)
2909 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2910 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2912 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2916 return Select (aPickedOwners, theSelScheme);
2919 //=======================================================================
2920 //function : SelectPolygon
2922 //=======================================================================
2923 AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt2d& thePolyline,
2924 const Handle(V3d_View)& theView,
2925 const AIS_SelectionScheme theSelScheme)
2927 if (theView->Viewer() != myMainVwr)
2929 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPolygon() - invalid argument");
2932 myLastActiveView = theView.get();
2933 myMainSel->Pick (thePolyline, theView);
2935 AIS_NArray1OfEntityOwner aPickedOwners;
2936 if (myMainSel->NbPicked() > 0)
2938 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2939 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2941 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2945 return Select (aPickedOwners, theSelScheme);
2948 //=======================================================================
2949 //function : SelectPoint
2951 //=======================================================================
2952 AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i& thePnt,
2953 const Handle(V3d_View)& theView,
2954 const AIS_SelectionScheme theSelScheme)
2956 if (theView->Viewer() != myMainVwr)
2958 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPoint() - invalid argument");
2961 myLastActiveView = theView.get();
2962 myMainSel->Pick (thePnt.x(), thePnt.y(), theView);
2964 AIS_NArray1OfEntityOwner aPickedOwners;
2965 if (myMainSel->NbPicked() > 0)
2967 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2968 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2970 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2974 return Select (aPickedOwners, theSelScheme);
2977 //=======================================================================
2978 //function : SelectDetected
2980 //=======================================================================
2981 AIS_StatusOfPick AIS_InteractiveContext::SelectDetected (const AIS_SelectionScheme theSelScheme)
2983 if (theSelScheme == AIS_SelectionScheme_Replace && !myLastPicked.IsNull())
2985 Graphic3d_Vec2i aMousePos (-1, -1);
2986 if (myMainSel->GetManager().GetActiveSelectionType() == SelectBasics_SelectingVolumeManager::Point)
2988 aMousePos.SetValues ((Standard_Integer )myMainSel->GetManager().GetMousePosition().X(),
2989 (Standard_Integer )myMainSel->GetManager().GetMousePosition().Y());
2991 if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
2993 return AIS_SOP_NothingSelected;
2997 AIS_NArray1OfEntityOwner aPickedOwners (1, 1);
2998 aPickedOwners.SetValue (1, myLastPicked);
2999 return Select (aPickedOwners, theSelScheme);
3002 //=======================================================================
3005 //=======================================================================
3006 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
3007 const Standard_Integer theYPMin,
3008 const Standard_Integer theXPMax,
3009 const Standard_Integer theYPMax,
3010 const Handle(V3d_View)& theView,
3011 const Standard_Boolean theToUpdateViewer)
3013 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
3014 Graphic3d_Vec2i (theXPMax, theYPMax),
3016 if (theToUpdateViewer)
3018 UpdateCurrentViewer();
3023 //=======================================================================
3025 //purpose : Selection by polyline
3026 //=======================================================================
3027 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
3028 const Handle(V3d_View)& theView,
3029 const Standard_Boolean theToUpdateViewer)
3031 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView);
3032 if (theToUpdateViewer)
3034 UpdateCurrentViewer();
3039 //=======================================================================
3042 //=======================================================================
3043 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean theToUpdateViewer)
3045 AIS_StatusOfPick aStatus = SelectDetected();
3046 if (theToUpdateViewer)
3048 UpdateCurrentViewer();
3053 //=======================================================================
3054 //function : ShiftSelect
3056 //=======================================================================
3057 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean theToUpdateViewer)
3059 AIS_StatusOfPick aStatus = SelectDetected (AIS_SelectionScheme_XOR);
3060 if (theToUpdateViewer)
3062 UpdateCurrentViewer();
3067 //=======================================================================
3068 //function : ShiftSelect
3070 //=======================================================================
3071 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
3072 const Standard_Integer theYPMin,
3073 const Standard_Integer theXPMax,
3074 const Standard_Integer theYPMax,
3075 const Handle(V3d_View)& theView,
3076 const Standard_Boolean theToUpdateViewer)
3078 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
3079 Graphic3d_Vec2i (theXPMax, theYPMax),
3081 AIS_SelectionScheme_XOR);
3082 if (theToUpdateViewer)
3084 UpdateCurrentViewer();
3089 //=======================================================================
3090 //function : ShiftSelect
3092 //=======================================================================
3093 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
3094 const Handle(V3d_View)& theView,
3095 const Standard_Boolean theToUpdateViewer)
3097 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView, AIS_SelectionScheme_XOR);
3098 if (theToUpdateViewer)
3100 UpdateCurrentViewer();
3105 //=======================================================================
3108 //=======================================================================
3109 AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners,
3110 const AIS_SelectionScheme theSelScheme)
3112 NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> aSelOwnerMap (myAutoHilight ? mySelection->Objects().Size() : 0);
3115 clearDynamicHighlight();
3117 // collect currently selected owners
3118 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3120 aSelOwnerMap.Add (anOwnerIter.Value());
3124 mySelection->SelectOwners (theOwners, theSelScheme, myMainSel->GetManager().IsOverlapAllowed(), myFilters);
3128 // collect lists of owners to unhighlight (unselected) and to highlight (selected)
3129 AIS_NListOfEntityOwner anOwnersToUnhighlight, anOwnersToHighlight;
3130 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3132 // add newly selected owners
3133 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3134 if (!aSelOwnerMap.RemoveKey (anOwner))
3136 // newly selected owner
3137 anOwnersToHighlight.Append (anOwner);
3141 // already selected owner
3142 if (!anOwner->IsAutoHilight()
3143 && theSelScheme != AIS_SelectionScheme_XOR
3144 && theSelScheme != AIS_SelectionScheme_Add)
3146 // hack to perform AIS_InteractiveObject::ClearSelected() before highlighting
3147 anOwnersToUnhighlight.Append (anOwner);
3148 anOwnersToHighlight.Append (anOwner);
3150 else if (anOwner->IsForcedHilight()
3151 || !anOwner->IsAutoHilight())
3153 anOwnersToHighlight.Append (anOwner);
3158 for (NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)>::Iterator anOwnerIter (aSelOwnerMap); anOwnerIter.More(); anOwnerIter.Next())
3160 // owners removed from selection
3161 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3162 anOwnersToUnhighlight.Append (anOwner);
3165 unhighlightOwners (anOwnersToUnhighlight);
3166 highlightOwners (anOwnersToHighlight, Handle(Prs3d_Drawer)());
3169 Standard_Integer aSelNum = NbSelected();
3170 return (aSelNum == 0) ? AIS_SOP_NothingSelected
3171 : (aSelNum == 1) ? AIS_SOP_OneSelected
3172 : AIS_SOP_SeveralSelected;
3175 //=======================================================================
3176 //function : HilightSelected
3178 //=======================================================================
3179 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
3181 // In case of selection without using local context
3182 clearDynamicHighlight();
3184 highlightOwners (mySelection->Objects(), Handle(Prs3d_Drawer)());
3186 if (theToUpdateViewer)
3188 UpdateCurrentViewer();
3192 //=======================================================================
3193 //function : highlightOwners
3195 //=======================================================================
3196 void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners,
3197 const Handle(Prs3d_Drawer)& theStyle)
3199 NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > anObjOwnerMap;
3200 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
3202 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
3203 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3207 const Handle(Prs3d_Drawer)& anObjSelStyle = !theStyle.IsNull() ? theStyle : getSelStyle (anObj, anOwner);
3208 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3213 if (anOwner == anObj->GlobalSelOwner())
3215 (*aStatusPtr)->SetHilightStatus (Standard_True);
3216 (*aStatusPtr)->SetHilightStyle (anObjSelStyle);
3218 if (!anOwner->IsAutoHilight())
3220 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
3221 if (anObjOwnerMap.Find (anObj, aSeq))
3223 aSeq->Append (anOwner);
3227 aSeq = new SelectMgr_SequenceOfOwner();
3228 aSeq->Append (anOwner);
3229 anObjOwnerMap.Bind (anObj, aSeq);
3234 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, (*aStatusPtr)->DisplayMode());
3235 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3239 if (!anObjOwnerMap.IsEmpty())
3241 for (NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> >::Iterator anIter (anObjOwnerMap);
3242 anIter.More(); anIter.Next())
3244 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
3246 anObjOwnerMap.Clear();
3250 //=======================================================================
3251 //function : UnhilightSelected
3253 //=======================================================================
3254 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
3256 unhighlightSelected();
3258 if (theToUpdateViewer)
3260 UpdateCurrentViewer();
3264 //=======================================================================
3265 //function : ClearSelected
3267 //=======================================================================
3268 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
3270 if (NbSelected() == 0)
3277 unhighlightSelected();
3280 mySelection->Clear();
3283 clearDynamicHighlight();
3286 if (theToUpdateViewer)
3288 UpdateCurrentViewer();
3292 //=======================================================================
3293 //function : SetSelected
3294 //purpose : Sets the whole object as selected and highlights it with selection color
3295 //=======================================================================
3296 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
3297 const Standard_Boolean theToUpdateViewer)
3299 if (theObject.IsNull())
3304 if (!myObjects.IsBound (theObject))
3309 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3310 if (anOwner.IsNull())
3315 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
3316 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
3318 Handle(Prs3d_Drawer) aCustomStyle;
3319 if (HighlightStyle (theObject, aCustomStyle))
3321 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3323 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
3329 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
3331 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
3332 if (!myFilters->IsOk (aSelOwner))
3337 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
3340 Unhilight (aSelectable, Standard_False);
3342 if (aSelOwner == aSelectable->GlobalSelOwner())
3344 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (aSelectable))
3346 (*aStatusPtr)->SetHilightStatus (Standard_False);
3351 // added to avoid untimely viewer update...
3352 mySelection->ClearAndSelect (anOwner);
3356 Handle(Prs3d_Drawer) aCustomStyle;
3357 if (HighlightStyle (theObject, aCustomStyle))
3359 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3361 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3366 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3370 if (theToUpdateViewer)
3372 UpdateCurrentViewer();
3376 //=======================================================================
3377 //function : SetSelected
3378 //purpose : Sets the whole object as selected and highlights it with selection color
3379 //=======================================================================
3380 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3381 const Standard_Boolean theToUpdateViewer)
3383 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
3388 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3389 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
3390 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
3392 Handle(Prs3d_Drawer) aCustomStyle;
3393 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
3395 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3397 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
3398 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3404 if (!myObjects.IsBound (anObject))
3411 unhighlightSelected();
3414 mySelection->ClearAndSelect (theOwner);
3417 Handle(Prs3d_Drawer) aCustomStyle;
3418 if (!HighlightStyle (theOwner, aCustomStyle) ||
3419 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
3421 highlightSelected (theOwner);
3425 if (theToUpdateViewer)
3427 UpdateCurrentViewer();
3431 //=======================================================================
3432 //function : AddOrRemoveSelected
3434 //=======================================================================
3435 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
3436 const Standard_Boolean theToUpdateViewer)
3438 if (theObject.IsNull()
3439 || !myObjects.IsBound (theObject))
3444 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3445 if (!anOwner.IsNull()
3446 && anOwner->HasSelectable())
3448 AddOrRemoveSelected (anOwner, theToUpdateViewer);
3452 //=======================================================================
3453 //function : AddOrRemoveSelected
3454 //purpose : Allows to highlight or unhighlight the owner given depending on
3455 // its selection status
3456 //=======================================================================
3457 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3458 const Standard_Boolean theToUpdateViewer)
3460 if (theOwner.IsNull() || !theOwner->HasSelectable())
3465 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
3470 mySelection->Select (theOwner);
3474 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3475 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3481 if (theOwner->IsSelected())
3483 highlightSelected (theOwner);
3487 AIS_NListOfEntityOwner anOwners;
3488 anOwners.Append (theOwner);
3489 unhighlightOwners (anOwners);
3491 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
3495 if (theToUpdateViewer)
3497 UpdateCurrentViewer();
3501 // =======================================================================
3502 // function : SetSelectedState
3504 // =======================================================================
3505 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
3506 const Standard_Boolean theIsSelected)
3508 if (theEntity.IsNull())
3510 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
3513 if (!theEntity->HasSelectable()
3514 || mySelection->IsSelected (theEntity) == theIsSelected)
3519 if (theEntity->IsAutoHilight())
3521 AddOrRemoveSelected (theEntity, false);
3527 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
3528 theEntity->SetSelected (true);
3529 return aSelStatus == AIS_SS_Added;
3533 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
3534 theEntity->SetSelected (false);
3535 return aSelStatus == AIS_SS_Removed;
3539 //=======================================================================
3540 //function : IsSelected
3542 //=======================================================================
3543 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
3545 if (theObj.IsNull())
3547 return Standard_False;
3550 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3551 if (aStatus == NULL)
3553 return Standard_False;
3556 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
3557 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
3558 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
3560 if (aModeIter.Value() == aGlobalSelMode)
3562 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
3564 return aGlobOwner->IsSelected();
3566 return Standard_False;
3569 return Standard_False;
3572 //=======================================================================
3573 //function : FirstSelectedObject
3575 //=======================================================================
3576 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
3578 return !mySelection->Objects().IsEmpty()
3579 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
3580 : Handle(AIS_InteractiveObject)();
3583 //=======================================================================
3584 //function : HasSelectedShape
3586 //=======================================================================
3587 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
3589 if (!mySelection->More())
3591 return Standard_False;
3594 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3595 return !anOwner.IsNull() && anOwner->HasShape();
3598 //=======================================================================
3599 //function : SelectedShape
3601 //=======================================================================
3602 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
3604 if (!mySelection->More())
3606 return TopoDS_Shape();
3609 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3610 if (anOwner.IsNull() || !anOwner->HasSelectable())
3612 return TopoDS_Shape();
3615 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
3618 //=======================================================================
3619 //function : EntityOwners
3621 //=======================================================================
3622 void AIS_InteractiveContext::EntityOwners (Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
3623 const Handle(AIS_InteractiveObject)& theIObj,
3624 const Standard_Integer theMode) const
3626 if (theIObj.IsNull())
3631 TColStd_ListOfInteger aModes;
3634 ActivatedModes (theIObj, aModes);
3638 aModes.Append (theMode);
3641 if (theOwners.IsNull())
3643 theOwners = new SelectMgr_IndexedMapOfOwner();
3646 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
3648 const int aMode = anItr.Value();
3649 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
3655 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
3657 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
3659 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
3661 theOwners->Add (aOwner);
3668 //=======================================================================
3669 //function : HasDetectedShape
3671 //=======================================================================
3672 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
3674 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3675 return !anOwner.IsNull()
3676 && anOwner->HasShape();
3679 //=======================================================================
3680 //function : DetectedShape
3682 //=======================================================================
3683 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
3685 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3686 return anOwner->Shape();
3689 //=======================================================================
3690 //function : HilightNextDetected
3692 //=======================================================================
3693 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
3694 const Standard_Boolean theToRedrawImmediate)
3696 myMainPM->ClearImmediateDraw();
3697 if (myDetectedSeq.IsEmpty())
3702 if (++myCurHighlighted > myDetectedSeq.Upper())
3704 myCurHighlighted = myDetectedSeq.Lower();
3706 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
3707 if (anOwner.IsNull())
3712 highlightWithColor (anOwner, theView->Viewer());
3713 myLastPicked = anOwner;
3715 if (theToRedrawImmediate)
3717 myMainPM->RedrawImmediate (theView->Viewer());
3718 myMainVwr->RedrawImmediate();
3721 return myCurHighlighted;
3724 //=======================================================================
3725 //function : HilightPreviousDetected
3727 //=======================================================================
3728 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
3729 const Standard_Boolean theToRedrawImmediate)
3731 myMainPM->ClearImmediateDraw();
3732 if (myDetectedSeq.IsEmpty())
3737 if (--myCurHighlighted < myDetectedSeq.Lower())
3739 myCurHighlighted = myDetectedSeq.Upper();
3741 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
3742 if (anOwner.IsNull())
3747 highlightWithColor (anOwner, theView->Viewer());
3748 myLastPicked = anOwner;
3750 if (theToRedrawImmediate)
3752 myMainPM->RedrawImmediate (theView->Viewer());
3753 myMainVwr->RedrawImmediate();
3756 return myCurHighlighted;
3759 //=======================================================================
3760 //function : DetectedCurrentOwner
3762 //=======================================================================
3763 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
3765 return MoreDetected()
3766 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
3767 : Handle(SelectMgr_EntityOwner)();
3770 //=======================================================================
3771 //function : DetectedCurrentShape
3773 //=======================================================================
3774 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
3776 static const TopoDS_Shape AIS_InteractiveContext_myDummyShape;
3778 Standard_DISABLE_DEPRECATION_WARNINGS
3779 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
3780 Standard_ENABLE_DEPRECATION_WARNINGS
3781 return !aCurrentShape.IsNull()
3782 ? aCurrentShape->Shape()
3783 : AIS_InteractiveContext_myDummyShape;
3786 //=======================================================================
3787 //function : DetectedCurrentObject
3789 //=======================================================================
3790 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
3792 return MoreDetected()
3793 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
3794 : Handle(AIS_InteractiveObject)();
3797 //=======================================================================
3798 //function : SetSelectionModeActive
3800 //=======================================================================
3801 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
3802 const Standard_Integer theMode,
3803 const Standard_Boolean theIsActive,
3804 const AIS_SelectionModesConcurrency theActiveFilter,
3805 const Standard_Boolean theIsForce)
3807 if (theObj.IsNull())
3812 const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
3820 && theActiveFilter == AIS_SelectionModesConcurrency_Single))
3822 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3827 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3829 mgrSelector->Deactivate (theObj, aModeIter.Value());
3834 mgrSelector->Deactivate (theObj, theMode);
3840 (*aStat)->ClearSelectionModes();
3844 (*aStat)->RemoveSelectionMode (theMode);
3848 else if (theMode == -1)
3853 if ((*aStat)->SelectionModes().Size() == 1
3854 && (*aStat)->SelectionModes().First() == theMode)
3859 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3862 switch (theActiveFilter)
3864 case AIS_SelectionModesConcurrency_Single:
3866 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3868 mgrSelector->Deactivate (theObj, aModeIter.Value());
3870 (*aStat)->ClearSelectionModes();
3873 case AIS_SelectionModesConcurrency_GlobalOrLocal:
3875 const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
3876 TColStd_ListOfInteger aRemovedModes;
3877 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3879 if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
3880 || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
3882 mgrSelector->Deactivate (theObj, aModeIter.Value());
3883 aRemovedModes.Append (aModeIter.Value());
3886 if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
3888 (*aStat)->ClearSelectionModes();
3892 for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
3894 (*aStat)->RemoveSelectionMode (aModeIter.Value());
3899 case AIS_SelectionModesConcurrency_Multiple:
3904 mgrSelector->Activate (theObj, theMode);
3906 (*aStat)->AddSelectionMode (theMode);
3909 // ============================================================================
3910 // function : Activate
3912 // ============================================================================
3913 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
3914 const Standard_Boolean theIsForce)
3916 AIS_ListOfInteractive aDisplayedObjects;
3917 DisplayedObjects (aDisplayedObjects);
3918 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3920 Load (anIter.Value(), -1);
3921 Activate (anIter.Value(), theMode, theIsForce);
3925 // ============================================================================
3926 // function : Deactivate
3928 // ============================================================================
3929 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
3931 AIS_ListOfInteractive aDisplayedObjects;
3932 DisplayedObjects (aDisplayedObjects);
3933 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3935 Deactivate (anIter.Value(), theMode);
3939 // ============================================================================
3940 // function : Deactivate
3942 // ============================================================================
3943 void AIS_InteractiveContext::Deactivate()
3945 AIS_ListOfInteractive aDisplayedObjects;
3946 DisplayedObjects (aDisplayedObjects);
3948 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3950 Deactivate (anIter.Value());
3954 //=======================================================================
3955 //function : ActivatedModes
3957 //=======================================================================
3958 void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
3959 TColStd_ListOfInteger& theList) const
3961 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3962 if (aStatus != NULL)
3964 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3966 theList.Append (aModeIter.Value());
3971 //=======================================================================
3972 //function : SubIntensityOn
3974 //=======================================================================
3975 void AIS_InteractiveContext::SubIntensityOn (const Handle(AIS_InteractiveObject)& theObj,
3976 const Standard_Boolean theToUpdateViewer)
3978 turnOnSubintensity (theObj);
3979 if (theToUpdateViewer)
3981 myMainVwr->Update();
3985 //=======================================================================
3986 //function : SubIntensityOff
3988 //=======================================================================
3989 void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
3990 const Standard_Boolean theToUpdateViewer)
3992 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3994 || !(*aStatus)->IsSubIntensityOn())
3999 (*aStatus)->SetSubIntensity (false);
4000 Standard_Boolean toUpdateMain = Standard_False;
4001 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4003 myMainPM->Unhighlight (theObj);
4004 toUpdateMain = Standard_True;
4007 if (IsSelected (theObj))
4009 highlightSelected (theObj->GlobalSelOwner());
4012 if (theToUpdateViewer && toUpdateMain)
4014 myMainVwr->Update();
4018 //=======================================================================
4019 //function : DisplayActiveSensitive
4021 //=======================================================================
4022 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& theView)
4024 myMainSel->DisplaySensitive (theView);
4027 //=======================================================================
4028 //function : DisplayActiveSensitive
4030 //=======================================================================
4031 void AIS_InteractiveContext::DisplayActiveSensitive (const Handle(AIS_InteractiveObject)& theObj,
4032 const Handle(V3d_View)& theView)
4034 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
4035 if (aStatus == NULL)
4040 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
4042 const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
4043 myMainSel->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
4047 //=======================================================================
4048 //function : ClearActiveSensitive
4050 //=======================================================================
4051 void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
4053 myMainSel->ClearSensitive (theView);
4056 //=======================================================================
4057 //function : IsImmediateModeOn
4059 //=======================================================================
4060 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
4062 return myMainPM->IsImmediateModeOn();
4065 //=======================================================================
4066 //function : BeginImmediateDraw
4068 //=======================================================================
4069 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
4071 if (myMainPM->IsImmediateModeOn())
4073 myMainPM->BeginImmediateDraw();
4074 return Standard_True;
4076 return Standard_False;
4079 //=======================================================================
4080 //function : ImmediateAdd
4082 //=======================================================================
4083 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
4084 const Standard_Integer theMode)
4086 if (myMainPM->IsImmediateModeOn())
4088 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
4089 return Standard_True;
4091 return Standard_False;
4094 //=======================================================================
4095 //function : EndImmediateDraw
4097 //=======================================================================
4098 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
4100 if (myMainPM->IsImmediateModeOn())
4102 myMainPM->EndImmediateDraw (theView->Viewer());
4103 return Standard_True;
4105 return Standard_False;
4108 //=======================================================================
4109 //function : EndImmediateDraw
4111 //=======================================================================
4112 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
4114 if (myMainPM->IsImmediateModeOn())
4116 myMainPM->EndImmediateDraw (myMainVwr);
4117 return Standard_True;
4119 return Standard_False;
4122 //=======================================================================
4123 //function : SetPolygonOffsets
4125 //=======================================================================
4126 void AIS_InteractiveContext::SetPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4127 const Standard_Integer theMode,
4128 const Standard_ShortReal theFactor,
4129 const Standard_ShortReal theUnits,
4130 const Standard_Boolean theToUpdateViewer)
4132 if (theObj.IsNull())
4137 setContextToObject (theObj);
4138 theObj->SetPolygonOffsets (theMode, theFactor, theUnits);
4140 const Handle(AIS_GlobalStatus)* aStatus = theToUpdateViewer ? myObjects.Seek (theObj) : NULL;
4142 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4144 myMainVwr->Update();
4148 //=======================================================================
4149 //function : HasPolygonOffsets
4151 //=======================================================================
4152 Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj) const
4154 return !theObj.IsNull() && theObj->HasPolygonOffsets();
4157 //=======================================================================
4158 //function : PolygonOffsets
4160 //=======================================================================
4161 void AIS_InteractiveContext::PolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4162 Standard_Integer& theMode,
4163 Standard_ShortReal& theFactor,
4164 Standard_ShortReal& theUnits) const
4166 if (HasPolygonOffsets (theObj))
4168 theObj->PolygonOffsets (theMode, theFactor, theUnits);
4172 //=======================================================================
4173 //function : DumpJson
4175 //=======================================================================
4176 void AIS_InteractiveContext::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
4178 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
4180 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myObjects.Size())
4182 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mgrSelector.get())
4183 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainPM.get())
4184 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainVwr.get())
4185 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainSel.get())
4186 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastActiveView)
4188 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastPicked.get())
4190 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToHilightSelected)
4192 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mySelection.get())
4193 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myFilters.get())
4194 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myDefaultDrawer.get())
4196 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Selected])
4197 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Dynamic])
4198 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalSelected])
4199 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalDynamic])
4200 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_SubIntensity])
4202 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDetectedSeq.Size())
4204 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurDetected)
4205 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurHighlighted)
4206 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPickingStrategy)
4207 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoHilight)
4208 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsAutoActivateSelMode)