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->Color (theIObj, aStatus->HilightColor(), 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 if (!aStatus->IsSModeIn (theSelectionMode))
538 aStatus->AddSelectionMode (theSelectionMode);
539 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
544 if (theToUpdateViewer)
550 //=======================================================================
553 //=======================================================================
554 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
555 const Standard_Integer theSelMode,
556 const Standard_Boolean theToAllowDecomposition)
558 if (theIObj.IsNull())
563 if (!theIObj->HasInteractiveContext())
565 theIObj->SetContext (this);
568 if (HasOpenedContext())
570 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
575 && !theToAllowDecomposition)
577 if (!myObjects.IsBound (theIObj))
579 Standard_Integer aDispMode, aHiMod, aSelModeDef;
580 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
581 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
582 myObjects.Bind (theIObj, aStatus);
585 // Register theIObj in the selection manager to prepare further activation of selection
586 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
587 if (!mgrSelector->Contains (anObj))
589 mgrSelector->Load (theIObj);
594 //=======================================================================
597 //=======================================================================
598 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
599 const Standard_Boolean theToUpdateViewer)
601 if (theIObj.IsNull())
606 if (!theIObj->IsAutoHilight())
608 theIObj->ClearSelected();
611 Standard_Boolean wasInCtx = Standard_False;
612 if (HasOpenedContext())
614 // First it is checked if it is possible to remove in the current local context
615 // then one tries to remove in other local contexts, if they allow it...
616 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
617 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
619 if (aCtxIter.Value()->AcceptErase())
621 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
628 EraseGlobal (theIObj, Standard_False);
631 if (theToUpdateViewer)
637 //=======================================================================
638 //function : EraseAll
640 //=======================================================================
641 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
643 if (HasOpenedContext())
648 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
650 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
652 Erase (anObjIter.Key(), Standard_False);
656 if (theToUpdateViewer)
662 //=======================================================================
663 //function : DisplayAll
665 //=======================================================================
666 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
668 if (HasOpenedContext())
673 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
675 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
676 if (aStatus == AIS_DS_Erased)
678 Display (anObjIter.Key(), Standard_False);
682 if (theToUpdateViewer)
688 //=======================================================================
689 //function : DisplaySelected
691 //=======================================================================
692 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
694 if (HasOpenedContext())
699 Standard_Boolean isFound = Standard_False;
700 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
701 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
703 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
704 Display (anObj, Standard_False);
705 isFound = Standard_True;
708 if (isFound && theToUpdateViewer)
714 //=======================================================================
715 //function : EraseSelected
717 //=======================================================================
718 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
720 if (HasOpenedContext())
725 Standard_Boolean isFound = Standard_False;
726 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
727 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
729 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
730 Erase (anObj, Standard_False);
731 isFound = Standard_True;
734 if (isFound && theToUpdateViewer)
740 //=======================================================================
743 //=======================================================================
745 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
746 const Standard_Integer WhichContext)
748 if(anIObj.IsNull()) return Standard_False;
750 if(!HasOpenedContext()) return Standard_False;
751 if(myObjects.IsBound(anIObj)) return Standard_False;
752 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
754 // Protection : if one tries to preserve a temporary object
755 // which is not in the local active context... rob 11-06-97
757 Standard_Integer IsItInLocal = myCurLocalIndex;
758 Standard_Boolean Found(Standard_False);
760 while(IsItInLocal>0 && !Found){
761 if(!myLocalContexts.IsBound(IsItInLocal))
763 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
764 Found = Standard_True;
769 if(!Found) return Standard_False;
772 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
773 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
775 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
776 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
780 if(LS->IsTemporary()){
781 Standard_Integer DM,HM,SM;
782 GetDefModes(anIObj,DM,HM,SM);
784 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
785 if(LS->DisplayMode()!= DM ){
786 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
787 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
790 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
794 // GS->SubIntensityOn();
795 myObjects.Bind(anIObj,GS);
796 mgrSelector->Load(anIObj);
797 mgrSelector->Activate(anIObj,SM,myMainSel);
799 LS->SetTemporary(Standard_False);
801 return Standard_True;
804 //=======================================================================
805 //function : DisplayStatus
807 //=======================================================================
808 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
810 if (theIObj.IsNull())
814 else if (myObjects.IsBound (theIObj))
816 return myObjects (theIObj)->GraphicStatus();
819 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
821 if (aCtxIter.Value()->IsIn (theIObj))
823 return AIS_DS_Temporary;
829 //=======================================================================
830 //function : DisplayedModes
832 //=======================================================================
833 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
835 return myObjects (theIObj)->DisplayedModes();
838 //=======================================================================
841 //=======================================================================
842 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
843 const Standard_Boolean theToUpdateViewer)
845 if (theIObj.IsNull())
850 if (HasOpenedContext())
852 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
853 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
855 if (aCtxIter.Value()->AcceptErase())
857 aCtxIter.Value()->Remove (theIObj);
862 ClearGlobal (theIObj, theToUpdateViewer);
865 //=======================================================================
866 //function : RemoveAll
868 //=======================================================================
869 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
871 AIS_ListOfInteractive aList;
872 ObjectsInside (aList);
873 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
875 Remove (aListIterator.Value(), Standard_False);
878 if (theToUpdateViewer)
884 //=======================================================================
885 //function : ClearPrs
887 //=======================================================================
888 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
889 const Standard_Integer theMode,
890 const Standard_Boolean theToUpdateViewer)
892 if (theIObj.IsNull())
897 if (!HasOpenedContext())
899 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
903 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
904 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
906 if (aCtxIter.Value()->AcceptErase())
908 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
913 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
915 else if (theToUpdateViewer)
921 //=======================================================================
924 //=======================================================================
925 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
926 const Standard_Boolean theToUpdateViewer)
928 if (theIObj.IsNull())
933 if (!theIObj->HasInteractiveContext())
935 theIObj->SetContext (this);
937 if (!HasOpenedContext())
939 if (!myObjects.IsBound (theIObj))
944 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
945 aStatus->SetHilightStatus (Standard_True);
946 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
948 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
949 myMainPM->Highlight (theIObj, aHilightMode);
954 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
957 if (theToUpdateViewer)
962 //=======================================================================
965 //=======================================================================
967 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
968 const Quantity_NameOfColor aCol,
969 const Standard_Boolean updateviewer)
971 if(anIObj.IsNull()) return;
973 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
975 if (!HasOpenedContext())
977 if(!myObjects.IsBound(anIObj)) return;
979 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
980 aStatus->SetHilightStatus (Standard_True);
982 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
984 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
985 myMainPM->Color (anIObj, aCol, aHilightMode);
986 aStatus->SetHilightColor (aCol);
991 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
993 if(updateviewer) myMainVwr->Update();
996 //=======================================================================
997 //function : Unhilight
999 //=======================================================================
1001 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
1003 if(anIObj.IsNull()) return;
1005 if (!HasOpenedContext())
1007 if(!myObjects.IsBound(anIObj)) return;
1009 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
1010 aStatus->SetHilightStatus (Standard_False);
1011 aStatus->SetHilightColor(Quantity_NOC_WHITE);
1013 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1015 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
1016 myMainPM->Unhighlight (anIObj, aHilightMode);
1021 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1023 if(updateviewer) myMainVwr->Update();
1026 //=======================================================================
1027 //function : IsHilighted
1029 //=======================================================================
1031 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1033 if(anIObj.IsNull()) return Standard_False;
1035 if (!HasOpenedContext()){
1036 if(!myObjects.IsBound(anIObj))
1037 return Standard_False;
1038 return myObjects(anIObj)->IsHilighted();
1040 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1041 for(;ItM.More();ItM.Next()){
1042 if(ItM.Value()->IsHilighted(anIObj))
1043 return Standard_True;
1045 return Standard_False;
1048 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1049 Standard_Boolean& WithColor,
1050 Quantity_NameOfColor& TheHiCol) const
1052 if(!HasOpenedContext()){
1053 if(myObjects.IsBound(anIObj)){
1054 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1055 if(STAT->IsHilighted()){
1056 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1057 WithColor=Standard_True;
1058 TheHiCol = STAT->HilightColor();
1061 WithColor = Standard_False;
1062 return Standard_True;
1065 return Standard_False;
1067 Standard_Integer MaxIndex = HighestIndex();
1068 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1069 if(myLocalContexts.IsBound(i)){
1070 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1071 return Standard_True;
1075 return Standard_False;
1078 //=======================================================================
1079 //function : IsHilighted
1080 //purpose : Returns true if the objects global status is set to highlighted.
1081 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1082 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1083 // custom highlight color name will be stored to theCustomColorName
1084 //=======================================================================
1085 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1086 Standard_Boolean& theIsCustomColor,
1087 Quantity_NameOfColor& theCustomColorName) const
1089 if (theOwner.IsNull() || !theOwner->HasSelectable())
1090 return Standard_False;
1092 const Handle(AIS_InteractiveObject) anObj =
1093 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1095 if (!myObjects.IsBound (anObj))
1096 return Standard_False;
1098 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1099 if (anObjStatus->IsHilighted())
1101 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1103 theIsCustomColor = Standard_True;
1104 theCustomColorName = anObjStatus->HilightColor();
1108 theIsCustomColor = Standard_False;
1111 return Standard_True;
1114 return Standard_False;
1117 //=======================================================================
1118 //function : IsDisplayed
1120 //=======================================================================
1122 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1124 if(anIObj.IsNull()) return Standard_False;
1127 if(myObjects.IsBound(anIObj))
1128 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1129 return Standard_True;
1131 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1132 for(;ItM.More();ItM.Next()){
1133 if(ItM.Value()->IsDisplayed(anIObj))
1134 return Standard_True;
1136 return Standard_False;
1140 //=======================================================================
1141 //function : IsDisplayed
1143 //=======================================================================
1144 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1145 const Standard_Integer theMode) const
1147 if (theIObj.IsNull())
1149 return Standard_False;
1152 if (myObjects.IsBound (theIObj))
1154 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1155 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1156 && aStatus->IsDModeIn (theMode))
1158 return Standard_True;
1162 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1164 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1166 return Standard_True;
1169 return Standard_False;
1172 //=======================================================================
1173 //function : DisplayPriority
1175 //=======================================================================
1176 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1178 if (theIObj.IsNull())
1182 else if (!myObjects.IsBound (theIObj))
1187 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1188 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1189 || aStatus->GraphicStatus() == AIS_DS_Erased)
1191 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1192 ? theIObj->DisplayMode()
1193 : (theIObj->AcceptDisplayMode (myDisplayMode)
1196 return myMainPM->DisplayPriority (theIObj, aDispMode);
1201 //=======================================================================
1202 //function : SetDisplayPriority
1204 //=======================================================================
1205 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1206 const Standard_Integer thePriority)
1208 if (theIObj.IsNull())
1213 if (!theIObj->HasInteractiveContext())
1215 theIObj->SetContext (this);
1218 if (myObjects.IsBound (theIObj))
1220 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1221 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1222 || aStatus->GraphicStatus() == AIS_DS_Erased)
1224 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1225 ? theIObj->DisplayMode()
1226 : (theIObj->AcceptDisplayMode (myDisplayMode)
1229 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1232 else if (HasOpenedContext())
1234 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1238 //=======================================================================
1239 //function : Redisplay
1241 //=======================================================================
1242 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1243 const Standard_Boolean theToUpdateViewer,
1244 const Standard_Boolean theAllModes)
1246 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1247 RecomputeSelectionOnly (theIObj);
1250 //=======================================================================
1251 //function : Redisplay
1253 //=======================================================================
1254 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1255 const Standard_Integer /*theSign*/,
1256 const Standard_Boolean theToUpdateViewer)
1258 Standard_Boolean isRedisplayed = Standard_False;
1259 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1261 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1262 if (anObj->Type() != theKOI)
1267 Redisplay (anObj, Standard_False);
1268 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1272 if (theToUpdateViewer
1275 myMainVwr->Update();
1279 //=======================================================================
1280 //function : RecomputePrsOnly
1282 //=======================================================================
1283 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1284 const Standard_Boolean theToUpdateViewer,
1285 const Standard_Boolean theAllModes)
1287 if (theIObj.IsNull())
1292 theIObj->Update (theAllModes);
1293 if (!theToUpdateViewer)
1298 if (HasOpenedContext()
1299 || (myObjects.IsBound (theIObj)
1300 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1302 myMainVwr->Update();
1305 //=======================================================================
1306 //function : RecomputeSelectionOnly
1308 //=======================================================================
1309 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1316 mgrSelector->RecomputeSelection (theIO);
1318 if (HasOpenedContext())
1320 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1322 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1327 if (!myObjects.IsBound (theIO) ||
1328 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1333 TColStd_ListOfInteger aModes;
1334 ActivatedModes (theIO, aModes);
1335 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1336 for (; aModesIter.More(); aModesIter.Next())
1338 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1342 //=======================================================================
1345 //=======================================================================
1346 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1347 const Standard_Boolean theUpdateViewer)
1349 if (theIObj.IsNull())
1354 TColStd_ListOfInteger aPrsModes;
1355 theIObj->ToBeUpdated (aPrsModes);
1356 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1358 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1361 mgrSelector->Update(theIObj);
1363 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1365 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1368 if (theUpdateViewer)
1370 if (!myObjects.IsBound (theIObj))
1375 switch (myObjects (theIObj)->GraphicStatus())
1377 case AIS_DS_Displayed:
1378 case AIS_DS_Temporary:
1379 myMainVwr->Update();
1387 //=======================================================================
1388 //function : SetLocation
1390 //=======================================================================
1391 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1392 const TopLoc_Location& theLoc)
1394 if (theIObj.IsNull())
1399 if (theIObj->HasTransformation()
1400 && theLoc.IsIdentity())
1402 theIObj->ResetTransformation();
1403 mgrSelector->Update (theIObj, Standard_False);
1406 else if (theLoc.IsIdentity())
1411 // first reset the previous location to properly clean everything...
1412 if (theIObj->HasTransformation())
1414 theIObj->ResetTransformation();
1417 theIObj->SetLocalTransformation (theLoc.Transformation());
1419 if (!HasOpenedContext())
1421 mgrSelector->Update (theIObj, Standard_False);
1425 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1426 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1430 //=======================================================================
1431 //function : ResetLocation
1433 //=======================================================================
1434 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1436 if (theIObj.IsNull())
1441 theIObj->ResetTransformation();
1442 mgrSelector->Update (theIObj, Standard_False);
1445 //=======================================================================
1446 //function : HasLocation
1448 //=======================================================================
1449 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1451 return !theIObj.IsNull()
1452 && theIObj->HasTransformation();
1455 //=======================================================================
1456 //function : Location
1458 //=======================================================================
1459 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1461 return theIObj->Transformation();
1464 //=======================================================================
1465 //function : SetDeviationCoefficient
1467 //=======================================================================
1468 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1470 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1473 //=======================================================================
1474 //function : SetDeviationAngle
1476 //=======================================================================
1477 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1479 myDefaultDrawer->SetDeviationCoefficient (theAngle);
1482 //=======================================================================
1483 //function : DeviationAngle
1484 //purpose : Gets deviationAngle
1485 //=======================================================================
1486 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1488 return myDefaultDrawer->DeviationAngle();
1491 //=======================================================================
1492 //function : DeviationCoefficient
1494 //=======================================================================
1495 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1497 return myDefaultDrawer->DeviationCoefficient();
1500 //=======================================================================
1501 //function : SetHLRDeviationCoefficient
1503 //=======================================================================
1504 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1506 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1509 //=======================================================================
1510 //function : HLRDeviationCoefficient
1512 //=======================================================================
1513 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1515 return myDefaultDrawer->HLRDeviationCoefficient();
1518 //=======================================================================
1519 //function : SetHLRAngle
1521 //=======================================================================
1522 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1524 myDefaultDrawer->SetHLRAngle (theAngle);
1527 //=======================================================================
1528 //function : SetHLRAngleAndDeviation
1529 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1530 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1531 // of myDefaultDrawer
1532 //=======================================================================
1533 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1535 Standard_Real anOutAngl, anOutDefl;
1536 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1538 myDefaultDrawer->SetHLRAngle (anOutAngl);
1539 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1542 //=======================================================================
1543 //function : HLRAngle
1545 //=======================================================================
1546 Standard_Real AIS_InteractiveContext::HLRAngle() const
1548 return myDefaultDrawer->HLRAngle();
1551 //=======================================================================
1552 //function : SetDisplayMode
1554 //=======================================================================
1555 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1556 const Standard_Boolean theToUpdateViewer)
1558 if (theMode == myDisplayMode)
1563 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1565 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1566 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1567 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1568 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1571 || anObj->HasDisplayMode()
1572 || !anObj->AcceptDisplayMode (theMode))
1577 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1578 if (aStatus->IsDModeIn (myDisplayMode))
1580 aStatus->RemoveDisplayMode (myDisplayMode);
1583 aStatus->AddDisplayMode (theMode);
1584 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1586 myMainPM->Display (anObj, theMode);
1587 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1589 myMainPM->BeginImmediateDraw();
1590 myMainPM->Unhighlight (anObj, myDisplayMode);
1591 myMainPM->EndImmediateDraw (myMainVwr);
1593 if (aStatus->IsSubIntensityOn())
1595 myMainPM->Color (anObj, mySubIntensity, theMode);
1597 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1601 myDisplayMode = theMode;
1602 if (theToUpdateViewer)
1604 myMainVwr->Update();
1608 //=======================================================================
1609 //function : SetDisplayMode
1611 //=======================================================================
1612 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1613 const Standard_Integer theMode,
1614 const Standard_Boolean theToUpdateViewer)
1616 if (!theIObj->HasInteractiveContext())
1618 theIObj->SetContext(this);
1621 if (!myObjects.IsBound (theIObj))
1623 theIObj->SetDisplayMode (theMode);
1626 else if (!theIObj->AcceptDisplayMode (theMode))
1631 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1632 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1634 theIObj->SetDisplayMode (theMode);
1638 // erase presentations for all display modes different from <aMode>
1639 TColStd_ListOfInteger aModesToRemove;
1640 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1642 const Standard_Integer anOldMode = aDispModeIter.Value();
1643 if (anOldMode != theMode)
1645 aModesToRemove.Append (anOldMode);
1646 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1648 myMainPM->Unhighlight (theIObj, anOldMode);
1650 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1654 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1656 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1659 if (!aStatus->IsDModeIn (theMode))
1661 aStatus->AddDisplayMode (theMode);
1664 myMainPM->Display (theIObj, theMode);
1665 Standard_Integer aDispMode, aHiMode, aSelMode;
1666 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1667 if (aStatus->IsHilighted())
1669 myMainPM->Highlight (theIObj, aHiMode);
1671 if (aStatus->IsSubIntensityOn())
1673 myMainPM->Color (theIObj, mySubIntensity, theMode);
1676 if (theToUpdateViewer)
1678 myMainVwr->Update();
1680 theIObj->SetDisplayMode (theMode);
1683 //=======================================================================
1684 //function : UnsetDisplayMode
1686 //=======================================================================
1687 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1688 const Standard_Boolean theToUpdateViewer)
1690 if (theIObj.IsNull()
1691 || !theIObj->HasDisplayMode())
1696 if (!myObjects.IsBound (theIObj))
1698 theIObj->UnsetDisplayMode();
1702 const Standard_Integer anOldMode = theIObj->DisplayMode();
1703 if (myDisplayMode == anOldMode)
1708 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1709 aStatus->RemoveDisplayMode (anOldMode);
1710 if (!aStatus->IsDModeIn(myDisplayMode))
1712 aStatus->AddDisplayMode (myDisplayMode);
1715 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1717 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1719 myMainPM->Unhighlight (theIObj, anOldMode);
1721 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1722 myMainPM->Display (theIObj, myDisplayMode);
1724 Standard_Integer aDispMode, aHiMode, aSelMode;
1725 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1726 if (aStatus->IsHilighted())
1728 myMainPM->Highlight (theIObj, aHiMode);
1730 if (aStatus->IsSubIntensityOn())
1732 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1735 if (theToUpdateViewer)
1737 myMainVwr->Update();
1741 theIObj->UnsetDisplayMode();
1744 //=======================================================================
1745 //function : SetCurrentFacingModel
1747 //=======================================================================
1748 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1749 const Aspect_TypeOfFacingModel theModel)
1751 if (!theIObj.IsNull())
1753 theIObj->SetCurrentFacingModel (theModel);
1757 //=======================================================================
1758 //function : redisplayPrsRecModes
1760 //=======================================================================
1761 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1762 const Standard_Boolean theToUpdateViewer)
1764 if (theIObj->RecomputeEveryPrs())
1766 theIObj->Update (Standard_True);
1767 theIObj->UpdateSelection();
1771 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1773 theIObj->Update (aModes.Value(), Standard_False);
1775 theIObj->UpdateSelection();
1776 theIObj->SetRecomputeOk();
1779 if (theToUpdateViewer)
1781 UpdateCurrentViewer();
1785 //=======================================================================
1786 //function : redisplayPrsModes
1788 //=======================================================================
1789 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1790 const Standard_Boolean theToUpdateViewer)
1792 if (theIObj->RecomputeEveryPrs())
1794 theIObj->Update (Standard_True);
1795 theIObj->UpdateSelection();
1799 TColStd_ListOfInteger aModes;
1800 theIObj->ToBeUpdated (aModes);
1801 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1803 theIObj->Update (aModeIter.Value(), Standard_False);
1805 theIObj->SetRecomputeOk();
1808 if (theToUpdateViewer)
1810 UpdateCurrentViewer();
1814 //=======================================================================
1815 //function : SetColor
1817 //=======================================================================
1818 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1819 const Quantity_NameOfColor theColor,
1820 const Standard_Boolean theToUpdateViewer)
1822 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1825 //=======================================================================
1826 //function : SetColor
1828 //=======================================================================
1829 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1830 const Quantity_Color& theColor,
1831 const Standard_Boolean theToUpdateViewer)
1833 if (theIObj.IsNull())
1838 if (!theIObj->HasInteractiveContext())
1840 theIObj->SetContext (this);
1842 theIObj->SetColor (theColor);
1843 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1846 //=======================================================================
1847 //function : SetIsoOnTriangulation
1849 //=======================================================================
1850 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1851 const Handle(AIS_InteractiveObject)& theObject)
1853 if (theObject.IsNull())
1858 theObject->SetIsoOnTriangulation (theIsEnabled);
1861 //=======================================================================
1862 //function : SetDeviationCoefficient
1864 //=======================================================================
1865 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1866 const Standard_Real theCoefficient,
1867 const Standard_Boolean theToUpdateViewer)
1869 if (theIObj.IsNull())
1874 if (!theIObj->HasInteractiveContext())
1876 theIObj->SetContext (this);
1879 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1880 if (theIObj->Type() != AIS_KOI_Object
1881 && theIObj->Type() != AIS_KOI_Shape)
1885 else if (theIObj->Signature() != 0)
1890 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1891 aShape->SetOwnDeviationCoefficient (theCoefficient);
1892 redisplayPrsModes (theIObj, theToUpdateViewer);
1895 //=======================================================================
1896 //function : SetHLRDeviationCoefficient
1898 //=======================================================================
1899 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1900 const Standard_Real theCoefficient,
1901 const Standard_Boolean theToUpdateViewer)
1903 if (theIObj.IsNull())
1908 if (!theIObj->HasInteractiveContext())
1910 theIObj->SetContext (this);
1913 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1914 if (theIObj->Type() != AIS_KOI_Object
1915 && theIObj->Type() != AIS_KOI_Shape)
1919 else if (theIObj->Signature() != 0)
1924 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1925 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1926 redisplayPrsModes (theIObj, theToUpdateViewer);
1929 //=======================================================================
1930 //function : SetDeviationAngle
1932 //=======================================================================
1933 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1934 const Standard_Real theAngle,
1935 const Standard_Boolean theToUpdateViewer)
1937 if (theIObj.IsNull())
1942 if (!theIObj->HasInteractiveContext())
1944 theIObj->SetContext (this);
1947 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1948 if (theIObj->Type() != AIS_KOI_Shape)
1952 else if (theIObj->Signature() != 0)
1957 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1958 aShape->SetOwnDeviationAngle (theAngle);
1959 redisplayPrsModes (theIObj, theToUpdateViewer);
1962 //=======================================================================
1963 //function : SetAngleAndDeviation
1965 //=======================================================================
1966 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1967 const Standard_Real theAngle,
1968 const Standard_Boolean theToUpdateViewer)
1970 if (theIObj.IsNull())
1975 if (!theIObj->HasInteractiveContext())
1977 theIObj->SetContext (this);
1980 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1981 if (theIObj->Type() != AIS_KOI_Shape)
1985 if (theIObj->Signature() != 0)
1990 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1991 aShape->SetAngleAndDeviation (theAngle);
1993 if (theIObj->RecomputeEveryPrs())
1995 theIObj->Update (Standard_True);
1996 theIObj->UpdateSelection();
2000 Update (theIObj, theToUpdateViewer);
2004 //=======================================================================
2005 //function : SetHLRAngleAndDeviation
2007 //=======================================================================
2008 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
2009 const Standard_Real theAngle,
2010 const Standard_Boolean theToUpdateViewer)
2012 if (theIObj.IsNull())
2017 if (!theIObj->HasInteractiveContext())
2019 theIObj->SetContext (this);
2022 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2023 if (theIObj->Type() != AIS_KOI_Shape)
2027 if (theIObj->Signature() != 0)
2031 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2032 aShape->SetHLRAngleAndDeviation (theAngle);
2033 redisplayPrsModes (theIObj, theToUpdateViewer);
2036 //=======================================================================
2037 //function : SetHLRDeviationAngle
2039 //=======================================================================
2040 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2041 const Standard_Real theAngle,
2042 const Standard_Boolean theToUpdateViewer)
2044 if (theIObj.IsNull())
2049 if (!theIObj->HasInteractiveContext())
2051 theIObj->SetContext (this);
2054 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2055 if (theIObj->Type() != AIS_KOI_Shape)
2059 if (theIObj->Signature() != 0)
2063 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2064 aShape->SetOwnHLRDeviationAngle (theAngle);
2065 redisplayPrsModes (theIObj, theToUpdateViewer);
2068 //=======================================================================
2069 //function : UnsetColor
2071 //=======================================================================
2072 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2073 const Standard_Boolean theToUpdateViewer)
2075 if (theIObj.IsNull())
2080 theIObj->UnsetColor();
2081 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2084 //=======================================================================
2085 //function : HasColor
2087 //=======================================================================
2088 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2090 return theIObj->HasColor();
2093 //=======================================================================
2096 //=======================================================================
2097 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2099 return theIObj->Color();
2102 //=======================================================================
2105 //=======================================================================
2106 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2107 Quantity_Color& theColor) const
2109 theIObj->Color (theColor);
2112 //=======================================================================
2115 //=======================================================================
2116 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2118 return theIObj->Width();
2121 //=======================================================================
2122 //function : SetWidth
2124 //=======================================================================
2125 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2126 const Standard_Real theWidth,
2127 const Standard_Boolean theToUpdateViewer)
2129 if (theIObj.IsNull())
2134 if (!theIObj->HasInteractiveContext())
2136 theIObj->SetContext (this);
2139 theIObj->SetWidth (theWidth);
2140 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2141 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2143 if (myLastinMain->IsAutoHilight())
2145 const Standard_Integer aHiMode =
2146 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2147 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2151 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2156 //=======================================================================
2157 //function : UnsetWidth
2159 //=======================================================================
2160 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2161 const Standard_Boolean theToUpdateViewer)
2163 if (theIObj.IsNull())
2168 theIObj->UnsetWidth();
2169 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2172 //=======================================================================
2173 //function : SetMaterial
2175 //=======================================================================
2176 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2177 const Graphic3d_NameOfMaterial theName,
2178 const Standard_Boolean theToUpdateViewer)
2180 if (theIObj.IsNull())
2185 if (!theIObj->HasInteractiveContext())
2187 theIObj->SetContext (this);
2190 theIObj->SetMaterial (theName);
2191 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2194 //=======================================================================
2195 //function : UnsetMaterial
2197 //=======================================================================
2198 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2199 const Standard_Boolean theToUpdateViewer)
2201 if (theIObj.IsNull())
2205 theIObj->UnsetMaterial();
2206 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2209 //=======================================================================
2210 //function : SetTransparency
2212 //=======================================================================
2213 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2214 const Standard_Real theValue,
2215 const Standard_Boolean theToUpdateViewer)
2217 if (theIObj.IsNull())
2222 if (!theIObj->HasInteractiveContext())
2224 theIObj->SetContext (this);
2227 if (!theIObj->IsTransparent()
2228 && theValue <= 0.05)
2233 if (theValue <= 0.05)
2235 UnsetTransparency (theIObj, theToUpdateViewer);
2239 theIObj->SetTransparency (theValue);
2240 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2243 //=======================================================================
2244 //function : UnsetTransparency
2246 //=======================================================================
2247 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2248 const Standard_Boolean theToUpdateViewer)
2250 if (theIObj.IsNull())
2255 theIObj->UnsetTransparency();
2256 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2259 //=======================================================================
2260 //function : SetSelectedAspect
2262 //=======================================================================
2263 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2264 const Standard_Boolean theIsGlobalChange,
2265 const Standard_Boolean theToUpdateViewer)
2267 if (HasOpenedContext())
2272 Standard_Boolean isFound = Standard_False;
2273 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2274 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2276 isFound = Standard_True;
2277 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2278 anObj->SetAspect (theAspect, theIsGlobalChange);
2282 && theToUpdateViewer)
2284 myMainVwr->Update();
2288 //=======================================================================
2289 //function : SetLocalAttributes
2291 //=======================================================================
2292 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2293 const Handle(Prs3d_Drawer)& theDrawer,
2294 const Standard_Boolean theToUpdateViewer)
2296 if (theIObj.IsNull())
2301 if (!theIObj->HasInteractiveContext())
2303 theIObj->SetContext (this);
2306 theIObj->SetAttributes (theDrawer);
2307 Update (theIObj, theToUpdateViewer);
2310 //=======================================================================
2311 //function : UnsetLocalAttributes
2313 //=======================================================================
2314 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2315 const Standard_Boolean theToUpdateViewer)
2317 if (theIObj.IsNull())
2322 if (!theIObj->HasInteractiveContext())
2324 theIObj->SetContext (this);
2326 theIObj->UnsetAttributes();
2327 Update (theIObj, theToUpdateViewer);
2330 //=======================================================================
2333 //=======================================================================
2334 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2335 TCollection_ExtendedString& theStatus) const
2338 if (theIObj.IsNull()
2339 || !myObjects.IsBound (theIObj))
2344 theStatus += "\t ____________________________________________";
2345 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2346 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2347 switch (aStatus->GraphicStatus())
2349 case AIS_DS_Displayed:
2351 theStatus += "\t| -->Displayed\n";
2356 theStatus += "\t| -->Erased\n";
2363 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2364 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2366 theStatus += "\t|\t Mode ";
2367 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2370 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2372 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2373 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2375 theStatus += "\t\t Mode ";
2376 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2379 theStatus += "\t ____________________________________________";
2382 //=======================================================================
2383 //function : GetDefModes
2385 //=======================================================================
2386 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2387 Standard_Integer& theDispMode,
2388 Standard_Integer& theHiMode,
2389 Standard_Integer& theSelMode) const
2391 if (theIObj.IsNull())
2396 theDispMode = theIObj->HasDisplayMode()
2397 ? theIObj->DisplayMode()
2398 : (theIObj->AcceptDisplayMode (myDisplayMode)
2401 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2402 theSelMode = theIObj->GlobalSelectionMode();
2405 //=======================================================================
2406 //function : EraseGlobal
2408 //=======================================================================
2409 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2410 const Standard_Boolean theToUpdateviewer)
2412 if (theIObj.IsNull()
2413 || !myObjects.IsBound (theIObj))
2418 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2420 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2421 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2422 || aStatus->GraphicStatus() == AIS_DS_Erased)
2427 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2429 if (aStatus->IsHilighted())
2431 if (IsCurrent (theIObj))
2433 AddOrRemoveCurrentObject (theIObj, Standard_False);
2435 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2437 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2441 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2444 if (IsSelected (theIObj)
2445 && !aStatus->IsDModeIn (aDispMode))
2447 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2450 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2452 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2454 aStatus->ClearSelectionModes();
2455 aStatus->SetGraphicStatus (AIS_DS_Erased);
2457 if (theToUpdateviewer)
2459 myMainVwr->Update();
2463 //=======================================================================
2464 //function : unhighlightOwners
2466 //=======================================================================
2467 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2469 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
2471 while (aSel->More())
2473 const Handle(SelectMgr_EntityOwner) anOwner =
2474 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
2475 if (anOwner->Selectable() == theObject)
2477 if (anOwner->IsSelected())
2479 AddOrRemoveSelected (anOwner, Standard_False);
2488 //=======================================================================
2489 //function : ClearGlobal
2491 //=======================================================================
2492 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2493 const Standard_Boolean theToUpdateviewer)
2495 if (theIObj.IsNull()
2496 || !myObjects.IsBound (theIObj))
2498 // for cases when reference shape of connected interactives was not displayed
2499 // but its selection primitives were calculated
2500 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2501 mgrSelector->Remove (anObj);
2505 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2506 unhighlightOwners (theIObj);
2507 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2509 myMainPM->Erase (theIObj, aDispModeIter.Value());
2510 myMainPM->Clear (theIObj, aDispModeIter.Value());
2513 // Object removes from Detected sequence
2514 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2516 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2518 && anObj != theIObj)
2520 myAISDetectedSeq.Remove (aDetIter);
2524 // remove IO from the selection manager to avoid memory leaks
2525 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2526 mgrSelector->Remove (anObj);
2528 myObjects.UnBind (theIObj);
2529 myMainVwr->Viewer()->UnregisterObject (theIObj);
2530 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2532 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2535 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2536 myLastinMain.Nullify();
2537 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2538 myLastPicked.Nullify();
2539 myMainPM->ClearImmediateDraw();
2541 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2543 myMainVwr->Update();
2547 //=======================================================================
2548 //function : ClearGlobalPrs
2550 //=======================================================================
2551 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2552 const Standard_Integer theMode,
2553 const Standard_Boolean theToUpdateViewer)
2555 if (theIObj.IsNull()
2556 || !myObjects.IsBound (theIObj))
2561 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2562 if (aStatus->IsDModeIn (theMode))
2564 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2565 if (aDispMode == theMode
2566 && myMainPM->IsHighlighted (theIObj, theMode))
2568 myMainPM->Unhighlight (theIObj, theMode);
2571 myMainPM->Erase (theIObj, theMode);
2572 myMainPM->Clear (theIObj, theMode);
2575 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2576 && theToUpdateViewer)
2578 myMainVwr->Update();
2582 //=======================================================================
2583 //function : DrawHiddenLine
2585 //=======================================================================
2586 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2588 return myDefaultDrawer->DrawHiddenLine();
2591 //=======================================================================
2592 //function : EnableDrawHiddenLine
2594 //=======================================================================
2595 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2597 myDefaultDrawer->EnableDrawHiddenLine();
2600 //=======================================================================
2601 //function : DisableDrawHiddenLine
2603 //=======================================================================
2604 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2606 myDefaultDrawer->DisableDrawHiddenLine();
2609 //=======================================================================
2610 //function : HiddenLineAspect
2612 //=======================================================================
2613 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2615 return myDefaultDrawer->HiddenLineAspect();
2618 //=======================================================================
2619 //function : SetHiddenLineAspect
2621 //=======================================================================
2622 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2624 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2627 //=======================================================================
2628 //function : SetIsoNumber
2630 //=======================================================================
2631 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2632 const AIS_TypeOfIso theType)
2637 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2640 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2643 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2644 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2649 //=======================================================================
2650 //function : IsoNumber
2652 //=======================================================================
2653 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2657 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2658 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2659 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2660 ? myDefaultDrawer->UIsoAspect()->Number()
2666 //=======================================================================
2667 //function : IsoOnPlane
2669 //=======================================================================
2670 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2672 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2675 //=======================================================================
2676 //function : IsoOnPlane
2678 //=======================================================================
2679 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2681 return myDefaultDrawer->IsoOnPlane();
2684 //=======================================================================
2685 //function : IsoOnTriangulation
2687 //=======================================================================
2688 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2690 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2693 //=======================================================================
2694 //function : IsoOnTriangulation
2696 //=======================================================================
2697 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2699 return myDefaultDrawer->IsoOnTriangulation();
2702 //function : SetPixelTolerance
2703 //purpose : Disables the mechanism of adaptive tolerance calculation in
2704 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2705 // sensitive entities activated. For more information, see
2706 // SelectMgr_ViewerSelector.hxx
2707 //=======================================================================
2708 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2710 if (HasOpenedContext())
2712 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2716 myMainSel->SetPixelTolerance (thePrecision);
2720 //=======================================================================
2721 //function : PixelTolerance
2723 //=======================================================================
2724 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2726 return HasOpenedContext()
2727 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2728 : myMainSel->PixelTolerance();
2731 //=======================================================================
2732 //function : IsInLocal
2734 //=======================================================================
2735 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2736 Standard_Integer& theIndex) const
2738 if (theIObj.IsNull())
2740 return Standard_False;
2743 // if it exists at neutral point 0 index is returned
2744 if (myObjects.IsBound (theIObj))
2747 return Standard_False;
2750 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2752 if (myLocalContexts.IsBound (aCtxIter))
2754 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2756 theIndex = aCtxIter;
2757 return Standard_True;
2762 return Standard_False;
2765 //=======================================================================
2766 //function : InitAttributes
2768 //=======================================================================
2769 void AIS_InteractiveContext::InitAttributes()
2771 mgrSelector->Add (myMainSel);
2772 myCurrentName = AIS_Context_NewCurName();
2773 mySelectionName = AIS_Context_NewSelName();
2775 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2776 AIS_Selection::CreateSelection (myCurrentName.ToCString());
2778 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2779 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2780 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2782 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2783 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2784 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2785 aLineAspect->SetWidth (1.0);
2786 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2788 // tolerance to 2 pixels...
2789 SetPixelTolerance (2);
2791 // Customizing the drawer for trihedrons and planes...
2792 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2793 const Standard_Real aLength = 100.0;
2794 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2795 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2796 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2797 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2798 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2800 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2801 const Standard_Real aPlaneLength = 200.0;
2802 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2803 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2806 //=======================================================================
2807 //function : TrihedronSize
2809 //=======================================================================
2810 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2812 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2815 //=======================================================================
2816 //function : SetTrihedronSize
2818 //=======================================================================
2819 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2820 const Standard_Boolean /*updateviewer*/)
2822 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2823 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2824 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2827 //=======================================================================
2828 //function : SetPlaneSize
2830 //=======================================================================
2831 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2832 const Standard_Real theValY,
2833 const Standard_Boolean /*updateviewer*/)
2835 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2836 Redisplay (AIS_KOI_Datum, 7);
2839 //=======================================================================
2840 //function : SetPlaneSize
2842 //=======================================================================
2843 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2844 const Standard_Boolean theToUpdateViewer)
2846 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2849 //=======================================================================
2850 //function : PlaneSize
2852 //=======================================================================
2853 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2854 Standard_Real& theY) const
2856 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2857 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2858 return (Abs (theX - theY) <= Precision::Confusion());
2861 //=======================================================================
2862 //function : SetAutoActivateSelection
2864 //=======================================================================
2865 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2867 myIsAutoActivateSelMode = theIsAuto;
2870 //=======================================================================
2871 //function : GetAutoActivateSelection
2873 //=======================================================================
2874 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2876 return myIsAutoActivateSelMode;
2879 //=======================================================================
2880 //function : SetZLayer
2882 //=======================================================================
2883 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2884 const Standard_Integer theLayerId)
2886 if (theIObj.IsNull())
2889 theIObj->SetZLayer (theLayerId);
2892 //=======================================================================
2893 //function : GetZLayer
2895 //=======================================================================
2896 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2898 return !theIObj.IsNull()
2900 : Graphic3d_ZLayerId_UNKNOWN;
2903 //=======================================================================
2904 //function : RebuildSelectionStructs
2905 //purpose : Rebuilds 1st level of BVH selection forcibly
2906 //=======================================================================
2907 void AIS_InteractiveContext::RebuildSelectionStructs()
2909 myMainSel->RebuildObjectsTree (Standard_True);
2912 //=======================================================================
2913 //function : Disconnect
2914 //purpose : Disconnects selectable object from an assembly and updates selection structures
2915 //=======================================================================
2916 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2917 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2919 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2921 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2922 theObj->Disconnect (theObjToDisconnect);
2923 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2924 mgrSelector->Remove (anObj);
2926 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2928 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2929 theObj->Disconnect();
2930 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2931 mgrSelector->Remove (anObj);
2937 //=======================================================================
2938 //function : FitSelected
2939 //purpose : Fits the view corresponding to the bounds of selected objects
2940 //=======================================================================
2941 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2942 const Standard_Real theMargin,
2943 const Standard_Boolean theToUpdate)
2945 Standard_CString aSelName = HasOpenedContext() ?
2946 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2947 : myCurrentName.ToCString();
2949 Bnd_Box aBndSelected;
2951 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2952 AIS_MapOfObjectOwners anObjectOwnerMap;
2953 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2955 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2956 if (!anObj.IsNull())
2958 if (anObj->IsInfinite())
2962 anObj->BoundingBox (aTmpBnd);
2963 aBndSelected.Add (aTmpBnd);
2967 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2968 if (anOwner.IsNull())
2971 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2972 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2974 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2975 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2978 anOwnerMap->Add (anOwner);
2982 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2984 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2985 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2986 aBndSelected.Add (aTmpBox);
2989 anObjectOwnerMap.Clear();
2991 if (aBndSelected.IsVoid())
2994 theView->FitAll (aBndSelected, theMargin, theToUpdate);