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 myToHilightSelected(Standard_True),
110 mySelection(new AIS_Selection()),
111 myFilters(new SelectMgr_OrFilter()),
112 myDefaultDrawer(new Prs3d_Drawer()),
115 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
116 myAutoHilight(Standard_True),
117 myIsAutoActivateSelMode(Standard_True)
119 mgrSelector = new SelectMgr_SelectionManager (myMainSel);
121 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
122 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
123 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
124 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
125 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
126 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
128 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
129 myDefaultDrawer->SetDisplayMode(0);
131 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
132 aStyle->Link (myDefaultDrawer);
133 initDefaultHilightAttributes (aStyle);
134 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
135 aStyle->SetColor (Quantity_NOC_CYAN1);
138 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
139 aStyle->Link (myDefaultDrawer);
140 initDefaultHilightAttributes (aStyle);
141 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
142 aStyle->SetColor (Quantity_NOC_CYAN1);
145 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
146 aStyle->Link (myDefaultDrawer);
147 initDefaultHilightAttributes (aStyle);
148 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
149 aStyle->SetColor (Quantity_NOC_GRAY80);
152 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
153 aStyle->Link (myDefaultDrawer);
154 initDefaultHilightAttributes (aStyle);
155 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
156 aStyle->SetColor (Quantity_NOC_GRAY80);
159 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
160 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
161 aStyle->SetMethod(Aspect_TOHM_COLOR);
162 aStyle->SetColor (Quantity_NOC_GRAY40);
168 //=======================================================================
169 //function : ~AIS_InteractiveContext
171 //=======================================================================
172 AIS_InteractiveContext::~AIS_InteractiveContext()
174 // clear the current selection
175 mySelection->Clear();
176 mgrSelector.Nullify();
178 Handle(AIS_InteractiveContext) aNullContext;
179 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
181 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
182 anObj->SetContext (aNullContext);
183 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
185 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
190 //=======================================================================
191 //function : LastActiveView
193 //=======================================================================
194 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
196 if (myLastActiveView == NULL
197 || myMainVwr.IsNull())
199 return Handle(V3d_View)();
202 // as a precaution - check that myLastActiveView pointer is a valid active View
203 for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
205 if (aViewIter.Value() == myLastActiveView)
207 return aViewIter.Value();
210 return Handle(V3d_View)();
213 //=======================================================================
214 //function : UpdateCurrentViewer
216 //=======================================================================
218 void AIS_InteractiveContext::UpdateCurrentViewer()
220 if (!myMainVwr.IsNull())
224 //=======================================================================
225 //function : DisplayedObjects
227 //=======================================================================
228 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
230 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
232 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
234 theListOfIO.Append (anObjIter.Key());
239 //=======================================================================
240 //function : DisplayedObjects
242 //=======================================================================
243 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
244 const Standard_Integer theSign,
245 AIS_ListOfInteractive& theListOfIO) const
247 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
250 //=======================================================================
251 //function : ErasedObjects
253 //=======================================================================
254 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
256 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
259 //=======================================================================
260 //function : ErasedObjects
262 //=======================================================================
263 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
264 const Standard_Integer theSign,
265 AIS_ListOfInteractive& theListOfIO) const
267 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
270 //=======================================================================
271 //function : ObjectsByDisplayStatus
273 //=======================================================================
274 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
275 AIS_ListOfInteractive& theListOfIO) const
277 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
279 if (anObjIter.Value()->GraphicStatus() == theStatus)
281 theListOfIO.Append (anObjIter.Key());
286 //=======================================================================
287 //function : ObjectsByDisplayStatus
289 //=======================================================================
290 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
291 const Standard_Integer theSign,
292 const AIS_DisplayStatus theStatus,
293 AIS_ListOfInteractive& theListOfIO) const
295 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
297 if (theStatus != AIS_DS_None
298 && anObjIter.Value()->GraphicStatus() != theStatus)
302 else if (anObjIter.Key()->Type() != theKind)
308 || anObjIter.Key()->Signature() == theSign)
310 theListOfIO.Append (anObjIter.Key());
315 //=======================================================================
316 //function : ObjectsInside
318 //=======================================================================
319 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
320 const AIS_KindOfInteractive theKind,
321 const Standard_Integer theSign) const
323 if (theKind == AIS_KOI_None
326 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
328 theListOfIO.Append (anObjIter.Key());
333 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
335 if (anObjIter.Key()->Type() != theKind)
341 || anObjIter.Key()->Signature() == theSign)
343 theListOfIO.Append (anObjIter.Key());
348 //=======================================================================
349 //function : ObjectsForView
351 //=======================================================================
352 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
353 const Handle(V3d_View)& theView,
354 const Standard_Boolean theIsVisibleInView,
355 const AIS_DisplayStatus theStatus) const
357 Handle(Graphic3d_CView) aViewImpl = theView->View();
358 const Standard_Integer aViewId = aViewImpl->Identification();
359 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
361 if (theStatus != AIS_DS_None
362 && anObjIter.Value()->GraphicStatus() != theStatus)
364 theListOfIO.Append (anObjIter.Key());
368 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
369 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
370 if (isVisible == theIsVisibleInView)
372 theListOfIO.Append (anObjIter.Key());
377 //=======================================================================
380 //=======================================================================
381 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
382 const Standard_Boolean theToUpdateViewer)
384 if (theIObj.IsNull())
389 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
390 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
391 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
394 //=======================================================================
395 //function : SetViewAffinity
397 //=======================================================================
398 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
399 const Handle(V3d_View)& theView,
400 const Standard_Boolean theIsVisible)
403 || !myObjects.IsBound (theIObj))
408 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
409 Handle(Graphic3d_CView) aViewImpl = theView->View();
410 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
413 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
417 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
421 //=======================================================================
424 //=======================================================================
425 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
426 const Standard_Integer theDispMode,
427 const Standard_Integer theSelectionMode,
428 const Standard_Boolean theToUpdateViewer,
429 const AIS_DisplayStatus theDispStatus)
431 if (theIObj.IsNull())
436 if (theDispStatus == AIS_DS_Erased)
438 Erase (theIObj, theToUpdateViewer);
439 Load (theIObj, theSelectionMode);
440 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
442 (*aStatusPtr)->SetDisplayMode (theDispMode);
447 setContextToObject (theIObj);
448 if (!myObjects.IsBound (theIObj))
450 setObjectStatus (theIObj, AIS_DS_Displayed, theDispMode, theSelectionMode);
451 myMainVwr->StructureManager()->RegisterObject (theIObj);
452 myMainPM->Display(theIObj, theDispMode);
453 if (theSelectionMode != -1)
455 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
456 if (!mgrSelector->Contains (anObj))
458 mgrSelector->Load (theIObj);
460 mgrSelector->Activate (theIObj, theSelectionMode);
465 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
467 // Mark the presentation modes hidden of interactive object different from aDispMode.
468 // Then make sure aDispMode is displayed and maybe highlighted.
469 // Finally, activate selection mode <SelMode> if not yet activated.
470 const Standard_Integer anOldMode = aStatus->DisplayMode();
471 if (anOldMode != theDispMode)
473 if(myMainPM->IsHighlighted (theIObj, anOldMode))
475 unhighlightGlobal (theIObj);
477 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
480 aStatus->SetDisplayMode (theDispMode);
482 myMainPM->Display (theIObj, theDispMode);
483 aStatus->SetGraphicStatus (AIS_DS_Displayed);
484 if (aStatus->IsHilighted())
486 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
488 if (theSelectionMode != -1)
490 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
491 if (!mgrSelector->Contains (anObj))
493 mgrSelector->Load (theIObj);
495 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
497 if (!aStatus->IsSModeIn (theSelectionMode))
498 aStatus->AddSelectionMode (theSelectionMode);
499 mgrSelector->Activate (theIObj, theSelectionMode);
504 if (theToUpdateViewer)
510 //=======================================================================
513 //=======================================================================
514 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
515 const Standard_Integer theSelMode)
517 if (theIObj.IsNull())
522 setContextToObject (theIObj);
523 if (!myObjects.IsBound (theIObj))
525 Standard_Integer aDispMode, aHiMod, aSelModeDef;
526 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
527 setObjectStatus (theIObj, AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
528 myMainVwr->StructureManager()->RegisterObject (theIObj);
531 // Register theIObj in the selection manager to prepare further activation of selection
532 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
533 if (!mgrSelector->Contains (anObj))
535 mgrSelector->Load (theIObj);
539 //=======================================================================
542 //=======================================================================
543 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
544 const Standard_Boolean theToUpdateViewer)
546 if (theIObj.IsNull())
551 if (!theIObj->IsAutoHilight())
553 theIObj->ClearSelected();
556 EraseGlobal (theIObj, Standard_False);
557 if (theToUpdateViewer)
563 //=======================================================================
564 //function : EraseAll
566 //=======================================================================
567 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
569 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
571 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
573 Erase (anObjIter.Key(), Standard_False);
577 if (theToUpdateViewer)
583 //=======================================================================
584 //function : DisplayAll
586 //=======================================================================
587 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
589 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
591 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
592 if (aStatus == AIS_DS_Erased)
594 Display (anObjIter.Key(), Standard_False);
598 if (theToUpdateViewer)
604 //=======================================================================
605 //function : DisplaySelected
607 //=======================================================================
608 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
610 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
612 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
613 Display (anObj, Standard_False);
616 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
622 //=======================================================================
623 //function : EraseSelected
625 //=======================================================================
626 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
628 Standard_Boolean isFound = Standard_False;
629 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
631 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
632 Erase (anObj, Standard_False);
633 isFound = Standard_True;
636 if (isFound && theToUpdateViewer)
642 //=======================================================================
643 //function : DisplayStatus
645 //=======================================================================
646 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
648 if (theIObj.IsNull())
652 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
653 return aStatus != NULL ? (*aStatus)->GraphicStatus() : AIS_DS_None;
656 //=======================================================================
659 //=======================================================================
660 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
661 const Standard_Boolean theToUpdateViewer)
663 if (theIObj.IsNull())
668 if (theIObj->HasInteractiveContext())
670 if (theIObj->myCTXPtr != this)
672 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
674 theIObj->SetContext (Handle(AIS_InteractiveContext)());
676 ClearGlobal (theIObj, theToUpdateViewer);
679 //=======================================================================
680 //function : RemoveAll
682 //=======================================================================
683 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
685 AIS_ListOfInteractive aList;
686 ObjectsInside (aList);
687 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
689 Remove (aListIterator.Value(), Standard_False);
692 if (theToUpdateViewer)
698 //=======================================================================
699 //function : HilightWithColor
701 //=======================================================================
702 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
703 const Handle(Prs3d_Drawer)& theStyle,
704 const Standard_Boolean theIsToUpdate)
709 setContextToObject (theObj);
710 if (!myObjects.IsBound (theObj))
713 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
714 aStatus->SetHilightStatus (Standard_True);
716 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
718 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
719 aStatus->SetHilightStyle (theStyle);
726 //=======================================================================
727 //function : Unhilight
729 //=======================================================================
730 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
732 if(anIObj.IsNull()) return;
733 if(!myObjects.IsBound(anIObj)) return;
735 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
736 aStatus->SetHilightStatus (Standard_False);
737 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
739 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
741 unhighlightGlobal (anIObj);
744 if(updateviewer) myMainVwr->Update();
747 //=======================================================================
748 //function : IsHilighted
749 //purpose : Returns true if the objects global status is set to highlighted.
750 //=======================================================================
751 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
753 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
754 return aStatus != NULL
755 && (*aStatus)->IsHilighted();
758 //=======================================================================
759 //function : IsHilighted
760 //purpose : Returns true if the owner is highlighted with selection style.
761 //=======================================================================
762 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
764 if (theOwner.IsNull() || !theOwner->HasSelectable())
765 return Standard_False;
767 const Handle(AIS_InteractiveObject) anObj =
768 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
770 if (anObj->GlobalSelOwner() == theOwner)
772 if (!myObjects.IsBound (anObj))
773 return Standard_False;
775 return myObjects (anObj)->IsHilighted();
778 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
779 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
780 return theOwner->IsHilighted (myMainPM, aHiMode);
783 //=======================================================================
784 //function : HighlightStyle
786 //=======================================================================
787 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
788 Handle(Prs3d_Drawer)& theStyle) const
790 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
792 && (*aStatus)->IsHilighted())
794 theStyle = (*aStatus)->HilightStyle();
795 return Standard_True;
799 return Standard_False;
802 //=======================================================================
803 //function : HighlightStyle
805 //=======================================================================
806 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
807 Handle(Prs3d_Drawer)& theStyle) const
809 if (theOwner.IsNull() || !theOwner->HasSelectable())
810 return Standard_False;
812 if (IsHilighted (theOwner))
814 const Handle(AIS_InteractiveObject) anObj =
815 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
816 if (anObj->GlobalSelOwner() == theOwner)
818 theStyle = myObjects (anObj)->HilightStyle();
822 // since part selection style is not stored in global status,
823 // check if the object has own selection style. If not, it can
824 // only be highlighted with default selection style (because
825 // sub-intensity does not modify any selection states)
826 theStyle = getSelStyle (anObj, theOwner);
828 return Standard_True;
833 return Standard_False;
837 //=======================================================================
838 //function : IsDisplayed
840 //=======================================================================
842 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
844 if(theObj.IsNull()) return Standard_False;
846 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
847 return aStatus != NULL
848 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed;
851 //=======================================================================
852 //function : IsDisplayed
854 //=======================================================================
855 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
856 const Standard_Integer theMode) const
858 if (theIObj.IsNull())
860 return Standard_False;
863 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
864 return aStatus != NULL
865 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed
866 && (*aStatus)->DisplayMode() == theMode;
869 //=======================================================================
870 //function : DisplayPriority
872 //=======================================================================
873 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
875 if (theIObj.IsNull())
880 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
882 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
883 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
885 Standard_Integer aDispMode = theIObj->HasDisplayMode()
886 ? theIObj->DisplayMode()
887 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
888 ? myDefaultDrawer->DisplayMode()
890 return myMainPM->DisplayPriority (theIObj, aDispMode);
895 //=======================================================================
896 //function : SetDisplayPriority
898 //=======================================================================
899 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
900 const Standard_Integer thePriority)
902 if (theIObj.IsNull())
907 setContextToObject (theIObj);
908 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
910 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
911 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
913 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
914 ? theIObj->DisplayMode()
915 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
916 ? myDefaultDrawer->DisplayMode()
918 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
922 //=======================================================================
923 //function : Redisplay
925 //=======================================================================
926 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
927 const Standard_Boolean theToUpdateViewer,
928 const Standard_Boolean theAllModes)
930 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
931 RecomputeSelectionOnly (theIObj);
934 //=======================================================================
935 //function : Redisplay
937 //=======================================================================
938 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
939 const Standard_Integer /*theSign*/,
940 const Standard_Boolean theToUpdateViewer)
942 Standard_Boolean isRedisplayed = Standard_False;
943 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
945 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
946 if (anObj->Type() != theKOI)
951 Redisplay (anObj, Standard_False);
952 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
956 if (theToUpdateViewer
963 //=======================================================================
964 //function : RecomputePrsOnly
966 //=======================================================================
967 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
968 const Standard_Boolean theToUpdateViewer,
969 const Standard_Boolean theAllModes)
971 if (theIObj.IsNull())
976 theIObj->SetToUpdate();
977 theIObj->UpdatePresentations (theAllModes);
978 if (!theToUpdateViewer)
983 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
985 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
990 //=======================================================================
991 //function : RecomputeSelectionOnly
993 //=======================================================================
994 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1001 mgrSelector->RecomputeSelection (theIO);
1003 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1005 || (*aStatus)->GraphicStatus() != AIS_DS_Displayed)
1010 TColStd_ListOfInteger aModes;
1011 ActivatedModes (theIO, aModes);
1012 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1013 for (; aModesIter.More(); aModesIter.Next())
1015 mgrSelector->Activate (theIO, aModesIter.Value());
1019 //=======================================================================
1022 //=======================================================================
1023 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1024 const Standard_Boolean theUpdateViewer)
1026 if (theIObj.IsNull())
1031 theIObj->UpdatePresentations();
1032 mgrSelector->Update(theIObj);
1034 if (theUpdateViewer)
1036 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1038 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
1040 myMainVwr->Update();
1045 //=======================================================================
1046 //function : SetLocation
1048 //=======================================================================
1049 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1050 const TopLoc_Location& theLoc)
1052 if (theIObj.IsNull())
1057 if (theIObj->HasTransformation()
1058 && theLoc.IsIdentity())
1060 theIObj->ResetTransformation();
1061 mgrSelector->Update (theIObj, Standard_False);
1064 else if (theLoc.IsIdentity())
1069 // first reset the previous location to properly clean everything...
1070 if (theIObj->HasTransformation())
1072 theIObj->ResetTransformation();
1075 theIObj->SetLocalTransformation (theLoc.Transformation());
1077 mgrSelector->Update (theIObj, Standard_False);
1079 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1080 // to its highlight structure immediately
1081 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1083 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1084 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1090 //=======================================================================
1091 //function : ResetLocation
1093 //=======================================================================
1094 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1096 if (theIObj.IsNull())
1101 theIObj->ResetTransformation();
1102 mgrSelector->Update (theIObj, Standard_False);
1105 //=======================================================================
1106 //function : HasLocation
1108 //=======================================================================
1109 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1111 return !theIObj.IsNull()
1112 && theIObj->HasTransformation();
1115 //=======================================================================
1116 //function : Location
1118 //=======================================================================
1119 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1121 return theIObj->Transformation();
1124 //=======================================================================
1125 //function : SetDeviationCoefficient
1127 //=======================================================================
1128 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1130 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1133 //=======================================================================
1134 //function : SetDeviationAngle
1136 //=======================================================================
1137 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1139 myDefaultDrawer->SetDeviationAngle (theAngle);
1142 //=======================================================================
1143 //function : DeviationAngle
1144 //purpose : Gets deviationAngle
1145 //=======================================================================
1146 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1148 return myDefaultDrawer->DeviationAngle();
1151 //=======================================================================
1152 //function : DeviationCoefficient
1154 //=======================================================================
1155 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1157 return myDefaultDrawer->DeviationCoefficient();
1160 //=======================================================================
1161 //function : SetHLRDeviationCoefficient
1163 //=======================================================================
1164 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1166 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1169 //=======================================================================
1170 //function : HLRDeviationCoefficient
1172 //=======================================================================
1173 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1175 return myDefaultDrawer->HLRDeviationCoefficient();
1178 //=======================================================================
1179 //function : SetHLRAngle
1181 //=======================================================================
1182 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1184 myDefaultDrawer->SetHLRAngle (theAngle);
1187 //=======================================================================
1188 //function : SetHLRAngleAndDeviation
1189 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1190 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1191 // of myDefaultDrawer
1192 //=======================================================================
1193 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1195 Standard_Real anOutAngl, anOutDefl;
1196 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1198 myDefaultDrawer->SetHLRAngle (anOutAngl);
1199 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1202 //=======================================================================
1203 //function : HLRAngle
1205 //=======================================================================
1206 Standard_Real AIS_InteractiveContext::HLRAngle() const
1208 return myDefaultDrawer->HLRAngle();
1211 //=======================================================================
1212 //function : SetDisplayMode
1214 //=======================================================================
1215 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1216 const Standard_Boolean theToUpdateViewer)
1218 if (theMode == myDefaultDrawer->DisplayMode())
1223 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1225 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1226 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1227 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1228 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1231 || anObj->HasDisplayMode()
1232 || !anObj->AcceptDisplayMode (theMode))
1237 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1238 aStatus->SetDisplayMode (theMode);
1240 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1242 myMainPM->Display (anObj, theMode);
1243 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1245 myMainPM->BeginImmediateDraw();
1246 unhighlightGlobal (anObj);
1247 myMainPM->EndImmediateDraw (myMainVwr);
1249 if (aStatus->IsSubIntensityOn())
1251 highlightWithSubintensity (anObj, theMode);
1253 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1257 myDefaultDrawer->SetDisplayMode (theMode);
1258 if (theToUpdateViewer)
1260 myMainVwr->Update();
1264 //=======================================================================
1265 //function : SetDisplayMode
1267 //=======================================================================
1268 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1269 const Standard_Integer theMode,
1270 const Standard_Boolean theToUpdateViewer)
1272 setContextToObject (theIObj);
1273 if (!myObjects.IsBound (theIObj))
1275 theIObj->SetDisplayMode (theMode);
1278 else if (!theIObj->AcceptDisplayMode (theMode))
1283 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1284 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1286 aStatus->SetDisplayMode (theMode);
1287 theIObj->SetDisplayMode (theMode);
1291 // erase presentations for all display modes different from <aMode>
1292 const Standard_Integer anOldMode = aStatus->DisplayMode();
1293 if (anOldMode != theMode)
1295 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1297 unhighlightGlobal (theIObj);
1299 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1302 aStatus->SetDisplayMode (theMode);
1304 myMainPM->Display (theIObj, theMode);
1305 if (aStatus->IsHilighted())
1307 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1309 if (aStatus->IsSubIntensityOn())
1311 highlightWithSubintensity (theIObj, theMode);
1314 if (theToUpdateViewer)
1316 myMainVwr->Update();
1318 theIObj->SetDisplayMode (theMode);
1321 //=======================================================================
1322 //function : UnsetDisplayMode
1324 //=======================================================================
1325 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1326 const Standard_Boolean theToUpdateViewer)
1328 if (theIObj.IsNull()
1329 || !theIObj->HasDisplayMode())
1334 if (!myObjects.IsBound (theIObj))
1336 theIObj->UnsetDisplayMode();
1340 const Standard_Integer anOldMode = theIObj->DisplayMode();
1341 if (myDefaultDrawer->DisplayMode() == anOldMode)
1346 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1347 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1349 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1351 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1353 unhighlightGlobal (theIObj);
1355 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1356 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1357 if (aStatus->IsHilighted())
1359 highlightSelected (theIObj->GlobalSelOwner());
1361 if (aStatus->IsSubIntensityOn())
1363 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1366 if (theToUpdateViewer)
1368 myMainVwr->Update();
1372 theIObj->UnsetDisplayMode();
1375 //=======================================================================
1376 //function : SetCurrentFacingModel
1378 //=======================================================================
1379 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1380 const Aspect_TypeOfFacingModel theModel)
1382 if (!theIObj.IsNull())
1384 theIObj->SetCurrentFacingModel (theModel);
1388 //=======================================================================
1389 //function : SetColor
1391 //=======================================================================
1392 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1393 const Quantity_Color& theColor,
1394 const Standard_Boolean theToUpdateViewer)
1396 if (theIObj.IsNull())
1401 setContextToObject (theIObj);
1402 theIObj->SetColor (theColor);
1403 theIObj->UpdatePresentations();
1404 if (theToUpdateViewer)
1406 UpdateCurrentViewer();
1410 //=======================================================================
1411 //function : SetIsoOnTriangulation
1413 //=======================================================================
1414 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1415 const Handle(AIS_InteractiveObject)& theObject)
1417 if (theObject.IsNull())
1422 theObject->SetIsoOnTriangulation (theIsEnabled);
1425 //=======================================================================
1426 //function : SetDeviationCoefficient
1428 //=======================================================================
1429 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1430 const Standard_Real theCoefficient,
1431 const Standard_Boolean theToUpdateViewer)
1433 if (theIObj.IsNull())
1438 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1439 setContextToObject (theIObj);
1440 if (theIObj->Type() != AIS_KOI_Object
1441 && theIObj->Type() != AIS_KOI_Shape)
1445 else if (theIObj->Signature() != 0)
1450 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1451 aShape->SetOwnDeviationCoefficient (theCoefficient);
1452 aShape->UpdatePresentations();
1453 if (theToUpdateViewer)
1455 UpdateCurrentViewer();
1459 //=======================================================================
1460 //function : SetHLRDeviationCoefficient
1462 //=======================================================================
1463 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1464 const Standard_Real theCoefficient,
1465 const Standard_Boolean theToUpdateViewer)
1467 if (theIObj.IsNull())
1472 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1473 setContextToObject (theIObj);
1474 if (theIObj->Type() != AIS_KOI_Object
1475 && theIObj->Type() != AIS_KOI_Shape)
1479 else if (theIObj->Signature() != 0)
1484 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1485 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1486 aShape->UpdatePresentations();
1487 if (theToUpdateViewer)
1489 UpdateCurrentViewer();
1493 //=======================================================================
1494 //function : SetDeviationAngle
1496 //=======================================================================
1497 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1498 const Standard_Real theAngle,
1499 const Standard_Boolean theToUpdateViewer)
1501 if (theIObj.IsNull())
1506 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1507 setContextToObject (theIObj);
1508 if (theIObj->Type() != AIS_KOI_Shape)
1512 else if (theIObj->Signature() != 0)
1517 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1518 aShape->SetOwnDeviationAngle (theAngle);
1519 aShape->UpdatePresentations();
1520 if (theToUpdateViewer)
1522 UpdateCurrentViewer();
1526 //=======================================================================
1527 //function : SetAngleAndDeviation
1529 //=======================================================================
1530 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1531 const Standard_Real theAngle,
1532 const Standard_Boolean theToUpdateViewer)
1534 if (theIObj.IsNull())
1539 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1540 setContextToObject (theIObj);
1541 if (theIObj->Type() != AIS_KOI_Shape)
1545 if (theIObj->Signature() != 0)
1550 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1551 aShape->SetAngleAndDeviation (theAngle);
1552 aShape->UpdatePresentations();
1553 if (theToUpdateViewer)
1555 UpdateCurrentViewer();
1559 //=======================================================================
1560 //function : SetHLRAngleAndDeviation
1562 //=======================================================================
1563 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1564 const Standard_Real theAngle,
1565 const Standard_Boolean theToUpdateViewer)
1567 if (theIObj.IsNull())
1572 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1573 setContextToObject (theIObj);
1574 if (theIObj->Type() != AIS_KOI_Shape)
1578 if (theIObj->Signature() != 0)
1582 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1583 aShape->SetHLRAngleAndDeviation (theAngle);
1584 aShape->UpdatePresentations();
1585 if (theToUpdateViewer)
1587 UpdateCurrentViewer();
1591 //=======================================================================
1592 //function : SetHLRDeviationAngle
1594 //=======================================================================
1595 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1596 const Standard_Real theAngle,
1597 const Standard_Boolean theToUpdateViewer)
1599 if (theIObj.IsNull())
1604 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1605 setContextToObject (theIObj);
1606 if (theIObj->Type() != AIS_KOI_Shape)
1610 if (theIObj->Signature() != 0)
1614 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1615 aShape->SetOwnHLRDeviationAngle (theAngle);
1616 aShape->UpdatePresentations();
1617 if (theToUpdateViewer)
1619 UpdateCurrentViewer();
1623 //=======================================================================
1624 //function : UnsetColor
1626 //=======================================================================
1627 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1628 const Standard_Boolean theToUpdateViewer)
1630 if (theIObj.IsNull())
1635 theIObj->UnsetColor();
1636 theIObj->UpdatePresentations();
1637 if (theToUpdateViewer)
1639 UpdateCurrentViewer();
1643 //=======================================================================
1644 //function : HasColor
1646 //=======================================================================
1647 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1649 return theIObj->HasColor();
1652 //=======================================================================
1655 //=======================================================================
1656 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1657 Quantity_Color& theColor) const
1659 theIObj->Color (theColor);
1662 //=======================================================================
1665 //=======================================================================
1666 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1668 return theIObj->Width();
1671 //=======================================================================
1672 //function : SetWidth
1674 //=======================================================================
1675 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1676 const Standard_Real theWidth,
1677 const Standard_Boolean theToUpdateViewer)
1679 if (theIObj.IsNull())
1684 setContextToObject (theIObj);
1685 theIObj->SetWidth (theWidth);
1686 theIObj->UpdatePresentations();
1687 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1689 if (myLastPicked->IsAutoHilight())
1691 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1692 myLastPicked->HilightWithColor (myMainPM,
1693 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1698 theIObj->HilightOwnerWithColor (myMainPM,
1699 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1703 if (theToUpdateViewer)
1705 UpdateCurrentViewer();
1709 //=======================================================================
1710 //function : UnsetWidth
1712 //=======================================================================
1713 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1714 const Standard_Boolean theToUpdateViewer)
1716 if (theIObj.IsNull())
1721 theIObj->UnsetWidth();
1722 theIObj->UpdatePresentations();
1723 if (theToUpdateViewer)
1725 UpdateCurrentViewer();
1729 //=======================================================================
1730 //function : SetMaterial
1732 //=======================================================================
1733 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1734 const Graphic3d_MaterialAspect& theMaterial,
1735 const Standard_Boolean theToUpdateViewer)
1737 if (theIObj.IsNull())
1742 setContextToObject (theIObj);
1743 theIObj->SetMaterial (theMaterial);
1744 theIObj->UpdatePresentations();
1745 if (theToUpdateViewer)
1747 UpdateCurrentViewer();
1751 //=======================================================================
1752 //function : UnsetMaterial
1754 //=======================================================================
1755 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1756 const Standard_Boolean theToUpdateViewer)
1758 if (theIObj.IsNull())
1762 theIObj->UnsetMaterial();
1763 theIObj->UpdatePresentations();
1764 if (theToUpdateViewer)
1766 UpdateCurrentViewer();
1770 //=======================================================================
1771 //function : SetTransparency
1773 //=======================================================================
1774 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1775 const Standard_Real theValue,
1776 const Standard_Boolean theToUpdateViewer)
1778 if (theIObj.IsNull())
1783 setContextToObject (theIObj);
1784 if (!theIObj->IsTransparent()
1785 && theValue <= 0.005)
1790 if (theValue <= 0.005)
1792 UnsetTransparency (theIObj, theToUpdateViewer);
1796 theIObj->SetTransparency (theValue);
1797 theIObj->UpdatePresentations();
1798 if (theToUpdateViewer)
1800 UpdateCurrentViewer();
1804 //=======================================================================
1805 //function : UnsetTransparency
1807 //=======================================================================
1808 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1809 const Standard_Boolean theToUpdateViewer)
1811 if (theIObj.IsNull())
1816 theIObj->UnsetTransparency();
1817 theIObj->UpdatePresentations();
1818 if (theToUpdateViewer)
1820 UpdateCurrentViewer();
1824 //=======================================================================
1825 //function : SetSelectedAspect
1827 //=======================================================================
1828 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1829 const Standard_Boolean theToUpdateViewer)
1831 Standard_DISABLE_DEPRECATION_WARNINGS
1832 Standard_Boolean isFound = Standard_False;
1833 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1835 isFound = Standard_True;
1836 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1837 anObj->SetAspect (theAspect);
1839 Standard_ENABLE_DEPRECATION_WARNINGS
1841 if (isFound && theToUpdateViewer)
1843 myMainVwr->Update();
1847 //=======================================================================
1848 //function : SetLocalAttributes
1850 //=======================================================================
1851 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1852 const Handle(Prs3d_Drawer)& theDrawer,
1853 const Standard_Boolean theToUpdateViewer)
1855 if (theIObj.IsNull())
1860 setContextToObject (theIObj);
1861 theIObj->SetAttributes (theDrawer);
1862 Update (theIObj, theToUpdateViewer);
1865 //=======================================================================
1866 //function : UnsetLocalAttributes
1868 //=======================================================================
1869 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1870 const Standard_Boolean theToUpdateViewer)
1872 if (theIObj.IsNull())
1877 setContextToObject (theIObj);
1878 theIObj->UnsetAttributes();
1879 Update (theIObj, theToUpdateViewer);
1882 //=======================================================================
1885 //=======================================================================
1886 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1887 TCollection_ExtendedString& theStatus) const
1890 if (theIObj.IsNull()
1891 || !myObjects.IsBound (theIObj))
1896 theStatus += "\t ____________________________________________";
1897 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1898 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1899 switch (aStatus->GraphicStatus())
1901 case AIS_DS_Displayed:
1903 theStatus += "\t| -->Displayed\n";
1908 theStatus += "\t| -->Erased\n";
1915 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1916 theStatus += "\t|\t Mode ";
1917 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1920 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1922 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1923 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1925 theStatus += "\t\t Mode ";
1926 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1929 theStatus += "\t ____________________________________________";
1932 //=======================================================================
1933 //function : GetDefModes
1935 //=======================================================================
1936 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1937 Standard_Integer& theDispMode,
1938 Standard_Integer& theHiMode,
1939 Standard_Integer& theSelMode) const
1941 if (theIObj.IsNull())
1946 theDispMode = theIObj->HasDisplayMode()
1947 ? theIObj->DisplayMode()
1948 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1949 ? myDefaultDrawer->DisplayMode()
1951 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1952 theSelMode = theIObj->GlobalSelectionMode();
1955 //=======================================================================
1956 //function : EraseGlobal
1958 //=======================================================================
1959 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1960 const Standard_Boolean theToUpdateviewer)
1962 Handle(AIS_GlobalStatus) aStatus;
1963 if (theIObj.IsNull()
1964 || !myObjects.Find (theIObj, aStatus)
1965 || aStatus->GraphicStatus() == AIS_DS_Erased)
1970 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1971 unselectOwners (theIObj);
1972 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1974 if (!myLastPicked.IsNull()
1975 && myLastPicked->IsSameSelectable (theIObj))
1977 clearDynamicHighlight();
1980 // make sure highlighting presentations are properly erased
1981 theIObj->ErasePresentations (false);
1983 if (IsSelected (theIObj)
1984 && aStatus->DisplayMode() != aDispMode)
1986 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1989 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1991 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1993 aStatus->ClearSelectionModes();
1994 aStatus->SetGraphicStatus (AIS_DS_Erased);
1996 if (theToUpdateviewer)
1998 myMainVwr->Update();
2002 //=======================================================================
2003 //function : unselectOwners
2005 //=======================================================================
2006 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
2008 SelectMgr_SequenceOfOwner aSeq;
2009 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2011 if (aSelIter.Value()->IsSameSelectable (theObject))
2013 aSeq.Append (aSelIter.Value());
2016 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2018 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2022 //=======================================================================
2023 //function : ClearGlobal
2025 //=======================================================================
2026 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2027 const Standard_Boolean theToUpdateviewer)
2029 Handle(AIS_GlobalStatus) aStatus;
2030 if (theIObj.IsNull()
2031 || !myObjects.Find (theIObj, aStatus))
2033 // for cases when reference shape of connected interactives was not displayed
2034 // but its selection primitives were calculated
2035 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2036 mgrSelector->Remove (anObj);
2040 unselectOwners (theIObj);
2042 myMainPM->Erase (theIObj, -1);
2043 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2045 // Object removes from Detected sequence
2046 Standard_DISABLE_DEPRECATION_WARNINGS
2047 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2049 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2050 Handle(AIS_InteractiveObject) anObj;
2051 if (!aPicked.IsNull())
2053 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2057 && anObj == theIObj)
2059 myDetectedSeq.Remove (aDetIter);
2060 if (myCurDetected == aDetIter)
2062 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2064 if (myCurHighlighted == aDetIter)
2066 myCurHighlighted = 0;
2074 Standard_ENABLE_DEPRECATION_WARNINGS
2076 // remove IO from the selection manager to avoid memory leaks
2077 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2078 mgrSelector->Remove (anObj);
2080 setObjectStatus (theIObj, AIS_DS_None, -1, -1);
2081 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2083 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2085 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2088 if (!myLastPicked.IsNull())
2090 if (myLastPicked->IsSameSelectable (theIObj))
2092 clearDynamicHighlight();
2093 myLastPicked.Nullify();
2097 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2099 myMainVwr->Update();
2103 //=======================================================================
2104 //function : ClearGlobalPrs
2106 //=======================================================================
2107 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2108 const Standard_Integer theMode,
2109 const Standard_Boolean theToUpdateViewer)
2111 if (theIObj.IsNull()
2112 || !myObjects.IsBound (theIObj))
2117 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2118 if (aStatus->DisplayMode() == theMode)
2120 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2121 if (aDispMode == theMode
2122 && myMainPM->IsHighlighted (theIObj, theMode))
2124 unhighlightGlobal (theIObj);
2127 myMainPM->Erase (theIObj, theMode);
2130 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2131 && theToUpdateViewer)
2133 myMainVwr->Update();
2137 //=======================================================================
2138 //function : ClearDetected
2140 //=======================================================================
2141 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2144 myCurHighlighted = 0;
2145 myDetectedSeq.Clear();
2146 Standard_Boolean toUpdate = Standard_False;
2147 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2149 toUpdate = Standard_True;
2150 clearDynamicHighlight();
2152 myLastPicked.Nullify();
2153 myMainSel->ClearPicked();
2154 if (toUpdate && theToRedrawImmediate)
2156 myMainVwr->RedrawImmediate();
2161 //=======================================================================
2162 //function : DrawHiddenLine
2164 //=======================================================================
2165 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2167 return myDefaultDrawer->DrawHiddenLine();
2170 //=======================================================================
2171 //function : EnableDrawHiddenLine
2173 //=======================================================================
2174 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2176 myDefaultDrawer->EnableDrawHiddenLine();
2179 //=======================================================================
2180 //function : DisableDrawHiddenLine
2182 //=======================================================================
2183 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2185 myDefaultDrawer->DisableDrawHiddenLine();
2188 //=======================================================================
2189 //function : HiddenLineAspect
2191 //=======================================================================
2192 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2194 return myDefaultDrawer->HiddenLineAspect();
2197 //=======================================================================
2198 //function : SetHiddenLineAspect
2200 //=======================================================================
2201 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2203 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2206 //=======================================================================
2207 //function : SetIsoNumber
2209 //=======================================================================
2210 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2211 const AIS_TypeOfIso theType)
2216 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2219 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2222 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2223 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2228 //=======================================================================
2229 //function : IsoNumber
2231 //=======================================================================
2232 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2236 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2237 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2238 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2239 ? myDefaultDrawer->UIsoAspect()->Number()
2245 //=======================================================================
2246 //function : IsoOnPlane
2248 //=======================================================================
2249 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2251 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2254 //=======================================================================
2255 //function : IsoOnPlane
2257 //=======================================================================
2258 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2260 return myDefaultDrawer->IsoOnPlane();
2263 //=======================================================================
2264 //function : IsoOnTriangulation
2266 //=======================================================================
2267 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2269 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2272 //=======================================================================
2273 //function : IsoOnTriangulation
2275 //=======================================================================
2276 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2278 return myDefaultDrawer->IsoOnTriangulation();
2281 //=======================================================================
2282 //function : SetPixelTolerance
2284 //=======================================================================
2285 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2287 myMainSel->SetPixelTolerance (thePrecision);
2290 //=======================================================================
2291 //function : PixelTolerance
2293 //=======================================================================
2294 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2296 return myMainSel->PixelTolerance();
2299 //=======================================================================
2300 //function : SetSelectionSensitivity
2301 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2302 //=======================================================================
2303 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2304 const Standard_Integer theMode,
2305 const Standard_Integer theNewSensitivity)
2307 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2310 //=======================================================================
2311 //function : InitAttributes
2313 //=======================================================================
2314 void AIS_InteractiveContext::InitAttributes()
2316 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2317 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2319 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2320 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2321 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2322 aLineAspect->SetWidth (1.0);
2323 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2325 // tolerance to 2 pixels...
2326 SetPixelTolerance (2);
2328 // Customizing the drawer for trihedrons and planes...
2329 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2330 const Standard_Real aLength = 100.0;
2331 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2332 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2333 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2334 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2335 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2337 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2338 const Standard_Real aPlaneLength = 200.0;
2339 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2340 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2343 //=======================================================================
2344 //function : TrihedronSize
2346 //=======================================================================
2347 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2349 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2352 //=======================================================================
2353 //function : SetTrihedronSize
2355 //=======================================================================
2356 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2357 const Standard_Boolean /*updateviewer*/)
2359 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2360 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2361 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2364 //=======================================================================
2365 //function : SetPlaneSize
2367 //=======================================================================
2368 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2369 const Standard_Real theValY,
2370 const Standard_Boolean theToUpdateViewer)
2372 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2373 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2376 //=======================================================================
2377 //function : SetPlaneSize
2379 //=======================================================================
2380 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2381 const Standard_Boolean theToUpdateViewer)
2383 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2386 //=======================================================================
2387 //function : PlaneSize
2389 //=======================================================================
2390 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2391 Standard_Real& theY) const
2393 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2394 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2395 return (Abs (theX - theY) <= Precision::Confusion());
2398 //=======================================================================
2399 //function : SetZLayer
2401 //=======================================================================
2402 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2403 const Graphic3d_ZLayerId theLayerId)
2405 if (theIObj.IsNull())
2408 theIObj->SetZLayer (theLayerId);
2411 //=======================================================================
2412 //function : GetZLayer
2414 //=======================================================================
2415 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2417 return !theIObj.IsNull()
2419 : Graphic3d_ZLayerId_UNKNOWN;
2422 //=======================================================================
2423 //function : RebuildSelectionStructs
2424 //purpose : Rebuilds 1st level of BVH selection forcibly
2425 //=======================================================================
2426 void AIS_InteractiveContext::RebuildSelectionStructs()
2428 myMainSel->RebuildObjectsTree (Standard_True);
2431 //=======================================================================
2432 //function : Disconnect
2433 //purpose : Disconnects selectable object from an assembly and updates selection structures
2434 //=======================================================================
2435 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2436 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2438 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2440 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2441 theObj->Disconnect (theObjToDisconnect);
2442 if (!myObjects.IsBound (theObjToDisconnect))
2444 // connected presentation might contain displayed presentations
2445 myMainPM->Erase (theObjToDisconnect, -1);
2446 theObjToDisconnect->ErasePresentations (true);
2449 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2450 mgrSelector->Remove (anObj);
2452 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2454 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2455 theObj->Disconnect();
2456 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2457 mgrSelector->Remove (anObj);
2463 //=======================================================================
2464 //function : FitSelected
2465 //purpose : Fits the view corresponding to the bounds of selected objects
2466 //=======================================================================
2467 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2469 FitSelected (theView, 0.01, Standard_True);
2472 //=======================================================================
2473 //function : BoundingBoxOfSelection
2475 //=======================================================================
2476 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
2478 Bnd_Box aBndSelected;
2479 AIS_MapOfObjectOwners anObjectOwnerMap;
2480 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2482 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2483 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2484 if (anObj->IsInfinite())
2489 if (anOwner == anObj->GlobalSelOwner())
2492 anObj->BoundingBox (aTmpBnd);
2493 aBndSelected.Add (aTmpBnd);
2497 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2498 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2500 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2501 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2504 anOwnerMap->Add (anOwner);
2508 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2510 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2511 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2512 aBndSelected.Add (aTmpBox);
2515 return aBndSelected;
2518 //=======================================================================
2519 //function : FitSelected
2520 //purpose : Fits the view corresponding to the bounds of selected objects
2521 //=======================================================================
2522 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2523 const Standard_Real theMargin,
2524 const Standard_Boolean theToUpdate)
2526 Bnd_Box aBndSelected = BoundingBoxOfSelection();
2527 if (!aBndSelected.IsVoid())
2529 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2533 //=======================================================================
2534 //function : SetTransformPersistence
2536 //=======================================================================
2537 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2538 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2540 theObject->SetTransformPersistence (theTrsfPers);
2541 if (!myObjects.IsBound (theObject))
2546 mgrSelector->UpdateSelection (theObject);
2548 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2549 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2550 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2552 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2553 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2557 //=======================================================================
2558 //function : GravityPoint
2560 //=======================================================================
2561 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2563 return theView->GravityPoint();
2565 //=======================================================================
2566 //function : setObjectStatus
2568 //=======================================================================
2569 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2570 const AIS_DisplayStatus theStatus,
2571 const Standard_Integer theDispMode,
2572 const Standard_Integer theSelectionMode)
2574 if (theStatus != AIS_DS_None)
2576 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
2577 myObjects.Bind (theIObj, aStatus);
2580 myObjects.UnBind (theIObj);
2582 for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2584 Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2585 if (aChild.IsNull())
2588 setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);