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