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 <Precision.hxx>
25 #include <Prs3d_DatumAspect.hxx>
26 #include <Prs3d_IsoAspect.hxx>
27 #include <Prs3d_LineAspect.hxx>
28 #include <Prs3d_PlaneAspect.hxx>
29 #include <Prs3d_PointAspect.hxx>
30 #include <Prs3d_ShadingAspect.hxx>
31 #include <SelectMgr_EntityOwner.hxx>
32 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
33 #include <TopLoc_Location.hxx>
34 #include <V3d_View.hxx>
35 #include <V3d_Viewer.hxx>
37 #include <AIS_Shape.hxx>
38 #include <StdSelect_BRepOwner.hxx>
39 #include <TopoDS_Shape.hxx>
41 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
45 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
46 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
48 //! Initialize default highlighting attributes.
49 static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
50 const Quantity_Color& theColor)
52 theDrawer->SetMethod (Aspect_TOHM_COLOR);
53 theDrawer->SetDisplayMode (0);
54 theDrawer->SetColor (theColor);
56 theDrawer->SetupOwnShadingAspect();
57 theDrawer->SetupOwnPointAspect();
58 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
59 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
60 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
61 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
62 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
63 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
64 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
65 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
66 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
67 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
68 theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
70 theDrawer->ShadingAspect()->SetColor (theColor);
71 theDrawer->WireAspect()->SetColor (theColor);
72 theDrawer->LineAspect()->SetColor (theColor);
73 theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
74 theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
75 theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
76 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
77 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
78 theDrawer->PointAspect()->SetColor (theColor);
79 for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_None; ++aPartIter)
81 if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
83 aLineAsp->SetColor (theColor);
87 theDrawer->WireAspect()->SetWidth (2.0);
88 theDrawer->LineAspect()->SetWidth (2.0);
89 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
90 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
91 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
92 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
93 theDrawer->PointAspect()->SetScale (2.0);
95 // the triangulation should be computed using main presentation attributes,
96 // and should not be overridden by highlighting
97 theDrawer->SetAutoTriangulation (Standard_False);
101 //=======================================================================
102 //function : AIS_InteractiveContext
104 //=======================================================================
106 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
107 myMainPM (new PrsMgr_PresentationManager (MainViewer->StructureManager())),
108 myMainVwr(MainViewer),
109 myToHilightSelected(Standard_True),
110 mySelection(new AIS_Selection()),
111 myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)),
112 myDefaultDrawer(new Prs3d_Drawer()),
115 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
116 myAutoHilight(Standard_True),
117 myIsAutoActivateSelMode(Standard_True)
119 mgrSelector = new SelectMgr_SelectionManager (new StdSelect_ViewerSelector3d());
121 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
122 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
123 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
124 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
125 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
126 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
128 myDefaultDrawer->SetupOwnDefaults();
129 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
130 myDefaultDrawer->SetDisplayMode(0);
132 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
133 aStyle->Link (myDefaultDrawer);
134 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
135 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
138 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
139 aStyle->Link (myDefaultDrawer);
140 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
141 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
144 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
145 aStyle->Link (myDefaultDrawer);
146 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
147 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
150 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
151 aStyle->Link (myDefaultDrawer);
152 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
153 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
156 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
157 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
158 aStyle->SetMethod(Aspect_TOHM_COLOR);
159 aStyle->SetColor (Quantity_NOC_GRAY40);
165 //=======================================================================
166 //function : ~AIS_InteractiveContext
168 //=======================================================================
169 AIS_InteractiveContext::~AIS_InteractiveContext()
171 // clear the current selection
172 mySelection->Clear();
173 mgrSelector.Nullify();
175 Handle(AIS_InteractiveContext) aNullContext;
176 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
178 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
179 anObj->SetContext (aNullContext);
180 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
182 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
187 //=======================================================================
188 //function : LastActiveView
190 //=======================================================================
191 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
193 if (myLastActiveView == NULL
194 || myMainVwr.IsNull())
196 return Handle(V3d_View)();
199 // as a precaution - check that myLastActiveView pointer is a valid active View
200 for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
202 if (aViewIter.Value() == myLastActiveView)
204 return aViewIter.Value();
207 return Handle(V3d_View)();
210 //=======================================================================
211 //function : UpdateCurrentViewer
213 //=======================================================================
215 void AIS_InteractiveContext::UpdateCurrentViewer()
217 if (!myMainVwr.IsNull())
221 //=======================================================================
222 //function : DisplayedObjects
224 //=======================================================================
225 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
227 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
229 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
231 theListOfIO.Append (anObjIter.Key());
236 //=======================================================================
237 //function : DisplayedObjects
239 //=======================================================================
240 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
241 const Standard_Integer theSign,
242 AIS_ListOfInteractive& theListOfIO) const
244 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Displayed, theListOfIO);
247 //=======================================================================
248 //function : ErasedObjects
250 //=======================================================================
251 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
253 ObjectsByDisplayStatus (PrsMgr_DisplayStatus_Erased, theListOfIO);
256 //=======================================================================
257 //function : ErasedObjects
259 //=======================================================================
260 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
261 const Standard_Integer theSign,
262 AIS_ListOfInteractive& theListOfIO) const
264 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Erased, theListOfIO);
267 //=======================================================================
268 //function : ObjectsByDisplayStatus
270 //=======================================================================
271 void AIS_InteractiveContext::ObjectsByDisplayStatus (const PrsMgr_DisplayStatus theStatus,
272 AIS_ListOfInteractive& theListOfIO) const
274 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
276 if (anObjIter.Key()->DisplayStatus() == theStatus)
278 theListOfIO.Append (anObjIter.Key());
283 //=======================================================================
284 //function : ObjectsByDisplayStatus
286 //=======================================================================
287 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
288 const Standard_Integer theSign,
289 const PrsMgr_DisplayStatus theStatus,
290 AIS_ListOfInteractive& theListOfIO) const
292 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
294 if (theStatus != PrsMgr_DisplayStatus_None
295 && anObjIter.Key()->DisplayStatus() != theStatus)
299 else if (anObjIter.Key()->Type() != theKind)
305 || anObjIter.Key()->Signature() == theSign)
307 theListOfIO.Append (anObjIter.Key());
312 //=======================================================================
313 //function : ObjectsInside
315 //=======================================================================
316 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
317 const AIS_KindOfInteractive theKind,
318 const Standard_Integer theSign) const
320 if (theKind == AIS_KindOfInteractive_None
323 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
325 theListOfIO.Append (anObjIter.Key());
330 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
332 if (anObjIter.Key()->Type() != theKind)
338 || anObjIter.Key()->Signature() == theSign)
340 theListOfIO.Append (anObjIter.Key());
345 //=======================================================================
346 //function : ObjectsForView
348 //=======================================================================
349 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
350 const Handle(V3d_View)& theView,
351 const Standard_Boolean theIsVisibleInView,
352 const PrsMgr_DisplayStatus theStatus) const
354 Handle(Graphic3d_CView) aViewImpl = theView->View();
355 const Standard_Integer aViewId = aViewImpl->Identification();
356 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
358 if (theStatus != PrsMgr_DisplayStatus_None
359 && anObjIter.Key()->DisplayStatus() != theStatus)
361 theListOfIO.Append (anObjIter.Key());
365 Handle(Graphic3d_ViewAffinity) anAffinity = anObjIter.Key()->ViewAffinity();
366 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
367 if (isVisible == theIsVisibleInView)
369 theListOfIO.Append (anObjIter.Key());
374 //=======================================================================
377 //=======================================================================
378 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
379 const Standard_Boolean theToUpdateViewer)
381 if (theIObj.IsNull())
386 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
387 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
388 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
391 //=======================================================================
392 //function : SetViewAffinity
394 //=======================================================================
395 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
396 const Handle(V3d_View)& theView,
397 const Standard_Boolean theIsVisible)
400 || !myObjects.IsBound (theIObj))
405 Handle(Graphic3d_ViewAffinity) anAffinity = theIObj->ViewAffinity();
406 Handle(Graphic3d_CView) aViewImpl = theView->View();
407 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
410 //=======================================================================
413 //=======================================================================
414 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
415 const Standard_Integer theDispMode,
416 const Standard_Integer theSelectionMode,
417 const Standard_Boolean theToUpdateViewer,
418 const PrsMgr_DisplayStatus theDispStatus)
420 if (theIObj.IsNull())
425 if (theDispStatus == PrsMgr_DisplayStatus_Erased)
427 Erase (theIObj, theToUpdateViewer);
428 Load (theIObj, theSelectionMode);
429 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
431 (*aStatusPtr)->SetDisplayMode (theDispMode);
436 setContextToObject (theIObj);
437 if (!myObjects.IsBound (theIObj))
439 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
440 theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
441 myMainVwr->StructureManager()->RegisterObject (theIObj, theIObj->ViewAffinity());
442 myMainPM->Display(theIObj, theDispMode);
443 if (theSelectionMode != -1)
445 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
446 if (!mgrSelector->Contains (anObj))
448 mgrSelector->Load (theIObj);
450 mgrSelector->Activate (theIObj, theSelectionMode);
455 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
457 // Mark the presentation modes hidden of interactive object different from aDispMode.
458 // Then make sure aDispMode is displayed and maybe highlighted.
459 // Finally, activate selection mode <SelMode> if not yet activated.
460 const Standard_Integer anOldMode = aStatus->DisplayMode();
461 if (anOldMode != theDispMode)
463 if(myMainPM->IsHighlighted (theIObj, anOldMode))
465 unhighlightGlobal (theIObj);
467 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
470 aStatus->SetDisplayMode (theDispMode);
472 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Displayed);
473 myMainPM->Display (theIObj, theDispMode);
474 if (aStatus->IsHilighted())
476 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
478 if (theSelectionMode != -1)
480 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
481 if (!mgrSelector->Contains (anObj))
483 mgrSelector->Load (theIObj);
485 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
487 aStatus->AddSelectionMode (theSelectionMode);
488 mgrSelector->Activate (theIObj, theSelectionMode);
493 if (theToUpdateViewer)
499 //=======================================================================
502 //=======================================================================
503 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
504 const Standard_Integer theSelMode)
506 if (theIObj.IsNull())
511 setContextToObject (theIObj);
512 if (!myObjects.IsBound (theIObj))
514 Standard_Integer aDispMode, aHiMod, aSelModeDef;
515 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
516 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
517 theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
518 myMainVwr->StructureManager()->RegisterObject (theIObj, theIObj->ViewAffinity());
521 // Register theIObj in the selection manager to prepare further activation of selection
522 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
523 if (!mgrSelector->Contains (anObj))
525 mgrSelector->Load (theIObj);
529 //=======================================================================
532 //=======================================================================
533 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
534 const Standard_Boolean theToUpdateViewer)
536 if (theIObj.IsNull())
541 if (!theIObj->IsAutoHilight())
543 theIObj->ClearSelected();
546 EraseGlobal (theIObj, Standard_False);
547 if (theToUpdateViewer)
553 //=======================================================================
554 //function : EraseAll
556 //=======================================================================
557 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
559 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
561 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
563 Erase (anObjIter.Key(), Standard_False);
567 if (theToUpdateViewer)
573 //=======================================================================
574 //function : DisplayAll
576 //=======================================================================
577 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
579 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
581 const PrsMgr_DisplayStatus aStatus = anObjIter.Key()->DisplayStatus();
582 if (aStatus == PrsMgr_DisplayStatus_Erased)
584 Display (anObjIter.Key(), Standard_False);
588 if (theToUpdateViewer)
594 //=======================================================================
595 //function : DisplaySelected
597 //=======================================================================
598 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
600 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
602 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
603 Display (anObj, Standard_False);
606 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
612 //=======================================================================
613 //function : EraseSelected
615 //=======================================================================
616 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
618 Standard_Boolean isFound = Standard_False;
619 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
621 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
622 Erase (anObj, Standard_False);
623 isFound = Standard_True;
626 if (isFound && theToUpdateViewer)
632 //=======================================================================
633 //function : DisplayStatus
635 //=======================================================================
636 PrsMgr_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
638 if (theIObj.IsNull())
640 return PrsMgr_DisplayStatus_None;
642 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
643 return aStatus != NULL ? theIObj->DisplayStatus() : PrsMgr_DisplayStatus_None;
646 //=======================================================================
649 //=======================================================================
650 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
651 const Standard_Boolean theToUpdateViewer)
653 if (theIObj.IsNull())
658 if (theIObj->HasInteractiveContext())
660 if (theIObj->myCTXPtr != this)
662 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
664 theIObj->SetContext (Handle(AIS_InteractiveContext)());
666 ClearGlobal (theIObj, theToUpdateViewer);
669 //=======================================================================
670 //function : RemoveAll
672 //=======================================================================
673 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
677 AIS_ListOfInteractive aList;
678 ObjectsInside (aList);
679 for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next())
681 Remove (aListIterator.Value(), Standard_False);
684 if (theToUpdateViewer)
690 //=======================================================================
691 //function : HilightWithColor
693 //=======================================================================
694 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
695 const Handle(Prs3d_Drawer)& theStyle,
696 const Standard_Boolean theIsToUpdate)
703 setContextToObject (theObj);
704 if (!myObjects.IsBound (theObj))
709 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
710 aStatus->SetHilightStatus (Standard_True);
712 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
714 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
715 aStatus->SetHilightStyle (theStyle);
724 //=======================================================================
725 //function : Unhilight
727 //=======================================================================
728 void AIS_InteractiveContext::Unhilight (const Handle(AIS_InteractiveObject)& theObj,
729 const Standard_Boolean theToUpdateViewer)
731 Handle(AIS_GlobalStatus)* aStatus = !theObj.IsNull() ? myObjects.ChangeSeek (theObj) : NULL;
737 (*aStatus)->SetHilightStatus (Standard_False);
738 (*aStatus)->SetHilightStyle (Handle(Prs3d_Drawer)());
739 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
741 unhighlightGlobal (theObj);
744 if (theToUpdateViewer)
750 //=======================================================================
751 //function : IsHilighted
752 //purpose : Returns true if the objects global status is set to highlighted.
753 //=======================================================================
754 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
756 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
757 return aStatus != NULL
758 && (*aStatus)->IsHilighted();
761 //=======================================================================
762 //function : IsHilighted
763 //purpose : Returns true if the owner is highlighted with selection style.
764 //=======================================================================
765 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
767 if (theOwner.IsNull() || !theOwner->HasSelectable())
768 return Standard_False;
770 const Handle(AIS_InteractiveObject) anObj =
771 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
773 if (anObj->GlobalSelOwner() == theOwner)
775 if (!myObjects.IsBound (anObj))
776 return Standard_False;
778 return myObjects (anObj)->IsHilighted();
781 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
782 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
783 return theOwner->IsHilighted (myMainPM, aHiMode);
786 //=======================================================================
787 //function : HighlightStyle
789 //=======================================================================
790 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
791 Handle(Prs3d_Drawer)& theStyle) const
793 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
795 && (*aStatus)->IsHilighted())
797 theStyle = (*aStatus)->HilightStyle();
798 return Standard_True;
802 return Standard_False;
805 //=======================================================================
806 //function : HighlightStyle
808 //=======================================================================
809 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
810 Handle(Prs3d_Drawer)& theStyle) const
812 if (theOwner.IsNull() || !theOwner->HasSelectable())
813 return Standard_False;
815 if (IsHilighted (theOwner))
817 const Handle(AIS_InteractiveObject) anObj =
818 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
819 if (anObj->GlobalSelOwner() == theOwner)
821 theStyle = myObjects (anObj)->HilightStyle();
825 // since part selection style is not stored in global status,
826 // check if the object has own selection style. If not, it can
827 // only be highlighted with default selection style (because
828 // sub-intensity does not modify any selection states)
829 theStyle = getSelStyle (anObj, theOwner);
831 return Standard_True;
836 return Standard_False;
840 //=======================================================================
841 //function : IsDisplayed
843 //=======================================================================
845 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
847 if(theObj.IsNull()) return Standard_False;
849 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
850 return aStatus != NULL
851 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed;
854 //=======================================================================
855 //function : IsDisplayed
857 //=======================================================================
858 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
859 const Standard_Integer theMode) const
861 if (theIObj.IsNull())
863 return Standard_False;
866 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
867 return aStatus != NULL
868 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
869 && (*aStatus)->DisplayMode() == theMode;
872 //=======================================================================
873 //function : DisplayPriority
875 //=======================================================================
876 Graphic3d_DisplayPriority AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
878 if (theIObj.IsNull())
880 return Graphic3d_DisplayPriority_INVALID;
883 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
885 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
886 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
888 Standard_Integer aDispMode = theIObj->HasDisplayMode()
889 ? theIObj->DisplayMode()
890 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
891 ? myDefaultDrawer->DisplayMode()
893 return myMainPM->DisplayPriority (theIObj, aDispMode);
895 return Graphic3d_DisplayPriority_INVALID;
898 //=======================================================================
899 //function : SetDisplayPriority
901 //=======================================================================
902 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
903 const Graphic3d_DisplayPriority thePriority)
905 if (theIObj.IsNull())
910 setContextToObject (theIObj);
911 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
913 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
914 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
916 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
917 ? theIObj->DisplayMode()
918 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
919 ? myDefaultDrawer->DisplayMode()
921 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
925 //=======================================================================
926 //function : Redisplay
928 //=======================================================================
929 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
930 const Standard_Boolean theToUpdateViewer,
931 const Standard_Boolean theAllModes)
933 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
934 RecomputeSelectionOnly (theIObj);
937 //=======================================================================
938 //function : Redisplay
940 //=======================================================================
941 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
942 const Standard_Integer /*theSign*/,
943 const Standard_Boolean theToUpdateViewer)
945 Standard_Boolean isRedisplayed = Standard_False;
946 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
948 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
949 if (anObj->Type() != theKOI)
954 Redisplay (anObj, Standard_False);
955 isRedisplayed = anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
959 if (theToUpdateViewer
966 //=======================================================================
967 //function : RecomputePrsOnly
969 //=======================================================================
970 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
971 const Standard_Boolean theToUpdateViewer,
972 const Standard_Boolean theAllModes)
974 if (theIObj.IsNull())
979 theIObj->SetToUpdate();
980 theIObj->UpdatePresentations (theAllModes);
981 if (!theToUpdateViewer)
986 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
988 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
993 //=======================================================================
994 //function : RecomputeSelectionOnly
996 //=======================================================================
997 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1004 TColStd_ListOfInteger aModes;
1005 ActivatedModes (theIO, aModes);
1007 for (TColStd_ListIteratorOfListOfInteger aModesIter (aModes); aModesIter.More(); aModesIter.Next())
1009 mgrSelector->Deactivate (theIO, aModesIter.Value());
1012 mgrSelector->RecomputeSelection (theIO);
1014 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1016 || theIO->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1021 for (TColStd_ListIteratorOfListOfInteger aModesIter (aModes); aModesIter.More(); aModesIter.Next())
1023 mgrSelector->Activate (theIO, aModesIter.Value());
1027 //=======================================================================
1030 //=======================================================================
1031 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1032 const Standard_Boolean theUpdateViewer)
1034 if (theIObj.IsNull())
1039 theIObj->UpdatePresentations();
1040 mgrSelector->Update(theIObj);
1042 if (theUpdateViewer)
1044 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1046 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1048 myMainVwr->Update();
1053 //=======================================================================
1054 //function : SetLocation
1056 //=======================================================================
1057 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1058 const TopLoc_Location& theLoc)
1060 if (theIObj.IsNull())
1065 if (theIObj->HasTransformation()
1066 && theLoc.IsIdentity())
1068 theIObj->ResetTransformation();
1069 mgrSelector->Update (theIObj, Standard_False);
1072 else if (theLoc.IsIdentity())
1077 // first reset the previous location to properly clean everything...
1078 if (theIObj->HasTransformation())
1080 theIObj->ResetTransformation();
1083 theIObj->SetLocalTransformation (theLoc.Transformation());
1085 mgrSelector->Update (theIObj, Standard_False);
1087 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1088 // to its highlight structure immediately
1089 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1091 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1092 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1098 //=======================================================================
1099 //function : ResetLocation
1101 //=======================================================================
1102 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1104 if (theIObj.IsNull())
1109 theIObj->ResetTransformation();
1110 mgrSelector->Update (theIObj, Standard_False);
1113 //=======================================================================
1114 //function : HasLocation
1116 //=======================================================================
1117 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1119 return !theIObj.IsNull()
1120 && theIObj->HasTransformation();
1123 //=======================================================================
1124 //function : Location
1126 //=======================================================================
1127 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1129 return theIObj->Transformation();
1132 //=======================================================================
1133 //function : SetDisplayMode
1135 //=======================================================================
1136 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1137 const Standard_Boolean theToUpdateViewer)
1139 if (theMode == myDefaultDrawer->DisplayMode())
1144 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1146 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1147 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1148 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1149 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1152 || anObj->HasDisplayMode()
1153 || !anObj->AcceptDisplayMode (theMode))
1158 const Handle(AIS_GlobalStatus)& aStatus = anObjIter.Value();
1159 aStatus->SetDisplayMode (theMode);
1161 if (anObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1163 myMainPM->Display (anObj, theMode);
1164 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1166 myMainPM->BeginImmediateDraw();
1167 unhighlightGlobal (anObj);
1168 myMainPM->EndImmediateDraw (myMainVwr);
1170 if (aStatus->IsSubIntensityOn())
1172 highlightWithSubintensity (anObj, theMode);
1174 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1178 myDefaultDrawer->SetDisplayMode (theMode);
1179 if (theToUpdateViewer)
1181 myMainVwr->Update();
1185 //=======================================================================
1186 //function : SetDisplayMode
1188 //=======================================================================
1189 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1190 const Standard_Integer theMode,
1191 const Standard_Boolean theToUpdateViewer)
1193 setContextToObject (theIObj);
1194 if (!myObjects.IsBound (theIObj))
1196 theIObj->SetDisplayMode (theMode);
1199 else if (!theIObj->AcceptDisplayMode (theMode))
1204 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1205 if (theIObj->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1207 aStatus->SetDisplayMode (theMode);
1208 theIObj->SetDisplayMode (theMode);
1212 // erase presentations for all display modes different from <aMode>
1213 const Standard_Integer anOldMode = aStatus->DisplayMode();
1214 if (anOldMode != theMode)
1216 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1218 unhighlightGlobal (theIObj);
1220 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1223 aStatus->SetDisplayMode (theMode);
1225 myMainPM->Display (theIObj, theMode);
1226 if (aStatus->IsHilighted())
1228 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1230 if (aStatus->IsSubIntensityOn())
1232 highlightWithSubintensity (theIObj, theMode);
1235 if (theToUpdateViewer)
1237 myMainVwr->Update();
1239 theIObj->SetDisplayMode (theMode);
1242 //=======================================================================
1243 //function : UnsetDisplayMode
1245 //=======================================================================
1246 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1247 const Standard_Boolean theToUpdateViewer)
1249 if (theIObj.IsNull()
1250 || !theIObj->HasDisplayMode())
1255 if (!myObjects.IsBound (theIObj))
1257 theIObj->UnsetDisplayMode();
1261 const Standard_Integer anOldMode = theIObj->DisplayMode();
1262 if (myDefaultDrawer->DisplayMode() == anOldMode)
1267 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1268 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1270 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1272 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1274 unhighlightGlobal (theIObj);
1276 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1277 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1278 if (aStatus->IsHilighted())
1280 highlightSelected (theIObj->GlobalSelOwner());
1282 if (aStatus->IsSubIntensityOn())
1284 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1287 if (theToUpdateViewer)
1289 myMainVwr->Update();
1293 theIObj->UnsetDisplayMode();
1296 //=======================================================================
1297 //function : SetCurrentFacingModel
1299 //=======================================================================
1300 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1301 const Aspect_TypeOfFacingModel theModel)
1303 if (!theIObj.IsNull())
1305 theIObj->SetCurrentFacingModel (theModel);
1309 //=======================================================================
1310 //function : SetColor
1312 //=======================================================================
1313 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1314 const Quantity_Color& theColor,
1315 const Standard_Boolean theToUpdateViewer)
1317 if (theIObj.IsNull())
1322 setContextToObject (theIObj);
1323 theIObj->SetColor (theColor);
1324 theIObj->UpdatePresentations();
1325 if (theToUpdateViewer)
1327 UpdateCurrentViewer();
1331 //=======================================================================
1332 //function : SetIsoOnTriangulation
1334 //=======================================================================
1335 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1336 const Handle(AIS_InteractiveObject)& theObject)
1338 if (theObject.IsNull())
1343 theObject->SetIsoOnTriangulation (theIsEnabled);
1346 //=======================================================================
1347 //function : SetDeviationCoefficient
1349 //=======================================================================
1350 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1351 const Standard_Real theCoefficient,
1352 const Standard_Boolean theToUpdateViewer)
1354 if (theIObj.IsNull())
1359 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1360 setContextToObject (theIObj);
1361 if (theIObj->Type() != AIS_KindOfInteractive_Object
1362 && theIObj->Type() != AIS_KindOfInteractive_Shape)
1366 else if (theIObj->Signature() != 0)
1371 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1372 aShape->SetOwnDeviationCoefficient (theCoefficient);
1373 aShape->UpdatePresentations();
1374 if (theToUpdateViewer)
1376 UpdateCurrentViewer();
1380 //=======================================================================
1381 //function : SetDeviationAngle
1383 //=======================================================================
1384 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1385 const Standard_Real theAngle,
1386 const Standard_Boolean theToUpdateViewer)
1388 if (theIObj.IsNull())
1393 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1394 setContextToObject (theIObj);
1395 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1399 else if (theIObj->Signature() != 0)
1404 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1405 aShape->SetOwnDeviationAngle (theAngle);
1406 aShape->UpdatePresentations();
1407 if (theToUpdateViewer)
1409 UpdateCurrentViewer();
1413 //=======================================================================
1414 //function : SetAngleAndDeviation
1416 //=======================================================================
1417 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1418 const Standard_Real theAngle,
1419 const Standard_Boolean theToUpdateViewer)
1421 if (theIObj.IsNull())
1426 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1427 setContextToObject (theIObj);
1428 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1432 if (theIObj->Signature() != 0)
1437 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1438 aShape->SetAngleAndDeviation (theAngle);
1439 aShape->UpdatePresentations();
1440 if (theToUpdateViewer)
1442 UpdateCurrentViewer();
1446 //=======================================================================
1447 //function : UnsetColor
1449 //=======================================================================
1450 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1451 const Standard_Boolean theToUpdateViewer)
1453 if (theIObj.IsNull())
1458 theIObj->UnsetColor();
1459 theIObj->UpdatePresentations();
1460 if (theToUpdateViewer)
1462 UpdateCurrentViewer();
1466 //=======================================================================
1467 //function : HasColor
1469 //=======================================================================
1470 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1472 return theIObj->HasColor();
1475 //=======================================================================
1478 //=======================================================================
1479 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1480 Quantity_Color& theColor) const
1482 theIObj->Color (theColor);
1485 //=======================================================================
1488 //=======================================================================
1489 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1491 return theIObj->Width();
1494 //=======================================================================
1495 //function : SetWidth
1497 //=======================================================================
1498 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1499 const Standard_Real theWidth,
1500 const Standard_Boolean theToUpdateViewer)
1502 if (theIObj.IsNull())
1507 setContextToObject (theIObj);
1508 theIObj->SetWidth (theWidth);
1509 theIObj->UpdatePresentations();
1510 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1512 if (myLastPicked->IsAutoHilight())
1514 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1515 myLastPicked->HilightWithColor (myMainPM,
1516 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1521 theIObj->HilightOwnerWithColor (myMainPM,
1522 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1526 if (theToUpdateViewer)
1528 UpdateCurrentViewer();
1532 //=======================================================================
1533 //function : UnsetWidth
1535 //=======================================================================
1536 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1537 const Standard_Boolean theToUpdateViewer)
1539 if (theIObj.IsNull())
1544 theIObj->UnsetWidth();
1545 theIObj->UpdatePresentations();
1546 if (theToUpdateViewer)
1548 UpdateCurrentViewer();
1552 //=======================================================================
1553 //function : SetMaterial
1555 //=======================================================================
1556 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1557 const Graphic3d_MaterialAspect& theMaterial,
1558 const Standard_Boolean theToUpdateViewer)
1560 if (theIObj.IsNull())
1565 setContextToObject (theIObj);
1566 theIObj->SetMaterial (theMaterial);
1567 theIObj->UpdatePresentations();
1568 if (theToUpdateViewer)
1570 UpdateCurrentViewer();
1574 //=======================================================================
1575 //function : UnsetMaterial
1577 //=======================================================================
1578 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1579 const Standard_Boolean theToUpdateViewer)
1581 if (theIObj.IsNull())
1585 theIObj->UnsetMaterial();
1586 theIObj->UpdatePresentations();
1587 if (theToUpdateViewer)
1589 UpdateCurrentViewer();
1593 //=======================================================================
1594 //function : SetTransparency
1596 //=======================================================================
1597 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1598 const Standard_Real theValue,
1599 const Standard_Boolean theToUpdateViewer)
1601 if (theIObj.IsNull())
1606 setContextToObject (theIObj);
1607 if (!theIObj->IsTransparent()
1608 && theValue <= 0.005)
1613 if (theValue <= 0.005)
1615 UnsetTransparency (theIObj, theToUpdateViewer);
1619 theIObj->SetTransparency (theValue);
1620 theIObj->UpdatePresentations();
1621 if (theToUpdateViewer)
1623 UpdateCurrentViewer();
1627 //=======================================================================
1628 //function : UnsetTransparency
1630 //=======================================================================
1631 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1632 const Standard_Boolean theToUpdateViewer)
1634 if (theIObj.IsNull())
1639 theIObj->UnsetTransparency();
1640 theIObj->UpdatePresentations();
1641 if (theToUpdateViewer)
1643 UpdateCurrentViewer();
1647 //=======================================================================
1648 //function : SetSelectedAspect
1650 //=======================================================================
1651 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1652 const Standard_Boolean theToUpdateViewer)
1654 Standard_DISABLE_DEPRECATION_WARNINGS
1655 Standard_Boolean isFound = Standard_False;
1656 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1658 isFound = Standard_True;
1659 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1660 anObj->SetAspect (theAspect);
1662 Standard_ENABLE_DEPRECATION_WARNINGS
1664 if (isFound && theToUpdateViewer)
1666 myMainVwr->Update();
1670 //=======================================================================
1671 //function : SetLocalAttributes
1673 //=======================================================================
1674 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1675 const Handle(Prs3d_Drawer)& theDrawer,
1676 const Standard_Boolean theToUpdateViewer)
1678 if (theIObj.IsNull())
1683 setContextToObject (theIObj);
1684 theIObj->SetAttributes (theDrawer);
1685 Update (theIObj, theToUpdateViewer);
1688 //=======================================================================
1689 //function : UnsetLocalAttributes
1691 //=======================================================================
1692 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1693 const Standard_Boolean theToUpdateViewer)
1695 if (theIObj.IsNull())
1700 setContextToObject (theIObj);
1701 theIObj->UnsetAttributes();
1702 Update (theIObj, theToUpdateViewer);
1705 //=======================================================================
1708 //=======================================================================
1709 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1710 TCollection_ExtendedString& theStatus) const
1713 if (theIObj.IsNull()
1714 || !myObjects.IsBound (theIObj))
1719 theStatus += "\t ____________________________________________";
1720 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1721 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1722 switch (theIObj->DisplayStatus())
1724 case PrsMgr_DisplayStatus_Displayed:
1726 theStatus += "\t| -->Displayed\n";
1729 case PrsMgr_DisplayStatus_Erased:
1731 theStatus += "\t| -->Erased\n";
1738 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1739 theStatus += "\t|\t Mode ";
1740 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1743 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1745 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1746 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1748 theStatus += "\t\t Mode ";
1749 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1752 theStatus += "\t ____________________________________________";
1755 //=======================================================================
1756 //function : GetDefModes
1758 //=======================================================================
1759 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1760 Standard_Integer& theDispMode,
1761 Standard_Integer& theHiMode,
1762 Standard_Integer& theSelMode) const
1764 if (theIObj.IsNull())
1769 theDispMode = theIObj->HasDisplayMode()
1770 ? theIObj->DisplayMode()
1771 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1772 ? myDefaultDrawer->DisplayMode()
1774 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1775 theSelMode = theIObj->GlobalSelectionMode();
1778 //=======================================================================
1779 //function : EraseGlobal
1781 //=======================================================================
1782 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1783 const Standard_Boolean theToUpdateviewer)
1785 Handle(AIS_GlobalStatus) aStatus;
1786 if (theIObj.IsNull()
1787 || !myObjects.Find (theIObj, aStatus)
1788 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased)
1793 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1794 unselectOwners (theIObj);
1795 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1797 if (!myLastPicked.IsNull()
1798 && myLastPicked->IsSameSelectable (theIObj))
1800 clearDynamicHighlight();
1803 // make sure highlighting presentations are properly erased
1804 theIObj->ErasePresentations (false);
1806 if (IsSelected (theIObj)
1807 && aStatus->DisplayMode() != aDispMode)
1809 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1812 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1814 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1816 aStatus->ClearSelectionModes();
1817 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Erased);
1819 if (theToUpdateviewer)
1821 myMainVwr->Update();
1825 //=======================================================================
1826 //function : unselectOwners
1828 //=======================================================================
1829 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
1831 SelectMgr_SequenceOfOwner aSeq;
1832 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1834 if (aSelIter.Value()->IsSameSelectable (theObject))
1836 aSeq.Append (aSelIter.Value());
1839 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1841 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
1845 //=======================================================================
1846 //function : ClearGlobal
1848 //=======================================================================
1849 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1850 const Standard_Boolean theToUpdateviewer)
1852 Handle(AIS_GlobalStatus) aStatus;
1853 if (theIObj.IsNull()
1854 || !myObjects.Find (theIObj, aStatus))
1856 // for cases when reference shape of connected interactives was not displayed
1857 // but its selection primitives were calculated
1858 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1859 mgrSelector->Remove (anObj);
1863 unselectOwners (theIObj);
1865 myMainPM->Erase (theIObj, -1);
1866 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
1868 // Object removes from Detected sequence
1869 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
1871 Handle(SelectMgr_EntityOwner) aPicked = MainSelector()->Picked (myDetectedSeq (aDetIter));
1872 Handle(AIS_InteractiveObject) anObj;
1873 if (!aPicked.IsNull())
1875 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
1879 && anObj == theIObj)
1881 myDetectedSeq.Remove (aDetIter);
1882 if (myCurDetected == aDetIter)
1884 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
1886 if (myCurHighlighted == aDetIter)
1888 myCurHighlighted = 0;
1897 // remove IO from the selection manager to avoid memory leaks
1898 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1899 mgrSelector->Remove (anObj);
1901 setObjectStatus (theIObj, PrsMgr_DisplayStatus_None, -1, -1);
1902 theIObj->ViewAffinity()->SetVisible (true); // reset view affinity mask
1903 myMainVwr->StructureManager()->UnregisterObject (theIObj);
1905 if (!myLastPicked.IsNull())
1907 if (myLastPicked->IsSameSelectable (theIObj))
1909 clearDynamicHighlight();
1910 myLastPicked.Nullify();
1914 if (theToUpdateviewer
1915 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1917 myMainVwr->Update();
1921 //=======================================================================
1922 //function : ClearGlobalPrs
1924 //=======================================================================
1925 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
1926 const Standard_Integer theMode,
1927 const Standard_Boolean theToUpdateViewer)
1929 const Handle(AIS_GlobalStatus)* aStatus = !theIObj.IsNull() ? myObjects.Seek (theIObj) : NULL;
1930 if (aStatus == NULL)
1935 if ((*aStatus)->DisplayMode() == theMode)
1937 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1938 if (aDispMode == theMode
1939 && myMainPM->IsHighlighted (theIObj, theMode))
1941 unhighlightGlobal (theIObj);
1944 myMainPM->Erase (theIObj, theMode);
1947 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
1948 && theToUpdateViewer)
1950 myMainVwr->Update();
1954 //=======================================================================
1955 //function : ClearDetected
1957 //=======================================================================
1958 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
1961 myCurHighlighted = 0;
1962 myDetectedSeq.Clear();
1963 Standard_Boolean toUpdate = Standard_False;
1964 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
1966 toUpdate = Standard_True;
1967 clearDynamicHighlight();
1969 myLastPicked.Nullify();
1970 MainSelector()->ClearPicked();
1971 if (toUpdate && theToRedrawImmediate)
1973 myMainVwr->RedrawImmediate();
1978 //=======================================================================
1979 //function : SetIsoNumber
1981 //=======================================================================
1982 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
1983 const AIS_TypeOfIso theType)
1988 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
1991 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
1994 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
1995 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2000 //=======================================================================
2001 //function : IsoNumber
2003 //=======================================================================
2004 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2008 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2009 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2010 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2011 ? myDefaultDrawer->UIsoAspect()->Number()
2017 //=======================================================================
2018 //function : SetPixelTolerance
2020 //=======================================================================
2021 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2023 MainSelector()->SetPixelTolerance (thePrecision);
2026 //=======================================================================
2027 //function : PixelTolerance
2029 //=======================================================================
2030 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2032 return MainSelector()->PixelTolerance();
2035 //=======================================================================
2036 //function : SetSelectionSensitivity
2037 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2038 //=======================================================================
2039 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2040 const Standard_Integer theMode,
2041 const Standard_Integer theNewSensitivity)
2043 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2046 //=======================================================================
2047 //function : InitAttributes
2049 //=======================================================================
2050 void AIS_InteractiveContext::InitAttributes()
2052 Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Brass);
2053 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2055 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2056 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2057 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2058 aLineAspect->SetWidth (1.0);
2059 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2061 // tolerance to 2 pixels...
2062 SetPixelTolerance (2);
2064 // Customizing the drawer for trihedrons and planes...
2065 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2066 const Standard_Real aLength = 100.0;
2067 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2068 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2069 aTrihAspect->LineAspect(Prs3d_DatumParts_XAxis)->SetColor (aColor);
2070 aTrihAspect->LineAspect(Prs3d_DatumParts_YAxis)->SetColor (aColor);
2071 aTrihAspect->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor (aColor);
2073 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2074 const Standard_Real aPlaneLength = 200.0;
2075 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2076 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2079 //=======================================================================
2080 //function : TrihedronSize
2082 //=======================================================================
2083 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2085 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
2088 //=======================================================================
2089 //function : SetTrihedronSize
2091 //=======================================================================
2092 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2093 const Standard_Boolean /*updateviewer*/)
2095 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2096 Redisplay (AIS_KindOfInteractive_Datum, 3, Standard_False);
2097 Redisplay (AIS_KindOfInteractive_Datum, 4, Standard_True);
2100 //=======================================================================
2101 //function : SetPlaneSize
2103 //=======================================================================
2104 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2105 const Standard_Real theValY,
2106 const Standard_Boolean theToUpdateViewer)
2108 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2109 Redisplay (AIS_KindOfInteractive_Datum, 7, theToUpdateViewer);
2112 //=======================================================================
2113 //function : SetPlaneSize
2115 //=======================================================================
2116 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2117 const Standard_Boolean theToUpdateViewer)
2119 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2122 //=======================================================================
2123 //function : PlaneSize
2125 //=======================================================================
2126 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2127 Standard_Real& theY) const
2129 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2130 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2131 return (Abs (theX - theY) <= Precision::Confusion());
2134 //=======================================================================
2135 //function : SetZLayer
2137 //=======================================================================
2138 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2139 const Graphic3d_ZLayerId theLayerId)
2141 if (theIObj.IsNull())
2144 theIObj->SetZLayer (theLayerId);
2147 //=======================================================================
2148 //function : GetZLayer
2150 //=======================================================================
2151 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2153 return !theIObj.IsNull()
2155 : Graphic3d_ZLayerId_UNKNOWN;
2158 //=======================================================================
2159 //function : RebuildSelectionStructs
2160 //purpose : Rebuilds 1st level of BVH selection forcibly
2161 //=======================================================================
2162 void AIS_InteractiveContext::RebuildSelectionStructs()
2164 MainSelector()->RebuildObjectsTree (Standard_True);
2167 //=======================================================================
2168 //function : Disconnect
2169 //purpose : Disconnects selectable object from an assembly and updates selection structures
2170 //=======================================================================
2171 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2172 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2174 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2176 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2177 theObj->Disconnect (theObjToDisconnect);
2178 if (!myObjects.IsBound (theObjToDisconnect))
2180 // connected presentation might contain displayed presentations
2181 myMainPM->Erase (theObjToDisconnect, -1);
2182 theObjToDisconnect->ErasePresentations (true);
2185 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2186 mgrSelector->Remove (anObj);
2188 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2190 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2191 theObj->Disconnect();
2192 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2193 mgrSelector->Remove (anObj);
2199 //=======================================================================
2200 //function : FitSelected
2201 //purpose : Fits the view corresponding to the bounds of selected objects
2202 //=======================================================================
2203 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2205 FitSelected (theView, 0.01, Standard_True);
2208 //=======================================================================
2209 //function : BoundingBoxOfSelection
2211 //=======================================================================
2212 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection (const Handle(V3d_View)& theView) const
2214 Bnd_Box aBndSelected;
2215 AIS_MapOfObjectOwners anObjectOwnerMap;
2216 const Standard_Integer aViewId = !theView.IsNull() ? theView->View()->Identification() : -1;
2217 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2219 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2220 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2221 if (anObj->IsInfinite())
2226 Handle(Graphic3d_ViewAffinity) anAffinity = anObj->ViewAffinity();
2227 const Standard_Boolean isVisible = aViewId == -1 || anAffinity->IsVisible (aViewId);
2233 if (anOwner == anObj->GlobalSelOwner())
2236 anObj->BoundingBox (aTmpBnd);
2237 aBndSelected.Add (aTmpBnd);
2241 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2242 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2244 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2245 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2248 anOwnerMap->Add (anOwner);
2252 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2254 const Handle(SelectMgr_SelectableObject)& anObject = anIter.Key();
2255 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2256 aBndSelected.Add (aTmpBox);
2259 return aBndSelected;
2262 //=======================================================================
2263 //function : FitSelected
2264 //purpose : Fits the view corresponding to the bounds of selected objects
2265 //=======================================================================
2266 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2267 const Standard_Real theMargin,
2268 const Standard_Boolean theToUpdate)
2270 Bnd_Box aBndSelected = BoundingBoxOfSelection (theView);
2271 if (!aBndSelected.IsVoid())
2273 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2277 //=======================================================================
2278 //function : SetTransformPersistence
2280 //=======================================================================
2281 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2282 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2284 theObject->SetTransformPersistence (theTrsfPers);
2285 if (!myObjects.IsBound (theObject))
2290 mgrSelector->UpdateSelection (theObject);
2292 const Graphic3d_ZLayerId aLayerId = theObject->ZLayer();
2293 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2294 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2296 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2297 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2301 //=======================================================================
2302 //function : GravityPoint
2304 //=======================================================================
2305 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2307 return theView->GravityPoint();
2310 //=======================================================================
2311 //function : setContextToObject
2313 //=======================================================================
2314 void AIS_InteractiveContext::setContextToObject (const Handle(AIS_InteractiveObject)& theObj)
2316 if (theObj->HasInteractiveContext())
2318 if (theObj->myCTXPtr != this)
2320 throw Standard_ProgramError("AIS_InteractiveContext - object has been already displayed in another context!");
2325 theObj->SetContext (this);
2328 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theObj->Children()); aPrsIter.More(); aPrsIter.Next())
2330 if (Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()))
2332 setContextToObject (aChild);
2337 //=======================================================================
2338 //function : setObjectStatus
2340 //=======================================================================
2341 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2342 const PrsMgr_DisplayStatus theStatus,
2343 const Standard_Integer theDispMode,
2344 const Standard_Integer theSelectionMode)
2346 theIObj->SetDisplayStatus (theStatus);
2347 if (theStatus != PrsMgr_DisplayStatus_None)
2349 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus();
2350 aStatus->SetDisplayMode (theDispMode);
2351 if (theSelectionMode != -1)
2353 aStatus->AddSelectionMode (theSelectionMode);
2355 myObjects.Bind (theIObj, aStatus);
2359 myObjects.UnBind (theIObj);
2362 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2364 Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2365 if (aChild.IsNull())
2370 setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
2374 //=======================================================================
2375 //function : highlightWithColor
2377 //=======================================================================
2378 void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
2379 const Handle(V3d_Viewer)& theViewer)
2381 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2387 const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
2388 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
2390 myMainPM->BeginImmediateDraw();
2391 theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
2392 myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
2395 //=======================================================================
2396 //function : highlightSelected
2398 //=======================================================================
2399 void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
2401 AIS_NListOfEntityOwner anOwners;
2402 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2408 if (!theOwner->IsAutoHilight())
2410 SelectMgr_SequenceOfOwner aSeq;
2411 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2413 if (aSelIter.Value()->IsSameSelectable (anObj))
2415 anOwners.Append (aSelIter.Value());
2421 anOwners.Append (theOwner);
2423 highlightOwners (anOwners, Handle(Prs3d_Drawer)());
2426 //=======================================================================
2427 //function : highlightGlobal
2429 //=======================================================================
2430 void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
2431 const Handle(Prs3d_Drawer)& theStyle,
2432 const Standard_Integer theDispMode)
2434 if (theObj.IsNull())
2439 const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
2440 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2442 if (aGlobOwner.IsNull())
2444 myMainPM->Color (theObj, theStyle, aHiMode);
2448 AIS_NListOfEntityOwner anOwners;
2449 if (!aGlobOwner->IsAutoHilight())
2451 SelectMgr_SequenceOfOwner aSeq;
2452 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2454 if (aSelIter.Value()->IsSameSelectable (theObj))
2456 anOwners.Append (aSelIter.Value());
2462 anOwners.Append (aGlobOwner);
2464 highlightOwners (anOwners, theStyle);
2467 //=======================================================================
2468 //function : unhighlightSelected
2470 //=======================================================================
2471 void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
2473 unhighlightOwners (mySelection->Objects(), theIsToHilightSubIntensity);
2476 //=======================================================================
2477 //function : unhighlightOwners
2479 //=======================================================================
2480 void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& theOwners,
2481 const Standard_Boolean theIsToHilightSubIntensity)
2483 NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
2484 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
2486 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
2487 const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
2488 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anInteractive);
2494 if (anOwner->IsAutoHilight())
2496 anOwner->Unhilight (myMainPM);
2497 if (theIsToHilightSubIntensity)
2499 if ((*aStatusPtr)->IsSubIntensityOn())
2501 const Standard_Integer aHiMode = getHilightMode (anInteractive, (*aStatusPtr)->HilightStyle(), (*aStatusPtr)->DisplayMode());
2502 highlightWithSubintensity (anOwner, aHiMode);
2508 anObjToClear.Add (anInteractive);
2510 if (anOwner == anInteractive->GlobalSelOwner())
2512 (*aStatusPtr)->SetHilightStatus (Standard_False);
2514 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
2516 for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
2518 const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
2519 myMainPM->Unhighlight (anObj);
2520 anObj->ClearSelected();
2524 //=======================================================================
2525 //function : unhighlightGlobal
2527 //=======================================================================
2528 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj)
2530 if (theObj.IsNull())
2535 const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2536 if (aGlobOwner.IsNull())
2538 myMainPM->Unhighlight (theObj);
2542 AIS_NListOfEntityOwner anOwners;
2543 anOwners.Append (aGlobOwner);
2544 unhighlightOwners (anOwners);
2547 //=======================================================================
2548 //function : turnOnSubintensity
2550 //=======================================================================
2551 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2552 const Standard_Integer theDispMode,
2553 const Standard_Boolean theIsDisplayedOnly) const
2555 // the only differ with selection highlight is color, so sync transparency values
2556 const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
2557 aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2559 if (theObject.IsNull())
2561 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
2563 const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
2564 if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2569 aStatus->SetSubIntensity (true);
2570 myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2575 Handle(AIS_GlobalStatus) aStatus;
2576 if (!myObjects.Find (theObject, aStatus))
2581 if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2586 aStatus->SetSubIntensity (true);
2587 myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2591 //=======================================================================
2592 //function : highlightWithSubintensity
2594 //=======================================================================
2595 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2596 const Standard_Integer theMode) const
2598 // the only differ with selection highlight is color, so
2599 // sync transparency values
2600 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2602 myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2605 //=======================================================================
2606 //function : highlightWithSubintensity
2608 //=======================================================================
2609 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
2610 const Standard_Integer theMode) const
2612 // the only differ with selection highlight is color, so
2613 // sync transparency values
2614 myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2616 theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2619 //=======================================================================
2620 //function : isSlowHiStyle
2622 //=======================================================================
2623 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
2624 const Handle(V3d_Viewer)& theViewer) const
2626 if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
2628 const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
2629 return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
2630 || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
2632 return Standard_False;
2635 //=======================================================================
2638 //=======================================================================
2639 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer theXPix,
2640 const Standard_Integer theYPix,
2641 const Handle(V3d_View)& theView,
2642 const Standard_Boolean theToRedrawOnUpdate)
2644 if (theView->Viewer() != myMainVwr)
2646 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2648 MainSelector()->Pick (theXPix, theYPix, theView);
2649 return moveTo (theView, theToRedrawOnUpdate);
2652 //=======================================================================
2655 //=======================================================================
2656 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const gp_Ax1& theAxis,
2657 const Handle(V3d_View)& theView,
2658 const Standard_Boolean theToRedrawOnUpdate)
2660 if (theView->Viewer() != myMainVwr)
2662 throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2664 MainSelector()->Pick (theAxis, theView);
2665 return moveTo (theView, theToRedrawOnUpdate);
2668 //=======================================================================
2671 //=======================================================================
2672 AIS_StatusOfDetection AIS_InteractiveContext::moveTo (const Handle(V3d_View)& theView,
2673 const Standard_Boolean theToRedrawOnUpdate)
2676 myCurHighlighted = 0;
2677 myDetectedSeq.Clear();
2678 myLastActiveView = theView.get();
2681 AIS_StatusOfDetection aStatus = AIS_SOD_Nothing;
2682 Standard_Boolean toUpdateViewer = Standard_False;
2684 // filling of myAISDetectedSeq sequence storing information about detected AIS objects
2685 // (the objects must be AIS_Shapes)
2686 const Standard_Integer aDetectedNb = MainSelector()->NbPicked();
2687 Standard_Integer aNewDetected = 0;
2688 Standard_Boolean toIgnoreDetTop = Standard_False;
2689 for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
2691 Handle(SelectMgr_EntityOwner) anOwner = MainSelector()->Picked (aDetIter);
2692 if (anOwner.IsNull()
2693 || !myFilters->IsOk (anOwner))
2695 if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
2697 toIgnoreDetTop = Standard_True;
2702 if (aNewDetected < 1
2705 aNewDetected = aDetIter;
2708 myDetectedSeq.Append (aDetIter);
2711 if (aNewDetected >= 1)
2713 myCurHighlighted = myDetectedSeq.Lower();
2715 // Does nothing if previously detected object is equal to the current one.
2716 // However in advanced selection modes the owners comparison
2717 // is not effective because in that case only one owner manage the
2718 // selection in current selection mode. It is necessary to check the current detected
2719 // entity and hilight it only if the detected entity is not the same as
2720 // previous detected (IsForcedHilight call)
2721 Handle(SelectMgr_EntityOwner) aNewPickedOwner = MainSelector()->Picked (aNewDetected);
2722 if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
2724 return myLastPicked->IsSelected()
2726 : AIS_SOD_OnlyOneDetected;
2729 // Previously detected object is unhilighted if it is not selected or hilighted
2730 // with selection color if it is selected. Such highlighting with selection color
2731 // is needed only if myToHilightSelected flag is true. In this case previously detected
2732 // object has been already highlighted with myHilightColor during previous MoveTo()
2733 // method call. As result it is necessary to rehighligt it with mySelectionColor.
2734 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2736 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2738 theView->Viewer()->Invalidate();
2741 clearDynamicHighlight();
2742 toUpdateViewer = Standard_True;
2745 // initialize myLastPicked field with currently detected object
2746 myLastPicked = aNewPickedOwner;
2748 // highlight detected object if it is not selected or myToHilightSelected flag is true
2749 if (myLastPicked->HasSelectable())
2752 && (!myLastPicked->IsSelected()
2753 || myToHilightSelected))
2755 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2757 theView->Viewer()->Invalidate();
2760 highlightWithColor (myLastPicked, theView->Viewer());
2761 toUpdateViewer = Standard_True;
2764 aStatus = myLastPicked->IsSelected()
2766 : AIS_SOD_OnlyOneDetected;
2771 // previously detected object is unhilighted if it is not selected or hilighted
2772 // with selection color if it is selected
2773 aStatus = AIS_SOD_Nothing;
2775 && !myLastPicked.IsNull()
2776 && myLastPicked->HasSelectable())
2778 if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2780 theView->Viewer()->Invalidate();
2783 clearDynamicHighlight();
2784 toUpdateViewer = Standard_True;
2787 myLastPicked.Nullify();
2791 && theToRedrawOnUpdate)
2793 if (theView->ComputedMode())
2795 theView->Viewer()->Update();
2799 if (theView->IsInvalidated())
2801 theView->Viewer()->Redraw();
2805 theView->Viewer()->RedrawImmediate();
2813 //=======================================================================
2814 //function : AddSelect
2816 //=======================================================================
2817 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
2819 mySelection->AddSelect (theObject);
2821 Standard_Integer aSelNum = NbSelected();
2822 return (aSelNum == 0) ? AIS_SOP_NothingSelected
2823 : (aSelNum == 1) ? AIS_SOP_OneSelected
2824 : AIS_SOP_SeveralSelected;
2827 //=======================================================================
2828 //function : SelectRectangle
2830 //=======================================================================
2831 AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i& thePntMin,
2832 const Graphic3d_Vec2i& thePntMax,
2833 const Handle(V3d_View)& theView,
2834 const AIS_SelectionScheme theSelScheme)
2836 if (theView->Viewer() != myMainVwr)
2838 throw Standard_ProgramError ("AIS_InteractiveContext::SelectRectangle() - invalid argument");
2841 myLastActiveView = theView.get();
2842 MainSelector()->Pick (thePntMin.x(), thePntMin.y(), thePntMax.x(), thePntMax.y(), theView);
2844 AIS_NArray1OfEntityOwner aPickedOwners;
2845 if (MainSelector()->NbPicked() > 0)
2847 aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2848 for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2850 aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2854 return Select (aPickedOwners, theSelScheme);
2857 //=======================================================================
2858 //function : SelectPolygon
2860 //=======================================================================
2861 AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt2d& thePolyline,
2862 const Handle(V3d_View)& theView,
2863 const AIS_SelectionScheme theSelScheme)
2865 if (theView->Viewer() != myMainVwr)
2867 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPolygon() - invalid argument");
2870 myLastActiveView = theView.get();
2871 MainSelector()->Pick (thePolyline, theView);
2873 AIS_NArray1OfEntityOwner aPickedOwners;
2874 if (MainSelector()->NbPicked() > 0)
2876 aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2877 for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2879 aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2883 return Select (aPickedOwners, theSelScheme);
2886 //=======================================================================
2887 //function : SelectPoint
2889 //=======================================================================
2890 AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i& thePnt,
2891 const Handle(V3d_View)& theView,
2892 const AIS_SelectionScheme theSelScheme)
2894 if (theView->Viewer() != myMainVwr)
2896 throw Standard_ProgramError ("AIS_InteractiveContext::SelectPoint() - invalid argument");
2899 myLastActiveView = theView.get();
2900 MainSelector()->Pick (thePnt.x(), thePnt.y(), theView);
2902 AIS_NArray1OfEntityOwner aPickedOwners;
2903 if (MainSelector()->NbPicked() > 0)
2905 aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2906 for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2908 aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2912 return Select (aPickedOwners, theSelScheme);
2915 //=======================================================================
2916 //function : SelectDetected
2918 //=======================================================================
2919 AIS_StatusOfPick AIS_InteractiveContext::SelectDetected (const AIS_SelectionScheme theSelScheme)
2921 if (theSelScheme == AIS_SelectionScheme_Replace && !myLastPicked.IsNull())
2923 Graphic3d_Vec2i aMousePos (-1, -1);
2924 gp_Pnt2d aMouseRealPos = MainSelector()->GetManager().GetMousePosition();
2925 if (!Precision::IsInfinite (aMouseRealPos.X()) &&
2926 !Precision::IsInfinite (aMouseRealPos.Y()))
2928 aMousePos.SetValues ((Standard_Integer )aMouseRealPos.X(), (Standard_Integer )aMouseRealPos.Y());
2930 if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
2932 return AIS_SOP_NothingSelected;
2936 AIS_NArray1OfEntityOwner aPickedOwners (1, 1);
2937 aPickedOwners.SetValue (1, myLastPicked);
2938 return Select (aPickedOwners, theSelScheme);
2941 //=======================================================================
2944 //=======================================================================
2945 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer theXPMin,
2946 const Standard_Integer theYPMin,
2947 const Standard_Integer theXPMax,
2948 const Standard_Integer theYPMax,
2949 const Handle(V3d_View)& theView,
2950 const Standard_Boolean theToUpdateViewer)
2952 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
2953 Graphic3d_Vec2i (theXPMax, theYPMax),
2955 if (theToUpdateViewer)
2957 UpdateCurrentViewer();
2962 //=======================================================================
2964 //purpose : Selection by polyline
2965 //=======================================================================
2966 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
2967 const Handle(V3d_View)& theView,
2968 const Standard_Boolean theToUpdateViewer)
2970 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView);
2971 if (theToUpdateViewer)
2973 UpdateCurrentViewer();
2978 //=======================================================================
2981 //=======================================================================
2982 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean theToUpdateViewer)
2984 AIS_StatusOfPick aStatus = SelectDetected();
2985 if (theToUpdateViewer)
2987 UpdateCurrentViewer();
2992 //=======================================================================
2993 //function : ShiftSelect
2995 //=======================================================================
2996 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean theToUpdateViewer)
2998 AIS_StatusOfPick aStatus = SelectDetected (AIS_SelectionScheme_XOR);
2999 if (theToUpdateViewer)
3001 UpdateCurrentViewer();
3006 //=======================================================================
3007 //function : ShiftSelect
3009 //=======================================================================
3010 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
3011 const Standard_Integer theYPMin,
3012 const Standard_Integer theXPMax,
3013 const Standard_Integer theYPMax,
3014 const Handle(V3d_View)& theView,
3015 const Standard_Boolean theToUpdateViewer)
3017 AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
3018 Graphic3d_Vec2i (theXPMax, theYPMax),
3020 AIS_SelectionScheme_XOR);
3021 if (theToUpdateViewer)
3023 UpdateCurrentViewer();
3028 //=======================================================================
3029 //function : ShiftSelect
3031 //=======================================================================
3032 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
3033 const Handle(V3d_View)& theView,
3034 const Standard_Boolean theToUpdateViewer)
3036 AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView, AIS_SelectionScheme_XOR);
3037 if (theToUpdateViewer)
3039 UpdateCurrentViewer();
3044 //=======================================================================
3047 //=======================================================================
3048 AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners,
3049 const AIS_SelectionScheme theSelScheme)
3051 NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> aSelOwnerMap (myAutoHilight ? mySelection->Objects().Size() : 0);
3054 clearDynamicHighlight();
3056 // collect currently selected owners
3057 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3059 aSelOwnerMap.Add (anOwnerIter.Value());
3063 mySelection->SelectOwners (theOwners, theSelScheme, MainSelector()->GetManager().IsOverlapAllowed(), myFilters);
3067 // collect lists of owners to unhighlight (unselected) and to highlight (selected)
3068 AIS_NListOfEntityOwner anOwnersToUnhighlight, anOwnersToHighlight;
3069 for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3071 // add newly selected owners
3072 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3073 if (!aSelOwnerMap.RemoveKey (anOwner))
3075 // newly selected owner
3076 anOwnersToHighlight.Append (anOwner);
3080 // already selected owner
3081 if (!anOwner->IsAutoHilight()
3082 && theSelScheme != AIS_SelectionScheme_XOR
3083 && theSelScheme != AIS_SelectionScheme_Add)
3085 // hack to perform AIS_InteractiveObject::ClearSelected() before highlighting
3086 anOwnersToUnhighlight.Append (anOwner);
3087 anOwnersToHighlight.Append (anOwner);
3089 else if (anOwner->IsForcedHilight()
3090 || !anOwner->IsAutoHilight())
3092 anOwnersToHighlight.Append (anOwner);
3097 for (NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)>::Iterator anOwnerIter (aSelOwnerMap); anOwnerIter.More(); anOwnerIter.Next())
3099 // owners removed from selection
3100 const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3101 anOwnersToUnhighlight.Append (anOwner);
3104 unhighlightOwners (anOwnersToUnhighlight);
3105 highlightOwners (anOwnersToHighlight, Handle(Prs3d_Drawer)());
3108 Standard_Integer aSelNum = NbSelected();
3109 return (aSelNum == 0) ? AIS_SOP_NothingSelected
3110 : (aSelNum == 1) ? AIS_SOP_OneSelected
3111 : AIS_SOP_SeveralSelected;
3114 //=======================================================================
3115 //function : HilightSelected
3117 //=======================================================================
3118 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
3120 // In case of selection without using local context
3121 clearDynamicHighlight();
3123 highlightOwners (mySelection->Objects(), Handle(Prs3d_Drawer)());
3125 if (theToUpdateViewer)
3127 UpdateCurrentViewer();
3131 //=======================================================================
3132 //function : highlightOwners
3134 //=======================================================================
3135 void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners,
3136 const Handle(Prs3d_Drawer)& theStyle)
3138 NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > anObjOwnerMap;
3139 for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
3141 const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
3142 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3146 const Handle(Prs3d_Drawer)& anObjSelStyle = !theStyle.IsNull() ? theStyle : getSelStyle (anObj, anOwner);
3147 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3152 if (anOwner == anObj->GlobalSelOwner())
3154 (*aStatusPtr)->SetHilightStatus (Standard_True);
3155 (*aStatusPtr)->SetHilightStyle (anObjSelStyle);
3157 if (!anOwner->IsAutoHilight())
3159 NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
3160 if (anObjOwnerMap.Find (anObj, aSeq))
3162 aSeq->Append (anOwner);
3166 aSeq = new SelectMgr_SequenceOfOwner();
3167 aSeq->Append (anOwner);
3168 anObjOwnerMap.Bind (anObj, aSeq);
3173 const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, (*aStatusPtr)->DisplayMode());
3174 anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3178 if (!anObjOwnerMap.IsEmpty())
3180 for (NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> >::Iterator anIter (anObjOwnerMap);
3181 anIter.More(); anIter.Next())
3183 anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
3185 anObjOwnerMap.Clear();
3189 //=======================================================================
3190 //function : UnhilightSelected
3192 //=======================================================================
3193 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
3195 unhighlightSelected();
3197 if (theToUpdateViewer)
3199 UpdateCurrentViewer();
3203 //=======================================================================
3204 //function : ClearSelected
3206 //=======================================================================
3207 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
3209 if (NbSelected() == 0)
3216 unhighlightSelected();
3219 mySelection->Clear();
3222 clearDynamicHighlight();
3225 if (theToUpdateViewer)
3227 UpdateCurrentViewer();
3231 //=======================================================================
3232 //function : isDetected
3234 //=======================================================================
3235 Standard_Boolean AIS_InteractiveContext::isDetected (const Handle(AIS_InteractiveObject)& theObject)
3237 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper(); aDetIter++)
3239 Handle(SelectMgr_EntityOwner) aPicked = MainSelector()->Picked(myDetectedSeq(aDetIter));
3240 Handle(AIS_InteractiveObject) anObj;
3241 if (!aPicked.IsNull())
3243 anObj = Handle(AIS_InteractiveObject)::DownCast(aPicked->Selectable());
3247 && anObj == theObject)
3249 return Standard_True;
3252 return Standard_False;
3255 //=======================================================================
3256 //function : SetSelected
3257 //purpose : Sets the whole object as selected and highlights it with selection color
3258 //=======================================================================
3259 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
3260 const Standard_Boolean theToUpdateViewer)
3262 if (theObject.IsNull())
3267 if (!myObjects.IsBound (theObject))
3272 Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3273 if (anOwner.IsNull())
3278 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
3279 if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
3281 Handle(Prs3d_Drawer) aCustomStyle;
3282 if (HighlightStyle (theObject, aCustomStyle))
3284 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3286 HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
3292 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
3294 const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
3295 if (!myFilters->IsOk (aSelOwner))
3300 Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
3303 Unhilight (aSelectable, Standard_False);
3305 if (aSelOwner == aSelectable->GlobalSelOwner())
3307 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (aSelectable))
3309 (*aStatusPtr)->SetHilightStatus (Standard_False);
3314 // added to avoid untimely viewer update...
3315 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3316 mySelection->ClearAndSelect (anOwner, myFilters, isDetected (anObj));
3320 Handle(Prs3d_Drawer) aCustomStyle;
3321 if (HighlightStyle (theObject, aCustomStyle))
3323 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3325 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3330 HilightWithColor (theObject, anObjSelStyle, Standard_False);
3334 if (theToUpdateViewer)
3336 UpdateCurrentViewer();
3340 //=======================================================================
3341 //function : SetSelected
3342 //purpose : Sets the whole object as selected and highlights it with selection color
3343 //=======================================================================
3344 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3345 const Standard_Boolean theToUpdateViewer)
3347 if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
3352 const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3353 const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
3354 if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
3356 Handle(Prs3d_Drawer) aCustomStyle;
3357 if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
3359 if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3361 const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
3362 theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3368 if (!myObjects.IsBound (anObject))
3375 unhighlightSelected();
3378 mySelection->ClearAndSelect (theOwner, myFilters, isDetected (anObject));
3381 Handle(Prs3d_Drawer) aCustomStyle;
3382 if (!HighlightStyle (theOwner, aCustomStyle) ||
3383 (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
3385 highlightSelected (theOwner);
3389 if (theToUpdateViewer)
3391 UpdateCurrentViewer();
3395 //=======================================================================
3396 //function : AddOrRemoveSelected
3398 //=======================================================================
3399 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
3400 const Standard_Boolean theToUpdateViewer)
3402 if (theObject.IsNull()
3403 || !myObjects.IsBound (theObject))
3408 const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3409 if (!anOwner.IsNull()
3410 && anOwner->HasSelectable())
3412 AddOrRemoveSelected (anOwner, theToUpdateViewer);
3416 //=======================================================================
3417 //function : AddOrRemoveSelected
3418 //purpose : Allows to highlight or unhighlight the owner given depending on
3419 // its selection status
3420 //=======================================================================
3421 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3422 const Standard_Boolean theToUpdateViewer)
3424 if (theOwner.IsNull() || !theOwner->HasSelectable())
3429 if (!myFilters->IsOk (theOwner) && !theOwner->IsSelected())
3434 AIS_SelectionScheme aSelScheme = theOwner->IsSelected() ? AIS_SelectionScheme_Remove : AIS_SelectionScheme_Add;
3435 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3436 mySelection->Select (theOwner, myFilters, aSelScheme, isDetected (anObj));
3440 Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3446 if (theOwner->IsSelected())
3448 highlightSelected (theOwner);
3452 AIS_NListOfEntityOwner anOwners;
3453 anOwners.Append (theOwner);
3454 unhighlightOwners (anOwners);
3456 (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
3460 if (theToUpdateViewer)
3462 UpdateCurrentViewer();
3466 // =======================================================================
3467 // function : SetSelectedState
3469 // =======================================================================
3470 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
3471 const Standard_Boolean theIsSelected)
3473 if (theEntity.IsNull())
3475 throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
3478 if (!theEntity->HasSelectable()
3479 || mySelection->IsSelected (theEntity) == theIsSelected)
3484 if (theEntity->IsAutoHilight())
3486 AddOrRemoveSelected (theEntity, false);
3492 const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
3493 theEntity->SetSelected (true);
3494 return aSelStatus == AIS_SS_Added;
3498 const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(theEntity->Selectable());
3499 const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity, myFilters, AIS_SelectionScheme_Remove, isDetected (anObj));
3500 theEntity->SetSelected (false);
3501 return aSelStatus == AIS_SS_Removed;
3505 //=======================================================================
3506 //function : IsSelected
3508 //=======================================================================
3509 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
3511 if (theObj.IsNull())
3513 return Standard_False;
3516 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3517 if (aStatus == NULL)
3519 return Standard_False;
3522 const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
3523 const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
3524 for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
3526 if (aModeIter.Value() == aGlobalSelMode)
3528 if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
3530 return aGlobOwner->IsSelected();
3532 return Standard_False;
3535 return Standard_False;
3538 //=======================================================================
3539 //function : FirstSelectedObject
3541 //=======================================================================
3542 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
3544 return !mySelection->Objects().IsEmpty()
3545 ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
3546 : Handle(AIS_InteractiveObject)();
3549 //=======================================================================
3550 //function : HasSelectedShape
3552 //=======================================================================
3553 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
3555 if (!mySelection->More())
3557 return Standard_False;
3560 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3561 return !anOwner.IsNull() && anOwner->HasShape();
3564 //=======================================================================
3565 //function : SelectedShape
3567 //=======================================================================
3568 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
3570 if (!mySelection->More())
3572 return TopoDS_Shape();
3575 const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3576 if (anOwner.IsNull() || !anOwner->HasSelectable())
3578 return TopoDS_Shape();
3581 return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
3584 //=======================================================================
3585 //function : EntityOwners
3587 //=======================================================================
3588 void AIS_InteractiveContext::EntityOwners (Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
3589 const Handle(AIS_InteractiveObject)& theIObj,
3590 const Standard_Integer theMode) const
3592 if (theIObj.IsNull())
3597 TColStd_ListOfInteger aModes;
3600 ActivatedModes (theIObj, aModes);
3604 aModes.Append (theMode);
3607 if (theOwners.IsNull())
3609 theOwners = new SelectMgr_IndexedMapOfOwner();
3612 for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
3614 const int aMode = anItr.Value();
3615 const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
3621 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
3623 if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
3625 if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
3627 theOwners->Add (aOwner);
3634 //=======================================================================
3635 //function : HasDetectedShape
3637 //=======================================================================
3638 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
3640 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3641 return !anOwner.IsNull()
3642 && anOwner->HasShape();
3645 //=======================================================================
3646 //function : DetectedShape
3648 //=======================================================================
3649 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
3651 Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3652 return anOwner->Shape();
3655 //=======================================================================
3656 //function : HilightNextDetected
3658 //=======================================================================
3659 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
3660 const Standard_Boolean theToRedrawImmediate)
3662 myMainPM->ClearImmediateDraw();
3663 if (myDetectedSeq.IsEmpty())
3668 if (++myCurHighlighted > myDetectedSeq.Upper())
3670 myCurHighlighted = myDetectedSeq.Lower();
3672 const Handle(SelectMgr_EntityOwner)& anOwner = MainSelector()->Picked (myDetectedSeq (myCurHighlighted));
3673 if (anOwner.IsNull())
3678 highlightWithColor (anOwner, theView->Viewer());
3679 myLastPicked = anOwner;
3681 if (theToRedrawImmediate)
3683 myMainPM->RedrawImmediate (theView->Viewer());
3684 myMainVwr->RedrawImmediate();
3687 return myCurHighlighted;
3690 //=======================================================================
3691 //function : HilightPreviousDetected
3693 //=======================================================================
3694 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
3695 const Standard_Boolean theToRedrawImmediate)
3697 myMainPM->ClearImmediateDraw();
3698 if (myDetectedSeq.IsEmpty())
3703 if (--myCurHighlighted < myDetectedSeq.Lower())
3705 myCurHighlighted = myDetectedSeq.Upper();
3707 const Handle(SelectMgr_EntityOwner)& anOwner = MainSelector()->Picked (myDetectedSeq (myCurHighlighted));
3708 if (anOwner.IsNull())
3713 highlightWithColor (anOwner, theView->Viewer());
3714 myLastPicked = anOwner;
3716 if (theToRedrawImmediate)
3718 myMainPM->RedrawImmediate (theView->Viewer());
3719 myMainVwr->RedrawImmediate();
3722 return myCurHighlighted;
3725 //=======================================================================
3726 //function : DetectedCurrentOwner
3728 //=======================================================================
3729 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
3731 return MoreDetected()
3732 ? MainSelector()->Picked (myDetectedSeq (myCurDetected))
3733 : Handle(SelectMgr_EntityOwner)();
3736 //=======================================================================
3737 //function : DetectedCurrentShape
3739 //=======================================================================
3740 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
3742 static const TopoDS_Shape AIS_InteractiveContext_myDummyShape;
3744 Standard_DISABLE_DEPRECATION_WARNINGS
3745 Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
3746 Standard_ENABLE_DEPRECATION_WARNINGS
3747 return !aCurrentShape.IsNull()
3748 ? aCurrentShape->Shape()
3749 : AIS_InteractiveContext_myDummyShape;
3752 //=======================================================================
3753 //function : DetectedCurrentObject
3755 //=======================================================================
3756 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
3758 return MoreDetected()
3759 ? Handle(AIS_InteractiveObject)::DownCast (MainSelector()->Picked (myDetectedSeq (myCurDetected))->Selectable())
3760 : Handle(AIS_InteractiveObject)();
3763 //=======================================================================
3764 //function : SetSelectionModeActive
3766 //=======================================================================
3767 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
3768 const Standard_Integer theMode,
3769 const Standard_Boolean theIsActive,
3770 const AIS_SelectionModesConcurrency theActiveFilter,
3771 const Standard_Boolean theIsForce)
3773 if (theObj.IsNull())
3778 const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
3786 && theActiveFilter == AIS_SelectionModesConcurrency_Single))
3788 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3793 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3795 mgrSelector->Deactivate (theObj, aModeIter.Value());
3800 mgrSelector->Deactivate (theObj, theMode);
3806 (*aStat)->ClearSelectionModes();
3810 (*aStat)->RemoveSelectionMode (theMode);
3814 else if (theMode == -1)
3819 if ((*aStat)->SelectionModes().Size() == 1
3820 && (*aStat)->SelectionModes().First() == theMode)
3825 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3828 switch (theActiveFilter)
3830 case AIS_SelectionModesConcurrency_Single:
3832 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3834 mgrSelector->Deactivate (theObj, aModeIter.Value());
3836 (*aStat)->ClearSelectionModes();
3839 case AIS_SelectionModesConcurrency_GlobalOrLocal:
3841 const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
3842 TColStd_ListOfInteger aRemovedModes;
3843 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3845 if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
3846 || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
3848 mgrSelector->Deactivate (theObj, aModeIter.Value());
3849 aRemovedModes.Append (aModeIter.Value());
3852 if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
3854 (*aStat)->ClearSelectionModes();
3858 for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
3860 (*aStat)->RemoveSelectionMode (aModeIter.Value());
3865 case AIS_SelectionModesConcurrency_Multiple:
3870 mgrSelector->Activate (theObj, theMode);
3872 (*aStat)->AddSelectionMode (theMode);
3875 // ============================================================================
3876 // function : Activate
3878 // ============================================================================
3879 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
3880 const Standard_Boolean theIsForce)
3882 AIS_ListOfInteractive aDisplayedObjects;
3883 DisplayedObjects (aDisplayedObjects);
3884 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3886 Load (anIter.Value(), -1);
3887 Activate (anIter.Value(), theMode, theIsForce);
3891 // ============================================================================
3892 // function : Deactivate
3894 // ============================================================================
3895 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
3897 AIS_ListOfInteractive aDisplayedObjects;
3898 DisplayedObjects (aDisplayedObjects);
3899 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3901 Deactivate (anIter.Value(), theMode);
3905 // ============================================================================
3906 // function : Deactivate
3908 // ============================================================================
3909 void AIS_InteractiveContext::Deactivate()
3911 AIS_ListOfInteractive aDisplayedObjects;
3912 DisplayedObjects (aDisplayedObjects);
3914 for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3916 Deactivate (anIter.Value());
3920 //=======================================================================
3921 //function : ActivatedModes
3923 //=======================================================================
3924 void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
3925 TColStd_ListOfInteger& theList) const
3927 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3928 if (aStatus != NULL)
3930 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3932 theList.Append (aModeIter.Value());
3937 //=======================================================================
3938 //function : SubIntensityOn
3940 //=======================================================================
3941 void AIS_InteractiveContext::SubIntensityOn (const Handle(AIS_InteractiveObject)& theObj,
3942 const Standard_Boolean theToUpdateViewer)
3944 turnOnSubintensity (theObj);
3945 if (theToUpdateViewer)
3947 myMainVwr->Update();
3951 //=======================================================================
3952 //function : SubIntensityOff
3954 //=======================================================================
3955 void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
3956 const Standard_Boolean theToUpdateViewer)
3958 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3960 || !(*aStatus)->IsSubIntensityOn())
3965 (*aStatus)->SetSubIntensity (false);
3966 Standard_Boolean toUpdateMain = Standard_False;
3967 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
3969 myMainPM->Unhighlight (theObj);
3970 toUpdateMain = Standard_True;
3973 if (IsSelected (theObj))
3975 highlightSelected (theObj->GlobalSelOwner());
3978 if (theToUpdateViewer && toUpdateMain)
3980 myMainVwr->Update();
3984 //=======================================================================
3985 //function : DisplayActiveSensitive
3987 //=======================================================================
3988 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& theView)
3990 MainSelector()->DisplaySensitive (theView);
3993 //=======================================================================
3994 //function : DisplayActiveSensitive
3996 //=======================================================================
3997 void AIS_InteractiveContext::DisplayActiveSensitive (const Handle(AIS_InteractiveObject)& theObj,
3998 const Handle(V3d_View)& theView)
4000 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
4001 if (aStatus == NULL)
4006 for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
4008 const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
4009 MainSelector()->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
4013 //=======================================================================
4014 //function : ClearActiveSensitive
4016 //=======================================================================
4017 void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
4019 MainSelector()->ClearSensitive (theView);
4022 //=======================================================================
4023 //function : IsImmediateModeOn
4025 //=======================================================================
4026 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
4028 return myMainPM->IsImmediateModeOn();
4031 //=======================================================================
4032 //function : BeginImmediateDraw
4034 //=======================================================================
4035 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
4037 if (myMainPM->IsImmediateModeOn())
4039 myMainPM->BeginImmediateDraw();
4040 return Standard_True;
4042 return Standard_False;
4045 //=======================================================================
4046 //function : ImmediateAdd
4048 //=======================================================================
4049 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
4050 const Standard_Integer theMode)
4052 if (myMainPM->IsImmediateModeOn())
4054 myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
4055 return Standard_True;
4057 return Standard_False;
4060 //=======================================================================
4061 //function : EndImmediateDraw
4063 //=======================================================================
4064 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
4066 if (myMainPM->IsImmediateModeOn())
4068 myMainPM->EndImmediateDraw (theView->Viewer());
4069 return Standard_True;
4071 return Standard_False;
4074 //=======================================================================
4075 //function : EndImmediateDraw
4077 //=======================================================================
4078 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
4080 if (myMainPM->IsImmediateModeOn())
4082 myMainPM->EndImmediateDraw (myMainVwr);
4083 return Standard_True;
4085 return Standard_False;
4088 //=======================================================================
4089 //function : SetPolygonOffsets
4091 //=======================================================================
4092 void AIS_InteractiveContext::SetPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4093 const Standard_Integer theMode,
4094 const Standard_ShortReal theFactor,
4095 const Standard_ShortReal theUnits,
4096 const Standard_Boolean theToUpdateViewer)
4098 if (theObj.IsNull())
4103 setContextToObject (theObj);
4104 theObj->SetPolygonOffsets (theMode, theFactor, theUnits);
4106 const Handle(AIS_GlobalStatus)* aStatus = theToUpdateViewer ? myObjects.Seek (theObj) : NULL;
4108 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4110 myMainVwr->Update();
4114 //=======================================================================
4115 //function : HasPolygonOffsets
4117 //=======================================================================
4118 Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj) const
4120 return !theObj.IsNull() && theObj->HasPolygonOffsets();
4123 //=======================================================================
4124 //function : PolygonOffsets
4126 //=======================================================================
4127 void AIS_InteractiveContext::PolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4128 Standard_Integer& theMode,
4129 Standard_ShortReal& theFactor,
4130 Standard_ShortReal& theUnits) const
4132 if (HasPolygonOffsets (theObj))
4134 theObj->PolygonOffsets (theMode, theFactor, theUnits);
4138 //=======================================================================
4139 //function : DumpJson
4141 //=======================================================================
4142 void AIS_InteractiveContext::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
4144 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
4146 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myObjects.Size())
4148 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mgrSelector.get())
4149 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainPM.get())
4150 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainVwr.get())
4151 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastActiveView)
4153 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastPicked.get())
4155 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToHilightSelected)
4157 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mySelection.get())
4158 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myFilters.get())
4159 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myDefaultDrawer.get())
4161 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Selected])
4162 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Dynamic])
4163 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalSelected])
4164 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalDynamic])
4165 OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_SubIntensity])
4167 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDetectedSeq.Size())
4169 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurDetected)
4170 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurHighlighted)
4171 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPickingStrategy)
4172 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoHilight)
4173 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsAutoActivateSelMode)