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