1826f14a29e41bc965edbe1eace2382eb029ee5b
[occt.git] / src / AIS / AIS_InteractiveContext.cxx
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_ListIteratorOfListOfInteractive.hxx>
24 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
25 #include <AIS_MultipleConnectedInteractive.hxx>
26 #include <AIS_Shape.hxx>
27 #include <AIS_Trihedron.hxx>
28 #include <Geom_Axis2Placement.hxx>
29 #include <Graphic3d_AspectFillArea3d.hxx>
30 #include <HLRBRep.hxx>
31 #include <OSD_Environment.hxx>
32 #include <Precision.hxx>
33 #include <Prs3d_BasicAspect.hxx>
34 #include <Prs3d_DatumAspect.hxx>
35 #include <Prs3d_IsoAspect.hxx>
36 #include <Prs3d_LineAspect.hxx>
37 #include <Prs3d_PlaneAspect.hxx>
38 #include <Prs3d_PointAspect.hxx>
39 #include <Prs3d_ShadingAspect.hxx>
40 #include <PrsMgr_PresentableObject.hxx>
41 #include <Quantity_Color.hxx>
42 #include <SelectMgr_EntityOwner.hxx>
43 #include <SelectMgr_Filter.hxx>
44 #include <SelectMgr_OrFilter.hxx>
45 #include <SelectMgr_SelectionManager.hxx>
46 #include <Standard_Atomic.hxx>
47 #include <Standard_Transient.hxx>
48 #include <Standard_Type.hxx>
49 #include <StdSelect_ViewerSelector3d.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <TCollection_ExtendedString.hxx>
52 #include <TColStd_ListIteratorOfListOfInteger.hxx>
53 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
54 #include <TopLoc_Location.hxx>
55 #include <TopoDS_Shape.hxx>
56 #include <UnitsAPI.hxx>
57 #include <V3d_View.hxx>
58 #include <V3d_Viewer.hxx>
59
60 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext, Standard_Transient)
61
62 namespace
63 {
64   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
65   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
66
67   //! Initialize default highlighting attributes.
68   static void initDefaultHilightAttributes (const Handle(Prs3d_Drawer)& theDrawer)
69   {
70     theDrawer->SetMethod (Aspect_TOHM_COLOR);
71     theDrawer->SetDisplayMode (0);
72
73     theDrawer->SetPointAspect (new Prs3d_PointAspect (Aspect_TOM_POINT, Quantity_NOC_BLACK, 1.0));
74     *theDrawer->PointAspect()->Aspect() = *theDrawer->Link()->PointAspect()->Aspect();
75     theDrawer->SetLineAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
76     *theDrawer->LineAspect()->Aspect() = *theDrawer->Link()->LineAspect()->Aspect();
77     theDrawer->SetWireAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
78     *theDrawer->WireAspect()->Aspect() = *theDrawer->Link()->WireAspect()->Aspect();
79     theDrawer->SetPlaneAspect (new Prs3d_PlaneAspect());
80     *theDrawer->PlaneAspect()->EdgesAspect() = *theDrawer->Link()->PlaneAspect()->EdgesAspect();
81     theDrawer->SetFreeBoundaryAspect   (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
82     *theDrawer->FreeBoundaryAspect()->Aspect() = *theDrawer->Link()->FreeBoundaryAspect()->Aspect();
83     theDrawer->SetUnFreeBoundaryAspect (new Prs3d_LineAspect (Quantity_NOC_BLACK, Aspect_TOL_SOLID, 1.0));
84     *theDrawer->UnFreeBoundaryAspect()->Aspect() = *theDrawer->Link()->UnFreeBoundaryAspect()->Aspect();
85
86     theDrawer->WireAspect()->SetWidth (2.0);
87     theDrawer->LineAspect()->SetWidth (2.0);
88     theDrawer->PlaneAspect()->EdgesAspect()->SetWidth (2.0);
89     theDrawer->FreeBoundaryAspect()  ->SetWidth (2.0);
90     theDrawer->UnFreeBoundaryAspect()->SetWidth (2.0);
91     theDrawer->PointAspect()->SetTypeOfMarker (Aspect_TOM_O_POINT);
92     theDrawer->PointAspect()->SetScale (2.0);
93
94     // the triangulation should be computed using main presentation attributes,
95     // and should not be overridden by highlighting
96     theDrawer->SetAutoTriangulation (Standard_False);
97   }
98 }
99
100 //=======================================================================
101 //function : AIS_InteractiveContext
102 //purpose  : 
103 //=======================================================================
104
105 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
106 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
107 myMainVwr(MainViewer),
108 myMainSel(new StdSelect_ViewerSelector3d()),
109 myToHilightSelected(Standard_True),
110 mySelection(new AIS_Selection()),
111 myFilters(new SelectMgr_OrFilter()),
112 myDefaultDrawer(new Prs3d_Drawer()),
113 myCurDetected(0),
114 myCurHighlighted(0),
115 myPickingStrategy (SelectMgr_PickingStrategy_FirstAcceptable),
116 myAutoHilight(Standard_True),
117 myIsAutoActivateSelMode(Standard_True)
118 {
119   mgrSelector = new SelectMgr_SelectionManager (myMainSel);
120
121   myStyles[Prs3d_TypeOfHighlight_None]          = myDefaultDrawer;
122   myStyles[Prs3d_TypeOfHighlight_Selected]      = new Prs3d_Drawer();
123   myStyles[Prs3d_TypeOfHighlight_Dynamic]       = new Prs3d_Drawer();
124   myStyles[Prs3d_TypeOfHighlight_LocalSelected] = new Prs3d_Drawer();
125   myStyles[Prs3d_TypeOfHighlight_LocalDynamic]  = new Prs3d_Drawer();
126   myStyles[Prs3d_TypeOfHighlight_SubIntensity]  = new Prs3d_Drawer();
127
128   myDefaultDrawer->SetZLayer(Graphic3d_ZLayerId_Default);
129   myDefaultDrawer->SetDisplayMode(0);
130   {
131     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Dynamic];
132     aStyle->Link (myDefaultDrawer);
133     initDefaultHilightAttributes (aStyle);
134     aStyle->SetZLayer(Graphic3d_ZLayerId_Top);
135     aStyle->SetColor (Quantity_NOC_CYAN1);
136   }
137   {
138     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalDynamic];
139     aStyle->Link (myDefaultDrawer);
140     initDefaultHilightAttributes (aStyle);
141     aStyle->SetZLayer(Graphic3d_ZLayerId_Topmost);
142     aStyle->SetColor (Quantity_NOC_CYAN1);
143   }
144   {
145     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_Selected];
146     aStyle->Link (myDefaultDrawer);
147     initDefaultHilightAttributes (aStyle);
148     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
149     aStyle->SetColor (Quantity_NOC_GRAY80);
150   }
151   {
152     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_LocalSelected];
153     aStyle->Link (myDefaultDrawer);
154     initDefaultHilightAttributes (aStyle);
155     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
156     aStyle->SetColor (Quantity_NOC_GRAY80);
157   }
158   {
159     const Handle(Prs3d_Drawer)& aStyle = myStyles[Prs3d_TypeOfHighlight_SubIntensity];
160     aStyle->SetZLayer(Graphic3d_ZLayerId_UNKNOWN);
161     aStyle->SetMethod(Aspect_TOHM_COLOR);
162     aStyle->SetColor (Quantity_NOC_GRAY40);
163   }
164
165   InitAttributes();
166 }
167
168 //=======================================================================
169 //function : ~AIS_InteractiveContext
170 //purpose  :
171 //=======================================================================
172 AIS_InteractiveContext::~AIS_InteractiveContext()
173 {
174   // clear the current selection
175   mySelection->Clear();
176   mgrSelector.Nullify();
177
178   Handle(AIS_InteractiveContext) aNullContext;
179   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
180   {
181     const Handle(AIS_InteractiveObject)& anObj = anObjIter.Key();
182     anObj->SetContext (aNullContext);
183     for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
184     {
185       aSelIter.Value()->UpdateBVHStatus (SelectMgr_TBU_Renew);
186     }
187   }
188 }
189
190 //=======================================================================
191 //function : LastActiveView
192 //purpose  :
193 //=======================================================================
194 Handle(V3d_View) AIS_InteractiveContext::LastActiveView() const
195 {
196   if (myLastActiveView == NULL
197    || myMainVwr.IsNull())
198   {
199     return Handle(V3d_View)();
200   }
201
202   // as a precaution - check that myLastActiveView pointer is a valid active View
203   for (V3d_ListOfViewIterator aViewIter = myMainVwr->ActiveViewIterator(); aViewIter.More(); aViewIter.Next())
204   {
205     if (aViewIter.Value() == myLastActiveView)
206     {
207       return aViewIter.Value();
208     }
209   }
210   return Handle(V3d_View)();
211 }
212
213 //=======================================================================
214 //function : UpdateCurrentViewer
215 //purpose  : 
216 //=======================================================================
217
218 void AIS_InteractiveContext::UpdateCurrentViewer()
219 {
220   if (!myMainVwr.IsNull())
221     myMainVwr->Update();
222 }
223
224 //=======================================================================
225 //function : DisplayedObjects
226 //purpose  :
227 //=======================================================================
228 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO) const
229 {
230   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
231   {
232     if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
233     {
234       theListOfIO.Append (anObjIter.Key());
235     }
236   }
237 }
238
239 //=======================================================================
240 //function : DisplayedObjects
241 //purpose  :
242 //=======================================================================
243 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
244                                                const Standard_Integer      theSign,
245                                                AIS_ListOfInteractive&      theListOfIO) const
246 {
247   ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
248 }
249
250 //=======================================================================
251 //function : ErasedObjects
252 //purpose  :
253 //=======================================================================
254 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
255 {
256   ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
257 }
258
259 //=======================================================================
260 //function : ErasedObjects
261 //purpose  :
262 //=======================================================================
263 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
264                                             const Standard_Integer      theSign,
265                                             AIS_ListOfInteractive&      theListOfIO) const
266 {
267   ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
268 }
269
270 //=======================================================================
271 //function : ObjectsByDisplayStatus
272 //purpose  :
273 //=======================================================================
274 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
275                                                      AIS_ListOfInteractive&  theListOfIO) const
276 {
277   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
278   {
279     if (anObjIter.Value()->GraphicStatus() == theStatus)
280     {
281       theListOfIO.Append (anObjIter.Key());
282     }
283   }
284 }
285
286 //=======================================================================
287 //function : ObjectsByDisplayStatus
288 //purpose  :
289 //=======================================================================
290 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
291                                                      const Standard_Integer      theSign,
292                                                      const AIS_DisplayStatus     theStatus,
293                                                      AIS_ListOfInteractive&      theListOfIO) const
294 {
295   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
296   {
297     if (theStatus != AIS_DS_None
298      && anObjIter.Value()->GraphicStatus() != theStatus)
299     {
300       continue;
301     }
302     else if (anObjIter.Key()->Type() != theKind)
303     {
304       continue;
305     }
306
307     if (theSign == -1
308      || anObjIter.Key()->Signature() == theSign)
309     {
310       theListOfIO.Append (anObjIter.Key());
311     }
312   }
313 }
314
315 //=======================================================================
316 //function : ObjectsInside
317 //purpose  :
318 //=======================================================================
319 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive&      theListOfIO,
320                                             const AIS_KindOfInteractive theKind,
321                                             const Standard_Integer      theSign) const
322 {
323   if (theKind == AIS_KOI_None
324    && theSign == -1)
325   {
326     for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
327     {
328       theListOfIO.Append (anObjIter.Key());
329     }
330     return;
331   }
332
333   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
334   {
335     if (anObjIter.Key()->Type() != theKind)
336     {
337       continue;
338     }
339
340     if (theSign == -1
341      || anObjIter.Key()->Signature() == theSign)
342     {
343       theListOfIO.Append (anObjIter.Key());
344     }
345   }
346 }
347
348 //=======================================================================
349 //function : ObjectsForView
350 //purpose  :
351 //=======================================================================
352 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive&  theListOfIO,
353                                              const Handle(V3d_View)& theView,
354                                              const Standard_Boolean  theIsVisibleInView,
355                                              const AIS_DisplayStatus theStatus) const
356 {
357   Handle(Graphic3d_CView) aViewImpl = theView->View();
358   const Standard_Integer  aViewId   = aViewImpl->Identification();
359   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
360   {
361     if (theStatus != AIS_DS_None
362      && anObjIter.Value()->GraphicStatus() != theStatus)
363     {
364       theListOfIO.Append (anObjIter.Key());
365       continue;
366     }
367
368     Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
369     const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
370     if (isVisible == theIsVisibleInView)
371     {
372       theListOfIO.Append (anObjIter.Key());
373     }
374   }
375 }
376
377 //=======================================================================
378 //function : Display
379 //purpose  :
380 //=======================================================================
381 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
382                                       const Standard_Boolean               theToUpdateViewer)
383 {
384   if (theIObj.IsNull())
385   {
386     return;
387   }
388
389   Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
390   GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
391   Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1, theToUpdateViewer);
392 }
393
394 //=======================================================================
395 //function : SetViewAffinity
396 //purpose  :
397 //=======================================================================
398 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
399                                               const Handle(V3d_View)&              theView,
400                                               const Standard_Boolean               theIsVisible)
401 {
402   if (theIObj.IsNull()
403   || !myObjects.IsBound (theIObj))
404   {
405     return;
406   }
407
408   Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
409   Handle(Graphic3d_CView) aViewImpl = theView->View();
410   anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
411   if (theIsVisible)
412   {
413     theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
414   }
415   else
416   {
417     theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
418   }
419 }
420
421 //=======================================================================
422 //function : Display
423 //purpose  :
424 //=======================================================================
425 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
426                                       const Standard_Integer               theDispMode,
427                                       const Standard_Integer               theSelectionMode,
428                                       const Standard_Boolean               theToUpdateViewer,
429                                       const AIS_DisplayStatus              theDispStatus)
430 {
431   if (theIObj.IsNull())
432   {
433     return;
434   }
435
436   if (theDispStatus == AIS_DS_Erased)
437   {
438     Erase  (theIObj, theToUpdateViewer);
439     Load (theIObj, theSelectionMode);
440     if (Handle(AIS_GlobalStatus)* aStatusPtr = myObjects.ChangeSeek (theIObj))
441     {
442       (*aStatusPtr)->SetDisplayMode (theDispMode);
443     }
444     return;
445   }
446
447   setContextToObject (theIObj);
448   if (!myObjects.IsBound (theIObj))
449   {
450     setObjectStatus (theIObj, AIS_DS_Displayed, theDispMode, theSelectionMode);
451     myMainVwr->StructureManager()->RegisterObject (theIObj);
452     myMainPM->Display(theIObj, theDispMode);
453     if (theSelectionMode != -1)
454     {
455       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
456       if (!mgrSelector->Contains (anObj))
457       {
458         mgrSelector->Load (theIObj);
459       }
460       mgrSelector->Activate (theIObj, theSelectionMode);
461     }
462   }
463   else
464   {
465     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
466
467     // Mark the presentation modes hidden of interactive object different from aDispMode.
468     // Then make sure aDispMode is displayed and maybe highlighted.
469     // Finally, activate selection mode <SelMode> if not yet activated.
470     const Standard_Integer anOldMode = aStatus->DisplayMode();
471     if (anOldMode != theDispMode)
472     {
473       if(myMainPM->IsHighlighted (theIObj, anOldMode))
474       {
475         unhighlightGlobal (theIObj);
476       }
477       myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
478     }
479
480     aStatus->SetDisplayMode (theDispMode);
481
482     myMainPM->Display (theIObj, theDispMode);
483     aStatus->SetGraphicStatus (AIS_DS_Displayed);
484     if (aStatus->IsHilighted())
485     {
486       highlightGlobal (theIObj, aStatus->HilightStyle(), theDispMode);
487     }
488     if (theSelectionMode != -1)
489     {
490       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
491       if (!mgrSelector->Contains (anObj))
492       {
493         mgrSelector->Load (theIObj);
494       }
495       if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
496       {
497         if (!aStatus->IsSModeIn (theSelectionMode))
498           aStatus->AddSelectionMode (theSelectionMode);
499         mgrSelector->Activate (theIObj, theSelectionMode);
500       }
501     }
502   }
503
504   if (theToUpdateViewer)
505   {
506     myMainVwr->Update();
507   }
508 }
509
510 //=======================================================================
511 //function : Load
512 //purpose  :
513 //=======================================================================
514 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
515                                    const Standard_Integer               theSelMode)
516 {
517   if (theIObj.IsNull())
518   {
519     return;
520   }
521
522   setContextToObject (theIObj);
523   if (!myObjects.IsBound (theIObj))
524   {
525     Standard_Integer aDispMode, aHiMod, aSelModeDef;
526     GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
527     setObjectStatus (theIObj, AIS_DS_Erased, aDispMode, theSelMode != -1 ? theSelMode : aSelModeDef);
528     myMainVwr->StructureManager()->RegisterObject (theIObj);
529   }
530
531   // Register theIObj in the selection manager to prepare further activation of selection
532   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
533   if (!mgrSelector->Contains (anObj))
534   {
535     mgrSelector->Load (theIObj);
536   }
537 }
538
539 //=======================================================================
540 //function : Erase
541 //purpose  :
542 //=======================================================================
543 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
544                                     const Standard_Boolean               theToUpdateViewer)
545 {
546   if (theIObj.IsNull())
547   {
548     return;
549   }
550   
551   if (!theIObj->IsAutoHilight())
552   {
553     theIObj->ClearSelected();
554   }
555
556   EraseGlobal (theIObj, Standard_False);
557   if (theToUpdateViewer)
558   {
559     myMainVwr->Update();
560   }
561 }
562
563 //=======================================================================
564 //function : EraseAll
565 //purpose  :
566 //=======================================================================
567 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
568 {
569   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
570   {
571     if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
572     {
573       Erase (anObjIter.Key(), Standard_False);
574     }
575   }
576
577   if (theToUpdateViewer)
578   {
579     myMainVwr->Update();
580   }
581 }
582
583 //=======================================================================
584 //function : DisplayAll
585 //purpose  :
586 //=======================================================================
587 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
588 {
589   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
590   {
591     const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
592     if (aStatus == AIS_DS_Erased)
593     {
594       Display (anObjIter.Key(), Standard_False);
595     }
596   }
597
598   if (theToUpdateViewer)
599   {
600     myMainVwr->Update();
601   }
602 }
603
604 //=======================================================================
605 //function : DisplaySelected
606 //purpose  :
607 //=======================================================================
608 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
609 {
610   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
611   {
612     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
613     Display (anObj, Standard_False);
614   }
615
616   if (theToUpdateViewer && !mySelection->Objects().IsEmpty())
617   {
618     myMainVwr->Update();
619   }
620 }
621
622 //=======================================================================
623 //function : EraseSelected
624 //purpose  :
625 //=======================================================================
626 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
627 {
628   Standard_Boolean isFound = Standard_False;
629   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Init (mySelection->Objects()))
630   {
631     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
632     Erase (anObj, Standard_False);
633     isFound = Standard_True;
634   }
635
636   if (isFound && theToUpdateViewer)
637   {
638     myMainVwr->Update();
639   }
640 }
641
642 //=======================================================================
643 //function : DisplayStatus
644 //purpose  :
645 //=======================================================================
646 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
647 {
648   if (theIObj.IsNull())
649   {
650     return AIS_DS_None;
651   }
652   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
653   return aStatus != NULL ? (*aStatus)->GraphicStatus() : AIS_DS_None;
654 }
655
656 //=======================================================================
657 //function : Remove
658 //purpose  :
659 //=======================================================================
660 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
661                                      const Standard_Boolean               theToUpdateViewer)
662 {
663   if (theIObj.IsNull())
664   {
665     return;
666   }
667
668   if (theIObj->HasInteractiveContext())
669   {
670     if (theIObj->myCTXPtr != this)
671     {
672       throw Standard_ProgramError("AIS_InteractiveContext - object has been displayed in another context!");
673     }
674     theIObj->SetContext (Handle(AIS_InteractiveContext)());
675   }
676   ClearGlobal (theIObj, theToUpdateViewer);
677 }
678
679 //=======================================================================
680 //function : RemoveAll
681 //purpose  :
682 //=======================================================================
683 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
684 {
685   AIS_ListOfInteractive aList;
686   ObjectsInside (aList);
687   for (AIS_ListIteratorOfListOfInteractive 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 //=======================================================================
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 (aStatus->GraphicStatus() == AIS_DS_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 //=======================================================================
730 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
731 {
732   if(anIObj.IsNull()) return;
733   if(!myObjects.IsBound(anIObj)) return;
734
735   const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
736   aStatus->SetHilightStatus (Standard_False);
737   aStatus->SetHilightStyle (Handle(Prs3d_Drawer)());
738
739   if (aStatus->GraphicStatus() == AIS_DS_Displayed)
740   {
741     unhighlightGlobal (anIObj);
742   }
743
744   if(updateviewer) myMainVwr->Update();
745 }
746
747 //=======================================================================
748 //function : IsHilighted
749 //purpose  : Returns true if the objects global status is set to highlighted.
750 //=======================================================================
751 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(AIS_InteractiveObject)& theObj) const
752 {
753   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
754   return aStatus != NULL
755       && (*aStatus)->IsHilighted();
756 }
757
758 //=======================================================================
759 //function : IsHilighted
760 //purpose  : Returns true if the owner is highlighted with selection style.
761 //=======================================================================
762 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner) const
763 {
764   if (theOwner.IsNull() || !theOwner->HasSelectable())
765     return Standard_False;
766
767   const Handle(AIS_InteractiveObject) anObj =
768     Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
769
770   if (anObj->GlobalSelOwner() == theOwner)
771   {
772     if (!myObjects.IsBound (anObj))
773       return Standard_False;
774
775     return myObjects (anObj)->IsHilighted();
776   }
777
778   const Handle(Prs3d_Drawer)& aStyle = getSelStyle (anObj, theOwner);
779   const Standard_Integer aHiMode = getHilightMode (anObj, aStyle, -1);
780   return theOwner->IsHilighted (myMainPM, aHiMode);
781 }
782
783 //=======================================================================
784 //function : HighlightStyle
785 //purpose  :
786 //=======================================================================
787 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObj,
788                                                          Handle(Prs3d_Drawer)& theStyle) const
789 {
790   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
791   if (aStatus != NULL
792    && (*aStatus)->IsHilighted())
793   {
794     theStyle = (*aStatus)->HilightStyle();
795     return Standard_True;
796   }
797
798   theStyle.Nullify();
799   return Standard_False;
800 }
801
802 //=======================================================================
803 //function : HighlightStyle
804 //purpose  :
805 //=======================================================================
806 Standard_Boolean AIS_InteractiveContext::HighlightStyle (const Handle(SelectMgr_EntityOwner)& theOwner,
807                                                          Handle(Prs3d_Drawer)& theStyle) const
808 {
809   if (theOwner.IsNull() || !theOwner->HasSelectable())
810     return Standard_False;
811
812   if (IsHilighted (theOwner))
813   {
814     const Handle(AIS_InteractiveObject) anObj =
815       Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
816     if (anObj->GlobalSelOwner() == theOwner)
817     {
818       theStyle = myObjects (anObj)->HilightStyle();
819     }
820     else
821     {
822       // since part selection style is not stored in global status,
823       // check if the object has own selection style. If not, it can
824       // only be highlighted with default selection style (because
825       // sub-intensity does not modify any selection states)
826       theStyle = getSelStyle (anObj, theOwner);
827     }
828     return Standard_True;
829   }
830   else
831   {
832     theStyle.Nullify();
833     return Standard_False;
834   }
835 }
836
837 //=======================================================================
838 //function : IsDisplayed
839 //purpose  : 
840 //=======================================================================
841
842 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& theObj) const 
843 {
844   if(theObj.IsNull()) return Standard_False;
845
846   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theObj);
847   return aStatus != NULL
848     && (*aStatus)->GraphicStatus() == AIS_DS_Displayed; 
849 }
850
851 //=======================================================================
852 //function : IsDisplayed
853 //purpose  :
854 //=======================================================================
855 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
856                                                       const Standard_Integer               theMode) const
857 {
858   if (theIObj.IsNull())
859   {
860     return Standard_False;
861   }
862
863   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
864   return aStatus != NULL
865       && (*aStatus)->GraphicStatus() == AIS_DS_Displayed
866       && (*aStatus)->DisplayMode() == theMode;
867 }
868
869 //=======================================================================
870 //function : DisplayPriority
871 //purpose  :
872 //=======================================================================
873 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
874 {
875   if (theIObj.IsNull())
876   {
877     return -1;
878   }
879
880   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
881   if (aStatus != NULL
882    && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
883     || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
884   {
885     Standard_Integer aDispMode = theIObj->HasDisplayMode()
886                                ? theIObj->DisplayMode()
887                                : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
888                                 ? myDefaultDrawer->DisplayMode()
889                                 : 0);
890     return myMainPM->DisplayPriority (theIObj, aDispMode);
891   }
892   return 0;
893 }
894
895 //=======================================================================
896 //function : SetDisplayPriority
897 //purpose  :
898 //=======================================================================
899 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
900                                                  const Standard_Integer               thePriority)
901 {
902   if (theIObj.IsNull())
903   {
904     return;
905   }
906
907   setContextToObject (theIObj);
908   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
909   if (aStatus != NULL
910    && ((*aStatus)->GraphicStatus() == AIS_DS_Displayed
911     || (*aStatus)->GraphicStatus() == AIS_DS_Erased))
912   {
913     Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
914                                   ? theIObj->DisplayMode()
915                                   : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
916                                     ? myDefaultDrawer->DisplayMode()
917                                     : 0);
918     myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
919   }
920 }
921
922 //=======================================================================
923 //function : Redisplay
924 //purpose  :
925 //=======================================================================
926 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
927                                         const Standard_Boolean               theToUpdateViewer,
928                                         const Standard_Boolean               theAllModes)
929 {
930   RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
931   RecomputeSelectionOnly (theIObj);
932 }
933
934 //=======================================================================
935 //function : Redisplay
936 //purpose  :
937 //=======================================================================
938 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
939                                         const Standard_Integer    /*theSign*/,
940                                         const Standard_Boolean      theToUpdateViewer)
941 {
942   Standard_Boolean isRedisplayed = Standard_False;
943   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
944   {
945     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
946     if (anObj->Type() != theKOI)
947     {
948       continue;
949     }
950
951     Redisplay (anObj, Standard_False);
952     isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
953                  || isRedisplayed;
954   }
955
956   if (theToUpdateViewer
957    && isRedisplayed)
958   {
959     myMainVwr->Update();
960   }
961 }
962
963 //=======================================================================
964 //function : RecomputePrsOnly
965 //purpose  :
966 //=======================================================================
967 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
968                                                const Standard_Boolean               theToUpdateViewer,
969                                                const Standard_Boolean               theAllModes)
970 {
971   if (theIObj.IsNull())
972   {
973     return;
974   }
975
976   theIObj->SetToUpdate();
977   theIObj->UpdatePresentations (theAllModes);
978   if (!theToUpdateViewer)
979   {
980     return;
981   }
982
983   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
984   if (aStatus != NULL
985    && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
986   {
987     myMainVwr->Update();
988   }
989 }
990 //=======================================================================
991 //function : RecomputeSelectionOnly
992 //purpose  : 
993 //=======================================================================
994 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
995 {
996   if (theIO.IsNull())
997   {
998     return;
999   }
1000
1001   mgrSelector->RecomputeSelection (theIO);
1002
1003   const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIO);
1004   if (aStatus == NULL
1005   || (*aStatus)->GraphicStatus() != AIS_DS_Displayed)
1006   {
1007     return;
1008   }
1009
1010   TColStd_ListOfInteger aModes;
1011   ActivatedModes (theIO, aModes);
1012   TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1013   for (; aModesIter.More(); aModesIter.Next())
1014   {
1015     mgrSelector->Activate (theIO, aModesIter.Value());
1016   }
1017 }
1018
1019 //=======================================================================
1020 //function : Update
1021 //purpose  :
1022 //=======================================================================
1023 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1024                                      const Standard_Boolean               theUpdateViewer)
1025 {
1026   if (theIObj.IsNull())
1027   {
1028     return;
1029   }
1030
1031   theIObj->UpdatePresentations();
1032   mgrSelector->Update(theIObj);
1033
1034   if (theUpdateViewer)
1035   {
1036     const Handle(AIS_GlobalStatus)* aStatus = myObjects.Seek (theIObj);
1037     if (aStatus != NULL
1038      && (*aStatus)->GraphicStatus() == AIS_DS_Displayed)
1039     {
1040       myMainVwr->Update();
1041     }
1042   }
1043 }
1044
1045 //=======================================================================
1046 //function : SetLocation
1047 //purpose  :
1048 //=======================================================================
1049 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1050                                           const TopLoc_Location&               theLoc)
1051 {
1052   if (theIObj.IsNull())
1053   {
1054     return;
1055   }
1056
1057   if (theIObj->HasTransformation()
1058    && theLoc.IsIdentity())
1059   {
1060     theIObj->ResetTransformation();
1061     mgrSelector->Update (theIObj, Standard_False);
1062     return;
1063   }
1064   else if (theLoc.IsIdentity())
1065   {
1066     return;
1067   }
1068
1069   // first reset the previous location to properly clean everything...
1070   if (theIObj->HasTransformation())
1071   {
1072     theIObj->ResetTransformation();
1073   }
1074
1075   theIObj->SetLocalTransformation (theLoc.Transformation());
1076
1077   mgrSelector->Update (theIObj, Standard_False);
1078
1079   // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1080   // to its highlight structure immediately
1081   if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1082   {
1083     const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1084     myLastPicked->UpdateHighlightTrsf (myMainVwr,
1085                                        myMainPM,
1086                                        aHiMod);
1087   }
1088 }
1089
1090 //=======================================================================
1091 //function : ResetLocation
1092 //purpose  :
1093 //=======================================================================
1094 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1095 {
1096   if (theIObj.IsNull())
1097   {
1098     return;
1099   }
1100
1101   theIObj->ResetTransformation();
1102   mgrSelector->Update (theIObj, Standard_False);
1103 }
1104
1105 //=======================================================================
1106 //function : HasLocation
1107 //purpose  :
1108 //=======================================================================
1109 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1110 {
1111   return !theIObj.IsNull()
1112        && theIObj->HasTransformation();
1113 }
1114
1115 //=======================================================================
1116 //function : Location
1117 //purpose  :
1118 //=======================================================================
1119 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1120 {
1121   return theIObj->Transformation();
1122 }
1123
1124 //=======================================================================
1125 //function : SetDeviationCoefficient
1126 //purpose  :
1127 //=======================================================================
1128 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1129 {
1130   myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1131 }
1132
1133 //=======================================================================
1134 //function : SetDeviationAngle
1135 //purpose  :
1136 //=======================================================================
1137 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1138 {
1139   myDefaultDrawer->SetDeviationAngle (theAngle);
1140 }
1141
1142 //=======================================================================
1143 //function : DeviationAngle
1144 //purpose  : Gets  deviationAngle
1145 //=======================================================================
1146 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1147 {
1148   return myDefaultDrawer->DeviationAngle();
1149 }
1150
1151 //=======================================================================
1152 //function : DeviationCoefficient
1153 //purpose  :
1154 //=======================================================================
1155 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1156 {
1157   return myDefaultDrawer->DeviationCoefficient();
1158 }
1159
1160 //=======================================================================
1161 //function : SetHLRDeviationCoefficient
1162 //purpose  :
1163 //=======================================================================
1164 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1165 {
1166   myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1167 }
1168
1169 //=======================================================================
1170 //function : HLRDeviationCoefficient
1171 //purpose  :
1172 //=======================================================================
1173 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1174 {
1175   return myDefaultDrawer->HLRDeviationCoefficient();
1176 }
1177
1178 //=======================================================================
1179 //function : SetHLRAngle
1180 //purpose  :
1181 //=======================================================================
1182 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1183 {
1184   myDefaultDrawer->SetHLRAngle (theAngle);
1185 }
1186
1187 //=======================================================================
1188 //function : SetHLRAngleAndDeviation
1189 //purpose  : compute with anangle a HLRAngle and a HLRDeviationCoefficient 
1190 //           and set them in myHLRAngle and in myHLRDeviationCoefficient
1191 //           of myDefaultDrawer 
1192 //=======================================================================
1193 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1194 {
1195   Standard_Real anOutAngl, anOutDefl;
1196   HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1197
1198   myDefaultDrawer->SetHLRAngle                (anOutAngl);
1199   myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1200 }
1201
1202 //=======================================================================
1203 //function : HLRAngle
1204 //purpose  :
1205 //=======================================================================
1206 Standard_Real AIS_InteractiveContext::HLRAngle() const 
1207 {
1208   return myDefaultDrawer->HLRAngle();
1209 }
1210
1211 //=======================================================================
1212 //function : SetDisplayMode
1213 //purpose  :
1214 //=======================================================================
1215 void AIS_InteractiveContext::SetDisplayMode(const Standard_Integer theMode,
1216                                             const Standard_Boolean theToUpdateViewer)
1217 {
1218   if (theMode == myDefaultDrawer->DisplayMode())
1219   {
1220     return;
1221   }
1222
1223   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1224   {
1225     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1226     Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1227                               || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1228                               || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1229     
1230     if (!toProcess
1231      ||  anObj->HasDisplayMode()
1232      || !anObj->AcceptDisplayMode (theMode))
1233     {
1234       continue;
1235     }
1236
1237     Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1238     aStatus->SetDisplayMode (theMode);
1239
1240     if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1241     {
1242       myMainPM->Display (anObj, theMode);
1243       if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (anObj))
1244       {
1245         myMainPM->BeginImmediateDraw();
1246         unhighlightGlobal (anObj);
1247         myMainPM->EndImmediateDraw (myMainVwr);
1248       }
1249       if (aStatus->IsSubIntensityOn())
1250       {
1251         highlightWithSubintensity (anObj, theMode);
1252       }
1253       myMainPM->SetVisibility (anObj, myDefaultDrawer->DisplayMode(), Standard_False);
1254     }
1255   }
1256
1257   myDefaultDrawer->SetDisplayMode (theMode);
1258   if (theToUpdateViewer)
1259   {
1260     myMainVwr->Update();
1261   }
1262 }
1263
1264 //=======================================================================
1265 //function : SetDisplayMode
1266 //purpose  :
1267 //=======================================================================
1268 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1269                                              const Standard_Integer               theMode,
1270                                              const Standard_Boolean               theToUpdateViewer)
1271 {
1272   setContextToObject (theIObj);
1273   if (!myObjects.IsBound (theIObj))
1274   {
1275     theIObj->SetDisplayMode (theMode);
1276     return;
1277   }
1278   else if (!theIObj->AcceptDisplayMode (theMode))
1279   {
1280     return;
1281   }
1282
1283   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1284   if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1285   {
1286     aStatus->SetDisplayMode (theMode);
1287     theIObj->SetDisplayMode (theMode);
1288     return;
1289   }
1290
1291   // erase presentations for all display modes different from <aMode>
1292   const Standard_Integer anOldMode = aStatus->DisplayMode();
1293   if (anOldMode != theMode)
1294   {
1295     if (myMainPM->IsHighlighted (theIObj, anOldMode))
1296     {
1297       unhighlightGlobal (theIObj);
1298     }
1299     myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1300   }
1301
1302   aStatus->SetDisplayMode (theMode);
1303
1304   myMainPM->Display (theIObj, theMode);
1305   if (aStatus->IsHilighted())
1306   {
1307     highlightGlobal (theIObj, getSelStyle (theIObj, theIObj->GlobalSelOwner()), theMode);
1308   }
1309   if (aStatus->IsSubIntensityOn())
1310   {
1311     highlightWithSubintensity (theIObj, theMode);
1312   }
1313
1314   if (theToUpdateViewer)
1315   {
1316     myMainVwr->Update();
1317   }
1318   theIObj->SetDisplayMode (theMode);
1319 }
1320
1321 //=======================================================================
1322 //function : UnsetDisplayMode
1323 //purpose  :
1324 //=======================================================================
1325 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1326                                                const Standard_Boolean               theToUpdateViewer)
1327 {
1328   if (theIObj.IsNull()
1329   || !theIObj->HasDisplayMode())
1330   {
1331     return;
1332   }
1333
1334   if (!myObjects.IsBound (theIObj))
1335   {
1336     theIObj->UnsetDisplayMode();
1337     return;
1338   }
1339
1340   const Standard_Integer anOldMode = theIObj->DisplayMode();
1341   if (myDefaultDrawer->DisplayMode() == anOldMode)
1342   {
1343     return;
1344   }
1345
1346   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1347   aStatus->SetDisplayMode (myDefaultDrawer->DisplayMode());
1348
1349   if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1350   {
1351     if (myMainPM->IsHighlighted (theIObj, anOldMode))
1352     {
1353       unhighlightGlobal (theIObj);
1354     }
1355     myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1356     myMainPM->Display (theIObj, myDefaultDrawer->DisplayMode());
1357     if (aStatus->IsHilighted())
1358     {
1359       highlightSelected (theIObj->GlobalSelOwner());
1360     }
1361     if (aStatus->IsSubIntensityOn())
1362     {
1363       highlightWithSubintensity (theIObj, myDefaultDrawer->DisplayMode());
1364     }
1365
1366     if (theToUpdateViewer)
1367     {
1368       myMainVwr->Update();
1369     }
1370   }
1371
1372   theIObj->UnsetDisplayMode();
1373 }
1374
1375 //=======================================================================
1376 //function : SetCurrentFacingModel
1377 //purpose  :
1378 //=======================================================================
1379 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1380                                                     const Aspect_TypeOfFacingModel       theModel)
1381 {
1382   if (!theIObj.IsNull())
1383   {
1384     theIObj->SetCurrentFacingModel (theModel);
1385   }
1386 }
1387
1388 //=======================================================================
1389 //function : SetColor
1390 //purpose  :
1391 //=======================================================================
1392 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1393                                        const Quantity_Color&                theColor,
1394                                        const Standard_Boolean               theToUpdateViewer)
1395 {
1396   if (theIObj.IsNull())
1397   {
1398     return;
1399   }
1400
1401   setContextToObject (theIObj);
1402   theIObj->SetColor (theColor);
1403   theIObj->UpdatePresentations();
1404   if (theToUpdateViewer)
1405   {
1406     UpdateCurrentViewer();
1407   }
1408 }
1409
1410 //=======================================================================
1411 //function : SetIsoOnTriangulation
1412 //purpose  :
1413 //=======================================================================
1414 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1415                                                  const Handle(AIS_InteractiveObject)& theObject)
1416 {
1417   if (theObject.IsNull())
1418   {
1419     return;
1420   }
1421
1422   theObject->SetIsoOnTriangulation (theIsEnabled);
1423 }
1424
1425 //=======================================================================
1426 //function : SetDeviationCoefficient
1427 //purpose  :
1428 //=======================================================================
1429 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1430                                                       const Standard_Real                  theCoefficient,
1431                                                       const Standard_Boolean               theToUpdateViewer)
1432 {
1433   if (theIObj.IsNull())
1434   {
1435     return;
1436   }
1437
1438   // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1439   setContextToObject (theIObj);
1440   if (theIObj->Type() != AIS_KOI_Object
1441    && theIObj->Type() != AIS_KOI_Shape)
1442   {
1443     return;
1444   }
1445   else if (theIObj->Signature() != 0)
1446   {
1447     return;
1448   }
1449
1450   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1451   aShape->SetOwnDeviationCoefficient (theCoefficient);
1452   aShape->UpdatePresentations();
1453   if (theToUpdateViewer)
1454   {
1455     UpdateCurrentViewer();
1456   }
1457 }
1458
1459 //=======================================================================
1460 //function : SetHLRDeviationCoefficient
1461 //purpose  :
1462 //=======================================================================
1463 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1464                                                          const Standard_Real                  theCoefficient,
1465                                                          const Standard_Boolean               theToUpdateViewer)
1466 {
1467   if (theIObj.IsNull())
1468   {
1469     return;
1470   }
1471
1472   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1473   setContextToObject (theIObj);
1474   if (theIObj->Type() != AIS_KOI_Object
1475    && theIObj->Type() != AIS_KOI_Shape)
1476   {
1477     return;
1478   }
1479   else if (theIObj->Signature() != 0)
1480   {
1481     return;
1482   }
1483
1484   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1485   aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1486   aShape->UpdatePresentations();
1487   if (theToUpdateViewer)
1488   {
1489     UpdateCurrentViewer();
1490   }
1491 }
1492
1493 //=======================================================================
1494 //function : SetDeviationAngle
1495 //purpose  :
1496 //=======================================================================
1497 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1498                                                 const Standard_Real                  theAngle,
1499                                                 const Standard_Boolean               theToUpdateViewer)
1500 {
1501   if (theIObj.IsNull())
1502   {
1503     return;
1504   }
1505
1506   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1507   setContextToObject (theIObj);
1508   if (theIObj->Type() != AIS_KOI_Shape)
1509   {
1510     return;
1511   }
1512   else if (theIObj->Signature() != 0)
1513   {
1514     return;
1515   }
1516
1517   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1518   aShape->SetOwnDeviationAngle (theAngle);
1519   aShape->UpdatePresentations();
1520   if (theToUpdateViewer)
1521   {
1522     UpdateCurrentViewer();
1523   }
1524 }
1525
1526 //=======================================================================
1527 //function : SetAngleAndDeviation
1528 //purpose  :
1529 //=======================================================================
1530 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1531                                                    const Standard_Real                  theAngle,
1532                                                    const Standard_Boolean               theToUpdateViewer)
1533 {
1534   if (theIObj.IsNull())
1535   {
1536     return;
1537   }
1538
1539   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1540   setContextToObject (theIObj);
1541   if (theIObj->Type() != AIS_KOI_Shape)
1542   {
1543     return;
1544   }
1545   if (theIObj->Signature() != 0)
1546   {
1547     return;
1548   }
1549
1550   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1551   aShape->SetAngleAndDeviation (theAngle);
1552   aShape->UpdatePresentations();
1553   if (theToUpdateViewer)
1554   {
1555     UpdateCurrentViewer();
1556   }
1557 }
1558
1559 //=======================================================================
1560 //function : SetHLRAngleAndDeviation
1561 //purpose  :
1562 //=======================================================================
1563 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1564                                                       const Standard_Real                  theAngle,
1565                                                       const Standard_Boolean               theToUpdateViewer)
1566 {
1567   if (theIObj.IsNull())
1568   {
1569     return;
1570   }
1571
1572   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1573   setContextToObject (theIObj);
1574   if (theIObj->Type() != AIS_KOI_Shape)
1575   {
1576     return;
1577   }
1578   if (theIObj->Signature() != 0)
1579   {
1580     return;
1581   }
1582   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1583   aShape->SetHLRAngleAndDeviation (theAngle);
1584   aShape->UpdatePresentations();
1585   if (theToUpdateViewer)
1586   {
1587     UpdateCurrentViewer();
1588   }
1589 }
1590
1591 //=======================================================================
1592 //function : SetHLRDeviationAngle
1593 //purpose  :
1594 //=======================================================================
1595 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1596                                                    const Standard_Real                  theAngle,
1597                                                    const Standard_Boolean               theToUpdateViewer)
1598 {
1599   if (theIObj.IsNull())
1600   {
1601     return;
1602   }
1603
1604   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1605   setContextToObject (theIObj);
1606   if (theIObj->Type() != AIS_KOI_Shape)
1607   {
1608     return;
1609   }
1610   if (theIObj->Signature() != 0)
1611   {
1612     return;
1613   }
1614   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1615   aShape->SetOwnHLRDeviationAngle (theAngle);
1616   aShape->UpdatePresentations();
1617   if (theToUpdateViewer)
1618   {
1619     UpdateCurrentViewer();
1620   }
1621 }
1622
1623 //=======================================================================
1624 //function : UnsetColor
1625 //purpose  :
1626 //=======================================================================
1627 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
1628                                          const Standard_Boolean               theToUpdateViewer)
1629 {
1630   if (theIObj.IsNull())
1631   {
1632     return;
1633   }
1634
1635   theIObj->UnsetColor();
1636   theIObj->UpdatePresentations();
1637   if (theToUpdateViewer)
1638   {
1639     UpdateCurrentViewer();
1640   }
1641 }
1642
1643 //=======================================================================
1644 //function : HasColor
1645 //purpose  :
1646 //=======================================================================
1647 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
1648 {
1649   return theIObj->HasColor();
1650 }
1651
1652 //=======================================================================
1653 //function : Color
1654 //purpose  :
1655 //=======================================================================
1656 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
1657                                     Quantity_Color&                      theColor) const
1658 {
1659   theIObj->Color (theColor);
1660 }
1661
1662 //=======================================================================
1663 //function : Width
1664 //purpose  :
1665 //=======================================================================
1666 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
1667 {
1668   return theIObj->Width();
1669 }
1670
1671 //=======================================================================
1672 //function : SetWidth
1673 //purpose  :
1674 //=======================================================================
1675 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1676                                        const Standard_Real                  theWidth,
1677                                        const Standard_Boolean               theToUpdateViewer)
1678 {
1679   if (theIObj.IsNull())
1680   {
1681     return;
1682   }
1683
1684   setContextToObject (theIObj);
1685   theIObj->SetWidth (theWidth);
1686   theIObj->UpdatePresentations();
1687   if (!myLastPicked.IsNull() && myLastPicked->IsSameSelectable (theIObj))
1688   {
1689     if (myLastPicked->IsAutoHilight())
1690     {
1691       const Standard_Integer aHiMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1692       myLastPicked->HilightWithColor (myMainPM,
1693                                       myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1694                                       aHiMode);
1695     }
1696     else
1697     {
1698       theIObj->HilightOwnerWithColor (myMainPM,
1699                                       myLastPicked->IsSelected() ? getSelStyle (theIObj, myLastPicked) : getHiStyle (theIObj, myLastPicked),
1700                                       myLastPicked);
1701     }
1702   }
1703   if (theToUpdateViewer)
1704   {
1705     UpdateCurrentViewer();
1706   }
1707 }
1708
1709 //=======================================================================
1710 //function : UnsetWidth
1711 //purpose  :
1712 //=======================================================================
1713 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
1714                                          const Standard_Boolean               theToUpdateViewer)
1715 {
1716   if (theIObj.IsNull())
1717   {
1718     return;
1719   }
1720
1721   theIObj->UnsetWidth();
1722   theIObj->UpdatePresentations();
1723   if (theToUpdateViewer)
1724   {
1725     UpdateCurrentViewer();
1726   }
1727 }
1728
1729 //=======================================================================
1730 //function : SetMaterial
1731 //purpose  :
1732 //=======================================================================
1733 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1734                                           const Graphic3d_MaterialAspect&      theMaterial,
1735                                           const Standard_Boolean               theToUpdateViewer)
1736 {
1737   if (theIObj.IsNull())
1738   {
1739     return;
1740   }
1741
1742   setContextToObject (theIObj);
1743   theIObj->SetMaterial (theMaterial);
1744   theIObj->UpdatePresentations();
1745   if (theToUpdateViewer)
1746   {
1747     UpdateCurrentViewer();
1748   }
1749 }
1750
1751 //=======================================================================
1752 //function : UnsetMaterial
1753 //purpose  :
1754 //=======================================================================
1755 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
1756                                             const Standard_Boolean               theToUpdateViewer)
1757 {
1758   if (theIObj.IsNull())
1759   {
1760     return;
1761   }
1762   theIObj->UnsetMaterial();
1763   theIObj->UpdatePresentations();
1764   if (theToUpdateViewer)
1765   {
1766     UpdateCurrentViewer();
1767   }
1768 }
1769
1770 //=======================================================================
1771 //function : SetTransparency
1772 //purpose  :
1773 //=======================================================================
1774 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1775                                               const Standard_Real                  theValue,
1776                                               const Standard_Boolean               theToUpdateViewer)
1777 {
1778   if (theIObj.IsNull())
1779   {
1780     return;
1781   }
1782
1783   setContextToObject (theIObj);
1784   if (!theIObj->IsTransparent()
1785     && theValue <= 0.005)
1786   {
1787     return;
1788   }
1789
1790   if (theValue <= 0.005)
1791   {
1792     UnsetTransparency (theIObj, theToUpdateViewer);
1793     return;
1794   }
1795
1796   theIObj->SetTransparency (theValue);
1797   theIObj->UpdatePresentations();
1798   if (theToUpdateViewer)
1799   {
1800     UpdateCurrentViewer();
1801   }
1802 }
1803
1804 //=======================================================================
1805 //function : UnsetTransparency
1806 //purpose  :
1807 //=======================================================================
1808 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
1809                                                 const Standard_Boolean               theToUpdateViewer)
1810 {
1811   if (theIObj.IsNull())
1812   {
1813     return;
1814   }
1815
1816   theIObj->UnsetTransparency();
1817   theIObj->UpdatePresentations();
1818   if (theToUpdateViewer)
1819   {
1820     UpdateCurrentViewer();
1821   }
1822 }
1823
1824 //=======================================================================
1825 //function : SetSelectedAspect
1826 //purpose  :
1827 //=======================================================================
1828 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
1829                                                 const Standard_Boolean           theToUpdateViewer)
1830 {
1831   Standard_DISABLE_DEPRECATION_WARNINGS
1832   Standard_Boolean isFound = Standard_False;
1833   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
1834   {
1835     isFound = Standard_True;
1836     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (aSelIter.Value()->Selectable());
1837     anObj->SetAspect (theAspect);
1838   }
1839   Standard_ENABLE_DEPRECATION_WARNINGS
1840
1841   if (isFound && theToUpdateViewer)
1842   {
1843     myMainVwr->Update();
1844   }
1845 }
1846
1847 //=======================================================================
1848 //function : SetLocalAttributes
1849 //purpose  :
1850 //=======================================================================
1851 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1852                                                  const Handle(Prs3d_Drawer)&          theDrawer,
1853                                                  const Standard_Boolean               theToUpdateViewer)
1854 {
1855   if (theIObj.IsNull())
1856   {
1857     return;
1858   }
1859
1860   setContextToObject (theIObj);
1861   theIObj->SetAttributes (theDrawer);
1862   Update (theIObj, theToUpdateViewer);
1863 }
1864
1865 //=======================================================================
1866 //function : UnsetLocalAttributes
1867 //purpose  :
1868 //=======================================================================
1869 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
1870                                                    const Standard_Boolean               theToUpdateViewer)
1871 {
1872   if (theIObj.IsNull())
1873   {
1874     return;
1875   }
1876
1877   setContextToObject (theIObj);
1878   theIObj->UnsetAttributes();
1879   Update (theIObj, theToUpdateViewer);
1880 }
1881
1882 //=======================================================================
1883 //function : Status
1884 //purpose  :
1885 //=======================================================================
1886 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
1887                                      TCollection_ExtendedString&          theStatus) const
1888 {
1889   theStatus = "";
1890   if (theIObj.IsNull()
1891   || !myObjects.IsBound (theIObj))
1892   {
1893     return;
1894   }
1895
1896   theStatus += "\t ____________________________________________";
1897   theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
1898   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1899   switch (aStatus->GraphicStatus())
1900   {
1901     case AIS_DS_Displayed:
1902     {
1903       theStatus += "\t| -->Displayed\n";
1904       break;
1905     }
1906     case AIS_DS_Erased:
1907     {
1908       theStatus += "\t| -->Erased\n";
1909       break;
1910     }
1911     default:
1912       break;
1913   }
1914
1915   theStatus += "\t| Active Display Modes in the MainViewer :\n";
1916   theStatus += "\t|\t Mode ";
1917   theStatus += TCollection_AsciiString (aStatus->DisplayMode());
1918   theStatus += "\n";
1919
1920   if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
1921
1922   theStatus += "\t| Active Selection Modes in the MainViewer :\n";
1923   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1924   {
1925     theStatus += "\t\t Mode ";
1926     theStatus += TCollection_AsciiString (aSelModeIter.Value());
1927     theStatus += "\n";
1928   }
1929   theStatus += "\t ____________________________________________";
1930 }
1931
1932 //=======================================================================
1933 //function : GetDefModes
1934 //purpose  :
1935 //=======================================================================
1936 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
1937                                           Standard_Integer&                    theDispMode,
1938                                           Standard_Integer&                    theHiMode,
1939                                           Standard_Integer&                    theSelMode) const
1940 {
1941   if (theIObj.IsNull())
1942   {
1943     return;
1944   }
1945
1946   theDispMode = theIObj->HasDisplayMode()
1947               ? theIObj->DisplayMode()
1948               : (theIObj->AcceptDisplayMode (myDefaultDrawer->DisplayMode())
1949                ? myDefaultDrawer->DisplayMode()
1950                : 0);
1951   theHiMode  = theIObj->HasHilightMode()   ? theIObj->HilightMode()   : theDispMode;
1952   theSelMode = theIObj->GlobalSelectionMode();
1953 }
1954
1955 //=======================================================================
1956 //function : EraseGlobal
1957 //purpose  :
1958 //=======================================================================
1959 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
1960                                           const Standard_Boolean               theToUpdateviewer)
1961 {
1962   Handle(AIS_GlobalStatus) aStatus;
1963   if (theIObj.IsNull()
1964   || !myObjects.Find (theIObj, aStatus)
1965   ||  aStatus->GraphicStatus() == AIS_DS_Erased)
1966   {
1967     return;
1968   }
1969
1970   const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
1971   unselectOwners (theIObj);
1972   myMainPM->SetVisibility (theIObj, aStatus->DisplayMode(), Standard_False);
1973
1974   if (!myLastPicked.IsNull()
1975     && myLastPicked->IsSameSelectable (theIObj))
1976   {
1977     clearDynamicHighlight();
1978   }
1979
1980   // make sure highlighting presentations are properly erased
1981   theIObj->ErasePresentations (false);
1982
1983   if (IsSelected (theIObj)
1984    && aStatus->DisplayMode() != aDispMode)
1985   {
1986     myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
1987   }
1988
1989   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
1990   {
1991     mgrSelector->Deactivate (theIObj, aSelModeIter.Value());
1992   }
1993   aStatus->ClearSelectionModes();
1994   aStatus->SetGraphicStatus (AIS_DS_Erased);
1995
1996   if (theToUpdateviewer)
1997   {
1998     myMainVwr->Update();
1999   }
2000 }
2001
2002 //=======================================================================
2003 //function : unselectOwners
2004 //purpose  :
2005 //=======================================================================
2006 void AIS_InteractiveContext::unselectOwners (const Handle(AIS_InteractiveObject)& theObject)
2007 {
2008   SelectMgr_SequenceOfOwner aSeq;
2009   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2010   {
2011     if (aSelIter.Value()->IsSameSelectable (theObject))
2012     {
2013       aSeq.Append (aSelIter.Value());
2014     }
2015   }
2016   for (SelectMgr_SequenceOfOwner::Iterator aDelIter (aSeq); aDelIter.More(); aDelIter.Next())
2017   {
2018     AddOrRemoveSelected (aDelIter.Value(), Standard_False);
2019   }
2020 }
2021
2022 //=======================================================================
2023 //function : ClearGlobal
2024 //purpose  :
2025 //=======================================================================
2026 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2027                                           const Standard_Boolean               theToUpdateviewer)
2028 {
2029   Handle(AIS_GlobalStatus) aStatus;
2030   if (theIObj.IsNull()
2031   || !myObjects.Find (theIObj, aStatus))
2032   {
2033     // for cases when reference shape of connected interactives was not displayed
2034     // but its selection primitives were calculated
2035     const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2036     mgrSelector->Remove (anObj);
2037     return;
2038   }
2039
2040   unselectOwners (theIObj);
2041
2042   myMainPM->Erase (theIObj, -1);
2043   theIObj->ErasePresentations (true); // make sure highlighting presentations are properly erased
2044
2045   // Object removes from Detected sequence
2046   Standard_DISABLE_DEPRECATION_WARNINGS
2047   for (Standard_Integer aDetIter = myDetectedSeq.Lower(); aDetIter <= myDetectedSeq.Upper();)
2048   {
2049     Handle(SelectMgr_EntityOwner) aPicked = myMainSel->Picked (myDetectedSeq (aDetIter));
2050     Handle(AIS_InteractiveObject) anObj;
2051     if (!aPicked.IsNull())
2052     {
2053       anObj = Handle(AIS_InteractiveObject)::DownCast (aPicked->Selectable());
2054     }
2055
2056     if (!anObj.IsNull()
2057       && anObj == theIObj)
2058     {
2059       myDetectedSeq.Remove (aDetIter);
2060       if (myCurDetected == aDetIter)
2061       {
2062         myCurDetected = Min (myDetectedSeq.Upper(), aDetIter);
2063       }
2064       if (myCurHighlighted == aDetIter)
2065       {
2066         myCurHighlighted = 0;
2067       }
2068     }
2069     else
2070     {
2071       aDetIter++;
2072     }
2073   }
2074   Standard_ENABLE_DEPRECATION_WARNINGS
2075
2076   // remove IO from the selection manager to avoid memory leaks
2077   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2078   mgrSelector->Remove (anObj);
2079
2080   setObjectStatus (theIObj, AIS_DS_None, -1, -1);
2081   myMainVwr->StructureManager()->UnregisterObject (theIObj);
2082
2083   for (V3d_ListOfViewIterator aDefViewIter (myMainVwr->DefinedViewIterator()); aDefViewIter.More(); aDefViewIter.Next())
2084   {
2085     aDefViewIter.Value()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2086   }
2087
2088   if (!myLastPicked.IsNull())
2089   {
2090     if (myLastPicked->IsSameSelectable (theIObj))
2091     {
2092       clearDynamicHighlight();
2093       myLastPicked.Nullify();
2094     }
2095   }
2096
2097   if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2098   {
2099     myMainVwr->Update();
2100   }
2101 }
2102
2103 //=======================================================================
2104 //function : ClearGlobalPrs
2105 //purpose  :
2106 //=======================================================================
2107 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2108                                              const Standard_Integer               theMode,
2109                                              const Standard_Boolean               theToUpdateViewer)
2110 {
2111   if (theIObj.IsNull()
2112   || !myObjects.IsBound (theIObj))
2113   {
2114     return;
2115   }
2116
2117   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2118   if (aStatus->DisplayMode() == theMode)
2119   {
2120     const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2121     if (aDispMode == theMode
2122      && myMainPM->IsHighlighted (theIObj, theMode))
2123     {
2124       unhighlightGlobal (theIObj);
2125     }
2126
2127     myMainPM->Erase (theIObj, theMode);
2128   }
2129
2130   if (aStatus->GraphicStatus() == AIS_DS_Displayed
2131    && theToUpdateViewer)
2132   {
2133     myMainVwr->Update();
2134   }
2135 }
2136
2137 //=======================================================================
2138 //function : ClearDetected
2139 //purpose  :
2140 //=======================================================================
2141 Standard_Boolean AIS_InteractiveContext::ClearDetected (Standard_Boolean theToRedrawImmediate)
2142 {
2143   myCurDetected = 0;
2144   myCurHighlighted = 0;
2145   myDetectedSeq.Clear();
2146   Standard_Boolean toUpdate = Standard_False;
2147   if (!myLastPicked.IsNull() && myLastPicked->HasSelectable())
2148   {
2149     toUpdate = Standard_True;
2150     clearDynamicHighlight();
2151   }
2152   myLastPicked.Nullify();
2153   myMainSel->ClearPicked();
2154   if (toUpdate && theToRedrawImmediate)
2155   {
2156     myMainVwr->RedrawImmediate();
2157   }
2158   return toUpdate;
2159 }
2160
2161 //=======================================================================
2162 //function : DrawHiddenLine
2163 //purpose  :
2164 //=======================================================================
2165 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2166 {
2167   return myDefaultDrawer->DrawHiddenLine();
2168 }
2169
2170 //=======================================================================
2171 //function : EnableDrawHiddenLine
2172 //purpose  :
2173 //=======================================================================
2174 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2175 {
2176   myDefaultDrawer->EnableDrawHiddenLine();
2177 }
2178
2179 //=======================================================================
2180 //function : DisableDrawHiddenLine 
2181 //purpose  :
2182 //=======================================================================
2183 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2184 {
2185   myDefaultDrawer->DisableDrawHiddenLine();
2186 }
2187
2188 //=======================================================================
2189 //function : HiddenLineAspect
2190 //purpose  :
2191 //=======================================================================
2192 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2193 {
2194   return myDefaultDrawer->HiddenLineAspect();
2195 }
2196
2197 //=======================================================================
2198 //function : SetHiddenLineAspect
2199 //purpose  :
2200 //=======================================================================
2201 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2202 {
2203   myDefaultDrawer->SetHiddenLineAspect (theAspect);
2204 }
2205
2206 //=======================================================================
2207 //function : SetIsoNumber
2208 //purpose  :
2209 //=======================================================================
2210 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2211                                            const AIS_TypeOfIso    theType)
2212 {
2213   switch (theType)
2214   {
2215     case AIS_TOI_IsoU:
2216       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2217       break;
2218     case AIS_TOI_IsoV:
2219       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2220       break;
2221     case AIS_TOI_Both:
2222       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2223       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2224       break;
2225   }
2226 }
2227
2228 //=======================================================================
2229 //function : IsoNumber
2230 //purpose  :
2231 //=======================================================================
2232 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2233 {
2234   switch (theType)
2235   {
2236     case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2237     case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2238     case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2239                             ? myDefaultDrawer->UIsoAspect()->Number()
2240                             : -1;
2241   }
2242   return 0;
2243 }
2244
2245 //=======================================================================
2246 //function : IsoOnPlane
2247 //purpose  :
2248 //=======================================================================
2249 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2250 {
2251   myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2252 }
2253
2254 //=======================================================================
2255 //function : IsoOnPlane
2256 //purpose  :
2257 //=======================================================================
2258 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2259 {
2260   return myDefaultDrawer->IsoOnPlane();
2261 }
2262
2263 //=======================================================================
2264 //function : IsoOnTriangulation
2265 //purpose  :
2266 //=======================================================================
2267 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2268 {
2269   myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2270 }
2271
2272 //=======================================================================
2273 //function : IsoOnTriangulation
2274 //purpose  :
2275 //=======================================================================
2276 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2277 {
2278   return myDefaultDrawer->IsoOnTriangulation();
2279 }
2280
2281 //=======================================================================
2282 //function : SetPixelTolerance
2283 //purpose  :
2284 //=======================================================================
2285 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2286 {
2287   myMainSel->SetPixelTolerance (thePrecision);
2288 }
2289
2290 //=======================================================================
2291 //function : PixelTolerance
2292 //purpose  :
2293 //=======================================================================
2294 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2295 {
2296   return myMainSel->PixelTolerance();
2297 }
2298
2299 //=======================================================================
2300 //function : SetSelectionSensitivity
2301 //purpose  : Allows to manage sensitivity of a particular selection of interactive object theObject
2302 //=======================================================================
2303 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2304                                                       const Standard_Integer theMode,
2305                                                       const Standard_Integer theNewSensitivity)
2306 {
2307   mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2308 }
2309
2310 //=======================================================================
2311 //function : InitAttributes
2312 //purpose  :
2313 //=======================================================================
2314 void AIS_InteractiveContext::InitAttributes()
2315 {
2316   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2317   myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2318
2319 //  myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2320   Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2321   aLineAspect->SetColor      (Quantity_NOC_GRAY20);
2322   aLineAspect->SetWidth      (1.0);
2323   aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2324
2325   // tolerance to 2 pixels...
2326   SetPixelTolerance (2);
2327
2328   // Customizing the drawer for trihedrons and planes...
2329   Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2330   const Standard_Real aLength = 100.0;
2331   aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2332   const Quantity_Color aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2333   aTrihAspect->LineAspect(Prs3d_DP_XAxis)->SetColor (aColor);
2334   aTrihAspect->LineAspect(Prs3d_DP_YAxis)->SetColor (aColor);
2335   aTrihAspect->LineAspect(Prs3d_DP_ZAxis)->SetColor (aColor);
2336
2337   Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2338   const Standard_Real aPlaneLength = 200.0;
2339   aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2340   aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2341 }
2342
2343 //=======================================================================
2344 //function : TrihedronSize
2345 //purpose  :
2346 //=======================================================================
2347 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2348 {
2349   return myDefaultDrawer->DatumAspect()->AxisLength(Prs3d_DP_XAxis);
2350 }
2351
2352 //=======================================================================
2353 //function : SetTrihedronSize
2354 //purpose  :
2355 //=======================================================================
2356 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real    theVal,
2357                                                const Standard_Boolean /*updateviewer*/)
2358 {
2359   myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2360   Redisplay (AIS_KOI_Datum, 3, Standard_False);
2361   Redisplay (AIS_KOI_Datum, 4, Standard_True);
2362 }
2363
2364 //=======================================================================
2365 //function : SetPlaneSize
2366 //purpose  :
2367 //=======================================================================
2368 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real    theValX,
2369                                           const Standard_Real    theValY,
2370                                           const Standard_Boolean theToUpdateViewer)
2371 {
2372   myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2373   Redisplay (AIS_KOI_Datum, 7, theToUpdateViewer);
2374 }
2375
2376 //=======================================================================
2377 //function : SetPlaneSize
2378 //purpose  :
2379 //=======================================================================
2380 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real    theVal,
2381                                            const Standard_Boolean theToUpdateViewer)
2382 {
2383   SetPlaneSize (theVal, theVal, theToUpdateViewer);
2384 }
2385
2386 //=======================================================================
2387 //function : PlaneSize
2388 //purpose  :
2389 //=======================================================================
2390 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2391                                                     Standard_Real& theY) const
2392 {
2393   theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2394   theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2395   return (Abs (theX - theY) <= Precision::Confusion());
2396 }
2397
2398 //=======================================================================
2399 //function : SetZLayer
2400 //purpose  :
2401 //=======================================================================
2402 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2403                                         const Graphic3d_ZLayerId theLayerId)
2404 {
2405   if (theIObj.IsNull())
2406     return;
2407
2408   theIObj->SetZLayer (theLayerId);
2409 }
2410
2411 //=======================================================================
2412 //function : GetZLayer
2413 //purpose  :
2414 //=======================================================================
2415 Graphic3d_ZLayerId AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2416 {
2417   return !theIObj.IsNull()
2418        ?  theIObj->ZLayer()
2419        :  Graphic3d_ZLayerId_UNKNOWN;
2420 }
2421
2422 //=======================================================================
2423 //function : RebuildSelectionStructs
2424 //purpose  : Rebuilds 1st level of BVH selection forcibly
2425 //=======================================================================
2426 void AIS_InteractiveContext::RebuildSelectionStructs()
2427 {
2428   myMainSel->RebuildObjectsTree (Standard_True);
2429 }
2430
2431 //=======================================================================
2432 //function : Disconnect
2433 //purpose  : Disconnects selectable object from an assembly and updates selection structures
2434 //=======================================================================
2435 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2436                                          const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2437 {
2438   if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2439   {
2440     Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2441     theObj->Disconnect (theObjToDisconnect);
2442     if (!myObjects.IsBound (theObjToDisconnect))
2443     {
2444       // connected presentation might contain displayed presentations
2445       myMainPM->Erase (theObjToDisconnect, -1);
2446       theObjToDisconnect->ErasePresentations (true);
2447     }
2448
2449     const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2450     mgrSelector->Remove (anObj);
2451   }
2452   else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2453   {
2454     Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2455     theObj->Disconnect();
2456     const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2457     mgrSelector->Remove (anObj);
2458   }
2459   else
2460     return;
2461 }
2462
2463 //=======================================================================
2464 //function : FitSelected
2465 //purpose  : Fits the view corresponding to the bounds of selected objects
2466 //=======================================================================
2467 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView)
2468 {
2469   FitSelected (theView, 0.01, Standard_True);
2470 }
2471
2472 //=======================================================================
2473 //function : BoundingBoxOfSelection
2474 //purpose  :
2475 //=======================================================================
2476 Bnd_Box AIS_InteractiveContext::BoundingBoxOfSelection() const
2477 {
2478   Bnd_Box aBndSelected;
2479   AIS_MapOfObjectOwners anObjectOwnerMap;
2480   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
2481   {
2482     const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
2483     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast(anOwner->Selectable());
2484     if (anObj->IsInfinite())
2485     {
2486       continue;
2487     }
2488
2489     if (anOwner == anObj->GlobalSelOwner())
2490     {
2491       Bnd_Box aTmpBnd;
2492       anObj->BoundingBox (aTmpBnd);
2493       aBndSelected.Add (aTmpBnd);
2494     }
2495     else
2496     {
2497       Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2498       if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2499       {
2500         anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2501         anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2502       }
2503
2504       anOwnerMap->Add (anOwner);
2505     }
2506   }
2507
2508   for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2509   {
2510     const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2511     Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2512     aBndSelected.Add (aTmpBox);
2513   }
2514
2515   return aBndSelected;
2516 }
2517
2518 //=======================================================================
2519 //function : FitSelected
2520 //purpose  : Fits the view corresponding to the bounds of selected objects
2521 //=======================================================================
2522 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2523                                           const Standard_Real theMargin,
2524                                           const Standard_Boolean theToUpdate)
2525 {
2526   Bnd_Box aBndSelected = BoundingBoxOfSelection();
2527   if (!aBndSelected.IsVoid())
2528   {
2529     theView->FitAll (aBndSelected, theMargin, theToUpdate);
2530   }
2531 }
2532
2533 //=======================================================================
2534 //function : SetTransformPersistence
2535 //purpose  :
2536 //=======================================================================
2537 void AIS_InteractiveContext::SetTransformPersistence (const Handle(AIS_InteractiveObject)& theObject,
2538                                                       const Handle(Graphic3d_TransformPers)& theTrsfPers)
2539 {
2540   theObject->SetTransformPersistence (theTrsfPers);
2541   if (!myObjects.IsBound (theObject))
2542   {
2543     return;
2544   }
2545
2546   mgrSelector->UpdateSelection (theObject);
2547
2548   const Standard_Integer    aLayerId   = myObjects.Find (theObject)->GetLayerIndex();
2549   const Handle(V3d_Viewer)& aCurViewer = CurrentViewer();
2550   for (V3d_ListOfViewIterator anActiveViewIter (aCurViewer->ActiveViewIterator()); anActiveViewIter.More(); anActiveViewIter.Next())
2551   {
2552     anActiveViewIter.Value()->View()->InvalidateBVHData (aLayerId);
2553     anActiveViewIter.Value()->View()->InvalidateZLayerBoundingBox (aLayerId);
2554   }
2555 }
2556
2557 //=======================================================================
2558 //function : GravityPoint
2559 //purpose  :
2560 //=======================================================================
2561 gp_Pnt AIS_InteractiveContext::GravityPoint (const Handle(V3d_View)& theView) const
2562 {
2563   return theView->GravityPoint();
2564 }
2565 //=======================================================================
2566 //function : setObjectStatus
2567 //purpose  :
2568 //=======================================================================
2569 void AIS_InteractiveContext::setObjectStatus (const Handle(AIS_InteractiveObject)& theIObj,
2570                                               const AIS_DisplayStatus theStatus,
2571                                               const Standard_Integer theDispMode,
2572                                               const Standard_Integer theSelectionMode)
2573 {
2574   if (theStatus != AIS_DS_None)
2575   {
2576     Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
2577     myObjects.Bind (theIObj, aStatus);
2578   }
2579   else
2580     myObjects.UnBind (theIObj);
2581
2582   for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (theIObj->Children()); aPrsIter.More(); aPrsIter.Next())
2583   {
2584     Handle(AIS_InteractiveObject) aChild (Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value()));
2585     if (aChild.IsNull())
2586       continue;
2587
2588     setObjectStatus (aChild, theStatus, theDispMode, theSelectionMode);
2589   }
2590 }