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->Select();
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())
139 //=======================================================================
140 //function : DomainOfMainViewer
142 //=======================================================================
144 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const
146 return myMainVwr->Domain();
150 //=======================================================================
151 //function : DisplayedObjects
153 //=======================================================================
154 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
155 const Standard_Boolean theOnlyFromNeutral) const
157 if (!HasOpenedContext()
158 || theOnlyFromNeutral)
160 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
162 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
164 theListOfIO.Append (anObjIter.Key());
171 TColStd_MapOfTransient aDispMap;
172 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
174 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
176 aDispMap.Add (anObjIter.Key());
180 // parse all local contexts...
181 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
183 const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
184 aLocCtx->DisplayedObjects (aDispMap);
187 Handle(AIS_InteractiveObject) anObj;
188 for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
190 const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
191 anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
192 theListOfIO.Append (anObj);
196 //=======================================================================
197 //function : DisplayedObjects
199 //=======================================================================
200 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
201 const Standard_Integer theSign,
202 AIS_ListOfInteractive& theListOfIO,
203 const Standard_Boolean /*OnlyFromNeutral*/) const
205 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
208 //=======================================================================
209 //function : ErasedObjects
211 //=======================================================================
212 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
214 ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
217 //=======================================================================
218 //function : ErasedObjects
220 //=======================================================================
221 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
222 const Standard_Integer theSign,
223 AIS_ListOfInteractive& theListOfIO) const
225 ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
228 //=======================================================================
229 //function : ObjectsByDisplayStatus
231 //=======================================================================
232 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
233 AIS_ListOfInteractive& theListOfIO) const
235 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
237 if (anObjIter.Value()->GraphicStatus() == theStatus)
239 theListOfIO.Append (anObjIter.Key());
244 //=======================================================================
245 //function : ObjectsByDisplayStatus
247 //=======================================================================
248 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
249 const Standard_Integer theSign,
250 const AIS_DisplayStatus theStatus,
251 AIS_ListOfInteractive& theListOfIO) const
253 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
255 if (theStatus != AIS_DS_None
256 && anObjIter.Value()->GraphicStatus() != theStatus)
260 else if (anObjIter.Key()->Type() != theKind)
266 || anObjIter.Key()->Signature() == theSign)
268 theListOfIO.Append (anObjIter.Key());
273 //=======================================================================
274 //function : ObjectsInside
276 //=======================================================================
277 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive& theListOfIO,
278 const AIS_KindOfInteractive theKind,
279 const Standard_Integer theSign) const
281 if (theKind == AIS_KOI_None
284 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
286 theListOfIO.Append (anObjIter.Key());
291 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
293 if (anObjIter.Key()->Type() != theKind)
299 || anObjIter.Key()->Signature() == theSign)
301 theListOfIO.Append (anObjIter.Key());
306 //=======================================================================
307 //function : ObjectsForView
309 //=======================================================================
310 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO,
311 const Handle(V3d_View)& theView,
312 const Standard_Boolean theIsVisibleInView,
313 const AIS_DisplayStatus theStatus) const
315 Handle(Graphic3d_CView) aViewImpl = theView->View();
316 const Standard_Integer aViewId = aViewImpl->Identification();
317 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
319 if (theStatus != AIS_DS_None
320 && anObjIter.Value()->GraphicStatus() != theStatus)
322 theListOfIO.Append (anObjIter.Key());
326 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
327 const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
328 if (isVisible == theIsVisibleInView)
330 theListOfIO.Append (anObjIter.Key());
335 //=======================================================================
338 //=======================================================================
339 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
340 const Standard_Boolean theToUpdateViewer)
342 if (theIObj.IsNull())
347 Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
348 GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
350 Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
351 theToUpdateViewer, theIObj->AcceptShapeDecomposition());
354 //=======================================================================
355 //function : SetViewAffinity
357 //=======================================================================
358 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
359 const Handle(V3d_View)& theView,
360 const Standard_Boolean theIsVisible)
363 || !myObjects.IsBound (theIObj))
368 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
369 Handle(Graphic3d_CView) aViewImpl = theView->View();
370 anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
373 theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
377 theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
381 //=======================================================================
384 //=======================================================================
385 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
386 const Standard_Integer theDispMode,
387 const Standard_Integer theSelectionMode,
388 const Standard_Boolean theToUpdateViewer,
389 const Standard_Boolean theToAllowDecomposition,
390 const AIS_DisplayStatus theDispStatus)
392 if (theIObj.IsNull())
397 if (theDispStatus == AIS_DS_Erased)
399 Erase (theIObj, theToUpdateViewer);
400 Load (theIObj, theSelectionMode, theToAllowDecomposition);
404 if (!theIObj->HasInteractiveContext())
406 theIObj->SetContext (this);
409 if (theDispStatus == AIS_DS_Temporary
410 && !HasOpenedContext())
414 else if (HasOpenedContext())
416 if (theDispStatus == AIS_DS_None
417 || theDispStatus == AIS_DS_Temporary)
419 myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
420 if (theToUpdateViewer)
428 if (!myObjects.IsBound (theIObj))
430 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
431 myObjects.Bind (theIObj, aStatus);
432 Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
433 myMainPM->Display(theIObj, theDispMode);
434 if (theSelectionMode != -1)
436 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
437 if (!mgrSelector->Contains (anObj))
439 mgrSelector->Load (theIObj);
441 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
446 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
447 if (aStatus->GraphicStatus() == AIS_DS_Temporary)
452 // Mark the presentation modes hidden of interactive object different from aDispMode.
453 // Then make sure aDispMode is displayed and maybe highlighted.
454 // Finally, activate selection mode <SelMode> if not yet activated.
455 TColStd_ListOfInteger aModesToRemove;
456 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
458 const Standard_Integer anOldMode = aDispModeIter.Value();
459 if (anOldMode != theDispMode)
461 aModesToRemove.Append (anOldMode);
462 if(myMainPM->IsHighlighted (theIObj, anOldMode))
464 myMainPM->Unhighlight (theIObj, anOldMode);
466 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
470 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
472 aStatus->RemoveDisplayMode (aRemModeIter.Value());
475 if (!aStatus->IsDModeIn (theDispMode))
477 aStatus->AddDisplayMode (theDispMode);
480 myMainPM->Display (theIObj, theDispMode);
481 aStatus->SetGraphicStatus (AIS_DS_Displayed);
482 if (aStatus->IsHilighted())
484 const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
485 myMainPM->Color (theIObj, aStatus->HilightColor(), aHiMod);
487 if (theSelectionMode != -1)
489 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
490 if (!mgrSelector->Contains (anObj))
492 mgrSelector->Load (theIObj);
494 if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
496 if (!aStatus->IsSModeIn (theSelectionMode))
497 aStatus->AddSelectionMode (theSelectionMode);
498 mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
503 if (theToUpdateViewer)
509 //=======================================================================
512 //=======================================================================
513 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
514 const Standard_Integer theSelMode,
515 const Standard_Boolean theToAllowDecomposition)
517 if (theIObj.IsNull())
522 if (!theIObj->HasInteractiveContext())
524 theIObj->SetContext (this);
527 if (HasOpenedContext())
529 myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
534 && !theToAllowDecomposition)
536 if (!myObjects.IsBound (theIObj))
538 Standard_Integer aDispMode, aHiMod, aSelModeDef;
539 GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
540 Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
541 myObjects.Bind (theIObj, aStatus);
544 // Register theIObj in the selection manager to prepare further activation of selection
545 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
546 if (!mgrSelector->Contains (anObj))
548 mgrSelector->Load (theIObj);
553 //=======================================================================
556 //=======================================================================
557 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
558 const Standard_Boolean theToUpdateViewer)
560 if (theIObj.IsNull())
565 if (!theIObj->IsAutoHilight())
567 theIObj->ClearSelected();
570 Standard_Boolean wasInCtx = Standard_False;
571 if (HasOpenedContext())
573 // First it is checked if it is possible to remove in the current local context
574 // then one tries to remove in other local contexts, if they allow it...
575 wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
576 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
578 if (aCtxIter.Value()->AcceptErase())
580 wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
587 EraseGlobal (theIObj, Standard_False);
590 if (theToUpdateViewer)
596 //=======================================================================
597 //function : EraseAll
599 //=======================================================================
600 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
602 if (HasOpenedContext())
607 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
609 if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
611 Erase (anObjIter.Key(), Standard_False);
615 if (theToUpdateViewer)
621 //=======================================================================
622 //function : DisplayAll
624 //=======================================================================
625 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
627 if (HasOpenedContext())
632 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
634 const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
635 if (aStatus == AIS_DS_Erased)
637 Display (anObjIter.Key(), Standard_False);
641 if (theToUpdateViewer)
647 //=======================================================================
648 //function : DisplaySelected
650 //=======================================================================
651 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
653 if (HasOpenedContext())
658 Standard_Boolean isFound = Standard_False;
659 for (mySelection->Init(); mySelection->More(); mySelection->Next())
661 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
662 Display (anObj, Standard_False);
663 isFound = Standard_True;
666 if (isFound && theToUpdateViewer)
672 //=======================================================================
673 //function : EraseSelected
675 //=======================================================================
676 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
678 if (HasOpenedContext())
683 Standard_Boolean isFound = Standard_False;
685 while (mySelection->More())
687 Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
688 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
690 Erase (anObj, Standard_False);
691 isFound = Standard_True;
696 if (isFound && theToUpdateViewer)
702 //=======================================================================
705 //=======================================================================
707 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
708 const Standard_Integer WhichContext)
710 if(anIObj.IsNull()) return Standard_False;
712 if(!HasOpenedContext()) return Standard_False;
713 if(myObjects.IsBound(anIObj)) return Standard_False;
714 if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
716 // Protection : if one tries to preserve a temporary object
717 // which is not in the local active context... rob 11-06-97
719 Standard_Integer IsItInLocal = myCurLocalIndex;
720 Standard_Boolean Found(Standard_False);
722 while(IsItInLocal>0 && !Found){
723 if(!myLocalContexts.IsBound(IsItInLocal))
725 else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
726 Found = Standard_True;
731 if(!Found) return Standard_False;
734 // const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ?
735 // myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
737 // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
738 Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
742 if(LS->IsTemporary()){
743 Standard_Integer DM,HM,SM;
744 GetDefModes(anIObj,DM,HM,SM);
746 SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
747 if(LS->DisplayMode()!= DM ){
748 Standard_Integer LSM = LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
749 myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
752 Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
756 // GS->SubIntensityOn();
757 myObjects.Bind(anIObj,GS);
758 mgrSelector->Load(anIObj);
759 mgrSelector->Activate(anIObj,SM,myMainSel);
761 LS->SetTemporary(Standard_False);
763 return Standard_True;
766 //=======================================================================
767 //function : DisplayStatus
769 //=======================================================================
770 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
772 if (theIObj.IsNull())
776 else if (myObjects.IsBound (theIObj))
778 return myObjects (theIObj)->GraphicStatus();
781 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
783 if (aCtxIter.Value()->IsIn (theIObj))
785 return AIS_DS_Temporary;
791 //=======================================================================
792 //function : DisplayedModes
794 //=======================================================================
795 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
797 return myObjects (theIObj)->DisplayedModes();
800 //=======================================================================
803 //=======================================================================
804 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
805 const Standard_Boolean theToUpdateViewer)
807 if (theIObj.IsNull())
812 if (HasOpenedContext())
814 myLocalContexts (myCurLocalIndex)->Remove (theIObj);
815 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
817 if (aCtxIter.Value()->AcceptErase())
819 aCtxIter.Value()->Remove (theIObj);
824 ClearGlobal (theIObj, theToUpdateViewer);
827 //=======================================================================
828 //function : RemoveAll
830 //=======================================================================
831 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
833 AIS_ListOfInteractive aList;
834 ObjectsInside (aList);
835 for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
837 Remove (aListIterator.Value(), Standard_False);
840 if (theToUpdateViewer)
846 //=======================================================================
847 //function : ClearPrs
849 //=======================================================================
850 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
851 const Standard_Integer theMode,
852 const Standard_Boolean theToUpdateViewer)
854 if (theIObj.IsNull())
859 if (!HasOpenedContext())
861 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
865 Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
866 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
868 if (aCtxIter.Value()->AcceptErase())
870 wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
875 ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
877 else if (theToUpdateViewer)
883 //=======================================================================
886 //=======================================================================
887 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
888 const Standard_Boolean theToUpdateViewer)
890 if (theIObj.IsNull())
895 if (!theIObj->HasInteractiveContext())
897 theIObj->SetContext (this);
899 if (!HasOpenedContext())
901 if (!myObjects.IsBound (theIObj))
906 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
907 aStatus->SetHilightStatus (Standard_True);
908 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
910 Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
911 myMainPM->Highlight (theIObj, aHilightMode);
916 myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
919 if (theToUpdateViewer)
924 //=======================================================================
927 //=======================================================================
929 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
930 const Quantity_NameOfColor aCol,
931 const Standard_Boolean updateviewer)
933 if(anIObj.IsNull()) return;
935 if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
937 if (!HasOpenedContext())
939 if(!myObjects.IsBound(anIObj)) return;
941 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
942 aStatus->SetHilightStatus (Standard_True);
944 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
946 const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
947 myMainPM->Color (anIObj, aCol, aHilightMode);
948 aStatus->SetHilightColor (aCol);
953 myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
955 if(updateviewer) myMainVwr->Update();
958 //=======================================================================
959 //function : Unhilight
961 //=======================================================================
963 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
965 if(anIObj.IsNull()) return;
967 if (!HasOpenedContext())
969 if(!myObjects.IsBound(anIObj)) return;
971 const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
972 aStatus->SetHilightStatus (Standard_False);
973 aStatus->SetHilightColor(Quantity_NOC_WHITE);
975 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
977 Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
978 myMainPM->Unhighlight (anIObj, aHilightMode);
983 myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
985 if(updateviewer) myMainVwr->Update();
988 //=======================================================================
989 //function : IsHilighted
991 //=======================================================================
993 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const
995 if(anIObj.IsNull()) return Standard_False;
997 if (!HasOpenedContext()){
998 if(!myObjects.IsBound(anIObj))
999 return Standard_False;
1000 return myObjects(anIObj)->IsHilighted();
1002 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1003 for(;ItM.More();ItM.Next()){
1004 if(ItM.Value()->IsHilighted(anIObj))
1005 return Standard_True;
1007 return Standard_False;
1010 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1011 Standard_Boolean& WithColor,
1012 Quantity_NameOfColor& TheHiCol) const
1014 if(!HasOpenedContext()){
1015 if(myObjects.IsBound(anIObj)){
1016 const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1017 if(STAT->IsHilighted()){
1018 if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1019 WithColor=Standard_True;
1020 TheHiCol = STAT->HilightColor();
1023 WithColor = Standard_False;
1024 return Standard_True;
1027 return Standard_False;
1029 Standard_Integer MaxIndex = HighestIndex();
1030 for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1031 if(myLocalContexts.IsBound(i)){
1032 if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1033 return Standard_True;
1037 return Standard_False;
1040 //=======================================================================
1041 //function : IsHilighted
1042 //purpose : Returns true if the objects global status is set to highlighted.
1043 // theIsCustomColor flag defines if highlight color is not equal to OCCT's
1044 // default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1045 // custom highlight color name will be stored to theCustomColorName
1046 //=======================================================================
1047 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1048 Standard_Boolean& theIsCustomColor,
1049 Quantity_NameOfColor& theCustomColorName) const
1051 if (theOwner.IsNull() || !theOwner->HasSelectable())
1052 return Standard_False;
1054 const Handle(AIS_InteractiveObject) anObj =
1055 Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1057 if (!myObjects.IsBound (anObj))
1058 return Standard_False;
1060 const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1061 if (anObjStatus->IsHilighted())
1063 if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1065 theIsCustomColor = Standard_True;
1066 theCustomColorName = anObjStatus->HilightColor();
1070 theIsCustomColor = Standard_False;
1073 return Standard_True;
1076 return Standard_False;
1079 //=======================================================================
1080 //function : IsDisplayed
1082 //=======================================================================
1084 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const
1086 if(anIObj.IsNull()) return Standard_False;
1089 if(myObjects.IsBound(anIObj))
1090 if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1091 return Standard_True;
1093 AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1094 for(;ItM.More();ItM.Next()){
1095 if(ItM.Value()->IsDisplayed(anIObj))
1096 return Standard_True;
1098 return Standard_False;
1102 //=======================================================================
1103 //function : IsDisplayed
1105 //=======================================================================
1106 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1107 const Standard_Integer theMode) const
1109 if (theIObj.IsNull())
1111 return Standard_False;
1114 if (myObjects.IsBound (theIObj))
1116 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1117 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1118 && aStatus->IsDModeIn (theMode))
1120 return Standard_True;
1124 for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1126 if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1128 return Standard_True;
1131 return Standard_False;
1134 //=======================================================================
1135 //function : DisplayPriority
1137 //=======================================================================
1138 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1140 if (theIObj.IsNull())
1144 else if (!myObjects.IsBound (theIObj))
1149 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1150 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1151 || aStatus->GraphicStatus() == AIS_DS_Erased)
1153 Standard_Integer aDispMode = theIObj->HasDisplayMode()
1154 ? theIObj->DisplayMode()
1155 : (theIObj->AcceptDisplayMode (myDisplayMode)
1158 return myMainPM->DisplayPriority (theIObj, aDispMode);
1163 //=======================================================================
1164 //function : SetDisplayPriority
1166 //=======================================================================
1167 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1168 const Standard_Integer thePriority)
1170 if (theIObj.IsNull())
1175 if (!theIObj->HasInteractiveContext())
1177 theIObj->SetContext (this);
1180 if (myObjects.IsBound (theIObj))
1182 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1183 if (aStatus->GraphicStatus() == AIS_DS_Displayed
1184 || aStatus->GraphicStatus() == AIS_DS_Erased)
1186 Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1187 ? theIObj->DisplayMode()
1188 : (theIObj->AcceptDisplayMode (myDisplayMode)
1191 myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1194 else if (HasOpenedContext())
1196 myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1200 //=======================================================================
1201 //function : Redisplay
1203 //=======================================================================
1204 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1205 const Standard_Boolean theToUpdateViewer,
1206 const Standard_Boolean theAllModes)
1208 RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1209 RecomputeSelectionOnly (theIObj);
1212 //=======================================================================
1213 //function : Redisplay
1215 //=======================================================================
1216 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1217 const Standard_Integer /*theSign*/,
1218 const Standard_Boolean theToUpdateViewer)
1220 Standard_Boolean isRedisplayed = Standard_False;
1221 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1223 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1224 if (anObj->Type() != theKOI)
1229 Redisplay (anObj, Standard_False);
1230 isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1234 if (theToUpdateViewer
1237 myMainVwr->Update();
1241 //=======================================================================
1242 //function : RecomputePrsOnly
1244 //=======================================================================
1245 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1246 const Standard_Boolean theToUpdateViewer,
1247 const Standard_Boolean theAllModes)
1249 if (theIObj.IsNull())
1254 theIObj->Update (theAllModes);
1255 if (!theToUpdateViewer)
1260 if (HasOpenedContext()
1261 || (myObjects.IsBound (theIObj)
1262 && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1264 myMainVwr->Update();
1267 //=======================================================================
1268 //function : RecomputeSelectionOnly
1270 //=======================================================================
1271 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1278 mgrSelector->RecomputeSelection (theIO);
1280 if (HasOpenedContext())
1282 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1284 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1289 if (!myObjects.IsBound (theIO) ||
1290 myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1295 TColStd_ListOfInteger aModes;
1296 ActivatedModes (theIO, aModes);
1297 TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1298 for (; aModesIter.More(); aModesIter.Next())
1300 mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1304 //=======================================================================
1307 //=======================================================================
1308 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1309 const Standard_Boolean theUpdateViewer)
1311 if (theIObj.IsNull())
1316 TColStd_ListOfInteger aPrsModes;
1317 theIObj->ToBeUpdated (aPrsModes);
1318 for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1320 theIObj->Update (aPrsModesIt.Value(), Standard_False);
1323 mgrSelector->Update(theIObj);
1325 for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1327 myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1330 if (theUpdateViewer)
1332 if (!myObjects.IsBound (theIObj))
1337 switch (myObjects (theIObj)->GraphicStatus())
1339 case AIS_DS_Displayed:
1340 case AIS_DS_Temporary:
1341 myMainVwr->Update();
1349 //=======================================================================
1350 //function : SetLocation
1352 //=======================================================================
1353 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1354 const TopLoc_Location& theLoc)
1356 if (theIObj.IsNull())
1361 if (theIObj->HasTransformation()
1362 && theLoc.IsIdentity())
1364 theIObj->ResetTransformation();
1365 mgrSelector->Update (theIObj, Standard_False);
1368 else if (theLoc.IsIdentity())
1373 // first reset the previous location to properly clean everything...
1374 if (theIObj->HasTransformation())
1376 theIObj->ResetTransformation();
1379 theIObj->SetLocalTransformation (theLoc.Transformation());
1381 if (!HasOpenedContext())
1383 mgrSelector->Update (theIObj, Standard_False);
1387 Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1388 mgrSelector->Update (theIObj, aTempSel, Standard_False);
1391 // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1392 // to its highlight structure immediately
1393 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
1395 myLastPicked->UpdateHighlightTrsf (myMainVwr,
1397 theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1401 //=======================================================================
1402 //function : ResetLocation
1404 //=======================================================================
1405 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1407 if (theIObj.IsNull())
1412 theIObj->ResetTransformation();
1413 mgrSelector->Update (theIObj, Standard_False);
1416 //=======================================================================
1417 //function : HasLocation
1419 //=======================================================================
1420 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1422 return !theIObj.IsNull()
1423 && theIObj->HasTransformation();
1426 //=======================================================================
1427 //function : Location
1429 //=======================================================================
1430 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1432 return theIObj->Transformation();
1435 //=======================================================================
1436 //function : SetDeviationCoefficient
1438 //=======================================================================
1439 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1441 myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1444 //=======================================================================
1445 //function : SetDeviationAngle
1447 //=======================================================================
1448 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1450 myDefaultDrawer->SetDeviationAngle (theAngle);
1453 //=======================================================================
1454 //function : DeviationAngle
1455 //purpose : Gets deviationAngle
1456 //=======================================================================
1457 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1459 return myDefaultDrawer->DeviationAngle();
1462 //=======================================================================
1463 //function : DeviationCoefficient
1465 //=======================================================================
1466 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1468 return myDefaultDrawer->DeviationCoefficient();
1471 //=======================================================================
1472 //function : SetHLRDeviationCoefficient
1474 //=======================================================================
1475 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1477 myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1480 //=======================================================================
1481 //function : HLRDeviationCoefficient
1483 //=======================================================================
1484 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1486 return myDefaultDrawer->HLRDeviationCoefficient();
1489 //=======================================================================
1490 //function : SetHLRAngle
1492 //=======================================================================
1493 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1495 myDefaultDrawer->SetHLRAngle (theAngle);
1498 //=======================================================================
1499 //function : SetHLRAngleAndDeviation
1500 //purpose : compute with anangle a HLRAngle and a HLRDeviationCoefficient
1501 // and set them in myHLRAngle and in myHLRDeviationCoefficient
1502 // of myDefaultDrawer
1503 //=======================================================================
1504 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1506 Standard_Real anOutAngl, anOutDefl;
1507 HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1509 myDefaultDrawer->SetHLRAngle (anOutAngl);
1510 myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1513 //=======================================================================
1514 //function : HLRAngle
1516 //=======================================================================
1517 Standard_Real AIS_InteractiveContext::HLRAngle() const
1519 return myDefaultDrawer->HLRAngle();
1522 //=======================================================================
1523 //function : SetDisplayMode
1525 //=======================================================================
1526 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode theMode,
1527 const Standard_Boolean theToUpdateViewer)
1529 if (theMode == myDisplayMode)
1534 for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1536 Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1537 Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1538 || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1539 || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1542 || anObj->HasDisplayMode()
1543 || !anObj->AcceptDisplayMode (theMode))
1548 Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1549 if (aStatus->IsDModeIn (myDisplayMode))
1551 aStatus->RemoveDisplayMode (myDisplayMode);
1554 aStatus->AddDisplayMode (theMode);
1555 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1557 myMainPM->Display (anObj, theMode);
1558 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1560 myMainPM->BeginImmediateDraw();
1561 myMainPM->Unhighlight (anObj, myDisplayMode);
1562 myMainPM->EndImmediateDraw (myMainVwr);
1564 if (aStatus->IsSubIntensityOn())
1566 myMainPM->Color (anObj, mySubIntensity, theMode);
1568 myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1572 myDisplayMode = theMode;
1573 if (theToUpdateViewer)
1575 myMainVwr->Update();
1579 //=======================================================================
1580 //function : SetDisplayMode
1582 //=======================================================================
1583 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1584 const Standard_Integer theMode,
1585 const Standard_Boolean theToUpdateViewer)
1587 if (!theIObj->HasInteractiveContext())
1589 theIObj->SetContext(this);
1592 if (!myObjects.IsBound (theIObj))
1594 theIObj->SetDisplayMode (theMode);
1597 else if (!theIObj->AcceptDisplayMode (theMode))
1602 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1603 if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1605 theIObj->SetDisplayMode (theMode);
1609 // erase presentations for all display modes different from <aMode>
1610 TColStd_ListOfInteger aModesToRemove;
1611 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1613 const Standard_Integer anOldMode = aDispModeIter.Value();
1614 if (anOldMode != theMode)
1616 aModesToRemove.Append (anOldMode);
1617 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1619 myMainPM->Unhighlight (theIObj, anOldMode);
1621 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1625 for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1627 aStatus->RemoveDisplayMode (aRemModeIter.Value());
1630 if (!aStatus->IsDModeIn (theMode))
1632 aStatus->AddDisplayMode (theMode);
1635 myMainPM->Display (theIObj, theMode);
1636 Standard_Integer aDispMode, aHiMode, aSelMode;
1637 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1638 if (aStatus->IsHilighted())
1640 myMainPM->Highlight (theIObj, aHiMode);
1642 if (aStatus->IsSubIntensityOn())
1644 myMainPM->Color (theIObj, mySubIntensity, theMode);
1647 if (theToUpdateViewer)
1649 myMainVwr->Update();
1651 theIObj->SetDisplayMode (theMode);
1654 //=======================================================================
1655 //function : UnsetDisplayMode
1657 //=======================================================================
1658 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1659 const Standard_Boolean theToUpdateViewer)
1661 if (theIObj.IsNull()
1662 || !theIObj->HasDisplayMode())
1667 if (!myObjects.IsBound (theIObj))
1669 theIObj->UnsetDisplayMode();
1673 const Standard_Integer anOldMode = theIObj->DisplayMode();
1674 if (myDisplayMode == anOldMode)
1679 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1680 aStatus->RemoveDisplayMode (anOldMode);
1681 if (!aStatus->IsDModeIn(myDisplayMode))
1683 aStatus->AddDisplayMode (myDisplayMode);
1686 if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1688 if (myMainPM->IsHighlighted (theIObj, anOldMode))
1690 myMainPM->Unhighlight (theIObj, anOldMode);
1692 myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1693 myMainPM->Display (theIObj, myDisplayMode);
1695 Standard_Integer aDispMode, aHiMode, aSelMode;
1696 GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1697 if (aStatus->IsHilighted())
1699 myMainPM->Highlight (theIObj, aHiMode);
1701 if (aStatus->IsSubIntensityOn())
1703 myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1706 if (theToUpdateViewer)
1708 myMainVwr->Update();
1712 theIObj->UnsetDisplayMode();
1715 //=======================================================================
1716 //function : SetCurrentFacingModel
1718 //=======================================================================
1719 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1720 const Aspect_TypeOfFacingModel theModel)
1722 if (!theIObj.IsNull())
1724 theIObj->SetCurrentFacingModel (theModel);
1728 //=======================================================================
1729 //function : redisplayPrsRecModes
1731 //=======================================================================
1732 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1733 const Standard_Boolean theToUpdateViewer)
1735 if (theIObj->RecomputeEveryPrs())
1737 theIObj->Update (Standard_True);
1738 theIObj->UpdateSelection();
1742 for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1744 theIObj->Update (aModes.Value(), Standard_False);
1746 theIObj->UpdateSelection();
1747 theIObj->SetRecomputeOk();
1750 if (theToUpdateViewer)
1752 UpdateCurrentViewer();
1756 //=======================================================================
1757 //function : redisplayPrsModes
1759 //=======================================================================
1760 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1761 const Standard_Boolean theToUpdateViewer)
1763 if (theIObj->RecomputeEveryPrs())
1765 theIObj->Update (Standard_True);
1766 theIObj->UpdateSelection();
1770 TColStd_ListOfInteger aModes;
1771 theIObj->ToBeUpdated (aModes);
1772 for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1774 theIObj->Update (aModeIter.Value(), Standard_False);
1776 theIObj->SetRecomputeOk();
1779 if (theToUpdateViewer)
1781 UpdateCurrentViewer();
1785 //=======================================================================
1786 //function : SetColor
1788 //=======================================================================
1789 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1790 const Quantity_NameOfColor theColor,
1791 const Standard_Boolean theToUpdateViewer)
1793 SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1796 //=======================================================================
1797 //function : SetColor
1799 //=======================================================================
1800 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1801 const Quantity_Color& theColor,
1802 const Standard_Boolean theToUpdateViewer)
1804 if (theIObj.IsNull())
1809 if (!theIObj->HasInteractiveContext())
1811 theIObj->SetContext (this);
1813 theIObj->SetColor (theColor);
1814 redisplayPrsRecModes (theIObj, theToUpdateViewer);
1817 //=======================================================================
1818 //function : SetIsoOnTriangulation
1820 //=======================================================================
1821 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1822 const Handle(AIS_InteractiveObject)& theObject)
1824 if (theObject.IsNull())
1829 theObject->SetIsoOnTriangulation (theIsEnabled);
1832 //=======================================================================
1833 //function : SetDeviationCoefficient
1835 //=======================================================================
1836 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1837 const Standard_Real theCoefficient,
1838 const Standard_Boolean theToUpdateViewer)
1840 if (theIObj.IsNull())
1845 if (!theIObj->HasInteractiveContext())
1847 theIObj->SetContext (this);
1850 // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1851 if (theIObj->Type() != AIS_KOI_Object
1852 && theIObj->Type() != AIS_KOI_Shape)
1856 else if (theIObj->Signature() != 0)
1861 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1862 aShape->SetOwnDeviationCoefficient (theCoefficient);
1863 redisplayPrsModes (theIObj, theToUpdateViewer);
1866 //=======================================================================
1867 //function : SetHLRDeviationCoefficient
1869 //=======================================================================
1870 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1871 const Standard_Real theCoefficient,
1872 const Standard_Boolean theToUpdateViewer)
1874 if (theIObj.IsNull())
1879 if (!theIObj->HasInteractiveContext())
1881 theIObj->SetContext (this);
1884 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1885 if (theIObj->Type() != AIS_KOI_Object
1886 && theIObj->Type() != AIS_KOI_Shape)
1890 else if (theIObj->Signature() != 0)
1895 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1896 aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1897 redisplayPrsModes (theIObj, theToUpdateViewer);
1900 //=======================================================================
1901 //function : SetDeviationAngle
1903 //=======================================================================
1904 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1905 const Standard_Real theAngle,
1906 const Standard_Boolean theToUpdateViewer)
1908 if (theIObj.IsNull())
1913 if (!theIObj->HasInteractiveContext())
1915 theIObj->SetContext (this);
1918 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1919 if (theIObj->Type() != AIS_KOI_Shape)
1923 else if (theIObj->Signature() != 0)
1928 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1929 aShape->SetOwnDeviationAngle (theAngle);
1930 redisplayPrsModes (theIObj, theToUpdateViewer);
1933 //=======================================================================
1934 //function : SetAngleAndDeviation
1936 //=======================================================================
1937 void AIS_InteractiveContext::SetAngleAndDeviation (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 if (theIObj->Signature() != 0)
1961 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1962 aShape->SetAngleAndDeviation (theAngle);
1964 if (theIObj->RecomputeEveryPrs())
1966 theIObj->Update (Standard_True);
1967 theIObj->UpdateSelection();
1971 Update (theIObj, theToUpdateViewer);
1975 //=======================================================================
1976 //function : SetHLRAngleAndDeviation
1978 //=======================================================================
1979 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1980 const Standard_Real theAngle,
1981 const Standard_Boolean theToUpdateViewer)
1983 if (theIObj.IsNull())
1988 if (!theIObj->HasInteractiveContext())
1990 theIObj->SetContext (this);
1993 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1994 if (theIObj->Type() != AIS_KOI_Shape)
1998 if (theIObj->Signature() != 0)
2002 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2003 aShape->SetHLRAngleAndDeviation (theAngle);
2004 redisplayPrsModes (theIObj, theToUpdateViewer);
2007 //=======================================================================
2008 //function : SetHLRDeviationAngle
2010 //=======================================================================
2011 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2012 const Standard_Real theAngle,
2013 const Standard_Boolean theToUpdateViewer)
2015 if (theIObj.IsNull())
2020 if (!theIObj->HasInteractiveContext())
2022 theIObj->SetContext (this);
2025 // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2026 if (theIObj->Type() != AIS_KOI_Shape)
2030 if (theIObj->Signature() != 0)
2034 Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2035 aShape->SetOwnHLRDeviationAngle (theAngle);
2036 redisplayPrsModes (theIObj, theToUpdateViewer);
2039 //=======================================================================
2040 //function : UnsetColor
2042 //=======================================================================
2043 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2044 const Standard_Boolean theToUpdateViewer)
2046 if (theIObj.IsNull())
2051 theIObj->UnsetColor();
2052 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2055 //=======================================================================
2056 //function : HasColor
2058 //=======================================================================
2059 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2061 return theIObj->HasColor();
2064 //=======================================================================
2067 //=======================================================================
2068 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2070 return theIObj->Color();
2073 //=======================================================================
2076 //=======================================================================
2077 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2078 Quantity_Color& theColor) const
2080 theIObj->Color (theColor);
2083 //=======================================================================
2086 //=======================================================================
2087 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2089 return theIObj->Width();
2092 //=======================================================================
2093 //function : SetWidth
2095 //=======================================================================
2096 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2097 const Standard_Real theWidth,
2098 const Standard_Boolean theToUpdateViewer)
2100 if (theIObj.IsNull())
2105 if (!theIObj->HasInteractiveContext())
2107 theIObj->SetContext (this);
2110 theIObj->SetWidth (theWidth);
2111 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2112 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2114 if (myLastinMain->IsAutoHilight())
2116 const Standard_Integer aHiMode =
2117 theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2118 myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2122 theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2127 //=======================================================================
2128 //function : UnsetWidth
2130 //=======================================================================
2131 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2132 const Standard_Boolean theToUpdateViewer)
2134 if (theIObj.IsNull())
2139 theIObj->UnsetWidth();
2140 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2143 //=======================================================================
2144 //function : SetMaterial
2146 //=======================================================================
2147 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2148 const Graphic3d_NameOfMaterial theName,
2149 const Standard_Boolean theToUpdateViewer)
2151 if (theIObj.IsNull())
2156 if (!theIObj->HasInteractiveContext())
2158 theIObj->SetContext (this);
2161 theIObj->SetMaterial (theName);
2162 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2165 //=======================================================================
2166 //function : UnsetMaterial
2168 //=======================================================================
2169 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2170 const Standard_Boolean theToUpdateViewer)
2172 if (theIObj.IsNull())
2176 theIObj->UnsetMaterial();
2177 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2180 //=======================================================================
2181 //function : SetTransparency
2183 //=======================================================================
2184 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2185 const Standard_Real theValue,
2186 const Standard_Boolean theToUpdateViewer)
2188 if (theIObj.IsNull())
2193 if (!theIObj->HasInteractiveContext())
2195 theIObj->SetContext (this);
2198 if (!theIObj->IsTransparent()
2199 && theValue <= 0.05)
2204 if (theValue <= 0.05)
2206 UnsetTransparency (theIObj, theToUpdateViewer);
2210 theIObj->SetTransparency (theValue);
2211 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2214 //=======================================================================
2215 //function : UnsetTransparency
2217 //=======================================================================
2218 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2219 const Standard_Boolean theToUpdateViewer)
2221 if (theIObj.IsNull())
2226 theIObj->UnsetTransparency();
2227 redisplayPrsRecModes (theIObj, theToUpdateViewer);
2230 //=======================================================================
2231 //function : SetSelectedAspect
2233 //=======================================================================
2234 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2235 const Standard_Boolean ,
2236 const Standard_Boolean theToUpdateViewer)
2238 if (HasOpenedContext())
2243 Standard_Boolean isFound = Standard_False;
2244 for (mySelection->Init(); mySelection->More(); mySelection->Next())
2246 isFound = Standard_True;
2247 Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
2248 anObj->SetAspect (theAspect);
2251 if (isFound && theToUpdateViewer)
2253 myMainVwr->Update();
2257 //=======================================================================
2258 //function : SetLocalAttributes
2260 //=======================================================================
2261 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2262 const Handle(Prs3d_Drawer)& theDrawer,
2263 const Standard_Boolean theToUpdateViewer)
2265 if (theIObj.IsNull())
2270 if (!theIObj->HasInteractiveContext())
2272 theIObj->SetContext (this);
2275 theIObj->SetAttributes (theDrawer);
2276 Update (theIObj, theToUpdateViewer);
2279 //=======================================================================
2280 //function : UnsetLocalAttributes
2282 //=======================================================================
2283 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2284 const Standard_Boolean theToUpdateViewer)
2286 if (theIObj.IsNull())
2291 if (!theIObj->HasInteractiveContext())
2293 theIObj->SetContext (this);
2295 theIObj->UnsetAttributes();
2296 Update (theIObj, theToUpdateViewer);
2299 //=======================================================================
2302 //=======================================================================
2303 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2304 TCollection_ExtendedString& theStatus) const
2307 if (theIObj.IsNull()
2308 || !myObjects.IsBound (theIObj))
2313 theStatus += "\t ____________________________________________";
2314 theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2315 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2316 switch (aStatus->GraphicStatus())
2318 case AIS_DS_Displayed:
2320 theStatus += "\t| -->Displayed\n";
2325 theStatus += "\t| -->Erased\n";
2332 theStatus += "\t| Active Display Modes in the MainViewer :\n";
2333 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2335 theStatus += "\t|\t Mode ";
2336 theStatus += TCollection_AsciiString (aDispModeIter.Value());
2339 if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2341 theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2342 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2344 theStatus += "\t\t Mode ";
2345 theStatus += TCollection_AsciiString (aSelModeIter.Value());
2348 theStatus += "\t ____________________________________________";
2351 //=======================================================================
2352 //function : GetDefModes
2354 //=======================================================================
2355 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2356 Standard_Integer& theDispMode,
2357 Standard_Integer& theHiMode,
2358 Standard_Integer& theSelMode) const
2360 if (theIObj.IsNull())
2365 theDispMode = theIObj->HasDisplayMode()
2366 ? theIObj->DisplayMode()
2367 : (theIObj->AcceptDisplayMode (myDisplayMode)
2370 theHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
2371 theSelMode = theIObj->GlobalSelectionMode();
2374 //=======================================================================
2375 //function : EraseGlobal
2377 //=======================================================================
2378 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2379 const Standard_Boolean theToUpdateviewer)
2381 if (theIObj.IsNull()
2382 || !myObjects.IsBound (theIObj))
2387 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2389 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2390 if (aStatus->GraphicStatus() == AIS_DS_Temporary
2391 || aStatus->GraphicStatus() == AIS_DS_Erased)
2396 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2398 if (aStatus->IsHilighted())
2400 if (IsCurrent (theIObj))
2402 AddOrRemoveCurrentObject (theIObj, Standard_False);
2404 else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2406 myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2410 myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2413 if (aStatus->IsHilighted()
2414 && theIObj->HasHilightMode())
2416 myMainPM->Unhighlight (theIObj, aDispMode);
2419 if (!myLastPicked.IsNull()
2420 && myLastPicked->Selectable() == theIObj)
2422 myMainPM->ClearImmediateDraw();
2425 if (IsSelected (theIObj)
2426 && !aStatus->IsDModeIn (aDispMode))
2428 myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2431 for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2433 mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2435 aStatus->ClearSelectionModes();
2436 aStatus->SetGraphicStatus (AIS_DS_Erased);
2438 if (theToUpdateviewer)
2440 myMainVwr->Update();
2444 //=======================================================================
2445 //function : unhighlightOwners
2447 //=======================================================================
2448 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2450 mySelection->Init();
2451 while (mySelection->More())
2453 const Handle(SelectMgr_EntityOwner) anOwner =
2454 Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
2455 if (anOwner->Selectable() == theObject)
2457 if (anOwner->IsSelected())
2459 AddOrRemoveSelected (anOwner, Standard_False);
2460 mySelection->Init();
2464 mySelection->Next();
2468 //=======================================================================
2469 //function : ClearGlobal
2471 //=======================================================================
2472 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2473 const Standard_Boolean theToUpdateviewer)
2475 if (theIObj.IsNull()
2476 || !myObjects.IsBound (theIObj))
2478 // for cases when reference shape of connected interactives was not displayed
2479 // but its selection primitives were calculated
2480 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2481 mgrSelector->Remove (anObj);
2485 Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2486 unhighlightOwners (theIObj);
2487 for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2489 myMainPM->Erase (theIObj, aDispModeIter.Value());
2490 myMainPM->Clear (theIObj, aDispModeIter.Value());
2493 if (aStatus->IsHilighted()
2494 && theIObj->HasHilightMode())
2496 myMainPM->Unhighlight (theIObj, theIObj->HilightMode());
2499 // Object removes from Detected sequence
2500 for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2502 Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2504 && anObj != theIObj)
2506 myAISDetectedSeq.Remove (aDetIter);
2510 // remove IO from the selection manager to avoid memory leaks
2511 const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2512 mgrSelector->Remove (anObj);
2514 myObjects.UnBind (theIObj);
2515 myMainVwr->StructureManager()->UnregisterObject (theIObj);
2516 for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2518 myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2521 if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2522 myLastinMain.Nullify();
2523 if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2524 myLastPicked.Nullify();
2525 myMainPM->ClearImmediateDraw();
2527 if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2529 myMainVwr->Update();
2533 //=======================================================================
2534 //function : ClearGlobalPrs
2536 //=======================================================================
2537 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2538 const Standard_Integer theMode,
2539 const Standard_Boolean theToUpdateViewer)
2541 if (theIObj.IsNull()
2542 || !myObjects.IsBound (theIObj))
2547 const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2548 if (aStatus->IsDModeIn (theMode))
2550 const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2551 if (aDispMode == theMode
2552 && myMainPM->IsHighlighted (theIObj, theMode))
2554 myMainPM->Unhighlight (theIObj, theMode);
2557 myMainPM->Erase (theIObj, theMode);
2558 myMainPM->Clear (theIObj, theMode);
2561 if (aStatus->GraphicStatus() == AIS_DS_Displayed
2562 && theToUpdateViewer)
2564 myMainVwr->Update();
2568 //=======================================================================
2569 //function : DrawHiddenLine
2571 //=======================================================================
2572 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2574 return myDefaultDrawer->DrawHiddenLine();
2577 //=======================================================================
2578 //function : EnableDrawHiddenLine
2580 //=======================================================================
2581 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2583 myDefaultDrawer->EnableDrawHiddenLine();
2586 //=======================================================================
2587 //function : DisableDrawHiddenLine
2589 //=======================================================================
2590 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2592 myDefaultDrawer->DisableDrawHiddenLine();
2595 //=======================================================================
2596 //function : HiddenLineAspect
2598 //=======================================================================
2599 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2601 return myDefaultDrawer->HiddenLineAspect();
2604 //=======================================================================
2605 //function : SetHiddenLineAspect
2607 //=======================================================================
2608 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2610 myDefaultDrawer->SetHiddenLineAspect (theAspect);
2613 //=======================================================================
2614 //function : SetIsoNumber
2616 //=======================================================================
2617 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2618 const AIS_TypeOfIso theType)
2623 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2626 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2629 myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2630 myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2635 //=======================================================================
2636 //function : IsoNumber
2638 //=======================================================================
2639 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2643 case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2644 case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2645 case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2646 ? myDefaultDrawer->UIsoAspect()->Number()
2652 //=======================================================================
2653 //function : IsoOnPlane
2655 //=======================================================================
2656 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2658 myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2661 //=======================================================================
2662 //function : IsoOnPlane
2664 //=======================================================================
2665 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2667 return myDefaultDrawer->IsoOnPlane();
2670 //=======================================================================
2671 //function : IsoOnTriangulation
2673 //=======================================================================
2674 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2676 myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2679 //=======================================================================
2680 //function : IsoOnTriangulation
2682 //=======================================================================
2683 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2685 return myDefaultDrawer->IsoOnTriangulation();
2688 //function : SetPixelTolerance
2689 //purpose : Disables the mechanism of adaptive tolerance calculation in
2690 // SelectMgr_ViewerSelector and sets the given tolerance for ALL
2691 // sensitive entities activated. For more information, see
2692 // SelectMgr_ViewerSelector.hxx
2693 //=======================================================================
2694 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2696 if (HasOpenedContext())
2698 myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2702 myMainSel->SetPixelTolerance (thePrecision);
2706 //=======================================================================
2707 //function : PixelTolerance
2709 //=======================================================================
2710 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2712 return HasOpenedContext()
2713 ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2714 : myMainSel->PixelTolerance();
2717 //=======================================================================
2718 //function : SetSelectionSensitivity
2719 //purpose : Allows to manage sensitivity of a particular selection of interactive object theObject
2720 //=======================================================================
2721 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2722 const Standard_Integer theMode,
2723 const Standard_Integer theNewSensitivity)
2725 if (HasOpenedContext())
2727 myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2731 mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2734 //=======================================================================
2735 //function : IsInLocal
2737 //=======================================================================
2738 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2739 Standard_Integer& theIndex) const
2741 if (theIObj.IsNull())
2743 return Standard_False;
2746 // if it exists at neutral point 0 index is returned
2747 if (myObjects.IsBound (theIObj))
2750 return Standard_False;
2753 for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2755 if (myLocalContexts.IsBound (aCtxIter))
2757 if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2759 theIndex = aCtxIter;
2760 return Standard_True;
2765 return Standard_False;
2768 //=======================================================================
2769 //function : InitAttributes
2771 //=======================================================================
2772 void AIS_InteractiveContext::InitAttributes()
2774 mgrSelector->Add (myMainSel);
2776 myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2777 Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2778 myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2780 // myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2781 Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2782 aLineAspect->SetColor (Quantity_NOC_GRAY20);
2783 aLineAspect->SetWidth (1.0);
2784 aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2786 // tolerance to 2 pixels...
2787 SetPixelTolerance (2);
2789 // Customizing the drawer for trihedrons and planes...
2790 Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2791 const Standard_Real aLength = 100.0;
2792 aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2793 const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2794 aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2795 aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2796 aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2798 Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2799 const Standard_Real aPlaneLength = 200.0;
2800 aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2801 aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2804 //=======================================================================
2805 //function : TrihedronSize
2807 //=======================================================================
2808 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2810 return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2813 //=======================================================================
2814 //function : SetTrihedronSize
2816 //=======================================================================
2817 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real theVal,
2818 const Standard_Boolean /*updateviewer*/)
2820 myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2821 Redisplay (AIS_KOI_Datum, 3, Standard_False);
2822 Redisplay (AIS_KOI_Datum, 4, Standard_True);
2825 //=======================================================================
2826 //function : SetPlaneSize
2828 //=======================================================================
2829 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real theValX,
2830 const Standard_Real theValY,
2831 const Standard_Boolean /*updateviewer*/)
2833 myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2834 Redisplay (AIS_KOI_Datum, 7);
2837 //=======================================================================
2838 //function : SetPlaneSize
2840 //=======================================================================
2841 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real theVal,
2842 const Standard_Boolean theToUpdateViewer)
2844 SetPlaneSize (theVal, theVal, theToUpdateViewer);
2847 //=======================================================================
2848 //function : PlaneSize
2850 //=======================================================================
2851 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2852 Standard_Real& theY) const
2854 theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2855 theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2856 return (Abs (theX - theY) <= Precision::Confusion());
2859 //=======================================================================
2860 //function : SetAutoActivateSelection
2862 //=======================================================================
2863 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2865 myIsAutoActivateSelMode = theIsAuto;
2868 //=======================================================================
2869 //function : GetAutoActivateSelection
2871 //=======================================================================
2872 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2874 return myIsAutoActivateSelMode;
2877 //=======================================================================
2878 //function : SetZLayer
2880 //=======================================================================
2881 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2882 const Standard_Integer theLayerId)
2884 if (theIObj.IsNull())
2887 theIObj->SetZLayer (theLayerId);
2890 //=======================================================================
2891 //function : GetZLayer
2893 //=======================================================================
2894 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2896 return !theIObj.IsNull()
2898 : Graphic3d_ZLayerId_UNKNOWN;
2901 //=======================================================================
2902 //function : RebuildSelectionStructs
2903 //purpose : Rebuilds 1st level of BVH selection forcibly
2904 //=======================================================================
2905 void AIS_InteractiveContext::RebuildSelectionStructs()
2907 myMainSel->RebuildObjectsTree (Standard_True);
2910 //=======================================================================
2911 //function : Disconnect
2912 //purpose : Disconnects selectable object from an assembly and updates selection structures
2913 //=======================================================================
2914 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2915 const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2917 if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2919 Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2920 theObj->Disconnect (theObjToDisconnect);
2921 const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2922 mgrSelector->Remove (anObj);
2924 else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2926 Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2927 theObj->Disconnect();
2928 const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2929 mgrSelector->Remove (anObj);
2935 //=======================================================================
2936 //function : FitSelected
2937 //purpose : Fits the view corresponding to the bounds of selected objects
2938 //=======================================================================
2939 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2940 const Standard_Real theMargin,
2941 const Standard_Boolean theToUpdate)
2943 const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2944 myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2946 Bnd_Box aBndSelected;
2948 AIS_MapOfObjectOwners anObjectOwnerMap;
2949 for (aSelection->Init(); aSelection->More(); aSelection->Next())
2951 Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2952 if (!anObj.IsNull())
2954 if (anObj->IsInfinite())
2958 anObj->BoundingBox (aTmpBnd);
2959 aBndSelected.Add (aTmpBnd);
2963 Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2964 if (anOwner.IsNull())
2967 Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2968 if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2970 anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2971 anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2974 anOwnerMap->Add (anOwner);
2978 for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2980 const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2981 Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2982 aBndSelected.Add (aTmpBox);
2985 anObjectOwnerMap.Clear();
2987 if (aBndSelected.IsVoid())
2990 theView->FitAll (aBndSelected, theMargin, theToUpdate);