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_Selection.hxx>
31 #include <AIS_Shape.hxx>
32 #include <AIS_Trihedron.hxx>
33 #include <Geom_Axis2Placement.hxx>
34 #include <Graphic3d_AspectFillArea3d.hxx>
35 #include <HLRBRep.hxx>
36 #include <OSD_Environment.hxx>
37 #include <Precision.hxx>
38 #include <Prs3d_BasicAspect.hxx>
39 #include <Prs3d_DatumAspect.hxx>
40 #include <Prs3d_IsoAspect.hxx>
41 #include <Prs3d_LineAspect.hxx>
42 #include <Prs3d_PlaneAspect.hxx>
43 #include <Prs3d_ShadingAspect.hxx>
44 #include <PrsMgr_ModedPresentation.hxx>
45 #include <PrsMgr_PresentableObject.hxx>
46 #include <Quantity_Color.hxx>
47 #include <SelectMgr_EntityOwner.hxx>
48 #include <SelectMgr_Filter.hxx>
49 #include <SelectMgr_OrFilter.hxx>
50 #include <SelectMgr_SelectionManager.hxx>
51 #include <Standard_Atomic.hxx>
52 #include <Standard_Transient.hxx>
53 #include <Standard_Type.hxx>
54 #include <StdSelect_ViewerSelector3d.hxx>
55 #include <TCollection_AsciiString.hxx>
56 #include <TCollection_ExtendedString.hxx>
57 #include <TColStd_ListIteratorOfListOfInteger.hxx>
58 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
59 #include <TopLoc_Location.hxx>
60 #include <TopoDS_Shape.hxx>
61 #include <UnitsAPI.hxx>
62 #include <V3d_View.hxx>
63 #include <V3d_Viewer.hxx>
64 #include <Visual3d_View.hxx>
65 #include <Visual3d_ViewManager.hxx>
67 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
70 static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
71 static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
73 static TCollection_AsciiString AIS_Context_NewSelName()
75 return TCollection_AsciiString ("AIS_SelContext_")
76 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
79 static TCollection_AsciiString AIS_Context_NewCurName()
81 return TCollection_AsciiString ("AIS_CurContext_")
82 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
85 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
86 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
89 //=======================================================================
90 //function : AIS_InteractiveContext
92 //=======================================================================
94 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
95 mgrSelector(new SelectMgr_SelectionManager()),
96 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
97 myMainVwr(MainViewer),
98 myMainSel(new StdSelect_ViewerSelector3d()),
99 myWasLastMain(Standard_False),
100 myCurrentTouched(Standard_False),
101 mySelectedTouched(Standard_False),
102 myToHilightSelected(Standard_True),
103 myFilters(new SelectMgr_OrFilter()),
104 myDefaultDrawer(new Prs3d_Drawer()),
105 myDefaultColor(Quantity_NOC_GOLDENROD),
106 myHilightColor(Quantity_NOC_CYAN1),
107 mySelectionColor(Quantity_NOC_GRAY80),
108 myPreselectionColor(Quantity_NOC_GREEN),
109 mySubIntensity(Quantity_NOC_GRAY40),
114 myIsAutoActivateSelMode( Standard_True )
119 void AIS_InteractiveContext::Delete() const
121 // clear the static current selection
122 AIS_Selection::ClearCurrentSelection();
124 // to avoid an exception
125 if (AIS_Selection::Find (mySelectionName.ToCString()))
127 AIS_Selection::Remove (mySelectionName.ToCString());
130 // to avoid an exception
131 if (AIS_Selection::Find (myCurrentName.ToCString()))
133 AIS_Selection::Remove (myCurrentName.ToCString());
136 // let's remove one reference explicitly. this operation's supposed to
137 // be performed when mgrSelector will be destroyed but anyway...
138 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
139 mgrSelector->Remove (aSelector);
141 Handle(AIS_InteractiveContext) aNullContext;
142 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
144 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
145 anObj->SetContext (aNullContext);
146 for (anObj->Init(); anObj->More(); anObj->Next())
148 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
151 MMgt_TShared::Delete();
154 //=======================================================================
155 //function : AIS_SelectionName
157 //=======================================================================
158 const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const
160 if(!HasOpenedContext())
161 return mySelectionName;
162 return myLocalContexts(myCurLocalIndex)->SelectionName();
168 //=======================================================================
169 //function : UpdateCurrentViewer
171 //=======================================================================
173 void AIS_InteractiveContext::UpdateCurrentViewer()
175 if (!myMainVwr.IsNull())
180 //=======================================================================
181 //function : DomainOfMainViewer
183 //=======================================================================
185 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
187 return myMainVwr->Domain();
191 //=======================================================================
192 //function : DisplayedObjects
194 //=======================================================================
195 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
196 const Standard_Boolean theOnlyFromNeutral) const
198 if (!HasOpenedContext()
199 || theOnlyFromNeutral)
201 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
203 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
205 theListOfIO.Append (anObjIter.Key());
212 TColStd_MapOfTransient aDispMap;
213 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
215 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
217 aDispMap.Add (anObjIter.Key());
221 // parse all local contexts...
222 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
224 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
225 aLocCtx->DisplayedObjects (aDispMap);
228 Handle(AIS_InteractiveObject) anObj;
229 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
231 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
232 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
233 theListOfIO.Append (anObj);
237 //=======================================================================
238 //function : DisplayedObjects
240 //=======================================================================
241 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
242 const Standard_Integer theSign,
243 AIS_ListOfInteractive& theListOfIO,
244 const Standard_Boolean /*OnlyFromNeutral*/) const
246 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
249 //=======================================================================
250 //function : ErasedObjects
252 //=======================================================================
253 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
255 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
258 //=======================================================================
259 //function : ErasedObjects
261 //=======================================================================
262 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
263 const Standard_Integer theSign,
264 AIS_ListOfInteractive& theListOfIO) const
266 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
269 //=======================================================================
270 //function : ObjectsByDisplayStatus
272 //=======================================================================
273 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
274 AIS_ListOfInteractive& theListOfIO) const
276 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
278 if (anObjIter.Value()->GraphicStatus() == theStatus)
280 theListOfIO.Append (anObjIter.Key());
285 //=======================================================================
286 //function : ObjectsByDisplayStatus
288 //=======================================================================
289 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
290 const Standard_Integer theSign,
291 const AIS_DisplayStatus theStatus,
292 AIS_ListOfInteractive& theListOfIO) const
294 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
296 if (theStatus != AIS_DS_None
297 && anObjIter.Value()->GraphicStatus() != theStatus)
301 else if (anObjIter.Key()->Type() != theKind)
307 || anObjIter.Key()->Signature() == theSign)
309 theListOfIO.Append (anObjIter.Key());
314 //=======================================================================
315 //function : ObjectsInside
317 //=======================================================================
318 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
319 const AIS_KindOfInteractive theKind,
320 const Standard_Integer theSign) const
322 if (theKind == AIS_KOI_None
325 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
327 theListOfIO.Append (anObjIter.Key());
332 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
334 if (anObjIter.Key()->Type() != theKind)
340 || anObjIter.Key()->Signature() == theSign)
342 theListOfIO.Append (anObjIter.Key());
347 //=======================================================================
348 //function : ObjectsForView
350 //=======================================================================
351 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
352 const Handle(V3d_View)& theView,
353 const Standard_Boolean theIsVisibleInView,
354 const AIS_DisplayStatus theStatus) const
356 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
357 const Standard_Integer aViewId = aCView->ViewId;
358 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
360 if (theStatus != AIS_DS_None
361 && anObjIter.Value()->GraphicStatus() != theStatus)
363 theListOfIO.Append (anObjIter.Key());
367 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (anObjIter.Key());
368 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
369 if (isVisible == theIsVisibleInView)
371 theListOfIO.Append (anObjIter.Key());
376 //=======================================================================
379 //=======================================================================
380 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
381 const Standard_Boolean theToUpdateViewer)
383 if (theIObj.IsNull())
388 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
389 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
391 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
392 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
395 //=======================================================================
396 //function : SetViewAffinity
398 //=======================================================================
399 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
400 const Handle(V3d_View)& theView,
401 const Standard_Boolean theIsVisible)
404 || !myObjects.IsBound (theIObj))
409 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (theIObj);
410 const Graphic3d_CView* aCView = reinterpret_cast<const Graphic3d_CView* >(theView->View()->CView());
411 anAffinity->SetVisible (aCView->ViewId, theIsVisible == Standard_True);
414 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
418 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
422 //=======================================================================
425 //=======================================================================
426 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
427 const Standard_Integer theDispMode,
428 const Standard_Integer theSelectionMode,
429 const Standard_Boolean theToUpdateViewer,
430 const Standard_Boolean theToAllowDecomposition,
431 const AIS_DisplayStatus theDispStatus)
433 if (theIObj.IsNull())
438 if (theDispStatus == AIS_DS_Erased)
440 Erase (theIObj, theToUpdateViewer);
441 Load (theIObj, theSelectionMode, theToAllowDecomposition);
445 if (!theIObj->HasInteractiveContext())
447 theIObj->SetContext (this);
450 if (theDispStatus == AIS_DS_Temporary
451 && !HasOpenedContext())
455 else if (HasOpenedContext())
457 if (theDispStatus == AIS_DS_None
458 || theDispStatus == AIS_DS_Temporary)
460 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
461 if (theToUpdateViewer)
469 if (!myObjects.IsBound (theIObj))
471 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
472 myObjects.Bind (theIObj, aStatus);
473 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->RegisterObject (theIObj);
474 myMainPM->Display(theIObj, theDispMode);
475 if (theSelectionMode != -1)
477 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
478 if (!mgrSelector->Contains (anObj))
480 mgrSelector->Load (theIObj);
482 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
487 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
488 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
493 // Erase presentations for all display modes different from aDispMode.
494 // Then make sure aDispMode is displayed and maybe highlighted.
495 // Finally, activate selection mode <SelMode> if not yet activated.
496 TColStd_ListOfInteger aModesToRemove;
497 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
499 const Standard_Integer anOldMode = aDispModeIter.Value();
500 if (anOldMode != theDispMode)
502 aModesToRemove.Append (anOldMode);
503 if(myMainPM->IsHighlighted (theIObj, anOldMode))
505 myMainPM->Unhighlight (theIObj, anOldMode);
507 myMainPM->Erase (theIObj, anOldMode);
511 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
513 aStatus->RemoveDisplayMode (aRemModeIter.Value());
516 if (!aStatus->IsDModeIn (theDispMode))
518 aStatus->AddDisplayMode (theDispMode);
521 myMainPM->Display (theIObj, theDispMode);
522 aStatus->SetGraphicStatus (AIS_DS_Displayed);
523 if (aStatus->IsHilighted())
525 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
526 myMainPM->Highlight (theIObj, aHiMod);
528 if (theSelectionMode != -1)
530 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
531 if (!mgrSelector->Contains (anObj))
533 mgrSelector->Load (theIObj);
535 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
537 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
542 if (theToUpdateViewer)
548 //=======================================================================
551 //=======================================================================
552 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
553 const Standard_Integer theSelMode,
554 const Standard_Boolean theToAllowDecomposition)
556 if (theIObj.IsNull())
561 if (!theIObj->HasInteractiveContext())
563 theIObj->SetContext (this);
566 if (HasOpenedContext())
568 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
573 && !theToAllowDecomposition)
575 if (!myObjects.IsBound (theIObj))
577 Standard_Integer aDispMode, aHiMod, aSelModeDef;
578 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
579 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
580 myObjects.Bind (theIObj, aStatus);
583 // Register theIObj in the selection manager to prepare further activation of selection
584 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
585 if (!mgrSelector->Contains (anObj))
587 mgrSelector->Load (theIObj);
592 //=======================================================================
595 //=======================================================================
596 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
597 const Standard_Boolean theToUpdateViewer)
599 if (theIObj.IsNull())
604 if (!theIObj->IsAutoHilight())
606 theIObj->ClearSelected();
609 Standard_Boolean wasInCtx = Standard_False;
610 if (HasOpenedContext())
612 // First it is checked if it is possible to remove in the current local context
613 // then one tries to remove in other local contexts, if they allow it...
614 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
615 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
617 if (aCtxIter.Value()->AcceptErase())
619 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
626 EraseGlobal (theIObj, Standard_False);
629 if (theToUpdateViewer)
635 //=======================================================================
636 //function : EraseAll
638 //=======================================================================
639 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
641 if (HasOpenedContext())
646 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
648 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
650 Erase (anObjIter.Key(), Standard_False);
654 if (theToUpdateViewer)
660 //=======================================================================
661 //function : DisplayAll
663 //=======================================================================
664 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
666 if (HasOpenedContext())
671 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
673 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
674 if (aStatus == AIS_DS_Erased)
676 Display (anObjIter.Key(), Standard_False);
680 if (theToUpdateViewer)
686 //=======================================================================
687 //function : DisplaySelected
689 //=======================================================================
690 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
692 if (HasOpenedContext())
697 Standard_Boolean isFound = Standard_False;
698 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
699 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
701 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
702 Display (anObj, Standard_False);
703 isFound = Standard_True;
706 if (isFound && theToUpdateViewer)
712 //=======================================================================
713 //function : EraseSelected
715 //=======================================================================
716 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
718 if (HasOpenedContext())
723 Standard_Boolean isFound = Standard_False;
724 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
725 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
727 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
728 Erase (anObj, Standard_False);
729 isFound = Standard_True;
732 if (isFound && theToUpdateViewer)
738 //=======================================================================
741 //=======================================================================
743 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
744 const Standard_Integer WhichContext)
746 if(anIObj.IsNull()) return Standard_False;
748 if(!HasOpenedContext()) return Standard_False;
749 if(myObjects.IsBound(anIObj)) return Standard_False;
750 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
752 // Protection : if one tries to preserve a temporary object
753 // which is not in the local active context... rob 11-06-97
755 Standard_Integer IsItInLocal = myCurLocalIndex;
756 Standard_Boolean Found(Standard_False);
758 while(IsItInLocal>0 && !Found){
759 if(!myLocalContexts.IsBound(IsItInLocal))
761 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
762 Found = Standard_True;
767 if(!Found) return Standard_False;
770 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
771 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
773 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
774 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
778 if(LS->IsTemporary()){
779 Standard_Integer DM,HM,SM;
780 GetDefModes(anIObj,DM,HM,SM);
782 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
783 if(LS->DisplayMode()!= DM ){
784 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
785 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
788 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
792 // GS->SubIntensityOn();
793 myObjects.Bind(anIObj,GS);
794 mgrSelector->Load(anIObj);
795 mgrSelector->Activate(anIObj,SM,myMainSel);
797 LS->SetTemporary(Standard_False);
799 return Standard_True;
802 //=======================================================================
803 //function : DisplayStatus
805 //=======================================================================
806 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
808 if (theIObj.IsNull())
812 else if (myObjects.IsBound (theIObj))
814 return myObjects (theIObj)->GraphicStatus();
817 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
819 if (aCtxIter.Value()->IsIn (theIObj))
821 return AIS_DS_Temporary;
827 //=======================================================================
828 //function : DisplayedModes
830 //=======================================================================
831 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
833 return myObjects (theIObj)->DisplayedModes();
836 //=======================================================================
839 //=======================================================================
840 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
841 const Standard_Boolean theToUpdateViewer)
843 if (theIObj.IsNull())
848 if (HasOpenedContext())
850 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
851 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
853 if (aCtxIter.Value()->AcceptErase())
855 aCtxIter.Value()->Remove (theIObj);
860 ClearGlobal (theIObj, theToUpdateViewer);
863 //=======================================================================
864 //function : RemoveAll
866 //=======================================================================
867 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
869 AIS_ListOfInteractive aList;
870 ObjectsInside (aList);
871 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
873 Remove (aListIterator.Value(), Standard_False);
876 if (theToUpdateViewer)
882 //=======================================================================
883 //function : ClearPrs
885 //=======================================================================
886 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
887 const Standard_Integer theMode,
888 const Standard_Boolean theToUpdateViewer)
890 if (theIObj.IsNull())
895 if (!HasOpenedContext())
897 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
901 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
902 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
904 if (aCtxIter.Value()->AcceptErase())
906 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
911 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
913 else if (theToUpdateViewer)
919 //=======================================================================
922 //=======================================================================
923 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
924 const Standard_Boolean theToUpdateViewer)
926 if (theIObj.IsNull())
931 if (!theIObj->HasInteractiveContext())
933 theIObj->SetContext (this);
935 if (!HasOpenedContext())
937 if (!myObjects.IsBound (theIObj))
942 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
943 aStatus->SetHilightStatus (Standard_True);
944 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
946 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
947 myMainPM->Highlight (theIObj, aHilightMode);
952 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
955 if (theToUpdateViewer)
960 //=======================================================================
963 //=======================================================================
965 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
966 const Quantity_NameOfColor aCol,
967 const Standard_Boolean updateviewer)
969 if(anIObj.IsNull()) return;
971 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
973 if (!HasOpenedContext())
975 if(!myObjects.IsBound(anIObj)) return;
977 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
978 aStatus->SetHilightStatus (Standard_True);
980 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
982 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
983 myMainPM->Color (anIObj, aCol, aHilightMode);
984 aStatus->SetHilightColor (aCol);
989 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
991 if(updateviewer) myMainVwr->Update();
994 //=======================================================================
995 //function : Unhilight
997 //=======================================================================
999 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
1001 if(anIObj.IsNull()) return;
1003 if (!HasOpenedContext())
1005 if(!myObjects.IsBound(anIObj)) return;
1007 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
1008 aStatus->SetHilightStatus (Standard_False);
1009 aStatus->SetHilightColor(Quantity_NOC_WHITE);
1011 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1013 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
1014 myMainPM->Unhighlight (anIObj, aHilightMode);
1019 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1021 if(updateviewer) myMainVwr->Update();
1024 //=======================================================================
1025 //function : IsHilighted
1027 //=======================================================================
1029 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1031 if(anIObj.IsNull()) return Standard_False;
1033 if (!HasOpenedContext()){
1034 if(!myObjects.IsBound(anIObj))
1035 return Standard_False;
1036 return myObjects(anIObj)->IsHilighted();
1038 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1039 for(;ItM.More();ItM.Next()){
1040 if(ItM.Value()->IsHilighted(anIObj))
1041 return Standard_True;
1043 return Standard_False;
1046 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1047 Standard_Boolean& WithColor,
1048 Quantity_NameOfColor& TheHiCol) const
1050 if(!HasOpenedContext()){
1051 if(myObjects.IsBound(anIObj)){
1052 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1053 if(STAT->IsHilighted()){
1054 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1055 WithColor=Standard_True;
1056 TheHiCol = STAT->HilightColor();
1059 WithColor = Standard_False;
1060 return Standard_True;
1063 return Standard_False;
1065 Standard_Integer MaxIndex = HighestIndex();
1066 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1067 if(myLocalContexts.IsBound(i)){
1068 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1069 return Standard_True;
1073 return Standard_False;
1076 //=======================================================================
1077 //function : IsHilighted
1078 //purpose : Returns true if the objects global status is set to highlighted.
1079 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1080 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1081 // custom highlight color name will be stored to theCustomColorName
1082 //=======================================================================
1083 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1084 Standard_Boolean& theIsCustomColor,
1085 Quantity_NameOfColor& theCustomColorName) const
1087 if (theOwner.IsNull() || !theOwner->HasSelectable())
1088 return Standard_False;
1090 const Handle(AIS_InteractiveObject) anObj =
1091 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1093 if (!myObjects.IsBound (anObj))
1094 return Standard_False;
1096 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1097 if (anObjStatus->IsHilighted())
1099 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1101 theIsCustomColor = Standard_True;
1102 theCustomColorName = anObjStatus->HilightColor();
1106 theIsCustomColor = Standard_False;
1109 return Standard_True;
1112 return Standard_False;
1115 //=======================================================================
1116 //function : IsDisplayed
1118 //=======================================================================
1120 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1122 if(anIObj.IsNull()) return Standard_False;
1125 if(myObjects.IsBound(anIObj))
1126 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1127 return Standard_True;
1129 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1130 for(;ItM.More();ItM.Next()){
1131 if(ItM.Value()->IsDisplayed(anIObj))
1132 return Standard_True;
1134 return Standard_False;
1138 //=======================================================================
1139 //function : IsDisplayed
1141 //=======================================================================
1142 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1143 const Standard_Integer theMode) const
1145 if (theIObj.IsNull())
1147 return Standard_False;
1150 if (myObjects.IsBound (theIObj))
1152 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1153 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1154 && aStatus->IsDModeIn (theMode))
1156 return Standard_True;
1160 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1162 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1164 return Standard_True;
1167 return Standard_False;
1170 //=======================================================================
1171 //function : DisplayPriority
1173 //=======================================================================
1174 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1176 if (theIObj.IsNull())
1180 else if (!myObjects.IsBound (theIObj))
1185 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1186 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1187 || aStatus->GraphicStatus() == AIS_DS_Erased)
1189 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1190 ? theIObj->DisplayMode()
1191 : (theIObj->AcceptDisplayMode (myDisplayMode)
1194 return myMainPM->DisplayPriority (theIObj, aDispMode);
1199 //=======================================================================
1200 //function : SetDisplayPriority
1202 //=======================================================================
1203 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1204 const Standard_Integer thePriority)
1206 if (theIObj.IsNull())
1211 if (!theIObj->HasInteractiveContext())
1213 theIObj->SetContext (this);
1216 if (myObjects.IsBound (theIObj))
1218 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1219 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1220 || aStatus->GraphicStatus() == AIS_DS_Erased)
1222 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1223 ? theIObj->DisplayMode()
1224 : (theIObj->AcceptDisplayMode (myDisplayMode)
1227 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1230 else if (HasOpenedContext())
1232 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1236 //=======================================================================
1237 //function : Redisplay
1239 //=======================================================================
1240 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1241 const Standard_Boolean theToUpdateViewer,
1242 const Standard_Boolean theAllModes)
1244 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1245 RecomputeSelectionOnly (theIObj);
1248 //=======================================================================
1249 //function : Redisplay
1251 //=======================================================================
1252 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1253 const Standard_Integer /*theSign*/,
1254 const Standard_Boolean theToUpdateViewer)
1256 Standard_Boolean isRedisplayed = Standard_False;
1257 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1259 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1260 if (anObj->Type() != theKOI)
1265 Redisplay (anObj, Standard_False);
1266 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1270 if (theToUpdateViewer
1273 myMainVwr->Update();
1277 //=======================================================================
1278 //function : RecomputePrsOnly
1280 //=======================================================================
1281 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1282 const Standard_Boolean theToUpdateViewer,
1283 const Standard_Boolean theAllModes)
1285 if (theIObj.IsNull())
1290 theIObj->Update (theAllModes);
1291 if (!theToUpdateViewer)
1296 if (HasOpenedContext()
1297 || (myObjects.IsBound (theIObj)
1298 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1300 myMainVwr->Update();
1303 //=======================================================================
1304 //function : RecomputeSelectionOnly
1306 //=======================================================================
1307 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1314 mgrSelector->RecomputeSelection (theIO);
1316 if (HasOpenedContext())
1318 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1320 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1325 if (!myObjects.IsBound (theIO) ||
1326 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1331 TColStd_ListOfInteger aModes;
1332 ActivatedModes (theIO, aModes);
1333 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1334 for (; aModesIter.More(); aModesIter.Next())
1336 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1340 //=======================================================================
1343 //=======================================================================
1344 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1345 const Standard_Boolean theUpdateViewer)
1347 if (theIObj.IsNull())
1352 TColStd_ListOfInteger aPrsModes;
1353 theIObj->ToBeUpdated (aPrsModes);
1354 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1356 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1359 mgrSelector->Update(theIObj);
1361 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1363 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1366 if (theUpdateViewer)
1368 if (!myObjects.IsBound (theIObj))
1373 switch (myObjects (theIObj)->GraphicStatus())
1375 case AIS_DS_Displayed:
1376 case AIS_DS_Temporary:
1377 myMainVwr->Update();
1385 //=======================================================================
1386 //function : SetLocation
1388 //=======================================================================
1389 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1390 const TopLoc_Location& theLoc)
1392 if (theIObj.IsNull())
1397 if (theIObj->HasTransformation()
1398 && theLoc.IsIdentity())
1400 theIObj->ResetTransformation();
1401 mgrSelector->Update (theIObj, Standard_False);
1404 else if (theLoc.IsIdentity())
1409 // first reset the previous location to properly clean everything...
1410 if (theIObj->HasTransformation())
1412 theIObj->ResetTransformation();
1415 theIObj->SetLocalTransformation (theLoc.Transformation());
1417 if (!HasOpenedContext())
1419 mgrSelector->Update (theIObj, Standard_False);
1423 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1424 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1428 //=======================================================================
1429 //function : ResetLocation
1431 //=======================================================================
1432 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1434 if (theIObj.IsNull())
1439 theIObj->ResetTransformation();
1440 mgrSelector->Update (theIObj, Standard_False);
1443 //=======================================================================
1444 //function : HasLocation
1446 //=======================================================================
1447 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1449 return !theIObj.IsNull()
1450 && theIObj->HasTransformation();
1453 //=======================================================================
1454 //function : Location
1456 //=======================================================================
1457 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1459 return theIObj->Transformation();
1462 //=======================================================================
1463 //function : SetDeviationCoefficient
1465 //=======================================================================
1466 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1468 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1471 //=======================================================================
1472 //function : SetDeviationAngle
1474 //=======================================================================
1475 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1477 myDefaultDrawer->SetDeviationCoefficient (theAngle);
1480 //=======================================================================
1481 //function : DeviationAngle
1482 //purpose : Gets deviationAngle
1483 //=======================================================================
1484 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1486 return myDefaultDrawer->DeviationAngle();
1489 //=======================================================================
1490 //function : DeviationCoefficient
1492 //=======================================================================
1493 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1495 return myDefaultDrawer->DeviationCoefficient();
1498 //=======================================================================
1499 //function : SetHLRDeviationCoefficient
1501 //=======================================================================
1502 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1504 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1507 //=======================================================================
1508 //function : HLRDeviationCoefficient
1510 //=======================================================================
1511 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1513 return myDefaultDrawer->HLRDeviationCoefficient();
1516 //=======================================================================
1517 //function : SetHLRAngle
1519 //=======================================================================
1520 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1522 myDefaultDrawer->SetHLRAngle (theAngle);
1525 //=======================================================================
1526 //function : SetHLRAngleAndDeviation
1527 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1528 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1529 // of myDefaultDrawer
1530 //=======================================================================
1531 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1533 Standard_Real anOutAngl, anOutDefl;
1534 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1536 myDefaultDrawer->SetHLRAngle (anOutAngl);
1537 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1540 //=======================================================================
1541 //function : HLRAngle
1543 //=======================================================================
1544 Standard_Real AIS_InteractiveContext::HLRAngle() const
1546 return myDefaultDrawer->HLRAngle();
1549 //=======================================================================
1550 //function : SetDisplayMode
1552 //=======================================================================
1553 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1554 const Standard_Boolean theToUpdateViewer)
1556 if (theMode == myDisplayMode)
1561 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1563 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1564 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1565 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1566 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1569 || anObj->HasDisplayMode()
1570 || !anObj->AcceptDisplayMode (theMode))
1575 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1576 if (aStatus->IsDModeIn (myDisplayMode))
1578 aStatus->RemoveDisplayMode (myDisplayMode);
1581 aStatus->AddDisplayMode (theMode);
1582 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1584 myMainPM->Display (anObj, theMode);
1585 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1587 myMainPM->BeginImmediateDraw();
1588 myMainPM->Unhighlight (anObj, myDisplayMode);
1589 myMainPM->EndImmediateDraw (myMainVwr);
1591 if (aStatus->IsSubIntensityOn())
1593 myMainPM->Color (anObj, mySubIntensity, theMode);
1595 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1599 myDisplayMode = theMode;
1600 if (theToUpdateViewer)
1602 myMainVwr->Update();
1606 //=======================================================================
1607 //function : SetDisplayMode
1609 //=======================================================================
1610 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1611 const Standard_Integer theMode,
1612 const Standard_Boolean theToUpdateViewer)
1614 if (!theIObj->HasInteractiveContext())
1616 theIObj->SetContext(this);
1619 if (!myObjects.IsBound (theIObj))
1621 theIObj->SetDisplayMode (theMode);
1624 else if (!theIObj->AcceptDisplayMode (theMode))
1629 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1630 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1632 theIObj->SetDisplayMode (theMode);
1636 // erase presentations for all display modes different from <aMode>
1637 TColStd_ListOfInteger aModesToRemove;
1638 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1640 const Standard_Integer anOldMode = aDispModeIter.Value();
1641 if (anOldMode != theMode)
1643 aModesToRemove.Append (anOldMode);
1644 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1646 myMainPM->Unhighlight (theIObj, anOldMode);
1648 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1652 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1654 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1657 if (!aStatus->IsDModeIn (theMode))
1659 aStatus->AddDisplayMode (theMode);
1662 myMainPM->Display (theIObj, theMode);
1663 Standard_Integer aDispMode, aHiMode, aSelMode;
1664 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1665 if (aStatus->IsHilighted())
1667 myMainPM->Highlight (theIObj, aHiMode);
1669 if (aStatus->IsSubIntensityOn())
1671 myMainPM->Color (theIObj, mySubIntensity, theMode);
1674 if (theToUpdateViewer)
1676 myMainVwr->Update();
1678 theIObj->SetDisplayMode (theMode);
1681 //=======================================================================
1682 //function : UnsetDisplayMode
1684 //=======================================================================
1685 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1686 const Standard_Boolean theToUpdateViewer)
1688 if (theIObj.IsNull()
1689 || !theIObj->HasDisplayMode())
1694 if (!myObjects.IsBound (theIObj))
1696 theIObj->UnsetDisplayMode();
1700 const Standard_Integer anOldMode = theIObj->DisplayMode();
1701 if (myDisplayMode == anOldMode)
1706 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1707 aStatus->RemoveDisplayMode (anOldMode);
1708 if (!aStatus->IsDModeIn(myDisplayMode))
1710 aStatus->AddDisplayMode (myDisplayMode);
1713 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1715 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1717 myMainPM->Unhighlight (theIObj, anOldMode);
1719 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1720 myMainPM->Display (theIObj, myDisplayMode);
1722 Standard_Integer aDispMode, aHiMode, aSelMode;
1723 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1724 if (aStatus->IsHilighted())
1726 myMainPM->Highlight (theIObj, aHiMode);
1728 if (aStatus->IsSubIntensityOn())
1730 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1733 if (theToUpdateViewer)
1735 myMainVwr->Update();
1739 theIObj->UnsetDisplayMode();
1742 //=======================================================================
1743 //function : SetCurrentFacingModel
1745 //=======================================================================
1746 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1747 const Aspect_TypeOfFacingModel theModel)
1749 if (!theIObj.IsNull())
1751 theIObj->SetCurrentFacingModel (theModel);
1755 //=======================================================================
1756 //function : redisplayPrsRecModes
1758 //=======================================================================
1759 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1760 const Standard_Boolean theToUpdateViewer)
1762 if (theIObj->RecomputeEveryPrs())
1764 theIObj->Update (Standard_True);
1765 theIObj->UpdateSelection();
1769 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1771 theIObj->Update (aModes.Value(), Standard_False);
1773 theIObj->UpdateSelection();
1774 theIObj->SetRecomputeOk();
1777 if (theToUpdateViewer)
1779 UpdateCurrentViewer();
1783 //=======================================================================
1784 //function : redisplayPrsModes
1786 //=======================================================================
1787 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1788 const Standard_Boolean theToUpdateViewer)
1790 if (theIObj->RecomputeEveryPrs())
1792 theIObj->Update (Standard_True);
1793 theIObj->UpdateSelection();
1797 TColStd_ListOfInteger aModes;
1798 theIObj->ToBeUpdated (aModes);
1799 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1801 theIObj->Update (aModeIter.Value(), Standard_False);
1803 theIObj->SetRecomputeOk();
1806 if (theToUpdateViewer)
1808 UpdateCurrentViewer();
1812 //=======================================================================
1813 //function : SetColor
1815 //=======================================================================
1816 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1817 const Quantity_NameOfColor theColor,
1818 const Standard_Boolean theToUpdateViewer)
1820 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1823 //=======================================================================
1824 //function : SetColor
1826 //=======================================================================
1827 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1828 const Quantity_Color& theColor,
1829 const Standard_Boolean theToUpdateViewer)
1831 if (theIObj.IsNull())
1836 if (!theIObj->HasInteractiveContext())
1838 theIObj->SetContext (this);
1840 theIObj->SetColor (theColor);
1841 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1844 //=======================================================================
1845 //function : SetDeviationCoefficient
1847 //=======================================================================
1848 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1849 const Standard_Real theCoefficient,
1850 const Standard_Boolean theToUpdateViewer)
1852 if (theIObj.IsNull())
1857 if (!theIObj->HasInteractiveContext())
1859 theIObj->SetContext (this);
1862 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1863 if (theIObj->Type() != AIS_KOI_Object
1864 && theIObj->Type() != AIS_KOI_Shape)
1868 else if (theIObj->Signature() != 0)
1873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1874 aShape->SetOwnDeviationCoefficient (theCoefficient);
1875 redisplayPrsModes (theIObj, theToUpdateViewer);
1878 //=======================================================================
1879 //function : SetHLRDeviationCoefficient
1881 //=======================================================================
1882 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1883 const Standard_Real theCoefficient,
1884 const Standard_Boolean theToUpdateViewer)
1886 if (theIObj.IsNull())
1891 if (!theIObj->HasInteractiveContext())
1893 theIObj->SetContext (this);
1896 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1897 if (theIObj->Type() != AIS_KOI_Object
1898 && theIObj->Type() != AIS_KOI_Shape)
1902 else if (theIObj->Signature() != 0)
1907 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1908 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1909 redisplayPrsModes (theIObj, theToUpdateViewer);
1912 //=======================================================================
1913 //function : SetDeviationAngle
1915 //=======================================================================
1916 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1917 const Standard_Real theAngle,
1918 const Standard_Boolean theToUpdateViewer)
1920 if (theIObj.IsNull())
1925 if (!theIObj->HasInteractiveContext())
1927 theIObj->SetContext (this);
1930 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1931 if (theIObj->Type() != AIS_KOI_Shape)
1935 else if (theIObj->Signature() != 0)
1940 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1941 aShape->SetOwnDeviationAngle (theAngle);
1942 redisplayPrsModes (theIObj, theToUpdateViewer);
1945 //=======================================================================
1946 //function : SetAngleAndDeviation
1948 //=======================================================================
1949 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1950 const Standard_Real theAngle,
1951 const Standard_Boolean theToUpdateViewer)
1953 if (theIObj.IsNull())
1958 if (!theIObj->HasInteractiveContext())
1960 theIObj->SetContext (this);
1963 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1964 if (theIObj->Type() != AIS_KOI_Shape)
1968 if (theIObj->Signature() != 0)
1973 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1974 aShape->SetAngleAndDeviation (theAngle);
1976 if (theIObj->RecomputeEveryPrs())
1978 theIObj->Update (Standard_True);
1979 theIObj->UpdateSelection();
1983 Update (theIObj, theToUpdateViewer);
1987 //=======================================================================
1988 //function : SetHLRAngleAndDeviation
1990 //=======================================================================
1991 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1992 const Standard_Real theAngle,
1993 const Standard_Boolean theToUpdateViewer)
1995 if (theIObj.IsNull())
2000 if (!theIObj->HasInteractiveContext())
2002 theIObj->SetContext (this);
2005 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2006 if (theIObj->Type() != AIS_KOI_Shape)
2010 if (theIObj->Signature() != 0)
2014 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2015 aShape->SetHLRAngleAndDeviation (theAngle);
2016 redisplayPrsModes (theIObj, theToUpdateViewer);
2019 //=======================================================================
2020 //function : SetHLRDeviationAngle
2022 //=======================================================================
2023 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2024 const Standard_Real theAngle,
2025 const Standard_Boolean theToUpdateViewer)
2027 if (theIObj.IsNull())
2032 if (!theIObj->HasInteractiveContext())
2034 theIObj->SetContext (this);
2037 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2038 if (theIObj->Type() != AIS_KOI_Shape)
2042 if (theIObj->Signature() != 0)
2046 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2047 aShape->SetOwnHLRDeviationAngle (theAngle);
2048 redisplayPrsModes (theIObj, theToUpdateViewer);
2051 //=======================================================================
2052 //function : UnsetColor
2054 //=======================================================================
2055 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2056 const Standard_Boolean theToUpdateViewer)
2058 if (theIObj.IsNull())
2063 theIObj->UnsetColor();
2064 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2067 //=======================================================================
2068 //function : HasColor
2070 //=======================================================================
2071 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2073 return theIObj->HasColor();
2076 //=======================================================================
2079 //=======================================================================
2080 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2082 return theIObj->Color();
2085 //=======================================================================
2088 //=======================================================================
2089 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2090 Quantity_Color& theColor) const
2092 theIObj->Color (theColor);
2095 //=======================================================================
2098 //=======================================================================
2099 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2101 return theIObj->Width();
2104 //=======================================================================
2105 //function : SetWidth
2107 //=======================================================================
2108 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2109 const Standard_Real theWidth,
2110 const Standard_Boolean theToUpdateViewer)
2112 if (theIObj.IsNull())
2117 if (!theIObj->HasInteractiveContext())
2119 theIObj->SetContext (this);
2122 theIObj->SetWidth (theWidth);
2123 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2124 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2126 if (myLastinMain->IsAutoHilight())
2128 const Standard_Integer aHiMode =
2129 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2130 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2134 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2139 //=======================================================================
2140 //function : UnsetWidth
2142 //=======================================================================
2143 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2144 const Standard_Boolean theToUpdateViewer)
2146 if (theIObj.IsNull())
2151 theIObj->UnsetWidth();
2152 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2155 //=======================================================================
2156 //function : SetMaterial
2158 //=======================================================================
2159 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2160 const Graphic3d_NameOfMaterial theName,
2161 const Standard_Boolean theToUpdateViewer)
2163 if (theIObj.IsNull())
2168 if (!theIObj->HasInteractiveContext())
2170 theIObj->SetContext (this);
2173 theIObj->SetMaterial (theName);
2174 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2177 //=======================================================================
2178 //function : UnsetMaterial
2180 //=======================================================================
2181 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2182 const Standard_Boolean theToUpdateViewer)
2184 if (theIObj.IsNull())
2188 theIObj->UnsetMaterial();
2189 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2192 //=======================================================================
2193 //function : SetTransparency
2195 //=======================================================================
2196 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2197 const Standard_Real theValue,
2198 const Standard_Boolean theToUpdateViewer)
2200 if (theIObj.IsNull())
2205 if (!theIObj->HasInteractiveContext())
2207 theIObj->SetContext (this);
2210 if (!theIObj->IsTransparent()
2211 && theValue <= 0.05)
2216 if (theValue <= 0.05)
2218 UnsetTransparency (theIObj, theToUpdateViewer);
2222 theIObj->SetTransparency (theValue);
2223 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2226 //=======================================================================
2227 //function : UnsetTransparency
2229 //=======================================================================
2230 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2231 const Standard_Boolean theToUpdateViewer)
2233 if (theIObj.IsNull())
2238 theIObj->UnsetTransparency();
2239 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2242 //=======================================================================
2243 //function : SetSelectedAspect
2245 //=======================================================================
2246 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2247 const Standard_Boolean theIsGlobalChange,
2248 const Standard_Boolean theToUpdateViewer)
2250 if (HasOpenedContext())
2255 Standard_Boolean isFound = Standard_False;
2256 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2257 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2259 isFound = Standard_True;
2260 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2261 anObj->SetAspect (theAspect, theIsGlobalChange);
2265 && theToUpdateViewer)
2267 myMainVwr->Update();
2271 //=======================================================================
2272 //function : SetLocalAttributes
2274 //=======================================================================
2275 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2276 const Handle(Prs3d_Drawer)& theDrawer,
2277 const Standard_Boolean theToUpdateViewer)
2279 if (theIObj.IsNull())
2284 if (!theIObj->HasInteractiveContext())
2286 theIObj->SetContext (this);
2289 theIObj->SetAttributes (theDrawer);
2290 Update (theIObj, theToUpdateViewer);
2293 //=======================================================================
2294 //function : UnsetLocalAttributes
2296 //=======================================================================
2297 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2298 const Standard_Boolean theToUpdateViewer)
2300 if (theIObj.IsNull())
2305 if (!theIObj->HasInteractiveContext())
2307 theIObj->SetContext (this);
2309 theIObj->UnsetAttributes();
2310 Update (theIObj, theToUpdateViewer);
2313 //=======================================================================
2316 //=======================================================================
2317 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2318 TCollection_ExtendedString& theStatus) const
2321 if (theIObj.IsNull()
2322 || !myObjects.IsBound (theIObj))
2327 theStatus += "\t ____________________________________________";
2328 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2329 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2330 switch (aStatus->GraphicStatus())
2332 case AIS_DS_Displayed:
2334 theStatus += "\t| -->Displayed\n";
2339 theStatus += "\t| -->Erased\n";
2346 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2347 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2349 theStatus += "\t|\t Mode ";
2350 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2353 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2355 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2356 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2358 theStatus += "\t\t Mode ";
2359 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2362 theStatus += "\t ____________________________________________";
2365 //=======================================================================
2366 //function : GetDefModes
2368 //=======================================================================
2369 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2370 Standard_Integer& theDispMode,
2371 Standard_Integer& theHiMode,
2372 Standard_Integer& theSelMode) const
2374 if (theIObj.IsNull())
2379 theDispMode = theIObj->HasDisplayMode()
2380 ? theIObj->DisplayMode()
2381 : (theIObj->AcceptDisplayMode (myDisplayMode)
2384 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2385 theSelMode = theIObj->GlobalSelectionMode();
2388 //=======================================================================
2389 //function : EraseGlobal
2391 //=======================================================================
2392 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2393 const Standard_Boolean theToUpdateviewer)
2395 if (theIObj.IsNull()
2396 || !myObjects.IsBound (theIObj))
2401 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2403 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2404 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2405 || aStatus->GraphicStatus() == AIS_DS_Erased)
2410 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2412 if (aStatus->IsHilighted())
2414 if (IsCurrent (theIObj))
2416 AddOrRemoveCurrentObject (theIObj, Standard_False);
2418 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2420 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2424 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2427 if (IsSelected (theIObj)
2428 && !aStatus->IsDModeIn (aDispMode))
2430 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2433 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2435 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2437 aStatus->ClearSelectionModes();
2438 aStatus->SetGraphicStatus (AIS_DS_Erased);
2440 if (theToUpdateviewer)
2442 myMainVwr->Update();
2446 //=======================================================================
2447 //function : unhighlightOwners
2449 //=======================================================================
2450 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2452 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
2454 while (aSel->More())
2456 const Handle(SelectMgr_EntityOwner) anOwner =
2457 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
2458 if (anOwner->Selectable() == theObject)
2460 if (anOwner->IsSelected())
2462 AddOrRemoveSelected (anOwner, Standard_False);
2471 //=======================================================================
2472 //function : ClearGlobal
2474 //=======================================================================
2475 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2476 const Standard_Boolean theToUpdateviewer)
2478 if (theIObj.IsNull()
2479 || !myObjects.IsBound (theIObj))
2481 // for cases when reference shape of connected interactives was not displayed
2482 // but its selection primitives were calculated
2483 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2484 mgrSelector->Remove (anObj);
2488 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2489 unhighlightOwners (theIObj);
2490 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2492 myMainPM->Erase (theIObj, aDispModeIter.Value());
2493 myMainPM->Clear (theIObj, aDispModeIter.Value());
2496 // Object removes from Detected sequence
2497 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2499 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2501 && anObj != theIObj)
2503 myAISDetectedSeq.Remove (aDetIter);
2507 // remove IO from the selection manager to avoid memory leaks
2508 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2509 mgrSelector->Remove (anObj);
2511 myObjects.UnBind (theIObj);
2512 myMainVwr->Viewer()->UnregisterObject (theIObj);
2513 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2515 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2518 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2519 myLastinMain.Nullify();
2520 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2521 myLastPicked.Nullify();
2522 myMainPM->ClearImmediateDraw();
2524 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2526 myMainVwr->Update();
2530 //=======================================================================
2531 //function : ClearGlobalPrs
2533 //=======================================================================
2534 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2535 const Standard_Integer theMode,
2536 const Standard_Boolean theToUpdateViewer)
2538 if (theIObj.IsNull()
2539 || !myObjects.IsBound (theIObj))
2544 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2545 if (aStatus->IsDModeIn (theMode))
2547 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2548 if (aDispMode == theMode
2549 && myMainPM->IsHighlighted (theIObj, theMode))
2551 myMainPM->Unhighlight (theIObj, theMode);
2554 myMainPM->Erase (theIObj, theMode);
2555 myMainPM->Clear (theIObj, theMode);
2558 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2559 && theToUpdateViewer)
2561 myMainVwr->Update();
2565 //=======================================================================
2566 //function : DrawHiddenLine
2568 //=======================================================================
2569 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2571 return myDefaultDrawer->DrawHiddenLine();
2574 //=======================================================================
2575 //function : EnableDrawHiddenLine
2577 //=======================================================================
2578 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2580 myDefaultDrawer->EnableDrawHiddenLine();
2583 //=======================================================================
2584 //function : DisableDrawHiddenLine
2586 //=======================================================================
2587 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2589 myDefaultDrawer->DisableDrawHiddenLine();
2592 //=======================================================================
2593 //function : HiddenLineAspect
2595 //=======================================================================
2596 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2598 return myDefaultDrawer->HiddenLineAspect();
2601 //=======================================================================
2602 //function : SetHiddenLineAspect
2604 //=======================================================================
2605 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2607 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2610 //=======================================================================
2611 //function : SetIsoNumber
2613 //=======================================================================
2614 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2615 const AIS_TypeOfIso theType)
2620 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2623 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2626 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2627 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2632 //=======================================================================
2633 //function : IsoNumber
2635 //=======================================================================
2636 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2640 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2641 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2642 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2643 ? myDefaultDrawer->UIsoAspect()->Number()
2649 //=======================================================================
2650 //function : IsoOnPlane
2652 //=======================================================================
2653 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2655 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2658 //=======================================================================
2659 //function : IsoOnPlane
2661 //=======================================================================
2662 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2664 return myDefaultDrawer->IsoOnPlane();
2667 //=======================================================================
2668 //function : SetPixelTolerance
2669 //purpose : Disables the mechanism of adaptive tolerance calculation in
2670 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2671 // sensitive entities activated. For more information, see
2672 // SelectMgr_ViewerSelector.hxx
2673 //=======================================================================
2674 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Real thePrecision)
2676 if (HasOpenedContext())
2678 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2682 myMainSel->SetPixelTolerance (thePrecision);
2686 //=======================================================================
2687 //function : PixelTolerance
2689 //=======================================================================
2690 Standard_Real AIS_InteractiveContext::PixelTolerance() const
2692 return HasOpenedContext()
2693 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2694 : myMainSel->PixelTolerance();
2697 //=======================================================================
2698 //function : IsInLocal
2700 //=======================================================================
2701 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2702 Standard_Integer& theIndex) const
2704 if (theIObj.IsNull())
2706 return Standard_False;
2709 // if it exists at neutral point 0 index is returned
2710 if (myObjects.IsBound (theIObj))
2713 return Standard_False;
2716 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2718 if (myLocalContexts.IsBound (aCtxIter))
2720 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2722 theIndex = aCtxIter;
2723 return Standard_True;
2728 return Standard_False;
2731 //=======================================================================
2732 //function : InitAttributes
2734 //=======================================================================
2735 void AIS_InteractiveContext::InitAttributes()
2737 mgrSelector->Add (myMainSel);
2738 myCurrentName = AIS_Context_NewCurName();
2739 mySelectionName = AIS_Context_NewSelName();
2741 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2742 AIS_Selection::CreateSelection (myCurrentName.ToCString());
2744 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2745 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2746 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2748 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2749 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2750 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2751 aLineAspect->SetWidth (1.0);
2752 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2754 // tolerance to 2 pixels...
2755 SetPixelTolerance (2.0);
2757 // Customizing the drawer for trihedrons and planes...
2758 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2759 const Standard_Real aLength = 100.0;
2760 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2761 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2762 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2763 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2764 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2766 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2767 const Standard_Real aPlaneLength = 200.0;
2768 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2769 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2772 //=======================================================================
2773 //function : TrihedronSize
2775 //=======================================================================
2776 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2778 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2781 //=======================================================================
2782 //function : SetTrihedronSize
2784 //=======================================================================
2785 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2786 const Standard_Boolean /*updateviewer*/)
2788 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2789 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2790 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2793 //=======================================================================
2794 //function : SetPlaneSize
2796 //=======================================================================
2797 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2798 const Standard_Real theValY,
2799 const Standard_Boolean /*updateviewer*/)
2801 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2802 Redisplay (AIS_KOI_Datum, 7);
2805 //=======================================================================
2806 //function : SetPlaneSize
2808 //=======================================================================
2809 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2810 const Standard_Boolean theToUpdateViewer)
2812 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2815 //=======================================================================
2816 //function : PlaneSize
2818 //=======================================================================
2819 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2820 Standard_Real& theY) const
2822 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2823 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2824 return (Abs (theX - theY) <= Precision::Confusion());
2827 //=======================================================================
2828 //function : SetAutoActivateSelection
2830 //=======================================================================
2831 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2833 myIsAutoActivateSelMode = theIsAuto;
2836 //=======================================================================
2837 //function : GetAutoActivateSelection
2839 //=======================================================================
2840 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2842 return myIsAutoActivateSelMode;
2845 //=======================================================================
2846 //function : SetZLayer
2848 //=======================================================================
2849 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2850 const Standard_Integer theLayerId)
2852 if (theIObj.IsNull())
2855 theIObj->SetZLayer (theLayerId);
2858 //=======================================================================
2859 //function : GetZLayer
2861 //=======================================================================
2862 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2864 return !theIObj.IsNull()
2866 : Graphic3d_ZLayerId_UNKNOWN;
2869 //=======================================================================
2870 //function : RebuildSelectionStructs
2871 //purpose : Rebuilds 1st level of BVH selection forcibly
2872 //=======================================================================
2873 void AIS_InteractiveContext::RebuildSelectionStructs()
2875 myMainSel->RebuildObjectsTree (Standard_True);
2878 //=======================================================================
2879 //function : Disconnect
2880 //purpose : Disconnects selectable object from an assembly and updates selection structures
2881 //=======================================================================
2882 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2883 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2885 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2887 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2888 theObj->Disconnect (theObjToDisconnect);
2889 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2890 mgrSelector->Remove (anObj);
2892 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2894 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2895 theObj->Disconnect();
2896 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2897 mgrSelector->Remove (anObj);
2903 //=======================================================================
2904 //function : FitSelected
2905 //purpose : Fits the view corresponding to the bounds of selected objects
2906 //=======================================================================
2907 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2908 const Standard_Real theMargin,
2909 const Standard_Boolean theToUpdate)
2911 Standard_CString aSelName = HasOpenedContext() ?
2912 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2913 : myCurrentName.ToCString();
2915 Bnd_Box aBndSelected;
2917 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2918 AIS_MapOfObjectOwners anObjectOwnerMap;
2919 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2921 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2922 if (!anObj.IsNull())
2924 if (anObj->IsInfinite())
2928 anObj->BoundingBox (aTmpBnd);
2929 aBndSelected.Add (aTmpBnd);
2933 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2934 if (anOwner.IsNull())
2937 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2938 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2940 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2941 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2944 anOwnerMap->Add (anOwner);
2948 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2950 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2951 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2952 aBndSelected.Add (aTmpBox);
2955 anObjectOwnerMap.Clear();
2957 if (aBndSelected.IsVoid())
2960 theView->FitAll (aBndSelected, theMargin, theToUpdate);