Integration of OCCT 6.5.0 from SVN
[occt.git] / src / AIS / AIS_InteractiveContext_2.cxx
1 // File:        AIS_InteractiveContext_2.cxx
2 // Created:     Wed Jan 29 10:55:05 1997
3 // Author:      Robert COUBLANC
4 //              <rob@robox.paris1.matra-dtv.fr>
5
6 #define IMP051001       //GG Adds SetZDetected() and ZDetected() methods
7
8 #include <AIS_InteractiveContext.jxx>
9
10 #include <AIS_LocalContext.hxx>
11
12 #include <AIS_GlobalStatus.hxx>
13 #include <TColStd_ListIteratorOfListOfInteger.hxx>
14
15 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
16 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
17 #include <Graphic3d_StructureManager.hxx>
18 #include <Graphic3d_Structure.hxx>
19 #include <Graphic3d_MapOfStructure.hxx>
20 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
21 #include <AIS_Selection.hxx>
22
23
24 static TColStd_ListIteratorOfListOfInteger ItL;
25 //=======================================================================
26 //function : OpenLocalContext
27 //purpose  : 
28 //=======================================================================
29
30 Standard_Integer AIS_InteractiveContext::
31 OpenLocalContext(const Standard_Boolean UseDisplayedObjects, 
32                  const Standard_Boolean AllowShapeDecomposition, 
33                  const Standard_Boolean AcceptEraseOfTemporary,
34                  const Standard_Boolean /*BothViewers*/)
35 {
36
37   // on dehilighte les eventuelles entitees detectees juste avant l'ouverture
38   // du contexte...
39   if(!IsCurrent(myLastPicked)){
40     if(!myLastPicked.IsNull()){
41       Standard_Integer HiMod = myLastPicked->HasHilightMode()?myLastPicked->HilightMode():0;
42       myMainPM->Unhighlight(myLastPicked,HiMod);
43     }}
44   
45   if(!mylastmoveview.IsNull()){
46     if(myCurLocalIndex>0)
47       myLocalContexts(myCurLocalIndex)->UnhilightLastDetected(mylastmoveview);
48   }
49   
50   // on met a 0 les entites liees a la selection dynamique au point neutre.
51   
52   myLastinMain.Nullify();
53   myLastinColl.Nullify();
54   myLastPicked.Nullify();
55   myWasLastMain = Standard_True;
56
57
58
59   Standard_Integer untilnow = myCurLocalIndex;
60   
61   myCurLocalIndex = HighestIndex() + 1;
62   
63   Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
64                                                           UseDisplayedObjects,
65                                                           AllowShapeDecomposition,
66                                                           AcceptEraseOfTemporary);
67   
68   // rob 16/04/97 pour les Pbs d'ordres asynchrones
69   if(myLocalContexts.Extent()>0){
70     const Select3D_Projector& Prj = myLocalContexts(untilnow)->MainSelector()->Projector();
71     NewLocal->MainSelector()->Set(Prj);
72   }
73   else{
74     const Select3D_Projector& Prj = myMainSel->Projector();
75     NewLocal->MainSelector()->Set(Prj);
76   }
77   
78   NewLocal->MainSelector()->UpdateConversion();
79   
80   myLocalContexts.Bind(myCurLocalIndex,NewLocal);
81
82
83 #ifdef DEB
84   cout<<"\tOpen Local Context No "<<myCurLocalIndex<<endl;
85   if(UseDisplayedObjects){
86     cout<<"\t\tObjects from Neutral Point loaded"<<endl;
87     if(AllowShapeDecomposition)
88       cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
89     else
90       cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
91   }
92   else
93     cout<<"\t\tNo Objects Were Loaded "<<endl;
94 #endif
95   return myCurLocalIndex;
96   
97 }
98
99 //=======================================================================
100 //function : CloseLocalContext
101 //purpose  : 
102 //=======================================================================
103
104 void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
105                                                const Standard_Boolean updateviewer)
106 {
107
108  Standard_Boolean debugmode(Standard_False);
109 #ifdef DEB 
110  debugmode = Standard_True;
111 #endif
112  
113  Standard_Integer GoodIndex = (Index ==-1) ? myCurLocalIndex : Index;
114
115  if(debugmode) cout<<"Call to CloseLocalContext - Index  "<<GoodIndex<<endl;
116  if(!HasOpenedContext()){
117    if(debugmode) cout<<"\t But No Local Context is opened"<<endl;
118    return;
119  }
120  if(!myLocalContexts.IsBound(GoodIndex)) {
121    if(debugmode) cout<<" Attempt to Close a non-existent Local Context"<<endl;
122    return;
123  }
124  
125  // On va fermer le seul contexte local ouvert...
126  if(myLocalContexts.Extent()==1 && GoodIndex == myCurLocalIndex){
127    
128    Standard_Boolean updateproj = !(myLocalContexts(myCurLocalIndex)->HasSameProjector(myMainSel->Projector()));
129    myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
130    myLocalContexts.UnBind(myCurLocalIndex);
131    myCurLocalIndex = 0;
132
133    ResetOriginalState(Standard_False);
134    if(updateproj)
135      myMainSel->UpdateConversion();
136    else{
137      myMainSel->ReactivateProjector();
138      myMainSel->UpdateSort();
139    }
140    if(debugmode)
141      cout<<"No More Opened Local Context "<<endl;
142  }
143  
144  // Sinon on aura encore un contexte local d'ouvert apres la fermeture du courant
145  else{
146    Handle(StdSelect_ViewerSelector3d) VS = myLocalContexts(GoodIndex)->MainSelector();
147    myLocalContexts(GoodIndex)->Terminate();
148    myLocalContexts.UnBind(GoodIndex);
149    // on ferme le courant...
150    if(GoodIndex==myCurLocalIndex){
151      myCurLocalIndex = HighestIndex();
152      const Handle(AIS_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex);
153      if(LocCtx->HasSameProjector(VS->Projector())){
154        LocCtx->MainSelector()->ReactivateProjector();
155      }
156      else
157        LocCtx->MainSelector()->UpdateConversion();
158    }
159    else if(debugmode)
160      cout<<"a No Current Local Context WasClosed"<<endl;
161    
162    if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
163    
164  }
165    
166  
167  if(updateviewer) myMainVwr->Update();
168 }
169
170 //=======================================================================
171 //function : CloseAllContexts
172 //purpose  : 
173 //=======================================================================
174
175 void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
176 {
177   
178   while(!myLocalContexts.IsEmpty()){
179     CloseLocalContext(myCurLocalIndex,Standard_False);
180   }
181   
182   ResetOriginalState(Standard_False);
183
184   myMainSel->UpdateSort();
185   if(!myIsCollClosed && !myCollectorSel.IsNull())
186     myCollectorSel->UpdateSort();
187   if(updateviewer) myMainVwr->Update();
188 }
189
190 //=======================================================================
191 //function : IndexOfCurrentLocal
192 //purpose  : 
193 //=======================================================================
194
195 Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
196 {
197   return myCurLocalIndex;
198 }
199
200 //=======================================================================
201 //function : ClearLocalContext
202 //purpose  : 
203 //=======================================================================
204
205 void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
206 {
207   if (!HasOpenedContext()) return;
208   myLocalContexts(myCurLocalIndex)->Clear(aMode);
209
210 }
211
212 //=======================================================================
213 //function : HighestIndex
214 //purpose  : 
215 //=======================================================================
216
217 Standard_Integer AIS_InteractiveContext::HighestIndex() const
218 {
219   AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
220   Standard_Integer HiInd = 0;
221   for(;It.More();It.Next())
222     HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
223   return HiInd;
224
225 }
226
227
228 //=======================================================================
229 //function : Activate
230 //purpose  : 
231 //=======================================================================
232
233 void AIS_InteractiveContext::
234 Activate(const Handle(AIS_InteractiveObject)& anIObj, 
235          const Standard_Integer aMode)
236 {
237   if(!HasOpenedContext()){
238     if(!myObjects.IsBound(anIObj)) return;
239     const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
240     if(STAT->GraphicStatus()==AIS_DS_Displayed)
241       mgrSelector->Activate(anIObj,aMode,myMainSel);
242     STAT ->AddSelectionMode(aMode);
243   }
244   else{
245    myLocalContexts(myCurLocalIndex)->ActivateMode(anIObj,aMode);
246   }
247 }
248
249 //=======================================================================
250 //function : LocalSelector
251 //purpose  : 
252 //=======================================================================
253 Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const
254 {
255   if( !HasOpenedContext() )
256       return Handle( StdSelect_ViewerSelector3d )();
257   else
258       return myLocalContexts( myCurLocalIndex )->MainSelector();
259 }
260
261
262 //=======================================================================
263 //function : DeActivate
264 //purpose  : 
265 //=======================================================================
266 void AIS_InteractiveContext::
267 Deactivate(const Handle(AIS_InteractiveObject)& anIObj)
268 {
269   if(!HasOpenedContext()){
270     if(!myObjects.IsBound(anIObj)) return;
271     for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
272         ItL.More();
273         ItL.Next()){
274       if(myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
275         mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
276     }
277     myObjects(anIObj)->ClearSelectionModes();
278   }
279   else{
280     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
281     LC->Deactivate(anIObj);
282   }
283 }
284
285 //=======================================================================
286 //function : Deactivate
287 //purpose  : 
288 //=======================================================================
289
290 void AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)& anIObj, 
291            const Standard_Integer aMode)
292 {
293   if(!HasOpenedContext()){
294     if(!myObjects.IsBound(anIObj)) return;
295     const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
296
297     if(STAT->GraphicStatus() == AIS_DS_Displayed)
298       mgrSelector->Deactivate(anIObj,aMode,myMainSel);
299     STAT->RemoveSelectionMode(aMode);
300   }
301   else{
302    myLocalContexts(myCurLocalIndex)->DeactivateMode(anIObj,aMode);
303   }
304 }
305
306 //=======================================================================
307 //function : ActivatedModes
308 //purpose  : 
309 //=======================================================================
310
311 void AIS_InteractiveContext::
312 ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj, 
313                TColStd_ListOfInteger& theList) const 
314 {
315   if(!HasOpenedContext()){
316     if(myObjects.IsBound(anIObj)){
317       //ItL est une variable statique... 
318       for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
319           ItL.More();
320           ItL.Next())
321         theList.Append(ItL.Value());
322       
323     }
324   }
325   else{
326     if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){
327       for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj));
328           ItL.More();
329           ItL.Next())
330         theList.Append(ItL.Value());
331     }
332   }
333 }
334
335 //=======================================================================
336 //function : SetShapeDecomposition
337 //purpose  : 
338 //=======================================================================
339
340 void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj,
341                                                    const Standard_Boolean StdModeSensitive)
342 {
343   if(!HasOpenedContext()) return;
344   myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive);
345 }
346
347 //=======================================================================
348 //function : SetTemporaryAttributes
349 //purpose  : 
350 //=======================================================================
351
352 void AIS_InteractiveContext::
353 SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/,
354                        const Handle(Prs3d_Drawer)& /*aDrawer*/,
355                        const Standard_Boolean /*updateviewer*/)
356 {
357 }
358
359 //=======================================================================
360 //function : SubIntensityOn
361 //purpose  : 
362 //=======================================================================
363 void AIS_InteractiveContext::
364 SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
365                const Standard_Boolean updateviewer)
366 {
367   if(!HasOpenedContext()){
368     if(!myObjects.IsBound(anIObj))
369       return;
370     const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
371     if(GB->IsSubIntensityOn())
372       return;
373     GB->SubIntensityOn();
374     Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
375     
376     for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
377       if(GB->GraphicStatus()==AIS_DS_Displayed){
378         myMainPM->Color(anIObj,mySubIntensity,It.Value());
379         UpdMain = Standard_True;}
380       else if(GB->GraphicStatus()==AIS_DS_Erased){
381         myCollectorPM->Color(anIObj,mySubIntensity,It.Value());
382         UpdColl=Standard_True;
383       }
384     }
385     if(updateviewer){
386       if(UpdMain)
387         myMainVwr->Update();
388       if(UpdColl)
389         myCollectorVwr->Update();
390     }
391   }
392   else {
393     if(myObjects.IsBound(anIObj)){
394       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
395       STAT->SubIntensityOn();
396       for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
397         myMainPM->Color(anIObj,mySubIntensity,ItL.Value());
398     }
399     else
400       myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
401     
402     if(updateviewer) myMainVwr->Update();
403   }
404 }
405 //=======================================================================
406 //function : SubIntensityOff
407 //purpose  : 
408 //=======================================================================
409
410 void AIS_InteractiveContext::
411 SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj,
412                 const Standard_Boolean updateviewer)
413 {
414   if(!HasOpenedContext()){
415     if(!myObjects.IsBound(anIObj))
416       return;
417     const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
418     if(!GB->IsSubIntensityOn())
419       return;
420     GB->SubIntensityOff();
421     Standard_Boolean UpdMain(Standard_False),UpdColl(Standard_False);
422     
423     for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
424       if(GB->GraphicStatus()!=AIS_DS_Erased){
425         myMainPM->Unhighlight(anIObj,It.Value());
426         UpdMain = Standard_True;}
427       else {
428         myCollectorPM->Unhighlight(anIObj,It.Value());
429         UpdColl=Standard_True;
430       }
431     }
432     
433     Standard_Integer DM,HM,SM;
434     GetDefModes(anIObj,DM,HM,SM);
435     if(AIS_Selection::IsSelected(anIObj))
436       myMainPM->Highlight(anIObj,HM);
437     
438     if(updateviewer){
439       if(UpdMain)
440         myMainVwr->Update();
441       if(UpdColl)
442         myCollectorVwr->Update();
443     }
444   }
445   else {
446     if(myObjects.IsBound(anIObj)){
447       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
448       STAT->SubIntensityOff();
449       for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
450         myMainPM->Unhighlight(anIObj,ItL.Value());
451       if(STAT->IsHilighted())
452         Hilight(anIObj);
453     }
454     else
455       myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
456     if(IsSelected(anIObj))
457       Hilight(anIObj);
458     
459     if(updateviewer) myMainVwr->Update();
460   }
461 }
462
463 //=======================================================================
464 //function : SubIntensityOn
465 //purpose  : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY...
466 //=======================================================================
467
468 void AIS_InteractiveContext::SubIntensityOn(const Standard_Boolean updateviewer)
469 {
470   if(!HasOpenedContext()) return;
471   
472   AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
473   TColStd_ListIteratorOfListOfInteger ItM;
474   for(;It.More();It.Next()){
475     const Handle(AIS_GlobalStatus)& STAT = It.Value();
476     if(STAT->GraphicStatus()==AIS_DS_Displayed)
477       {
478         STAT->SubIntensityOn();
479         for(ItM.Initialize(STAT->DisplayedModes());ItM.More();ItM.Next())
480           {myMainPM->Color(It.Key(),mySubIntensity,ItM.Value());}
481       }
482   }
483   if(updateviewer) myMainVwr->Update();
484 }
485
486 //=======================================================================
487 //function : SubIntensityOff
488 //purpose  : 
489 //=======================================================================
490 void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer)
491 {
492   
493   if(!HasOpenedContext()) return;
494   
495   AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
496   
497   for(;It.More();It.Next()){
498     const Handle(AIS_GlobalStatus)& STAT = It.Value();
499     if(STAT->IsSubIntensityOn())
500       STAT->SubIntensityOff();
501     for(ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
502       myMainPM->Unhighlight(It.Key());
503   }
504   
505   if(updateviewer) myMainVwr->Update();
506 }
507
508 //=======================================================================
509 //function : AddFilter
510 //purpose  : 
511 //=======================================================================
512 void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
513 {
514   if(HasOpenedContext())
515     myLocalContexts(myCurLocalIndex)->AddFilter(aFilter);
516   else
517     myFilters->Add(aFilter);
518 }
519
520 //=======================================================================
521 //function : ActivateStandardMode
522 //purpose  : 
523 //=======================================================================
524 void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
525 {
526   if(!HasOpenedContext()) return;
527   myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation);
528 }
529
530 //=======================================================================
531 //function : DeActivateStandardMode
532 //purpose  : 
533 //=======================================================================
534 void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
535 {
536   if(!HasOpenedContext()) return;
537   myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation);
538 }
539
540 //=======================================================================
541 //function : RemoveFilter
542 //purpose  : 
543 //=======================================================================
544 void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
545 {
546   if(HasOpenedContext())
547     myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter);
548   else
549     myFilters->Remove(aFilter);
550 }
551
552 //=======================================================================
553 //function : RemoveFilters
554 //purpose  : 
555 //=======================================================================
556
557 void AIS_InteractiveContext::RemoveFilters()
558 {
559   if(!HasOpenedContext())
560     myFilters->Clear();
561   else
562     myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters);
563 }
564
565 //=======================================================================
566 //function : ActivatedStandardModes
567 //purpose  : 
568 //=======================================================================
569 const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const 
570 {
571   return myLocalContexts(myCurLocalIndex)->StandardModes();
572 }
573
574 //=======================================================================
575 //function : Filters
576 //purpose  : 
577 //=======================================================================
578 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
579 {
580   if(HasOpenedContext())
581     return myLocalContexts(myCurLocalIndex)->ListOfFilter();
582   return myFilters->StoredFilters();
583 }
584
585 //=======================================================================
586 //function : DisplayActiveAreas
587 //purpose  : 
588 //=======================================================================
589 void AIS_InteractiveContext::DisplayActiveAreas(const Handle(V3d_View)& aviou)
590 {
591   if(HasOpenedContext())
592     myLocalContexts(myCurLocalIndex)->DisplayAreas(aviou);
593   else
594     myMainSel->DisplayAreas(aviou);
595   
596 }
597
598 //=======================================================================
599 //function : ClearActiveAreas
600 //purpose  : 
601 //=======================================================================
602 void AIS_InteractiveContext::ClearActiveAreas(const Handle(V3d_View)& aviou)
603 {
604   if(HasOpenedContext())
605     myLocalContexts(myCurLocalIndex)->ClearAreas(aviou);
606   else
607     myMainSel->ClearAreas(aviou);
608 }
609
610 //=======================================================================
611 //function : DisplayActiveSensitive
612 //purpose  : 
613 //=======================================================================
614 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
615 {
616   if(HasOpenedContext())
617     myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou);
618   else
619     myMainSel->DisplaySensitive(aviou);
620 }
621 //=======================================================================
622 //function : DisplayActiveSensitive
623 //purpose  : 
624 //=======================================================================
625
626 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj,
627                                                     const Handle(V3d_View)& aviou)
628 {
629   TColStd_ListIteratorOfListOfInteger It;
630   Handle(StdSelect_ViewerSelector3d) VS;
631   if(HasOpenedContext()){
632     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
633     if(!LC->IsIn(anIObj)) return;
634     It.Initialize(LC->SelectionModes(anIObj));
635     VS = LC->MainSelector();
636   }
637   else{
638     if(!myObjects.IsBound(anIObj)) return;
639     It.Initialize(myObjects(anIObj)->SelectionModes());
640     VS = myMainSel;
641   }
642   
643   
644   for(;It.More();It.Next()){
645     const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
646     VS->DisplaySensitive(Sel,aviou,Standard_False);
647   }  
648   
649 }
650
651 //=======================================================================
652 //function : DisplayActiveAreas
653 //purpose  : 
654 //=======================================================================
655
656 void AIS_InteractiveContext::DisplayActiveAreas(const Handle(AIS_InteractiveObject)& anIObj,
657                                                 const Handle(V3d_View)& aviou)
658 {
659   TColStd_ListIteratorOfListOfInteger It;
660   Handle(StdSelect_ViewerSelector3d) VS;
661   if(HasOpenedContext()){
662     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
663     if(!LC->IsIn(anIObj)) return;
664     It.Initialize(LC->SelectionModes(anIObj));
665     VS = LC->MainSelector();
666   }
667   else{
668     if(!myObjects.IsBound(anIObj)) return;
669     It.Initialize(myObjects(anIObj)->SelectionModes());
670     VS = myMainSel;
671   }
672   
673   
674   for(;It.More();It.Next()){
675     const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
676     VS->DisplayAreas(Sel,aviou,Standard_False);
677   }  
678   
679 }
680   
681 //=======================================================================
682 //function : ClearActiveSensitive
683 //purpose  : 
684 //=======================================================================
685 void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou)
686 {
687   
688   if(HasOpenedContext())
689     myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou);
690   else
691     myMainSel->ClearSensitive(aviou);
692 }
693
694 //=======================================================================
695 //function : SetAutomaticHilight
696 //purpose  : 
697 //=======================================================================
698 void  AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus)
699 {
700
701   if(HasOpenedContext())
702     myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
703 }
704
705 //=======================================================================
706 //function : AutomaticHilight
707 //purpose  : 
708 //=======================================================================
709 Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const 
710 {
711   if(HasOpenedContext())
712     return myLocalContexts(myCurLocalIndex)->AutomaticHilight();
713   return Standard_True;
714 }
715
716 //=======================================================================
717 //function : UseDisplayedObjects
718 //purpose  : 
719 //=======================================================================
720
721 void AIS_InteractiveContext::UseDisplayedObjects()
722 {
723   if(HasOpenedContext())
724     myLocalContexts(myCurLocalIndex)->LoadContextObjects();
725 }
726
727 //=======================================================================
728 //function : NotUseDisplayedObjects
729 //purpose  : 
730 //=======================================================================
731
732 void AIS_InteractiveContext::NotUseDisplayedObjects()
733 {
734   if(HasOpenedContext())
735     myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
736 }
737
738
739
740
741 //=======================================================================
742 //function : PurgeDisplay
743 //purpose  : 
744 //=======================================================================
745
746 Standard_Integer AIS_InteractiveContext::PurgeDisplay(const Standard_Boolean CollectorToo)
747 {
748   if(HasOpenedContext()) return 0;
749   
750   Standard_Integer NbStr = PurgeViewer(myMainVwr);
751   if(!myCollectorVwr.IsNull())
752     if(CollectorToo){
753       NbStr+=PurgeViewer(myCollectorVwr);
754       if(!IsCollectorClosed())
755         myCollectorVwr->Update();
756     }
757   myMainVwr->Update();
758   return NbStr;
759
760 }
761
762
763 //=======================================================================
764 //function : PurgeViewer
765 //purpose  : 
766 //=======================================================================
767 Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
768 {
769   const Handle(Graphic3d_StructureManager)& GSM = Vwr->Viewer();
770   Standard_Integer NbCleared(0);
771   Graphic3d_MapOfStructure SOS;
772   GSM->DisplayedStructures(SOS);
773
774   Handle(Graphic3d_Structure) G;
775   for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){
776     G = It.Key();
777     Standard_Address Add = G->Owner();
778     if(Add==NULL){
779       G->Erase();
780       G->Clear();// ca veut dire qu'elle n'est pas reference comme une presentation d'un InterfactiveObject...
781       NbCleared++;
782     }
783     Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add;
784     if(!myObjects.IsBound(IO)){
785       G->Erase();
786       NbCleared++;
787     }
788   }
789   return NbCleared;
790 }
791
792
793 //=======================================================================
794 //function : IsImmediateModeOn
795 //purpose  : 
796 //=======================================================================
797 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
798 {
799   if(!HasOpenedContext()) return Standard_False;
800   return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
801 }
802
803 Standard_Boolean  AIS_InteractiveContext::BeginImmediateDraw()
804 {
805   if(HasOpenedContext())
806     return myLocalContexts(myCurLocalIndex)->BeginImmediateDraw();
807   return Standard_False;
808 }
809
810 //=======================================================================
811 //function : ImmediateAdd
812 //purpose  : 
813 //=======================================================================
814
815 Standard_Boolean AIS_InteractiveContext::ImmediateAdd(const Handle(AIS_InteractiveObject)& anIObj,
816                                                       const Standard_Integer AMode)
817
818   if(HasOpenedContext()){
819     return myLocalContexts(myCurLocalIndex)->ImmediateAdd(anIObj,AMode);}
820   return Standard_False;
821 }
822
823 //=======================================================================
824 //function : ImmediateRemove
825 //purpose  : 
826 //=======================================================================
827
828 Standard_Boolean AIS_InteractiveContext::ImmediateRemove(const Handle(AIS_InteractiveObject)& anIObj,
829                                                          const Standard_Integer aMode)
830 {
831   if(HasOpenedContext())
832     return myLocalContexts(myCurLocalIndex)->ImmediateRemove(anIObj,aMode);
833   return Standard_False;
834 }
835
836 //=======================================================================
837 //function : EndImmediateDraw
838 //purpose  : 
839 //=======================================================================
840
841 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Handle(V3d_View)& aView,
842                                                           const Standard_Boolean DoubleBuf)
843 {
844   if(HasOpenedContext())
845     return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(aView,DoubleBuf);
846   return Standard_False;
847   
848 }
849
850 //=======================================================================
851 //function : EndImmediateDraw
852 //purpose  : 
853 //=======================================================================
854
855 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw(const Standard_Boolean DoubleBuf)
856 {
857   if(HasOpenedContext()){
858     Handle(V3d_View) V ;
859     myMainVwr->InitActiveViews();
860     if(myMainVwr->MoreActiveViews()){
861       V = myMainVwr->ActiveView();
862       
863       return myLocalContexts(myCurLocalIndex)->EndImmediateDraw(V,DoubleBuf);
864     }
865   }
866   return Standard_False;
867   
868 }
869
870
871 //=======================================================================
872 //function : ResetOriginalState
873 //purpose  : 
874 //=======================================================================
875
876 void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
877 {
878   Standard_Boolean upd_main(Standard_False),upd_col(Standard_False);
879   TColStd_ListIteratorOfListOfInteger itl;
880   
881   for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
882     const Handle(AIS_InteractiveObject)& iobj = it.Key();
883     const Handle(AIS_GlobalStatus)& STAT = it.Value();
884     switch(STAT->GraphicStatus()){
885     case AIS_DS_Displayed:{
886       upd_main = Standard_True;
887       
888       // partie display...
889       for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
890         myMainPM->Display(iobj,itl.Value());
891       if(STAT->IsHilighted()){
892         if(STAT->HilightColor()!=Quantity_NOC_WHITE)
893           HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
894         else
895           Hilight(iobj,Standard_False);
896       }
897       //partie selection
898       for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
899         if(itl.Value()!=-1)
900           mgrSelector->Activate(iobj,itl.Value(),myMainSel);
901       }
902       break; 
903     }
904     case AIS_DS_Erased:{
905       upd_col = Standard_True;
906       EraseGlobal(iobj,Standard_False,Standard_True);
907       break;
908     }
909     case AIS_DS_FullErased:{
910       EraseGlobal(iobj,Standard_False,Standard_False);
911       break;
912     }
913     default:
914       break;
915     }
916   }
917   if(updateviewer){
918     if(upd_main) 
919       myMainVwr->Update();
920     if(upd_col)
921       myCollectorVwr->Update();
922   }
923 }
924
925 #ifdef IMP051001
926 //=======================================================================
927 //function : SetZDetection
928 //purpose  : 
929 //=======================================================================
930 void  AIS_InteractiveContext::SetZDetection(const Standard_Boolean aStatus)
931 {
932   myZDetectionFlag = aStatus;
933 }
934
935 //=======================================================================
936 //function : ZDetection 
937 //purpose  : 
938 //=======================================================================
939 Standard_Boolean AIS_InteractiveContext::ZDetection() const 
940 {
941   return myZDetectionFlag;
942 }
943 #endif