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 myIsAutoActivateSelMode(Standard_True)
124 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
125 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
126 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
127 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
128 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
129 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
131 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
132 myDefaultDrawer->SetDisplayMode(0);
134 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
135 aStyle->Link (myDefaultDrawer);
136 initDefaultHilightAttributes (aStyle);
137 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
138 aStyle->SetColor (Quantity_NOC_CYAN1);
141 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
142 aStyle->Link (myDefaultDrawer);
143 initDefaultHilightAttributes (aStyle);
144 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
145 aStyle->SetColor (Quantity_NOC_CYAN1);
148 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
149 aStyle->Link (myDefaultDrawer);
150 initDefaultHilightAttributes (aStyle);
151 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
152 aStyle->SetColor (Quantity_NOC_GRAY80);
155 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
156 aStyle->Link (myDefaultDrawer);
157 initDefaultHilightAttributes (aStyle);
158 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
159 aStyle->SetColor (Quantity_NOC_GRAY80);
162 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
163 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
164 aStyle->SetMethod(Aspect_TOHM_COLOR);
165 aStyle->SetColor (Quantity_NOC_GRAY40);
171 //=======================================================================
172 //function : ~AIS_InteractiveContext
174 //=======================================================================
175 AIS_InteractiveContext::~AIS_InteractiveContext()
177 // clear the current selection
178 mySelection->Clear();
180 // let's remove one reference explicitly. this operation's supposed to
181 // be performed when mgrSelector will be destroyed but anyway...
182 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
183 mgrSelector->Remove (aSelector);
185 Handle(AIS_InteractiveContext) aNullContext;
186 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
188 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
189 anObj->SetContext (aNullContext);
190 for (anObj->Init(); anObj->More(); anObj->Next())
192 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
197 //=======================================================================
198 //function : UpdateCurrentViewer
200 //=======================================================================
202 void AIS_InteractiveContext::UpdateCurrentViewer()
204 if (!myMainVwr.IsNull())
208 //=======================================================================
209 //function : DisplayedObjects
211 //=======================================================================
212 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
213 const Standard_Boolean theOnlyFromNeutral) const
215 if (!HasOpenedContext()
216 || theOnlyFromNeutral)
218 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
220 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
222 theListOfIO.Append (anObjIter.Key());
229 TColStd_MapOfTransient aDispMap;
230 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
232 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
234 aDispMap.Add (anObjIter.Key());
238 // parse all local contexts...
239 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
241 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
242 aLocCtx->DisplayedObjects (aDispMap);
245 Handle(AIS_InteractiveObject) anObj;
246 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
248 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
249 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
250 theListOfIO.Append (anObj);
254 //=======================================================================
255 //function : DisplayedObjects
257 //=======================================================================
258 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
259 const Standard_Integer theSign,
260 AIS_ListOfInteractive& theListOfIO,
261 const Standard_Boolean /*OnlyFromNeutral*/) const
263 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
266 //=======================================================================
267 //function : ErasedObjects
269 //=======================================================================
270 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
272 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
275 //=======================================================================
276 //function : ErasedObjects
278 //=======================================================================
279 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
280 const Standard_Integer theSign,
281 AIS_ListOfInteractive& theListOfIO) const
283 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
286 //=======================================================================
287 //function : ObjectsByDisplayStatus
289 //=======================================================================
290 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
291 AIS_ListOfInteractive& theListOfIO) const
293 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
295 if (anObjIter.Value()->GraphicStatus() == theStatus)
297 theListOfIO.Append (anObjIter.Key());
302 //=======================================================================
303 //function : ObjectsByDisplayStatus
305 //=======================================================================
306 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
307 const Standard_Integer theSign,
308 const AIS_DisplayStatus theStatus,
309 AIS_ListOfInteractive& theListOfIO) const
311 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
313 if (theStatus != AIS_DS_None
314 && anObjIter.Value()->GraphicStatus() != theStatus)
318 else if (anObjIter.Key()->Type() != theKind)
324 || anObjIter.Key()->Signature() == theSign)
326 theListOfIO.Append (anObjIter.Key());
331 //=======================================================================
332 //function : ObjectsInside
334 //=======================================================================
335 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
336 const AIS_KindOfInteractive theKind,
337 const Standard_Integer theSign) const
339 if (theKind == AIS_KOI_None
342 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
344 theListOfIO.Append (anObjIter.Key());
349 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
351 if (anObjIter.Key()->Type() != theKind)
357 || anObjIter.Key()->Signature() == theSign)
359 theListOfIO.Append (anObjIter.Key());
364 //=======================================================================
365 //function : ObjectsForView
367 //=======================================================================
368 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
369 const Handle(V3d_View)& theView,
370 const Standard_Boolean theIsVisibleInView,
371 const AIS_DisplayStatus theStatus) const
373 Handle(Graphic3d_CView) aViewImpl = theView->View();
374 const Standard_Integer aViewId = aViewImpl->Identification();
375 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
377 if (theStatus != AIS_DS_None
378 && anObjIter.Value()->GraphicStatus() != theStatus)
380 theListOfIO.Append (anObjIter.Key());
384 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
385 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
386 if (isVisible == theIsVisibleInView)
388 theListOfIO.Append (anObjIter.Key());
393 //=======================================================================
396 //=======================================================================
397 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
398 const Standard_Boolean theToUpdateViewer)
400 if (theIObj.IsNull())
405 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
406 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
408 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
409 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
412 //=======================================================================
413 //function : SetViewAffinity
415 //=======================================================================
416 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
417 const Handle(V3d_View)& theView,
418 const Standard_Boolean theIsVisible)
421 || !myObjects.IsBound (theIObj))
426 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
427 Handle(Graphic3d_CView) aViewImpl = theView->View();
428 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
431 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
435 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
439 //=======================================================================
442 //=======================================================================
443 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
444 const Standard_Integer theDispMode,
445 const Standard_Integer theSelectionMode,
446 const Standard_Boolean theToUpdateViewer,
447 const Standard_Boolean theToAllowDecomposition,
448 const AIS_DisplayStatus theDispStatus)
450 if (theIObj.IsNull())
455 if (theDispStatus == AIS_DS_Erased)
457 Erase (theIObj, theToUpdateViewer);
458 Load (theIObj, theSelectionMode, theToAllowDecomposition);
462 setContextToObject (theIObj);
463 if (theDispStatus == AIS_DS_Temporary
464 && !HasOpenedContext())
468 else if (HasOpenedContext())
470 if (theDispStatus == AIS_DS_None
471 || theDispStatus == AIS_DS_Temporary)
473 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
474 if (theToUpdateViewer)
482 if (!myObjects.IsBound (theIObj))
484 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
485 myObjects.Bind (theIObj, aStatus);
486 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
487 myMainPM->Display(theIObj, theDispMode);
488 if (theSelectionMode != -1)
490 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
491 if (!mgrSelector->Contains (anObj))
493 mgrSelector->Load (theIObj);
495 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
500 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
501 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
506 // Mark the presentation modes hidden of interactive object different from aDispMode.
507 // Then make sure aDispMode is displayed and maybe highlighted.
508 // Finally, activate selection mode <SelMode> if not yet activated.
509 const Standard_Integer anOldMode = aStatus->DisplayMode();
510 if (anOldMode != theDispMode)
512 if(myMainPM->IsHighlighted (theIObj, anOldMode))
514 unhighlightGlobal (theIObj);
516 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
519 aStatus->SetDisplayMode (theDispMode);
521 myMainPM->Display (theIObj, theDispMode);
522 aStatus->SetGraphicStatus (AIS_DS_Displayed);
523 if (aStatus->IsHilighted())
525 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
527 if (theSelectionMode != -1)
529 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
530 if (!mgrSelector->Contains (anObj))
532 mgrSelector->Load (theIObj);
534 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
536 if (!aStatus->IsSModeIn (theSelectionMode))
537 aStatus->AddSelectionMode (theSelectionMode);
538 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
543 if (theToUpdateViewer)
549 //=======================================================================
552 //=======================================================================
553 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
554 const Standard_Integer theSelMode,
555 const Standard_Boolean theToAllowDecomposition)
557 if (theIObj.IsNull())
562 setContextToObject (theIObj);
563 if (HasOpenedContext())
565 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
570 && !theToAllowDecomposition)
572 if (!myObjects.IsBound (theIObj))
574 Standard_Integer aDispMode, aHiMod, aSelModeDef;
575 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
576 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
577 myObjects.Bind (theIObj, aStatus);
580 // Register theIObj in the selection manager to prepare further activation of selection
581 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
582 if (!mgrSelector->Contains (anObj))
584 mgrSelector->Load (theIObj);
589 //=======================================================================
592 //=======================================================================
593 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
594 const Standard_Boolean theToUpdateViewer)
596 if (theIObj.IsNull())
601 if (!theIObj->IsAutoHilight())
603 theIObj->ClearSelected();
606 Standard_Boolean wasInCtx = Standard_False;
607 if (HasOpenedContext())
609 // First it is checked if it is possible to remove in the current local context
610 // then one tries to remove in other local contexts, if they allow it...
611 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
612 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
614 if (aCtxIter.Value()->AcceptErase())
616 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
623 EraseGlobal (theIObj, Standard_False);
626 if (theToUpdateViewer)
632 //=======================================================================
633 //function : EraseAll
635 //=======================================================================
636 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
638 if (HasOpenedContext())
643 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
645 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
647 Erase (anObjIter.Key(), Standard_False);
651 if (theToUpdateViewer)
657 //=======================================================================
658 //function : DisplayAll
660 //=======================================================================
661 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
663 if (HasOpenedContext())
668 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
670 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
671 if (aStatus == AIS_DS_Erased)
673 Display (anObjIter.Key(), Standard_False);
677 if (theToUpdateViewer)
683 //=======================================================================
684 //function : DisplaySelected
686 //=======================================================================
687 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
689 if (HasOpenedContext())
694 Standard_Boolean isFound = Standard_False;
695 for (mySelection->Init(); mySelection->More(); mySelection->Next())
697 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
698 Display (anObj, Standard_False);
699 isFound = Standard_True;
702 if (isFound && theToUpdateViewer)
708 //=======================================================================
709 //function : EraseSelected
711 //=======================================================================
712 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
714 if (HasOpenedContext())
719 Standard_Boolean isFound = Standard_False;
721 while (mySelection->More())
723 Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value();
724 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
726 Erase (anObj, Standard_False);
727 isFound = Standard_True;
732 if (isFound && theToUpdateViewer)
738 //=======================================================================
741 //=======================================================================
743 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
744 const Standard_Integer WhichContext)
746 if(anIObj.IsNull()) return Standard_False;
748 if(!HasOpenedContext()) return Standard_False;
749 if(myObjects.IsBound(anIObj)) return Standard_False;
750 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
752 // Protection : if one tries to preserve a temporary object
753 // which is not in the local active context... rob 11-06-97
755 Standard_Integer IsItInLocal = myCurLocalIndex;
756 Standard_Boolean Found(Standard_False);
758 while(IsItInLocal>0 && !Found){
759 if(!myLocalContexts.IsBound(IsItInLocal))
761 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
762 Found = Standard_True;
767 if(!Found) return Standard_False;
770 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
771 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
773 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
774 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
778 if(LS->IsTemporary()){
779 Standard_Integer DM,HM,SM;
780 GetDefModes(anIObj,DM,HM,SM);
782 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
783 if(LS->DisplayMode()!= DM ){
784 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
785 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
788 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
792 // GS->SubIntensityOn();
793 myObjects.Bind(anIObj,GS);
794 mgrSelector->Load(anIObj);
795 mgrSelector->Activate(anIObj,SM,myMainSel);
797 LS->SetTemporary(Standard_False);
799 return Standard_True;
802 //=======================================================================
803 //function : DisplayStatus
805 //=======================================================================
806 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
808 if (theIObj.IsNull())
812 else if (myObjects.IsBound (theIObj))
814 return myObjects (theIObj)->GraphicStatus();
817 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
819 if (aCtxIter.Value()->IsIn (theIObj))
821 return AIS_DS_Temporary;
827 //=======================================================================
830 //=======================================================================
831 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
832 const Standard_Boolean theToUpdateViewer)
834 if (theIObj.IsNull())
839 if (theIObj->HasInteractiveContext())
841 if (theIObj->myCTXPtr != this)
843 Standard_ProgramError::Raise ("AIS_InteractiveContext - object has been displayed in another context!");
845 theIObj->SetContext (Handle(AIS_InteractiveContext)());
848 if (HasOpenedContext())
850 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
851 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
853 if (aCtxIter.Value()->AcceptErase())
855 aCtxIter.Value()->Remove (theIObj);
860 ClearGlobal (theIObj, theToUpdateViewer);
863 //=======================================================================
864 //function : RemoveAll
866 //=======================================================================
867 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
869 AIS_ListOfInteractive aList;
870 ObjectsInside (aList);
871 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
873 Remove (aListIterator.Value(), Standard_False);
876 if (theToUpdateViewer)
882 //=======================================================================
883 //function : ClearPrs
885 //=======================================================================
886 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
887 const Standard_Integer theMode,
888 const Standard_Boolean theToUpdateViewer)
890 if (theIObj.IsNull())
895 if (!HasOpenedContext())
897 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
901 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
902 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
904 if (aCtxIter.Value()->AcceptErase())
906 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
911 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
913 else if (theToUpdateViewer)
919 //=======================================================================
920 //function : HilightWithColor
922 //=======================================================================
923 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
924 const Handle(Prs3d_Drawer)& theStyle,
925 const Standard_Boolean theIsToUpdate)
930 setContextToObject (theObj);
931 if (!HasOpenedContext())
933 if (!myObjects.IsBound (theObj))
936 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
937 aStatus->SetHilightStatus (Standard_True);
939 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
941 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
942 aStatus->SetHilightStyle (theStyle);
947 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
954 //=======================================================================
955 //function : Unhilight
957 //=======================================================================
958 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
960 if(anIObj.IsNull()) return;
962 if (!HasOpenedContext())
964 if(!myObjects.IsBound(anIObj)) return;
966 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
967 aStatus->SetHilightStatus (Standard_False);
968 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
970 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
972 unhighlightGlobal (anIObj);
977 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
979 if(updateviewer) myMainVwr->Update();
982 //=======================================================================
983 //function : IsHilighted
984 //purpose : Returns true if the objects global status is set to highlighted.
985 //=======================================================================
986 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
988 if (!HasOpenedContext())
990 if (!myObjects.IsBound (theObj))
991 return Standard_False;
993 return myObjects (theObj)->IsHilighted();
996 Standard_DISABLE_DEPRECATION_WARNINGS
997 Standard_Integer aCtxIdx = HighestIndex();
998 Standard_ENABLE_DEPRECATION_WARNINGS
999 for (; aCtxIdx >= 1; aCtxIdx--)
1001 if (myLocalContexts.IsBound (aCtxIdx))
1003 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
1004 return Standard_True;
1008 return Standard_False;
1011 //=======================================================================
1012 //function : IsHilighted
1013 //purpose : Returns true if the owner is highlighted with selection style.
1014 //=======================================================================
1015 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
1017 if (theOwner.IsNull() || !theOwner->HasSelectable())
1018 return Standard_False;
1020 const Handle(AIS_InteractiveObject) anObj =
1021 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1023 if (anObj->GlobalSelOwner() == theOwner)
1025 if (!myObjects.IsBound (anObj))
1026 return Standard_False;
1028 return myObjects (anObj)->IsHilighted();
1031 return theOwner->IsSelected();
1034 //=======================================================================
1035 //function : HighlightStyle
1037 //=======================================================================
1038 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
1039 Handle(Prs3d_Drawer)& theStyle) const
1041 if (HasOpenedContext())
1042 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
1044 if (IsHilighted (theObj))
1046 theStyle = myObjects (theObj)->HilightStyle();
1047 return Standard_True;
1052 return Standard_False;
1056 //=======================================================================
1057 //function : HighlightStyle
1059 //=======================================================================
1060 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
1061 Handle(Prs3d_Drawer)& theStyle) const
1063 if (theOwner.IsNull() || !theOwner->HasSelectable())
1064 return Standard_False;
1066 if (IsHilighted (theOwner))
1068 const Handle(AIS_InteractiveObject) anObj =
1069 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1070 if (anObj->GlobalSelOwner() == theOwner)
1072 theStyle = myObjects (anObj)->HilightStyle();
1076 // since part selection style is not stored in global status,
1077 // check if the object has own selection style. If not, it can
1078 // only be highlighted with default selection style (because
1079 // sub-intensity does not modify any selection states)
1080 theStyle = getSelStyle (anObj, theOwner);
1082 return Standard_True;
1087 return Standard_False;
1091 //=======================================================================
1092 //function : IsDisplayed
1094 //=======================================================================
1096 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1098 if(anIObj.IsNull()) return Standard_False;
1101 if(myObjects.IsBound(anIObj))
1102 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1103 return Standard_True;
1105 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1106 for(;ItM.More();ItM.Next()){
1107 if(ItM.Value()->IsDisplayed(anIObj))
1108 return Standard_True;
1110 return Standard_False;
1114 //=======================================================================
1115 //function : IsDisplayed
1117 //=======================================================================
1118 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1119 const Standard_Integer theMode) const
1121 if (theIObj.IsNull())
1123 return Standard_False;
1126 if (myObjects.IsBound (theIObj))
1128 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1129 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1130 && aStatus->DisplayMode() == theMode)
1132 return Standard_True;
1136 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1138 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1140 return Standard_True;
1143 return Standard_False;
1146 //=======================================================================
1147 //function : DisplayPriority
1149 //=======================================================================
1150 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1152 if (theIObj.IsNull())
1156 else if (!myObjects.IsBound (theIObj))
1161 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1162 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1163 || aStatus->GraphicStatus() == AIS_DS_Erased)
1165 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1166 ? theIObj->DisplayMode()
1167 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1168 ? myDefaultDrawer->DisplayMode()
1170 return myMainPM->DisplayPriority (theIObj, aDispMode);
1175 //=======================================================================
1176 //function : SetDisplayPriority
1178 //=======================================================================
1179 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1180 const Standard_Integer thePriority)
1182 if (theIObj.IsNull())
1187 setContextToObject (theIObj);
1188 if (myObjects.IsBound (theIObj))
1190 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1191 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1192 || aStatus->GraphicStatus() == AIS_DS_Erased)
1194 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1195 ? theIObj->DisplayMode()
1196 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1197 ? myDefaultDrawer->DisplayMode()
1199 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1202 else if (HasOpenedContext())
1204 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1208 //=======================================================================
1209 //function : Redisplay
1211 //=======================================================================
1212 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1213 const Standard_Boolean theToUpdateViewer,
1214 const Standard_Boolean theAllModes)
1216 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1217 RecomputeSelectionOnly (theIObj);
1220 //=======================================================================
1221 //function : Redisplay
1223 //=======================================================================
1224 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1225 const Standard_Integer /*theSign*/,
1226 const Standard_Boolean theToUpdateViewer)
1228 Standard_Boolean isRedisplayed = Standard_False;
1229 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1231 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1232 if (anObj->Type() != theKOI)
1237 Redisplay (anObj, Standard_False);
1238 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1242 if (theToUpdateViewer
1245 myMainVwr->Update();
1249 //=======================================================================
1250 //function : RecomputePrsOnly
1252 //=======================================================================
1253 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1254 const Standard_Boolean theToUpdateViewer,
1255 const Standard_Boolean theAllModes)
1257 if (theIObj.IsNull())
1262 theIObj->Update (theAllModes);
1263 if (!theToUpdateViewer)
1268 if (HasOpenedContext()
1269 || (myObjects.IsBound (theIObj)
1270 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1272 myMainVwr->Update();
1275 //=======================================================================
1276 //function : RecomputeSelectionOnly
1278 //=======================================================================
1279 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1286 mgrSelector->RecomputeSelection (theIO);
1288 if (HasOpenedContext())
1290 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1292 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1297 if (!myObjects.IsBound (theIO) ||
1298 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1303 TColStd_ListOfInteger aModes;
1304 ActivatedModes (theIO, aModes);
1305 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1306 for (; aModesIter.More(); aModesIter.Next())
1308 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1312 //=======================================================================
1315 //=======================================================================
1316 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1317 const Standard_Boolean theUpdateViewer)
1319 if (theIObj.IsNull())
1324 TColStd_ListOfInteger aPrsModes;
1325 theIObj->ToBeUpdated (aPrsModes);
1326 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1328 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1331 mgrSelector->Update(theIObj);
1333 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1335 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1338 if (theUpdateViewer)
1340 if (!myObjects.IsBound (theIObj))
1345 switch (myObjects (theIObj)->GraphicStatus())
1347 case AIS_DS_Displayed:
1348 case AIS_DS_Temporary:
1349 myMainVwr->Update();
1357 //=======================================================================
1358 //function : SetLocation
1360 //=======================================================================
1361 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1362 const TopLoc_Location& theLoc)
1364 if (theIObj.IsNull())
1369 if (theIObj->HasTransformation()
1370 && theLoc.IsIdentity())
1372 theIObj->ResetTransformation();
1373 mgrSelector->Update (theIObj, Standard_False);
1376 else if (theLoc.IsIdentity())
1381 // first reset the previous location to properly clean everything...
1382 if (theIObj->HasTransformation())
1384 theIObj->ResetTransformation();
1387 theIObj->SetLocalTransformation (theLoc.Transformation());
1389 if (!HasOpenedContext())
1391 mgrSelector->Update (theIObj, Standard_False);
1395 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1396 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1399 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1400 // to its highlight structure immediately
1401 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1403 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1404 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1410 //=======================================================================
1411 //function : ResetLocation
1413 //=======================================================================
1414 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1416 if (theIObj.IsNull())
1421 theIObj->ResetTransformation();
1422 mgrSelector->Update (theIObj, Standard_False);
1425 //=======================================================================
1426 //function : HasLocation
1428 //=======================================================================
1429 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1431 return !theIObj.IsNull()
1432 && theIObj->HasTransformation();
1435 //=======================================================================
1436 //function : Location
1438 //=======================================================================
1439 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1441 return theIObj->Transformation();
1444 //=======================================================================
1445 //function : SetDeviationCoefficient
1447 //=======================================================================
1448 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1450 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1453 //=======================================================================
1454 //function : SetDeviationAngle
1456 //=======================================================================
1457 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1459 myDefaultDrawer->SetDeviationAngle (theAngle);
1462 //=======================================================================
1463 //function : DeviationAngle
1464 //purpose : Gets deviationAngle
1465 //=======================================================================
1466 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1468 return myDefaultDrawer->DeviationAngle();
1471 //=======================================================================
1472 //function : DeviationCoefficient
1474 //=======================================================================
1475 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1477 return myDefaultDrawer->DeviationCoefficient();
1480 //=======================================================================
1481 //function : SetHLRDeviationCoefficient
1483 //=======================================================================
1484 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1486 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1489 //=======================================================================
1490 //function : HLRDeviationCoefficient
1492 //=======================================================================
1493 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1495 return myDefaultDrawer->HLRDeviationCoefficient();
1498 //=======================================================================
1499 //function : SetHLRAngle
1501 //=======================================================================
1502 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1504 myDefaultDrawer->SetHLRAngle (theAngle);
1507 //=======================================================================
1508 //function : SetHLRAngleAndDeviation
1509 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1510 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1511 // of myDefaultDrawer
1512 //=======================================================================
1513 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1515 Standard_Real anOutAngl, anOutDefl;
1516 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1518 myDefaultDrawer->SetHLRAngle (anOutAngl);
1519 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1522 //=======================================================================
1523 //function : HLRAngle
1525 //=======================================================================
1526 Standard_Real AIS_InteractiveContext::HLRAngle() const
1528 return myDefaultDrawer->HLRAngle();
1531 //=======================================================================
1532 //function : SetDisplayMode
1534 //=======================================================================
1535 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1536 const Standard_Boolean theToUpdateViewer)
1538 if (theMode == myDefaultDrawer->DisplayMode())
1543 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1545 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1546 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1547 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1548 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1551 || anObj->HasDisplayMode()
1552 || !anObj->AcceptDisplayMode (theMode))
1557 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1558 aStatus->SetDisplayMode (theMode);
1560 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1562 myMainPM->Display (anObj, theMode);
1563 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1565 myMainPM->BeginImmediateDraw();
1566 unhighlightGlobal (anObj);
1567 myMainPM->EndImmediateDraw (myMainVwr);
1569 if (aStatus->IsSubIntensityOn())
1571 highlightWithSubintensity (anObj, theMode);
1573 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1577 myDefaultDrawer->SetDisplayMode (theMode);
1578 if (theToUpdateViewer)
1580 myMainVwr->Update();
1584 //=======================================================================
1585 //function : SetDisplayMode
1587 //=======================================================================
1588 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1589 const Standard_Integer theMode,
1590 const Standard_Boolean theToUpdateViewer)
1592 setContextToObject (theIObj);
1593 if (!myObjects.IsBound (theIObj))
1595 theIObj->SetDisplayMode (theMode);
1598 else if (!theIObj->AcceptDisplayMode (theMode))
1603 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1604 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1606 aStatus->SetDisplayMode (theMode);
1607 theIObj->SetDisplayMode (theMode);
1611 // erase presentations for all display modes different from <aMode>
1612 const Standard_Integer anOldMode = aStatus->DisplayMode();
1613 if (anOldMode != theMode)
1615 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1617 unhighlightGlobal (theIObj);
1619 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1622 aStatus->SetDisplayMode (theMode);
1624 myMainPM->Display (theIObj, theMode);
1625 if (aStatus->IsHilighted())
1627 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1629 if (aStatus->IsSubIntensityOn())
1631 highlightWithSubintensity (theIObj, theMode);
1634 if (theToUpdateViewer)
1636 myMainVwr->Update();
1638 theIObj->SetDisplayMode (theMode);
1641 //=======================================================================
1642 //function : UnsetDisplayMode
1644 //=======================================================================
1645 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1646 const Standard_Boolean theToUpdateViewer)
1648 if (theIObj.IsNull()
1649 || !theIObj->HasDisplayMode())
1654 if (!myObjects.IsBound (theIObj))
1656 theIObj->UnsetDisplayMode();
1660 const Standard_Integer anOldMode = theIObj->DisplayMode();
1661 if (myDefaultDrawer->DisplayMode() == anOldMode)
1666 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1667 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1669 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1671 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1673 unhighlightGlobal (theIObj);
1675 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1676 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1677 if (aStatus->IsHilighted())
1679 highlightSelected (theIObj->GlobalSelOwner());
1681 if (aStatus->IsSubIntensityOn())
1683 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1686 if (theToUpdateViewer)
1688 myMainVwr->Update();
1692 theIObj->UnsetDisplayMode();
1695 //=======================================================================
1696 //function : SetCurrentFacingModel
1698 //=======================================================================
1699 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1700 const Aspect_TypeOfFacingModel theModel)
1702 if (!theIObj.IsNull())
1704 theIObj->SetCurrentFacingModel (theModel);
1708 //=======================================================================
1709 //function : redisplayPrsRecModes
1711 //=======================================================================
1712 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1713 const Standard_Boolean theToUpdateViewer)
1715 if (theIObj->RecomputeEveryPrs())
1717 theIObj->Update (Standard_True);
1718 theIObj->UpdateSelection();
1722 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1724 theIObj->Update (aModes.Value(), Standard_False);
1726 theIObj->UpdateSelection();
1727 theIObj->SetRecomputeOk();
1730 if (theToUpdateViewer)
1732 UpdateCurrentViewer();
1736 //=======================================================================
1737 //function : redisplayPrsModes
1739 //=======================================================================
1740 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1741 const Standard_Boolean theToUpdateViewer)
1743 if (theIObj->RecomputeEveryPrs())
1745 theIObj->Update (Standard_True);
1746 theIObj->UpdateSelection();
1750 TColStd_ListOfInteger aModes;
1751 theIObj->ToBeUpdated (aModes);
1752 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1754 theIObj->Update (aModeIter.Value(), Standard_False);
1756 theIObj->SetRecomputeOk();
1759 if (theToUpdateViewer)
1761 UpdateCurrentViewer();
1765 //=======================================================================
1766 //function : SetColor
1768 //=======================================================================
1769 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1770 const Quantity_NameOfColor theColor,
1771 const Standard_Boolean theToUpdateViewer)
1773 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1776 //=======================================================================
1777 //function : SetColor
1779 //=======================================================================
1780 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1781 const Quantity_Color& theColor,
1782 const Standard_Boolean theToUpdateViewer)
1784 if (theIObj.IsNull())
1789 setContextToObject (theIObj);
1790 theIObj->SetColor (theColor);
1791 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1794 //=======================================================================
1795 //function : SetIsoOnTriangulation
1797 //=======================================================================
1798 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1799 const Handle(AIS_InteractiveObject)& theObject)
1801 if (theObject.IsNull())
1806 theObject->SetIsoOnTriangulation (theIsEnabled);
1809 //=======================================================================
1810 //function : SetDeviationCoefficient
1812 //=======================================================================
1813 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1814 const Standard_Real theCoefficient,
1815 const Standard_Boolean theToUpdateViewer)
1817 if (theIObj.IsNull())
1822 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1823 setContextToObject (theIObj);
1824 if (theIObj->Type() != AIS_KOI_Object
1825 && theIObj->Type() != AIS_KOI_Shape)
1829 else if (theIObj->Signature() != 0)
1834 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1835 aShape->SetOwnDeviationCoefficient (theCoefficient);
1836 redisplayPrsModes (theIObj, theToUpdateViewer);
1839 //=======================================================================
1840 //function : SetHLRDeviationCoefficient
1842 //=======================================================================
1843 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1844 const Standard_Real theCoefficient,
1845 const Standard_Boolean theToUpdateViewer)
1847 if (theIObj.IsNull())
1852 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1853 setContextToObject (theIObj);
1854 if (theIObj->Type() != AIS_KOI_Object
1855 && theIObj->Type() != AIS_KOI_Shape)
1859 else if (theIObj->Signature() != 0)
1864 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1865 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1866 redisplayPrsModes (theIObj, theToUpdateViewer);
1869 //=======================================================================
1870 //function : SetDeviationAngle
1872 //=======================================================================
1873 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1874 const Standard_Real theAngle,
1875 const Standard_Boolean theToUpdateViewer)
1877 if (theIObj.IsNull())
1882 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1883 setContextToObject (theIObj);
1884 if (theIObj->Type() != AIS_KOI_Shape)
1888 else if (theIObj->Signature() != 0)
1893 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1894 aShape->SetOwnDeviationAngle (theAngle);
1895 redisplayPrsModes (theIObj, theToUpdateViewer);
1898 //=======================================================================
1899 //function : SetAngleAndDeviation
1901 //=======================================================================
1902 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1903 const Standard_Real theAngle,
1904 const Standard_Boolean theToUpdateViewer)
1906 if (theIObj.IsNull())
1911 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1912 setContextToObject (theIObj);
1913 if (theIObj->Type() != AIS_KOI_Shape)
1917 if (theIObj->Signature() != 0)
1922 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1923 aShape->SetAngleAndDeviation (theAngle);
1925 if (theIObj->RecomputeEveryPrs())
1927 theIObj->Update (Standard_True);
1928 theIObj->UpdateSelection();
1932 Update (theIObj, theToUpdateViewer);
1936 //=======================================================================
1937 //function : SetHLRAngleAndDeviation
1939 //=======================================================================
1940 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1941 const Standard_Real theAngle,
1942 const Standard_Boolean theToUpdateViewer)
1944 if (theIObj.IsNull())
1949 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1950 setContextToObject (theIObj);
1951 if (theIObj->Type() != AIS_KOI_Shape)
1955 if (theIObj->Signature() != 0)
1959 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1960 aShape->SetHLRAngleAndDeviation (theAngle);
1961 redisplayPrsModes (theIObj, theToUpdateViewer);
1964 //=======================================================================
1965 //function : SetHLRDeviationAngle
1967 //=======================================================================
1968 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1969 const Standard_Real theAngle,
1970 const Standard_Boolean theToUpdateViewer)
1972 if (theIObj.IsNull())
1977 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1978 setContextToObject (theIObj);
1979 if (theIObj->Type() != AIS_KOI_Shape)
1983 if (theIObj->Signature() != 0)
1987 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1988 aShape->SetOwnHLRDeviationAngle (theAngle);
1989 redisplayPrsModes (theIObj, theToUpdateViewer);
1992 //=======================================================================
1993 //function : UnsetColor
1995 //=======================================================================
1996 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1997 const Standard_Boolean theToUpdateViewer)
1999 if (theIObj.IsNull())
2004 theIObj->UnsetColor();
2005 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2008 //=======================================================================
2009 //function : HasColor
2011 //=======================================================================
2012 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2014 return theIObj->HasColor();
2017 //=======================================================================
2020 //=======================================================================
2021 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2023 return theIObj->Color();
2026 //=======================================================================
2029 //=======================================================================
2030 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2031 Quantity_Color& theColor) const
2033 theIObj->Color (theColor);
2036 //=======================================================================
2039 //=======================================================================
2040 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2042 return theIObj->Width();
2045 //=======================================================================
2046 //function : SetWidth
2048 //=======================================================================
2049 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2050 const Standard_Real theWidth,
2051 const Standard_Boolean theToUpdateViewer)
2053 if (theIObj.IsNull())
2058 setContextToObject (theIObj);
2059 theIObj->SetWidth (theWidth);
2060 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2061 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2063 if (myLastinMain->IsAutoHilight())
2065 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2066 myLastinMain->HilightWithColor (myMainPM,
2067 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2072 theIObj->HilightOwnerWithColor (myMainPM,
2073 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2079 //=======================================================================
2080 //function : UnsetWidth
2082 //=======================================================================
2083 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2084 const Standard_Boolean theToUpdateViewer)
2086 if (theIObj.IsNull())
2091 theIObj->UnsetWidth();
2092 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2095 //=======================================================================
2096 //function : SetMaterial
2098 //=======================================================================
2099 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2100 const Graphic3d_NameOfMaterial theName,
2101 const Standard_Boolean theToUpdateViewer)
2103 if (theIObj.IsNull())
2108 setContextToObject (theIObj);
2109 theIObj->SetMaterial (theName);
2110 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2113 //=======================================================================
2114 //function : UnsetMaterial
2116 //=======================================================================
2117 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2118 const Standard_Boolean theToUpdateViewer)
2120 if (theIObj.IsNull())
2124 theIObj->UnsetMaterial();
2125 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2128 //=======================================================================
2129 //function : SetTransparency
2131 //=======================================================================
2132 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2133 const Standard_Real theValue,
2134 const Standard_Boolean theToUpdateViewer)
2136 if (theIObj.IsNull())
2141 setContextToObject (theIObj);
2142 if (!theIObj->IsTransparent()
2143 && theValue <= 0.005)
2148 if (theValue <= 0.005)
2150 UnsetTransparency (theIObj, theToUpdateViewer);
2154 theIObj->SetTransparency (theValue);
2155 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2158 //=======================================================================
2159 //function : UnsetTransparency
2161 //=======================================================================
2162 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2163 const Standard_Boolean theToUpdateViewer)
2165 if (theIObj.IsNull())
2170 theIObj->UnsetTransparency();
2171 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2174 //=======================================================================
2175 //function : SetSelectedAspect
2177 //=======================================================================
2178 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2179 const Standard_Boolean ,
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(); ++aDetIter)
2424 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2426 && anObj != theIObj)
2428 myDetectedSeq.Remove (aDetIter);
2431 Standard_ENABLE_DEPRECATION_WARNINGS
2433 // remove IO from the selection manager to avoid memory leaks
2434 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2435 mgrSelector->Remove (anObj);
2437 myObjects.UnBind (theIObj);
2438 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2440 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2442 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2445 if (!myLastinMain.IsNull())
2447 if (myLastinMain->IsSameSelectable (theIObj)
2448 || myLastPicked->IsSameSelectable(theIObj))
2450 clearDynamicHighlight();
2451 myLastinMain.Nullify();
2455 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2457 myMainVwr->Update();
2461 //=======================================================================
2462 //function : ClearGlobalPrs
2464 //=======================================================================
2465 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2466 const Standard_Integer theMode,
2467 const Standard_Boolean theToUpdateViewer)
2469 if (theIObj.IsNull()
2470 || !myObjects.IsBound (theIObj))
2475 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2476 if (aStatus->DisplayMode() == theMode)
2478 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2479 if (aDispMode == theMode
2480 && myMainPM->IsHighlighted (theIObj, theMode))
2482 unhighlightGlobal (theIObj);
2485 myMainPM->Erase (theIObj, theMode);
2488 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2489 && theToUpdateViewer)
2491 myMainVwr->Update();
2495 //=======================================================================
2496 //function : DrawHiddenLine
2498 //=======================================================================
2499 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2501 return myDefaultDrawer->DrawHiddenLine();
2504 //=======================================================================
2505 //function : EnableDrawHiddenLine
2507 //=======================================================================
2508 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2510 myDefaultDrawer->EnableDrawHiddenLine();
2513 //=======================================================================
2514 //function : DisableDrawHiddenLine
2516 //=======================================================================
2517 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2519 myDefaultDrawer->DisableDrawHiddenLine();
2522 //=======================================================================
2523 //function : HiddenLineAspect
2525 //=======================================================================
2526 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2528 return myDefaultDrawer->HiddenLineAspect();
2531 //=======================================================================
2532 //function : SetHiddenLineAspect
2534 //=======================================================================
2535 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2537 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2540 //=======================================================================
2541 //function : SetIsoNumber
2543 //=======================================================================
2544 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2545 const AIS_TypeOfIso theType)
2550 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2553 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2556 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2557 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2562 //=======================================================================
2563 //function : IsoNumber
2565 //=======================================================================
2566 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2570 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2571 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2572 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2573 ? myDefaultDrawer->UIsoAspect()->Number()
2579 //=======================================================================
2580 //function : IsoOnPlane
2582 //=======================================================================
2583 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2585 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2588 //=======================================================================
2589 //function : IsoOnPlane
2591 //=======================================================================
2592 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2594 return myDefaultDrawer->IsoOnPlane();
2597 //=======================================================================
2598 //function : IsoOnTriangulation
2600 //=======================================================================
2601 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2603 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2606 //=======================================================================
2607 //function : IsoOnTriangulation
2609 //=======================================================================
2610 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2612 return myDefaultDrawer->IsoOnTriangulation();
2615 //function : SetPixelTolerance
2616 //purpose : Disables the mechanism of adaptive tolerance calculation in
2617 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2618 // sensitive entities activated. For more information, see
2619 // SelectMgr_ViewerSelector.hxx
2620 //=======================================================================
2621 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2623 if (HasOpenedContext())
2625 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2629 myMainSel->SetPixelTolerance (thePrecision);
2633 //=======================================================================
2634 //function : PixelTolerance
2636 //=======================================================================
2637 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2639 return HasOpenedContext()
2640 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2641 : myMainSel->PixelTolerance();
2644 //=======================================================================
2645 //function : SetSelectionSensitivity
2646 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2647 //=======================================================================
2648 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2649 const Standard_Integer theMode,
2650 const Standard_Integer theNewSensitivity)
2652 if (HasOpenedContext())
2654 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2658 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2661 //=======================================================================
2662 //function : IsInLocal
2664 //=======================================================================
2665 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2666 Standard_Integer& theIndex) const
2668 if (theIObj.IsNull())
2670 return Standard_False;
2673 // if it exists at neutral point 0 index is returned
2674 if (myObjects.IsBound (theIObj))
2677 return Standard_False;
2680 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2682 if (myLocalContexts.IsBound (aCtxIter))
2684 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2686 theIndex = aCtxIter;
2687 return Standard_True;
2692 return Standard_False;
2695 //=======================================================================
2696 //function : InitAttributes
2698 //=======================================================================
2699 void AIS_InteractiveContext::InitAttributes()
2701 mgrSelector->Add (myMainSel);
2703 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2704 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2706 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2707 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2708 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2709 aLineAspect->SetWidth (1.0);
2710 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2712 // tolerance to 2 pixels...
2713 SetPixelTolerance (2);
2715 // Customizing the drawer for trihedrons and planes...
2716 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2717 const Standard_Real aLength = 100.0;
2718 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2719 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2720 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2721 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2722 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2724 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2725 const Standard_Real aPlaneLength = 200.0;
2726 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2727 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2730 //=======================================================================
2731 //function : TrihedronSize
2733 //=======================================================================
2734 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2736 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2739 //=======================================================================
2740 //function : SetTrihedronSize
2742 //=======================================================================
2743 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2744 const Standard_Boolean /*updateviewer*/)
2746 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2747 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2748 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2751 //=======================================================================
2752 //function : SetPlaneSize
2754 //=======================================================================
2755 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2756 const Standard_Real theValY,
2757 const Standard_Boolean /*updateviewer*/)
2759 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2760 Redisplay (AIS_KOI_Datum, 7);
2763 //=======================================================================
2764 //function : SetPlaneSize
2766 //=======================================================================
2767 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2768 const Standard_Boolean theToUpdateViewer)
2770 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2773 //=======================================================================
2774 //function : PlaneSize
2776 //=======================================================================
2777 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2778 Standard_Real& theY) const
2780 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2781 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2782 return (Abs (theX - theY) <= Precision::Confusion());
2785 //=======================================================================
2786 //function : SetAutoActivateSelection
2788 //=======================================================================
2789 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2791 myIsAutoActivateSelMode = theIsAuto;
2794 //=======================================================================
2795 //function : GetAutoActivateSelection
2797 //=======================================================================
2798 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2800 return myIsAutoActivateSelMode;
2803 //=======================================================================
2804 //function : SetZLayer
2806 //=======================================================================
2807 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2808 const Standard_Integer theLayerId)
2810 if (theIObj.IsNull())
2813 theIObj->SetZLayer (theLayerId);
2816 //=======================================================================
2817 //function : GetZLayer
2819 //=======================================================================
2820 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2822 return !theIObj.IsNull()
2824 : Graphic3d_ZLayerId_UNKNOWN;
2827 //=======================================================================
2828 //function : RebuildSelectionStructs
2829 //purpose : Rebuilds 1st level of BVH selection forcibly
2830 //=======================================================================
2831 void AIS_InteractiveContext::RebuildSelectionStructs()
2833 myMainSel->RebuildObjectsTree (Standard_True);
2836 //=======================================================================
2837 //function : Disconnect
2838 //purpose : Disconnects selectable object from an assembly and updates selection structures
2839 //=======================================================================
2840 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2841 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2843 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2845 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2846 theObj->Disconnect (theObjToDisconnect);
2847 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2848 mgrSelector->Remove (anObj);
2850 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2852 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2853 theObj->Disconnect();
2854 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2855 mgrSelector->Remove (anObj);
2861 //=======================================================================
2862 //function : FitSelected
2863 //purpose : Fits the view corresponding to the bounds of selected objects
2864 //=======================================================================
2865 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2866 const Standard_Real theMargin,
2867 const Standard_Boolean theToUpdate)
2869 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2870 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2872 Bnd_Box aBndSelected;
2874 AIS_MapOfObjectOwners anObjectOwnerMap;
2875 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2877 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2878 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2879 if (anObj->IsInfinite())
2884 if (anOwner == anObj->GlobalSelOwner())
2887 anObj->BoundingBox (aTmpBnd);
2888 aBndSelected.Add (aTmpBnd);
2892 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2893 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2895 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2896 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2899 anOwnerMap->Add (anOwner);
2903 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2905 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2906 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2907 aBndSelected.Add (aTmpBox);
2910 anObjectOwnerMap.Clear();
2912 if (aBndSelected.IsVoid())
2915 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2918 //=======================================================================
2919 //function : SetTransformPersistence
2921 //=======================================================================
2922 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2923 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2925 theObject->SetTransformPersistence (theTrsfPers);
2926 if (!myObjects.IsBound (theObject))
2931 mgrSelector->UpdateSelection (theObject);
2933 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2934 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2935 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2937 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2938 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);