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