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 // Modified by XAB & Serguei Dec 97 (angle &deviation coeffts)
19 #include <AIS_ConnectedInteractive.hxx>
20 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
21 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
22 #include <AIS_GlobalStatus.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <AIS_LocalContext.hxx>
27 #include <AIS_LocalStatus.hxx>
28 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
29 #include <AIS_MultipleConnectedInteractive.hxx>
30 #include <AIS_Shape.hxx>
31 #include <AIS_Trihedron.hxx>
32 #include <Geom_Axis2Placement.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <HLRBRep.hxx>
35 #include <OSD_Environment.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_BasicAspect.hxx>
38 #include <Prs3d_DatumAspect.hxx>
39 #include <Prs3d_IsoAspect.hxx>
40 #include <Prs3d_LineAspect.hxx>
41 #include <Prs3d_PlaneAspect.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,MMgt_TShared)
66 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
69 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
70 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
73 //=======================================================================
74 //function : AIS_InteractiveContext
76 //=======================================================================
78 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
79 mgrSelector(new SelectMgr_SelectionManager()),
80 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
81 myMainVwr(MainViewer),
82 myMainSel(new StdSelect_ViewerSelector3d()),
83 myWasLastMain(Standard_False),
84 myCurrentTouched(Standard_False),
85 mySelectedTouched(Standard_False),
86 myToHilightSelected(Standard_True),
87 myFilters(new SelectMgr_OrFilter()),
88 myDefaultDrawer(new Prs3d_Drawer()),
89 mySelection(new AIS_Selection()),
90 myDefaultColor(Quantity_NOC_GOLDENROD),
91 myHiStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_CYAN1)),
92 mySelStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY80)),
93 myPreselectionColor(Quantity_NOC_GREEN),
94 mySubintStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY40)),
99 myIsAutoActivateSelMode(Standard_True)
104 void AIS_InteractiveContext::Delete() const
106 // clear the current selection
107 mySelection->Clear();
109 // let's remove one reference explicitly. this operation's supposed to
110 // be performed when mgrSelector will be destroyed but anyway...
111 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
112 mgrSelector->Remove (aSelector);
114 Handle(AIS_InteractiveContext) aNullContext;
115 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
117 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
118 anObj->SetContext (aNullContext);
119 for (anObj->Init(); anObj->More(); anObj->Next())
121 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
124 MMgt_TShared::Delete();
127 //=======================================================================
128 //function : UpdateCurrentViewer
130 //=======================================================================
132 void AIS_InteractiveContext::UpdateCurrentViewer()
134 if (!myMainVwr.IsNull())
138 //=======================================================================
139 //function : DisplayedObjects
141 //=======================================================================
142 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
143 const Standard_Boolean theOnlyFromNeutral) const
145 if (!HasOpenedContext()
146 || theOnlyFromNeutral)
148 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
150 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
152 theListOfIO.Append (anObjIter.Key());
159 TColStd_MapOfTransient aDispMap;
160 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
162 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
164 aDispMap.Add (anObjIter.Key());
168 // parse all local contexts...
169 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
171 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
172 aLocCtx->DisplayedObjects (aDispMap);
175 Handle(AIS_InteractiveObject) anObj;
176 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
178 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
179 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
180 theListOfIO.Append (anObj);
184 //=======================================================================
185 //function : DisplayedObjects
187 //=======================================================================
188 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
189 const Standard_Integer theSign,
190 AIS_ListOfInteractive& theListOfIO,
191 const Standard_Boolean /*OnlyFromNeutral*/) const
193 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
196 //=======================================================================
197 //function : ErasedObjects
199 //=======================================================================
200 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
202 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
205 //=======================================================================
206 //function : ErasedObjects
208 //=======================================================================
209 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
210 const Standard_Integer theSign,
211 AIS_ListOfInteractive& theListOfIO) const
213 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
216 //=======================================================================
217 //function : ObjectsByDisplayStatus
219 //=======================================================================
220 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
221 AIS_ListOfInteractive& theListOfIO) const
223 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
225 if (anObjIter.Value()->GraphicStatus() == theStatus)
227 theListOfIO.Append (anObjIter.Key());
232 //=======================================================================
233 //function : ObjectsByDisplayStatus
235 //=======================================================================
236 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
237 const Standard_Integer theSign,
238 const AIS_DisplayStatus theStatus,
239 AIS_ListOfInteractive& theListOfIO) const
241 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
243 if (theStatus != AIS_DS_None
244 && anObjIter.Value()->GraphicStatus() != theStatus)
248 else if (anObjIter.Key()->Type() != theKind)
254 || anObjIter.Key()->Signature() == theSign)
256 theListOfIO.Append (anObjIter.Key());
261 //=======================================================================
262 //function : ObjectsInside
264 //=======================================================================
265 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
266 const AIS_KindOfInteractive theKind,
267 const Standard_Integer theSign) const
269 if (theKind == AIS_KOI_None
272 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
274 theListOfIO.Append (anObjIter.Key());
279 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
281 if (anObjIter.Key()->Type() != theKind)
287 || anObjIter.Key()->Signature() == theSign)
289 theListOfIO.Append (anObjIter.Key());
294 //=======================================================================
295 //function : ObjectsForView
297 //=======================================================================
298 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
299 const Handle(V3d_View)& theView,
300 const Standard_Boolean theIsVisibleInView,
301 const AIS_DisplayStatus theStatus) const
303 Handle(Graphic3d_CView) aViewImpl = theView->View();
304 const Standard_Integer aViewId = aViewImpl->Identification();
305 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
307 if (theStatus != AIS_DS_None
308 && anObjIter.Value()->GraphicStatus() != theStatus)
310 theListOfIO.Append (anObjIter.Key());
314 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
315 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
316 if (isVisible == theIsVisibleInView)
318 theListOfIO.Append (anObjIter.Key());
323 //=======================================================================
326 //=======================================================================
327 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
328 const Standard_Boolean theToUpdateViewer)
330 if (theIObj.IsNull())
335 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
336 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
338 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
339 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
342 //=======================================================================
343 //function : SetViewAffinity
345 //=======================================================================
346 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
347 const Handle(V3d_View)& theView,
348 const Standard_Boolean theIsVisible)
351 || !myObjects.IsBound (theIObj))
356 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
357 Handle(Graphic3d_CView) aViewImpl = theView->View();
358 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
361 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
365 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
369 //=======================================================================
372 //=======================================================================
373 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
374 const Standard_Integer theDispMode,
375 const Standard_Integer theSelectionMode,
376 const Standard_Boolean theToUpdateViewer,
377 const Standard_Boolean theToAllowDecomposition,
378 const AIS_DisplayStatus theDispStatus)
380 if (theIObj.IsNull())
385 if (theDispStatus == AIS_DS_Erased)
387 Erase (theIObj, theToUpdateViewer);
388 Load (theIObj, theSelectionMode, theToAllowDecomposition);
392 if (!theIObj->HasInteractiveContext())
394 theIObj->SetContext (this);
397 if (theDispStatus == AIS_DS_Temporary
398 && !HasOpenedContext())
402 else if (HasOpenedContext())
404 if (theDispStatus == AIS_DS_None
405 || theDispStatus == AIS_DS_Temporary)
407 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
408 if (theToUpdateViewer)
416 if (!myObjects.IsBound (theIObj))
418 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
419 myObjects.Bind (theIObj, aStatus);
420 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
421 myMainPM->Display(theIObj, theDispMode);
422 if (theSelectionMode != -1)
424 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
425 if (!mgrSelector->Contains (anObj))
427 mgrSelector->Load (theIObj);
429 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
434 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
435 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
440 // Mark the presentation modes hidden of interactive object different from aDispMode.
441 // Then make sure aDispMode is displayed and maybe highlighted.
442 // Finally, activate selection mode <SelMode> if not yet activated.
443 const Standard_Integer anOldMode = aStatus->DisplayMode();
444 if (anOldMode != theDispMode)
446 if(myMainPM->IsHighlighted (theIObj, anOldMode))
448 unhighlightGlobal (theIObj, anOldMode);
450 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
453 aStatus->SetDisplayMode (theDispMode);
455 myMainPM->Display (theIObj, theDispMode);
456 aStatus->SetGraphicStatus (AIS_DS_Displayed);
457 if (aStatus->IsHilighted())
459 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
460 highlightGlobal (theIObj, aStatus->HilightStyle(), aHiMod);
462 if (theSelectionMode != -1)
464 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
465 if (!mgrSelector->Contains (anObj))
467 mgrSelector->Load (theIObj);
469 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
471 if (!aStatus->IsSModeIn (theSelectionMode))
472 aStatus->AddSelectionMode (theSelectionMode);
473 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
478 if (theToUpdateViewer)
484 //=======================================================================
487 //=======================================================================
488 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
489 const Standard_Integer theSelMode,
490 const Standard_Boolean theToAllowDecomposition)
492 if (theIObj.IsNull())
497 if (!theIObj->HasInteractiveContext())
499 theIObj->SetContext (this);
502 if (HasOpenedContext())
504 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
509 && !theToAllowDecomposition)
511 if (!myObjects.IsBound (theIObj))
513 Standard_Integer aDispMode, aHiMod, aSelModeDef;
514 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
515 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
516 myObjects.Bind (theIObj, aStatus);
519 // Register theIObj in the selection manager to prepare further activation of selection
520 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
521 if (!mgrSelector->Contains (anObj))
523 mgrSelector->Load (theIObj);
528 //=======================================================================
531 //=======================================================================
532 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
533 const Standard_Boolean theToUpdateViewer)
535 if (theIObj.IsNull())
540 if (!theIObj->IsAutoHilight())
542 theIObj->ClearSelected();
545 Standard_Boolean wasInCtx = Standard_False;
546 if (HasOpenedContext())
548 // First it is checked if it is possible to remove in the current local context
549 // then one tries to remove in other local contexts, if they allow it...
550 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
551 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
553 if (aCtxIter.Value()->AcceptErase())
555 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
562 EraseGlobal (theIObj, Standard_False);
565 if (theToUpdateViewer)
571 //=======================================================================
572 //function : EraseAll
574 //=======================================================================
575 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
577 if (HasOpenedContext())
582 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
584 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
586 Erase (anObjIter.Key(), Standard_False);
590 if (theToUpdateViewer)
596 //=======================================================================
597 //function : DisplayAll
599 //=======================================================================
600 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
602 if (HasOpenedContext())
607 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
609 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
610 if (aStatus == AIS_DS_Erased)
612 Display (anObjIter.Key(), Standard_False);
616 if (theToUpdateViewer)
622 //=======================================================================
623 //function : DisplaySelected
625 //=======================================================================
626 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
628 if (HasOpenedContext())
633 Standard_Boolean isFound = Standard_False;
634 for (mySelection->Init(); mySelection->More(); mySelection->Next())
636 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
637 Display (anObj, Standard_False);
638 isFound = Standard_True;
641 if (isFound && theToUpdateViewer)
647 //=======================================================================
648 //function : EraseSelected
650 //=======================================================================
651 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
653 if (HasOpenedContext())
658 Standard_Boolean isFound = Standard_False;
660 while (mySelection->More())
662 Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value();
663 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
665 Erase (anObj, Standard_False);
666 isFound = Standard_True;
671 if (isFound && theToUpdateViewer)
677 //=======================================================================
680 //=======================================================================
682 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
683 const Standard_Integer WhichContext)
685 if(anIObj.IsNull()) return Standard_False;
687 if(!HasOpenedContext()) return Standard_False;
688 if(myObjects.IsBound(anIObj)) return Standard_False;
689 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
691 // Protection : if one tries to preserve a temporary object
692 // which is not in the local active context... rob 11-06-97
694 Standard_Integer IsItInLocal = myCurLocalIndex;
695 Standard_Boolean Found(Standard_False);
697 while(IsItInLocal>0 && !Found){
698 if(!myLocalContexts.IsBound(IsItInLocal))
700 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
701 Found = Standard_True;
706 if(!Found) return Standard_False;
709 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
710 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
712 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
713 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
717 if(LS->IsTemporary()){
718 Standard_Integer DM,HM,SM;
719 GetDefModes(anIObj,DM,HM,SM);
721 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
722 if(LS->DisplayMode()!= DM ){
723 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
724 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
727 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
731 // GS->SubIntensityOn();
732 myObjects.Bind(anIObj,GS);
733 mgrSelector->Load(anIObj);
734 mgrSelector->Activate(anIObj,SM,myMainSel);
736 LS->SetTemporary(Standard_False);
738 return Standard_True;
741 //=======================================================================
742 //function : DisplayStatus
744 //=======================================================================
745 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
747 if (theIObj.IsNull())
751 else if (myObjects.IsBound (theIObj))
753 return myObjects (theIObj)->GraphicStatus();
756 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
758 if (aCtxIter.Value()->IsIn (theIObj))
760 return AIS_DS_Temporary;
766 //=======================================================================
769 //=======================================================================
770 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
771 const Standard_Boolean theToUpdateViewer)
773 if (theIObj.IsNull())
778 if (HasOpenedContext())
780 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
781 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
783 if (aCtxIter.Value()->AcceptErase())
785 aCtxIter.Value()->Remove (theIObj);
790 ClearGlobal (theIObj, theToUpdateViewer);
793 //=======================================================================
794 //function : RemoveAll
796 //=======================================================================
797 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
799 AIS_ListOfInteractive aList;
800 ObjectsInside (aList);
801 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
803 Remove (aListIterator.Value(), Standard_False);
806 if (theToUpdateViewer)
812 //=======================================================================
813 //function : ClearPrs
815 //=======================================================================
816 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
817 const Standard_Integer theMode,
818 const Standard_Boolean theToUpdateViewer)
820 if (theIObj.IsNull())
825 if (!HasOpenedContext())
827 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
831 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
832 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
834 if (aCtxIter.Value()->AcceptErase())
836 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
841 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
843 else if (theToUpdateViewer)
849 //=======================================================================
850 //function : HilightWithColor
852 //=======================================================================
853 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
854 const Handle(Graphic3d_HighlightStyle)& theStyle,
855 const Standard_Boolean theIsToUpdate)
860 if (!theObj->HasInteractiveContext())
861 theObj->SetContext (this);
863 if (!HasOpenedContext())
865 if (!myObjects.IsBound (theObj))
868 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
869 aStatus->SetHilightStatus (Standard_True);
871 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
873 const Standard_Integer aHilightMode = theObj->HasHilightMode() ? theObj->HilightMode() : 0;
874 highlightGlobal (theObj, theStyle, aHilightMode);
875 aStatus->SetHilightStyle (theStyle);
880 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
887 //=======================================================================
888 //function : Unhilight
890 //=======================================================================
891 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
893 if(anIObj.IsNull()) return;
895 if (!HasOpenedContext())
897 if(!myObjects.IsBound(anIObj)) return;
899 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
900 aStatus->SetHilightStatus (Standard_False);
901 aStatus->SetHilightStyle (new Graphic3d_HighlightStyle());
903 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
905 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
906 unhighlightGlobal (anIObj, aHilightMode);
911 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
913 if(updateviewer) myMainVwr->Update();
916 //=======================================================================
917 //function : IsHilighted
918 //purpose : Returns true if the objects global status is set to highlighted.
919 //=======================================================================
920 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
922 if (!HasOpenedContext())
924 if (!myObjects.IsBound (theObj))
925 return Standard_False;
927 return myObjects (theObj)->IsHilighted();
930 for (Standard_Integer aCtxIdx = HighestIndex(); aCtxIdx >= 1; aCtxIdx--)
932 if (myLocalContexts.IsBound (aCtxIdx))
934 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
935 return Standard_True;
939 return Standard_False;
942 //=======================================================================
943 //function : IsHilighted
944 //purpose : Returns true if the owner is highlighted with selection style.
945 //=======================================================================
946 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
948 if (theOwner.IsNull() || !theOwner->HasSelectable())
949 return Standard_False;
951 const Handle(AIS_InteractiveObject) anObj =
952 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
954 if (anObj->GlobalSelOwner() == theOwner)
956 if (!myObjects.IsBound (anObj))
957 return Standard_False;
959 return myObjects (anObj)->IsHilighted();
962 return theOwner->IsSelected();
965 //=======================================================================
966 //function : HighlightStyle
968 //=======================================================================
969 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
970 Handle(Graphic3d_HighlightStyle)& theStyle) const
972 if (HasOpenedContext())
973 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
975 if (IsHilighted (theObj))
977 theStyle = myObjects (theObj)->HilightStyle();
978 return Standard_True;
983 return Standard_False;
987 //=======================================================================
988 //function : HighlightStyle
990 //=======================================================================
991 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
992 Handle(Graphic3d_HighlightStyle)& theStyle) const
994 if (theOwner.IsNull() || !theOwner->HasSelectable())
995 return Standard_False;
997 if (IsHilighted (theOwner))
999 const Handle(AIS_InteractiveObject) anObj =
1000 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1001 if (anObj->GlobalSelOwner() == theOwner)
1003 theStyle = myObjects (anObj)->HilightStyle();
1007 // since part selection style is not stored in global status,
1008 // check if the object has own selection style. If not, it can
1009 // only be highlighted with default selection style (because
1010 // sub-intensity does not modify any selection states)
1011 theStyle = getSelStyle (anObj);
1013 return Standard_True;
1018 return Standard_False;
1022 //=======================================================================
1023 //function : IsDisplayed
1025 //=======================================================================
1027 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1029 if(anIObj.IsNull()) return Standard_False;
1032 if(myObjects.IsBound(anIObj))
1033 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1034 return Standard_True;
1036 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1037 for(;ItM.More();ItM.Next()){
1038 if(ItM.Value()->IsDisplayed(anIObj))
1039 return Standard_True;
1041 return Standard_False;
1045 //=======================================================================
1046 //function : IsDisplayed
1048 //=======================================================================
1049 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1050 const Standard_Integer theMode) const
1052 if (theIObj.IsNull())
1054 return Standard_False;
1057 if (myObjects.IsBound (theIObj))
1059 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1060 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1061 && aStatus->DisplayMode() == theMode)
1063 return Standard_True;
1067 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1069 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1071 return Standard_True;
1074 return Standard_False;
1077 //=======================================================================
1078 //function : DisplayPriority
1080 //=======================================================================
1081 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1083 if (theIObj.IsNull())
1087 else if (!myObjects.IsBound (theIObj))
1092 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1093 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1094 || aStatus->GraphicStatus() == AIS_DS_Erased)
1096 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1097 ? theIObj->DisplayMode()
1098 : (theIObj->AcceptDisplayMode (myDisplayMode)
1101 return myMainPM->DisplayPriority (theIObj, aDispMode);
1106 //=======================================================================
1107 //function : SetDisplayPriority
1109 //=======================================================================
1110 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1111 const Standard_Integer thePriority)
1113 if (theIObj.IsNull())
1118 if (!theIObj->HasInteractiveContext())
1120 theIObj->SetContext (this);
1123 if (myObjects.IsBound (theIObj))
1125 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1126 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1127 || aStatus->GraphicStatus() == AIS_DS_Erased)
1129 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1130 ? theIObj->DisplayMode()
1131 : (theIObj->AcceptDisplayMode (myDisplayMode)
1134 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1137 else if (HasOpenedContext())
1139 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1143 //=======================================================================
1144 //function : Redisplay
1146 //=======================================================================
1147 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1148 const Standard_Boolean theToUpdateViewer,
1149 const Standard_Boolean theAllModes)
1151 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1152 RecomputeSelectionOnly (theIObj);
1155 //=======================================================================
1156 //function : Redisplay
1158 //=======================================================================
1159 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1160 const Standard_Integer /*theSign*/,
1161 const Standard_Boolean theToUpdateViewer)
1163 Standard_Boolean isRedisplayed = Standard_False;
1164 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1166 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1167 if (anObj->Type() != theKOI)
1172 Redisplay (anObj, Standard_False);
1173 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1177 if (theToUpdateViewer
1180 myMainVwr->Update();
1184 //=======================================================================
1185 //function : RecomputePrsOnly
1187 //=======================================================================
1188 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1189 const Standard_Boolean theToUpdateViewer,
1190 const Standard_Boolean theAllModes)
1192 if (theIObj.IsNull())
1197 theIObj->Update (theAllModes);
1198 if (!theToUpdateViewer)
1203 if (HasOpenedContext()
1204 || (myObjects.IsBound (theIObj)
1205 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1207 myMainVwr->Update();
1210 //=======================================================================
1211 //function : RecomputeSelectionOnly
1213 //=======================================================================
1214 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1221 mgrSelector->RecomputeSelection (theIO);
1223 if (HasOpenedContext())
1225 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1227 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1232 if (!myObjects.IsBound (theIO) ||
1233 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1238 TColStd_ListOfInteger aModes;
1239 ActivatedModes (theIO, aModes);
1240 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1241 for (; aModesIter.More(); aModesIter.Next())
1243 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1247 //=======================================================================
1250 //=======================================================================
1251 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1252 const Standard_Boolean theUpdateViewer)
1254 if (theIObj.IsNull())
1259 TColStd_ListOfInteger aPrsModes;
1260 theIObj->ToBeUpdated (aPrsModes);
1261 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1263 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1266 mgrSelector->Update(theIObj);
1268 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1270 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1273 if (theUpdateViewer)
1275 if (!myObjects.IsBound (theIObj))
1280 switch (myObjects (theIObj)->GraphicStatus())
1282 case AIS_DS_Displayed:
1283 case AIS_DS_Temporary:
1284 myMainVwr->Update();
1292 //=======================================================================
1293 //function : SetLocation
1295 //=======================================================================
1296 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1297 const TopLoc_Location& theLoc)
1299 if (theIObj.IsNull())
1304 if (theIObj->HasTransformation()
1305 && theLoc.IsIdentity())
1307 theIObj->ResetTransformation();
1308 mgrSelector->Update (theIObj, Standard_False);
1311 else if (theLoc.IsIdentity())
1316 // first reset the previous location to properly clean everything...
1317 if (theIObj->HasTransformation())
1319 theIObj->ResetTransformation();
1322 theIObj->SetLocalTransformation (theLoc.Transformation());
1324 if (!HasOpenedContext())
1326 mgrSelector->Update (theIObj, Standard_False);
1330 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1331 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1334 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1335 // to its highlight structure immediately
1336 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1338 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1340 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1344 //=======================================================================
1345 //function : ResetLocation
1347 //=======================================================================
1348 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1350 if (theIObj.IsNull())
1355 theIObj->ResetTransformation();
1356 mgrSelector->Update (theIObj, Standard_False);
1359 //=======================================================================
1360 //function : HasLocation
1362 //=======================================================================
1363 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1365 return !theIObj.IsNull()
1366 && theIObj->HasTransformation();
1369 //=======================================================================
1370 //function : Location
1372 //=======================================================================
1373 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1375 return theIObj->Transformation();
1378 //=======================================================================
1379 //function : SetDeviationCoefficient
1381 //=======================================================================
1382 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1384 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1387 //=======================================================================
1388 //function : SetDeviationAngle
1390 //=======================================================================
1391 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1393 myDefaultDrawer->SetDeviationAngle (theAngle);
1396 //=======================================================================
1397 //function : DeviationAngle
1398 //purpose : Gets deviationAngle
1399 //=======================================================================
1400 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1402 return myDefaultDrawer->DeviationAngle();
1405 //=======================================================================
1406 //function : DeviationCoefficient
1408 //=======================================================================
1409 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1411 return myDefaultDrawer->DeviationCoefficient();
1414 //=======================================================================
1415 //function : SetHLRDeviationCoefficient
1417 //=======================================================================
1418 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1420 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1423 //=======================================================================
1424 //function : HLRDeviationCoefficient
1426 //=======================================================================
1427 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1429 return myDefaultDrawer->HLRDeviationCoefficient();
1432 //=======================================================================
1433 //function : SetHLRAngle
1435 //=======================================================================
1436 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1438 myDefaultDrawer->SetHLRAngle (theAngle);
1441 //=======================================================================
1442 //function : SetHLRAngleAndDeviation
1443 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1444 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1445 // of myDefaultDrawer
1446 //=======================================================================
1447 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1449 Standard_Real anOutAngl, anOutDefl;
1450 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1452 myDefaultDrawer->SetHLRAngle (anOutAngl);
1453 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1456 //=======================================================================
1457 //function : HLRAngle
1459 //=======================================================================
1460 Standard_Real AIS_InteractiveContext::HLRAngle() const
1462 return myDefaultDrawer->HLRAngle();
1465 //=======================================================================
1466 //function : SetDisplayMode
1468 //=======================================================================
1469 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1470 const Standard_Boolean theToUpdateViewer)
1472 if (theMode == myDisplayMode)
1477 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1479 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1480 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1481 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1482 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1485 || anObj->HasDisplayMode()
1486 || !anObj->AcceptDisplayMode (theMode))
1491 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1492 aStatus->SetDisplayMode (theMode);
1494 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1496 myMainPM->Display (anObj, theMode);
1497 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1499 myMainPM->BeginImmediateDraw();
1500 unhighlightGlobal (anObj, myDisplayMode);
1501 myMainPM->EndImmediateDraw (myMainVwr);
1503 if (aStatus->IsSubIntensityOn())
1505 highlightWithSubintensity (anObj, theMode);
1507 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1511 myDisplayMode = theMode;
1512 if (theToUpdateViewer)
1514 myMainVwr->Update();
1518 //=======================================================================
1519 //function : SetDisplayMode
1521 //=======================================================================
1522 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1523 const Standard_Integer theMode,
1524 const Standard_Boolean theToUpdateViewer)
1526 if (!theIObj->HasInteractiveContext())
1528 theIObj->SetContext(this);
1531 if (!myObjects.IsBound (theIObj))
1533 theIObj->SetDisplayMode (theMode);
1536 else if (!theIObj->AcceptDisplayMode (theMode))
1541 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1542 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1544 aStatus->SetDisplayMode (theMode);
1545 theIObj->SetDisplayMode (theMode);
1549 // erase presentations for all display modes different from <aMode>
1550 const Standard_Integer anOldMode = aStatus->DisplayMode();
1551 if (anOldMode != theMode)
1553 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1555 unhighlightGlobal (theIObj, anOldMode);
1557 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1560 aStatus->SetDisplayMode (theMode);
1562 myMainPM->Display (theIObj, theMode);
1563 Standard_Integer aDispMode, aHiMode, aSelMode;
1564 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1565 if (aStatus->IsHilighted())
1567 highlightGlobal (theIObj, getSelStyle (theIObj), aHiMode);
1569 if (aStatus->IsSubIntensityOn())
1571 highlightWithSubintensity (theIObj, theMode);
1574 if (theToUpdateViewer)
1576 myMainVwr->Update();
1578 theIObj->SetDisplayMode (theMode);
1581 //=======================================================================
1582 //function : UnsetDisplayMode
1584 //=======================================================================
1585 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1586 const Standard_Boolean theToUpdateViewer)
1588 if (theIObj.IsNull()
1589 || !theIObj->HasDisplayMode())
1594 if (!myObjects.IsBound (theIObj))
1596 theIObj->UnsetDisplayMode();
1600 const Standard_Integer anOldMode = theIObj->DisplayMode();
1601 if (myDisplayMode == anOldMode)
1606 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1607 aStatus->SetDisplayMode (myDisplayMode);
1609 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1611 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1613 unhighlightGlobal (theIObj, anOldMode);
1615 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1616 myMainPM->Display (theIObj, myDisplayMode);
1618 Standard_Integer aDispMode, aHiMode, aSelMode;
1619 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1620 if (aStatus->IsHilighted())
1622 highlightSelected (theIObj->GlobalSelOwner());
1624 if (aStatus->IsSubIntensityOn())
1626 highlightWithSubintensity (theIObj, myDisplayMode);
1629 if (theToUpdateViewer)
1631 myMainVwr->Update();
1635 theIObj->UnsetDisplayMode();
1638 //=======================================================================
1639 //function : SetCurrentFacingModel
1641 //=======================================================================
1642 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1643 const Aspect_TypeOfFacingModel theModel)
1645 if (!theIObj.IsNull())
1647 theIObj->SetCurrentFacingModel (theModel);
1651 //=======================================================================
1652 //function : redisplayPrsRecModes
1654 //=======================================================================
1655 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1656 const Standard_Boolean theToUpdateViewer)
1658 if (theIObj->RecomputeEveryPrs())
1660 theIObj->Update (Standard_True);
1661 theIObj->UpdateSelection();
1665 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1667 theIObj->Update (aModes.Value(), Standard_False);
1669 theIObj->UpdateSelection();
1670 theIObj->SetRecomputeOk();
1673 if (theToUpdateViewer)
1675 UpdateCurrentViewer();
1679 //=======================================================================
1680 //function : redisplayPrsModes
1682 //=======================================================================
1683 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1684 const Standard_Boolean theToUpdateViewer)
1686 if (theIObj->RecomputeEveryPrs())
1688 theIObj->Update (Standard_True);
1689 theIObj->UpdateSelection();
1693 TColStd_ListOfInteger aModes;
1694 theIObj->ToBeUpdated (aModes);
1695 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1697 theIObj->Update (aModeIter.Value(), Standard_False);
1699 theIObj->SetRecomputeOk();
1702 if (theToUpdateViewer)
1704 UpdateCurrentViewer();
1708 //=======================================================================
1709 //function : SetColor
1711 //=======================================================================
1712 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1713 const Quantity_NameOfColor theColor,
1714 const Standard_Boolean theToUpdateViewer)
1716 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1719 //=======================================================================
1720 //function : SetColor
1722 //=======================================================================
1723 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1724 const Quantity_Color& theColor,
1725 const Standard_Boolean theToUpdateViewer)
1727 if (theIObj.IsNull())
1732 if (!theIObj->HasInteractiveContext())
1734 theIObj->SetContext (this);
1736 theIObj->SetColor (theColor);
1737 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1740 //=======================================================================
1741 //function : SetIsoOnTriangulation
1743 //=======================================================================
1744 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1745 const Handle(AIS_InteractiveObject)& theObject)
1747 if (theObject.IsNull())
1752 theObject->SetIsoOnTriangulation (theIsEnabled);
1755 //=======================================================================
1756 //function : SetDeviationCoefficient
1758 //=======================================================================
1759 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1760 const Standard_Real theCoefficient,
1761 const Standard_Boolean theToUpdateViewer)
1763 if (theIObj.IsNull())
1768 if (!theIObj->HasInteractiveContext())
1770 theIObj->SetContext (this);
1773 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1774 if (theIObj->Type() != AIS_KOI_Object
1775 && theIObj->Type() != AIS_KOI_Shape)
1779 else if (theIObj->Signature() != 0)
1784 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1785 aShape->SetOwnDeviationCoefficient (theCoefficient);
1786 redisplayPrsModes (theIObj, theToUpdateViewer);
1789 //=======================================================================
1790 //function : SetHLRDeviationCoefficient
1792 //=======================================================================
1793 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1794 const Standard_Real theCoefficient,
1795 const Standard_Boolean theToUpdateViewer)
1797 if (theIObj.IsNull())
1802 if (!theIObj->HasInteractiveContext())
1804 theIObj->SetContext (this);
1807 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1808 if (theIObj->Type() != AIS_KOI_Object
1809 && theIObj->Type() != AIS_KOI_Shape)
1813 else if (theIObj->Signature() != 0)
1818 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1819 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1820 redisplayPrsModes (theIObj, theToUpdateViewer);
1823 //=======================================================================
1824 //function : SetDeviationAngle
1826 //=======================================================================
1827 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1828 const Standard_Real theAngle,
1829 const Standard_Boolean theToUpdateViewer)
1831 if (theIObj.IsNull())
1836 if (!theIObj->HasInteractiveContext())
1838 theIObj->SetContext (this);
1841 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1842 if (theIObj->Type() != AIS_KOI_Shape)
1846 else if (theIObj->Signature() != 0)
1851 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1852 aShape->SetOwnDeviationAngle (theAngle);
1853 redisplayPrsModes (theIObj, theToUpdateViewer);
1856 //=======================================================================
1857 //function : SetAngleAndDeviation
1859 //=======================================================================
1860 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1861 const Standard_Real theAngle,
1862 const Standard_Boolean theToUpdateViewer)
1864 if (theIObj.IsNull())
1869 if (!theIObj->HasInteractiveContext())
1871 theIObj->SetContext (this);
1874 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1875 if (theIObj->Type() != AIS_KOI_Shape)
1879 if (theIObj->Signature() != 0)
1884 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1885 aShape->SetAngleAndDeviation (theAngle);
1887 if (theIObj->RecomputeEveryPrs())
1889 theIObj->Update (Standard_True);
1890 theIObj->UpdateSelection();
1894 Update (theIObj, theToUpdateViewer);
1898 //=======================================================================
1899 //function : SetHLRAngleAndDeviation
1901 //=======================================================================
1902 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1903 const Standard_Real theAngle,
1904 const Standard_Boolean theToUpdateViewer)
1906 if (theIObj.IsNull())
1911 if (!theIObj->HasInteractiveContext())
1913 theIObj->SetContext (this);
1916 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1917 if (theIObj->Type() != AIS_KOI_Shape)
1921 if (theIObj->Signature() != 0)
1925 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1926 aShape->SetHLRAngleAndDeviation (theAngle);
1927 redisplayPrsModes (theIObj, theToUpdateViewer);
1930 //=======================================================================
1931 //function : SetHLRDeviationAngle
1933 //=======================================================================
1934 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1935 const Standard_Real theAngle,
1936 const Standard_Boolean theToUpdateViewer)
1938 if (theIObj.IsNull())
1943 if (!theIObj->HasInteractiveContext())
1945 theIObj->SetContext (this);
1948 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1949 if (theIObj->Type() != AIS_KOI_Shape)
1953 if (theIObj->Signature() != 0)
1957 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1958 aShape->SetOwnHLRDeviationAngle (theAngle);
1959 redisplayPrsModes (theIObj, theToUpdateViewer);
1962 //=======================================================================
1963 //function : UnsetColor
1965 //=======================================================================
1966 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1967 const Standard_Boolean theToUpdateViewer)
1969 if (theIObj.IsNull())
1974 theIObj->UnsetColor();
1975 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1978 //=======================================================================
1979 //function : HasColor
1981 //=======================================================================
1982 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1984 return theIObj->HasColor();
1987 //=======================================================================
1990 //=======================================================================
1991 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
1993 return theIObj->Color();
1996 //=======================================================================
1999 //=======================================================================
2000 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2001 Quantity_Color& theColor) const
2003 theIObj->Color (theColor);
2006 //=======================================================================
2009 //=======================================================================
2010 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2012 return theIObj->Width();
2015 //=======================================================================
2016 //function : SetWidth
2018 //=======================================================================
2019 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2020 const Standard_Real theWidth,
2021 const Standard_Boolean theToUpdateViewer)
2023 if (theIObj.IsNull())
2028 if (!theIObj->HasInteractiveContext())
2030 theIObj->SetContext (this);
2033 theIObj->SetWidth (theWidth);
2034 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2035 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2037 if (myLastinMain->IsAutoHilight())
2039 const Standard_Integer aHiMode =
2040 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2041 myLastinMain->HilightWithColor (myMainPM,
2042 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2047 theIObj->HilightOwnerWithColor (myMainPM,
2048 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2054 //=======================================================================
2055 //function : UnsetWidth
2057 //=======================================================================
2058 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2059 const Standard_Boolean theToUpdateViewer)
2061 if (theIObj.IsNull())
2066 theIObj->UnsetWidth();
2067 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2070 //=======================================================================
2071 //function : SetMaterial
2073 //=======================================================================
2074 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2075 const Graphic3d_NameOfMaterial theName,
2076 const Standard_Boolean theToUpdateViewer)
2078 if (theIObj.IsNull())
2083 if (!theIObj->HasInteractiveContext())
2085 theIObj->SetContext (this);
2088 theIObj->SetMaterial (theName);
2089 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2092 //=======================================================================
2093 //function : UnsetMaterial
2095 //=======================================================================
2096 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2097 const Standard_Boolean theToUpdateViewer)
2099 if (theIObj.IsNull())
2103 theIObj->UnsetMaterial();
2104 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2107 //=======================================================================
2108 //function : SetTransparency
2110 //=======================================================================
2111 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2112 const Standard_Real theValue,
2113 const Standard_Boolean theToUpdateViewer)
2115 if (theIObj.IsNull())
2120 if (!theIObj->HasInteractiveContext())
2122 theIObj->SetContext (this);
2125 if (!theIObj->IsTransparent()
2126 && theValue <= 0.05)
2131 if (theValue <= 0.05)
2133 UnsetTransparency (theIObj, theToUpdateViewer);
2137 theIObj->SetTransparency (theValue);
2138 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2141 //=======================================================================
2142 //function : UnsetTransparency
2144 //=======================================================================
2145 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2146 const Standard_Boolean theToUpdateViewer)
2148 if (theIObj.IsNull())
2153 theIObj->UnsetTransparency();
2154 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2157 //=======================================================================
2158 //function : SetSelectedAspect
2160 //=======================================================================
2161 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2162 const Standard_Boolean ,
2163 const Standard_Boolean theToUpdateViewer)
2165 if (HasOpenedContext())
2170 Standard_Boolean isFound = Standard_False;
2171 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2173 isFound = Standard_True;
2174 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2175 anObj->SetAspect (theAspect);
2178 if (isFound && theToUpdateViewer)
2180 myMainVwr->Update();
2184 //=======================================================================
2185 //function : SetLocalAttributes
2187 //=======================================================================
2188 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2189 const Handle(Prs3d_Drawer)& theDrawer,
2190 const Standard_Boolean theToUpdateViewer)
2192 if (theIObj.IsNull())
2197 if (!theIObj->HasInteractiveContext())
2199 theIObj->SetContext (this);
2202 theIObj->SetAttributes (theDrawer);
2203 Update (theIObj, theToUpdateViewer);
2206 //=======================================================================
2207 //function : UnsetLocalAttributes
2209 //=======================================================================
2210 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2211 const Standard_Boolean theToUpdateViewer)
2213 if (theIObj.IsNull())
2218 if (!theIObj->HasInteractiveContext())
2220 theIObj->SetContext (this);
2222 theIObj->UnsetAttributes();
2223 Update (theIObj, theToUpdateViewer);
2226 //=======================================================================
2229 //=======================================================================
2230 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2231 TCollection_ExtendedString& theStatus) const
2234 if (theIObj.IsNull()
2235 || !myObjects.IsBound (theIObj))
2240 theStatus += "\t ____________________________________________";
2241 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2242 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2243 switch (aStatus->GraphicStatus())
2245 case AIS_DS_Displayed:
2247 theStatus += "\t| -->Displayed\n";
2252 theStatus += "\t| -->Erased\n";
2259 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2260 theStatus += "\t|\t Mode ";
2261 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2264 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2266 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2267 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2269 theStatus += "\t\t Mode ";
2270 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2273 theStatus += "\t ____________________________________________";
2276 //=======================================================================
2277 //function : GetDefModes
2279 //=======================================================================
2280 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2281 Standard_Integer& theDispMode,
2282 Standard_Integer& theHiMode,
2283 Standard_Integer& theSelMode) const
2285 if (theIObj.IsNull())
2290 theDispMode = theIObj->HasDisplayMode()
2291 ? theIObj->DisplayMode()
2292 : (theIObj->AcceptDisplayMode (myDisplayMode)
2295 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2296 theSelMode = theIObj->GlobalSelectionMode();
2299 //=======================================================================
2300 //function : EraseGlobal
2302 //=======================================================================
2303 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2304 const Standard_Boolean theToUpdateviewer)
2306 if (theIObj.IsNull()
2307 || !myObjects.IsBound (theIObj))
2312 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2314 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2315 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2316 || aStatus->GraphicStatus() == AIS_DS_Erased)
2321 if (aStatus->IsHilighted())
2323 if (IsCurrent (theIObj))
2325 AddOrRemoveCurrentObject (theIObj, Standard_False);
2327 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2329 unhighlightGlobal (theIObj, aStatus->DisplayMode());
2333 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2335 if (aStatus->IsHilighted()
2336 && theIObj->HasHilightMode())
2338 unhighlightGlobal (theIObj, aDispMode);
2341 if (!myLastPicked.IsNull()
2342 && myLastPicked->IsSameSelectable (theIObj))
2344 myMainPM->ClearImmediateDraw();
2347 if (IsSelected (theIObj)
2348 && aStatus->DisplayMode() != aDispMode)
2350 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2353 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2355 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2357 aStatus->ClearSelectionModes();
2358 aStatus->SetGraphicStatus (AIS_DS_Erased);
2360 if (theToUpdateviewer)
2362 myMainVwr->Update();
2366 //=======================================================================
2367 //function : unhighlightOwners
2369 //=======================================================================
2370 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2372 SelectMgr_SequenceOfOwner aSeq;
2373 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2375 if (aSelIter.Value()->IsSameSelectable (theObject)
2376 && aSelIter.Value()->IsSelected())
2378 aSeq.Append (aSelIter.Value());
2381 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2383 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2387 //=======================================================================
2388 //function : ClearGlobal
2390 //=======================================================================
2391 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2392 const Standard_Boolean theToUpdateviewer)
2394 if (theIObj.IsNull()
2395 || !myObjects.IsBound (theIObj))
2397 // for cases when reference shape of connected interactives was not displayed
2398 // but its selection primitives were calculated
2399 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2400 mgrSelector->Remove (anObj);
2404 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2405 unhighlightOwners (theIObj);
2407 myMainPM->Erase (theIObj, -1);
2409 // Object removes from Detected sequence
2410 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2412 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2414 && anObj != theIObj)
2416 myAISDetectedSeq.Remove (aDetIter);
2420 // remove IO from the selection manager to avoid memory leaks
2421 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2422 mgrSelector->Remove (anObj);
2424 myObjects.UnBind (theIObj);
2425 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2427 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2429 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2432 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2433 myLastinMain.Nullify();
2434 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
2435 myLastPicked.Nullify();
2436 myMainPM->ClearImmediateDraw();
2438 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2440 myMainVwr->Update();
2444 //=======================================================================
2445 //function : ClearGlobalPrs
2447 //=======================================================================
2448 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2449 const Standard_Integer theMode,
2450 const Standard_Boolean theToUpdateViewer)
2452 if (theIObj.IsNull()
2453 || !myObjects.IsBound (theIObj))
2458 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2459 if (aStatus->DisplayMode() == theMode)
2461 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2462 if (aDispMode == theMode
2463 && myMainPM->IsHighlighted (theIObj, theMode))
2465 unhighlightGlobal (theIObj, theMode);
2468 myMainPM->Erase (theIObj, theMode);
2471 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2472 && theToUpdateViewer)
2474 myMainVwr->Update();
2478 //=======================================================================
2479 //function : DrawHiddenLine
2481 //=======================================================================
2482 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2484 return myDefaultDrawer->DrawHiddenLine();
2487 //=======================================================================
2488 //function : EnableDrawHiddenLine
2490 //=======================================================================
2491 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2493 myDefaultDrawer->EnableDrawHiddenLine();
2496 //=======================================================================
2497 //function : DisableDrawHiddenLine
2499 //=======================================================================
2500 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2502 myDefaultDrawer->DisableDrawHiddenLine();
2505 //=======================================================================
2506 //function : HiddenLineAspect
2508 //=======================================================================
2509 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2511 return myDefaultDrawer->HiddenLineAspect();
2514 //=======================================================================
2515 //function : SetHiddenLineAspect
2517 //=======================================================================
2518 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2520 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2523 //=======================================================================
2524 //function : SetIsoNumber
2526 //=======================================================================
2527 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2528 const AIS_TypeOfIso theType)
2533 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2536 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2539 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2540 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2545 //=======================================================================
2546 //function : IsoNumber
2548 //=======================================================================
2549 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2553 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2554 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2555 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2556 ? myDefaultDrawer->UIsoAspect()->Number()
2562 //=======================================================================
2563 //function : IsoOnPlane
2565 //=======================================================================
2566 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2568 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2571 //=======================================================================
2572 //function : IsoOnPlane
2574 //=======================================================================
2575 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2577 return myDefaultDrawer->IsoOnPlane();
2580 //=======================================================================
2581 //function : IsoOnTriangulation
2583 //=======================================================================
2584 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2586 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2589 //=======================================================================
2590 //function : IsoOnTriangulation
2592 //=======================================================================
2593 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2595 return myDefaultDrawer->IsoOnTriangulation();
2598 //function : SetPixelTolerance
2599 //purpose : Disables the mechanism of adaptive tolerance calculation in
2600 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2601 // sensitive entities activated. For more information, see
2602 // SelectMgr_ViewerSelector.hxx
2603 //=======================================================================
2604 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2606 if (HasOpenedContext())
2608 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2612 myMainSel->SetPixelTolerance (thePrecision);
2616 //=======================================================================
2617 //function : PixelTolerance
2619 //=======================================================================
2620 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2622 return HasOpenedContext()
2623 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2624 : myMainSel->PixelTolerance();
2627 //=======================================================================
2628 //function : SetSelectionSensitivity
2629 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2630 //=======================================================================
2631 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2632 const Standard_Integer theMode,
2633 const Standard_Integer theNewSensitivity)
2635 if (HasOpenedContext())
2637 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2641 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2644 //=======================================================================
2645 //function : IsInLocal
2647 //=======================================================================
2648 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2649 Standard_Integer& theIndex) const
2651 if (theIObj.IsNull())
2653 return Standard_False;
2656 // if it exists at neutral point 0 index is returned
2657 if (myObjects.IsBound (theIObj))
2660 return Standard_False;
2663 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2665 if (myLocalContexts.IsBound (aCtxIter))
2667 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2669 theIndex = aCtxIter;
2670 return Standard_True;
2675 return Standard_False;
2678 //=======================================================================
2679 //function : InitAttributes
2681 //=======================================================================
2682 void AIS_InteractiveContext::InitAttributes()
2684 mgrSelector->Add (myMainSel);
2686 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2687 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2689 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2690 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2691 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2692 aLineAspect->SetWidth (1.0);
2693 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2695 // tolerance to 2 pixels...
2696 SetPixelTolerance (2);
2698 // Customizing the drawer for trihedrons and planes...
2699 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2700 const Standard_Real aLength = 100.0;
2701 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2702 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2703 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2704 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2705 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2707 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2708 const Standard_Real aPlaneLength = 200.0;
2709 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2710 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2713 //=======================================================================
2714 //function : TrihedronSize
2716 //=======================================================================
2717 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2719 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2722 //=======================================================================
2723 //function : SetTrihedronSize
2725 //=======================================================================
2726 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2727 const Standard_Boolean /*updateviewer*/)
2729 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2730 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2731 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2734 //=======================================================================
2735 //function : SetPlaneSize
2737 //=======================================================================
2738 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2739 const Standard_Real theValY,
2740 const Standard_Boolean /*updateviewer*/)
2742 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2743 Redisplay (AIS_KOI_Datum, 7);
2746 //=======================================================================
2747 //function : SetPlaneSize
2749 //=======================================================================
2750 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2751 const Standard_Boolean theToUpdateViewer)
2753 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2756 //=======================================================================
2757 //function : PlaneSize
2759 //=======================================================================
2760 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2761 Standard_Real& theY) const
2763 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2764 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2765 return (Abs (theX - theY) <= Precision::Confusion());
2768 //=======================================================================
2769 //function : SetAutoActivateSelection
2771 //=======================================================================
2772 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2774 myIsAutoActivateSelMode = theIsAuto;
2777 //=======================================================================
2778 //function : GetAutoActivateSelection
2780 //=======================================================================
2781 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2783 return myIsAutoActivateSelMode;
2786 //=======================================================================
2787 //function : SetZLayer
2789 //=======================================================================
2790 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2791 const Standard_Integer theLayerId)
2793 if (theIObj.IsNull())
2796 theIObj->SetZLayer (theLayerId);
2799 //=======================================================================
2800 //function : GetZLayer
2802 //=======================================================================
2803 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2805 return !theIObj.IsNull()
2807 : Graphic3d_ZLayerId_UNKNOWN;
2810 //=======================================================================
2811 //function : RebuildSelectionStructs
2812 //purpose : Rebuilds 1st level of BVH selection forcibly
2813 //=======================================================================
2814 void AIS_InteractiveContext::RebuildSelectionStructs()
2816 myMainSel->RebuildObjectsTree (Standard_True);
2819 //=======================================================================
2820 //function : Disconnect
2821 //purpose : Disconnects selectable object from an assembly and updates selection structures
2822 //=======================================================================
2823 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2824 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2826 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2828 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2829 theObj->Disconnect (theObjToDisconnect);
2830 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2831 mgrSelector->Remove (anObj);
2833 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2835 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2836 theObj->Disconnect();
2837 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2838 mgrSelector->Remove (anObj);
2844 //=======================================================================
2845 //function : FitSelected
2846 //purpose : Fits the view corresponding to the bounds of selected objects
2847 //=======================================================================
2848 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2849 const Standard_Real theMargin,
2850 const Standard_Boolean theToUpdate)
2852 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2853 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2855 Bnd_Box aBndSelected;
2857 AIS_MapOfObjectOwners anObjectOwnerMap;
2858 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2860 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2861 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2862 if (anObj->IsInfinite())
2867 if (anOwner == anObj->GlobalSelOwner())
2870 anObj->BoundingBox (aTmpBnd);
2871 aBndSelected.Add (aTmpBnd);
2875 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2876 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2878 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2879 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2882 anOwnerMap->Add (anOwner);
2886 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2888 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2889 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2890 aBndSelected.Add (aTmpBox);
2893 anObjectOwnerMap.Clear();
2895 if (aBndSelected.IsVoid())
2898 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2901 //=======================================================================
2902 //function : SetTransformPersistence
2904 //=======================================================================
2905 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2906 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2908 theObject->SetTransformPersistence (theTrsfPers);
2909 if (!myObjects.IsBound (theObject))
2914 mgrSelector->UpdateSelection (theObject);
2916 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2917 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2918 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2920 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2921 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);