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_ListIteratorOfListOfInteractive.hxx>
24 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
25 #include <AIS_MultipleConnectedInteractive.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Trihedron.hxx>
28 #include <Geom_Axis2Placement.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <HLRBRep.hxx>
31 #include <OSD_Environment.hxx>
32 #include <Precision.hxx>
33 #include <Prs3d_BasicAspect.hxx>
34 #include <Prs3d_DatumAspect.hxx>
35 #include <Prs3d_IsoAspect.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Prs3d_PlaneAspect.hxx>
38 #include <Prs3d_PointAspect.hxx>
39 #include <Prs3d_ShadingAspect.hxx>
40 #include <PrsMgr_PresentableObject.hxx>
41 #include <Quantity_Color.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Filter.hxx>
44 #include <SelectMgr_OrFilter.hxx>
45 #include <SelectMgr_SelectionManager.hxx>
46 #include <Standard_Atomic.hxx>
47 #include <Standard_Transient.hxx>
48 #include <Standard_Type.hxx>
49 #include <StdSelect_ViewerSelector3d.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <TCollection_ExtendedString.hxx>
52 #include <TColStd_ListIteratorOfListOfInteger.hxx>
53 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
54 #include <TopLoc_Location.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <UnitsAPI.hxx>
57 #include <V3d_View.hxx>
58 #include <V3d_Viewer.hxx>
60 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
64 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
65 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
67 //! Initialize default highlighting attributes.
68 static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
69 const Quantity_Color& theColor)
71 theDrawer->SetMethod (Aspect_TOHM_COLOR);
72 theDrawer->SetDisplayMode (0);
73 theDrawer->SetColor (theColor);
75 theDrawer->SetupOwnShadingAspect();
76 theDrawer->SetupOwnPointAspect();
77 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
78 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
79 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
80 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
81 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
82 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
83 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
84 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
85 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
86 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
87 theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
89 theDrawer->ShadingAspect()->SetColor (theColor);
90 theDrawer->WireAspect()->SetColor (theColor);
91 theDrawer->LineAspect()->SetColor (theColor);
92 theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
93 theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
94 theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
95 theDrawer->FreeBoundaryAspect()->SetColor (theColor);
96 theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
97 theDrawer->PointAspect()->SetColor (theColor);
98 for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_None; ++aPartIter)
100 if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
102 aLineAsp->SetColor (theColor);
106 theDrawer->WireAspect()->SetWidth (2.0);
107 theDrawer->LineAspect()->SetWidth (2.0);
108 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
109 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
110 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
111 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
112 theDrawer->PointAspect()->SetScale (2.0);
114 // the triangulation should be computed using main presentation attributes,
115 // and should not be overridden by highlighting
116 theDrawer->SetAutoTriangulation (Standard_False);
120 //=======================================================================
121 //function : AIS_InteractiveContext
123 //=======================================================================
125 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
126 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
127 myMainVwr(MainViewer),
128 myMainSel(new StdSelect_ViewerSelector3d()),
129 myToHilightSelected(Standard_True),
130 mySelection(new AIS_Selection()),
131 myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)),
132 myDefaultDrawer(new Prs3d_Drawer()),
135 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
136 myAutoHilight(Standard_True),
137 myIsAutoActivateSelMode(Standard_True)
139 mgrSelector = new SelectMgr_SelectionManager (myMainSel);
141 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
142 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
143 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
144 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
145 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
146 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
148 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
149 myDefaultDrawer->SetDisplayMode(0);
151 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
152 aStyle->Link (myDefaultDrawer);
153 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
154 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
157 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
158 aStyle->Link (myDefaultDrawer);
159 initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
160 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
163 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
164 aStyle->Link (myDefaultDrawer);
165 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
166 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
169 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
170 aStyle->Link (myDefaultDrawer);
171 initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
172 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
175 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
176 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
177 aStyle->SetMethod(Aspect_TOHM_COLOR);
178 aStyle->SetColor (Quantity_NOC_GRAY40);
184 //=======================================================================
185 //function : ~AIS_InteractiveContext
187 //=======================================================================
188 AIS_InteractiveContext::~AIS_InteractiveContext()
190 // clear the current selection
191 mySelection->Clear();
192 mgrSelector.Nullify();
194 Handle(AIS_InteractiveContext) aNullContext;
195 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
197 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
198 anObj->SetContext (aNullContext);
199 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
201 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
206 //=======================================================================
207 //function : LastActiveView
209 //=======================================================================
210 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
212 if (myLastActiveView == NULL
213 || myMainVwr.IsNull())
215 return Handle(V3d_View)();
218 // as a precaution - check that myLastActiveView pointer is a valid active View
219 for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
221 if (aViewIter.Value() == myLastActiveView)
223 return aViewIter.Value();
226 return Handle(V3d_View)();
229 //=======================================================================
230 //function : UpdateCurrentViewer
232 //=======================================================================
234 void AIS_InteractiveContext::UpdateCurrentViewer()
236 if (!myMainVwr.IsNull())
240 //=======================================================================
241 //function : DisplayedObjects
243 //=======================================================================
244 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
246 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
248 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
250 theListOfIO.Append (anObjIter.Key());
255 //=======================================================================
256 //function : DisplayedObjects
258 //=======================================================================
259 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
260 const Standard_Integer theSign,
261 AIS_ListOfInteractive& theListOfIO) const
263 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Displayed, theListOfIO);
266 //=======================================================================
267 //function : ErasedObjects
269 //=======================================================================
270 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
272 ObjectsByDisplayStatus (PrsMgr_DisplayStatus_Erased, theListOfIO);
275 //=======================================================================
276 //function : ErasedObjects
278 //=======================================================================
279 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
280 const Standard_Integer theSign,
281 AIS_ListOfInteractive& theListOfIO) const
283 ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Erased, theListOfIO);
286 //=======================================================================
287 //function : ObjectsByDisplayStatus
289 //=======================================================================
290 void AIS_InteractiveContext::ObjectsByDisplayStatus (const PrsMgr_DisplayStatus theStatus,
291 AIS_ListOfInteractive& theListOfIO) const
293 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
295 if (anObjIter.Key()->DisplayStatus() == theStatus)
297 theListOfIO.Append (anObjIter.Key());
302 //=======================================================================
303 //function : ObjectsByDisplayStatus
305 //=======================================================================
306 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
307 const Standard_Integer theSign,
308 const PrsMgr_DisplayStatus theStatus,
309 AIS_ListOfInteractive& theListOfIO) const
311 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
313 if (theStatus != PrsMgr_DisplayStatus_None
314 && anObjIter.Key()->DisplayStatus() != theStatus)
318 else if (anObjIter.Key()->Type() != theKind)
324 || anObjIter.Key()->Signature() == theSign)
326 theListOfIO.Append (anObjIter.Key());
331 //=======================================================================
332 //function : ObjectsInside
334 //=======================================================================
335 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
336 const AIS_KindOfInteractive theKind,
337 const Standard_Integer theSign) const
339 if (theKind == AIS_KindOfInteractive_None
342 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
344 theListOfIO.Append (anObjIter.Key());
349 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
351 if (anObjIter.Key()->Type() != theKind)
357 || anObjIter.Key()->Signature() == theSign)
359 theListOfIO.Append (anObjIter.Key());
364 //=======================================================================
365 //function : ObjectsForView
367 //=======================================================================
368 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
369 const Handle(V3d_View)& theView,
370 const Standard_Boolean theIsVisibleInView,
371 const PrsMgr_DisplayStatus theStatus) const
373 Handle(Graphic3d_CView) aViewImpl = theView->View();
374 const Standard_Integer aViewId = aViewImpl->Identification();
375 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
377 if (theStatus != PrsMgr_DisplayStatus_None
378 && anObjIter.Key()->DisplayStatus() != theStatus)
380 theListOfIO.Append (anObjIter.Key());
384 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
385 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
386 if (isVisible == theIsVisibleInView)
388 theListOfIO.Append (anObjIter.Key());
393 //=======================================================================
396 //=======================================================================
397 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
398 const Standard_Boolean theToUpdateViewer)
400 if (theIObj.IsNull())
405 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
406 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
407 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
410 //=======================================================================
411 //function : SetViewAffinity
413 //=======================================================================
414 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
415 const Handle(V3d_View)& theView,
416 const Standard_Boolean theIsVisible)
419 || !myObjects.IsBound (theIObj))
424 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
425 Handle(Graphic3d_CView) aViewImpl = theView->View();
426 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
429 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
433 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
437 //=======================================================================
440 //=======================================================================
441 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
442 const Standard_Integer theDispMode,
443 const Standard_Integer theSelectionMode,
444 const Standard_Boolean theToUpdateViewer,
445 const PrsMgr_DisplayStatus theDispStatus)
447 if (theIObj.IsNull())
452 if (theDispStatus == PrsMgr_DisplayStatus_Erased)
454 Erase (theIObj, theToUpdateViewer);
455 Load (theIObj, theSelectionMode);
456 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
458 (*aStatusPtr)->SetDisplayMode (theDispMode);
463 setContextToObject (theIObj);
464 if (!myObjects.IsBound (theIObj))
466 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
467 myMainVwr->StructureManager()->RegisterObject (theIObj);
468 myMainPM->Display(theIObj, theDispMode);
469 if (theSelectionMode != -1)
471 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
472 if (!mgrSelector->Contains (anObj))
474 mgrSelector->Load (theIObj);
476 mgrSelector->Activate (theIObj, theSelectionMode);
481 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
483 // Mark the presentation modes hidden of interactive object different from aDispMode.
484 // Then make sure aDispMode is displayed and maybe highlighted.
485 // Finally, activate selection mode <SelMode> if not yet activated.
486 const Standard_Integer anOldMode = aStatus->DisplayMode();
487 if (anOldMode != theDispMode)
489 if(myMainPM->IsHighlighted (theIObj, anOldMode))
491 unhighlightGlobal (theIObj);
493 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
496 aStatus->SetDisplayMode (theDispMode);
498 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Displayed);
499 myMainPM->Display (theIObj, theDispMode);
500 if (aStatus->IsHilighted())
502 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
504 if (theSelectionMode != -1)
506 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
507 if (!mgrSelector->Contains (anObj))
509 mgrSelector->Load (theIObj);
511 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
513 if (!aStatus->IsSModeIn (theSelectionMode))
514 aStatus->AddSelectionMode (theSelectionMode);
515 mgrSelector->Activate (theIObj, theSelectionMode);
520 if (theToUpdateViewer)
526 //=======================================================================
529 //=======================================================================
530 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
531 const Standard_Integer theSelMode)
533 if (theIObj.IsNull())
538 setContextToObject (theIObj);
539 if (!myObjects.IsBound (theIObj))
541 Standard_Integer aDispMode, aHiMod, aSelModeDef;
542 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
543 setObjectStatus (theIObj, PrsMgr_DisplayStatus_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
544 myMainVwr->StructureManager()->RegisterObject (theIObj);
547 // Register theIObj in the selection manager to prepare further activation of selection
548 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
549 if (!mgrSelector->Contains (anObj))
551 mgrSelector->Load (theIObj);
555 //=======================================================================
558 //=======================================================================
559 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
560 const Standard_Boolean theToUpdateViewer)
562 if (theIObj.IsNull())
567 if (!theIObj->IsAutoHilight())
569 theIObj->ClearSelected();
572 EraseGlobal (theIObj, Standard_False);
573 if (theToUpdateViewer)
579 //=======================================================================
580 //function : EraseAll
582 //=======================================================================
583 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
585 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
587 if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
589 Erase (anObjIter.Key(), Standard_False);
593 if (theToUpdateViewer)
599 //=======================================================================
600 //function : DisplayAll
602 //=======================================================================
603 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
605 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
607 const PrsMgr_DisplayStatus aStatus = anObjIter.Key()->DisplayStatus();
608 if (aStatus == PrsMgr_DisplayStatus_Erased)
610 Display (anObjIter.Key(), Standard_False);
614 if (theToUpdateViewer)
620 //=======================================================================
621 //function : DisplaySelected
623 //=======================================================================
624 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
626 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
628 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
629 Display (anObj, Standard_False);
632 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
638 //=======================================================================
639 //function : EraseSelected
641 //=======================================================================
642 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
644 Standard_Boolean isFound = Standard_False;
645 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
647 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
648 Erase (anObj, Standard_False);
649 isFound = Standard_True;
652 if (isFound && theToUpdateViewer)
658 //=======================================================================
659 //function : DisplayStatus
661 //=======================================================================
662 PrsMgr_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
664 if (theIObj.IsNull())
666 return PrsMgr_DisplayStatus_None;
668 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
669 return aStatus != NULL ? theIObj->DisplayStatus() : PrsMgr_DisplayStatus_None;
672 //=======================================================================
675 //=======================================================================
676 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
677 const Standard_Boolean theToUpdateViewer)
679 if (theIObj.IsNull())
684 if (theIObj->HasInteractiveContext())
686 if (theIObj->myCTXPtr != this)
688 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
690 theIObj->SetContext (Handle(AIS_InteractiveContext)());
692 ClearGlobal (theIObj, theToUpdateViewer);
695 //=======================================================================
696 //function : RemoveAll
698 //=======================================================================
699 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
701 AIS_ListOfInteractive aList;
702 ObjectsInside (aList);
703 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
705 Remove (aListIterator.Value(), Standard_False);
708 if (theToUpdateViewer)
714 //=======================================================================
715 //function : HilightWithColor
717 //=======================================================================
718 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
719 const Handle(Prs3d_Drawer)& theStyle,
720 const Standard_Boolean theIsToUpdate)
725 setContextToObject (theObj);
726 if (!myObjects.IsBound (theObj))
729 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
730 aStatus->SetHilightStatus (Standard_True);
732 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
734 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
735 aStatus->SetHilightStyle (theStyle);
742 //=======================================================================
743 //function : Unhilight
745 //=======================================================================
746 void AIS_InteractiveContext::Unhilight (const Handle(AIS_InteractiveObject)& theObj,
747 const Standard_Boolean theToUpdateViewer)
749 Handle(AIS_GlobalStatus)* aStatus = !theObj.IsNull() ? myObjects.ChangeSeek (theObj) : NULL;
755 (*aStatus)->SetHilightStatus (Standard_False);
756 (*aStatus)->SetHilightStyle (Handle(Prs3d_Drawer)());
757 if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
759 unhighlightGlobal (theObj);
762 if (theToUpdateViewer)
768 //=======================================================================
769 //function : IsHilighted
770 //purpose : Returns true if the objects global status is set to highlighted.
771 //=======================================================================
772 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
774 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
775 return aStatus != NULL
776 && (*aStatus)->IsHilighted();
779 //=======================================================================
780 //function : IsHilighted
781 //purpose : Returns true if the owner is highlighted with selection style.
782 //=======================================================================
783 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
785 if (theOwner.IsNull() || !theOwner->HasSelectable())
786 return Standard_False;
788 const Handle(AIS_InteractiveObject) anObj =
789 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
791 if (anObj->GlobalSelOwner() == theOwner)
793 if (!myObjects.IsBound (anObj))
794 return Standard_False;
796 return myObjects (anObj)->IsHilighted();
799 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
800 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
801 return theOwner->IsHilighted (myMainPM, aHiMode);
804 //=======================================================================
805 //function : HighlightStyle
807 //=======================================================================
808 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
809 Handle(Prs3d_Drawer)& theStyle) const
811 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
813 && (*aStatus)->IsHilighted())
815 theStyle = (*aStatus)->HilightStyle();
816 return Standard_True;
820 return Standard_False;
823 //=======================================================================
824 //function : HighlightStyle
826 //=======================================================================
827 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
828 Handle(Prs3d_Drawer)& theStyle) const
830 if (theOwner.IsNull() || !theOwner->HasSelectable())
831 return Standard_False;
833 if (IsHilighted (theOwner))
835 const Handle(AIS_InteractiveObject) anObj =
836 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
837 if (anObj->GlobalSelOwner() == theOwner)
839 theStyle = myObjects (anObj)->HilightStyle();
843 // since part selection style is not stored in global status,
844 // check if the object has own selection style. If not, it can
845 // only be highlighted with default selection style (because
846 // sub-intensity does not modify any selection states)
847 theStyle = getSelStyle (anObj, theOwner);
849 return Standard_True;
854 return Standard_False;
858 //=======================================================================
859 //function : IsDisplayed
861 //=======================================================================
863 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
865 if(theObj.IsNull()) return Standard_False;
867 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
868 return aStatus != NULL
869 && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed;
872 //=======================================================================
873 //function : IsDisplayed
875 //=======================================================================
876 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
877 const Standard_Integer theMode) const
879 if (theIObj.IsNull())
881 return Standard_False;
884 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
885 return aStatus != NULL
886 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
887 && (*aStatus)->DisplayMode() == theMode;
890 //=======================================================================
891 //function : DisplayPriority
893 //=======================================================================
894 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
896 if (theIObj.IsNull())
901 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
903 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
904 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
906 Standard_Integer aDispMode = theIObj->HasDisplayMode()
907 ? theIObj->DisplayMode()
908 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
909 ? myDefaultDrawer->DisplayMode()
911 return myMainPM->DisplayPriority (theIObj, aDispMode);
916 //=======================================================================
917 //function : SetDisplayPriority
919 //=======================================================================
920 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
921 const Standard_Integer thePriority)
923 if (theIObj.IsNull())
928 setContextToObject (theIObj);
929 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
931 && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
932 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
934 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
935 ? theIObj->DisplayMode()
936 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
937 ? myDefaultDrawer->DisplayMode()
939 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
943 //=======================================================================
944 //function : Redisplay
946 //=======================================================================
947 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
948 const Standard_Boolean theToUpdateViewer,
949 const Standard_Boolean theAllModes)
951 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
952 RecomputeSelectionOnly (theIObj);
955 //=======================================================================
956 //function : Redisplay
958 //=======================================================================
959 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
960 const Standard_Integer /*theSign*/,
961 const Standard_Boolean theToUpdateViewer)
963 Standard_Boolean isRedisplayed = Standard_False;
964 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
966 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
967 if (anObj->Type() != theKOI)
972 Redisplay (anObj, Standard_False);
973 isRedisplayed = anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
977 if (theToUpdateViewer
984 //=======================================================================
985 //function : RecomputePrsOnly
987 //=======================================================================
988 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
989 const Standard_Boolean theToUpdateViewer,
990 const Standard_Boolean theAllModes)
992 if (theIObj.IsNull())
997 theIObj->SetToUpdate();
998 theIObj->UpdatePresentations (theAllModes);
999 if (!theToUpdateViewer)
1004 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1006 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1008 myMainVwr->Update();
1011 //=======================================================================
1012 //function : RecomputeSelectionOnly
1014 //=======================================================================
1015 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1022 mgrSelector->RecomputeSelection (theIO);
1024 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1026 || theIO->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1031 TColStd_ListOfInteger aModes;
1032 ActivatedModes (theIO, aModes);
1033 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1034 for (; aModesIter.More(); aModesIter.Next())
1036 mgrSelector->Activate (theIO, aModesIter.Value());
1040 //=======================================================================
1043 //=======================================================================
1044 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1045 const Standard_Boolean theUpdateViewer)
1047 if (theIObj.IsNull())
1052 theIObj->UpdatePresentations();
1053 mgrSelector->Update(theIObj);
1055 if (theUpdateViewer)
1057 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1059 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1061 myMainVwr->Update();
1066 //=======================================================================
1067 //function : SetLocation
1069 //=======================================================================
1070 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1071 const TopLoc_Location& theLoc)
1073 if (theIObj.IsNull())
1078 if (theIObj->HasTransformation()
1079 && theLoc.IsIdentity())
1081 theIObj->ResetTransformation();
1082 mgrSelector->Update (theIObj, Standard_False);
1085 else if (theLoc.IsIdentity())
1090 // first reset the previous location to properly clean everything...
1091 if (theIObj->HasTransformation())
1093 theIObj->ResetTransformation();
1096 theIObj->SetLocalTransformation (theLoc.Transformation());
1098 mgrSelector->Update (theIObj, Standard_False);
1100 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1101 // to its highlight structure immediately
1102 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1104 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1105 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1111 //=======================================================================
1112 //function : ResetLocation
1114 //=======================================================================
1115 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1117 if (theIObj.IsNull())
1122 theIObj->ResetTransformation();
1123 mgrSelector->Update (theIObj, Standard_False);
1126 //=======================================================================
1127 //function : HasLocation
1129 //=======================================================================
1130 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1132 return !theIObj.IsNull()
1133 && theIObj->HasTransformation();
1136 //=======================================================================
1137 //function : Location
1139 //=======================================================================
1140 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1142 return theIObj->Transformation();
1145 //=======================================================================
1146 //function : SetDeviationCoefficient
1148 //=======================================================================
1149 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1151 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1154 //=======================================================================
1155 //function : SetDeviationAngle
1157 //=======================================================================
1158 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1160 myDefaultDrawer->SetDeviationAngle (theAngle);
1163 //=======================================================================
1164 //function : DeviationAngle
1165 //purpose : Gets deviationAngle
1166 //=======================================================================
1167 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1169 return myDefaultDrawer->DeviationAngle();
1172 //=======================================================================
1173 //function : DeviationCoefficient
1175 //=======================================================================
1176 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1178 return myDefaultDrawer->DeviationCoefficient();
1181 //=======================================================================
1182 //function : SetDisplayMode
1184 //=======================================================================
1185 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1186 const Standard_Boolean theToUpdateViewer)
1188 if (theMode == myDefaultDrawer->DisplayMode())
1193 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1195 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1196 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1197 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1198 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1201 || anObj->HasDisplayMode()
1202 || !anObj->AcceptDisplayMode (theMode))
1207 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1208 aStatus->SetDisplayMode (theMode);
1210 if (anObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1212 myMainPM->Display (anObj, theMode);
1213 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1215 myMainPM->BeginImmediateDraw();
1216 unhighlightGlobal (anObj);
1217 myMainPM->EndImmediateDraw (myMainVwr);
1219 if (aStatus->IsSubIntensityOn())
1221 highlightWithSubintensity (anObj, theMode);
1223 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1227 myDefaultDrawer->SetDisplayMode (theMode);
1228 if (theToUpdateViewer)
1230 myMainVwr->Update();
1234 //=======================================================================
1235 //function : SetDisplayMode
1237 //=======================================================================
1238 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1239 const Standard_Integer theMode,
1240 const Standard_Boolean theToUpdateViewer)
1242 setContextToObject (theIObj);
1243 if (!myObjects.IsBound (theIObj))
1245 theIObj->SetDisplayMode (theMode);
1248 else if (!theIObj->AcceptDisplayMode (theMode))
1253 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1254 if (theIObj->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1256 aStatus->SetDisplayMode (theMode);
1257 theIObj->SetDisplayMode (theMode);
1261 // erase presentations for all display modes different from <aMode>
1262 const Standard_Integer anOldMode = aStatus->DisplayMode();
1263 if (anOldMode != theMode)
1265 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1267 unhighlightGlobal (theIObj);
1269 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1272 aStatus->SetDisplayMode (theMode);
1274 myMainPM->Display (theIObj, theMode);
1275 if (aStatus->IsHilighted())
1277 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1279 if (aStatus->IsSubIntensityOn())
1281 highlightWithSubintensity (theIObj, theMode);
1284 if (theToUpdateViewer)
1286 myMainVwr->Update();
1288 theIObj->SetDisplayMode (theMode);
1291 //=======================================================================
1292 //function : UnsetDisplayMode
1294 //=======================================================================
1295 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1296 const Standard_Boolean theToUpdateViewer)
1298 if (theIObj.IsNull()
1299 || !theIObj->HasDisplayMode())
1304 if (!myObjects.IsBound (theIObj))
1306 theIObj->UnsetDisplayMode();
1310 const Standard_Integer anOldMode = theIObj->DisplayMode();
1311 if (myDefaultDrawer->DisplayMode() == anOldMode)
1316 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1317 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1319 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1321 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1323 unhighlightGlobal (theIObj);
1325 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1326 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1327 if (aStatus->IsHilighted())
1329 highlightSelected (theIObj->GlobalSelOwner());
1331 if (aStatus->IsSubIntensityOn())
1333 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1336 if (theToUpdateViewer)
1338 myMainVwr->Update();
1342 theIObj->UnsetDisplayMode();
1345 //=======================================================================
1346 //function : SetCurrentFacingModel
1348 //=======================================================================
1349 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1350 const Aspect_TypeOfFacingModel theModel)
1352 if (!theIObj.IsNull())
1354 theIObj->SetCurrentFacingModel (theModel);
1358 //=======================================================================
1359 //function : SetColor
1361 //=======================================================================
1362 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1363 const Quantity_Color& theColor,
1364 const Standard_Boolean theToUpdateViewer)
1366 if (theIObj.IsNull())
1371 setContextToObject (theIObj);
1372 theIObj->SetColor (theColor);
1373 theIObj->UpdatePresentations();
1374 if (theToUpdateViewer)
1376 UpdateCurrentViewer();
1380 //=======================================================================
1381 //function : SetIsoOnTriangulation
1383 //=======================================================================
1384 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1385 const Handle(AIS_InteractiveObject)& theObject)
1387 if (theObject.IsNull())
1392 theObject->SetIsoOnTriangulation (theIsEnabled);
1395 //=======================================================================
1396 //function : SetDeviationCoefficient
1398 //=======================================================================
1399 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1400 const Standard_Real theCoefficient,
1401 const Standard_Boolean theToUpdateViewer)
1403 if (theIObj.IsNull())
1408 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1409 setContextToObject (theIObj);
1410 if (theIObj->Type() != AIS_KindOfInteractive_Object
1411 && theIObj->Type() != AIS_KindOfInteractive_Shape)
1415 else if (theIObj->Signature() != 0)
1420 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1421 aShape->SetOwnDeviationCoefficient (theCoefficient);
1422 aShape->UpdatePresentations();
1423 if (theToUpdateViewer)
1425 UpdateCurrentViewer();
1429 //=======================================================================
1430 //function : SetDeviationAngle
1432 //=======================================================================
1433 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1434 const Standard_Real theAngle,
1435 const Standard_Boolean theToUpdateViewer)
1437 if (theIObj.IsNull())
1442 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1443 setContextToObject (theIObj);
1444 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1448 else if (theIObj->Signature() != 0)
1453 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1454 aShape->SetOwnDeviationAngle (theAngle);
1455 aShape->UpdatePresentations();
1456 if (theToUpdateViewer)
1458 UpdateCurrentViewer();
1462 //=======================================================================
1463 //function : SetAngleAndDeviation
1465 //=======================================================================
1466 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1467 const Standard_Real theAngle,
1468 const Standard_Boolean theToUpdateViewer)
1470 if (theIObj.IsNull())
1475 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1476 setContextToObject (theIObj);
1477 if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1481 if (theIObj->Signature() != 0)
1486 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1487 aShape->SetAngleAndDeviation (theAngle);
1488 aShape->UpdatePresentations();
1489 if (theToUpdateViewer)
1491 UpdateCurrentViewer();
1495 //=======================================================================
1496 //function : UnsetColor
1498 //=======================================================================
1499 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1500 const Standard_Boolean theToUpdateViewer)
1502 if (theIObj.IsNull())
1507 theIObj->UnsetColor();
1508 theIObj->UpdatePresentations();
1509 if (theToUpdateViewer)
1511 UpdateCurrentViewer();
1515 //=======================================================================
1516 //function : HasColor
1518 //=======================================================================
1519 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1521 return theIObj->HasColor();
1524 //=======================================================================
1527 //=======================================================================
1528 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1529 Quantity_Color& theColor) const
1531 theIObj->Color (theColor);
1534 //=======================================================================
1537 //=======================================================================
1538 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1540 return theIObj->Width();
1543 //=======================================================================
1544 //function : SetWidth
1546 //=======================================================================
1547 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1548 const Standard_Real theWidth,
1549 const Standard_Boolean theToUpdateViewer)
1551 if (theIObj.IsNull())
1556 setContextToObject (theIObj);
1557 theIObj->SetWidth (theWidth);
1558 theIObj->UpdatePresentations();
1559 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1561 if (myLastPicked->IsAutoHilight())
1563 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1564 myLastPicked->HilightWithColor (myMainPM,
1565 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1570 theIObj->HilightOwnerWithColor (myMainPM,
1571 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1575 if (theToUpdateViewer)
1577 UpdateCurrentViewer();
1581 //=======================================================================
1582 //function : UnsetWidth
1584 //=======================================================================
1585 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1586 const Standard_Boolean theToUpdateViewer)
1588 if (theIObj.IsNull())
1593 theIObj->UnsetWidth();
1594 theIObj->UpdatePresentations();
1595 if (theToUpdateViewer)
1597 UpdateCurrentViewer();
1601 //=======================================================================
1602 //function : SetMaterial
1604 //=======================================================================
1605 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1606 const Graphic3d_MaterialAspect& theMaterial,
1607 const Standard_Boolean theToUpdateViewer)
1609 if (theIObj.IsNull())
1614 setContextToObject (theIObj);
1615 theIObj->SetMaterial (theMaterial);
1616 theIObj->UpdatePresentations();
1617 if (theToUpdateViewer)
1619 UpdateCurrentViewer();
1623 //=======================================================================
1624 //function : UnsetMaterial
1626 //=======================================================================
1627 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1628 const Standard_Boolean theToUpdateViewer)
1630 if (theIObj.IsNull())
1634 theIObj->UnsetMaterial();
1635 theIObj->UpdatePresentations();
1636 if (theToUpdateViewer)
1638 UpdateCurrentViewer();
1642 //=======================================================================
1643 //function : SetTransparency
1645 //=======================================================================
1646 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1647 const Standard_Real theValue,
1648 const Standard_Boolean theToUpdateViewer)
1650 if (theIObj.IsNull())
1655 setContextToObject (theIObj);
1656 if (!theIObj->IsTransparent()
1657 && theValue <= 0.005)
1662 if (theValue <= 0.005)
1664 UnsetTransparency (theIObj, theToUpdateViewer);
1668 theIObj->SetTransparency (theValue);
1669 theIObj->UpdatePresentations();
1670 if (theToUpdateViewer)
1672 UpdateCurrentViewer();
1676 //=======================================================================
1677 //function : UnsetTransparency
1679 //=======================================================================
1680 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1681 const Standard_Boolean theToUpdateViewer)
1683 if (theIObj.IsNull())
1688 theIObj->UnsetTransparency();
1689 theIObj->UpdatePresentations();
1690 if (theToUpdateViewer)
1692 UpdateCurrentViewer();
1696 //=======================================================================
1697 //function : SetSelectedAspect
1699 //=======================================================================
1700 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1701 const Standard_Boolean theToUpdateViewer)
1703 Standard_DISABLE_DEPRECATION_WARNINGS
1704 Standard_Boolean isFound = Standard_False;
1705 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1707 isFound = Standard_True;
1708 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1709 anObj->SetAspect (theAspect);
1711 Standard_ENABLE_DEPRECATION_WARNINGS
1713 if (isFound && theToUpdateViewer)
1715 myMainVwr->Update();
1719 //=======================================================================
1720 //function : SetLocalAttributes
1722 //=======================================================================
1723 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1724 const Handle(Prs3d_Drawer)& theDrawer,
1725 const Standard_Boolean theToUpdateViewer)
1727 if (theIObj.IsNull())
1732 setContextToObject (theIObj);
1733 theIObj->SetAttributes (theDrawer);
1734 Update (theIObj, theToUpdateViewer);
1737 //=======================================================================
1738 //function : UnsetLocalAttributes
1740 //=======================================================================
1741 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1742 const Standard_Boolean theToUpdateViewer)
1744 if (theIObj.IsNull())
1749 setContextToObject (theIObj);
1750 theIObj->UnsetAttributes();
1751 Update (theIObj, theToUpdateViewer);
1754 //=======================================================================
1757 //=======================================================================
1758 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1759 TCollection_ExtendedString& theStatus) const
1762 if (theIObj.IsNull()
1763 || !myObjects.IsBound (theIObj))
1768 theStatus += "\t ____________________________________________";
1769 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1770 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1771 switch (theIObj->DisplayStatus())
1773 case PrsMgr_DisplayStatus_Displayed:
1775 theStatus += "\t| -->Displayed\n";
1778 case PrsMgr_DisplayStatus_Erased:
1780 theStatus += "\t| -->Erased\n";
1787 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1788 theStatus += "\t|\t Mode ";
1789 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1792 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1794 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1795 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1797 theStatus += "\t\t Mode ";
1798 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1801 theStatus += "\t ____________________________________________";
1804 //=======================================================================
1805 //function : GetDefModes
1807 //=======================================================================
1808 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1809 Standard_Integer& theDispMode,
1810 Standard_Integer& theHiMode,
1811 Standard_Integer& theSelMode) const
1813 if (theIObj.IsNull())
1818 theDispMode = theIObj->HasDisplayMode()
1819 ? theIObj->DisplayMode()
1820 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1821 ? myDefaultDrawer->DisplayMode()
1823 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1824 theSelMode = theIObj->GlobalSelectionMode();
1827 //=======================================================================
1828 //function : EraseGlobal
1830 //=======================================================================
1831 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1832 const Standard_Boolean theToUpdateviewer)
1834 Handle(AIS_GlobalStatus) aStatus;
1835 if (theIObj.IsNull()
1836 || !myObjects.Find (theIObj, aStatus)
1837 || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased)
1842 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1843 unselectOwners (theIObj);
1844 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1846 if (!myLastPicked.IsNull()
1847 && myLastPicked->IsSameSelectable (theIObj))
1849 clearDynamicHighlight();
1852 // make sure highlighting presentations are properly erased
1853 theIObj->ErasePresentations (false);
1855 if (IsSelected (theIObj)
1856 && aStatus->DisplayMode() != aDispMode)
1858 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1861 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1863 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1865 aStatus->ClearSelectionModes();
1866 theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Erased);
1868 if (theToUpdateviewer)
1870 myMainVwr->Update();
1874 //=======================================================================
1875 //function : unselectOwners
1877 //=======================================================================
1878 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
1880 SelectMgr_SequenceOfOwner aSeq;
1881 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1883 if (aSelIter.Value()->IsSameSelectable (theObject))
1885 aSeq.Append (aSelIter.Value());
1888 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1890 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
1894 //=======================================================================
1895 //function : ClearGlobal
1897 //=======================================================================
1898 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1899 const Standard_Boolean theToUpdateviewer)
1901 Handle(AIS_GlobalStatus) aStatus;
1902 if (theIObj.IsNull()
1903 || !myObjects.Find (theIObj, aStatus))
1905 // for cases when reference shape of connected interactives was not displayed
1906 // but its selection primitives were calculated
1907 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1908 mgrSelector->Remove (anObj);
1912 unselectOwners (theIObj);
1914 myMainPM->Erase (theIObj, -1);
1915 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
1917 // Object removes from Detected sequence
1918 Standard_DISABLE_DEPRECATION_WARNINGS
1919 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
1921 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
1922 Handle(AIS_InteractiveObject) anObj;
1923 if (!aPicked.IsNull())
1925 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
1929 && anObj == theIObj)
1931 myDetectedSeq.Remove (aDetIter);
1932 if (myCurDetected == aDetIter)
1934 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
1936 if (myCurHighlighted == aDetIter)
1938 myCurHighlighted = 0;
1946 Standard_ENABLE_DEPRECATION_WARNINGS
1948 // remove IO from the selection manager to avoid memory leaks
1949 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1950 mgrSelector->Remove (anObj);
1952 setObjectStatus (theIObj, PrsMgr_DisplayStatus_None, -1, -1);
1953 myMainVwr->StructureManager()->UnregisterObject (theIObj);
1955 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
1957 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
1960 if (!myLastPicked.IsNull())
1962 if (myLastPicked->IsSameSelectable (theIObj))
1964 clearDynamicHighlight();
1965 myLastPicked.Nullify();
1969 if (theToUpdateviewer
1970 && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1972 myMainVwr->Update();
1976 //=======================================================================
1977 //function : ClearGlobalPrs
1979 //=======================================================================
1980 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
1981 const Standard_Integer theMode,
1982 const Standard_Boolean theToUpdateViewer)
1984 const Handle(AIS_GlobalStatus)* aStatus = !theIObj.IsNull() ? myObjects.Seek (theIObj) : NULL;
1985 if (aStatus == NULL)
1990 if ((*aStatus)->DisplayMode() == theMode)
1992 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1993 if (aDispMode == theMode
1994 && myMainPM->IsHighlighted (theIObj, theMode))
1996 unhighlightGlobal (theIObj);
1999 myMainPM->Erase (theIObj, theMode);
2002 if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
2003 && theToUpdateViewer)
2005 myMainVwr->Update();
2009 //=======================================================================
2010 //function : ClearDetected
2012 //=======================================================================
2013 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2016 myCurHighlighted = 0;
2017 myDetectedSeq.Clear();
2018 Standard_Boolean toUpdate = Standard_False;
2019 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2021 toUpdate = Standard_True;
2022 clearDynamicHighlight();
2024 myLastPicked.Nullify();
2025 myMainSel->ClearPicked();
2026 if (toUpdate && theToRedrawImmediate)
2028 myMainVwr->RedrawImmediate();
2033 //=======================================================================
2034 //function : DrawHiddenLine
2036 //=======================================================================
2037 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2039 return myDefaultDrawer->DrawHiddenLine();
2042 //=======================================================================
2043 //function : EnableDrawHiddenLine
2045 //=======================================================================
2046 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2048 myDefaultDrawer->EnableDrawHiddenLine();
2051 //=======================================================================
2052 //function : DisableDrawHiddenLine
2054 //=======================================================================
2055 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2057 myDefaultDrawer->DisableDrawHiddenLine();
2060 //=======================================================================
2061 //function : HiddenLineAspect
2063 //=======================================================================
2064 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2066 return myDefaultDrawer->HiddenLineAspect();
2069 //=======================================================================
2070 //function : SetHiddenLineAspect
2072 //=======================================================================
2073 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2075 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2078 //=======================================================================
2079 //function : SetIsoNumber
2081 //=======================================================================
2082 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2083 const AIS_TypeOfIso theType)
2088 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2091 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2094 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2095 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2100 //=======================================================================
2101 //function : IsoNumber
2103 //=======================================================================
2104 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2108 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2109 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2110 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2111 ? myDefaultDrawer->UIsoAspect()->Number()
2117 //=======================================================================
2118 //function : IsoOnPlane
2120 //=======================================================================
2121 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2123 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2126 //=======================================================================
2127 //function : IsoOnPlane
2129 //=======================================================================
2130 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2132 return myDefaultDrawer->IsoOnPlane();
2135 //=======================================================================
2136 //function : IsoOnTriangulation
2138 //=======================================================================
2139 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2141 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2144 //=======================================================================
2145 //function : IsoOnTriangulation
2147 //=======================================================================
2148 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2150 return myDefaultDrawer->IsoOnTriangulation();
2153 //=======================================================================
2154 //function : SetPixelTolerance
2156 //=======================================================================
2157 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2159 myMainSel->SetPixelTolerance (thePrecision);
2162 //=======================================================================
2163 //function : PixelTolerance
2165 //=======================================================================
2166 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2168 return myMainSel->PixelTolerance();
2171 //=======================================================================
2172 //function : SetSelectionSensitivity
2173 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2174 //=======================================================================
2175 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2176 const Standard_Integer theMode,
2177 const Standard_Integer theNewSensitivity)
2179 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2182 //=======================================================================
2183 //function : InitAttributes
2185 //=======================================================================
2186 void AIS_InteractiveContext::InitAttributes()
2188 Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Brass);
2189 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2191 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2192 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2193 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2194 aLineAspect->SetWidth (1.0);
2195 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2197 // tolerance to 2 pixels...
2198 SetPixelTolerance (2);
2200 // Customizing the drawer for trihedrons and planes...
2201 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2202 const Standard_Real aLength = 100.0;
2203 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2204 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2205 aTrihAspect->LineAspect(Prs3d_DatumParts_XAxis)->SetColor (aColor);
2206 aTrihAspect->LineAspect(Prs3d_DatumParts_YAxis)->SetColor (aColor);
2207 aTrihAspect->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor (aColor);
2209 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2210 const Standard_Real aPlaneLength = 200.0;
2211 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2212 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2215 //=======================================================================
2216 //function : TrihedronSize
2218 //=======================================================================
2219 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2221 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
2224 //=======================================================================
2225 //function : SetTrihedronSize
2227 //=======================================================================
2228 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2229 const Standard_Boolean /*updateviewer*/)
2231 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2232 Redisplay (AIS_KindOfInteractive_Datum, 3, Standard_False);
2233 Redisplay (AIS_KindOfInteractive_Datum, 4, Standard_True);
2236 //=======================================================================
2237 //function : SetPlaneSize
2239 //=======================================================================
2240 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2241 const Standard_Real theValY,
2242 const Standard_Boolean theToUpdateViewer)
2244 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2245 Redisplay (AIS_KindOfInteractive_Datum, 7, theToUpdateViewer);
2248 //=======================================================================
2249 //function : SetPlaneSize
2251 //=======================================================================
2252 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2253 const Standard_Boolean theToUpdateViewer)
2255 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2258 //=======================================================================
2259 //function : PlaneSize
2261 //=======================================================================
2262 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2263 Standard_Real& theY) const
2265 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2266 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2267 return (Abs (theX - theY) <= Precision::Confusion());
2270 //=======================================================================
2271 //function : SetZLayer
2273 //=======================================================================
2274 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2275 const Graphic3d_ZLayerId theLayerId)
2277 if (theIObj.IsNull())
2280 theIObj->SetZLayer (theLayerId);
2283 //=======================================================================
2284 //function : GetZLayer
2286 //=======================================================================
2287 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2289 return !theIObj.IsNull()
2291 : Graphic3d_ZLayerId_UNKNOWN;
2294 //=======================================================================
2295 //function : RebuildSelectionStructs
2296 //purpose : Rebuilds 1st level of BVH selection forcibly
2297 //=======================================================================
2298 void AIS_InteractiveContext::RebuildSelectionStructs()
2300 myMainSel->RebuildObjectsTree (Standard_True);
2303 //=======================================================================
2304 //function : Disconnect
2305 //purpose : Disconnects selectable object from an assembly and updates selection structures
2306 //=======================================================================
2307 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2308 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2310 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2312 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2313 theObj->Disconnect (theObjToDisconnect);
2314 if (!myObjects.IsBound (theObjToDisconnect))
2316 // connected presentation might contain displayed presentations
2317 myMainPM->Erase (theObjToDisconnect, -1);
2318 theObjToDisconnect->ErasePresentations (true);
2321 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2322 mgrSelector->Remove (anObj);
2324 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2326 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2327 theObj->Disconnect();
2328 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2329 mgrSelector->Remove (anObj);
2335 //=======================================================================
2336 //function : FitSelected
2337 //purpose : Fits the view corresponding to the bounds of selected objects
2338 //=======================================================================
2339 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2341 FitSelected (theView, 0.01, Standard_True);
2344 //=======================================================================
2345 //function : BoundingBoxOfSelection
2347 //=======================================================================
2348 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
2350 Bnd_Box aBndSelected;
2351 AIS_MapOfObjectOwners anObjectOwnerMap;
2352 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2354 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2355 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2356 if (anObj->IsInfinite())
2361 if (anOwner == anObj->GlobalSelOwner())
2364 anObj->BoundingBox (aTmpBnd);
2365 aBndSelected.Add (aTmpBnd);
2369 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2370 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2372 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2373 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2376 anOwnerMap->Add (anOwner);
2380 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2382 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2383 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2384 aBndSelected.Add (aTmpBox);
2387 return aBndSelected;
2390 //=======================================================================
2391 //function : FitSelected
2392 //purpose : Fits the view corresponding to the bounds of selected objects
2393 //=======================================================================
2394 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2395 const Standard_Real theMargin,
2396 const Standard_Boolean theToUpdate)
2398 Bnd_Box aBndSelected = BoundingBoxOfSelection();
2399 if (!aBndSelected.IsVoid())
2401 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2405 //=======================================================================
2406 //function : SetTransformPersistence
2408 //=======================================================================
2409 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2410 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2412 theObject->SetTransformPersistence (theTrsfPers);
2413 if (!myObjects.IsBound (theObject))
2418 mgrSelector->UpdateSelection (theObject);
2420 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2421 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2422 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2424 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2425 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2429 //=======================================================================
2430 //function : GravityPoint
2432 //=======================================================================
2433 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2435 return theView->GravityPoint();
2438 //=======================================================================
2439 //function : setObjectStatus
2441 //=======================================================================
2442 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2443 const PrsMgr_DisplayStatus theStatus,
2444 const Standard_Integer theDispMode,
2445 const Standard_Integer theSelectionMode)
2447 theIObj->SetDisplayStatus (theStatus);
2448 if (theStatus != PrsMgr_DisplayStatus_None)
2450 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (theDispMode, theSelectionMode);
2451 myObjects.Bind (theIObj, aStatus);
2455 myObjects.UnBind (theIObj);
2458 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2460 Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2461 if (aChild.IsNull())
2466 setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);