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