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 myHilightColor(Quantity_NOC_CYAN1),
92 mySelectionColor(Quantity_NOC_GRAY80),
93 myPreselectionColor(Quantity_NOC_GREEN),
94 mySubIntensity(Quantity_NOC_GRAY40),
99 myIsAutoActivateSelMode(Standard_True)
104 void AIS_InteractiveContext::Delete() const
106 // clear the current selection
107 mySelection->Select();
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())
139 //=======================================================================
140 //function : DomainOfMainViewer
142 //=======================================================================
144 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
146 return myMainVwr->Domain();
150 //=======================================================================
151 //function : DisplayedObjects
153 //=======================================================================
154 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
155 const Standard_Boolean theOnlyFromNeutral) const
157 if (!HasOpenedContext()
158 || theOnlyFromNeutral)
160 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
162 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
164 theListOfIO.Append (anObjIter.Key());
171 TColStd_MapOfTransient aDispMap;
172 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
174 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
176 aDispMap.Add (anObjIter.Key());
180 // parse all local contexts...
181 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
183 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
184 aLocCtx->DisplayedObjects (aDispMap);
187 Handle(AIS_InteractiveObject) anObj;
188 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
190 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
191 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
192 theListOfIO.Append (anObj);
196 //=======================================================================
197 //function : DisplayedObjects
199 //=======================================================================
200 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
201 const Standard_Integer theSign,
202 AIS_ListOfInteractive& theListOfIO,
203 const Standard_Boolean /*OnlyFromNeutral*/) const
205 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
208 //=======================================================================
209 //function : ErasedObjects
211 //=======================================================================
212 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
214 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
217 //=======================================================================
218 //function : ErasedObjects
220 //=======================================================================
221 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
222 const Standard_Integer theSign,
223 AIS_ListOfInteractive& theListOfIO) const
225 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
228 //=======================================================================
229 //function : ObjectsByDisplayStatus
231 //=======================================================================
232 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
233 AIS_ListOfInteractive& theListOfIO) const
235 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
237 if (anObjIter.Value()->GraphicStatus() == theStatus)
239 theListOfIO.Append (anObjIter.Key());
244 //=======================================================================
245 //function : ObjectsByDisplayStatus
247 //=======================================================================
248 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
249 const Standard_Integer theSign,
250 const AIS_DisplayStatus theStatus,
251 AIS_ListOfInteractive& theListOfIO) const
253 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
255 if (theStatus != AIS_DS_None
256 && anObjIter.Value()->GraphicStatus() != theStatus)
260 else if (anObjIter.Key()->Type() != theKind)
266 || anObjIter.Key()->Signature() == theSign)
268 theListOfIO.Append (anObjIter.Key());
273 //=======================================================================
274 //function : ObjectsInside
276 //=======================================================================
277 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
278 const AIS_KindOfInteractive theKind,
279 const Standard_Integer theSign) const
281 if (theKind == AIS_KOI_None
284 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
286 theListOfIO.Append (anObjIter.Key());
291 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
293 if (anObjIter.Key()->Type() != theKind)
299 || anObjIter.Key()->Signature() == theSign)
301 theListOfIO.Append (anObjIter.Key());
306 //=======================================================================
307 //function : ObjectsForView
309 //=======================================================================
310 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
311 const Handle(V3d_View)& theView,
312 const Standard_Boolean theIsVisibleInView,
313 const AIS_DisplayStatus theStatus) const
315 Handle(Graphic3d_CView) aViewImpl = theView->View();
316 const Standard_Integer aViewId = aViewImpl->Identification();
317 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
319 if (theStatus != AIS_DS_None
320 && anObjIter.Value()->GraphicStatus() != theStatus)
322 theListOfIO.Append (anObjIter.Key());
326 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
327 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
328 if (isVisible == theIsVisibleInView)
330 theListOfIO.Append (anObjIter.Key());
335 //=======================================================================
338 //=======================================================================
339 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
340 const Standard_Boolean theToUpdateViewer)
342 if (theIObj.IsNull())
347 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
348 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
350 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
351 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
354 //=======================================================================
355 //function : SetViewAffinity
357 //=======================================================================
358 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
359 const Handle(V3d_View)& theView,
360 const Standard_Boolean theIsVisible)
363 || !myObjects.IsBound (theIObj))
368 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
369 Handle(Graphic3d_CView) aViewImpl = theView->View();
370 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
373 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
377 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
381 //=======================================================================
384 //=======================================================================
385 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
386 const Standard_Integer theDispMode,
387 const Standard_Integer theSelectionMode,
388 const Standard_Boolean theToUpdateViewer,
389 const Standard_Boolean theToAllowDecomposition,
390 const AIS_DisplayStatus theDispStatus)
392 if (theIObj.IsNull())
397 if (theDispStatus == AIS_DS_Erased)
399 Erase (theIObj, theToUpdateViewer);
400 Load (theIObj, theSelectionMode, theToAllowDecomposition);
404 if (!theIObj->HasInteractiveContext())
406 theIObj->SetContext (this);
409 if (theDispStatus == AIS_DS_Temporary
410 && !HasOpenedContext())
414 else if (HasOpenedContext())
416 if (theDispStatus == AIS_DS_None
417 || theDispStatus == AIS_DS_Temporary)
419 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
420 if (theToUpdateViewer)
428 if (!myObjects.IsBound (theIObj))
430 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
431 myObjects.Bind (theIObj, aStatus);
432 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
433 myMainPM->Display(theIObj, theDispMode);
434 if (theSelectionMode != -1)
436 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
437 if (!mgrSelector->Contains (anObj))
439 mgrSelector->Load (theIObj);
441 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
446 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
447 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
452 // Mark the presentation modes hidden of interactive object different from aDispMode.
453 // Then make sure aDispMode is displayed and maybe highlighted.
454 // Finally, activate selection mode <SelMode> if not yet activated.
455 const Standard_Integer anOldMode = aStatus->DisplayMode();
456 if (anOldMode != theDispMode)
458 if(myMainPM->IsHighlighted (theIObj, anOldMode))
460 myMainPM->Unhighlight (theIObj, anOldMode);
462 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
465 aStatus->SetDisplayMode (theDispMode);
467 myMainPM->Display (theIObj, theDispMode);
468 aStatus->SetGraphicStatus (AIS_DS_Displayed);
469 if (aStatus->IsHilighted())
471 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
472 myMainPM->Color (theIObj, aStatus->HilightColor(), aHiMod);
474 if (theSelectionMode != -1)
476 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
477 if (!mgrSelector->Contains (anObj))
479 mgrSelector->Load (theIObj);
481 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
483 if (!aStatus->IsSModeIn (theSelectionMode))
484 aStatus->AddSelectionMode (theSelectionMode);
485 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
490 if (theToUpdateViewer)
496 //=======================================================================
499 //=======================================================================
500 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
501 const Standard_Integer theSelMode,
502 const Standard_Boolean theToAllowDecomposition)
504 if (theIObj.IsNull())
509 if (!theIObj->HasInteractiveContext())
511 theIObj->SetContext (this);
514 if (HasOpenedContext())
516 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
521 && !theToAllowDecomposition)
523 if (!myObjects.IsBound (theIObj))
525 Standard_Integer aDispMode, aHiMod, aSelModeDef;
526 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
527 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
528 myObjects.Bind (theIObj, aStatus);
531 // Register theIObj in the selection manager to prepare further activation of selection
532 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
533 if (!mgrSelector->Contains (anObj))
535 mgrSelector->Load (theIObj);
540 //=======================================================================
543 //=======================================================================
544 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
545 const Standard_Boolean theToUpdateViewer)
547 if (theIObj.IsNull())
552 if (!theIObj->IsAutoHilight())
554 theIObj->ClearSelected();
557 Standard_Boolean wasInCtx = Standard_False;
558 if (HasOpenedContext())
560 // First it is checked if it is possible to remove in the current local context
561 // then one tries to remove in other local contexts, if they allow it...
562 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
563 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
565 if (aCtxIter.Value()->AcceptErase())
567 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
574 EraseGlobal (theIObj, Standard_False);
577 if (theToUpdateViewer)
583 //=======================================================================
584 //function : EraseAll
586 //=======================================================================
587 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
589 if (HasOpenedContext())
594 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
596 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
598 Erase (anObjIter.Key(), Standard_False);
602 if (theToUpdateViewer)
608 //=======================================================================
609 //function : DisplayAll
611 //=======================================================================
612 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
614 if (HasOpenedContext())
619 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
621 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
622 if (aStatus == AIS_DS_Erased)
624 Display (anObjIter.Key(), Standard_False);
628 if (theToUpdateViewer)
634 //=======================================================================
635 //function : DisplaySelected
637 //=======================================================================
638 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
640 if (HasOpenedContext())
645 Standard_Boolean isFound = Standard_False;
646 for (mySelection->Init(); mySelection->More(); mySelection->Next())
648 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
649 Display (anObj, Standard_False);
650 isFound = Standard_True;
653 if (isFound && theToUpdateViewer)
659 //=======================================================================
660 //function : EraseSelected
662 //=======================================================================
663 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
665 if (HasOpenedContext())
670 Standard_Boolean isFound = Standard_False;
672 while (mySelection->More())
674 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
675 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
677 Erase (anObj, Standard_False);
678 isFound = Standard_True;
683 if (isFound && theToUpdateViewer)
689 //=======================================================================
692 //=======================================================================
694 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
695 const Standard_Integer WhichContext)
697 if(anIObj.IsNull()) return Standard_False;
699 if(!HasOpenedContext()) return Standard_False;
700 if(myObjects.IsBound(anIObj)) return Standard_False;
701 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
703 // Protection : if one tries to preserve a temporary object
704 // which is not in the local active context... rob 11-06-97
706 Standard_Integer IsItInLocal = myCurLocalIndex;
707 Standard_Boolean Found(Standard_False);
709 while(IsItInLocal>0 && !Found){
710 if(!myLocalContexts.IsBound(IsItInLocal))
712 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
713 Found = Standard_True;
718 if(!Found) return Standard_False;
721 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
722 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
724 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
725 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
729 if(LS->IsTemporary()){
730 Standard_Integer DM,HM,SM;
731 GetDefModes(anIObj,DM,HM,SM);
733 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
734 if(LS->DisplayMode()!= DM ){
735 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
736 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
739 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
743 // GS->SubIntensityOn();
744 myObjects.Bind(anIObj,GS);
745 mgrSelector->Load(anIObj);
746 mgrSelector->Activate(anIObj,SM,myMainSel);
748 LS->SetTemporary(Standard_False);
750 return Standard_True;
753 //=======================================================================
754 //function : DisplayStatus
756 //=======================================================================
757 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
759 if (theIObj.IsNull())
763 else if (myObjects.IsBound (theIObj))
765 return myObjects (theIObj)->GraphicStatus();
768 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
770 if (aCtxIter.Value()->IsIn (theIObj))
772 return AIS_DS_Temporary;
778 //=======================================================================
781 //=======================================================================
782 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
783 const Standard_Boolean theToUpdateViewer)
785 if (theIObj.IsNull())
790 if (HasOpenedContext())
792 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
793 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
795 if (aCtxIter.Value()->AcceptErase())
797 aCtxIter.Value()->Remove (theIObj);
802 ClearGlobal (theIObj, theToUpdateViewer);
805 //=======================================================================
806 //function : RemoveAll
808 //=======================================================================
809 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
811 AIS_ListOfInteractive aList;
812 ObjectsInside (aList);
813 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
815 Remove (aListIterator.Value(), Standard_False);
818 if (theToUpdateViewer)
824 //=======================================================================
825 //function : ClearPrs
827 //=======================================================================
828 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
829 const Standard_Integer theMode,
830 const Standard_Boolean theToUpdateViewer)
832 if (theIObj.IsNull())
837 if (!HasOpenedContext())
839 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
843 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
844 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
846 if (aCtxIter.Value()->AcceptErase())
848 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
853 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
855 else if (theToUpdateViewer)
861 //=======================================================================
864 //=======================================================================
865 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
866 const Standard_Boolean theToUpdateViewer)
868 if (theIObj.IsNull())
873 if (!theIObj->HasInteractiveContext())
875 theIObj->SetContext (this);
877 if (!HasOpenedContext())
879 if (!myObjects.IsBound (theIObj))
884 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
885 aStatus->SetHilightStatus (Standard_True);
886 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
888 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
889 myMainPM->Highlight (theIObj, aHilightMode);
894 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
897 if (theToUpdateViewer)
902 //=======================================================================
905 //=======================================================================
907 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
908 const Quantity_NameOfColor aCol,
909 const Standard_Boolean updateviewer)
911 if(anIObj.IsNull()) return;
913 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
915 if (!HasOpenedContext())
917 if(!myObjects.IsBound(anIObj)) return;
919 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
920 aStatus->SetHilightStatus (Standard_True);
922 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
924 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
925 myMainPM->Color (anIObj, aCol, aHilightMode);
926 aStatus->SetHilightColor (aCol);
931 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
933 if(updateviewer) myMainVwr->Update();
936 //=======================================================================
937 //function : Unhilight
939 //=======================================================================
941 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
943 if(anIObj.IsNull()) return;
945 if (!HasOpenedContext())
947 if(!myObjects.IsBound(anIObj)) return;
949 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
950 aStatus->SetHilightStatus (Standard_False);
951 aStatus->SetHilightColor(Quantity_NOC_WHITE);
953 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
955 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
956 myMainPM->Unhighlight (anIObj, aHilightMode);
961 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
963 if(updateviewer) myMainVwr->Update();
966 //=======================================================================
967 //function : IsHilighted
969 //=======================================================================
971 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
973 if(anIObj.IsNull()) return Standard_False;
975 if (!HasOpenedContext()){
976 if(!myObjects.IsBound(anIObj))
977 return Standard_False;
978 return myObjects(anIObj)->IsHilighted();
980 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
981 for(;ItM.More();ItM.Next()){
982 if(ItM.Value()->IsHilighted(anIObj))
983 return Standard_True;
985 return Standard_False;
988 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
989 Standard_Boolean& WithColor,
990 Quantity_NameOfColor& TheHiCol) const
992 if(!HasOpenedContext()){
993 if(myObjects.IsBound(anIObj)){
994 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
995 if(STAT->IsHilighted()){
996 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
997 WithColor=Standard_True;
998 TheHiCol = STAT->HilightColor();
1001 WithColor = Standard_False;
1002 return Standard_True;
1005 return Standard_False;
1007 Standard_Integer MaxIndex = HighestIndex();
1008 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1009 if(myLocalContexts.IsBound(i)){
1010 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1011 return Standard_True;
1015 return Standard_False;
1018 //=======================================================================
1019 //function : IsHilighted
1020 //purpose : Returns true if the objects global status is set to highlighted.
1021 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1022 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1023 // custom highlight color name will be stored to theCustomColorName
1024 //=======================================================================
1025 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1026 Standard_Boolean& theIsCustomColor,
1027 Quantity_NameOfColor& theCustomColorName) const
1029 if (theOwner.IsNull() || !theOwner->HasSelectable())
1030 return Standard_False;
1032 const Handle(AIS_InteractiveObject) anObj =
1033 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1035 if (!myObjects.IsBound (anObj))
1036 return Standard_False;
1038 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1039 if (anObjStatus->IsHilighted())
1041 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1043 theIsCustomColor = Standard_True;
1044 theCustomColorName = anObjStatus->HilightColor();
1048 theIsCustomColor = Standard_False;
1051 return Standard_True;
1054 return Standard_False;
1057 //=======================================================================
1058 //function : IsDisplayed
1060 //=======================================================================
1062 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1064 if(anIObj.IsNull()) return Standard_False;
1067 if(myObjects.IsBound(anIObj))
1068 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1069 return Standard_True;
1071 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1072 for(;ItM.More();ItM.Next()){
1073 if(ItM.Value()->IsDisplayed(anIObj))
1074 return Standard_True;
1076 return Standard_False;
1080 //=======================================================================
1081 //function : IsDisplayed
1083 //=======================================================================
1084 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1085 const Standard_Integer theMode) const
1087 if (theIObj.IsNull())
1089 return Standard_False;
1092 if (myObjects.IsBound (theIObj))
1094 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1095 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1096 && theIObj->DisplayMode() == theMode)
1098 return Standard_True;
1102 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1104 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1106 return Standard_True;
1109 return Standard_False;
1112 //=======================================================================
1113 //function : DisplayPriority
1115 //=======================================================================
1116 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1118 if (theIObj.IsNull())
1122 else if (!myObjects.IsBound (theIObj))
1127 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1128 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1129 || aStatus->GraphicStatus() == AIS_DS_Erased)
1131 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1132 ? theIObj->DisplayMode()
1133 : (theIObj->AcceptDisplayMode (myDisplayMode)
1136 return myMainPM->DisplayPriority (theIObj, aDispMode);
1141 //=======================================================================
1142 //function : SetDisplayPriority
1144 //=======================================================================
1145 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1146 const Standard_Integer thePriority)
1148 if (theIObj.IsNull())
1153 if (!theIObj->HasInteractiveContext())
1155 theIObj->SetContext (this);
1158 if (myObjects.IsBound (theIObj))
1160 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1161 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1162 || aStatus->GraphicStatus() == AIS_DS_Erased)
1164 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1165 ? theIObj->DisplayMode()
1166 : (theIObj->AcceptDisplayMode (myDisplayMode)
1169 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1172 else if (HasOpenedContext())
1174 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1178 //=======================================================================
1179 //function : Redisplay
1181 //=======================================================================
1182 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1183 const Standard_Boolean theToUpdateViewer,
1184 const Standard_Boolean theAllModes)
1186 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1187 RecomputeSelectionOnly (theIObj);
1190 //=======================================================================
1191 //function : Redisplay
1193 //=======================================================================
1194 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1195 const Standard_Integer /*theSign*/,
1196 const Standard_Boolean theToUpdateViewer)
1198 Standard_Boolean isRedisplayed = Standard_False;
1199 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1201 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1202 if (anObj->Type() != theKOI)
1207 Redisplay (anObj, Standard_False);
1208 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1212 if (theToUpdateViewer
1215 myMainVwr->Update();
1219 //=======================================================================
1220 //function : RecomputePrsOnly
1222 //=======================================================================
1223 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1224 const Standard_Boolean theToUpdateViewer,
1225 const Standard_Boolean theAllModes)
1227 if (theIObj.IsNull())
1232 theIObj->Update (theAllModes);
1233 if (!theToUpdateViewer)
1238 if (HasOpenedContext()
1239 || (myObjects.IsBound (theIObj)
1240 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1242 myMainVwr->Update();
1245 //=======================================================================
1246 //function : RecomputeSelectionOnly
1248 //=======================================================================
1249 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1256 mgrSelector->RecomputeSelection (theIO);
1258 if (HasOpenedContext())
1260 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1262 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1267 if (!myObjects.IsBound (theIO) ||
1268 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1273 TColStd_ListOfInteger aModes;
1274 ActivatedModes (theIO, aModes);
1275 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1276 for (; aModesIter.More(); aModesIter.Next())
1278 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1282 //=======================================================================
1285 //=======================================================================
1286 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1287 const Standard_Boolean theUpdateViewer)
1289 if (theIObj.IsNull())
1294 TColStd_ListOfInteger aPrsModes;
1295 theIObj->ToBeUpdated (aPrsModes);
1296 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1298 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1301 mgrSelector->Update(theIObj);
1303 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1305 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1308 if (theUpdateViewer)
1310 if (!myObjects.IsBound (theIObj))
1315 switch (myObjects (theIObj)->GraphicStatus())
1317 case AIS_DS_Displayed:
1318 case AIS_DS_Temporary:
1319 myMainVwr->Update();
1327 //=======================================================================
1328 //function : SetLocation
1330 //=======================================================================
1331 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1332 const TopLoc_Location& theLoc)
1334 if (theIObj.IsNull())
1339 if (theIObj->HasTransformation()
1340 && theLoc.IsIdentity())
1342 theIObj->ResetTransformation();
1343 mgrSelector->Update (theIObj, Standard_False);
1346 else if (theLoc.IsIdentity())
1351 // first reset the previous location to properly clean everything...
1352 if (theIObj->HasTransformation())
1354 theIObj->ResetTransformation();
1357 theIObj->SetLocalTransformation (theLoc.Transformation());
1359 if (!HasOpenedContext())
1361 mgrSelector->Update (theIObj, Standard_False);
1365 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1366 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1369 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1370 // to its highlight structure immediately
1371 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
1373 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1375 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1379 //=======================================================================
1380 //function : ResetLocation
1382 //=======================================================================
1383 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1385 if (theIObj.IsNull())
1390 theIObj->ResetTransformation();
1391 mgrSelector->Update (theIObj, Standard_False);
1394 //=======================================================================
1395 //function : HasLocation
1397 //=======================================================================
1398 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1400 return !theIObj.IsNull()
1401 && theIObj->HasTransformation();
1404 //=======================================================================
1405 //function : Location
1407 //=======================================================================
1408 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1410 return theIObj->Transformation();
1413 //=======================================================================
1414 //function : SetDeviationCoefficient
1416 //=======================================================================
1417 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1419 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1422 //=======================================================================
1423 //function : SetDeviationAngle
1425 //=======================================================================
1426 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1428 myDefaultDrawer->SetDeviationAngle (theAngle);
1431 //=======================================================================
1432 //function : DeviationAngle
1433 //purpose : Gets deviationAngle
1434 //=======================================================================
1435 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1437 return myDefaultDrawer->DeviationAngle();
1440 //=======================================================================
1441 //function : DeviationCoefficient
1443 //=======================================================================
1444 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1446 return myDefaultDrawer->DeviationCoefficient();
1449 //=======================================================================
1450 //function : SetHLRDeviationCoefficient
1452 //=======================================================================
1453 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1455 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1458 //=======================================================================
1459 //function : HLRDeviationCoefficient
1461 //=======================================================================
1462 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1464 return myDefaultDrawer->HLRDeviationCoefficient();
1467 //=======================================================================
1468 //function : SetHLRAngle
1470 //=======================================================================
1471 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1473 myDefaultDrawer->SetHLRAngle (theAngle);
1476 //=======================================================================
1477 //function : SetHLRAngleAndDeviation
1478 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1479 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1480 // of myDefaultDrawer
1481 //=======================================================================
1482 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1484 Standard_Real anOutAngl, anOutDefl;
1485 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1487 myDefaultDrawer->SetHLRAngle (anOutAngl);
1488 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1491 //=======================================================================
1492 //function : HLRAngle
1494 //=======================================================================
1495 Standard_Real AIS_InteractiveContext::HLRAngle() const
1497 return myDefaultDrawer->HLRAngle();
1500 //=======================================================================
1501 //function : SetDisplayMode
1503 //=======================================================================
1504 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1505 const Standard_Boolean theToUpdateViewer)
1507 if (theMode == myDisplayMode)
1512 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1514 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1515 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1516 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1517 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1520 || anObj->HasDisplayMode()
1521 || !anObj->AcceptDisplayMode (theMode))
1526 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1527 aStatus->SetDisplayMode (theMode);
1529 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1531 myMainPM->Display (anObj, theMode);
1532 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1534 myMainPM->BeginImmediateDraw();
1535 myMainPM->Unhighlight (anObj, myDisplayMode);
1536 myMainPM->EndImmediateDraw (myMainVwr);
1538 if (aStatus->IsSubIntensityOn())
1540 myMainPM->Color (anObj, mySubIntensity, theMode);
1542 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1546 myDisplayMode = theMode;
1547 if (theToUpdateViewer)
1549 myMainVwr->Update();
1553 //=======================================================================
1554 //function : SetDisplayMode
1556 //=======================================================================
1557 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1558 const Standard_Integer theMode,
1559 const Standard_Boolean theToUpdateViewer)
1561 if (!theIObj->HasInteractiveContext())
1563 theIObj->SetContext(this);
1566 if (!myObjects.IsBound (theIObj))
1568 theIObj->SetDisplayMode (theMode);
1571 else if (!theIObj->AcceptDisplayMode (theMode))
1576 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1577 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1579 theIObj->SetDisplayMode (theMode);
1583 // erase presentations for all display modes different from <aMode>
1584 const Standard_Integer anOldMode = aStatus->DisplayMode();
1585 if (anOldMode != theMode)
1587 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1589 myMainPM->Unhighlight (theIObj, anOldMode);
1591 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1594 aStatus->SetDisplayMode (theMode);
1596 myMainPM->Display (theIObj, theMode);
1597 Standard_Integer aDispMode, aHiMode, aSelMode;
1598 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1599 if (aStatus->IsHilighted())
1601 myMainPM->Highlight (theIObj, aHiMode);
1603 if (aStatus->IsSubIntensityOn())
1605 myMainPM->Color (theIObj, mySubIntensity, theMode);
1608 if (theToUpdateViewer)
1610 myMainVwr->Update();
1612 theIObj->SetDisplayMode (theMode);
1615 //=======================================================================
1616 //function : UnsetDisplayMode
1618 //=======================================================================
1619 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1620 const Standard_Boolean theToUpdateViewer)
1622 if (theIObj.IsNull()
1623 || !theIObj->HasDisplayMode())
1628 if (!myObjects.IsBound (theIObj))
1630 theIObj->UnsetDisplayMode();
1634 const Standard_Integer anOldMode = theIObj->DisplayMode();
1635 if (myDisplayMode == anOldMode)
1640 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1641 aStatus->SetDisplayMode (myDisplayMode);
1643 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1645 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1647 myMainPM->Unhighlight (theIObj, anOldMode);
1649 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1650 myMainPM->Display (theIObj, myDisplayMode);
1652 Standard_Integer aDispMode, aHiMode, aSelMode;
1653 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1654 if (aStatus->IsHilighted())
1656 myMainPM->Highlight (theIObj, aHiMode);
1658 if (aStatus->IsSubIntensityOn())
1660 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1663 if (theToUpdateViewer)
1665 myMainVwr->Update();
1669 theIObj->UnsetDisplayMode();
1672 //=======================================================================
1673 //function : SetCurrentFacingModel
1675 //=======================================================================
1676 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1677 const Aspect_TypeOfFacingModel theModel)
1679 if (!theIObj.IsNull())
1681 theIObj->SetCurrentFacingModel (theModel);
1685 //=======================================================================
1686 //function : redisplayPrsRecModes
1688 //=======================================================================
1689 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1690 const Standard_Boolean theToUpdateViewer)
1692 if (theIObj->RecomputeEveryPrs())
1694 theIObj->Update (Standard_True);
1695 theIObj->UpdateSelection();
1699 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1701 theIObj->Update (aModes.Value(), Standard_False);
1703 theIObj->UpdateSelection();
1704 theIObj->SetRecomputeOk();
1707 if (theToUpdateViewer)
1709 UpdateCurrentViewer();
1713 //=======================================================================
1714 //function : redisplayPrsModes
1716 //=======================================================================
1717 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1718 const Standard_Boolean theToUpdateViewer)
1720 if (theIObj->RecomputeEveryPrs())
1722 theIObj->Update (Standard_True);
1723 theIObj->UpdateSelection();
1727 TColStd_ListOfInteger aModes;
1728 theIObj->ToBeUpdated (aModes);
1729 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1731 theIObj->Update (aModeIter.Value(), Standard_False);
1733 theIObj->SetRecomputeOk();
1736 if (theToUpdateViewer)
1738 UpdateCurrentViewer();
1742 //=======================================================================
1743 //function : SetColor
1745 //=======================================================================
1746 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1747 const Quantity_NameOfColor theColor,
1748 const Standard_Boolean theToUpdateViewer)
1750 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1753 //=======================================================================
1754 //function : SetColor
1756 //=======================================================================
1757 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1758 const Quantity_Color& theColor,
1759 const Standard_Boolean theToUpdateViewer)
1761 if (theIObj.IsNull())
1766 if (!theIObj->HasInteractiveContext())
1768 theIObj->SetContext (this);
1770 theIObj->SetColor (theColor);
1771 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1774 //=======================================================================
1775 //function : SetIsoOnTriangulation
1777 //=======================================================================
1778 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1779 const Handle(AIS_InteractiveObject)& theObject)
1781 if (theObject.IsNull())
1786 theObject->SetIsoOnTriangulation (theIsEnabled);
1789 //=======================================================================
1790 //function : SetDeviationCoefficient
1792 //=======================================================================
1793 void AIS_InteractiveContext::SetDeviationCoefficient (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->SetOwnDeviationCoefficient (theCoefficient);
1820 redisplayPrsModes (theIObj, theToUpdateViewer);
1823 //=======================================================================
1824 //function : SetHLRDeviationCoefficient
1826 //=======================================================================
1827 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1828 const Standard_Real theCoefficient,
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_Object
1843 && theIObj->Type() != AIS_KOI_Shape)
1847 else if (theIObj->Signature() != 0)
1852 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1853 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1854 redisplayPrsModes (theIObj, theToUpdateViewer);
1857 //=======================================================================
1858 //function : SetDeviationAngle
1860 //=======================================================================
1861 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1862 const Standard_Real theAngle,
1863 const Standard_Boolean theToUpdateViewer)
1865 if (theIObj.IsNull())
1870 if (!theIObj->HasInteractiveContext())
1872 theIObj->SetContext (this);
1875 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1876 if (theIObj->Type() != AIS_KOI_Shape)
1880 else if (theIObj->Signature() != 0)
1885 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1886 aShape->SetOwnDeviationAngle (theAngle);
1887 redisplayPrsModes (theIObj, theToUpdateViewer);
1890 //=======================================================================
1891 //function : SetAngleAndDeviation
1893 //=======================================================================
1894 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1895 const Standard_Real theAngle,
1896 const Standard_Boolean theToUpdateViewer)
1898 if (theIObj.IsNull())
1903 if (!theIObj->HasInteractiveContext())
1905 theIObj->SetContext (this);
1908 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1909 if (theIObj->Type() != AIS_KOI_Shape)
1913 if (theIObj->Signature() != 0)
1918 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1919 aShape->SetAngleAndDeviation (theAngle);
1921 if (theIObj->RecomputeEveryPrs())
1923 theIObj->Update (Standard_True);
1924 theIObj->UpdateSelection();
1928 Update (theIObj, theToUpdateViewer);
1932 //=======================================================================
1933 //function : SetHLRAngleAndDeviation
1935 //=======================================================================
1936 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1937 const Standard_Real theAngle,
1938 const Standard_Boolean theToUpdateViewer)
1940 if (theIObj.IsNull())
1945 if (!theIObj->HasInteractiveContext())
1947 theIObj->SetContext (this);
1950 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1951 if (theIObj->Type() != AIS_KOI_Shape)
1955 if (theIObj->Signature() != 0)
1959 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1960 aShape->SetHLRAngleAndDeviation (theAngle);
1961 redisplayPrsModes (theIObj, theToUpdateViewer);
1964 //=======================================================================
1965 //function : SetHLRDeviationAngle
1967 //=======================================================================
1968 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1969 const Standard_Real theAngle,
1970 const Standard_Boolean theToUpdateViewer)
1972 if (theIObj.IsNull())
1977 if (!theIObj->HasInteractiveContext())
1979 theIObj->SetContext (this);
1982 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1983 if (theIObj->Type() != AIS_KOI_Shape)
1987 if (theIObj->Signature() != 0)
1991 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1992 aShape->SetOwnHLRDeviationAngle (theAngle);
1993 redisplayPrsModes (theIObj, theToUpdateViewer);
1996 //=======================================================================
1997 //function : UnsetColor
1999 //=======================================================================
2000 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2001 const Standard_Boolean theToUpdateViewer)
2003 if (theIObj.IsNull())
2008 theIObj->UnsetColor();
2009 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2012 //=======================================================================
2013 //function : HasColor
2015 //=======================================================================
2016 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2018 return theIObj->HasColor();
2021 //=======================================================================
2024 //=======================================================================
2025 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2027 return theIObj->Color();
2030 //=======================================================================
2033 //=======================================================================
2034 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2035 Quantity_Color& theColor) const
2037 theIObj->Color (theColor);
2040 //=======================================================================
2043 //=======================================================================
2044 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2046 return theIObj->Width();
2049 //=======================================================================
2050 //function : SetWidth
2052 //=======================================================================
2053 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2054 const Standard_Real theWidth,
2055 const Standard_Boolean theToUpdateViewer)
2057 if (theIObj.IsNull())
2062 if (!theIObj->HasInteractiveContext())
2064 theIObj->SetContext (this);
2067 theIObj->SetWidth (theWidth);
2068 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2069 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2071 if (myLastinMain->IsAutoHilight())
2073 const Standard_Integer aHiMode =
2074 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2075 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2079 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2084 //=======================================================================
2085 //function : UnsetWidth
2087 //=======================================================================
2088 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2089 const Standard_Boolean theToUpdateViewer)
2091 if (theIObj.IsNull())
2096 theIObj->UnsetWidth();
2097 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2100 //=======================================================================
2101 //function : SetMaterial
2103 //=======================================================================
2104 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2105 const Graphic3d_NameOfMaterial theName,
2106 const Standard_Boolean theToUpdateViewer)
2108 if (theIObj.IsNull())
2113 if (!theIObj->HasInteractiveContext())
2115 theIObj->SetContext (this);
2118 theIObj->SetMaterial (theName);
2119 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2122 //=======================================================================
2123 //function : UnsetMaterial
2125 //=======================================================================
2126 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2127 const Standard_Boolean theToUpdateViewer)
2129 if (theIObj.IsNull())
2133 theIObj->UnsetMaterial();
2134 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2137 //=======================================================================
2138 //function : SetTransparency
2140 //=======================================================================
2141 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2142 const Standard_Real theValue,
2143 const Standard_Boolean theToUpdateViewer)
2145 if (theIObj.IsNull())
2150 if (!theIObj->HasInteractiveContext())
2152 theIObj->SetContext (this);
2155 if (!theIObj->IsTransparent()
2156 && theValue <= 0.05)
2161 if (theValue <= 0.05)
2163 UnsetTransparency (theIObj, theToUpdateViewer);
2167 theIObj->SetTransparency (theValue);
2168 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2171 //=======================================================================
2172 //function : UnsetTransparency
2174 //=======================================================================
2175 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2176 const Standard_Boolean theToUpdateViewer)
2178 if (theIObj.IsNull())
2183 theIObj->UnsetTransparency();
2184 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2187 //=======================================================================
2188 //function : SetSelectedAspect
2190 //=======================================================================
2191 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2192 const Standard_Boolean ,
2193 const Standard_Boolean theToUpdateViewer)
2195 if (HasOpenedContext())
2200 Standard_Boolean isFound = Standard_False;
2201 for (mySelection->Init(); mySelection->More(); mySelection->Next())
2203 isFound = Standard_True;
2204 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
2205 anObj->SetAspect (theAspect);
2208 if (isFound && theToUpdateViewer)
2210 myMainVwr->Update();
2214 //=======================================================================
2215 //function : SetLocalAttributes
2217 //=======================================================================
2218 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2219 const Handle(Prs3d_Drawer)& theDrawer,
2220 const Standard_Boolean theToUpdateViewer)
2222 if (theIObj.IsNull())
2227 if (!theIObj->HasInteractiveContext())
2229 theIObj->SetContext (this);
2232 theIObj->SetAttributes (theDrawer);
2233 Update (theIObj, theToUpdateViewer);
2236 //=======================================================================
2237 //function : UnsetLocalAttributes
2239 //=======================================================================
2240 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2241 const Standard_Boolean theToUpdateViewer)
2243 if (theIObj.IsNull())
2248 if (!theIObj->HasInteractiveContext())
2250 theIObj->SetContext (this);
2252 theIObj->UnsetAttributes();
2253 Update (theIObj, theToUpdateViewer);
2256 //=======================================================================
2259 //=======================================================================
2260 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2261 TCollection_ExtendedString& theStatus) const
2264 if (theIObj.IsNull()
2265 || !myObjects.IsBound (theIObj))
2270 theStatus += "\t ____________________________________________";
2271 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2272 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2273 switch (aStatus->GraphicStatus())
2275 case AIS_DS_Displayed:
2277 theStatus += "\t| -->Displayed\n";
2282 theStatus += "\t| -->Erased\n";
2289 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2290 theStatus += "\t|\t Mode ";
2291 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2294 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2296 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2297 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2299 theStatus += "\t\t Mode ";
2300 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2303 theStatus += "\t ____________________________________________";
2306 //=======================================================================
2307 //function : GetDefModes
2309 //=======================================================================
2310 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2311 Standard_Integer& theDispMode,
2312 Standard_Integer& theHiMode,
2313 Standard_Integer& theSelMode) const
2315 if (theIObj.IsNull())
2320 theDispMode = theIObj->HasDisplayMode()
2321 ? theIObj->DisplayMode()
2322 : (theIObj->AcceptDisplayMode (myDisplayMode)
2325 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2326 theSelMode = theIObj->GlobalSelectionMode();
2329 //=======================================================================
2330 //function : EraseGlobal
2332 //=======================================================================
2333 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2334 const Standard_Boolean theToUpdateviewer)
2336 if (theIObj.IsNull()
2337 || !myObjects.IsBound (theIObj))
2342 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2344 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2345 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2346 || aStatus->GraphicStatus() == AIS_DS_Erased)
2351 if (aStatus->IsHilighted())
2353 if (IsCurrent (theIObj))
2355 AddOrRemoveCurrentObject (theIObj, Standard_False);
2357 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2359 myMainPM->Unhighlight (theIObj, aStatus->DisplayMode());
2363 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2365 if (aStatus->IsHilighted()
2366 && theIObj->HasHilightMode())
2368 myMainPM->Unhighlight (theIObj, aDispMode);
2371 if (!myLastPicked.IsNull()
2372 && myLastPicked->Selectable() == theIObj)
2374 myMainPM->ClearImmediateDraw();
2377 if (IsSelected (theIObj)
2378 && aStatus->DisplayMode() != aDispMode)
2380 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2383 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2385 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2387 aStatus->ClearSelectionModes();
2388 aStatus->SetGraphicStatus (AIS_DS_Erased);
2390 if (theToUpdateviewer)
2392 myMainVwr->Update();
2396 //=======================================================================
2397 //function : unhighlightOwners
2399 //=======================================================================
2400 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2402 mySelection->Init();
2403 while (mySelection->More())
2405 const Handle(SelectMgr_EntityOwner) anOwner =
2406 Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
2407 if (anOwner->Selectable() == theObject)
2409 if (anOwner->IsSelected())
2411 AddOrRemoveSelected (anOwner, Standard_False);
2412 mySelection->Init();
2416 mySelection->Next();
2420 //=======================================================================
2421 //function : ClearGlobal
2423 //=======================================================================
2424 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2425 const Standard_Boolean theToUpdateviewer)
2427 if (theIObj.IsNull()
2428 || !myObjects.IsBound (theIObj))
2430 // for cases when reference shape of connected interactives was not displayed
2431 // but its selection primitives were calculated
2432 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2433 mgrSelector->Remove (anObj);
2437 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2438 unhighlightOwners (theIObj);
2440 myMainPM->Erase (theIObj, -1);
2442 // Object removes from Detected sequence
2443 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2445 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2447 && anObj != theIObj)
2449 myAISDetectedSeq.Remove (aDetIter);
2453 // remove IO from the selection manager to avoid memory leaks
2454 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2455 mgrSelector->Remove (anObj);
2457 myObjects.UnBind (theIObj);
2458 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2459 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2461 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2464 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2465 myLastinMain.Nullify();
2466 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2467 myLastPicked.Nullify();
2468 myMainPM->ClearImmediateDraw();
2470 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2472 myMainVwr->Update();
2476 //=======================================================================
2477 //function : ClearGlobalPrs
2479 //=======================================================================
2480 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2481 const Standard_Integer theMode,
2482 const Standard_Boolean theToUpdateViewer)
2484 if (theIObj.IsNull()
2485 || !myObjects.IsBound (theIObj))
2490 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2491 if (aStatus->DisplayMode() == theMode)
2493 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2494 if (aDispMode == theMode
2495 && myMainPM->IsHighlighted (theIObj, theMode))
2497 myMainPM->Unhighlight (theIObj, theMode);
2500 myMainPM->Erase (theIObj, theMode);
2503 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2504 && theToUpdateViewer)
2506 myMainVwr->Update();
2510 //=======================================================================
2511 //function : DrawHiddenLine
2513 //=======================================================================
2514 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2516 return myDefaultDrawer->DrawHiddenLine();
2519 //=======================================================================
2520 //function : EnableDrawHiddenLine
2522 //=======================================================================
2523 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2525 myDefaultDrawer->EnableDrawHiddenLine();
2528 //=======================================================================
2529 //function : DisableDrawHiddenLine
2531 //=======================================================================
2532 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2534 myDefaultDrawer->DisableDrawHiddenLine();
2537 //=======================================================================
2538 //function : HiddenLineAspect
2540 //=======================================================================
2541 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2543 return myDefaultDrawer->HiddenLineAspect();
2546 //=======================================================================
2547 //function : SetHiddenLineAspect
2549 //=======================================================================
2550 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2552 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2555 //=======================================================================
2556 //function : SetIsoNumber
2558 //=======================================================================
2559 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2560 const AIS_TypeOfIso theType)
2565 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2568 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2571 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2572 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2577 //=======================================================================
2578 //function : IsoNumber
2580 //=======================================================================
2581 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2585 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2586 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2587 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2588 ? myDefaultDrawer->UIsoAspect()->Number()
2594 //=======================================================================
2595 //function : IsoOnPlane
2597 //=======================================================================
2598 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2600 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2603 //=======================================================================
2604 //function : IsoOnPlane
2606 //=======================================================================
2607 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2609 return myDefaultDrawer->IsoOnPlane();
2612 //=======================================================================
2613 //function : IsoOnTriangulation
2615 //=======================================================================
2616 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2618 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2621 //=======================================================================
2622 //function : IsoOnTriangulation
2624 //=======================================================================
2625 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2627 return myDefaultDrawer->IsoOnTriangulation();
2630 //function : SetPixelTolerance
2631 //purpose : Disables the mechanism of adaptive tolerance calculation in
2632 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2633 // sensitive entities activated. For more information, see
2634 // SelectMgr_ViewerSelector.hxx
2635 //=======================================================================
2636 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2638 if (HasOpenedContext())
2640 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2644 myMainSel->SetPixelTolerance (thePrecision);
2648 //=======================================================================
2649 //function : PixelTolerance
2651 //=======================================================================
2652 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2654 return HasOpenedContext()
2655 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2656 : myMainSel->PixelTolerance();
2659 //=======================================================================
2660 //function : SetSelectionSensitivity
2661 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2662 //=======================================================================
2663 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2664 const Standard_Integer theMode,
2665 const Standard_Integer theNewSensitivity)
2667 if (HasOpenedContext())
2669 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2673 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2676 //=======================================================================
2677 //function : IsInLocal
2679 //=======================================================================
2680 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2681 Standard_Integer& theIndex) const
2683 if (theIObj.IsNull())
2685 return Standard_False;
2688 // if it exists at neutral point 0 index is returned
2689 if (myObjects.IsBound (theIObj))
2692 return Standard_False;
2695 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2697 if (myLocalContexts.IsBound (aCtxIter))
2699 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2701 theIndex = aCtxIter;
2702 return Standard_True;
2707 return Standard_False;
2710 //=======================================================================
2711 //function : InitAttributes
2713 //=======================================================================
2714 void AIS_InteractiveContext::InitAttributes()
2716 mgrSelector->Add (myMainSel);
2718 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2719 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2721 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2722 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2723 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2724 aLineAspect->SetWidth (1.0);
2725 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2727 // tolerance to 2 pixels...
2728 SetPixelTolerance (2);
2730 // Customizing the drawer for trihedrons and planes...
2731 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2732 const Standard_Real aLength = 100.0;
2733 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2734 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2735 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2736 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2737 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2739 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2740 const Standard_Real aPlaneLength = 200.0;
2741 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2742 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2745 //=======================================================================
2746 //function : TrihedronSize
2748 //=======================================================================
2749 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2751 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2754 //=======================================================================
2755 //function : SetTrihedronSize
2757 //=======================================================================
2758 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2759 const Standard_Boolean /*updateviewer*/)
2761 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2762 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2763 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2766 //=======================================================================
2767 //function : SetPlaneSize
2769 //=======================================================================
2770 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2771 const Standard_Real theValY,
2772 const Standard_Boolean /*updateviewer*/)
2774 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2775 Redisplay (AIS_KOI_Datum, 7);
2778 //=======================================================================
2779 //function : SetPlaneSize
2781 //=======================================================================
2782 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2783 const Standard_Boolean theToUpdateViewer)
2785 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2788 //=======================================================================
2789 //function : PlaneSize
2791 //=======================================================================
2792 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2793 Standard_Real& theY) const
2795 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2796 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2797 return (Abs (theX - theY) <= Precision::Confusion());
2800 //=======================================================================
2801 //function : SetAutoActivateSelection
2803 //=======================================================================
2804 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2806 myIsAutoActivateSelMode = theIsAuto;
2809 //=======================================================================
2810 //function : GetAutoActivateSelection
2812 //=======================================================================
2813 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2815 return myIsAutoActivateSelMode;
2818 //=======================================================================
2819 //function : SetZLayer
2821 //=======================================================================
2822 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2823 const Standard_Integer theLayerId)
2825 if (theIObj.IsNull())
2828 theIObj->SetZLayer (theLayerId);
2831 //=======================================================================
2832 //function : GetZLayer
2834 //=======================================================================
2835 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2837 return !theIObj.IsNull()
2839 : Graphic3d_ZLayerId_UNKNOWN;
2842 //=======================================================================
2843 //function : RebuildSelectionStructs
2844 //purpose : Rebuilds 1st level of BVH selection forcibly
2845 //=======================================================================
2846 void AIS_InteractiveContext::RebuildSelectionStructs()
2848 myMainSel->RebuildObjectsTree (Standard_True);
2851 //=======================================================================
2852 //function : Disconnect
2853 //purpose : Disconnects selectable object from an assembly and updates selection structures
2854 //=======================================================================
2855 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2856 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2858 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2860 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2861 theObj->Disconnect (theObjToDisconnect);
2862 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2863 mgrSelector->Remove (anObj);
2865 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2867 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2868 theObj->Disconnect();
2869 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2870 mgrSelector->Remove (anObj);
2876 //=======================================================================
2877 //function : FitSelected
2878 //purpose : Fits the view corresponding to the bounds of selected objects
2879 //=======================================================================
2880 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2881 const Standard_Real theMargin,
2882 const Standard_Boolean theToUpdate)
2884 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2885 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2887 Bnd_Box aBndSelected;
2889 AIS_MapOfObjectOwners anObjectOwnerMap;
2890 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2892 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2893 if (!anObj.IsNull())
2895 if (anObj->IsInfinite())
2899 anObj->BoundingBox (aTmpBnd);
2900 aBndSelected.Add (aTmpBnd);
2904 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2905 if (anOwner.IsNull())
2908 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2909 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2911 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2912 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2915 anOwnerMap->Add (anOwner);
2919 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2921 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2922 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2923 aBndSelected.Add (aTmpBox);
2926 anObjectOwnerMap.Clear();
2928 if (aBndSelected.IsVoid())
2931 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2934 //=======================================================================
2935 //function : SetTransformPersistence
2937 //=======================================================================
2938 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2939 const Graphic3d_TransModeFlags& theFlag,
2940 const gp_Pnt& thePoint)
2942 theObject->SetTransformPersistence (theFlag, thePoint);
2944 if (!myObjects.IsBound (theObject))
2949 mgrSelector->UpdateSelection (theObject);
2951 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2952 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2953 for (aCurViewer->InitActiveViews(); aCurViewer->MoreActiveViews(); aCurViewer->NextActiveViews())
2955 aCurViewer->ActiveView()->View()->InvalidateBVHData (aLayerId);
2956 aCurViewer->ActiveView()->View()->InvalidateZLayerBoundingBox (aLayerId);