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)
687 AIS_ListOfInteractive aList;
688 ObjectsInside (aList);
689 for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next())
691 Remove (aListIterator.Value(), Standard_False);
694 if (theToUpdateViewer)
700 //=======================================================================
701 //function : HilightWithColor
703 //=======================================================================
704 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
705 const Handle(Prs3d_Drawer)& theStyle,
706 const Standard_Boolean theIsToUpdate)
711 setContextToObject (theObj);
712 if (!myObjects.IsBound (theObj))
715 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
716 aStatus->SetHilightStatus (Standard_True);
718 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
720 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
721 aStatus->SetHilightStyle (theStyle);
728 //=======================================================================
729 //function : Unhilight
731 //=======================================================================
732 void AIS_InteractiveContext::Unhilight (const Handle(AIS_InteractiveObject)& theObj,
733 const Standard_Boolean theToUpdateViewer)
735 Handle(AIS_GlobalStatus)* aStatus = !theObj.IsNull() ? myObjects.ChangeSeek (theObj) : NULL;
741 (*aStatus)->SetHilightStatus (Standard_False);
742 (*aStatus)->SetHilightStyle (Handle(Prs3d_Drawer)());
743 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
745 unhighlightGlobal (theObj);
748 if (theToUpdateViewer)
754 //=======================================================================
755 //function : IsHilighted
756 //purpose : Returns true if the objects global status is set to highlighted.
757 //=======================================================================
758 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
760 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
761 return aStatus != NULL
762 && (*aStatus)->IsHilighted();
765 //=======================================================================
766 //function : IsHilighted
767 //purpose : Returns true if the owner is highlighted with selection style.
768 //=======================================================================
769 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
771 if (theOwner.IsNull() || !theOwner->HasSelectable())
772 return Standard_False;
774 const Handle(AIS_InteractiveObject) anObj =
775 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
777 if (anObj->GlobalSelOwner() == theOwner)
779 if (!myObjects.IsBound (anObj))
780 return Standard_False;
782 return myObjects (anObj)->IsHilighted();
785 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
786 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
787 return theOwner->IsHilighted (myMainPM, aHiMode);
790 //=======================================================================
791 //function : HighlightStyle
793 //=======================================================================
794 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
795 Handle(Prs3d_Drawer)& theStyle) const
797 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
799 && (*aStatus)->IsHilighted())
801 theStyle = (*aStatus)->HilightStyle();
802 return Standard_True;
806 return Standard_False;
809 //=======================================================================
810 //function : HighlightStyle
812 //=======================================================================
813 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
814 Handle(Prs3d_Drawer)& theStyle) const
816 if (theOwner.IsNull() || !theOwner->HasSelectable())
817 return Standard_False;
819 if (IsHilighted (theOwner))
821 const Handle(AIS_InteractiveObject) anObj =
822 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
823 if (anObj->GlobalSelOwner() == theOwner)
825 theStyle = myObjects (anObj)->HilightStyle();
829 // since part selection style is not stored in global status,
830 // check if the object has own selection style. If not, it can
831 // only be highlighted with default selection style (because
832 // sub-intensity does not modify any selection states)
833 theStyle = getSelStyle (anObj, theOwner);
835 return Standard_True;
840 return Standard_False;
844 //=======================================================================
845 //function : IsDisplayed
847 //=======================================================================
849 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
851 if(theObj.IsNull()) return Standard_False;
853 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
854 return aStatus != NULL
855 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed;
858 //=======================================================================
859 //function : IsDisplayed
861 //=======================================================================
862 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
863 const Standard_Integer theMode) const
865 if (theIObj.IsNull())
867 return Standard_False;
870 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
871 return aStatus != NULL
872 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
873 && (*aStatus)->DisplayMode() == theMode;
876 //=======================================================================
877 //function : DisplayPriority
879 //=======================================================================
880 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
882 if (theIObj.IsNull())
887 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
889 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
890 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
892 Standard_Integer aDispMode = theIObj->HasDisplayMode()
893 ? theIObj->DisplayMode()
894 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
895 ? myDefaultDrawer->DisplayMode()
897 return myMainPM->DisplayPriority (theIObj, aDispMode);
902 //=======================================================================
903 //function : SetDisplayPriority
905 //=======================================================================
906 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
907 const Standard_Integer thePriority)
909 if (theIObj.IsNull())
914 setContextToObject (theIObj);
915 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
917 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
918 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
920 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
921 ? theIObj->DisplayMode()
922 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
923 ? myDefaultDrawer->DisplayMode()
925 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
929 //=======================================================================
930 //function : Redisplay
932 //=======================================================================
933 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
934 const Standard_Boolean theToUpdateViewer,
935 const Standard_Boolean theAllModes)
937 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
938 RecomputeSelectionOnly (theIObj);
941 //=======================================================================
942 //function : Redisplay
944 //=======================================================================
945 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
946 const Standard_Integer /*theSign*/,
947 const Standard_Boolean theToUpdateViewer)
949 Standard_Boolean isRedisplayed = Standard_False;
950 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
952 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
953 if (anObj->Type() != theKOI)
958 Redisplay (anObj, Standard_False);
959 isRedisplayed = anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
963 if (theToUpdateViewer
970 //=======================================================================
971 //function : RecomputePrsOnly
973 //=======================================================================
974 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
975 const Standard_Boolean theToUpdateViewer,
976 const Standard_Boolean theAllModes)
978 if (theIObj.IsNull())
983 theIObj->SetToUpdate();
984 theIObj->UpdatePresentations (theAllModes);
985 if (!theToUpdateViewer)
990 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
992 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
997 //=======================================================================
998 //function : RecomputeSelectionOnly
1000 //=======================================================================
1001 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1008 mgrSelector->RecomputeSelection (theIO);
1010 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1012 || theIO->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1017 TColStd_ListOfInteger aModes;
1018 ActivatedModes (theIO, aModes);
1019 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1020 for (; aModesIter.More(); aModesIter.Next())
1022 mgrSelector->Activate (theIO, aModesIter.Value());
1026 //=======================================================================
1029 //=======================================================================
1030 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1031 const Standard_Boolean theUpdateViewer)
1033 if (theIObj.IsNull())
1038 theIObj->UpdatePresentations();
1039 mgrSelector->Update(theIObj);
1041 if (theUpdateViewer)
1043 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1045 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1047 myMainVwr->Update();
1052 //=======================================================================
1053 //function : SetLocation
1055 //=======================================================================
1056 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1057 const TopLoc_Location& theLoc)
1059 if (theIObj.IsNull())
1064 if (theIObj->HasTransformation()
1065 && theLoc.IsIdentity())
1067 theIObj->ResetTransformation();
1068 mgrSelector->Update (theIObj, Standard_False);
1071 else if (theLoc.IsIdentity())
1076 // first reset the previous location to properly clean everything...
1077 if (theIObj->HasTransformation())
1079 theIObj->ResetTransformation();
1082 theIObj->SetLocalTransformation (theLoc.Transformation());
1084 mgrSelector->Update (theIObj, Standard_False);
1086 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1087 // to its highlight structure immediately
1088 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1090 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1091 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1097 //=======================================================================
1098 //function : ResetLocation
1100 //=======================================================================
1101 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1103 if (theIObj.IsNull())
1108 theIObj->ResetTransformation();
1109 mgrSelector->Update (theIObj, Standard_False);
1112 //=======================================================================
1113 //function : HasLocation
1115 //=======================================================================
1116 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1118 return !theIObj.IsNull()
1119 && theIObj->HasTransformation();
1122 //=======================================================================
1123 //function : Location
1125 //=======================================================================
1126 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1128 return theIObj->Transformation();
1131 //=======================================================================
1132 //function : SetDeviationCoefficient
1134 //=======================================================================
1135 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1137 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1140 //=======================================================================
1141 //function : SetDeviationAngle
1143 //=======================================================================
1144 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1146 myDefaultDrawer->SetDeviationAngle (theAngle);
1149 //=======================================================================
1150 //function : DeviationAngle
1151 //purpose : Gets deviationAngle
1152 //=======================================================================
1153 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1155 return myDefaultDrawer->DeviationAngle();
1158 //=======================================================================
1159 //function : DeviationCoefficient
1161 //=======================================================================
1162 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1164 return myDefaultDrawer->DeviationCoefficient();
1167 //=======================================================================
1168 //function : SetDisplayMode
1170 //=======================================================================
1171 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1172 const Standard_Boolean theToUpdateViewer)
1174 if (theMode == myDefaultDrawer->DisplayMode())
1179 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1181 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1182 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1183 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1184 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1187 || anObj->HasDisplayMode()
1188 || !anObj->AcceptDisplayMode (theMode))
1193 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1194 aStatus->SetDisplayMode (theMode);
1196 if (anObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1198 myMainPM->Display (anObj, theMode);
1199 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1201 myMainPM->BeginImmediateDraw();
1202 unhighlightGlobal (anObj);
1203 myMainPM->EndImmediateDraw (myMainVwr);
1205 if (aStatus->IsSubIntensityOn())
1207 highlightWithSubintensity (anObj, theMode);
1209 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1213 myDefaultDrawer->SetDisplayMode (theMode);
1214 if (theToUpdateViewer)
1216 myMainVwr->Update();
1220 //=======================================================================
1221 //function : SetDisplayMode
1223 //=======================================================================
1224 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1225 const Standard_Integer theMode,
1226 const Standard_Boolean theToUpdateViewer)
1228 setContextToObject (theIObj);
1229 if (!myObjects.IsBound (theIObj))
1231 theIObj->SetDisplayMode (theMode);
1234 else if (!theIObj->AcceptDisplayMode (theMode))
1239 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1240 if (theIObj->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1242 aStatus->SetDisplayMode (theMode);
1243 theIObj->SetDisplayMode (theMode);
1247 // erase presentations for all display modes different from <aMode>
1248 const Standard_Integer anOldMode = aStatus->DisplayMode();
1249 if (anOldMode != theMode)
1251 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1253 unhighlightGlobal (theIObj);
1255 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1258 aStatus->SetDisplayMode (theMode);
1260 myMainPM->Display (theIObj, theMode);
1261 if (aStatus->IsHilighted())
1263 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1265 if (aStatus->IsSubIntensityOn())
1267 highlightWithSubintensity (theIObj, theMode);
1270 if (theToUpdateViewer)
1272 myMainVwr->Update();
1274 theIObj->SetDisplayMode (theMode);
1277 //=======================================================================
1278 //function : UnsetDisplayMode
1280 //=======================================================================
1281 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1282 const Standard_Boolean theToUpdateViewer)
1284 if (theIObj.IsNull()
1285 || !theIObj->HasDisplayMode())
1290 if (!myObjects.IsBound (theIObj))
1292 theIObj->UnsetDisplayMode();
1296 const Standard_Integer anOldMode = theIObj->DisplayMode();
1297 if (myDefaultDrawer->DisplayMode() == anOldMode)
1302 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1303 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1305 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1307 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1309 unhighlightGlobal (theIObj);
1311 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1312 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1313 if (aStatus->IsHilighted())
1315 highlightSelected (theIObj->GlobalSelOwner());
1317 if (aStatus->IsSubIntensityOn())
1319 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1322 if (theToUpdateViewer)
1324 myMainVwr->Update();
1328 theIObj->UnsetDisplayMode();
1331 //=======================================================================
1332 //function : SetCurrentFacingModel
1334 //=======================================================================
1335 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1336 const Aspect_TypeOfFacingModel theModel)
1338 if (!theIObj.IsNull())
1340 theIObj->SetCurrentFacingModel (theModel);
1344 //=======================================================================
1345 //function : SetColor
1347 //=======================================================================
1348 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1349 const Quantity_Color& theColor,
1350 const Standard_Boolean theToUpdateViewer)
1352 if (theIObj.IsNull())
1357 setContextToObject (theIObj);
1358 theIObj->SetColor (theColor);
1359 theIObj->UpdatePresentations();
1360 if (theToUpdateViewer)
1362 UpdateCurrentViewer();
1366 //=======================================================================
1367 //function : SetIsoOnTriangulation
1369 //=======================================================================
1370 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1371 const Handle(AIS_InteractiveObject)& theObject)
1373 if (theObject.IsNull())
1378 theObject->SetIsoOnTriangulation (theIsEnabled);
1381 //=======================================================================
1382 //function : SetDeviationCoefficient
1384 //=======================================================================
1385 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1386 const Standard_Real theCoefficient,
1387 const Standard_Boolean theToUpdateViewer)
1389 if (theIObj.IsNull())
1394 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1395 setContextToObject (theIObj);
1396 if (theIObj->Type() != AIS_KindOfInteractive_Object
1397 && theIObj->Type() != AIS_KindOfInteractive_Shape)
1401 else if (theIObj->Signature() != 0)
1406 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1407 aShape->SetOwnDeviationCoefficient (theCoefficient);
1408 aShape->UpdatePresentations();
1409 if (theToUpdateViewer)
1411 UpdateCurrentViewer();
1415 //=======================================================================
1416 //function : SetDeviationAngle
1418 //=======================================================================
1419 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1420 const Standard_Real theAngle,
1421 const Standard_Boolean theToUpdateViewer)
1423 if (theIObj.IsNull())
1428 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1429 setContextToObject (theIObj);
1430 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1434 else if (theIObj->Signature() != 0)
1439 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1440 aShape->SetOwnDeviationAngle (theAngle);
1441 aShape->UpdatePresentations();
1442 if (theToUpdateViewer)
1444 UpdateCurrentViewer();
1448 //=======================================================================
1449 //function : SetAngleAndDeviation
1451 //=======================================================================
1452 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1453 const Standard_Real theAngle,
1454 const Standard_Boolean theToUpdateViewer)
1456 if (theIObj.IsNull())
1461 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1462 setContextToObject (theIObj);
1463 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1467 if (theIObj->Signature() != 0)
1472 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1473 aShape->SetAngleAndDeviation (theAngle);
1474 aShape->UpdatePresentations();
1475 if (theToUpdateViewer)
1477 UpdateCurrentViewer();
1481 //=======================================================================
1482 //function : UnsetColor
1484 //=======================================================================
1485 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1486 const Standard_Boolean theToUpdateViewer)
1488 if (theIObj.IsNull())
1493 theIObj->UnsetColor();
1494 theIObj->UpdatePresentations();
1495 if (theToUpdateViewer)
1497 UpdateCurrentViewer();
1501 //=======================================================================
1502 //function : HasColor
1504 //=======================================================================
1505 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1507 return theIObj->HasColor();
1510 //=======================================================================
1513 //=======================================================================
1514 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1515 Quantity_Color& theColor) const
1517 theIObj->Color (theColor);
1520 //=======================================================================
1523 //=======================================================================
1524 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1526 return theIObj->Width();
1529 //=======================================================================
1530 //function : SetWidth
1532 //=======================================================================
1533 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1534 const Standard_Real theWidth,
1535 const Standard_Boolean theToUpdateViewer)
1537 if (theIObj.IsNull())
1542 setContextToObject (theIObj);
1543 theIObj->SetWidth (theWidth);
1544 theIObj->UpdatePresentations();
1545 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1547 if (myLastPicked->IsAutoHilight())
1549 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1550 myLastPicked->HilightWithColor (myMainPM,
1551 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1556 theIObj->HilightOwnerWithColor (myMainPM,
1557 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1561 if (theToUpdateViewer)
1563 UpdateCurrentViewer();
1567 //=======================================================================
1568 //function : UnsetWidth
1570 //=======================================================================
1571 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1572 const Standard_Boolean theToUpdateViewer)
1574 if (theIObj.IsNull())
1579 theIObj->UnsetWidth();
1580 theIObj->UpdatePresentations();
1581 if (theToUpdateViewer)
1583 UpdateCurrentViewer();
1587 //=======================================================================
1588 //function : SetMaterial
1590 //=======================================================================
1591 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1592 const Graphic3d_MaterialAspect& theMaterial,
1593 const Standard_Boolean theToUpdateViewer)
1595 if (theIObj.IsNull())
1600 setContextToObject (theIObj);
1601 theIObj->SetMaterial (theMaterial);
1602 theIObj->UpdatePresentations();
1603 if (theToUpdateViewer)
1605 UpdateCurrentViewer();
1609 //=======================================================================
1610 //function : UnsetMaterial
1612 //=======================================================================
1613 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1614 const Standard_Boolean theToUpdateViewer)
1616 if (theIObj.IsNull())
1620 theIObj->UnsetMaterial();
1621 theIObj->UpdatePresentations();
1622 if (theToUpdateViewer)
1624 UpdateCurrentViewer();
1628 //=======================================================================
1629 //function : SetTransparency
1631 //=======================================================================
1632 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1633 const Standard_Real theValue,
1634 const Standard_Boolean theToUpdateViewer)
1636 if (theIObj.IsNull())
1641 setContextToObject (theIObj);
1642 if (!theIObj->IsTransparent()
1643 && theValue <= 0.005)
1648 if (theValue <= 0.005)
1650 UnsetTransparency (theIObj, theToUpdateViewer);
1654 theIObj->SetTransparency (theValue);
1655 theIObj->UpdatePresentations();
1656 if (theToUpdateViewer)
1658 UpdateCurrentViewer();
1662 //=======================================================================
1663 //function : UnsetTransparency
1665 //=======================================================================
1666 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1667 const Standard_Boolean theToUpdateViewer)
1669 if (theIObj.IsNull())
1674 theIObj->UnsetTransparency();
1675 theIObj->UpdatePresentations();
1676 if (theToUpdateViewer)
1678 UpdateCurrentViewer();
1682 //=======================================================================
1683 //function : SetSelectedAspect
1685 //=======================================================================
1686 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1687 const Standard_Boolean theToUpdateViewer)
1689 Standard_DISABLE_DEPRECATION_WARNINGS
1690 Standard_Boolean isFound = Standard_False;
1691 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1693 isFound = Standard_True;
1694 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1695 anObj->SetAspect (theAspect);
1697 Standard_ENABLE_DEPRECATION_WARNINGS
1699 if (isFound && theToUpdateViewer)
1701 myMainVwr->Update();
1705 //=======================================================================
1706 //function : SetLocalAttributes
1708 //=======================================================================
1709 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1710 const Handle(Prs3d_Drawer)& theDrawer,
1711 const Standard_Boolean theToUpdateViewer)
1713 if (theIObj.IsNull())
1718 setContextToObject (theIObj);
1719 theIObj->SetAttributes (theDrawer);
1720 Update (theIObj, theToUpdateViewer);
1723 //=======================================================================
1724 //function : UnsetLocalAttributes
1726 //=======================================================================
1727 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1728 const Standard_Boolean theToUpdateViewer)
1730 if (theIObj.IsNull())
1735 setContextToObject (theIObj);
1736 theIObj->UnsetAttributes();
1737 Update (theIObj, theToUpdateViewer);
1740 //=======================================================================
1743 //=======================================================================
1744 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1745 TCollection_ExtendedString& theStatus) const
1748 if (theIObj.IsNull()
1749 || !myObjects.IsBound (theIObj))
1754 theStatus += "\t ____________________________________________";
1755 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1756 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1757 switch (theIObj->DisplayStatus())
1759 case PrsMgr_DisplayStatus_Displayed:
1761 theStatus += "\t| -->Displayed\n";
1764 case PrsMgr_DisplayStatus_Erased:
1766 theStatus += "\t| -->Erased\n";
1773 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1774 theStatus += "\t|\t Mode ";
1775 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1778 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1780 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1781 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1783 theStatus += "\t\t Mode ";
1784 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1787 theStatus += "\t ____________________________________________";
1790 //=======================================================================
1791 //function : GetDefModes
1793 //=======================================================================
1794 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1795 Standard_Integer& theDispMode,
1796 Standard_Integer& theHiMode,
1797 Standard_Integer& theSelMode) const
1799 if (theIObj.IsNull())
1804 theDispMode = theIObj->HasDisplayMode()
1805 ? theIObj->DisplayMode()
1806 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1807 ? myDefaultDrawer->DisplayMode()
1809 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1810 theSelMode = theIObj->GlobalSelectionMode();
1813 //=======================================================================
1814 //function : EraseGlobal
1816 //=======================================================================
1817 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1818 const Standard_Boolean theToUpdateviewer)
1820 Handle(AIS_GlobalStatus) aStatus;
1821 if (theIObj.IsNull()
1822 || !myObjects.Find (theIObj, aStatus)
1823 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased)
1828 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1829 unselectOwners (theIObj);
1830 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1832 if (!myLastPicked.IsNull()
1833 && myLastPicked->IsSameSelectable (theIObj))
1835 clearDynamicHighlight();
1838 // make sure highlighting presentations are properly erased
1839 theIObj->ErasePresentations (false);
1841 if (IsSelected (theIObj)
1842 && aStatus->DisplayMode() != aDispMode)
1844 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1847 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1849 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1851 aStatus->ClearSelectionModes();
1852 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Erased);
1854 if (theToUpdateviewer)
1856 myMainVwr->Update();
1860 //=======================================================================
1861 //function : unselectOwners
1863 //=======================================================================
1864 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
1866 SelectMgr_SequenceOfOwner aSeq;
1867 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1869 if (aSelIter.Value()->IsSameSelectable (theObject))
1871 aSeq.Append (aSelIter.Value());
1874 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1876 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
1880 //=======================================================================
1881 //function : ClearGlobal
1883 //=======================================================================
1884 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1885 const Standard_Boolean theToUpdateviewer)
1887 Handle(AIS_GlobalStatus) aStatus;
1888 if (theIObj.IsNull()
1889 || !myObjects.Find (theIObj, aStatus))
1891 // for cases when reference shape of connected interactives was not displayed
1892 // but its selection primitives were calculated
1893 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1894 mgrSelector->Remove (anObj);
1898 unselectOwners (theIObj);
1900 myMainPM->Erase (theIObj, -1);
1901 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
1903 // Object removes from Detected sequence
1904 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
1906 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
1907 Handle(AIS_InteractiveObject) anObj;
1908 if (!aPicked.IsNull())
1910 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
1914 && anObj == theIObj)
1916 myDetectedSeq.Remove (aDetIter);
1917 if (myCurDetected == aDetIter)
1919 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
1921 if (myCurHighlighted == aDetIter)
1923 myCurHighlighted = 0;
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");
2733 myMainSel->Pick (theXPix, theYPix, theView);
2734 return moveTo (theView, theToRedrawOnUpdate);
2737 //=======================================================================
2740 //=======================================================================
2741 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const gp_Ax1& theAxis,
2742 const Handle(V3d_View)& theView,
2743 const Standard_Boolean theToRedrawOnUpdate)
2745 if (theView->Viewer() != myMainVwr)
2747 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2749 myMainSel->Pick (theAxis, theView);
2750 return moveTo (theView, theToRedrawOnUpdate);
2753 //=======================================================================
2756 //=======================================================================
2757 AIS_StatusOfDetection AIS_InteractiveContext::moveTo (const Handle(V3d_View)& theView,
2758 const Standard_Boolean theToRedrawOnUpdate)
2761 myCurHighlighted = 0;
2762 myDetectedSeq.Clear();
2763 myLastActiveView = theView.get();
2766 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
2767 Standard_Boolean toUpdateViewer = Standard_False;
2769 myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
2771 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
2772 // (the objects must be AIS_Shapes)
2773 const Standard_Integer aDetectedNb = myMainSel->NbPicked();
2774 Standard_Integer aNewDetected = 0;
2775 Standard_Boolean toIgnoreDetTop = Standard_False;
2776 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
2778 Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
2779 if (anOwner.IsNull()
2780 || !myFilters->IsOk (anOwner))
2782 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
2784 toIgnoreDetTop = Standard_True;
2789 if (aNewDetected < 1
2792 aNewDetected = aDetIter;
2795 myDetectedSeq.Append (aDetIter);
2798 if (aNewDetected >= 1)
2800 myCurHighlighted = myDetectedSeq.Lower();
2802 // Does nothing if previously detected object is equal to the current one.
2803 // However in advanced selection modes the owners comparison
2804 // is not effective because in that case only one owner manage the
2805 // selection in current selection mode. It is necessary to check the current detected
2806 // entity and hilight it only if the detected entity is not the same as
2807 // previous detected (IsForcedHilight call)
2808 Handle(SelectMgr_EntityOwner) aNewPickedOwner = myMainSel->Picked (aNewDetected);
2809 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
2811 return myLastPicked->IsSelected()
2813 : AIS_SOD_OnlyOneDetected;
2816 // Previously detected object is unhilighted if it is not selected or hilighted
2817 // with selection color if it is selected. Such highlighting with selection color
2818 // is needed only if myToHilightSelected flag is true. In this case previously detected
2819 // object has been already highlighted with myHilightColor during previous MoveTo()
2820 // method call. As result it is necessary to rehighligt it with mySelectionColor.
2821 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2823 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2825 theView->Viewer()->Invalidate();
2828 clearDynamicHighlight();
2829 toUpdateViewer = Standard_True;
2832 // initialize myLastPicked field with currently detected object
2833 myLastPicked = aNewPickedOwner;
2835 // highlight detected object if it is not selected or myToHilightSelected flag is true
2836 if (myLastPicked->HasSelectable())
2839 && (!myLastPicked->IsSelected()
2840 || myToHilightSelected))
2842 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2844 theView->Viewer()->Invalidate();
2847 highlightWithColor (myLastPicked, theView->Viewer());
2848 toUpdateViewer = Standard_True;
2851 aStatus = myLastPicked->IsSelected()
2853 : AIS_SOD_OnlyOneDetected;
2858 // previously detected object is unhilighted if it is not selected or hilighted
2859 // with selection color if it is selected
2860 aStatus = AIS_SOD_Nothing;
2862 && !myLastPicked.IsNull()
2863 && myLastPicked->HasSelectable())
2865 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2867 theView->Viewer()->Invalidate();
2870 clearDynamicHighlight();
2871 toUpdateViewer = Standard_True;
2874 myLastPicked.Nullify();
2878 && theToRedrawOnUpdate)
2880 if (theView->ComputedMode())
2882 theView->Viewer()->Update();
2886 if (theView->IsInvalidated())
2888 theView->Viewer()->Redraw();
2892 theView->Viewer()->RedrawImmediate();
2900 //=======================================================================
2901 //function : AddSelect
2903 //=======================================================================
2904 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
2906 mySelection->AddSelect (theObject);
2908 Standard_Integer aSelNum = NbSelected();
2909 return (aSelNum == 0) ? AIS_SOP_NothingSelected
2910 : (aSelNum == 1) ? AIS_SOP_OneSelected
2911 : AIS_SOP_SeveralSelected;
2914 //=======================================================================
2915 //function : SelectRectangle
2917 //=======================================================================
2918 AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i& thePntMin,
2919 const Graphic3d_Vec2i& thePntMax,
2920 const Handle(V3d_View)& theView,
2921 const AIS_SelectionScheme theSelScheme)
2923 if (theView->Viewer() != myMainVwr)
2925 throw Standard_ProgramError ("AIS_InteractiveContext::SelectRectangle() - invalid argument");
2928 myLastActiveView = theView.get();
2929 myMainSel->Pick (thePntMin.x(), thePntMin.y(), thePntMax.x(), thePntMax.y(), theView);
2931 AIS_NArray1OfEntityOwner aPickedOwners;
2932 if (myMainSel->NbPicked() > 0)
2934 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2935 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2937 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2941 return Select (aPickedOwners, theSelScheme);
2944 //=======================================================================
2945 //function : SelectPolygon
2947 //=======================================================================
2948 AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt2d& thePolyline,
2949 const Handle(V3d_View)& theView,
2950 const AIS_SelectionScheme theSelScheme)
2952 if (theView->Viewer() != myMainVwr)
2954 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPolygon() - invalid argument");
2957 myLastActiveView = theView.get();
2958 myMainSel->Pick (thePolyline, theView);
2960 AIS_NArray1OfEntityOwner aPickedOwners;
2961 if (myMainSel->NbPicked() > 0)
2963 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2964 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2966 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2970 return Select (aPickedOwners, theSelScheme);
2973 //=======================================================================
2974 //function : SelectPoint
2976 //=======================================================================
2977 AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i& thePnt,
2978 const Handle(V3d_View)& theView,
2979 const AIS_SelectionScheme theSelScheme)
2981 if (theView->Viewer() != myMainVwr)
2983 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPoint() - invalid argument");
2986 myLastActiveView = theView.get();
2987 myMainSel->Pick (thePnt.x(), thePnt.y(), theView);
2989 AIS_NArray1OfEntityOwner aPickedOwners;
2990 if (myMainSel->NbPicked() > 0)
2992 aPickedOwners.Resize (1, myMainSel->NbPicked(), false);
2993 for (Standard_Integer aPickIter = 1; aPickIter <= myMainSel->NbPicked(); ++aPickIter)
2995 aPickedOwners.SetValue (aPickIter, myMainSel->Picked (aPickIter));
2999 return Select (aPickedOwners, theSelScheme);
3002 //=======================================================================
3003 //function : SelectDetected
3005 //=======================================================================
3006 AIS_StatusOfPick AIS_InteractiveContext::SelectDetected (const AIS_SelectionScheme theSelScheme)
3008 if (theSelScheme == AIS_SelectionScheme_Replace && !myLastPicked.IsNull())
3010 Graphic3d_Vec2i aMousePos (-1, -1);
3011 gp_Pnt2d aMouseRealPos = myMainSel->GetManager().GetMousePosition();
3012 if (!Precision::IsInfinite (aMouseRealPos.X()) &&
3013 !Precision::IsInfinite (aMouseRealPos.Y()))
3015 aMousePos.SetValues ((Standard_Integer )aMouseRealPos.X(), (Standard_Integer )aMouseRealPos.Y());
3017 if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
3019 return AIS_SOP_NothingSelected;
3023 AIS_NArray1OfEntityOwner aPickedOwners (1, 1);
3024 aPickedOwners.SetValue (1, myLastPicked);
3025 return Select (aPickedOwners, theSelScheme);
3028 //=======================================================================
3031 //=======================================================================
3032 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
3033 const Standard_Integer theYPMin,
3034 const Standard_Integer theXPMax,
3035 const Standard_Integer theYPMax,
3036 const Handle(V3d_View)& theView,
3037 const Standard_Boolean theToUpdateViewer)
3039 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
3040 Graphic3d_Vec2i (theXPMax, theYPMax),
3042 if (theToUpdateViewer)
3044 UpdateCurrentViewer();
3049 //=======================================================================
3051 //purpose : Selection by polyline
3052 //=======================================================================
3053 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
3054 const Handle(V3d_View)& theView,
3055 const Standard_Boolean theToUpdateViewer)
3057 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView);
3058 if (theToUpdateViewer)
3060 UpdateCurrentViewer();
3065 //=======================================================================
3068 //=======================================================================
3069 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean theToUpdateViewer)
3071 AIS_StatusOfPick aStatus = SelectDetected();
3072 if (theToUpdateViewer)
3074 UpdateCurrentViewer();
3079 //=======================================================================
3080 //function : ShiftSelect
3082 //=======================================================================
3083 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean theToUpdateViewer)
3085 AIS_StatusOfPick aStatus = SelectDetected (AIS_SelectionScheme_XOR);
3086 if (theToUpdateViewer)
3088 UpdateCurrentViewer();
3093 //=======================================================================
3094 //function : ShiftSelect
3096 //=======================================================================
3097 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
3098 const Standard_Integer theYPMin,
3099 const Standard_Integer theXPMax,
3100 const Standard_Integer theYPMax,
3101 const Handle(V3d_View)& theView,
3102 const Standard_Boolean theToUpdateViewer)
3104 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
3105 Graphic3d_Vec2i (theXPMax, theYPMax),
3107 AIS_SelectionScheme_XOR);
3108 if (theToUpdateViewer)
3110 UpdateCurrentViewer();
3115 //=======================================================================
3116 //function : ShiftSelect
3118 //=======================================================================
3119 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
3120 const Handle(V3d_View)& theView,
3121 const Standard_Boolean theToUpdateViewer)
3123 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView, AIS_SelectionScheme_XOR);
3124 if (theToUpdateViewer)
3126 UpdateCurrentViewer();
3131 //=======================================================================
3134 //=======================================================================
3135 AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners,
3136 const AIS_SelectionScheme theSelScheme)
3138 NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> aSelOwnerMap (myAutoHilight ? mySelection->Objects().Size() : 0);
3141 clearDynamicHighlight();
3143 // collect currently selected owners
3144 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3146 aSelOwnerMap.Add (anOwnerIter.Value());
3150 mySelection->SelectOwners (theOwners, theSelScheme, myMainSel->GetManager().IsOverlapAllowed(), myFilters);
3154 // collect lists of owners to unhighlight (unselected) and to highlight (selected)
3155 AIS_NListOfEntityOwner anOwnersToUnhighlight, anOwnersToHighlight;
3156 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3158 // add newly selected owners
3159 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3160 if (!aSelOwnerMap.RemoveKey (anOwner))
3162 // newly selected owner
3163 anOwnersToHighlight.Append (anOwner);
3167 // already selected owner
3168 if (!anOwner->IsAutoHilight()
3169 && theSelScheme != AIS_SelectionScheme_XOR
3170 && theSelScheme != AIS_SelectionScheme_Add)
3172 // hack to perform AIS_InteractiveObject::ClearSelected() before highlighting
3173 anOwnersToUnhighlight.Append (anOwner);
3174 anOwnersToHighlight.Append (anOwner);
3176 else if (anOwner->IsForcedHilight()
3177 || !anOwner->IsAutoHilight())
3179 anOwnersToHighlight.Append (anOwner);
3184 for (NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)>::Iterator anOwnerIter (aSelOwnerMap); anOwnerIter.More(); anOwnerIter.Next())
3186 // owners removed from selection
3187 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3188 anOwnersToUnhighlight.Append (anOwner);
3191 unhighlightOwners (anOwnersToUnhighlight);
3192 highlightOwners (anOwnersToHighlight, Handle(Prs3d_Drawer)());
3195 Standard_Integer aSelNum = NbSelected();
3196 return (aSelNum == 0) ? AIS_SOP_NothingSelected
3197 : (aSelNum == 1) ? AIS_SOP_OneSelected
3198 : AIS_SOP_SeveralSelected;
3201 //=======================================================================
3202 //function : HilightSelected
3204 //=======================================================================
3205 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
3207 // In case of selection without using local context
3208 clearDynamicHighlight();
3210 highlightOwners (mySelection->Objects(), Handle(Prs3d_Drawer)());
3212 if (theToUpdateViewer)
3214 UpdateCurrentViewer();
3218 //=======================================================================
3219 //function : highlightOwners
3221 //=======================================================================
3222 void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners,
3223 const Handle(Prs3d_Drawer)& theStyle)
3225 NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > anObjOwnerMap;
3226 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
3228 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
3229 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3233 const Handle(Prs3d_Drawer)& anObjSelStyle = !theStyle.IsNull() ? theStyle : getSelStyle (anObj, anOwner);
3234 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3239 if (anOwner == anObj->GlobalSelOwner())
3241 (*aStatusPtr)->SetHilightStatus (Standard_True);
3242 (*aStatusPtr)->SetHilightStyle (anObjSelStyle);
3244 if (!anOwner->IsAutoHilight())
3246 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
3247 if (anObjOwnerMap.Find (anObj, aSeq))
3249 aSeq->Append (anOwner);
3253 aSeq = new SelectMgr_SequenceOfOwner();
3254 aSeq->Append (anOwner);
3255 anObjOwnerMap.Bind (anObj, aSeq);
3260 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, (*aStatusPtr)->DisplayMode());
3261 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3265 if (!anObjOwnerMap.IsEmpty())
3267 for (NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> >::Iterator anIter (anObjOwnerMap);
3268 anIter.More(); anIter.Next())
3270 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
3272 anObjOwnerMap.Clear();
3276 //=======================================================================
3277 //function : UnhilightSelected
3279 //=======================================================================
3280 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
3282 unhighlightSelected();
3284 if (theToUpdateViewer)
3286 UpdateCurrentViewer();
3290 //=======================================================================
3291 //function : ClearSelected
3293 //=======================================================================
3294 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
3296 if (NbSelected() == 0)
3303 unhighlightSelected();
3306 mySelection->Clear();
3309 clearDynamicHighlight();
3312 if (theToUpdateViewer)
3314 UpdateCurrentViewer();
3318 //=======================================================================
3319 //function : SetSelected
3320 //purpose : Sets the whole object as selected and highlights it with selection color
3321 //=======================================================================
3322 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
3323 const Standard_Boolean theToUpdateViewer)
3325 if (theObject.IsNull())
3330 if (!myObjects.IsBound (theObject))
3335 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3336 if (anOwner.IsNull())
3341 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
3342 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
3344 Handle(Prs3d_Drawer) aCustomStyle;
3345 if (HighlightStyle (theObject, aCustomStyle))
3347 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3349 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
3355 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
3357 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
3358 if (!myFilters->IsOk (aSelOwner))
3363 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
3366 Unhilight (aSelectable, Standard_False);
3368 if (aSelOwner == aSelectable->GlobalSelOwner())
3370 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (aSelectable))
3372 (*aStatusPtr)->SetHilightStatus (Standard_False);
3377 // added to avoid untimely viewer update...
3378 mySelection->ClearAndSelect (anOwner);
3382 Handle(Prs3d_Drawer) aCustomStyle;
3383 if (HighlightStyle (theObject, aCustomStyle))
3385 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3387 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3392 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3396 if (theToUpdateViewer)
3398 UpdateCurrentViewer();
3402 //=======================================================================
3403 //function : SetSelected
3404 //purpose : Sets the whole object as selected and highlights it with selection color
3405 //=======================================================================
3406 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3407 const Standard_Boolean theToUpdateViewer)
3409 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
3414 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3415 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
3416 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
3418 Handle(Prs3d_Drawer) aCustomStyle;
3419 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
3421 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3423 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
3424 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3430 if (!myObjects.IsBound (anObject))
3437 unhighlightSelected();
3440 mySelection->ClearAndSelect (theOwner);
3443 Handle(Prs3d_Drawer) aCustomStyle;
3444 if (!HighlightStyle (theOwner, aCustomStyle) ||
3445 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
3447 highlightSelected (theOwner);
3451 if (theToUpdateViewer)
3453 UpdateCurrentViewer();
3457 //=======================================================================
3458 //function : AddOrRemoveSelected
3460 //=======================================================================
3461 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
3462 const Standard_Boolean theToUpdateViewer)
3464 if (theObject.IsNull()
3465 || !myObjects.IsBound (theObject))
3470 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3471 if (!anOwner.IsNull()
3472 && anOwner->HasSelectable())
3474 AddOrRemoveSelected (anOwner, theToUpdateViewer);
3478 //=======================================================================
3479 //function : AddOrRemoveSelected
3480 //purpose : Allows to highlight or unhighlight the owner given depending on
3481 // its selection status
3482 //=======================================================================
3483 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3484 const Standard_Boolean theToUpdateViewer)
3486 if (theOwner.IsNull() || !theOwner->HasSelectable())
3491 if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
3496 mySelection->Select (theOwner);
3500 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3501 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3507 if (theOwner->IsSelected())
3509 highlightSelected (theOwner);
3513 AIS_NListOfEntityOwner anOwners;
3514 anOwners.Append (theOwner);
3515 unhighlightOwners (anOwners);
3517 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
3521 if (theToUpdateViewer)
3523 UpdateCurrentViewer();
3527 // =======================================================================
3528 // function : SetSelectedState
3530 // =======================================================================
3531 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
3532 const Standard_Boolean theIsSelected)
3534 if (theEntity.IsNull())
3536 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
3539 if (!theEntity->HasSelectable()
3540 || mySelection->IsSelected (theEntity) == theIsSelected)
3545 if (theEntity->IsAutoHilight())
3547 AddOrRemoveSelected (theEntity, false);
3553 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
3554 theEntity->SetSelected (true);
3555 return aSelStatus == AIS_SS_Added;
3559 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
3560 theEntity->SetSelected (false);
3561 return aSelStatus == AIS_SS_Removed;
3565 //=======================================================================
3566 //function : IsSelected
3568 //=======================================================================
3569 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
3571 if (theObj.IsNull())
3573 return Standard_False;
3576 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3577 if (aStatus == NULL)
3579 return Standard_False;
3582 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
3583 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
3584 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
3586 if (aModeIter.Value() == aGlobalSelMode)
3588 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
3590 return aGlobOwner->IsSelected();
3592 return Standard_False;
3595 return Standard_False;
3598 //=======================================================================
3599 //function : FirstSelectedObject
3601 //=======================================================================
3602 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
3604 return !mySelection->Objects().IsEmpty()
3605 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
3606 : Handle(AIS_InteractiveObject)();
3609 //=======================================================================
3610 //function : HasSelectedShape
3612 //=======================================================================
3613 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
3615 if (!mySelection->More())
3617 return Standard_False;
3620 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3621 return !anOwner.IsNull() && anOwner->HasShape();
3624 //=======================================================================
3625 //function : SelectedShape
3627 //=======================================================================
3628 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
3630 if (!mySelection->More())
3632 return TopoDS_Shape();
3635 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3636 if (anOwner.IsNull() || !anOwner->HasSelectable())
3638 return TopoDS_Shape();
3641 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
3644 //=======================================================================
3645 //function : EntityOwners
3647 //=======================================================================
3648 void AIS_InteractiveContext::EntityOwners (Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
3649 const Handle(AIS_InteractiveObject)& theIObj,
3650 const Standard_Integer theMode) const
3652 if (theIObj.IsNull())
3657 TColStd_ListOfInteger aModes;
3660 ActivatedModes (theIObj, aModes);
3664 aModes.Append (theMode);
3667 if (theOwners.IsNull())
3669 theOwners = new SelectMgr_IndexedMapOfOwner();
3672 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
3674 const int aMode = anItr.Value();
3675 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
3681 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
3683 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
3685 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
3687 theOwners->Add (aOwner);
3694 //=======================================================================
3695 //function : HasDetectedShape
3697 //=======================================================================
3698 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
3700 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3701 return !anOwner.IsNull()
3702 && anOwner->HasShape();
3705 //=======================================================================
3706 //function : DetectedShape
3708 //=======================================================================
3709 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
3711 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3712 return anOwner->Shape();
3715 //=======================================================================
3716 //function : HilightNextDetected
3718 //=======================================================================
3719 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
3720 const Standard_Boolean theToRedrawImmediate)
3722 myMainPM->ClearImmediateDraw();
3723 if (myDetectedSeq.IsEmpty())
3728 if (++myCurHighlighted > myDetectedSeq.Upper())
3730 myCurHighlighted = myDetectedSeq.Lower();
3732 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
3733 if (anOwner.IsNull())
3738 highlightWithColor (anOwner, theView->Viewer());
3739 myLastPicked = anOwner;
3741 if (theToRedrawImmediate)
3743 myMainPM->RedrawImmediate (theView->Viewer());
3744 myMainVwr->RedrawImmediate();
3747 return myCurHighlighted;
3750 //=======================================================================
3751 //function : HilightPreviousDetected
3753 //=======================================================================
3754 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
3755 const Standard_Boolean theToRedrawImmediate)
3757 myMainPM->ClearImmediateDraw();
3758 if (myDetectedSeq.IsEmpty())
3763 if (--myCurHighlighted < myDetectedSeq.Lower())
3765 myCurHighlighted = myDetectedSeq.Upper();
3767 const Handle(SelectMgr_EntityOwner)& anOwner = myMainSel->Picked (myDetectedSeq (myCurHighlighted));
3768 if (anOwner.IsNull())
3773 highlightWithColor (anOwner, theView->Viewer());
3774 myLastPicked = anOwner;
3776 if (theToRedrawImmediate)
3778 myMainPM->RedrawImmediate (theView->Viewer());
3779 myMainVwr->RedrawImmediate();
3782 return myCurHighlighted;
3785 //=======================================================================
3786 //function : DetectedCurrentOwner
3788 //=======================================================================
3789 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
3791 return MoreDetected()
3792 ? myMainSel->Picked (myDetectedSeq (myCurDetected))
3793 : Handle(SelectMgr_EntityOwner)();
3796 //=======================================================================
3797 //function : DetectedCurrentShape
3799 //=======================================================================
3800 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
3802 static const TopoDS_Shape AIS_InteractiveContext_myDummyShape;
3804 Standard_DISABLE_DEPRECATION_WARNINGS
3805 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
3806 Standard_ENABLE_DEPRECATION_WARNINGS
3807 return !aCurrentShape.IsNull()
3808 ? aCurrentShape->Shape()
3809 : AIS_InteractiveContext_myDummyShape;
3812 //=======================================================================
3813 //function : DetectedCurrentObject
3815 //=======================================================================
3816 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
3818 return MoreDetected()
3819 ? Handle(AIS_InteractiveObject)::DownCast (myMainSel->Picked (myDetectedSeq (myCurDetected))->Selectable())
3820 : Handle(AIS_InteractiveObject)();
3823 //=======================================================================
3824 //function : SetSelectionModeActive
3826 //=======================================================================
3827 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
3828 const Standard_Integer theMode,
3829 const Standard_Boolean theIsActive,
3830 const AIS_SelectionModesConcurrency theActiveFilter,
3831 const Standard_Boolean theIsForce)
3833 if (theObj.IsNull())
3838 const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
3846 && theActiveFilter == AIS_SelectionModesConcurrency_Single))
3848 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3853 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3855 mgrSelector->Deactivate (theObj, aModeIter.Value());
3860 mgrSelector->Deactivate (theObj, theMode);
3866 (*aStat)->ClearSelectionModes();
3870 (*aStat)->RemoveSelectionMode (theMode);
3874 else if (theMode == -1)
3879 if ((*aStat)->SelectionModes().Size() == 1
3880 && (*aStat)->SelectionModes().First() == theMode)
3885 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3888 switch (theActiveFilter)
3890 case AIS_SelectionModesConcurrency_Single:
3892 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3894 mgrSelector->Deactivate (theObj, aModeIter.Value());
3896 (*aStat)->ClearSelectionModes();
3899 case AIS_SelectionModesConcurrency_GlobalOrLocal:
3901 const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
3902 TColStd_ListOfInteger aRemovedModes;
3903 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3905 if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
3906 || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
3908 mgrSelector->Deactivate (theObj, aModeIter.Value());
3909 aRemovedModes.Append (aModeIter.Value());
3912 if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
3914 (*aStat)->ClearSelectionModes();
3918 for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
3920 (*aStat)->RemoveSelectionMode (aModeIter.Value());
3925 case AIS_SelectionModesConcurrency_Multiple:
3930 mgrSelector->Activate (theObj, theMode);
3932 (*aStat)->AddSelectionMode (theMode);
3935 // ============================================================================
3936 // function : Activate
3938 // ============================================================================
3939 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
3940 const Standard_Boolean theIsForce)
3942 AIS_ListOfInteractive aDisplayedObjects;
3943 DisplayedObjects (aDisplayedObjects);
3944 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3946 Load (anIter.Value(), -1);
3947 Activate (anIter.Value(), theMode, theIsForce);
3951 // ============================================================================
3952 // function : Deactivate
3954 // ============================================================================
3955 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
3957 AIS_ListOfInteractive aDisplayedObjects;
3958 DisplayedObjects (aDisplayedObjects);
3959 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3961 Deactivate (anIter.Value(), theMode);
3965 // ============================================================================
3966 // function : Deactivate
3968 // ============================================================================
3969 void AIS_InteractiveContext::Deactivate()
3971 AIS_ListOfInteractive aDisplayedObjects;
3972 DisplayedObjects (aDisplayedObjects);
3974 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3976 Deactivate (anIter.Value());
3980 //=======================================================================
3981 //function : ActivatedModes
3983 //=======================================================================
3984 void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
3985 TColStd_ListOfInteger& theList) const
3987 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3988 if (aStatus != NULL)
3990 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3992 theList.Append (aModeIter.Value());
3997 //=======================================================================
3998 //function : SubIntensityOn
4000 //=======================================================================
4001 void AIS_InteractiveContext::SubIntensityOn (const Handle(AIS_InteractiveObject)& theObj,
4002 const Standard_Boolean theToUpdateViewer)
4004 turnOnSubintensity (theObj);
4005 if (theToUpdateViewer)
4007 myMainVwr->Update();
4011 //=======================================================================
4012 //function : SubIntensityOff
4014 //=======================================================================
4015 void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
4016 const Standard_Boolean theToUpdateViewer)
4018 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
4020 || !(*aStatus)->IsSubIntensityOn())
4025 (*aStatus)->SetSubIntensity (false);
4026 Standard_Boolean toUpdateMain = Standard_False;
4027 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4029 myMainPM->Unhighlight (theObj);
4030 toUpdateMain = Standard_True;
4033 if (IsSelected (theObj))
4035 highlightSelected (theObj->GlobalSelOwner());
4038 if (theToUpdateViewer && toUpdateMain)
4040 myMainVwr->Update();
4044 //=======================================================================
4045 //function : DisplayActiveSensitive
4047 //=======================================================================
4048 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& theView)
4050 myMainSel->DisplaySensitive (theView);
4053 //=======================================================================
4054 //function : DisplayActiveSensitive
4056 //=======================================================================
4057 void AIS_InteractiveContext::DisplayActiveSensitive (const Handle(AIS_InteractiveObject)& theObj,
4058 const Handle(V3d_View)& theView)
4060 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
4061 if (aStatus == NULL)
4066 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
4068 const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
4069 myMainSel->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
4073 //=======================================================================
4074 //function : ClearActiveSensitive
4076 //=======================================================================
4077 void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
4079 myMainSel->ClearSensitive (theView);
4082 //=======================================================================
4083 //function : IsImmediateModeOn
4085 //=======================================================================
4086 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
4088 return myMainPM->IsImmediateModeOn();
4091 //=======================================================================
4092 //function : BeginImmediateDraw
4094 //=======================================================================
4095 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
4097 if (myMainPM->IsImmediateModeOn())
4099 myMainPM->BeginImmediateDraw();
4100 return Standard_True;
4102 return Standard_False;
4105 //=======================================================================
4106 //function : ImmediateAdd
4108 //=======================================================================
4109 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
4110 const Standard_Integer theMode)
4112 if (myMainPM->IsImmediateModeOn())
4114 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
4115 return Standard_True;
4117 return Standard_False;
4120 //=======================================================================
4121 //function : EndImmediateDraw
4123 //=======================================================================
4124 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
4126 if (myMainPM->IsImmediateModeOn())
4128 myMainPM->EndImmediateDraw (theView->Viewer());
4129 return Standard_True;
4131 return Standard_False;
4134 //=======================================================================
4135 //function : EndImmediateDraw
4137 //=======================================================================
4138 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
4140 if (myMainPM->IsImmediateModeOn())
4142 myMainPM->EndImmediateDraw (myMainVwr);
4143 return Standard_True;
4145 return Standard_False;
4148 //=======================================================================
4149 //function : SetPolygonOffsets
4151 //=======================================================================
4152 void AIS_InteractiveContext::SetPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4153 const Standard_Integer theMode,
4154 const Standard_ShortReal theFactor,
4155 const Standard_ShortReal theUnits,
4156 const Standard_Boolean theToUpdateViewer)
4158 if (theObj.IsNull())
4163 setContextToObject (theObj);
4164 theObj->SetPolygonOffsets (theMode, theFactor, theUnits);
4166 const Handle(AIS_GlobalStatus)* aStatus = theToUpdateViewer ? myObjects.Seek (theObj) : NULL;
4168 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4170 myMainVwr->Update();
4174 //=======================================================================
4175 //function : HasPolygonOffsets
4177 //=======================================================================
4178 Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj) const
4180 return !theObj.IsNull() && theObj->HasPolygonOffsets();
4183 //=======================================================================
4184 //function : PolygonOffsets
4186 //=======================================================================
4187 void AIS_InteractiveContext::PolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4188 Standard_Integer& theMode,
4189 Standard_ShortReal& theFactor,
4190 Standard_ShortReal& theUnits) const
4192 if (HasPolygonOffsets (theObj))
4194 theObj->PolygonOffsets (theMode, theFactor, theUnits);
4198 //=======================================================================
4199 //function : DumpJson
4201 //=======================================================================
4202 void AIS_InteractiveContext::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
4204 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
4206 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myObjects.Size())
4208 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mgrSelector.get())
4209 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainPM.get())
4210 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainVwr.get())
4211 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainSel.get())
4212 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastActiveView)
4214 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastPicked.get())
4216 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToHilightSelected)
4218 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mySelection.get())
4219 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myFilters.get())
4220 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myDefaultDrawer.get())
4222 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Selected])
4223 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Dynamic])
4224 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalSelected])
4225 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalDynamic])
4226 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_SubIntensity])
4228 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDetectedSeq.Size())
4230 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurDetected)
4231 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurHighlighted)
4232 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPickingStrategy)
4233 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoHilight)
4234 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsAutoActivateSelMode)