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_ModedPresentation.hxx>
41 #include <PrsMgr_PresentableObject.hxx>
42 #include <Quantity_Color.hxx>
43 #include <SelectMgr_EntityOwner.hxx>
44 #include <SelectMgr_Filter.hxx>
45 #include <SelectMgr_OrFilter.hxx>
46 #include <SelectMgr_SelectionManager.hxx>
47 #include <Standard_Atomic.hxx>
48 #include <Standard_Transient.hxx>
49 #include <Standard_Type.hxx>
50 #include <StdSelect_ViewerSelector3d.hxx>
51 #include <TCollection_AsciiString.hxx>
52 #include <TCollection_ExtendedString.hxx>
53 #include <TColStd_ListIteratorOfListOfInteger.hxx>
54 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
55 #include <TopLoc_Location.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <UnitsAPI.hxx>
58 #include <V3d_View.hxx>
59 #include <V3d_Viewer.hxx>
61 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
65 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
66 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
68 //! Initialize default highlighting attributes.
69 static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
71 theDrawer->SetMethod (Aspect_TOHM_COLOR);
72 theDrawer->SetDisplayMode (0);
74 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
75 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
76 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
77 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
78 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
79 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
80 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
81 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
82 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
83 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
84 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
85 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
87 theDrawer->WireAspect()->SetWidth (2.0);
88 theDrawer->LineAspect()->SetWidth (2.0);
89 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
90 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
91 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
92 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
93 theDrawer->PointAspect()->SetScale (2.0);
95 // the triangulation should be computed using main presentation attributes,
96 // and should not be overridden by highlighting
97 theDrawer->SetAutoTriangulation (Standard_False);
101 //=======================================================================
102 //function : AIS_InteractiveContext
104 //=======================================================================
106 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
107 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
108 myMainVwr(MainViewer),
109 myMainSel(new StdSelect_ViewerSelector3d()),
110 myWasLastMain(Standard_False),
111 myToHilightSelected(Standard_True),
112 mySelection(new AIS_Selection()),
113 myFilters(new SelectMgr_OrFilter()),
114 myDefaultDrawer(new Prs3d_Drawer()),
117 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
118 myAutoHilight(Standard_True),
119 myIsAutoActivateSelMode(Standard_True)
121 mgrSelector = new SelectMgr_SelectionManager (myMainSel);
123 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
124 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
125 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
126 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
127 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
128 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
130 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
131 myDefaultDrawer->SetDisplayMode(0);
133 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
134 aStyle->Link (myDefaultDrawer);
135 initDefaultHilightAttributes (aStyle);
136 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
137 aStyle->SetColor (Quantity_NOC_CYAN1);
140 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
141 aStyle->Link (myDefaultDrawer);
142 initDefaultHilightAttributes (aStyle);
143 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
144 aStyle->SetColor (Quantity_NOC_CYAN1);
147 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
148 aStyle->Link (myDefaultDrawer);
149 initDefaultHilightAttributes (aStyle);
150 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
151 aStyle->SetColor (Quantity_NOC_GRAY80);
154 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
155 aStyle->Link (myDefaultDrawer);
156 initDefaultHilightAttributes (aStyle);
157 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
158 aStyle->SetColor (Quantity_NOC_GRAY80);
161 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
162 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
163 aStyle->SetMethod(Aspect_TOHM_COLOR);
164 aStyle->SetColor (Quantity_NOC_GRAY40);
170 //=======================================================================
171 //function : ~AIS_InteractiveContext
173 //=======================================================================
174 AIS_InteractiveContext::~AIS_InteractiveContext()
176 // clear the current selection
177 mySelection->Clear();
178 mgrSelector.Nullify();
180 Handle(AIS_InteractiveContext) aNullContext;
181 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
183 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
184 anObj->SetContext (aNullContext);
185 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
187 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
192 //=======================================================================
193 //function : UpdateCurrentViewer
195 //=======================================================================
197 void AIS_InteractiveContext::UpdateCurrentViewer()
199 if (!myMainVwr.IsNull())
203 //=======================================================================
204 //function : DisplayedObjects
206 //=======================================================================
207 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
209 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
211 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
213 theListOfIO.Append (anObjIter.Key());
218 //=======================================================================
219 //function : DisplayedObjects
221 //=======================================================================
222 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
223 const Standard_Integer theSign,
224 AIS_ListOfInteractive& theListOfIO) const
226 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
229 //=======================================================================
230 //function : ErasedObjects
232 //=======================================================================
233 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
235 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
238 //=======================================================================
239 //function : ErasedObjects
241 //=======================================================================
242 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
243 const Standard_Integer theSign,
244 AIS_ListOfInteractive& theListOfIO) const
246 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
249 //=======================================================================
250 //function : ObjectsByDisplayStatus
252 //=======================================================================
253 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
254 AIS_ListOfInteractive& theListOfIO) const
256 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
258 if (anObjIter.Value()->GraphicStatus() == theStatus)
260 theListOfIO.Append (anObjIter.Key());
265 //=======================================================================
266 //function : ObjectsByDisplayStatus
268 //=======================================================================
269 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
270 const Standard_Integer theSign,
271 const AIS_DisplayStatus theStatus,
272 AIS_ListOfInteractive& theListOfIO) const
274 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
276 if (theStatus != AIS_DS_None
277 && anObjIter.Value()->GraphicStatus() != theStatus)
281 else if (anObjIter.Key()->Type() != theKind)
287 || anObjIter.Key()->Signature() == theSign)
289 theListOfIO.Append (anObjIter.Key());
294 //=======================================================================
295 //function : ObjectsInside
297 //=======================================================================
298 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
299 const AIS_KindOfInteractive theKind,
300 const Standard_Integer theSign) const
302 if (theKind == AIS_KOI_None
305 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
307 theListOfIO.Append (anObjIter.Key());
312 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
314 if (anObjIter.Key()->Type() != theKind)
320 || anObjIter.Key()->Signature() == theSign)
322 theListOfIO.Append (anObjIter.Key());
327 //=======================================================================
328 //function : ObjectsForView
330 //=======================================================================
331 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
332 const Handle(V3d_View)& theView,
333 const Standard_Boolean theIsVisibleInView,
334 const AIS_DisplayStatus theStatus) const
336 Handle(Graphic3d_CView) aViewImpl = theView->View();
337 const Standard_Integer aViewId = aViewImpl->Identification();
338 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
340 if (theStatus != AIS_DS_None
341 && anObjIter.Value()->GraphicStatus() != theStatus)
343 theListOfIO.Append (anObjIter.Key());
347 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
348 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
349 if (isVisible == theIsVisibleInView)
351 theListOfIO.Append (anObjIter.Key());
356 //=======================================================================
359 //=======================================================================
360 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
361 const Standard_Boolean theToUpdateViewer)
363 if (theIObj.IsNull())
368 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
369 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
370 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
373 //=======================================================================
374 //function : SetViewAffinity
376 //=======================================================================
377 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
378 const Handle(V3d_View)& theView,
379 const Standard_Boolean theIsVisible)
382 || !myObjects.IsBound (theIObj))
387 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
388 Handle(Graphic3d_CView) aViewImpl = theView->View();
389 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
392 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
396 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
400 //=======================================================================
403 //=======================================================================
404 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
405 const Standard_Integer theDispMode,
406 const Standard_Integer theSelectionMode,
407 const Standard_Boolean theToUpdateViewer,
408 const AIS_DisplayStatus theDispStatus)
410 if (theIObj.IsNull())
415 if (theDispStatus == AIS_DS_Erased)
417 Erase (theIObj, theToUpdateViewer);
418 Load (theIObj, theSelectionMode);
419 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
421 (*aStatusPtr)->SetDisplayMode (theDispMode);
426 setContextToObject (theIObj);
427 if (!myObjects.IsBound (theIObj))
429 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
430 myObjects.Bind (theIObj, aStatus);
431 myMainVwr->StructureManager()->RegisterObject (theIObj);
432 myMainPM->Display(theIObj, theDispMode);
433 if (theSelectionMode != -1)
435 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
436 if (!mgrSelector->Contains (anObj))
438 mgrSelector->Load (theIObj);
440 mgrSelector->Activate (theIObj, theSelectionMode);
445 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
447 // Mark the presentation modes hidden of interactive object different from aDispMode.
448 // Then make sure aDispMode is displayed and maybe highlighted.
449 // Finally, activate selection mode <SelMode> if not yet activated.
450 const Standard_Integer anOldMode = aStatus->DisplayMode();
451 if (anOldMode != theDispMode)
453 if(myMainPM->IsHighlighted (theIObj, anOldMode))
455 unhighlightGlobal (theIObj);
457 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
460 aStatus->SetDisplayMode (theDispMode);
462 myMainPM->Display (theIObj, theDispMode);
463 aStatus->SetGraphicStatus (AIS_DS_Displayed);
464 if (aStatus->IsHilighted())
466 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
468 if (theSelectionMode != -1)
470 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
471 if (!mgrSelector->Contains (anObj))
473 mgrSelector->Load (theIObj);
475 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
477 if (!aStatus->IsSModeIn (theSelectionMode))
478 aStatus->AddSelectionMode (theSelectionMode);
479 mgrSelector->Activate (theIObj, theSelectionMode);
484 if (theToUpdateViewer)
490 //=======================================================================
493 //=======================================================================
494 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
495 const Standard_Integer theSelMode)
497 if (theIObj.IsNull())
502 setContextToObject (theIObj);
503 if (!myObjects.IsBound (theIObj))
505 Standard_Integer aDispMode, aHiMod, aSelModeDef;
506 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
507 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
508 myObjects.Bind (theIObj, aStatus);
509 myMainVwr->StructureManager()->RegisterObject (theIObj);
512 // Register theIObj in the selection manager to prepare further activation of selection
513 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
514 if (!mgrSelector->Contains (anObj))
516 mgrSelector->Load (theIObj);
520 //=======================================================================
523 //=======================================================================
524 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
525 const Standard_Boolean theToUpdateViewer)
527 if (theIObj.IsNull())
532 if (!theIObj->IsAutoHilight())
534 theIObj->ClearSelected();
537 EraseGlobal (theIObj, Standard_False);
538 if (theToUpdateViewer)
544 //=======================================================================
545 //function : EraseAll
547 //=======================================================================
548 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
550 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
552 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
554 Erase (anObjIter.Key(), Standard_False);
558 if (theToUpdateViewer)
564 //=======================================================================
565 //function : DisplayAll
567 //=======================================================================
568 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
570 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
572 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
573 if (aStatus == AIS_DS_Erased)
575 Display (anObjIter.Key(), Standard_False);
579 if (theToUpdateViewer)
585 //=======================================================================
586 //function : DisplaySelected
588 //=======================================================================
589 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
591 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
593 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
594 Display (anObj, Standard_False);
597 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
603 //=======================================================================
604 //function : EraseSelected
606 //=======================================================================
607 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
609 Standard_Boolean isFound = Standard_False;
610 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
612 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
613 Erase (anObj, Standard_False);
614 isFound = Standard_True;
617 if (isFound && theToUpdateViewer)
623 //=======================================================================
624 //function : DisplayStatus
626 //=======================================================================
627 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
629 if (theIObj.IsNull())
633 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
634 return aStatus != NULL ? (*aStatus)->GraphicStatus() : AIS_DS_None;
637 //=======================================================================
640 //=======================================================================
641 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
642 const Standard_Boolean theToUpdateViewer)
644 if (theIObj.IsNull())
649 if (theIObj->HasInteractiveContext())
651 if (theIObj->myCTXPtr != this)
653 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
655 theIObj->SetContext (Handle(AIS_InteractiveContext)());
657 ClearGlobal (theIObj, theToUpdateViewer);
660 //=======================================================================
661 //function : RemoveAll
663 //=======================================================================
664 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
666 AIS_ListOfInteractive aList;
667 ObjectsInside (aList);
668 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
670 Remove (aListIterator.Value(), Standard_False);
673 if (theToUpdateViewer)
679 //=======================================================================
680 //function : HilightWithColor
682 //=======================================================================
683 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
684 const Handle(Prs3d_Drawer)& theStyle,
685 const Standard_Boolean theIsToUpdate)
690 setContextToObject (theObj);
691 if (!myObjects.IsBound (theObj))
694 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
695 aStatus->SetHilightStatus (Standard_True);
697 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
699 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
700 aStatus->SetHilightStyle (theStyle);
707 //=======================================================================
708 //function : Unhilight
710 //=======================================================================
711 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
713 if(anIObj.IsNull()) return;
714 if(!myObjects.IsBound(anIObj)) return;
716 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
717 aStatus->SetHilightStatus (Standard_False);
718 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
720 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
722 unhighlightGlobal (anIObj);
725 if(updateviewer) myMainVwr->Update();
728 //=======================================================================
729 //function : IsHilighted
730 //purpose : Returns true if the objects global status is set to highlighted.
731 //=======================================================================
732 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
734 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
735 return aStatus != NULL
736 && (*aStatus)->IsHilighted();
739 //=======================================================================
740 //function : IsHilighted
741 //purpose : Returns true if the owner is highlighted with selection style.
742 //=======================================================================
743 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
745 if (theOwner.IsNull() || !theOwner->HasSelectable())
746 return Standard_False;
748 const Handle(AIS_InteractiveObject) anObj =
749 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
751 if (anObj->GlobalSelOwner() == theOwner)
753 if (!myObjects.IsBound (anObj))
754 return Standard_False;
756 return myObjects (anObj)->IsHilighted();
759 return theOwner->IsSelected();
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->Update (theAllModes);
956 if (!theToUpdateViewer)
961 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
963 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
968 //=======================================================================
969 //function : RecomputeSelectionOnly
971 //=======================================================================
972 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
979 mgrSelector->RecomputeSelection (theIO);
981 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
983 || (*aStatus)->GraphicStatus() != AIS_DS_Displayed)
988 TColStd_ListOfInteger aModes;
989 ActivatedModes (theIO, aModes);
990 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
991 for (; aModesIter.More(); aModesIter.Next())
993 mgrSelector->Activate (theIO, aModesIter.Value());
997 //=======================================================================
1000 //=======================================================================
1001 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1002 const Standard_Boolean theUpdateViewer)
1004 if (theIObj.IsNull())
1009 TColStd_ListOfInteger aPrsModes;
1010 theIObj->ToBeUpdated (aPrsModes);
1011 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1013 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1016 mgrSelector->Update(theIObj);
1018 if (theUpdateViewer)
1020 const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1022 && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
1024 myMainVwr->Update();
1029 //=======================================================================
1030 //function : SetLocation
1032 //=======================================================================
1033 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1034 const TopLoc_Location& theLoc)
1036 if (theIObj.IsNull())
1041 if (theIObj->HasTransformation()
1042 && theLoc.IsIdentity())
1044 theIObj->ResetTransformation();
1045 mgrSelector->Update (theIObj, Standard_False);
1048 else if (theLoc.IsIdentity())
1053 // first reset the previous location to properly clean everything...
1054 if (theIObj->HasTransformation())
1056 theIObj->ResetTransformation();
1059 theIObj->SetLocalTransformation (theLoc.Transformation());
1061 mgrSelector->Update (theIObj, Standard_False);
1063 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1064 // to its highlight structure immediately
1065 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1067 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1068 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1074 //=======================================================================
1075 //function : ResetLocation
1077 //=======================================================================
1078 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1080 if (theIObj.IsNull())
1085 theIObj->ResetTransformation();
1086 mgrSelector->Update (theIObj, Standard_False);
1089 //=======================================================================
1090 //function : HasLocation
1092 //=======================================================================
1093 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1095 return !theIObj.IsNull()
1096 && theIObj->HasTransformation();
1099 //=======================================================================
1100 //function : Location
1102 //=======================================================================
1103 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1105 return theIObj->Transformation();
1108 //=======================================================================
1109 //function : SetDeviationCoefficient
1111 //=======================================================================
1112 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1114 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1117 //=======================================================================
1118 //function : SetDeviationAngle
1120 //=======================================================================
1121 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1123 myDefaultDrawer->SetDeviationAngle (theAngle);
1126 //=======================================================================
1127 //function : DeviationAngle
1128 //purpose : Gets deviationAngle
1129 //=======================================================================
1130 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1132 return myDefaultDrawer->DeviationAngle();
1135 //=======================================================================
1136 //function : DeviationCoefficient
1138 //=======================================================================
1139 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1141 return myDefaultDrawer->DeviationCoefficient();
1144 //=======================================================================
1145 //function : SetHLRDeviationCoefficient
1147 //=======================================================================
1148 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1150 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1153 //=======================================================================
1154 //function : HLRDeviationCoefficient
1156 //=======================================================================
1157 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1159 return myDefaultDrawer->HLRDeviationCoefficient();
1162 //=======================================================================
1163 //function : SetHLRAngle
1165 //=======================================================================
1166 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1168 myDefaultDrawer->SetHLRAngle (theAngle);
1171 //=======================================================================
1172 //function : SetHLRAngleAndDeviation
1173 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1174 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1175 // of myDefaultDrawer
1176 //=======================================================================
1177 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1179 Standard_Real anOutAngl, anOutDefl;
1180 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1182 myDefaultDrawer->SetHLRAngle (anOutAngl);
1183 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1186 //=======================================================================
1187 //function : HLRAngle
1189 //=======================================================================
1190 Standard_Real AIS_InteractiveContext::HLRAngle() const
1192 return myDefaultDrawer->HLRAngle();
1195 //=======================================================================
1196 //function : SetDisplayMode
1198 //=======================================================================
1199 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1200 const Standard_Boolean theToUpdateViewer)
1202 if (theMode == myDefaultDrawer->DisplayMode())
1207 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1209 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1210 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1211 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1212 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1215 || anObj->HasDisplayMode()
1216 || !anObj->AcceptDisplayMode (theMode))
1221 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1222 aStatus->SetDisplayMode (theMode);
1224 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1226 myMainPM->Display (anObj, theMode);
1227 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1229 myMainPM->BeginImmediateDraw();
1230 unhighlightGlobal (anObj);
1231 myMainPM->EndImmediateDraw (myMainVwr);
1233 if (aStatus->IsSubIntensityOn())
1235 highlightWithSubintensity (anObj, theMode);
1237 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1241 myDefaultDrawer->SetDisplayMode (theMode);
1242 if (theToUpdateViewer)
1244 myMainVwr->Update();
1248 //=======================================================================
1249 //function : SetDisplayMode
1251 //=======================================================================
1252 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1253 const Standard_Integer theMode,
1254 const Standard_Boolean theToUpdateViewer)
1256 setContextToObject (theIObj);
1257 if (!myObjects.IsBound (theIObj))
1259 theIObj->SetDisplayMode (theMode);
1262 else if (!theIObj->AcceptDisplayMode (theMode))
1267 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1268 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1270 aStatus->SetDisplayMode (theMode);
1271 theIObj->SetDisplayMode (theMode);
1275 // erase presentations for all display modes different from <aMode>
1276 const Standard_Integer anOldMode = aStatus->DisplayMode();
1277 if (anOldMode != theMode)
1279 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1281 unhighlightGlobal (theIObj);
1283 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1286 aStatus->SetDisplayMode (theMode);
1288 myMainPM->Display (theIObj, theMode);
1289 if (aStatus->IsHilighted())
1291 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1293 if (aStatus->IsSubIntensityOn())
1295 highlightWithSubintensity (theIObj, theMode);
1298 if (theToUpdateViewer)
1300 myMainVwr->Update();
1302 theIObj->SetDisplayMode (theMode);
1305 //=======================================================================
1306 //function : UnsetDisplayMode
1308 //=======================================================================
1309 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1310 const Standard_Boolean theToUpdateViewer)
1312 if (theIObj.IsNull()
1313 || !theIObj->HasDisplayMode())
1318 if (!myObjects.IsBound (theIObj))
1320 theIObj->UnsetDisplayMode();
1324 const Standard_Integer anOldMode = theIObj->DisplayMode();
1325 if (myDefaultDrawer->DisplayMode() == anOldMode)
1330 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1331 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1333 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1335 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1337 unhighlightGlobal (theIObj);
1339 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1340 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1341 if (aStatus->IsHilighted())
1343 highlightSelected (theIObj->GlobalSelOwner());
1345 if (aStatus->IsSubIntensityOn())
1347 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1350 if (theToUpdateViewer)
1352 myMainVwr->Update();
1356 theIObj->UnsetDisplayMode();
1359 //=======================================================================
1360 //function : SetCurrentFacingModel
1362 //=======================================================================
1363 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1364 const Aspect_TypeOfFacingModel theModel)
1366 if (!theIObj.IsNull())
1368 theIObj->SetCurrentFacingModel (theModel);
1372 //=======================================================================
1373 //function : redisplayPrsRecModes
1375 //=======================================================================
1376 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1377 const Standard_Boolean theToUpdateViewer)
1379 if (theIObj->RecomputeEveryPrs())
1381 theIObj->Update (Standard_True);
1382 theIObj->UpdateSelection();
1386 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1388 theIObj->Update (aModes.Value(), Standard_False);
1390 theIObj->UpdateSelection();
1391 theIObj->SetRecomputeOk();
1394 if (theToUpdateViewer)
1396 UpdateCurrentViewer();
1400 //=======================================================================
1401 //function : redisplayPrsModes
1403 //=======================================================================
1404 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1405 const Standard_Boolean theToUpdateViewer)
1407 if (theIObj->RecomputeEveryPrs())
1409 theIObj->Update (Standard_True);
1410 theIObj->UpdateSelection();
1414 TColStd_ListOfInteger aModes;
1415 theIObj->ToBeUpdated (aModes);
1416 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1418 theIObj->Update (aModeIter.Value(), Standard_False);
1420 theIObj->SetRecomputeOk();
1423 if (theToUpdateViewer)
1425 UpdateCurrentViewer();
1429 //=======================================================================
1430 //function : SetColor
1432 //=======================================================================
1433 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1434 const Quantity_Color& theColor,
1435 const Standard_Boolean theToUpdateViewer)
1437 if (theIObj.IsNull())
1442 setContextToObject (theIObj);
1443 theIObj->SetColor (theColor);
1444 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1447 //=======================================================================
1448 //function : SetIsoOnTriangulation
1450 //=======================================================================
1451 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1452 const Handle(AIS_InteractiveObject)& theObject)
1454 if (theObject.IsNull())
1459 theObject->SetIsoOnTriangulation (theIsEnabled);
1462 //=======================================================================
1463 //function : SetDeviationCoefficient
1465 //=======================================================================
1466 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1467 const Standard_Real theCoefficient,
1468 const Standard_Boolean theToUpdateViewer)
1470 if (theIObj.IsNull())
1475 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1476 setContextToObject (theIObj);
1477 if (theIObj->Type() != AIS_KOI_Object
1478 && theIObj->Type() != AIS_KOI_Shape)
1482 else if (theIObj->Signature() != 0)
1487 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1488 aShape->SetOwnDeviationCoefficient (theCoefficient);
1489 redisplayPrsModes (theIObj, theToUpdateViewer);
1492 //=======================================================================
1493 //function : SetHLRDeviationCoefficient
1495 //=======================================================================
1496 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1497 const Standard_Real theCoefficient,
1498 const Standard_Boolean theToUpdateViewer)
1500 if (theIObj.IsNull())
1505 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1506 setContextToObject (theIObj);
1507 if (theIObj->Type() != AIS_KOI_Object
1508 && theIObj->Type() != AIS_KOI_Shape)
1512 else if (theIObj->Signature() != 0)
1517 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1518 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1519 redisplayPrsModes (theIObj, theToUpdateViewer);
1522 //=======================================================================
1523 //function : SetDeviationAngle
1525 //=======================================================================
1526 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1527 const Standard_Real theAngle,
1528 const Standard_Boolean theToUpdateViewer)
1530 if (theIObj.IsNull())
1535 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1536 setContextToObject (theIObj);
1537 if (theIObj->Type() != AIS_KOI_Shape)
1541 else if (theIObj->Signature() != 0)
1546 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1547 aShape->SetOwnDeviationAngle (theAngle);
1548 redisplayPrsModes (theIObj, theToUpdateViewer);
1551 //=======================================================================
1552 //function : SetAngleAndDeviation
1554 //=======================================================================
1555 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1556 const Standard_Real theAngle,
1557 const Standard_Boolean theToUpdateViewer)
1559 if (theIObj.IsNull())
1564 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1565 setContextToObject (theIObj);
1566 if (theIObj->Type() != AIS_KOI_Shape)
1570 if (theIObj->Signature() != 0)
1575 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1576 aShape->SetAngleAndDeviation (theAngle);
1578 if (theIObj->RecomputeEveryPrs())
1580 theIObj->Update (Standard_True);
1581 theIObj->UpdateSelection();
1585 Update (theIObj, theToUpdateViewer);
1589 //=======================================================================
1590 //function : SetHLRAngleAndDeviation
1592 //=======================================================================
1593 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1594 const Standard_Real theAngle,
1595 const Standard_Boolean theToUpdateViewer)
1597 if (theIObj.IsNull())
1602 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1603 setContextToObject (theIObj);
1604 if (theIObj->Type() != AIS_KOI_Shape)
1608 if (theIObj->Signature() != 0)
1612 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1613 aShape->SetHLRAngleAndDeviation (theAngle);
1614 redisplayPrsModes (theIObj, theToUpdateViewer);
1617 //=======================================================================
1618 //function : SetHLRDeviationAngle
1620 //=======================================================================
1621 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1622 const Standard_Real theAngle,
1623 const Standard_Boolean theToUpdateViewer)
1625 if (theIObj.IsNull())
1630 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1631 setContextToObject (theIObj);
1632 if (theIObj->Type() != AIS_KOI_Shape)
1636 if (theIObj->Signature() != 0)
1640 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1641 aShape->SetOwnHLRDeviationAngle (theAngle);
1642 redisplayPrsModes (theIObj, theToUpdateViewer);
1645 //=======================================================================
1646 //function : UnsetColor
1648 //=======================================================================
1649 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1650 const Standard_Boolean theToUpdateViewer)
1652 if (theIObj.IsNull())
1657 theIObj->UnsetColor();
1658 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1661 //=======================================================================
1662 //function : HasColor
1664 //=======================================================================
1665 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1667 return theIObj->HasColor();
1670 //=======================================================================
1673 //=======================================================================
1674 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1675 Quantity_Color& theColor) const
1677 theIObj->Color (theColor);
1680 //=======================================================================
1683 //=======================================================================
1684 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1686 return theIObj->Width();
1689 //=======================================================================
1690 //function : SetWidth
1692 //=======================================================================
1693 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1694 const Standard_Real theWidth,
1695 const Standard_Boolean theToUpdateViewer)
1697 if (theIObj.IsNull())
1702 setContextToObject (theIObj);
1703 theIObj->SetWidth (theWidth);
1704 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1705 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
1707 if (myLastinMain->IsAutoHilight())
1709 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1710 myLastinMain->HilightWithColor (myMainPM,
1711 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
1716 theIObj->HilightOwnerWithColor (myMainPM,
1717 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
1723 //=======================================================================
1724 //function : UnsetWidth
1726 //=======================================================================
1727 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1728 const Standard_Boolean theToUpdateViewer)
1730 if (theIObj.IsNull())
1735 theIObj->UnsetWidth();
1736 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1739 //=======================================================================
1740 //function : SetMaterial
1742 //=======================================================================
1743 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1744 const Graphic3d_MaterialAspect& theMaterial,
1745 const Standard_Boolean theToUpdateViewer)
1747 if (theIObj.IsNull())
1752 setContextToObject (theIObj);
1753 theIObj->SetMaterial (theMaterial);
1754 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1757 //=======================================================================
1758 //function : UnsetMaterial
1760 //=======================================================================
1761 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1762 const Standard_Boolean theToUpdateViewer)
1764 if (theIObj.IsNull())
1768 theIObj->UnsetMaterial();
1769 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1772 //=======================================================================
1773 //function : SetTransparency
1775 //=======================================================================
1776 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1777 const Standard_Real theValue,
1778 const Standard_Boolean theToUpdateViewer)
1780 if (theIObj.IsNull())
1785 setContextToObject (theIObj);
1786 if (!theIObj->IsTransparent()
1787 && theValue <= 0.005)
1792 if (theValue <= 0.005)
1794 UnsetTransparency (theIObj, theToUpdateViewer);
1798 theIObj->SetTransparency (theValue);
1799 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1802 //=======================================================================
1803 //function : UnsetTransparency
1805 //=======================================================================
1806 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1807 const Standard_Boolean theToUpdateViewer)
1809 if (theIObj.IsNull())
1814 theIObj->UnsetTransparency();
1815 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1818 //=======================================================================
1819 //function : SetSelectedAspect
1821 //=======================================================================
1822 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1823 const Standard_Boolean theToUpdateViewer)
1825 Standard_Boolean isFound = Standard_False;
1826 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1828 isFound = Standard_True;
1829 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1830 anObj->SetAspect (theAspect);
1833 if (isFound && theToUpdateViewer)
1835 myMainVwr->Update();
1839 //=======================================================================
1840 //function : SetLocalAttributes
1842 //=======================================================================
1843 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1844 const Handle(Prs3d_Drawer)& theDrawer,
1845 const Standard_Boolean theToUpdateViewer)
1847 if (theIObj.IsNull())
1852 setContextToObject (theIObj);
1853 theIObj->SetAttributes (theDrawer);
1854 Update (theIObj, theToUpdateViewer);
1857 //=======================================================================
1858 //function : UnsetLocalAttributes
1860 //=======================================================================
1861 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1862 const Standard_Boolean theToUpdateViewer)
1864 if (theIObj.IsNull())
1869 setContextToObject (theIObj);
1870 theIObj->UnsetAttributes();
1871 Update (theIObj, theToUpdateViewer);
1874 //=======================================================================
1877 //=======================================================================
1878 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1879 TCollection_ExtendedString& theStatus) const
1882 if (theIObj.IsNull()
1883 || !myObjects.IsBound (theIObj))
1888 theStatus += "\t ____________________________________________";
1889 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1890 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1891 switch (aStatus->GraphicStatus())
1893 case AIS_DS_Displayed:
1895 theStatus += "\t| -->Displayed\n";
1900 theStatus += "\t| -->Erased\n";
1907 theStatus += "\t| Active Display Modes in the MainViewer :\n";
1908 theStatus += "\t|\t Mode ";
1909 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1912 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1914 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1915 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1917 theStatus += "\t\t Mode ";
1918 theStatus += TCollection_AsciiString (aSelModeIter.Value());
1921 theStatus += "\t ____________________________________________";
1924 //=======================================================================
1925 //function : GetDefModes
1927 //=======================================================================
1928 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1929 Standard_Integer& theDispMode,
1930 Standard_Integer& theHiMode,
1931 Standard_Integer& theSelMode) const
1933 if (theIObj.IsNull())
1938 theDispMode = theIObj->HasDisplayMode()
1939 ? theIObj->DisplayMode()
1940 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1941 ? myDefaultDrawer->DisplayMode()
1943 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
1944 theSelMode = theIObj->GlobalSelectionMode();
1947 //=======================================================================
1948 //function : EraseGlobal
1950 //=======================================================================
1951 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1952 const Standard_Boolean theToUpdateviewer)
1954 if (theIObj.IsNull()
1955 || !myObjects.IsBound (theIObj))
1960 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1962 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1963 if (aStatus->GraphicStatus() == AIS_DS_Erased)
1968 if (aStatus->IsHilighted())
1970 Standard_DISABLE_DEPRECATION_WARNINGS
1971 if (IsCurrent (theIObj))
1973 AddOrRemoveCurrentObject (theIObj, Standard_False);
1975 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
1977 unhighlightGlobal (theIObj);
1979 Standard_ENABLE_DEPRECATION_WARNINGS
1982 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1984 if (aStatus->IsHilighted()
1985 && theIObj->HasHilightMode())
1987 unhighlightGlobal (theIObj);
1990 if (!myLastPicked.IsNull()
1991 && myLastPicked->IsSameSelectable (theIObj))
1993 clearDynamicHighlight();
1996 // make sure highlighting presentations are properly erased
1997 theIObj->ErasePresentations (false);
1999 if (IsSelected (theIObj)
2000 && aStatus->DisplayMode() != aDispMode)
2002 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2005 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2007 mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
2009 aStatus->ClearSelectionModes();
2010 aStatus->SetGraphicStatus (AIS_DS_Erased);
2012 if (theToUpdateviewer)
2014 myMainVwr->Update();
2018 //=======================================================================
2019 //function : unhighlightOwners
2021 //=======================================================================
2022 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2024 SelectMgr_SequenceOfOwner aSeq;
2025 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2027 if (aSelIter.Value()->IsSameSelectable (theObject))
2029 aSeq.Append (aSelIter.Value());
2032 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2034 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2038 //=======================================================================
2039 //function : ClearGlobal
2041 //=======================================================================
2042 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2043 const Standard_Boolean theToUpdateviewer)
2045 if (theIObj.IsNull()
2046 || !myObjects.IsBound (theIObj))
2048 // for cases when reference shape of connected interactives was not displayed
2049 // but its selection primitives were calculated
2050 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2051 mgrSelector->Remove (anObj);
2055 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2056 unhighlightOwners (theIObj);
2058 myMainPM->Erase (theIObj, -1);
2059 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2061 // Object removes from Detected sequence
2062 Standard_DISABLE_DEPRECATION_WARNINGS
2063 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2065 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2066 Handle(AIS_InteractiveObject) anObj;
2067 if (!aPicked.IsNull())
2069 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2073 && anObj == theIObj)
2075 myDetectedSeq.Remove (aDetIter);
2076 if (myCurDetected == aDetIter)
2078 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2080 if (myCurHighlighted == aDetIter)
2082 myCurHighlighted = 0;
2090 Standard_ENABLE_DEPRECATION_WARNINGS
2092 // remove IO from the selection manager to avoid memory leaks
2093 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2094 mgrSelector->Remove (anObj);
2096 myObjects.UnBind (theIObj);
2097 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2099 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2101 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2104 if (!myLastinMain.IsNull())
2106 if (myLastinMain->IsSameSelectable (theIObj)
2107 || myLastPicked->IsSameSelectable(theIObj))
2109 clearDynamicHighlight();
2110 myLastinMain.Nullify();
2111 myLastPicked.Nullify();
2115 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2117 myMainVwr->Update();
2121 //=======================================================================
2122 //function : ClearGlobalPrs
2124 //=======================================================================
2125 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2126 const Standard_Integer theMode,
2127 const Standard_Boolean theToUpdateViewer)
2129 if (theIObj.IsNull()
2130 || !myObjects.IsBound (theIObj))
2135 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2136 if (aStatus->DisplayMode() == theMode)
2138 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2139 if (aDispMode == theMode
2140 && myMainPM->IsHighlighted (theIObj, theMode))
2142 unhighlightGlobal (theIObj);
2145 myMainPM->Erase (theIObj, theMode);
2148 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2149 && theToUpdateViewer)
2151 myMainVwr->Update();
2155 //=======================================================================
2156 //function : ClearDetected
2158 //=======================================================================
2159 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2162 myCurHighlighted = 0;
2163 myDetectedSeq.Clear();
2164 myLastPicked = myLastinMain;
2165 myWasLastMain = Standard_True;
2166 Standard_Boolean toUpdate = Standard_False;
2167 if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2169 toUpdate = Standard_True;
2170 clearDynamicHighlight();
2172 myLastinMain.Nullify();
2173 myLastPicked.Nullify();
2174 myMainSel->ClearPicked();
2175 if (toUpdate && theToRedrawImmediate)
2177 myMainVwr->RedrawImmediate();
2182 //=======================================================================
2183 //function : DrawHiddenLine
2185 //=======================================================================
2186 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2188 return myDefaultDrawer->DrawHiddenLine();
2191 //=======================================================================
2192 //function : EnableDrawHiddenLine
2194 //=======================================================================
2195 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2197 myDefaultDrawer->EnableDrawHiddenLine();
2200 //=======================================================================
2201 //function : DisableDrawHiddenLine
2203 //=======================================================================
2204 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2206 myDefaultDrawer->DisableDrawHiddenLine();
2209 //=======================================================================
2210 //function : HiddenLineAspect
2212 //=======================================================================
2213 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2215 return myDefaultDrawer->HiddenLineAspect();
2218 //=======================================================================
2219 //function : SetHiddenLineAspect
2221 //=======================================================================
2222 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2224 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2227 //=======================================================================
2228 //function : SetIsoNumber
2230 //=======================================================================
2231 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2232 const AIS_TypeOfIso theType)
2237 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2240 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2243 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2244 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2249 //=======================================================================
2250 //function : IsoNumber
2252 //=======================================================================
2253 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2257 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2258 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2259 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2260 ? myDefaultDrawer->UIsoAspect()->Number()
2266 //=======================================================================
2267 //function : IsoOnPlane
2269 //=======================================================================
2270 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2272 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2275 //=======================================================================
2276 //function : IsoOnPlane
2278 //=======================================================================
2279 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2281 return myDefaultDrawer->IsoOnPlane();
2284 //=======================================================================
2285 //function : IsoOnTriangulation
2287 //=======================================================================
2288 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2290 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2293 //=======================================================================
2294 //function : IsoOnTriangulation
2296 //=======================================================================
2297 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2299 return myDefaultDrawer->IsoOnTriangulation();
2302 //=======================================================================
2303 //function : SetPixelTolerance
2305 //=======================================================================
2306 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2308 myMainSel->SetPixelTolerance (thePrecision);
2311 //=======================================================================
2312 //function : PixelTolerance
2314 //=======================================================================
2315 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2317 return myMainSel->PixelTolerance();
2320 //=======================================================================
2321 //function : SetSelectionSensitivity
2322 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2323 //=======================================================================
2324 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2325 const Standard_Integer theMode,
2326 const Standard_Integer theNewSensitivity)
2328 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2331 //=======================================================================
2332 //function : InitAttributes
2334 //=======================================================================
2335 void AIS_InteractiveContext::InitAttributes()
2337 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2338 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2340 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2341 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2342 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2343 aLineAspect->SetWidth (1.0);
2344 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2346 // tolerance to 2 pixels...
2347 SetPixelTolerance (2);
2349 // Customizing the drawer for trihedrons and planes...
2350 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2351 const Standard_Real aLength = 100.0;
2352 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2353 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2354 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2355 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2356 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2358 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2359 const Standard_Real aPlaneLength = 200.0;
2360 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2361 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2364 //=======================================================================
2365 //function : TrihedronSize
2367 //=======================================================================
2368 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2370 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2373 //=======================================================================
2374 //function : SetTrihedronSize
2376 //=======================================================================
2377 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2378 const Standard_Boolean /*updateviewer*/)
2380 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2381 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2382 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2385 //=======================================================================
2386 //function : SetPlaneSize
2388 //=======================================================================
2389 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2390 const Standard_Real theValY,
2391 const Standard_Boolean theToUpdateViewer)
2393 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2394 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2397 //=======================================================================
2398 //function : SetPlaneSize
2400 //=======================================================================
2401 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2402 const Standard_Boolean theToUpdateViewer)
2404 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2407 //=======================================================================
2408 //function : PlaneSize
2410 //=======================================================================
2411 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2412 Standard_Real& theY) const
2414 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2415 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2416 return (Abs (theX - theY) <= Precision::Confusion());
2419 //=======================================================================
2420 //function : SetZLayer
2422 //=======================================================================
2423 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2424 const Graphic3d_ZLayerId theLayerId)
2426 if (theIObj.IsNull())
2429 theIObj->SetZLayer (theLayerId);
2432 //=======================================================================
2433 //function : GetZLayer
2435 //=======================================================================
2436 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2438 return !theIObj.IsNull()
2440 : Graphic3d_ZLayerId_UNKNOWN;
2443 //=======================================================================
2444 //function : RebuildSelectionStructs
2445 //purpose : Rebuilds 1st level of BVH selection forcibly
2446 //=======================================================================
2447 void AIS_InteractiveContext::RebuildSelectionStructs()
2449 myMainSel->RebuildObjectsTree (Standard_True);
2452 //=======================================================================
2453 //function : Disconnect
2454 //purpose : Disconnects selectable object from an assembly and updates selection structures
2455 //=======================================================================
2456 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2457 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2459 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2461 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2462 theObj->Disconnect (theObjToDisconnect);
2463 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2464 mgrSelector->Remove (anObj);
2466 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2468 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2469 theObj->Disconnect();
2470 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2471 mgrSelector->Remove (anObj);
2477 //=======================================================================
2478 //function : FitSelected
2479 //purpose : Fits the view corresponding to the bounds of selected objects
2480 //=======================================================================
2481 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2483 FitSelected (theView, 0.01, Standard_True);
2486 //=======================================================================
2487 //function : FitSelected
2488 //purpose : Fits the view corresponding to the bounds of selected objects
2489 //=======================================================================
2490 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2491 const Standard_Real theMargin,
2492 const Standard_Boolean theToUpdate)
2494 Bnd_Box aBndSelected;
2495 AIS_MapOfObjectOwners anObjectOwnerMap;
2496 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2498 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2499 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2500 if (anObj->IsInfinite())
2505 if (anOwner == anObj->GlobalSelOwner())
2508 anObj->BoundingBox (aTmpBnd);
2509 aBndSelected.Add (aTmpBnd);
2513 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2514 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2516 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2517 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2520 anOwnerMap->Add (anOwner);
2524 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2526 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2527 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2528 aBndSelected.Add (aTmpBox);
2531 anObjectOwnerMap.Clear();
2533 if (aBndSelected.IsVoid())
2536 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2539 //=======================================================================
2540 //function : SetTransformPersistence
2542 //=======================================================================
2543 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2544 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2546 theObject->SetTransformPersistence (theTrsfPers);
2547 if (!myObjects.IsBound (theObject))
2552 mgrSelector->UpdateSelection (theObject);
2554 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2555 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2556 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2558 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2559 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);