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