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