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