0025335: Visualization - method ::SelectedShape() in AIS_LocalContext and AIS_Interac...
[occt.git] / src / AIS / AIS_InteractiveContext_1.cxx
1 // Created on: 1997-01-29
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 #define UKI60826        //GG_161199     Use the requested selection color instead of default
18
19 #define IMP280200       //GG Don't returns a NULL shape in SelectedShape()
20 //                      method when the current selected is a shape !
21
22 #define BUC60814        //GG_300101     Idem UKI60826
23
24 #define OCC138          //VTN Avoding infinit loop in AddOrRemoveCurrentObject method.
25
26 #define OCC9657
27
28 #include <AIS_InteractiveContext.jxx>
29 #include <SelectMgr_EntityOwner.hxx>
30 #include <AIS_Selection.hxx>
31 #include <AIS_StatusOfDetection.hxx>
32 #include <AIS_StatusOfPick.hxx>
33
34 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
35 #include <AIS_LocalContext.hxx>
36 #include <AIS_GlobalStatus.hxx>
37 #include <AIS_Shape.hxx>
38
39 #include <Aspect_Grid.hxx>
40
41 #include <V3d_Light.hxx>
42 #include <V3d_PositionalLight.hxx>
43 #include <V3d_SpotLight.hxx>
44 #include <V3d_DirectionalLight.hxx>
45 #include <V3d_AmbientLight.hxx>
46
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <SelectMgr_Selection.hxx>
49 #include <SelectBasics_SensitiveEntity.hxx>
50
51 #include <Prs3d_Presentation.hxx>
52
53 #ifdef OCC9657
54 #include <AIS_MapOfInteractive.hxx>
55 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
56 #endif
57
58 //unused
59 /*#ifdef DEB
60 static void InfoOnLight(const Handle(V3d_View) aView)
61 {
62   Standard_Real V1=0.,V2=0.,V3=0.;
63   Standard_Integer IndexOfLit(0);
64   
65   static Standard_Boolean FirstTime (Standard_True);
66   if(FirstTime)
67     {
68       FirstTime = Standard_False;
69       for (aView->InitActiveLights();aView->MoreActiveLights();aView->NextActiveLights()){
70         IndexOfLit++;
71         cout<<"lumiere no "<<IndexOfLit<<"\n************\n\t";
72         Handle(V3d_Light) Li = aView->ActiveLight();
73         Quantity_NameOfColor Col;
74         Li->Color(Col);
75         cout<<"Color :"<<Standard_Integer(Col)<<"\n\t"<<endl;
76         cout<<"type :";
77         switch(Li->Type()){
78         case V3d_AMBIENT:
79           {
80             cout<<" AMBIENT\n\t";
81 //POP K4L
82 //          Handle(V3d_AmbientLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
83             cout<<"Position : X1 = "<<V1<<"  X2 = "<<V2<<"  X3 = "<<V3<<endl; 
84             break;
85           }
86         case V3d_DIRECTIONAL:
87           {
88             cout<<" DIRECTIONAL\n\t";
89             Handle(V3d_DirectionalLight)::DownCast(Li)->DisplayPosition(V1,V2,V3);
90             cout<<"Position : X1 = "<<V1<<"  X2 = "<<V2<<"  X3 = "<<V3<<endl; 
91             Handle(V3d_DirectionalLight)::DownCast(Li)->Direction(V1,V2,V3);
92             cout<<"Direction : V1 = "<<V1<<"  V2 = "<<V2<<"  V3 = "<<V3<<endl; 
93
94             break;
95           }
96         case V3d_POSITIONAL:
97           {
98             cout<<" POSITIONAL\n\t";
99             Handle(V3d_PositionalLight)::DownCast(Li)->Position(V1,V2,V3);
100             cout<<"Position : X1 = "<<V1<<"  X2 = "<<V2<<"  X3 = "<<V3<<endl; 
101             Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
102             cout<<"Target    : x1 = "<<V1<<"  x2 = "<<V2<<"  x3 = "<<V3<<endl; 
103             break;
104           }
105         case V3d_SPOT:
106           {
107             cout<<" SPOT\n\t";
108             cout<<" DIRECTIONAL\n\t";
109             Handle(V3d_SpotLight)::DownCast(Li)->Position(V1,V2,V3);
110             cout<<"Position : X1 = "<<V1<<"  X2 = "<<V2<<"  X3 = "<<V3<<endl; 
111             Handle(V3d_SpotLight)::DownCast(Li)->Direction(V1,V2,V3);
112             cout<<"Direction : V1 = "<<V1<<"  V2 = "<<V2<<"  V3 = "<<V3<<endl; 
113             Handle(V3d_PositionalLight)::DownCast(Li)->Target(V1,V2,V3);
114             cout<<"Target    : x1 = "<<V1<<"  x2 = "<<V2<<"  x3 = "<<V3<<endl; 
115             cout<<"\tAngle :"<<Handle(V3d_SpotLight)::DownCast(Li)->Angle()<<endl;
116             break;
117           }
118         }
119       }
120     }
121 }
122 #endif
123 */
124
125 //=======================================================================
126 //function : MoveTo
127 //purpose  :
128 //=======================================================================
129 AIS_StatusOfDetection AIS_InteractiveContext::MoveTo (const Standard_Integer  theXPix,
130                                                       const Standard_Integer  theYPix,
131                                                       const Handle(V3d_View)& theView,
132                                                       const Standard_Boolean  theToRedrawOnUpdate)
133 {
134   if (HasOpenedContext())
135   {
136     myWasLastMain = Standard_True;
137     return myLocalContexts (myCurLocalIndex)->MoveTo (theXPix, theYPix, theView, theToRedrawOnUpdate);
138   }
139
140   myAISCurDetected = 0;
141   myAISDetectedSeq.Clear();
142
143   if (theView->Viewer() != myMainVwr)
144   {
145     return AIS_SOD_Error;
146   }
147
148   // preliminaires
149   myLastPicked  = myLastinMain;
150   myWasLastMain = Standard_True;
151   AIS_StatusOfDetection aStatus        = AIS_SOD_Nothing;
152   Standard_Boolean      toUpdateViewer = Standard_False;
153
154   // allonzy
155   myMainSel->Pick (theXPix, theYPix, theView);
156
157   // filling of myAISDetectedSeq sequence storing information about detected AIS objects
158   // (the objects must be AIS_Shapes)
159   const Standard_Integer aDetectedNb = myMainSel->NbPicked();
160   for (Standard_Integer aDetIter = 1; aDetIter <= aDetectedNb; ++aDetIter)
161   {
162     Handle(SelectMgr_EntityOwner) anOwner = myMainSel->Picked (aDetIter);
163     if (anOwner.IsNull()
164      || !myFilters->IsOk (anOwner))
165     {
166       continue;
167     }
168
169     Handle(AIS_InteractiveObject) anObj = Handle(AIS_InteractiveObject)::DownCast (anOwner->Selectable());
170     if (!anObj.IsNull())
171     {
172       myAISDetectedSeq.Append (anObj);
173     }
174   }
175
176   myMainSel->Init();
177   if (myMainSel->More())
178   {
179     // does nothing if previously detected object is equal to the current one
180     if (myMainSel->OnePicked()->Selectable() == myLastPicked)
181     {
182       return myLastPicked->State() == 1
183            ? AIS_SOD_Selected
184            : AIS_SOD_OnlyOneDetected;
185     }
186  
187     // Previously detected object is unhilighted if it is not selected or hilighted 
188     // with selection color if it is selected. Such highlighting with selection color 
189     // is needed only if myToHilightSelected flag is true. In this case previously detected
190     // object has been already highlighted with myHilightColor during previous MoveTo() 
191     // method call. As result it is necessary to rehighligt it with mySelectionColor.
192     if (!myLastPicked.IsNull())
193     {
194       const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
195       if (myLastPicked->State() != 1)
196       {
197         myMainPM->Unhighlight (myLastPicked, aHiMod);
198         toUpdateViewer = Standard_True;
199       }
200       else if (myToHilightSelected)
201       {
202         myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
203         toUpdateViewer = Standard_True;
204       }
205     }
206
207     // initialize myLastPicked field with currently detected object
208     myLastPicked = Handle(AIS_InteractiveObject)::DownCast (myMainSel->OnePicked()->Selectable());
209     myLastinMain = myLastPicked;
210
211     // highlight detected object if it is not selected or myToHilightSelected flag is true
212     if (!myLastPicked.IsNull())
213     {
214       if (myLastPicked->State() != 1 || myToHilightSelected)
215       {
216         const Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
217         myMainPM->Color (myLastPicked, myHilightColor, aHiMod);
218         toUpdateViewer = Standard_True;
219       }
220
221       aStatus = myLastPicked->State() == 1
222               ? AIS_SOD_Selected
223               : AIS_SOD_OnlyOneDetected;
224     }
225   }
226   else 
227   {
228     // previously detected object is unhilighted if it is not selected or hilighted
229     // with selection color if it is selected
230     aStatus = AIS_SOD_Nothing;
231     if (!myLastPicked.IsNull())
232     {
233       Standard_Integer aHiMod = myLastPicked->HasHilightMode() ? myLastPicked->HilightMode() : 0;
234       if (myLastPicked->State() != 1)
235       {
236         myMainPM->Unhighlight (myLastPicked, aHiMod);
237         toUpdateViewer = Standard_True;
238       }
239       else if (myToHilightSelected)
240       {
241         myMainPM->Color (myLastPicked, mySelectionColor, aHiMod);
242         toUpdateViewer = Standard_True;
243       }
244     }
245
246     myLastinMain.Nullify();
247     myLastPicked.Nullify();
248   }
249
250   if (toUpdateViewer)
251   {
252     if (theToRedrawOnUpdate)
253     {
254       theView->Viewer()->Update();
255     }
256     else
257     {
258       theView->Viewer()->Invalidate();
259     }
260   }
261
262   mylastmoveview = theView;
263   return aStatus;
264 }
265
266 //=======================================================================
267 //function : Select
268 //purpose  : 
269 //=======================================================================
270 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Integer  theXPMin,
271                                                  const Standard_Integer  theYPMin,
272                                                  const Standard_Integer  theXPMax,
273                                                  const Standard_Integer  theYPMax,
274                                                  const Handle(V3d_View)& theView,
275                                                  const Standard_Boolean  toUpdateViewer)
276 {
277   // all objects detected by the selector are taken, previous current objects are emptied,
278   // new objects are put...
279
280   if (HasOpenedContext())
281   {
282     return myLocalContexts(myCurLocalIndex)->Select (theXPMin, theYPMin,
283                                                      theXPMax, theYPMax,
284                                                      theView, toUpdateViewer);
285   }
286
287   ClearCurrents (Standard_False);
288
289   Handle(StdSelect_ViewerSelector3d) aSelector;
290
291   if (theView->Viewer() == myMainVwr)
292   {
293     aSelector = myMainSel;
294     myWasLastMain = Standard_True;
295   }
296
297   aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
298   AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
299
300   AIS_MapOfInteractive anObjectsToSelect;
301   for (aSelector->Init(); aSelector->More(); aSelector->Next())
302   {
303     Handle(AIS_InteractiveObject) anObj = 
304       Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
305     if (!anObj.IsNull())
306     {
307       anObjectsToSelect.Add (anObj);
308     }
309   }
310
311   AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
312   for ( ; anIt.More(); anIt.Next())
313   {
314     AIS_Selection::Select (anIt.Key());
315     anIt.Key()->State (1);
316   }
317
318   HilightCurrents (toUpdateViewer);
319
320   Standard_Integer aSelNum = NbCurrents();
321
322   return (aSelNum == 0) ? AIS_SOP_NothingSelected
323                         : (aSelNum == 1) ? AIS_SOP_OneSelected
324                                          : AIS_SOP_SeveralSelected;
325   
326 }
327
328 //=======================================================================
329 //function : Select
330 //purpose  : Selection by polyline
331 //=======================================================================
332 AIS_StatusOfPick AIS_InteractiveContext::Select (const TColgp_Array1OfPnt2d& thePolyline,
333                                                  const Handle(V3d_View)&     theView,
334                                                  const Standard_Boolean      toUpdateViewer)
335 {
336   // all objects detected by the selector are taken, previous current objects are emptied,
337   // new objects are put...
338
339   if (HasOpenedContext())
340   {
341     return myLocalContexts(myCurLocalIndex)->Select (thePolyline, theView, toUpdateViewer);
342   }
343
344   ClearCurrents (Standard_False);
345
346   Handle(StdSelect_ViewerSelector3d) aSelector;
347
348   if (theView->Viewer() == myMainVwr)
349   {
350     aSelector = myMainSel;
351     myWasLastMain = Standard_True;
352   }
353
354   aSelector->Pick (thePolyline, theView);
355   AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
356
357   AIS_MapOfInteractive anObjectsToSelect;
358   for (aSelector->Init(); aSelector->More(); aSelector->Next())
359   {
360     Handle(AIS_InteractiveObject) anObj = 
361       Handle( AIS_InteractiveObject )::DownCast (aSelector->Picked()->Selectable());
362     if (!anObj.IsNull())
363     {
364       anObjectsToSelect.Add (anObj);
365     }
366   }
367
368   AIS_MapIteratorOfMapOfInteractive anIt (anObjectsToSelect);
369   for ( ; anIt.More(); anIt.Next())
370   {
371     AIS_Selection::Select (anIt.Key());
372     anIt.Key()->State (1);
373   }
374
375   HilightCurrents (toUpdateViewer);
376
377   Standard_Integer aSelNum = NbCurrents();
378
379   return (aSelNum == 0) ? AIS_SOP_NothingSelected
380                         : (aSelNum == 1) ? AIS_SOP_OneSelected
381                                          : AIS_SOP_SeveralSelected;
382   
383 }
384
385 //=======================================================================
386 //function : Select
387 //purpose  : 
388 //=======================================================================
389 AIS_StatusOfPick AIS_InteractiveContext::Select (const Standard_Boolean toUpdateViewer)
390 {
391   if (HasOpenedContext())
392   {
393     if(myWasLastMain)
394     {
395       return myLocalContexts(myCurLocalIndex)->Select (toUpdateViewer);
396     }
397     else
398     {
399       myLocalContexts(myCurLocalIndex)->SetSelected (myLastPicked, toUpdateViewer);
400       return AIS_SOP_OneSelected;
401     }
402   }
403
404   if (myWasLastMain && !myLastinMain.IsNull())
405   {
406     if(myLastinMain->State() != 1)
407     {
408       SetCurrentObject (myLastinMain,Standard_False);
409       if(toUpdateViewer)
410       {
411         UpdateCurrentViewer();
412       }
413     }
414   }
415   else
416   {
417     AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
418     Handle(AIS_Selection) aSelection = AIS_Selection::CurrentSelection();
419     Handle(AIS_InteractiveObject) anObj;
420     for (aSelection->Init(); aSelection->More(); aSelection->Next())
421     {
422       anObj = Handle(AIS_InteractiveObject)::DownCast (aSelection->Value());
423       anObj->State (0);
424       Unhilight (anObj,Standard_False);
425       if (myObjects.IsBound (anObj) && myObjects(anObj)->IsSubIntensityOn())
426       {
427         HilightWithColor (anObj, mySubIntensity, Standard_False);
428       }
429     }
430
431     AIS_Selection::Select();
432     if (toUpdateViewer && myWasLastMain)
433     {
434         UpdateCurrentViewer();
435     }
436   }
437
438   Standard_Integer aSelNum = NbCurrents();
439
440   return (aSelNum == 0) ? AIS_SOP_NothingSelected
441                         : (aSelNum == 1) ? AIS_SOP_OneSelected
442                                          : AIS_SOP_SeveralSelected;
443 }
444
445 //=======================================================================
446 //function : ShiftSelect
447 //purpose  : 
448 //=======================================================================
449 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Boolean toUpdateViewer)
450 {
451   if (HasOpenedContext())
452   {
453     if(myWasLastMain)
454     {
455       return myLocalContexts (myCurLocalIndex)->ShiftSelect (toUpdateViewer);
456     }
457     else
458     {
459       myLocalContexts (myCurLocalIndex)->AddOrRemoveSelected (myLastPicked, toUpdateViewer);
460
461       Standard_Integer aSelNum = NbSelected();
462       return (aSelNum == 0) ? AIS_SOP_NothingSelected
463                             : (aSelNum == 1) ? AIS_SOP_OneSelected
464                                              : AIS_SOP_SeveralSelected;
465     }
466   }
467
468   if (myWasLastMain && !myLastinMain.IsNull())
469   {
470     AddOrRemoveCurrentObject (myLastinMain, toUpdateViewer);
471   }
472
473   Standard_Integer aCurrentSelNum = NbCurrents();
474
475   return (aCurrentSelNum == 0) ? AIS_SOP_NothingSelected
476                                : (aCurrentSelNum == 1) ? AIS_SOP_OneSelected
477                                                        : AIS_SOP_SeveralSelected;
478 }
479
480 //=======================================================================
481 //function : ShiftSelect
482 //purpose  : 
483 //=======================================================================
484 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const Standard_Integer theXPMin,
485                                                       const Standard_Integer theYPMin,
486                                                       const Standard_Integer theXPMax,
487                                                       const Standard_Integer theYPMax,
488                                                       const Handle(V3d_View)& theView,
489                                                       const Standard_Boolean toUpdateViewer)
490 {
491   if (HasOpenedContext())
492   {
493     return myLocalContexts(myCurLocalIndex)->ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax,
494                                                           theView, toUpdateViewer);
495   }
496
497   UnhilightCurrents (Standard_False);
498
499   Handle(StdSelect_ViewerSelector3d) aSelector;
500   if (theView->Viewer() == myMainVwr)
501   {
502     aSelector = myMainSel;
503     myWasLastMain = Standard_True;
504   }
505   else
506   {
507     return AIS_SOP_NothingSelected;
508   }
509
510   aSelector->Pick (theXPMin, theYPMin, theXPMax, theYPMax, theView);
511   AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
512   for (aSelector->Init(); aSelector->More(); aSelector->Next())
513   {
514     Handle(AIS_InteractiveObject) anObjToSelect =  Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
515     if (!anObjToSelect.IsNull())
516     {
517       AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
518       Standard_Integer aState = (aSelStatus == AIS_SS_Added) ? 1 : 0;
519       anObjToSelect->State (aState);
520     }
521   }
522
523   HilightCurrents (toUpdateViewer);
524
525   Standard_Integer aSelNum = NbCurrents();
526
527   return (aSelNum == 0) ? AIS_SOP_NothingSelected
528                         : (aSelNum == 1) ? AIS_SOP_OneSelected
529                                          : AIS_SOP_SeveralSelected;
530
531 }
532
533 //=======================================================================
534 //function : ShiftSelect
535 //purpose  : 
536 //=======================================================================
537 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline,
538                                                       const Handle(V3d_View)& theView,
539                                                       const Standard_Boolean toUpdateViewer)
540 {
541   if (HasOpenedContext())
542   {
543     return myLocalContexts(myCurLocalIndex)->ShiftSelect (thePolyline, theView, toUpdateViewer);
544   }
545
546   UnhilightCurrents (Standard_False);
547
548   Handle(StdSelect_ViewerSelector3d) aSelector;
549
550   if (theView->Viewer() == myMainVwr)
551   {
552     aSelector= myMainSel;
553     myWasLastMain = Standard_True;
554   }
555   else
556   {
557     return AIS_SOP_NothingSelected;
558   }
559
560   aSelector->Pick (thePolyline, theView);
561
562   AIS_Selection::SetCurrentSelection (myCurrentName.ToCString());
563   for (aSelector->Init(); aSelector->More(); aSelector->Next())
564   {
565     Handle(AIS_InteractiveObject) anObjToSelect = Handle(AIS_InteractiveObject)::DownCast (aSelector->Picked()->Selectable());
566     if (!anObjToSelect.IsNull())
567     {
568       AIS_SelectStatus aSelStatus = AIS_Selection::Select (anObjToSelect);
569       Standard_Integer aState = (aSelStatus == AIS_SS_Added ) ? 1 : 0;
570       anObjToSelect->State (aState);
571     }
572   }
573
574   HilightCurrents (toUpdateViewer);
575
576   Standard_Integer aSelNum = NbCurrents();
577
578   return (aSelNum == 0) ? AIS_SOP_NothingSelected
579                         : (aSelNum == 1) ? AIS_SOP_OneSelected
580                                          : AIS_SOP_SeveralSelected;
581 }
582
583 //=======================================================================
584 //function : SetCurrentObject
585 //purpose  : 
586 //=======================================================================
587 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
588                                               const Standard_Boolean updateviewer)
589 {
590   // single case processing...
591   if(NbCurrents()==1 && anIObj->State()==1){
592     Quantity_NameOfColor HiCol;
593     Standard_Boolean HasHiCol;
594     if(IsHilighted(anIObj,HasHiCol,HiCol)){
595       if(HasHiCol && HiCol!= mySelectionColor) {
596 #ifdef UKI60826
597         HilightWithColor(anIObj,mySelectionColor,updateviewer);
598 #else
599         Hilight(anIObj,updateviewer);
600 #endif
601       }
602     }
603     return;
604   }
605
606
607   // 
608   if(!HasOpenedContext()) {
609     if(anIObj.IsNull()) return;
610     if(!myObjects.IsBound(anIObj)) 
611       Display(anIObj,Standard_False);
612     
613     AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
614     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
615     Handle(Standard_Transient) TR;
616     Handle(AIS_InteractiveObject) IO;
617     sel->Init();
618     while (sel->More()) {
619       TR = sel->Value();
620       IO = *((Handle(AIS_InteractiveObject)*)&TR);
621       Unhilight(IO,Standard_False);
622       IO->State(0);
623       sel->Next();
624     }
625     
626     // added to avoid untimely viewer update...
627     AIS_Selection::ClearAndSelect(anIObj);
628     anIObj->State(1);
629     Quantity_NameOfColor HiCol;
630     Standard_Boolean HasHiCol;
631     if(IsHilighted(anIObj,HasHiCol,HiCol)){
632       if(HasHiCol && HiCol!= mySelectionColor) {
633 #ifdef UKI60826
634           HilightWithColor(anIObj,mySelectionColor,Standard_False);
635 #else
636           Hilight(anIObj,Standard_False);
637 #endif
638       }
639     }
640     else{
641 #ifdef UKI60826
642         HilightWithColor(anIObj,mySelectionColor,Standard_False);
643 #else
644       Hilight(anIObj,Standard_False);
645 #endif
646     }
647     if (updateviewer) 
648       UpdateCurrentViewer();
649   }
650   else{
651 #ifdef DEB
652     cout<<"Nothing Done : Opened Local Context"<<endl;
653 #endif
654   }
655 }
656
657 //=======================================================================
658 //function : AddOrRemoveCurrentObject
659 //purpose  : 
660 //=======================================================================
661
662 void AIS_InteractiveContext::
663 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
664                          const Standard_Boolean updateviewer)
665 {
666   if(anIObj.IsNull()) return;
667 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
668   if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
669     
670     AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
671     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
672
673     AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
674     
675     Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
676     anIObj->State(mod);
677     if(mod==1)
678 #ifdef BUC60814
679       HilightWithColor(anIObj,mySelectionColor,Standard_False);
680 #else
681       Hilight(anIObj,Standard_False);
682 #endif
683     else 
684       Unhilight(anIObj,Standard_False);
685     
686     
687     if(updateviewer) 
688       UpdateCurrentViewer();
689   }
690   else{
691 #ifdef DEB
692     cout<<"Nothing Done : Opened Local Context"<<endl;
693 #endif
694   }
695 }
696 //=======================================================================
697 //function : UpdateCurrent
698 //purpose  : 
699 //=======================================================================
700
701 void AIS_InteractiveContext::UpdateCurrent()
702 {
703   HilightCurrents();
704 }
705
706 //=======================================================================
707 //function : IsCurrent
708 //purpose  : 
709 //=======================================================================
710
711 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const 
712 {
713
714   if (anIObj.IsNull()) return Standard_False;
715   return (anIObj->State()==1);
716   
717   //   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
718   //   sel->Init();
719   //   while (sel->More()) {
720   //     if (anIObj == sel->Value()) return Standard_True;
721   //     sel->Next();
722   //   }
723   //   return Standard_False;
724
725 }
726
727 //=======================================================================
728 //function : InitCurrent
729 //purpose  : 
730 //=======================================================================
731
732 void AIS_InteractiveContext::InitCurrent()
733 {
734   AIS_Selection::Selection(myCurrentName.ToCString())->Init();
735 }
736
737 //=======================================================================
738 //function : MoreCurrent
739 //purpose  : 
740 //=======================================================================
741
742 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const 
743 {
744   return AIS_Selection::Selection(myCurrentName.ToCString())->More();
745
746 }
747
748 //=======================================================================
749 //function : NextCurrent
750 //purpose  : 
751 //=======================================================================
752
753 void AIS_InteractiveContext::NextCurrent()
754 {
755   AIS_Selection::Selection(myCurrentName.ToCString())->Next();
756 }
757
758 //=======================================================================
759 //function : Current
760 //purpose  : 
761 //=======================================================================
762
763 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const 
764 {
765   Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
766   Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
767   return IO;
768 }
769
770 //=======================================================================
771 //function : FirstCurrentObject
772 //purpose  : 
773 //=======================================================================
774 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()  
775 {
776   Handle(AIS_InteractiveObject) IO ;
777   InitCurrent();
778   if(MoreCurrent()){
779     return Current();
780   }
781   return IO;
782 }
783
784 //=======================================================================
785 //function : NbCurrents
786 //purpose  : 
787 //=======================================================================
788 Standard_Integer AIS_InteractiveContext::NbCurrents()
789 {
790   Standard_Integer i(0);
791   for(InitCurrent();MoreCurrent();NextCurrent())
792     {i++;}
793   return i;
794 }
795
796 //=======================================================================
797 //function : HilightCurrents
798 //purpose  : 
799 //=======================================================================
800 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
801 {
802   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
803   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
804   Handle(Standard_Transient) TR;
805   Handle(AIS_InteractiveObject) IO;
806   sel->Init();
807   while (sel->More()) {
808     TR = sel->Value();
809     IO = *((Handle(AIS_InteractiveObject)*)&TR);
810 #ifdef BUC60814
811     HilightWithColor(IO,mySelectionColor,Standard_False);
812 #else
813     Hilight(IO,Standard_False);
814 #endif
815     sel->Next();
816   }
817   if(updateviewer) 
818     UpdateCurrentViewer();
819 }
820
821 //=======================================================================
822 //function : UnhilightCurrents
823 //purpose  : 
824 //=======================================================================
825
826 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
827 {
828   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
829   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
830   Handle(Standard_Transient) TR;
831   Handle(AIS_InteractiveObject) IO;
832   sel->Init();
833   while (sel->More()) {
834     TR = sel->Value();
835     IO = *((Handle(AIS_InteractiveObject)*)&TR);
836     Unhilight(IO,Standard_False);
837     sel->Next();
838   }
839   if(updateviewer) 
840     UpdateCurrentViewer();
841 }
842
843 //=======================================================================
844 //function : ClearCurrents
845 //purpose  : 
846 //=======================================================================
847
848 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
849 {
850   if(NbCurrents()==0) return;
851   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
852   Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
853   Handle(Standard_Transient) Tr;
854   Handle(AIS_InteractiveObject) IO;
855   for(S->Init();S->More();S->Next()){
856     Tr = S->Value();
857     IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
858     IO->State(0);
859     Unhilight(IO,Standard_False);
860   }
861   AIS_Selection::Select();
862   if(updateviewer)
863     UpdateCurrentViewer();
864 }
865
866
867 //=======================================================================
868 //function : HilightSelected
869 //purpose  : 
870 //=======================================================================
871
872 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
873 {
874   if(!HasOpenedContext()){
875     AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
876     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
877     Handle(Standard_Transient) TR;
878     Handle(AIS_InteractiveObject) IO;
879     sel->Init();
880     while (sel->More()) {
881       TR = sel->Value();
882       IO = *((Handle(AIS_InteractiveObject)*)&TR);
883 #ifdef BUC60814
884       HilightWithColor(IO,mySelectionColor,Standard_False);
885 #else
886       Hilight(IO,Standard_False);
887 #endif
888       sel->Next();
889     }
890   }
891   else
892     {
893       myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
894     }
895   if(updateviewer)
896     UpdateCurrentViewer();
897 }
898
899 //=======================================================================
900 //function : UnhilightSelected
901 //purpose  : 
902 //=======================================================================
903
904 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
905 {
906   if(!HasOpenedContext()){
907     AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
908     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
909     Handle(Standard_Transient) TR;
910     Handle(AIS_InteractiveObject) IO;
911     sel->Init();
912     while (sel->More()) {
913       TR = sel->Value();
914       IO = *((Handle(AIS_InteractiveObject)*)&TR);
915       Unhilight(IO,Standard_False);
916       sel->Next();
917     }
918     if(updateviewer)
919       UpdateCurrentViewer();
920   }
921   else
922     {
923       myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
924     }
925 }
926
927
928 //=======================================================================
929 //function : ClearSelected
930 //purpose  : 
931 //=======================================================================
932
933 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
934 {
935   if(!HasOpenedContext())
936     ClearCurrents(updateviewer);
937   else 
938     myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
939   
940 }
941
942
943 //=======================================================================
944 //function : SetSelectedCurrent
945 //purpose  : 
946 //=======================================================================
947
948 void AIS_InteractiveContext::SetSelectedCurrent()
949 {
950
951
952 #ifdef DEB
953   cout<<"Not Yet Implemented"<<endl;
954 #endif
955 }
956
957 //=======================================================================
958 //function : UpdateSelection
959 //purpose  : 
960 //=======================================================================
961
962 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
963 {
964   if(!HasOpenedContext()) {
965     HilightSelected();
966 #ifndef BUG
967     return;
968 #endif
969   }
970   myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
971 }
972
973 //=======================================================================
974 //function : SetCurrentObject
975 //purpose  : 
976 //=======================================================================
977 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
978 {
979   if(!HasOpenedContext()) 
980     SetCurrentObject(anIObj,updateviewer);
981   else
982     myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
983 }
984
985 //=======================================================================
986 //function : AddOrRemoveSelected
987 //purpose  : 
988 //=======================================================================
989
990 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
991                                                  const Standard_Boolean updateviewer)
992 {
993   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
994   if(!HasOpenedContext())
995     AddOrRemoveCurrentObject(anIObj,updateviewer);
996   else
997     myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
998   
999 }
1000 //=======================================================================
1001 //function : AddOrRemoveSelected
1002 //purpose  : 
1003 //=======================================================================
1004
1005 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
1006                                             const Standard_Boolean updateviewer)
1007
1008   if(!HasOpenedContext()) {
1009 #ifdef DEB
1010     cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
1011 #endif
1012     return;
1013   }
1014   
1015   myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1016   if(updateviewer) UpdateCurrentViewer();
1017   
1018 }
1019 //=======================================================================
1020 //function : AddOrRemoveSelected
1021 //purpose  : 
1022 //=======================================================================
1023
1024 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1025                                                  const Standard_Boolean updateviewer)
1026
1027   if(!HasOpenedContext()) {
1028 #ifdef DEB
1029     cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1030 #endif
1031     return;
1032   }
1033   
1034   myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1035   if(updateviewer) UpdateCurrentViewer();
1036   
1037 }
1038
1039
1040
1041 //=======================================================================
1042 //function : IsSelected
1043 //purpose  : 
1044 //=======================================================================
1045
1046 Standard_Boolean AIS_InteractiveContext::
1047 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const 
1048 {
1049   if (anIObj.IsNull()) return Standard_False;
1050   
1051   if(!HasOpenedContext()) 
1052     return (anIObj->State()==1);
1053   else 
1054     return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1055 }
1056
1057
1058 //=======================================================================
1059 //function : InitSelected
1060 //purpose  : 
1061 //=======================================================================
1062
1063 void AIS_InteractiveContext::InitSelected()
1064 {
1065   if(!HasOpenedContext())
1066     AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1067   else
1068     myLocalContexts(myCurLocalIndex)->InitSelected();
1069 }
1070
1071 //=======================================================================
1072 //function : MoreSelected
1073 //purpose  : 
1074 //=======================================================================
1075
1076 Standard_Boolean AIS_InteractiveContext::MoreSelected() const 
1077 {
1078   if(!HasOpenedContext())
1079     return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1080   return myLocalContexts(myCurLocalIndex)->MoreSelected();
1081 }
1082
1083 //=======================================================================
1084 //function : NextSelected
1085 //purpose  : 
1086 //=======================================================================
1087
1088 void AIS_InteractiveContext::NextSelected()
1089 {
1090   if(!HasOpenedContext())
1091     AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1092   else
1093     myLocalContexts(myCurLocalIndex)->NextSelected();
1094 }
1095
1096 //=======================================================================
1097 //function : HasSelectedShape
1098 //purpose  : 
1099 //=======================================================================
1100
1101 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const 
1102 {
1103   if(!HasOpenedContext()) {
1104 #ifdef IMP280200
1105     Handle(AIS_Shape) shape = 
1106         Handle(AIS_Shape)::DownCast(SelectedInteractive());
1107     if( !shape.IsNull() ) return Standard_True;
1108 #endif
1109     return Standard_False;
1110   }
1111   return myLocalContexts(myCurLocalIndex)->HasShape();
1112   
1113   
1114 }
1115
1116 //=======================================================================
1117 //function : SelectedShape
1118 //purpose  : 
1119 //=======================================================================
1120
1121 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const 
1122 {
1123   if (!HasOpenedContext())
1124   {
1125     TopoDS_Shape aResShape;
1126     Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (SelectedInteractive());
1127     if (!aShape.IsNull())
1128     {
1129       aResShape = aShape->Shape().Located (TopLoc_Location (SelectedInteractive()->Transformation()) * aShape->Shape().Location());
1130     }
1131
1132     return aResShape;
1133   } 
1134   else
1135   {
1136     return myLocalContexts (myCurLocalIndex)->SelectedShape();
1137   }
1138 }
1139
1140 //=======================================================================
1141 //function : Interactive
1142 //purpose  : 
1143 //=======================================================================
1144
1145 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const 
1146 {
1147   return SelectedInteractive();
1148 }
1149
1150 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const 
1151 {
1152   if(!HasOpenedContext()){
1153     Handle(Standard_Transient) TR  =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1154     Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1155     return IO;}
1156   
1157   return  myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1158   
1159 }
1160 //=======================================================================
1161 //function : Interactive
1162 //purpose  : 
1163 //=======================================================================
1164
1165 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const 
1166 {
1167   if(!HasOpenedContext()){
1168     Handle(SelectMgr_EntityOwner) Ownr;
1169     return Ownr;
1170   }
1171   return  myLocalContexts(myCurLocalIndex)->SelectedOwner();
1172   
1173 }
1174
1175 //=======================================================================
1176 //function : EntityOwners
1177 //purpose  : 
1178 //=======================================================================
1179 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1180                                           const Handle(AIS_InteractiveObject)& theIObj,
1181                                           const Standard_Integer theMode) const 
1182 {
1183   if ( theIObj.IsNull() )
1184       return;
1185
1186   TColStd_ListOfInteger aModes;
1187   if ( theMode == -1 )
1188     ActivatedModes( theIObj, aModes );
1189   else
1190     aModes.Append( theMode );
1191
1192   TColStd_ListIteratorOfListOfInteger anItr( aModes );
1193   for (; anItr.More(); anItr.Next() )
1194   {
1195     int aMode = anItr.Value();
1196     if ( !theIObj->HasSelection( aMode ) )
1197       continue;
1198
1199     Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1200
1201     for ( aSel->Init(); aSel->More(); aSel->Next() )
1202     {
1203       Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1204       if ( aEntity.IsNull() )
1205         continue;
1206
1207       Handle(SelectMgr_EntityOwner) aOwner =
1208         Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1209       if ( !aOwner.IsNull() )
1210         theOwners.Add( aOwner );
1211     }
1212   }
1213 }
1214
1215 Standard_Integer AIS_InteractiveContext::NbSelected() 
1216 {
1217   Standard_Integer i(0);
1218   for(InitSelected();MoreSelected();NextSelected())
1219     {i++;}
1220   return i;
1221 }
1222
1223 //=======================================================================
1224 //function : HasApplicative
1225 //purpose  : 
1226 //=======================================================================
1227
1228   Standard_Boolean AIS_InteractiveContext::HasApplicative() const 
1229 {
1230   return Interactive()->HasOwner();
1231 }
1232
1233 //=======================================================================
1234 //function : Applicative
1235 //purpose  : 
1236 //=======================================================================
1237
1238 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const 
1239 {
1240   return Interactive()->GetOwner();
1241 }
1242
1243
1244
1245 //==================================================
1246 // Function: 
1247 // Purpose :
1248 //==================================================
1249 Standard_Boolean AIS_InteractiveContext::HasDetected() const 
1250 {
1251   if(HasOpenedContext())
1252     return myLocalContexts(myCurLocalIndex)->HasDetected();
1253   else
1254     return !myLastPicked.IsNull();
1255 }
1256
1257 //=======================================================================
1258 //function : HasDetectedShape
1259 //purpose  : 
1260 //=======================================================================
1261
1262 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const 
1263 {
1264   if(HasOpenedContext())
1265     return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1266   return Standard_False;
1267 }
1268
1269 //=======================================================================
1270 //function : DetectedShape
1271 //purpose  : 
1272 //=======================================================================
1273
1274 const TopoDS_Shape&
1275 AIS_InteractiveContext::DetectedShape() const
1276 {
1277   return myLocalContexts(myCurLocalIndex)->DetectedShape();
1278 }                                           
1279
1280 //=======================================================================
1281 //function : DetectedInteractive
1282 //purpose  : 
1283 //=======================================================================
1284
1285 Handle(AIS_InteractiveObject) 
1286 AIS_InteractiveContext::DetectedInteractive() const 
1287 {
1288   if(HasOpenedContext())
1289     return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1290   return myLastPicked;
1291 }
1292
1293
1294 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const 
1295 {
1296   if(!HasOpenedContext())
1297     return Standard_False; // temporaire
1298   else
1299     return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1300   
1301 }
1302
1303
1304 //=======================================================================
1305 //function : DetectedOwner
1306 //purpose  : 
1307 //=======================================================================
1308 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1309 {
1310   if(HasOpenedContext())
1311     return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1312   Handle(SelectMgr_EntityOwner) Ownr;
1313   return Ownr;
1314 }
1315
1316
1317 //=======================================================================
1318 //function : HilightNextDetected
1319 //purpose  :
1320 //=======================================================================
1321 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1322                                                               const Standard_Boolean  theToRedrawImmediate)
1323 {
1324   return HasOpenedContext()
1325        ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1326        : 0;
1327     
1328 }
1329
1330 //=======================================================================
1331 //function : HilightNextDetected
1332 //purpose  :
1333 //=======================================================================
1334 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1335                                                                   const Standard_Boolean  theToRedrawImmediate)
1336 {
1337   return HasOpenedContext()
1338        ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1339        : 0;
1340     
1341 }
1342
1343 //=======================================================================
1344 //function : InitDetected
1345 //purpose  :
1346 //=======================================================================
1347 void AIS_InteractiveContext::InitDetected()
1348 {
1349   if (HasOpenedContext())
1350   {
1351     myLocalContexts(myCurLocalIndex)->InitDetected();
1352     return;
1353   }
1354
1355   if(myAISDetectedSeq.Length() != 0)
1356   {
1357     myAISCurDetected = 1;
1358   }
1359 }
1360
1361 //=======================================================================
1362 //function : MoreDetected
1363 //purpose  :
1364 //=======================================================================
1365 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1366 {
1367   if (HasOpenedContext())
1368   {
1369     return myLocalContexts(myCurLocalIndex)->MoreDetected();
1370   }
1371
1372   return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1373           Standard_True : Standard_False;
1374 }
1375
1376 //=======================================================================
1377 //function : NextDetected
1378 //purpose  :
1379 //=======================================================================
1380 void AIS_InteractiveContext::NextDetected()
1381 {
1382   if(HasOpenedContext())
1383   {
1384     myLocalContexts(myCurLocalIndex)->NextDetected();
1385     return;
1386   }
1387
1388   myAISCurDetected++;
1389 }
1390
1391 //=======================================================================
1392 //function : DetectedCurrentShape
1393 //purpose  :
1394 //=======================================================================
1395 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1396 {
1397   if (HasOpenedContext())
1398   {
1399     return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1400   }
1401
1402   static TopoDS_Shape aDummyShape;
1403
1404   Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1405
1406   if (aCurrentShape.IsNull())
1407   {
1408     return aDummyShape;
1409   }
1410
1411   return aCurrentShape->Shape();
1412 }
1413
1414 //=======================================================================
1415 //function : DetectedCurrentObject
1416 //purpose  :
1417 //=======================================================================
1418 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1419 {
1420   if (HasOpenedContext())
1421   {
1422     return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1423   }
1424
1425   return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
1426 }