1 // Created on: 1997-01-17
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by XAB & Serguei Dec 97 (angle &deviation coeffts)
19 #include <AIS_ConnectedInteractive.hxx>
20 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
21 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
22 #include <AIS_GlobalStatus.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <AIS_LocalContext.hxx>
27 #include <AIS_LocalStatus.hxx>
28 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
29 #include <AIS_MultipleConnectedInteractive.hxx>
30 #include <AIS_Shape.hxx>
31 #include <AIS_Trihedron.hxx>
32 #include <Geom_Axis2Placement.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <HLRBRep.hxx>
35 #include <OSD_Environment.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_BasicAspect.hxx>
38 #include <Prs3d_DatumAspect.hxx>
39 #include <Prs3d_IsoAspect.hxx>
40 #include <Prs3d_LineAspect.hxx>
41 #include <Prs3d_PlaneAspect.hxx>
42 #include <Prs3d_ShadingAspect.hxx>
43 #include <PrsMgr_ModedPresentation.hxx>
44 #include <PrsMgr_PresentableObject.hxx>
45 #include <Quantity_Color.hxx>
46 #include <SelectMgr_EntityOwner.hxx>
47 #include <SelectMgr_Filter.hxx>
48 #include <SelectMgr_OrFilter.hxx>
49 #include <SelectMgr_SelectionManager.hxx>
50 #include <Standard_Atomic.hxx>
51 #include <Standard_Transient.hxx>
52 #include <Standard_Type.hxx>
53 #include <StdSelect_ViewerSelector3d.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <TCollection_ExtendedString.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
58 #include <TopLoc_Location.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <UnitsAPI.hxx>
61 #include <V3d_View.hxx>
62 #include <V3d_Viewer.hxx>
64 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext,MMgt_TShared)
66 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
69 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
70 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
73 //=======================================================================
74 //function : AIS_InteractiveContext
76 //=======================================================================
78 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
79 mgrSelector(new SelectMgr_SelectionManager()),
80 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
81 myMainVwr(MainViewer),
82 myMainSel(new StdSelect_ViewerSelector3d()),
83 myWasLastMain(Standard_False),
84 myCurrentTouched(Standard_False),
85 mySelectedTouched(Standard_False),
86 myToHilightSelected(Standard_True),
87 myFilters(new SelectMgr_OrFilter()),
88 myDefaultDrawer(new Prs3d_Drawer()),
89 mySelection(new AIS_Selection()),
90 myDefaultColor(Quantity_NOC_GOLDENROD),
91 myHilightColor(Quantity_NOC_CYAN1),
92 mySelectionColor(Quantity_NOC_GRAY80),
93 myPreselectionColor(Quantity_NOC_GREEN),
94 mySubIntensity(Quantity_NOC_GRAY40),
99 myIsAutoActivateSelMode(Standard_True)
104 void AIS_InteractiveContext::Delete() const
106 // clear the current selection
107 mySelection->Clear();
109 // let's remove one reference explicitly. this operation's supposed to
110 // be performed when mgrSelector will be destroyed but anyway...
111 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
112 mgrSelector->Remove (aSelector);
114 Handle(AIS_InteractiveContext) aNullContext;
115 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
117 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
118 anObj->SetContext (aNullContext);
119 for (anObj->Init(); anObj->More(); anObj->Next())
121 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
124 MMgt_TShared::Delete();
127 //=======================================================================
128 //function : UpdateCurrentViewer
130 //=======================================================================
132 void AIS_InteractiveContext::UpdateCurrentViewer()
134 if (!myMainVwr.IsNull())
138 //=======================================================================
139 //function : DisplayedObjects
141 //=======================================================================
142 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
143 const Standard_Boolean theOnlyFromNeutral) const
145 if (!HasOpenedContext()
146 || theOnlyFromNeutral)
148 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
150 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
152 theListOfIO.Append (anObjIter.Key());
159 TColStd_MapOfTransient aDispMap;
160 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
162 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
164 aDispMap.Add (anObjIter.Key());
168 // parse all local contexts...
169 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
171 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
172 aLocCtx->DisplayedObjects (aDispMap);
175 Handle(AIS_InteractiveObject) anObj;
176 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
178 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
179 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
180 theListOfIO.Append (anObj);
184 //=======================================================================
185 //function : DisplayedObjects
187 //=======================================================================
188 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
189 const Standard_Integer theSign,
190 AIS_ListOfInteractive& theListOfIO,
191 const Standard_Boolean /*OnlyFromNeutral*/) const
193 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
196 //=======================================================================
197 //function : ErasedObjects
199 //=======================================================================
200 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
202 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
205 //=======================================================================
206 //function : ErasedObjects
208 //=======================================================================
209 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
210 const Standard_Integer theSign,
211 AIS_ListOfInteractive& theListOfIO) const
213 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
216 //=======================================================================
217 //function : ObjectsByDisplayStatus
219 //=======================================================================
220 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
221 AIS_ListOfInteractive& theListOfIO) const
223 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
225 if (anObjIter.Value()->GraphicStatus() == theStatus)
227 theListOfIO.Append (anObjIter.Key());
232 //=======================================================================
233 //function : ObjectsByDisplayStatus
235 //=======================================================================
236 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
237 const Standard_Integer theSign,
238 const AIS_DisplayStatus theStatus,
239 AIS_ListOfInteractive& theListOfIO) const
241 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
243 if (theStatus != AIS_DS_None
244 && anObjIter.Value()->GraphicStatus() != theStatus)
248 else if (anObjIter.Key()->Type() != theKind)
254 || anObjIter.Key()->Signature() == theSign)
256 theListOfIO.Append (anObjIter.Key());
261 //=======================================================================
262 //function : ObjectsInside
264 //=======================================================================
265 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
266 const AIS_KindOfInteractive theKind,
267 const Standard_Integer theSign) const
269 if (theKind == AIS_KOI_None
272 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
274 theListOfIO.Append (anObjIter.Key());
279 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
281 if (anObjIter.Key()->Type() != theKind)
287 || anObjIter.Key()->Signature() == theSign)
289 theListOfIO.Append (anObjIter.Key());
294 //=======================================================================
295 //function : ObjectsForView
297 //=======================================================================
298 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
299 const Handle(V3d_View)& theView,
300 const Standard_Boolean theIsVisibleInView,
301 const AIS_DisplayStatus theStatus) const
303 Handle(Graphic3d_CView) aViewImpl = theView->View();
304 const Standard_Integer aViewId = aViewImpl->Identification();
305 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
307 if (theStatus != AIS_DS_None
308 && anObjIter.Value()->GraphicStatus() != theStatus)
310 theListOfIO.Append (anObjIter.Key());
314 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
315 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
316 if (isVisible == theIsVisibleInView)
318 theListOfIO.Append (anObjIter.Key());
323 //=======================================================================
326 //=======================================================================
327 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
328 const Standard_Boolean theToUpdateViewer)
330 if (theIObj.IsNull())
335 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
336 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
338 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
339 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
342 //=======================================================================
343 //function : SetViewAffinity
345 //=======================================================================
346 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
347 const Handle(V3d_View)& theView,
348 const Standard_Boolean theIsVisible)
351 || !myObjects.IsBound (theIObj))
356 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
357 Handle(Graphic3d_CView) aViewImpl = theView->View();
358 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
361 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
365 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
369 //=======================================================================
372 //=======================================================================
373 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
374 const Standard_Integer theDispMode,
375 const Standard_Integer theSelectionMode,
376 const Standard_Boolean theToUpdateViewer,
377 const Standard_Boolean theToAllowDecomposition,
378 const AIS_DisplayStatus theDispStatus)
380 if (theIObj.IsNull())
385 if (theDispStatus == AIS_DS_Erased)
387 Erase (theIObj, theToUpdateViewer);
388 Load (theIObj, theSelectionMode, theToAllowDecomposition);
392 if (!theIObj->HasInteractiveContext())
394 theIObj->SetContext (this);
397 if (theDispStatus == AIS_DS_Temporary
398 && !HasOpenedContext())
402 else if (HasOpenedContext())
404 if (theDispStatus == AIS_DS_None
405 || theDispStatus == AIS_DS_Temporary)
407 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
408 if (theToUpdateViewer)
416 if (!myObjects.IsBound (theIObj))
418 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
419 myObjects.Bind (theIObj, aStatus);
420 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
421 myMainPM->Display(theIObj, theDispMode);
422 if (theSelectionMode != -1)
424 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
425 if (!mgrSelector->Contains (anObj))
427 mgrSelector->Load (theIObj);
429 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
434 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
435 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
440 // Mark the presentation modes hidden of interactive object different from aDispMode.
441 // Then make sure aDispMode is displayed and maybe highlighted.
442 // Finally, activate selection mode <SelMode> if not yet activated.
443 const Standard_Integer anOldMode = aStatus->DisplayMode();
444 if (anOldMode != theDispMode)
446 if(myMainPM->IsHighlighted (theIObj, anOldMode))
448 myMainPM->Unhighlight (theIObj, anOldMode);
450 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
453 aStatus->SetDisplayMode (theDispMode);
455 myMainPM->Display (theIObj, theDispMode);
456 aStatus->SetGraphicStatus (AIS_DS_Displayed);
457 if (aStatus->IsHilighted())
459 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
460 myMainPM->Color (theIObj, aStatus->HilightColor(), aHiMod);
462 if (theSelectionMode != -1)
464 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
465 if (!mgrSelector->Contains (anObj))
467 mgrSelector->Load (theIObj);
469 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
471 if (!aStatus->IsSModeIn (theSelectionMode))
472 aStatus->AddSelectionMode (theSelectionMode);
473 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
478 if (theToUpdateViewer)
484 //=======================================================================
487 //=======================================================================
488 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
489 const Standard_Integer theSelMode,
490 const Standard_Boolean theToAllowDecomposition)
492 if (theIObj.IsNull())
497 if (!theIObj->HasInteractiveContext())
499 theIObj->SetContext (this);
502 if (HasOpenedContext())
504 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
509 && !theToAllowDecomposition)
511 if (!myObjects.IsBound (theIObj))
513 Standard_Integer aDispMode, aHiMod, aSelModeDef;
514 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
515 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
516 myObjects.Bind (theIObj, aStatus);
519 // Register theIObj in the selection manager to prepare further activation of selection
520 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
521 if (!mgrSelector->Contains (anObj))
523 mgrSelector->Load (theIObj);
528 //=======================================================================
531 //=======================================================================
532 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
533 const Standard_Boolean theToUpdateViewer)
535 if (theIObj.IsNull())
540 if (!theIObj->IsAutoHilight())
542 theIObj->ClearSelected();
545 Standard_Boolean wasInCtx = Standard_False;
546 if (HasOpenedContext())
548 // First it is checked if it is possible to remove in the current local context
549 // then one tries to remove in other local contexts, if they allow it...
550 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
551 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
553 if (aCtxIter.Value()->AcceptErase())
555 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
562 EraseGlobal (theIObj, Standard_False);
565 if (theToUpdateViewer)
571 //=======================================================================
572 //function : EraseAll
574 //=======================================================================
575 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
577 if (HasOpenedContext())
582 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
584 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
586 Erase (anObjIter.Key(), Standard_False);
590 if (theToUpdateViewer)
596 //=======================================================================
597 //function : DisplayAll
599 //=======================================================================
600 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
602 if (HasOpenedContext())
607 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
609 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
610 if (aStatus == AIS_DS_Erased)
612 Display (anObjIter.Key(), Standard_False);
616 if (theToUpdateViewer)
622 //=======================================================================
623 //function : DisplaySelected
625 //=======================================================================
626 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
628 if (HasOpenedContext())
633 Standard_Boolean isFound = Standard_False;
634 for (mySelection->Init(); mySelection->More(); mySelection->Next())
636 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value()->Selectable());
637 Display (anObj, Standard_False);
638 isFound = Standard_True;
641 if (isFound && theToUpdateViewer)
647 //=======================================================================
648 //function : EraseSelected
650 //=======================================================================
651 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
653 if (HasOpenedContext())
658 Standard_Boolean isFound = Standard_False;
660 while (mySelection->More())
662 Handle(SelectMgr_EntityOwner) anOwner = mySelection->Value();
663 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
665 Erase (anObj, Standard_False);
666 isFound = Standard_True;
671 if (isFound && theToUpdateViewer)
677 //=======================================================================
680 //=======================================================================
682 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
683 const Standard_Integer WhichContext)
685 if(anIObj.IsNull()) return Standard_False;
687 if(!HasOpenedContext()) return Standard_False;
688 if(myObjects.IsBound(anIObj)) return Standard_False;
689 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
691 // Protection : if one tries to preserve a temporary object
692 // which is not in the local active context... rob 11-06-97
694 Standard_Integer IsItInLocal = myCurLocalIndex;
695 Standard_Boolean Found(Standard_False);
697 while(IsItInLocal>0 && !Found){
698 if(!myLocalContexts.IsBound(IsItInLocal))
700 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
701 Found = Standard_True;
706 if(!Found) return Standard_False;
709 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
710 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
712 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
713 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
717 if(LS->IsTemporary()){
718 Standard_Integer DM,HM,SM;
719 GetDefModes(anIObj,DM,HM,SM);
721 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
722 if(LS->DisplayMode()!= DM ){
723 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
724 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
727 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
731 // GS->SubIntensityOn();
732 myObjects.Bind(anIObj,GS);
733 mgrSelector->Load(anIObj);
734 mgrSelector->Activate(anIObj,SM,myMainSel);
736 LS->SetTemporary(Standard_False);
738 return Standard_True;
741 //=======================================================================
742 //function : DisplayStatus
744 //=======================================================================
745 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
747 if (theIObj.IsNull())
751 else if (myObjects.IsBound (theIObj))
753 return myObjects (theIObj)->GraphicStatus();
756 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
758 if (aCtxIter.Value()->IsIn (theIObj))
760 return AIS_DS_Temporary;
766 //=======================================================================
769 //=======================================================================
770 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
771 const Standard_Boolean theToUpdateViewer)
773 if (theIObj.IsNull())
778 if (HasOpenedContext())
780 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
781 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
783 if (aCtxIter.Value()->AcceptErase())
785 aCtxIter.Value()->Remove (theIObj);
790 ClearGlobal (theIObj, theToUpdateViewer);
793 //=======================================================================
794 //function : RemoveAll
796 //=======================================================================
797 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
799 AIS_ListOfInteractive aList;
800 ObjectsInside (aList);
801 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
803 Remove (aListIterator.Value(), Standard_False);
806 if (theToUpdateViewer)
812 //=======================================================================
813 //function : ClearPrs
815 //=======================================================================
816 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
817 const Standard_Integer theMode,
818 const Standard_Boolean theToUpdateViewer)
820 if (theIObj.IsNull())
825 if (!HasOpenedContext())
827 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
831 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
832 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
834 if (aCtxIter.Value()->AcceptErase())
836 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
841 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
843 else if (theToUpdateViewer)
849 //=======================================================================
852 //=======================================================================
853 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
854 const Standard_Boolean theToUpdateViewer)
856 if (theIObj.IsNull())
861 if (!theIObj->HasInteractiveContext())
863 theIObj->SetContext (this);
865 if (!HasOpenedContext())
867 if (!myObjects.IsBound (theIObj))
872 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
873 aStatus->SetHilightStatus (Standard_True);
874 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
876 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
877 myMainPM->Highlight (theIObj, aHilightMode);
882 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
885 if (theToUpdateViewer)
890 //=======================================================================
893 //=======================================================================
895 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
896 const Quantity_NameOfColor aCol,
897 const Standard_Boolean updateviewer)
899 if(anIObj.IsNull()) return;
901 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
903 if (!HasOpenedContext())
905 if(!myObjects.IsBound(anIObj)) return;
907 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
908 aStatus->SetHilightStatus (Standard_True);
910 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
912 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
913 myMainPM->Color (anIObj, aCol, aHilightMode);
914 aStatus->SetHilightColor (aCol);
919 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
921 if(updateviewer) myMainVwr->Update();
924 //=======================================================================
925 //function : Unhilight
927 //=======================================================================
929 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
931 if(anIObj.IsNull()) return;
933 if (!HasOpenedContext())
935 if(!myObjects.IsBound(anIObj)) return;
937 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
938 aStatus->SetHilightStatus (Standard_False);
939 aStatus->SetHilightColor(Quantity_NOC_WHITE);
941 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
943 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
944 myMainPM->Unhighlight (anIObj, aHilightMode);
949 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
951 if(updateviewer) myMainVwr->Update();
954 //=======================================================================
955 //function : IsHilighted
957 //=======================================================================
959 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
961 if(anIObj.IsNull()) return Standard_False;
963 if (!HasOpenedContext()){
964 if(!myObjects.IsBound(anIObj))
965 return Standard_False;
966 return myObjects(anIObj)->IsHilighted();
968 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
969 for(;ItM.More();ItM.Next()){
970 if(ItM.Value()->IsHilighted(anIObj))
971 return Standard_True;
973 return Standard_False;
976 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
977 Standard_Boolean& WithColor,
978 Quantity_NameOfColor& TheHiCol) const
980 if(!HasOpenedContext()){
981 if(myObjects.IsBound(anIObj)){
982 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
983 if(STAT->IsHilighted()){
984 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
985 WithColor=Standard_True;
986 TheHiCol = STAT->HilightColor();
989 WithColor = Standard_False;
990 return Standard_True;
993 return Standard_False;
995 Standard_Integer MaxIndex = HighestIndex();
996 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
997 if(myLocalContexts.IsBound(i)){
998 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
999 return Standard_True;
1003 return Standard_False;
1006 //=======================================================================
1007 //function : IsHilighted
1008 //purpose : Returns true if the objects global status is set to highlighted.
1009 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1010 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1011 // custom highlight color name will be stored to theCustomColorName
1012 //=======================================================================
1013 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1014 Standard_Boolean& theIsCustomColor,
1015 Quantity_NameOfColor& theCustomColorName) const
1017 if (theOwner.IsNull() || !theOwner->HasSelectable())
1018 return Standard_False;
1020 const Handle(AIS_InteractiveObject) anObj =
1021 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1023 if (!myObjects.IsBound (anObj))
1024 return Standard_False;
1026 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1027 if (anObjStatus->IsHilighted())
1029 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1031 theIsCustomColor = Standard_True;
1032 theCustomColorName = anObjStatus->HilightColor();
1036 theIsCustomColor = Standard_False;
1039 return Standard_True;
1042 return Standard_False;
1045 //=======================================================================
1046 //function : IsDisplayed
1048 //=======================================================================
1050 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1052 if(anIObj.IsNull()) return Standard_False;
1055 if(myObjects.IsBound(anIObj))
1056 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1057 return Standard_True;
1059 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1060 for(;ItM.More();ItM.Next()){
1061 if(ItM.Value()->IsDisplayed(anIObj))
1062 return Standard_True;
1064 return Standard_False;
1068 //=======================================================================
1069 //function : IsDisplayed
1071 //=======================================================================
1072 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1073 const Standard_Integer theMode) const
1075 if (theIObj.IsNull())
1077 return Standard_False;
1080 if (myObjects.IsBound (theIObj))
1082 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1083 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1084 && theIObj->DisplayMode() == theMode)
1086 return Standard_True;
1090 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1092 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1094 return Standard_True;
1097 return Standard_False;
1100 //=======================================================================
1101 //function : DisplayPriority
1103 //=======================================================================
1104 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1106 if (theIObj.IsNull())
1110 else if (!myObjects.IsBound (theIObj))
1115 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1116 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1117 || aStatus->GraphicStatus() == AIS_DS_Erased)
1119 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1120 ? theIObj->DisplayMode()
1121 : (theIObj->AcceptDisplayMode (myDisplayMode)
1124 return myMainPM->DisplayPriority (theIObj, aDispMode);
1129 //=======================================================================
1130 //function : SetDisplayPriority
1132 //=======================================================================
1133 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1134 const Standard_Integer thePriority)
1136 if (theIObj.IsNull())
1141 if (!theIObj->HasInteractiveContext())
1143 theIObj->SetContext (this);
1146 if (myObjects.IsBound (theIObj))
1148 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1149 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1150 || aStatus->GraphicStatus() == AIS_DS_Erased)
1152 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1153 ? theIObj->DisplayMode()
1154 : (theIObj->AcceptDisplayMode (myDisplayMode)
1157 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1160 else if (HasOpenedContext())
1162 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1166 //=======================================================================
1167 //function : Redisplay
1169 //=======================================================================
1170 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1171 const Standard_Boolean theToUpdateViewer,
1172 const Standard_Boolean theAllModes)
1174 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1175 RecomputeSelectionOnly (theIObj);
1178 //=======================================================================
1179 //function : Redisplay
1181 //=======================================================================
1182 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1183 const Standard_Integer /*theSign*/,
1184 const Standard_Boolean theToUpdateViewer)
1186 Standard_Boolean isRedisplayed = Standard_False;
1187 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1189 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1190 if (anObj->Type() != theKOI)
1195 Redisplay (anObj, Standard_False);
1196 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1200 if (theToUpdateViewer
1203 myMainVwr->Update();
1207 //=======================================================================
1208 //function : RecomputePrsOnly
1210 //=======================================================================
1211 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1212 const Standard_Boolean theToUpdateViewer,
1213 const Standard_Boolean theAllModes)
1215 if (theIObj.IsNull())
1220 theIObj->Update (theAllModes);
1221 if (!theToUpdateViewer)
1226 if (HasOpenedContext()
1227 || (myObjects.IsBound (theIObj)
1228 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1230 myMainVwr->Update();
1233 //=======================================================================
1234 //function : RecomputeSelectionOnly
1236 //=======================================================================
1237 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1244 mgrSelector->RecomputeSelection (theIO);
1246 if (HasOpenedContext())
1248 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1250 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1255 if (!myObjects.IsBound (theIO) ||
1256 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1261 TColStd_ListOfInteger aModes;
1262 ActivatedModes (theIO, aModes);
1263 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1264 for (; aModesIter.More(); aModesIter.Next())
1266 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1270 //=======================================================================
1273 //=======================================================================
1274 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1275 const Standard_Boolean theUpdateViewer)
1277 if (theIObj.IsNull())
1282 TColStd_ListOfInteger aPrsModes;
1283 theIObj->ToBeUpdated (aPrsModes);
1284 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1286 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1289 mgrSelector->Update(theIObj);
1291 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1293 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1296 if (theUpdateViewer)
1298 if (!myObjects.IsBound (theIObj))
1303 switch (myObjects (theIObj)->GraphicStatus())
1305 case AIS_DS_Displayed:
1306 case AIS_DS_Temporary:
1307 myMainVwr->Update();
1315 //=======================================================================
1316 //function : SetLocation
1318 //=======================================================================
1319 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1320 const TopLoc_Location& theLoc)
1322 if (theIObj.IsNull())
1327 if (theIObj->HasTransformation()
1328 && theLoc.IsIdentity())
1330 theIObj->ResetTransformation();
1331 mgrSelector->Update (theIObj, Standard_False);
1334 else if (theLoc.IsIdentity())
1339 // first reset the previous location to properly clean everything...
1340 if (theIObj->HasTransformation())
1342 theIObj->ResetTransformation();
1345 theIObj->SetLocalTransformation (theLoc.Transformation());
1347 if (!HasOpenedContext())
1349 mgrSelector->Update (theIObj, Standard_False);
1353 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1354 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1357 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1358 // to its highlight structure immediately
1359 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
1361 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1363 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1367 //=======================================================================
1368 //function : ResetLocation
1370 //=======================================================================
1371 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1373 if (theIObj.IsNull())
1378 theIObj->ResetTransformation();
1379 mgrSelector->Update (theIObj, Standard_False);
1382 //=======================================================================
1383 //function : HasLocation
1385 //=======================================================================
1386 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1388 return !theIObj.IsNull()
1389 && theIObj->HasTransformation();
1392 //=======================================================================
1393 //function : Location
1395 //=======================================================================
1396 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1398 return theIObj->Transformation();
1401 //=======================================================================
1402 //function : SetDeviationCoefficient
1404 //=======================================================================
1405 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1407 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1410 //=======================================================================
1411 //function : SetDeviationAngle
1413 //=======================================================================
1414 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1416 myDefaultDrawer->SetDeviationAngle (theAngle);
1419 //=======================================================================
1420 //function : DeviationAngle
1421 //purpose : Gets deviationAngle
1422 //=======================================================================
1423 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1425 return myDefaultDrawer->DeviationAngle();
1428 //=======================================================================
1429 //function : DeviationCoefficient
1431 //=======================================================================
1432 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1434 return myDefaultDrawer->DeviationCoefficient();
1437 //=======================================================================
1438 //function : SetHLRDeviationCoefficient
1440 //=======================================================================
1441 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1443 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1446 //=======================================================================
1447 //function : HLRDeviationCoefficient
1449 //=======================================================================
1450 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1452 return myDefaultDrawer->HLRDeviationCoefficient();
1455 //=======================================================================
1456 //function : SetHLRAngle
1458 //=======================================================================
1459 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1461 myDefaultDrawer->SetHLRAngle (theAngle);
1464 //=======================================================================
1465 //function : SetHLRAngleAndDeviation
1466 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1467 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1468 // of myDefaultDrawer
1469 //=======================================================================
1470 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1472 Standard_Real anOutAngl, anOutDefl;
1473 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1475 myDefaultDrawer->SetHLRAngle (anOutAngl);
1476 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1479 //=======================================================================
1480 //function : HLRAngle
1482 //=======================================================================
1483 Standard_Real AIS_InteractiveContext::HLRAngle() const
1485 return myDefaultDrawer->HLRAngle();
1488 //=======================================================================
1489 //function : SetDisplayMode
1491 //=======================================================================
1492 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1493 const Standard_Boolean theToUpdateViewer)
1495 if (theMode == myDisplayMode)
1500 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1502 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1503 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1504 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1505 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1508 || anObj->HasDisplayMode()
1509 || !anObj->AcceptDisplayMode (theMode))
1514 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1515 aStatus->SetDisplayMode (theMode);
1517 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1519 myMainPM->Display (anObj, theMode);
1520 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1522 myMainPM->BeginImmediateDraw();
1523 myMainPM->Unhighlight (anObj, myDisplayMode);
1524 myMainPM->EndImmediateDraw (myMainVwr);
1526 if (aStatus->IsSubIntensityOn())
1528 myMainPM->Color (anObj, mySubIntensity, theMode);
1530 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1534 myDisplayMode = theMode;
1535 if (theToUpdateViewer)
1537 myMainVwr->Update();
1541 //=======================================================================
1542 //function : SetDisplayMode
1544 //=======================================================================
1545 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1546 const Standard_Integer theMode,
1547 const Standard_Boolean theToUpdateViewer)
1549 if (!theIObj->HasInteractiveContext())
1551 theIObj->SetContext(this);
1554 if (!myObjects.IsBound (theIObj))
1556 theIObj->SetDisplayMode (theMode);
1559 else if (!theIObj->AcceptDisplayMode (theMode))
1564 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1565 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1567 theIObj->SetDisplayMode (theMode);
1571 // erase presentations for all display modes different from <aMode>
1572 const Standard_Integer anOldMode = aStatus->DisplayMode();
1573 if (anOldMode != theMode)
1575 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1577 myMainPM->Unhighlight (theIObj, anOldMode);
1579 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1582 aStatus->SetDisplayMode (theMode);
1584 myMainPM->Display (theIObj, theMode);
1585 Standard_Integer aDispMode, aHiMode, aSelMode;
1586 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1587 if (aStatus->IsHilighted())
1589 myMainPM->Highlight (theIObj, aHiMode);
1591 if (aStatus->IsSubIntensityOn())
1593 myMainPM->Color (theIObj, mySubIntensity, theMode);
1596 if (theToUpdateViewer)
1598 myMainVwr->Update();
1600 theIObj->SetDisplayMode (theMode);
1603 //=======================================================================
1604 //function : UnsetDisplayMode
1606 //=======================================================================
1607 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1608 const Standard_Boolean theToUpdateViewer)
1610 if (theIObj.IsNull()
1611 || !theIObj->HasDisplayMode())
1616 if (!myObjects.IsBound (theIObj))
1618 theIObj->UnsetDisplayMode();
1622 const Standard_Integer anOldMode = theIObj->DisplayMode();
1623 if (myDisplayMode == anOldMode)
1628 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1629 aStatus->SetDisplayMode (myDisplayMode);
1631 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1633 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1635 myMainPM->Unhighlight (theIObj, anOldMode);
1637 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1638 myMainPM->Display (theIObj, myDisplayMode);
1640 Standard_Integer aDispMode, aHiMode, aSelMode;
1641 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1642 if (aStatus->IsHilighted())
1644 myMainPM->Highlight (theIObj, aHiMode);
1646 if (aStatus->IsSubIntensityOn())
1648 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1651 if (theToUpdateViewer)
1653 myMainVwr->Update();
1657 theIObj->UnsetDisplayMode();
1660 //=======================================================================
1661 //function : SetCurrentFacingModel
1663 //=======================================================================
1664 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1665 const Aspect_TypeOfFacingModel theModel)
1667 if (!theIObj.IsNull())
1669 theIObj->SetCurrentFacingModel (theModel);
1673 //=======================================================================
1674 //function : redisplayPrsRecModes
1676 //=======================================================================
1677 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1678 const Standard_Boolean theToUpdateViewer)
1680 if (theIObj->RecomputeEveryPrs())
1682 theIObj->Update (Standard_True);
1683 theIObj->UpdateSelection();
1687 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1689 theIObj->Update (aModes.Value(), Standard_False);
1691 theIObj->UpdateSelection();
1692 theIObj->SetRecomputeOk();
1695 if (theToUpdateViewer)
1697 UpdateCurrentViewer();
1701 //=======================================================================
1702 //function : redisplayPrsModes
1704 //=======================================================================
1705 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1706 const Standard_Boolean theToUpdateViewer)
1708 if (theIObj->RecomputeEveryPrs())
1710 theIObj->Update (Standard_True);
1711 theIObj->UpdateSelection();
1715 TColStd_ListOfInteger aModes;
1716 theIObj->ToBeUpdated (aModes);
1717 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1719 theIObj->Update (aModeIter.Value(), Standard_False);
1721 theIObj->SetRecomputeOk();
1724 if (theToUpdateViewer)
1726 UpdateCurrentViewer();
1730 //=======================================================================
1731 //function : SetColor
1733 //=======================================================================
1734 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1735 const Quantity_NameOfColor theColor,
1736 const Standard_Boolean theToUpdateViewer)
1738 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1741 //=======================================================================
1742 //function : SetColor
1744 //=======================================================================
1745 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1746 const Quantity_Color& theColor,
1747 const Standard_Boolean theToUpdateViewer)
1749 if (theIObj.IsNull())
1754 if (!theIObj->HasInteractiveContext())
1756 theIObj->SetContext (this);
1758 theIObj->SetColor (theColor);
1759 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1762 //=======================================================================
1763 //function : SetIsoOnTriangulation
1765 //=======================================================================
1766 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1767 const Handle(AIS_InteractiveObject)& theObject)
1769 if (theObject.IsNull())
1774 theObject->SetIsoOnTriangulation (theIsEnabled);
1777 //=======================================================================
1778 //function : SetDeviationCoefficient
1780 //=======================================================================
1781 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1782 const Standard_Real theCoefficient,
1783 const Standard_Boolean theToUpdateViewer)
1785 if (theIObj.IsNull())
1790 if (!theIObj->HasInteractiveContext())
1792 theIObj->SetContext (this);
1795 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1796 if (theIObj->Type() != AIS_KOI_Object
1797 && theIObj->Type() != AIS_KOI_Shape)
1801 else if (theIObj->Signature() != 0)
1806 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1807 aShape->SetOwnDeviationCoefficient (theCoefficient);
1808 redisplayPrsModes (theIObj, theToUpdateViewer);
1811 //=======================================================================
1812 //function : SetHLRDeviationCoefficient
1814 //=======================================================================
1815 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1816 const Standard_Real theCoefficient,
1817 const Standard_Boolean theToUpdateViewer)
1819 if (theIObj.IsNull())
1824 if (!theIObj->HasInteractiveContext())
1826 theIObj->SetContext (this);
1829 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1830 if (theIObj->Type() != AIS_KOI_Object
1831 && theIObj->Type() != AIS_KOI_Shape)
1835 else if (theIObj->Signature() != 0)
1840 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1841 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1842 redisplayPrsModes (theIObj, theToUpdateViewer);
1845 //=======================================================================
1846 //function : SetDeviationAngle
1848 //=======================================================================
1849 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1850 const Standard_Real theAngle,
1851 const Standard_Boolean theToUpdateViewer)
1853 if (theIObj.IsNull())
1858 if (!theIObj->HasInteractiveContext())
1860 theIObj->SetContext (this);
1863 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1864 if (theIObj->Type() != AIS_KOI_Shape)
1868 else if (theIObj->Signature() != 0)
1873 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1874 aShape->SetOwnDeviationAngle (theAngle);
1875 redisplayPrsModes (theIObj, theToUpdateViewer);
1878 //=======================================================================
1879 //function : SetAngleAndDeviation
1881 //=======================================================================
1882 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1883 const Standard_Real theAngle,
1884 const Standard_Boolean theToUpdateViewer)
1886 if (theIObj.IsNull())
1891 if (!theIObj->HasInteractiveContext())
1893 theIObj->SetContext (this);
1896 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1897 if (theIObj->Type() != AIS_KOI_Shape)
1901 if (theIObj->Signature() != 0)
1906 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1907 aShape->SetAngleAndDeviation (theAngle);
1909 if (theIObj->RecomputeEveryPrs())
1911 theIObj->Update (Standard_True);
1912 theIObj->UpdateSelection();
1916 Update (theIObj, theToUpdateViewer);
1920 //=======================================================================
1921 //function : SetHLRAngleAndDeviation
1923 //=======================================================================
1924 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1925 const Standard_Real theAngle,
1926 const Standard_Boolean theToUpdateViewer)
1928 if (theIObj.IsNull())
1933 if (!theIObj->HasInteractiveContext())
1935 theIObj->SetContext (this);
1938 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1939 if (theIObj->Type() != AIS_KOI_Shape)
1943 if (theIObj->Signature() != 0)
1947 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1948 aShape->SetHLRAngleAndDeviation (theAngle);
1949 redisplayPrsModes (theIObj, theToUpdateViewer);
1952 //=======================================================================
1953 //function : SetHLRDeviationAngle
1955 //=======================================================================
1956 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1957 const Standard_Real theAngle,
1958 const Standard_Boolean theToUpdateViewer)
1960 if (theIObj.IsNull())
1965 if (!theIObj->HasInteractiveContext())
1967 theIObj->SetContext (this);
1970 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1971 if (theIObj->Type() != AIS_KOI_Shape)
1975 if (theIObj->Signature() != 0)
1979 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1980 aShape->SetOwnHLRDeviationAngle (theAngle);
1981 redisplayPrsModes (theIObj, theToUpdateViewer);
1984 //=======================================================================
1985 //function : UnsetColor
1987 //=======================================================================
1988 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1989 const Standard_Boolean theToUpdateViewer)
1991 if (theIObj.IsNull())
1996 theIObj->UnsetColor();
1997 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2000 //=======================================================================
2001 //function : HasColor
2003 //=======================================================================
2004 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2006 return theIObj->HasColor();
2009 //=======================================================================
2012 //=======================================================================
2013 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2015 return theIObj->Color();
2018 //=======================================================================
2021 //=======================================================================
2022 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2023 Quantity_Color& theColor) const
2025 theIObj->Color (theColor);
2028 //=======================================================================
2031 //=======================================================================
2032 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2034 return theIObj->Width();
2037 //=======================================================================
2038 //function : SetWidth
2040 //=======================================================================
2041 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2042 const Standard_Real theWidth,
2043 const Standard_Boolean theToUpdateViewer)
2045 if (theIObj.IsNull())
2050 if (!theIObj->HasInteractiveContext())
2052 theIObj->SetContext (this);
2055 theIObj->SetWidth (theWidth);
2056 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2057 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2059 if (myLastinMain->IsAutoHilight())
2061 const Standard_Integer aHiMode =
2062 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2063 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2067 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2072 //=======================================================================
2073 //function : UnsetWidth
2075 //=======================================================================
2076 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2077 const Standard_Boolean theToUpdateViewer)
2079 if (theIObj.IsNull())
2084 theIObj->UnsetWidth();
2085 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2088 //=======================================================================
2089 //function : SetMaterial
2091 //=======================================================================
2092 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2093 const Graphic3d_NameOfMaterial theName,
2094 const Standard_Boolean theToUpdateViewer)
2096 if (theIObj.IsNull())
2101 if (!theIObj->HasInteractiveContext())
2103 theIObj->SetContext (this);
2106 theIObj->SetMaterial (theName);
2107 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2110 //=======================================================================
2111 //function : UnsetMaterial
2113 //=======================================================================
2114 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2115 const Standard_Boolean theToUpdateViewer)
2117 if (theIObj.IsNull())
2121 theIObj->UnsetMaterial();
2122 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2125 //=======================================================================
2126 //function : SetTransparency
2128 //=======================================================================
2129 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2130 const Standard_Real theValue,
2131 const Standard_Boolean theToUpdateViewer)
2133 if (theIObj.IsNull())
2138 if (!theIObj->HasInteractiveContext())
2140 theIObj->SetContext (this);
2143 if (!theIObj->IsTransparent()
2144 && theValue <= 0.05)
2149 if (theValue <= 0.05)
2151 UnsetTransparency (theIObj, theToUpdateViewer);
2155 theIObj->SetTransparency (theValue);
2156 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2159 //=======================================================================
2160 //function : UnsetTransparency
2162 //=======================================================================
2163 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2164 const Standard_Boolean theToUpdateViewer)
2166 if (theIObj.IsNull())
2171 theIObj->UnsetTransparency();
2172 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2175 //=======================================================================
2176 //function : SetSelectedAspect
2178 //=======================================================================
2179 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2180 const Standard_Boolean ,
2181 const Standard_Boolean theToUpdateViewer)
2183 if (HasOpenedContext())
2188 Standard_Boolean isFound = Standard_False;
2189 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2191 isFound = Standard_True;
2192 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
2193 anObj->SetAspect (theAspect);
2196 if (isFound && theToUpdateViewer)
2198 myMainVwr->Update();
2202 //=======================================================================
2203 //function : SetLocalAttributes
2205 //=======================================================================
2206 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2207 const Handle(Prs3d_Drawer)& theDrawer,
2208 const Standard_Boolean theToUpdateViewer)
2210 if (theIObj.IsNull())
2215 if (!theIObj->HasInteractiveContext())
2217 theIObj->SetContext (this);
2220 theIObj->SetAttributes (theDrawer);
2221 Update (theIObj, theToUpdateViewer);
2224 //=======================================================================
2225 //function : UnsetLocalAttributes
2227 //=======================================================================
2228 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2229 const Standard_Boolean theToUpdateViewer)
2231 if (theIObj.IsNull())
2236 if (!theIObj->HasInteractiveContext())
2238 theIObj->SetContext (this);
2240 theIObj->UnsetAttributes();
2241 Update (theIObj, theToUpdateViewer);
2244 //=======================================================================
2247 //=======================================================================
2248 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2249 TCollection_ExtendedString& theStatus) const
2252 if (theIObj.IsNull()
2253 || !myObjects.IsBound (theIObj))
2258 theStatus += "\t ____________________________________________";
2259 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2260 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2261 switch (aStatus->GraphicStatus())
2263 case AIS_DS_Displayed:
2265 theStatus += "\t| -->Displayed\n";
2270 theStatus += "\t| -->Erased\n";
2277 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2278 theStatus += "\t|\t Mode ";
2279 theStatus += TCollection_AsciiString (aStatus->DisplayMode());
2282 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2284 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2285 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2287 theStatus += "\t\t Mode ";
2288 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2291 theStatus += "\t ____________________________________________";
2294 //=======================================================================
2295 //function : GetDefModes
2297 //=======================================================================
2298 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2299 Standard_Integer& theDispMode,
2300 Standard_Integer& theHiMode,
2301 Standard_Integer& theSelMode) const
2303 if (theIObj.IsNull())
2308 theDispMode = theIObj->HasDisplayMode()
2309 ? theIObj->DisplayMode()
2310 : (theIObj->AcceptDisplayMode (myDisplayMode)
2313 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2314 theSelMode = theIObj->GlobalSelectionMode();
2317 //=======================================================================
2318 //function : EraseGlobal
2320 //=======================================================================
2321 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2322 const Standard_Boolean theToUpdateviewer)
2324 if (theIObj.IsNull()
2325 || !myObjects.IsBound (theIObj))
2330 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2332 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2333 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2334 || aStatus->GraphicStatus() == AIS_DS_Erased)
2339 if (aStatus->IsHilighted())
2341 if (IsCurrent (theIObj))
2343 AddOrRemoveCurrentObject (theIObj, Standard_False);
2345 else if (myMainPM->IsHighlighted (theIObj, aStatus->DisplayMode()))
2347 myMainPM->Unhighlight (theIObj, aStatus->DisplayMode());
2351 myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
2353 if (aStatus->IsHilighted()
2354 && theIObj->HasHilightMode())
2356 myMainPM->Unhighlight (theIObj, aDispMode);
2359 if (!myLastPicked.IsNull()
2360 && myLastPicked->Selectable() == theIObj)
2362 myMainPM->ClearImmediateDraw();
2365 if (IsSelected (theIObj)
2366 && aStatus->DisplayMode() != aDispMode)
2368 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2371 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2373 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2375 aStatus->ClearSelectionModes();
2376 aStatus->SetGraphicStatus (AIS_DS_Erased);
2378 if (theToUpdateviewer)
2380 myMainVwr->Update();
2384 //=======================================================================
2385 //function : unhighlightOwners
2387 //=======================================================================
2388 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2390 SelectMgr_SequenceOfOwner aSeq;
2391 for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2393 if (aSelIter.Value()->Selectable() == theObject
2394 && aSelIter.Value()->IsSelected())
2396 aSeq.Append (aSelIter.Value());
2399 for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2401 AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2405 //=======================================================================
2406 //function : ClearGlobal
2408 //=======================================================================
2409 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2410 const Standard_Boolean theToUpdateviewer)
2412 if (theIObj.IsNull()
2413 || !myObjects.IsBound (theIObj))
2415 // for cases when reference shape of connected interactives was not displayed
2416 // but its selection primitives were calculated
2417 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2418 mgrSelector->Remove (anObj);
2422 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2423 unhighlightOwners (theIObj);
2425 myMainPM->Erase (theIObj, -1);
2427 // Object removes from Detected sequence
2428 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2430 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2432 && anObj != theIObj)
2434 myAISDetectedSeq.Remove (aDetIter);
2438 // remove IO from the selection manager to avoid memory leaks
2439 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2440 mgrSelector->Remove (anObj);
2442 myObjects.UnBind (theIObj);
2443 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2445 for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2447 aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2450 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2451 myLastinMain.Nullify();
2452 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2453 myLastPicked.Nullify();
2454 myMainPM->ClearImmediateDraw();
2456 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2458 myMainVwr->Update();
2462 //=======================================================================
2463 //function : ClearGlobalPrs
2465 //=======================================================================
2466 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2467 const Standard_Integer theMode,
2468 const Standard_Boolean theToUpdateViewer)
2470 if (theIObj.IsNull()
2471 || !myObjects.IsBound (theIObj))
2476 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2477 if (aStatus->DisplayMode() == theMode)
2479 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2480 if (aDispMode == theMode
2481 && myMainPM->IsHighlighted (theIObj, theMode))
2483 myMainPM->Unhighlight (theIObj, theMode);
2486 myMainPM->Erase (theIObj, theMode);
2489 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2490 && theToUpdateViewer)
2492 myMainVwr->Update();
2496 //=======================================================================
2497 //function : DrawHiddenLine
2499 //=======================================================================
2500 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2502 return myDefaultDrawer->DrawHiddenLine();
2505 //=======================================================================
2506 //function : EnableDrawHiddenLine
2508 //=======================================================================
2509 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2511 myDefaultDrawer->EnableDrawHiddenLine();
2514 //=======================================================================
2515 //function : DisableDrawHiddenLine
2517 //=======================================================================
2518 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2520 myDefaultDrawer->DisableDrawHiddenLine();
2523 //=======================================================================
2524 //function : HiddenLineAspect
2526 //=======================================================================
2527 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2529 return myDefaultDrawer->HiddenLineAspect();
2532 //=======================================================================
2533 //function : SetHiddenLineAspect
2535 //=======================================================================
2536 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2538 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2541 //=======================================================================
2542 //function : SetIsoNumber
2544 //=======================================================================
2545 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2546 const AIS_TypeOfIso theType)
2551 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2554 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2557 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2558 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2563 //=======================================================================
2564 //function : IsoNumber
2566 //=======================================================================
2567 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2571 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2572 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2573 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2574 ? myDefaultDrawer->UIsoAspect()->Number()
2580 //=======================================================================
2581 //function : IsoOnPlane
2583 //=======================================================================
2584 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2586 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2589 //=======================================================================
2590 //function : IsoOnPlane
2592 //=======================================================================
2593 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2595 return myDefaultDrawer->IsoOnPlane();
2598 //=======================================================================
2599 //function : IsoOnTriangulation
2601 //=======================================================================
2602 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2604 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2607 //=======================================================================
2608 //function : IsoOnTriangulation
2610 //=======================================================================
2611 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2613 return myDefaultDrawer->IsoOnTriangulation();
2616 //function : SetPixelTolerance
2617 //purpose : Disables the mechanism of adaptive tolerance calculation in
2618 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2619 // sensitive entities activated. For more information, see
2620 // SelectMgr_ViewerSelector.hxx
2621 //=======================================================================
2622 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2624 if (HasOpenedContext())
2626 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2630 myMainSel->SetPixelTolerance (thePrecision);
2634 //=======================================================================
2635 //function : PixelTolerance
2637 //=======================================================================
2638 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2640 return HasOpenedContext()
2641 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2642 : myMainSel->PixelTolerance();
2645 //=======================================================================
2646 //function : SetSelectionSensitivity
2647 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2648 //=======================================================================
2649 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2650 const Standard_Integer theMode,
2651 const Standard_Integer theNewSensitivity)
2653 if (HasOpenedContext())
2655 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2659 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2662 //=======================================================================
2663 //function : IsInLocal
2665 //=======================================================================
2666 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2667 Standard_Integer& theIndex) const
2669 if (theIObj.IsNull())
2671 return Standard_False;
2674 // if it exists at neutral point 0 index is returned
2675 if (myObjects.IsBound (theIObj))
2678 return Standard_False;
2681 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2683 if (myLocalContexts.IsBound (aCtxIter))
2685 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2687 theIndex = aCtxIter;
2688 return Standard_True;
2693 return Standard_False;
2696 //=======================================================================
2697 //function : InitAttributes
2699 //=======================================================================
2700 void AIS_InteractiveContext::InitAttributes()
2702 mgrSelector->Add (myMainSel);
2704 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2705 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2707 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2708 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2709 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2710 aLineAspect->SetWidth (1.0);
2711 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2713 // tolerance to 2 pixels...
2714 SetPixelTolerance (2);
2716 // Customizing the drawer for trihedrons and planes...
2717 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2718 const Standard_Real aLength = 100.0;
2719 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2720 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2721 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2722 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2723 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2725 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2726 const Standard_Real aPlaneLength = 200.0;
2727 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2728 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2731 //=======================================================================
2732 //function : TrihedronSize
2734 //=======================================================================
2735 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2737 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2740 //=======================================================================
2741 //function : SetTrihedronSize
2743 //=======================================================================
2744 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2745 const Standard_Boolean /*updateviewer*/)
2747 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2748 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2749 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2752 //=======================================================================
2753 //function : SetPlaneSize
2755 //=======================================================================
2756 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2757 const Standard_Real theValY,
2758 const Standard_Boolean /*updateviewer*/)
2760 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2761 Redisplay (AIS_KOI_Datum, 7);
2764 //=======================================================================
2765 //function : SetPlaneSize
2767 //=======================================================================
2768 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2769 const Standard_Boolean theToUpdateViewer)
2771 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2774 //=======================================================================
2775 //function : PlaneSize
2777 //=======================================================================
2778 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2779 Standard_Real& theY) const
2781 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2782 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2783 return (Abs (theX - theY) <= Precision::Confusion());
2786 //=======================================================================
2787 //function : SetAutoActivateSelection
2789 //=======================================================================
2790 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2792 myIsAutoActivateSelMode = theIsAuto;
2795 //=======================================================================
2796 //function : GetAutoActivateSelection
2798 //=======================================================================
2799 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2801 return myIsAutoActivateSelMode;
2804 //=======================================================================
2805 //function : SetZLayer
2807 //=======================================================================
2808 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2809 const Standard_Integer theLayerId)
2811 if (theIObj.IsNull())
2814 theIObj->SetZLayer (theLayerId);
2817 //=======================================================================
2818 //function : GetZLayer
2820 //=======================================================================
2821 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2823 return !theIObj.IsNull()
2825 : Graphic3d_ZLayerId_UNKNOWN;
2828 //=======================================================================
2829 //function : RebuildSelectionStructs
2830 //purpose : Rebuilds 1st level of BVH selection forcibly
2831 //=======================================================================
2832 void AIS_InteractiveContext::RebuildSelectionStructs()
2834 myMainSel->RebuildObjectsTree (Standard_True);
2837 //=======================================================================
2838 //function : Disconnect
2839 //purpose : Disconnects selectable object from an assembly and updates selection structures
2840 //=======================================================================
2841 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2842 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2844 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2846 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2847 theObj->Disconnect (theObjToDisconnect);
2848 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2849 mgrSelector->Remove (anObj);
2851 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2853 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2854 theObj->Disconnect();
2855 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2856 mgrSelector->Remove (anObj);
2862 //=======================================================================
2863 //function : FitSelected
2864 //purpose : Fits the view corresponding to the bounds of selected objects
2865 //=======================================================================
2866 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2867 const Standard_Real theMargin,
2868 const Standard_Boolean theToUpdate)
2870 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2871 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2873 Bnd_Box aBndSelected;
2875 AIS_MapOfObjectOwners anObjectOwnerMap;
2876 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2878 const Handle(SelectMgr_EntityOwner)& anOwner = aSelection->Value();
2879 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2880 if (anObj->IsInfinite())
2885 if (anOwner == anObj->GlobalSelOwner())
2888 anObj->BoundingBox (aTmpBnd);
2889 aBndSelected.Add (aTmpBnd);
2893 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2894 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2896 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2897 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2900 anOwnerMap->Add (anOwner);
2904 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2906 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2907 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2908 aBndSelected.Add (aTmpBox);
2911 anObjectOwnerMap.Clear();
2913 if (aBndSelected.IsVoid())
2916 theView->FitAll (aBndSelected, theMargin, theToUpdate);
2919 //=======================================================================
2920 //function : SetTransformPersistence
2922 //=======================================================================
2923 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2924 const Handle(Graphic3d_TransformPers)& theTrsfPers)
2926 theObject->SetTransformPersistence (theTrsfPers);
2927 if (!myObjects.IsBound (theObject))
2932 mgrSelector->UpdateSelection (theObject);
2934 const Standard_Integer aLayerId = myObjects.Find (theObject)->GetLayerIndex();
2935 const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2936 for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2938 anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2939 anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);