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