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_ShadingAspect.hxx>
42 #include <PrsMgr_ModedPresentation.hxx>
43 #include <PrsMgr_PresentableObject.hxx>
44 #include <Quantity_Color.hxx>
45 #include <SelectMgr_EntityOwner.hxx>
46 #include <SelectMgr_Filter.hxx>
47 #include <SelectMgr_OrFilter.hxx>
48 #include <SelectMgr_SelectionManager.hxx>
49 #include <Standard_Atomic.hxx>
50 #include <Standard_Transient.hxx>
51 #include <Standard_Type.hxx>
52 #include <StdSelect_ViewerSelector3d.hxx>
53 #include <TCollection_AsciiString.hxx>
54 #include <TCollection_ExtendedString.hxx>
55 #include <TColStd_ListIteratorOfListOfInteger.hxx>
56 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
57 #include <TopLoc_Location.hxx>
58 #include <TopoDS_Shape.hxx>
59 #include <UnitsAPI.hxx>
60 #include <V3d_View.hxx>
61 #include <V3d_Viewer.hxx>
63 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
67 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
68 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
71 //=======================================================================
72 //function : AIS_InteractiveContext
74 //=======================================================================
76 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
77 mgrSelector(new SelectMgr_SelectionManager()),
78 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
79 myMainVwr(MainViewer),
80 myMainSel(new StdSelect_ViewerSelector3d()),
81 myWasLastMain(Standard_False),
82 myCurrentTouched(Standard_False),
83 mySelectedTouched(Standard_False),
84 myToHilightSelected(Standard_True),
85 myFilters(new SelectMgr_OrFilter()),
86 myDefaultDrawer(new Prs3d_Drawer()),
87 mySelection(new AIS_Selection()),
88 myDefaultColor(Quantity_NOC_GOLDENROD),
89 myHiStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_CYAN1)),
90 mySelStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY80)),
91 myPreselectionColor(Quantity_NOC_GREEN),
92 mySubintStyle(new Graphic3d_HighlightStyle (Aspect_TOHM_COLOR, Quantity_NOC_GRAY40)),
98 myIsAutoActivateSelMode(Standard_True)
103 //=======================================================================
104 //function : ~AIS_InteractiveContext
106 //=======================================================================
107 AIS_InteractiveContext::~AIS_InteractiveContext()
109 // clear the current selection
110 mySelection->Clear();
112 // let's remove one reference explicitly. this operation's supposed to
113 // be performed when mgrSelector will be destroyed but anyway...
114 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
115 mgrSelector->Remove (aSelector);
117 Handle(AIS_InteractiveContext) aNullContext;
118 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
120 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
121 anObj->SetContext (aNullContext);
122 for (anObj->Init(); anObj->More(); anObj->Next())
124 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
129 //=======================================================================
130 //function : UpdateCurrentViewer
132 //=======================================================================
134 void AIS_InteractiveContext::UpdateCurrentViewer()
136 if (!myMainVwr.IsNull())
140 //=======================================================================
141 //function : DisplayedObjects
143 //=======================================================================
144 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
145 const Standard_Boolean theOnlyFromNeutral) const
147 if (!HasOpenedContext()
148 || theOnlyFromNeutral)
150 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
152 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
154 theListOfIO.Append (anObjIter.Key());
161 TColStd_MapOfTransient aDispMap;
162 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
164 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
166 aDispMap.Add (anObjIter.Key());
170 // parse all local contexts...
171 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
173 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
174 aLocCtx->DisplayedObjects (aDispMap);
177 Handle(AIS_InteractiveObject) anObj;
178 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
180 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
181 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
182 theListOfIO.Append (anObj);
186 //=======================================================================
187 //function : DisplayedObjects
189 //=======================================================================
190 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
191 const Standard_Integer theSign,
192 AIS_ListOfInteractive& theListOfIO,
193 const Standard_Boolean /*OnlyFromNeutral*/) const
195 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
198 //=======================================================================
199 //function : ErasedObjects
201 //=======================================================================
202 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
204 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
207 //=======================================================================
208 //function : ErasedObjects
210 //=======================================================================
211 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
212 const Standard_Integer theSign,
213 AIS_ListOfInteractive& theListOfIO) const
215 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
218 //=======================================================================
219 //function : ObjectsByDisplayStatus
221 //=======================================================================
222 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
223 AIS_ListOfInteractive& theListOfIO) const
225 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
227 if (anObjIter.Value()->GraphicStatus() == theStatus)
229 theListOfIO.Append (anObjIter.Key());
234 //=======================================================================
235 //function : ObjectsByDisplayStatus
237 //=======================================================================
238 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
239 const Standard_Integer theSign,
240 const AIS_DisplayStatus theStatus,
241 AIS_ListOfInteractive& theListOfIO) const
243 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
245 if (theStatus != AIS_DS_None
246 && anObjIter.Value()->GraphicStatus() != theStatus)
250 else if (anObjIter.Key()->Type() != theKind)
256 || anObjIter.Key()->Signature() == theSign)
258 theListOfIO.Append (anObjIter.Key());
263 //=======================================================================
264 //function : ObjectsInside
266 //=======================================================================
267 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
268 const AIS_KindOfInteractive theKind,
269 const Standard_Integer theSign) const
271 if (theKind == AIS_KOI_None
274 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
276 theListOfIO.Append (anObjIter.Key());
281 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
283 if (anObjIter.Key()->Type() != theKind)
289 || anObjIter.Key()->Signature() == theSign)
291 theListOfIO.Append (anObjIter.Key());
296 //=======================================================================
297 //function : ObjectsForView
299 //=======================================================================
300 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
301 const Handle(V3d_View)& theView,
302 const Standard_Boolean theIsVisibleInView,
303 const AIS_DisplayStatus theStatus) const
305 Handle(Graphic3d_CView) aViewImpl = theView->View();
306 const Standard_Integer aViewId = aViewImpl->Identification();
307 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
309 if (theStatus != AIS_DS_None
310 && anObjIter.Value()->GraphicStatus() != theStatus)
312 theListOfIO.Append (anObjIter.Key());
316 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
317 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
318 if (isVisible == theIsVisibleInView)
320 theListOfIO.Append (anObjIter.Key());
325 //=======================================================================
328 //=======================================================================
329 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
330 const Standard_Boolean theToUpdateViewer)
332 if (theIObj.IsNull())
337 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
338 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
340 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
341 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
344 //=======================================================================
345 //function : SetViewAffinity
347 //=======================================================================
348 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
349 const Handle(V3d_View)& theView,
350 const Standard_Boolean theIsVisible)
353 || !myObjects.IsBound (theIObj))
358 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
359 Handle(Graphic3d_CView) aViewImpl = theView->View();
360 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
363 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
367 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
371 //=======================================================================
374 //=======================================================================
375 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
376 const Standard_Integer theDispMode,
377 const Standard_Integer theSelectionMode,
378 const Standard_Boolean theToUpdateViewer,
379 const Standard_Boolean theToAllowDecomposition,
380 const AIS_DisplayStatus theDispStatus)
382 if (theIObj.IsNull())
387 if (theDispStatus == AIS_DS_Erased)
389 Erase (theIObj, theToUpdateViewer);
390 Load (theIObj, theSelectionMode, theToAllowDecomposition);
394 setContextToObject (theIObj);
395 if (theDispStatus == AIS_DS_Temporary
396 && !HasOpenedContext())
400 else if (HasOpenedContext())
402 if (theDispStatus == AIS_DS_None
403 || theDispStatus == AIS_DS_Temporary)
405 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
406 if (theToUpdateViewer)
414 if (!myObjects.IsBound (theIObj))
416 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
417 myObjects.Bind (theIObj, aStatus);
418 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
419 myMainPM->Display(theIObj, theDispMode);
420 if (theSelectionMode != -1)
422 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
423 if (!mgrSelector->Contains (anObj))
425 mgrSelector->Load (theIObj);
427 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
432 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
433 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
438 // Mark the presentation modes hidden of interactive object different from aDispMode.
439 // Then make sure aDispMode is displayed and maybe highlighted.
440 // Finally, activate selection mode <SelMode> if not yet activated.
441 const Standard_Integer anOldMode = aStatus->DisplayMode();
442 if (anOldMode != theDispMode)
444 if(myMainPM->IsHighlighted (theIObj, anOldMode))
446 unhighlightGlobal (theIObj, anOldMode);
448 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
451 aStatus->SetDisplayMode (theDispMode);
453 myMainPM->Display (theIObj, theDispMode);
454 aStatus->SetGraphicStatus (AIS_DS_Displayed);
455 if (aStatus->IsHilighted())
457 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
458 highlightGlobal (theIObj, aStatus->HilightStyle(), aHiMod);
460 if (theSelectionMode != -1)
462 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
463 if (!mgrSelector->Contains (anObj))
465 mgrSelector->Load (theIObj);
467 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
469 if (!aStatus->IsSModeIn (theSelectionMode))
470 aStatus->AddSelectionMode (theSelectionMode);
471 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
476 if (theToUpdateViewer)
482 //=======================================================================
485 //=======================================================================
486 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
487 const Standard_Integer theSelMode,
488 const Standard_Boolean theToAllowDecomposition)
490 if (theIObj.IsNull())
495 setContextToObject (theIObj);
496 if (HasOpenedContext())
498 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
503 && !theToAllowDecomposition)
505 if (!myObjects.IsBound (theIObj))
507 Standard_Integer aDispMode, aHiMod, aSelModeDef;
508 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
509 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
510 myObjects.Bind (theIObj, aStatus);
513 // Register theIObj in the selection manager to prepare further activation of selection
514 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
515 if (!mgrSelector->Contains (anObj))
517 mgrSelector->Load (theIObj);
522 //=======================================================================
525 //=======================================================================
526 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
527 const Standard_Boolean theToUpdateViewer)
529 if (theIObj.IsNull())
534 if (!theIObj->IsAutoHilight())
536 theIObj->ClearSelected();
539 Standard_Boolean wasInCtx = Standard_False;
540 if (HasOpenedContext())
542 // First it is checked if it is possible to remove in the current local context
543 // then one tries to remove in other local contexts, if they allow it...
544 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
545 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
547 if (aCtxIter.Value()->AcceptErase())
549 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
556 EraseGlobal (theIObj, Standard_False);
559 if (theToUpdateViewer)
565 //=======================================================================
566 //function : EraseAll
568 //=======================================================================
569 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
571 if (HasOpenedContext())
576 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
578 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
580 Erase (anObjIter.Key(), Standard_False);
584 if (theToUpdateViewer)
590 //=======================================================================
591 //function : DisplayAll
593 //=======================================================================
594 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
596 if (HasOpenedContext())
601 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
603 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
604 if (aStatus == AIS_DS_Erased)
606 Display (anObjIter.Key(), Standard_False);
610 if (theToUpdateViewer)
616 //=======================================================================
617 //function : DisplaySelected
619 //=======================================================================
620 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
622 if (HasOpenedContext())
627 Standard_Boolean isFound = Standard_False;
628 for (mySelection->Init(); mySelection->More(); mySelection->Next())
630 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
631 Display (anObj, Standard_False);
632 isFound = Standard_True;
635 if (isFound && theToUpdateViewer)
641 //=======================================================================
642 //function : EraseSelected
644 //=======================================================================
645 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
647 if (HasOpenedContext())
652 Standard_Boolean isFound = Standard_False;
654 while (mySelection->More())
656 Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value();
657 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
659 Erase (anObj, Standard_False);
660 isFound = Standard_True;
665 if (isFound && theToUpdateViewer)
671 //=======================================================================
674 //=======================================================================
676 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
677 const Standard_Integer WhichContext)
679 if(anIObj.IsNull()) return Standard_False;
681 if(!HasOpenedContext()) return Standard_False;
682 if(myObjects.IsBound(anIObj)) return Standard_False;
683 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
685 // Protection : if one tries to preserve a temporary object
686 // which is not in the local active context... rob 11-06-97
688 Standard_Integer IsItInLocal = myCurLocalIndex;
689 Standard_Boolean Found(Standard_False);
691 while(IsItInLocal>0 && !Found){
692 if(!myLocalContexts.IsBound(IsItInLocal))
694 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
695 Found = Standard_True;
700 if(!Found) return Standard_False;
703 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
704 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
706 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
707 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
711 if(LS->IsTemporary()){
712 Standard_Integer DM,HM,SM;
713 GetDefModes(anIObj,DM,HM,SM);
715 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
716 if(LS->DisplayMode()!= DM ){
717 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
718 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
721 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
725 // GS->SubIntensityOn();
726 myObjects.Bind(anIObj,GS);
727 mgrSelector->Load(anIObj);
728 mgrSelector->Activate(anIObj,SM,myMainSel);
730 LS->SetTemporary(Standard_False);
732 return Standard_True;
735 //=======================================================================
736 //function : DisplayStatus
738 //=======================================================================
739 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
741 if (theIObj.IsNull())
745 else if (myObjects.IsBound (theIObj))
747 return myObjects (theIObj)->GraphicStatus();
750 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
752 if (aCtxIter.Value()->IsIn (theIObj))
754 return AIS_DS_Temporary;
760 //=======================================================================
763 //=======================================================================
764 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
765 const Standard_Boolean theToUpdateViewer)
767 if (theIObj.IsNull())
772 if (theIObj->HasInteractiveContext())
774 if (theIObj->myCTXPtr != this)
776 Standard_ProgramError::Raise ("AIS_InteractiveContext - object has been displayed in another context!");
778 theIObj->SetContext (Handle(AIS_InteractiveContext)());
781 if (HasOpenedContext())
783 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
784 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
786 if (aCtxIter.Value()->AcceptErase())
788 aCtxIter.Value()->Remove (theIObj);
793 ClearGlobal (theIObj, theToUpdateViewer);
796 //=======================================================================
797 //function : RemoveAll
799 //=======================================================================
800 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
802 AIS_ListOfInteractive aList;
803 ObjectsInside (aList);
804 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
806 Remove (aListIterator.Value(), Standard_False);
809 if (theToUpdateViewer)
815 //=======================================================================
816 //function : ClearPrs
818 //=======================================================================
819 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
820 const Standard_Integer theMode,
821 const Standard_Boolean theToUpdateViewer)
823 if (theIObj.IsNull())
828 if (!HasOpenedContext())
830 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
834 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
835 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
837 if (aCtxIter.Value()->AcceptErase())
839 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
844 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
846 else if (theToUpdateViewer)
852 //=======================================================================
853 //function : HilightWithColor
855 //=======================================================================
856 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
857 const Handle(Graphic3d_HighlightStyle)& theStyle,
858 const Standard_Boolean theIsToUpdate)
863 setContextToObject (theObj);
864 if (!HasOpenedContext())
866 if (!myObjects.IsBound (theObj))
869 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
870 aStatus->SetHilightStatus (Standard_True);
872 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
874 const Standard_Integer aHilightMode = theObj->HasHilightMode() ? theObj->HilightMode() : 0;
875 highlightGlobal (theObj, theStyle, aHilightMode);
876 aStatus->SetHilightStyle (theStyle);
881 myLocalContexts (myCurLocalIndex)->Hilight (theObj, theStyle);
888 //=======================================================================
889 //function : Unhilight
891 //=======================================================================
892 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
894 if(anIObj.IsNull()) return;
896 if (!HasOpenedContext())
898 if(!myObjects.IsBound(anIObj)) return;
900 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
901 aStatus->SetHilightStatus (Standard_False);
902 aStatus->SetHilightStyle (new Graphic3d_HighlightStyle());
904 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
906 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
907 unhighlightGlobal (anIObj, aHilightMode);
912 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
914 if(updateviewer) myMainVwr->Update();
917 //=======================================================================
918 //function : IsHilighted
919 //purpose : Returns true if the objects global status is set to highlighted.
920 //=======================================================================
921 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
923 if (!HasOpenedContext())
925 if (!myObjects.IsBound (theObj))
926 return Standard_False;
928 return myObjects (theObj)->IsHilighted();
931 for (Standard_Integer aCtxIdx = HighestIndex(); aCtxIdx >= 1; aCtxIdx--)
933 if (myLocalContexts.IsBound (aCtxIdx))
935 if (myLocalContexts (aCtxIdx)->IsHilighted (theObj))
936 return Standard_True;
940 return Standard_False;
943 //=======================================================================
944 //function : IsHilighted
945 //purpose : Returns true if the owner is highlighted with selection style.
946 //=======================================================================
947 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
949 if (theOwner.IsNull() || !theOwner->HasSelectable())
950 return Standard_False;
952 const Handle(AIS_InteractiveObject) anObj =
953 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
955 if (anObj->GlobalSelOwner() == theOwner)
957 if (!myObjects.IsBound (anObj))
958 return Standard_False;
960 return myObjects (anObj)->IsHilighted();
963 return theOwner->IsSelected();
966 //=======================================================================
967 //function : HighlightStyle
969 //=======================================================================
970 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
971 Handle(Graphic3d_HighlightStyle)& theStyle) const
973 if (HasOpenedContext())
974 myLocalContexts (myCurLocalIndex)->HighlightStyle (theObj, theStyle);
976 if (IsHilighted (theObj))
978 theStyle = myObjects (theObj)->HilightStyle();
979 return Standard_True;
984 return Standard_False;
988 //=======================================================================
989 //function : HighlightStyle
991 //=======================================================================
992 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
993 Handle(Graphic3d_HighlightStyle)& theStyle) const
995 if (theOwner.IsNull() || !theOwner->HasSelectable())
996 return Standard_False;
998 if (IsHilighted (theOwner))
1000 const Handle(AIS_InteractiveObject) anObj =
1001 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1002 if (anObj->GlobalSelOwner() == theOwner)
1004 theStyle = myObjects (anObj)->HilightStyle();
1008 // since part selection style is not stored in global status,
1009 // check if the object has own selection style. If not, it can
1010 // only be highlighted with default selection style (because
1011 // sub-intensity does not modify any selection states)
1012 theStyle = getSelStyle (anObj);
1014 return Standard_True;
1019 return Standard_False;
1023 //=======================================================================
1024 //function : IsDisplayed
1026 //=======================================================================
1028 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1030 if(anIObj.IsNull()) return Standard_False;
1033 if(myObjects.IsBound(anIObj))
1034 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1035 return Standard_True;
1037 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1038 for(;ItM.More();ItM.Next()){
1039 if(ItM.Value()->IsDisplayed(anIObj))
1040 return Standard_True;
1042 return Standard_False;
1046 //=======================================================================
1047 //function : IsDisplayed
1049 //=======================================================================
1050 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1051 const Standard_Integer theMode) const
1053 if (theIObj.IsNull())
1055 return Standard_False;
1058 if (myObjects.IsBound (theIObj))
1060 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1061 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1062 && aStatus->DisplayMode() == theMode)
1064 return Standard_True;
1068 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1070 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1072 return Standard_True;
1075 return Standard_False;
1078 //=======================================================================
1079 //function : DisplayPriority
1081 //=======================================================================
1082 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1084 if (theIObj.IsNull())
1088 else if (!myObjects.IsBound (theIObj))
1093 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1094 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1095 || aStatus->GraphicStatus() == AIS_DS_Erased)
1097 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1098 ? theIObj->DisplayMode()
1099 : (theIObj->AcceptDisplayMode (myDisplayMode)
1102 return myMainPM->DisplayPriority (theIObj, aDispMode);
1107 //=======================================================================
1108 //function : SetDisplayPriority
1110 //=======================================================================
1111 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1112 const Standard_Integer thePriority)
1114 if (theIObj.IsNull())
1119 setContextToObject (theIObj);
1120 if (myObjects.IsBound (theIObj))
1122 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1123 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1124 || aStatus->GraphicStatus() == AIS_DS_Erased)
1126 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1127 ? theIObj->DisplayMode()
1128 : (theIObj->AcceptDisplayMode (myDisplayMode)
1131 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1134 else if (HasOpenedContext())
1136 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1140 //=======================================================================
1141 //function : Redisplay
1143 //=======================================================================
1144 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1145 const Standard_Boolean theToUpdateViewer,
1146 const Standard_Boolean theAllModes)
1148 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1149 RecomputeSelectionOnly (theIObj);
1152 //=======================================================================
1153 //function : Redisplay
1155 //=======================================================================
1156 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1157 const Standard_Integer /*theSign*/,
1158 const Standard_Boolean theToUpdateViewer)
1160 Standard_Boolean isRedisplayed = Standard_False;
1161 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1163 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1164 if (anObj->Type() != theKOI)
1169 Redisplay (anObj, Standard_False);
1170 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1174 if (theToUpdateViewer
1177 myMainVwr->Update();
1181 //=======================================================================
1182 //function : RecomputePrsOnly
1184 //=======================================================================
1185 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1186 const Standard_Boolean theToUpdateViewer,
1187 const Standard_Boolean theAllModes)
1189 if (theIObj.IsNull())
1194 theIObj->Update (theAllModes);
1195 if (!theToUpdateViewer)
1200 if (HasOpenedContext()
1201 || (myObjects.IsBound (theIObj)
1202 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1204 myMainVwr->Update();
1207 //=======================================================================
1208 //function : RecomputeSelectionOnly
1210 //=======================================================================
1211 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1218 mgrSelector->RecomputeSelection (theIO);
1220 if (HasOpenedContext())
1222 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1224 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1229 if (!myObjects.IsBound (theIO) ||
1230 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1235 TColStd_ListOfInteger aModes;
1236 ActivatedModes (theIO, aModes);
1237 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1238 for (; aModesIter.More(); aModesIter.Next())
1240 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1244 //=======================================================================
1247 //=======================================================================
1248 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1249 const Standard_Boolean theUpdateViewer)
1251 if (theIObj.IsNull())
1256 TColStd_ListOfInteger aPrsModes;
1257 theIObj->ToBeUpdated (aPrsModes);
1258 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1260 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1263 mgrSelector->Update(theIObj);
1265 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1267 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1270 if (theUpdateViewer)
1272 if (!myObjects.IsBound (theIObj))
1277 switch (myObjects (theIObj)->GraphicStatus())
1279 case AIS_DS_Displayed:
1280 case AIS_DS_Temporary:
1281 myMainVwr->Update();
1289 //=======================================================================
1290 //function : SetLocation
1292 //=======================================================================
1293 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1294 const TopLoc_Location& theLoc)
1296 if (theIObj.IsNull())
1301 if (theIObj->HasTransformation()
1302 && theLoc.IsIdentity())
1304 theIObj->ResetTransformation();
1305 mgrSelector->Update (theIObj, Standard_False);
1308 else if (theLoc.IsIdentity())
1313 // first reset the previous location to properly clean everything...
1314 if (theIObj->HasTransformation())
1316 theIObj->ResetTransformation();
1319 theIObj->SetLocalTransformation (theLoc.Transformation());
1321 if (!HasOpenedContext())
1323 mgrSelector->Update (theIObj, Standard_False);
1327 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1328 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1331 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1332 // to its highlight structure immediately
1333 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1335 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1336 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1342 //=======================================================================
1343 //function : ResetLocation
1345 //=======================================================================
1346 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1348 if (theIObj.IsNull())
1353 theIObj->ResetTransformation();
1354 mgrSelector->Update (theIObj, Standard_False);
1357 //=======================================================================
1358 //function : HasLocation
1360 //=======================================================================
1361 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1363 return !theIObj.IsNull()
1364 && theIObj->HasTransformation();
1367 //=======================================================================
1368 //function : Location
1370 //=======================================================================
1371 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1373 return theIObj->Transformation();
1376 //=======================================================================
1377 //function : SetDeviationCoefficient
1379 //=======================================================================
1380 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1382 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1385 //=======================================================================
1386 //function : SetDeviationAngle
1388 //=======================================================================
1389 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1391 myDefaultDrawer->SetDeviationAngle (theAngle);
1394 //=======================================================================
1395 //function : DeviationAngle
1396 //purpose : Gets deviationAngle
1397 //=======================================================================
1398 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1400 return myDefaultDrawer->DeviationAngle();
1403 //=======================================================================
1404 //function : DeviationCoefficient
1406 //=======================================================================
1407 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1409 return myDefaultDrawer->DeviationCoefficient();
1412 //=======================================================================
1413 //function : SetHLRDeviationCoefficient
1415 //=======================================================================
1416 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1418 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1421 //=======================================================================
1422 //function : HLRDeviationCoefficient
1424 //=======================================================================
1425 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1427 return myDefaultDrawer->HLRDeviationCoefficient();
1430 //=======================================================================
1431 //function : SetHLRAngle
1433 //=======================================================================
1434 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1436 myDefaultDrawer->SetHLRAngle (theAngle);
1439 //=======================================================================
1440 //function : SetHLRAngleAndDeviation
1441 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1442 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1443 // of myDefaultDrawer
1444 //=======================================================================
1445 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1447 Standard_Real anOutAngl, anOutDefl;
1448 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1450 myDefaultDrawer->SetHLRAngle (anOutAngl);
1451 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1454 //=======================================================================
1455 //function : HLRAngle
1457 //=======================================================================
1458 Standard_Real AIS_InteractiveContext::HLRAngle() const
1460 return myDefaultDrawer->HLRAngle();
1463 //=======================================================================
1464 //function : SetDisplayMode
1466 //=======================================================================
1467 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1468 const Standard_Boolean theToUpdateViewer)
1470 if (theMode == myDisplayMode)
1475 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1477 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1478 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1479 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1480 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1483 || anObj->HasDisplayMode()
1484 || !anObj->AcceptDisplayMode (theMode))
1489 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1490 aStatus->SetDisplayMode (theMode);
1492 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1494 myMainPM->Display (anObj, theMode);
1495 if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1497 myMainPM->BeginImmediateDraw();
1498 unhighlightGlobal (anObj, myDisplayMode);
1499 myMainPM->EndImmediateDraw (myMainVwr);
1501 if (aStatus->IsSubIntensityOn())
1503 highlightWithSubintensity (anObj, theMode);
1505 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1509 myDisplayMode = theMode;
1510 if (theToUpdateViewer)
1512 myMainVwr->Update();
1516 //=======================================================================
1517 //function : SetDisplayMode
1519 //=======================================================================
1520 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1521 const Standard_Integer theMode,
1522 const Standard_Boolean theToUpdateViewer)
1524 setContextToObject (theIObj);
1525 if (!myObjects.IsBound (theIObj))
1527 theIObj->SetDisplayMode (theMode);
1530 else if (!theIObj->AcceptDisplayMode (theMode))
1535 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1536 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1538 aStatus->SetDisplayMode (theMode);
1539 theIObj->SetDisplayMode (theMode);
1543 // erase presentations for all display modes different from <aMode>
1544 const Standard_Integer anOldMode = aStatus->DisplayMode();
1545 if (anOldMode != theMode)
1547 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1549 unhighlightGlobal (theIObj, anOldMode);
1551 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1554 aStatus->SetDisplayMode (theMode);
1556 myMainPM->Display (theIObj, theMode);
1557 Standard_Integer aDispMode, aHiMode, aSelMode;
1558 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1559 if (aStatus->IsHilighted())
1561 highlightGlobal (theIObj, getSelStyle (theIObj), aHiMode);
1563 if (aStatus->IsSubIntensityOn())
1565 highlightWithSubintensity (theIObj, theMode);
1568 if (theToUpdateViewer)
1570 myMainVwr->Update();
1572 theIObj->SetDisplayMode (theMode);
1575 //=======================================================================
1576 //function : UnsetDisplayMode
1578 //=======================================================================
1579 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1580 const Standard_Boolean theToUpdateViewer)
1582 if (theIObj.IsNull()
1583 || !theIObj->HasDisplayMode())
1588 if (!myObjects.IsBound (theIObj))
1590 theIObj->UnsetDisplayMode();
1594 const Standard_Integer anOldMode = theIObj->DisplayMode();
1595 if (myDisplayMode == anOldMode)
1600 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1601 aStatus->SetDisplayMode (myDisplayMode);
1603 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1605 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1607 unhighlightGlobal (theIObj, anOldMode);
1609 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1610 myMainPM->Display (theIObj, myDisplayMode);
1612 Standard_Integer aDispMode, aHiMode, aSelMode;
1613 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1614 if (aStatus->IsHilighted())
1616 highlightSelected (theIObj->GlobalSelOwner());
1618 if (aStatus->IsSubIntensityOn())
1620 highlightWithSubintensity (theIObj, myDisplayMode);
1623 if (theToUpdateViewer)
1625 myMainVwr->Update();
1629 theIObj->UnsetDisplayMode();
1632 //=======================================================================
1633 //function : SetCurrentFacingModel
1635 //=======================================================================
1636 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1637 const Aspect_TypeOfFacingModel theModel)
1639 if (!theIObj.IsNull())
1641 theIObj->SetCurrentFacingModel (theModel);
1645 //=======================================================================
1646 //function : redisplayPrsRecModes
1648 //=======================================================================
1649 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1650 const Standard_Boolean theToUpdateViewer)
1652 if (theIObj->RecomputeEveryPrs())
1654 theIObj->Update (Standard_True);
1655 theIObj->UpdateSelection();
1659 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1661 theIObj->Update (aModes.Value(), Standard_False);
1663 theIObj->UpdateSelection();
1664 theIObj->SetRecomputeOk();
1667 if (theToUpdateViewer)
1669 UpdateCurrentViewer();
1673 //=======================================================================
1674 //function : redisplayPrsModes
1676 //=======================================================================
1677 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1678 const Standard_Boolean theToUpdateViewer)
1680 if (theIObj->RecomputeEveryPrs())
1682 theIObj->Update (Standard_True);
1683 theIObj->UpdateSelection();
1687 TColStd_ListOfInteger aModes;
1688 theIObj->ToBeUpdated (aModes);
1689 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1691 theIObj->Update (aModeIter.Value(), Standard_False);
1693 theIObj->SetRecomputeOk();
1696 if (theToUpdateViewer)
1698 UpdateCurrentViewer();
1702 //=======================================================================
1703 //function : SetColor
1705 //=======================================================================
1706 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1707 const Quantity_NameOfColor theColor,
1708 const Standard_Boolean theToUpdateViewer)
1710 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1713 //=======================================================================
1714 //function : SetColor
1716 //=======================================================================
1717 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1718 const Quantity_Color& theColor,
1719 const Standard_Boolean theToUpdateViewer)
1721 if (theIObj.IsNull())
1726 setContextToObject (theIObj);
1727 theIObj->SetColor (theColor);
1728 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1731 //=======================================================================
1732 //function : SetIsoOnTriangulation
1734 //=======================================================================
1735 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1736 const Handle(AIS_InteractiveObject)& theObject)
1738 if (theObject.IsNull())
1743 theObject->SetIsoOnTriangulation (theIsEnabled);
1746 //=======================================================================
1747 //function : SetDeviationCoefficient
1749 //=======================================================================
1750 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1751 const Standard_Real theCoefficient,
1752 const Standard_Boolean theToUpdateViewer)
1754 if (theIObj.IsNull())
1759 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1760 setContextToObject (theIObj);
1761 if (theIObj->Type() != AIS_KOI_Object
1762 && theIObj->Type() != AIS_KOI_Shape)
1766 else if (theIObj->Signature() != 0)
1771 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1772 aShape->SetOwnDeviationCoefficient (theCoefficient);
1773 redisplayPrsModes (theIObj, theToUpdateViewer);
1776 //=======================================================================
1777 //function : SetHLRDeviationCoefficient
1779 //=======================================================================
1780 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1781 const Standard_Real theCoefficient,
1782 const Standard_Boolean theToUpdateViewer)
1784 if (theIObj.IsNull())
1789 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1790 setContextToObject (theIObj);
1791 if (theIObj->Type() != AIS_KOI_Object
1792 && theIObj->Type() != AIS_KOI_Shape)
1796 else if (theIObj->Signature() != 0)
1801 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1802 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1803 redisplayPrsModes (theIObj, theToUpdateViewer);
1806 //=======================================================================
1807 //function : SetDeviationAngle
1809 //=======================================================================
1810 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1811 const Standard_Real theAngle,
1812 const Standard_Boolean theToUpdateViewer)
1814 if (theIObj.IsNull())
1819 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1820 setContextToObject (theIObj);
1821 if (theIObj->Type() != AIS_KOI_Shape)
1825 else if (theIObj->Signature() != 0)
1830 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1831 aShape->SetOwnDeviationAngle (theAngle);
1832 redisplayPrsModes (theIObj, theToUpdateViewer);
1835 //=======================================================================
1836 //function : SetAngleAndDeviation
1838 //=======================================================================
1839 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1840 const Standard_Real theAngle,
1841 const Standard_Boolean theToUpdateViewer)
1843 if (theIObj.IsNull())
1848 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1849 setContextToObject (theIObj);
1850 if (theIObj->Type() != AIS_KOI_Shape)
1854 if (theIObj->Signature() != 0)
1859 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1860 aShape->SetAngleAndDeviation (theAngle);
1862 if (theIObj->RecomputeEveryPrs())
1864 theIObj->Update (Standard_True);
1865 theIObj->UpdateSelection();
1869 Update (theIObj, theToUpdateViewer);
1873 //=======================================================================
1874 //function : SetHLRAngleAndDeviation
1876 //=======================================================================
1877 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1878 const Standard_Real theAngle,
1879 const Standard_Boolean theToUpdateViewer)
1881 if (theIObj.IsNull())
1886 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1887 setContextToObject (theIObj);
1888 if (theIObj->Type() != AIS_KOI_Shape)
1892 if (theIObj->Signature() != 0)
1896 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1897 aShape->SetHLRAngleAndDeviation (theAngle);
1898 redisplayPrsModes (theIObj, theToUpdateViewer);
1901 //=======================================================================
1902 //function : SetHLRDeviationAngle
1904 //=======================================================================
1905 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1906 const Standard_Real theAngle,
1907 const Standard_Boolean theToUpdateViewer)
1909 if (theIObj.IsNull())
1914 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1915 setContextToObject (theIObj);
1916 if (theIObj->Type() != AIS_KOI_Shape)
1920 if (theIObj->Signature() != 0)
1924 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1925 aShape->SetOwnHLRDeviationAngle (theAngle);
1926 redisplayPrsModes (theIObj, theToUpdateViewer);
1929 //=======================================================================
1930 //function : UnsetColor
1932 //=======================================================================
1933 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1934 const Standard_Boolean theToUpdateViewer)
1936 if (theIObj.IsNull())
1941 theIObj->UnsetColor();
1942 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1945 //=======================================================================
1946 //function : HasColor
1948 //=======================================================================
1949 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1951 return theIObj->HasColor();
1954 //=======================================================================
1957 //=======================================================================
1958 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
1960 return theIObj->Color();
1963 //=======================================================================
1966 //=======================================================================
1967 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1968 Quantity_Color& theColor) const
1970 theIObj->Color (theColor);
1973 //=======================================================================
1976 //=======================================================================
1977 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1979 return theIObj->Width();
1982 //=======================================================================
1983 //function : SetWidth
1985 //=======================================================================
1986 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1987 const Standard_Real theWidth,
1988 const Standard_Boolean theToUpdateViewer)
1990 if (theIObj.IsNull())
1995 setContextToObject (theIObj);
1996 theIObj->SetWidth (theWidth);
1997 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1998 if (!myLastinMain.IsNull() && myLastinMain->IsSameSelectable (theIObj))
2000 if (myLastinMain->IsAutoHilight())
2002 const Standard_Integer aHiMode =
2003 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2004 myLastinMain->HilightWithColor (myMainPM,
2005 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2010 theIObj->HilightOwnerWithColor (myMainPM,
2011 myLastinMain->IsSelected() ? getSelStyle (theIObj) : getHiStyle (theIObj),
2017 //=======================================================================
2018 //function : UnsetWidth
2020 //=======================================================================
2021 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2022 const Standard_Boolean theToUpdateViewer)
2024 if (theIObj.IsNull())
2029 theIObj->UnsetWidth();
2030 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2033 //=======================================================================
2034 //function : SetMaterial
2036 //=======================================================================
2037 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2038 const Graphic3d_NameOfMaterial theName,
2039 const Standard_Boolean theToUpdateViewer)
2041 if (theIObj.IsNull())
2046 setContextToObject (theIObj);
2047 theIObj->SetMaterial (theName);
2048 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2051 //=======================================================================
2052 //function : UnsetMaterial
2054 //=======================================================================
2055 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2056 const Standard_Boolean theToUpdateViewer)
2058 if (theIObj.IsNull())
2062 theIObj->UnsetMaterial();
2063 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2066 //=======================================================================
2067 //function : SetTransparency
2069 //=======================================================================
2070 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2071 const Standard_Real theValue,
2072 const Standard_Boolean theToUpdateViewer)
2074 if (theIObj.IsNull())
2079 setContextToObject (theIObj);
2080 if (!theIObj->IsTransparent()
2081 && theValue <= 0.05)
2086 if (theValue <= 0.05)
2088 UnsetTransparency (theIObj, theToUpdateViewer);
2092 theIObj->SetTransparency (theValue);
2093 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2096 //=======================================================================
2097 //function : UnsetTransparency
2099 //=======================================================================
2100 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2101 const Standard_Boolean theToUpdateViewer)
2103 if (theIObj.IsNull())
2108 theIObj->UnsetTransparency();
2109 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2112 //=======================================================================
2113 //function : SetSelectedAspect
2115 //=======================================================================
2116 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2117 const Standard_Boolean ,
2118 const Standard_Boolean theToUpdateViewer)
2120 if (HasOpenedContext())
2125 Standard_Boolean isFound = Standard_False;
2126 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2128 isFound = Standard_True;
2129 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2130 anObj->SetAspect (theAspect);
2133 if (isFound && theToUpdateViewer)
2135 myMainVwr->Update();
2139 //=======================================================================
2140 //function : SetLocalAttributes
2142 //=======================================================================
2143 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2144 const Handle(Prs3d_Drawer)& theDrawer,
2145 const Standard_Boolean theToUpdateViewer)
2147 if (theIObj.IsNull())
2152 setContextToObject (theIObj);
2153 theIObj->SetAttributes (theDrawer);
2154 Update (theIObj, theToUpdateViewer);
2157 //=======================================================================
2158 //function : UnsetLocalAttributes
2160 //=======================================================================
2161 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2162 const Standard_Boolean theToUpdateViewer)
2164 if (theIObj.IsNull())
2169 setContextToObject (theIObj);
2170 theIObj->UnsetAttributes();
2171 Update (theIObj, theToUpdateViewer);
2174 //=======================================================================
2177 //=======================================================================
2178 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2179 TCollection_ExtendedString& theStatus) const
2182 if (theIObj.IsNull()
2183 || !myObjects.IsBound (theIObj))
2188 theStatus += "\t ____________________________________________";
2189 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2190 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2191 switch (aStatus->GraphicStatus())
2193 case AIS_DS_Displayed:
2195 theStatus += "\t| -->Displayed\n";
2200 theStatus += "\t| -->Erased\n";
2207 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2208 theStatus += "\t|\t Mode ";
2209 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2212 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2214 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2215 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2217 theStatus += "\t\t Mode ";
2218 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2221 theStatus += "\t ____________________________________________";
2224 //=======================================================================
2225 //function : GetDefModes
2227 //=======================================================================
2228 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2229 Standard_Integer& theDispMode,
2230 Standard_Integer& theHiMode,
2231 Standard_Integer& theSelMode) const
2233 if (theIObj.IsNull())
2238 theDispMode = theIObj->HasDisplayMode()
2239 ? theIObj->DisplayMode()
2240 : (theIObj->AcceptDisplayMode (myDisplayMode)
2243 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2244 theSelMode = theIObj->GlobalSelectionMode();
2247 //=======================================================================
2248 //function : EraseGlobal
2250 //=======================================================================
2251 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2252 const Standard_Boolean theToUpdateviewer)
2254 if (theIObj.IsNull()
2255 || !myObjects.IsBound (theIObj))
2260 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2262 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2263 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2264 || aStatus->GraphicStatus() == AIS_DS_Erased)
2269 if (aStatus->IsHilighted())
2271 if (IsCurrent (theIObj))
2273 AddOrRemoveCurrentObject (theIObj, Standard_False);
2275 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2277 unhighlightGlobal (theIObj, aStatus->DisplayMode());
2281 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2283 if (aStatus->IsHilighted()
2284 && theIObj->HasHilightMode())
2286 unhighlightGlobal (theIObj, aDispMode);
2289 if (!myLastPicked.IsNull()
2290 && myLastPicked->IsSameSelectable (theIObj))
2292 myMainPM->ClearImmediateDraw();
2295 if (IsSelected (theIObj)
2296 && aStatus->DisplayMode() != aDispMode)
2298 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2301 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2303 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2305 aStatus->ClearSelectionModes();
2306 aStatus->SetGraphicStatus (AIS_DS_Erased);
2308 if (theToUpdateviewer)
2310 myMainVwr->Update();
2314 //=======================================================================
2315 //function : unhighlightOwners
2317 //=======================================================================
2318 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2320 SelectMgr_SequenceOfOwner aSeq;
2321 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2323 if (aSelIter.Value()->IsSameSelectable (theObject))
2325 aSeq.Append (aSelIter.Value());
2328 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2330 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2334 //=======================================================================
2335 //function : ClearGlobal
2337 //=======================================================================
2338 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2339 const Standard_Boolean theToUpdateviewer)
2341 if (theIObj.IsNull()
2342 || !myObjects.IsBound (theIObj))
2344 // for cases when reference shape of connected interactives was not displayed
2345 // but its selection primitives were calculated
2346 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2347 mgrSelector->Remove (anObj);
2351 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2352 unhighlightOwners (theIObj);
2354 myMainPM->Erase (theIObj, -1);
2356 // Object removes from Detected sequence
2357 for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper(); ++aDetIter)
2359 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2361 && anObj != theIObj)
2363 myDetectedSeq.Remove (aDetIter);
2367 // remove IO from the selection manager to avoid memory leaks
2368 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2369 mgrSelector->Remove (anObj);
2371 myObjects.UnBind (theIObj);
2372 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2374 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2376 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2379 if (!myLastinMain.IsNull())
2381 if (myLastinMain->IsSameSelectable (theIObj)
2382 || myLastPicked->IsSameSelectable(theIObj))
2384 myLastinMain.Nullify();
2385 myMainPM->ClearImmediateDraw();
2389 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2391 myMainVwr->Update();
2395 //=======================================================================
2396 //function : ClearGlobalPrs
2398 //=======================================================================
2399 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2400 const Standard_Integer theMode,
2401 const Standard_Boolean theToUpdateViewer)
2403 if (theIObj.IsNull()
2404 || !myObjects.IsBound (theIObj))
2409 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2410 if (aStatus->DisplayMode() == theMode)
2412 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2413 if (aDispMode == theMode
2414 && myMainPM->IsHighlighted (theIObj, theMode))
2416 unhighlightGlobal (theIObj, theMode);
2419 myMainPM->Erase (theIObj, theMode);
2422 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2423 && theToUpdateViewer)
2425 myMainVwr->Update();
2429 //=======================================================================
2430 //function : DrawHiddenLine
2432 //=======================================================================
2433 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2435 return myDefaultDrawer->DrawHiddenLine();
2438 //=======================================================================
2439 //function : EnableDrawHiddenLine
2441 //=======================================================================
2442 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2444 myDefaultDrawer->EnableDrawHiddenLine();
2447 //=======================================================================
2448 //function : DisableDrawHiddenLine
2450 //=======================================================================
2451 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2453 myDefaultDrawer->DisableDrawHiddenLine();
2456 //=======================================================================
2457 //function : HiddenLineAspect
2459 //=======================================================================
2460 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2462 return myDefaultDrawer->HiddenLineAspect();
2465 //=======================================================================
2466 //function : SetHiddenLineAspect
2468 //=======================================================================
2469 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2471 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2474 //=======================================================================
2475 //function : SetIsoNumber
2477 //=======================================================================
2478 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2479 const AIS_TypeOfIso theType)
2484 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2487 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2490 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2491 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2496 //=======================================================================
2497 //function : IsoNumber
2499 //=======================================================================
2500 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2504 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2505 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2506 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2507 ? myDefaultDrawer->UIsoAspect()->Number()
2513 //=======================================================================
2514 //function : IsoOnPlane
2516 //=======================================================================
2517 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2519 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2522 //=======================================================================
2523 //function : IsoOnPlane
2525 //=======================================================================
2526 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2528 return myDefaultDrawer->IsoOnPlane();
2531 //=======================================================================
2532 //function : IsoOnTriangulation
2534 //=======================================================================
2535 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2537 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2540 //=======================================================================
2541 //function : IsoOnTriangulation
2543 //=======================================================================
2544 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2546 return myDefaultDrawer->IsoOnTriangulation();
2549 //function : SetPixelTolerance
2550 //purpose : Disables the mechanism of adaptive tolerance calculation in
2551 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2552 // sensitive entities activated. For more information, see
2553 // SelectMgr_ViewerSelector.hxx
2554 //=======================================================================
2555 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2557 if (HasOpenedContext())
2559 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2563 myMainSel->SetPixelTolerance (thePrecision);
2567 //=======================================================================
2568 //function : PixelTolerance
2570 //=======================================================================
2571 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2573 return HasOpenedContext()
2574 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2575 : myMainSel->PixelTolerance();
2578 //=======================================================================
2579 //function : SetSelectionSensitivity
2580 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2581 //=======================================================================
2582 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2583 const Standard_Integer theMode,
2584 const Standard_Integer theNewSensitivity)
2586 if (HasOpenedContext())
2588 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2592 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2595 //=======================================================================
2596 //function : IsInLocal
2598 //=======================================================================
2599 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2600 Standard_Integer& theIndex) const
2602 if (theIObj.IsNull())
2604 return Standard_False;
2607 // if it exists at neutral point 0 index is returned
2608 if (myObjects.IsBound (theIObj))
2611 return Standard_False;
2614 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2616 if (myLocalContexts.IsBound (aCtxIter))
2618 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2620 theIndex = aCtxIter;
2621 return Standard_True;
2626 return Standard_False;
2629 //=======================================================================
2630 //function : InitAttributes
2632 //=======================================================================
2633 void AIS_InteractiveContext::InitAttributes()
2635 mgrSelector->Add (myMainSel);
2637 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2638 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2640 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2641 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2642 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2643 aLineAspect->SetWidth (1.0);
2644 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2646 // tolerance to 2 pixels...
2647 SetPixelTolerance (2);
2649 // Customizing the drawer for trihedrons and planes...
2650 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2651 const Standard_Real aLength = 100.0;
2652 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2653 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2654 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2655 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2656 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2658 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2659 const Standard_Real aPlaneLength = 200.0;
2660 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2661 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2664 //=======================================================================
2665 //function : TrihedronSize
2667 //=======================================================================
2668 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2670 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2673 //=======================================================================
2674 //function : SetTrihedronSize
2676 //=======================================================================
2677 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2678 const Standard_Boolean /*updateviewer*/)
2680 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2681 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2682 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2685 //=======================================================================
2686 //function : SetPlaneSize
2688 //=======================================================================
2689 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2690 const Standard_Real theValY,
2691 const Standard_Boolean /*updateviewer*/)
2693 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2694 Redisplay (AIS_KOI_Datum, 7);
2697 //=======================================================================
2698 //function : SetPlaneSize
2700 //=======================================================================
2701 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2702 const Standard_Boolean theToUpdateViewer)
2704 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2707 //=======================================================================
2708 //function : PlaneSize
2710 //=======================================================================
2711 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2712 Standard_Real& theY) const
2714 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2715 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2716 return (Abs (theX - theY) <= Precision::Confusion());
2719 //=======================================================================
2720 //function : SetAutoActivateSelection
2722 //=======================================================================
2723 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2725 myIsAutoActivateSelMode = theIsAuto;
2728 //=======================================================================
2729 //function : GetAutoActivateSelection
2731 //=======================================================================
2732 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2734 return myIsAutoActivateSelMode;
2737 //=======================================================================
2738 //function : SetZLayer
2740 //=======================================================================
2741 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2742 const Standard_Integer theLayerId)
2744 if (theIObj.IsNull())
2747 theIObj->SetZLayer (theLayerId);
2750 //=======================================================================
2751 //function : GetZLayer
2753 //=======================================================================
2754 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2756 return !theIObj.IsNull()
2758 : Graphic3d_ZLayerId_UNKNOWN;
2761 //=======================================================================
2762 //function : RebuildSelectionStructs
2763 //purpose : Rebuilds 1st level of BVH selection forcibly
2764 //=======================================================================
2765 void AIS_InteractiveContext::RebuildSelectionStructs()
2767 myMainSel->RebuildObjectsTree (Standard_True);
2770 //=======================================================================
2771 //function : Disconnect
2772 //purpose : Disconnects selectable object from an assembly and updates selection structures
2773 //=======================================================================
2774 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2775 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2777 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2779 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2780 theObj->Disconnect (theObjToDisconnect);
2781 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2782 mgrSelector->Remove (anObj);
2784 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2786 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2787 theObj->Disconnect();
2788 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2789 mgrSelector->Remove (anObj);
2795 //=======================================================================
2796 //function : FitSelected
2797 //purpose : Fits the view corresponding to the bounds of selected objects
2798 //=======================================================================
2799 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2800 const Standard_Real theMargin,
2801 const Standard_Boolean theToUpdate)
2803 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2804 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2806 Bnd_Box aBndSelected;
2808 AIS_MapOfObjectOwners anObjectOwnerMap;
2809 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2811 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2812 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2813 if (anObj->IsInfinite())
2818 if (anOwner == anObj->GlobalSelOwner())
2821 anObj->BoundingBox (aTmpBnd);
2822 aBndSelected.Add (aTmpBnd);
2826 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2827 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2829 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2830 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2833 anOwnerMap->Add (anOwner);
2837 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2839 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2840 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2841 aBndSelected.Add (aTmpBox);
2844 anObjectOwnerMap.Clear();
2846 if (aBndSelected.IsVoid())
2849 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2852 //=======================================================================
2853 //function : SetTransformPersistence
2855 //=======================================================================
2856 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2857 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2859 theObject->SetTransformPersistence (theTrsfPers);
2860 if (!myObjects.IsBound (theObject))
2865 mgrSelector->UpdateSelection (theObject);
2867 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2868 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2869 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2871 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2872 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);