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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16 
17 #include <AIS_InteractiveContext.hxx>
18 
19 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
20 #include <AIS_ConnectedInteractive.hxx>
21 #include <AIS_GlobalStatus.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_MultipleConnectedInteractive.hxx>
24 #include <Graphic3d_AspectFillArea3d.hxx>
25 #include <Precision.hxx>
26 #include <Prs3d_BasicAspect.hxx>
27 #include <Prs3d_DatumAspect.hxx>
28 #include <Prs3d_IsoAspect.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_PlaneAspect.hxx>
31 #include <Prs3d_PointAspect.hxx>
32 #include <Prs3d_ShadingAspect.hxx>
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <TColStd_ListIteratorOfListOfInteger.hxx>
35 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
36 #include <TopLoc_Location.hxx>
37 #include <V3d_View.hxx>
38 #include <V3d_Viewer.hxx>
39 
40 #include <AIS_Shape.hxx>
41 #include <StdSelect_BRepOwner.hxx>
42 #include <TopoDS_Shape.hxx>
43 
44 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
45 
46 namespace
47 {
48   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
49   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
50 
51   //! Initialize default highlighting attributes.
initDefaultHilightAttributes(const Handle (Prs3d_Drawer)& theDrawer,const Quantity_Color & theColor)52   static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer,
53                                             const Quantity_Color& theColor)
54   {
55     theDrawer->SetMethod (Aspect_TOHM_COLOR);
56     theDrawer->SetDisplayMode (0);
57     theDrawer->SetColor (theColor);
58 
59     theDrawer->SetupOwnShadingAspect();
60     theDrawer->SetupOwnPointAspect();
61     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
62     *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
63     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
64     *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
65     theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
66     *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
67     theDrawer->SetFreeBoundaryAspect   (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
68     *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
69     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
70     *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
71     theDrawer->SetDatumAspect (new Prs3d_DatumAspect());
72 
73     theDrawer->ShadingAspect()->SetColor (theColor);
74     theDrawer->WireAspect()->SetColor (theColor);
75     theDrawer->LineAspect()->SetColor (theColor);
76     theDrawer->PlaneAspect()->ArrowAspect()->SetColor (theColor);
77     theDrawer->PlaneAspect()->IsoAspect()->SetColor (theColor);
78     theDrawer->PlaneAspect()->EdgesAspect()->SetColor (theColor);
79     theDrawer->FreeBoundaryAspect()->SetColor (theColor);
80     theDrawer->UnFreeBoundaryAspect()->SetColor (theColor);
81     theDrawer->PointAspect()->SetColor (theColor);
82     for (Standard_Integer aPartIter = 0; aPartIter < Prs3d_DatumParts_None; ++aPartIter)
83     {
84       if (Handle(Prs3d_LineAspect) aLineAsp = theDrawer->DatumAspect()->LineAspect ((Prs3d_DatumParts )aPartIter))
85       {
86         aLineAsp->SetColor (theColor);
87       }
88     }
89 
90     theDrawer->WireAspect()->SetWidth (2.0);
91     theDrawer->LineAspect()->SetWidth (2.0);
92     theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
93     theDrawer->FreeBoundaryAspect()  ->SetWidth (2.0);
94     theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
95     theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
96     theDrawer->PointAspect()->SetScale (2.0);
97 
98     // the triangulation should be computed using main presentation attributes,
99     // and should not be overridden by highlighting
100     theDrawer->SetAutoTriangulation (Standard_False);
101   }
102 }
103 
104 //=======================================================================
105 //function : AIS_InteractiveContext
106 //purpose  :
107 //=======================================================================
108 
AIS_InteractiveContext(const Handle (V3d_Viewer)& MainViewer)109 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
110 myMainPM (new PrsMgr_PresentationManager (MainViewer->StructureManager())),
111 myMainVwr(MainViewer),
112 myToHilightSelected(Standard_True),
113 mySelection(new AIS_Selection()),
114 myFilters (new SelectMgr_AndOrFilter(SelectMgr_FilterType_OR)),
115 myDefaultDrawer(new Prs3d_Drawer()),
116 myCurDetected(0),
117 myCurHighlighted(0),
118 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
119 myAutoHilight(Standard_True),
120 myIsAutoActivateSelMode(Standard_True)
121 {
122   mgrSelector = new SelectMgr_SelectionManager (new StdSelect_ViewerSelector3d());
123 
124   myStyles[Prs3d_TypeOfHighlight_None]          = myDefaultDrawer;
125   myStyles[Prs3d_TypeOfHighlight_Selected]      = new Prs3d_Drawer();
126   myStyles[Prs3d_TypeOfHighlight_Dynamic]       = new Prs3d_Drawer();
127   myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
128   myStyles[Prs3d_TypeOfHighlight_LocalDynamic]  = new Prs3d_Drawer();
129   myStyles[Prs3d_TypeOfHighlight_SubIntensity]  = new Prs3d_Drawer();
130 
131   myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
132   myDefaultDrawer->SetDisplayMode(0);
133   {
134     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
135     aStyle->Link (myDefaultDrawer);
136     initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
137     aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
138   }
139   {
140     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
141     aStyle->Link (myDefaultDrawer);
142     initDefaultHilightAttributes (aStyle, Quantity_NOC_CYAN1);
143     aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
144   }
145   {
146     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
147     aStyle->Link (myDefaultDrawer);
148     initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
149     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
150   }
151   {
152     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
153     aStyle->Link (myDefaultDrawer);
154     initDefaultHilightAttributes (aStyle, Quantity_NOC_GRAY80);
155     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
156   }
157   {
158     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
159     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
160     aStyle->SetMethod(Aspect_TOHM_COLOR);
161     aStyle->SetColor (Quantity_NOC_GRAY40);
162   }
163 
164   InitAttributes();
165 }
166 
167 //=======================================================================
168 //function : ~AIS_InteractiveContext
169 //purpose  :
170 //=======================================================================
~AIS_InteractiveContext()171 AIS_InteractiveContext::~AIS_InteractiveContext()
172 {
173   // clear the current selection
174   mySelection->Clear();
175   mgrSelector.Nullify();
176 
177   Handle(AIS_InteractiveContext) aNullContext;
178   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
179   {
180     const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
181     anObj->SetContext (aNullContext);
182     for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
183     {
184       aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
185     }
186   }
187 }
188 
189 //=======================================================================
190 //function : LastActiveView
191 //purpose  :
192 //=======================================================================
Handle(V3d_View)193 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
194 {
195   if (myLastActiveView == NULL
196    || myMainVwr.IsNull())
197   {
198     return Handle(V3d_View)();
199   }
200 
201   // as a precaution - check that myLastActiveView pointer is a valid active View
202   for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
203   {
204     if (aViewIter.Value() == myLastActiveView)
205     {
206       return aViewIter.Value();
207     }
208   }
209   return Handle(V3d_View)();
210 }
211 
212 //=======================================================================
213 //function : UpdateCurrentViewer
214 //purpose  :
215 //=======================================================================
216 
UpdateCurrentViewer()217 void AIS_InteractiveContext::UpdateCurrentViewer()
218 {
219   if (!myMainVwr.IsNull())
220     myMainVwr->Update();
221 }
222 
223 //=======================================================================
224 //function : DisplayedObjects
225 //purpose  :
226 //=======================================================================
DisplayedObjects(AIS_ListOfInteractive & theListOfIO) const227 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
228 {
229   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
230   {
231     if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
232     {
233       theListOfIO.Append (anObjIter.Key());
234     }
235   }
236 }
237 
238 //=======================================================================
239 //function : DisplayedObjects
240 //purpose  :
241 //=======================================================================
DisplayedObjects(const AIS_KindOfInteractive theKind,const Standard_Integer theSign,AIS_ListOfInteractive & theListOfIO) const242 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
243                                                const Standard_Integer      theSign,
244                                                AIS_ListOfInteractive&      theListOfIO) const
245 {
246   ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Displayed, theListOfIO);
247 }
248 
249 //=======================================================================
250 //function : ErasedObjects
251 //purpose  :
252 //=======================================================================
ErasedObjects(AIS_ListOfInteractive & theListOfIO) const253 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
254 {
255   ObjectsByDisplayStatus (PrsMgr_DisplayStatus_Erased, theListOfIO);
256 }
257 
258 //=======================================================================
259 //function : ErasedObjects
260 //purpose  :
261 //=======================================================================
ErasedObjects(const AIS_KindOfInteractive theKind,const Standard_Integer theSign,AIS_ListOfInteractive & theListOfIO) const262 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
263                                             const Standard_Integer      theSign,
264                                             AIS_ListOfInteractive&      theListOfIO) const
265 {
266   ObjectsByDisplayStatus (theKind, theSign, PrsMgr_DisplayStatus_Erased, theListOfIO);
267 }
268 
269 //=======================================================================
270 //function : ObjectsByDisplayStatus
271 //purpose  :
272 //=======================================================================
ObjectsByDisplayStatus(const PrsMgr_DisplayStatus theStatus,AIS_ListOfInteractive & theListOfIO) const273 void AIS_InteractiveContext::ObjectsByDisplayStatus (const PrsMgr_DisplayStatus theStatus,
274                                                      AIS_ListOfInteractive&  theListOfIO) const
275 {
276   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
277   {
278     if (anObjIter.Key()->DisplayStatus() == theStatus)
279     {
280       theListOfIO.Append (anObjIter.Key());
281     }
282   }
283 }
284 
285 //=======================================================================
286 //function : ObjectsByDisplayStatus
287 //purpose  :
288 //=======================================================================
ObjectsByDisplayStatus(const AIS_KindOfInteractive theKind,const Standard_Integer theSign,const PrsMgr_DisplayStatus theStatus,AIS_ListOfInteractive & theListOfIO) const289 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
290                                                      const Standard_Integer      theSign,
291                                                      const PrsMgr_DisplayStatus  theStatus,
292                                                      AIS_ListOfInteractive&      theListOfIO) const
293 {
294   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
295   {
296     if (theStatus != PrsMgr_DisplayStatus_None
297      && anObjIter.Key()->DisplayStatus() != theStatus)
298     {
299       continue;
300     }
301     else if (anObjIter.Key()->Type() != theKind)
302     {
303       continue;
304     }
305 
306     if (theSign == -1
307      || anObjIter.Key()->Signature() == theSign)
308     {
309       theListOfIO.Append (anObjIter.Key());
310     }
311   }
312 }
313 
314 //=======================================================================
315 //function : ObjectsInside
316 //purpose  :
317 //=======================================================================
ObjectsInside(AIS_ListOfInteractive & theListOfIO,const AIS_KindOfInteractive theKind,const Standard_Integer theSign) const318 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive&      theListOfIO,
319                                             const AIS_KindOfInteractive theKind,
320                                             const Standard_Integer      theSign) const
321 {
322   if (theKind == AIS_KindOfInteractive_None
323    && theSign == -1)
324   {
325     for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
326     {
327       theListOfIO.Append (anObjIter.Key());
328     }
329     return;
330   }
331 
332   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
333   {
334     if (anObjIter.Key()->Type() != theKind)
335     {
336       continue;
337     }
338 
339     if (theSign == -1
340      || anObjIter.Key()->Signature() == theSign)
341     {
342       theListOfIO.Append (anObjIter.Key());
343     }
344   }
345 }
346 
347 //=======================================================================
348 //function : ObjectsForView
349 //purpose  :
350 //=======================================================================
ObjectsForView(AIS_ListOfInteractive & theListOfIO,const Handle (V3d_View)& theView,const Standard_Boolean theIsVisibleInView,const PrsMgr_DisplayStatus theStatus) const351 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive&  theListOfIO,
352                                              const Handle(V3d_View)& theView,
353                                              const Standard_Boolean  theIsVisibleInView,
354                                              const PrsMgr_DisplayStatus theStatus) const
355 {
356   Handle(Graphic3d_CView) aViewImpl = theView->View();
357   const Standard_Integer  aViewId   = aViewImpl->Identification();
358   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
359   {
360     if (theStatus != PrsMgr_DisplayStatus_None
361      && anObjIter.Key()->DisplayStatus() != theStatus)
362     {
363       theListOfIO.Append (anObjIter.Key());
364       continue;
365     }
366 
367     Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
368     const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
369     if (isVisible == theIsVisibleInView)
370     {
371       theListOfIO.Append (anObjIter.Key());
372     }
373   }
374 }
375 
376 //=======================================================================
377 //function : Display
378 //purpose  :
379 //=======================================================================
Display(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)380 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
381                                       const Standard_Boolean               theToUpdateViewer)
382 {
383   if (theIObj.IsNull())
384   {
385     return;
386   }
387 
388   Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
389   GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
390   Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
391 }
392 
393 //=======================================================================
394 //function : SetViewAffinity
395 //purpose  :
396 //=======================================================================
SetViewAffinity(const Handle (AIS_InteractiveObject)& theIObj,const Handle (V3d_View)& theView,const Standard_Boolean theIsVisible)397 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
398                                               const Handle(V3d_View)&              theView,
399                                               const Standard_Boolean               theIsVisible)
400 {
401   if (theIObj.IsNull()
402   || !myObjects.IsBound (theIObj))
403   {
404     return;
405   }
406 
407   Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
408   Handle(Graphic3d_CView) aViewImpl = theView->View();
409   anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
410   if (theIsVisible)
411   {
412     theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
413   }
414   else
415   {
416     theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
417   }
418 }
419 
420 //=======================================================================
421 //function : Display
422 //purpose  :
423 //=======================================================================
Display(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theDispMode,const Standard_Integer theSelectionMode,const Standard_Boolean theToUpdateViewer,const PrsMgr_DisplayStatus theDispStatus)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 PrsMgr_DisplayStatus           theDispStatus)
429 {
430   if (theIObj.IsNull())
431   {
432     return;
433   }
434 
435   if (theDispStatus == PrsMgr_DisplayStatus_Erased)
436   {
437     Erase  (theIObj, theToUpdateViewer);
438     Load (theIObj, theSelectionMode);
439     if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
440     {
441       (*aStatusPtr)->SetDisplayMode (theDispMode);
442     }
443     return;
444   }
445 
446   setContextToObject (theIObj);
447   if (!myObjects.IsBound (theIObj))
448   {
449     setObjectStatus (theIObj, PrsMgr_DisplayStatus_Displayed, theDispMode, theSelectionMode);
450     myMainVwr->StructureManager()->RegisterObject (theIObj);
451     myMainPM->Display(theIObj, theDispMode);
452     if (theSelectionMode != -1)
453     {
454       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
455       if (!mgrSelector->Contains (anObj))
456       {
457         mgrSelector->Load (theIObj);
458       }
459       mgrSelector->Activate (theIObj, theSelectionMode);
460     }
461   }
462   else
463   {
464     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
465 
466     // Mark the presentation modes hidden of interactive object different from aDispMode.
467     // Then make sure aDispMode is displayed and maybe highlighted.
468     // Finally, activate selection mode <SelMode> if not yet activated.
469     const Standard_Integer anOldMode = aStatus->DisplayMode();
470     if (anOldMode != theDispMode)
471     {
472       if(myMainPM->IsHighlighted (theIObj, anOldMode))
473       {
474         unhighlightGlobal (theIObj);
475       }
476       myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
477     }
478 
479     aStatus->SetDisplayMode (theDispMode);
480 
481     theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Displayed);
482     myMainPM->Display (theIObj, theDispMode);
483     if (aStatus->IsHilighted())
484     {
485       highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
486     }
487     if (theSelectionMode != -1)
488     {
489       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
490       if (!mgrSelector->Contains (anObj))
491       {
492         mgrSelector->Load (theIObj);
493       }
494       if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
495       {
496         aStatus->AddSelectionMode (theSelectionMode);
497         mgrSelector->Activate (theIObj, theSelectionMode);
498       }
499     }
500   }
501 
502   if (theToUpdateViewer)
503   {
504     myMainVwr->Update();
505   }
506 }
507 
508 //=======================================================================
509 //function : Load
510 //purpose  :
511 //=======================================================================
Load(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theSelMode)512 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
513                                    const Standard_Integer               theSelMode)
514 {
515   if (theIObj.IsNull())
516   {
517     return;
518   }
519 
520   setContextToObject (theIObj);
521   if (!myObjects.IsBound (theIObj))
522   {
523     Standard_Integer aDispMode, aHiMod, aSelModeDef;
524     GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
525     setObjectStatus (theIObj, PrsMgr_DisplayStatus_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
526     myMainVwr->StructureManager()->RegisterObject (theIObj);
527   }
528 
529   // Register theIObj in the selection manager to prepare further activation of selection
530   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
531   if (!mgrSelector->Contains (anObj))
532   {
533     mgrSelector->Load (theIObj);
534   }
535 }
536 
537 //=======================================================================
538 //function : Erase
539 //purpose  :
540 //=======================================================================
Erase(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)541 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
542                                     const Standard_Boolean               theToUpdateViewer)
543 {
544   if (theIObj.IsNull())
545   {
546     return;
547   }
548 
549   if (!theIObj->IsAutoHilight())
550   {
551     theIObj->ClearSelected();
552   }
553 
554   EraseGlobal (theIObj, Standard_False);
555   if (theToUpdateViewer)
556   {
557     myMainVwr->Update();
558   }
559 }
560 
561 //=======================================================================
562 //function : EraseAll
563 //purpose  :
564 //=======================================================================
EraseAll(const Standard_Boolean theToUpdateViewer)565 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
566 {
567   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
568   {
569     if (anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
570     {
571       Erase (anObjIter.Key(), Standard_False);
572     }
573   }
574 
575   if (theToUpdateViewer)
576   {
577     myMainVwr->Update();
578   }
579 }
580 
581 //=======================================================================
582 //function : DisplayAll
583 //purpose  :
584 //=======================================================================
DisplayAll(const Standard_Boolean theToUpdateViewer)585 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
586 {
587   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
588   {
589     const PrsMgr_DisplayStatus aStatus = anObjIter.Key()->DisplayStatus();
590     if (aStatus == PrsMgr_DisplayStatus_Erased)
591     {
592       Display (anObjIter.Key(), Standard_False);
593     }
594   }
595 
596   if (theToUpdateViewer)
597   {
598     myMainVwr->Update();
599   }
600 }
601 
602 //=======================================================================
603 //function : DisplaySelected
604 //purpose  :
605 //=======================================================================
DisplaySelected(const Standard_Boolean theToUpdateViewer)606 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
607 {
608   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
609   {
610     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
611     Display (anObj, Standard_False);
612   }
613 
614   if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
615   {
616     myMainVwr->Update();
617   }
618 }
619 
620 //=======================================================================
621 //function : EraseSelected
622 //purpose  :
623 //=======================================================================
EraseSelected(const Standard_Boolean theToUpdateViewer)624 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
625 {
626   Standard_Boolean isFound = Standard_False;
627   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
628   {
629     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
630     Erase (anObj, Standard_False);
631     isFound = Standard_True;
632   }
633 
634   if (isFound && theToUpdateViewer)
635   {
636     myMainVwr->Update();
637   }
638 }
639 
640 //=======================================================================
641 //function : DisplayStatus
642 //purpose  :
643 //=======================================================================
DisplayStatus(const Handle (AIS_InteractiveObject)& theIObj) const644 PrsMgr_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
645 {
646   if (theIObj.IsNull())
647   {
648     return PrsMgr_DisplayStatus_None;
649   }
650   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
651   return aStatus != NULL ? theIObj->DisplayStatus() : PrsMgr_DisplayStatus_None;
652 }
653 
654 //=======================================================================
655 //function : Remove
656 //purpose  :
657 //=======================================================================
Remove(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)658 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
659                                      const Standard_Boolean               theToUpdateViewer)
660 {
661   if (theIObj.IsNull())
662   {
663     return;
664   }
665 
666   if (theIObj->HasInteractiveContext())
667   {
668     if (theIObj->myCTXPtr != this)
669     {
670       throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
671     }
672     theIObj->SetContext (Handle(AIS_InteractiveContext)());
673   }
674   ClearGlobal (theIObj, theToUpdateViewer);
675 }
676 
677 //=======================================================================
678 //function : RemoveAll
679 //purpose  :
680 //=======================================================================
RemoveAll(const Standard_Boolean theToUpdateViewer)681 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
682 {
683   ClearDetected();
684 
685   AIS_ListOfInteractive aList;
686   ObjectsInside (aList);
687   for (AIS_ListOfInteractive::Iterator aListIterator (aList); aListIterator.More(); aListIterator.Next())
688   {
689     Remove (aListIterator.Value(), Standard_False);
690   }
691 
692   if (theToUpdateViewer)
693   {
694     myMainVwr->Update();
695   }
696 }
697 
698 //=======================================================================
699 //function : HilightWithColor
700 //purpose  :
701 //=======================================================================
HilightWithColor(const Handle (AIS_InteractiveObject)& theObj,const Handle (Prs3d_Drawer)& theStyle,const Standard_Boolean theIsToUpdate)702 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& theObj,
703                                               const Handle(Prs3d_Drawer)& theStyle,
704                                               const Standard_Boolean theIsToUpdate)
705 {
706   if (theObj.IsNull())
707     return;
708 
709   setContextToObject (theObj);
710   if (!myObjects.IsBound (theObj))
711     return;
712 
713   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theObj);
714   aStatus->SetHilightStatus (Standard_True);
715 
716   if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
717   {
718     highlightGlobal (theObj, theStyle, aStatus->DisplayMode());
719     aStatus->SetHilightStyle (theStyle);
720   }
721 
722   if (theIsToUpdate)
723     myMainVwr->Update();
724 }
725 
726 //=======================================================================
727 //function : Unhilight
728 //purpose  :
729 //=======================================================================
Unhilight(const Handle (AIS_InteractiveObject)& theObj,const Standard_Boolean theToUpdateViewer)730 void AIS_InteractiveContext::Unhilight (const Handle(AIS_InteractiveObject)& theObj,
731                                         const Standard_Boolean theToUpdateViewer)
732 {
733   Handle(AIS_GlobalStatus)* aStatus = !theObj.IsNull() ? myObjects.ChangeSeek (theObj) : NULL;
734   if (aStatus == NULL)
735   {
736     return;
737   }
738 
739   (*aStatus)->SetHilightStatus (Standard_False);
740   (*aStatus)->SetHilightStyle (Handle(Prs3d_Drawer)());
741   if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
742   {
743     unhighlightGlobal (theObj);
744   }
745 
746   if (theToUpdateViewer)
747   {
748     myMainVwr->Update();
749   }
750 }
751 
752 //=======================================================================
753 //function : IsHilighted
754 //purpose  : Returns true if the objects global status is set to highlighted.
755 //=======================================================================
IsHilighted(const Handle (AIS_InteractiveObject)& theObj) const756 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
757 {
758   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
759   return aStatus != NULL
760       && (*aStatus)->IsHilighted();
761 }
762 
763 //=======================================================================
764 //function : IsHilighted
765 //purpose  : Returns true if the owner is highlighted with selection style.
766 //=======================================================================
IsHilighted(const Handle (SelectMgr_EntityOwner)& theOwner) const767 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
768 {
769   if (theOwner.IsNull() || !theOwner->HasSelectable())
770     return Standard_False;
771 
772   const Handle(AIS_InteractiveObject) anObj =
773     Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
774 
775   if (anObj->GlobalSelOwner() == theOwner)
776   {
777     if (!myObjects.IsBound (anObj))
778       return Standard_False;
779 
780     return myObjects (anObj)->IsHilighted();
781   }
782 
783   const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
784   const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
785   return theOwner->IsHilighted (myMainPM, aHiMode);
786 }
787 
788 //=======================================================================
789 //function : HighlightStyle
790 //purpose  :
791 //=======================================================================
HighlightStyle(const Handle (AIS_InteractiveObject)& theObj,Handle (Prs3d_Drawer)& theStyle) const792 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
793                                                          Handle(Prs3d_Drawer)& theStyle) const
794 {
795   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
796   if (aStatus != NULL
797    && (*aStatus)->IsHilighted())
798   {
799     theStyle = (*aStatus)->HilightStyle();
800     return Standard_True;
801   }
802 
803   theStyle.Nullify();
804   return Standard_False;
805 }
806 
807 //=======================================================================
808 //function : HighlightStyle
809 //purpose  :
810 //=======================================================================
HighlightStyle(const Handle (SelectMgr_EntityOwner)& theOwner,Handle (Prs3d_Drawer)& theStyle) const811 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
812                                                          Handle(Prs3d_Drawer)& theStyle) const
813 {
814   if (theOwner.IsNull() || !theOwner->HasSelectable())
815     return Standard_False;
816 
817   if (IsHilighted (theOwner))
818   {
819     const Handle(AIS_InteractiveObject) anObj =
820       Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
821     if (anObj->GlobalSelOwner() == theOwner)
822     {
823       theStyle = myObjects (anObj)->HilightStyle();
824     }
825     else
826     {
827       // since part selection style is not stored in global status,
828       // check if the object has own selection style. If not, it can
829       // only be highlighted with default selection style (because
830       // sub-intensity does not modify any selection states)
831       theStyle = getSelStyle (anObj, theOwner);
832     }
833     return Standard_True;
834   }
835   else
836   {
837     theStyle.Nullify();
838     return Standard_False;
839   }
840 }
841 
842 //=======================================================================
843 //function : IsDisplayed
844 //purpose  :
845 //=======================================================================
846 
IsDisplayed(const Handle (AIS_InteractiveObject)& theObj) const847 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const
848 {
849   if(theObj.IsNull()) return Standard_False;
850 
851   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
852   return aStatus != NULL
853       && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed;
854 }
855 
856 //=======================================================================
857 //function : IsDisplayed
858 //purpose  :
859 //=======================================================================
IsDisplayed(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theMode) const860 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
861                                                       const Standard_Integer               theMode) const
862 {
863   if (theIObj.IsNull())
864   {
865     return Standard_False;
866   }
867 
868   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
869   return aStatus != NULL
870       && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
871       && (*aStatus)->DisplayMode() == theMode;
872 }
873 
874 //=======================================================================
875 //function : DisplayPriority
876 //purpose  :
877 //=======================================================================
DisplayPriority(const Handle (AIS_InteractiveObject)& theIObj) const878 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
879 {
880   if (theIObj.IsNull())
881   {
882     return -1;
883   }
884 
885   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
886   if (aStatus != NULL
887    && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
888     || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
889   {
890     Standard_Integer aDispMode = theIObj->HasDisplayMode()
891                                ? theIObj->DisplayMode()
892                                : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
893                                 ? myDefaultDrawer->DisplayMode()
894                                 : 0);
895     return myMainPM->DisplayPriority (theIObj, aDispMode);
896   }
897   return 0;
898 }
899 
900 //=======================================================================
901 //function : SetDisplayPriority
902 //purpose  :
903 //=======================================================================
SetDisplayPriority(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer thePriority)904 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
905                                                  const Standard_Integer               thePriority)
906 {
907   if (theIObj.IsNull())
908   {
909     return;
910   }
911 
912   setContextToObject (theIObj);
913   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
914   if (aStatus != NULL
915    && (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
916     || theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased))
917   {
918     Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
919                                   ? theIObj->DisplayMode()
920                                   : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
921                                     ? myDefaultDrawer->DisplayMode()
922                                     : 0);
923     myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
924   }
925 }
926 
927 //=======================================================================
928 //function : Redisplay
929 //purpose  :
930 //=======================================================================
Redisplay(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer,const Standard_Boolean theAllModes)931 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
932                                         const Standard_Boolean               theToUpdateViewer,
933                                         const Standard_Boolean               theAllModes)
934 {
935   RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
936   RecomputeSelectionOnly (theIObj);
937 }
938 
939 //=======================================================================
940 //function : Redisplay
941 //purpose  :
942 //=======================================================================
Redisplay(const AIS_KindOfInteractive theKOI,const Standard_Integer,const Standard_Boolean theToUpdateViewer)943 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
944                                         const Standard_Integer    /*theSign*/,
945                                         const Standard_Boolean      theToUpdateViewer)
946 {
947   Standard_Boolean isRedisplayed = Standard_False;
948   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
949   {
950     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
951     if (anObj->Type() != theKOI)
952     {
953       continue;
954     }
955 
956     Redisplay (anObj, Standard_False);
957     isRedisplayed = anObjIter.Key()->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
958                  || isRedisplayed;
959   }
960 
961   if (theToUpdateViewer
962    && isRedisplayed)
963   {
964     myMainVwr->Update();
965   }
966 }
967 
968 //=======================================================================
969 //function : RecomputePrsOnly
970 //purpose  :
971 //=======================================================================
RecomputePrsOnly(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer,const Standard_Boolean theAllModes)972 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
973                                                const Standard_Boolean               theToUpdateViewer,
974                                                const Standard_Boolean               theAllModes)
975 {
976   if (theIObj.IsNull())
977   {
978     return;
979   }
980 
981   theIObj->SetToUpdate();
982   theIObj->UpdatePresentations (theAllModes);
983   if (!theToUpdateViewer)
984   {
985     return;
986   }
987 
988   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
989   if (aStatus != NULL
990    && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
991   {
992     myMainVwr->Update();
993   }
994 }
995 //=======================================================================
996 //function : RecomputeSelectionOnly
997 //purpose  :
998 //=======================================================================
RecomputeSelectionOnly(const Handle (AIS_InteractiveObject)& theIO)999 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1000 {
1001   if (theIO.IsNull())
1002   {
1003     return;
1004   }
1005 
1006   mgrSelector->RecomputeSelection (theIO);
1007 
1008   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1009   if (aStatus == NULL
1010    || theIO->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1011   {
1012     return;
1013   }
1014 
1015   TColStd_ListOfInteger aModes;
1016   ActivatedModes (theIO, aModes);
1017   TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1018   for (; aModesIter.More(); aModesIter.Next())
1019   {
1020     mgrSelector->Activate (theIO, aModesIter.Value());
1021   }
1022 }
1023 
1024 //=======================================================================
1025 //function : Update
1026 //purpose  :
1027 //=======================================================================
Update(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theUpdateViewer)1028 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1029                                      const Standard_Boolean               theUpdateViewer)
1030 {
1031   if (theIObj.IsNull())
1032   {
1033     return;
1034   }
1035 
1036   theIObj->UpdatePresentations();
1037   mgrSelector->Update(theIObj);
1038 
1039   if (theUpdateViewer)
1040   {
1041     const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1042     if (aStatus != NULL
1043      && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1044     {
1045       myMainVwr->Update();
1046     }
1047   }
1048 }
1049 
1050 //=======================================================================
1051 //function : SetLocation
1052 //purpose  :
1053 //=======================================================================
SetLocation(const Handle (AIS_InteractiveObject)& theIObj,const TopLoc_Location & theLoc)1054 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1055                                           const TopLoc_Location&               theLoc)
1056 {
1057   if (theIObj.IsNull())
1058   {
1059     return;
1060   }
1061 
1062   if (theIObj->HasTransformation()
1063    && theLoc.IsIdentity())
1064   {
1065     theIObj->ResetTransformation();
1066     mgrSelector->Update (theIObj, Standard_False);
1067     return;
1068   }
1069   else if (theLoc.IsIdentity())
1070   {
1071     return;
1072   }
1073 
1074   // first reset the previous location to properly clean everything...
1075   if (theIObj->HasTransformation())
1076   {
1077     theIObj->ResetTransformation();
1078   }
1079 
1080   theIObj->SetLocalTransformation (theLoc.Transformation());
1081 
1082   mgrSelector->Update (theIObj, Standard_False);
1083 
1084   // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1085   // to its highlight structure immediately
1086   if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1087   {
1088     const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1089     myLastPicked->UpdateHighlightTrsf (myMainVwr,
1090                                        myMainPM,
1091                                        aHiMod);
1092   }
1093 }
1094 
1095 //=======================================================================
1096 //function : ResetLocation
1097 //purpose  :
1098 //=======================================================================
ResetLocation(const Handle (AIS_InteractiveObject)& theIObj)1099 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1100 {
1101   if (theIObj.IsNull())
1102   {
1103     return;
1104   }
1105 
1106   theIObj->ResetTransformation();
1107   mgrSelector->Update (theIObj, Standard_False);
1108 }
1109 
1110 //=======================================================================
1111 //function : HasLocation
1112 //purpose  :
1113 //=======================================================================
HasLocation(const Handle (AIS_InteractiveObject)& theIObj) const1114 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1115 {
1116   return !theIObj.IsNull()
1117        && theIObj->HasTransformation();
1118 }
1119 
1120 //=======================================================================
1121 //function : Location
1122 //purpose  :
1123 //=======================================================================
Location(const Handle (AIS_InteractiveObject)& theIObj) const1124 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1125 {
1126   return theIObj->Transformation();
1127 }
1128 
1129 //=======================================================================
1130 //function : SetDisplayMode
1131 //purpose  :
1132 //=======================================================================
SetDisplayMode(const Standard_Integer theMode,const Standard_Boolean theToUpdateViewer)1133 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1134                                             const Standard_Boolean theToUpdateViewer)
1135 {
1136   if (theMode == myDefaultDrawer->DisplayMode())
1137   {
1138     return;
1139   }
1140 
1141   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1142   {
1143     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1144     Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1145                               || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1146                               || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1147 
1148     if (!toProcess
1149      ||  anObj->HasDisplayMode()
1150      || !anObj->AcceptDisplayMode (theMode))
1151     {
1152       continue;
1153     }
1154 
1155     Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1156     aStatus->SetDisplayMode (theMode);
1157 
1158     if (anObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1159     {
1160       myMainPM->Display (anObj, theMode);
1161       if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1162       {
1163         myMainPM->BeginImmediateDraw();
1164         unhighlightGlobal (anObj);
1165         myMainPM->EndImmediateDraw (myMainVwr);
1166       }
1167       if (aStatus->IsSubIntensityOn())
1168       {
1169         highlightWithSubintensity (anObj, theMode);
1170       }
1171       myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1172     }
1173   }
1174 
1175   myDefaultDrawer->SetDisplayMode (theMode);
1176   if (theToUpdateViewer)
1177   {
1178     myMainVwr->Update();
1179   }
1180 }
1181 
1182 //=======================================================================
1183 //function : SetDisplayMode
1184 //purpose  :
1185 //=======================================================================
SetDisplayMode(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theMode,const Standard_Boolean theToUpdateViewer)1186 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1187                                              const Standard_Integer               theMode,
1188                                              const Standard_Boolean               theToUpdateViewer)
1189 {
1190   setContextToObject (theIObj);
1191   if (!myObjects.IsBound (theIObj))
1192   {
1193     theIObj->SetDisplayMode (theMode);
1194     return;
1195   }
1196   else if (!theIObj->AcceptDisplayMode (theMode))
1197   {
1198     return;
1199   }
1200 
1201   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1202   if (theIObj->DisplayStatus() != PrsMgr_DisplayStatus_Displayed)
1203   {
1204     aStatus->SetDisplayMode (theMode);
1205     theIObj->SetDisplayMode (theMode);
1206     return;
1207   }
1208 
1209   // erase presentations for all display modes different from <aMode>
1210   const Standard_Integer anOldMode = aStatus->DisplayMode();
1211   if (anOldMode != theMode)
1212   {
1213     if (myMainPM->IsHighlighted (theIObj, anOldMode))
1214     {
1215       unhighlightGlobal (theIObj);
1216     }
1217     myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1218   }
1219 
1220   aStatus->SetDisplayMode (theMode);
1221 
1222   myMainPM->Display (theIObj, theMode);
1223   if (aStatus->IsHilighted())
1224   {
1225     highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1226   }
1227   if (aStatus->IsSubIntensityOn())
1228   {
1229     highlightWithSubintensity (theIObj, theMode);
1230   }
1231 
1232   if (theToUpdateViewer)
1233   {
1234     myMainVwr->Update();
1235   }
1236   theIObj->SetDisplayMode (theMode);
1237 }
1238 
1239 //=======================================================================
1240 //function : UnsetDisplayMode
1241 //purpose  :
1242 //=======================================================================
UnsetDisplayMode(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1243 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1244                                                const Standard_Boolean               theToUpdateViewer)
1245 {
1246   if (theIObj.IsNull()
1247   || !theIObj->HasDisplayMode())
1248   {
1249     return;
1250   }
1251 
1252   if (!myObjects.IsBound (theIObj))
1253   {
1254     theIObj->UnsetDisplayMode();
1255     return;
1256   }
1257 
1258   const Standard_Integer anOldMode = theIObj->DisplayMode();
1259   if (myDefaultDrawer->DisplayMode() == anOldMode)
1260   {
1261     return;
1262   }
1263 
1264   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1265   aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1266 
1267   if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1268   {
1269     if (myMainPM->IsHighlighted (theIObj, anOldMode))
1270     {
1271       unhighlightGlobal (theIObj);
1272     }
1273     myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1274     myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1275     if (aStatus->IsHilighted())
1276     {
1277       highlightSelected (theIObj->GlobalSelOwner());
1278     }
1279     if (aStatus->IsSubIntensityOn())
1280     {
1281       highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1282     }
1283 
1284     if (theToUpdateViewer)
1285     {
1286       myMainVwr->Update();
1287     }
1288   }
1289 
1290   theIObj->UnsetDisplayMode();
1291 }
1292 
1293 //=======================================================================
1294 //function : SetCurrentFacingModel
1295 //purpose  :
1296 //=======================================================================
SetCurrentFacingModel(const Handle (AIS_InteractiveObject)& theIObj,const Aspect_TypeOfFacingModel theModel)1297 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1298                                                     const Aspect_TypeOfFacingModel       theModel)
1299 {
1300   if (!theIObj.IsNull())
1301   {
1302     theIObj->SetCurrentFacingModel (theModel);
1303   }
1304 }
1305 
1306 //=======================================================================
1307 //function : SetColor
1308 //purpose  :
1309 //=======================================================================
SetColor(const Handle (AIS_InteractiveObject)& theIObj,const Quantity_Color & theColor,const Standard_Boolean theToUpdateViewer)1310 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1311                                        const Quantity_Color&                theColor,
1312                                        const Standard_Boolean               theToUpdateViewer)
1313 {
1314   if (theIObj.IsNull())
1315   {
1316     return;
1317   }
1318 
1319   setContextToObject (theIObj);
1320   theIObj->SetColor (theColor);
1321   theIObj->UpdatePresentations();
1322   if (theToUpdateViewer)
1323   {
1324     UpdateCurrentViewer();
1325   }
1326 }
1327 
1328 //=======================================================================
1329 //function : SetIsoOnTriangulation
1330 //purpose  :
1331 //=======================================================================
IsoOnTriangulation(const Standard_Boolean theIsEnabled,const Handle (AIS_InteractiveObject)& theObject)1332 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1333                                                  const Handle(AIS_InteractiveObject)& theObject)
1334 {
1335   if (theObject.IsNull())
1336   {
1337     return;
1338   }
1339 
1340   theObject->SetIsoOnTriangulation (theIsEnabled);
1341 }
1342 
1343 //=======================================================================
1344 //function : SetDeviationCoefficient
1345 //purpose  :
1346 //=======================================================================
SetDeviationCoefficient(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Real theCoefficient,const Standard_Boolean theToUpdateViewer)1347 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1348                                                       const Standard_Real                  theCoefficient,
1349                                                       const Standard_Boolean               theToUpdateViewer)
1350 {
1351   if (theIObj.IsNull())
1352   {
1353     return;
1354   }
1355 
1356   // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1357   setContextToObject (theIObj);
1358   if (theIObj->Type() != AIS_KindOfInteractive_Object
1359    && theIObj->Type() != AIS_KindOfInteractive_Shape)
1360   {
1361     return;
1362   }
1363   else if (theIObj->Signature() != 0)
1364   {
1365     return;
1366   }
1367 
1368   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1369   aShape->SetOwnDeviationCoefficient (theCoefficient);
1370   aShape->UpdatePresentations();
1371   if (theToUpdateViewer)
1372   {
1373     UpdateCurrentViewer();
1374   }
1375 }
1376 
1377 //=======================================================================
1378 //function : SetDeviationAngle
1379 //purpose  :
1380 //=======================================================================
SetDeviationAngle(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Real theAngle,const Standard_Boolean theToUpdateViewer)1381 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1382                                                 const Standard_Real                  theAngle,
1383                                                 const Standard_Boolean               theToUpdateViewer)
1384 {
1385   if (theIObj.IsNull())
1386   {
1387     return;
1388   }
1389 
1390   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1391   setContextToObject (theIObj);
1392   if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1393   {
1394     return;
1395   }
1396   else if (theIObj->Signature() != 0)
1397   {
1398     return;
1399   }
1400 
1401   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1402   aShape->SetOwnDeviationAngle (theAngle);
1403   aShape->UpdatePresentations();
1404   if (theToUpdateViewer)
1405   {
1406     UpdateCurrentViewer();
1407   }
1408 }
1409 
1410 //=======================================================================
1411 //function : SetAngleAndDeviation
1412 //purpose  :
1413 //=======================================================================
SetAngleAndDeviation(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Real theAngle,const Standard_Boolean theToUpdateViewer)1414 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1415                                                    const Standard_Real                  theAngle,
1416                                                    const Standard_Boolean               theToUpdateViewer)
1417 {
1418   if (theIObj.IsNull())
1419   {
1420     return;
1421   }
1422 
1423   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1424   setContextToObject (theIObj);
1425   if (theIObj->Type() != AIS_KindOfInteractive_Shape)
1426   {
1427     return;
1428   }
1429   if (theIObj->Signature() != 0)
1430   {
1431     return;
1432   }
1433 
1434   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1435   aShape->SetAngleAndDeviation (theAngle);
1436   aShape->UpdatePresentations();
1437   if (theToUpdateViewer)
1438   {
1439     UpdateCurrentViewer();
1440   }
1441 }
1442 
1443 //=======================================================================
1444 //function : UnsetColor
1445 //purpose  :
1446 //=======================================================================
UnsetColor(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1447 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1448                                          const Standard_Boolean               theToUpdateViewer)
1449 {
1450   if (theIObj.IsNull())
1451   {
1452     return;
1453   }
1454 
1455   theIObj->UnsetColor();
1456   theIObj->UpdatePresentations();
1457   if (theToUpdateViewer)
1458   {
1459     UpdateCurrentViewer();
1460   }
1461 }
1462 
1463 //=======================================================================
1464 //function : HasColor
1465 //purpose  :
1466 //=======================================================================
HasColor(const Handle (AIS_InteractiveObject)& theIObj) const1467 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1468 {
1469   return theIObj->HasColor();
1470 }
1471 
1472 //=======================================================================
1473 //function : Color
1474 //purpose  :
1475 //=======================================================================
Color(const Handle (AIS_InteractiveObject)& theIObj,Quantity_Color & theColor) const1476 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1477                                     Quantity_Color&                      theColor) const
1478 {
1479   theIObj->Color (theColor);
1480 }
1481 
1482 //=======================================================================
1483 //function : Width
1484 //purpose  :
1485 //=======================================================================
Width(const Handle (AIS_InteractiveObject)& theIObj) const1486 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1487 {
1488   return theIObj->Width();
1489 }
1490 
1491 //=======================================================================
1492 //function : SetWidth
1493 //purpose  :
1494 //=======================================================================
SetWidth(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Real theWidth,const Standard_Boolean theToUpdateViewer)1495 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1496                                        const Standard_Real                  theWidth,
1497                                        const Standard_Boolean               theToUpdateViewer)
1498 {
1499   if (theIObj.IsNull())
1500   {
1501     return;
1502   }
1503 
1504   setContextToObject (theIObj);
1505   theIObj->SetWidth (theWidth);
1506   theIObj->UpdatePresentations();
1507   if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1508   {
1509     if (myLastPicked->IsAutoHilight())
1510     {
1511       const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1512       myLastPicked->HilightWithColor (myMainPM,
1513                                       myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1514                                       aHiMode);
1515     }
1516     else
1517     {
1518       theIObj->HilightOwnerWithColor (myMainPM,
1519                                       myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1520                                       myLastPicked);
1521     }
1522   }
1523   if (theToUpdateViewer)
1524   {
1525     UpdateCurrentViewer();
1526   }
1527 }
1528 
1529 //=======================================================================
1530 //function : UnsetWidth
1531 //purpose  :
1532 //=======================================================================
UnsetWidth(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1533 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1534                                          const Standard_Boolean               theToUpdateViewer)
1535 {
1536   if (theIObj.IsNull())
1537   {
1538     return;
1539   }
1540 
1541   theIObj->UnsetWidth();
1542   theIObj->UpdatePresentations();
1543   if (theToUpdateViewer)
1544   {
1545     UpdateCurrentViewer();
1546   }
1547 }
1548 
1549 //=======================================================================
1550 //function : SetMaterial
1551 //purpose  :
1552 //=======================================================================
SetMaterial(const Handle (AIS_InteractiveObject)& theIObj,const Graphic3d_MaterialAspect & theMaterial,const Standard_Boolean theToUpdateViewer)1553 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1554                                           const Graphic3d_MaterialAspect&      theMaterial,
1555                                           const Standard_Boolean               theToUpdateViewer)
1556 {
1557   if (theIObj.IsNull())
1558   {
1559     return;
1560   }
1561 
1562   setContextToObject (theIObj);
1563   theIObj->SetMaterial (theMaterial);
1564   theIObj->UpdatePresentations();
1565   if (theToUpdateViewer)
1566   {
1567     UpdateCurrentViewer();
1568   }
1569 }
1570 
1571 //=======================================================================
1572 //function : UnsetMaterial
1573 //purpose  :
1574 //=======================================================================
UnsetMaterial(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1575 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1576                                             const Standard_Boolean               theToUpdateViewer)
1577 {
1578   if (theIObj.IsNull())
1579   {
1580     return;
1581   }
1582   theIObj->UnsetMaterial();
1583   theIObj->UpdatePresentations();
1584   if (theToUpdateViewer)
1585   {
1586     UpdateCurrentViewer();
1587   }
1588 }
1589 
1590 //=======================================================================
1591 //function : SetTransparency
1592 //purpose  :
1593 //=======================================================================
SetTransparency(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Real theValue,const Standard_Boolean theToUpdateViewer)1594 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1595                                               const Standard_Real                  theValue,
1596                                               const Standard_Boolean               theToUpdateViewer)
1597 {
1598   if (theIObj.IsNull())
1599   {
1600     return;
1601   }
1602 
1603   setContextToObject (theIObj);
1604   if (!theIObj->IsTransparent()
1605     && theValue <= 0.005)
1606   {
1607     return;
1608   }
1609 
1610   if (theValue <= 0.005)
1611   {
1612     UnsetTransparency (theIObj, theToUpdateViewer);
1613     return;
1614   }
1615 
1616   theIObj->SetTransparency (theValue);
1617   theIObj->UpdatePresentations();
1618   if (theToUpdateViewer)
1619   {
1620     UpdateCurrentViewer();
1621   }
1622 }
1623 
1624 //=======================================================================
1625 //function : UnsetTransparency
1626 //purpose  :
1627 //=======================================================================
UnsetTransparency(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1628 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1629                                                 const Standard_Boolean               theToUpdateViewer)
1630 {
1631   if (theIObj.IsNull())
1632   {
1633     return;
1634   }
1635 
1636   theIObj->UnsetTransparency();
1637   theIObj->UpdatePresentations();
1638   if (theToUpdateViewer)
1639   {
1640     UpdateCurrentViewer();
1641   }
1642 }
1643 
1644 //=======================================================================
1645 //function : SetSelectedAspect
1646 //purpose  :
1647 //=======================================================================
SetSelectedAspect(const Handle (Prs3d_BasicAspect)& theAspect,const Standard_Boolean theToUpdateViewer)1648 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1649                                                 const Standard_Boolean           theToUpdateViewer)
1650 {
1651   Standard_DISABLE_DEPRECATION_WARNINGS
1652   Standard_Boolean isFound = Standard_False;
1653   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1654   {
1655     isFound = Standard_True;
1656     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1657     anObj->SetAspect (theAspect);
1658   }
1659   Standard_ENABLE_DEPRECATION_WARNINGS
1660 
1661   if (isFound && theToUpdateViewer)
1662   {
1663     myMainVwr->Update();
1664   }
1665 }
1666 
1667 //=======================================================================
1668 //function : SetLocalAttributes
1669 //purpose  :
1670 //=======================================================================
SetLocalAttributes(const Handle (AIS_InteractiveObject)& theIObj,const Handle (Prs3d_Drawer)& theDrawer,const Standard_Boolean theToUpdateViewer)1671 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1672                                                  const Handle(Prs3d_Drawer)&          theDrawer,
1673                                                  const Standard_Boolean               theToUpdateViewer)
1674 {
1675   if (theIObj.IsNull())
1676   {
1677     return;
1678   }
1679 
1680   setContextToObject (theIObj);
1681   theIObj->SetAttributes (theDrawer);
1682   Update (theIObj, theToUpdateViewer);
1683 }
1684 
1685 //=======================================================================
1686 //function : UnsetLocalAttributes
1687 //purpose  :
1688 //=======================================================================
UnsetLocalAttributes(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateViewer)1689 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1690                                                    const Standard_Boolean               theToUpdateViewer)
1691 {
1692   if (theIObj.IsNull())
1693   {
1694     return;
1695   }
1696 
1697   setContextToObject (theIObj);
1698   theIObj->UnsetAttributes();
1699   Update (theIObj, theToUpdateViewer);
1700 }
1701 
1702 //=======================================================================
1703 //function : Status
1704 //purpose  :
1705 //=======================================================================
Status(const Handle (AIS_InteractiveObject)& theIObj,TCollection_ExtendedString & theStatus) const1706 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1707                                      TCollection_ExtendedString&          theStatus) const
1708 {
1709   theStatus = "";
1710   if (theIObj.IsNull()
1711   || !myObjects.IsBound (theIObj))
1712   {
1713     return;
1714   }
1715 
1716   theStatus += "\t ____________________________________________";
1717   theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1718   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1719   switch (theIObj->DisplayStatus())
1720   {
1721     case PrsMgr_DisplayStatus_Displayed:
1722     {
1723       theStatus += "\t| -->Displayed\n";
1724       break;
1725     }
1726     case PrsMgr_DisplayStatus_Erased:
1727     {
1728       theStatus += "\t| -->Erased\n";
1729       break;
1730     }
1731     default:
1732       break;
1733   }
1734 
1735   theStatus += "\t| Active Display Modes in the MainViewer :\n";
1736   theStatus += "\t|\t Mode ";
1737   theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1738   theStatus += "\n";
1739 
1740   if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1741 
1742   theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1743   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1744   {
1745     theStatus += "\t\t Mode ";
1746     theStatus += TCollection_AsciiString (aSelModeIter.Value());
1747     theStatus += "\n";
1748   }
1749   theStatus += "\t ____________________________________________";
1750 }
1751 
1752 //=======================================================================
1753 //function : GetDefModes
1754 //purpose  :
1755 //=======================================================================
GetDefModes(const Handle (AIS_InteractiveObject)& theIObj,Standard_Integer & theDispMode,Standard_Integer & theHiMode,Standard_Integer & theSelMode) const1756 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1757                                           Standard_Integer&                    theDispMode,
1758                                           Standard_Integer&                    theHiMode,
1759                                           Standard_Integer&                    theSelMode) const
1760 {
1761   if (theIObj.IsNull())
1762   {
1763     return;
1764   }
1765 
1766   theDispMode = theIObj->HasDisplayMode()
1767               ? theIObj->DisplayMode()
1768               : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1769                ? myDefaultDrawer->DisplayMode()
1770                : 0);
1771   theHiMode  = theIObj->HasHilightMode()   ? theIObj->HilightMode()   : theDispMode;
1772   theSelMode = theIObj->GlobalSelectionMode();
1773 }
1774 
1775 //=======================================================================
1776 //function : EraseGlobal
1777 //purpose  :
1778 //=======================================================================
EraseGlobal(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateviewer)1779 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1780                                           const Standard_Boolean               theToUpdateviewer)
1781 {
1782   Handle(AIS_GlobalStatus) aStatus;
1783   if (theIObj.IsNull()
1784   || !myObjects.Find (theIObj, aStatus)
1785   ||  theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Erased)
1786   {
1787     return;
1788   }
1789 
1790   const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1791   unselectOwners (theIObj);
1792   myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1793 
1794   if (!myLastPicked.IsNull()
1795     && myLastPicked->IsSameSelectable (theIObj))
1796   {
1797     clearDynamicHighlight();
1798   }
1799 
1800   // make sure highlighting presentations are properly erased
1801   theIObj->ErasePresentations (false);
1802 
1803   if (IsSelected (theIObj)
1804    && aStatus->DisplayMode() != aDispMode)
1805   {
1806     myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1807   }
1808 
1809   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1810   {
1811     mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1812   }
1813   aStatus->ClearSelectionModes();
1814   theIObj->SetDisplayStatus (PrsMgr_DisplayStatus_Erased);
1815 
1816   if (theToUpdateviewer)
1817   {
1818     myMainVwr->Update();
1819   }
1820 }
1821 
1822 //=======================================================================
1823 //function : unselectOwners
1824 //purpose  :
1825 //=======================================================================
unselectOwners(const Handle (AIS_InteractiveObject)& theObject)1826 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
1827 {
1828   SelectMgr_SequenceOfOwner aSeq;
1829   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1830   {
1831     if (aSelIter.Value()->IsSameSelectable (theObject))
1832     {
1833       aSeq.Append (aSelIter.Value());
1834     }
1835   }
1836   for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
1837   {
1838     AddOrRemoveSelected (aDelIter.Value(), Standard_False);
1839   }
1840 }
1841 
1842 //=======================================================================
1843 //function : ClearGlobal
1844 //purpose  :
1845 //=======================================================================
ClearGlobal(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Boolean theToUpdateviewer)1846 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1847                                           const Standard_Boolean               theToUpdateviewer)
1848 {
1849   Handle(AIS_GlobalStatus) aStatus;
1850   if (theIObj.IsNull()
1851   || !myObjects.Find (theIObj, aStatus))
1852   {
1853     // for cases when reference shape of connected interactives was not displayed
1854     // but its selection primitives were calculated
1855     const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1856     mgrSelector->Remove (anObj);
1857     return;
1858   }
1859 
1860   unselectOwners (theIObj);
1861 
1862   myMainPM->Erase (theIObj, -1);
1863   theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
1864 
1865   // Object removes from Detected sequence
1866   for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
1867   {
1868     Handle(SelectMgr_EntityOwner) aPicked = MainSelector()->Picked (myDetectedSeq (aDetIter));
1869     Handle(AIS_InteractiveObject) anObj;
1870     if (!aPicked.IsNull())
1871     {
1872       anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
1873     }
1874 
1875     if (!anObj.IsNull()
1876       && anObj == theIObj)
1877     {
1878       myDetectedSeq.Remove (aDetIter);
1879       if (myCurDetected == aDetIter)
1880       {
1881         myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
1882       }
1883       if (myCurHighlighted == aDetIter)
1884       {
1885         myCurHighlighted = 0;
1886       }
1887     }
1888     else
1889     {
1890       aDetIter++;
1891     }
1892   }
1893 
1894   // remove IO from the selection manager to avoid memory leaks
1895   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
1896   mgrSelector->Remove (anObj);
1897 
1898   setObjectStatus (theIObj, PrsMgr_DisplayStatus_None, -1, -1);
1899   myMainVwr->StructureManager()->UnregisterObject (theIObj);
1900 
1901   for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
1902   {
1903     aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
1904   }
1905 
1906   if (!myLastPicked.IsNull())
1907   {
1908     if (myLastPicked->IsSameSelectable (theIObj))
1909     {
1910       clearDynamicHighlight();
1911       myLastPicked.Nullify();
1912     }
1913   }
1914 
1915   if (theToUpdateviewer
1916    && theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
1917   {
1918     myMainVwr->Update();
1919   }
1920 }
1921 
1922 //=======================================================================
1923 //function : ClearGlobalPrs
1924 //purpose  :
1925 //=======================================================================
ClearGlobalPrs(const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theMode,const Standard_Boolean theToUpdateViewer)1926 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
1927                                              const Standard_Integer               theMode,
1928                                              const Standard_Boolean               theToUpdateViewer)
1929 {
1930   const Handle(AIS_GlobalStatus)* aStatus = !theIObj.IsNull() ? myObjects.Seek (theIObj) : NULL;
1931   if (aStatus == NULL)
1932   {
1933     return;
1934   }
1935 
1936   if ((*aStatus)->DisplayMode() == theMode)
1937   {
1938     const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1939     if (aDispMode == theMode
1940      && myMainPM->IsHighlighted (theIObj, theMode))
1941     {
1942       unhighlightGlobal (theIObj);
1943     }
1944 
1945     myMainPM->Erase (theIObj, theMode);
1946   }
1947 
1948   if (theIObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
1949    && theToUpdateViewer)
1950   {
1951     myMainVwr->Update();
1952   }
1953 }
1954 
1955 //=======================================================================
1956 //function : ClearDetected
1957 //purpose  :
1958 //=======================================================================
ClearDetected(Standard_Boolean theToRedrawImmediate)1959 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
1960 {
1961   myCurDetected = 0;
1962   myCurHighlighted = 0;
1963   myDetectedSeq.Clear();
1964   Standard_Boolean toUpdate = Standard_False;
1965   if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
1966   {
1967     toUpdate = Standard_True;
1968     clearDynamicHighlight();
1969   }
1970   myLastPicked.Nullify();
1971   MainSelector()->ClearPicked();
1972   if (toUpdate && theToRedrawImmediate)
1973   {
1974     myMainVwr->RedrawImmediate();
1975   }
1976   return toUpdate;
1977 }
1978 
1979 //=======================================================================
1980 //function : SetIsoNumber
1981 //purpose  :
1982 //=======================================================================
SetIsoNumber(const Standard_Integer theNb,const AIS_TypeOfIso theType)1983 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
1984                                            const AIS_TypeOfIso    theType)
1985 {
1986   switch (theType)
1987   {
1988     case AIS_TOI_IsoU:
1989       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
1990       break;
1991     case AIS_TOI_IsoV:
1992       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
1993       break;
1994     case AIS_TOI_Both:
1995       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
1996       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
1997       break;
1998   }
1999 }
2000 
2001 //=======================================================================
2002 //function : IsoNumber
2003 //purpose  :
2004 //=======================================================================
IsoNumber(const AIS_TypeOfIso theType)2005 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2006 {
2007   switch (theType)
2008   {
2009     case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2010     case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2011     case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2012                             ? myDefaultDrawer->UIsoAspect()->Number()
2013                             : -1;
2014   }
2015   return 0;
2016 }
2017 
2018 //=======================================================================
2019 //function : SetPixelTolerance
2020 //purpose  :
2021 //=======================================================================
SetPixelTolerance(const Standard_Integer thePrecision)2022 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2023 {
2024   MainSelector()->SetPixelTolerance (thePrecision);
2025 }
2026 
2027 //=======================================================================
2028 //function : PixelTolerance
2029 //purpose  :
2030 //=======================================================================
PixelTolerance() const2031 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2032 {
2033   return MainSelector()->PixelTolerance();
2034 }
2035 
2036 //=======================================================================
2037 //function : SetSelectionSensitivity
2038 //purpose  : Allows to manage sensitivity of a particular selection of interactive object theObject
2039 //=======================================================================
SetSelectionSensitivity(const Handle (AIS_InteractiveObject)& theObject,const Standard_Integer theMode,const Standard_Integer theNewSensitivity)2040 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2041                                                       const Standard_Integer theMode,
2042                                                       const Standard_Integer theNewSensitivity)
2043 {
2044   mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2045 }
2046 
2047 //=======================================================================
2048 //function : InitAttributes
2049 //purpose  :
2050 //=======================================================================
InitAttributes()2051 void AIS_InteractiveContext::InitAttributes()
2052 {
2053   Graphic3d_MaterialAspect aMat (Graphic3d_NameOfMaterial_Brass);
2054   myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2055 
2056 //  myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2057   Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2058   aLineAspect->SetColor      (Quantity_NOC_GRAY20);
2059   aLineAspect->SetWidth      (1.0);
2060   aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2061 
2062   // tolerance to 2 pixels...
2063   SetPixelTolerance (2);
2064 
2065   // Customizing the drawer for trihedrons and planes...
2066   Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2067   const Standard_Real aLength = 100.0;
2068   aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2069   const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2070   aTrihAspect->LineAspect(Prs3d_DatumParts_XAxis)->SetColor (aColor);
2071   aTrihAspect->LineAspect(Prs3d_DatumParts_YAxis)->SetColor (aColor);
2072   aTrihAspect->LineAspect(Prs3d_DatumParts_ZAxis)->SetColor (aColor);
2073 
2074   Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2075   const Standard_Real aPlaneLength = 200.0;
2076   aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2077   aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2078 }
2079 
2080 //=======================================================================
2081 //function : TrihedronSize
2082 //purpose  :
2083 //=======================================================================
TrihedronSize() const2084 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2085 {
2086   return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DatumParts_XAxis);
2087 }
2088 
2089 //=======================================================================
2090 //function : SetTrihedronSize
2091 //purpose  :
2092 //=======================================================================
SetTrihedronSize(const Standard_Real theVal,const Standard_Boolean)2093 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real    theVal,
2094                                                const Standard_Boolean /*updateviewer*/)
2095 {
2096   myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2097   Redisplay (AIS_KindOfInteractive_Datum, 3, Standard_False);
2098   Redisplay (AIS_KindOfInteractive_Datum, 4, Standard_True);
2099 }
2100 
2101 //=======================================================================
2102 //function : SetPlaneSize
2103 //purpose  :
2104 //=======================================================================
SetPlaneSize(const Standard_Real theValX,const Standard_Real theValY,const Standard_Boolean theToUpdateViewer)2105 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real    theValX,
2106                                           const Standard_Real    theValY,
2107                                           const Standard_Boolean theToUpdateViewer)
2108 {
2109   myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2110   Redisplay (AIS_KindOfInteractive_Datum, 7, theToUpdateViewer);
2111 }
2112 
2113 //=======================================================================
2114 //function : SetPlaneSize
2115 //purpose  :
2116 //=======================================================================
SetPlaneSize(const Standard_Real theVal,const Standard_Boolean theToUpdateViewer)2117 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real    theVal,
2118                                            const Standard_Boolean theToUpdateViewer)
2119 {
2120   SetPlaneSize (theVal, theVal, theToUpdateViewer);
2121 }
2122 
2123 //=======================================================================
2124 //function : PlaneSize
2125 //purpose  :
2126 //=======================================================================
PlaneSize(Standard_Real & theX,Standard_Real & theY) const2127 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2128                                                     Standard_Real& theY) const
2129 {
2130   theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2131   theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2132   return (Abs (theX - theY) <= Precision::Confusion());
2133 }
2134 
2135 //=======================================================================
2136 //function : SetZLayer
2137 //purpose  :
2138 //=======================================================================
SetZLayer(const Handle (AIS_InteractiveObject)& theIObj,const Graphic3d_ZLayerId theLayerId)2139 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2140                                         const Graphic3d_ZLayerId theLayerId)
2141 {
2142   if (theIObj.IsNull())
2143     return;
2144 
2145   theIObj->SetZLayer (theLayerId);
2146 }
2147 
2148 //=======================================================================
2149 //function : GetZLayer
2150 //purpose  :
2151 //=======================================================================
GetZLayer(const Handle (AIS_InteractiveObject)& theIObj) const2152 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2153 {
2154   return !theIObj.IsNull()
2155        ?  theIObj->ZLayer()
2156        :  Graphic3d_ZLayerId_UNKNOWN;
2157 }
2158 
2159 //=======================================================================
2160 //function : RebuildSelectionStructs
2161 //purpose  : Rebuilds 1st level of BVH selection forcibly
2162 //=======================================================================
RebuildSelectionStructs()2163 void AIS_InteractiveContext::RebuildSelectionStructs()
2164 {
2165   MainSelector()->RebuildObjectsTree (Standard_True);
2166 }
2167 
2168 //=======================================================================
2169 //function : Disconnect
2170 //purpose  : Disconnects selectable object from an assembly and updates selection structures
2171 //=======================================================================
Disconnect(const Handle (AIS_InteractiveObject)& theAssembly,const Handle (AIS_InteractiveObject)& theObjToDisconnect)2172 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2173                                          const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2174 {
2175   if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2176   {
2177     Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2178     theObj->Disconnect (theObjToDisconnect);
2179     if (!myObjects.IsBound (theObjToDisconnect))
2180     {
2181       // connected presentation might contain displayed presentations
2182       myMainPM->Erase (theObjToDisconnect, -1);
2183       theObjToDisconnect->ErasePresentations (true);
2184     }
2185 
2186     const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2187     mgrSelector->Remove (anObj);
2188   }
2189   else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2190   {
2191     Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2192     theObj->Disconnect();
2193     const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2194     mgrSelector->Remove (anObj);
2195   }
2196   else
2197     return;
2198 }
2199 
2200 //=======================================================================
2201 //function : FitSelected
2202 //purpose  : Fits the view corresponding to the bounds of selected objects
2203 //=======================================================================
FitSelected(const Handle (V3d_View)& theView)2204 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2205 {
2206   FitSelected (theView, 0.01, Standard_True);
2207 }
2208 
2209 //=======================================================================
2210 //function : BoundingBoxOfSelection
2211 //purpose  :
2212 //=======================================================================
BoundingBoxOfSelection() const2213 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
2214 {
2215   Bnd_Box aBndSelected;
2216   AIS_MapOfObjectOwners anObjectOwnerMap;
2217   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2218   {
2219     const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2220     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2221     if (anObj->IsInfinite())
2222     {
2223       continue;
2224     }
2225 
2226     if (anOwner == anObj->GlobalSelOwner())
2227     {
2228       Bnd_Box aTmpBnd;
2229       anObj->BoundingBox (aTmpBnd);
2230       aBndSelected.Add (aTmpBnd);
2231     }
2232     else
2233     {
2234       Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2235       if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2236       {
2237         anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2238         anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2239       }
2240 
2241       anOwnerMap->Add (anOwner);
2242     }
2243   }
2244 
2245   for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2246   {
2247     const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2248     Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2249     aBndSelected.Add (aTmpBox);
2250   }
2251 
2252   return aBndSelected;
2253 }
2254 
2255 //=======================================================================
2256 //function : FitSelected
2257 //purpose  : Fits the view corresponding to the bounds of selected objects
2258 //=======================================================================
FitSelected(const Handle (V3d_View)& theView,const Standard_Real theMargin,const Standard_Boolean theToUpdate)2259 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2260                                           const Standard_Real theMargin,
2261                                           const Standard_Boolean theToUpdate)
2262 {
2263   Bnd_Box aBndSelected = BoundingBoxOfSelection();
2264   if (!aBndSelected.IsVoid())
2265   {
2266     theView->FitAll (aBndSelected, theMargin, theToUpdate);
2267   }
2268 }
2269 
2270 //=======================================================================
2271 //function : SetTransformPersistence
2272 //purpose  :
2273 //=======================================================================
SetTransformPersistence(const Handle (AIS_InteractiveObject)& theObject,const Handle (Graphic3d_TransformPers)& theTrsfPers)2274 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2275                                                       const Handle(Graphic3d_TransformPers)& theTrsfPers)
2276 {
2277   theObject->SetTransformPersistence (theTrsfPers);
2278   if (!myObjects.IsBound (theObject))
2279   {
2280     return;
2281   }
2282 
2283   mgrSelector->UpdateSelection (theObject);
2284 
2285   const Graphic3d_ZLayerId  aLayerId   = theObject->ZLayer();
2286   const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2287   for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2288   {
2289     anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2290     anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2291   }
2292 }
2293 
2294 //=======================================================================
2295 //function : GravityPoint
2296 //purpose  :
2297 //=======================================================================
GravityPoint(const Handle (V3d_View)& theView) const2298 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2299 {
2300   return theView->GravityPoint();
2301 }
2302 
2303 //=======================================================================
2304 //function : setObjectStatus
2305 //purpose  :
2306 //=======================================================================
setObjectStatus(const Handle (AIS_InteractiveObject)& theIObj,const PrsMgr_DisplayStatus theStatus,const Standard_Integer theDispMode,const Standard_Integer theSelectionMode)2307 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2308                                               const PrsMgr_DisplayStatus theStatus,
2309                                               const Standard_Integer theDispMode,
2310                                               const Standard_Integer theSelectionMode)
2311 {
2312   theIObj->SetDisplayStatus (theStatus);
2313   if (theStatus != PrsMgr_DisplayStatus_None)
2314   {
2315     Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus();
2316     aStatus->SetDisplayMode (theDispMode);
2317     if (theSelectionMode != -1)
2318     {
2319       aStatus->AddSelectionMode (theSelectionMode);
2320     }
2321     myObjects.Bind (theIObj, aStatus);
2322   }
2323   else
2324   {
2325     myObjects.UnBind (theIObj);
2326   }
2327 
2328   for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2329   {
2330     Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2331     if (aChild.IsNull())
2332     {
2333       continue;
2334     }
2335 
2336     setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
2337   }
2338 }
2339 
2340 //=======================================================================
2341 //function : highlightWithColor
2342 //purpose  :
2343 //=======================================================================
highlightWithColor(const Handle (SelectMgr_EntityOwner)& theOwner,const Handle (V3d_Viewer)& theViewer)2344 void AIS_InteractiveContext::highlightWithColor (const Handle(SelectMgr_EntityOwner)& theOwner,
2345                                                  const Handle(V3d_Viewer)& theViewer)
2346 {
2347   const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2348   if (anObj.IsNull())
2349   {
2350     return;
2351   }
2352 
2353   const Handle(Prs3d_Drawer)& aStyle = getHiStyle (anObj, theOwner);
2354   const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
2355 
2356   myMainPM->BeginImmediateDraw();
2357   theOwner->HilightWithColor (myMainPM, aStyle, aHiMode);
2358   myMainPM->EndImmediateDraw (theViewer.IsNull() ? myMainVwr : theViewer);
2359 }
2360 
2361 //=======================================================================
2362 //function : highlightSelected
2363 //purpose  :
2364 //=======================================================================
highlightSelected(const Handle (SelectMgr_EntityOwner)& theOwner)2365 void AIS_InteractiveContext::highlightSelected (const Handle(SelectMgr_EntityOwner)& theOwner)
2366 {
2367   AIS_NListOfEntityOwner anOwners;
2368   const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
2369   if (anObj.IsNull())
2370   {
2371     return;
2372   }
2373 
2374   if (!theOwner->IsAutoHilight())
2375   {
2376     SelectMgr_SequenceOfOwner aSeq;
2377     for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2378     {
2379       if (aSelIter.Value()->IsSameSelectable (anObj))
2380       {
2381         anOwners.Append (aSelIter.Value());
2382       }
2383     }
2384   }
2385   else
2386   {
2387     anOwners.Append (theOwner);
2388   }
2389   highlightOwners (anOwners, Handle(Prs3d_Drawer)());
2390 }
2391 
2392 //=======================================================================
2393 //function : highlightGlobal
2394 //purpose  :
2395 //=======================================================================
highlightGlobal(const Handle (AIS_InteractiveObject)& theObj,const Handle (Prs3d_Drawer)& theStyle,const Standard_Integer theDispMode)2396 void AIS_InteractiveContext::highlightGlobal (const Handle(AIS_InteractiveObject)& theObj,
2397                                               const Handle(Prs3d_Drawer)& theStyle,
2398                                               const Standard_Integer theDispMode)
2399 {
2400   if (theObj.IsNull())
2401   {
2402     return;
2403   }
2404 
2405   const Standard_Integer aHiMode = getHilightMode (theObj, theStyle, theDispMode);
2406   const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2407 
2408   if (aGlobOwner.IsNull())
2409   {
2410     myMainPM->Color (theObj, theStyle, aHiMode);
2411     return;
2412   }
2413 
2414   AIS_NListOfEntityOwner anOwners;
2415   if (!aGlobOwner->IsAutoHilight())
2416   {
2417     SelectMgr_SequenceOfOwner aSeq;
2418     for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2419     {
2420       if (aSelIter.Value()->IsSameSelectable (theObj))
2421       {
2422         anOwners.Append (aSelIter.Value());
2423       }
2424     }
2425   }
2426   else
2427   {
2428     anOwners.Append (aGlobOwner);
2429   }
2430   highlightOwners (anOwners, theStyle);
2431 }
2432 
2433 //=======================================================================
2434 //function : unhighlightSelected
2435 //purpose  :
2436 //=======================================================================
unhighlightSelected(const Standard_Boolean theIsToHilightSubIntensity)2437 void AIS_InteractiveContext::unhighlightSelected (const Standard_Boolean theIsToHilightSubIntensity)
2438 {
2439   unhighlightOwners (mySelection->Objects(), theIsToHilightSubIntensity);
2440 }
2441 
2442 //=======================================================================
2443 //function : unhighlightOwners
2444 //purpose  :
2445 //=======================================================================
unhighlightOwners(const AIS_NListOfEntityOwner & theOwners,const Standard_Boolean theIsToHilightSubIntensity)2446 void AIS_InteractiveContext::unhighlightOwners (const AIS_NListOfEntityOwner& theOwners,
2447                                                 const Standard_Boolean theIsToHilightSubIntensity)
2448 {
2449   NCollection_IndexedMap<Handle(AIS_InteractiveObject)> anObjToClear;
2450   for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
2451   {
2452     const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
2453     const Handle(AIS_InteractiveObject) anInteractive = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
2454     Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anInteractive);
2455     if (!aStatusPtr)
2456     {
2457       continue;
2458     }
2459 
2460     if (anOwner->IsAutoHilight())
2461     {
2462       anOwner->Unhilight (myMainPM);
2463       if (theIsToHilightSubIntensity)
2464       {
2465         if ((*aStatusPtr)->IsSubIntensityOn())
2466         {
2467           const Standard_Integer aHiMode = getHilightMode (anInteractive, (*aStatusPtr)->HilightStyle(), (*aStatusPtr)->DisplayMode());
2468           highlightWithSubintensity (anOwner, aHiMode);
2469         }
2470       }
2471     }
2472     else
2473     {
2474       anObjToClear.Add (anInteractive);
2475     }
2476     if (anOwner == anInteractive->GlobalSelOwner())
2477     {
2478       (*aStatusPtr)->SetHilightStatus (Standard_False);
2479     }
2480     (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
2481   }
2482   for (NCollection_IndexedMap<Handle(AIS_InteractiveObject)>::Iterator anIter (anObjToClear); anIter.More(); anIter.Next())
2483   {
2484     const Handle(AIS_InteractiveObject)& anObj = anIter.Value();
2485     myMainPM->Unhighlight (anObj);
2486     anObj->ClearSelected();
2487   }
2488 }
2489 
2490 //=======================================================================
2491 //function : unhighlightGlobal
2492 //purpose  :
2493 //=======================================================================
unhighlightGlobal(const Handle (AIS_InteractiveObject)& theObj)2494 void AIS_InteractiveContext::unhighlightGlobal (const Handle(AIS_InteractiveObject)& theObj)
2495 {
2496   if (theObj.IsNull())
2497   {
2498     return;
2499   }
2500 
2501   const Handle(SelectMgr_EntityOwner)& aGlobOwner = theObj->GlobalSelOwner();
2502   if (aGlobOwner.IsNull())
2503   {
2504     myMainPM->Unhighlight (theObj);
2505     return;
2506   }
2507 
2508   AIS_NListOfEntityOwner anOwners;
2509   anOwners.Append (aGlobOwner);
2510   unhighlightOwners (anOwners);
2511 }
2512 
2513 //=======================================================================
2514 //function : turnOnSubintensity
2515 //purpose  :
2516 //=======================================================================
turnOnSubintensity(const Handle (AIS_InteractiveObject)& theObject,const Standard_Integer theDispMode,const Standard_Boolean theIsDisplayedOnly) const2517 void AIS_InteractiveContext::turnOnSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2518                                                  const Standard_Integer theDispMode,
2519                                                  const Standard_Boolean theIsDisplayedOnly) const
2520 {
2521   // the only differ with selection highlight is color, so sync transparency values
2522   const Handle(Prs3d_Drawer)& aSubStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
2523   aSubStyle->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2524 
2525   if (theObject.IsNull())
2526   {
2527     for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjsIter (myObjects); anObjsIter.More(); anObjsIter.Next())
2528     {
2529       const Handle(AIS_GlobalStatus)& aStatus = anObjsIter.Value();
2530       if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2531       {
2532         continue;
2533       }
2534 
2535       aStatus->SetSubIntensity (true);
2536       myMainPM->Color (anObjsIter.Key(), aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2537     }
2538   }
2539   else
2540   {
2541     Handle(AIS_GlobalStatus) aStatus;
2542     if (!myObjects.Find (theObject, aStatus))
2543     {
2544       return;
2545     }
2546 
2547     if (theObject->DisplayStatus() != PrsMgr_DisplayStatus_Displayed && theIsDisplayedOnly)
2548     {
2549       return;
2550     }
2551 
2552     aStatus->SetSubIntensity (true);
2553     myMainPM->Color (theObject, aSubStyle, theDispMode != -1 ? theDispMode : aStatus->DisplayMode());
2554   }
2555 }
2556 
2557 //=======================================================================
2558 //function : highlightWithSubintensity
2559 //purpose  :
2560 //=======================================================================
highlightWithSubintensity(const Handle (AIS_InteractiveObject)& theObject,const Standard_Integer theMode) const2561 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(AIS_InteractiveObject)& theObject,
2562                                                         const Standard_Integer theMode) const
2563 {
2564   // the only differ with selection highlight is color, so
2565   // sync transparency values
2566   myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2567 
2568   myMainPM->Color (theObject, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2569 }
2570 
2571 //=======================================================================
2572 //function : highlightWithSubintensity
2573 //purpose  :
2574 //=======================================================================
highlightWithSubintensity(const Handle (SelectMgr_EntityOwner)& theOwner,const Standard_Integer theMode) const2575 void AIS_InteractiveContext::highlightWithSubintensity (const Handle(SelectMgr_EntityOwner)& theOwner,
2576                                                         const Standard_Integer theMode) const
2577 {
2578   // the only differ with selection highlight is color, so
2579   // sync transparency values
2580   myStyles[Prs3d_TypeOfHighlight_SubIntensity]->SetTransparency (myStyles[Prs3d_TypeOfHighlight_Selected]->Transparency());
2581 
2582   theOwner->HilightWithColor (myMainPM, myStyles[Prs3d_TypeOfHighlight_SubIntensity], theMode);
2583 }
2584 
2585 //=======================================================================
2586 //function : isSlowHiStyle
2587 //purpose  :
2588 //=======================================================================
isSlowHiStyle(const Handle (SelectMgr_EntityOwner)& theOwner,const Handle (V3d_Viewer)& theViewer) const2589 Standard_Boolean AIS_InteractiveContext::isSlowHiStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
2590                                                         const Handle(V3d_Viewer)& theViewer) const
2591 {
2592   if (const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable()))
2593   {
2594     const Handle(Prs3d_Drawer)& aHiStyle = getHiStyle (anObj, myLastPicked);
2595     return aHiStyle->ZLayer() == Graphic3d_ZLayerId_UNKNOWN
2596        || !theViewer->ZLayerSettings (aHiStyle->ZLayer()).IsImmediate();
2597   }
2598   return Standard_False;
2599 }
2600 
2601 //=======================================================================
2602 //function : MoveTo
2603 //purpose  :
2604 //=======================================================================
MoveTo(const Standard_Integer theXPix,const Standard_Integer theYPix,const Handle (V3d_View)& theView,const Standard_Boolean theToRedrawOnUpdate)2605 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer  theXPix,
2606                                                       const Standard_Integer  theYPix,
2607                                                       const Handle(V3d_View)& theView,
2608                                                       const Standard_Boolean  theToRedrawOnUpdate)
2609 {
2610   if (theView->Viewer() != myMainVwr)
2611   {
2612     throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2613   }
2614   MainSelector()->Pick (theXPix, theYPix, theView);
2615   return moveTo (theView, theToRedrawOnUpdate);
2616 }
2617 
2618 //=======================================================================
2619 //function : MoveTo
2620 //purpose  :
2621 //=======================================================================
MoveTo(const gp_Ax1 & theAxis,const Handle (V3d_View)& theView,const Standard_Boolean theToRedrawOnUpdate)2622 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const gp_Ax1& theAxis,
2623                                                       const Handle(V3d_View)& theView,
2624                                                       const Standard_Boolean  theToRedrawOnUpdate)
2625 {
2626   if (theView->Viewer() != myMainVwr)
2627   {
2628     throw Standard_ProgramError ("AIS_InteractiveContext::MoveTo() - invalid argument");
2629   }
2630   MainSelector()->Pick (theAxis, theView);
2631   return moveTo (theView, theToRedrawOnUpdate);
2632 }
2633 
2634 //=======================================================================
2635 //function : moveTo
2636 //purpose  :
2637 //=======================================================================
moveTo(const Handle (V3d_View)& theView,const Standard_Boolean theToRedrawOnUpdate)2638 AIS_StatusOfDetection AIS_InteractiveContext::moveTo (const Handle(V3d_View)& theView,
2639                                                       const Standard_Boolean  theToRedrawOnUpdate)
2640 {
2641   myCurDetected = 0;
2642   myCurHighlighted = 0;
2643   myDetectedSeq.Clear();
2644   myLastActiveView = theView.get();
2645 
2646   // preliminaires
2647   AIS_StatusOfDetection aStatus        = AIS_SOD_Nothing;
2648   Standard_Boolean      toUpdateViewer = Standard_False;
2649 
2650   myFilters->SetDisabledObjects (theView->View()->HiddenObjects());
2651 
2652   // filling of myAISDetectedSeq sequence storing information about detected AIS objects
2653   // (the objects must be AIS_Shapes)
2654   const Standard_Integer aDetectedNb = MainSelector()->NbPicked();
2655   Standard_Integer aNewDetected = 0;
2656   Standard_Boolean toIgnoreDetTop = Standard_False;
2657   for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
2658   {
2659     Handle(SelectMgr_EntityOwner) anOwner = MainSelector()->Picked (aDetIter);
2660     if (anOwner.IsNull()
2661      || !myFilters->IsOk (anOwner))
2662     {
2663       if (myPickingStrategy == SelectMgr_PickingStrategy_OnlyTopmost)
2664       {
2665         toIgnoreDetTop = Standard_True;
2666       }
2667       continue;
2668     }
2669 
2670     if (aNewDetected < 1
2671     && !toIgnoreDetTop)
2672     {
2673       aNewDetected = aDetIter;
2674     }
2675 
2676     myDetectedSeq.Append (aDetIter);
2677   }
2678 
2679   if (aNewDetected >= 1)
2680   {
2681     myCurHighlighted = myDetectedSeq.Lower();
2682 
2683     // Does nothing if previously detected object is equal to the current one.
2684     // However in advanced selection modes the owners comparison
2685     // is not effective because in that case only one owner manage the
2686     // selection in current selection mode. It is necessary to check the current detected
2687     // entity and hilight it only if the detected entity is not the same as
2688     // previous detected (IsForcedHilight call)
2689     Handle(SelectMgr_EntityOwner) aNewPickedOwner = MainSelector()->Picked (aNewDetected);
2690     if (aNewPickedOwner == myLastPicked && !aNewPickedOwner->IsForcedHilight())
2691     {
2692       return myLastPicked->IsSelected()
2693            ? AIS_SOD_Selected
2694            : AIS_SOD_OnlyOneDetected;
2695     }
2696 
2697     // Previously detected object is unhilighted if it is not selected or hilighted
2698     // with selection color if it is selected. Such highlighting with selection color
2699     // is needed only if myToHilightSelected flag is true. In this case previously detected
2700     // object has been already highlighted with myHilightColor during previous MoveTo()
2701     // method call. As result it is necessary to rehighligt it with mySelectionColor.
2702     if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2703     {
2704       if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2705       {
2706         theView->Viewer()->Invalidate();
2707       }
2708 
2709       clearDynamicHighlight();
2710       toUpdateViewer = Standard_True;
2711     }
2712 
2713     // initialize myLastPicked field with currently detected object
2714     myLastPicked = aNewPickedOwner;
2715 
2716     // highlight detected object if it is not selected or myToHilightSelected flag is true
2717     if (myLastPicked->HasSelectable())
2718     {
2719       if (myAutoHilight
2720        && (!myLastPicked->IsSelected()
2721          || myToHilightSelected))
2722       {
2723         if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2724         {
2725           theView->Viewer()->Invalidate();
2726         }
2727 
2728         highlightWithColor (myLastPicked, theView->Viewer());
2729         toUpdateViewer = Standard_True;
2730       }
2731 
2732       aStatus = myLastPicked->IsSelected()
2733               ? AIS_SOD_Selected
2734               : AIS_SOD_OnlyOneDetected;
2735     }
2736   }
2737   else
2738   {
2739     // previously detected object is unhilighted if it is not selected or hilighted
2740     // with selection color if it is selected
2741     aStatus = AIS_SOD_Nothing;
2742     if (myAutoHilight
2743     && !myLastPicked.IsNull()
2744      && myLastPicked->HasSelectable())
2745     {
2746       if (isSlowHiStyle (myLastPicked, theView->Viewer()))
2747       {
2748         theView->Viewer()->Invalidate();
2749       }
2750 
2751       clearDynamicHighlight();
2752       toUpdateViewer = Standard_True;
2753     }
2754 
2755     myLastPicked.Nullify();
2756   }
2757 
2758   if (toUpdateViewer
2759    && theToRedrawOnUpdate)
2760   {
2761     if (theView->ComputedMode())
2762     {
2763       theView->Viewer()->Update();
2764     }
2765     else
2766     {
2767       if (theView->IsInvalidated())
2768       {
2769         theView->Viewer()->Redraw();
2770       }
2771       else
2772       {
2773         theView->Viewer()->RedrawImmediate();
2774       }
2775     }
2776   }
2777 
2778   return aStatus;
2779 }
2780 
2781 //=======================================================================
2782 //function : AddSelect
2783 //purpose  :
2784 //=======================================================================
AddSelect(const Handle (SelectMgr_EntityOwner)& theObject)2785 AIS_StatusOfPick AIS_InteractiveContext::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
2786 {
2787   mySelection->AddSelect (theObject);
2788 
2789   Standard_Integer aSelNum = NbSelected();
2790   return (aSelNum == 0) ? AIS_SOP_NothingSelected
2791                         : (aSelNum == 1) ? AIS_SOP_OneSelected
2792                                          : AIS_SOP_SeveralSelected;
2793 }
2794 
2795 //=======================================================================
2796 //function : SelectRectangle
2797 //purpose  :
2798 //=======================================================================
SelectRectangle(const Graphic3d_Vec2i & thePntMin,const Graphic3d_Vec2i & thePntMax,const Handle (V3d_View)& theView,const AIS_SelectionScheme theSelScheme)2799 AIS_StatusOfPick AIS_InteractiveContext::SelectRectangle (const Graphic3d_Vec2i&    thePntMin,
2800                                                           const Graphic3d_Vec2i&    thePntMax,
2801                                                           const Handle(V3d_View)&   theView,
2802                                                           const AIS_SelectionScheme theSelScheme)
2803 {
2804   if (theView->Viewer() != myMainVwr)
2805   {
2806     throw Standard_ProgramError ("AIS_InteractiveContext::SelectRectangle() - invalid argument");
2807   }
2808 
2809   myLastActiveView = theView.get();
2810   MainSelector()->Pick (thePntMin.x(), thePntMin.y(), thePntMax.x(), thePntMax.y(), theView);
2811 
2812   AIS_NArray1OfEntityOwner aPickedOwners;
2813   if (MainSelector()->NbPicked() > 0)
2814   {
2815     aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2816     for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2817     {
2818       aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2819     }
2820   }
2821 
2822   return Select (aPickedOwners, theSelScheme);
2823 }
2824 
2825 //=======================================================================
2826 //function : SelectPolygon
2827 //purpose  :
2828 //=======================================================================
SelectPolygon(const TColgp_Array1OfPnt2d & thePolyline,const Handle (V3d_View)& theView,const AIS_SelectionScheme theSelScheme)2829 AIS_StatusOfPick AIS_InteractiveContext::SelectPolygon (const TColgp_Array1OfPnt2d& thePolyline,
2830                                                         const Handle(V3d_View)&     theView,
2831                                                         const AIS_SelectionScheme   theSelScheme)
2832 {
2833   if (theView->Viewer() != myMainVwr)
2834   {
2835     throw Standard_ProgramError ("AIS_InteractiveContext::SelectPolygon() - invalid argument");
2836   }
2837 
2838   myLastActiveView = theView.get();
2839   MainSelector()->Pick (thePolyline, theView);
2840 
2841   AIS_NArray1OfEntityOwner aPickedOwners;
2842   if (MainSelector()->NbPicked() > 0)
2843   {
2844     aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2845     for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2846     {
2847       aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2848     }
2849   }
2850 
2851   return Select (aPickedOwners, theSelScheme);
2852 }
2853 
2854 //=======================================================================
2855 //function : SelectPoint
2856 //purpose  :
2857 //=======================================================================
SelectPoint(const Graphic3d_Vec2i & thePnt,const Handle (V3d_View)& theView,const AIS_SelectionScheme theSelScheme)2858 AIS_StatusOfPick AIS_InteractiveContext::SelectPoint (const Graphic3d_Vec2i&    thePnt,
2859                                                       const Handle(V3d_View)&   theView,
2860                                                       const AIS_SelectionScheme theSelScheme)
2861 {
2862   if (theView->Viewer() != myMainVwr)
2863   {
2864     throw Standard_ProgramError ("AIS_InteractiveContext::SelectPoint() - invalid argument");
2865   }
2866 
2867   myLastActiveView = theView.get();
2868   MainSelector()->Pick (thePnt.x(), thePnt.y(), theView);
2869 
2870   AIS_NArray1OfEntityOwner aPickedOwners;
2871   if (MainSelector()->NbPicked() > 0)
2872   {
2873     aPickedOwners.Resize (1, MainSelector()->NbPicked(), false);
2874     for (Standard_Integer aPickIter = 1; aPickIter <= MainSelector()->NbPicked(); ++aPickIter)
2875     {
2876       aPickedOwners.SetValue (aPickIter, MainSelector()->Picked (aPickIter));
2877     }
2878   }
2879 
2880   return Select (aPickedOwners, theSelScheme);
2881 }
2882 
2883 //=======================================================================
2884 //function : SelectDetected
2885 //purpose  :
2886 //=======================================================================
SelectDetected(const AIS_SelectionScheme theSelScheme)2887 AIS_StatusOfPick AIS_InteractiveContext::SelectDetected (const AIS_SelectionScheme theSelScheme)
2888 {
2889   if (theSelScheme == AIS_SelectionScheme_Replace && !myLastPicked.IsNull())
2890   {
2891     Graphic3d_Vec2i aMousePos (-1, -1);
2892     gp_Pnt2d aMouseRealPos = MainSelector()->GetManager().GetMousePosition();
2893     if (!Precision::IsInfinite (aMouseRealPos.X()) &&
2894         !Precision::IsInfinite (aMouseRealPos.Y()))
2895     {
2896       aMousePos.SetValues ((Standard_Integer )aMouseRealPos.X(), (Standard_Integer )aMouseRealPos.Y());
2897     }
2898     if (myLastPicked->HandleMouseClick (aMousePos, Aspect_VKeyMouse_LeftButton, Aspect_VKeyFlags_NONE, false))
2899     {
2900       return AIS_SOP_NothingSelected;
2901     }
2902   }
2903 
2904   AIS_NArray1OfEntityOwner aPickedOwners (1, 1);
2905   aPickedOwners.SetValue (1, myLastPicked);
2906   return Select (aPickedOwners, theSelScheme);
2907 }
2908 
2909 //=======================================================================
2910 //function : Select
2911 //purpose  :
2912 //=======================================================================
Select(const Standard_Integer theXPMin,const Standard_Integer theYPMin,const Standard_Integer theXPMax,const Standard_Integer theYPMax,const Handle (V3d_View)& theView,const Standard_Boolean theToUpdateViewer)2913 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMin,
2914                                                  const Standard_Integer  theYPMin,
2915                                                  const Standard_Integer  theXPMax,
2916                                                  const Standard_Integer  theYPMax,
2917                                                  const Handle(V3d_View)& theView,
2918                                                  const Standard_Boolean  theToUpdateViewer)
2919 {
2920   AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
2921                                               Graphic3d_Vec2i (theXPMax, theYPMax),
2922                                               theView);
2923   if (theToUpdateViewer)
2924   {
2925     UpdateCurrentViewer();
2926   }
2927   return aStatus;
2928 }
2929 
2930 //=======================================================================
2931 //function : Select
2932 //purpose  : Selection by polyline
2933 //=======================================================================
Select(const TColgp_Array1OfPnt2d & thePolyline,const Handle (V3d_View)& theView,const Standard_Boolean theToUpdateViewer)2934 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
2935                                                  const Handle(V3d_View)&     theView,
2936                                                  const Standard_Boolean      theToUpdateViewer)
2937 {
2938   AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView);
2939   if (theToUpdateViewer)
2940   {
2941     UpdateCurrentViewer();
2942   }
2943   return aStatus;
2944 }
2945 
2946 //=======================================================================
2947 //function : Select
2948 //purpose  :
2949 //=======================================================================
Select(const Standard_Boolean theToUpdateViewer)2950 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean theToUpdateViewer)
2951 {
2952   AIS_StatusOfPick aStatus = SelectDetected();
2953   if (theToUpdateViewer)
2954   {
2955     UpdateCurrentViewer();
2956   }
2957   return aStatus;
2958 }
2959 
2960 //=======================================================================
2961 //function : ShiftSelect
2962 //purpose  :
2963 //=======================================================================
ShiftSelect(const Standard_Boolean theToUpdateViewer)2964 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean theToUpdateViewer)
2965 {
2966   AIS_StatusOfPick aStatus = SelectDetected (AIS_SelectionScheme_XOR);
2967   if (theToUpdateViewer)
2968   {
2969     UpdateCurrentViewer();
2970   }
2971   return aStatus;
2972 }
2973 
2974 //=======================================================================
2975 //function : ShiftSelect
2976 //purpose  :
2977 //=======================================================================
ShiftSelect(const Standard_Integer theXPMin,const Standard_Integer theYPMin,const Standard_Integer theXPMax,const Standard_Integer theYPMax,const Handle (V3d_View)& theView,const Standard_Boolean theToUpdateViewer)2978 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
2979                                                       const Standard_Integer theYPMin,
2980                                                       const Standard_Integer theXPMax,
2981                                                       const Standard_Integer theYPMax,
2982                                                       const Handle(V3d_View)& theView,
2983                                                       const Standard_Boolean theToUpdateViewer)
2984 {
2985   AIS_StatusOfPick aStatus = SelectRectangle (Graphic3d_Vec2i (theXPMin, theYPMin),
2986                                               Graphic3d_Vec2i (theXPMax, theYPMax),
2987                                               theView,
2988                                               AIS_SelectionScheme_XOR);
2989   if (theToUpdateViewer)
2990   {
2991     UpdateCurrentViewer();
2992   }
2993   return aStatus;
2994 }
2995 
2996 //=======================================================================
2997 //function : ShiftSelect
2998 //purpose  :
2999 //=======================================================================
ShiftSelect(const TColgp_Array1OfPnt2d & thePolyline,const Handle (V3d_View)& theView,const Standard_Boolean theToUpdateViewer)3000 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
3001                                                       const Handle(V3d_View)& theView,
3002                                                       const Standard_Boolean theToUpdateViewer)
3003 {
3004   AIS_StatusOfPick aStatus = SelectPolygon (thePolyline, theView, AIS_SelectionScheme_XOR);
3005   if (theToUpdateViewer)
3006   {
3007     UpdateCurrentViewer();
3008   }
3009   return aStatus;
3010 }
3011 
3012 //=======================================================================
3013 //function : Select
3014 //purpose  :
3015 //=======================================================================
Select(const AIS_NArray1OfEntityOwner & theOwners,const AIS_SelectionScheme theSelScheme)3016 AIS_StatusOfPick AIS_InteractiveContext::Select (const AIS_NArray1OfEntityOwner& theOwners,
3017                                                  const AIS_SelectionScheme theSelScheme)
3018 {
3019   NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)> aSelOwnerMap (myAutoHilight ? mySelection->Objects().Size() : 0);
3020   if (myAutoHilight)
3021   {
3022     clearDynamicHighlight();
3023 
3024     // collect currently selected owners
3025     for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3026     {
3027       aSelOwnerMap.Add (anOwnerIter.Value());
3028     }
3029   }
3030 
3031   mySelection->SelectOwners (theOwners, theSelScheme, MainSelector()->GetManager().IsOverlapAllowed(), myFilters);
3032 
3033   if (myAutoHilight)
3034   {
3035     // collect lists of owners to unhighlight (unselected) and to highlight (selected)
3036     AIS_NListOfEntityOwner anOwnersToUnhighlight, anOwnersToHighlight;
3037     for (AIS_NListOfEntityOwner::Iterator anOwnerIter (mySelection->Objects()); anOwnerIter.More(); anOwnerIter.Next())
3038     {
3039       // add newly selected owners
3040       const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3041       if (!aSelOwnerMap.RemoveKey (anOwner))
3042       {
3043         // newly selected owner
3044         anOwnersToHighlight.Append (anOwner);
3045       }
3046       else
3047       {
3048         // already selected owner
3049         if (!anOwner->IsAutoHilight()
3050           && theSelScheme != AIS_SelectionScheme_XOR
3051           && theSelScheme != AIS_SelectionScheme_Add)
3052         {
3053           // hack to perform AIS_InteractiveObject::ClearSelected() before highlighting
3054           anOwnersToUnhighlight.Append (anOwner);
3055           anOwnersToHighlight.Append (anOwner);
3056         }
3057         else if (anOwner->IsForcedHilight()
3058              || !anOwner->IsAutoHilight())
3059         {
3060           anOwnersToHighlight.Append (anOwner);
3061         }
3062       }
3063     }
3064 
3065     for (NCollection_IndexedMap<Handle(SelectMgr_EntityOwner)>::Iterator anOwnerIter (aSelOwnerMap); anOwnerIter.More(); anOwnerIter.Next())
3066     {
3067       // owners removed from selection
3068       const Handle(SelectMgr_EntityOwner)& anOwner = anOwnerIter.Value();
3069       anOwnersToUnhighlight.Append (anOwner);
3070     }
3071 
3072     unhighlightOwners (anOwnersToUnhighlight);
3073     highlightOwners (anOwnersToHighlight, Handle(Prs3d_Drawer)());
3074   }
3075 
3076   Standard_Integer aSelNum = NbSelected();
3077   return (aSelNum == 0) ? AIS_SOP_NothingSelected
3078                         : (aSelNum == 1) ? AIS_SOP_OneSelected
3079                                          : AIS_SOP_SeveralSelected;
3080 }
3081 
3082 //=======================================================================
3083 //function : HilightSelected
3084 //purpose  :
3085 //=======================================================================
HilightSelected(const Standard_Boolean theToUpdateViewer)3086 void AIS_InteractiveContext::HilightSelected (const Standard_Boolean theToUpdateViewer)
3087 {
3088   // In case of selection without using local context
3089   clearDynamicHighlight();
3090 
3091   highlightOwners (mySelection->Objects(), Handle(Prs3d_Drawer)());
3092 
3093   if (theToUpdateViewer)
3094   {
3095     UpdateCurrentViewer();
3096   }
3097 }
3098 
3099 //=======================================================================
3100 //function : highlightOwners
3101 //purpose  :
3102 //=======================================================================
highlightOwners(const AIS_NListOfEntityOwner & theOwners,const Handle (Prs3d_Drawer)& theStyle)3103 void AIS_InteractiveContext::highlightOwners (const AIS_NListOfEntityOwner& theOwners,
3104                                               const Handle(Prs3d_Drawer)& theStyle)
3105 {
3106   NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> > anObjOwnerMap;
3107   for (AIS_NListOfEntityOwner::Iterator aSelIter (theOwners); aSelIter.More(); aSelIter.Next())
3108   {
3109     const Handle(SelectMgr_EntityOwner) anOwner = aSelIter.Value();
3110     const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
3111     if (anObj.IsNull())
3112       continue;
3113 
3114     const Handle(Prs3d_Drawer)& anObjSelStyle = !theStyle.IsNull() ? theStyle : getSelStyle (anObj, anOwner);
3115     Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3116     if (!aStatusPtr)
3117     {
3118       continue;
3119     }
3120     if (anOwner == anObj->GlobalSelOwner())
3121     {
3122       (*aStatusPtr)->SetHilightStatus (Standard_True);
3123       (*aStatusPtr)->SetHilightStyle (anObjSelStyle);
3124     }
3125     if (!anOwner->IsAutoHilight())
3126     {
3127       NCollection_Handle<SelectMgr_SequenceOfOwner> aSeq;
3128       if (anObjOwnerMap.Find (anObj, aSeq))
3129       {
3130         aSeq->Append (anOwner);
3131       }
3132       else
3133       {
3134         aSeq = new SelectMgr_SequenceOfOwner();
3135         aSeq->Append (anOwner);
3136         anObjOwnerMap.Bind (anObj, aSeq);
3137       }
3138     }
3139     else
3140     {
3141       const Standard_Integer aHiMode = getHilightMode (anObj, anObjSelStyle, (*aStatusPtr)->DisplayMode());
3142       anOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3143     }
3144   }
3145 
3146   if (!anObjOwnerMap.IsEmpty())
3147   {
3148     for (NCollection_DataMap<Handle(AIS_InteractiveObject), NCollection_Handle<SelectMgr_SequenceOfOwner> >::Iterator anIter (anObjOwnerMap);
3149          anIter.More(); anIter.Next())
3150     {
3151       anIter.Key()->HilightSelected (myMainPM, *anIter.Value());
3152     }
3153     anObjOwnerMap.Clear();
3154   }
3155 }
3156 
3157 //=======================================================================
3158 //function : UnhilightSelected
3159 //purpose  :
3160 //=======================================================================
UnhilightSelected(const Standard_Boolean theToUpdateViewer)3161 void AIS_InteractiveContext::UnhilightSelected (const Standard_Boolean theToUpdateViewer)
3162 {
3163   unhighlightSelected();
3164 
3165   if (theToUpdateViewer)
3166   {
3167     UpdateCurrentViewer();
3168   }
3169 }
3170 
3171 //=======================================================================
3172 //function : ClearSelected
3173 //purpose  :
3174 //=======================================================================
ClearSelected(const Standard_Boolean theToUpdateViewer)3175 void AIS_InteractiveContext::ClearSelected (const Standard_Boolean theToUpdateViewer)
3176 {
3177   if (NbSelected() == 0)
3178   {
3179     return;
3180   }
3181 
3182   if (myAutoHilight)
3183   {
3184     unhighlightSelected();
3185   }
3186 
3187   mySelection->Clear();
3188   if (myAutoHilight)
3189   {
3190     clearDynamicHighlight();
3191   }
3192 
3193   if (theToUpdateViewer)
3194   {
3195     UpdateCurrentViewer();
3196   }
3197 }
3198 
3199 //=======================================================================
3200 //function : SetSelected
3201 //purpose  : Sets the whole object as selected and highlights it with selection color
3202 //=======================================================================
SetSelected(const Handle (AIS_InteractiveObject)& theObject,const Standard_Boolean theToUpdateViewer)3203 void AIS_InteractiveContext::SetSelected (const Handle(AIS_InteractiveObject)& theObject,
3204                                           const Standard_Boolean theToUpdateViewer)
3205 {
3206   if (theObject.IsNull())
3207   {
3208     return;
3209   }
3210 
3211   if (!myObjects.IsBound (theObject))
3212   {
3213     return;
3214   }
3215 
3216   Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3217   if (anOwner.IsNull())
3218   {
3219     return;
3220   }
3221 
3222   const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (theObject, anOwner);
3223   if (NbSelected() == 1 && myObjects (theObject)->IsHilighted() && myAutoHilight)
3224   {
3225     Handle(Prs3d_Drawer) aCustomStyle;
3226     if (HighlightStyle (theObject, aCustomStyle))
3227     {
3228       if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3229       {
3230         HilightWithColor (theObject, anObjSelStyle, theToUpdateViewer);
3231       }
3232     }
3233     return;
3234   }
3235 
3236   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
3237   {
3238     const Handle(SelectMgr_EntityOwner)& aSelOwner = aSelIter.Value();
3239     if (!myFilters->IsOk (aSelOwner))
3240     {
3241       continue;
3242     }
3243 
3244     Handle(AIS_InteractiveObject) aSelectable = Handle(AIS_InteractiveObject)::DownCast (aSelOwner->Selectable());
3245     if (myAutoHilight)
3246     {
3247       Unhilight (aSelectable, Standard_False);
3248     }
3249     if (aSelOwner == aSelectable->GlobalSelOwner())
3250     {
3251       if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (aSelectable))
3252       {
3253         (*aStatusPtr)->SetHilightStatus (Standard_False);
3254       }
3255     }
3256   }
3257 
3258   // added to avoid untimely viewer update...
3259   mySelection->ClearAndSelect (anOwner);
3260 
3261   if (myAutoHilight)
3262   {
3263     Handle(Prs3d_Drawer) aCustomStyle;
3264     if (HighlightStyle (theObject, aCustomStyle))
3265     {
3266       if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3267       {
3268         HilightWithColor (theObject, anObjSelStyle, Standard_False);
3269       }
3270     }
3271     else
3272     {
3273       HilightWithColor (theObject, anObjSelStyle, Standard_False);
3274     }
3275   }
3276 
3277   if (theToUpdateViewer)
3278   {
3279     UpdateCurrentViewer();
3280   }
3281 }
3282 
3283 //=======================================================================
3284 //function : SetSelected
3285 //purpose  : Sets the whole object as selected and highlights it with selection color
3286 //=======================================================================
SetSelected(const Handle (SelectMgr_EntityOwner)& theOwner,const Standard_Boolean theToUpdateViewer)3287 void AIS_InteractiveContext::SetSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3288                                           const Standard_Boolean theToUpdateViewer)
3289 {
3290   if (theOwner.IsNull() || !theOwner->HasSelectable() || !myFilters->IsOk (theOwner))
3291   {
3292     return;
3293   }
3294 
3295   const Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3296   const Handle(Prs3d_Drawer)& anObjSelStyle = getSelStyle (anObject, theOwner);
3297   if (NbSelected() == 1 && theOwner->IsSelected() && !theOwner->IsForcedHilight())
3298   {
3299     Handle(Prs3d_Drawer) aCustomStyle;
3300     if (myAutoHilight && HighlightStyle (theOwner, aCustomStyle))
3301     {
3302       if (!aCustomStyle.IsNull() && anObjSelStyle != aCustomStyle)
3303       {
3304         const Standard_Integer aHiMode = anObject->HasHilightMode() ? anObject->HilightMode() : 0;
3305         theOwner->HilightWithColor (myMainPM, anObjSelStyle, aHiMode);
3306       }
3307     }
3308     return;
3309   }
3310 
3311   if (!myObjects.IsBound (anObject))
3312   {
3313     return;
3314   }
3315 
3316   if (myAutoHilight)
3317   {
3318     unhighlightSelected();
3319   }
3320 
3321   mySelection->ClearAndSelect (theOwner);
3322   if (myAutoHilight)
3323   {
3324     Handle(Prs3d_Drawer) aCustomStyle;
3325     if (!HighlightStyle (theOwner, aCustomStyle) ||
3326       (!aCustomStyle.IsNull() && aCustomStyle != anObjSelStyle))
3327     {
3328       highlightSelected (theOwner);
3329     }
3330   }
3331 
3332   if (theToUpdateViewer)
3333   {
3334     UpdateCurrentViewer();
3335   }
3336 }
3337 
3338 //=======================================================================
3339 //function : AddOrRemoveSelected
3340 //purpose  :
3341 //=======================================================================
AddOrRemoveSelected(const Handle (AIS_InteractiveObject)& theObject,const Standard_Boolean theToUpdateViewer)3342 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(AIS_InteractiveObject)& theObject,
3343                                                   const Standard_Boolean theToUpdateViewer)
3344 {
3345   if (theObject.IsNull()
3346   || !myObjects.IsBound (theObject))
3347   {
3348     return;
3349   }
3350 
3351   const Handle(SelectMgr_EntityOwner) anOwner = theObject->GlobalSelOwner();
3352   if (!anOwner.IsNull()
3353     && anOwner->HasSelectable())
3354   {
3355     AddOrRemoveSelected (anOwner, theToUpdateViewer);
3356   }
3357 }
3358 
3359 //=======================================================================
3360 //function : AddOrRemoveSelected
3361 //purpose  : Allows to highlight or unhighlight the owner given depending on
3362 //           its selection status
3363 //=======================================================================
AddOrRemoveSelected(const Handle (SelectMgr_EntityOwner)& theOwner,const Standard_Boolean theToUpdateViewer)3364 void AIS_InteractiveContext::AddOrRemoveSelected (const Handle(SelectMgr_EntityOwner)& theOwner,
3365                                                   const Standard_Boolean theToUpdateViewer)
3366 {
3367   if (theOwner.IsNull() || !theOwner->HasSelectable())
3368   {
3369     return;
3370   }
3371 
3372   if (!myFilters->IsOk(theOwner) && !theOwner->IsSelected())
3373   {
3374     return;
3375   }
3376 
3377   mySelection->Select (theOwner);
3378 
3379   if (myAutoHilight)
3380   {
3381     const Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
3382     Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (anObj);
3383     if (!aStatusPtr)
3384     {
3385       return;
3386     }
3387 
3388     if (theOwner->IsSelected())
3389     {
3390       highlightSelected (theOwner);
3391     }
3392     else
3393     {
3394       AIS_NListOfEntityOwner anOwners;
3395       anOwners.Append (theOwner);
3396       unhighlightOwners (anOwners);
3397 
3398       (*aStatusPtr)->SetHilightStyle (Handle(Prs3d_Drawer)());
3399     }
3400   }
3401 
3402   if (theToUpdateViewer)
3403   {
3404     UpdateCurrentViewer();
3405   }
3406 }
3407 
3408 // =======================================================================
3409 // function : SetSelectedState
3410 // purpose  :
3411 // =======================================================================
SetSelectedState(const Handle (SelectMgr_EntityOwner)& theEntity,const Standard_Boolean theIsSelected)3412 Standard_Boolean AIS_InteractiveContext::SetSelectedState (const Handle(SelectMgr_EntityOwner)& theEntity,
3413                                                            const Standard_Boolean theIsSelected)
3414 {
3415   if (theEntity.IsNull())
3416   {
3417     throw Standard_ProgramError ("Internal error: AIS_InteractiveContext::SetSelectedState() called with NO object");
3418   }
3419 
3420   if (!theEntity->HasSelectable()
3421     || mySelection->IsSelected (theEntity) == theIsSelected)
3422   {
3423     return false;
3424   }
3425 
3426   if (theEntity->IsAutoHilight())
3427   {
3428     AddOrRemoveSelected (theEntity, false);
3429     return true;
3430   }
3431 
3432   if (theIsSelected)
3433   {
3434     const AIS_SelectStatus aSelStatus = mySelection->AddSelect (theEntity);
3435     theEntity->SetSelected (true);
3436     return aSelStatus == AIS_SS_Added;
3437   }
3438   else
3439   {
3440     const AIS_SelectStatus aSelStatus = mySelection->Select (theEntity);
3441     theEntity->SetSelected (false);
3442     return aSelStatus == AIS_SS_Removed;
3443   }
3444 }
3445 
3446 //=======================================================================
3447 //function : IsSelected
3448 //purpose  :
3449 //=======================================================================
IsSelected(const Handle (AIS_InteractiveObject)& theObj) const3450 Standard_Boolean AIS_InteractiveContext::IsSelected (const Handle(AIS_InteractiveObject)& theObj) const
3451 {
3452   if (theObj.IsNull())
3453   {
3454     return Standard_False;
3455   }
3456 
3457   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3458   if (aStatus == NULL)
3459   {
3460     return Standard_False;
3461   }
3462 
3463   const Standard_Integer aGlobalSelMode = theObj->GlobalSelectionMode();
3464   const TColStd_ListOfInteger& anActivatedModes = (*aStatus)->SelectionModes();
3465   for (TColStd_ListIteratorOfListOfInteger aModeIter (anActivatedModes); aModeIter.More(); aModeIter.Next())
3466   {
3467     if (aModeIter.Value() == aGlobalSelMode)
3468     {
3469       if (Handle(SelectMgr_EntityOwner) aGlobOwner = theObj->GlobalSelOwner())
3470       {
3471         return aGlobOwner->IsSelected();
3472       }
3473       return Standard_False;
3474     }
3475   }
3476   return Standard_False;
3477 }
3478 
3479 //=======================================================================
3480 //function : FirstSelectedObject
3481 //purpose  :
3482 //=======================================================================
Handle(AIS_InteractiveObject)3483 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstSelectedObject() const
3484 {
3485   return !mySelection->Objects().IsEmpty()
3486         ? Handle(AIS_InteractiveObject)::DownCast (mySelection->Objects().First()->Selectable())
3487         : Handle(AIS_InteractiveObject)();
3488 }
3489 
3490 //=======================================================================
3491 //function : HasSelectedShape
3492 //purpose  :
3493 //=======================================================================
HasSelectedShape() const3494 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const
3495 {
3496   if (!mySelection->More())
3497   {
3498     return Standard_False;
3499   }
3500 
3501   const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3502   return !anOwner.IsNull() && anOwner->HasShape();
3503 }
3504 
3505 //=======================================================================
3506 //function : SelectedShape
3507 //purpose  :
3508 //=======================================================================
SelectedShape() const3509 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const
3510 {
3511   if (!mySelection->More())
3512   {
3513     return TopoDS_Shape();
3514   }
3515 
3516   const Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (mySelection->Value());
3517   if (anOwner.IsNull() || !anOwner->HasSelectable())
3518   {
3519     return TopoDS_Shape();
3520   }
3521 
3522   return anOwner->Shape().Located (anOwner->Location() * anOwner->Shape().Location());
3523 }
3524 
3525 //=======================================================================
3526 //function : EntityOwners
3527 //purpose  :
3528 //=======================================================================
EntityOwners(Handle (SelectMgr_IndexedMapOfOwner)& theOwners,const Handle (AIS_InteractiveObject)& theIObj,const Standard_Integer theMode) const3529 void AIS_InteractiveContext::EntityOwners (Handle(SelectMgr_IndexedMapOfOwner)& theOwners,
3530                                            const Handle(AIS_InteractiveObject)& theIObj,
3531                                            const Standard_Integer theMode) const
3532 {
3533   if (theIObj.IsNull())
3534   {
3535     return;
3536   }
3537 
3538   TColStd_ListOfInteger aModes;
3539   if (theMode == -1)
3540   {
3541     ActivatedModes (theIObj, aModes);
3542   }
3543   else
3544   {
3545     aModes.Append (theMode);
3546   }
3547 
3548   if (theOwners.IsNull())
3549   {
3550     theOwners = new SelectMgr_IndexedMapOfOwner();
3551   }
3552 
3553   for (TColStd_ListIteratorOfListOfInteger anItr (aModes); anItr.More(); anItr.Next())
3554   {
3555     const int aMode = anItr.Value();
3556     const Handle(SelectMgr_Selection)& aSel = theIObj->Selection (aMode);
3557     if (aSel.IsNull())
3558     {
3559       continue;
3560     }
3561 
3562     for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (aSel->Entities()); aSelEntIter.More(); aSelEntIter.Next())
3563     {
3564       if (Handle(Select3D_SensitiveEntity) aEntity = aSelEntIter.Value()->BaseSensitive())
3565       {
3566         if (const Handle(SelectMgr_EntityOwner)& aOwner = aEntity->OwnerId())
3567         {
3568           theOwners->Add (aOwner);
3569         }
3570       }
3571     }
3572   }
3573 }
3574 
3575 //=======================================================================
3576 //function : HasDetectedShape
3577 //purpose  :
3578 //=======================================================================
HasDetectedShape() const3579 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const
3580 {
3581   Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3582   return !anOwner.IsNull()
3583        && anOwner->HasShape();
3584 }
3585 
3586 //=======================================================================
3587 //function : DetectedShape
3588 //purpose  :
3589 //=======================================================================
DetectedShape() const3590 const TopoDS_Shape& AIS_InteractiveContext::DetectedShape() const
3591 {
3592   Handle(StdSelect_BRepOwner) anOwner = Handle(StdSelect_BRepOwner)::DownCast (myLastPicked);
3593   return anOwner->Shape();
3594 }
3595 
3596 //=======================================================================
3597 //function : HilightNextDetected
3598 //purpose  :
3599 //=======================================================================
HilightNextDetected(const Handle (V3d_View)& theView,const Standard_Boolean theToRedrawImmediate)3600 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
3601                                                               const Standard_Boolean  theToRedrawImmediate)
3602 {
3603   myMainPM->ClearImmediateDraw();
3604   if (myDetectedSeq.IsEmpty())
3605   {
3606     return 0;
3607   }
3608 
3609   if (++myCurHighlighted > myDetectedSeq.Upper())
3610   {
3611     myCurHighlighted = myDetectedSeq.Lower();
3612   }
3613   const Handle(SelectMgr_EntityOwner)& anOwner = MainSelector()->Picked (myDetectedSeq (myCurHighlighted));
3614   if (anOwner.IsNull())
3615   {
3616     return 0;
3617   }
3618 
3619   highlightWithColor (anOwner, theView->Viewer());
3620   myLastPicked = anOwner;
3621 
3622   if (theToRedrawImmediate)
3623   {
3624     myMainPM->RedrawImmediate (theView->Viewer());
3625     myMainVwr->RedrawImmediate();
3626   }
3627 
3628   return myCurHighlighted;
3629 }
3630 
3631 //=======================================================================
3632 //function : HilightPreviousDetected
3633 //purpose  :
3634 //=======================================================================
HilightPreviousDetected(const Handle (V3d_View)& theView,const Standard_Boolean theToRedrawImmediate)3635 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
3636                                                                   const Standard_Boolean  theToRedrawImmediate)
3637 {
3638   myMainPM->ClearImmediateDraw();
3639   if (myDetectedSeq.IsEmpty())
3640   {
3641     return 0;
3642   }
3643 
3644   if (--myCurHighlighted < myDetectedSeq.Lower())
3645   {
3646     myCurHighlighted = myDetectedSeq.Upper();
3647   }
3648   const Handle(SelectMgr_EntityOwner)& anOwner = MainSelector()->Picked (myDetectedSeq (myCurHighlighted));
3649   if (anOwner.IsNull())
3650   {
3651     return 0;
3652   }
3653 
3654   highlightWithColor (anOwner, theView->Viewer());
3655   myLastPicked = anOwner;
3656 
3657   if (theToRedrawImmediate)
3658   {
3659     myMainPM->RedrawImmediate (theView->Viewer());
3660     myMainVwr->RedrawImmediate();
3661   }
3662 
3663   return myCurHighlighted;
3664 }
3665 
3666 //=======================================================================
3667 //function : DetectedCurrentOwner
3668 //purpose  :
3669 //=======================================================================
Handle(SelectMgr_EntityOwner)3670 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedCurrentOwner() const
3671 {
3672   return MoreDetected()
3673        ? MainSelector()->Picked (myDetectedSeq (myCurDetected))
3674        : Handle(SelectMgr_EntityOwner)();
3675 }
3676 
3677 //=======================================================================
3678 //function : DetectedCurrentShape
3679 //purpose  :
3680 //=======================================================================
DetectedCurrentShape() const3681 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
3682 {
3683   static const TopoDS_Shape AIS_InteractiveContext_myDummyShape;
3684 
3685   Standard_DISABLE_DEPRECATION_WARNINGS
3686   Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
3687   Standard_ENABLE_DEPRECATION_WARNINGS
3688   return !aCurrentShape.IsNull()
3689         ? aCurrentShape->Shape()
3690         : AIS_InteractiveContext_myDummyShape;
3691 }
3692 
3693 //=======================================================================
3694 //function : DetectedCurrentObject
3695 //purpose  :
3696 //=======================================================================
Handle(AIS_InteractiveObject)3697 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
3698 {
3699   return MoreDetected()
3700        ? Handle(AIS_InteractiveObject)::DownCast (MainSelector()->Picked (myDetectedSeq (myCurDetected))->Selectable())
3701        : Handle(AIS_InteractiveObject)();
3702 }
3703 
3704 //=======================================================================
3705 //function : SetSelectionModeActive
3706 //purpose  :
3707 //=======================================================================
SetSelectionModeActive(const Handle (AIS_InteractiveObject)& theObj,const Standard_Integer theMode,const Standard_Boolean theIsActive,const AIS_SelectionModesConcurrency theActiveFilter,const Standard_Boolean theIsForce)3708 void AIS_InteractiveContext::SetSelectionModeActive (const Handle(AIS_InteractiveObject)& theObj,
3709                                                      const Standard_Integer theMode,
3710                                                      const Standard_Boolean theIsActive,
3711                                                      const AIS_SelectionModesConcurrency theActiveFilter,
3712                                                      const Standard_Boolean theIsForce)
3713 {
3714   if (theObj.IsNull())
3715   {
3716     return;
3717   }
3718 
3719   const Handle(AIS_GlobalStatus)* aStat = myObjects.Seek (theObj);
3720   if (aStat == NULL)
3721   {
3722     return;
3723   }
3724 
3725   if (!theIsActive
3726    || (theMode == -1
3727     && theActiveFilter == AIS_SelectionModesConcurrency_Single))
3728   {
3729     if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3730      || theIsForce)
3731     {
3732       if (theMode == -1)
3733       {
3734         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3735         {
3736           mgrSelector->Deactivate (theObj, aModeIter.Value());
3737         }
3738       }
3739       else
3740       {
3741         mgrSelector->Deactivate (theObj, theMode);
3742       }
3743     }
3744 
3745     if (theMode == -1)
3746     {
3747       (*aStat)->ClearSelectionModes();
3748     }
3749     else
3750     {
3751       (*aStat)->RemoveSelectionMode (theMode);
3752     }
3753     return;
3754   }
3755   else if (theMode == -1)
3756   {
3757     return;
3758   }
3759 
3760   if ((*aStat)->SelectionModes().Size() == 1
3761    && (*aStat)->SelectionModes().First() == theMode)
3762   {
3763     return;
3764   }
3765 
3766   if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed
3767    || theIsForce)
3768   {
3769     switch (theActiveFilter)
3770     {
3771       case AIS_SelectionModesConcurrency_Single:
3772       {
3773         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3774         {
3775           mgrSelector->Deactivate (theObj, aModeIter.Value());
3776         }
3777         (*aStat)->ClearSelectionModes();
3778         break;
3779       }
3780       case AIS_SelectionModesConcurrency_GlobalOrLocal:
3781       {
3782         const Standard_Integer aGlobSelMode = theObj->GlobalSelectionMode();
3783         TColStd_ListOfInteger aRemovedModes;
3784         for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStat)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3785         {
3786           if ((theMode == aGlobSelMode && aModeIter.Value() != aGlobSelMode)
3787            || (theMode != aGlobSelMode && aModeIter.Value() == aGlobSelMode))
3788           {
3789             mgrSelector->Deactivate (theObj, aModeIter.Value());
3790             aRemovedModes.Append (aModeIter.Value());
3791           }
3792         }
3793         if (aRemovedModes.Size() == (*aStat)->SelectionModes().Size())
3794         {
3795           (*aStat)->ClearSelectionModes();
3796         }
3797         else
3798         {
3799           for (TColStd_ListIteratorOfListOfInteger aModeIter (aRemovedModes); aModeIter.More(); aModeIter.Next())
3800           {
3801             (*aStat)->RemoveSelectionMode (aModeIter.Value());
3802           }
3803         }
3804         break;
3805       }
3806       case AIS_SelectionModesConcurrency_Multiple:
3807       {
3808         break;
3809       }
3810     }
3811     mgrSelector->Activate (theObj, theMode);
3812   }
3813   (*aStat)->AddSelectionMode (theMode);
3814 }
3815 
3816 // ============================================================================
3817 // function : Activate
3818 // purpose  :
3819 // ============================================================================
Activate(const Standard_Integer theMode,const Standard_Boolean theIsForce)3820 void AIS_InteractiveContext::Activate (const Standard_Integer theMode,
3821                                        const Standard_Boolean theIsForce)
3822 {
3823   AIS_ListOfInteractive aDisplayedObjects;
3824   DisplayedObjects (aDisplayedObjects);
3825   for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3826   {
3827     Load (anIter.Value(), -1);
3828     Activate (anIter.Value(), theMode, theIsForce);
3829   }
3830 }
3831 
3832 // ============================================================================
3833 // function : Deactivate
3834 // purpose  :
3835 // ============================================================================
Deactivate(const Standard_Integer theMode)3836 void AIS_InteractiveContext::Deactivate (const Standard_Integer theMode)
3837 {
3838   AIS_ListOfInteractive aDisplayedObjects;
3839   DisplayedObjects (aDisplayedObjects);
3840   for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3841   {
3842     Deactivate (anIter.Value(), theMode);
3843   }
3844 }
3845 
3846 // ============================================================================
3847 // function : Deactivate
3848 // purpose  :
3849 // ============================================================================
Deactivate()3850 void AIS_InteractiveContext::Deactivate()
3851 {
3852   AIS_ListOfInteractive aDisplayedObjects;
3853   DisplayedObjects (aDisplayedObjects);
3854 
3855   for (AIS_ListOfInteractive::Iterator anIter (aDisplayedObjects); anIter.More(); anIter.Next())
3856   {
3857     Deactivate (anIter.Value());
3858   }
3859 }
3860 
3861 //=======================================================================
3862 //function : ActivatedModes
3863 //purpose  :
3864 //=======================================================================
ActivatedModes(const Handle (AIS_InteractiveObject)& theObj,TColStd_ListOfInteger & theList) const3865 void AIS_InteractiveContext::ActivatedModes (const Handle(AIS_InteractiveObject)& theObj,
3866                                              TColStd_ListOfInteger& theList) const
3867 {
3868   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3869   if (aStatus != NULL)
3870   {
3871     for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3872     {
3873       theList.Append (aModeIter.Value());
3874     }
3875   }
3876 }
3877 
3878 //=======================================================================
3879 //function : SubIntensityOn
3880 //purpose  :
3881 //=======================================================================
SubIntensityOn(const Handle (AIS_InteractiveObject)& theObj,const Standard_Boolean theToUpdateViewer)3882 void AIS_InteractiveContext::SubIntensityOn (const Handle(AIS_InteractiveObject)& theObj,
3883                                              const Standard_Boolean theToUpdateViewer)
3884 {
3885   turnOnSubintensity (theObj);
3886   if (theToUpdateViewer)
3887   {
3888     myMainVwr->Update();
3889   }
3890 }
3891 
3892 //=======================================================================
3893 //function : SubIntensityOff
3894 //purpose  :
3895 //=======================================================================
SubIntensityOff(const Handle (AIS_InteractiveObject)& theObj,const Standard_Boolean theToUpdateViewer)3896 void AIS_InteractiveContext::SubIntensityOff (const Handle(AIS_InteractiveObject)& theObj,
3897                                               const Standard_Boolean theToUpdateViewer)
3898 {
3899   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3900   if (aStatus == NULL
3901    || !(*aStatus)->IsSubIntensityOn())
3902   {
3903     return;
3904   }
3905 
3906   (*aStatus)->SetSubIntensity (false);
3907   Standard_Boolean toUpdateMain = Standard_False;
3908   if (theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
3909   {
3910     myMainPM->Unhighlight (theObj);
3911     toUpdateMain = Standard_True;
3912   }
3913 
3914   if (IsSelected (theObj))
3915   {
3916     highlightSelected (theObj->GlobalSelOwner());
3917   }
3918 
3919   if (theToUpdateViewer && toUpdateMain)
3920   {
3921     myMainVwr->Update();
3922   }
3923 }
3924 
3925 //=======================================================================
3926 //function : DisplayActiveSensitive
3927 //purpose  :
3928 //=======================================================================
DisplayActiveSensitive(const Handle (V3d_View)& theView)3929 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& theView)
3930 {
3931   MainSelector()->DisplaySensitive (theView);
3932 }
3933 
3934 //=======================================================================
3935 //function : DisplayActiveSensitive
3936 //purpose  :
3937 //=======================================================================
DisplayActiveSensitive(const Handle (AIS_InteractiveObject)& theObj,const Handle (V3d_View)& theView)3938 void AIS_InteractiveContext::DisplayActiveSensitive (const Handle(AIS_InteractiveObject)& theObj,
3939                                                      const Handle(V3d_View)& theView)
3940 {
3941   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
3942   if (aStatus == NULL)
3943   {
3944     return;
3945   }
3946 
3947   for (TColStd_ListIteratorOfListOfInteger aModeIter ((*aStatus)->SelectionModes()); aModeIter.More(); aModeIter.Next())
3948   {
3949     const Handle(SelectMgr_Selection)& aSel = theObj->Selection (aModeIter.Value());
3950     MainSelector()->DisplaySensitive (aSel, theObj->Transformation(), theView, Standard_False);
3951   }
3952 }
3953 
3954 //=======================================================================
3955 //function : ClearActiveSensitive
3956 //purpose  :
3957 //=======================================================================
ClearActiveSensitive(const Handle (V3d_View)& theView)3958 void AIS_InteractiveContext::ClearActiveSensitive (const Handle(V3d_View)& theView)
3959 {
3960   MainSelector()->ClearSensitive (theView);
3961 }
3962 
3963 //=======================================================================
3964 //function : IsImmediateModeOn
3965 //purpose  :
3966 //=======================================================================
IsImmediateModeOn() const3967 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn() const
3968 {
3969   return myMainPM->IsImmediateModeOn();
3970 }
3971 
3972 //=======================================================================
3973 //function : BeginImmediateDraw
3974 //purpose  :
3975 //=======================================================================
BeginImmediateDraw()3976 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
3977 {
3978   if (myMainPM->IsImmediateModeOn())
3979   {
3980     myMainPM->BeginImmediateDraw();
3981     return Standard_True;
3982   }
3983   return Standard_False;
3984 }
3985 
3986 //=======================================================================
3987 //function : ImmediateAdd
3988 //purpose  :
3989 //=======================================================================
ImmediateAdd(const Handle (AIS_InteractiveObject)& theObj,const Standard_Integer theMode)3990 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
3991                                                        const Standard_Integer theMode)
3992 {
3993   if (myMainPM->IsImmediateModeOn())
3994   {
3995     myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode));
3996     return Standard_True;
3997   }
3998   return Standard_False;
3999 }
4000 
4001 //=======================================================================
4002 //function : EndImmediateDraw
4003 //purpose  :
4004 //=======================================================================
EndImmediateDraw(const Handle (V3d_View)& theView)4005 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
4006 {
4007   if (myMainPM->IsImmediateModeOn())
4008   {
4009     myMainPM->EndImmediateDraw (theView->Viewer());
4010     return Standard_True;
4011   }
4012   return Standard_False;
4013 }
4014 
4015 //=======================================================================
4016 //function : EndImmediateDraw
4017 //purpose  :
4018 //=======================================================================
EndImmediateDraw()4019 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
4020 {
4021   if (myMainPM->IsImmediateModeOn())
4022   {
4023     myMainPM->EndImmediateDraw (myMainVwr);
4024     return Standard_True;
4025   }
4026   return Standard_False;
4027 }
4028 
4029 //=======================================================================
4030 //function : SetPolygonOffsets
4031 //purpose  :
4032 //=======================================================================
SetPolygonOffsets(const Handle (AIS_InteractiveObject)& theObj,const Standard_Integer theMode,const Standard_ShortReal theFactor,const Standard_ShortReal theUnits,const Standard_Boolean theToUpdateViewer)4033 void AIS_InteractiveContext::SetPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4034                                                 const Standard_Integer   theMode,
4035                                                 const Standard_ShortReal theFactor,
4036                                                 const Standard_ShortReal theUnits,
4037                                                 const Standard_Boolean   theToUpdateViewer)
4038 {
4039   if (theObj.IsNull())
4040   {
4041     return;
4042   }
4043 
4044   setContextToObject (theObj);
4045   theObj->SetPolygonOffsets (theMode, theFactor, theUnits);
4046 
4047   const Handle(AIS_GlobalStatus)* aStatus = theToUpdateViewer ? myObjects.Seek (theObj) : NULL;
4048   if (aStatus != NULL
4049    && theObj->DisplayStatus() == PrsMgr_DisplayStatus_Displayed)
4050   {
4051     myMainVwr->Update();
4052   }
4053 }
4054 
4055 //=======================================================================
4056 //function : HasPolygonOffsets
4057 //purpose  :
4058 //=======================================================================
HasPolygonOffsets(const Handle (AIS_InteractiveObject)& theObj) const4059 Standard_Boolean AIS_InteractiveContext::HasPolygonOffsets (const Handle(AIS_InteractiveObject)& theObj) const
4060 {
4061   return !theObj.IsNull() && theObj->HasPolygonOffsets();
4062 }
4063 
4064 //=======================================================================
4065 //function : PolygonOffsets
4066 //purpose  :
4067 //=======================================================================
PolygonOffsets(const Handle (AIS_InteractiveObject)& theObj,Standard_Integer & theMode,Standard_ShortReal & theFactor,Standard_ShortReal & theUnits) const4068 void AIS_InteractiveContext::PolygonOffsets (const Handle(AIS_InteractiveObject)& theObj,
4069                                              Standard_Integer&   theMode,
4070                                              Standard_ShortReal& theFactor,
4071                                              Standard_ShortReal& theUnits) const
4072 {
4073   if (HasPolygonOffsets (theObj))
4074   {
4075     theObj->PolygonOffsets (theMode, theFactor, theUnits);
4076   }
4077 }
4078 
4079 //=======================================================================
4080 //function : DumpJson
4081 //purpose  :
4082 //=======================================================================
DumpJson(Standard_OStream & theOStream,Standard_Integer) const4083 void AIS_InteractiveContext::DumpJson (Standard_OStream& theOStream, Standard_Integer) const
4084 {
4085   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
4086 
4087   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myObjects.Size())
4088 
4089   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mgrSelector.get())
4090   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainPM.get())
4091   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myMainVwr.get())
4092   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastActiveView)
4093 
4094   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myLastPicked.get())
4095 
4096   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myToHilightSelected)
4097 
4098   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, mySelection.get())
4099   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myFilters.get())
4100   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myDefaultDrawer.get())
4101 
4102   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Selected])
4103   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_Dynamic])
4104   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalSelected])
4105   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_LocalDynamic])
4106   OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, myStyles[Prs3d_TypeOfHighlight_SubIntensity])
4107 
4108   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myDetectedSeq.Size())
4109 
4110   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurDetected)
4111   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myCurHighlighted)
4112   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myPickingStrategy)
4113   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myAutoHilight)
4114   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsAutoActivateSelMode)
4115 }
4116