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_DataMapIteratorOfDataMapOfILC.hxx>
20 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
21 #include <AIS_ConnectedInteractive.hxx>
22 #include <AIS_GlobalStatus.hxx>
23 #include <AIS_InteractiveObject.hxx>
24 #include <AIS_ListIteratorOfListOfInteractive.hxx>
25 #include <AIS_LocalContext.hxx>
26 #include <AIS_LocalStatus.hxx>
27 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
28 #include <AIS_MultipleConnectedInteractive.hxx>
29 #include <AIS_Shape.hxx>
30 #include <AIS_Trihedron.hxx>
31 #include <Geom_Axis2Placement.hxx>
32 #include <Graphic3d_AspectFillArea3d.hxx>
33 #include <HLRBRep.hxx>
34 #include <OSD_Environment.hxx>
35 #include <Precision.hxx>
36 #include <Prs3d_BasicAspect.hxx>
37 #include <Prs3d_DatumAspect.hxx>
38 #include <Prs3d_IsoAspect.hxx>
39 #include <Prs3d_LineAspect.hxx>
40 #include <Prs3d_PlaneAspect.hxx>
41 #include <Prs3d_PointAspect.hxx>
42 #include <Prs3d_ShadingAspect.hxx>
43 #include <PrsMgr_ModedPresentation.hxx>
44 #include <PrsMgr_PresentableObject.hxx>
45 #include <Quantity_Color.hxx>
46 #include <SelectMgr_EntityOwner.hxx>
47 #include <SelectMgr_Filter.hxx>
48 #include <SelectMgr_OrFilter.hxx>
49 #include <SelectMgr_SelectionManager.hxx>
50 #include <Standard_Atomic.hxx>
51 #include <Standard_Transient.hxx>
52 #include <Standard_Type.hxx>
53 #include <StdSelect_ViewerSelector3d.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <TCollection_ExtendedString.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
58 #include <TopLoc_Location.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <UnitsAPI.hxx>
61 #include <V3d_View.hxx>
62 #include <V3d_Viewer.hxx>
64 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
68 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
69 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
71 //! Initialize default highlighting attributes.
72 static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
74 theDrawer->SetMethod (Aspect_TOHM_COLOR);
75 theDrawer->SetDisplayMode (0);
77 theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
78 *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
79 theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
80 *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
81 theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
82 *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
83 theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
84 *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
85 theDrawer->SetFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
86 *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
87 theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
88 *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
90 theDrawer->WireAspect()->SetWidth (2.0);
91 theDrawer->LineAspect()->SetWidth (2.0);
92 theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
93 theDrawer->FreeBoundaryAspect() ->SetWidth (2.0);
94 theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
95 theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
96 theDrawer->PointAspect()->SetScale (2.0);
98 // the triangulation should be computed using main presentation attributes,
99 // and should not be overridden by highlighting
100 theDrawer->SetAutoTriangulation (Standard_False);
104 //=======================================================================
105 //function : AIS_InteractiveContext
107 //=======================================================================
109 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
110 mgrSelector(new SelectMgr_SelectionManager()),
111 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
112 myMainVwr(MainViewer),
113 myMainSel(new StdSelect_ViewerSelector3d()),
114 myWasLastMain(Standard_False),
115 myToHilightSelected(Standard_True),
116 mySelection(new AIS_Selection()),
117 myFilters(new SelectMgr_OrFilter()),
118 myDefaultDrawer(new Prs3d_Drawer()),
122 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
123 myIsAutoActivateSelMode(Standard_True)
125 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
126 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
127 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
128 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
129 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
130 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
132 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
133 myDefaultDrawer->SetDisplayMode(0);
135 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
136 aStyle->Link (myDefaultDrawer);
137 initDefaultHilightAttributes (aStyle);
138 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
139 aStyle->SetColor (Quantity_NOC_CYAN1);
142 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
143 aStyle->Link (myDefaultDrawer);
144 initDefaultHilightAttributes (aStyle);
145 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
146 aStyle->SetColor (Quantity_NOC_CYAN1);
149 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
150 aStyle->Link (myDefaultDrawer);
151 initDefaultHilightAttributes (aStyle);
152 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
153 aStyle->SetColor (Quantity_NOC_GRAY80);
156 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
157 aStyle->Link (myDefaultDrawer);
158 initDefaultHilightAttributes (aStyle);
159 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
160 aStyle->SetColor (Quantity_NOC_GRAY80);
163 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
164 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
165 aStyle->SetMethod(Aspect_TOHM_COLOR);
166 aStyle->SetColor (Quantity_NOC_GRAY40);
172 //=======================================================================
173 //function : ~AIS_InteractiveContext
175 //=======================================================================
176 AIS_InteractiveContext::~AIS_InteractiveContext()
178 // clear the current selection
179 mySelection->Clear();
181 // let's remove one reference explicitly. this operation's supposed to
182 // be performed when mgrSelector will be destroyed but anyway...
183 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
184 mgrSelector->Remove (aSelector);
186 Handle(AIS_InteractiveContext) aNullContext;
187 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
189 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
190 anObj->SetContext (aNullContext);
191 for (anObj->Init(); anObj->More(); anObj->Next())
193 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
198 //=======================================================================
199 //function : UpdateCurrentViewer
201 //=======================================================================
203 void AIS_InteractiveContext::UpdateCurrentViewer()
205 if (!myMainVwr.IsNull())
209 //=======================================================================
210 //function : DisplayedObjects
212 //=======================================================================
213 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
214 const Standard_Boolean theOnlyFromNeutral) const
216 if (!HasOpenedContext()
217 || theOnlyFromNeutral)
219 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
221 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
223 theListOfIO.Append (anObjIter.Key());
230 TColStd_MapOfTransient aDispMap;
231 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
233 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
235 aDispMap.Add (anObjIter.Key());
239 // parse all local contexts...
240 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
242 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
243 aLocCtx->DisplayedObjects (aDispMap);
246 Handle(AIS_InteractiveObject) anObj;
247 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
249 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
250 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
251 theListOfIO.Append (anObj);
255 //=======================================================================
256 //function : DisplayedObjects
258 //=======================================================================
259 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
260 const Standard_Integer theSign,
261 AIS_ListOfInteractive& theListOfIO,
262 const Standard_Boolean /*OnlyFromNeutral*/) const
264 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
267 //=======================================================================
268 //function : ErasedObjects
270 //=======================================================================
271 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
273 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
276 //=======================================================================
277 //function : ErasedObjects
279 //=======================================================================
280 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
281 const Standard_Integer theSign,
282 AIS_ListOfInteractive& theListOfIO) const
284 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
287 //=======================================================================
288 //function : ObjectsByDisplayStatus
290 //=======================================================================
291 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
292 AIS_ListOfInteractive& theListOfIO) const
294 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
296 if (anObjIter.Value()->GraphicStatus() == theStatus)
298 theListOfIO.Append (anObjIter.Key());
303 //=======================================================================
304 //function : ObjectsByDisplayStatus
306 //=======================================================================
307 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
308 const Standard_Integer theSign,
309 const AIS_DisplayStatus theStatus,
310 AIS_ListOfInteractive& theListOfIO) const
312 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
314 if (theStatus != AIS_DS_None
315 && anObjIter.Value()->GraphicStatus() != theStatus)
319 else if (anObjIter.Key()->Type() != theKind)
325 || anObjIter.Key()->Signature() == theSign)
327 theListOfIO.Append (anObjIter.Key());
332 //=======================================================================
333 //function : ObjectsInside
335 //=======================================================================
336 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
337 const AIS_KindOfInteractive theKind,
338 const Standard_Integer theSign) const
340 if (theKind == AIS_KOI_None
343 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
345 theListOfIO.Append (anObjIter.Key());
350 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
352 if (anObjIter.Key()->Type() != theKind)
358 || anObjIter.Key()->Signature() == theSign)
360 theListOfIO.Append (anObjIter.Key());
365 //=======================================================================
366 //function : ObjectsForView
368 //=======================================================================
369 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
370 const Handle(V3d_View)& theView,
371 const Standard_Boolean theIsVisibleInView,
372 const AIS_DisplayStatus theStatus) const
374 Handle(Graphic3d_CView) aViewImpl = theView->View();
375 const Standard_Integer aViewId = aViewImpl->Identification();
376 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
378 if (theStatus != AIS_DS_None
379 && anObjIter.Value()->GraphicStatus() != theStatus)
381 theListOfIO.Append (anObjIter.Key());
385 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
386 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
387 if (isVisible == theIsVisibleInView)
389 theListOfIO.Append (anObjIter.Key());
394 //=======================================================================
397 //=======================================================================
398 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
399 const Standard_Boolean theToUpdateViewer)
401 if (theIObj.IsNull())
406 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
407 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
409 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
410 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
413 //=======================================================================
414 //function : SetViewAffinity
416 //=======================================================================
417 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
418 const Handle(V3d_View)& theView,
419 const Standard_Boolean theIsVisible)
422 || !myObjects.IsBound (theIObj))
427 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
428 Handle(Graphic3d_CView) aViewImpl = theView->View();
429 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
432 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
436 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
440 //=======================================================================
443 //=======================================================================
444 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
445 const Standard_Integer theDispMode,
446 const Standard_Integer theSelectionMode,
447 const Standard_Boolean theToUpdateViewer,
448 const Standard_Boolean theToAllowDecomposition,
449 const AIS_DisplayStatus theDispStatus)
451 if (theIObj.IsNull())
456 if (theDispStatus == AIS_DS_Erased)
458 Erase (theIObj, theToUpdateViewer);
459 Load (theIObj, theSelectionMode, theToAllowDecomposition);
463 setContextToObject (theIObj);
464 if (theDispStatus == AIS_DS_Temporary
465 && !HasOpenedContext())
469 else if (HasOpenedContext())
471 if (theDispStatus == AIS_DS_None
472 || theDispStatus == AIS_DS_Temporary)
474 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
475 if (theToUpdateViewer)
483 if (!myObjects.IsBound (theIObj))
485 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
486 myObjects.Bind (theIObj, aStatus);
487 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
488 myMainPM->Display(theIObj, theDispMode);
489 if (theSelectionMode != -1)
491 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
492 if (!mgrSelector->Contains (anObj))
494 mgrSelector->Load (theIObj);
496 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
501 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
502 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
507 // Mark the presentation modes hidden of interactive object different from aDispMode.
508 // Then make sure aDispMode is displayed and maybe highlighted.
509 // Finally, activate selection mode <SelMode> if not yet activated.
510 const Standard_Integer anOldMode = aStatus->DisplayMode();
511 if (anOldMode != theDispMode)
513 if(myMainPM->IsHighlighted (theIObj, anOldMode))
515 unhighlightGlobal (theIObj);
517 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
520 aStatus->SetDisplayMode (theDispMode);
522 myMainPM->Display (theIObj, theDispMode);
523 aStatus->SetGraphicStatus (AIS_DS_Displayed);
524 if (aStatus->IsHilighted())
526 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
528 if (theSelectionMode != -1)
530 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
531 if (!mgrSelector->Contains (anObj))
533 mgrSelector->Load (theIObj);
535 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
537 if (!aStatus->IsSModeIn (theSelectionMode))
538 aStatus->AddSelectionMode (theSelectionMode);
539 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
544 if (theToUpdateViewer)
550 //=======================================================================
553 //=======================================================================
554 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
555 const Standard_Integer theSelMode,
556 const Standard_Boolean theToAllowDecomposition)
558 if (theIObj.IsNull())
563 setContextToObject (theIObj);
564 if (HasOpenedContext())
566 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
571 && !theToAllowDecomposition)
573 if (!myObjects.IsBound (theIObj))
575 Standard_Integer aDispMode, aHiMod, aSelModeDef;
576 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
577 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
578 myObjects.Bind (theIObj, aStatus);
581 // Register theIObj in the selection manager to prepare further activation of selection
582 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
583 if (!mgrSelector->Contains (anObj))
585 mgrSelector->Load (theIObj);
590 //=======================================================================
593 //=======================================================================
594 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
595 const Standard_Boolean theToUpdateViewer)
597 if (theIObj.IsNull())
602 if (!theIObj->IsAutoHilight())
604 theIObj->ClearSelected();
607 Standard_Boolean wasInCtx = Standard_False;
608 if (HasOpenedContext())
610 // First it is checked if it is possible to remove in the current local context
611 // then one tries to remove in other local contexts, if they allow it...
612 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
613 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
615 if (aCtxIter.Value()->AcceptErase())
617 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
624 EraseGlobal (theIObj, Standard_False);
627 if (theToUpdateViewer)
633 //=======================================================================
634 //function : EraseAll
636 //=======================================================================
637 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
639 if (HasOpenedContext())
644 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
646 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
648 Erase (anObjIter.Key(), Standard_False);
652 if (theToUpdateViewer)
658 //=======================================================================
659 //function : DisplayAll
661 //=======================================================================
662 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
664 if (HasOpenedContext())
669 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
671 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
672 if (aStatus == AIS_DS_Erased)
674 Display (anObjIter.Key(), Standard_False);
678 if (theToUpdateViewer)
684 //=======================================================================
685 //function : DisplaySelected
687 //=======================================================================
688 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
690 if (HasOpenedContext())
695 Standard_Boolean isFound = Standard_False;
696 for (mySelection->Init(); mySelection->More(); mySelection->Next())
698 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
699 Display (anObj, Standard_False);
700 isFound = Standard_True;
703 if (isFound && theToUpdateViewer)
709 //=======================================================================
710 //function : EraseSelected
712 //=======================================================================
713 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
715 if (HasOpenedContext())
720 Standard_Boolean isFound = Standard_False;
722 while (mySelection->More())
724 Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value();
725 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
727 Erase (anObj, Standard_False);
728 isFound = Standard_True;
733 if (isFound && theToUpdateViewer)
739 //=======================================================================
742 //=======================================================================
744 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
745 const Standard_Integer WhichContext)
747 if(anIObj.IsNull()) return Standard_False;
749 if(!HasOpenedContext()) return Standard_False;
750 if(myObjects.IsBound(anIObj)) return Standard_False;
751 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
753 // Protection : if one tries to preserve a temporary object
754 // which is not in the local active context... rob 11-06-97
756 Standard_Integer IsItInLocal = myCurLocalIndex;
757 Standard_Boolean Found(Standard_False);
759 while(IsItInLocal>0 && !Found){
760 if(!myLocalContexts.IsBound(IsItInLocal))
762 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
763 Found = Standard_True;
768 if(!Found) return Standard_False;
771 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
772 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
774 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
775 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
779 if(LS->IsTemporary()){
780 Standard_Integer DM,HM,SM;
781 GetDefModes(anIObj,DM,HM,SM);
783 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
784 if(LS->DisplayMode()!= DM ){
785 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
786 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
789 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
793 // GS->SubIntensityOn();
794 myObjects.Bind(anIObj,GS);
795 mgrSelector->Load(anIObj);
796 mgrSelector->Activate(anIObj,SM,myMainSel);
798 LS->SetTemporary(Standard_False);
800 return Standard_True;
803 //=======================================================================
804 //function : DisplayStatus
806 //=======================================================================
807 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
809 if (theIObj.IsNull())
813 else if (myObjects.IsBound (theIObj))
815 return myObjects (theIObj)->GraphicStatus();
818 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
820 if (aCtxIter.Value()->IsIn (theIObj))
822 return AIS_DS_Temporary;
828 //=======================================================================
831 //=======================================================================
832 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
833 const Standard_Boolean theToUpdateViewer)
835 if (theIObj.IsNull())
840 if (theIObj->HasInteractiveContext())
842 if (theIObj->myCTXPtr != this)
844 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
846 theIObj->SetContext (Handle(AIS_InteractiveContext)());
849 if (HasOpenedContext())
851 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
852 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
854 if (aCtxIter.Value()->AcceptErase())
856 aCtxIter.Value()->Remove (theIObj);
861 ClearGlobal (theIObj, theToUpdateViewer);
864 //=======================================================================
865 //function : RemoveAll
867 //=======================================================================
868 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
870 AIS_ListOfInteractive aList;
871 ObjectsInside (aList);
872 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
874 Remove (aListIterator.Value(), Standard_False);
877 if (theToUpdateViewer)
883 //=======================================================================
884 //function : ClearPrs
886 //=======================================================================
887 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
888 const Standard_Integer theMode,
889 const Standard_Boolean theToUpdateViewer)
891 if (theIObj.IsNull())
896 if (!HasOpenedContext())
898 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
902 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
903 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
905 if (aCtxIter.Value()->AcceptErase())
907 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
912 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
914 else if (theToUpdateViewer)
920 //=======================================================================
921 //function : HilightWithColor
923 //=======================================================================
924 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
925 const Handle(Prs3d_Drawer)& theStyle,
926 const Standard_Boolean theIsToUpdate)
931 setContextToObject (theObj);
932 if (!HasOpenedContext())
934 if (!myObjects.IsBound (theObj))
937 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
938 aStatus->SetHilightStatus (Standard_True);
940 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
942 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
943 aStatus->SetHilightStyle (theStyle);
948 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
955 //=======================================================================
956 //function : Unhilight
958 //=======================================================================
959 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
961 if(anIObj.IsNull()) return;
963 if (!HasOpenedContext())
965 if(!myObjects.IsBound(anIObj)) return;
967 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
968 aStatus->SetHilightStatus (Standard_False);
969 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
971 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
973 unhighlightGlobal (anIObj);
978 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
980 if(updateviewer) myMainVwr->Update();
983 //=======================================================================
984 //function : IsHilighted
985 //purpose : Returns true if the objects global status is set to highlighted.
986 //=======================================================================
987 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
989 if (!HasOpenedContext())
991 if (!myObjects.IsBound (theObj))
992 return Standard_False;
994 return myObjects (theObj)->IsHilighted();
997 Standard_DISABLE_DEPRECATION_WARNINGS
998 Standard_Integer aCtxIdx = HighestIndex();
999 Standard_ENABLE_DEPRECATION_WARNINGS
1000 for (; aCtxIdx >= 1; aCtxIdx--)
1002 if (myLocalContexts.IsBound (aCtxIdx))
1004 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
1005 return Standard_True;
1009 return Standard_False;
1012 //=======================================================================
1013 //function : IsHilighted
1014 //purpose : Returns true if the owner is highlighted with selection style.
1015 //=======================================================================
1016 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
1018 if (theOwner.IsNull() || !theOwner->HasSelectable())
1019 return Standard_False;
1021 const Handle(AIS_InteractiveObject) anObj =
1022 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1024 if (anObj->GlobalSelOwner() == theOwner)
1026 if (!myObjects.IsBound (anObj))
1027 return Standard_False;
1029 return myObjects (anObj)->IsHilighted();
1032 return theOwner->IsSelected();
1035 //=======================================================================
1036 //function : HighlightStyle
1038 //=======================================================================
1039 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
1040 Handle(Prs3d_Drawer)& theStyle) const
1042 if (HasOpenedContext())
1043 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
1045 if (IsHilighted (theObj))
1047 theStyle = myObjects (theObj)->HilightStyle();
1048 return Standard_True;
1053 return Standard_False;
1057 //=======================================================================
1058 //function : HighlightStyle
1060 //=======================================================================
1061 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
1062 Handle(Prs3d_Drawer)& theStyle) const
1064 if (theOwner.IsNull() || !theOwner->HasSelectable())
1065 return Standard_False;
1067 if (IsHilighted (theOwner))
1069 const Handle(AIS_InteractiveObject) anObj =
1070 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1071 if (anObj->GlobalSelOwner() == theOwner)
1073 theStyle = myObjects (anObj)->HilightStyle();
1077 // since part selection style is not stored in global status,
1078 // check if the object has own selection style. If not, it can
1079 // only be highlighted with default selection style (because
1080 // sub-intensity does not modify any selection states)
1081 theStyle = getSelStyle (anObj, theOwner);
1083 return Standard_True;
1088 return Standard_False;
1092 //=======================================================================
1093 //function : IsDisplayed
1095 //=======================================================================
1097 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1099 if(anIObj.IsNull()) return Standard_False;
1102 if(myObjects.IsBound(anIObj))
1103 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1104 return Standard_True;
1106 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1107 for(;ItM.More();ItM.Next()){
1108 if(ItM.Value()->IsDisplayed(anIObj))
1109 return Standard_True;
1111 return Standard_False;
1115 //=======================================================================
1116 //function : IsDisplayed
1118 //=======================================================================
1119 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1120 const Standard_Integer theMode) const
1122 if (theIObj.IsNull())
1124 return Standard_False;
1127 if (myObjects.IsBound (theIObj))
1129 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1130 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1131 && aStatus->DisplayMode() == theMode)
1133 return Standard_True;
1137 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1139 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1141 return Standard_True;
1144 return Standard_False;
1147 //=======================================================================
1148 //function : DisplayPriority
1150 //=======================================================================
1151 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1153 if (theIObj.IsNull())
1157 else if (!myObjects.IsBound (theIObj))
1162 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1163 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1164 || aStatus->GraphicStatus() == AIS_DS_Erased)
1166 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1167 ? theIObj->DisplayMode()
1168 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1169 ? myDefaultDrawer->DisplayMode()
1171 return myMainPM->DisplayPriority (theIObj, aDispMode);
1176 //=======================================================================
1177 //function : SetDisplayPriority
1179 //=======================================================================
1180 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1181 const Standard_Integer thePriority)
1183 if (theIObj.IsNull())
1188 setContextToObject (theIObj);
1189 if (myObjects.IsBound (theIObj))
1191 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1192 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1193 || aStatus->GraphicStatus() == AIS_DS_Erased)
1195 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1196 ? theIObj->DisplayMode()
1197 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1198 ? myDefaultDrawer->DisplayMode()
1200 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1203 else if (HasOpenedContext())
1205 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1209 //=======================================================================
1210 //function : Redisplay
1212 //=======================================================================
1213 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1214 const Standard_Boolean theToUpdateViewer,
1215 const Standard_Boolean theAllModes)
1217 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1218 RecomputeSelectionOnly (theIObj);
1221 //=======================================================================
1222 //function : Redisplay
1224 //=======================================================================
1225 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1226 const Standard_Integer /*theSign*/,
1227 const Standard_Boolean theToUpdateViewer)
1229 Standard_Boolean isRedisplayed = Standard_False;
1230 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1232 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1233 if (anObj->Type() != theKOI)
1238 Redisplay (anObj, Standard_False);
1239 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1243 if (theToUpdateViewer
1246 myMainVwr->Update();
1250 //=======================================================================
1251 //function : RecomputePrsOnly
1253 //=======================================================================
1254 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1255 const Standard_Boolean theToUpdateViewer,
1256 const Standard_Boolean theAllModes)
1258 if (theIObj.IsNull())
1263 theIObj->Update (theAllModes);
1264 if (!theToUpdateViewer)
1269 if (HasOpenedContext()
1270 || (myObjects.IsBound (theIObj)
1271 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1273 myMainVwr->Update();
1276 //=======================================================================
1277 //function : RecomputeSelectionOnly
1279 //=======================================================================
1280 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1287 mgrSelector->RecomputeSelection (theIO);
1289 if (HasOpenedContext())
1291 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1293 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1298 if (!myObjects.IsBound (theIO) ||
1299 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1304 TColStd_ListOfInteger aModes;
1305 ActivatedModes (theIO, aModes);
1306 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1307 for (; aModesIter.More(); aModesIter.Next())
1309 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1313 //=======================================================================
1316 //=======================================================================
1317 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1318 const Standard_Boolean theUpdateViewer)
1320 if (theIObj.IsNull())
1325 TColStd_ListOfInteger aPrsModes;
1326 theIObj->ToBeUpdated (aPrsModes);
1327 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1329 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1332 mgrSelector->Update(theIObj);
1334 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1336 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1339 if (theUpdateViewer)
1341 if (!myObjects.IsBound (theIObj))
1346 switch (myObjects (theIObj)->GraphicStatus())
1348 case AIS_DS_Displayed:
1349 case AIS_DS_Temporary:
1350 myMainVwr->Update();
1358 //=======================================================================
1359 //function : SetLocation
1361 //=======================================================================
1362 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1363 const TopLoc_Location& theLoc)
1365 if (theIObj.IsNull())
1370 if (theIObj->HasTransformation()
1371 && theLoc.IsIdentity())
1373 theIObj->ResetTransformation();
1374 mgrSelector->Update (theIObj, Standard_False);
1377 else if (theLoc.IsIdentity())
1382 // first reset the previous location to properly clean everything...
1383 if (theIObj->HasTransformation())
1385 theIObj->ResetTransformation();
1388 theIObj->SetLocalTransformation (theLoc.Transformation());
1390 if (!HasOpenedContext())
1392 mgrSelector->Update (theIObj, Standard_False);
1396 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1397 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1400 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1401 // to its highlight structure immediately
1402 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1404 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1405 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1411 //=======================================================================
1412 //function : ResetLocation
1414 //=======================================================================
1415 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1417 if (theIObj.IsNull())
1422 theIObj->ResetTransformation();
1423 mgrSelector->Update (theIObj, Standard_False);
1426 //=======================================================================
1427 //function : HasLocation
1429 //=======================================================================
1430 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1432 return !theIObj.IsNull()
1433 && theIObj->HasTransformation();
1436 //=======================================================================
1437 //function : Location
1439 //=======================================================================
1440 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1442 return theIObj->Transformation();
1445 //=======================================================================
1446 //function : SetDeviationCoefficient
1448 //=======================================================================
1449 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1451 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1454 //=======================================================================
1455 //function : SetDeviationAngle
1457 //=======================================================================
1458 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1460 myDefaultDrawer->SetDeviationAngle (theAngle);
1463 //=======================================================================
1464 //function : DeviationAngle
1465 //purpose : Gets deviationAngle
1466 //=======================================================================
1467 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1469 return myDefaultDrawer->DeviationAngle();
1472 //=======================================================================
1473 //function : DeviationCoefficient
1475 //=======================================================================
1476 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1478 return myDefaultDrawer->DeviationCoefficient();
1481 //=======================================================================
1482 //function : SetHLRDeviationCoefficient
1484 //=======================================================================
1485 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1487 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1490 //=======================================================================
1491 //function : HLRDeviationCoefficient
1493 //=======================================================================
1494 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1496 return myDefaultDrawer->HLRDeviationCoefficient();
1499 //=======================================================================
1500 //function : SetHLRAngle
1502 //=======================================================================
1503 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1505 myDefaultDrawer->SetHLRAngle (theAngle);
1508 //=======================================================================
1509 //function : SetHLRAngleAndDeviation
1510 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1511 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1512 // of myDefaultDrawer
1513 //=======================================================================
1514 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1516 Standard_Real anOutAngl, anOutDefl;
1517 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1519 myDefaultDrawer->SetHLRAngle (anOutAngl);
1520 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1523 //=======================================================================
1524 //function : HLRAngle
1526 //=======================================================================
1527 Standard_Real AIS_InteractiveContext::HLRAngle() const
1529 return myDefaultDrawer->HLRAngle();
1532 //=======================================================================
1533 //function : SetDisplayMode
1535 //=======================================================================
1536 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1537 const Standard_Boolean theToUpdateViewer)
1539 if (theMode == myDefaultDrawer->DisplayMode())
1544 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1546 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1547 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1548 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1549 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1552 || anObj->HasDisplayMode()
1553 || !anObj->AcceptDisplayMode (theMode))
1558 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1559 aStatus->SetDisplayMode (theMode);
1561 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1563 myMainPM->Display (anObj, theMode);
1564 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1566 myMainPM->BeginImmediateDraw();
1567 unhighlightGlobal (anObj);
1568 myMainPM->EndImmediateDraw (myMainVwr);
1570 if (aStatus->IsSubIntensityOn())
1572 highlightWithSubintensity (anObj, theMode);
1574 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1578 myDefaultDrawer->SetDisplayMode (theMode);
1579 if (theToUpdateViewer)
1581 myMainVwr->Update();
1585 //=======================================================================
1586 //function : SetDisplayMode
1588 //=======================================================================
1589 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1590 const Standard_Integer theMode,
1591 const Standard_Boolean theToUpdateViewer)
1593 setContextToObject (theIObj);
1594 if (!myObjects.IsBound (theIObj))
1596 theIObj->SetDisplayMode (theMode);
1599 else if (!theIObj->AcceptDisplayMode (theMode))
1604 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1605 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1607 aStatus->SetDisplayMode (theMode);
1608 theIObj->SetDisplayMode (theMode);
1612 // erase presentations for all display modes different from <aMode>
1613 const Standard_Integer anOldMode = aStatus->DisplayMode();
1614 if (anOldMode != theMode)
1616 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1618 unhighlightGlobal (theIObj);
1620 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1623 aStatus->SetDisplayMode (theMode);
1625 myMainPM->Display (theIObj, theMode);
1626 if (aStatus->IsHilighted())
1628 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1630 if (aStatus->IsSubIntensityOn())
1632 highlightWithSubintensity (theIObj, theMode);
1635 if (theToUpdateViewer)
1637 myMainVwr->Update();
1639 theIObj->SetDisplayMode (theMode);
1642 //=======================================================================
1643 //function : UnsetDisplayMode
1645 //=======================================================================
1646 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1647 const Standard_Boolean theToUpdateViewer)
1649 if (theIObj.IsNull()
1650 || !theIObj->HasDisplayMode())
1655 if (!myObjects.IsBound (theIObj))
1657 theIObj->UnsetDisplayMode();
1661 const Standard_Integer anOldMode = theIObj->DisplayMode();
1662 if (myDefaultDrawer->DisplayMode() == anOldMode)
1667 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1668 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1670 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1672 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1674 unhighlightGlobal (theIObj);
1676 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1677 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1678 if (aStatus->IsHilighted())
1680 highlightSelected (theIObj->GlobalSelOwner());
1682 if (aStatus->IsSubIntensityOn())
1684 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1687 if (theToUpdateViewer)
1689 myMainVwr->Update();
1693 theIObj->UnsetDisplayMode();
1696 //=======================================================================
1697 //function : SetCurrentFacingModel
1699 //=======================================================================
1700 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1701 const Aspect_TypeOfFacingModel theModel)
1703 if (!theIObj.IsNull())
1705 theIObj->SetCurrentFacingModel (theModel);
1709 //=======================================================================
1710 //function : redisplayPrsRecModes
1712 //=======================================================================
1713 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1714 const Standard_Boolean theToUpdateViewer)
1716 if (theIObj->RecomputeEveryPrs())
1718 theIObj->Update (Standard_True);
1719 theIObj->UpdateSelection();
1723 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1725 theIObj->Update (aModes.Value(), Standard_False);
1727 theIObj->UpdateSelection();
1728 theIObj->SetRecomputeOk();
1731 if (theToUpdateViewer)
1733 UpdateCurrentViewer();
1737 //=======================================================================
1738 //function : redisplayPrsModes
1740 //=======================================================================
1741 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1742 const Standard_Boolean theToUpdateViewer)
1744 if (theIObj->RecomputeEveryPrs())
1746 theIObj->Update (Standard_True);
1747 theIObj->UpdateSelection();
1751 TColStd_ListOfInteger aModes;
1752 theIObj->ToBeUpdated (aModes);
1753 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1755 theIObj->Update (aModeIter.Value(), Standard_False);
1757 theIObj->SetRecomputeOk();
1760 if (theToUpdateViewer)
1762 UpdateCurrentViewer();
1766 //=======================================================================
1767 //function : SetColor
1769 //=======================================================================
1770 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1771 const Quantity_NameOfColor theColor,
1772 const Standard_Boolean theToUpdateViewer)
1774 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1777 //=======================================================================
1778 //function : SetColor
1780 //=======================================================================
1781 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1782 const Quantity_Color& theColor,
1783 const Standard_Boolean theToUpdateViewer)
1785 if (theIObj.IsNull())
1790 setContextToObject (theIObj);
1791 theIObj->SetColor (theColor);
1792 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1795 //=======================================================================
1796 //function : SetIsoOnTriangulation
1798 //=======================================================================
1799 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1800 const Handle(AIS_InteractiveObject)& theObject)
1802 if (theObject.IsNull())
1807 theObject->SetIsoOnTriangulation (theIsEnabled);
1810 //=======================================================================
1811 //function : SetDeviationCoefficient
1813 //=======================================================================
1814 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1815 const Standard_Real theCoefficient,
1816 const Standard_Boolean theToUpdateViewer)
1818 if (theIObj.IsNull())
1823 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1824 setContextToObject (theIObj);
1825 if (theIObj->Type() != AIS_KOI_Object
1826 && theIObj->Type() != AIS_KOI_Shape)
1830 else if (theIObj->Signature() != 0)
1835 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1836 aShape->SetOwnDeviationCoefficient (theCoefficient);
1837 redisplayPrsModes (theIObj, theToUpdateViewer);
1840 //=======================================================================
1841 //function : SetHLRDeviationCoefficient
1843 //=======================================================================
1844 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1845 const Standard_Real theCoefficient,
1846 const Standard_Boolean theToUpdateViewer)
1848 if (theIObj.IsNull())
1853 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1854 setContextToObject (theIObj);
1855 if (theIObj->Type() != AIS_KOI_Object
1856 && theIObj->Type() != AIS_KOI_Shape)
1860 else if (theIObj->Signature() != 0)
1865 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1866 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1867 redisplayPrsModes (theIObj, theToUpdateViewer);
1870 //=======================================================================
1871 //function : SetDeviationAngle
1873 //=======================================================================
1874 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1875 const Standard_Real theAngle,
1876 const Standard_Boolean theToUpdateViewer)
1878 if (theIObj.IsNull())
1883 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1884 setContextToObject (theIObj);
1885 if (theIObj->Type() != AIS_KOI_Shape)
1889 else if (theIObj->Signature() != 0)
1894 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1895 aShape->SetOwnDeviationAngle (theAngle);
1896 redisplayPrsModes (theIObj, theToUpdateViewer);
1899 //=======================================================================
1900 //function : SetAngleAndDeviation
1902 //=======================================================================
1903 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1904 const Standard_Real theAngle,
1905 const Standard_Boolean theToUpdateViewer)
1907 if (theIObj.IsNull())
1912 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1913 setContextToObject (theIObj);
1914 if (theIObj->Type() != AIS_KOI_Shape)
1918 if (theIObj->Signature() != 0)
1923 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1924 aShape->SetAngleAndDeviation (theAngle);
1926 if (theIObj->RecomputeEveryPrs())
1928 theIObj->Update (Standard_True);
1929 theIObj->UpdateSelection();
1933 Update (theIObj, theToUpdateViewer);
1937 //=======================================================================
1938 //function : SetHLRAngleAndDeviation
1940 //=======================================================================
1941 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1942 const Standard_Real theAngle,
1943 const Standard_Boolean theToUpdateViewer)
1945 if (theIObj.IsNull())
1950 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1951 setContextToObject (theIObj);
1952 if (theIObj->Type() != AIS_KOI_Shape)
1956 if (theIObj->Signature() != 0)
1960 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1961 aShape->SetHLRAngleAndDeviation (theAngle);
1962 redisplayPrsModes (theIObj, theToUpdateViewer);
1965 //=======================================================================
1966 //function : SetHLRDeviationAngle
1968 //=======================================================================
1969 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1970 const Standard_Real theAngle,
1971 const Standard_Boolean theToUpdateViewer)
1973 if (theIObj.IsNull())
1978 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1979 setContextToObject (theIObj);
1980 if (theIObj->Type() != AIS_KOI_Shape)
1984 if (theIObj->Signature() != 0)
1988 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1989 aShape->SetOwnHLRDeviationAngle (theAngle);
1990 redisplayPrsModes (theIObj, theToUpdateViewer);
1993 //=======================================================================
1994 //function : UnsetColor
1996 //=======================================================================
1997 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1998 const Standard_Boolean theToUpdateViewer)
2000 if (theIObj.IsNull())
2005 theIObj->UnsetColor();
2006 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2009 //=======================================================================
2010 //function : HasColor
2012 //=======================================================================
2013 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2015 return theIObj->HasColor();
2018 //=======================================================================
2021 //=======================================================================
2022 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2024 return theIObj->Color();
2027 //=======================================================================
2030 //=======================================================================
2031 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2032 Quantity_Color& theColor) const
2034 theIObj->Color (theColor);
2037 //=======================================================================
2040 //=======================================================================
2041 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2043 return theIObj->Width();
2046 //=======================================================================
2047 //function : SetWidth
2049 //=======================================================================
2050 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2051 const Standard_Real theWidth,
2052 const Standard_Boolean theToUpdateViewer)
2054 if (theIObj.IsNull())
2059 setContextToObject (theIObj);
2060 theIObj->SetWidth (theWidth);
2061 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2062 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2064 if (myLastinMain->IsAutoHilight())
2066 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2067 myLastinMain->HilightWithColor (myMainPM,
2068 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2073 theIObj->HilightOwnerWithColor (myMainPM,
2074 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2080 //=======================================================================
2081 //function : UnsetWidth
2083 //=======================================================================
2084 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2085 const Standard_Boolean theToUpdateViewer)
2087 if (theIObj.IsNull())
2092 theIObj->UnsetWidth();
2093 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2096 //=======================================================================
2097 //function : SetMaterial
2099 //=======================================================================
2100 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2101 const Graphic3d_NameOfMaterial theName,
2102 const Standard_Boolean theToUpdateViewer)
2104 if (theIObj.IsNull())
2109 setContextToObject (theIObj);
2110 theIObj->SetMaterial (theName);
2111 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2114 //=======================================================================
2115 //function : UnsetMaterial
2117 //=======================================================================
2118 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2119 const Standard_Boolean theToUpdateViewer)
2121 if (theIObj.IsNull())
2125 theIObj->UnsetMaterial();
2126 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2129 //=======================================================================
2130 //function : SetTransparency
2132 //=======================================================================
2133 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2134 const Standard_Real theValue,
2135 const Standard_Boolean theToUpdateViewer)
2137 if (theIObj.IsNull())
2142 setContextToObject (theIObj);
2143 if (!theIObj->IsTransparent()
2144 && theValue <= 0.005)
2149 if (theValue <= 0.005)
2151 UnsetTransparency (theIObj, theToUpdateViewer);
2155 theIObj->SetTransparency (theValue);
2156 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2159 //=======================================================================
2160 //function : UnsetTransparency
2162 //=======================================================================
2163 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2164 const Standard_Boolean theToUpdateViewer)
2166 if (theIObj.IsNull())
2171 theIObj->UnsetTransparency();
2172 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2175 //=======================================================================
2176 //function : SetSelectedAspect
2178 //=======================================================================
2179 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2180 const Standard_Boolean theToUpdateViewer)
2182 if (HasOpenedContext())
2187 Standard_Boolean isFound = Standard_False;
2188 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2190 isFound = Standard_True;
2191 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2192 anObj->SetAspect (theAspect);
2195 if (isFound && theToUpdateViewer)
2197 myMainVwr->Update();
2201 //=======================================================================
2202 //function : SetLocalAttributes
2204 //=======================================================================
2205 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2206 const Handle(Prs3d_Drawer)& theDrawer,
2207 const Standard_Boolean theToUpdateViewer)
2209 if (theIObj.IsNull())
2214 setContextToObject (theIObj);
2215 theIObj->SetAttributes (theDrawer);
2216 Update (theIObj, theToUpdateViewer);
2219 //=======================================================================
2220 //function : UnsetLocalAttributes
2222 //=======================================================================
2223 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2224 const Standard_Boolean theToUpdateViewer)
2226 if (theIObj.IsNull())
2231 setContextToObject (theIObj);
2232 theIObj->UnsetAttributes();
2233 Update (theIObj, theToUpdateViewer);
2236 //=======================================================================
2239 //=======================================================================
2240 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2241 TCollection_ExtendedString& theStatus) const
2244 if (theIObj.IsNull()
2245 || !myObjects.IsBound (theIObj))
2250 theStatus += "\t ____________________________________________";
2251 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2252 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2253 switch (aStatus->GraphicStatus())
2255 case AIS_DS_Displayed:
2257 theStatus += "\t| -->Displayed\n";
2262 theStatus += "\t| -->Erased\n";
2269 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2270 theStatus += "\t|\t Mode ";
2271 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2274 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2276 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2277 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2279 theStatus += "\t\t Mode ";
2280 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2283 theStatus += "\t ____________________________________________";
2286 //=======================================================================
2287 //function : GetDefModes
2289 //=======================================================================
2290 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2291 Standard_Integer& theDispMode,
2292 Standard_Integer& theHiMode,
2293 Standard_Integer& theSelMode) const
2295 if (theIObj.IsNull())
2300 theDispMode = theIObj->HasDisplayMode()
2301 ? theIObj->DisplayMode()
2302 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
2303 ? myDefaultDrawer->DisplayMode()
2305 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2306 theSelMode = theIObj->GlobalSelectionMode();
2309 //=======================================================================
2310 //function : EraseGlobal
2312 //=======================================================================
2313 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2314 const Standard_Boolean theToUpdateviewer)
2316 if (theIObj.IsNull()
2317 || !myObjects.IsBound (theIObj))
2322 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2324 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2325 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2326 || aStatus->GraphicStatus() == AIS_DS_Erased)
2331 if (aStatus->IsHilighted())
2333 Standard_DISABLE_DEPRECATION_WARNINGS
2334 if (IsCurrent (theIObj))
2336 AddOrRemoveCurrentObject (theIObj, Standard_False);
2338 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2340 unhighlightGlobal (theIObj);
2342 Standard_ENABLE_DEPRECATION_WARNINGS
2345 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2347 if (aStatus->IsHilighted()
2348 && theIObj->HasHilightMode())
2350 unhighlightGlobal (theIObj);
2353 if (!myLastPicked.IsNull()
2354 && myLastPicked->IsSameSelectable (theIObj))
2356 clearDynamicHighlight();
2359 if (IsSelected (theIObj)
2360 && aStatus->DisplayMode() != aDispMode)
2362 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2365 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2367 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2369 aStatus->ClearSelectionModes();
2370 aStatus->SetGraphicStatus (AIS_DS_Erased);
2372 if (theToUpdateviewer)
2374 myMainVwr->Update();
2378 //=======================================================================
2379 //function : unhighlightOwners
2381 //=======================================================================
2382 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2384 SelectMgr_SequenceOfOwner aSeq;
2385 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2387 if (aSelIter.Value()->IsSameSelectable (theObject))
2389 aSeq.Append (aSelIter.Value());
2392 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2394 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2398 //=======================================================================
2399 //function : ClearGlobal
2401 //=======================================================================
2402 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2403 const Standard_Boolean theToUpdateviewer)
2405 if (theIObj.IsNull()
2406 || !myObjects.IsBound (theIObj))
2408 // for cases when reference shape of connected interactives was not displayed
2409 // but its selection primitives were calculated
2410 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2411 mgrSelector->Remove (anObj);
2415 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2416 unhighlightOwners (theIObj);
2418 myMainPM->Erase (theIObj, -1);
2420 // Object removes from Detected sequence
2421 Standard_DISABLE_DEPRECATION_WARNINGS
2422 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2424 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2425 Handle(AIS_InteractiveObject) anObj;
2426 if (!aPicked.IsNull())
2428 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2432 && anObj == theIObj)
2434 myDetectedSeq.Remove (aDetIter);
2435 if (myCurDetected == aDetIter)
2437 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2439 if (myCurHighlighted == aDetIter)
2441 myCurHighlighted = 0;
2449 Standard_ENABLE_DEPRECATION_WARNINGS
2451 // remove IO from the selection manager to avoid memory leaks
2452 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2453 mgrSelector->Remove (anObj);
2455 myObjects.UnBind (theIObj);
2456 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2458 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2460 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2463 if (!myLastinMain.IsNull())
2465 if (myLastinMain->IsSameSelectable (theIObj)
2466 || myLastPicked->IsSameSelectable(theIObj))
2468 clearDynamicHighlight();
2469 myLastinMain.Nullify();
2470 myLastPicked.Nullify();
2474 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2476 myMainVwr->Update();
2480 //=======================================================================
2481 //function : ClearGlobalPrs
2483 //=======================================================================
2484 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2485 const Standard_Integer theMode,
2486 const Standard_Boolean theToUpdateViewer)
2488 if (theIObj.IsNull()
2489 || !myObjects.IsBound (theIObj))
2494 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2495 if (aStatus->DisplayMode() == theMode)
2497 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2498 if (aDispMode == theMode
2499 && myMainPM->IsHighlighted (theIObj, theMode))
2501 unhighlightGlobal (theIObj);
2504 myMainPM->Erase (theIObj, theMode);
2507 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2508 && theToUpdateViewer)
2510 myMainVwr->Update();
2514 //=======================================================================
2515 //function : DrawHiddenLine
2517 //=======================================================================
2518 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2520 return myDefaultDrawer->DrawHiddenLine();
2523 //=======================================================================
2524 //function : EnableDrawHiddenLine
2526 //=======================================================================
2527 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2529 myDefaultDrawer->EnableDrawHiddenLine();
2532 //=======================================================================
2533 //function : DisableDrawHiddenLine
2535 //=======================================================================
2536 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2538 myDefaultDrawer->DisableDrawHiddenLine();
2541 //=======================================================================
2542 //function : HiddenLineAspect
2544 //=======================================================================
2545 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2547 return myDefaultDrawer->HiddenLineAspect();
2550 //=======================================================================
2551 //function : SetHiddenLineAspect
2553 //=======================================================================
2554 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2556 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2559 //=======================================================================
2560 //function : SetIsoNumber
2562 //=======================================================================
2563 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2564 const AIS_TypeOfIso theType)
2569 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2572 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2575 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2576 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2581 //=======================================================================
2582 //function : IsoNumber
2584 //=======================================================================
2585 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2589 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2590 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2591 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2592 ? myDefaultDrawer->UIsoAspect()->Number()
2598 //=======================================================================
2599 //function : IsoOnPlane
2601 //=======================================================================
2602 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2604 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2607 //=======================================================================
2608 //function : IsoOnPlane
2610 //=======================================================================
2611 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2613 return myDefaultDrawer->IsoOnPlane();
2616 //=======================================================================
2617 //function : IsoOnTriangulation
2619 //=======================================================================
2620 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2622 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2625 //=======================================================================
2626 //function : IsoOnTriangulation
2628 //=======================================================================
2629 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2631 return myDefaultDrawer->IsoOnTriangulation();
2634 //function : SetPixelTolerance
2635 //purpose : Disables the mechanism of adaptive tolerance calculation in
2636 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2637 // sensitive entities activated. For more information, see
2638 // SelectMgr_ViewerSelector.hxx
2639 //=======================================================================
2640 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2642 if (HasOpenedContext())
2644 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2648 myMainSel->SetPixelTolerance (thePrecision);
2652 //=======================================================================
2653 //function : PixelTolerance
2655 //=======================================================================
2656 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2658 return HasOpenedContext()
2659 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2660 : myMainSel->PixelTolerance();
2663 //=======================================================================
2664 //function : SetSelectionSensitivity
2665 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2666 //=======================================================================
2667 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2668 const Standard_Integer theMode,
2669 const Standard_Integer theNewSensitivity)
2671 if (HasOpenedContext())
2673 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2677 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2680 //=======================================================================
2681 //function : IsInLocal
2683 //=======================================================================
2684 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2685 Standard_Integer& theIndex) const
2687 if (theIObj.IsNull())
2689 return Standard_False;
2692 // if it exists at neutral point 0 index is returned
2693 if (myObjects.IsBound (theIObj))
2696 return Standard_False;
2699 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2701 if (myLocalContexts.IsBound (aCtxIter))
2703 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2705 theIndex = aCtxIter;
2706 return Standard_True;
2711 return Standard_False;
2714 //=======================================================================
2715 //function : InitAttributes
2717 //=======================================================================
2718 void AIS_InteractiveContext::InitAttributes()
2720 mgrSelector->Add (myMainSel);
2722 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2723 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2725 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2726 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2727 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2728 aLineAspect->SetWidth (1.0);
2729 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2731 // tolerance to 2 pixels...
2732 SetPixelTolerance (2);
2734 // Customizing the drawer for trihedrons and planes...
2735 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2736 const Standard_Real aLength = 100.0;
2737 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2738 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2739 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2740 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2741 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2743 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2744 const Standard_Real aPlaneLength = 200.0;
2745 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2746 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2749 //=======================================================================
2750 //function : TrihedronSize
2752 //=======================================================================
2753 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2755 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2758 //=======================================================================
2759 //function : SetTrihedronSize
2761 //=======================================================================
2762 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2763 const Standard_Boolean /*updateviewer*/)
2765 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2766 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2767 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2770 //=======================================================================
2771 //function : SetPlaneSize
2773 //=======================================================================
2774 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2775 const Standard_Real theValY,
2776 const Standard_Boolean theToUpdateViewer)
2778 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2779 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2782 //=======================================================================
2783 //function : SetPlaneSize
2785 //=======================================================================
2786 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2787 const Standard_Boolean theToUpdateViewer)
2789 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2792 //=======================================================================
2793 //function : PlaneSize
2795 //=======================================================================
2796 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2797 Standard_Real& theY) const
2799 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2800 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2801 return (Abs (theX - theY) <= Precision::Confusion());
2804 //=======================================================================
2805 //function : SetAutoActivateSelection
2807 //=======================================================================
2808 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2810 myIsAutoActivateSelMode = theIsAuto;
2813 //=======================================================================
2814 //function : GetAutoActivateSelection
2816 //=======================================================================
2817 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2819 return myIsAutoActivateSelMode;
2822 //=======================================================================
2823 //function : SetZLayer
2825 //=======================================================================
2826 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2827 const Standard_Integer theLayerId)
2829 if (theIObj.IsNull())
2832 theIObj->SetZLayer (theLayerId);
2835 //=======================================================================
2836 //function : GetZLayer
2838 //=======================================================================
2839 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2841 return !theIObj.IsNull()
2843 : Graphic3d_ZLayerId_UNKNOWN;
2846 //=======================================================================
2847 //function : RebuildSelectionStructs
2848 //purpose : Rebuilds 1st level of BVH selection forcibly
2849 //=======================================================================
2850 void AIS_InteractiveContext::RebuildSelectionStructs()
2852 myMainSel->RebuildObjectsTree (Standard_True);
2855 //=======================================================================
2856 //function : Disconnect
2857 //purpose : Disconnects selectable object from an assembly and updates selection structures
2858 //=======================================================================
2859 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2860 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2862 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2864 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2865 theObj->Disconnect (theObjToDisconnect);
2866 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2867 mgrSelector->Remove (anObj);
2869 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2871 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2872 theObj->Disconnect();
2873 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2874 mgrSelector->Remove (anObj);
2880 //=======================================================================
2881 //function : FitSelected
2882 //purpose : Fits the view corresponding to the bounds of selected objects
2883 //=======================================================================
2884 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2886 FitSelected (theView, 0.01, Standard_True);
2889 //=======================================================================
2890 //function : FitSelected
2891 //purpose : Fits the view corresponding to the bounds of selected objects
2892 //=======================================================================
2893 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2894 const Standard_Real theMargin,
2895 const Standard_Boolean theToUpdate)
2897 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2898 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2900 Bnd_Box aBndSelected;
2902 AIS_MapOfObjectOwners anObjectOwnerMap;
2903 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2905 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2906 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2907 if (anObj->IsInfinite())
2912 if (anOwner == anObj->GlobalSelOwner())
2915 anObj->BoundingBox (aTmpBnd);
2916 aBndSelected.Add (aTmpBnd);
2920 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2921 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2923 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2924 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2927 anOwnerMap->Add (anOwner);
2931 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2933 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2934 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2935 aBndSelected.Add (aTmpBox);
2938 anObjectOwnerMap.Clear();
2940 if (aBndSelected.IsVoid())
2943 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2946 //=======================================================================
2947 //function : SetTransformPersistence
2949 //=======================================================================
2950 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2951 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2953 theObject->SetTransformPersistence (theTrsfPers);
2954 if (!myObjects.IsBound (theObject))
2959 mgrSelector->UpdateSelection (theObject);
2961 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2962 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2963 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2965 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2966 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);