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