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 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
68 static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
69 static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
71 static TCollection_AsciiString AIS_Context_NewSelName()
73 return TCollection_AsciiString ("AIS_SelContext_")
74 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
77 static TCollection_AsciiString AIS_Context_NewCurName()
79 return TCollection_AsciiString ("AIS_CurContext_")
80 + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
83 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
84 typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
87 //=======================================================================
88 //function : AIS_InteractiveContext
90 //=======================================================================
92 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
93 mgrSelector(new SelectMgr_SelectionManager()),
94 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
95 myMainVwr(MainViewer),
96 myMainSel(new StdSelect_ViewerSelector3d()),
97 myWasLastMain(Standard_False),
98 myCurrentTouched(Standard_False),
99 mySelectedTouched(Standard_False),
100 myToHilightSelected(Standard_True),
101 myFilters(new SelectMgr_OrFilter()),
102 myDefaultDrawer(new Prs3d_Drawer()),
103 myDefaultColor(Quantity_NOC_GOLDENROD),
104 myHilightColor(Quantity_NOC_CYAN1),
105 mySelectionColor(Quantity_NOC_GRAY80),
106 myPreselectionColor(Quantity_NOC_GREEN),
107 mySubIntensity(Quantity_NOC_GRAY40),
112 myIsAutoActivateSelMode( Standard_True )
117 void AIS_InteractiveContext::Delete() const
119 // clear the static current selection
120 AIS_Selection::ClearCurrentSelection();
122 // to avoid an exception
123 if (AIS_Selection::Find (mySelectionName.ToCString()))
125 AIS_Selection::Remove (mySelectionName.ToCString());
128 // to avoid an exception
129 if (AIS_Selection::Find (myCurrentName.ToCString()))
131 AIS_Selection::Remove (myCurrentName.ToCString());
134 // let's remove one reference explicitly. this operation's supposed to
135 // be performed when mgrSelector will be destroyed but anyway...
136 const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
137 mgrSelector->Remove (aSelector);
139 Handle(AIS_InteractiveContext) aNullContext;
140 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
142 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
143 anObj->SetContext (aNullContext);
144 for (anObj->Init(); anObj->More(); anObj->Next())
146 anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
149 MMgt_TShared::Delete();
152 //=======================================================================
153 //function : AIS_SelectionName
155 //=======================================================================
156 const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const
158 if(!HasOpenedContext())
159 return mySelectionName;
160 return myLocalContexts(myCurLocalIndex)->SelectionName();
166 //=======================================================================
167 //function : UpdateCurrentViewer
169 //=======================================================================
171 void AIS_InteractiveContext::UpdateCurrentViewer()
173 if (!myMainVwr.IsNull())
178 //=======================================================================
179 //function : DomainOfMainViewer
181 //=======================================================================
183 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
185 return myMainVwr->Domain();
189 //=======================================================================
190 //function : DisplayedObjects
192 //=======================================================================
193 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
194 const Standard_Boolean theOnlyFromNeutral) const
196 if (!HasOpenedContext()
197 || theOnlyFromNeutral)
199 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
201 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
203 theListOfIO.Append (anObjIter.Key());
210 TColStd_MapOfTransient aDispMap;
211 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
213 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
215 aDispMap.Add (anObjIter.Key());
219 // parse all local contexts...
220 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
222 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
223 aLocCtx->DisplayedObjects (aDispMap);
226 Handle(AIS_InteractiveObject) anObj;
227 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
229 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
230 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
231 theListOfIO.Append (anObj);
235 //=======================================================================
236 //function : DisplayedObjects
238 //=======================================================================
239 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
240 const Standard_Integer theSign,
241 AIS_ListOfInteractive& theListOfIO,
242 const Standard_Boolean /*OnlyFromNeutral*/) const
244 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
247 //=======================================================================
248 //function : ErasedObjects
250 //=======================================================================
251 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
253 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
256 //=======================================================================
257 //function : ErasedObjects
259 //=======================================================================
260 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
261 const Standard_Integer theSign,
262 AIS_ListOfInteractive& theListOfIO) const
264 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
267 //=======================================================================
268 //function : ObjectsByDisplayStatus
270 //=======================================================================
271 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
272 AIS_ListOfInteractive& theListOfIO) const
274 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
276 if (anObjIter.Value()->GraphicStatus() == theStatus)
278 theListOfIO.Append (anObjIter.Key());
283 //=======================================================================
284 //function : ObjectsByDisplayStatus
286 //=======================================================================
287 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
288 const Standard_Integer theSign,
289 const AIS_DisplayStatus theStatus,
290 AIS_ListOfInteractive& theListOfIO) const
292 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
294 if (theStatus != AIS_DS_None
295 && anObjIter.Value()->GraphicStatus() != theStatus)
299 else if (anObjIter.Key()->Type() != theKind)
305 || anObjIter.Key()->Signature() == theSign)
307 theListOfIO.Append (anObjIter.Key());
312 //=======================================================================
313 //function : ObjectsInside
315 //=======================================================================
316 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
317 const AIS_KindOfInteractive theKind,
318 const Standard_Integer theSign) const
320 if (theKind == AIS_KOI_None
323 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
325 theListOfIO.Append (anObjIter.Key());
330 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
332 if (anObjIter.Key()->Type() != theKind)
338 || anObjIter.Key()->Signature() == theSign)
340 theListOfIO.Append (anObjIter.Key());
345 //=======================================================================
346 //function : ObjectsForView
348 //=======================================================================
349 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
350 const Handle(V3d_View)& theView,
351 const Standard_Boolean theIsVisibleInView,
352 const AIS_DisplayStatus theStatus) const
354 Handle(Graphic3d_CView) aViewImpl = theView->View();
355 const Standard_Integer aViewId = aViewImpl->Identification();
356 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
358 if (theStatus != AIS_DS_None
359 && anObjIter.Value()->GraphicStatus() != theStatus)
361 theListOfIO.Append (anObjIter.Key());
365 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
366 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
367 if (isVisible == theIsVisibleInView)
369 theListOfIO.Append (anObjIter.Key());
374 //=======================================================================
377 //=======================================================================
378 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
379 const Standard_Boolean theToUpdateViewer)
381 if (theIObj.IsNull())
386 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
387 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
389 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
390 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
393 //=======================================================================
394 //function : SetViewAffinity
396 //=======================================================================
397 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
398 const Handle(V3d_View)& theView,
399 const Standard_Boolean theIsVisible)
402 || !myObjects.IsBound (theIObj))
407 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
408 Handle(Graphic3d_CView) aViewImpl = theView->View();
409 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
412 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
416 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
420 //=======================================================================
423 //=======================================================================
424 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
425 const Standard_Integer theDispMode,
426 const Standard_Integer theSelectionMode,
427 const Standard_Boolean theToUpdateViewer,
428 const Standard_Boolean theToAllowDecomposition,
429 const AIS_DisplayStatus theDispStatus)
431 if (theIObj.IsNull())
436 if (theDispStatus == AIS_DS_Erased)
438 Erase (theIObj, theToUpdateViewer);
439 Load (theIObj, theSelectionMode, theToAllowDecomposition);
443 if (!theIObj->HasInteractiveContext())
445 theIObj->SetContext (this);
448 if (theDispStatus == AIS_DS_Temporary
449 && !HasOpenedContext())
453 else if (HasOpenedContext())
455 if (theDispStatus == AIS_DS_None
456 || theDispStatus == AIS_DS_Temporary)
458 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
459 if (theToUpdateViewer)
467 if (!myObjects.IsBound (theIObj))
469 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
470 myObjects.Bind (theIObj, aStatus);
471 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
472 myMainPM->Display(theIObj, theDispMode);
473 if (theSelectionMode != -1)
475 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
476 if (!mgrSelector->Contains (anObj))
478 mgrSelector->Load (theIObj);
480 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
485 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
486 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
491 // Erase presentations for all display modes different from aDispMode.
492 // Then make sure aDispMode is displayed and maybe highlighted.
493 // Finally, activate selection mode <SelMode> if not yet activated.
494 TColStd_ListOfInteger aModesToRemove;
495 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
497 const Standard_Integer anOldMode = aDispModeIter.Value();
498 if (anOldMode != theDispMode)
500 aModesToRemove.Append (anOldMode);
501 if(myMainPM->IsHighlighted (theIObj, anOldMode))
503 myMainPM->Unhighlight (theIObj, anOldMode);
505 myMainPM->Erase (theIObj, anOldMode);
509 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
511 aStatus->RemoveDisplayMode (aRemModeIter.Value());
514 if (!aStatus->IsDModeIn (theDispMode))
516 aStatus->AddDisplayMode (theDispMode);
519 myMainPM->Display (theIObj, theDispMode);
520 aStatus->SetGraphicStatus (AIS_DS_Displayed);
521 if (aStatus->IsHilighted())
523 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
524 myMainPM->Color (theIObj, aStatus->HilightColor(), aHiMod);
526 if (theSelectionMode != -1)
528 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
529 if (!mgrSelector->Contains (anObj))
531 mgrSelector->Load (theIObj);
533 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
535 if (!aStatus->IsSModeIn (theSelectionMode))
536 aStatus->AddSelectionMode (theSelectionMode);
537 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
542 if (theToUpdateViewer)
548 //=======================================================================
551 //=======================================================================
552 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
553 const Standard_Integer theSelMode,
554 const Standard_Boolean theToAllowDecomposition)
556 if (theIObj.IsNull())
561 if (!theIObj->HasInteractiveContext())
563 theIObj->SetContext (this);
566 if (HasOpenedContext())
568 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
573 && !theToAllowDecomposition)
575 if (!myObjects.IsBound (theIObj))
577 Standard_Integer aDispMode, aHiMod, aSelModeDef;
578 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
579 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
580 myObjects.Bind (theIObj, aStatus);
583 // Register theIObj in the selection manager to prepare further activation of selection
584 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
585 if (!mgrSelector->Contains (anObj))
587 mgrSelector->Load (theIObj);
592 //=======================================================================
595 //=======================================================================
596 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
597 const Standard_Boolean theToUpdateViewer)
599 if (theIObj.IsNull())
604 if (!theIObj->IsAutoHilight())
606 theIObj->ClearSelected();
609 Standard_Boolean wasInCtx = Standard_False;
610 if (HasOpenedContext())
612 // First it is checked if it is possible to remove in the current local context
613 // then one tries to remove in other local contexts, if they allow it...
614 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
615 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
617 if (aCtxIter.Value()->AcceptErase())
619 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
626 EraseGlobal (theIObj, Standard_False);
629 if (theToUpdateViewer)
635 //=======================================================================
636 //function : EraseAll
638 //=======================================================================
639 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
641 if (HasOpenedContext())
646 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
648 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
650 Erase (anObjIter.Key(), Standard_False);
654 if (theToUpdateViewer)
660 //=======================================================================
661 //function : DisplayAll
663 //=======================================================================
664 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
666 if (HasOpenedContext())
671 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
673 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
674 if (aStatus == AIS_DS_Erased)
676 Display (anObjIter.Key(), Standard_False);
680 if (theToUpdateViewer)
686 //=======================================================================
687 //function : DisplaySelected
689 //=======================================================================
690 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
692 if (HasOpenedContext())
697 Standard_Boolean isFound = Standard_False;
698 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
699 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
701 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
702 Display (anObj, Standard_False);
703 isFound = Standard_True;
706 if (isFound && theToUpdateViewer)
712 //=======================================================================
713 //function : EraseSelected
715 //=======================================================================
716 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
718 if (HasOpenedContext())
723 Standard_Boolean isFound = Standard_False;
724 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection(myCurrentName.ToCString());
727 while (aSelIter->More())
729 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aSelIter->Value());
730 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
732 Erase (anObj, Standard_False);
733 isFound = Standard_True;
738 if (isFound && theToUpdateViewer)
744 //=======================================================================
747 //=======================================================================
749 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
750 const Standard_Integer WhichContext)
752 if(anIObj.IsNull()) return Standard_False;
754 if(!HasOpenedContext()) return Standard_False;
755 if(myObjects.IsBound(anIObj)) return Standard_False;
756 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
758 // Protection : if one tries to preserve a temporary object
759 // which is not in the local active context... rob 11-06-97
761 Standard_Integer IsItInLocal = myCurLocalIndex;
762 Standard_Boolean Found(Standard_False);
764 while(IsItInLocal>0 && !Found){
765 if(!myLocalContexts.IsBound(IsItInLocal))
767 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
768 Found = Standard_True;
773 if(!Found) return Standard_False;
776 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
777 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
779 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
780 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
784 if(LS->IsTemporary()){
785 Standard_Integer DM,HM,SM;
786 GetDefModes(anIObj,DM,HM,SM);
788 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
789 if(LS->DisplayMode()!= DM ){
790 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
791 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
794 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
798 // GS->SubIntensityOn();
799 myObjects.Bind(anIObj,GS);
800 mgrSelector->Load(anIObj);
801 mgrSelector->Activate(anIObj,SM,myMainSel);
803 LS->SetTemporary(Standard_False);
805 return Standard_True;
808 //=======================================================================
809 //function : DisplayStatus
811 //=======================================================================
812 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
814 if (theIObj.IsNull())
818 else if (myObjects.IsBound (theIObj))
820 return myObjects (theIObj)->GraphicStatus();
823 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
825 if (aCtxIter.Value()->IsIn (theIObj))
827 return AIS_DS_Temporary;
833 //=======================================================================
834 //function : DisplayedModes
836 //=======================================================================
837 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
839 return myObjects (theIObj)->DisplayedModes();
842 //=======================================================================
845 //=======================================================================
846 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
847 const Standard_Boolean theToUpdateViewer)
849 if (theIObj.IsNull())
854 if (HasOpenedContext())
856 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
857 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
859 if (aCtxIter.Value()->AcceptErase())
861 aCtxIter.Value()->Remove (theIObj);
866 ClearGlobal (theIObj, theToUpdateViewer);
869 //=======================================================================
870 //function : RemoveAll
872 //=======================================================================
873 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
875 AIS_ListOfInteractive aList;
876 ObjectsInside (aList);
877 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
879 Remove (aListIterator.Value(), Standard_False);
882 if (theToUpdateViewer)
888 //=======================================================================
889 //function : ClearPrs
891 //=======================================================================
892 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
893 const Standard_Integer theMode,
894 const Standard_Boolean theToUpdateViewer)
896 if (theIObj.IsNull())
901 if (!HasOpenedContext())
903 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
907 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
908 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
910 if (aCtxIter.Value()->AcceptErase())
912 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
917 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
919 else if (theToUpdateViewer)
925 //=======================================================================
928 //=======================================================================
929 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
930 const Standard_Boolean theToUpdateViewer)
932 if (theIObj.IsNull())
937 if (!theIObj->HasInteractiveContext())
939 theIObj->SetContext (this);
941 if (!HasOpenedContext())
943 if (!myObjects.IsBound (theIObj))
948 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
949 aStatus->SetHilightStatus (Standard_True);
950 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
952 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
953 myMainPM->Highlight (theIObj, aHilightMode);
958 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
961 if (theToUpdateViewer)
966 //=======================================================================
969 //=======================================================================
971 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
972 const Quantity_NameOfColor aCol,
973 const Standard_Boolean updateviewer)
975 if(anIObj.IsNull()) return;
977 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
979 if (!HasOpenedContext())
981 if(!myObjects.IsBound(anIObj)) return;
983 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
984 aStatus->SetHilightStatus (Standard_True);
986 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
988 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
989 myMainPM->Color (anIObj, aCol, aHilightMode);
990 aStatus->SetHilightColor (aCol);
995 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
997 if(updateviewer) myMainVwr->Update();
1000 //=======================================================================
1001 //function : Unhilight
1003 //=======================================================================
1005 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
1007 if(anIObj.IsNull()) return;
1009 if (!HasOpenedContext())
1011 if(!myObjects.IsBound(anIObj)) return;
1013 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
1014 aStatus->SetHilightStatus (Standard_False);
1015 aStatus->SetHilightColor(Quantity_NOC_WHITE);
1017 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1019 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
1020 myMainPM->Unhighlight (anIObj, aHilightMode);
1025 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1027 if(updateviewer) myMainVwr->Update();
1030 //=======================================================================
1031 //function : IsHilighted
1033 //=======================================================================
1035 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
1037 if(anIObj.IsNull()) return Standard_False;
1039 if (!HasOpenedContext()){
1040 if(!myObjects.IsBound(anIObj))
1041 return Standard_False;
1042 return myObjects(anIObj)->IsHilighted();
1044 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1045 for(;ItM.More();ItM.Next()){
1046 if(ItM.Value()->IsHilighted(anIObj))
1047 return Standard_True;
1049 return Standard_False;
1052 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1053 Standard_Boolean& WithColor,
1054 Quantity_NameOfColor& TheHiCol) const
1056 if(!HasOpenedContext()){
1057 if(myObjects.IsBound(anIObj)){
1058 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1059 if(STAT->IsHilighted()){
1060 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1061 WithColor=Standard_True;
1062 TheHiCol = STAT->HilightColor();
1065 WithColor = Standard_False;
1066 return Standard_True;
1069 return Standard_False;
1071 Standard_Integer MaxIndex = HighestIndex();
1072 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1073 if(myLocalContexts.IsBound(i)){
1074 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1075 return Standard_True;
1079 return Standard_False;
1082 //=======================================================================
1083 //function : IsHilighted
1084 //purpose : Returns true if the objects global status is set to highlighted.
1085 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1086 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1087 // custom highlight color name will be stored to theCustomColorName
1088 //=======================================================================
1089 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1090 Standard_Boolean& theIsCustomColor,
1091 Quantity_NameOfColor& theCustomColorName) const
1093 if (theOwner.IsNull() || !theOwner->HasSelectable())
1094 return Standard_False;
1096 const Handle(AIS_InteractiveObject) anObj =
1097 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1099 if (!myObjects.IsBound (anObj))
1100 return Standard_False;
1102 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1103 if (anObjStatus->IsHilighted())
1105 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1107 theIsCustomColor = Standard_True;
1108 theCustomColorName = anObjStatus->HilightColor();
1112 theIsCustomColor = Standard_False;
1115 return Standard_True;
1118 return Standard_False;
1121 //=======================================================================
1122 //function : IsDisplayed
1124 //=======================================================================
1126 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1128 if(anIObj.IsNull()) return Standard_False;
1131 if(myObjects.IsBound(anIObj))
1132 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1133 return Standard_True;
1135 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1136 for(;ItM.More();ItM.Next()){
1137 if(ItM.Value()->IsDisplayed(anIObj))
1138 return Standard_True;
1140 return Standard_False;
1144 //=======================================================================
1145 //function : IsDisplayed
1147 //=======================================================================
1148 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1149 const Standard_Integer theMode) const
1151 if (theIObj.IsNull())
1153 return Standard_False;
1156 if (myObjects.IsBound (theIObj))
1158 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1159 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1160 && aStatus->IsDModeIn (theMode))
1162 return Standard_True;
1166 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1168 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1170 return Standard_True;
1173 return Standard_False;
1176 //=======================================================================
1177 //function : DisplayPriority
1179 //=======================================================================
1180 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1182 if (theIObj.IsNull())
1186 else if (!myObjects.IsBound (theIObj))
1191 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1192 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1193 || aStatus->GraphicStatus() == AIS_DS_Erased)
1195 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1196 ? theIObj->DisplayMode()
1197 : (theIObj->AcceptDisplayMode (myDisplayMode)
1200 return myMainPM->DisplayPriority (theIObj, aDispMode);
1205 //=======================================================================
1206 //function : SetDisplayPriority
1208 //=======================================================================
1209 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1210 const Standard_Integer thePriority)
1212 if (theIObj.IsNull())
1217 if (!theIObj->HasInteractiveContext())
1219 theIObj->SetContext (this);
1222 if (myObjects.IsBound (theIObj))
1224 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1225 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1226 || aStatus->GraphicStatus() == AIS_DS_Erased)
1228 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1229 ? theIObj->DisplayMode()
1230 : (theIObj->AcceptDisplayMode (myDisplayMode)
1233 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1236 else if (HasOpenedContext())
1238 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1242 //=======================================================================
1243 //function : Redisplay
1245 //=======================================================================
1246 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1247 const Standard_Boolean theToUpdateViewer,
1248 const Standard_Boolean theAllModes)
1250 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1251 RecomputeSelectionOnly (theIObj);
1254 //=======================================================================
1255 //function : Redisplay
1257 //=======================================================================
1258 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1259 const Standard_Integer /*theSign*/,
1260 const Standard_Boolean theToUpdateViewer)
1262 Standard_Boolean isRedisplayed = Standard_False;
1263 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1265 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1266 if (anObj->Type() != theKOI)
1271 Redisplay (anObj, Standard_False);
1272 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1276 if (theToUpdateViewer
1279 myMainVwr->Update();
1283 //=======================================================================
1284 //function : RecomputePrsOnly
1286 //=======================================================================
1287 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1288 const Standard_Boolean theToUpdateViewer,
1289 const Standard_Boolean theAllModes)
1291 if (theIObj.IsNull())
1296 theIObj->Update (theAllModes);
1297 if (!theToUpdateViewer)
1302 if (HasOpenedContext()
1303 || (myObjects.IsBound (theIObj)
1304 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1306 myMainVwr->Update();
1309 //=======================================================================
1310 //function : RecomputeSelectionOnly
1312 //=======================================================================
1313 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1320 mgrSelector->RecomputeSelection (theIO);
1322 if (HasOpenedContext())
1324 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1326 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1331 if (!myObjects.IsBound (theIO) ||
1332 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1337 TColStd_ListOfInteger aModes;
1338 ActivatedModes (theIO, aModes);
1339 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1340 for (; aModesIter.More(); aModesIter.Next())
1342 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1346 //=======================================================================
1349 //=======================================================================
1350 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1351 const Standard_Boolean theUpdateViewer)
1353 if (theIObj.IsNull())
1358 TColStd_ListOfInteger aPrsModes;
1359 theIObj->ToBeUpdated (aPrsModes);
1360 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1362 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1365 mgrSelector->Update(theIObj);
1367 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1369 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1372 if (theUpdateViewer)
1374 if (!myObjects.IsBound (theIObj))
1379 switch (myObjects (theIObj)->GraphicStatus())
1381 case AIS_DS_Displayed:
1382 case AIS_DS_Temporary:
1383 myMainVwr->Update();
1391 //=======================================================================
1392 //function : SetLocation
1394 //=======================================================================
1395 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1396 const TopLoc_Location& theLoc)
1398 if (theIObj.IsNull())
1403 if (theIObj->HasTransformation()
1404 && theLoc.IsIdentity())
1406 theIObj->ResetTransformation();
1407 mgrSelector->Update (theIObj, Standard_False);
1410 else if (theLoc.IsIdentity())
1415 // first reset the previous location to properly clean everything...
1416 if (theIObj->HasTransformation())
1418 theIObj->ResetTransformation();
1421 theIObj->SetLocalTransformation (theLoc.Transformation());
1423 if (!HasOpenedContext())
1425 mgrSelector->Update (theIObj, Standard_False);
1429 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1430 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1434 //=======================================================================
1435 //function : ResetLocation
1437 //=======================================================================
1438 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1440 if (theIObj.IsNull())
1445 theIObj->ResetTransformation();
1446 mgrSelector->Update (theIObj, Standard_False);
1449 //=======================================================================
1450 //function : HasLocation
1452 //=======================================================================
1453 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1455 return !theIObj.IsNull()
1456 && theIObj->HasTransformation();
1459 //=======================================================================
1460 //function : Location
1462 //=======================================================================
1463 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1465 return theIObj->Transformation();
1468 //=======================================================================
1469 //function : SetDeviationCoefficient
1471 //=======================================================================
1472 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1474 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1477 //=======================================================================
1478 //function : SetDeviationAngle
1480 //=======================================================================
1481 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1483 myDefaultDrawer->SetDeviationCoefficient (theAngle);
1486 //=======================================================================
1487 //function : DeviationAngle
1488 //purpose : Gets deviationAngle
1489 //=======================================================================
1490 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1492 return myDefaultDrawer->DeviationAngle();
1495 //=======================================================================
1496 //function : DeviationCoefficient
1498 //=======================================================================
1499 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1501 return myDefaultDrawer->DeviationCoefficient();
1504 //=======================================================================
1505 //function : SetHLRDeviationCoefficient
1507 //=======================================================================
1508 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1510 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1513 //=======================================================================
1514 //function : HLRDeviationCoefficient
1516 //=======================================================================
1517 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1519 return myDefaultDrawer->HLRDeviationCoefficient();
1522 //=======================================================================
1523 //function : SetHLRAngle
1525 //=======================================================================
1526 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1528 myDefaultDrawer->SetHLRAngle (theAngle);
1531 //=======================================================================
1532 //function : SetHLRAngleAndDeviation
1533 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1534 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1535 // of myDefaultDrawer
1536 //=======================================================================
1537 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1539 Standard_Real anOutAngl, anOutDefl;
1540 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1542 myDefaultDrawer->SetHLRAngle (anOutAngl);
1543 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1546 //=======================================================================
1547 //function : HLRAngle
1549 //=======================================================================
1550 Standard_Real AIS_InteractiveContext::HLRAngle() const
1552 return myDefaultDrawer->HLRAngle();
1555 //=======================================================================
1556 //function : SetDisplayMode
1558 //=======================================================================
1559 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1560 const Standard_Boolean theToUpdateViewer)
1562 if (theMode == myDisplayMode)
1567 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1569 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1570 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1571 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1572 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1575 || anObj->HasDisplayMode()
1576 || !anObj->AcceptDisplayMode (theMode))
1581 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1582 if (aStatus->IsDModeIn (myDisplayMode))
1584 aStatus->RemoveDisplayMode (myDisplayMode);
1587 aStatus->AddDisplayMode (theMode);
1588 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1590 myMainPM->Display (anObj, theMode);
1591 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1593 myMainPM->BeginImmediateDraw();
1594 myMainPM->Unhighlight (anObj, myDisplayMode);
1595 myMainPM->EndImmediateDraw (myMainVwr);
1597 if (aStatus->IsSubIntensityOn())
1599 myMainPM->Color (anObj, mySubIntensity, theMode);
1601 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1605 myDisplayMode = theMode;
1606 if (theToUpdateViewer)
1608 myMainVwr->Update();
1612 //=======================================================================
1613 //function : SetDisplayMode
1615 //=======================================================================
1616 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1617 const Standard_Integer theMode,
1618 const Standard_Boolean theToUpdateViewer)
1620 if (!theIObj->HasInteractiveContext())
1622 theIObj->SetContext(this);
1625 if (!myObjects.IsBound (theIObj))
1627 theIObj->SetDisplayMode (theMode);
1630 else if (!theIObj->AcceptDisplayMode (theMode))
1635 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1636 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1638 theIObj->SetDisplayMode (theMode);
1642 // erase presentations for all display modes different from <aMode>
1643 TColStd_ListOfInteger aModesToRemove;
1644 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1646 const Standard_Integer anOldMode = aDispModeIter.Value();
1647 if (anOldMode != theMode)
1649 aModesToRemove.Append (anOldMode);
1650 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1652 myMainPM->Unhighlight (theIObj, anOldMode);
1654 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1658 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1660 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1663 if (!aStatus->IsDModeIn (theMode))
1665 aStatus->AddDisplayMode (theMode);
1668 myMainPM->Display (theIObj, theMode);
1669 Standard_Integer aDispMode, aHiMode, aSelMode;
1670 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1671 if (aStatus->IsHilighted())
1673 myMainPM->Highlight (theIObj, aHiMode);
1675 if (aStatus->IsSubIntensityOn())
1677 myMainPM->Color (theIObj, mySubIntensity, theMode);
1680 if (theToUpdateViewer)
1682 myMainVwr->Update();
1684 theIObj->SetDisplayMode (theMode);
1687 //=======================================================================
1688 //function : UnsetDisplayMode
1690 //=======================================================================
1691 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1692 const Standard_Boolean theToUpdateViewer)
1694 if (theIObj.IsNull()
1695 || !theIObj->HasDisplayMode())
1700 if (!myObjects.IsBound (theIObj))
1702 theIObj->UnsetDisplayMode();
1706 const Standard_Integer anOldMode = theIObj->DisplayMode();
1707 if (myDisplayMode == anOldMode)
1712 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1713 aStatus->RemoveDisplayMode (anOldMode);
1714 if (!aStatus->IsDModeIn(myDisplayMode))
1716 aStatus->AddDisplayMode (myDisplayMode);
1719 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1721 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1723 myMainPM->Unhighlight (theIObj, anOldMode);
1725 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1726 myMainPM->Display (theIObj, myDisplayMode);
1728 Standard_Integer aDispMode, aHiMode, aSelMode;
1729 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1730 if (aStatus->IsHilighted())
1732 myMainPM->Highlight (theIObj, aHiMode);
1734 if (aStatus->IsSubIntensityOn())
1736 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1739 if (theToUpdateViewer)
1741 myMainVwr->Update();
1745 theIObj->UnsetDisplayMode();
1748 //=======================================================================
1749 //function : SetCurrentFacingModel
1751 //=======================================================================
1752 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1753 const Aspect_TypeOfFacingModel theModel)
1755 if (!theIObj.IsNull())
1757 theIObj->SetCurrentFacingModel (theModel);
1761 //=======================================================================
1762 //function : redisplayPrsRecModes
1764 //=======================================================================
1765 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1766 const Standard_Boolean theToUpdateViewer)
1768 if (theIObj->RecomputeEveryPrs())
1770 theIObj->Update (Standard_True);
1771 theIObj->UpdateSelection();
1775 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1777 theIObj->Update (aModes.Value(), Standard_False);
1779 theIObj->UpdateSelection();
1780 theIObj->SetRecomputeOk();
1783 if (theToUpdateViewer)
1785 UpdateCurrentViewer();
1789 //=======================================================================
1790 //function : redisplayPrsModes
1792 //=======================================================================
1793 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1794 const Standard_Boolean theToUpdateViewer)
1796 if (theIObj->RecomputeEveryPrs())
1798 theIObj->Update (Standard_True);
1799 theIObj->UpdateSelection();
1803 TColStd_ListOfInteger aModes;
1804 theIObj->ToBeUpdated (aModes);
1805 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1807 theIObj->Update (aModeIter.Value(), Standard_False);
1809 theIObj->SetRecomputeOk();
1812 if (theToUpdateViewer)
1814 UpdateCurrentViewer();
1818 //=======================================================================
1819 //function : SetColor
1821 //=======================================================================
1822 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1823 const Quantity_NameOfColor theColor,
1824 const Standard_Boolean theToUpdateViewer)
1826 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1829 //=======================================================================
1830 //function : SetColor
1832 //=======================================================================
1833 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1834 const Quantity_Color& theColor,
1835 const Standard_Boolean theToUpdateViewer)
1837 if (theIObj.IsNull())
1842 if (!theIObj->HasInteractiveContext())
1844 theIObj->SetContext (this);
1846 theIObj->SetColor (theColor);
1847 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1850 //=======================================================================
1851 //function : SetIsoOnTriangulation
1853 //=======================================================================
1854 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1855 const Handle(AIS_InteractiveObject)& theObject)
1857 if (theObject.IsNull())
1862 theObject->SetIsoOnTriangulation (theIsEnabled);
1865 //=======================================================================
1866 //function : SetDeviationCoefficient
1868 //=======================================================================
1869 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1870 const Standard_Real theCoefficient,
1871 const Standard_Boolean theToUpdateViewer)
1873 if (theIObj.IsNull())
1878 if (!theIObj->HasInteractiveContext())
1880 theIObj->SetContext (this);
1883 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1884 if (theIObj->Type() != AIS_KOI_Object
1885 && theIObj->Type() != AIS_KOI_Shape)
1889 else if (theIObj->Signature() != 0)
1894 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1895 aShape->SetOwnDeviationCoefficient (theCoefficient);
1896 redisplayPrsModes (theIObj, theToUpdateViewer);
1899 //=======================================================================
1900 //function : SetHLRDeviationCoefficient
1902 //=======================================================================
1903 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1904 const Standard_Real theCoefficient,
1905 const Standard_Boolean theToUpdateViewer)
1907 if (theIObj.IsNull())
1912 if (!theIObj->HasInteractiveContext())
1914 theIObj->SetContext (this);
1917 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1918 if (theIObj->Type() != AIS_KOI_Object
1919 && theIObj->Type() != AIS_KOI_Shape)
1923 else if (theIObj->Signature() != 0)
1928 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1929 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1930 redisplayPrsModes (theIObj, theToUpdateViewer);
1933 //=======================================================================
1934 //function : SetDeviationAngle
1936 //=======================================================================
1937 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1938 const Standard_Real theAngle,
1939 const Standard_Boolean theToUpdateViewer)
1941 if (theIObj.IsNull())
1946 if (!theIObj->HasInteractiveContext())
1948 theIObj->SetContext (this);
1951 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1952 if (theIObj->Type() != AIS_KOI_Shape)
1956 else if (theIObj->Signature() != 0)
1961 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1962 aShape->SetOwnDeviationAngle (theAngle);
1963 redisplayPrsModes (theIObj, theToUpdateViewer);
1966 //=======================================================================
1967 //function : SetAngleAndDeviation
1969 //=======================================================================
1970 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1971 const Standard_Real theAngle,
1972 const Standard_Boolean theToUpdateViewer)
1974 if (theIObj.IsNull())
1979 if (!theIObj->HasInteractiveContext())
1981 theIObj->SetContext (this);
1984 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1985 if (theIObj->Type() != AIS_KOI_Shape)
1989 if (theIObj->Signature() != 0)
1994 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1995 aShape->SetAngleAndDeviation (theAngle);
1997 if (theIObj->RecomputeEveryPrs())
1999 theIObj->Update (Standard_True);
2000 theIObj->UpdateSelection();
2004 Update (theIObj, theToUpdateViewer);
2008 //=======================================================================
2009 //function : SetHLRAngleAndDeviation
2011 //=======================================================================
2012 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
2013 const Standard_Real theAngle,
2014 const Standard_Boolean theToUpdateViewer)
2016 if (theIObj.IsNull())
2021 if (!theIObj->HasInteractiveContext())
2023 theIObj->SetContext (this);
2026 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2027 if (theIObj->Type() != AIS_KOI_Shape)
2031 if (theIObj->Signature() != 0)
2035 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2036 aShape->SetHLRAngleAndDeviation (theAngle);
2037 redisplayPrsModes (theIObj, theToUpdateViewer);
2040 //=======================================================================
2041 //function : SetHLRDeviationAngle
2043 //=======================================================================
2044 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2045 const Standard_Real theAngle,
2046 const Standard_Boolean theToUpdateViewer)
2048 if (theIObj.IsNull())
2053 if (!theIObj->HasInteractiveContext())
2055 theIObj->SetContext (this);
2058 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2059 if (theIObj->Type() != AIS_KOI_Shape)
2063 if (theIObj->Signature() != 0)
2067 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2068 aShape->SetOwnHLRDeviationAngle (theAngle);
2069 redisplayPrsModes (theIObj, theToUpdateViewer);
2072 //=======================================================================
2073 //function : UnsetColor
2075 //=======================================================================
2076 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2077 const Standard_Boolean theToUpdateViewer)
2079 if (theIObj.IsNull())
2084 theIObj->UnsetColor();
2085 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2088 //=======================================================================
2089 //function : HasColor
2091 //=======================================================================
2092 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2094 return theIObj->HasColor();
2097 //=======================================================================
2100 //=======================================================================
2101 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2103 return theIObj->Color();
2106 //=======================================================================
2109 //=======================================================================
2110 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2111 Quantity_Color& theColor) const
2113 theIObj->Color (theColor);
2116 //=======================================================================
2119 //=======================================================================
2120 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2122 return theIObj->Width();
2125 //=======================================================================
2126 //function : SetWidth
2128 //=======================================================================
2129 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2130 const Standard_Real theWidth,
2131 const Standard_Boolean theToUpdateViewer)
2133 if (theIObj.IsNull())
2138 if (!theIObj->HasInteractiveContext())
2140 theIObj->SetContext (this);
2143 theIObj->SetWidth (theWidth);
2144 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2145 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2147 if (myLastinMain->IsAutoHilight())
2149 const Standard_Integer aHiMode =
2150 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2151 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2155 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2160 //=======================================================================
2161 //function : UnsetWidth
2163 //=======================================================================
2164 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2165 const Standard_Boolean theToUpdateViewer)
2167 if (theIObj.IsNull())
2172 theIObj->UnsetWidth();
2173 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2176 //=======================================================================
2177 //function : SetMaterial
2179 //=======================================================================
2180 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2181 const Graphic3d_NameOfMaterial theName,
2182 const Standard_Boolean theToUpdateViewer)
2184 if (theIObj.IsNull())
2189 if (!theIObj->HasInteractiveContext())
2191 theIObj->SetContext (this);
2194 theIObj->SetMaterial (theName);
2195 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2198 //=======================================================================
2199 //function : UnsetMaterial
2201 //=======================================================================
2202 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2203 const Standard_Boolean theToUpdateViewer)
2205 if (theIObj.IsNull())
2209 theIObj->UnsetMaterial();
2210 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2213 //=======================================================================
2214 //function : SetTransparency
2216 //=======================================================================
2217 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2218 const Standard_Real theValue,
2219 const Standard_Boolean theToUpdateViewer)
2221 if (theIObj.IsNull())
2226 if (!theIObj->HasInteractiveContext())
2228 theIObj->SetContext (this);
2231 if (!theIObj->IsTransparent()
2232 && theValue <= 0.05)
2237 if (theValue <= 0.05)
2239 UnsetTransparency (theIObj, theToUpdateViewer);
2243 theIObj->SetTransparency (theValue);
2244 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2247 //=======================================================================
2248 //function : UnsetTransparency
2250 //=======================================================================
2251 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2252 const Standard_Boolean theToUpdateViewer)
2254 if (theIObj.IsNull())
2259 theIObj->UnsetTransparency();
2260 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2263 //=======================================================================
2264 //function : SetSelectedAspect
2266 //=======================================================================
2267 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2268 const Standard_Boolean theIsGlobalChange,
2269 const Standard_Boolean theToUpdateViewer)
2271 if (HasOpenedContext())
2276 Standard_Boolean isFound = Standard_False;
2277 Handle(AIS_Selection) aSelIter = AIS_Selection::Selection (myCurrentName.ToCString());
2278 for (aSelIter->Init(); aSelIter->More(); aSelIter->Next())
2280 isFound = Standard_True;
2281 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter->Value());
2282 anObj->SetAspect (theAspect, theIsGlobalChange);
2286 && theToUpdateViewer)
2288 myMainVwr->Update();
2292 //=======================================================================
2293 //function : SetLocalAttributes
2295 //=======================================================================
2296 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2297 const Handle(Prs3d_Drawer)& theDrawer,
2298 const Standard_Boolean theToUpdateViewer)
2300 if (theIObj.IsNull())
2305 if (!theIObj->HasInteractiveContext())
2307 theIObj->SetContext (this);
2310 theIObj->SetAttributes (theDrawer);
2311 Update (theIObj, theToUpdateViewer);
2314 //=======================================================================
2315 //function : UnsetLocalAttributes
2317 //=======================================================================
2318 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2319 const Standard_Boolean theToUpdateViewer)
2321 if (theIObj.IsNull())
2326 if (!theIObj->HasInteractiveContext())
2328 theIObj->SetContext (this);
2330 theIObj->UnsetAttributes();
2331 Update (theIObj, theToUpdateViewer);
2334 //=======================================================================
2337 //=======================================================================
2338 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2339 TCollection_ExtendedString& theStatus) const
2342 if (theIObj.IsNull()
2343 || !myObjects.IsBound (theIObj))
2348 theStatus += "\t ____________________________________________";
2349 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2350 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2351 switch (aStatus->GraphicStatus())
2353 case AIS_DS_Displayed:
2355 theStatus += "\t| -->Displayed\n";
2360 theStatus += "\t| -->Erased\n";
2367 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2368 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2370 theStatus += "\t|\t Mode ";
2371 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2374 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2376 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2377 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2379 theStatus += "\t\t Mode ";
2380 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2383 theStatus += "\t ____________________________________________";
2386 //=======================================================================
2387 //function : GetDefModes
2389 //=======================================================================
2390 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2391 Standard_Integer& theDispMode,
2392 Standard_Integer& theHiMode,
2393 Standard_Integer& theSelMode) const
2395 if (theIObj.IsNull())
2400 theDispMode = theIObj->HasDisplayMode()
2401 ? theIObj->DisplayMode()
2402 : (theIObj->AcceptDisplayMode (myDisplayMode)
2405 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2406 theSelMode = theIObj->GlobalSelectionMode();
2409 //=======================================================================
2410 //function : EraseGlobal
2412 //=======================================================================
2413 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2414 const Standard_Boolean theToUpdateviewer)
2416 if (theIObj.IsNull()
2417 || !myObjects.IsBound (theIObj))
2422 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2424 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2425 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2426 || aStatus->GraphicStatus() == AIS_DS_Erased)
2431 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2433 if (aStatus->IsHilighted())
2435 if (IsCurrent (theIObj))
2437 AddOrRemoveCurrentObject (theIObj, Standard_False);
2439 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2441 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2445 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2448 if (IsSelected (theIObj)
2449 && !aStatus->IsDModeIn (aDispMode))
2451 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2454 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2456 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2458 aStatus->ClearSelectionModes();
2459 aStatus->SetGraphicStatus (AIS_DS_Erased);
2461 if (theToUpdateviewer)
2463 myMainVwr->Update();
2467 //=======================================================================
2468 //function : unhighlightOwners
2470 //=======================================================================
2471 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2473 Handle(AIS_Selection) aSel = AIS_Selection::Selection (myCurrentName.ToCString());
2475 while (aSel->More())
2477 const Handle(SelectMgr_EntityOwner) anOwner =
2478 Handle(SelectMgr_EntityOwner)::DownCast (aSel->Value());
2479 if (anOwner->Selectable() == theObject)
2481 if (anOwner->IsSelected())
2483 AddOrRemoveSelected (anOwner, Standard_False);
2492 //=======================================================================
2493 //function : ClearGlobal
2495 //=======================================================================
2496 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2497 const Standard_Boolean theToUpdateviewer)
2499 if (theIObj.IsNull()
2500 || !myObjects.IsBound (theIObj))
2502 // for cases when reference shape of connected interactives was not displayed
2503 // but its selection primitives were calculated
2504 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2505 mgrSelector->Remove (anObj);
2509 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2510 unhighlightOwners (theIObj);
2511 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2513 myMainPM->Erase (theIObj, aDispModeIter.Value());
2514 myMainPM->Clear (theIObj, aDispModeIter.Value());
2517 // Object removes from Detected sequence
2518 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2520 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2522 && anObj != theIObj)
2524 myAISDetectedSeq.Remove (aDetIter);
2528 // remove IO from the selection manager to avoid memory leaks
2529 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2530 mgrSelector->Remove (anObj);
2532 myObjects.UnBind (theIObj);
2533 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2534 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2536 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2539 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2540 myLastinMain.Nullify();
2541 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2542 myLastPicked.Nullify();
2543 myMainPM->ClearImmediateDraw();
2545 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2547 myMainVwr->Update();
2551 //=======================================================================
2552 //function : ClearGlobalPrs
2554 //=======================================================================
2555 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2556 const Standard_Integer theMode,
2557 const Standard_Boolean theToUpdateViewer)
2559 if (theIObj.IsNull()
2560 || !myObjects.IsBound (theIObj))
2565 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2566 if (aStatus->IsDModeIn (theMode))
2568 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2569 if (aDispMode == theMode
2570 && myMainPM->IsHighlighted (theIObj, theMode))
2572 myMainPM->Unhighlight (theIObj, theMode);
2575 myMainPM->Erase (theIObj, theMode);
2576 myMainPM->Clear (theIObj, theMode);
2579 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2580 && theToUpdateViewer)
2582 myMainVwr->Update();
2586 //=======================================================================
2587 //function : DrawHiddenLine
2589 //=======================================================================
2590 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2592 return myDefaultDrawer->DrawHiddenLine();
2595 //=======================================================================
2596 //function : EnableDrawHiddenLine
2598 //=======================================================================
2599 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2601 myDefaultDrawer->EnableDrawHiddenLine();
2604 //=======================================================================
2605 //function : DisableDrawHiddenLine
2607 //=======================================================================
2608 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2610 myDefaultDrawer->DisableDrawHiddenLine();
2613 //=======================================================================
2614 //function : HiddenLineAspect
2616 //=======================================================================
2617 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2619 return myDefaultDrawer->HiddenLineAspect();
2622 //=======================================================================
2623 //function : SetHiddenLineAspect
2625 //=======================================================================
2626 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2628 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2631 //=======================================================================
2632 //function : SetIsoNumber
2634 //=======================================================================
2635 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2636 const AIS_TypeOfIso theType)
2641 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2644 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2647 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2648 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2653 //=======================================================================
2654 //function : IsoNumber
2656 //=======================================================================
2657 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2661 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2662 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2663 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2664 ? myDefaultDrawer->UIsoAspect()->Number()
2670 //=======================================================================
2671 //function : IsoOnPlane
2673 //=======================================================================
2674 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2676 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2679 //=======================================================================
2680 //function : IsoOnPlane
2682 //=======================================================================
2683 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2685 return myDefaultDrawer->IsoOnPlane();
2688 //=======================================================================
2689 //function : IsoOnTriangulation
2691 //=======================================================================
2692 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2694 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2697 //=======================================================================
2698 //function : IsoOnTriangulation
2700 //=======================================================================
2701 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2703 return myDefaultDrawer->IsoOnTriangulation();
2706 //function : SetPixelTolerance
2707 //purpose : Disables the mechanism of adaptive tolerance calculation in
2708 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2709 // sensitive entities activated. For more information, see
2710 // SelectMgr_ViewerSelector.hxx
2711 //=======================================================================
2712 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2714 if (HasOpenedContext())
2716 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2720 myMainSel->SetPixelTolerance (thePrecision);
2724 //=======================================================================
2725 //function : PixelTolerance
2727 //=======================================================================
2728 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2730 return HasOpenedContext()
2731 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2732 : myMainSel->PixelTolerance();
2735 //=======================================================================
2736 //function : SetSelectionSensitivity
2737 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2738 //=======================================================================
2739 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2740 const Standard_Integer theMode,
2741 const Standard_Integer theNewSensitivity)
2743 if (HasOpenedContext())
2745 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2749 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2752 //=======================================================================
2753 //function : IsInLocal
2755 //=======================================================================
2756 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2757 Standard_Integer& theIndex) const
2759 if (theIObj.IsNull())
2761 return Standard_False;
2764 // if it exists at neutral point 0 index is returned
2765 if (myObjects.IsBound (theIObj))
2768 return Standard_False;
2771 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2773 if (myLocalContexts.IsBound (aCtxIter))
2775 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2777 theIndex = aCtxIter;
2778 return Standard_True;
2783 return Standard_False;
2786 //=======================================================================
2787 //function : InitAttributes
2789 //=======================================================================
2790 void AIS_InteractiveContext::InitAttributes()
2792 mgrSelector->Add (myMainSel);
2793 myCurrentName = AIS_Context_NewCurName();
2794 mySelectionName = AIS_Context_NewSelName();
2796 AIS_Selection::CreateSelection (mySelectionName.ToCString());
2797 AIS_Selection::CreateSelection (myCurrentName.ToCString());
2799 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2800 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2801 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2803 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2804 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2805 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2806 aLineAspect->SetWidth (1.0);
2807 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2809 // tolerance to 2 pixels...
2810 SetPixelTolerance (2);
2812 // Customizing the drawer for trihedrons and planes...
2813 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2814 const Standard_Real aLength = 100.0;
2815 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2816 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2817 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2818 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2819 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2821 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2822 const Standard_Real aPlaneLength = 200.0;
2823 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2824 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2827 //=======================================================================
2828 //function : TrihedronSize
2830 //=======================================================================
2831 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2833 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2836 //=======================================================================
2837 //function : SetTrihedronSize
2839 //=======================================================================
2840 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2841 const Standard_Boolean /*updateviewer*/)
2843 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2844 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2845 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2848 //=======================================================================
2849 //function : SetPlaneSize
2851 //=======================================================================
2852 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2853 const Standard_Real theValY,
2854 const Standard_Boolean /*updateviewer*/)
2856 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2857 Redisplay (AIS_KOI_Datum, 7);
2860 //=======================================================================
2861 //function : SetPlaneSize
2863 //=======================================================================
2864 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2865 const Standard_Boolean theToUpdateViewer)
2867 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2870 //=======================================================================
2871 //function : PlaneSize
2873 //=======================================================================
2874 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2875 Standard_Real& theY) const
2877 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2878 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2879 return (Abs (theX - theY) <= Precision::Confusion());
2882 //=======================================================================
2883 //function : SetAutoActivateSelection
2885 //=======================================================================
2886 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2888 myIsAutoActivateSelMode = theIsAuto;
2891 //=======================================================================
2892 //function : GetAutoActivateSelection
2894 //=======================================================================
2895 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2897 return myIsAutoActivateSelMode;
2900 //=======================================================================
2901 //function : SetZLayer
2903 //=======================================================================
2904 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2905 const Standard_Integer theLayerId)
2907 if (theIObj.IsNull())
2910 theIObj->SetZLayer (theLayerId);
2913 //=======================================================================
2914 //function : GetZLayer
2916 //=======================================================================
2917 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2919 return !theIObj.IsNull()
2921 : Graphic3d_ZLayerId_UNKNOWN;
2924 //=======================================================================
2925 //function : RebuildSelectionStructs
2926 //purpose : Rebuilds 1st level of BVH selection forcibly
2927 //=======================================================================
2928 void AIS_InteractiveContext::RebuildSelectionStructs()
2930 myMainSel->RebuildObjectsTree (Standard_True);
2933 //=======================================================================
2934 //function : Disconnect
2935 //purpose : Disconnects selectable object from an assembly and updates selection structures
2936 //=======================================================================
2937 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2938 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2940 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2942 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2943 theObj->Disconnect (theObjToDisconnect);
2944 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2945 mgrSelector->Remove (anObj);
2947 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2949 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2950 theObj->Disconnect();
2951 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2952 mgrSelector->Remove (anObj);
2958 //=======================================================================
2959 //function : FitSelected
2960 //purpose : Fits the view corresponding to the bounds of selected objects
2961 //=======================================================================
2962 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2963 const Standard_Real theMargin,
2964 const Standard_Boolean theToUpdate)
2966 Standard_CString aSelName = HasOpenedContext() ?
2967 myLocalContexts (myCurLocalIndex)->SelectionName().ToCString()
2968 : myCurrentName.ToCString();
2970 Bnd_Box aBndSelected;
2972 const Handle(AIS_Selection)& aSelection = AIS_Selection::Selection (aSelName);
2973 AIS_MapOfObjectOwners anObjectOwnerMap;
2974 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2976 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2977 if (!anObj.IsNull())
2979 if (anObj->IsInfinite())
2983 anObj->BoundingBox (aTmpBnd);
2984 aBndSelected.Add (aTmpBnd);
2988 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2989 if (anOwner.IsNull())
2992 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2993 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2995 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2996 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2999 anOwnerMap->Add (anOwner);
3003 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
3005 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
3006 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
3007 aBndSelected.Add (aTmpBox);
3010 anObjectOwnerMap.Clear();
3012 if (aBndSelected.IsVoid())
3015 theView->FitAll (aBndSelected, theMargin, theToUpdate);