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)
70 theDrawer->SetMethod (Aspect_TOHM_COLOR);
71 theDrawer->SetDisplayMode (0);
73 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
74 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
75 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
76 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
77 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
78 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
79 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
80 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
81 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
82 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
83 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
84 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
86 theDrawer->WireAspect()->SetWidth (2.0);
87 theDrawer->LineAspect()->SetWidth (2.0);
88 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
89 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
90 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
91 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
92 theDrawer->PointAspect()->SetScale (2.0);
94 // the triangulation should be computed using main presentation attributes,
95 // and should not be overridden by highlighting
96 theDrawer->SetAutoTriangulation (Standard_False);
100 //=======================================================================
101 //function : AIS_InteractiveContext
103 //=======================================================================
105 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
106 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
107 myMainVwr(MainViewer),
108 myMainSel(new StdSelect_ViewerSelector3d()),
109 myWasLastMain(Standard_False),
110 myToHilightSelected(Standard_True),
111 mySelection(new AIS_Selection()),
112 myFilters(new SelectMgr_OrFilter()),
113 myDefaultDrawer(new Prs3d_Drawer()),
116 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
117 myAutoHilight(Standard_True),
118 myIsAutoActivateSelMode(Standard_True)
120 mgrSelector = new SelectMgr_SelectionManager (myMainSel);
122 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
123 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
124 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
125 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
126 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
127 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
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);
135 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
136 aStyle->SetColor (Quantity_NOC_CYAN1);
139 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
140 aStyle->Link (myDefaultDrawer);
141 initDefaultHilightAttributes (aStyle);
142 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
143 aStyle->SetColor (Quantity_NOC_CYAN1);
146 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
147 aStyle->Link (myDefaultDrawer);
148 initDefaultHilightAttributes (aStyle);
149 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
150 aStyle->SetColor (Quantity_NOC_GRAY80);
153 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
154 aStyle->Link (myDefaultDrawer);
155 initDefaultHilightAttributes (aStyle);
156 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
157 aStyle->SetColor (Quantity_NOC_GRAY80);
160 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
161 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
162 aStyle->SetMethod(Aspect_TOHM_COLOR);
163 aStyle->SetColor (Quantity_NOC_GRAY40);
169 //=======================================================================
170 //function : ~AIS_InteractiveContext
172 //=======================================================================
173 AIS_InteractiveContext::~AIS_InteractiveContext()
175 // clear the current selection
176 mySelection->Clear();
177 mgrSelector.Nullify();
179 Handle(AIS_InteractiveContext) aNullContext;
180 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
182 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
183 anObj->SetContext (aNullContext);
184 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
186 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
191 //=======================================================================
192 //function : UpdateCurrentViewer
194 //=======================================================================
196 void AIS_InteractiveContext::UpdateCurrentViewer()
198 if (!myMainVwr.IsNull())
202 //=======================================================================
203 //function : DisplayedObjects
205 //=======================================================================
206 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
208 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
210 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
212 theListOfIO.Append (anObjIter.Key());
217 //=======================================================================
218 //function : DisplayedObjects
220 //=======================================================================
221 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
222 const Standard_Integer theSign,
223 AIS_ListOfInteractive& theListOfIO) const
225 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
228 //=======================================================================
229 //function : ErasedObjects
231 //=======================================================================
232 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
234 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
237 //=======================================================================
238 //function : ErasedObjects
240 //=======================================================================
241 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
242 const Standard_Integer theSign,
243 AIS_ListOfInteractive& theListOfIO) const
245 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
248 //=======================================================================
249 //function : ObjectsByDisplayStatus
251 //=======================================================================
252 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
253 AIS_ListOfInteractive& theListOfIO) const
255 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
257 if (anObjIter.Value()->GraphicStatus() == theStatus)
259 theListOfIO.Append (anObjIter.Key());
264 //=======================================================================
265 //function : ObjectsByDisplayStatus
267 //=======================================================================
268 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
269 const Standard_Integer theSign,
270 const AIS_DisplayStatus theStatus,
271 AIS_ListOfInteractive& theListOfIO) const
273 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
275 if (theStatus != AIS_DS_None
276 && anObjIter.Value()->GraphicStatus() != theStatus)
280 else if (anObjIter.Key()->Type() != theKind)
286 || anObjIter.Key()->Signature() == theSign)
288 theListOfIO.Append (anObjIter.Key());
293 //=======================================================================
294 //function : ObjectsInside
296 //=======================================================================
297 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
298 const AIS_KindOfInteractive theKind,
299 const Standard_Integer theSign) const
301 if (theKind == AIS_KOI_None
304 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
306 theListOfIO.Append (anObjIter.Key());
311 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
313 if (anObjIter.Key()->Type() != theKind)
319 || anObjIter.Key()->Signature() == theSign)
321 theListOfIO.Append (anObjIter.Key());
326 //=======================================================================
327 //function : ObjectsForView
329 //=======================================================================
330 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
331 const Handle(V3d_View)& theView,
332 const Standard_Boolean theIsVisibleInView,
333 const AIS_DisplayStatus theStatus) const
335 Handle(Graphic3d_CView) aViewImpl = theView->View();
336 const Standard_Integer aViewId = aViewImpl->Identification();
337 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
339 if (theStatus != AIS_DS_None
340 && anObjIter.Value()->GraphicStatus() != theStatus)
342 theListOfIO.Append (anObjIter.Key());
346 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
347 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
348 if (isVisible == theIsVisibleInView)
350 theListOfIO.Append (anObjIter.Key());
355 //=======================================================================
358 //=======================================================================
359 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
360 const Standard_Boolean theToUpdateViewer)
362 if (theIObj.IsNull())
367 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
368 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
369 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
372 //=======================================================================
373 //function : SetViewAffinity
375 //=======================================================================
376 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
377 const Handle(V3d_View)& theView,
378 const Standard_Boolean theIsVisible)
381 || !myObjects.IsBound (theIObj))
386 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
387 Handle(Graphic3d_CView) aViewImpl = theView->View();
388 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
391 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
395 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
399 //=======================================================================
402 //=======================================================================
403 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
404 const Standard_Integer theDispMode,
405 const Standard_Integer theSelectionMode,
406 const Standard_Boolean theToUpdateViewer,
407 const AIS_DisplayStatus theDispStatus)
409 if (theIObj.IsNull())
414 if (theDispStatus == AIS_DS_Erased)
416 Erase (theIObj, theToUpdateViewer);
417 Load (theIObj, theSelectionMode);
418 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
420 (*aStatusPtr)->SetDisplayMode (theDispMode);
425 setContextToObject (theIObj);
426 if (!myObjects.IsBound (theIObj))
428 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
429 myObjects.Bind (theIObj, aStatus);
430 myMainVwr->StructureManager()->RegisterObject (theIObj);
431 myMainPM->Display(theIObj, theDispMode);
432 if (theSelectionMode != -1)
434 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
435 if (!mgrSelector->Contains (anObj))
437 mgrSelector->Load (theIObj);
439 mgrSelector->Activate (theIObj, theSelectionMode);
444 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
446 // Mark the presentation modes hidden of interactive object different from aDispMode.
447 // Then make sure aDispMode is displayed and maybe highlighted.
448 // Finally, activate selection mode <SelMode> if not yet activated.
449 const Standard_Integer anOldMode = aStatus->DisplayMode();
450 if (anOldMode != theDispMode)
452 if(myMainPM->IsHighlighted (theIObj, anOldMode))
454 unhighlightGlobal (theIObj);
456 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
459 aStatus->SetDisplayMode (theDispMode);
461 myMainPM->Display (theIObj, theDispMode);
462 aStatus->SetGraphicStatus (AIS_DS_Displayed);
463 if (aStatus->IsHilighted())
465 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
467 if (theSelectionMode != -1)
469 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
470 if (!mgrSelector->Contains (anObj))
472 mgrSelector->Load (theIObj);
474 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
476 if (!aStatus->IsSModeIn (theSelectionMode))
477 aStatus->AddSelectionMode (theSelectionMode);
478 mgrSelector->Activate (theIObj, theSelectionMode);
483 if (theToUpdateViewer)
489 //=======================================================================
492 //=======================================================================
493 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
494 const Standard_Integer theSelMode)
496 if (theIObj.IsNull())
501 setContextToObject (theIObj);
502 if (!myObjects.IsBound (theIObj))
504 Standard_Integer aDispMode, aHiMod, aSelModeDef;
505 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
506 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
507 myObjects.Bind (theIObj, aStatus);
508 myMainVwr->StructureManager()->RegisterObject (theIObj);
511 // Register theIObj in the selection manager to prepare further activation of selection
512 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
513 if (!mgrSelector->Contains (anObj))
515 mgrSelector->Load (theIObj);
519 //=======================================================================
522 //=======================================================================
523 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
524 const Standard_Boolean theToUpdateViewer)
526 if (theIObj.IsNull())
531 if (!theIObj->IsAutoHilight())
533 theIObj->ClearSelected();
536 EraseGlobal (theIObj, Standard_False);
537 if (theToUpdateViewer)
543 //=======================================================================
544 //function : EraseAll
546 //=======================================================================
547 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
549 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
551 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
553 Erase (anObjIter.Key(), Standard_False);
557 if (theToUpdateViewer)
563 //=======================================================================
564 //function : DisplayAll
566 //=======================================================================
567 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
569 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
571 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
572 if (aStatus == AIS_DS_Erased)
574 Display (anObjIter.Key(), Standard_False);
578 if (theToUpdateViewer)
584 //=======================================================================
585 //function : DisplaySelected
587 //=======================================================================
588 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
590 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
592 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
593 Display (anObj, Standard_False);
596 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
602 //=======================================================================
603 //function : EraseSelected
605 //=======================================================================
606 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
608 Standard_Boolean isFound = Standard_False;
609 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
611 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
612 Erase (anObj, Standard_False);
613 isFound = Standard_True;
616 if (isFound && theToUpdateViewer)
622 //=======================================================================
623 //function : DisplayStatus
625 //=======================================================================
626 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
628 if (theIObj.IsNull())
632 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
633 return aStatus != NULL ? (*aStatus)->GraphicStatus() : AIS_DS_None;
636 //=======================================================================
639 //=======================================================================
640 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
641 const Standard_Boolean theToUpdateViewer)
643 if (theIObj.IsNull())
648 if (theIObj->HasInteractiveContext())
650 if (theIObj->myCTXPtr != this)
652 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
654 theIObj->SetContext (Handle(AIS_InteractiveContext)());
656 ClearGlobal (theIObj, theToUpdateViewer);
659 //=======================================================================
660 //function : RemoveAll
662 //=======================================================================
663 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
665 AIS_ListOfInteractive aList;
666 ObjectsInside (aList);
667 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
669 Remove (aListIterator.Value(), Standard_False);
672 if (theToUpdateViewer)
678 //=======================================================================
679 //function : HilightWithColor
681 //=======================================================================
682 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
683 const Handle(Prs3d_Drawer)& theStyle,
684 const Standard_Boolean theIsToUpdate)
689 setContextToObject (theObj);
690 if (!myObjects.IsBound (theObj))
693 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
694 aStatus->SetHilightStatus (Standard_True);
696 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
698 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
699 aStatus->SetHilightStyle (theStyle);
706 //=======================================================================
707 //function : Unhilight
709 //=======================================================================
710 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
712 if(anIObj.IsNull()) return;
713 if(!myObjects.IsBound(anIObj)) return;
715 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
716 aStatus->SetHilightStatus (Standard_False);
717 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
719 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
721 unhighlightGlobal (anIObj);
724 if(updateviewer) myMainVwr->Update();
727 //=======================================================================
728 //function : IsHilighted
729 //purpose : Returns true if the objects global status is set to highlighted.
730 //=======================================================================
731 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
733 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
734 return aStatus != NULL
735 && (*aStatus)->IsHilighted();
738 //=======================================================================
739 //function : IsHilighted
740 //purpose : Returns true if the owner is highlighted with selection style.
741 //=======================================================================
742 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
744 if (theOwner.IsNull() || !theOwner->HasSelectable())
745 return Standard_False;
747 const Handle(AIS_InteractiveObject) anObj =
748 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
750 if (anObj->GlobalSelOwner() == theOwner)
752 if (!myObjects.IsBound (anObj))
753 return Standard_False;
755 return myObjects (anObj)->IsHilighted();
758 return theOwner->IsSelected();
761 //=======================================================================
762 //function : HighlightStyle
764 //=======================================================================
765 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
766 Handle(Prs3d_Drawer)& theStyle) const
768 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
770 && (*aStatus)->IsHilighted())
772 theStyle = (*aStatus)->HilightStyle();
773 return Standard_True;
777 return Standard_False;
780 //=======================================================================
781 //function : HighlightStyle
783 //=======================================================================
784 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
785 Handle(Prs3d_Drawer)& theStyle) const
787 if (theOwner.IsNull() || !theOwner->HasSelectable())
788 return Standard_False;
790 if (IsHilighted (theOwner))
792 const Handle(AIS_InteractiveObject) anObj =
793 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
794 if (anObj->GlobalSelOwner() == theOwner)
796 theStyle = myObjects (anObj)->HilightStyle();
800 // since part selection style is not stored in global status,
801 // check if the object has own selection style. If not, it can
802 // only be highlighted with default selection style (because
803 // sub-intensity does not modify any selection states)
804 theStyle = getSelStyle (anObj, theOwner);
806 return Standard_True;
811 return Standard_False;
815 //=======================================================================
816 //function : IsDisplayed
818 //=======================================================================
820 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
822 if(theObj.IsNull()) return Standard_False;
824 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
825 return aStatus != NULL
826 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed;
829 //=======================================================================
830 //function : IsDisplayed
832 //=======================================================================
833 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
834 const Standard_Integer theMode) const
836 if (theIObj.IsNull())
838 return Standard_False;
841 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
842 return aStatus != NULL
843 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed
844 && (*aStatus)->DisplayMode() == theMode;
847 //=======================================================================
848 //function : DisplayPriority
850 //=======================================================================
851 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
853 if (theIObj.IsNull())
858 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
860 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
861 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
863 Standard_Integer aDispMode = theIObj->HasDisplayMode()
864 ? theIObj->DisplayMode()
865 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
866 ? myDefaultDrawer->DisplayMode()
868 return myMainPM->DisplayPriority (theIObj, aDispMode);
873 //=======================================================================
874 //function : SetDisplayPriority
876 //=======================================================================
877 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
878 const Standard_Integer thePriority)
880 if (theIObj.IsNull())
885 setContextToObject (theIObj);
886 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
888 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
889 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
891 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
892 ? theIObj->DisplayMode()
893 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
894 ? myDefaultDrawer->DisplayMode()
896 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
900 //=======================================================================
901 //function : Redisplay
903 //=======================================================================
904 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
905 const Standard_Boolean theToUpdateViewer,
906 const Standard_Boolean theAllModes)
908 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
909 RecomputeSelectionOnly (theIObj);
912 //=======================================================================
913 //function : Redisplay
915 //=======================================================================
916 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
917 const Standard_Integer /*theSign*/,
918 const Standard_Boolean theToUpdateViewer)
920 Standard_Boolean isRedisplayed = Standard_False;
921 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
923 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
924 if (anObj->Type() != theKOI)
929 Redisplay (anObj, Standard_False);
930 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
934 if (theToUpdateViewer
941 //=======================================================================
942 //function : RecomputePrsOnly
944 //=======================================================================
945 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
946 const Standard_Boolean theToUpdateViewer,
947 const Standard_Boolean theAllModes)
949 if (theIObj.IsNull())
954 theIObj->SetToUpdate();
955 theIObj->UpdatePresentations (theAllModes);
956 if (!theToUpdateViewer)
961 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
963 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
968 //=======================================================================
969 //function : RecomputeSelectionOnly
971 //=======================================================================
972 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
979 mgrSelector->RecomputeSelection (theIO);
981 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
983 || (*aStatus)->GraphicStatus() != AIS_DS_Displayed)
988 TColStd_ListOfInteger aModes;
989 ActivatedModes (theIO, aModes);
990 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
991 for (; aModesIter.More(); aModesIter.Next())
993 mgrSelector->Activate (theIO, aModesIter.Value());
997 //=======================================================================
1000 //=======================================================================
1001 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1002 const Standard_Boolean theUpdateViewer)
1004 if (theIObj.IsNull())
1009 theIObj->UpdatePresentations();
1010 mgrSelector->Update(theIObj);
1012 if (theUpdateViewer)
1014 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1016 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
1018 myMainVwr->Update();
1023 //=======================================================================
1024 //function : SetLocation
1026 //=======================================================================
1027 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1028 const TopLoc_Location& theLoc)
1030 if (theIObj.IsNull())
1035 if (theIObj->HasTransformation()
1036 && theLoc.IsIdentity())
1038 theIObj->ResetTransformation();
1039 mgrSelector->Update (theIObj, Standard_False);
1042 else if (theLoc.IsIdentity())
1047 // first reset the previous location to properly clean everything...
1048 if (theIObj->HasTransformation())
1050 theIObj->ResetTransformation();
1053 theIObj->SetLocalTransformation (theLoc.Transformation());
1055 mgrSelector->Update (theIObj, Standard_False);
1057 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1058 // to its highlight structure immediately
1059 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1061 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1062 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1068 //=======================================================================
1069 //function : ResetLocation
1071 //=======================================================================
1072 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1074 if (theIObj.IsNull())
1079 theIObj->ResetTransformation();
1080 mgrSelector->Update (theIObj, Standard_False);
1083 //=======================================================================
1084 //function : HasLocation
1086 //=======================================================================
1087 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1089 return !theIObj.IsNull()
1090 && theIObj->HasTransformation();
1093 //=======================================================================
1094 //function : Location
1096 //=======================================================================
1097 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1099 return theIObj->Transformation();
1102 //=======================================================================
1103 //function : SetDeviationCoefficient
1105 //=======================================================================
1106 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1108 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1111 //=======================================================================
1112 //function : SetDeviationAngle
1114 //=======================================================================
1115 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1117 myDefaultDrawer->SetDeviationAngle (theAngle);
1120 //=======================================================================
1121 //function : DeviationAngle
1122 //purpose : Gets deviationAngle
1123 //=======================================================================
1124 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1126 return myDefaultDrawer->DeviationAngle();
1129 //=======================================================================
1130 //function : DeviationCoefficient
1132 //=======================================================================
1133 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1135 return myDefaultDrawer->DeviationCoefficient();
1138 //=======================================================================
1139 //function : SetHLRDeviationCoefficient
1141 //=======================================================================
1142 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1144 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1147 //=======================================================================
1148 //function : HLRDeviationCoefficient
1150 //=======================================================================
1151 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1153 return myDefaultDrawer->HLRDeviationCoefficient();
1156 //=======================================================================
1157 //function : SetHLRAngle
1159 //=======================================================================
1160 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1162 myDefaultDrawer->SetHLRAngle (theAngle);
1165 //=======================================================================
1166 //function : SetHLRAngleAndDeviation
1167 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1168 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1169 // of myDefaultDrawer
1170 //=======================================================================
1171 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1173 Standard_Real anOutAngl, anOutDefl;
1174 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1176 myDefaultDrawer->SetHLRAngle (anOutAngl);
1177 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1180 //=======================================================================
1181 //function : HLRAngle
1183 //=======================================================================
1184 Standard_Real AIS_InteractiveContext::HLRAngle() const
1186 return myDefaultDrawer->HLRAngle();
1189 //=======================================================================
1190 //function : SetDisplayMode
1192 //=======================================================================
1193 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1194 const Standard_Boolean theToUpdateViewer)
1196 if (theMode == myDefaultDrawer->DisplayMode())
1201 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1203 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1204 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1205 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1206 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1209 || anObj->HasDisplayMode()
1210 || !anObj->AcceptDisplayMode (theMode))
1215 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1216 aStatus->SetDisplayMode (theMode);
1218 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1220 myMainPM->Display (anObj, theMode);
1221 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1223 myMainPM->BeginImmediateDraw();
1224 unhighlightGlobal (anObj);
1225 myMainPM->EndImmediateDraw (myMainVwr);
1227 if (aStatus->IsSubIntensityOn())
1229 highlightWithSubintensity (anObj, theMode);
1231 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1235 myDefaultDrawer->SetDisplayMode (theMode);
1236 if (theToUpdateViewer)
1238 myMainVwr->Update();
1242 //=======================================================================
1243 //function : SetDisplayMode
1245 //=======================================================================
1246 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1247 const Standard_Integer theMode,
1248 const Standard_Boolean theToUpdateViewer)
1250 setContextToObject (theIObj);
1251 if (!myObjects.IsBound (theIObj))
1253 theIObj->SetDisplayMode (theMode);
1256 else if (!theIObj->AcceptDisplayMode (theMode))
1261 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1262 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1264 aStatus->SetDisplayMode (theMode);
1265 theIObj->SetDisplayMode (theMode);
1269 // erase presentations for all display modes different from <aMode>
1270 const Standard_Integer anOldMode = aStatus->DisplayMode();
1271 if (anOldMode != theMode)
1273 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1275 unhighlightGlobal (theIObj);
1277 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1280 aStatus->SetDisplayMode (theMode);
1282 myMainPM->Display (theIObj, theMode);
1283 if (aStatus->IsHilighted())
1285 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1287 if (aStatus->IsSubIntensityOn())
1289 highlightWithSubintensity (theIObj, theMode);
1292 if (theToUpdateViewer)
1294 myMainVwr->Update();
1296 theIObj->SetDisplayMode (theMode);
1299 //=======================================================================
1300 //function : UnsetDisplayMode
1302 //=======================================================================
1303 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1304 const Standard_Boolean theToUpdateViewer)
1306 if (theIObj.IsNull()
1307 || !theIObj->HasDisplayMode())
1312 if (!myObjects.IsBound (theIObj))
1314 theIObj->UnsetDisplayMode();
1318 const Standard_Integer anOldMode = theIObj->DisplayMode();
1319 if (myDefaultDrawer->DisplayMode() == anOldMode)
1324 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1325 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1327 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1329 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1331 unhighlightGlobal (theIObj);
1333 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1334 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1335 if (aStatus->IsHilighted())
1337 highlightSelected (theIObj->GlobalSelOwner());
1339 if (aStatus->IsSubIntensityOn())
1341 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1344 if (theToUpdateViewer)
1346 myMainVwr->Update();
1350 theIObj->UnsetDisplayMode();
1353 //=======================================================================
1354 //function : SetCurrentFacingModel
1356 //=======================================================================
1357 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1358 const Aspect_TypeOfFacingModel theModel)
1360 if (!theIObj.IsNull())
1362 theIObj->SetCurrentFacingModel (theModel);
1366 //=======================================================================
1367 //function : SetColor
1369 //=======================================================================
1370 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1371 const Quantity_Color& theColor,
1372 const Standard_Boolean theToUpdateViewer)
1374 if (theIObj.IsNull())
1379 setContextToObject (theIObj);
1380 theIObj->SetColor (theColor);
1381 theIObj->UpdatePresentations();
1382 if (theToUpdateViewer)
1384 UpdateCurrentViewer();
1388 //=======================================================================
1389 //function : SetIsoOnTriangulation
1391 //=======================================================================
1392 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1393 const Handle(AIS_InteractiveObject)& theObject)
1395 if (theObject.IsNull())
1400 theObject->SetIsoOnTriangulation (theIsEnabled);
1403 //=======================================================================
1404 //function : SetDeviationCoefficient
1406 //=======================================================================
1407 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1408 const Standard_Real theCoefficient,
1409 const Standard_Boolean theToUpdateViewer)
1411 if (theIObj.IsNull())
1416 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1417 setContextToObject (theIObj);
1418 if (theIObj->Type() != AIS_KOI_Object
1419 && theIObj->Type() != AIS_KOI_Shape)
1423 else if (theIObj->Signature() != 0)
1428 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1429 aShape->SetOwnDeviationCoefficient (theCoefficient);
1430 aShape->UpdatePresentations();
1431 if (theToUpdateViewer)
1433 UpdateCurrentViewer();
1437 //=======================================================================
1438 //function : SetHLRDeviationCoefficient
1440 //=======================================================================
1441 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1442 const Standard_Real theCoefficient,
1443 const Standard_Boolean theToUpdateViewer)
1445 if (theIObj.IsNull())
1450 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1451 setContextToObject (theIObj);
1452 if (theIObj->Type() != AIS_KOI_Object
1453 && theIObj->Type() != AIS_KOI_Shape)
1457 else if (theIObj->Signature() != 0)
1462 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1463 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1464 aShape->UpdatePresentations();
1465 if (theToUpdateViewer)
1467 UpdateCurrentViewer();
1471 //=======================================================================
1472 //function : SetDeviationAngle
1474 //=======================================================================
1475 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1476 const Standard_Real theAngle,
1477 const Standard_Boolean theToUpdateViewer)
1479 if (theIObj.IsNull())
1484 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1485 setContextToObject (theIObj);
1486 if (theIObj->Type() != AIS_KOI_Shape)
1490 else if (theIObj->Signature() != 0)
1495 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1496 aShape->SetOwnDeviationAngle (theAngle);
1497 aShape->UpdatePresentations();
1498 if (theToUpdateViewer)
1500 UpdateCurrentViewer();
1504 //=======================================================================
1505 //function : SetAngleAndDeviation
1507 //=======================================================================
1508 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1509 const Standard_Real theAngle,
1510 const Standard_Boolean theToUpdateViewer)
1512 if (theIObj.IsNull())
1517 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1518 setContextToObject (theIObj);
1519 if (theIObj->Type() != AIS_KOI_Shape)
1523 if (theIObj->Signature() != 0)
1528 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1529 aShape->SetAngleAndDeviation (theAngle);
1530 aShape->UpdatePresentations();
1531 if (theToUpdateViewer)
1533 UpdateCurrentViewer();
1537 //=======================================================================
1538 //function : SetHLRAngleAndDeviation
1540 //=======================================================================
1541 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1542 const Standard_Real theAngle,
1543 const Standard_Boolean theToUpdateViewer)
1545 if (theIObj.IsNull())
1550 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1551 setContextToObject (theIObj);
1552 if (theIObj->Type() != AIS_KOI_Shape)
1556 if (theIObj->Signature() != 0)
1560 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1561 aShape->SetHLRAngleAndDeviation (theAngle);
1562 aShape->UpdatePresentations();
1563 if (theToUpdateViewer)
1565 UpdateCurrentViewer();
1569 //=======================================================================
1570 //function : SetHLRDeviationAngle
1572 //=======================================================================
1573 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1574 const Standard_Real theAngle,
1575 const Standard_Boolean theToUpdateViewer)
1577 if (theIObj.IsNull())
1582 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1583 setContextToObject (theIObj);
1584 if (theIObj->Type() != AIS_KOI_Shape)
1588 if (theIObj->Signature() != 0)
1592 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1593 aShape->SetOwnHLRDeviationAngle (theAngle);
1594 aShape->UpdatePresentations();
1595 if (theToUpdateViewer)
1597 UpdateCurrentViewer();
1601 //=======================================================================
1602 //function : UnsetColor
1604 //=======================================================================
1605 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1606 const Standard_Boolean theToUpdateViewer)
1608 if (theIObj.IsNull())
1613 theIObj->UnsetColor();
1614 theIObj->UpdatePresentations();
1615 if (theToUpdateViewer)
1617 UpdateCurrentViewer();
1621 //=======================================================================
1622 //function : HasColor
1624 //=======================================================================
1625 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1627 return theIObj->HasColor();
1630 //=======================================================================
1633 //=======================================================================
1634 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1635 Quantity_Color& theColor) const
1637 theIObj->Color (theColor);
1640 //=======================================================================
1643 //=======================================================================
1644 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1646 return theIObj->Width();
1649 //=======================================================================
1650 //function : SetWidth
1652 //=======================================================================
1653 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1654 const Standard_Real theWidth,
1655 const Standard_Boolean theToUpdateViewer)
1657 if (theIObj.IsNull())
1662 setContextToObject (theIObj);
1663 theIObj->SetWidth (theWidth);
1664 theIObj->UpdatePresentations();
1665 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
1667 if (myLastinMain->IsAutoHilight())
1669 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1670 myLastinMain->HilightWithColor (myMainPM,
1671 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
1676 theIObj->HilightOwnerWithColor (myMainPM,
1677 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
1681 if (theToUpdateViewer)
1683 UpdateCurrentViewer();
1687 //=======================================================================
1688 //function : UnsetWidth
1690 //=======================================================================
1691 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1692 const Standard_Boolean theToUpdateViewer)
1694 if (theIObj.IsNull())
1699 theIObj->UnsetWidth();
1700 theIObj->UpdatePresentations();
1701 if (theToUpdateViewer)
1703 UpdateCurrentViewer();
1707 //=======================================================================
1708 //function : SetMaterial
1710 //=======================================================================
1711 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1712 const Graphic3d_MaterialAspect& theMaterial,
1713 const Standard_Boolean theToUpdateViewer)
1715 if (theIObj.IsNull())
1720 setContextToObject (theIObj);
1721 theIObj->SetMaterial (theMaterial);
1722 theIObj->UpdatePresentations();
1723 if (theToUpdateViewer)
1725 UpdateCurrentViewer();
1729 //=======================================================================
1730 //function : UnsetMaterial
1732 //=======================================================================
1733 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1734 const Standard_Boolean theToUpdateViewer)
1736 if (theIObj.IsNull())
1740 theIObj->UnsetMaterial();
1741 theIObj->UpdatePresentations();
1742 if (theToUpdateViewer)
1744 UpdateCurrentViewer();
1748 //=======================================================================
1749 //function : SetTransparency
1751 //=======================================================================
1752 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1753 const Standard_Real theValue,
1754 const Standard_Boolean theToUpdateViewer)
1756 if (theIObj.IsNull())
1761 setContextToObject (theIObj);
1762 if (!theIObj->IsTransparent()
1763 && theValue <= 0.005)
1768 if (theValue <= 0.005)
1770 UnsetTransparency (theIObj, theToUpdateViewer);
1774 theIObj->SetTransparency (theValue);
1775 theIObj->UpdatePresentations();
1776 if (theToUpdateViewer)
1778 UpdateCurrentViewer();
1782 //=======================================================================
1783 //function : UnsetTransparency
1785 //=======================================================================
1786 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1787 const Standard_Boolean theToUpdateViewer)
1789 if (theIObj.IsNull())
1794 theIObj->UnsetTransparency();
1795 theIObj->UpdatePresentations();
1796 if (theToUpdateViewer)
1798 UpdateCurrentViewer();
1802 //=======================================================================
1803 //function : SetSelectedAspect
1805 //=======================================================================
1806 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1807 const Standard_Boolean theToUpdateViewer)
1809 Standard_DISABLE_DEPRECATION_WARNINGS
1810 Standard_Boolean isFound = Standard_False;
1811 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1813 isFound = Standard_True;
1814 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1815 anObj->SetAspect (theAspect);
1817 Standard_ENABLE_DEPRECATION_WARNINGS
1819 if (isFound && theToUpdateViewer)
1821 myMainVwr->Update();
1825 //=======================================================================
1826 //function : SetLocalAttributes
1828 //=======================================================================
1829 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1830 const Handle(Prs3d_Drawer)& theDrawer,
1831 const Standard_Boolean theToUpdateViewer)
1833 if (theIObj.IsNull())
1838 setContextToObject (theIObj);
1839 theIObj->SetAttributes (theDrawer);
1840 Update (theIObj, theToUpdateViewer);
1843 //=======================================================================
1844 //function : UnsetLocalAttributes
1846 //=======================================================================
1847 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1848 const Standard_Boolean theToUpdateViewer)
1850 if (theIObj.IsNull())
1855 setContextToObject (theIObj);
1856 theIObj->UnsetAttributes();
1857 Update (theIObj, theToUpdateViewer);
1860 //=======================================================================
1863 //=======================================================================
1864 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1865 TCollection_ExtendedString& theStatus) const
1868 if (theIObj.IsNull()
1869 || !myObjects.IsBound (theIObj))
1874 theStatus += "\t ____________________________________________";
1875 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1876 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1877 switch (aStatus->GraphicStatus())
1879 case AIS_DS_Displayed:
1881 theStatus += "\t| -->Displayed\n";
1886 theStatus += "\t| -->Erased\n";
1893 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1894 theStatus += "\t|\t Mode ";
1895 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1898 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1900 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1901 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1903 theStatus += "\t\t Mode ";
1904 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1907 theStatus += "\t ____________________________________________";
1910 //=======================================================================
1911 //function : GetDefModes
1913 //=======================================================================
1914 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1915 Standard_Integer& theDispMode,
1916 Standard_Integer& theHiMode,
1917 Standard_Integer& theSelMode) const
1919 if (theIObj.IsNull())
1924 theDispMode = theIObj->HasDisplayMode()
1925 ? theIObj->DisplayMode()
1926 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1927 ? myDefaultDrawer->DisplayMode()
1929 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1930 theSelMode = theIObj->GlobalSelectionMode();
1933 //=======================================================================
1934 //function : EraseGlobal
1936 //=======================================================================
1937 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1938 const Standard_Boolean theToUpdateviewer)
1940 if (theIObj.IsNull()
1941 || !myObjects.IsBound (theIObj))
1946 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1948 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1949 if (aStatus->GraphicStatus() == AIS_DS_Erased)
1954 if (aStatus->IsHilighted())
1956 Standard_DISABLE_DEPRECATION_WARNINGS
1957 if (IsCurrent (theIObj))
1959 AddOrRemoveCurrentObject (theIObj, Standard_False);
1961 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
1963 unhighlightGlobal (theIObj);
1965 Standard_ENABLE_DEPRECATION_WARNINGS
1968 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1970 if (aStatus->IsHilighted()
1971 && theIObj->HasHilightMode())
1973 unhighlightGlobal (theIObj);
1976 if (!myLastPicked.IsNull()
1977 && myLastPicked->IsSameSelectable (theIObj))
1979 clearDynamicHighlight();
1982 // make sure highlighting presentations are properly erased
1983 theIObj->ErasePresentations (false);
1985 if (IsSelected (theIObj)
1986 && aStatus->DisplayMode() != aDispMode)
1988 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1991 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1993 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1995 aStatus->ClearSelectionModes();
1996 aStatus->SetGraphicStatus (AIS_DS_Erased);
1998 if (theToUpdateviewer)
2000 myMainVwr->Update();
2004 //=======================================================================
2005 //function : unhighlightOwners
2007 //=======================================================================
2008 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2010 SelectMgr_SequenceOfOwner aSeq;
2011 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2013 if (aSelIter.Value()->IsSameSelectable (theObject))
2015 aSeq.Append (aSelIter.Value());
2018 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2020 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2024 //=======================================================================
2025 //function : ClearGlobal
2027 //=======================================================================
2028 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2029 const Standard_Boolean theToUpdateviewer)
2031 if (theIObj.IsNull()
2032 || !myObjects.IsBound (theIObj))
2034 // for cases when reference shape of connected interactives was not displayed
2035 // but its selection primitives were calculated
2036 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2037 mgrSelector->Remove (anObj);
2041 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2042 unhighlightOwners (theIObj);
2044 myMainPM->Erase (theIObj, -1);
2045 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2047 // Object removes from Detected sequence
2048 Standard_DISABLE_DEPRECATION_WARNINGS
2049 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2051 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2052 Handle(AIS_InteractiveObject) anObj;
2053 if (!aPicked.IsNull())
2055 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2059 && anObj == theIObj)
2061 myDetectedSeq.Remove (aDetIter);
2062 if (myCurDetected == aDetIter)
2064 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2066 if (myCurHighlighted == aDetIter)
2068 myCurHighlighted = 0;
2076 Standard_ENABLE_DEPRECATION_WARNINGS
2078 // remove IO from the selection manager to avoid memory leaks
2079 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2080 mgrSelector->Remove (anObj);
2082 myObjects.UnBind (theIObj);
2083 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2085 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2087 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2090 if (!myLastinMain.IsNull())
2092 if (myLastinMain->IsSameSelectable (theIObj)
2093 || myLastPicked->IsSameSelectable(theIObj))
2095 clearDynamicHighlight();
2096 myLastinMain.Nullify();
2097 myLastPicked.Nullify();
2101 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2103 myMainVwr->Update();
2107 //=======================================================================
2108 //function : ClearGlobalPrs
2110 //=======================================================================
2111 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2112 const Standard_Integer theMode,
2113 const Standard_Boolean theToUpdateViewer)
2115 if (theIObj.IsNull()
2116 || !myObjects.IsBound (theIObj))
2121 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2122 if (aStatus->DisplayMode() == theMode)
2124 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2125 if (aDispMode == theMode
2126 && myMainPM->IsHighlighted (theIObj, theMode))
2128 unhighlightGlobal (theIObj);
2131 myMainPM->Erase (theIObj, theMode);
2134 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2135 && theToUpdateViewer)
2137 myMainVwr->Update();
2141 //=======================================================================
2142 //function : ClearDetected
2144 //=======================================================================
2145 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2148 myCurHighlighted = 0;
2149 myDetectedSeq.Clear();
2150 myLastPicked = myLastinMain;
2151 myWasLastMain = Standard_True;
2152 Standard_Boolean toUpdate = Standard_False;
2153 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2155 toUpdate = Standard_True;
2156 clearDynamicHighlight();
2158 myLastinMain.Nullify();
2159 myLastPicked.Nullify();
2160 myMainSel->ClearPicked();
2161 if (toUpdate && theToRedrawImmediate)
2163 myMainVwr->RedrawImmediate();
2168 //=======================================================================
2169 //function : DrawHiddenLine
2171 //=======================================================================
2172 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2174 return myDefaultDrawer->DrawHiddenLine();
2177 //=======================================================================
2178 //function : EnableDrawHiddenLine
2180 //=======================================================================
2181 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2183 myDefaultDrawer->EnableDrawHiddenLine();
2186 //=======================================================================
2187 //function : DisableDrawHiddenLine
2189 //=======================================================================
2190 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2192 myDefaultDrawer->DisableDrawHiddenLine();
2195 //=======================================================================
2196 //function : HiddenLineAspect
2198 //=======================================================================
2199 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2201 return myDefaultDrawer->HiddenLineAspect();
2204 //=======================================================================
2205 //function : SetHiddenLineAspect
2207 //=======================================================================
2208 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2210 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2213 //=======================================================================
2214 //function : SetIsoNumber
2216 //=======================================================================
2217 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2218 const AIS_TypeOfIso theType)
2223 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2226 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2229 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2230 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2235 //=======================================================================
2236 //function : IsoNumber
2238 //=======================================================================
2239 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2243 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2244 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2245 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2246 ? myDefaultDrawer->UIsoAspect()->Number()
2252 //=======================================================================
2253 //function : IsoOnPlane
2255 //=======================================================================
2256 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2258 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2261 //=======================================================================
2262 //function : IsoOnPlane
2264 //=======================================================================
2265 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2267 return myDefaultDrawer->IsoOnPlane();
2270 //=======================================================================
2271 //function : IsoOnTriangulation
2273 //=======================================================================
2274 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2276 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2279 //=======================================================================
2280 //function : IsoOnTriangulation
2282 //=======================================================================
2283 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2285 return myDefaultDrawer->IsoOnTriangulation();
2288 //=======================================================================
2289 //function : SetPixelTolerance
2291 //=======================================================================
2292 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2294 myMainSel->SetPixelTolerance (thePrecision);
2297 //=======================================================================
2298 //function : PixelTolerance
2300 //=======================================================================
2301 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2303 return myMainSel->PixelTolerance();
2306 //=======================================================================
2307 //function : SetSelectionSensitivity
2308 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2309 //=======================================================================
2310 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2311 const Standard_Integer theMode,
2312 const Standard_Integer theNewSensitivity)
2314 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2317 //=======================================================================
2318 //function : InitAttributes
2320 //=======================================================================
2321 void AIS_InteractiveContext::InitAttributes()
2323 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2324 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2326 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2327 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2328 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2329 aLineAspect->SetWidth (1.0);
2330 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2332 // tolerance to 2 pixels...
2333 SetPixelTolerance (2);
2335 // Customizing the drawer for trihedrons and planes...
2336 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2337 const Standard_Real aLength = 100.0;
2338 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2339 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2340 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2341 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2342 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2344 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2345 const Standard_Real aPlaneLength = 200.0;
2346 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2347 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2350 //=======================================================================
2351 //function : TrihedronSize
2353 //=======================================================================
2354 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2356 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2359 //=======================================================================
2360 //function : SetTrihedronSize
2362 //=======================================================================
2363 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2364 const Standard_Boolean /*updateviewer*/)
2366 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2367 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2368 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2371 //=======================================================================
2372 //function : SetPlaneSize
2374 //=======================================================================
2375 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2376 const Standard_Real theValY,
2377 const Standard_Boolean theToUpdateViewer)
2379 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2380 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2383 //=======================================================================
2384 //function : SetPlaneSize
2386 //=======================================================================
2387 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2388 const Standard_Boolean theToUpdateViewer)
2390 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2393 //=======================================================================
2394 //function : PlaneSize
2396 //=======================================================================
2397 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2398 Standard_Real& theY) const
2400 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2401 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2402 return (Abs (theX - theY) <= Precision::Confusion());
2405 //=======================================================================
2406 //function : SetZLayer
2408 //=======================================================================
2409 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2410 const Graphic3d_ZLayerId theLayerId)
2412 if (theIObj.IsNull())
2415 theIObj->SetZLayer (theLayerId);
2418 //=======================================================================
2419 //function : GetZLayer
2421 //=======================================================================
2422 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2424 return !theIObj.IsNull()
2426 : Graphic3d_ZLayerId_UNKNOWN;
2429 //=======================================================================
2430 //function : RebuildSelectionStructs
2431 //purpose : Rebuilds 1st level of BVH selection forcibly
2432 //=======================================================================
2433 void AIS_InteractiveContext::RebuildSelectionStructs()
2435 myMainSel->RebuildObjectsTree (Standard_True);
2438 //=======================================================================
2439 //function : Disconnect
2440 //purpose : Disconnects selectable object from an assembly and updates selection structures
2441 //=======================================================================
2442 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2443 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2445 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2447 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2448 theObj->Disconnect (theObjToDisconnect);
2449 if (!myObjects.IsBound (theObjToDisconnect))
2451 // connected presentation might contain displayed presentations
2452 myMainPM->Erase (theObjToDisconnect, -1);
2453 theObjToDisconnect->ErasePresentations (true);
2456 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2457 mgrSelector->Remove (anObj);
2459 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2461 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2462 theObj->Disconnect();
2463 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2464 mgrSelector->Remove (anObj);
2470 //=======================================================================
2471 //function : FitSelected
2472 //purpose : Fits the view corresponding to the bounds of selected objects
2473 //=======================================================================
2474 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2476 FitSelected (theView, 0.01, Standard_True);
2479 //=======================================================================
2480 //function : FitSelected
2481 //purpose : Fits the view corresponding to the bounds of selected objects
2482 //=======================================================================
2483 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2484 const Standard_Real theMargin,
2485 const Standard_Boolean theToUpdate)
2487 Bnd_Box aBndSelected;
2488 AIS_MapOfObjectOwners anObjectOwnerMap;
2489 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2491 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2492 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2493 if (anObj->IsInfinite())
2498 if (anOwner == anObj->GlobalSelOwner())
2501 anObj->BoundingBox (aTmpBnd);
2502 aBndSelected.Add (aTmpBnd);
2506 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2507 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2509 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2510 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2513 anOwnerMap->Add (anOwner);
2517 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2519 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2520 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2521 aBndSelected.Add (aTmpBox);
2524 anObjectOwnerMap.Clear();
2526 if (aBndSelected.IsVoid())
2529 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2532 //=======================================================================
2533 //function : SetTransformPersistence
2535 //=======================================================================
2536 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2537 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2539 theObject->SetTransformPersistence (theTrsfPers);
2540 if (!myObjects.IsBound (theObject))
2545 mgrSelector->UpdateSelection (theObject);
2547 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2548 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2549 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2551 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2552 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);