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