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