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