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>
65 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext,MMgt_TShared)
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->StructureManager())),
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 Handle(Graphic3d_CView) aViewImpl = theView->View();
357 const Standard_Integer aViewId = aViewImpl->Identification();
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->StructureManager()->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->StructureManager()->ObjectAffinity (theIObj);
410 Handle(Graphic3d_CView) aViewImpl = theView->View();
411 anAffinity->SetVisible (aViewImpl->Identification(), 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->StructureManager()->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());
729 while (aSelIter->More())
731 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelIter->Value());
732 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
734 Erase (anObj, Standard_False);
735 isFound = Standard_True;
740 if (isFound && theToUpdateViewer)
746 //=======================================================================
749 //=======================================================================
751 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
752 const Standard_Integer WhichContext)
754 if(anIObj.IsNull()) return Standard_False;
756 if(!HasOpenedContext()) return Standard_False;
757 if(myObjects.IsBound(anIObj)) return Standard_False;
758 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
760 // Protection : if one tries to preserve a temporary object
761 // which is not in the local active context... rob 11-06-97
763 Standard_Integer IsItInLocal = myCurLocalIndex;
764 Standard_Boolean Found(Standard_False);
766 while(IsItInLocal>0 && !Found){
767 if(!myLocalContexts.IsBound(IsItInLocal))
769 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
770 Found = Standard_True;
775 if(!Found) return Standard_False;
778 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
779 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
781 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
782 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
786 if(LS->IsTemporary()){
787 Standard_Integer DM,HM,SM;
788 GetDefModes(anIObj,DM,HM,SM);
790 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
791 if(LS->DisplayMode()!= DM ){
792 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
793 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
796 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
800 // GS->SubIntensityOn();
801 myObjects.Bind(anIObj,GS);
802 mgrSelector->Load(anIObj);
803 mgrSelector->Activate(anIObj,SM,myMainSel);
805 LS->SetTemporary(Standard_False);
807 return Standard_True;
810 //=======================================================================
811 //function : DisplayStatus
813 //=======================================================================
814 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
816 if (theIObj.IsNull())
820 else if (myObjects.IsBound (theIObj))
822 return myObjects (theIObj)->GraphicStatus();
825 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
827 if (aCtxIter.Value()->IsIn (theIObj))
829 return AIS_DS_Temporary;
835 //=======================================================================
836 //function : DisplayedModes
838 //=======================================================================
839 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
841 return myObjects (theIObj)->DisplayedModes();
844 //=======================================================================
847 //=======================================================================
848 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
849 const Standard_Boolean theToUpdateViewer)
851 if (theIObj.IsNull())
856 if (HasOpenedContext())
858 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
859 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
861 if (aCtxIter.Value()->AcceptErase())
863 aCtxIter.Value()->Remove (theIObj);
868 ClearGlobal (theIObj, theToUpdateViewer);
871 //=======================================================================
872 //function : RemoveAll
874 //=======================================================================
875 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
877 AIS_ListOfInteractive aList;
878 ObjectsInside (aList);
879 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
881 Remove (aListIterator.Value(), Standard_False);
884 if (theToUpdateViewer)
890 //=======================================================================
891 //function : ClearPrs
893 //=======================================================================
894 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
895 const Standard_Integer theMode,
896 const Standard_Boolean theToUpdateViewer)
898 if (theIObj.IsNull())
903 if (!HasOpenedContext())
905 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
909 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
910 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
912 if (aCtxIter.Value()->AcceptErase())
914 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
919 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
921 else if (theToUpdateViewer)
927 //=======================================================================
930 //=======================================================================
931 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
932 const Standard_Boolean theToUpdateViewer)
934 if (theIObj.IsNull())
939 if (!theIObj->HasInteractiveContext())
941 theIObj->SetContext (this);
943 if (!HasOpenedContext())
945 if (!myObjects.IsBound (theIObj))
950 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
951 aStatus->SetHilightStatus (Standard_True);
952 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
954 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
955 myMainPM->Highlight (theIObj, aHilightMode);
960 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
963 if (theToUpdateViewer)
968 //=======================================================================
971 //=======================================================================
973 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
974 const Quantity_NameOfColor aCol,
975 const Standard_Boolean updateviewer)
977 if(anIObj.IsNull()) return;
979 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
981 if (!HasOpenedContext())
983 if(!myObjects.IsBound(anIObj)) return;
985 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
986 aStatus->SetHilightStatus (Standard_True);
988 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
990 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
991 myMainPM->Color (anIObj, aCol, aHilightMode);
992 aStatus->SetHilightColor (aCol);
997 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
999 if(updateviewer) myMainVwr->Update();
1002 //=======================================================================
1003 //function : Unhilight
1005 //=======================================================================
1007 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
1009 if(anIObj.IsNull()) return;
1011 if (!HasOpenedContext())
1013 if(!myObjects.IsBound(anIObj)) return;
1015 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
1016 aStatus->SetHilightStatus (Standard_False);
1017 aStatus->SetHilightColor(Quantity_NOC_WHITE);
1019 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1021 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
1022 myMainPM->Unhighlight (anIObj, aHilightMode);
1027 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1029 if(updateviewer) myMainVwr->Update();
1032 //=======================================================================
1033 //function : IsHilighted
1035 //=======================================================================
1037 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1039 if(anIObj.IsNull()) return Standard_False;
1041 if (!HasOpenedContext()){
1042 if(!myObjects.IsBound(anIObj))
1043 return Standard_False;
1044 return myObjects(anIObj)->IsHilighted();
1046 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1047 for(;ItM.More();ItM.Next()){
1048 if(ItM.Value()->IsHilighted(anIObj))
1049 return Standard_True;
1051 return Standard_False;
1054 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1055 Standard_Boolean& WithColor,
1056 Quantity_NameOfColor& TheHiCol) const
1058 if(!HasOpenedContext()){
1059 if(myObjects.IsBound(anIObj)){
1060 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1061 if(STAT->IsHilighted()){
1062 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1063 WithColor=Standard_True;
1064 TheHiCol = STAT->HilightColor();
1067 WithColor = Standard_False;
1068 return Standard_True;
1071 return Standard_False;
1073 Standard_Integer MaxIndex = HighestIndex();
1074 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1075 if(myLocalContexts.IsBound(i)){
1076 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1077 return Standard_True;
1081 return Standard_False;
1084 //=======================================================================
1085 //function : IsHilighted
1086 //purpose : Returns true if the objects global status is set to highlighted.
1087 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1088 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1089 // custom highlight color name will be stored to theCustomColorName
1090 //=======================================================================
1091 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1092 Standard_Boolean& theIsCustomColor,
1093 Quantity_NameOfColor& theCustomColorName) const
1095 if (theOwner.IsNull() || !theOwner->HasSelectable())
1096 return Standard_False;
1098 const Handle(AIS_InteractiveObject) anObj =
1099 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1101 if (!myObjects.IsBound (anObj))
1102 return Standard_False;
1104 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1105 if (anObjStatus->IsHilighted())
1107 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1109 theIsCustomColor = Standard_True;
1110 theCustomColorName = anObjStatus->HilightColor();
1114 theIsCustomColor = Standard_False;
1117 return Standard_True;
1120 return Standard_False;
1123 //=======================================================================
1124 //function : IsDisplayed
1126 //=======================================================================
1128 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1130 if(anIObj.IsNull()) return Standard_False;
1133 if(myObjects.IsBound(anIObj))
1134 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1135 return Standard_True;
1137 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1138 for(;ItM.More();ItM.Next()){
1139 if(ItM.Value()->IsDisplayed(anIObj))
1140 return Standard_True;
1142 return Standard_False;
1146 //=======================================================================
1147 //function : IsDisplayed
1149 //=======================================================================
1150 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1151 const Standard_Integer theMode) const
1153 if (theIObj.IsNull())
1155 return Standard_False;
1158 if (myObjects.IsBound (theIObj))
1160 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1161 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1162 && aStatus->IsDModeIn (theMode))
1164 return Standard_True;
1168 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1170 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1172 return Standard_True;
1175 return Standard_False;
1178 //=======================================================================
1179 //function : DisplayPriority
1181 //=======================================================================
1182 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1184 if (theIObj.IsNull())
1188 else if (!myObjects.IsBound (theIObj))
1193 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1194 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1195 || aStatus->GraphicStatus() == AIS_DS_Erased)
1197 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1198 ? theIObj->DisplayMode()
1199 : (theIObj->AcceptDisplayMode (myDisplayMode)
1202 return myMainPM->DisplayPriority (theIObj, aDispMode);
1207 //=======================================================================
1208 //function : SetDisplayPriority
1210 //=======================================================================
1211 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1212 const Standard_Integer thePriority)
1214 if (theIObj.IsNull())
1219 if (!theIObj->HasInteractiveContext())
1221 theIObj->SetContext (this);
1224 if (myObjects.IsBound (theIObj))
1226 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1227 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1228 || aStatus->GraphicStatus() == AIS_DS_Erased)
1230 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1231 ? theIObj->DisplayMode()
1232 : (theIObj->AcceptDisplayMode (myDisplayMode)
1235 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1238 else if (HasOpenedContext())
1240 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1244 //=======================================================================
1245 //function : Redisplay
1247 //=======================================================================
1248 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1249 const Standard_Boolean theToUpdateViewer,
1250 const Standard_Boolean theAllModes)
1252 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1253 RecomputeSelectionOnly (theIObj);
1256 //=======================================================================
1257 //function : Redisplay
1259 //=======================================================================
1260 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1261 const Standard_Integer /*theSign*/,
1262 const Standard_Boolean theToUpdateViewer)
1264 Standard_Boolean isRedisplayed = Standard_False;
1265 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1267 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1268 if (anObj->Type() != theKOI)
1273 Redisplay (anObj, Standard_False);
1274 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1278 if (theToUpdateViewer
1281 myMainVwr->Update();
1285 //=======================================================================
1286 //function : RecomputePrsOnly
1288 //=======================================================================
1289 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1290 const Standard_Boolean theToUpdateViewer,
1291 const Standard_Boolean theAllModes)
1293 if (theIObj.IsNull())
1298 theIObj->Update (theAllModes);
1299 if (!theToUpdateViewer)
1304 if (HasOpenedContext()
1305 || (myObjects.IsBound (theIObj)
1306 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1308 myMainVwr->Update();
1311 //=======================================================================
1312 //function : RecomputeSelectionOnly
1314 //=======================================================================
1315 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1322 mgrSelector->RecomputeSelection (theIO);
1324 if (HasOpenedContext())
1326 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1328 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1333 if (!myObjects.IsBound (theIO) ||
1334 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1339 TColStd_ListOfInteger aModes;
1340 ActivatedModes (theIO, aModes);
1341 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1342 for (; aModesIter.More(); aModesIter.Next())
1344 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1348 //=======================================================================
1351 //=======================================================================
1352 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1353 const Standard_Boolean theUpdateViewer)
1355 if (theIObj.IsNull())
1360 TColStd_ListOfInteger aPrsModes;
1361 theIObj->ToBeUpdated (aPrsModes);
1362 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1364 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1367 mgrSelector->Update(theIObj);
1369 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1371 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1374 if (theUpdateViewer)
1376 if (!myObjects.IsBound (theIObj))
1381 switch (myObjects (theIObj)->GraphicStatus())
1383 case AIS_DS_Displayed:
1384 case AIS_DS_Temporary:
1385 myMainVwr->Update();
1393 //=======================================================================
1394 //function : SetLocation
1396 //=======================================================================
1397 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1398 const TopLoc_Location& theLoc)
1400 if (theIObj.IsNull())
1405 if (theIObj->HasTransformation()
1406 && theLoc.IsIdentity())
1408 theIObj->ResetTransformation();
1409 mgrSelector->Update (theIObj, Standard_False);
1412 else if (theLoc.IsIdentity())
1417 // first reset the previous location to properly clean everything...
1418 if (theIObj->HasTransformation())
1420 theIObj->ResetTransformation();
1423 theIObj->SetLocalTransformation (theLoc.Transformation());
1425 if (!HasOpenedContext())
1427 mgrSelector->Update (theIObj, Standard_False);
1431 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1432 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1435 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1436 // to its highlight structure immediately
1437 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
1439 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1441 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1445 //=======================================================================
1446 //function : ResetLocation
1448 //=======================================================================
1449 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1451 if (theIObj.IsNull())
1456 theIObj->ResetTransformation();
1457 mgrSelector->Update (theIObj, Standard_False);
1460 //=======================================================================
1461 //function : HasLocation
1463 //=======================================================================
1464 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1466 return !theIObj.IsNull()
1467 && theIObj->HasTransformation();
1470 //=======================================================================
1471 //function : Location
1473 //=======================================================================
1474 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1476 return theIObj->Transformation();
1479 //=======================================================================
1480 //function : SetDeviationCoefficient
1482 //=======================================================================
1483 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1485 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1488 //=======================================================================
1489 //function : SetDeviationAngle
1491 //=======================================================================
1492 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1494 myDefaultDrawer->SetDeviationAngle (theAngle);
1497 //=======================================================================
1498 //function : DeviationAngle
1499 //purpose : Gets deviationAngle
1500 //=======================================================================
1501 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1503 return myDefaultDrawer->DeviationAngle();
1506 //=======================================================================
1507 //function : DeviationCoefficient
1509 //=======================================================================
1510 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1512 return myDefaultDrawer->DeviationCoefficient();
1515 //=======================================================================
1516 //function : SetHLRDeviationCoefficient
1518 //=======================================================================
1519 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1521 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1524 //=======================================================================
1525 //function : HLRDeviationCoefficient
1527 //=======================================================================
1528 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1530 return myDefaultDrawer->HLRDeviationCoefficient();
1533 //=======================================================================
1534 //function : SetHLRAngle
1536 //=======================================================================
1537 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1539 myDefaultDrawer->SetHLRAngle (theAngle);
1542 //=======================================================================
1543 //function : SetHLRAngleAndDeviation
1544 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1545 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1546 // of myDefaultDrawer
1547 //=======================================================================
1548 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1550 Standard_Real anOutAngl, anOutDefl;
1551 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1553 myDefaultDrawer->SetHLRAngle (anOutAngl);
1554 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1557 //=======================================================================
1558 //function : HLRAngle
1560 //=======================================================================
1561 Standard_Real AIS_InteractiveContext::HLRAngle() const
1563 return myDefaultDrawer->HLRAngle();
1566 //=======================================================================
1567 //function : SetDisplayMode
1569 //=======================================================================
1570 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1571 const Standard_Boolean theToUpdateViewer)
1573 if (theMode == myDisplayMode)
1578 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1580 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1581 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1582 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1583 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1586 || anObj->HasDisplayMode()
1587 || !anObj->AcceptDisplayMode (theMode))
1592 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1593 if (aStatus->IsDModeIn (myDisplayMode))
1595 aStatus->RemoveDisplayMode (myDisplayMode);
1598 aStatus->AddDisplayMode (theMode);
1599 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1601 myMainPM->Display (anObj, theMode);
1602 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1604 myMainPM->BeginImmediateDraw();
1605 myMainPM->Unhighlight (anObj, myDisplayMode);
1606 myMainPM->EndImmediateDraw (myMainVwr);
1608 if (aStatus->IsSubIntensityOn())
1610 myMainPM->Color (anObj, mySubIntensity, theMode);
1612 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1616 myDisplayMode = theMode;
1617 if (theToUpdateViewer)
1619 myMainVwr->Update();
1623 //=======================================================================
1624 //function : SetDisplayMode
1626 //=======================================================================
1627 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1628 const Standard_Integer theMode,
1629 const Standard_Boolean theToUpdateViewer)
1631 if (!theIObj->HasInteractiveContext())
1633 theIObj->SetContext(this);
1636 if (!myObjects.IsBound (theIObj))
1638 theIObj->SetDisplayMode (theMode);
1641 else if (!theIObj->AcceptDisplayMode (theMode))
1646 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1647 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1649 theIObj->SetDisplayMode (theMode);
1653 // erase presentations for all display modes different from <aMode>
1654 TColStd_ListOfInteger aModesToRemove;
1655 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1657 const Standard_Integer anOldMode = aDispModeIter.Value();
1658 if (anOldMode != theMode)
1660 aModesToRemove.Append (anOldMode);
1661 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1663 myMainPM->Unhighlight (theIObj, anOldMode);
1665 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1669 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1671 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1674 if (!aStatus->IsDModeIn (theMode))
1676 aStatus->AddDisplayMode (theMode);
1679 myMainPM->Display (theIObj, theMode);
1680 Standard_Integer aDispMode, aHiMode, aSelMode;
1681 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1682 if (aStatus->IsHilighted())
1684 myMainPM->Highlight (theIObj, aHiMode);
1686 if (aStatus->IsSubIntensityOn())
1688 myMainPM->Color (theIObj, mySubIntensity, theMode);
1691 if (theToUpdateViewer)
1693 myMainVwr->Update();
1695 theIObj->SetDisplayMode (theMode);
1698 //=======================================================================
1699 //function : UnsetDisplayMode
1701 //=======================================================================
1702 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1703 const Standard_Boolean theToUpdateViewer)
1705 if (theIObj.IsNull()
1706 || !theIObj->HasDisplayMode())
1711 if (!myObjects.IsBound (theIObj))
1713 theIObj->UnsetDisplayMode();
1717 const Standard_Integer anOldMode = theIObj->DisplayMode();
1718 if (myDisplayMode == anOldMode)
1723 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1724 aStatus->RemoveDisplayMode (anOldMode);
1725 if (!aStatus->IsDModeIn(myDisplayMode))
1727 aStatus->AddDisplayMode (myDisplayMode);
1730 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1732 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1734 myMainPM->Unhighlight (theIObj, anOldMode);
1736 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1737 myMainPM->Display (theIObj, myDisplayMode);
1739 Standard_Integer aDispMode, aHiMode, aSelMode;
1740 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1741 if (aStatus->IsHilighted())
1743 myMainPM->Highlight (theIObj, aHiMode);
1745 if (aStatus->IsSubIntensityOn())
1747 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1750 if (theToUpdateViewer)
1752 myMainVwr->Update();
1756 theIObj->UnsetDisplayMode();
1759 //=======================================================================
1760 //function : SetCurrentFacingModel
1762 //=======================================================================
1763 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1764 const Aspect_TypeOfFacingModel theModel)
1766 if (!theIObj.IsNull())
1768 theIObj->SetCurrentFacingModel (theModel);
1772 //=======================================================================
1773 //function : redisplayPrsRecModes
1775 //=======================================================================
1776 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1777 const Standard_Boolean theToUpdateViewer)
1779 if (theIObj->RecomputeEveryPrs())
1781 theIObj->Update (Standard_True);
1782 theIObj->UpdateSelection();
1786 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1788 theIObj->Update (aModes.Value(), Standard_False);
1790 theIObj->UpdateSelection();
1791 theIObj->SetRecomputeOk();
1794 if (theToUpdateViewer)
1796 UpdateCurrentViewer();
1800 //=======================================================================
1801 //function : redisplayPrsModes
1803 //=======================================================================
1804 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1805 const Standard_Boolean theToUpdateViewer)
1807 if (theIObj->RecomputeEveryPrs())
1809 theIObj->Update (Standard_True);
1810 theIObj->UpdateSelection();
1814 TColStd_ListOfInteger aModes;
1815 theIObj->ToBeUpdated (aModes);
1816 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1818 theIObj->Update (aModeIter.Value(), Standard_False);
1820 theIObj->SetRecomputeOk();
1823 if (theToUpdateViewer)
1825 UpdateCurrentViewer();
1829 //=======================================================================
1830 //function : SetColor
1832 //=======================================================================
1833 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1834 const Quantity_NameOfColor theColor,
1835 const Standard_Boolean theToUpdateViewer)
1837 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1840 //=======================================================================
1841 //function : SetColor
1843 //=======================================================================
1844 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1845 const Quantity_Color& theColor,
1846 const Standard_Boolean theToUpdateViewer)
1848 if (theIObj.IsNull())
1853 if (!theIObj->HasInteractiveContext())
1855 theIObj->SetContext (this);
1857 theIObj->SetColor (theColor);
1858 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1861 //=======================================================================
1862 //function : SetIsoOnTriangulation
1864 //=======================================================================
1865 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1866 const Handle(AIS_InteractiveObject)& theObject)
1868 if (theObject.IsNull())
1873 theObject->SetIsoOnTriangulation (theIsEnabled);
1876 //=======================================================================
1877 //function : SetDeviationCoefficient
1879 //=======================================================================
1880 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1881 const Standard_Real theCoefficient,
1882 const Standard_Boolean theToUpdateViewer)
1884 if (theIObj.IsNull())
1889 if (!theIObj->HasInteractiveContext())
1891 theIObj->SetContext (this);
1894 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1895 if (theIObj->Type() != AIS_KOI_Object
1896 && theIObj->Type() != AIS_KOI_Shape)
1900 else if (theIObj->Signature() != 0)
1905 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1906 aShape->SetOwnDeviationCoefficient (theCoefficient);
1907 redisplayPrsModes (theIObj, theToUpdateViewer);
1910 //=======================================================================
1911 //function : SetHLRDeviationCoefficient
1913 //=======================================================================
1914 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1915 const Standard_Real theCoefficient,
1916 const Standard_Boolean theToUpdateViewer)
1918 if (theIObj.IsNull())
1923 if (!theIObj->HasInteractiveContext())
1925 theIObj->SetContext (this);
1928 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1929 if (theIObj->Type() != AIS_KOI_Object
1930 && theIObj->Type() != AIS_KOI_Shape)
1934 else if (theIObj->Signature() != 0)
1939 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1940 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1941 redisplayPrsModes (theIObj, theToUpdateViewer);
1944 //=======================================================================
1945 //function : SetDeviationAngle
1947 //=======================================================================
1948 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1949 const Standard_Real theAngle,
1950 const Standard_Boolean theToUpdateViewer)
1952 if (theIObj.IsNull())
1957 if (!theIObj->HasInteractiveContext())
1959 theIObj->SetContext (this);
1962 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1963 if (theIObj->Type() != AIS_KOI_Shape)
1967 else if (theIObj->Signature() != 0)
1972 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1973 aShape->SetOwnDeviationAngle (theAngle);
1974 redisplayPrsModes (theIObj, theToUpdateViewer);
1977 //=======================================================================
1978 //function : SetAngleAndDeviation
1980 //=======================================================================
1981 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1982 const Standard_Real theAngle,
1983 const Standard_Boolean theToUpdateViewer)
1985 if (theIObj.IsNull())
1990 if (!theIObj->HasInteractiveContext())
1992 theIObj->SetContext (this);
1995 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1996 if (theIObj->Type() != AIS_KOI_Shape)
2000 if (theIObj->Signature() != 0)
2005 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2006 aShape->SetAngleAndDeviation (theAngle);
2008 if (theIObj->RecomputeEveryPrs())
2010 theIObj->Update (Standard_True);
2011 theIObj->UpdateSelection();
2015 Update (theIObj, theToUpdateViewer);
2019 //=======================================================================
2020 //function : SetHLRAngleAndDeviation
2022 //=======================================================================
2023 void AIS_InteractiveContext::SetHLRAngleAndDeviation (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->SetHLRAngleAndDeviation (theAngle);
2048 redisplayPrsModes (theIObj, theToUpdateViewer);
2051 //=======================================================================
2052 //function : SetHLRDeviationAngle
2054 //=======================================================================
2055 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2056 const Standard_Real theAngle,
2057 const Standard_Boolean theToUpdateViewer)
2059 if (theIObj.IsNull())
2064 if (!theIObj->HasInteractiveContext())
2066 theIObj->SetContext (this);
2069 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2070 if (theIObj->Type() != AIS_KOI_Shape)
2074 if (theIObj->Signature() != 0)
2078 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2079 aShape->SetOwnHLRDeviationAngle (theAngle);
2080 redisplayPrsModes (theIObj, theToUpdateViewer);
2083 //=======================================================================
2084 //function : UnsetColor
2086 //=======================================================================
2087 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2088 const Standard_Boolean theToUpdateViewer)
2090 if (theIObj.IsNull())
2095 theIObj->UnsetColor();
2096 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2099 //=======================================================================
2100 //function : HasColor
2102 //=======================================================================
2103 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2105 return theIObj->HasColor();
2108 //=======================================================================
2111 //=======================================================================
2112 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2114 return theIObj->Color();
2117 //=======================================================================
2120 //=======================================================================
2121 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2122 Quantity_Color& theColor) const
2124 theIObj->Color (theColor);
2127 //=======================================================================
2130 //=======================================================================
2131 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2133 return theIObj->Width();
2136 //=======================================================================
2137 //function : SetWidth
2139 //=======================================================================
2140 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2141 const Standard_Real theWidth,
2142 const Standard_Boolean theToUpdateViewer)
2144 if (theIObj.IsNull())
2149 if (!theIObj->HasInteractiveContext())
2151 theIObj->SetContext (this);
2154 theIObj->SetWidth (theWidth);
2155 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2156 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2158 if (myLastinMain->IsAutoHilight())
2160 const Standard_Integer aHiMode =
2161 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2162 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2166 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2171 //=======================================================================
2172 //function : UnsetWidth
2174 //=======================================================================
2175 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2176 const Standard_Boolean theToUpdateViewer)
2178 if (theIObj.IsNull())
2183 theIObj->UnsetWidth();
2184 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2187 //=======================================================================
2188 //function : SetMaterial
2190 //=======================================================================
2191 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2192 const Graphic3d_NameOfMaterial theName,
2193 const Standard_Boolean theToUpdateViewer)
2195 if (theIObj.IsNull())
2200 if (!theIObj->HasInteractiveContext())
2202 theIObj->SetContext (this);
2205 theIObj->SetMaterial (theName);
2206 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2209 //=======================================================================
2210 //function : UnsetMaterial
2212 //=======================================================================
2213 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2214 const Standard_Boolean theToUpdateViewer)
2216 if (theIObj.IsNull())
2220 theIObj->UnsetMaterial();
2221 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2224 //=======================================================================
2225 //function : SetTransparency
2227 //=======================================================================
2228 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2229 const Standard_Real theValue,
2230 const Standard_Boolean theToUpdateViewer)
2232 if (theIObj.IsNull())
2237 if (!theIObj->HasInteractiveContext())
2239 theIObj->SetContext (this);
2242 if (!theIObj->IsTransparent()
2243 && theValue <= 0.05)
2248 if (theValue <= 0.05)
2250 UnsetTransparency (theIObj, theToUpdateViewer);
2254 theIObj->SetTransparency (theValue);
2255 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2258 //=======================================================================
2259 //function : UnsetTransparency
2261 //=======================================================================
2262 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2263 const Standard_Boolean theToUpdateViewer)
2265 if (theIObj.IsNull())
2270 theIObj->UnsetTransparency();
2271 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2274 //=======================================================================
2275 //function : SetSelectedAspect
2277 //=======================================================================
2278 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2279 const Standard_Boolean theIsGlobalChange,
2280 const Standard_Boolean theToUpdateViewer)
2282 if (HasOpenedContext())
2287 Standard_Boolean isFound = Standard_False;
2288 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2289 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2291 isFound = Standard_True;
2292 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2293 anObj->SetAspect (theAspect, theIsGlobalChange);
2297 && theToUpdateViewer)
2299 myMainVwr->Update();
2303 //=======================================================================
2304 //function : SetLocalAttributes
2306 //=======================================================================
2307 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2308 const Handle(Prs3d_Drawer)& theDrawer,
2309 const Standard_Boolean theToUpdateViewer)
2311 if (theIObj.IsNull())
2316 if (!theIObj->HasInteractiveContext())
2318 theIObj->SetContext (this);
2321 theIObj->SetAttributes (theDrawer);
2322 Update (theIObj, theToUpdateViewer);
2325 //=======================================================================
2326 //function : UnsetLocalAttributes
2328 //=======================================================================
2329 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2330 const Standard_Boolean theToUpdateViewer)
2332 if (theIObj.IsNull())
2337 if (!theIObj->HasInteractiveContext())
2339 theIObj->SetContext (this);
2341 theIObj->UnsetAttributes();
2342 Update (theIObj, theToUpdateViewer);
2345 //=======================================================================
2348 //=======================================================================
2349 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2350 TCollection_ExtendedString& theStatus) const
2353 if (theIObj.IsNull()
2354 || !myObjects.IsBound (theIObj))
2359 theStatus += "\t ____________________________________________";
2360 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2361 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2362 switch (aStatus->GraphicStatus())
2364 case AIS_DS_Displayed:
2366 theStatus += "\t| -->Displayed\n";
2371 theStatus += "\t| -->Erased\n";
2378 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2379 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2381 theStatus += "\t|\t Mode ";
2382 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2385 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2387 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2388 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2390 theStatus += "\t\t Mode ";
2391 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2394 theStatus += "\t ____________________________________________";
2397 //=======================================================================
2398 //function : GetDefModes
2400 //=======================================================================
2401 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2402 Standard_Integer& theDispMode,
2403 Standard_Integer& theHiMode,
2404 Standard_Integer& theSelMode) const
2406 if (theIObj.IsNull())
2411 theDispMode = theIObj->HasDisplayMode()
2412 ? theIObj->DisplayMode()
2413 : (theIObj->AcceptDisplayMode (myDisplayMode)
2416 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2417 theSelMode = theIObj->GlobalSelectionMode();
2420 //=======================================================================
2421 //function : EraseGlobal
2423 //=======================================================================
2424 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2425 const Standard_Boolean theToUpdateviewer)
2427 if (theIObj.IsNull()
2428 || !myObjects.IsBound (theIObj))
2433 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2435 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2436 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2437 || aStatus->GraphicStatus() == AIS_DS_Erased)
2442 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2444 if (aStatus->IsHilighted())
2446 if (IsCurrent (theIObj))
2448 AddOrRemoveCurrentObject (theIObj, Standard_False);
2450 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2452 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2456 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2459 if (IsSelected (theIObj)
2460 && !aStatus->IsDModeIn (aDispMode))
2462 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2465 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2467 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2469 aStatus->ClearSelectionModes();
2470 aStatus->SetGraphicStatus (AIS_DS_Erased);
2472 if (theToUpdateviewer)
2474 myMainVwr->Update();
2478 //=======================================================================
2479 //function : unhighlightOwners
2481 //=======================================================================
2482 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2484 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
2486 while (aSel->More())
2488 const Handle(SelectMgr_EntityOwner) anOwner =
2489 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
2490 if (anOwner->Selectable() == theObject)
2492 if (anOwner->IsSelected())
2494 AddOrRemoveSelected (anOwner, Standard_False);
2503 //=======================================================================
2504 //function : ClearGlobal
2506 //=======================================================================
2507 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2508 const Standard_Boolean theToUpdateviewer)
2510 if (theIObj.IsNull()
2511 || !myObjects.IsBound (theIObj))
2513 // for cases when reference shape of connected interactives was not displayed
2514 // but its selection primitives were calculated
2515 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2516 mgrSelector->Remove (anObj);
2520 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2521 unhighlightOwners (theIObj);
2522 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2524 myMainPM->Erase (theIObj, aDispModeIter.Value());
2525 myMainPM->Clear (theIObj, aDispModeIter.Value());
2528 // Object removes from Detected sequence
2529 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2531 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2533 && anObj != theIObj)
2535 myAISDetectedSeq.Remove (aDetIter);
2539 // remove IO from the selection manager to avoid memory leaks
2540 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2541 mgrSelector->Remove (anObj);
2543 myObjects.UnBind (theIObj);
2544 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2545 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2547 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2550 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2551 myLastinMain.Nullify();
2552 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2553 myLastPicked.Nullify();
2554 myMainPM->ClearImmediateDraw();
2556 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2558 myMainVwr->Update();
2562 //=======================================================================
2563 //function : ClearGlobalPrs
2565 //=======================================================================
2566 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2567 const Standard_Integer theMode,
2568 const Standard_Boolean theToUpdateViewer)
2570 if (theIObj.IsNull()
2571 || !myObjects.IsBound (theIObj))
2576 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2577 if (aStatus->IsDModeIn (theMode))
2579 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2580 if (aDispMode == theMode
2581 && myMainPM->IsHighlighted (theIObj, theMode))
2583 myMainPM->Unhighlight (theIObj, theMode);
2586 myMainPM->Erase (theIObj, theMode);
2587 myMainPM->Clear (theIObj, theMode);
2590 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2591 && theToUpdateViewer)
2593 myMainVwr->Update();
2597 //=======================================================================
2598 //function : DrawHiddenLine
2600 //=======================================================================
2601 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2603 return myDefaultDrawer->DrawHiddenLine();
2606 //=======================================================================
2607 //function : EnableDrawHiddenLine
2609 //=======================================================================
2610 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2612 myDefaultDrawer->EnableDrawHiddenLine();
2615 //=======================================================================
2616 //function : DisableDrawHiddenLine
2618 //=======================================================================
2619 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2621 myDefaultDrawer->DisableDrawHiddenLine();
2624 //=======================================================================
2625 //function : HiddenLineAspect
2627 //=======================================================================
2628 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2630 return myDefaultDrawer->HiddenLineAspect();
2633 //=======================================================================
2634 //function : SetHiddenLineAspect
2636 //=======================================================================
2637 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2639 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2642 //=======================================================================
2643 //function : SetIsoNumber
2645 //=======================================================================
2646 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2647 const AIS_TypeOfIso theType)
2652 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2655 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2658 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2659 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2664 //=======================================================================
2665 //function : IsoNumber
2667 //=======================================================================
2668 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2672 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2673 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2674 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2675 ? myDefaultDrawer->UIsoAspect()->Number()
2681 //=======================================================================
2682 //function : IsoOnPlane
2684 //=======================================================================
2685 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2687 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2690 //=======================================================================
2691 //function : IsoOnPlane
2693 //=======================================================================
2694 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2696 return myDefaultDrawer->IsoOnPlane();
2699 //=======================================================================
2700 //function : IsoOnTriangulation
2702 //=======================================================================
2703 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2705 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2708 //=======================================================================
2709 //function : IsoOnTriangulation
2711 //=======================================================================
2712 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2714 return myDefaultDrawer->IsoOnTriangulation();
2717 //function : SetPixelTolerance
2718 //purpose : Disables the mechanism of adaptive tolerance calculation in
2719 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2720 // sensitive entities activated. For more information, see
2721 // SelectMgr_ViewerSelector.hxx
2722 //=======================================================================
2723 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2725 if (HasOpenedContext())
2727 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2731 myMainSel->SetPixelTolerance (thePrecision);
2735 //=======================================================================
2736 //function : PixelTolerance
2738 //=======================================================================
2739 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2741 return HasOpenedContext()
2742 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2743 : myMainSel->PixelTolerance();
2746 //=======================================================================
2747 //function : SetSelectionSensitivity
2748 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2749 //=======================================================================
2750 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2751 const Standard_Integer theMode,
2752 const Standard_Integer theNewSensitivity)
2754 if (HasOpenedContext())
2756 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2760 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2763 //=======================================================================
2764 //function : IsInLocal
2766 //=======================================================================
2767 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2768 Standard_Integer& theIndex) const
2770 if (theIObj.IsNull())
2772 return Standard_False;
2775 // if it exists at neutral point 0 index is returned
2776 if (myObjects.IsBound (theIObj))
2779 return Standard_False;
2782 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2784 if (myLocalContexts.IsBound (aCtxIter))
2786 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2788 theIndex = aCtxIter;
2789 return Standard_True;
2794 return Standard_False;
2797 //=======================================================================
2798 //function : InitAttributes
2800 //=======================================================================
2801 void AIS_InteractiveContext::InitAttributes()
2803 mgrSelector->Add (myMainSel);
2804 myCurrentName = AIS_Context_NewCurName();
2805 mySelectionName = AIS_Context_NewSelName();
2807 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2808 AIS_Selection::CreateSelection (myCurrentName.ToCString());
2810 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2811 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2812 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2814 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2815 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2816 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2817 aLineAspect->SetWidth (1.0);
2818 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2820 // tolerance to 2 pixels...
2821 SetPixelTolerance (2);
2823 // Customizing the drawer for trihedrons and planes...
2824 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2825 const Standard_Real aLength = 100.0;
2826 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2827 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2828 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2829 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2830 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2832 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2833 const Standard_Real aPlaneLength = 200.0;
2834 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2835 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2838 //=======================================================================
2839 //function : TrihedronSize
2841 //=======================================================================
2842 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2844 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2847 //=======================================================================
2848 //function : SetTrihedronSize
2850 //=======================================================================
2851 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2852 const Standard_Boolean /*updateviewer*/)
2854 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2855 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2856 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2859 //=======================================================================
2860 //function : SetPlaneSize
2862 //=======================================================================
2863 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2864 const Standard_Real theValY,
2865 const Standard_Boolean /*updateviewer*/)
2867 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2868 Redisplay (AIS_KOI_Datum, 7);
2871 //=======================================================================
2872 //function : SetPlaneSize
2874 //=======================================================================
2875 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2876 const Standard_Boolean theToUpdateViewer)
2878 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2881 //=======================================================================
2882 //function : PlaneSize
2884 //=======================================================================
2885 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2886 Standard_Real& theY) const
2888 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2889 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2890 return (Abs (theX - theY) <= Precision::Confusion());
2893 //=======================================================================
2894 //function : SetAutoActivateSelection
2896 //=======================================================================
2897 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2899 myIsAutoActivateSelMode = theIsAuto;
2902 //=======================================================================
2903 //function : GetAutoActivateSelection
2905 //=======================================================================
2906 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2908 return myIsAutoActivateSelMode;
2911 //=======================================================================
2912 //function : SetZLayer
2914 //=======================================================================
2915 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2916 const Standard_Integer theLayerId)
2918 if (theIObj.IsNull())
2921 theIObj->SetZLayer (theLayerId);
2924 //=======================================================================
2925 //function : GetZLayer
2927 //=======================================================================
2928 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2930 return !theIObj.IsNull()
2932 : Graphic3d_ZLayerId_UNKNOWN;
2935 //=======================================================================
2936 //function : RebuildSelectionStructs
2937 //purpose : Rebuilds 1st level of BVH selection forcibly
2938 //=======================================================================
2939 void AIS_InteractiveContext::RebuildSelectionStructs()
2941 myMainSel->RebuildObjectsTree (Standard_True);
2944 //=======================================================================
2945 //function : Disconnect
2946 //purpose : Disconnects selectable object from an assembly and updates selection structures
2947 //=======================================================================
2948 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2949 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2951 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2953 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2954 theObj->Disconnect (theObjToDisconnect);
2955 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2956 mgrSelector->Remove (anObj);
2958 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2960 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2961 theObj->Disconnect();
2962 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2963 mgrSelector->Remove (anObj);
2969 //=======================================================================
2970 //function : FitSelected
2971 //purpose : Fits the view corresponding to the bounds of selected objects
2972 //=======================================================================
2973 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2974 const Standard_Real theMargin,
2975 const Standard_Boolean theToUpdate)
2977 Standard_CString aSelName = HasOpenedContext() ?
2978 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2979 : myCurrentName.ToCString();
2981 Bnd_Box aBndSelected;
2983 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2984 AIS_MapOfObjectOwners anObjectOwnerMap;
2985 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2987 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2988 if (!anObj.IsNull())
2990 if (anObj->IsInfinite())
2994 anObj->BoundingBox (aTmpBnd);
2995 aBndSelected.Add (aTmpBnd);
2999 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
3000 if (anOwner.IsNull())
3003 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
3004 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
3006 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
3007 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
3010 anOwnerMap->Add (anOwner);
3014 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
3016 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
3017 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
3018 aBndSelected.Add (aTmpBox);
3021 anObjectOwnerMap.Clear();
3023 if (aBndSelected.IsVoid())
3026 theView->FitAll (aBndSelected, theMargin, theToUpdate);