0026945: Visualization - selection does not work after closing one of local contexts...
[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-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
18 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
19 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
20 #include <AIS_GlobalStatus.hxx>
21 #include <AIS_InteractiveContext.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <AIS_LocalContext.hxx>
24 #include <AIS_Selection.hxx>
25 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
26 #include <Graphic3d_MapOfStructure.hxx>
27 #include <Graphic3d_Structure.hxx>
28 #include <Graphic3d_StructureManager.hxx>
29 #include <Prs3d_BasicAspect.hxx>
30 #include <Prs3d_LineAspect.hxx>
31 #include <Quantity_Color.hxx>
32 #include <SelectMgr_EntityOwner.hxx>
33 #include <SelectMgr_Filter.hxx>
34 #include <SelectMgr_OrFilter.hxx>
35 #include <SelectMgr_SelectionManager.hxx>
36 #include <Standard_Transient.hxx>
37 #include <StdSelect_ViewerSelector3d.hxx>
38 #include <TCollection_AsciiString.hxx>
39 #include <TCollection_ExtendedString.hxx>
40 #include <TColStd_ListIteratorOfListOfInteger.hxx>
41 #include <TopLoc_Location.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <V3d_View.hxx>
44 #include <V3d_Viewer.hxx>
45
46 //=======================================================================
47 //function : OpenLocalContext
48 //purpose  : 
49 //=======================================================================
50 Standard_Integer AIS_InteractiveContext::
51 OpenLocalContext(const Standard_Boolean UseDisplayedObjects, 
52                  const Standard_Boolean AllowShapeDecomposition, 
53                  const Standard_Boolean AcceptEraseOfTemporary,
54                  const Standard_Boolean /*BothViewers*/)
55 {
56
57   // the entities eventually detected just before the context was opened are unhighlighted...
58   if(!IsSelected(myLastPicked)){
59     if(!myLastPicked.IsNull()){
60       const Handle(AIS_InteractiveObject) aLastPickedAIS =
61         Handle(AIS_InteractiveObject)::DownCast (myLastPicked->Selectable());
62       Standard_Integer HiMod = aLastPickedAIS->HasHilightMode()?aLastPickedAIS->HilightMode():0;
63       myMainPM->Unhighlight (aLastPickedAIS, HiMod);
64     }}
65   
66   if(!mylastmoveview.IsNull()){
67     if(myCurLocalIndex>0)
68       myLocalContexts(myCurLocalIndex)->UnhilightLastDetected(mylastmoveview);
69   }
70   
71   // entities connected to dynamic selection at neutral point are set to 0.
72   
73   myLastinMain.Nullify();
74   myLastPicked.Nullify();
75   myWasLastMain = Standard_True;
76
77   myCurLocalIndex = HighestIndex() + 1;
78   
79   Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
80                                                           UseDisplayedObjects,
81                                                           AllowShapeDecomposition,
82                                                           AcceptEraseOfTemporary);
83   // the AIS_LocalContext bind itself to myLocalContexts
84   // because procedures performed in AIS_LocalContext constructor
85   // already may access myLocalContexts(myCurLocalIndex) (like methods AIS_LocalContext::IsSelected()).
86
87 #ifdef OCCT_DEBUG
88   cout<<"\tOpen Local Context No "<<myCurLocalIndex<<endl;
89   if(UseDisplayedObjects){
90     cout<<"\t\tObjects from Neutral Point loaded"<<endl;
91     if(AllowShapeDecomposition)
92       cout<<"\t\tDecomposition Authorized for Loaded Shapes"<<endl;
93     else
94       cout<<"\t\tNo Decomposition Authorized for Loaded Shapes"<<endl;
95   }
96   else
97     cout<<"\t\tNo Objects Were Loaded "<<endl;
98 #endif
99   return myCurLocalIndex;
100 }
101
102 //=======================================================================
103 //function : CloseLocalContext
104 //purpose  : 
105 //=======================================================================
106
107 void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
108                                                const Standard_Boolean updateviewer)
109 {
110
111  Standard_Boolean debugmode(Standard_False);
112 #ifdef OCCT_DEBUG
113  debugmode = Standard_True;
114 #endif
115  
116  Standard_Integer GoodIndex = (Index ==-1) ? myCurLocalIndex : Index;
117
118  if(debugmode) cout<<"Call to CloseLocalContext - Index  "<<GoodIndex<<endl;
119  if(!HasOpenedContext()){
120    if(debugmode) cout<<"\t But No Local Context is opened"<<endl;
121    return;
122  }
123  if(!myLocalContexts.IsBound(GoodIndex)) {
124    if(debugmode) cout<<" Attempt to Close a non-existent Local Context"<<endl;
125    return;
126  }
127  
128  // the only open local context is closed...
129  if(myLocalContexts.Extent()==1 && GoodIndex == myCurLocalIndex){
130    
131    myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
132    myLocalContexts.UnBind(myCurLocalIndex);
133    myCurLocalIndex = 0;
134
135    ResetOriginalState(Standard_False);
136    if(debugmode)
137      cout<<"No More Opened Local Context "<<endl;
138  }
139  
140  // Otherwise the local context will be still open after the current is closed
141  else{
142    Handle(StdSelect_ViewerSelector3d) VS = myLocalContexts(GoodIndex)->MainSelector();
143    myLocalContexts(GoodIndex)->Terminate();
144    myLocalContexts.UnBind(GoodIndex);
145    // the current is closed...
146    if(GoodIndex==myCurLocalIndex){
147      myCurLocalIndex = HighestIndex();
148    }
149    else if(debugmode)
150      cout<<"a No Current Local Context WasClosed"<<endl;
151
152    // restore activated selections of current local context
153    myLocalContexts (myCurLocalIndex)->RestoreActivatedModes();
154
155    if(debugmode) cout<<"Index Of CurrentLocalContext:"<<myCurLocalIndex<<endl;
156    
157  }
158    
159  
160  if(updateviewer) myMainVwr->Update();
161 }
162
163 //=======================================================================
164 //function : CloseAllContexts
165 //purpose  : 
166 //=======================================================================
167
168 void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewer)
169 {
170   
171   while(!myLocalContexts.IsEmpty()){
172     CloseLocalContext(myCurLocalIndex,Standard_False);
173   }
174   
175   ResetOriginalState(Standard_False);
176
177   if(updateviewer) myMainVwr->Update();
178 }
179
180 //=======================================================================
181 //function : IndexOfCurrentLocal
182 //purpose  : 
183 //=======================================================================
184
185 Standard_Integer AIS_InteractiveContext::IndexOfCurrentLocal() const
186 {
187   return myCurLocalIndex;
188 }
189
190 //=======================================================================
191 //function : ClearLocalContext
192 //purpose  : 
193 //=======================================================================
194
195 void AIS_InteractiveContext::ClearLocalContext(const AIS_ClearMode aMode)
196 {
197   if (!HasOpenedContext()) return;
198   myLocalContexts(myCurLocalIndex)->Clear(aMode);
199
200 }
201
202 //=======================================================================
203 //function : HighestIndex
204 //purpose  : 
205 //=======================================================================
206
207 Standard_Integer AIS_InteractiveContext::HighestIndex() const
208 {
209   AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
210   Standard_Integer HiInd = 0;
211   for(;It.More();It.Next())
212     HiInd = (It.Key()>HiInd) ? It.Key() : HiInd;
213   return HiInd;
214
215 }
216
217
218 //=======================================================================
219 //function : Activate
220 //purpose  : 
221 //=======================================================================
222
223 void AIS_InteractiveContext::
224 Activate(const Handle(AIS_InteractiveObject)& anIObj, 
225          const Standard_Integer aMode,
226          const Standard_Boolean theIsForce)
227 {
228   if(!HasOpenedContext()){
229     if(!myObjects.IsBound(anIObj)) return;
230     const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
231     if(STAT->GraphicStatus()==AIS_DS_Displayed || theIsForce)
232       mgrSelector->Activate(anIObj,aMode,myMainSel);
233     STAT ->AddSelectionMode(aMode);
234   }
235   else{
236    myLocalContexts(myCurLocalIndex)->ActivateMode(anIObj,aMode);
237   }
238 }
239
240 //=======================================================================
241 //function : LocalSelector
242 //purpose  : 
243 //=======================================================================
244 Handle( StdSelect_ViewerSelector3d ) AIS_InteractiveContext::LocalSelector() const
245 {
246   if( !HasOpenedContext() )
247       return Handle( StdSelect_ViewerSelector3d )();
248   else
249       return myLocalContexts( myCurLocalIndex )->MainSelector();
250 }
251
252
253 //=======================================================================
254 //function : DeActivate
255 //purpose  : 
256 //=======================================================================
257 void AIS_InteractiveContext::
258 Deactivate(const Handle(AIS_InteractiveObject)& anIObj)
259 {
260   if(!HasOpenedContext()){
261     if(!myObjects.IsBound(anIObj)) return;
262     TColStd_ListIteratorOfListOfInteger ItL;
263     for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
264         ItL.More();
265         ItL.Next()){
266       if(myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
267         mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
268     }
269     myObjects(anIObj)->ClearSelectionModes();
270   }
271   else{
272     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
273     LC->Deactivate(anIObj);
274   }
275 }
276
277 //=======================================================================
278 //function : Deactivate
279 //purpose  : 
280 //=======================================================================
281
282 void AIS_InteractiveContext::Deactivate(const Handle(AIS_InteractiveObject)& anIObj, 
283            const Standard_Integer aMode)
284 {
285   if(!HasOpenedContext()){
286     if(!myObjects.IsBound(anIObj)) return;
287     const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
288
289     if(STAT->GraphicStatus() == AIS_DS_Displayed)
290       mgrSelector->Deactivate(anIObj,aMode,myMainSel);
291     STAT->RemoveSelectionMode(aMode);
292   }
293   else{
294    myLocalContexts(myCurLocalIndex)->DeactivateMode(anIObj,aMode);
295   }
296 }
297
298 //=======================================================================
299 //function : ActivatedModes
300 //purpose  : 
301 //=======================================================================
302
303 void AIS_InteractiveContext::
304 ActivatedModes(const Handle(AIS_InteractiveObject)& anIObj, 
305                TColStd_ListOfInteger& theList) const 
306 {
307   TColStd_ListIteratorOfListOfInteger ItL;
308   if(!HasOpenedContext()){
309     if(myObjects.IsBound(anIObj)){
310       for(ItL.Initialize(myObjects(anIObj)->SelectionModes());
311           ItL.More();
312           ItL.Next())
313         theList.Append(ItL.Value());
314       
315     }
316   }
317   else{
318     if(myLocalContexts(myCurLocalIndex)->IsIn(anIObj)){
319       for(ItL.Initialize(myLocalContexts(myCurLocalIndex)->SelectionModes(anIObj));
320           ItL.More();
321           ItL.Next())
322         theList.Append(ItL.Value());
323     }
324   }
325 }
326
327 //=======================================================================
328 //function : SetShapeDecomposition
329 //purpose  : 
330 //=======================================================================
331
332 void AIS_InteractiveContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& anIObj,
333                                                    const Standard_Boolean StdModeSensitive)
334 {
335   if(!HasOpenedContext()) return;
336   myLocalContexts(myCurLocalIndex)->SetShapeDecomposition(anIObj,StdModeSensitive);
337 }
338
339 //=======================================================================
340 //function : SetTemporaryAttributes
341 //purpose  : 
342 //=======================================================================
343
344 void AIS_InteractiveContext::
345 SetTemporaryAttributes(const Handle(AIS_InteractiveObject)& /*anObj*/,
346                        const Handle(Prs3d_Drawer)& /*aDrawer*/,
347                        const Standard_Boolean /*updateviewer*/)
348 {
349 }
350
351 //=======================================================================
352 //function : SubIntensityOn
353 //purpose  : 
354 //=======================================================================
355 void AIS_InteractiveContext::
356 SubIntensityOn(const Handle(AIS_InteractiveObject)& anIObj,
357                const Standard_Boolean updateviewer)
358 {
359   if(!HasOpenedContext()){
360     if(!myObjects.IsBound(anIObj))
361       return;
362     const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
363     if(GB->IsSubIntensityOn())
364       return;
365     GB->SubIntensityOn();
366     Standard_Boolean UpdMain(Standard_False);
367     
368     for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
369       if (GB->GraphicStatus()==AIS_DS_Displayed)
370       {
371         myMainPM->Color(anIObj,mySubIntensity,It.Value());
372         UpdMain = Standard_True;
373       }
374     }
375     if(updateviewer){
376       if(UpdMain)
377         myMainVwr->Update();
378     }
379   }
380   else {
381     if(myObjects.IsBound(anIObj)){
382       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
383       STAT->SubIntensityOn();
384       TColStd_ListIteratorOfListOfInteger ItL;
385       for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
386         myMainPM->Color(anIObj,mySubIntensity,ItL.Value());
387     }
388     else
389       myLocalContexts(myCurLocalIndex)->SubIntensityOn(anIObj);
390     
391     if(updateviewer) myMainVwr->Update();
392   }
393 }
394 //=======================================================================
395 //function : SubIntensityOff
396 //purpose  : 
397 //=======================================================================
398
399 void AIS_InteractiveContext::
400 SubIntensityOff(const Handle(AIS_InteractiveObject)& anIObj,
401                 const Standard_Boolean updateviewer)
402 {
403   if(!HasOpenedContext()){
404     if(!myObjects.IsBound(anIObj))
405       return;
406     const Handle(AIS_GlobalStatus)& GB=myObjects(anIObj);
407     if(!GB->IsSubIntensityOn())
408       return;
409     GB->SubIntensityOff();
410     Standard_Boolean UpdMain(Standard_False);
411     
412     for(TColStd_ListIteratorOfListOfInteger It(GB->DisplayedModes());It.More();It.Next()){
413       if(GB->GraphicStatus()==AIS_DS_Displayed)
414       {
415         myMainPM->Unhighlight(anIObj,It.Value());
416         UpdMain = Standard_True;
417       }
418     }
419     
420     Standard_Integer DM,HM,SM;
421     GetDefModes(anIObj,DM,HM,SM);
422     if(AIS_Selection::IsSelected(anIObj))
423       myMainPM->Highlight(anIObj,HM);
424     
425     if(updateviewer){
426       if(UpdMain)
427         myMainVwr->Update();
428     }
429   }
430   else {
431     if(myObjects.IsBound(anIObj)){
432       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
433       STAT->SubIntensityOff();
434       TColStd_ListIteratorOfListOfInteger ItL;
435       for (ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
436         myMainPM->Unhighlight(anIObj,ItL.Value());
437       if(STAT->IsHilighted())
438         Hilight(anIObj);
439     }
440     else
441       myLocalContexts(myCurLocalIndex)->SubIntensityOff(anIObj);
442     if(IsSelected(anIObj))
443       Hilight(anIObj);
444     
445     if(updateviewer) myMainVwr->Update();
446   }
447 }
448
449 //=======================================================================
450 //function : SubIntensityOn
451 //purpose  : ALL THE DISPLAYED OBJECTS HAVE SUBINTENSITY...
452 //=======================================================================
453
454 void AIS_InteractiveContext::SubIntensityOn(const Standard_Boolean updateviewer)
455 {
456   if(!HasOpenedContext()) return;
457   
458   AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
459   TColStd_ListIteratorOfListOfInteger ItM;
460   for(;It.More();It.Next()){
461     const Handle(AIS_GlobalStatus)& STAT = It.Value();
462     if(STAT->GraphicStatus()==AIS_DS_Displayed)
463       {
464         STAT->SubIntensityOn();
465         for(ItM.Initialize(STAT->DisplayedModes());ItM.More();ItM.Next())
466           {myMainPM->Color(It.Key(),mySubIntensity,ItM.Value());}
467       }
468   }
469   if(updateviewer) myMainVwr->Update();
470 }
471
472 //=======================================================================
473 //function : SubIntensityOff
474 //purpose  : 
475 //=======================================================================
476 void AIS_InteractiveContext::SubIntensityOff(const Standard_Boolean updateviewer)
477 {
478   if(!HasOpenedContext()) return;
479
480   AIS_DataMapIteratorOfDataMapOfIOStatus It (myObjects);
481   TColStd_ListIteratorOfListOfInteger ItL;
482   for(;It.More();It.Next()){
483     const Handle(AIS_GlobalStatus)& STAT = It.Value();
484     if(STAT->IsSubIntensityOn())
485       STAT->SubIntensityOff();
486     for(ItL.Initialize(STAT->DisplayedModes());ItL.More();ItL.Next())
487       myMainPM->Unhighlight(It.Key());
488   }
489
490   if(updateviewer) myMainVwr->Update();
491 }
492
493 //=======================================================================
494 //function : AddFilter
495 //purpose  : 
496 //=======================================================================
497 void AIS_InteractiveContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
498 {
499   if(HasOpenedContext())
500     myLocalContexts(myCurLocalIndex)->AddFilter(aFilter);
501   else
502     myFilters->Add(aFilter);
503 }
504
505 //=======================================================================
506 //function : ActivateStandardMode
507 //purpose  : 
508 //=======================================================================
509 void AIS_InteractiveContext::ActivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
510 {
511   if(!HasOpenedContext()) return;
512   myLocalContexts(myCurLocalIndex)->ActivateStandardMode (aStandardActivation);
513 }
514
515 //=======================================================================
516 //function : DeActivateStandardMode
517 //purpose  : 
518 //=======================================================================
519 void AIS_InteractiveContext::DeactivateStandardMode(const TopAbs_ShapeEnum aStandardActivation)
520 {
521   if(!HasOpenedContext()) return;
522   myLocalContexts(myCurLocalIndex)->DeactivateStandardMode (aStandardActivation);
523 }
524
525 //=======================================================================
526 //function : RemoveFilter
527 //purpose  : 
528 //=======================================================================
529 void AIS_InteractiveContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
530 {
531   if(HasOpenedContext())
532     myLocalContexts(myCurLocalIndex)->RemoveFilter (aFilter);
533   else
534     myFilters->Remove(aFilter);
535 }
536
537 //=======================================================================
538 //function : RemoveFilters
539 //purpose  : 
540 //=======================================================================
541
542 void AIS_InteractiveContext::RemoveFilters()
543 {
544   if(!HasOpenedContext())
545     myFilters->Clear();
546   else
547     myLocalContexts(myCurLocalIndex)->Clear(AIS_CM_Filters);
548 }
549
550 //=======================================================================
551 //function : ActivatedStandardModes
552 //purpose  : 
553 //=======================================================================
554 const TColStd_ListOfInteger& AIS_InteractiveContext::ActivatedStandardModes() const 
555 {
556   return myLocalContexts(myCurLocalIndex)->StandardModes();
557 }
558
559 //=======================================================================
560 //function : Filters
561 //purpose  : 
562 //=======================================================================
563 const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const 
564 {
565   if(HasOpenedContext())
566     return myLocalContexts(myCurLocalIndex)->ListOfFilter();
567   return myFilters->StoredFilters();
568 }
569
570 //=======================================================================
571 //function : DisplayActiveSensitive
572 //purpose  : 
573 //=======================================================================
574 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(V3d_View)& aviou)
575 {
576   if(HasOpenedContext())
577     myLocalContexts(myCurLocalIndex)->DisplaySensitive(aviou);
578   else
579     myMainSel->DisplaySensitive(aviou);
580 }
581 //=======================================================================
582 //function : DisplayActiveSensitive
583 //purpose  : 
584 //=======================================================================
585
586 void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_InteractiveObject)& anIObj,
587                                                     const Handle(V3d_View)& aviou)
588 {
589   TColStd_ListIteratorOfListOfInteger It;
590   Handle(StdSelect_ViewerSelector3d) VS;
591   if(HasOpenedContext()){
592     const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
593     if(!LC->IsIn(anIObj)) return;
594     It.Initialize(LC->SelectionModes(anIObj));
595     VS = LC->MainSelector();
596   }
597   else{
598     if(!myObjects.IsBound(anIObj)) return;
599     It.Initialize(myObjects(anIObj)->SelectionModes());
600     VS = myMainSel;
601   }
602   
603   
604   for(;It.More();It.Next()){
605     const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
606     VS->DisplaySensitive(Sel,anIObj->Transformation(), aviou,Standard_False);
607   }  
608   
609 }
610
611 //=======================================================================
612 //function : ClearActiveSensitive
613 //purpose  : 
614 //=======================================================================
615 void AIS_InteractiveContext::ClearActiveSensitive(const Handle(V3d_View)& aviou)
616 {
617   
618   if(HasOpenedContext())
619     myLocalContexts(myCurLocalIndex)->ClearSensitive(aviou);
620   else
621     myMainSel->ClearSensitive(aviou);
622 }
623
624 //=======================================================================
625 //function : SetAutomaticHilight
626 //purpose  : 
627 //=======================================================================
628 void  AIS_InteractiveContext::SetAutomaticHilight(const Standard_Boolean aStatus)
629 {
630
631   if(HasOpenedContext())
632     myLocalContexts(myCurLocalIndex)->SetAutomaticHilight(aStatus);
633 }
634
635 //=======================================================================
636 //function : AutomaticHilight
637 //purpose  : 
638 //=======================================================================
639 Standard_Boolean AIS_InteractiveContext::AutomaticHilight() const 
640 {
641   if(HasOpenedContext())
642     return myLocalContexts(myCurLocalIndex)->AutomaticHilight();
643   return Standard_True;
644 }
645
646 //=======================================================================
647 //function : UseDisplayedObjects
648 //purpose  : 
649 //=======================================================================
650
651 void AIS_InteractiveContext::UseDisplayedObjects()
652 {
653   if(HasOpenedContext())
654     myLocalContexts(myCurLocalIndex)->LoadContextObjects();
655 }
656
657 //=======================================================================
658 //function : NotUseDisplayedObjects
659 //purpose  : 
660 //=======================================================================
661
662 void AIS_InteractiveContext::NotUseDisplayedObjects()
663 {
664   if(HasOpenedContext())
665     myLocalContexts(myCurLocalIndex)->UnloadContextObjects();
666 }
667
668
669
670
671 //=======================================================================
672 //function : PurgeDisplay
673 //purpose  : 
674 //=======================================================================
675
676 Standard_Integer AIS_InteractiveContext::PurgeDisplay()
677 {
678   if(HasOpenedContext()) return 0;
679   
680   Standard_Integer NbStr = PurgeViewer(myMainVwr);
681   myMainVwr->Update();
682   return NbStr;
683
684 }
685
686
687 //=======================================================================
688 //function : PurgeViewer
689 //purpose  : 
690 //=======================================================================
691 Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr)
692 {
693   Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager();
694   Standard_Integer NbCleared(0);
695   Graphic3d_MapOfStructure SOS;
696   GSM->DisplayedStructures(SOS);
697
698   Handle(Graphic3d_Structure) G;
699   for(Graphic3d_MapIteratorOfMapOfStructure It(SOS); It.More();It.Next()){
700     G = It.Key();
701     Standard_Address Add = G->Owner();
702     if(Add==NULL){
703       G->Erase();
704       G->Clear();// it means that it is not referenced as a presentation of InterfactiveObject...
705       NbCleared++;
706     }
707     Handle(AIS_InteractiveObject) IO = (AIS_InteractiveObject*)Add;
708     if(!myObjects.IsBound(IO)){
709       G->Erase();
710       NbCleared++;
711     }
712   }
713   return NbCleared;
714 }
715
716 //=======================================================================
717 //function : IsImmediateModeOn
718 //purpose  :
719 //=======================================================================
720
721 Standard_Boolean AIS_InteractiveContext::IsImmediateModeOn()  const 
722 {
723   if(!HasOpenedContext()) return Standard_False;
724   return myLocalContexts(myCurLocalIndex)->IsImmediateModeOn();
725 }
726
727 //=======================================================================
728 //function : BeginImmediateDraw
729 //purpose  :
730 //=======================================================================
731
732 Standard_Boolean AIS_InteractiveContext::BeginImmediateDraw()
733 {
734   return HasOpenedContext()
735       && myLocalContexts (myCurLocalIndex)->BeginImmediateDraw();
736 }
737
738 //=======================================================================
739 //function : ImmediateAdd
740 //purpose  :
741 //=======================================================================
742
743 Standard_Boolean AIS_InteractiveContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
744                                                        const Standard_Integer               theMode)
745 {
746   return HasOpenedContext()
747       && myLocalContexts (myCurLocalIndex)->ImmediateAdd (theObj, theMode);
748 }
749
750 //=======================================================================
751 //function : EndImmediateDraw
752 //purpose  :
753 //=======================================================================
754
755 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw (const Handle(V3d_View)& theView)
756 {
757   return HasOpenedContext()
758       && myLocalContexts (myCurLocalIndex)->EndImmediateDraw (theView->Viewer());
759 }
760
761 //=======================================================================
762 //function : EndImmediateDraw
763 //purpose  :
764 //=======================================================================
765
766 Standard_Boolean AIS_InteractiveContext::EndImmediateDraw()
767 {
768   if (!HasOpenedContext())
769   {
770     return Standard_False;
771   }
772
773   myMainVwr->InitActiveViews();
774   if (!myMainVwr->MoreActiveViews())
775   {
776     return Standard_False;
777   }
778
779   Handle(V3d_View) aView = myMainVwr->ActiveView();
780   return myLocalContexts (myCurLocalIndex)->EndImmediateDraw (aView->Viewer());
781 }
782
783
784 //=======================================================================
785 //function : ResetOriginalState
786 //purpose  : 
787 //=======================================================================
788
789 void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updateviewer)
790 {
791   Standard_Boolean upd_main(Standard_False);
792   TColStd_ListIteratorOfListOfInteger itl;
793   myMainSel->ResetSelectionActivationStatus();
794
795   for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
796     const Handle(AIS_InteractiveObject)& iobj = it.Key();
797     const Handle(AIS_GlobalStatus)& STAT = it.Value();
798     switch(STAT->GraphicStatus()){
799     case AIS_DS_Displayed:{
800       upd_main = Standard_True;
801       
802       // part display...
803       for(itl.Initialize(STAT->DisplayedModes());itl.More();itl.Next())
804         myMainPM->Display(iobj,itl.Value());
805       if(STAT->IsHilighted()){
806         if(STAT->HilightColor()!=Quantity_NOC_WHITE)
807           HilightWithColor(iobj,STAT->HilightColor(),Standard_False);
808         else
809           Hilight(iobj,Standard_False);
810       }
811       //part selection
812       for(itl.Initialize(STAT->SelectionModes());itl.More();itl.Next()){
813         if(itl.Value()!=-1)
814           mgrSelector->Activate(iobj,itl.Value(),myMainSel);
815       }
816       break; 
817     }
818     case AIS_DS_Erased:{
819       EraseGlobal(iobj,Standard_False);
820       break;
821     }
822     default:
823       break;
824     }
825   }
826   if(updateviewer){
827     if(upd_main) 
828       myMainVwr->Update();
829   }
830 }
831
832 //=======================================================================
833 //function : SetZDetection
834 //purpose  : 
835 //=======================================================================
836 void  AIS_InteractiveContext::SetZDetection(const Standard_Boolean aStatus)
837 {
838   myZDetectionFlag = aStatus;
839 }
840
841 //=======================================================================
842 //function : ZDetection 
843 //purpose  : 
844 //=======================================================================
845 Standard_Boolean AIS_InteractiveContext::ZDetection() const 
846 {
847   return myZDetectionFlag;
848 }