0026372: Meshing of surface of revolution fails in debug mode
[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 // Modified by  XAB & Serguei Dec 97 (angle &deviation coeffts)
18
19 #include <AIS_ConnectedInteractive.hxx>
20 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
21 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
22 #include <AIS_GlobalStatus.hxx>
23 #include <AIS_InteractiveContext.hxx>
24 #include <AIS_InteractiveObject.hxx>
25 #include <AIS_ListIteratorOfListOfInteractive.hxx>
26 #include <AIS_LocalContext.hxx>
27 #include <AIS_LocalStatus.hxx>
28 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
29 #include <AIS_MultipleConnectedInteractive.hxx>
30 #include <AIS_Shape.hxx>
31 #include <AIS_Trihedron.hxx>
32 #include <Geom_Axis2Placement.hxx>
33 #include <Graphic3d_AspectFillArea3d.hxx>
34 #include <HLRBRep.hxx>
35 #include <OSD_Environment.hxx>
36 #include <Precision.hxx>
37 #include <Prs3d_BasicAspect.hxx>
38 #include <Prs3d_DatumAspect.hxx>
39 #include <Prs3d_IsoAspect.hxx>
40 #include <Prs3d_LineAspect.hxx>
41 #include <Prs3d_PlaneAspect.hxx>
42 #include <Prs3d_ShadingAspect.hxx>
43 #include <PrsMgr_ModedPresentation.hxx>
44 #include <PrsMgr_PresentableObject.hxx>
45 #include <Quantity_Color.hxx>
46 #include <SelectMgr_EntityOwner.hxx>
47 #include <SelectMgr_Filter.hxx>
48 #include <SelectMgr_OrFilter.hxx>
49 #include <SelectMgr_SelectionManager.hxx>
50 #include <Standard_Atomic.hxx>
51 #include <Standard_Transient.hxx>
52 #include <Standard_Type.hxx>
53 #include <StdSelect_ViewerSelector3d.hxx>
54 #include <TCollection_AsciiString.hxx>
55 #include <TCollection_ExtendedString.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
58 #include <TopLoc_Location.hxx>
59 #include <TopoDS_Shape.hxx>
60 #include <UnitsAPI.hxx>
61 #include <V3d_View.hxx>
62 #include <V3d_Viewer.hxx>
63
64 IMPLEMENT_STANDARD_RTTIEXT(AIS_InteractiveContext,MMgt_TShared)
65
66 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
67 namespace
68 {
69   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)> AIS_MapOfObjectOwners;
70   typedef NCollection_DataMap<Handle(SelectMgr_SelectableObject), Handle(SelectMgr_IndexedMapOfOwner)>::Iterator AIS_MapIteratorOfMapOfObjectOwners;
71 }
72
73 //=======================================================================
74 //function : AIS_InteractiveContext
75 //purpose  : 
76 //=======================================================================
77
78 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
79 mgrSelector(new SelectMgr_SelectionManager()),
80 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())),
81 myMainVwr(MainViewer),
82 myMainSel(new StdSelect_ViewerSelector3d()),
83 myWasLastMain(Standard_False),
84 myCurrentTouched(Standard_False),
85 mySelectedTouched(Standard_False),
86 myToHilightSelected(Standard_True),
87 myFilters(new SelectMgr_OrFilter()),
88 myDefaultDrawer(new Prs3d_Drawer()),
89 mySelection(new AIS_Selection()),
90 myDefaultColor(Quantity_NOC_GOLDENROD),
91 myHilightColor(Quantity_NOC_CYAN1),
92 mySelectionColor(Quantity_NOC_GRAY80),
93 myPreselectionColor(Quantity_NOC_GREEN),
94 mySubIntensity(Quantity_NOC_GRAY40),
95 myDisplayMode(0),
96 myCurLocalIndex(0),
97 myAISCurDetected(0),
98 myZDetectionFlag(0),
99 myIsAutoActivateSelMode(Standard_True)
100
101   InitAttributes();
102 }
103
104 void AIS_InteractiveContext::Delete() const
105 {
106   // clear the current selection
107   mySelection->Select();
108
109   // let's remove one reference explicitly. this operation's supposed to
110   // be performed when mgrSelector will be destroyed but anyway...
111   const Handle(SelectMgr_ViewerSelector)& aSelector = myMainSel; // to avoid ambiguity
112   mgrSelector->Remove (aSelector);
113
114   Handle(AIS_InteractiveContext) aNullContext;
115   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
116   {
117     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
118     anObj->SetContext (aNullContext);
119     for (anObj->Init(); anObj->More(); anObj->Next())
120     {
121       anObj->CurrentSelection()->UpdateBVHStatus (SelectMgr_TBU_Renew);
122     }
123   }
124   MMgt_TShared::Delete();
125 }
126
127 //=======================================================================
128 //function : UpdateCurrentViewer
129 //purpose  : 
130 //=======================================================================
131
132 void AIS_InteractiveContext::UpdateCurrentViewer()
133 {
134   if (!myMainVwr.IsNull())
135     myMainVwr->Update();
136 }
137
138
139 //=======================================================================
140 //function : DomainOfMainViewer
141 //purpose  : 
142 //=======================================================================
143
144 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const 
145 {
146   return myMainVwr->Domain();
147   
148 }
149
150 //=======================================================================
151 //function : DisplayedObjects
152 //purpose  :
153 //=======================================================================
154 void AIS_InteractiveContext::DisplayedObjects (AIS_ListOfInteractive& theListOfIO,
155                                                const Standard_Boolean theOnlyFromNeutral) const
156 {
157   if (!HasOpenedContext()
158    || theOnlyFromNeutral)
159   {
160     for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
161     {
162       if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
163       {
164         theListOfIO.Append (anObjIter.Key());
165       }
166     }
167     return;
168   }
169
170   // neutral point
171   TColStd_MapOfTransient aDispMap;
172   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
173   {
174     if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
175     {
176       aDispMap.Add (anObjIter.Key());
177     }
178   }
179
180   // parse all local contexts...
181   for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
182   {
183     const Handle(AIS_LocalContext)& aLocCtx = aCtxIter.Value();
184     aLocCtx->DisplayedObjects (aDispMap);
185   }
186
187   Handle(AIS_InteractiveObject) anObj;
188   for (TColStd_MapIteratorOfMapOfTransient aDispMapIter (aDispMap); aDispMapIter.More(); aDispMapIter.Next())
189   {
190     const Handle(Standard_Transient)& aTransient = aDispMapIter.Key();
191     anObj = Handle(AIS_InteractiveObject)::DownCast (aTransient);
192     theListOfIO.Append (anObj);
193   }
194 }
195
196 //=======================================================================
197 //function : DisplayedObjects
198 //purpose  :
199 //=======================================================================
200 void AIS_InteractiveContext::DisplayedObjects (const AIS_KindOfInteractive theKind,
201                                                const Standard_Integer      theSign,
202                                                AIS_ListOfInteractive&      theListOfIO,
203                                                const Standard_Boolean /*OnlyFromNeutral*/) const
204 {
205   ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Displayed, theListOfIO);
206 }
207
208 //=======================================================================
209 //function : ErasedObjects
210 //purpose  :
211 //=======================================================================
212 void AIS_InteractiveContext::ErasedObjects (AIS_ListOfInteractive& theListOfIO) const
213 {
214   ObjectsByDisplayStatus (AIS_DS_Erased, theListOfIO);
215 }
216
217 //=======================================================================
218 //function : ErasedObjects
219 //purpose  :
220 //=======================================================================
221 void AIS_InteractiveContext::ErasedObjects (const AIS_KindOfInteractive theKind,
222                                             const Standard_Integer      theSign,
223                                             AIS_ListOfInteractive&      theListOfIO) const
224 {
225   ObjectsByDisplayStatus (theKind, theSign, AIS_DS_Erased, theListOfIO);
226 }
227
228 //=======================================================================
229 //function : ObjectsByDisplayStatus
230 //purpose  :
231 //=======================================================================
232 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_DisplayStatus theStatus,
233                                                      AIS_ListOfInteractive&  theListOfIO) const
234 {
235   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
236   {
237     if (anObjIter.Value()->GraphicStatus() == theStatus)
238     {
239       theListOfIO.Append (anObjIter.Key());
240     }
241   }
242 }
243
244 //=======================================================================
245 //function : ObjectsByDisplayStatus
246 //purpose  :
247 //=======================================================================
248 void AIS_InteractiveContext::ObjectsByDisplayStatus (const AIS_KindOfInteractive theKind,
249                                                      const Standard_Integer      theSign,
250                                                      const AIS_DisplayStatus     theStatus,
251                                                      AIS_ListOfInteractive&      theListOfIO) const
252 {
253   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
254   {
255     if (theStatus != AIS_DS_None
256      && anObjIter.Value()->GraphicStatus() != theStatus)
257     {
258       continue;
259     }
260     else if (anObjIter.Key()->Type() != theKind)
261     {
262       continue;
263     }
264
265     if (theSign == -1
266      || anObjIter.Key()->Signature() == theSign)
267     {
268       theListOfIO.Append (anObjIter.Key());
269     }
270   }
271 }
272
273 //=======================================================================
274 //function : ObjectsInside
275 //purpose  :
276 //=======================================================================
277 void AIS_InteractiveContext::ObjectsInside (AIS_ListOfInteractive&      theListOfIO,
278                                             const AIS_KindOfInteractive theKind,
279                                             const Standard_Integer      theSign) const
280 {
281   if (theKind == AIS_KOI_None
282    && theSign == -1)
283   {
284     for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
285     {
286       theListOfIO.Append (anObjIter.Key());
287     }
288     return;
289   }
290
291   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
292   {
293     if (anObjIter.Key()->Type() != theKind)
294     {
295       continue;
296     }
297
298     if (theSign == -1
299      || anObjIter.Key()->Signature() == theSign)
300     {
301       theListOfIO.Append (anObjIter.Key());
302     }
303   }
304 }
305
306 //=======================================================================
307 //function : ObjectsForView
308 //purpose  :
309 //=======================================================================
310 void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive&  theListOfIO,
311                                              const Handle(V3d_View)& theView,
312                                              const Standard_Boolean  theIsVisibleInView,
313                                              const AIS_DisplayStatus theStatus) const
314 {
315   Handle(Graphic3d_CView) aViewImpl = theView->View();
316   const Standard_Integer  aViewId   = aViewImpl->Identification();
317   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
318   {
319     if (theStatus != AIS_DS_None
320      && anObjIter.Value()->GraphicStatus() != theStatus)
321     {
322       theListOfIO.Append (anObjIter.Key());
323       continue;
324     }
325
326     Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key());
327     const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId);
328     if (isVisible == theIsVisibleInView)
329     {
330       theListOfIO.Append (anObjIter.Key());
331     }
332   }
333 }
334
335 //=======================================================================
336 //function : Display
337 //purpose  :
338 //=======================================================================
339 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
340                                       const Standard_Boolean               theToUpdateViewer)
341 {
342   if (theIObj.IsNull())
343   {
344     return;
345   }
346
347   Standard_Integer aDispMode = 0, aHiMod = -1, aSelMode = -1;
348   GetDefModes (theIObj, aDispMode, aHiMod, aSelMode);
349
350   Display (theIObj, aDispMode, myIsAutoActivateSelMode ? aSelMode : -1,
351            theToUpdateViewer, theIObj->AcceptShapeDecomposition());
352 }
353
354 //=======================================================================
355 //function : SetViewAffinity
356 //purpose  :
357 //=======================================================================
358 void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject)& theIObj,
359                                               const Handle(V3d_View)&              theView,
360                                               const Standard_Boolean               theIsVisible)
361 {
362   if (theIObj.IsNull()
363   || !myObjects.IsBound (theIObj))
364   {
365     return;
366   }
367
368   Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj);
369   Handle(Graphic3d_CView) aViewImpl = theView->View();
370   anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True);
371   if (theIsVisible)
372   {
373     theView->View()->ChangeHiddenObjects()->Remove (theIObj.get());
374   }
375   else
376   {
377     theView->View()->ChangeHiddenObjects()->Add (theIObj.get());
378   }
379 }
380
381 //=======================================================================
382 //function : Display
383 //purpose  :
384 //=======================================================================
385 void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIObj,
386                                       const Standard_Integer               theDispMode,
387                                       const Standard_Integer               theSelectionMode,
388                                       const Standard_Boolean               theToUpdateViewer,
389                                       const Standard_Boolean               theToAllowDecomposition,
390                                       const AIS_DisplayStatus              theDispStatus)
391 {
392   if (theIObj.IsNull())
393   {
394     return;
395   }
396
397   if (theDispStatus == AIS_DS_Erased)
398   {
399     Erase  (theIObj, theToUpdateViewer);
400     Load (theIObj, theSelectionMode, theToAllowDecomposition);
401     return;
402   }
403
404   if (!theIObj->HasInteractiveContext())
405   {
406     theIObj->SetContext (this);
407   }
408
409   if (theDispStatus == AIS_DS_Temporary
410   && !HasOpenedContext())
411   {
412     return;
413   }
414   else if (HasOpenedContext())
415   {
416     if (theDispStatus == AIS_DS_None
417      || theDispStatus == AIS_DS_Temporary)
418     {
419       myLocalContexts (myCurLocalIndex)->Display (theIObj, theDispMode, theToAllowDecomposition, theSelectionMode);
420       if (theToUpdateViewer)
421       {
422         myMainVwr->Update();
423       }
424       return;
425     }
426   }
427
428   if (!myObjects.IsBound (theIObj))
429   {
430     Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode);
431     myObjects.Bind   (theIObj, aStatus);
432     Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj);
433     myMainPM->Display(theIObj, theDispMode);
434     if (theSelectionMode != -1)
435     {
436       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
437       if (!mgrSelector->Contains (anObj))
438       {
439         mgrSelector->Load (theIObj);
440       }
441       mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
442     }
443   }
444   else
445   {
446     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
447     if (aStatus->GraphicStatus() == AIS_DS_Temporary)
448     {
449       return;
450     }
451
452     // Mark the presentation modes hidden of interactive object different from aDispMode.
453     // Then make sure aDispMode is displayed and maybe highlighted.
454     // Finally, activate selection mode <SelMode> if not yet activated.
455     TColStd_ListOfInteger aModesToRemove;
456     for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
457     {
458       const Standard_Integer anOldMode = aDispModeIter.Value();
459       if (anOldMode != theDispMode)
460       {
461         aModesToRemove.Append (anOldMode);
462         if(myMainPM->IsHighlighted (theIObj, anOldMode))
463         {
464           myMainPM->Unhighlight (theIObj, anOldMode);
465         }
466         myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
467       }
468     }
469
470     for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
471     {
472       aStatus->RemoveDisplayMode (aRemModeIter.Value());
473     }
474
475     if (!aStatus->IsDModeIn (theDispMode))
476     {
477       aStatus->AddDisplayMode (theDispMode);
478     }
479
480     myMainPM->Display (theIObj, theDispMode);
481     aStatus->SetGraphicStatus (AIS_DS_Displayed);
482     if (aStatus->IsHilighted())
483     {
484       const Standard_Integer aHiMod = theIObj->HasHilightMode() ? theIObj->HilightMode() : theDispMode;
485       myMainPM->Color (theIObj, aStatus->HilightColor(), aHiMod);
486     }
487     if (theSelectionMode != -1)
488     {
489       const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
490       if (!mgrSelector->Contains (anObj))
491       {
492         mgrSelector->Load (theIObj);
493       }
494       if (!mgrSelector->IsActivated (theIObj, theSelectionMode))
495       {
496         if (!aStatus->IsSModeIn (theSelectionMode))
497           aStatus->AddSelectionMode (theSelectionMode);
498         mgrSelector->Activate (theIObj, theSelectionMode, myMainSel);
499       }
500     }
501   }
502
503   if (theToUpdateViewer)
504   {
505     myMainVwr->Update();
506   }
507 }
508
509 //=======================================================================
510 //function : Load
511 //purpose  :
512 //=======================================================================
513 void AIS_InteractiveContext::Load (const Handle(AIS_InteractiveObject)& theIObj,
514                                    const Standard_Integer               theSelMode,
515                                    const Standard_Boolean               theToAllowDecomposition)
516 {
517   if (theIObj.IsNull())
518   {
519     return;
520   }
521
522   if (!theIObj->HasInteractiveContext())
523   {
524     theIObj->SetContext (this);
525   }
526
527   if (HasOpenedContext())
528   {
529     myLocalContexts (myCurLocalIndex)->Load (theIObj, theToAllowDecomposition, theSelMode);
530     return;
531   }
532
533   if (theSelMode == -1
534   && !theToAllowDecomposition)
535   {
536     if (!myObjects.IsBound (theIObj))
537     {
538       Standard_Integer aDispMode, aHiMod, aSelModeDef;
539       GetDefModes (theIObj, aDispMode, aHiMod, aSelModeDef);
540       Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Erased, aDispMode, aSelModeDef);
541       myObjects.Bind (theIObj, aStatus);
542     }
543
544     // Register theIObj in the selection manager to prepare further activation of selection
545     const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
546     if (!mgrSelector->Contains (anObj))
547     {
548       mgrSelector->Load (theIObj);
549     }
550   }
551 }
552
553 //=======================================================================
554 //function : Erase
555 //purpose  :
556 //=======================================================================
557 void AIS_InteractiveContext::Erase (const Handle(AIS_InteractiveObject)& theIObj,
558                                     const Standard_Boolean               theToUpdateViewer)
559 {
560   if (theIObj.IsNull())
561   {
562     return;
563   }
564   
565   if (!theIObj->IsAutoHilight())
566   {
567     theIObj->ClearSelected();
568   }
569
570   Standard_Boolean wasInCtx = Standard_False;
571   if (HasOpenedContext())
572   {
573     // First it is checked if it is possible to remove in the current local context
574     // then one tries to remove in other local contexts, if they allow it...
575     wasInCtx = myLocalContexts (myCurLocalIndex)->Erase (theIObj);
576     for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
577     {
578       if (aCtxIter.Value()->AcceptErase())
579       {
580         wasInCtx = aCtxIter.Value()->Erase (theIObj) || wasInCtx;
581       }
582     }
583   }
584
585   if (!wasInCtx)
586   {
587     EraseGlobal (theIObj, Standard_False);
588   }
589
590   if (theToUpdateViewer)
591   {
592     myMainVwr->Update();
593   }
594 }
595
596 //=======================================================================
597 //function : EraseAll
598 //purpose  :
599 //=======================================================================
600 void AIS_InteractiveContext::EraseAll (const Standard_Boolean theToUpdateViewer)
601 {
602   if (HasOpenedContext())
603   {
604     return;
605   }
606
607   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
608   {
609     if (anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed)
610     {
611       Erase (anObjIter.Key(), Standard_False);
612     }
613   }
614
615   if (theToUpdateViewer)
616   {
617     myMainVwr->Update();
618   }
619 }
620
621 //=======================================================================
622 //function : DisplayAll
623 //purpose  :
624 //=======================================================================
625 void AIS_InteractiveContext::DisplayAll (const Standard_Boolean theToUpdateViewer)
626 {
627   if (HasOpenedContext())
628   {
629     return;
630   }
631
632   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
633   {
634     const AIS_DisplayStatus aStatus = anObjIter.Value()->GraphicStatus();
635     if (aStatus == AIS_DS_Erased)
636     {
637       Display (anObjIter.Key(), Standard_False);
638     }
639   }
640
641   if (theToUpdateViewer)
642   {
643     myMainVwr->Update();
644   }
645 }
646
647 //=======================================================================
648 //function : DisplaySelected
649 //purpose  :
650 //=======================================================================
651 void AIS_InteractiveContext::DisplaySelected (const Standard_Boolean theToUpdateViewer)
652 {
653   if (HasOpenedContext())
654   {
655     return;
656   }
657
658   Standard_Boolean      isFound  = Standard_False;
659   for (mySelection->Init(); mySelection->More(); mySelection->Next())
660   {
661     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
662     Display (anObj, Standard_False);
663     isFound = Standard_True;
664   }
665
666   if (isFound && theToUpdateViewer)
667   {
668     myMainVwr->Update();
669   }
670 }
671
672 //=======================================================================
673 //function : EraseSelected
674 //purpose  :
675 //=======================================================================
676 void AIS_InteractiveContext::EraseSelected (const Standard_Boolean theToUpdateViewer)
677 {
678   if (HasOpenedContext())
679   {
680     return;
681   }
682
683   Standard_Boolean      isFound  = Standard_False;
684   mySelection->Init();
685   while (mySelection->More())
686   {
687     Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
688     Handle(AIS_InteractiveObject) anObj   = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
689
690     Erase (anObj, Standard_False);
691     isFound = Standard_True;
692
693     mySelection->Init();
694   }
695
696   if (isFound && theToUpdateViewer)
697   {
698     myMainVwr->Update();
699   }
700 }
701
702 //=======================================================================
703 //function : 
704 //purpose  : 
705 //=======================================================================
706
707 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
708                                                        const Standard_Integer WhichContext)
709 {
710   if(anIObj.IsNull()) return Standard_False;
711
712   if(!HasOpenedContext()) return Standard_False;
713   if(myObjects.IsBound(anIObj)) return Standard_False;
714   if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
715   
716   // Protection : if one tries to preserve a temporary object
717   // which is not in the local active context... rob 11-06-97
718
719   Standard_Integer IsItInLocal = myCurLocalIndex;
720   Standard_Boolean Found(Standard_False);
721
722   while(IsItInLocal>0 && !Found){
723     if(!myLocalContexts.IsBound(IsItInLocal))
724       IsItInLocal--;
725     else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
726       Found = Standard_True;
727     else
728       IsItInLocal--;
729   }
730
731   if(!Found) return Standard_False;
732   
733
734 //  const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ? 
735 //    myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
736   // CLE
737   // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
738   Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
739   // ENDCLE
740   
741   
742   if(LS->IsTemporary()){
743     Standard_Integer DM,HM,SM;
744     GetDefModes(anIObj,DM,HM,SM);
745     
746     SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
747     if(LS->DisplayMode()!= DM ){
748       Standard_Integer LSM =  LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
749       myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
750     }
751
752     Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
753                                                         DM,
754                                                         SM,
755                                                         Standard_False);
756 //    GS->SubIntensityOn();
757     myObjects.Bind(anIObj,GS);
758     mgrSelector->Load(anIObj);
759     mgrSelector->Activate(anIObj,SM,myMainSel);
760     
761     LS->SetTemporary(Standard_False);
762   }                                 
763   return Standard_True;
764 }
765
766 //=======================================================================
767 //function : DisplayStatus
768 //purpose  :
769 //=======================================================================
770 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus (const Handle(AIS_InteractiveObject)& theIObj) const
771 {
772   if (theIObj.IsNull())
773   {
774     return AIS_DS_None;
775   }
776   else if (myObjects.IsBound (theIObj))
777   {
778     return myObjects (theIObj)->GraphicStatus();
779   }
780
781   for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
782   {
783     if (aCtxIter.Value()->IsIn (theIObj))
784     {
785       return AIS_DS_Temporary;
786     }
787   }
788   return AIS_DS_None;
789 }
790
791 //=======================================================================
792 //function : DisplayedModes
793 //purpose  :
794 //=======================================================================
795 const TColStd_ListOfInteger& AIS_InteractiveContext::DisplayedModes (const Handle(AIS_InteractiveObject)& theIObj) const
796 {
797   return myObjects (theIObj)->DisplayedModes();
798 }
799
800 //=======================================================================
801 //function : Remove
802 //purpose  :
803 //=======================================================================
804 void AIS_InteractiveContext::Remove (const Handle(AIS_InteractiveObject)& theIObj,
805                                      const Standard_Boolean               theToUpdateViewer)
806 {
807   if (theIObj.IsNull())
808   {
809     return;
810   }
811
812   if (HasOpenedContext())
813   {
814     myLocalContexts (myCurLocalIndex)->Remove (theIObj);
815     for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
816     {
817       if (aCtxIter.Value()->AcceptErase())
818       {
819         aCtxIter.Value()->Remove (theIObj);
820       }
821     }
822   }
823
824   ClearGlobal (theIObj, theToUpdateViewer);
825 }
826
827 //=======================================================================
828 //function : RemoveAll
829 //purpose  :
830 //=======================================================================
831 void AIS_InteractiveContext::RemoveAll (const Standard_Boolean theToUpdateViewer)
832 {
833   AIS_ListOfInteractive aList;
834   ObjectsInside (aList);
835   for (AIS_ListIteratorOfListOfInteractive aListIterator (aList); aListIterator.More(); aListIterator.Next())
836   {
837     Remove (aListIterator.Value(), Standard_False);
838   }
839
840   if (theToUpdateViewer)
841   {
842     myMainVwr->Update();
843   }
844 }
845
846 //=======================================================================
847 //function : ClearPrs
848 //purpose  :
849 //=======================================================================
850 void AIS_InteractiveContext::ClearPrs (const Handle(AIS_InteractiveObject)& theIObj,
851                                        const Standard_Integer               theMode,
852                                        const Standard_Boolean               theToUpdateViewer)
853 {
854   if (theIObj.IsNull())
855   {
856     return;
857   }
858
859   if (!HasOpenedContext())
860   {
861     ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
862     return;
863   }
864
865   Standard_Boolean wasInCtx = myLocalContexts (myCurLocalIndex)->ClearPrs (theIObj, theMode);
866   for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
867   {
868     if (aCtxIter.Value()->AcceptErase())
869     {
870       wasInCtx = aCtxIter.Value()->ClearPrs (theIObj, theMode) || wasInCtx;
871     }
872   }
873   if (!wasInCtx)
874   {
875     ClearGlobalPrs (theIObj, theMode, theToUpdateViewer);
876   }
877   else if (theToUpdateViewer)
878   {
879     myMainVwr->Update();
880   }
881 }
882
883 //=======================================================================
884 //function : Hilight
885 //purpose  :
886 //=======================================================================
887 void AIS_InteractiveContext::Hilight (const Handle(AIS_InteractiveObject)& theIObj,
888                                       const Standard_Boolean               theToUpdateViewer)
889 {
890   if (theIObj.IsNull())
891   {
892     return;
893   }
894
895   if (!theIObj->HasInteractiveContext())
896   {
897     theIObj->SetContext (this);
898   }
899   if (!HasOpenedContext())
900   {
901     if (!myObjects.IsBound (theIObj))
902     {
903       return;
904     }
905
906     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
907     aStatus->SetHilightStatus (Standard_True);
908     if (aStatus->GraphicStatus() == AIS_DS_Displayed)
909     {
910       Standard_Integer aHilightMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
911       myMainPM->Highlight (theIObj, aHilightMode);
912     }
913   }
914   else
915   {
916     myLocalContexts (myCurLocalIndex)->Hilight (theIObj);
917   }
918
919   if (theToUpdateViewer)
920   {
921     myMainVwr->Update();
922   }
923 }
924 //=======================================================================
925 //function : Hilight
926 //purpose  : 
927 //=======================================================================
928
929 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
930                                               const Quantity_NameOfColor aCol,
931                                               const Standard_Boolean updateviewer)
932 {
933   if(anIObj.IsNull()) return;
934
935   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
936
937   if (!HasOpenedContext())
938   {
939     if(!myObjects.IsBound(anIObj)) return;
940
941     const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
942     aStatus->SetHilightStatus (Standard_True);
943
944     if (aStatus->GraphicStatus() == AIS_DS_Displayed)
945     {
946       const Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
947       myMainPM->Color (anIObj, aCol, aHilightMode);
948       aStatus->SetHilightColor (aCol);
949     }
950   }
951   else
952   {
953     myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
954   }
955   if(updateviewer) myMainVwr->Update();
956 }
957
958 //=======================================================================
959 //function : Unhilight
960 //purpose  : 
961 //=======================================================================
962
963 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
964 {
965   if(anIObj.IsNull()) return;
966
967   if (!HasOpenedContext())
968   {
969     if(!myObjects.IsBound(anIObj)) return;
970
971     const Handle(AIS_GlobalStatus)& aStatus = myObjects(anIObj);
972     aStatus->SetHilightStatus (Standard_False);
973     aStatus->SetHilightColor(Quantity_NOC_WHITE);
974
975     if (aStatus->GraphicStatus() == AIS_DS_Displayed)
976     {
977       Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
978       myMainPM->Unhighlight (anIObj, aHilightMode);
979     }
980   }
981   else
982   {
983     myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
984   }
985   if(updateviewer) myMainVwr->Update();
986 }
987
988 //=======================================================================
989 //function : IsHilighted
990 //purpose  : 
991 //=======================================================================
992
993 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const 
994 {
995   if(anIObj.IsNull()) return Standard_False;
996
997   if (!HasOpenedContext()){
998     if(!myObjects.IsBound(anIObj)) 
999       return Standard_False;
1000     return myObjects(anIObj)->IsHilighted();
1001   }
1002   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1003   for(;ItM.More();ItM.Next()){
1004     if(ItM.Value()->IsHilighted(anIObj))
1005       return Standard_True;
1006   }
1007   return Standard_False;
1008 }
1009
1010 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1011                                                      Standard_Boolean& WithColor,
1012                                                      Quantity_NameOfColor& TheHiCol) const
1013 {
1014   if(!HasOpenedContext()){
1015     if(myObjects.IsBound(anIObj)){
1016       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1017       if(STAT->IsHilighted()){
1018         if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1019           WithColor=Standard_True;
1020           TheHiCol = STAT->HilightColor();
1021         }
1022         else
1023           WithColor = Standard_False;
1024         return Standard_True;
1025       }
1026     }
1027     return Standard_False;
1028   }
1029   Standard_Integer MaxIndex = HighestIndex();
1030   for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1031     if(myLocalContexts.IsBound(i)){
1032       if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1033         return Standard_True;
1034     }
1035     
1036   }
1037   return Standard_False;
1038 }
1039
1040 //=======================================================================
1041 //function : IsHilighted
1042 //purpose  : Returns true if the objects global status is set to highlighted.
1043 //           theIsCustomColor flag defines if highlight color is not equal to OCCT's
1044 //           default Quantity_NOC_WHITE color. If theIsCustomColor is true,
1045 //           custom highlight color name will be stored to theCustomColorName
1046 //=======================================================================
1047 Standard_Boolean AIS_InteractiveContext::IsHilighted (const Handle(SelectMgr_EntityOwner)& theOwner,
1048                                                       Standard_Boolean& theIsCustomColor,
1049                                                       Quantity_NameOfColor& theCustomColorName) const
1050 {
1051   if (theOwner.IsNull() || !theOwner->HasSelectable())
1052     return Standard_False;
1053
1054   const Handle(AIS_InteractiveObject) anObj =
1055     Handle(AIS_InteractiveObject)::DownCast (theOwner->Selectable());
1056
1057   if (!myObjects.IsBound (anObj))
1058     return Standard_False;
1059
1060   const Handle(AIS_GlobalStatus)& anObjStatus = myObjects (anObj);
1061   if (anObjStatus->IsHilighted())
1062   {
1063     if (anObjStatus->HilightColor() != Quantity_NOC_WHITE)
1064     {
1065       theIsCustomColor = Standard_True;
1066       theCustomColorName = anObjStatus->HilightColor();
1067     }
1068     else
1069     {
1070       theIsCustomColor = Standard_False;
1071     }
1072
1073     return Standard_True;
1074   }
1075
1076   return Standard_False;
1077 }
1078
1079 //=======================================================================
1080 //function : IsDisplayed
1081 //purpose  : 
1082 //=======================================================================
1083
1084 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const 
1085 {
1086   if(anIObj.IsNull()) return Standard_False;
1087
1088
1089   if(myObjects.IsBound(anIObj)) 
1090     if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1091       return Standard_True;
1092   
1093   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1094   for(;ItM.More();ItM.Next()){
1095     if(ItM.Value()->IsDisplayed(anIObj))
1096       return Standard_True;
1097   }
1098   return Standard_False;
1099   
1100 }
1101
1102 //=======================================================================
1103 //function : IsDisplayed
1104 //purpose  :
1105 //=======================================================================
1106 Standard_Boolean AIS_InteractiveContext::IsDisplayed (const Handle(AIS_InteractiveObject)& theIObj,
1107                                                       const Standard_Integer               theMode) const
1108 {
1109   if (theIObj.IsNull())
1110   {
1111     return Standard_False;
1112   }
1113
1114   if (myObjects.IsBound (theIObj))
1115   {
1116     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1117     if (aStatus->GraphicStatus() == AIS_DS_Displayed
1118      && aStatus->IsDModeIn (theMode))
1119     {
1120       return Standard_True;
1121     }
1122   }
1123
1124   for (AIS_DataMapIteratorOfDataMapOfILC aCtxIter (myLocalContexts); aCtxIter.More(); aCtxIter.Next())
1125   {
1126     if (aCtxIter.Value()->IsDisplayed (theIObj, theMode))
1127     {
1128       return Standard_True;
1129     }
1130   }
1131   return Standard_False;
1132 }
1133
1134 //=======================================================================
1135 //function : DisplayPriority
1136 //purpose  :
1137 //=======================================================================
1138 Standard_Integer AIS_InteractiveContext::DisplayPriority (const Handle(AIS_InteractiveObject)& theIObj) const
1139 {
1140   if (theIObj.IsNull())
1141   {
1142     return -1;
1143   }
1144   else if (!myObjects.IsBound (theIObj))
1145   {
1146     return 0;
1147   }
1148
1149   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1150   if (aStatus->GraphicStatus() == AIS_DS_Displayed
1151    || aStatus->GraphicStatus() == AIS_DS_Erased)
1152   {
1153     Standard_Integer aDispMode = theIObj->HasDisplayMode()
1154                                ? theIObj->DisplayMode()
1155                                : (theIObj->AcceptDisplayMode (myDisplayMode)
1156                                 ? myDisplayMode
1157                                 : 0);
1158     return myMainPM->DisplayPriority (theIObj, aDispMode);
1159   }
1160   return 0;
1161 }
1162
1163 //=======================================================================
1164 //function : SetDisplayPriority
1165 //purpose  :
1166 //=======================================================================
1167 void AIS_InteractiveContext::SetDisplayPriority (const Handle(AIS_InteractiveObject)& theIObj,
1168                                                  const Standard_Integer               thePriority)
1169 {
1170   if (theIObj.IsNull())
1171   {
1172     return;
1173   }
1174
1175   if (!theIObj->HasInteractiveContext())
1176   {
1177     theIObj->SetContext (this);
1178   }
1179
1180   if (myObjects.IsBound (theIObj))
1181   {
1182     Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1183     if (aStatus->GraphicStatus() == AIS_DS_Displayed
1184      || aStatus->GraphicStatus() == AIS_DS_Erased)
1185     {
1186       Standard_Integer aDisplayMode = theIObj->HasDisplayMode()
1187                                     ? theIObj->DisplayMode()
1188                                     : (theIObj->AcceptDisplayMode (myDisplayMode)
1189                                      ? myDisplayMode
1190                                      : 0);
1191       myMainPM->SetDisplayPriority (theIObj, aDisplayMode, thePriority);
1192     }
1193   }
1194   else if (HasOpenedContext())
1195   {
1196     myLocalContexts (myCurLocalIndex)->SetDisplayPriority (theIObj, thePriority);
1197   }
1198 }
1199
1200 //=======================================================================
1201 //function : Redisplay
1202 //purpose  :
1203 //=======================================================================
1204 void AIS_InteractiveContext::Redisplay (const Handle(AIS_InteractiveObject)& theIObj,
1205                                         const Standard_Boolean               theToUpdateViewer,
1206                                         const Standard_Boolean               theAllModes)
1207 {
1208   RecomputePrsOnly (theIObj, theToUpdateViewer, theAllModes);
1209   RecomputeSelectionOnly (theIObj);
1210 }
1211
1212 //=======================================================================
1213 //function : Redisplay
1214 //purpose  :
1215 //=======================================================================
1216 void AIS_InteractiveContext::Redisplay (const AIS_KindOfInteractive theKOI,
1217                                         const Standard_Integer    /*theSign*/,
1218                                         const Standard_Boolean      theToUpdateViewer)
1219 {
1220   Standard_Boolean isRedisplayed = Standard_False;
1221   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1222   {
1223     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1224     if (anObj->Type() != theKOI)
1225     {
1226       continue;
1227     }
1228
1229     Redisplay (anObj, Standard_False);
1230     isRedisplayed = anObjIter.Value()->GraphicStatus() == AIS_DS_Displayed
1231                  || isRedisplayed;
1232   }
1233
1234   if (theToUpdateViewer
1235    && isRedisplayed)
1236   {
1237     myMainVwr->Update();
1238   }
1239 }
1240
1241 //=======================================================================
1242 //function : RecomputePrsOnly
1243 //purpose  :
1244 //=======================================================================
1245 void AIS_InteractiveContext::RecomputePrsOnly (const Handle(AIS_InteractiveObject)& theIObj,
1246                                                const Standard_Boolean               theToUpdateViewer,
1247                                                const Standard_Boolean               theAllModes)
1248 {
1249   if (theIObj.IsNull())
1250   {
1251     return;
1252   }
1253
1254   theIObj->Update (theAllModes);
1255   if (!theToUpdateViewer)
1256   {
1257     return;
1258   }
1259
1260   if (HasOpenedContext()
1261    || (myObjects.IsBound (theIObj)
1262     && myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed))
1263   {
1264     myMainVwr->Update();
1265   }
1266 }
1267 //=======================================================================
1268 //function : RecomputeSelectionOnly
1269 //purpose  : 
1270 //=======================================================================
1271 void AIS_InteractiveContext::RecomputeSelectionOnly (const Handle(AIS_InteractiveObject)& theIO)
1272 {
1273   if (theIO.IsNull())
1274   {
1275     return;
1276   }
1277
1278   mgrSelector->RecomputeSelection (theIO);
1279
1280   if (HasOpenedContext())
1281   {
1282     for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1283     {
1284       myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIO, Standard_False);
1285     }
1286     return;
1287   }
1288
1289   if (!myObjects.IsBound (theIO) ||
1290       myObjects (theIO)->GraphicStatus() != AIS_DS_Displayed)
1291   {
1292     return;
1293   }
1294
1295   TColStd_ListOfInteger aModes;
1296   ActivatedModes (theIO, aModes);
1297   TColStd_ListIteratorOfListOfInteger aModesIter (aModes);
1298   for (; aModesIter.More(); aModesIter.Next())
1299   {
1300     mgrSelector->Activate (theIO, aModesIter.Value(), myMainSel);
1301   }
1302 }
1303
1304 //=======================================================================
1305 //function : Update
1306 //purpose  :
1307 //=======================================================================
1308 void AIS_InteractiveContext::Update (const Handle(AIS_InteractiveObject)& theIObj,
1309                                      const Standard_Boolean               theUpdateViewer)
1310 {
1311   if (theIObj.IsNull())
1312   {
1313     return;
1314   }
1315
1316   TColStd_ListOfInteger aPrsModes;
1317   theIObj->ToBeUpdated (aPrsModes);
1318   for (TColStd_ListIteratorOfListOfInteger aPrsModesIt (aPrsModes); aPrsModesIt.More(); aPrsModesIt.Next())
1319   {
1320     theIObj->Update (aPrsModesIt.Value(), Standard_False);
1321   }
1322
1323   mgrSelector->Update(theIObj);
1324
1325   for (Standard_Integer aContextIdx = 1; aContextIdx <= myLocalContexts.Extent(); aContextIdx++)
1326   {
1327     myLocalContexts (aContextIdx)->ClearOutdatedSelection (theIObj, Standard_False);
1328   }
1329
1330   if (theUpdateViewer)
1331   {
1332     if (!myObjects.IsBound (theIObj))
1333     {
1334       return;
1335     }
1336
1337     switch (myObjects (theIObj)->GraphicStatus())
1338     {
1339       case AIS_DS_Displayed:
1340       case AIS_DS_Temporary:
1341         myMainVwr->Update();
1342         break;
1343       default:
1344         break;
1345     }
1346   }
1347 }
1348
1349 //=======================================================================
1350 //function : SetLocation
1351 //purpose  :
1352 //=======================================================================
1353 void AIS_InteractiveContext::SetLocation (const Handle(AIS_InteractiveObject)& theIObj,
1354                                           const TopLoc_Location&               theLoc)
1355 {
1356   if (theIObj.IsNull())
1357   {
1358     return;
1359   }
1360
1361   if (theIObj->HasTransformation()
1362    && theLoc.IsIdentity())
1363   {
1364     theIObj->ResetTransformation();
1365     mgrSelector->Update (theIObj, Standard_False);
1366     return;
1367   }
1368   else if (theLoc.IsIdentity())
1369   {
1370     return;
1371   }
1372
1373   // first reset the previous location to properly clean everything...
1374   if (theIObj->HasTransformation())
1375   {
1376     theIObj->ResetTransformation();
1377   }
1378
1379   theIObj->SetLocalTransformation (theLoc.Transformation());
1380
1381   if (!HasOpenedContext())
1382   {
1383     mgrSelector->Update (theIObj, Standard_False);
1384   }
1385   else
1386   {
1387     Handle(StdSelect_ViewerSelector3d) aTempSel = myLocalContexts (myCurLocalIndex)->MainSelector();
1388     mgrSelector->Update (theIObj, aTempSel, Standard_False);
1389   }
1390
1391   // if the object or its part is highlighted dynamically, it is necessary to apply location transformation
1392   // to its highlight structure immediately
1393   if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
1394   {
1395     myLastPicked->UpdateHighlightTrsf (myMainVwr,
1396                                        myMainPM,
1397                                        theIObj->HasDisplayMode() ? theIObj->DisplayMode() : 0);
1398   }
1399 }
1400
1401 //=======================================================================
1402 //function : ResetLocation
1403 //purpose  :
1404 //=======================================================================
1405 void AIS_InteractiveContext::ResetLocation (const Handle(AIS_InteractiveObject)& theIObj)
1406 {
1407   if (theIObj.IsNull())
1408   {
1409     return;
1410   }
1411
1412   theIObj->ResetTransformation();
1413   mgrSelector->Update (theIObj, Standard_False);
1414 }
1415
1416 //=======================================================================
1417 //function : HasLocation
1418 //purpose  :
1419 //=======================================================================
1420 Standard_Boolean AIS_InteractiveContext::HasLocation (const Handle(AIS_InteractiveObject)& theIObj) const
1421 {
1422   return !theIObj.IsNull()
1423        && theIObj->HasTransformation();
1424 }
1425
1426 //=======================================================================
1427 //function : Location
1428 //purpose  :
1429 //=======================================================================
1430 TopLoc_Location AIS_InteractiveContext::Location (const Handle(AIS_InteractiveObject)& theIObj) const
1431 {
1432   return theIObj->Transformation();
1433 }
1434
1435 //=======================================================================
1436 //function : SetDeviationCoefficient
1437 //purpose  :
1438 //=======================================================================
1439 void AIS_InteractiveContext::SetDeviationCoefficient (const Standard_Real theCoefficient)
1440 {
1441   myDefaultDrawer->SetDeviationCoefficient (theCoefficient);
1442 }
1443
1444 //=======================================================================
1445 //function : SetDeviationAngle
1446 //purpose  :
1447 //=======================================================================
1448 void AIS_InteractiveContext::SetDeviationAngle (const Standard_Real theAngle)
1449 {
1450   myDefaultDrawer->SetDeviationAngle (theAngle);
1451 }
1452
1453 //=======================================================================
1454 //function : DeviationAngle
1455 //purpose  : Gets  deviationAngle
1456 //=======================================================================
1457 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1458 {
1459   return myDefaultDrawer->DeviationAngle();
1460 }
1461
1462 //=======================================================================
1463 //function : DeviationCoefficient
1464 //purpose  :
1465 //=======================================================================
1466 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const
1467 {
1468   return myDefaultDrawer->DeviationCoefficient();
1469 }
1470
1471 //=======================================================================
1472 //function : SetHLRDeviationCoefficient
1473 //purpose  :
1474 //=======================================================================
1475 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Standard_Real theCoefficient)
1476 {
1477   myDefaultDrawer->SetHLRDeviationCoefficient (theCoefficient);
1478 }
1479
1480 //=======================================================================
1481 //function : HLRDeviationCoefficient
1482 //purpose  :
1483 //=======================================================================
1484 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const
1485 {
1486   return myDefaultDrawer->HLRDeviationCoefficient();
1487 }
1488
1489 //=======================================================================
1490 //function : SetHLRAngle
1491 //purpose  :
1492 //=======================================================================
1493 void AIS_InteractiveContext::SetHLRAngle (const Standard_Real theAngle)
1494 {
1495   myDefaultDrawer->SetHLRAngle (theAngle);
1496 }
1497
1498 //=======================================================================
1499 //function : SetHLRAngleAndDeviation
1500 //purpose  : compute with anangle a HLRAngle and a HLRDeviationCoefficient 
1501 //           and set them in myHLRAngle and in myHLRDeviationCoefficient
1502 //           of myDefaultDrawer 
1503 //=======================================================================
1504 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Standard_Real theAngle)
1505 {
1506   Standard_Real anOutAngl, anOutDefl;
1507   HLRBRep::PolyHLRAngleAndDeflection (theAngle, anOutAngl, anOutDefl);
1508
1509   myDefaultDrawer->SetHLRAngle                (anOutAngl);
1510   myDefaultDrawer->SetHLRDeviationCoefficient (anOutDefl);
1511 }
1512
1513 //=======================================================================
1514 //function : HLRAngle
1515 //purpose  :
1516 //=======================================================================
1517 Standard_Real AIS_InteractiveContext::HLRAngle() const 
1518 {
1519   return myDefaultDrawer->HLRAngle();
1520 }
1521
1522 //=======================================================================
1523 //function : SetDisplayMode
1524 //purpose  :
1525 //=======================================================================
1526 void AIS_InteractiveContext::SetDisplayMode (const AIS_DisplayMode  theMode,
1527                                              const Standard_Boolean theToUpdateViewer)
1528 {
1529   if (theMode == myDisplayMode)
1530   {
1531     return;
1532   }
1533
1534   for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next())
1535   {
1536     Handle(AIS_InteractiveObject) anObj = anObjIter.Key();
1537     Standard_Boolean toProcess = anObj->IsKind (STANDARD_TYPE(AIS_Shape))
1538                               || anObj->IsKind (STANDARD_TYPE(AIS_ConnectedInteractive))
1539                               || anObj->IsKind (STANDARD_TYPE(AIS_MultipleConnectedInteractive));
1540     
1541     if (!toProcess
1542      ||  anObj->HasDisplayMode()
1543      || !anObj->AcceptDisplayMode (theMode))
1544     {
1545       continue;
1546     }
1547
1548     Handle(AIS_GlobalStatus) aStatus = anObjIter.Value();
1549     if (aStatus->IsDModeIn (myDisplayMode))
1550     {
1551       aStatus->RemoveDisplayMode (myDisplayMode);
1552     }
1553
1554     aStatus->AddDisplayMode (theMode);
1555     if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1556     {
1557       myMainPM->Display (anObj, theMode);
1558       if (!myLastPicked.IsNull() && myLastPicked->Selectable() == anObj)
1559       {
1560         myMainPM->BeginImmediateDraw();
1561         myMainPM->Unhighlight (anObj, myDisplayMode);
1562         myMainPM->EndImmediateDraw (myMainVwr);
1563       }
1564       if (aStatus->IsSubIntensityOn())
1565       {
1566         myMainPM->Color (anObj, mySubIntensity, theMode);
1567       }
1568       myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1569     }
1570   }
1571
1572   myDisplayMode = theMode;
1573   if (theToUpdateViewer)
1574   {
1575     myMainVwr->Update();
1576   }
1577 }
1578
1579 //=======================================================================
1580 //function : SetDisplayMode
1581 //purpose  :
1582 //=======================================================================
1583 void AIS_InteractiveContext::SetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1584                                              const Standard_Integer               theMode,
1585                                              const Standard_Boolean               theToUpdateViewer)
1586 {
1587   if (!theIObj->HasInteractiveContext())
1588   {
1589     theIObj->SetContext(this);
1590   }
1591
1592   if (!myObjects.IsBound (theIObj))
1593   {
1594     theIObj->SetDisplayMode (theMode);
1595     return;
1596   }
1597   else if (!theIObj->AcceptDisplayMode (theMode))
1598   {
1599     return;
1600   }
1601
1602   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
1603   if (aStatus->GraphicStatus() != AIS_DS_Displayed)
1604   {
1605     theIObj->SetDisplayMode (theMode);
1606     return;
1607   }
1608
1609   // erase presentations for all display modes different from <aMode>
1610   TColStd_ListOfInteger aModesToRemove;
1611   for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
1612   {
1613     const Standard_Integer anOldMode = aDispModeIter.Value();
1614     if (anOldMode != theMode)
1615     {
1616       aModesToRemove.Append (anOldMode);
1617       if (myMainPM->IsHighlighted (theIObj, anOldMode))
1618       {
1619         myMainPM->Unhighlight (theIObj, anOldMode);
1620       }
1621       myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1622     }
1623   }
1624
1625   for (TColStd_ListIteratorOfListOfInteger aRemModeIter (aModesToRemove); aRemModeIter.More(); aRemModeIter.Next())
1626   {
1627     aStatus->RemoveDisplayMode (aRemModeIter.Value());
1628   }
1629
1630   if (!aStatus->IsDModeIn (theMode))
1631   {
1632     aStatus->AddDisplayMode (theMode);
1633   }
1634
1635   myMainPM->Display (theIObj, theMode);
1636   Standard_Integer aDispMode, aHiMode, aSelMode;
1637   GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1638   if (aStatus->IsHilighted())
1639   {
1640     myMainPM->Highlight (theIObj, aHiMode);
1641   }
1642   if (aStatus->IsSubIntensityOn())
1643   {
1644     myMainPM->Color (theIObj, mySubIntensity, theMode);
1645   }
1646
1647   if (theToUpdateViewer)
1648   {
1649     myMainVwr->Update();
1650   }
1651   theIObj->SetDisplayMode (theMode);
1652 }
1653
1654 //=======================================================================
1655 //function : UnsetDisplayMode
1656 //purpose  :
1657 //=======================================================================
1658 void AIS_InteractiveContext::UnsetDisplayMode (const Handle(AIS_InteractiveObject)& theIObj,
1659                                                const Standard_Boolean               theToUpdateViewer)
1660 {
1661   if (theIObj.IsNull()
1662   || !theIObj->HasDisplayMode())
1663   {
1664     return;
1665   }
1666
1667   if (!myObjects.IsBound (theIObj))
1668   {
1669     theIObj->UnsetDisplayMode();
1670     return;
1671   }
1672
1673   const Standard_Integer anOldMode = theIObj->DisplayMode();
1674   if (myDisplayMode == anOldMode)
1675   {
1676     return;
1677   }
1678
1679   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
1680   aStatus->RemoveDisplayMode (anOldMode);
1681   if (!aStatus->IsDModeIn(myDisplayMode))
1682   {
1683     aStatus->AddDisplayMode (myDisplayMode);
1684   }
1685
1686   if (aStatus->GraphicStatus() == AIS_DS_Displayed)
1687   {
1688     if (myMainPM->IsHighlighted (theIObj, anOldMode))
1689     {
1690       myMainPM->Unhighlight (theIObj, anOldMode);
1691     }
1692     myMainPM->SetVisibility (theIObj, anOldMode, Standard_False);
1693     myMainPM->Display (theIObj, myDisplayMode);
1694
1695     Standard_Integer aDispMode, aHiMode, aSelMode;
1696     GetDefModes (theIObj, aDispMode, aHiMode, aSelMode);
1697     if (aStatus->IsHilighted())
1698     {
1699       myMainPM->Highlight (theIObj, aHiMode);
1700     }
1701     if (aStatus->IsSubIntensityOn())
1702     {
1703       myMainPM->Color (theIObj, mySubIntensity, myDisplayMode);
1704     }
1705
1706     if (theToUpdateViewer)
1707     {
1708       myMainVwr->Update();
1709     }
1710   }
1711
1712   theIObj->UnsetDisplayMode();
1713 }
1714
1715 //=======================================================================
1716 //function : SetCurrentFacingModel
1717 //purpose  :
1718 //=======================================================================
1719 void AIS_InteractiveContext::SetCurrentFacingModel (const Handle(AIS_InteractiveObject)& theIObj,
1720                                                     const Aspect_TypeOfFacingModel       theModel)
1721 {
1722   if (!theIObj.IsNull())
1723   {
1724     theIObj->SetCurrentFacingModel (theModel);
1725   }
1726 }
1727
1728 //=======================================================================
1729 //function : redisplayPrsRecModes
1730 //purpose  :
1731 //=======================================================================
1732 void AIS_InteractiveContext::redisplayPrsRecModes (const Handle(AIS_InteractiveObject)& theIObj,
1733                                                    const Standard_Boolean               theToUpdateViewer)
1734 {
1735   if (theIObj->RecomputeEveryPrs())
1736   {
1737     theIObj->Update (Standard_True);
1738     theIObj->UpdateSelection();
1739   }
1740   else
1741   {
1742     for (TColStd_ListIteratorOfListOfInteger aModes (theIObj->ListOfRecomputeModes()); aModes.More(); aModes.Next())
1743     {
1744       theIObj->Update (aModes.Value(), Standard_False);
1745     }
1746     theIObj->UpdateSelection();
1747     theIObj->SetRecomputeOk();
1748   }
1749
1750   if (theToUpdateViewer)
1751   {
1752     UpdateCurrentViewer();
1753   }
1754 }
1755
1756 //=======================================================================
1757 //function : redisplayPrsModes
1758 //purpose  :
1759 //=======================================================================
1760 void AIS_InteractiveContext::redisplayPrsModes (const Handle(AIS_InteractiveObject)& theIObj,
1761                                                 const Standard_Boolean               theToUpdateViewer)
1762 {
1763   if (theIObj->RecomputeEveryPrs())
1764   {
1765     theIObj->Update (Standard_True);
1766     theIObj->UpdateSelection();
1767   }
1768   else
1769   {
1770     TColStd_ListOfInteger aModes;
1771     theIObj->ToBeUpdated (aModes);
1772     for (TColStd_ListIteratorOfListOfInteger aModeIter (aModes); aModeIter.More(); aModeIter.Next())
1773     {
1774       theIObj->Update (aModeIter.Value(), Standard_False);
1775     }
1776     theIObj->SetRecomputeOk();
1777   }
1778
1779   if (theToUpdateViewer)
1780   {
1781     UpdateCurrentViewer();
1782   }
1783 }
1784
1785 //=======================================================================
1786 //function : SetColor
1787 //purpose  :
1788 //=======================================================================
1789 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1790                                        const Quantity_NameOfColor           theColor,
1791                                        const Standard_Boolean               theToUpdateViewer)
1792 {
1793   SetColor (theIObj, Quantity_Color(theColor), theToUpdateViewer);
1794 }
1795
1796 //=======================================================================
1797 //function : SetColor
1798 //purpose  :
1799 //=======================================================================
1800 void AIS_InteractiveContext::SetColor (const Handle(AIS_InteractiveObject)& theIObj,
1801                                        const Quantity_Color&                theColor,
1802                                        const Standard_Boolean               theToUpdateViewer)
1803 {
1804   if (theIObj.IsNull())
1805   {
1806     return;
1807   }
1808
1809   if (!theIObj->HasInteractiveContext())
1810   {
1811     theIObj->SetContext (this);
1812   }
1813   theIObj->SetColor (theColor);
1814   redisplayPrsRecModes (theIObj, theToUpdateViewer);
1815 }
1816
1817 //=======================================================================
1818 //function : SetIsoOnTriangulation
1819 //purpose  :
1820 //=======================================================================
1821 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theIsEnabled,
1822                                                  const Handle(AIS_InteractiveObject)& theObject)
1823 {
1824   if (theObject.IsNull())
1825   {
1826     return;
1827   }
1828
1829   theObject->SetIsoOnTriangulation (theIsEnabled);
1830 }
1831
1832 //=======================================================================
1833 //function : SetDeviationCoefficient
1834 //purpose  :
1835 //=======================================================================
1836 void AIS_InteractiveContext::SetDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1837                                                       const Standard_Real                  theCoefficient,
1838                                                       const Standard_Boolean               theToUpdateViewer)
1839 {
1840   if (theIObj.IsNull())
1841   {
1842     return;
1843   }
1844
1845   if (!theIObj->HasInteractiveContext())
1846   {
1847     theIObj->SetContext (this);
1848   }
1849
1850   // to be modified after the related methods of AIS_Shape are passed to InteractiveObject
1851   if (theIObj->Type() != AIS_KOI_Object
1852    && theIObj->Type() != AIS_KOI_Shape)
1853   {
1854     return;
1855   }
1856   else if (theIObj->Signature() != 0)
1857   {
1858     return;
1859   }
1860
1861   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1862   aShape->SetOwnDeviationCoefficient (theCoefficient);
1863   redisplayPrsModes (theIObj, theToUpdateViewer);
1864 }
1865
1866 //=======================================================================
1867 //function : SetHLRDeviationCoefficient
1868 //purpose  :
1869 //=======================================================================
1870 void AIS_InteractiveContext::SetHLRDeviationCoefficient (const Handle(AIS_InteractiveObject)& theIObj,
1871                                                          const Standard_Real                  theCoefficient,
1872                                                          const Standard_Boolean               theToUpdateViewer)
1873 {
1874   if (theIObj.IsNull())
1875   {
1876     return;
1877   }
1878
1879   if (!theIObj->HasInteractiveContext())
1880   {
1881     theIObj->SetContext (this);
1882   }
1883  
1884   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1885   if (theIObj->Type() != AIS_KOI_Object
1886    && theIObj->Type() != AIS_KOI_Shape)
1887   {
1888     return;
1889   }
1890   else if (theIObj->Signature() != 0)
1891   {
1892     return;
1893   }
1894
1895   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1896   aShape->SetOwnHLRDeviationCoefficient (theCoefficient);
1897   redisplayPrsModes (theIObj, theToUpdateViewer);
1898 }
1899
1900 //=======================================================================
1901 //function : SetDeviationAngle
1902 //purpose  :
1903 //=======================================================================
1904 void AIS_InteractiveContext::SetDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
1905                                                 const Standard_Real                  theAngle,
1906                                                 const Standard_Boolean               theToUpdateViewer)
1907 {
1908   if (theIObj.IsNull())
1909   {
1910     return;
1911   }
1912
1913   if (!theIObj->HasInteractiveContext())
1914   {
1915     theIObj->SetContext (this);
1916   }
1917  
1918   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1919   if (theIObj->Type() != AIS_KOI_Shape)
1920   {
1921     return;
1922   }
1923   else if (theIObj->Signature() != 0)
1924   {
1925     return;
1926   }
1927
1928   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1929   aShape->SetOwnDeviationAngle (theAngle);
1930   redisplayPrsModes (theIObj, theToUpdateViewer);
1931 }
1932
1933 //=======================================================================
1934 //function : SetAngleAndDeviation
1935 //purpose  :
1936 //=======================================================================
1937 void AIS_InteractiveContext::SetAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1938                                                    const Standard_Real                  theAngle,
1939                                                    const Standard_Boolean               theToUpdateViewer)
1940 {
1941   if (theIObj.IsNull())
1942   {
1943     return;
1944   }
1945
1946   if (!theIObj->HasInteractiveContext())
1947   {
1948     theIObj->SetContext (this);
1949   }
1950
1951   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1952   if (theIObj->Type() != AIS_KOI_Shape)
1953   {
1954     return;
1955   }
1956   if (theIObj->Signature() != 0)
1957   {
1958     return;
1959   }
1960
1961   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
1962   aShape->SetAngleAndDeviation (theAngle);
1963
1964   if (theIObj->RecomputeEveryPrs())
1965   {
1966     theIObj->Update (Standard_True);
1967     theIObj->UpdateSelection();
1968   }
1969   else
1970   {
1971     Update (theIObj, theToUpdateViewer);
1972   }
1973 }
1974
1975 //=======================================================================
1976 //function : SetHLRAngleAndDeviation
1977 //purpose  :
1978 //=======================================================================
1979 void AIS_InteractiveContext::SetHLRAngleAndDeviation (const Handle(AIS_InteractiveObject)& theIObj,
1980                                                       const Standard_Real                  theAngle,
1981                                                       const Standard_Boolean               theToUpdateViewer)
1982 {
1983   if (theIObj.IsNull())
1984   {
1985     return;
1986   }
1987
1988   if (!theIObj->HasInteractiveContext())
1989   {
1990     theIObj->SetContext (this);
1991   }
1992
1993   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1994   if (theIObj->Type() != AIS_KOI_Shape)
1995   {
1996     return;
1997   }
1998   if (theIObj->Signature() != 0)
1999   {
2000     return;
2001   }
2002   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2003   aShape->SetHLRAngleAndDeviation (theAngle);
2004   redisplayPrsModes (theIObj, theToUpdateViewer);
2005 }
2006
2007 //=======================================================================
2008 //function : SetHLRDeviationAngle
2009 //purpose  :
2010 //=======================================================================
2011 void AIS_InteractiveContext::SetHLRDeviationAngle (const Handle(AIS_InteractiveObject)& theIObj,
2012                                                    const Standard_Real                  theAngle,
2013                                                    const Standard_Boolean               theToUpdateViewer)
2014 {
2015   if (theIObj.IsNull())
2016   {
2017     return;
2018   }
2019
2020   if (!theIObj->HasInteractiveContext())
2021   {
2022     theIObj->SetContext (this);
2023   }
2024
2025   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
2026   if (theIObj->Type() != AIS_KOI_Shape)
2027   {
2028     return;
2029   }
2030   if (theIObj->Signature() != 0)
2031   {
2032     return;
2033   }
2034   Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (theIObj);
2035   aShape->SetOwnHLRDeviationAngle (theAngle);
2036   redisplayPrsModes (theIObj, theToUpdateViewer);
2037 }
2038
2039 //=======================================================================
2040 //function : UnsetColor
2041 //purpose  :
2042 //=======================================================================
2043 void AIS_InteractiveContext::UnsetColor (const Handle(AIS_InteractiveObject)& theIObj,
2044                                          const Standard_Boolean               theToUpdateViewer)
2045 {
2046   if (theIObj.IsNull())
2047   {
2048     return;
2049   }
2050
2051   theIObj->UnsetColor();
2052   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2053 }
2054
2055 //=======================================================================
2056 //function : HasColor
2057 //purpose  :
2058 //=======================================================================
2059 Standard_Boolean AIS_InteractiveContext::HasColor (const Handle(AIS_InteractiveObject)& theIObj) const
2060 {
2061   return theIObj->HasColor();
2062 }
2063
2064 //=======================================================================
2065 //function : Color
2066 //purpose  :
2067 //=======================================================================
2068 Quantity_NameOfColor AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj) const
2069 {
2070   return theIObj->Color();
2071 }
2072
2073 //=======================================================================
2074 //function : Color
2075 //purpose  :
2076 //=======================================================================
2077 void AIS_InteractiveContext::Color (const Handle(AIS_InteractiveObject)& theIObj,
2078                                     Quantity_Color&                      theColor) const
2079 {
2080   theIObj->Color (theColor);
2081 }
2082
2083 //=======================================================================
2084 //function : Width
2085 //purpose  :
2086 //=======================================================================
2087 Standard_Real AIS_InteractiveContext::Width (const Handle(AIS_InteractiveObject)& theIObj) const
2088 {
2089   return theIObj->Width();
2090 }
2091
2092 //=======================================================================
2093 //function : SetWidth
2094 //purpose  :
2095 //=======================================================================
2096 void AIS_InteractiveContext::SetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2097                                        const Standard_Real                  theWidth,
2098                                        const Standard_Boolean               theToUpdateViewer)
2099 {
2100   if (theIObj.IsNull())
2101   {
2102     return;
2103   }
2104
2105   if (!theIObj->HasInteractiveContext())
2106   {
2107     theIObj->SetContext (this);
2108   }
2109
2110   theIObj->SetWidth (theWidth);
2111   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2112   if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2113   {
2114     if (myLastinMain->IsAutoHilight())
2115     {
2116       const Standard_Integer aHiMode =
2117         theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2118       myLastinMain->HilightWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, aHiMode);
2119     }
2120     else
2121     {
2122       theIObj->HilightOwnerWithColor (myMainPM, myLastinMain->IsSelected() ? mySelectionColor : myHilightColor, myLastinMain);
2123     }
2124   }
2125 }
2126
2127 //=======================================================================
2128 //function : UnsetWidth
2129 //purpose  :
2130 //=======================================================================
2131 void AIS_InteractiveContext::UnsetWidth (const Handle(AIS_InteractiveObject)& theIObj,
2132                                          const Standard_Boolean               theToUpdateViewer)
2133 {
2134   if (theIObj.IsNull())
2135   {
2136     return;
2137   }
2138
2139   theIObj->UnsetWidth();
2140   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2141 }
2142
2143 //=======================================================================
2144 //function : SetMaterial
2145 //purpose  :
2146 //=======================================================================
2147 void AIS_InteractiveContext::SetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2148                                           const Graphic3d_NameOfMaterial       theName,
2149                                           const Standard_Boolean               theToUpdateViewer)
2150 {
2151   if (theIObj.IsNull())
2152   {
2153     return;
2154   }
2155
2156   if (!theIObj->HasInteractiveContext())
2157   {
2158     theIObj->SetContext (this);
2159   }
2160
2161   theIObj->SetMaterial (theName);
2162   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2163 }
2164
2165 //=======================================================================
2166 //function : UnsetMaterial
2167 //purpose  :
2168 //=======================================================================
2169 void AIS_InteractiveContext::UnsetMaterial (const Handle(AIS_InteractiveObject)& theIObj,
2170                                             const Standard_Boolean               theToUpdateViewer)
2171 {
2172   if (theIObj.IsNull())
2173   {
2174     return;
2175   }
2176   theIObj->UnsetMaterial();
2177   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2178 }
2179
2180 //=======================================================================
2181 //function : SetTransparency
2182 //purpose  :
2183 //=======================================================================
2184 void AIS_InteractiveContext::SetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2185                                               const Standard_Real                  theValue,
2186                                               const Standard_Boolean               theToUpdateViewer)
2187 {
2188   if (theIObj.IsNull())
2189   {
2190     return;
2191   }
2192
2193   if (!theIObj->HasInteractiveContext())
2194   {
2195     theIObj->SetContext (this);
2196   }
2197
2198   if (!theIObj->IsTransparent()
2199     && theValue <= 0.05)
2200   {
2201     return;
2202   }
2203
2204   if (theValue <= 0.05)
2205   {
2206     UnsetTransparency (theIObj, theToUpdateViewer);
2207     return;
2208   }
2209
2210   theIObj->SetTransparency (theValue);
2211   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2212 }
2213
2214 //=======================================================================
2215 //function : UnsetTransparency
2216 //purpose  :
2217 //=======================================================================
2218 void AIS_InteractiveContext::UnsetTransparency (const Handle(AIS_InteractiveObject)& theIObj,
2219                                                 const Standard_Boolean               theToUpdateViewer)
2220 {
2221   if (theIObj.IsNull())
2222   {
2223     return;
2224   }
2225
2226   theIObj->UnsetTransparency();
2227   redisplayPrsRecModes (theIObj, theToUpdateViewer);
2228 }
2229
2230 //=======================================================================
2231 //function : SetSelectedAspect
2232 //purpose  :
2233 //=======================================================================
2234 void AIS_InteractiveContext::SetSelectedAspect (const Handle(Prs3d_BasicAspect)& theAspect,
2235                                                 const Standard_Boolean ,
2236                                                 const Standard_Boolean           theToUpdateViewer)
2237 {
2238   if (HasOpenedContext())
2239   {
2240     return;
2241   }
2242
2243   Standard_Boolean isFound = Standard_False;
2244   for (mySelection->Init(); mySelection->More(); mySelection->Next())
2245   {
2246     isFound = Standard_True;
2247     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (mySelection->Value());
2248     anObj->SetAspect (theAspect);
2249   }
2250
2251   if (isFound && theToUpdateViewer)
2252   {
2253     myMainVwr->Update();
2254   }
2255 }
2256
2257 //=======================================================================
2258 //function : SetLocalAttributes
2259 //purpose  :
2260 //=======================================================================
2261 void AIS_InteractiveContext::SetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2262                                                  const Handle(Prs3d_Drawer)&          theDrawer,
2263                                                  const Standard_Boolean               theToUpdateViewer)
2264 {
2265   if (theIObj.IsNull())
2266   {
2267     return;
2268   }
2269
2270   if (!theIObj->HasInteractiveContext())
2271   {
2272     theIObj->SetContext (this);
2273   }
2274
2275   theIObj->SetAttributes (theDrawer);
2276   Update (theIObj, theToUpdateViewer);
2277 }
2278
2279 //=======================================================================
2280 //function : UnsetLocalAttributes
2281 //purpose  :
2282 //=======================================================================
2283 void AIS_InteractiveContext::UnsetLocalAttributes (const Handle(AIS_InteractiveObject)& theIObj,
2284                                                    const Standard_Boolean               theToUpdateViewer)
2285 {
2286   if (theIObj.IsNull())
2287   {
2288     return;
2289   }
2290
2291   if (!theIObj->HasInteractiveContext())
2292   {
2293     theIObj->SetContext (this);
2294   }
2295   theIObj->UnsetAttributes();
2296   Update (theIObj, theToUpdateViewer);
2297 }
2298
2299 //=======================================================================
2300 //function : Status
2301 //purpose  :
2302 //=======================================================================
2303 void AIS_InteractiveContext::Status (const Handle(AIS_InteractiveObject)& theIObj,
2304                                      TCollection_ExtendedString&          theStatus) const
2305 {
2306   theStatus = "";
2307   if (theIObj.IsNull()
2308   || !myObjects.IsBound (theIObj))
2309   {
2310     return;
2311   }
2312
2313   theStatus += "\t ____________________________________________";
2314   theStatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2315   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2316   switch (aStatus->GraphicStatus())
2317   {
2318     case AIS_DS_Displayed:
2319     {
2320       theStatus += "\t| -->Displayed\n";
2321       break;
2322     }
2323     case AIS_DS_Erased:
2324     {
2325       theStatus += "\t| -->Erased\n";
2326       break;
2327     }
2328     default:
2329       break;
2330   }
2331
2332   theStatus += "\t| Active Display Modes in the MainViewer :\n";
2333   for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2334   {
2335     theStatus += "\t|\t Mode ";
2336     theStatus += TCollection_AsciiString (aDispModeIter.Value());
2337     theStatus += "\n";
2338   }
2339   if (IsSelected(theIObj)) theStatus +="\t| Selected\n";
2340
2341   theStatus += "\t| Active Selection Modes in the MainViewer :\n";
2342   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2343   {
2344     theStatus += "\t\t Mode ";
2345     theStatus += TCollection_AsciiString (aSelModeIter.Value());
2346     theStatus += "\n";
2347   }
2348   theStatus += "\t ____________________________________________";
2349 }
2350
2351 //=======================================================================
2352 //function : GetDefModes
2353 //purpose  :
2354 //=======================================================================
2355 void AIS_InteractiveContext::GetDefModes (const Handle(AIS_InteractiveObject)& theIObj,
2356                                           Standard_Integer&                    theDispMode,
2357                                           Standard_Integer&                    theHiMode,
2358                                           Standard_Integer&                    theSelMode) const
2359 {
2360   if (theIObj.IsNull())
2361   {
2362     return;
2363   }
2364
2365   theDispMode = theIObj->HasDisplayMode()
2366               ? theIObj->DisplayMode()
2367               : (theIObj->AcceptDisplayMode (myDisplayMode)
2368                ? myDisplayMode
2369                : 0);
2370   theHiMode  = theIObj->HasHilightMode()   ? theIObj->HilightMode()   : theDispMode;
2371   theSelMode = theIObj->GlobalSelectionMode();
2372 }
2373
2374 //=======================================================================
2375 //function : EraseGlobal
2376 //purpose  :
2377 //=======================================================================
2378 void AIS_InteractiveContext::EraseGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2379                                           const Standard_Boolean               theToUpdateviewer)
2380 {
2381   if (theIObj.IsNull()
2382   || !myObjects.IsBound (theIObj))
2383   {
2384     return;
2385   }
2386
2387   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2388
2389   const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2390   if (aStatus->GraphicStatus() == AIS_DS_Temporary
2391    || aStatus->GraphicStatus() == AIS_DS_Erased)
2392   {
2393     return;
2394   }
2395
2396   for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2397   {
2398     if (aStatus->IsHilighted())
2399     {
2400       if (IsCurrent (theIObj))
2401       {
2402         AddOrRemoveCurrentObject (theIObj, Standard_False);
2403       }
2404       else if (myMainPM->IsHighlighted (theIObj, aDispModeIter.Value()))
2405       {
2406         myMainPM->Unhighlight (theIObj, aDispModeIter.Value());
2407       }
2408     }
2409
2410     myMainPM->SetVisibility (theIObj, aDispModeIter.Value(), Standard_False);
2411   }
2412
2413   if (aStatus->IsHilighted()
2414    && theIObj->HasHilightMode())
2415   {
2416     myMainPM->Unhighlight (theIObj, aDispMode);
2417   }
2418
2419   if (!myLastPicked.IsNull()
2420     && myLastPicked->Selectable() == theIObj)
2421   {
2422     myMainPM->ClearImmediateDraw();
2423   }
2424
2425   if (IsSelected (theIObj)
2426   && !aStatus->IsDModeIn (aDispMode))
2427   {
2428     myMainPM->SetVisibility (theIObj, aDispMode, Standard_False);
2429   }
2430
2431   for (TColStd_ListIteratorOfListOfInteger aSelModeIter (aStatus->SelectionModes()); aSelModeIter.More(); aSelModeIter.Next())
2432   {
2433     mgrSelector->Deactivate (theIObj, aSelModeIter.Value(), myMainSel);
2434   }
2435   aStatus->ClearSelectionModes();
2436   aStatus->SetGraphicStatus (AIS_DS_Erased);
2437
2438   if (theToUpdateviewer)
2439   {
2440     myMainVwr->Update();
2441   }
2442 }
2443
2444 //=======================================================================
2445 //function : unhighlightOwners
2446 //purpose  :
2447 //=======================================================================
2448 void AIS_InteractiveContext::unhighlightOwners (const Handle(AIS_InteractiveObject)& theObject)
2449 {
2450   mySelection->Init();
2451   while (mySelection->More())
2452   {
2453     const Handle(SelectMgr_EntityOwner) anOwner =
2454       Handle(SelectMgr_EntityOwner)::DownCast (mySelection->Value());
2455     if (anOwner->Selectable() == theObject)
2456     {
2457       if (anOwner->IsSelected())
2458       {
2459         AddOrRemoveSelected (anOwner, Standard_False);
2460         mySelection->Init();
2461         continue;
2462       }
2463     }
2464     mySelection->Next();
2465   }
2466 }
2467
2468 //=======================================================================
2469 //function : ClearGlobal
2470 //purpose  :
2471 //=======================================================================
2472 void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& theIObj,
2473                                           const Standard_Boolean               theToUpdateviewer)
2474 {
2475   if (theIObj.IsNull()
2476   || !myObjects.IsBound (theIObj))
2477   {
2478     // for cases when reference shape of connected interactives was not displayed
2479     // but its selection primitives were calculated
2480     const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2481     mgrSelector->Remove (anObj);
2482     return;
2483   }
2484
2485   Handle(AIS_GlobalStatus) aStatus = myObjects (theIObj);
2486   unhighlightOwners (theIObj);
2487   for (TColStd_ListIteratorOfListOfInteger aDispModeIter (aStatus->DisplayedModes()); aDispModeIter.More(); aDispModeIter.Next())
2488   {
2489     myMainPM->Erase (theIObj, aDispModeIter.Value());
2490     myMainPM->Clear (theIObj, aDispModeIter.Value());
2491   }
2492
2493   if (aStatus->IsHilighted()
2494    && theIObj->HasHilightMode())
2495   {
2496     myMainPM->Unhighlight (theIObj, theIObj->HilightMode());
2497   }
2498
2499   // Object removes from Detected sequence
2500   for(Standard_Integer aDetIter = 1; aDetIter < myAISDetectedSeq.Length(); ++aDetIter)
2501   {
2502     Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2503     if (!anObj.IsNull()
2504       && anObj != theIObj)
2505     {
2506       myAISDetectedSeq.Remove (aDetIter);
2507     }
2508   }
2509
2510   // remove IO from the selection manager to avoid memory leaks
2511   const Handle(SelectMgr_SelectableObject)& anObj = theIObj; // to avoid ambiguity
2512   mgrSelector->Remove (anObj);
2513
2514   myObjects.UnBind (theIObj);
2515   myMainVwr->StructureManager()->UnregisterObject (theIObj);
2516   for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews())
2517   {
2518     myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get());
2519   }
2520
2521   if (!myLastinMain.IsNull() && myLastinMain->Selectable() == theIObj)
2522     myLastinMain.Nullify();
2523   if (!myLastPicked.IsNull() && myLastPicked->Selectable() == theIObj)
2524     myLastPicked.Nullify();
2525   myMainPM->ClearImmediateDraw();
2526
2527   if (theToUpdateviewer && aStatus->GraphicStatus() == AIS_DS_Displayed)
2528   {
2529     myMainVwr->Update();
2530   }
2531 }
2532
2533 //=======================================================================
2534 //function : ClearGlobalPrs
2535 //purpose  :
2536 //=======================================================================
2537 void AIS_InteractiveContext::ClearGlobalPrs (const Handle(AIS_InteractiveObject)& theIObj,
2538                                              const Standard_Integer               theMode,
2539                                              const Standard_Boolean               theToUpdateViewer)
2540 {
2541   if (theIObj.IsNull()
2542   || !myObjects.IsBound (theIObj))
2543   {
2544     return;
2545   }
2546
2547   const Handle(AIS_GlobalStatus)& aStatus = myObjects (theIObj);
2548   if (aStatus->IsDModeIn (theMode))
2549   {
2550     const Standard_Integer aDispMode = theIObj->HasHilightMode() ? theIObj->HilightMode() : 0;
2551     if (aDispMode == theMode
2552      && myMainPM->IsHighlighted (theIObj, theMode))
2553     {
2554       myMainPM->Unhighlight (theIObj, theMode);
2555     }
2556
2557     myMainPM->Erase (theIObj, theMode);
2558     myMainPM->Clear (theIObj, theMode);
2559   }
2560
2561   if (aStatus->GraphicStatus() == AIS_DS_Displayed
2562    && theToUpdateViewer)
2563   {
2564     myMainVwr->Update();
2565   }
2566 }
2567
2568 //=======================================================================
2569 //function : DrawHiddenLine
2570 //purpose  :
2571 //=======================================================================
2572 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine() const
2573 {
2574   return myDefaultDrawer->DrawHiddenLine();
2575 }
2576
2577 //=======================================================================
2578 //function : EnableDrawHiddenLine
2579 //purpose  :
2580 //=======================================================================
2581 void AIS_InteractiveContext::EnableDrawHiddenLine() const
2582 {
2583   myDefaultDrawer->EnableDrawHiddenLine();
2584 }
2585
2586 //=======================================================================
2587 //function : DisableDrawHiddenLine 
2588 //purpose  :
2589 //=======================================================================
2590 void AIS_InteractiveContext::DisableDrawHiddenLine() const
2591 {
2592   myDefaultDrawer->DisableDrawHiddenLine();
2593 }
2594
2595 //=======================================================================
2596 //function : HiddenLineAspect
2597 //purpose  :
2598 //=======================================================================
2599 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect() const
2600 {
2601   return myDefaultDrawer->HiddenLineAspect();
2602 }
2603
2604 //=======================================================================
2605 //function : SetHiddenLineAspect
2606 //purpose  :
2607 //=======================================================================
2608 void AIS_InteractiveContext::SetHiddenLineAspect (const Handle(Prs3d_LineAspect)& theAspect) const
2609 {
2610   myDefaultDrawer->SetHiddenLineAspect (theAspect);
2611 }
2612
2613 //=======================================================================
2614 //function : SetIsoNumber
2615 //purpose  :
2616 //=======================================================================
2617 void AIS_InteractiveContext::SetIsoNumber (const Standard_Integer theNb,
2618                                            const AIS_TypeOfIso    theType)
2619 {
2620   switch (theType)
2621   {
2622     case AIS_TOI_IsoU:
2623       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2624       break;
2625     case AIS_TOI_IsoV:
2626       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2627       break;
2628     case AIS_TOI_Both:
2629       myDefaultDrawer->UIsoAspect()->SetNumber (theNb);
2630       myDefaultDrawer->VIsoAspect()->SetNumber (theNb);
2631       break;
2632   }
2633 }
2634
2635 //=======================================================================
2636 //function : IsoNumber
2637 //purpose  :
2638 //=======================================================================
2639 Standard_Integer AIS_InteractiveContext::IsoNumber (const AIS_TypeOfIso theType)
2640 {
2641   switch (theType)
2642   {
2643     case AIS_TOI_IsoU: return myDefaultDrawer->UIsoAspect()->Number();
2644     case AIS_TOI_IsoV: return myDefaultDrawer->VIsoAspect()->Number();
2645     case AIS_TOI_Both: return myDefaultDrawer->UIsoAspect()->Number() == myDefaultDrawer->VIsoAspect()->Number()
2646                             ? myDefaultDrawer->UIsoAspect()->Number()
2647                             : -1;
2648   }
2649   return 0;
2650 }
2651
2652 //=======================================================================
2653 //function : IsoOnPlane
2654 //purpose  :
2655 //=======================================================================
2656 void AIS_InteractiveContext::IsoOnPlane (const Standard_Boolean theToSwitchOn)
2657 {
2658   myDefaultDrawer->SetIsoOnPlane (theToSwitchOn);
2659 }
2660
2661 //=======================================================================
2662 //function : IsoOnPlane
2663 //purpose  :
2664 //=======================================================================
2665 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const
2666 {
2667   return myDefaultDrawer->IsoOnPlane();
2668 }
2669
2670 //=======================================================================
2671 //function : IsoOnTriangulation
2672 //purpose  :
2673 //=======================================================================
2674 void AIS_InteractiveContext::IsoOnTriangulation (const Standard_Boolean theToSwitchOn)
2675 {
2676   myDefaultDrawer->SetIsoOnTriangulation (theToSwitchOn);
2677 }
2678
2679 //=======================================================================
2680 //function : IsoOnTriangulation
2681 //purpose  :
2682 //=======================================================================
2683 Standard_Boolean AIS_InteractiveContext::IsoOnTriangulation() const
2684 {
2685   return myDefaultDrawer->IsoOnTriangulation();
2686 }
2687
2688 //function : SetPixelTolerance
2689 //purpose  : Disables the mechanism of adaptive tolerance calculation in
2690 //           SelectMgr_ViewerSelector and sets the given tolerance for ALL
2691 //           sensitive entities activated. For more information, see
2692 //           SelectMgr_ViewerSelector.hxx
2693 //=======================================================================
2694 void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
2695 {
2696   if (HasOpenedContext())
2697   {
2698     myLocalContexts (myCurLocalIndex)->SetPixelTolerance (thePrecision);
2699   }
2700   else
2701   {
2702     myMainSel->SetPixelTolerance (thePrecision);
2703   }
2704 }
2705
2706 //=======================================================================
2707 //function : PixelTolerance
2708 //purpose  :
2709 //=======================================================================
2710 Standard_Integer AIS_InteractiveContext::PixelTolerance() const
2711 {
2712   return HasOpenedContext()
2713        ? myLocalContexts (myCurLocalIndex)->PixelTolerance()
2714        : myMainSel->PixelTolerance();
2715 }
2716
2717 //=======================================================================
2718 //function : SetSelectionSensitivity
2719 //purpose  : Allows to manage sensitivity of a particular selection of interactive object theObject
2720 //=======================================================================
2721 void AIS_InteractiveContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
2722                                                       const Standard_Integer theMode,
2723                                                       const Standard_Integer theNewSensitivity)
2724 {
2725   if (HasOpenedContext())
2726   {
2727     myLocalContexts (myCurLocalIndex)->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2728     return;
2729   }
2730
2731   mgrSelector->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
2732 }
2733
2734 //=======================================================================
2735 //function : IsInLocal
2736 //purpose  :
2737 //=======================================================================
2738 Standard_Boolean AIS_InteractiveContext::IsInLocal (const Handle(AIS_InteractiveObject)& theIObj,
2739                                                     Standard_Integer&                    theIndex) const
2740 {
2741   if (theIObj.IsNull())
2742   {
2743     return Standard_False;
2744   }
2745
2746   // if it exists at neutral point 0 index is returned
2747   if (myObjects.IsBound (theIObj))
2748   {
2749     theIndex = 0;
2750     return Standard_False;
2751   }
2752
2753   for (Standard_Integer aCtxIter = 1; aCtxIter <= myLocalContexts.Extent(); ++aCtxIter)
2754   {
2755     if (myLocalContexts.IsBound (aCtxIter))
2756     {
2757       if(myLocalContexts (aCtxIter)->IsIn (theIObj))
2758       {
2759         theIndex = aCtxIter;
2760         return Standard_True;
2761       }
2762     }
2763   }
2764   theIndex = -1;
2765   return Standard_False;
2766 }
2767
2768 //=======================================================================
2769 //function : InitAttributes
2770 //purpose  :
2771 //=======================================================================
2772 void AIS_InteractiveContext::InitAttributes()
2773 {
2774   mgrSelector->Add (myMainSel);
2775
2776   myDefaultDrawer->SetShadingAspectGlobal (Standard_False);
2777   Graphic3d_MaterialAspect aMat (Graphic3d_NOM_BRASS);
2778   myDefaultDrawer->ShadingAspect()->SetMaterial (aMat);
2779
2780 //  myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2781   Handle(Prs3d_LineAspect) aLineAspect = myDefaultDrawer->HiddenLineAspect();
2782   aLineAspect->SetColor      (Quantity_NOC_GRAY20);
2783   aLineAspect->SetWidth      (1.0);
2784   aLineAspect->SetTypeOfLine (Aspect_TOL_DASH);
2785
2786   // tolerance to 2 pixels...
2787   SetPixelTolerance (2);
2788
2789   // Customizing the drawer for trihedrons and planes...
2790   Handle(Prs3d_DatumAspect) aTrihAspect = myDefaultDrawer->DatumAspect();
2791   const Standard_Real aLength = 100.0;
2792   aTrihAspect->SetAxisLength (aLength, aLength, aLength);
2793   const Quantity_NameOfColor aColor = Quantity_NOC_LIGHTSTEELBLUE4;
2794   aTrihAspect->FirstAxisAspect() ->SetColor (aColor);
2795   aTrihAspect->SecondAxisAspect()->SetColor (aColor);
2796   aTrihAspect->ThirdAxisAspect() ->SetColor (aColor);
2797
2798   Handle(Prs3d_PlaneAspect) aPlaneAspect = myDefaultDrawer->PlaneAspect();
2799   const Standard_Real aPlaneLength = 200.0;
2800   aPlaneAspect->SetPlaneLength (aPlaneLength, aPlaneLength);
2801   aPlaneAspect->EdgesAspect()->SetColor (Quantity_NOC_SKYBLUE);
2802 }
2803
2804 //=======================================================================
2805 //function : TrihedronSize
2806 //purpose  :
2807 //=======================================================================
2808 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2809 {
2810   return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2811 }
2812
2813 //=======================================================================
2814 //function : SetTrihedronSize
2815 //purpose  :
2816 //=======================================================================
2817 void AIS_InteractiveContext::SetTrihedronSize (const Standard_Real    theVal,
2818                                                const Standard_Boolean /*updateviewer*/)
2819 {
2820   myDefaultDrawer->DatumAspect()->SetAxisLength (theVal, theVal, theVal);
2821   Redisplay (AIS_KOI_Datum, 3, Standard_False);
2822   Redisplay (AIS_KOI_Datum, 4, Standard_True);
2823 }
2824
2825 //=======================================================================
2826 //function : SetPlaneSize
2827 //purpose  :
2828 //=======================================================================
2829 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real    theValX,
2830                                           const Standard_Real    theValY,
2831                                           const Standard_Boolean /*updateviewer*/)
2832 {
2833   myDefaultDrawer->PlaneAspect()->SetPlaneLength (theValX, theValY);
2834   Redisplay (AIS_KOI_Datum, 7);
2835 }
2836
2837 //=======================================================================
2838 //function : SetPlaneSize
2839 //purpose  :
2840 //=======================================================================
2841 void AIS_InteractiveContext::SetPlaneSize (const Standard_Real    theVal,
2842                                            const Standard_Boolean theToUpdateViewer)
2843 {
2844   SetPlaneSize (theVal, theVal, theToUpdateViewer);
2845 }
2846
2847 //=======================================================================
2848 //function : PlaneSize
2849 //purpose  :
2850 //=======================================================================
2851 Standard_Boolean AIS_InteractiveContext::PlaneSize (Standard_Real& theX,
2852                                                     Standard_Real& theY) const
2853 {
2854   theX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2855   theY = myDefaultDrawer->PlaneAspect()->PlaneYLength();
2856   return (Abs (theX - theY) <= Precision::Confusion());
2857 }
2858
2859 //=======================================================================
2860 //function : SetAutoActivateSelection
2861 //purpose  :
2862 //=======================================================================
2863 void AIS_InteractiveContext::SetAutoActivateSelection (const Standard_Boolean theIsAuto)
2864 {
2865   myIsAutoActivateSelMode = theIsAuto;
2866 }
2867
2868 //=======================================================================
2869 //function : GetAutoActivateSelection
2870 //purpose  :
2871 //=======================================================================
2872 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2873 {
2874   return myIsAutoActivateSelMode;
2875 }
2876
2877 //=======================================================================
2878 //function : SetZLayer
2879 //purpose  :
2880 //=======================================================================
2881 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2882                                         const Standard_Integer theLayerId)
2883 {
2884   if (theIObj.IsNull())
2885     return;
2886
2887   theIObj->SetZLayer (theLayerId);
2888 }
2889
2890 //=======================================================================
2891 //function : GetZLayer
2892 //purpose  :
2893 //=======================================================================
2894 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2895 {
2896   return !theIObj.IsNull()
2897        ?  theIObj->ZLayer()
2898        :  Graphic3d_ZLayerId_UNKNOWN;
2899 }
2900
2901 //=======================================================================
2902 //function : RebuildSelectionStructs
2903 //purpose  : Rebuilds 1st level of BVH selection forcibly
2904 //=======================================================================
2905 void AIS_InteractiveContext::RebuildSelectionStructs()
2906 {
2907   myMainSel->RebuildObjectsTree (Standard_True);
2908 }
2909
2910 //=======================================================================
2911 //function : Disconnect
2912 //purpose  : Disconnects selectable object from an assembly and updates selection structures
2913 //=======================================================================
2914 void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
2915                                          const Handle(AIS_InteractiveObject)& theObjToDisconnect)
2916 {
2917   if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
2918   {
2919     Handle(AIS_MultipleConnectedInteractive) theObj (Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly));
2920     theObj->Disconnect (theObjToDisconnect);
2921     const Handle(SelectMgr_SelectableObject)& anObj = theObjToDisconnect; // to avoid ambiguity
2922     mgrSelector->Remove (anObj);
2923   }
2924   else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect.IsNull())
2925   {
2926     Handle(AIS_ConnectedInteractive) theObj (Handle(AIS_ConnectedInteractive)::DownCast (theAssembly));
2927     theObj->Disconnect();
2928     const Handle(SelectMgr_SelectableObject)& anObj = theObj; // to avoid ambiguity
2929     mgrSelector->Remove (anObj);
2930   }
2931   else
2932     return;
2933 }
2934
2935 //=======================================================================
2936 //function : FitSelected
2937 //purpose  : Fits the view corresponding to the bounds of selected objects
2938 //=======================================================================
2939 void AIS_InteractiveContext::FitSelected (const Handle(V3d_View)& theView,
2940                                           const Standard_Real theMargin,
2941                                           const Standard_Boolean theToUpdate)
2942 {
2943   const Handle(AIS_Selection)& aSelection = HasOpenedContext() ?
2944       myLocalContexts(myCurLocalIndex)->Selection() : mySelection;
2945
2946   Bnd_Box aBndSelected;
2947
2948   AIS_MapOfObjectOwners anObjectOwnerMap;
2949   for (aSelection->Init(); aSelection->More(); aSelection->Next())
2950   {
2951     Handle(AIS_InteractiveObject) anObj (Handle(AIS_InteractiveObject)::DownCast (aSelection->Value()));
2952     if (!anObj.IsNull())
2953     {
2954       if (anObj->IsInfinite())
2955         continue;
2956
2957       Bnd_Box aTmpBnd;
2958       anObj->BoundingBox (aTmpBnd);
2959       aBndSelected.Add (aTmpBnd);
2960     }
2961     else
2962     {
2963       Handle(SelectMgr_EntityOwner) anOwner (Handle(SelectMgr_EntityOwner)::DownCast (aSelection->Value()));
2964       if (anOwner.IsNull())
2965         continue;
2966
2967       Handle(SelectMgr_IndexedMapOfOwner) anOwnerMap;
2968       if (!anObjectOwnerMap.Find (anOwner->Selectable(), anOwnerMap))
2969       {
2970         anOwnerMap = new SelectMgr_IndexedMapOfOwner();
2971         anObjectOwnerMap.Bind (anOwner->Selectable(), anOwnerMap);
2972       }
2973
2974       anOwnerMap->Add (anOwner);
2975     }
2976   }
2977
2978   for (AIS_MapIteratorOfMapOfObjectOwners anIter (anObjectOwnerMap); anIter.More(); anIter.Next())
2979   {
2980     const Handle(SelectMgr_SelectableObject) anObject = anIter.Key();
2981     Bnd_Box aTmpBox = anObject->BndBoxOfSelected (anIter.ChangeValue());
2982     aBndSelected.Add (aTmpBox);
2983   }
2984
2985   anObjectOwnerMap.Clear();
2986
2987   if (aBndSelected.IsVoid())
2988     return;
2989
2990   theView->FitAll (aBndSelected, theMargin, theToUpdate);
2991 }