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