0025127: Wrong result done by General Fuse algorithm
[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
271 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Integer XPMin,
272                                                 const Standard_Integer  YPMin,
273                                                 const Standard_Integer  XPMax,
274                                                 const Standard_Integer  YPMax, 
275                                                 const Handle(V3d_View)& aView,
276                                                 const Standard_Boolean updateviewer)
277 {
278   // all objects detected by the selector are taken, previous current objects are emptied,
279   // new objects are put...
280
281   if(HasOpenedContext())
282     return myLocalContexts(myCurLocalIndex)->Select(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
283
284   ClearCurrents(Standard_False);
285   // OCC11904 - local variables made non-static - it looks and works better like this
286   Handle(StdSelect_ViewerSelector3d) selector;
287   
288   if(aView->Viewer()== myMainVwr) {
289     selector= myMainSel;
290     myWasLastMain = Standard_True;}
291
292   selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
293   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
294
295 #ifdef OCC9657
296   AIS_MapOfInteractive theSelectedObj;
297   for( selector->Init(); selector->More(); selector->Next() )
298   {
299     Handle( AIS_InteractiveObject ) anObj = 
300       Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
301     if( !anObj.IsNull() )
302       theSelectedObj.Add( anObj );
303   }
304   AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
305   for( ; anIt.More(); anIt.Next() )
306   {
307     AIS_Selection::Select( anIt.Key() );
308     anIt.Key()->State(1);
309   }
310 #else
311   for(selector->Init();selector->More();selector->Next()){
312     const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
313     if(!SO.IsNull()){
314 #ifdef OCC138
315       AIS_Selection::Select(SO);
316       (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
317 #else
318       (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
319       AIS_Selection::Select(SO);
320 #endif //OCC138
321     }
322   }
323
324 #endif //OCC9657
325   HilightCurrents(updateviewer);
326   
327   Standard_Integer NS = NbCurrents();
328   if(NS==0) return AIS_SOP_NothingSelected;
329   if(NS==1) return AIS_SOP_OneSelected;
330   return AIS_SOP_SeveralSelected;
331   
332 }
333
334 //=======================================================================
335 //function : Select
336 //purpose  : Selection by polyline
337 //=======================================================================
338
339 AIS_StatusOfPick AIS_InteractiveContext::Select(const TColgp_Array1OfPnt2d& aPolyline,
340                                                 const Handle(V3d_View)& aView,
341                                                 const Standard_Boolean updateviewer)
342 {
343   // all objects detected by the selector are taken, previous current objects are emptied,
344   // new objects are put...
345
346   if(HasOpenedContext())
347     return myLocalContexts(myCurLocalIndex)->Select(aPolyline,aView,updateviewer);
348
349   ClearCurrents(Standard_False);
350   // OCC11904 - local variables made non-static - it looks and works better like this
351   Handle(StdSelect_ViewerSelector3d) selector;
352   
353   if(aView->Viewer()== myMainVwr) {
354     selector= myMainSel;
355     myWasLastMain = Standard_True;}
356
357   selector->Pick(aPolyline,aView);
358   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
359
360
361 #ifdef OCC9657
362   AIS_MapOfInteractive theSelectedObj;
363   for( selector->Init(); selector->More(); selector->Next() )
364   {
365     Handle( AIS_InteractiveObject ) anObj = 
366       Handle( AIS_InteractiveObject )::DownCast( selector->Picked()->Selectable() );
367     if( !anObj.IsNull() )
368       theSelectedObj.Add( anObj );
369   }
370   AIS_MapIteratorOfMapOfInteractive anIt( theSelectedObj );
371   for( ; anIt.More(); anIt.Next() )
372   {
373     AIS_Selection::Select( anIt.Key() );
374     anIt.Key()->State(1);
375   }
376 #else
377   for(selector->Init();selector->More();selector->Next()){
378     const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
379     if(!SO.IsNull()){
380 #ifdef OCC138
381       AIS_Selection::Select(SO);
382       (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
383 #else
384       (*((Handle(AIS_InteractiveObject)*)&SO))->State(1);
385       AIS_Selection::Select(SO);
386 #endif //OCC138
387     }
388   }
389 #endif //OCC9657
390   HilightCurrents(updateviewer);
391   
392   Standard_Integer NS = NbCurrents();
393   if(NS==0) return AIS_SOP_NothingSelected;
394   if(NS==1) return AIS_SOP_OneSelected;
395   return AIS_SOP_SeveralSelected;
396   
397 }
398
399 //=======================================================================
400 //function : Select
401 //purpose  : 
402 //=======================================================================
403
404 AIS_StatusOfPick AIS_InteractiveContext::Select(const Standard_Boolean updateviewer)
405 {
406   if(HasOpenedContext()){
407     if(myWasLastMain)
408       return myLocalContexts(myCurLocalIndex)->Select(updateviewer);
409     else
410       {
411         myLocalContexts(myCurLocalIndex)->SetSelected(myLastPicked,updateviewer);
412         return AIS_SOP_OneSelected;
413       }
414   }
415 //  AIS_StatusOfPick PS(AIS_SOP_NothingSelected);
416   if(myWasLastMain && !myLastinMain.IsNull()){
417     if(myLastinMain->State()!=1){
418       SetCurrentObject(myLastinMain,Standard_False);
419       if(updateviewer)
420         UpdateCurrentViewer();}
421   }
422   else{
423     AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
424     Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
425     Handle(Standard_Transient) Tr;
426     Handle(AIS_InteractiveObject) IO;
427     
428     for(S->Init();S->More();S->Next()){
429       Tr = S->Value();
430       IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
431       IO->State(0);
432       Unhilight(IO,Standard_False);
433       if(myObjects.IsBound(IO)){ // anti-plantage-rob
434         if(myObjects(IO)->IsSubIntensityOn())
435           HilightWithColor(IO,mySubIntensity,Standard_False);
436       }
437     }
438     
439     AIS_Selection::Select();
440     if(updateviewer){
441       if(myWasLastMain)
442         UpdateCurrentViewer();
443     }
444   }
445   Standard_Integer NS = NbCurrents();
446   if(NS==0) return AIS_SOP_NothingSelected;
447   if(NS==1) return AIS_SOP_OneSelected;
448   return AIS_SOP_SeveralSelected;
449 }
450
451 //=======================================================================
452 //function : ShiftSelect
453 //purpose  : 
454 //=======================================================================
455
456 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Boolean updateviewer)
457 {
458   if(HasOpenedContext()){
459     if(myWasLastMain)
460       return myLocalContexts(myCurLocalIndex)->ShiftSelect(updateviewer);
461     else{
462       myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(myLastPicked,updateviewer);
463       Standard_Integer NS =NbSelected();
464       if(NS==0) return AIS_SOP_NothingSelected;
465       if(NS==1) return AIS_SOP_OneSelected;
466       return AIS_SOP_SeveralSelected;
467     }
468   }
469   if(myWasLastMain && !myLastinMain.IsNull())
470     AddOrRemoveCurrentObject(myLastinMain,updateviewer);
471
472   Standard_Integer NS = NbCurrents();
473   if(NS==0) return AIS_SOP_NothingSelected;
474   if(NS==1) return AIS_SOP_OneSelected;
475   return AIS_SOP_SeveralSelected;
476 }
477
478
479 //=======================================================================
480 //function : ShiftSelect
481 //purpose  : 
482 //=======================================================================
483
484 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect(const Standard_Integer XPMin, 
485                                                      const Standard_Integer YPMin, 
486                                                      const Standard_Integer XPMax, 
487                                                      const Standard_Integer YPMax, 
488                                                      const Handle(V3d_View)& aView,
489                                                      const Standard_Boolean updateviewer)
490 {
491   
492   if(HasOpenedContext())
493     return myLocalContexts(myCurLocalIndex)->ShiftSelect(XPMin,YPMin,XPMax,YPMax,aView,updateviewer);
494   
495   UnhilightCurrents(Standard_False);
496   // OCC11904 - local variables made non-static - it looks and works better like this
497   Handle(StdSelect_ViewerSelector3d) selector;
498   
499   if(aView->Viewer()== myMainVwr) {
500     selector= myMainSel;
501     myWasLastMain = Standard_True;}
502   else
503     return AIS_SOP_NothingSelected;
504   
505   selector->Pick(XPMin,YPMin,XPMax,YPMax,aView);
506   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
507   for(selector->Init();selector->More();selector->Next()){
508     const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
509     if(!SO.IsNull()){
510       AIS_SelectStatus SelStat = AIS_Selection::Select(SO);
511       Standard_Integer mod = (SelStat==AIS_SS_Added)?1:0;
512       (*((Handle(AIS_InteractiveObject)*)&SO))->State(mod);
513     }
514   }
515   
516   HilightCurrents(updateviewer);
517   
518   Standard_Integer NS =NbCurrents();
519   if(NS==0) return AIS_SOP_NothingSelected;
520   if(NS==1) return AIS_SOP_OneSelected;
521   return AIS_SOP_SeveralSelected;
522   
523 }
524
525 //=======================================================================
526 //function : ShiftSelect
527 //purpose  : 
528 //=======================================================================
529
530 AIS_StatusOfPick AIS_InteractiveContext::ShiftSelect( const TColgp_Array1OfPnt2d& aPolyline,
531                                                       const Handle(V3d_View)& aView,
532                                                       const Standard_Boolean updateviewer )
533 {
534     if( HasOpenedContext() )
535         return myLocalContexts( myCurLocalIndex )->ShiftSelect( aPolyline, aView, updateviewer );
536
537     UnhilightCurrents( Standard_False );
538     // OCC11904 - local variables made non-static - it looks and works better like this
539     Handle(StdSelect_ViewerSelector3d) selector;
540   
541     if( aView->Viewer() == myMainVwr ) {
542         selector= myMainSel;
543         myWasLastMain = Standard_True;
544     }
545     else
546         return AIS_SOP_NothingSelected;
547
548     selector->Pick( aPolyline, aView );
549     
550     AIS_Selection::SetCurrentSelection( myCurrentName.ToCString() );
551     for( selector->Init(); selector->More(); selector->Next() ) {
552         const Handle(SelectMgr_SelectableObject)& SO = selector->Picked()->Selectable();
553         if( !SO.IsNull() ) {
554             AIS_SelectStatus SelStat = AIS_Selection::Select( SO );
555             Standard_Integer mod = ( SelStat == AIS_SS_Added ) ? 1 : 0;
556             (*((Handle(AIS_InteractiveObject)*)&SO))->State( mod );
557         }
558     }
559     
560     HilightCurrents( updateviewer );
561     Standard_Integer NS = NbCurrents();
562     if( NS == 0 ) return AIS_SOP_NothingSelected;
563     if( NS == 1 ) return AIS_SOP_OneSelected;
564     return AIS_SOP_SeveralSelected;
565 }
566
567 //=======================================================================
568 //function : SetCurrentObject
569 //purpose  : 
570 //=======================================================================
571
572 void AIS_InteractiveContext::SetCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
573                                               const Standard_Boolean updateviewer)
574 {
575   // single case processing...
576   if(NbCurrents()==1 && anIObj->State()==1){
577     Quantity_NameOfColor HiCol;
578     Standard_Boolean HasHiCol;
579     if(IsHilighted(anIObj,HasHiCol,HiCol)){
580       if(HasHiCol && HiCol!= mySelectionColor) {
581 #ifdef UKI60826
582         HilightWithColor(anIObj,mySelectionColor,updateviewer);
583 #else
584         Hilight(anIObj,updateviewer);
585 #endif
586       }
587     }
588     return;
589   }
590
591
592   // 
593   if(!HasOpenedContext()) {
594     if(anIObj.IsNull()) return;
595     if(!myObjects.IsBound(anIObj)) 
596       Display(anIObj,Standard_False);
597     
598     AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
599     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
600     Handle(Standard_Transient) TR;
601     Handle(AIS_InteractiveObject) IO;
602     sel->Init();
603     while (sel->More()) {
604       TR = sel->Value();
605       IO = *((Handle(AIS_InteractiveObject)*)&TR);
606       Unhilight(IO,Standard_False);
607       IO->State(0);
608       sel->Next();
609     }
610     
611     // added to avoid untimely viewer update...
612     AIS_Selection::ClearAndSelect(anIObj);
613     anIObj->State(1);
614     Quantity_NameOfColor HiCol;
615     Standard_Boolean HasHiCol;
616     if(IsHilighted(anIObj,HasHiCol,HiCol)){
617       if(HasHiCol && HiCol!= mySelectionColor) {
618 #ifdef UKI60826
619           HilightWithColor(anIObj,mySelectionColor,Standard_False);
620 #else
621           Hilight(anIObj,Standard_False);
622 #endif
623       }
624     }
625     else{
626 #ifdef UKI60826
627         HilightWithColor(anIObj,mySelectionColor,Standard_False);
628 #else
629       Hilight(anIObj,Standard_False);
630 #endif
631     }
632     if (updateviewer) 
633       UpdateCurrentViewer();
634   }
635   else{
636 #ifdef DEB
637     cout<<"Nothing Done : Opened Local Context"<<endl;
638 #endif
639   }
640 }
641
642 //=======================================================================
643 //function : AddOrRemoveCurrentObject
644 //purpose  : 
645 //=======================================================================
646
647 void AIS_InteractiveContext::
648 AddOrRemoveCurrentObject(const Handle(AIS_InteractiveObject)& anIObj,
649                          const Standard_Boolean updateviewer)
650 {
651   if(anIObj.IsNull()) return;
652 //OCC5682 to remove an object from neutral point even if Local Context is opened (Remove method)
653   if(!HasOpenedContext() /*OCC5682*/|| myObjects.IsBound(anIObj)) {
654     
655     AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
656     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
657
658     AIS_SelectStatus SelStat = AIS_Selection::Select(anIObj);
659     
660     Standard_Integer mod = (SelStat==AIS_SS_Added) ? 1 : 0;
661     anIObj->State(mod);
662     if(mod==1)
663 #ifdef BUC60814
664       HilightWithColor(anIObj,mySelectionColor,Standard_False);
665 #else
666       Hilight(anIObj,Standard_False);
667 #endif
668     else 
669       Unhilight(anIObj,Standard_False);
670     
671     
672     if(updateviewer) 
673       UpdateCurrentViewer();
674   }
675   else{
676 #ifdef DEB
677     cout<<"Nothing Done : Opened Local Context"<<endl;
678 #endif
679   }
680 }
681 //=======================================================================
682 //function : UpdateCurrent
683 //purpose  : 
684 //=======================================================================
685
686 void AIS_InteractiveContext::UpdateCurrent()
687 {
688   HilightCurrents();
689 }
690
691 //=======================================================================
692 //function : IsCurrent
693 //purpose  : 
694 //=======================================================================
695
696 Standard_Boolean AIS_InteractiveContext::IsCurrent(const Handle(AIS_InteractiveObject)& anIObj) const 
697 {
698
699   if (anIObj.IsNull()) return Standard_False;
700   return (anIObj->State()==1);
701   
702   //   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
703   //   sel->Init();
704   //   while (sel->More()) {
705   //     if (anIObj == sel->Value()) return Standard_True;
706   //     sel->Next();
707   //   }
708   //   return Standard_False;
709
710 }
711
712 //=======================================================================
713 //function : InitCurrent
714 //purpose  : 
715 //=======================================================================
716
717 void AIS_InteractiveContext::InitCurrent()
718 {
719   AIS_Selection::Selection(myCurrentName.ToCString())->Init();
720 }
721
722 //=======================================================================
723 //function : MoreCurrent
724 //purpose  : 
725 //=======================================================================
726
727 Standard_Boolean AIS_InteractiveContext::MoreCurrent() const 
728 {
729   return AIS_Selection::Selection(myCurrentName.ToCString())->More();
730
731 }
732
733 //=======================================================================
734 //function : NextCurrent
735 //purpose  : 
736 //=======================================================================
737
738 void AIS_InteractiveContext::NextCurrent()
739 {
740   AIS_Selection::Selection(myCurrentName.ToCString())->Next();
741 }
742
743 //=======================================================================
744 //function : Current
745 //purpose  : 
746 //=======================================================================
747
748 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Current() const 
749 {
750   Handle(Standard_Transient) TR = AIS_Selection::Selection(myCurrentName.ToCString())->Value();
751   Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
752   return IO;
753 }
754
755 //=======================================================================
756 //function : FirstCurrentObject
757 //purpose  : 
758 //=======================================================================
759 Handle(AIS_InteractiveObject) AIS_InteractiveContext::FirstCurrentObject()  
760 {
761   Handle(AIS_InteractiveObject) IO ;
762   InitCurrent();
763   if(MoreCurrent()){
764     return Current();
765   }
766   return IO;
767 }
768
769 //=======================================================================
770 //function : NbCurrents
771 //purpose  : 
772 //=======================================================================
773 Standard_Integer AIS_InteractiveContext::NbCurrents()
774 {
775   Standard_Integer i(0);
776   for(InitCurrent();MoreCurrent();NextCurrent())
777     {i++;}
778   return i;
779 }
780
781 //=======================================================================
782 //function : HilightCurrents
783 //purpose  : 
784 //=======================================================================
785 void AIS_InteractiveContext::HilightCurrents(const Standard_Boolean updateviewer)
786 {
787   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
788   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
789   Handle(Standard_Transient) TR;
790   Handle(AIS_InteractiveObject) IO;
791   sel->Init();
792   while (sel->More()) {
793     TR = sel->Value();
794     IO = *((Handle(AIS_InteractiveObject)*)&TR);
795 #ifdef BUC60814
796     HilightWithColor(IO,mySelectionColor,Standard_False);
797 #else
798     Hilight(IO,Standard_False);
799 #endif
800     sel->Next();
801   }
802   if(updateviewer) 
803     UpdateCurrentViewer();
804 }
805
806 //=======================================================================
807 //function : UnhilightCurrents
808 //purpose  : 
809 //=======================================================================
810
811 void AIS_InteractiveContext::UnhilightCurrents(const Standard_Boolean updateviewer)
812 {
813   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
814   Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
815   Handle(Standard_Transient) TR;
816   Handle(AIS_InteractiveObject) IO;
817   sel->Init();
818   while (sel->More()) {
819     TR = sel->Value();
820     IO = *((Handle(AIS_InteractiveObject)*)&TR);
821     Unhilight(IO,Standard_False);
822     sel->Next();
823   }
824   if(updateviewer) 
825     UpdateCurrentViewer();
826 }
827
828 //=======================================================================
829 //function : ClearCurrents
830 //purpose  : 
831 //=======================================================================
832
833 void AIS_InteractiveContext::ClearCurrents(const Standard_Boolean updateviewer)
834 {
835   if(NbCurrents()==0) return;
836   AIS_Selection::SetCurrentSelection(myCurrentName.ToCString());
837   Handle(AIS_Selection) S = AIS_Selection::CurrentSelection();
838   Handle(Standard_Transient) Tr;
839   Handle(AIS_InteractiveObject) IO;
840   for(S->Init();S->More();S->Next()){
841     Tr = S->Value();
842     IO = (*((Handle(AIS_InteractiveObject)*)&Tr));
843     IO->State(0);
844     Unhilight(IO,Standard_False);
845   }
846   AIS_Selection::Select();
847   if(updateviewer)
848     UpdateCurrentViewer();
849 }
850
851
852 //=======================================================================
853 //function : HilightSelected
854 //purpose  : 
855 //=======================================================================
856
857 void AIS_InteractiveContext::HilightSelected(const Standard_Boolean updateviewer)
858 {
859   if(!HasOpenedContext()){
860     AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
861     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
862     Handle(Standard_Transient) TR;
863     Handle(AIS_InteractiveObject) IO;
864     sel->Init();
865     while (sel->More()) {
866       TR = sel->Value();
867       IO = *((Handle(AIS_InteractiveObject)*)&TR);
868 #ifdef BUC60814
869       HilightWithColor(IO,mySelectionColor,Standard_False);
870 #else
871       Hilight(IO,Standard_False);
872 #endif
873       sel->Next();
874     }
875   }
876   else
877     {
878       myLocalContexts(myCurLocalIndex)->HilightPicked(updateviewer);
879     }
880   if(updateviewer)
881     UpdateCurrentViewer();
882 }
883
884 //=======================================================================
885 //function : UnhilightSelected
886 //purpose  : 
887 //=======================================================================
888
889 void AIS_InteractiveContext::UnhilightSelected(const Standard_Boolean updateviewer)
890 {
891   if(!HasOpenedContext()){
892     AIS_Selection::SetCurrentSelection(mySelectionName.ToCString());
893     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
894     Handle(Standard_Transient) TR;
895     Handle(AIS_InteractiveObject) IO;
896     sel->Init();
897     while (sel->More()) {
898       TR = sel->Value();
899       IO = *((Handle(AIS_InteractiveObject)*)&TR);
900       Unhilight(IO,Standard_False);
901       sel->Next();
902     }
903     if(updateviewer)
904       UpdateCurrentViewer();
905   }
906   else
907     {
908       myLocalContexts(myCurLocalIndex)->UnhilightPicked(updateviewer);
909     }
910 }
911
912
913 //=======================================================================
914 //function : ClearSelected
915 //purpose  : 
916 //=======================================================================
917
918 void AIS_InteractiveContext::ClearSelected(const Standard_Boolean updateviewer)
919 {
920   if(!HasOpenedContext())
921     ClearCurrents(updateviewer);
922   else 
923     myLocalContexts(myCurLocalIndex)->ClearSelected(updateviewer);
924   
925 }
926
927
928 //=======================================================================
929 //function : SetSelectedCurrent
930 //purpose  : 
931 //=======================================================================
932
933 void AIS_InteractiveContext::SetSelectedCurrent()
934 {
935
936
937 #ifdef DEB
938   cout<<"Not Yet Implemented"<<endl;
939 #endif
940 }
941
942 //=======================================================================
943 //function : UpdateSelection
944 //purpose  : 
945 //=======================================================================
946
947 void AIS_InteractiveContext::UpdateSelected(const Standard_Boolean updateviewer)
948 {
949   if(!HasOpenedContext()) {
950     HilightSelected();
951 #ifndef BUG
952     return;
953 #endif
954   }
955   myLocalContexts(myCurLocalIndex)->UpdateSelected(updateviewer);
956 }
957
958 //=======================================================================
959 //function : SetCurrentObject
960 //purpose  : 
961 //=======================================================================
962 void AIS_InteractiveContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,const Standard_Boolean updateviewer)
963 {
964   if(!HasOpenedContext()) 
965     SetCurrentObject(anIObj,updateviewer);
966   else
967     myLocalContexts(myCurLocalIndex)->SetSelected(anIObj,updateviewer);
968 }
969
970 //=======================================================================
971 //function : AddOrRemoveSelected
972 //purpose  : 
973 //=======================================================================
974
975 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)& anIObj,
976                                                  const Standard_Boolean updateviewer)
977 {
978   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
979   if(!HasOpenedContext())
980     AddOrRemoveCurrentObject(anIObj,updateviewer);
981   else
982     myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(anIObj,updateviewer);
983   
984 }
985 //=======================================================================
986 //function : AddOrRemoveSelected
987 //purpose  : 
988 //=======================================================================
989
990 void AIS_InteractiveContext::AddOrRemoveSelected(const TopoDS_Shape& aShap,
991                                             const Standard_Boolean updateviewer)
992
993   if(!HasOpenedContext()) {
994 #ifdef DEB
995     cout<<" Attempt to remove a selected shape with no opened local context"<<endl;
996 #endif
997     return;
998   }
999   
1000   myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(aShap,updateviewer);
1001   if(updateviewer) UpdateCurrentViewer();
1002   
1003 }
1004 //=======================================================================
1005 //function : AddOrRemoveSelected
1006 //purpose  : 
1007 //=======================================================================
1008
1009 void AIS_InteractiveContext::AddOrRemoveSelected(const Handle(SelectMgr_EntityOwner)& Own,
1010                                                  const Standard_Boolean updateviewer)
1011
1012   if(!HasOpenedContext()) {
1013 #ifdef DEB
1014     cout<<" Attempt to remove a selected ownr with no opened local context"<<endl;
1015 #endif
1016     return;
1017   }
1018   
1019   myLocalContexts(myCurLocalIndex)->AddOrRemoveSelected(Own,Standard_False);
1020   if(updateviewer) UpdateCurrentViewer();
1021   
1022 }
1023
1024
1025
1026 //=======================================================================
1027 //function : IsSelected
1028 //purpose  : 
1029 //=======================================================================
1030
1031 Standard_Boolean AIS_InteractiveContext::
1032 IsSelected(const Handle(AIS_InteractiveObject)& anIObj) const 
1033 {
1034   if (anIObj.IsNull()) return Standard_False;
1035   
1036   if(!HasOpenedContext()) 
1037     return (anIObj->State()==1);
1038   else 
1039     return myLocalContexts(myCurLocalIndex)->IsSelected(anIObj);
1040 }
1041
1042
1043 //=======================================================================
1044 //function : InitSelected
1045 //purpose  : 
1046 //=======================================================================
1047
1048 void AIS_InteractiveContext::InitSelected()
1049 {
1050   if(!HasOpenedContext())
1051     AIS_Selection::Selection(myCurrentName.ToCString())->Init();
1052   else
1053     myLocalContexts(myCurLocalIndex)->InitSelected();
1054 }
1055
1056 //=======================================================================
1057 //function : MoreSelected
1058 //purpose  : 
1059 //=======================================================================
1060
1061 Standard_Boolean AIS_InteractiveContext::MoreSelected() const 
1062 {
1063   if(!HasOpenedContext())
1064     return AIS_Selection::Selection(myCurrentName.ToCString())->More();
1065   return myLocalContexts(myCurLocalIndex)->MoreSelected();
1066 }
1067
1068 //=======================================================================
1069 //function : NextSelected
1070 //purpose  : 
1071 //=======================================================================
1072
1073 void AIS_InteractiveContext::NextSelected()
1074 {
1075   if(!HasOpenedContext())
1076     AIS_Selection::Selection(myCurrentName.ToCString())->Next();
1077   else
1078     myLocalContexts(myCurLocalIndex)->NextSelected();
1079 }
1080
1081 //=======================================================================
1082 //function : HasSelectedShape
1083 //purpose  : 
1084 //=======================================================================
1085
1086 Standard_Boolean AIS_InteractiveContext::HasSelectedShape() const 
1087 {
1088   if(!HasOpenedContext()) {
1089 #ifdef IMP280200
1090     Handle(AIS_Shape) shape = 
1091         Handle(AIS_Shape)::DownCast(SelectedInteractive());
1092     if( !shape.IsNull() ) return Standard_True;
1093 #endif
1094     return Standard_False;
1095   }
1096   return myLocalContexts(myCurLocalIndex)->HasShape();
1097   
1098   
1099 }
1100
1101 //=======================================================================
1102 //function : SelectedShape
1103 //purpose  : 
1104 //=======================================================================
1105
1106 TopoDS_Shape AIS_InteractiveContext::SelectedShape() const 
1107 {
1108
1109   if(!HasOpenedContext()){
1110     TopoDS_Shape sh;
1111 #ifdef IMP280200
1112     Handle(AIS_Shape) shape = 
1113         Handle(AIS_Shape)::DownCast(SelectedInteractive());
1114     if( !shape.IsNull() ) sh = shape->Shape();
1115 #endif
1116     return sh;
1117   } else
1118     return myLocalContexts(myCurLocalIndex)->SelectedShape();
1119 }
1120
1121 //=======================================================================
1122 //function : Interactive
1123 //purpose  : 
1124 //=======================================================================
1125
1126 Handle(AIS_InteractiveObject) AIS_InteractiveContext::Interactive() const 
1127 {
1128   return SelectedInteractive();
1129 }
1130
1131 Handle(AIS_InteractiveObject) AIS_InteractiveContext::SelectedInteractive() const 
1132 {
1133   if(!HasOpenedContext()){
1134     Handle(Standard_Transient) TR  =AIS_Selection::Selection(myCurrentName.ToCString())->Value();
1135     Handle(AIS_InteractiveObject) IO = *((Handle(AIS_InteractiveObject)*)&TR);
1136     return IO;}
1137   
1138   return  myLocalContexts(myCurLocalIndex)->SelectedInteractive();
1139   
1140 }
1141 //=======================================================================
1142 //function : Interactive
1143 //purpose  : 
1144 //=======================================================================
1145
1146 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::SelectedOwner() const 
1147 {
1148   if(!HasOpenedContext()){
1149     Handle(SelectMgr_EntityOwner) Ownr;
1150     return Ownr;
1151   }
1152   return  myLocalContexts(myCurLocalIndex)->SelectedOwner();
1153   
1154 }
1155
1156 //=======================================================================
1157 //function : EntityOwners
1158 //purpose  : 
1159 //=======================================================================
1160 void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners,
1161                                           const Handle(AIS_InteractiveObject)& theIObj,
1162                                           const Standard_Integer theMode) const 
1163 {
1164   if ( theIObj.IsNull() )
1165       return;
1166
1167   TColStd_ListOfInteger aModes;
1168   if ( theMode == -1 )
1169     ActivatedModes( theIObj, aModes );
1170   else
1171     aModes.Append( theMode );
1172
1173   TColStd_ListIteratorOfListOfInteger anItr( aModes );
1174   for (; anItr.More(); anItr.Next() )
1175   {
1176     int aMode = anItr.Value();
1177     if ( !theIObj->HasSelection( aMode ) )
1178       continue;
1179
1180     Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
1181
1182     for ( aSel->Init(); aSel->More(); aSel->Next() )
1183     {
1184       Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
1185       if ( aEntity.IsNull() )
1186         continue;
1187
1188       Handle(SelectMgr_EntityOwner) aOwner =
1189         Handle(SelectMgr_EntityOwner)::DownCast(aEntity->OwnerId());
1190       if ( !aOwner.IsNull() )
1191         theOwners.Add( aOwner );
1192     }
1193   }
1194 }
1195
1196 Standard_Integer AIS_InteractiveContext::NbSelected() 
1197 {
1198   Standard_Integer i(0);
1199   for(InitSelected();MoreSelected();NextSelected())
1200     {i++;}
1201   return i;
1202 }
1203
1204 //=======================================================================
1205 //function : HasApplicative
1206 //purpose  : 
1207 //=======================================================================
1208
1209   Standard_Boolean AIS_InteractiveContext::HasApplicative() const 
1210 {
1211   return Interactive()->HasOwner();
1212 }
1213
1214 //=======================================================================
1215 //function : Applicative
1216 //purpose  : 
1217 //=======================================================================
1218
1219 Handle(Standard_Transient) AIS_InteractiveContext::Applicative() const 
1220 {
1221   return Interactive()->GetOwner();
1222 }
1223
1224
1225
1226 //==================================================
1227 // Function: 
1228 // Purpose :
1229 //==================================================
1230 Standard_Boolean AIS_InteractiveContext::HasDetected() const 
1231 {
1232   if(HasOpenedContext())
1233     return myLocalContexts(myCurLocalIndex)->HasDetected();
1234   else
1235     return !myLastPicked.IsNull();
1236 }
1237
1238 //=======================================================================
1239 //function : HasDetectedShape
1240 //purpose  : 
1241 //=======================================================================
1242
1243 Standard_Boolean AIS_InteractiveContext::HasDetectedShape() const 
1244 {
1245   if(HasOpenedContext())
1246     return myLocalContexts(myCurLocalIndex)->HasDetectedShape();
1247   return Standard_False;
1248 }
1249
1250 //=======================================================================
1251 //function : DetectedShape
1252 //purpose  : 
1253 //=======================================================================
1254
1255 const TopoDS_Shape&
1256 AIS_InteractiveContext::DetectedShape() const
1257 {
1258   return myLocalContexts(myCurLocalIndex)->DetectedShape();
1259 }                                           
1260
1261 //=======================================================================
1262 //function : DetectedInteractive
1263 //purpose  : 
1264 //=======================================================================
1265
1266 Handle(AIS_InteractiveObject) 
1267 AIS_InteractiveContext::DetectedInteractive() const 
1268 {
1269   if(HasOpenedContext())
1270     return myLocalContexts(myCurLocalIndex)->DetectedInteractive();
1271   return myLastPicked;
1272 }
1273
1274
1275 Standard_Boolean AIS_InteractiveContext::HasNextDetected() const 
1276 {
1277   if(!HasOpenedContext())
1278     return Standard_False; // temporaire
1279   else
1280     return myLocalContexts(myCurLocalIndex)->HasNextDetected();
1281   
1282 }
1283
1284
1285 //=======================================================================
1286 //function : DetectedOwner
1287 //purpose  : 
1288 //=======================================================================
1289 Handle(SelectMgr_EntityOwner) AIS_InteractiveContext::DetectedOwner() const
1290 {
1291   if(HasOpenedContext())
1292     return myLocalContexts(myCurLocalIndex)->DetectedOwner();
1293   Handle(SelectMgr_EntityOwner) Ownr;
1294   return Ownr;
1295 }
1296
1297
1298 //=======================================================================
1299 //function : HilightNextDetected
1300 //purpose  :
1301 //=======================================================================
1302 Standard_Integer AIS_InteractiveContext::HilightNextDetected (const Handle(V3d_View)& theView,
1303                                                               const Standard_Boolean  theToRedrawImmediate)
1304 {
1305   return HasOpenedContext()
1306        ? myLocalContexts (myCurLocalIndex)->HilightNextDetected (theView, theToRedrawImmediate)
1307        : 0;
1308     
1309 }
1310
1311 //=======================================================================
1312 //function : HilightNextDetected
1313 //purpose  :
1314 //=======================================================================
1315 Standard_Integer AIS_InteractiveContext::HilightPreviousDetected (const Handle(V3d_View)& theView,
1316                                                                   const Standard_Boolean  theToRedrawImmediate)
1317 {
1318   return HasOpenedContext()
1319        ? myLocalContexts (myCurLocalIndex)->HilightPreviousDetected (theView, theToRedrawImmediate)
1320        : 0;
1321     
1322 }
1323
1324 //=======================================================================
1325 //function : InitDetected
1326 //purpose  :
1327 //=======================================================================
1328 void AIS_InteractiveContext::InitDetected()
1329 {
1330   if (HasOpenedContext())
1331   {
1332     myLocalContexts(myCurLocalIndex)->InitDetected();
1333     return;
1334   }
1335
1336   if(myAISDetectedSeq.Length() != 0)
1337   {
1338     myAISCurDetected = 1;
1339   }
1340 }
1341
1342 //=======================================================================
1343 //function : MoreDetected
1344 //purpose  :
1345 //=======================================================================
1346 Standard_Boolean AIS_InteractiveContext::MoreDetected() const
1347 {
1348   if (HasOpenedContext())
1349   {
1350     return myLocalContexts(myCurLocalIndex)->MoreDetected();
1351   }
1352
1353   return (myAISCurDetected > 0 && myAISCurDetected <= myAISDetectedSeq.Length()) ?
1354           Standard_True : Standard_False;
1355 }
1356
1357 //=======================================================================
1358 //function : NextDetected
1359 //purpose  :
1360 //=======================================================================
1361 void AIS_InteractiveContext::NextDetected()
1362 {
1363   if(HasOpenedContext())
1364   {
1365     myLocalContexts(myCurLocalIndex)->NextDetected();
1366     return;
1367   }
1368
1369   myAISCurDetected++;
1370 }
1371
1372 //=======================================================================
1373 //function : DetectedCurrentShape
1374 //purpose  :
1375 //=======================================================================
1376 const TopoDS_Shape& AIS_InteractiveContext::DetectedCurrentShape() const
1377 {
1378   if (HasOpenedContext())
1379   {
1380     return myLocalContexts(myCurLocalIndex)->DetectedCurrentShape();
1381   }
1382
1383   static TopoDS_Shape aDummyShape;
1384
1385   Handle(AIS_Shape) aCurrentShape = Handle(AIS_Shape)::DownCast (DetectedCurrentObject());
1386
1387   if (aCurrentShape.IsNull())
1388   {
1389     return aDummyShape;
1390   }
1391
1392   return aCurrentShape->Shape();
1393 }
1394
1395 //=======================================================================
1396 //function : DetectedCurrentObject
1397 //purpose  :
1398 //=======================================================================
1399 Handle(AIS_InteractiveObject) AIS_InteractiveContext::DetectedCurrentObject() const
1400 {
1401   if (HasOpenedContext())
1402   {
1403     return myLocalContexts(myCurLocalIndex)->DetectedCurrentObject();
1404   }
1405
1406   return MoreDetected() ? myAISDetectedSeq(myAISCurDetected) : NULL;
1407 }