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_InteractiveContext.ixx>
21 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
22 #include <TColStd_ListIteratorOfListOfInteger.hxx>
23 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
24 #include <AIS_LocalContext.hxx>
25 #include <AIS_LocalStatus.hxx>
26 #include <Precision.hxx>
27 #include <AIS_Selection.hxx>
28 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
29 #include <AIS_ConnectedInteractive.hxx>
30 #include <AIS_MultipleConnectedInteractive.hxx>
31 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
32 #include <AIS_GlobalStatus.hxx>
33 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
34 #include <PrsMgr_ModedPresentation.hxx>
35 #include <Visual3d_ViewManager.hxx>
36 #include <Visual3d_View.hxx>
37 #include <Prs3d_ShadingAspect.hxx>
38 #include <AIS_Shape.hxx>
39 #include <Graphic3d_AspectFillArea3d.hxx>
40 #include <HLRBRep.hxx>
41 #include <Prs3d_IsoAspect.hxx>
42 #include <Prs3d_DatumAspect.hxx>
43 #include <Prs3d_PlaneAspect.hxx>
44 #include <PrsMgr_PresentableObject.hxx>
45 #include <Standard_Atomic.hxx>
46 #include <StdSelect_ViewerSelector3d.hxx>
47 #include <UnitsAPI.hxx>
49 #include <AIS_Trihedron.hxx>
50 #include <Geom_Axis2Placement.hxx>
51 #include <OSD_Environment.hxx>
53 #include <AIS_ListIteratorOfListOfInteractive.hxx>
54 #include <AIS_InteractiveObject.hxx>
55 #include <SelectMgr_EntityOwner.hxx>
59 static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
60 static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
62 static TCollection_AsciiString AIS_Context_NewSelName()
64 return TCollection_AsciiString ("AIS_SelContext_")
65 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
68 static TCollection_AsciiString AIS_Context_NewCurName()
70 return TCollection_AsciiString ("AIS_CurContext_")
71 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
74 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
75 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
78 //=======================================================================
79 //function : AIS_InteractiveContext
81 //=======================================================================
83 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
84 mgrSelector(new SelectMgr_SelectionManager()),
85 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
86 myMainVwr(MainViewer),
87 myMainSel(new StdSelect_ViewerSelector3d()),
88 myWasLastMain(Standard_False),
89 myCurrentTouched(Standard_False),
90 mySelectedTouched(Standard_False),
91 myToHilightSelected(Standard_True),
92 myFilters(new SelectMgr_OrFilter()),
93 myDefaultDrawer(new Prs3d_Drawer()),
94 myDefaultColor(Quantity_NOC_GOLDENROD),
95 myHilightColor(Quantity_NOC_CYAN1),
96 mySelectionColor(Quantity_NOC_GRAY80),
97 myPreselectionColor(Quantity_NOC_GREEN),
98 mySubIntensity(Quantity_NOC_GRAY40),
103 myIsAutoActivateSelMode( Standard_True )
108 void AIS_InteractiveContext::Delete() const
110 // clear the static current selection
111 AIS_Selection::ClearCurrentSelection();
113 // to avoid an exception
114 if (AIS_Selection::Find (mySelectionName.ToCString()))
116 AIS_Selection::Remove (mySelectionName.ToCString());
119 // to avoid an exception
120 if (AIS_Selection::Find (myCurrentName.ToCString()))
122 AIS_Selection::Remove (myCurrentName.ToCString());
125 // let's remove one reference explicitly. this operation's supposed to
126 // be performed when mgrSelector will be destroyed but anyway...
127 mgrSelector->Remove (myMainSel);
129 Handle(AIS_InteractiveContext) aNullContext;
130 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
132 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
133 anObj->SetContext (aNullContext);
135 MMgt_TShared::Delete();
138 //=======================================================================
139 //function : AIS_SelectionName
141 //=======================================================================
142 const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const
144 if(!HasOpenedContext())
145 return mySelectionName;
146 return myLocalContexts(myCurLocalIndex)->SelectionName();
152 //=======================================================================
153 //function : UpdateCurrentViewer
155 //=======================================================================
157 void AIS_InteractiveContext::UpdateCurrentViewer()
159 if (!myMainVwr.IsNull())
164 //=======================================================================
165 //function : DomainOfMainViewer
167 //=======================================================================
169 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
171 return myMainVwr->Domain();
175 //=======================================================================
176 //function : DisplayedObjects
178 //=======================================================================
179 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
180 const Standard_Boolean theOnlyFromNeutral) const
182 if (!HasOpenedContext()
183 || theOnlyFromNeutral)
185 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
187 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
189 theListOfIO.Append (anObjIter.Key());
196 TColStd_MapOfTransient aDispMap;
197 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
199 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
201 aDispMap.Add (anObjIter.Key());
205 // parse all local contexts...
206 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
208 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
209 aLocCtx->DisplayedObjects (aDispMap);
212 Handle(AIS_InteractiveObject) anObj;
213 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
215 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
216 anObj = *((Handle(AIS_InteractiveObject)* )&aTransient);
217 theListOfIO.Append (anObj);
221 //=======================================================================
222 //function : DisplayedObjects
224 //=======================================================================
225 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
226 const Standard_Integer theSign,
227 AIS_ListOfInteractive& theListOfIO,
228 const Standard_Boolean /*OnlyFromNeutral*/) const
230 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
233 //=======================================================================
234 //function : ErasedObjects
236 //=======================================================================
237 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
239 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
242 //=======================================================================
243 //function : ErasedObjects
245 //=======================================================================
246 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
247 const Standard_Integer theSign,
248 AIS_ListOfInteractive& theListOfIO) const
250 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
253 //=======================================================================
254 //function : ObjectsByDisplayStatus
256 //=======================================================================
257 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
258 AIS_ListOfInteractive& theListOfIO) const
260 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
262 if (anObjIter.Value()->GraphicStatus() == theStatus)
264 theListOfIO.Append (anObjIter.Key());
269 //=======================================================================
270 //function : ObjectsByDisplayStatus
272 //=======================================================================
273 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
274 const Standard_Integer theSign,
275 const AIS_DisplayStatus theStatus,
276 AIS_ListOfInteractive& theListOfIO) const
278 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
280 if (theStatus != AIS_DS_None
281 && anObjIter.Value()->GraphicStatus() != theStatus)
285 else if (anObjIter.Key()->Type() != theKind)
291 || anObjIter.Key()->Signature() == theSign)
293 theListOfIO.Append (anObjIter.Key());
298 //=======================================================================
299 //function : ObjectsInside
301 //=======================================================================
302 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
303 const AIS_KindOfInteractive theKind,
304 const Standard_Integer theSign) const
306 if (theKind == AIS_KOI_None
309 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
311 theListOfIO.Append (anObjIter.Key());
316 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
318 if (anObjIter.Key()->Type() != theKind)
324 || anObjIter.Key()->Signature() == theSign)
326 theListOfIO.Append (anObjIter.Key());
331 //=======================================================================
332 //function : ObjectsForView
334 //=======================================================================
335 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
336 const Handle(V3d_View)& theView,
337 const Standard_Boolean theIsVisibleInView,
338 const AIS_DisplayStatus theStatus) const
340 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
341 const Standard_Integer aViewId = aCView->ViewId;
342 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
344 if (theStatus != AIS_DS_None
345 && anObjIter.Value()->GraphicStatus() != theStatus)
347 theListOfIO.Append (anObjIter.Key());
351 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (anObjIter.Key());
352 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
353 if (isVisible == theIsVisibleInView)
355 theListOfIO.Append (anObjIter.Key());
360 //=======================================================================
363 //=======================================================================
364 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
365 const Standard_Boolean theToUpdateViewer)
367 if (theIObj.IsNull())
372 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
373 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
375 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
376 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
379 //=======================================================================
380 //function : SetViewAffinity
382 //=======================================================================
383 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
384 const Handle(V3d_View)& theView,
385 const Standard_Boolean theIsVisible)
388 || !myObjects.IsBound (theIObj))
393 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (theIObj);
394 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
395 anAffinity->SetVisible (aCView->ViewId, theIsVisible == Standard_True);
398 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
402 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
406 //=======================================================================
409 //=======================================================================
410 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
411 const Standard_Integer theDispMode,
412 const Standard_Integer theSelectionMode,
413 const Standard_Boolean theToUpdateViewer,
414 const Standard_Boolean theToAllowDecomposition,
415 const AIS_DisplayStatus theDispStatus)
417 if (theIObj.IsNull())
422 if (theDispStatus == AIS_DS_Erased)
424 Erase (theIObj, theToUpdateViewer);
425 Load (theIObj, theSelectionMode, theToAllowDecomposition);
429 if (!theIObj->HasInteractiveContext())
431 theIObj->SetContext (this);
434 if (theDispStatus == AIS_DS_Temporary
435 && !HasOpenedContext())
439 else if (HasOpenedContext())
441 if (theDispStatus == AIS_DS_None
442 || theDispStatus == AIS_DS_Temporary)
444 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
445 if (theToUpdateViewer)
453 if (!myObjects.IsBound (theIObj))
455 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
456 myObjects.Bind (theIObj, aStatus);
457 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->RegisterObject (theIObj);
458 myMainPM->Display(theIObj, theDispMode);
459 if (theSelectionMode != -1)
461 if (!mgrSelector->Contains (theIObj))
463 mgrSelector->Load (theIObj);
465 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
470 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
471 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
476 // Erase presentations for all display modes different from aDispMode.
477 // Then make sure aDispMode is displayed and maybe highlighted.
478 // Finally, activate selection mode <SelMode> if not yet activated.
479 TColStd_ListOfInteger aModesToRemove;
480 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
482 const Standard_Integer anOldMode = aDispModeIter.Value();
483 if (anOldMode != theDispMode)
485 aModesToRemove.Append (anOldMode);
486 if(myMainPM->IsHighlighted (theIObj, anOldMode))
488 myMainPM->Unhighlight (theIObj, anOldMode);
490 myMainPM->Erase (theIObj, anOldMode);
494 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
496 aStatus->RemoveDisplayMode (aRemModeIter.Value());
499 if (!aStatus->IsDModeIn (theDispMode))
501 aStatus->AddDisplayMode (theDispMode);
504 myMainPM->Display (theIObj, theDispMode);
505 aStatus->SetGraphicStatus (AIS_DS_Displayed);
506 if (aStatus->IsHilighted())
508 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
509 myMainPM->Highlight (theIObj, aHiMod);
511 if (theSelectionMode != -1)
513 if (!mgrSelector->Contains (theIObj))
515 mgrSelector->Load (theIObj);
517 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
519 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
524 if (theToUpdateViewer)
530 //=======================================================================
533 //=======================================================================
534 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
535 const Standard_Integer theSelMode,
536 const Standard_Boolean theToAllowDecomposition)
538 if (theIObj.IsNull())
543 if (!theIObj->HasInteractiveContext())
545 theIObj->SetContext (this);
548 if (HasOpenedContext())
550 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
555 && !theToAllowDecomposition)
557 if (!myObjects.IsBound (theIObj))
559 Standard_Integer aDispMode, aHiMod, aSelModeDef;
560 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
561 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
562 myObjects.Bind (theIObj, aStatus);
565 // Register theIObj in the selection manager to prepare further activation of selection
566 if (!mgrSelector->Contains (theIObj))
568 mgrSelector->Load (theIObj);
573 //=======================================================================
576 //=======================================================================
577 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
578 const Standard_Boolean theToUpdateViewer)
580 if (theIObj.IsNull())
585 if (!theIObj->IsAutoHilight())
587 theIObj->ClearSelected();
590 Standard_Boolean wasInCtx = Standard_False;
591 if (HasOpenedContext())
593 // First it is checked if it is possible to remove in the current local context
594 // then one tries to remove in other local contexts, if they allow it...
595 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
596 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
598 if (aCtxIter.Value()->AcceptErase())
600 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
607 EraseGlobal (theIObj, Standard_False);
610 if (theToUpdateViewer)
616 //=======================================================================
617 //function : EraseAll
619 //=======================================================================
620 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
622 if (HasOpenedContext())
627 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
629 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
631 Erase (anObjIter.Key(), Standard_False);
635 if (theToUpdateViewer)
641 //=======================================================================
642 //function : DisplayAll
644 //=======================================================================
645 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
647 if (HasOpenedContext())
652 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
654 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
655 if (aStatus == AIS_DS_Erased)
657 Display (anObjIter.Key(), Standard_False);
661 if (theToUpdateViewer)
667 //=======================================================================
668 //function : DisplaySelected
670 //=======================================================================
671 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
673 if (HasOpenedContext())
678 Standard_Boolean isFound = Standard_False;
679 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
680 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
682 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
683 Display (anObj, Standard_False);
684 isFound = Standard_True;
687 if (isFound && theToUpdateViewer)
693 //=======================================================================
694 //function : EraseSelected
696 //=======================================================================
697 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
699 if (HasOpenedContext())
704 Standard_Boolean isFound = Standard_False;
705 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
706 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
708 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
709 Erase (anObj, Standard_False);
710 isFound = Standard_True;
713 if (isFound && theToUpdateViewer)
719 //=======================================================================
722 //=======================================================================
724 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
725 const Standard_Integer WhichContext)
727 if(anIObj.IsNull()) return Standard_False;
729 if(!HasOpenedContext()) return Standard_False;
730 if(myObjects.IsBound(anIObj)) return Standard_False;
731 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
733 // Protection : if one tries to preserve a temporary object
734 // which is not in the local active context... rob 11-06-97
736 Standard_Integer IsItInLocal = myCurLocalIndex;
737 Standard_Boolean Found(Standard_False);
739 while(IsItInLocal>0 && !Found){
740 if(!myLocalContexts.IsBound(IsItInLocal))
742 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
743 Found = Standard_True;
748 if(!Found) return Standard_False;
751 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
752 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
754 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
755 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
759 if(LS->IsTemporary()){
760 Standard_Integer DM,HM,SM;
761 GetDefModes(anIObj,DM,HM,SM);
763 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
764 if(LS->DisplayMode()!= DM ){
765 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
766 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
769 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
773 // GS->SubIntensityOn();
774 myObjects.Bind(anIObj,GS);
775 mgrSelector->Load(anIObj);
776 mgrSelector->Activate(anIObj,SM,myMainSel);
778 LS->SetTemporary(Standard_False);
780 return Standard_True;
783 //=======================================================================
784 //function : DisplayStatus
786 //=======================================================================
787 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
789 if (theIObj.IsNull())
793 else if (myObjects.IsBound (theIObj))
795 return myObjects (theIObj)->GraphicStatus();
798 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
800 if (aCtxIter.Value()->IsIn (theIObj))
802 return AIS_DS_Temporary;
808 //=======================================================================
809 //function : DisplayedModes
811 //=======================================================================
812 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
814 return myObjects (theIObj)->DisplayedModes();
817 //=======================================================================
820 //=======================================================================
821 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
822 const Standard_Boolean theToUpdateViewer)
824 if (theIObj.IsNull())
829 if (HasOpenedContext())
831 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
832 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
834 if (aCtxIter.Value()->AcceptErase())
836 aCtxIter.Value()->Remove (theIObj);
841 ClearGlobal (theIObj, theToUpdateViewer);
844 //=======================================================================
845 //function : RemoveAll
847 //=======================================================================
848 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
850 AIS_ListOfInteractive aList;
851 ObjectsInside (aList);
852 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
854 Remove (aListIterator.Value(), Standard_False);
857 if (theToUpdateViewer)
863 //=======================================================================
864 //function : ClearPrs
866 //=======================================================================
867 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
868 const Standard_Integer theMode,
869 const Standard_Boolean theToUpdateViewer)
871 if (theIObj.IsNull())
876 if (!HasOpenedContext())
878 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
882 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
883 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
885 if (aCtxIter.Value()->AcceptErase())
887 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
892 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
894 else if (theToUpdateViewer)
900 //=======================================================================
903 //=======================================================================
904 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
905 const Standard_Boolean theToUpdateViewer)
907 if (theIObj.IsNull())
912 if (!theIObj->HasInteractiveContext())
914 theIObj->SetContext (this);
916 if (!HasOpenedContext())
918 if (!myObjects.IsBound (theIObj))
923 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
924 aStatus->SetHilightStatus (Standard_True);
925 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
927 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
928 myMainPM->Highlight (theIObj, aHilightMode);
933 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
936 if (theToUpdateViewer)
941 //=======================================================================
944 //=======================================================================
946 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
947 const Quantity_NameOfColor aCol,
948 const Standard_Boolean updateviewer)
950 if(anIObj.IsNull()) return;
952 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
954 if (!HasOpenedContext())
956 if(!myObjects.IsBound(anIObj)) return;
958 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
959 aStatus->SetHilightStatus (Standard_True);
961 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
963 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
964 myMainPM->Color (anIObj, aCol, aHilightMode);
965 aStatus->SetHilightColor (aCol);
970 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
972 if(updateviewer) myMainVwr->Update();
975 //=======================================================================
976 //function : Unhilight
978 //=======================================================================
980 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
982 if(anIObj.IsNull()) return;
984 if (!HasOpenedContext())
986 if(!myObjects.IsBound(anIObj)) return;
988 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
989 aStatus->SetHilightStatus (Standard_False);
990 aStatus->SetHilightColor(Quantity_NOC_WHITE);
992 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
994 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
995 myMainPM->Unhighlight (anIObj, aHilightMode);
1000 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1002 if(updateviewer) myMainVwr->Update();
1005 //=======================================================================
1006 //function : IsHilighted
1008 //=======================================================================
1010 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1012 if(anIObj.IsNull()) return Standard_False;
1014 if (!HasOpenedContext()){
1015 if(!myObjects.IsBound(anIObj))
1016 return Standard_False;
1017 return myObjects(anIObj)->IsHilighted();
1019 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1020 for(;ItM.More();ItM.Next()){
1021 if(ItM.Value()->IsHilighted(anIObj))
1022 return Standard_True;
1024 return Standard_False;
1027 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1028 Standard_Boolean& WithColor,
1029 Quantity_NameOfColor& TheHiCol) const
1031 if(!HasOpenedContext()){
1032 if(myObjects.IsBound(anIObj)){
1033 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1034 if(STAT->IsHilighted()){
1035 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1036 WithColor=Standard_True;
1037 TheHiCol = STAT->HilightColor();
1040 WithColor = Standard_False;
1041 return Standard_True;
1044 return Standard_False;
1046 Standard_Integer MaxIndex = HighestIndex();
1047 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1048 if(myLocalContexts.IsBound(i)){
1049 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1050 return Standard_True;
1054 return Standard_False;
1059 //=======================================================================
1060 //function : IsDisplayed
1062 //=======================================================================
1064 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1066 if(anIObj.IsNull()) return Standard_False;
1069 if(myObjects.IsBound(anIObj))
1070 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1071 return Standard_True;
1073 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1074 for(;ItM.More();ItM.Next()){
1075 if(ItM.Value()->IsDisplayed(anIObj))
1076 return Standard_True;
1078 return Standard_False;
1082 //=======================================================================
1083 //function : IsDisplayed
1085 //=======================================================================
1086 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1087 const Standard_Integer theMode) const
1089 if (theIObj.IsNull())
1091 return Standard_False;
1094 if (myObjects.IsBound (theIObj))
1096 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1097 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1098 && aStatus->IsDModeIn (theMode))
1100 return Standard_True;
1104 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1106 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1108 return Standard_True;
1111 return Standard_False;
1114 //=======================================================================
1115 //function : DisplayPriority
1117 //=======================================================================
1118 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1120 if (theIObj.IsNull())
1124 else if (!myObjects.IsBound (theIObj))
1129 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1130 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1131 || aStatus->GraphicStatus() == AIS_DS_Erased)
1133 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1134 ? theIObj->DisplayMode()
1135 : (theIObj->AcceptDisplayMode (myDisplayMode)
1138 return myMainPM->DisplayPriority (theIObj, aDispMode);
1143 //=======================================================================
1144 //function : SetDisplayPriority
1146 //=======================================================================
1147 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1148 const Standard_Integer thePriority)
1150 if (theIObj.IsNull())
1155 if (!theIObj->HasInteractiveContext())
1157 theIObj->SetContext (this);
1160 if (myObjects.IsBound (theIObj))
1162 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1163 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1164 || aStatus->GraphicStatus() == AIS_DS_Erased)
1166 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1167 ? theIObj->DisplayMode()
1168 : (theIObj->AcceptDisplayMode (myDisplayMode)
1171 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1174 else if (HasOpenedContext())
1176 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1180 //=======================================================================
1181 //function : Redisplay
1183 //=======================================================================
1184 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1185 const Standard_Boolean theToUpdateViewer,
1186 const Standard_Boolean theAllModes)
1188 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1189 RecomputeSelectionOnly (theIObj);
1192 //=======================================================================
1193 //function : Redisplay
1195 //=======================================================================
1196 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1197 const Standard_Integer /*theSign*/,
1198 const Standard_Boolean theToUpdateViewer)
1200 Standard_Boolean isRedisplayed = Standard_False;
1201 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1203 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1204 if (anObj->Type() != theKOI)
1209 Redisplay (anObj, Standard_False);
1210 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1214 if (theToUpdateViewer
1217 myMainVwr->Update();
1221 //=======================================================================
1222 //function : RecomputePrsOnly
1224 //=======================================================================
1225 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1226 const Standard_Boolean theToUpdateViewer,
1227 const Standard_Boolean theAllModes)
1229 if (theIObj.IsNull())
1234 theIObj->Update (theAllModes);
1235 if (!theToUpdateViewer)
1240 if (HasOpenedContext()
1241 || (myObjects.IsBound (theIObj)
1242 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1244 myMainVwr->Update();
1247 //=======================================================================
1248 //function : RecomputeSelectionOnly
1250 //=======================================================================
1251 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1258 mgrSelector->RecomputeSelection (theIO);
1260 if (HasOpenedContext())
1262 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1264 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1269 if (!myObjects.IsBound (theIO) ||
1270 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1275 TColStd_ListOfInteger aModes;
1276 ActivatedModes (theIO, aModes);
1277 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1278 for (; aModesIter.More(); aModesIter.Next())
1280 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1284 //=======================================================================
1287 //=======================================================================
1288 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1289 const Standard_Boolean theUpdateViewer)
1291 if (theIObj.IsNull())
1296 TColStd_ListOfInteger aPrsModes;
1297 theIObj->ToBeUpdated (aPrsModes);
1298 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1300 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1303 mgrSelector->Update(theIObj);
1305 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1307 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1310 if (theUpdateViewer)
1312 if (!myObjects.IsBound (theIObj))
1317 switch (myObjects (theIObj)->GraphicStatus())
1319 case AIS_DS_Displayed:
1320 case AIS_DS_Temporary:
1321 myMainVwr->Update();
1329 //=======================================================================
1330 //function : SetLocation
1332 //=======================================================================
1333 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1334 const TopLoc_Location& theLoc)
1336 if (theIObj.IsNull())
1341 if (theIObj->HasTransformation()
1342 && theLoc.IsIdentity())
1344 theIObj->ResetTransformation();
1345 mgrSelector->Update (theIObj, Standard_False);
1348 else if (theLoc.IsIdentity())
1353 // first reset the previous location to properly clean everything...
1354 if (theIObj->HasTransformation())
1356 theIObj->ResetTransformation();
1359 theIObj->SetLocalTransformation (theLoc.Transformation());
1361 if (!HasOpenedContext())
1363 mgrSelector->Update (theIObj, Standard_False);
1367 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1368 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1372 //=======================================================================
1373 //function : ResetLocation
1375 //=======================================================================
1376 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1378 if (theIObj.IsNull())
1383 theIObj->ResetTransformation();
1384 mgrSelector->Update (theIObj, Standard_False);
1387 //=======================================================================
1388 //function : HasLocation
1390 //=======================================================================
1391 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1393 return !theIObj.IsNull()
1394 && theIObj->HasTransformation();
1397 //=======================================================================
1398 //function : Location
1400 //=======================================================================
1401 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1403 return theIObj->Transformation();
1406 //=======================================================================
1407 //function : SetDeviationCoefficient
1409 //=======================================================================
1410 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1412 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1415 //=======================================================================
1416 //function : SetDeviationAngle
1418 //=======================================================================
1419 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1421 myDefaultDrawer->SetDeviationCoefficient (theAngle);
1424 //=======================================================================
1425 //function : DeviationAngle
1426 //purpose : Gets deviationAngle
1427 //=======================================================================
1428 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1430 return myDefaultDrawer->DeviationAngle();
1433 //=======================================================================
1434 //function : DeviationCoefficient
1436 //=======================================================================
1437 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1439 return myDefaultDrawer->DeviationCoefficient();
1442 //=======================================================================
1443 //function : SetHLRDeviationCoefficient
1445 //=======================================================================
1446 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1448 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1451 //=======================================================================
1452 //function : HLRDeviationCoefficient
1454 //=======================================================================
1455 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1457 return myDefaultDrawer->HLRDeviationCoefficient();
1460 //=======================================================================
1461 //function : SetHLRAngle
1463 //=======================================================================
1464 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1466 myDefaultDrawer->SetHLRAngle (theAngle);
1469 //=======================================================================
1470 //function : SetHLRAngleAndDeviation
1471 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1472 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1473 // of myDefaultDrawer
1474 //=======================================================================
1475 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1477 Standard_Real anOutAngl, anOutDefl;
1478 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1480 myDefaultDrawer->SetHLRAngle (anOutAngl);
1481 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1484 //=======================================================================
1485 //function : HLRAngle
1487 //=======================================================================
1488 Standard_Real AIS_InteractiveContext::HLRAngle() const
1490 return myDefaultDrawer->HLRAngle();
1493 //=======================================================================
1494 //function : SetDisplayMode
1496 //=======================================================================
1497 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1498 const Standard_Boolean theToUpdateViewer)
1500 if (theMode == myDisplayMode)
1505 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1507 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1508 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1509 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1510 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1513 || anObj->HasDisplayMode()
1514 || !anObj->AcceptDisplayMode (theMode))
1519 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1520 if (aStatus->IsDModeIn (myDisplayMode))
1522 aStatus->RemoveDisplayMode (myDisplayMode);
1525 aStatus->AddDisplayMode (theMode);
1526 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1528 myMainPM->Display (anObj, theMode);
1529 if (aStatus->IsSubIntensityOn())
1531 myMainPM->Color (anObj, mySubIntensity, theMode);
1533 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1537 myDisplayMode = theMode;
1538 if (theToUpdateViewer)
1540 myMainVwr->Update();
1544 //=======================================================================
1545 //function : SetDisplayMode
1547 //=======================================================================
1548 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1549 const Standard_Integer theMode,
1550 const Standard_Boolean theToUpdateViewer)
1552 if (!theIObj->HasInteractiveContext())
1554 theIObj->SetContext(this);
1557 if (!myObjects.IsBound (theIObj))
1559 theIObj->SetDisplayMode (theMode);
1562 else if (!theIObj->AcceptDisplayMode (theMode))
1567 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1568 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1570 theIObj->SetDisplayMode (theMode);
1574 // erase presentations for all display modes different from <aMode>
1575 TColStd_ListOfInteger aModesToRemove;
1576 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1578 const Standard_Integer anOldMode = aDispModeIter.Value();
1579 if (anOldMode != theMode)
1581 aModesToRemove.Append (anOldMode);
1582 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1584 myMainPM->Unhighlight (theIObj, anOldMode);
1586 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1590 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1592 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1595 if (!aStatus->IsDModeIn (theMode))
1597 aStatus->AddDisplayMode (theMode);
1600 myMainPM->Display (theIObj, theMode);
1601 Standard_Integer aDispMode, aHiMode, aSelMode;
1602 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1603 if (aStatus->IsHilighted())
1605 myMainPM->Highlight (theIObj, aHiMode);
1607 if (aStatus->IsSubIntensityOn())
1609 myMainPM->Color (theIObj, mySubIntensity, theMode);
1612 if (theToUpdateViewer)
1614 myMainVwr->Update();
1616 theIObj->SetDisplayMode (theMode);
1619 //=======================================================================
1620 //function : UnsetDisplayMode
1622 //=======================================================================
1623 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1624 const Standard_Boolean theToUpdateViewer)
1626 if (theIObj.IsNull()
1627 || !theIObj->HasDisplayMode())
1632 if (!myObjects.IsBound (theIObj))
1634 theIObj->UnsetDisplayMode();
1638 const Standard_Integer anOldMode = theIObj->DisplayMode();
1639 if (myDisplayMode == anOldMode)
1644 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1645 aStatus->RemoveDisplayMode (anOldMode);
1646 if (!aStatus->IsDModeIn(myDisplayMode))
1648 aStatus->AddDisplayMode (myDisplayMode);
1651 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1653 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1655 myMainPM->Unhighlight (theIObj, anOldMode);
1657 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1658 myMainPM->Display (theIObj, myDisplayMode);
1660 Standard_Integer aDispMode, aHiMode, aSelMode;
1661 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1662 if (aStatus->IsHilighted())
1664 myMainPM->Highlight (theIObj, aHiMode);
1666 if (aStatus->IsSubIntensityOn())
1668 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1671 if (theToUpdateViewer)
1673 myMainVwr->Update();
1677 theIObj->UnsetDisplayMode();
1680 //=======================================================================
1681 //function : SetCurrentFacingModel
1683 //=======================================================================
1684 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1685 const Aspect_TypeOfFacingModel theModel)
1687 if (!theIObj.IsNull())
1689 theIObj->SetCurrentFacingModel (theModel);
1693 //=======================================================================
1694 //function : redisplayPrsRecModes
1696 //=======================================================================
1697 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1698 const Standard_Boolean theToUpdateViewer)
1700 if (theIObj->RecomputeEveryPrs())
1702 theIObj->Update (Standard_True);
1703 theIObj->UpdateSelection();
1707 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1709 theIObj->Update (aModes.Value(), Standard_False);
1711 theIObj->UpdateSelection();
1712 theIObj->SetRecomputeOk();
1715 if (theToUpdateViewer)
1717 UpdateCurrentViewer();
1721 //=======================================================================
1722 //function : redisplayPrsModes
1724 //=======================================================================
1725 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1726 const Standard_Boolean theToUpdateViewer)
1728 if (theIObj->RecomputeEveryPrs())
1730 theIObj->Update (Standard_True);
1731 theIObj->UpdateSelection();
1735 TColStd_ListOfInteger aModes;
1736 theIObj->ToBeUpdated (aModes);
1737 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1739 theIObj->Update (aModeIter.Value(), Standard_False);
1741 theIObj->SetRecomputeOk();
1744 if (theToUpdateViewer)
1746 UpdateCurrentViewer();
1750 //=======================================================================
1751 //function : SetColor
1753 //=======================================================================
1754 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1755 const Quantity_NameOfColor theColor,
1756 const Standard_Boolean theToUpdateViewer)
1758 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1761 //=======================================================================
1762 //function : SetColor
1764 //=======================================================================
1765 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1766 const Quantity_Color& theColor,
1767 const Standard_Boolean theToUpdateViewer)
1769 if (theIObj.IsNull())
1774 if (!theIObj->HasInteractiveContext())
1776 theIObj->SetContext (this);
1778 theIObj->SetColor (theColor);
1779 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1782 //=======================================================================
1783 //function : SetDeviationCoefficient
1785 //=======================================================================
1786 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1787 const Standard_Real theCoefficient,
1788 const Standard_Boolean theToUpdateViewer)
1790 if (theIObj.IsNull())
1795 if (!theIObj->HasInteractiveContext())
1797 theIObj->SetContext (this);
1800 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1801 if (theIObj->Type() != AIS_KOI_Object
1802 && theIObj->Type() != AIS_KOI_Shape)
1806 else if (theIObj->Signature() != 0)
1811 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1812 aShape->SetOwnDeviationCoefficient (theCoefficient);
1813 redisplayPrsModes (theIObj, theToUpdateViewer);
1816 //=======================================================================
1817 //function : SetHLRDeviationCoefficient
1819 //=======================================================================
1820 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1821 const Standard_Real theCoefficient,
1822 const Standard_Boolean theToUpdateViewer)
1824 if (theIObj.IsNull())
1829 if (!theIObj->HasInteractiveContext())
1831 theIObj->SetContext (this);
1834 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1835 if (theIObj->Type() != AIS_KOI_Object
1836 && theIObj->Type() != AIS_KOI_Shape)
1840 else if (theIObj->Signature() != 0)
1845 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1846 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1847 redisplayPrsModes (theIObj, theToUpdateViewer);
1850 //=======================================================================
1851 //function : SetDeviationAngle
1853 //=======================================================================
1854 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1855 const Standard_Real theAngle,
1856 const Standard_Boolean theToUpdateViewer)
1858 if (theIObj.IsNull())
1863 if (!theIObj->HasInteractiveContext())
1865 theIObj->SetContext (this);
1868 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1869 if (theIObj->Type() != AIS_KOI_Shape)
1873 else if (theIObj->Signature() != 0)
1878 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1879 aShape->SetOwnDeviationAngle (theAngle);
1880 redisplayPrsModes (theIObj, theToUpdateViewer);
1883 //=======================================================================
1884 //function : SetAngleAndDeviation
1886 //=======================================================================
1887 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1888 const Standard_Real theAngle,
1889 const Standard_Boolean theToUpdateViewer)
1891 if (theIObj.IsNull())
1896 if (!theIObj->HasInteractiveContext())
1898 theIObj->SetContext (this);
1901 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1902 if (theIObj->Type() != AIS_KOI_Shape)
1906 if (theIObj->Signature() != 0)
1911 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1912 aShape->SetAngleAndDeviation (theAngle);
1914 if (theIObj->RecomputeEveryPrs())
1916 theIObj->Update (Standard_True);
1917 theIObj->UpdateSelection();
1921 Update (theIObj, theToUpdateViewer);
1925 //=======================================================================
1926 //function : SetHLRAngleAndDeviation
1928 //=======================================================================
1929 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1930 const Standard_Real theAngle,
1931 const Standard_Boolean theToUpdateViewer)
1933 if (theIObj.IsNull())
1938 if (!theIObj->HasInteractiveContext())
1940 theIObj->SetContext (this);
1943 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1944 if (theIObj->Type() != AIS_KOI_Shape)
1948 if (theIObj->Signature() != 0)
1952 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1953 aShape->SetHLRAngleAndDeviation (theAngle);
1954 redisplayPrsModes (theIObj, theToUpdateViewer);
1957 //=======================================================================
1958 //function : SetHLRDeviationAngle
1960 //=======================================================================
1961 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1962 const Standard_Real theAngle,
1963 const Standard_Boolean theToUpdateViewer)
1965 if (theIObj.IsNull())
1970 if (!theIObj->HasInteractiveContext())
1972 theIObj->SetContext (this);
1975 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1976 if (theIObj->Type() != AIS_KOI_Shape)
1980 if (theIObj->Signature() != 0)
1984 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1985 aShape->SetOwnHLRDeviationAngle (theAngle);
1986 redisplayPrsModes (theIObj, theToUpdateViewer);
1989 //=======================================================================
1990 //function : UnsetColor
1992 //=======================================================================
1993 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1994 const Standard_Boolean theToUpdateViewer)
1996 if (theIObj.IsNull())
2001 theIObj->UnsetColor();
2002 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2005 //=======================================================================
2006 //function : HasColor
2008 //=======================================================================
2009 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2011 return theIObj->HasColor();
2014 //=======================================================================
2017 //=======================================================================
2018 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2020 return theIObj->Color();
2023 //=======================================================================
2026 //=======================================================================
2027 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2028 Quantity_Color& theColor) const
2030 theIObj->Color (theColor);
2033 //=======================================================================
2036 //=======================================================================
2037 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2039 return theIObj->Width();
2042 //=======================================================================
2043 //function : SetWidth
2045 //=======================================================================
2046 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2047 const Standard_Real theWidth,
2048 const Standard_Boolean theToUpdateViewer)
2050 if (theIObj.IsNull())
2055 if (!theIObj->HasInteractiveContext())
2057 theIObj->SetContext (this);
2060 theIObj->SetWidth (theWidth);
2061 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2064 //=======================================================================
2065 //function : UnsetWidth
2067 //=======================================================================
2068 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2069 const Standard_Boolean theToUpdateViewer)
2071 if (theIObj.IsNull())
2076 theIObj->UnsetWidth();
2077 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2080 //=======================================================================
2081 //function : SetMaterial
2083 //=======================================================================
2084 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2085 const Graphic3d_NameOfMaterial theName,
2086 const Standard_Boolean theToUpdateViewer)
2088 if (theIObj.IsNull())
2093 if (!theIObj->HasInteractiveContext())
2095 theIObj->SetContext (this);
2098 theIObj->SetMaterial (theName);
2099 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2102 //=======================================================================
2103 //function : UnsetMaterial
2105 //=======================================================================
2106 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2107 const Standard_Boolean theToUpdateViewer)
2109 if (theIObj.IsNull())
2113 theIObj->UnsetMaterial();
2114 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2117 //=======================================================================
2118 //function : SetTransparency
2120 //=======================================================================
2121 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2122 const Standard_Real theValue,
2123 const Standard_Boolean theToUpdateViewer)
2125 if (theIObj.IsNull())
2130 if (!theIObj->HasInteractiveContext())
2132 theIObj->SetContext (this);
2135 if (!theIObj->IsTransparent()
2136 && theValue <= 0.05)
2141 if (theValue <= 0.05)
2143 UnsetTransparency (theIObj, theToUpdateViewer);
2147 theIObj->SetTransparency (theValue);
2148 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2151 //=======================================================================
2152 //function : UnsetTransparency
2154 //=======================================================================
2155 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2156 const Standard_Boolean theToUpdateViewer)
2158 if (theIObj.IsNull())
2163 theIObj->UnsetTransparency();
2164 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2167 //=======================================================================
2168 //function : SetSelectedAspect
2170 //=======================================================================
2171 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2172 const Standard_Boolean theIsGlobalChange,
2173 const Standard_Boolean theToUpdateViewer)
2175 if (HasOpenedContext())
2180 Standard_Boolean isFound = Standard_False;
2181 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2182 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2184 isFound = Standard_True;
2185 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2186 anObj->SetAspect (theAspect, theIsGlobalChange);
2190 && theToUpdateViewer)
2192 myMainVwr->Update();
2196 //=======================================================================
2197 //function : SetLocalAttributes
2199 //=======================================================================
2200 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2201 const Handle(Prs3d_Drawer)& theDrawer,
2202 const Standard_Boolean theToUpdateViewer)
2204 if (theIObj.IsNull())
2209 if (!theIObj->HasInteractiveContext())
2211 theIObj->SetContext (this);
2214 theIObj->SetAttributes (theDrawer);
2215 Update (theIObj, theToUpdateViewer);
2218 //=======================================================================
2219 //function : UnsetLocalAttributes
2221 //=======================================================================
2222 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2223 const Standard_Boolean theToUpdateViewer)
2225 if (theIObj.IsNull())
2230 if (!theIObj->HasInteractiveContext())
2232 theIObj->SetContext (this);
2234 theIObj->UnsetAttributes();
2235 Update (theIObj, theToUpdateViewer);
2238 //=======================================================================
2241 //=======================================================================
2242 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2243 TCollection_ExtendedString& theStatus) const
2246 if (theIObj.IsNull()
2247 || !myObjects.IsBound (theIObj))
2252 theStatus += "\t ____________________________________________";
2253 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2254 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2255 switch (aStatus->GraphicStatus())
2257 case AIS_DS_Displayed:
2259 theStatus += "\t| -->Displayed\n";
2264 theStatus += "\t| -->Erased\n";
2271 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2272 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2274 theStatus += "\t|\t Mode ";
2275 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2278 if (IsCurrent (theIObj)) theStatus +="\t| Current\n";
2279 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2281 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2282 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2284 theStatus += "\t\t Mode ";
2285 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2288 theStatus += "\t ____________________________________________";
2291 //=======================================================================
2292 //function : GetDefModes
2294 //=======================================================================
2295 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2296 Standard_Integer& theDispMode,
2297 Standard_Integer& theHiMode,
2298 Standard_Integer& theSelMode) const
2300 if (theIObj.IsNull())
2305 theDispMode = theIObj->HasDisplayMode()
2306 ? theIObj->DisplayMode()
2307 : (theIObj->AcceptDisplayMode (myDisplayMode)
2310 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2311 theSelMode = theIObj->HasSelectionMode() ? theIObj->SelectionMode() : -1;
2314 //=======================================================================
2315 //function : EraseGlobal
2317 //=======================================================================
2318 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2319 const Standard_Boolean theToUpdateviewer)
2321 if (theIObj.IsNull()
2322 || !myObjects.IsBound (theIObj))
2327 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2329 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2330 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2331 || aStatus->GraphicStatus() == AIS_DS_Erased)
2336 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2338 if (aStatus->IsHilighted())
2340 if (IsCurrent (theIObj))
2342 AddOrRemoveCurrentObject (theIObj, Standard_False);
2344 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2346 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2350 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2353 if (IsCurrent (theIObj)
2354 && !aStatus->IsDModeIn (aDispMode))
2356 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2359 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2361 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2363 aStatus->SetGraphicStatus (AIS_DS_Erased);
2365 if (theToUpdateviewer)
2367 myMainVwr->Update();
2371 //=======================================================================
2372 //function : ClearGlobal
2374 //=======================================================================
2375 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2376 const Standard_Boolean theToUpdateviewer)
2378 if (theIObj.IsNull()
2379 || !myObjects.IsBound (theIObj))
2381 // for cases when reference shape of connected interactives was not displayed
2382 // but its selection primitives were calculated
2383 mgrSelector->Remove (theIObj);
2387 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2388 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2390 if (aStatus->IsHilighted())
2392 if (IsCurrent (theIObj))
2394 AddOrRemoveCurrentObject (theIObj, theToUpdateviewer);
2396 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2398 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2401 myMainPM->Erase (theIObj, aDispModeIter.Value());
2402 myMainPM->Clear (theIObj, aDispModeIter.Value());
2403 if (theIObj->HasHilightMode())
2405 Standard_Integer im = theIObj->HilightMode();
2406 myMainPM->Unhighlight (theIObj, im);
2407 myMainPM->Erase (theIObj, im);
2411 // Object removes from Detected sequence
2412 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2414 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2416 && anObj != theIObj)
2418 myAISDetectedSeq.Remove (aDetIter);
2422 if (myLastinMain == theIObj)
2424 myLastinMain.Nullify();
2426 if (myLastPicked == theIObj)
2428 myLastPicked.Nullify();
2431 // remove IO from the selection manager to avoid memory leaks
2432 mgrSelector->Remove (theIObj);
2434 myObjects.UnBind (theIObj);
2435 myMainVwr->Viewer()->UnregisterObject (theIObj);
2436 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2438 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2441 if (theToUpdateviewer
2442 && aStatus->GraphicStatus() == AIS_DS_Displayed)
2444 myMainVwr->Update();
2448 //=======================================================================
2449 //function : ClearGlobalPrs
2451 //=======================================================================
2452 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2453 const Standard_Integer theMode,
2454 const Standard_Boolean theToUpdateViewer)
2456 if (theIObj.IsNull()
2457 || !myObjects.IsBound (theIObj))
2462 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2463 if (aStatus->IsDModeIn (theMode))
2465 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2466 if (aDispMode == theMode
2467 && myMainPM->IsHighlighted (theIObj, theMode))
2469 myMainPM->Unhighlight (theIObj, theMode);
2472 myMainPM->Erase (theIObj, theMode);
2473 myMainPM->Clear (theIObj, theMode);
2476 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2477 && theToUpdateViewer)
2479 myMainVwr->Update();
2483 //=======================================================================
2484 //function : DrawHiddenLine
2486 //=======================================================================
2487 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2489 return myDefaultDrawer->DrawHiddenLine();
2492 //=======================================================================
2493 //function : EnableDrawHiddenLine
2495 //=======================================================================
2496 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2498 myDefaultDrawer->EnableDrawHiddenLine();
2501 //=======================================================================
2502 //function : DisableDrawHiddenLine
2504 //=======================================================================
2505 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2507 myDefaultDrawer->DisableDrawHiddenLine();
2510 //=======================================================================
2511 //function : HiddenLineAspect
2513 //=======================================================================
2514 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2516 return myDefaultDrawer->HiddenLineAspect();
2519 //=======================================================================
2520 //function : SetHiddenLineAspect
2522 //=======================================================================
2523 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2525 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2528 //=======================================================================
2529 //function : SetIsoNumber
2531 //=======================================================================
2532 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2533 const AIS_TypeOfIso theType)
2538 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2541 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2544 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2545 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2550 //=======================================================================
2551 //function : IsoNumber
2553 //=======================================================================
2554 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2558 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2559 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2560 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2561 ? myDefaultDrawer->UIsoAspect()->Number()
2567 //=======================================================================
2568 //function : IsoOnPlane
2570 //=======================================================================
2571 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2573 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2576 //=======================================================================
2577 //function : IsoOnPlane
2579 //=======================================================================
2580 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2582 return myDefaultDrawer->IsoOnPlane();
2585 //=======================================================================
2586 //function : SetSelectionMode
2588 //=======================================================================
2589 void AIS_InteractiveContext::SetSelectionMode (const Handle(AIS_InteractiveObject)& ,
2590 const Standard_Integer )
2595 //=======================================================================
2596 //function : UnsetSelectionMode
2598 //=======================================================================
2599 void AIS_InteractiveContext::UnsetSelectionMode (const Handle(AIS_InteractiveObject)& )
2604 //=======================================================================
2605 //function : SetPixelTolerance
2606 //purpose : Disables the mechanism of adaptive tolerance calculation in
2607 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2608 // sensitive entities activated. For more information, see
2609 // SelectMgr_ViewerSelector.hxx
2610 //=======================================================================
2611 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Real thePrecision)
2613 if (HasOpenedContext())
2615 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2619 myMainSel->SetPixelTolerance (thePrecision);
2623 //=======================================================================
2624 //function : PixelTolerance
2626 //=======================================================================
2627 Standard_Real AIS_InteractiveContext::PixelTolerance() const
2629 return HasOpenedContext()
2630 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2631 : myMainSel->PixelTolerance();
2634 //=======================================================================
2635 //function : IsInLocal
2637 //=======================================================================
2638 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2639 Standard_Integer& theIndex) const
2641 if (theIObj.IsNull())
2643 return Standard_False;
2646 // if it exists at neutral point 0 index is returned
2647 if (myObjects.IsBound (theIObj))
2650 return Standard_False;
2653 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2655 if (myLocalContexts.IsBound (aCtxIter))
2657 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2659 theIndex = aCtxIter;
2660 return Standard_True;
2665 return Standard_False;
2668 //=======================================================================
2669 //function : InitAttributes
2671 //=======================================================================
2672 void AIS_InteractiveContext::InitAttributes()
2674 mgrSelector->Add (myMainSel);
2675 myCurrentName = AIS_Context_NewCurName();
2676 mySelectionName = AIS_Context_NewSelName();
2678 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2679 AIS_Selection::CreateSelection (myCurrentName.ToCString());
2681 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2682 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2683 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2685 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2686 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2687 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2688 aLineAspect->SetWidth (1.0);
2689 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2691 // tolerance to 2 pixels...
2692 SetPixelTolerance (2.0);
2694 // Customizing the drawer for trihedrons and planes...
2695 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2696 const Standard_Real aLength = 100.0;
2697 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2698 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2699 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2700 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2701 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2703 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2704 const Standard_Real aPlaneLength = 200.0;
2705 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2706 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2709 //=======================================================================
2710 //function : TrihedronSize
2712 //=======================================================================
2713 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2715 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2718 //=======================================================================
2719 //function : SetTrihedronSize
2721 //=======================================================================
2722 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2723 const Standard_Boolean /*updateviewer*/)
2725 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2726 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2727 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2730 //=======================================================================
2731 //function : SetPlaneSize
2733 //=======================================================================
2734 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2735 const Standard_Real theValY,
2736 const Standard_Boolean /*updateviewer*/)
2738 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2739 Redisplay (AIS_KOI_Datum, 7);
2742 //=======================================================================
2743 //function : SetPlaneSize
2745 //=======================================================================
2746 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2747 const Standard_Boolean theToUpdateViewer)
2749 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2752 //=======================================================================
2753 //function : PlaneSize
2755 //=======================================================================
2756 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2757 Standard_Real& theY) const
2759 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2760 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2761 return (Abs (theX - theY) <= Precision::Confusion());
2764 //=======================================================================
2765 //function : SetAutoActivateSelection
2767 //=======================================================================
2768 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2770 myIsAutoActivateSelMode = theIsAuto;
2773 //=======================================================================
2774 //function : GetAutoActivateSelection
2776 //=======================================================================
2777 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2779 return myIsAutoActivateSelMode;
2782 //=======================================================================
2783 //function : SetZLayer
2785 //=======================================================================
2786 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2787 const Standard_Integer theLayerId)
2789 if (theIObj.IsNull())
2792 theIObj->SetZLayer (theLayerId);
2795 //=======================================================================
2796 //function : GetZLayer
2798 //=======================================================================
2799 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2801 return !theIObj.IsNull()
2803 : Graphic3d_ZLayerId_UNKNOWN;
2806 //=======================================================================
2807 //function : RebuildSelectionStructs
2808 //purpose : Rebuilds 1st level of BVH selection forcibly
2809 //=======================================================================
2810 void AIS_InteractiveContext::RebuildSelectionStructs()
2812 myMainSel->RebuildObjectsTree (Standard_True);
2815 //=======================================================================
2816 //function : Disconnect
2817 //purpose : Disconnects selectable object from an assembly and updates selection structures
2818 //=======================================================================
2819 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2820 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2822 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2824 const Handle(AIS_MultipleConnectedInteractive)& theObj =
2825 Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly);
2826 theObj->Disconnect (theObjToDisconnect);
2827 mgrSelector->Remove (theObjToDisconnect);
2829 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2831 const Handle(AIS_ConnectedInteractive)& theObj =
2832 Handle(AIS_ConnectedInteractive)::DownCast (theAssembly);
2833 theObj->Disconnect();
2834 mgrSelector->Remove (theObj);
2840 //=======================================================================
2841 //function : FitSelected
2842 //purpose : Fits the view corresponding to the bounds of selected objects
2843 //=======================================================================
2844 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2845 const Standard_Real theMargin,
2846 const Standard_Boolean theToUpdate)
2848 Standard_CString aSelName = HasOpenedContext() ?
2849 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2850 : myCurrentName.ToCString();
2852 Bnd_Box aBndSelected;
2854 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2855 AIS_MapOfObjectOwners anObjectOwnerMap;
2856 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2858 const Handle(AIS_InteractiveObject)& anObj =
2859 Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
2860 if (!anObj.IsNull())
2862 if (anObj->IsInfinite())
2866 anObj->BoundingBox (aTmpBnd);
2867 aBndSelected.Add (aTmpBnd);
2871 const Handle(SelectMgr_EntityOwner)& anOwner =
2872 Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value());
2873 if (anOwner.IsNull())
2876 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2877 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2879 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2880 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2883 anOwnerMap->Add (anOwner);
2887 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2889 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2890 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2891 aBndSelected.Add (aTmpBox);
2894 anObjectOwnerMap.Clear();
2896 if (aBndSelected.IsVoid())
2899 theView->FitAll (aBndSelected, theMargin, theToUpdate);