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 : UpdateCurrentViewer
193 //=======================================================================
195 void AIS_InteractiveContext::UpdateCurrentViewer()
197 if (!myMainVwr.IsNull())
201 //=======================================================================
202 //function : DisplayedObjects
204 //=======================================================================
205 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
207 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
209 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
211 theListOfIO.Append (anObjIter.Key());
216 //=======================================================================
217 //function : DisplayedObjects
219 //=======================================================================
220 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
221 const Standard_Integer theSign,
222 AIS_ListOfInteractive& theListOfIO) const
224 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
227 //=======================================================================
228 //function : ErasedObjects
230 //=======================================================================
231 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
233 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
236 //=======================================================================
237 //function : ErasedObjects
239 //=======================================================================
240 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
241 const Standard_Integer theSign,
242 AIS_ListOfInteractive& theListOfIO) const
244 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
247 //=======================================================================
248 //function : ObjectsByDisplayStatus
250 //=======================================================================
251 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
252 AIS_ListOfInteractive& theListOfIO) const
254 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
256 if (anObjIter.Value()->GraphicStatus() == theStatus)
258 theListOfIO.Append (anObjIter.Key());
263 //=======================================================================
264 //function : ObjectsByDisplayStatus
266 //=======================================================================
267 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
268 const Standard_Integer theSign,
269 const AIS_DisplayStatus theStatus,
270 AIS_ListOfInteractive& theListOfIO) const
272 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
274 if (theStatus != AIS_DS_None
275 && anObjIter.Value()->GraphicStatus() != theStatus)
279 else if (anObjIter.Key()->Type() != theKind)
285 || anObjIter.Key()->Signature() == theSign)
287 theListOfIO.Append (anObjIter.Key());
292 //=======================================================================
293 //function : ObjectsInside
295 //=======================================================================
296 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
297 const AIS_KindOfInteractive theKind,
298 const Standard_Integer theSign) const
300 if (theKind == AIS_KOI_None
303 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
305 theListOfIO.Append (anObjIter.Key());
310 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
312 if (anObjIter.Key()->Type() != theKind)
318 || anObjIter.Key()->Signature() == theSign)
320 theListOfIO.Append (anObjIter.Key());
325 //=======================================================================
326 //function : ObjectsForView
328 //=======================================================================
329 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
330 const Handle(V3d_View)& theView,
331 const Standard_Boolean theIsVisibleInView,
332 const AIS_DisplayStatus theStatus) const
334 Handle(Graphic3d_CView) aViewImpl = theView->View();
335 const Standard_Integer aViewId = aViewImpl->Identification();
336 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
338 if (theStatus != AIS_DS_None
339 && anObjIter.Value()->GraphicStatus() != theStatus)
341 theListOfIO.Append (anObjIter.Key());
345 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
346 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
347 if (isVisible == theIsVisibleInView)
349 theListOfIO.Append (anObjIter.Key());
354 //=======================================================================
357 //=======================================================================
358 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
359 const Standard_Boolean theToUpdateViewer)
361 if (theIObj.IsNull())
366 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
367 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
368 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
371 //=======================================================================
372 //function : SetViewAffinity
374 //=======================================================================
375 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
376 const Handle(V3d_View)& theView,
377 const Standard_Boolean theIsVisible)
380 || !myObjects.IsBound (theIObj))
385 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
386 Handle(Graphic3d_CView) aViewImpl = theView->View();
387 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
390 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
394 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
398 //=======================================================================
401 //=======================================================================
402 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
403 const Standard_Integer theDispMode,
404 const Standard_Integer theSelectionMode,
405 const Standard_Boolean theToUpdateViewer,
406 const AIS_DisplayStatus theDispStatus)
408 if (theIObj.IsNull())
413 if (theDispStatus == AIS_DS_Erased)
415 Erase (theIObj, theToUpdateViewer);
416 Load (theIObj, theSelectionMode);
417 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
419 (*aStatusPtr)->SetDisplayMode (theDispMode);
424 setContextToObject (theIObj);
425 if (!myObjects.IsBound (theIObj))
427 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
428 myObjects.Bind (theIObj, aStatus);
429 myMainVwr->StructureManager()->RegisterObject (theIObj);
430 myMainPM->Display(theIObj, theDispMode);
431 if (theSelectionMode != -1)
433 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
434 if (!mgrSelector->Contains (anObj))
436 mgrSelector->Load (theIObj);
438 mgrSelector->Activate (theIObj, theSelectionMode);
443 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
445 // Mark the presentation modes hidden of interactive object different from aDispMode.
446 // Then make sure aDispMode is displayed and maybe highlighted.
447 // Finally, activate selection mode <SelMode> if not yet activated.
448 const Standard_Integer anOldMode = aStatus->DisplayMode();
449 if (anOldMode != theDispMode)
451 if(myMainPM->IsHighlighted (theIObj, anOldMode))
453 unhighlightGlobal (theIObj);
455 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
458 aStatus->SetDisplayMode (theDispMode);
460 myMainPM->Display (theIObj, theDispMode);
461 aStatus->SetGraphicStatus (AIS_DS_Displayed);
462 if (aStatus->IsHilighted())
464 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
466 if (theSelectionMode != -1)
468 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
469 if (!mgrSelector->Contains (anObj))
471 mgrSelector->Load (theIObj);
473 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
475 if (!aStatus->IsSModeIn (theSelectionMode))
476 aStatus->AddSelectionMode (theSelectionMode);
477 mgrSelector->Activate (theIObj, theSelectionMode);
482 if (theToUpdateViewer)
488 //=======================================================================
491 //=======================================================================
492 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
493 const Standard_Integer theSelMode)
495 if (theIObj.IsNull())
500 setContextToObject (theIObj);
501 if (!myObjects.IsBound (theIObj))
503 Standard_Integer aDispMode, aHiMod, aSelModeDef;
504 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
505 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
506 myObjects.Bind (theIObj, aStatus);
507 myMainVwr->StructureManager()->RegisterObject (theIObj);
510 // Register theIObj in the selection manager to prepare further activation of selection
511 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
512 if (!mgrSelector->Contains (anObj))
514 mgrSelector->Load (theIObj);
518 //=======================================================================
521 //=======================================================================
522 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
523 const Standard_Boolean theToUpdateViewer)
525 if (theIObj.IsNull())
530 if (!theIObj->IsAutoHilight())
532 theIObj->ClearSelected();
535 EraseGlobal (theIObj, Standard_False);
536 if (theToUpdateViewer)
542 //=======================================================================
543 //function : EraseAll
545 //=======================================================================
546 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
548 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
550 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
552 Erase (anObjIter.Key(), Standard_False);
556 if (theToUpdateViewer)
562 //=======================================================================
563 //function : DisplayAll
565 //=======================================================================
566 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
568 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
570 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
571 if (aStatus == AIS_DS_Erased)
573 Display (anObjIter.Key(), Standard_False);
577 if (theToUpdateViewer)
583 //=======================================================================
584 //function : DisplaySelected
586 //=======================================================================
587 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
589 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
591 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
592 Display (anObj, Standard_False);
595 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
601 //=======================================================================
602 //function : EraseSelected
604 //=======================================================================
605 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
607 Standard_Boolean isFound = Standard_False;
608 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
610 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
611 Erase (anObj, Standard_False);
612 isFound = Standard_True;
615 if (isFound && theToUpdateViewer)
621 //=======================================================================
622 //function : DisplayStatus
624 //=======================================================================
625 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
627 if (theIObj.IsNull())
631 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
632 return aStatus != NULL ? (*aStatus)->GraphicStatus() : AIS_DS_None;
635 //=======================================================================
638 //=======================================================================
639 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
640 const Standard_Boolean theToUpdateViewer)
642 if (theIObj.IsNull())
647 if (theIObj->HasInteractiveContext())
649 if (theIObj->myCTXPtr != this)
651 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
653 theIObj->SetContext (Handle(AIS_InteractiveContext)());
655 ClearGlobal (theIObj, theToUpdateViewer);
658 //=======================================================================
659 //function : RemoveAll
661 //=======================================================================
662 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
664 AIS_ListOfInteractive aList;
665 ObjectsInside (aList);
666 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
668 Remove (aListIterator.Value(), Standard_False);
671 if (theToUpdateViewer)
677 //=======================================================================
678 //function : HilightWithColor
680 //=======================================================================
681 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
682 const Handle(Prs3d_Drawer)& theStyle,
683 const Standard_Boolean theIsToUpdate)
688 setContextToObject (theObj);
689 if (!myObjects.IsBound (theObj))
692 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
693 aStatus->SetHilightStatus (Standard_True);
695 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
697 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
698 aStatus->SetHilightStyle (theStyle);
705 //=======================================================================
706 //function : Unhilight
708 //=======================================================================
709 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
711 if(anIObj.IsNull()) return;
712 if(!myObjects.IsBound(anIObj)) return;
714 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
715 aStatus->SetHilightStatus (Standard_False);
716 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
718 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
720 unhighlightGlobal (anIObj);
723 if(updateviewer) myMainVwr->Update();
726 //=======================================================================
727 //function : IsHilighted
728 //purpose : Returns true if the objects global status is set to highlighted.
729 //=======================================================================
730 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
732 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
733 return aStatus != NULL
734 && (*aStatus)->IsHilighted();
737 //=======================================================================
738 //function : IsHilighted
739 //purpose : Returns true if the owner is highlighted with selection style.
740 //=======================================================================
741 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
743 if (theOwner.IsNull() || !theOwner->HasSelectable())
744 return Standard_False;
746 const Handle(AIS_InteractiveObject) anObj =
747 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
749 if (anObj->GlobalSelOwner() == theOwner)
751 if (!myObjects.IsBound (anObj))
752 return Standard_False;
754 return myObjects (anObj)->IsHilighted();
757 const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
758 const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
759 return theOwner->IsHilighted (myMainPM, aHiMode);
762 //=======================================================================
763 //function : HighlightStyle
765 //=======================================================================
766 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
767 Handle(Prs3d_Drawer)& theStyle) const
769 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
771 && (*aStatus)->IsHilighted())
773 theStyle = (*aStatus)->HilightStyle();
774 return Standard_True;
778 return Standard_False;
781 //=======================================================================
782 //function : HighlightStyle
784 //=======================================================================
785 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
786 Handle(Prs3d_Drawer)& theStyle) const
788 if (theOwner.IsNull() || !theOwner->HasSelectable())
789 return Standard_False;
791 if (IsHilighted (theOwner))
793 const Handle(AIS_InteractiveObject) anObj =
794 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
795 if (anObj->GlobalSelOwner() == theOwner)
797 theStyle = myObjects (anObj)->HilightStyle();
801 // since part selection style is not stored in global status,
802 // check if the object has own selection style. If not, it can
803 // only be highlighted with default selection style (because
804 // sub-intensity does not modify any selection states)
805 theStyle = getSelStyle (anObj, theOwner);
807 return Standard_True;
812 return Standard_False;
816 //=======================================================================
817 //function : IsDisplayed
819 //=======================================================================
821 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
823 if(theObj.IsNull()) return Standard_False;
825 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
826 return aStatus != NULL
827 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed;
830 //=======================================================================
831 //function : IsDisplayed
833 //=======================================================================
834 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
835 const Standard_Integer theMode) const
837 if (theIObj.IsNull())
839 return Standard_False;
842 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
843 return aStatus != NULL
844 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed
845 && (*aStatus)->DisplayMode() == theMode;
848 //=======================================================================
849 //function : DisplayPriority
851 //=======================================================================
852 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
854 if (theIObj.IsNull())
859 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
861 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
862 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
864 Standard_Integer aDispMode = theIObj->HasDisplayMode()
865 ? theIObj->DisplayMode()
866 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
867 ? myDefaultDrawer->DisplayMode()
869 return myMainPM->DisplayPriority (theIObj, aDispMode);
874 //=======================================================================
875 //function : SetDisplayPriority
877 //=======================================================================
878 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
879 const Standard_Integer thePriority)
881 if (theIObj.IsNull())
886 setContextToObject (theIObj);
887 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
889 && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
890 || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
892 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
893 ? theIObj->DisplayMode()
894 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
895 ? myDefaultDrawer->DisplayMode()
897 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
901 //=======================================================================
902 //function : Redisplay
904 //=======================================================================
905 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
906 const Standard_Boolean theToUpdateViewer,
907 const Standard_Boolean theAllModes)
909 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
910 RecomputeSelectionOnly (theIObj);
913 //=======================================================================
914 //function : Redisplay
916 //=======================================================================
917 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
918 const Standard_Integer /*theSign*/,
919 const Standard_Boolean theToUpdateViewer)
921 Standard_Boolean isRedisplayed = Standard_False;
922 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
924 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
925 if (anObj->Type() != theKOI)
930 Redisplay (anObj, Standard_False);
931 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
935 if (theToUpdateViewer
942 //=======================================================================
943 //function : RecomputePrsOnly
945 //=======================================================================
946 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
947 const Standard_Boolean theToUpdateViewer,
948 const Standard_Boolean theAllModes)
950 if (theIObj.IsNull())
955 theIObj->SetToUpdate();
956 theIObj->UpdatePresentations (theAllModes);
957 if (!theToUpdateViewer)
962 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
964 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
969 //=======================================================================
970 //function : RecomputeSelectionOnly
972 //=======================================================================
973 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
980 mgrSelector->RecomputeSelection (theIO);
982 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
984 || (*aStatus)->GraphicStatus() != AIS_DS_Displayed)
989 TColStd_ListOfInteger aModes;
990 ActivatedModes (theIO, aModes);
991 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
992 for (; aModesIter.More(); aModesIter.Next())
994 mgrSelector->Activate (theIO, aModesIter.Value());
998 //=======================================================================
1001 //=======================================================================
1002 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1003 const Standard_Boolean theUpdateViewer)
1005 if (theIObj.IsNull())
1010 theIObj->UpdatePresentations();
1011 mgrSelector->Update(theIObj);
1013 if (theUpdateViewer)
1015 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1017 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
1019 myMainVwr->Update();
1024 //=======================================================================
1025 //function : SetLocation
1027 //=======================================================================
1028 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1029 const TopLoc_Location& theLoc)
1031 if (theIObj.IsNull())
1036 if (theIObj->HasTransformation()
1037 && theLoc.IsIdentity())
1039 theIObj->ResetTransformation();
1040 mgrSelector->Update (theIObj, Standard_False);
1043 else if (theLoc.IsIdentity())
1048 // first reset the previous location to properly clean everything...
1049 if (theIObj->HasTransformation())
1051 theIObj->ResetTransformation();
1054 theIObj->SetLocalTransformation (theLoc.Transformation());
1056 mgrSelector->Update (theIObj, Standard_False);
1058 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1059 // to its highlight structure immediately
1060 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1062 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1063 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1069 //=======================================================================
1070 //function : ResetLocation
1072 //=======================================================================
1073 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1075 if (theIObj.IsNull())
1080 theIObj->ResetTransformation();
1081 mgrSelector->Update (theIObj, Standard_False);
1084 //=======================================================================
1085 //function : HasLocation
1087 //=======================================================================
1088 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1090 return !theIObj.IsNull()
1091 && theIObj->HasTransformation();
1094 //=======================================================================
1095 //function : Location
1097 //=======================================================================
1098 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1100 return theIObj->Transformation();
1103 //=======================================================================
1104 //function : SetDeviationCoefficient
1106 //=======================================================================
1107 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1109 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1112 //=======================================================================
1113 //function : SetDeviationAngle
1115 //=======================================================================
1116 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1118 myDefaultDrawer->SetDeviationAngle (theAngle);
1121 //=======================================================================
1122 //function : DeviationAngle
1123 //purpose : Gets deviationAngle
1124 //=======================================================================
1125 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1127 return myDefaultDrawer->DeviationAngle();
1130 //=======================================================================
1131 //function : DeviationCoefficient
1133 //=======================================================================
1134 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1136 return myDefaultDrawer->DeviationCoefficient();
1139 //=======================================================================
1140 //function : SetHLRDeviationCoefficient
1142 //=======================================================================
1143 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1145 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1148 //=======================================================================
1149 //function : HLRDeviationCoefficient
1151 //=======================================================================
1152 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1154 return myDefaultDrawer->HLRDeviationCoefficient();
1157 //=======================================================================
1158 //function : SetHLRAngle
1160 //=======================================================================
1161 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1163 myDefaultDrawer->SetHLRAngle (theAngle);
1166 //=======================================================================
1167 //function : SetHLRAngleAndDeviation
1168 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1169 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1170 // of myDefaultDrawer
1171 //=======================================================================
1172 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1174 Standard_Real anOutAngl, anOutDefl;
1175 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1177 myDefaultDrawer->SetHLRAngle (anOutAngl);
1178 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1181 //=======================================================================
1182 //function : HLRAngle
1184 //=======================================================================
1185 Standard_Real AIS_InteractiveContext::HLRAngle() const
1187 return myDefaultDrawer->HLRAngle();
1190 //=======================================================================
1191 //function : SetDisplayMode
1193 //=======================================================================
1194 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1195 const Standard_Boolean theToUpdateViewer)
1197 if (theMode == myDefaultDrawer->DisplayMode())
1202 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1204 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1205 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1206 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1207 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1210 || anObj->HasDisplayMode()
1211 || !anObj->AcceptDisplayMode (theMode))
1216 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1217 aStatus->SetDisplayMode (theMode);
1219 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1221 myMainPM->Display (anObj, theMode);
1222 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1224 myMainPM->BeginImmediateDraw();
1225 unhighlightGlobal (anObj);
1226 myMainPM->EndImmediateDraw (myMainVwr);
1228 if (aStatus->IsSubIntensityOn())
1230 highlightWithSubintensity (anObj, theMode);
1232 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1236 myDefaultDrawer->SetDisplayMode (theMode);
1237 if (theToUpdateViewer)
1239 myMainVwr->Update();
1243 //=======================================================================
1244 //function : SetDisplayMode
1246 //=======================================================================
1247 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1248 const Standard_Integer theMode,
1249 const Standard_Boolean theToUpdateViewer)
1251 setContextToObject (theIObj);
1252 if (!myObjects.IsBound (theIObj))
1254 theIObj->SetDisplayMode (theMode);
1257 else if (!theIObj->AcceptDisplayMode (theMode))
1262 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1263 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1265 aStatus->SetDisplayMode (theMode);
1266 theIObj->SetDisplayMode (theMode);
1270 // erase presentations for all display modes different from <aMode>
1271 const Standard_Integer anOldMode = aStatus->DisplayMode();
1272 if (anOldMode != theMode)
1274 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1276 unhighlightGlobal (theIObj);
1278 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1281 aStatus->SetDisplayMode (theMode);
1283 myMainPM->Display (theIObj, theMode);
1284 if (aStatus->IsHilighted())
1286 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1288 if (aStatus->IsSubIntensityOn())
1290 highlightWithSubintensity (theIObj, theMode);
1293 if (theToUpdateViewer)
1295 myMainVwr->Update();
1297 theIObj->SetDisplayMode (theMode);
1300 //=======================================================================
1301 //function : UnsetDisplayMode
1303 //=======================================================================
1304 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1305 const Standard_Boolean theToUpdateViewer)
1307 if (theIObj.IsNull()
1308 || !theIObj->HasDisplayMode())
1313 if (!myObjects.IsBound (theIObj))
1315 theIObj->UnsetDisplayMode();
1319 const Standard_Integer anOldMode = theIObj->DisplayMode();
1320 if (myDefaultDrawer->DisplayMode() == anOldMode)
1325 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1326 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1328 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1330 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1332 unhighlightGlobal (theIObj);
1334 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1335 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1336 if (aStatus->IsHilighted())
1338 highlightSelected (theIObj->GlobalSelOwner());
1340 if (aStatus->IsSubIntensityOn())
1342 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1345 if (theToUpdateViewer)
1347 myMainVwr->Update();
1351 theIObj->UnsetDisplayMode();
1354 //=======================================================================
1355 //function : SetCurrentFacingModel
1357 //=======================================================================
1358 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1359 const Aspect_TypeOfFacingModel theModel)
1361 if (!theIObj.IsNull())
1363 theIObj->SetCurrentFacingModel (theModel);
1367 //=======================================================================
1368 //function : SetColor
1370 //=======================================================================
1371 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1372 const Quantity_Color& theColor,
1373 const Standard_Boolean theToUpdateViewer)
1375 if (theIObj.IsNull())
1380 setContextToObject (theIObj);
1381 theIObj->SetColor (theColor);
1382 theIObj->UpdatePresentations();
1383 if (theToUpdateViewer)
1385 UpdateCurrentViewer();
1389 //=======================================================================
1390 //function : SetIsoOnTriangulation
1392 //=======================================================================
1393 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1394 const Handle(AIS_InteractiveObject)& theObject)
1396 if (theObject.IsNull())
1401 theObject->SetIsoOnTriangulation (theIsEnabled);
1404 //=======================================================================
1405 //function : SetDeviationCoefficient
1407 //=======================================================================
1408 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1409 const Standard_Real theCoefficient,
1410 const Standard_Boolean theToUpdateViewer)
1412 if (theIObj.IsNull())
1417 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1418 setContextToObject (theIObj);
1419 if (theIObj->Type() != AIS_KOI_Object
1420 && theIObj->Type() != AIS_KOI_Shape)
1424 else if (theIObj->Signature() != 0)
1429 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1430 aShape->SetOwnDeviationCoefficient (theCoefficient);
1431 aShape->UpdatePresentations();
1432 if (theToUpdateViewer)
1434 UpdateCurrentViewer();
1438 //=======================================================================
1439 //function : SetHLRDeviationCoefficient
1441 //=======================================================================
1442 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1443 const Standard_Real theCoefficient,
1444 const Standard_Boolean theToUpdateViewer)
1446 if (theIObj.IsNull())
1451 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1452 setContextToObject (theIObj);
1453 if (theIObj->Type() != AIS_KOI_Object
1454 && theIObj->Type() != AIS_KOI_Shape)
1458 else if (theIObj->Signature() != 0)
1463 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1464 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1465 aShape->UpdatePresentations();
1466 if (theToUpdateViewer)
1468 UpdateCurrentViewer();
1472 //=======================================================================
1473 //function : SetDeviationAngle
1475 //=======================================================================
1476 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1477 const Standard_Real theAngle,
1478 const Standard_Boolean theToUpdateViewer)
1480 if (theIObj.IsNull())
1485 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1486 setContextToObject (theIObj);
1487 if (theIObj->Type() != AIS_KOI_Shape)
1491 else if (theIObj->Signature() != 0)
1496 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1497 aShape->SetOwnDeviationAngle (theAngle);
1498 aShape->UpdatePresentations();
1499 if (theToUpdateViewer)
1501 UpdateCurrentViewer();
1505 //=======================================================================
1506 //function : SetAngleAndDeviation
1508 //=======================================================================
1509 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1510 const Standard_Real theAngle,
1511 const Standard_Boolean theToUpdateViewer)
1513 if (theIObj.IsNull())
1518 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1519 setContextToObject (theIObj);
1520 if (theIObj->Type() != AIS_KOI_Shape)
1524 if (theIObj->Signature() != 0)
1529 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1530 aShape->SetAngleAndDeviation (theAngle);
1531 aShape->UpdatePresentations();
1532 if (theToUpdateViewer)
1534 UpdateCurrentViewer();
1538 //=======================================================================
1539 //function : SetHLRAngleAndDeviation
1541 //=======================================================================
1542 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1543 const Standard_Real theAngle,
1544 const Standard_Boolean theToUpdateViewer)
1546 if (theIObj.IsNull())
1551 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1552 setContextToObject (theIObj);
1553 if (theIObj->Type() != AIS_KOI_Shape)
1557 if (theIObj->Signature() != 0)
1561 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1562 aShape->SetHLRAngleAndDeviation (theAngle);
1563 aShape->UpdatePresentations();
1564 if (theToUpdateViewer)
1566 UpdateCurrentViewer();
1570 //=======================================================================
1571 //function : SetHLRDeviationAngle
1573 //=======================================================================
1574 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1575 const Standard_Real theAngle,
1576 const Standard_Boolean theToUpdateViewer)
1578 if (theIObj.IsNull())
1583 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1584 setContextToObject (theIObj);
1585 if (theIObj->Type() != AIS_KOI_Shape)
1589 if (theIObj->Signature() != 0)
1593 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1594 aShape->SetOwnHLRDeviationAngle (theAngle);
1595 aShape->UpdatePresentations();
1596 if (theToUpdateViewer)
1598 UpdateCurrentViewer();
1602 //=======================================================================
1603 //function : UnsetColor
1605 //=======================================================================
1606 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1607 const Standard_Boolean theToUpdateViewer)
1609 if (theIObj.IsNull())
1614 theIObj->UnsetColor();
1615 theIObj->UpdatePresentations();
1616 if (theToUpdateViewer)
1618 UpdateCurrentViewer();
1622 //=======================================================================
1623 //function : HasColor
1625 //=======================================================================
1626 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1628 return theIObj->HasColor();
1631 //=======================================================================
1634 //=======================================================================
1635 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1636 Quantity_Color& theColor) const
1638 theIObj->Color (theColor);
1641 //=======================================================================
1644 //=======================================================================
1645 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1647 return theIObj->Width();
1650 //=======================================================================
1651 //function : SetWidth
1653 //=======================================================================
1654 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1655 const Standard_Real theWidth,
1656 const Standard_Boolean theToUpdateViewer)
1658 if (theIObj.IsNull())
1663 setContextToObject (theIObj);
1664 theIObj->SetWidth (theWidth);
1665 theIObj->UpdatePresentations();
1666 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1668 if (myLastPicked->IsAutoHilight())
1670 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1671 myLastPicked->HilightWithColor (myMainPM,
1672 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1677 theIObj->HilightOwnerWithColor (myMainPM,
1678 myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1682 if (theToUpdateViewer)
1684 UpdateCurrentViewer();
1688 //=======================================================================
1689 //function : UnsetWidth
1691 //=======================================================================
1692 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1693 const Standard_Boolean theToUpdateViewer)
1695 if (theIObj.IsNull())
1700 theIObj->UnsetWidth();
1701 theIObj->UpdatePresentations();
1702 if (theToUpdateViewer)
1704 UpdateCurrentViewer();
1708 //=======================================================================
1709 //function : SetMaterial
1711 //=======================================================================
1712 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1713 const Graphic3d_MaterialAspect& theMaterial,
1714 const Standard_Boolean theToUpdateViewer)
1716 if (theIObj.IsNull())
1721 setContextToObject (theIObj);
1722 theIObj->SetMaterial (theMaterial);
1723 theIObj->UpdatePresentations();
1724 if (theToUpdateViewer)
1726 UpdateCurrentViewer();
1730 //=======================================================================
1731 //function : UnsetMaterial
1733 //=======================================================================
1734 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1735 const Standard_Boolean theToUpdateViewer)
1737 if (theIObj.IsNull())
1741 theIObj->UnsetMaterial();
1742 theIObj->UpdatePresentations();
1743 if (theToUpdateViewer)
1745 UpdateCurrentViewer();
1749 //=======================================================================
1750 //function : SetTransparency
1752 //=======================================================================
1753 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1754 const Standard_Real theValue,
1755 const Standard_Boolean theToUpdateViewer)
1757 if (theIObj.IsNull())
1762 setContextToObject (theIObj);
1763 if (!theIObj->IsTransparent()
1764 && theValue <= 0.005)
1769 if (theValue <= 0.005)
1771 UnsetTransparency (theIObj, theToUpdateViewer);
1775 theIObj->SetTransparency (theValue);
1776 theIObj->UpdatePresentations();
1777 if (theToUpdateViewer)
1779 UpdateCurrentViewer();
1783 //=======================================================================
1784 //function : UnsetTransparency
1786 //=======================================================================
1787 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1788 const Standard_Boolean theToUpdateViewer)
1790 if (theIObj.IsNull())
1795 theIObj->UnsetTransparency();
1796 theIObj->UpdatePresentations();
1797 if (theToUpdateViewer)
1799 UpdateCurrentViewer();
1803 //=======================================================================
1804 //function : SetSelectedAspect
1806 //=======================================================================
1807 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1808 const Standard_Boolean theToUpdateViewer)
1810 Standard_DISABLE_DEPRECATION_WARNINGS
1811 Standard_Boolean isFound = Standard_False;
1812 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1814 isFound = Standard_True;
1815 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1816 anObj->SetAspect (theAspect);
1818 Standard_ENABLE_DEPRECATION_WARNINGS
1820 if (isFound && theToUpdateViewer)
1822 myMainVwr->Update();
1826 //=======================================================================
1827 //function : SetLocalAttributes
1829 //=======================================================================
1830 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1831 const Handle(Prs3d_Drawer)& theDrawer,
1832 const Standard_Boolean theToUpdateViewer)
1834 if (theIObj.IsNull())
1839 setContextToObject (theIObj);
1840 theIObj->SetAttributes (theDrawer);
1841 Update (theIObj, theToUpdateViewer);
1844 //=======================================================================
1845 //function : UnsetLocalAttributes
1847 //=======================================================================
1848 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1849 const Standard_Boolean theToUpdateViewer)
1851 if (theIObj.IsNull())
1856 setContextToObject (theIObj);
1857 theIObj->UnsetAttributes();
1858 Update (theIObj, theToUpdateViewer);
1861 //=======================================================================
1864 //=======================================================================
1865 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1866 TCollection_ExtendedString& theStatus) const
1869 if (theIObj.IsNull()
1870 || !myObjects.IsBound (theIObj))
1875 theStatus += "\t ____________________________________________";
1876 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1877 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1878 switch (aStatus->GraphicStatus())
1880 case AIS_DS_Displayed:
1882 theStatus += "\t| -->Displayed\n";
1887 theStatus += "\t| -->Erased\n";
1894 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1895 theStatus += "\t|\t Mode ";
1896 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1899 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1901 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1902 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1904 theStatus += "\t\t Mode ";
1905 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1908 theStatus += "\t ____________________________________________";
1911 //=======================================================================
1912 //function : GetDefModes
1914 //=======================================================================
1915 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1916 Standard_Integer& theDispMode,
1917 Standard_Integer& theHiMode,
1918 Standard_Integer& theSelMode) const
1920 if (theIObj.IsNull())
1925 theDispMode = theIObj->HasDisplayMode()
1926 ? theIObj->DisplayMode()
1927 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1928 ? myDefaultDrawer->DisplayMode()
1930 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1931 theSelMode = theIObj->GlobalSelectionMode();
1934 //=======================================================================
1935 //function : EraseGlobal
1937 //=======================================================================
1938 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1939 const Standard_Boolean theToUpdateviewer)
1941 Handle(AIS_GlobalStatus) aStatus;
1942 if (theIObj.IsNull()
1943 || !myObjects.Find (theIObj, aStatus)
1944 || aStatus->GraphicStatus() == AIS_DS_Erased)
1949 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1950 unhighlightOwners (theIObj);
1951 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1953 if (!myLastPicked.IsNull()
1954 && myLastPicked->IsSameSelectable (theIObj))
1956 clearDynamicHighlight();
1959 // make sure highlighting presentations are properly erased
1960 theIObj->ErasePresentations (false);
1962 if (IsSelected (theIObj)
1963 && aStatus->DisplayMode() != aDispMode)
1965 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1968 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1970 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1972 aStatus->ClearSelectionModes();
1973 aStatus->SetGraphicStatus (AIS_DS_Erased);
1975 if (theToUpdateviewer)
1977 myMainVwr->Update();
1981 //=======================================================================
1982 //function : unhighlightOwners
1984 //=======================================================================
1985 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
1987 SelectMgr_SequenceOfOwner aSeq;
1988 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1990 if (aSelIter.Value()->IsSameSelectable (theObject))
1992 aSeq.Append (aSelIter.Value());
1995 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1997 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2001 //=======================================================================
2002 //function : ClearGlobal
2004 //=======================================================================
2005 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2006 const Standard_Boolean theToUpdateviewer)
2008 Handle(AIS_GlobalStatus) aStatus;
2009 if (theIObj.IsNull()
2010 || !myObjects.Find (theIObj, aStatus))
2012 // for cases when reference shape of connected interactives was not displayed
2013 // but its selection primitives were calculated
2014 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2015 mgrSelector->Remove (anObj);
2019 unhighlightOwners (theIObj);
2021 myMainPM->Erase (theIObj, -1);
2022 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2024 // Object removes from Detected sequence
2025 Standard_DISABLE_DEPRECATION_WARNINGS
2026 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2028 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2029 Handle(AIS_InteractiveObject) anObj;
2030 if (!aPicked.IsNull())
2032 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2036 && anObj == theIObj)
2038 myDetectedSeq.Remove (aDetIter);
2039 if (myCurDetected == aDetIter)
2041 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2043 if (myCurHighlighted == aDetIter)
2045 myCurHighlighted = 0;
2053 Standard_ENABLE_DEPRECATION_WARNINGS
2055 // remove IO from the selection manager to avoid memory leaks
2056 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2057 mgrSelector->Remove (anObj);
2059 myObjects.UnBind (theIObj);
2060 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2062 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2064 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2067 if (!myLastPicked.IsNull())
2069 if (myLastPicked->IsSameSelectable (theIObj))
2071 clearDynamicHighlight();
2072 myLastPicked.Nullify();
2076 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2078 myMainVwr->Update();
2082 //=======================================================================
2083 //function : ClearGlobalPrs
2085 //=======================================================================
2086 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2087 const Standard_Integer theMode,
2088 const Standard_Boolean theToUpdateViewer)
2090 if (theIObj.IsNull()
2091 || !myObjects.IsBound (theIObj))
2096 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2097 if (aStatus->DisplayMode() == theMode)
2099 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2100 if (aDispMode == theMode
2101 && myMainPM->IsHighlighted (theIObj, theMode))
2103 unhighlightGlobal (theIObj);
2106 myMainPM->Erase (theIObj, theMode);
2109 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2110 && theToUpdateViewer)
2112 myMainVwr->Update();
2116 //=======================================================================
2117 //function : ClearDetected
2119 //=======================================================================
2120 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2123 myCurHighlighted = 0;
2124 myDetectedSeq.Clear();
2125 Standard_Boolean toUpdate = Standard_False;
2126 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2128 toUpdate = Standard_True;
2129 clearDynamicHighlight();
2131 myLastPicked.Nullify();
2132 myMainSel->ClearPicked();
2133 if (toUpdate && theToRedrawImmediate)
2135 myMainVwr->RedrawImmediate();
2140 //=======================================================================
2141 //function : DrawHiddenLine
2143 //=======================================================================
2144 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2146 return myDefaultDrawer->DrawHiddenLine();
2149 //=======================================================================
2150 //function : EnableDrawHiddenLine
2152 //=======================================================================
2153 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2155 myDefaultDrawer->EnableDrawHiddenLine();
2158 //=======================================================================
2159 //function : DisableDrawHiddenLine
2161 //=======================================================================
2162 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2164 myDefaultDrawer->DisableDrawHiddenLine();
2167 //=======================================================================
2168 //function : HiddenLineAspect
2170 //=======================================================================
2171 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2173 return myDefaultDrawer->HiddenLineAspect();
2176 //=======================================================================
2177 //function : SetHiddenLineAspect
2179 //=======================================================================
2180 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2182 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2185 //=======================================================================
2186 //function : SetIsoNumber
2188 //=======================================================================
2189 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2190 const AIS_TypeOfIso theType)
2195 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2198 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2201 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2202 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2207 //=======================================================================
2208 //function : IsoNumber
2210 //=======================================================================
2211 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2215 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2216 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2217 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2218 ? myDefaultDrawer->UIsoAspect()->Number()
2224 //=======================================================================
2225 //function : IsoOnPlane
2227 //=======================================================================
2228 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2230 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2233 //=======================================================================
2234 //function : IsoOnPlane
2236 //=======================================================================
2237 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2239 return myDefaultDrawer->IsoOnPlane();
2242 //=======================================================================
2243 //function : IsoOnTriangulation
2245 //=======================================================================
2246 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2248 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2251 //=======================================================================
2252 //function : IsoOnTriangulation
2254 //=======================================================================
2255 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2257 return myDefaultDrawer->IsoOnTriangulation();
2260 //=======================================================================
2261 //function : SetPixelTolerance
2263 //=======================================================================
2264 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2266 myMainSel->SetPixelTolerance (thePrecision);
2269 //=======================================================================
2270 //function : PixelTolerance
2272 //=======================================================================
2273 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2275 return myMainSel->PixelTolerance();
2278 //=======================================================================
2279 //function : SetSelectionSensitivity
2280 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2281 //=======================================================================
2282 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2283 const Standard_Integer theMode,
2284 const Standard_Integer theNewSensitivity)
2286 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2289 //=======================================================================
2290 //function : InitAttributes
2292 //=======================================================================
2293 void AIS_InteractiveContext::InitAttributes()
2295 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2296 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2298 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2299 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2300 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2301 aLineAspect->SetWidth (1.0);
2302 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2304 // tolerance to 2 pixels...
2305 SetPixelTolerance (2);
2307 // Customizing the drawer for trihedrons and planes...
2308 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2309 const Standard_Real aLength = 100.0;
2310 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2311 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2312 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2313 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2314 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2316 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2317 const Standard_Real aPlaneLength = 200.0;
2318 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2319 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2322 //=======================================================================
2323 //function : TrihedronSize
2325 //=======================================================================
2326 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2328 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2331 //=======================================================================
2332 //function : SetTrihedronSize
2334 //=======================================================================
2335 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2336 const Standard_Boolean /*updateviewer*/)
2338 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2339 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2340 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2343 //=======================================================================
2344 //function : SetPlaneSize
2346 //=======================================================================
2347 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2348 const Standard_Real theValY,
2349 const Standard_Boolean theToUpdateViewer)
2351 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2352 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2355 //=======================================================================
2356 //function : SetPlaneSize
2358 //=======================================================================
2359 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2360 const Standard_Boolean theToUpdateViewer)
2362 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2365 //=======================================================================
2366 //function : PlaneSize
2368 //=======================================================================
2369 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2370 Standard_Real& theY) const
2372 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2373 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2374 return (Abs (theX - theY) <= Precision::Confusion());
2377 //=======================================================================
2378 //function : SetZLayer
2380 //=======================================================================
2381 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2382 const Graphic3d_ZLayerId theLayerId)
2384 if (theIObj.IsNull())
2387 theIObj->SetZLayer (theLayerId);
2390 //=======================================================================
2391 //function : GetZLayer
2393 //=======================================================================
2394 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2396 return !theIObj.IsNull()
2398 : Graphic3d_ZLayerId_UNKNOWN;
2401 //=======================================================================
2402 //function : RebuildSelectionStructs
2403 //purpose : Rebuilds 1st level of BVH selection forcibly
2404 //=======================================================================
2405 void AIS_InteractiveContext::RebuildSelectionStructs()
2407 myMainSel->RebuildObjectsTree (Standard_True);
2410 //=======================================================================
2411 //function : Disconnect
2412 //purpose : Disconnects selectable object from an assembly and updates selection structures
2413 //=======================================================================
2414 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2415 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2417 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2419 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2420 theObj->Disconnect (theObjToDisconnect);
2421 if (!myObjects.IsBound (theObjToDisconnect))
2423 // connected presentation might contain displayed presentations
2424 myMainPM->Erase (theObjToDisconnect, -1);
2425 theObjToDisconnect->ErasePresentations (true);
2428 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2429 mgrSelector->Remove (anObj);
2431 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2433 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2434 theObj->Disconnect();
2435 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2436 mgrSelector->Remove (anObj);
2442 //=======================================================================
2443 //function : FitSelected
2444 //purpose : Fits the view corresponding to the bounds of selected objects
2445 //=======================================================================
2446 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2448 FitSelected (theView, 0.01, Standard_True);
2451 //=======================================================================
2452 //function : FitSelected
2453 //purpose : Fits the view corresponding to the bounds of selected objects
2454 //=======================================================================
2455 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2456 const Standard_Real theMargin,
2457 const Standard_Boolean theToUpdate)
2459 Bnd_Box aBndSelected;
2460 AIS_MapOfObjectOwners anObjectOwnerMap;
2461 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2463 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2464 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2465 if (anObj->IsInfinite())
2470 if (anOwner == anObj->GlobalSelOwner())
2473 anObj->BoundingBox (aTmpBnd);
2474 aBndSelected.Add (aTmpBnd);
2478 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2479 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2481 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2482 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2485 anOwnerMap->Add (anOwner);
2489 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2491 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2492 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2493 aBndSelected.Add (aTmpBox);
2496 anObjectOwnerMap.Clear();
2498 if (aBndSelected.IsVoid())
2501 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2504 //=======================================================================
2505 //function : SetTransformPersistence
2507 //=======================================================================
2508 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2509 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2511 theObject->SetTransformPersistence (theTrsfPers);
2512 if (!myObjects.IsBound (theObject))
2517 mgrSelector->UpdateSelection (theObject);
2519 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2520 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2521 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2523 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2524 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);