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