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 mgrSelector->Add (myMainSel);
126 myStyles[Prs3d_TypeOfHighlight_None] = myDefaultDrawer;
127 myStyles[Prs3d_TypeOfHighlight_Selected] = new Prs3d_Drawer();
128 myStyles[Prs3d_TypeOfHighlight_Dynamic] = new Prs3d_Drawer();
129 myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
130 myStyles[Prs3d_TypeOfHighlight_LocalDynamic] = new Prs3d_Drawer();
131 myStyles[Prs3d_TypeOfHighlight_SubIntensity] = new Prs3d_Drawer();
133 myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
134 myDefaultDrawer->SetDisplayMode(0);
136 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
137 aStyle->Link (myDefaultDrawer);
138 initDefaultHilightAttributes (aStyle);
139 aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
140 aStyle->SetColor (Quantity_NOC_CYAN1);
143 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
144 aStyle->Link (myDefaultDrawer);
145 initDefaultHilightAttributes (aStyle);
146 aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
147 aStyle->SetColor (Quantity_NOC_CYAN1);
150 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
151 aStyle->Link (myDefaultDrawer);
152 initDefaultHilightAttributes (aStyle);
153 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
154 aStyle->SetColor (Quantity_NOC_GRAY80);
157 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
158 aStyle->Link (myDefaultDrawer);
159 initDefaultHilightAttributes (aStyle);
160 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
161 aStyle->SetColor (Quantity_NOC_GRAY80);
164 const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
165 aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
166 aStyle->SetMethod(Aspect_TOHM_COLOR);
167 aStyle->SetColor (Quantity_NOC_GRAY40);
173 //=======================================================================
174 //function : ~AIS_InteractiveContext
176 //=======================================================================
177 AIS_InteractiveContext::~AIS_InteractiveContext()
179 // clear the current selection
180 mySelection->Clear();
182 // let's remove one reference explicitly. this operation's supposed to
183 // be performed when mgrSelector will be destroyed but anyway...
184 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
185 mgrSelector->Remove (aSelector);
187 Handle(AIS_InteractiveContext) aNullContext;
188 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
190 const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
191 anObj->SetContext (aNullContext);
192 for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
194 aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
199 //=======================================================================
200 //function : UpdateCurrentViewer
202 //=======================================================================
204 void AIS_InteractiveContext::UpdateCurrentViewer()
206 if (!myMainVwr.IsNull())
210 //=======================================================================
211 //function : DisplayedObjects
213 //=======================================================================
214 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
215 const Standard_Boolean theOnlyFromNeutral) const
217 if (!HasOpenedContext()
218 || theOnlyFromNeutral)
220 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
222 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
224 theListOfIO.Append (anObjIter.Key());
231 TColStd_MapOfTransient aDispMap;
232 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
234 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
236 aDispMap.Add (anObjIter.Key());
240 // parse all local contexts...
241 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
243 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
244 aLocCtx->DisplayedObjects (aDispMap);
247 Handle(AIS_InteractiveObject) anObj;
248 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
250 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
251 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
252 theListOfIO.Append (anObj);
256 //=======================================================================
257 //function : DisplayedObjects
259 //=======================================================================
260 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
261 const Standard_Integer theSign,
262 AIS_ListOfInteractive& theListOfIO,
263 const Standard_Boolean /*OnlyFromNeutral*/) const
265 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
268 //=======================================================================
269 //function : ErasedObjects
271 //=======================================================================
272 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
274 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
277 //=======================================================================
278 //function : ErasedObjects
280 //=======================================================================
281 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
282 const Standard_Integer theSign,
283 AIS_ListOfInteractive& theListOfIO) const
285 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
288 //=======================================================================
289 //function : ObjectsByDisplayStatus
291 //=======================================================================
292 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
293 AIS_ListOfInteractive& theListOfIO) const
295 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
297 if (anObjIter.Value()->GraphicStatus() == theStatus)
299 theListOfIO.Append (anObjIter.Key());
304 //=======================================================================
305 //function : ObjectsByDisplayStatus
307 //=======================================================================
308 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
309 const Standard_Integer theSign,
310 const AIS_DisplayStatus theStatus,
311 AIS_ListOfInteractive& theListOfIO) const
313 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
315 if (theStatus != AIS_DS_None
316 && anObjIter.Value()->GraphicStatus() != theStatus)
320 else if (anObjIter.Key()->Type() != theKind)
326 || anObjIter.Key()->Signature() == theSign)
328 theListOfIO.Append (anObjIter.Key());
333 //=======================================================================
334 //function : ObjectsInside
336 //=======================================================================
337 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
338 const AIS_KindOfInteractive theKind,
339 const Standard_Integer theSign) const
341 if (theKind == AIS_KOI_None
344 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
346 theListOfIO.Append (anObjIter.Key());
351 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
353 if (anObjIter.Key()->Type() != theKind)
359 || anObjIter.Key()->Signature() == theSign)
361 theListOfIO.Append (anObjIter.Key());
366 //=======================================================================
367 //function : ObjectsForView
369 //=======================================================================
370 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
371 const Handle(V3d_View)& theView,
372 const Standard_Boolean theIsVisibleInView,
373 const AIS_DisplayStatus theStatus) const
375 Handle(Graphic3d_CView) aViewImpl = theView->View();
376 const Standard_Integer aViewId = aViewImpl->Identification();
377 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
379 if (theStatus != AIS_DS_None
380 && anObjIter.Value()->GraphicStatus() != theStatus)
382 theListOfIO.Append (anObjIter.Key());
386 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
387 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
388 if (isVisible == theIsVisibleInView)
390 theListOfIO.Append (anObjIter.Key());
395 //=======================================================================
398 //=======================================================================
399 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
400 const Standard_Boolean theToUpdateViewer)
402 if (theIObj.IsNull())
407 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
408 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
410 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
411 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
414 //=======================================================================
415 //function : SetViewAffinity
417 //=======================================================================
418 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
419 const Handle(V3d_View)& theView,
420 const Standard_Boolean theIsVisible)
423 || !myObjects.IsBound (theIObj))
428 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
429 Handle(Graphic3d_CView) aViewImpl = theView->View();
430 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
433 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
437 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
441 //=======================================================================
444 //=======================================================================
445 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
446 const Standard_Integer theDispMode,
447 const Standard_Integer theSelectionMode,
448 const Standard_Boolean theToUpdateViewer,
449 const Standard_Boolean theToAllowDecomposition,
450 const AIS_DisplayStatus theDispStatus)
452 if (theIObj.IsNull())
457 if (theDispStatus == AIS_DS_Erased)
459 Erase (theIObj, theToUpdateViewer);
460 Load (theIObj, theSelectionMode, theToAllowDecomposition);
461 if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
463 (*aStatusPtr)->SetDisplayMode (theDispMode);
468 setContextToObject (theIObj);
469 if (theDispStatus == AIS_DS_Temporary
470 && !HasOpenedContext())
474 else if (HasOpenedContext())
476 if (theDispStatus == AIS_DS_None
477 || theDispStatus == AIS_DS_Temporary)
479 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
480 if (theToUpdateViewer)
488 if (!myObjects.IsBound (theIObj))
490 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
491 myObjects.Bind (theIObj, aStatus);
492 myMainVwr->StructureManager()->RegisterObject (theIObj);
493 myMainPM->Display(theIObj, theDispMode);
494 if (theSelectionMode != -1)
496 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
497 if (!mgrSelector->Contains (anObj))
499 mgrSelector->Load (theIObj);
501 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
506 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
507 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
512 // Mark the presentation modes hidden of interactive object different from aDispMode.
513 // Then make sure aDispMode is displayed and maybe highlighted.
514 // Finally, activate selection mode <SelMode> if not yet activated.
515 const Standard_Integer anOldMode = aStatus->DisplayMode();
516 if (anOldMode != theDispMode)
518 if(myMainPM->IsHighlighted (theIObj, anOldMode))
520 unhighlightGlobal (theIObj);
522 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
525 aStatus->SetDisplayMode (theDispMode);
527 myMainPM->Display (theIObj, theDispMode);
528 aStatus->SetGraphicStatus (AIS_DS_Displayed);
529 if (aStatus->IsHilighted())
531 highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
533 if (theSelectionMode != -1)
535 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
536 if (!mgrSelector->Contains (anObj))
538 mgrSelector->Load (theIObj);
540 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
542 if (!aStatus->IsSModeIn (theSelectionMode))
543 aStatus->AddSelectionMode (theSelectionMode);
544 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
549 if (theToUpdateViewer)
555 //=======================================================================
558 //=======================================================================
559 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
560 const Standard_Integer theSelMode,
561 const Standard_Boolean theToAllowDecomposition)
563 if (theIObj.IsNull())
568 setContextToObject (theIObj);
569 if (HasOpenedContext())
571 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
575 if (!myObjects.IsBound (theIObj))
577 Standard_Integer aDispMode, aHiMod, aSelModeDef;
578 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
579 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
580 myObjects.Bind (theIObj, aStatus);
581 myMainVwr->StructureManager()->RegisterObject (theIObj);
584 // Register theIObj in the selection manager to prepare further activation of selection
585 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
586 if (!mgrSelector->Contains (anObj))
588 mgrSelector->Load (theIObj);
592 //=======================================================================
595 //=======================================================================
596 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
597 const Standard_Boolean theToUpdateViewer)
599 if (theIObj.IsNull())
604 if (!theIObj->IsAutoHilight())
606 theIObj->ClearSelected();
609 Standard_Boolean wasInCtx = Standard_False;
610 if (HasOpenedContext())
612 // First it is checked if it is possible to remove in the current local context
613 // then one tries to remove in other local contexts, if they allow it...
614 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
615 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
617 if (aCtxIter.Value()->AcceptErase())
619 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
626 EraseGlobal (theIObj, Standard_False);
629 if (theToUpdateViewer)
635 //=======================================================================
636 //function : EraseAll
638 //=======================================================================
639 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
641 if (HasOpenedContext())
646 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
648 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
650 Erase (anObjIter.Key(), Standard_False);
654 if (theToUpdateViewer)
660 //=======================================================================
661 //function : DisplayAll
663 //=======================================================================
664 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
666 if (HasOpenedContext())
671 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
673 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
674 if (aStatus == AIS_DS_Erased)
676 Display (anObjIter.Key(), Standard_False);
680 if (theToUpdateViewer)
686 //=======================================================================
687 //function : DisplaySelected
689 //=======================================================================
690 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
692 if (HasOpenedContext())
697 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
699 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
700 Display (anObj, Standard_False);
703 if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
709 //=======================================================================
710 //function : EraseSelected
712 //=======================================================================
713 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
715 if (HasOpenedContext())
720 Standard_Boolean isFound = Standard_False;
721 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
723 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
724 Erase (anObj, Standard_False);
725 isFound = Standard_True;
728 if (isFound && theToUpdateViewer)
734 //=======================================================================
737 //=======================================================================
739 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
740 const Standard_Integer WhichContext)
742 if(anIObj.IsNull()) return Standard_False;
744 if(!HasOpenedContext()) return Standard_False;
745 if(myObjects.IsBound(anIObj)) return Standard_False;
746 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
748 // Protection : if one tries to preserve a temporary object
749 // which is not in the local active context... rob 11-06-97
751 Standard_Integer IsItInLocal = myCurLocalIndex;
752 Standard_Boolean Found(Standard_False);
754 while(IsItInLocal>0 && !Found){
755 if(!myLocalContexts.IsBound(IsItInLocal))
757 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
758 Found = Standard_True;
763 if(!Found) return Standard_False;
766 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
767 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
769 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
770 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
774 if(LS->IsTemporary()){
775 Standard_Integer DM,HM,SM;
776 GetDefModes(anIObj,DM,HM,SM);
778 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
779 if(LS->DisplayMode()!= DM ){
780 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
781 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
784 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
788 // GS->SubIntensityOn();
789 myObjects.Bind(anIObj,GS);
790 myMainVwr->StructureManager()->RegisterObject (anIObj);
791 mgrSelector->Load(anIObj);
792 mgrSelector->Activate(anIObj,SM,myMainSel);
794 LS->SetTemporary(Standard_False);
796 return Standard_True;
799 //=======================================================================
800 //function : DisplayStatus
802 //=======================================================================
803 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
805 if (theIObj.IsNull())
809 else if (myObjects.IsBound (theIObj))
811 return myObjects (theIObj)->GraphicStatus();
814 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
816 if (aCtxIter.Value()->IsIn (theIObj))
818 return AIS_DS_Temporary;
824 //=======================================================================
827 //=======================================================================
828 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
829 const Standard_Boolean theToUpdateViewer)
831 if (theIObj.IsNull())
836 if (theIObj->HasInteractiveContext())
838 if (theIObj->myCTXPtr != this)
840 throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
842 theIObj->SetContext (Handle(AIS_InteractiveContext)());
845 if (HasOpenedContext())
847 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
848 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
850 if (aCtxIter.Value()->AcceptErase())
852 aCtxIter.Value()->Remove (theIObj);
857 ClearGlobal (theIObj, theToUpdateViewer);
860 //=======================================================================
861 //function : RemoveAll
863 //=======================================================================
864 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
866 AIS_ListOfInteractive aList;
867 ObjectsInside (aList);
868 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
870 Remove (aListIterator.Value(), Standard_False);
873 if (theToUpdateViewer)
879 //=======================================================================
880 //function : ClearPrs
882 //=======================================================================
883 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
884 const Standard_Integer theMode,
885 const Standard_Boolean theToUpdateViewer)
887 if (theIObj.IsNull())
892 if (!HasOpenedContext())
894 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
898 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
899 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
901 if (aCtxIter.Value()->AcceptErase())
903 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
908 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
910 else if (theToUpdateViewer)
916 //=======================================================================
917 //function : HilightWithColor
919 //=======================================================================
920 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
921 const Handle(Prs3d_Drawer)& theStyle,
922 const Standard_Boolean theIsToUpdate)
927 setContextToObject (theObj);
928 if (!HasOpenedContext())
930 if (!myObjects.IsBound (theObj))
933 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
934 aStatus->SetHilightStatus (Standard_True);
936 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
938 highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
939 aStatus->SetHilightStyle (theStyle);
944 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
951 //=======================================================================
952 //function : Unhilight
954 //=======================================================================
955 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
957 if(anIObj.IsNull()) return;
959 if (!HasOpenedContext())
961 if(!myObjects.IsBound(anIObj)) return;
963 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
964 aStatus->SetHilightStatus (Standard_False);
965 aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
967 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
969 unhighlightGlobal (anIObj);
974 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
976 if(updateviewer) myMainVwr->Update();
979 //=======================================================================
980 //function : IsHilighted
981 //purpose : Returns true if the objects global status is set to highlighted.
982 //=======================================================================
983 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
985 if (!HasOpenedContext())
987 if (!myObjects.IsBound (theObj))
988 return Standard_False;
990 return myObjects (theObj)->IsHilighted();
993 Standard_DISABLE_DEPRECATION_WARNINGS
994 Standard_Integer aCtxIdx = HighestIndex();
995 Standard_ENABLE_DEPRECATION_WARNINGS
996 for (; aCtxIdx >= 1; aCtxIdx--)
998 if (myLocalContexts.IsBound (aCtxIdx))
1000 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
1001 return Standard_True;
1005 return Standard_False;
1008 //=======================================================================
1009 //function : IsHilighted
1010 //purpose : Returns true if the owner is highlighted with selection style.
1011 //=======================================================================
1012 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
1014 if (theOwner.IsNull() || !theOwner->HasSelectable())
1015 return Standard_False;
1017 const Handle(AIS_InteractiveObject) anObj =
1018 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1020 if (anObj->GlobalSelOwner() == theOwner)
1022 if (!myObjects.IsBound (anObj))
1023 return Standard_False;
1025 return myObjects (anObj)->IsHilighted();
1028 return theOwner->IsSelected();
1031 //=======================================================================
1032 //function : HighlightStyle
1034 //=======================================================================
1035 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
1036 Handle(Prs3d_Drawer)& theStyle) const
1038 if (HasOpenedContext())
1039 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
1041 if (IsHilighted (theObj))
1043 theStyle = myObjects (theObj)->HilightStyle();
1044 return Standard_True;
1049 return Standard_False;
1053 //=======================================================================
1054 //function : HighlightStyle
1056 //=======================================================================
1057 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
1058 Handle(Prs3d_Drawer)& theStyle) const
1060 if (theOwner.IsNull() || !theOwner->HasSelectable())
1061 return Standard_False;
1063 if (IsHilighted (theOwner))
1065 const Handle(AIS_InteractiveObject) anObj =
1066 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1067 if (anObj->GlobalSelOwner() == theOwner)
1069 theStyle = myObjects (anObj)->HilightStyle();
1073 // since part selection style is not stored in global status,
1074 // check if the object has own selection style. If not, it can
1075 // only be highlighted with default selection style (because
1076 // sub-intensity does not modify any selection states)
1077 theStyle = getSelStyle (anObj, theOwner);
1079 return Standard_True;
1084 return Standard_False;
1088 //=======================================================================
1089 //function : IsDisplayed
1091 //=======================================================================
1093 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1095 if(anIObj.IsNull()) return Standard_False;
1098 if(myObjects.IsBound(anIObj))
1099 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1100 return Standard_True;
1102 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1103 for(;ItM.More();ItM.Next()){
1104 if(ItM.Value()->IsDisplayed(anIObj))
1105 return Standard_True;
1107 return Standard_False;
1111 //=======================================================================
1112 //function : IsDisplayed
1114 //=======================================================================
1115 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1116 const Standard_Integer theMode) const
1118 if (theIObj.IsNull())
1120 return Standard_False;
1123 if (myObjects.IsBound (theIObj))
1125 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1126 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1127 && aStatus->DisplayMode() == theMode)
1129 return Standard_True;
1133 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1135 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1137 return Standard_True;
1140 return Standard_False;
1143 //=======================================================================
1144 //function : DisplayPriority
1146 //=======================================================================
1147 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1149 if (theIObj.IsNull())
1153 else if (!myObjects.IsBound (theIObj))
1158 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1159 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1160 || aStatus->GraphicStatus() == AIS_DS_Erased)
1162 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1163 ? theIObj->DisplayMode()
1164 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1165 ? myDefaultDrawer->DisplayMode()
1167 return myMainPM->DisplayPriority (theIObj, aDispMode);
1172 //=======================================================================
1173 //function : SetDisplayPriority
1175 //=======================================================================
1176 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1177 const Standard_Integer thePriority)
1179 if (theIObj.IsNull())
1184 setContextToObject (theIObj);
1185 if (myObjects.IsBound (theIObj))
1187 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1188 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1189 || aStatus->GraphicStatus() == AIS_DS_Erased)
1191 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1192 ? theIObj->DisplayMode()
1193 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1194 ? myDefaultDrawer->DisplayMode()
1196 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1199 else if (HasOpenedContext())
1201 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1205 //=======================================================================
1206 //function : Redisplay
1208 //=======================================================================
1209 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1210 const Standard_Boolean theToUpdateViewer,
1211 const Standard_Boolean theAllModes)
1213 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1214 RecomputeSelectionOnly (theIObj);
1217 //=======================================================================
1218 //function : Redisplay
1220 //=======================================================================
1221 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1222 const Standard_Integer /*theSign*/,
1223 const Standard_Boolean theToUpdateViewer)
1225 Standard_Boolean isRedisplayed = Standard_False;
1226 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1228 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1229 if (anObj->Type() != theKOI)
1234 Redisplay (anObj, Standard_False);
1235 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1239 if (theToUpdateViewer
1242 myMainVwr->Update();
1246 //=======================================================================
1247 //function : RecomputePrsOnly
1249 //=======================================================================
1250 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1251 const Standard_Boolean theToUpdateViewer,
1252 const Standard_Boolean theAllModes)
1254 if (theIObj.IsNull())
1259 theIObj->Update (theAllModes);
1260 if (!theToUpdateViewer)
1265 if (HasOpenedContext()
1266 || (myObjects.IsBound (theIObj)
1267 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1269 myMainVwr->Update();
1272 //=======================================================================
1273 //function : RecomputeSelectionOnly
1275 //=======================================================================
1276 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1283 mgrSelector->RecomputeSelection (theIO);
1285 if (HasOpenedContext())
1287 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1289 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1294 if (!myObjects.IsBound (theIO) ||
1295 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1300 TColStd_ListOfInteger aModes;
1301 ActivatedModes (theIO, aModes);
1302 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1303 for (; aModesIter.More(); aModesIter.Next())
1305 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1309 //=======================================================================
1312 //=======================================================================
1313 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1314 const Standard_Boolean theUpdateViewer)
1316 if (theIObj.IsNull())
1321 TColStd_ListOfInteger aPrsModes;
1322 theIObj->ToBeUpdated (aPrsModes);
1323 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1325 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1328 mgrSelector->Update(theIObj);
1330 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1332 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1335 if (theUpdateViewer)
1337 if (!myObjects.IsBound (theIObj))
1342 switch (myObjects (theIObj)->GraphicStatus())
1344 case AIS_DS_Displayed:
1345 case AIS_DS_Temporary:
1346 myMainVwr->Update();
1354 //=======================================================================
1355 //function : SetLocation
1357 //=======================================================================
1358 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1359 const TopLoc_Location& theLoc)
1361 if (theIObj.IsNull())
1366 if (theIObj->HasTransformation()
1367 && theLoc.IsIdentity())
1369 theIObj->ResetTransformation();
1370 mgrSelector->Update (theIObj, Standard_False);
1373 else if (theLoc.IsIdentity())
1378 // first reset the previous location to properly clean everything...
1379 if (theIObj->HasTransformation())
1381 theIObj->ResetTransformation();
1384 theIObj->SetLocalTransformation (theLoc.Transformation());
1386 if (!HasOpenedContext())
1388 mgrSelector->Update (theIObj, Standard_False);
1392 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1393 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1396 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1397 // to its highlight structure immediately
1398 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1400 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1401 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1407 //=======================================================================
1408 //function : ResetLocation
1410 //=======================================================================
1411 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1413 if (theIObj.IsNull())
1418 theIObj->ResetTransformation();
1419 mgrSelector->Update (theIObj, Standard_False);
1422 //=======================================================================
1423 //function : HasLocation
1425 //=======================================================================
1426 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1428 return !theIObj.IsNull()
1429 && theIObj->HasTransformation();
1432 //=======================================================================
1433 //function : Location
1435 //=======================================================================
1436 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1438 return theIObj->Transformation();
1441 //=======================================================================
1442 //function : SetDeviationCoefficient
1444 //=======================================================================
1445 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1447 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1450 //=======================================================================
1451 //function : SetDeviationAngle
1453 //=======================================================================
1454 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1456 myDefaultDrawer->SetDeviationAngle (theAngle);
1459 //=======================================================================
1460 //function : DeviationAngle
1461 //purpose : Gets deviationAngle
1462 //=======================================================================
1463 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1465 return myDefaultDrawer->DeviationAngle();
1468 //=======================================================================
1469 //function : DeviationCoefficient
1471 //=======================================================================
1472 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1474 return myDefaultDrawer->DeviationCoefficient();
1477 //=======================================================================
1478 //function : SetHLRDeviationCoefficient
1480 //=======================================================================
1481 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1483 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1486 //=======================================================================
1487 //function : HLRDeviationCoefficient
1489 //=======================================================================
1490 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1492 return myDefaultDrawer->HLRDeviationCoefficient();
1495 //=======================================================================
1496 //function : SetHLRAngle
1498 //=======================================================================
1499 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1501 myDefaultDrawer->SetHLRAngle (theAngle);
1504 //=======================================================================
1505 //function : SetHLRAngleAndDeviation
1506 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1507 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1508 // of myDefaultDrawer
1509 //=======================================================================
1510 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1512 Standard_Real anOutAngl, anOutDefl;
1513 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1515 myDefaultDrawer->SetHLRAngle (anOutAngl);
1516 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1519 //=======================================================================
1520 //function : HLRAngle
1522 //=======================================================================
1523 Standard_Real AIS_InteractiveContext::HLRAngle() const
1525 return myDefaultDrawer->HLRAngle();
1528 //=======================================================================
1529 //function : SetDisplayMode
1531 //=======================================================================
1532 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1533 const Standard_Boolean theToUpdateViewer)
1535 if (theMode == myDefaultDrawer->DisplayMode())
1540 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1542 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1543 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1544 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1545 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1548 || anObj->HasDisplayMode()
1549 || !anObj->AcceptDisplayMode (theMode))
1554 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1555 aStatus->SetDisplayMode (theMode);
1557 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1559 myMainPM->Display (anObj, theMode);
1560 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1562 myMainPM->BeginImmediateDraw();
1563 unhighlightGlobal (anObj);
1564 myMainPM->EndImmediateDraw (myMainVwr);
1566 if (aStatus->IsSubIntensityOn())
1568 highlightWithSubintensity (anObj, theMode);
1570 myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1574 myDefaultDrawer->SetDisplayMode (theMode);
1575 if (theToUpdateViewer)
1577 myMainVwr->Update();
1581 //=======================================================================
1582 //function : SetDisplayMode
1584 //=======================================================================
1585 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1586 const Standard_Integer theMode,
1587 const Standard_Boolean theToUpdateViewer)
1589 setContextToObject (theIObj);
1590 if (!myObjects.IsBound (theIObj))
1592 theIObj->SetDisplayMode (theMode);
1595 else if (!theIObj->AcceptDisplayMode (theMode))
1600 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1601 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1603 aStatus->SetDisplayMode (theMode);
1604 theIObj->SetDisplayMode (theMode);
1608 // erase presentations for all display modes different from <aMode>
1609 const Standard_Integer anOldMode = aStatus->DisplayMode();
1610 if (anOldMode != theMode)
1612 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1614 unhighlightGlobal (theIObj);
1616 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1619 aStatus->SetDisplayMode (theMode);
1621 myMainPM->Display (theIObj, theMode);
1622 if (aStatus->IsHilighted())
1624 highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1626 if (aStatus->IsSubIntensityOn())
1628 highlightWithSubintensity (theIObj, theMode);
1631 if (theToUpdateViewer)
1633 myMainVwr->Update();
1635 theIObj->SetDisplayMode (theMode);
1638 //=======================================================================
1639 //function : UnsetDisplayMode
1641 //=======================================================================
1642 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1643 const Standard_Boolean theToUpdateViewer)
1645 if (theIObj.IsNull()
1646 || !theIObj->HasDisplayMode())
1651 if (!myObjects.IsBound (theIObj))
1653 theIObj->UnsetDisplayMode();
1657 const Standard_Integer anOldMode = theIObj->DisplayMode();
1658 if (myDefaultDrawer->DisplayMode() == anOldMode)
1663 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1664 aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1666 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1668 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1670 unhighlightGlobal (theIObj);
1672 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1673 myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1674 if (aStatus->IsHilighted())
1676 highlightSelected (theIObj->GlobalSelOwner());
1678 if (aStatus->IsSubIntensityOn())
1680 highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1683 if (theToUpdateViewer)
1685 myMainVwr->Update();
1689 theIObj->UnsetDisplayMode();
1692 //=======================================================================
1693 //function : SetCurrentFacingModel
1695 //=======================================================================
1696 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1697 const Aspect_TypeOfFacingModel theModel)
1699 if (!theIObj.IsNull())
1701 theIObj->SetCurrentFacingModel (theModel);
1705 //=======================================================================
1706 //function : redisplayPrsRecModes
1708 //=======================================================================
1709 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1710 const Standard_Boolean theToUpdateViewer)
1712 if (theIObj->RecomputeEveryPrs())
1714 theIObj->Update (Standard_True);
1715 theIObj->UpdateSelection();
1719 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1721 theIObj->Update (aModes.Value(), Standard_False);
1723 theIObj->UpdateSelection();
1724 theIObj->SetRecomputeOk();
1727 if (theToUpdateViewer)
1729 UpdateCurrentViewer();
1733 //=======================================================================
1734 //function : redisplayPrsModes
1736 //=======================================================================
1737 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1738 const Standard_Boolean theToUpdateViewer)
1740 if (theIObj->RecomputeEveryPrs())
1742 theIObj->Update (Standard_True);
1743 theIObj->UpdateSelection();
1747 TColStd_ListOfInteger aModes;
1748 theIObj->ToBeUpdated (aModes);
1749 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1751 theIObj->Update (aModeIter.Value(), Standard_False);
1753 theIObj->SetRecomputeOk();
1756 if (theToUpdateViewer)
1758 UpdateCurrentViewer();
1762 //=======================================================================
1763 //function : SetColor
1765 //=======================================================================
1766 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1767 const Quantity_Color& theColor,
1768 const Standard_Boolean theToUpdateViewer)
1770 if (theIObj.IsNull())
1775 setContextToObject (theIObj);
1776 theIObj->SetColor (theColor);
1777 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1780 //=======================================================================
1781 //function : SetIsoOnTriangulation
1783 //=======================================================================
1784 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1785 const Handle(AIS_InteractiveObject)& theObject)
1787 if (theObject.IsNull())
1792 theObject->SetIsoOnTriangulation (theIsEnabled);
1795 //=======================================================================
1796 //function : SetDeviationCoefficient
1798 //=======================================================================
1799 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1800 const Standard_Real theCoefficient,
1801 const Standard_Boolean theToUpdateViewer)
1803 if (theIObj.IsNull())
1808 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1809 setContextToObject (theIObj);
1810 if (theIObj->Type() != AIS_KOI_Object
1811 && theIObj->Type() != AIS_KOI_Shape)
1815 else if (theIObj->Signature() != 0)
1820 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1821 aShape->SetOwnDeviationCoefficient (theCoefficient);
1822 redisplayPrsModes (theIObj, theToUpdateViewer);
1825 //=======================================================================
1826 //function : SetHLRDeviationCoefficient
1828 //=======================================================================
1829 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1830 const Standard_Real theCoefficient,
1831 const Standard_Boolean theToUpdateViewer)
1833 if (theIObj.IsNull())
1838 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1839 setContextToObject (theIObj);
1840 if (theIObj->Type() != AIS_KOI_Object
1841 && theIObj->Type() != AIS_KOI_Shape)
1845 else if (theIObj->Signature() != 0)
1850 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1851 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1852 redisplayPrsModes (theIObj, theToUpdateViewer);
1855 //=======================================================================
1856 //function : SetDeviationAngle
1858 //=======================================================================
1859 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1860 const Standard_Real theAngle,
1861 const Standard_Boolean theToUpdateViewer)
1863 if (theIObj.IsNull())
1868 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1869 setContextToObject (theIObj);
1870 if (theIObj->Type() != AIS_KOI_Shape)
1874 else if (theIObj->Signature() != 0)
1879 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1880 aShape->SetOwnDeviationAngle (theAngle);
1881 redisplayPrsModes (theIObj, theToUpdateViewer);
1884 //=======================================================================
1885 //function : SetAngleAndDeviation
1887 //=======================================================================
1888 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1889 const Standard_Real theAngle,
1890 const Standard_Boolean theToUpdateViewer)
1892 if (theIObj.IsNull())
1897 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1898 setContextToObject (theIObj);
1899 if (theIObj->Type() != AIS_KOI_Shape)
1903 if (theIObj->Signature() != 0)
1908 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1909 aShape->SetAngleAndDeviation (theAngle);
1911 if (theIObj->RecomputeEveryPrs())
1913 theIObj->Update (Standard_True);
1914 theIObj->UpdateSelection();
1918 Update (theIObj, theToUpdateViewer);
1922 //=======================================================================
1923 //function : SetHLRAngleAndDeviation
1925 //=======================================================================
1926 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1927 const Standard_Real theAngle,
1928 const Standard_Boolean theToUpdateViewer)
1930 if (theIObj.IsNull())
1935 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1936 setContextToObject (theIObj);
1937 if (theIObj->Type() != AIS_KOI_Shape)
1941 if (theIObj->Signature() != 0)
1945 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1946 aShape->SetHLRAngleAndDeviation (theAngle);
1947 redisplayPrsModes (theIObj, theToUpdateViewer);
1950 //=======================================================================
1951 //function : SetHLRDeviationAngle
1953 //=======================================================================
1954 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1955 const Standard_Real theAngle,
1956 const Standard_Boolean theToUpdateViewer)
1958 if (theIObj.IsNull())
1963 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1964 setContextToObject (theIObj);
1965 if (theIObj->Type() != AIS_KOI_Shape)
1969 if (theIObj->Signature() != 0)
1973 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1974 aShape->SetOwnHLRDeviationAngle (theAngle);
1975 redisplayPrsModes (theIObj, theToUpdateViewer);
1978 //=======================================================================
1979 //function : UnsetColor
1981 //=======================================================================
1982 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1983 const Standard_Boolean theToUpdateViewer)
1985 if (theIObj.IsNull())
1990 theIObj->UnsetColor();
1991 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1994 //=======================================================================
1995 //function : HasColor
1997 //=======================================================================
1998 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2000 return theIObj->HasColor();
2003 //=======================================================================
2006 //=======================================================================
2007 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2008 Quantity_Color& theColor) const
2010 theIObj->Color (theColor);
2013 //=======================================================================
2016 //=======================================================================
2017 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2019 return theIObj->Width();
2022 //=======================================================================
2023 //function : SetWidth
2025 //=======================================================================
2026 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2027 const Standard_Real theWidth,
2028 const Standard_Boolean theToUpdateViewer)
2030 if (theIObj.IsNull())
2035 setContextToObject (theIObj);
2036 theIObj->SetWidth (theWidth);
2037 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2038 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2040 if (myLastinMain->IsAutoHilight())
2042 const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2043 myLastinMain->HilightWithColor (myMainPM,
2044 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2049 theIObj->HilightOwnerWithColor (myMainPM,
2050 myLastinMain->IsSelected() ? getSelStyle (theIObj, myLastinMain) : getHiStyle (theIObj, myLastinMain),
2056 //=======================================================================
2057 //function : UnsetWidth
2059 //=======================================================================
2060 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2061 const Standard_Boolean theToUpdateViewer)
2063 if (theIObj.IsNull())
2068 theIObj->UnsetWidth();
2069 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2072 //=======================================================================
2073 //function : SetMaterial
2075 //=======================================================================
2076 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2077 const Graphic3d_MaterialAspect& theMaterial,
2078 const Standard_Boolean theToUpdateViewer)
2080 if (theIObj.IsNull())
2085 setContextToObject (theIObj);
2086 theIObj->SetMaterial (theMaterial);
2087 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2090 //=======================================================================
2091 //function : UnsetMaterial
2093 //=======================================================================
2094 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2095 const Standard_Boolean theToUpdateViewer)
2097 if (theIObj.IsNull())
2101 theIObj->UnsetMaterial();
2102 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2105 //=======================================================================
2106 //function : SetTransparency
2108 //=======================================================================
2109 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2110 const Standard_Real theValue,
2111 const Standard_Boolean theToUpdateViewer)
2113 if (theIObj.IsNull())
2118 setContextToObject (theIObj);
2119 if (!theIObj->IsTransparent()
2120 && theValue <= 0.005)
2125 if (theValue <= 0.005)
2127 UnsetTransparency (theIObj, theToUpdateViewer);
2131 theIObj->SetTransparency (theValue);
2132 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2135 //=======================================================================
2136 //function : UnsetTransparency
2138 //=======================================================================
2139 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2140 const Standard_Boolean theToUpdateViewer)
2142 if (theIObj.IsNull())
2147 theIObj->UnsetTransparency();
2148 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2151 //=======================================================================
2152 //function : SetSelectedAspect
2154 //=======================================================================
2155 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2156 const Standard_Boolean theToUpdateViewer)
2158 if (HasOpenedContext())
2163 Standard_Boolean isFound = Standard_False;
2164 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2166 isFound = Standard_True;
2167 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2168 anObj->SetAspect (theAspect);
2171 if (isFound && theToUpdateViewer)
2173 myMainVwr->Update();
2177 //=======================================================================
2178 //function : SetLocalAttributes
2180 //=======================================================================
2181 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2182 const Handle(Prs3d_Drawer)& theDrawer,
2183 const Standard_Boolean theToUpdateViewer)
2185 if (theIObj.IsNull())
2190 setContextToObject (theIObj);
2191 theIObj->SetAttributes (theDrawer);
2192 Update (theIObj, theToUpdateViewer);
2195 //=======================================================================
2196 //function : UnsetLocalAttributes
2198 //=======================================================================
2199 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2200 const Standard_Boolean theToUpdateViewer)
2202 if (theIObj.IsNull())
2207 setContextToObject (theIObj);
2208 theIObj->UnsetAttributes();
2209 Update (theIObj, theToUpdateViewer);
2212 //=======================================================================
2215 //=======================================================================
2216 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2217 TCollection_ExtendedString& theStatus) const
2220 if (theIObj.IsNull()
2221 || !myObjects.IsBound (theIObj))
2226 theStatus += "\t ____________________________________________";
2227 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2228 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2229 switch (aStatus->GraphicStatus())
2231 case AIS_DS_Displayed:
2233 theStatus += "\t| -->Displayed\n";
2238 theStatus += "\t| -->Erased\n";
2245 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2246 theStatus += "\t|\t Mode ";
2247 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2250 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2252 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2253 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2255 theStatus += "\t\t Mode ";
2256 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2259 theStatus += "\t ____________________________________________";
2262 //=======================================================================
2263 //function : GetDefModes
2265 //=======================================================================
2266 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2267 Standard_Integer& theDispMode,
2268 Standard_Integer& theHiMode,
2269 Standard_Integer& theSelMode) const
2271 if (theIObj.IsNull())
2276 theDispMode = theIObj->HasDisplayMode()
2277 ? theIObj->DisplayMode()
2278 : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
2279 ? myDefaultDrawer->DisplayMode()
2281 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2282 theSelMode = theIObj->GlobalSelectionMode();
2285 //=======================================================================
2286 //function : EraseGlobal
2288 //=======================================================================
2289 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2290 const Standard_Boolean theToUpdateviewer)
2292 if (theIObj.IsNull()
2293 || !myObjects.IsBound (theIObj))
2298 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2300 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2301 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2302 || aStatus->GraphicStatus() == AIS_DS_Erased)
2307 if (aStatus->IsHilighted())
2309 Standard_DISABLE_DEPRECATION_WARNINGS
2310 if (IsCurrent (theIObj))
2312 AddOrRemoveCurrentObject (theIObj, Standard_False);
2314 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2316 unhighlightGlobal (theIObj);
2318 Standard_ENABLE_DEPRECATION_WARNINGS
2321 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2323 if (aStatus->IsHilighted()
2324 && theIObj->HasHilightMode())
2326 unhighlightGlobal (theIObj);
2329 if (!myLastPicked.IsNull()
2330 && myLastPicked->IsSameSelectable (theIObj))
2332 clearDynamicHighlight();
2335 // make sure highlighting presentations are properly erased
2336 theIObj->ErasePresentations (false);
2338 if (IsSelected (theIObj)
2339 && aStatus->DisplayMode() != aDispMode)
2341 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2344 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2346 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2348 aStatus->ClearSelectionModes();
2349 aStatus->SetGraphicStatus (AIS_DS_Erased);
2351 if (theToUpdateviewer)
2353 myMainVwr->Update();
2357 //=======================================================================
2358 //function : unhighlightOwners
2360 //=======================================================================
2361 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2363 SelectMgr_SequenceOfOwner aSeq;
2364 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2366 if (aSelIter.Value()->IsSameSelectable (theObject))
2368 aSeq.Append (aSelIter.Value());
2371 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2373 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2377 //=======================================================================
2378 //function : ClearGlobal
2380 //=======================================================================
2381 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2382 const Standard_Boolean theToUpdateviewer)
2384 if (theIObj.IsNull()
2385 || !myObjects.IsBound (theIObj))
2387 // for cases when reference shape of connected interactives was not displayed
2388 // but its selection primitives were calculated
2389 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2390 mgrSelector->Remove (anObj);
2394 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2395 unhighlightOwners (theIObj);
2397 myMainPM->Erase (theIObj, -1);
2398 theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2400 // Object removes from Detected sequence
2401 Standard_DISABLE_DEPRECATION_WARNINGS
2402 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2404 Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2405 Handle(AIS_InteractiveObject) anObj;
2406 if (!aPicked.IsNull())
2408 anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2412 && anObj == theIObj)
2414 myDetectedSeq.Remove (aDetIter);
2415 if (myCurDetected == aDetIter)
2417 myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2419 if (myCurHighlighted == aDetIter)
2421 myCurHighlighted = 0;
2429 Standard_ENABLE_DEPRECATION_WARNINGS
2431 // remove IO from the selection manager to avoid memory leaks
2432 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2433 mgrSelector->Remove (anObj);
2435 myObjects.UnBind (theIObj);
2436 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2438 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2440 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2443 if (!myLastinMain.IsNull())
2445 if (myLastinMain->IsSameSelectable (theIObj)
2446 || myLastPicked->IsSameSelectable(theIObj))
2448 clearDynamicHighlight();
2449 myLastinMain.Nullify();
2450 myLastPicked.Nullify();
2454 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2456 myMainVwr->Update();
2460 //=======================================================================
2461 //function : ClearGlobalPrs
2463 //=======================================================================
2464 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2465 const Standard_Integer theMode,
2466 const Standard_Boolean theToUpdateViewer)
2468 if (theIObj.IsNull()
2469 || !myObjects.IsBound (theIObj))
2474 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2475 if (aStatus->DisplayMode() == theMode)
2477 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2478 if (aDispMode == theMode
2479 && myMainPM->IsHighlighted (theIObj, theMode))
2481 unhighlightGlobal (theIObj);
2484 myMainPM->Erase (theIObj, theMode);
2487 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2488 && theToUpdateViewer)
2490 myMainVwr->Update();
2494 //=======================================================================
2495 //function : DrawHiddenLine
2497 //=======================================================================
2498 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2500 return myDefaultDrawer->DrawHiddenLine();
2503 //=======================================================================
2504 //function : EnableDrawHiddenLine
2506 //=======================================================================
2507 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2509 myDefaultDrawer->EnableDrawHiddenLine();
2512 //=======================================================================
2513 //function : DisableDrawHiddenLine
2515 //=======================================================================
2516 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2518 myDefaultDrawer->DisableDrawHiddenLine();
2521 //=======================================================================
2522 //function : HiddenLineAspect
2524 //=======================================================================
2525 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2527 return myDefaultDrawer->HiddenLineAspect();
2530 //=======================================================================
2531 //function : SetHiddenLineAspect
2533 //=======================================================================
2534 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2536 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2539 //=======================================================================
2540 //function : SetIsoNumber
2542 //=======================================================================
2543 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2544 const AIS_TypeOfIso theType)
2549 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2552 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2555 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2556 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2561 //=======================================================================
2562 //function : IsoNumber
2564 //=======================================================================
2565 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2569 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2570 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2571 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2572 ? myDefaultDrawer->UIsoAspect()->Number()
2578 //=======================================================================
2579 //function : IsoOnPlane
2581 //=======================================================================
2582 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2584 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2587 //=======================================================================
2588 //function : IsoOnPlane
2590 //=======================================================================
2591 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2593 return myDefaultDrawer->IsoOnPlane();
2596 //=======================================================================
2597 //function : IsoOnTriangulation
2599 //=======================================================================
2600 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2602 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2605 //=======================================================================
2606 //function : IsoOnTriangulation
2608 //=======================================================================
2609 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2611 return myDefaultDrawer->IsoOnTriangulation();
2614 //=======================================================================
2615 //function : SetPixelTolerance
2617 //=======================================================================
2618 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2620 if (HasOpenedContext())
2622 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2626 myMainSel->SetPixelTolerance (thePrecision);
2630 //=======================================================================
2631 //function : PixelTolerance
2633 //=======================================================================
2634 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2636 return HasOpenedContext()
2637 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2638 : myMainSel->PixelTolerance();
2641 //=======================================================================
2642 //function : SetSelectionSensitivity
2643 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2644 //=======================================================================
2645 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2646 const Standard_Integer theMode,
2647 const Standard_Integer theNewSensitivity)
2649 if (HasOpenedContext())
2651 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2655 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2658 //=======================================================================
2659 //function : IsInLocal
2661 //=======================================================================
2662 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2663 Standard_Integer& theIndex) const
2665 if (theIObj.IsNull())
2667 return Standard_False;
2670 // if it exists at neutral point 0 index is returned
2671 if (myObjects.IsBound (theIObj))
2674 return Standard_False;
2677 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2679 if (myLocalContexts.IsBound (aCtxIter))
2681 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2683 theIndex = aCtxIter;
2684 return Standard_True;
2689 return Standard_False;
2692 //=======================================================================
2693 //function : InitAttributes
2695 //=======================================================================
2696 void AIS_InteractiveContext::InitAttributes()
2699 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2700 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2702 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2703 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2704 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2705 aLineAspect->SetWidth (1.0);
2706 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2708 // tolerance to 2 pixels...
2709 SetPixelTolerance (2);
2711 // Customizing the drawer for trihedrons and planes...
2712 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2713 const Standard_Real aLength = 100.0;
2714 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2715 const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2716 aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2717 aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2718 aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2720 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2721 const Standard_Real aPlaneLength = 200.0;
2722 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2723 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2726 //=======================================================================
2727 //function : TrihedronSize
2729 //=======================================================================
2730 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2732 return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2735 //=======================================================================
2736 //function : SetTrihedronSize
2738 //=======================================================================
2739 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2740 const Standard_Boolean /*updateviewer*/)
2742 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2743 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2744 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2747 //=======================================================================
2748 //function : SetPlaneSize
2750 //=======================================================================
2751 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2752 const Standard_Real theValY,
2753 const Standard_Boolean theToUpdateViewer)
2755 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2756 Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2759 //=======================================================================
2760 //function : SetPlaneSize
2762 //=======================================================================
2763 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2764 const Standard_Boolean theToUpdateViewer)
2766 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2769 //=======================================================================
2770 //function : PlaneSize
2772 //=======================================================================
2773 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2774 Standard_Real& theY) const
2776 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2777 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2778 return (Abs (theX - theY) <= Precision::Confusion());
2781 //=======================================================================
2782 //function : SetZLayer
2784 //=======================================================================
2785 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2786 const Standard_Integer theLayerId)
2788 if (theIObj.IsNull())
2791 theIObj->SetZLayer (theLayerId);
2794 //=======================================================================
2795 //function : GetZLayer
2797 //=======================================================================
2798 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2800 return !theIObj.IsNull()
2802 : Graphic3d_ZLayerId_UNKNOWN;
2805 //=======================================================================
2806 //function : RebuildSelectionStructs
2807 //purpose : Rebuilds 1st level of BVH selection forcibly
2808 //=======================================================================
2809 void AIS_InteractiveContext::RebuildSelectionStructs()
2811 myMainSel->RebuildObjectsTree (Standard_True);
2814 //=======================================================================
2815 //function : Disconnect
2816 //purpose : Disconnects selectable object from an assembly and updates selection structures
2817 //=======================================================================
2818 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2819 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2821 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2823 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2824 theObj->Disconnect (theObjToDisconnect);
2825 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2826 mgrSelector->Remove (anObj);
2828 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2830 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2831 theObj->Disconnect();
2832 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2833 mgrSelector->Remove (anObj);
2839 //=======================================================================
2840 //function : FitSelected
2841 //purpose : Fits the view corresponding to the bounds of selected objects
2842 //=======================================================================
2843 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2845 FitSelected (theView, 0.01, Standard_True);
2848 //=======================================================================
2849 //function : FitSelected
2850 //purpose : Fits the view corresponding to the bounds of selected objects
2851 //=======================================================================
2852 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2853 const Standard_Real theMargin,
2854 const Standard_Boolean theToUpdate)
2856 const Handle(AIS_Selection)& aSelection = HasOpenedContext()
2857 ? myLocalContexts(myCurLocalIndex)->Selection()
2859 Bnd_Box aBndSelected;
2860 AIS_MapOfObjectOwners anObjectOwnerMap;
2861 for (AIS_NListOfEntityOwner::Iterator aSelIter (aSelection->Objects()); aSelIter.More(); aSelIter.Next())
2863 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2864 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2865 if (anObj->IsInfinite())
2870 if (anOwner == anObj->GlobalSelOwner())
2873 anObj->BoundingBox (aTmpBnd);
2874 aBndSelected.Add (aTmpBnd);
2878 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2879 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2881 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2882 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2885 anOwnerMap->Add (anOwner);
2889 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2891 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2892 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2893 aBndSelected.Add (aTmpBox);
2896 anObjectOwnerMap.Clear();
2898 if (aBndSelected.IsVoid())
2901 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2904 //=======================================================================
2905 //function : SetTransformPersistence
2907 //=======================================================================
2908 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2909 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2911 theObject->SetTransformPersistence (theTrsfPers);
2912 if (!myObjects.IsBound (theObject))
2917 mgrSelector->UpdateSelection (theObject);
2919 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2920 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2921 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2923 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2924 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);