0029109: Visualization, AIS_Trihedron - add option hiding arrows tips
[occt.git] / src / AIS / AIS_LocalContext.cxx
1 // Created on: 1997-01-17
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 //Modified by ROB : Traque des UpdateConversion intempestifs.
18
19 #include <AIS_DataMapIteratorOfDataMapOfSelStat.hxx>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <AIS_ListIteratorOfListOfInteractive.hxx>
23 #include <AIS_ListOfInteractive.hxx>
24 #include <AIS_LocalContext.hxx>
25 #include <AIS_LocalStatus.hxx>
26 #include <AIS_Shape.hxx>
27 #include <Aspect_TypeOfMarker.hxx>
28 #include <Graphic3d_Structure.hxx>
29 #include <Prs3d_LineAspect.hxx>
30 #include <Prs3d_PlaneAspect.hxx>
31 #include <Prs3d_PointAspect.hxx>
32 #include <Prs3d_Presentation.hxx>
33 #include <SelectMgr_CompositionFilter.hxx>
34 #include <SelectMgr_EntityOwner.hxx>
35 #include <SelectMgr_Filter.hxx>
36 #include <SelectMgr_OrFilter.hxx>
37 #include <SelectMgr_SelectableObject.hxx>
38 #include <SelectMgr_SelectionManager.hxx>
39 #include <Standard_Transient.hxx>
40 #include <Standard_Type.hxx>
41 #include <StdSelect_ShapeTypeFilter.hxx>
42 #include <StdSelect_ViewerSelector3d.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TColStd_ListIteratorOfListOfInteger.hxx>
45 #include <TopAbs_ShapeEnum.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <V3d_View.hxx>
48 #include <V3d_Viewer.hxx>
49
50 #include <stdio.h>
51 IMPLEMENT_STANDARD_RTTIEXT(AIS_LocalContext,Standard_Transient)
52
53 //=======================================================================
54 //function : AIS_LocalContext
55 //purpose  : 
56 //=======================================================================
57
58
59 AIS_LocalContext::AIS_LocalContext(){}
60
61 AIS_LocalContext::AIS_LocalContext(const Handle(AIS_InteractiveContext)& aCtx,
62                                    const Standard_Integer Index,
63                                    const Standard_Boolean LoadDisplayed,
64                                    const Standard_Boolean AcceptStandardModes,
65                                    const Standard_Boolean AcceptEraseOfTemp,
66                                    const Standard_Boolean /*BothViewers*/):
67 myCTX(aCtx),
68 myLoadDisplayed(LoadDisplayed),
69 myAcceptStdMode(AcceptStandardModes),
70 myAcceptErase(AcceptEraseOfTemp),
71 mySM(aCtx->SelectionManager()),
72 myMainVS(aCtx->MainSelector()),
73 myFilters(new SelectMgr_OrFilter()),
74 myAutoHilight(Standard_True),
75 myMapOfOwner (new SelectMgr_IndexedMapOfOwner()),
76 mySelection(new AIS_Selection()),
77 mylastindex(0),
78 mylastgood(0),
79 myCurDetected(0),
80 myAISCurDetected(0),
81 mySubintStyle (new Prs3d_Drawer())
82 {
83   mySubintStyle->Link (aCtx->SelectionStyle());
84   mySubintStyle->SetColor        (aCtx->SelectionStyle()->Color());
85   mySubintStyle->SetTransparency (aCtx->SelectionStyle()->Transparency());
86   mySubintStyle->SetMethod       (aCtx->SelectionStyle()->Method());
87
88   // bind self to AIS_InteractiveContext::myLocalContexts. Further, the
89   // constructor executes logic that implies that the context is already
90   // created and mapped.
91   aCtx->myLocalContexts.Bind (Index, this);
92
93   myMainVS->ResetSelectionActivationStatus();
94   myMainPM = aCtx->MainPrsMgr();
95
96   mySM->Add(myMainVS);
97   if(myLoadDisplayed) LoadContextObjects();
98   Process();
99
100 }
101
102
103 //=======================================================================
104 //function : SetContext
105 //purpose  : 
106 //=======================================================================
107
108 void AIS_LocalContext::SetContext(const Handle(AIS_InteractiveContext)& aCtx)
109 {  myCTX = aCtx;}
110
111 //=======================================================================
112 //function : Display
113 //purpose  : 
114 //=======================================================================
115
116 Standard_Boolean AIS_LocalContext::Display(const Handle(AIS_InteractiveObject)& anInteractive,
117                                            const Standard_Integer WhichMode,
118                                            const Standard_Boolean AllowShapeDecomposition,
119                                            const Standard_Integer ActivationMode)
120 {
121   if(myActiveObjects.IsBound(anInteractive)){
122     const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
123     
124     if(STAT->DisplayMode() == -1){
125       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
126         myMainPM->Display(anInteractive,WhichMode);
127       if(STAT->IsTemporary())
128         STAT->SetDisplayMode(WhichMode);
129     }
130     else if(STAT->DisplayMode()!=WhichMode && STAT->IsTemporary()){
131       myMainPM->Erase(anInteractive,STAT->DisplayMode());
132       STAT->SetDisplayMode(WhichMode);
133       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
134         myMainPM->Display(anInteractive,WhichMode);
135     }
136     
137     if(ActivationMode!=-1){
138       if(!STAT->IsActivated(ActivationMode)){
139         STAT->ClearSelectionModes();
140         mySM->Load(anInteractive,myMainVS);
141         STAT->AddSelectionMode(ActivationMode);
142         mySM->Activate(anInteractive,ActivationMode,myMainVS);
143       }
144     }
145   }
146   else {
147     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
148     
149     if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
150       Att->SetDecomposition(Standard_True);
151     else 
152       Att->SetDecomposition(Standard_False);
153     // status temporary or not
154     if(myCTX->DisplayStatus(anInteractive) == AIS_DS_None ||
155        myCTX->DisplayStatus(anInteractive) == AIS_DS_Temporary)
156       Att->SetTemporary(Standard_True);
157     else
158       Att->SetTemporary(Standard_False); 
159
160
161     
162     if(!myCTX->IsDisplayed(anInteractive,WhichMode)){
163       
164       //storing information....
165       Att->SetDisplayMode(WhichMode);
166       if (ActivationMode!=-1)
167         Att->AddSelectionMode(ActivationMode);
168       Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
169       Att->SetHilightMode(HiMod);
170
171       if(!myMainPM->IsDisplayed(anInteractive,WhichMode))
172         myMainPM->Display(anInteractive,WhichMode);
173       
174       if(ActivationMode!=-1){
175         mySM->Load(anInteractive,myMainVS);
176         mySM->Activate(anInteractive,ActivationMode,myMainVS);
177       }
178     }
179     else{
180       Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode(): WhichMode;
181       Att->SetHilightMode(HiMod);
182     }
183     myActiveObjects.Bind(anInteractive,Att);
184   }  
185   Process(anInteractive);
186
187   
188   
189
190   return Standard_True;
191 }
192
193 //=======================================================================
194 //function : Load
195 //purpose  : 
196 //=======================================================================
197
198 Standard_Boolean AIS_LocalContext::
199 Load(const Handle(AIS_InteractiveObject)& anInteractive,
200      const Standard_Boolean AllowShapeDecomposition,
201      const Standard_Integer ActivationMode)
202 {
203   if (myActiveObjects.IsBound (anInteractive))
204   {
205     if (const Handle(SelectMgr_Selection)& aSel = anInteractive->Selection (ActivationMode))
206     {
207       if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
208       {
209         if (!myMainVS->Contains (anInteractive))
210         {
211           mySM->Load (anInteractive, myMainVS);
212         }
213         mySM->Activate (anInteractive, ActivationMode, myMainVS);
214         return Standard_True;
215       }
216     }
217     return Standard_False;
218   }
219
220   Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
221   
222   if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
223     Att->SetDecomposition(Standard_True);
224   else 
225     Att->SetDecomposition(Standard_False);
226   
227   if(!myCTX->IsDisplayed(anInteractive))
228     Att->SetTemporary(Standard_True);
229   else
230     Att->SetTemporary(Standard_False);
231   Att->SetDisplayMode(-1);
232   
233   //storing information....
234   if(ActivationMode!=-1)
235     Att->AddSelectionMode(ActivationMode);
236   Standard_Integer HiMod = anInteractive->HasHilightMode()? anInteractive->HilightMode():0;
237   Att->SetHilightMode(HiMod);
238   //Action
239   
240   mySM->Load(anInteractive,myMainVS);
241   if(ActivationMode != -1){
242     mySM->Activate(anInteractive,ActivationMode,myMainVS);
243   }
244   myActiveObjects.Bind(anInteractive,Att);
245   Process(anInteractive);
246   return Standard_True;
247 }
248
249 //=======================================================================
250 //function : ClearPrs
251 //purpose  : 
252 //=======================================================================
253
254 Standard_Boolean AIS_LocalContext::
255 ClearPrs(const Handle(AIS_InteractiveObject)& anInteractive,
256          const Standard_Integer aMode)
257 {
258   if(!myActiveObjects.IsBound(anInteractive))
259     return Standard_False;
260
261   Standard_Boolean jobdone(Standard_False);
262   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
263   
264   //Display step
265   if(STAT->IsSubIntensityOn()) {
266     STAT->SubIntensityOff();
267     if(STAT->HilightMode()==aMode)
268       myMainPM->Unhighlight(anInteractive);
269   }
270   myMainPM->Clear(anInteractive,aMode); // correction connexions 23/09/97
271   jobdone = Standard_True;
272   if(STAT->DisplayMode()==aMode)
273     STAT->SetDisplayMode(-1);
274   return jobdone;
275 }
276 //=======================================================================
277 //function : Erase
278 //purpose  : 
279 //=======================================================================
280
281 Standard_Boolean AIS_LocalContext::
282 Erase(const Handle(AIS_InteractiveObject)& anInteractive)
283 {
284   if(!myActiveObjects.IsBound(anInteractive))
285     return Standard_False;
286   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anInteractive);
287   
288   //Display step
289   if(STAT->IsSubIntensityOn()) {
290     STAT->SubIntensityOff();
291     myMainPM->Unhighlight (anInteractive);
292   }
293
294   Standard_Boolean status(Standard_False);
295
296   if(STAT->DisplayMode()!=-1) {
297     if(IsSelected(anInteractive))
298       AddOrRemoveSelected(anInteractive);
299     if(myMainPM->IsHighlighted(anInteractive,STAT->HilightMode()))
300     {
301       myMainPM->Unhighlight (anInteractive);
302     }
303     myMainPM->SetVisibility (anInteractive, STAT->DisplayMode(), Standard_False);
304     STAT->SetDisplayMode(-1);
305     status = Standard_True;
306   }
307   if(STAT->IsTemporary()){
308     if(myMainPM->IsDisplayed(anInteractive,STAT->HilightMode()))
309       myMainPM->SetVisibility (anInteractive, STAT->HilightMode(), Standard_False);
310   }
311
312   // Deactivate selectable entities of interactive object
313   const Handle(SelectMgr_SelectableObject)& anObj = anInteractive; // to avoid ambiguity
314   if (mySM->Contains (anObj))
315   {
316     while (!STAT->SelectionModes().IsEmpty())
317     {
318       mySM->Deactivate (anInteractive, STAT->SelectionModes().Last(), myMainVS);
319       STAT->RemoveSelectionMode (STAT->SelectionModes().Last());
320     }
321   }
322
323   ClearOutdatedSelection (anInteractive, Standard_True);
324
325   return status;
326 }
327
328
329 //=======================================================================
330 //function : SetShapeDecomposition
331 //purpose  : 
332 //=======================================================================
333
334 void AIS_LocalContext::SetShapeDecomposition(const Handle(AIS_InteractiveObject)& aStoredObject, 
335                                                 const Standard_Boolean aStatus)
336 {
337   if(!myActiveObjects.IsBound(aStoredObject)) return;
338   
339   if(aStatus == myActiveObjects(aStoredObject)->Decomposed()) 
340     return;
341   
342   myActiveObjects(aStoredObject)->SetDecomposition(aStatus);
343
344   Process(aStoredObject);
345 }
346
347 //=======================================================================
348 //function : Clear
349 //purpose  : 
350 //=======================================================================
351
352 void AIS_LocalContext::Clear(const AIS_ClearMode aType)
353 {
354   switch (aType){
355   case AIS_CM_All:
356     {
357       ClearObjects();
358       myFilters->Clear();
359       while(!myListOfStandardMode.IsEmpty())
360         DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
361       break;
362     }
363   case AIS_CM_Interactive:
364     ClearObjects();
365     break;
366   case AIS_CM_Filters:
367     myFilters->Clear();
368     break;
369   case AIS_CM_StandardModes:
370     {
371       while(!myListOfStandardMode.IsEmpty())
372         DeactivateStandardMode(AIS_Shape::SelectionType(myListOfStandardMode.Last()));
373       break;
374     }
375   case AIS_CM_TemporaryShapePrs:
376     ClearDetected();
377   }
378 }
379 //=======================================================================
380 //function : ActivateMode
381 //purpose  : 
382 //=======================================================================
383
384 void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
385                                        const Standard_Integer aMode)
386 {
387   if(!myActiveObjects.IsBound(aSelectable)) return;
388 //  if(myActiveObjects(aSelectable)->SelectionMode()!=aMode)
389 //    mySM->Deactivate(aSelectable,aMode,myMainVS);
390   if(aMode != -1){
391     myActiveObjects(aSelectable)->AddSelectionMode(aMode);
392     mySM->Activate(aSelectable,aMode,myMainVS);
393   }
394 }
395 //=======================================================================
396 //function : ActivateMode
397 //purpose  : 
398 //=======================================================================
399
400 void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSelectable,
401                                          const Standard_Integer aMode)
402 {
403   if(!myActiveObjects.IsBound(aSelectable)) return;
404   
405   if(aMode==-1) return;
406   
407   myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
408   mySM->Deactivate(aSelectable,aMode,myMainVS);
409 }
410 //=======================================================================
411 //function : ActivateMode
412 //purpose  : 
413 //=======================================================================
414
415 void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectable)
416 {
417   if(!myActiveObjects.IsBound(aSelectable)) return;
418   
419   mySM->Deactivate(aSelectable, -1, myMainVS);
420   myActiveObjects(aSelectable)->ClearSelectionModes();
421 }
422
423 //=======================================================================
424 //function : Remove
425 //purpose  : 
426 //=======================================================================
427
428 Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& aSelectable)
429 {
430   if(!myActiveObjects.IsBound (aSelectable))
431   {
432     return Standard_False;
433   }
434
435   if (IsSelected (aSelectable))
436   {
437     AddOrRemoveSelected (aSelectable, Standard_False);
438   }
439
440   const Handle(AIS_LocalStatus)& Att = myActiveObjects (aSelectable);
441
442   TColStd_ListIteratorOfListOfInteger It;
443
444   // Deactivate standard modes
445   if (Att->Decomposed())
446   {
447     for (It.Initialize (myListOfStandardMode); It.More(); It.Next())
448     {
449       mySM->Deactivate (aSelectable, It.Value(), myMainVS);
450     }
451   }
452
453   // If object or temporary presentations
454   if (Att->IsTemporary())
455   {
456     if (Att->IsSubIntensityOn())
457     {
458       myMainPM->Unhighlight (aSelectable);
459     }
460
461     myMainPM->Erase (aSelectable, Att->DisplayMode());
462     if (myMainPM->IsDisplayed (aSelectable, Att->HilightMode()))
463     {
464       myMainPM->Erase (aSelectable, Att->HilightMode());
465     }
466   }
467   // If subintensity used
468   else if (Att->IsSubIntensityOn())
469   {
470     myCTX->SubIntensityOff (aSelectable, Standard_False);
471   }
472
473   // Deactivate stored selection modes
474   for (It.Initialize (Att->SelectionModes()); It.More(); It.Next())
475   {
476     mySM->Deactivate (aSelectable, It.Value(), myMainVS);
477   }
478
479   // Remove the interactive object from selection manager
480   const Handle(SelectMgr_SelectableObject)& anObj = aSelectable; // to avoid ambiguity
481   if (mySM->Contains (anObj))
482   {
483     mySM->Remove (anObj);
484   }
485   ClearOutdatedSelection (aSelectable, Standard_True);
486
487   // This should be done at the very end because most methods use
488   // myActiveObjects even during clean-up
489   myActiveObjects.UnBind (aSelectable);
490   return Standard_True;
491 }
492
493 //=======================================================================
494 //function : ActivateStandardMode
495 //purpose  : 
496 //=======================================================================
497
498 void AIS_LocalContext::ActivateStandardMode(const TopAbs_ShapeEnum aType)
499 {
500   
501   //check if it is not in the list
502   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
503   for(;It.More();It.Next())
504     if(It.Value()==aType)  return;
505   Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
506   
507
508   // create a hidden filter answering ok to the type except for :
509   // if the type is shape...
510   // if the filters already impact at the type <aType>
511   if(aType != TopAbs_SHAPE){
512     if(myStdFilters[IMode].IsNull())
513       myStdFilters[IMode] = new StdSelect_ShapeTypeFilter(aType);
514     if(!HasFilters(aType))
515       myFilters->Add(myStdFilters[IMode]);
516   }
517   
518   // the mode is activated for all objects of type Shape 
519   // accepting the decomposition in standard mode.
520   myListOfStandardMode.Append(IMode);
521   
522   AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
523
524   for(;ItM.More();ItM.Next()){
525     if(ItM.Value()->Decomposed())
526       myCTX->SelectionManager()->Activate(ItM.Key(),
527                                           IMode,
528                                           myMainVS);
529     ItM.Value()->AddSelectionMode (IMode);
530   }
531   
532 }
533
534 //=======================================================================
535 //function : DeActivateStandardMode
536 //purpose  : 
537 //=======================================================================
538
539 void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
540 {
541   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
542   Standard_Integer IMode = AIS_Shape::SelectionMode(aType);
543   for(;It.More();It.Next())
544     if(It.Value()==IMode) {
545       AIS_DataMapIteratorOfDataMapOfSelStat ItM(myActiveObjects);
546       
547       for(;ItM.More();ItM.Next()){
548         if(ItM.Value()->Decomposed()){
549           myCTX->SelectionManager()->Deactivate(ItM.Key(),
550                                                 IMode,
551                                                 myMainVS);
552           ItM.Value()->RemoveSelectionMode(IMode);
553         }
554       }
555       myListOfStandardMode.Remove(It);
556       if(myFilters->IsIn(myStdFilters[IMode]))
557         myFilters->Remove(myStdFilters[IMode]);
558       return;
559     }   
560 }
561
562 //=======================================================================
563 //function : AddFilter
564 //purpose  : 
565 //=======================================================================
566
567 void AIS_LocalContext::AddFilter(const Handle(SelectMgr_Filter)& aFilter)
568 {
569   // it is checked if the filter impacts at the type of active sub-shape 
570   // for which a filter of type has been already implemented...
571
572   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
573   
574   for(;It.More();It.Next()){
575     if(aFilter->ActsOn(AIS_Shape::SelectionType(It.Value())))
576       if(myFilters->IsIn(myStdFilters[It.Value()]))
577         myFilters->Remove(myStdFilters[It.Value()]);
578   } 
579   myFilters->Add(aFilter);
580 }
581
582 //=======================================================================
583 //function : RemoveFilter
584 //purpose  : 
585 //=======================================================================
586
587 void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
588 {
589   if(myFilters->IsIn(aFilter)) myFilters->Remove(aFilter);
590   
591   // it is checked if the filter for type standard is active.
592   // if yes, it is checked there are still similarities among the
593   // remaining filters...
594   //     otherwise, the standard filter is restored to
595   //     continu selecting active modes...
596   TColStd_ListIteratorOfListOfInteger It(myListOfStandardMode);
597   TopAbs_ShapeEnum SE;
598   for(;It.More();It.Next()){
599     SE = AIS_Shape::SelectionType(It.Value());
600     if(aFilter->ActsOn(SE))
601       if(!HasFilters(SE))
602         myFilters->Add(myStdFilters[It.Value()]);
603   }
604 }
605
606 //=======================================================================
607 //function : Terminate
608 //purpose  :
609 //=======================================================================
610
611 void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
612 {
613   ClearDetected();
614   Clear();
615   myMapOfOwner->Clear();
616   
617   mylastindex=0;
618   // clear the selector...
619   myMainVS->Clear();
620   
621   for (AIS_NListOfEntityOwner::Iterator aSelIter (mySelection->Objects()); aSelIter.More(); aSelIter.Next())
622   {
623     aSelIter.Value()->SetSelected (Standard_False);
624   }
625   mySelection->Clear();
626
627   Handle(V3d_View) aDummyView;
628   myMainVS->ClearSensitive (aDummyView);
629
630   if (theToUpdate)
631   {
632     myCTX->UpdateCurrentViewer();
633   }
634 }
635
636
637 //=======================================================================
638 //function : SubIntensity
639 //purpose  : 
640 //=======================================================================
641
642 void AIS_LocalContext::SubIntensityOn(const Handle(AIS_InteractiveObject)& anObject)
643 {
644   if(!myActiveObjects.IsBound(anObject)) return;
645   mySubintStyle->SetColor (myCTX->SubIntensityColor());
646   
647   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
648
649   if(Att->IsTemporary())
650   {
651     myMainPM->Color (anObject, mySubintStyle, Att->DisplayMode());
652   }
653   
654   Att->SubIntensityOn();
655 }
656 //=======================================================================
657 //function : SubIntensity
658 //purpose  : 
659 //=======================================================================
660
661 void AIS_LocalContext::SubIntensityOff(const Handle(AIS_InteractiveObject)& anObject)
662 {
663   if(!myActiveObjects.IsBound(anObject)) return;
664   
665   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
666
667   if(Att->IsTemporary()) 
668     myMainPM->Unhighlight(anObject);
669   Att->SubIntensityOff();
670 }
671
672
673 //=======================================================================
674 //function : Hilight
675 //purpose  : 
676 //=======================================================================
677
678 void AIS_LocalContext::Hilight(const  Handle(AIS_InteractiveObject)& anObject)
679 {
680   if(!myActiveObjects.IsBound(anObject)){
681     Standard_Integer HiMod = anObject->HasHilightMode()? anObject->HilightMode() : 0; 
682     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus(Standard_True,
683                                                       Standard_False,
684                                                       -1,-1,HiMod);
685     myActiveObjects.Bind(anObject,Att);
686     
687   }
688   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
689   myMainPM->Color(anObject, myCTX->getHiStyle (anObject, anObject->GlobalSelOwner()), Att->HilightMode());
690   Att->SubIntensityOn();
691 }
692 //=======================================================================
693 //function : Hilight
694 //purpose  : 
695 //=======================================================================
696
697 void AIS_LocalContext::Hilight (const Handle(AIS_InteractiveObject)& theObj,
698                                 const Handle(Prs3d_Drawer)& theStyle)
699 {
700   if (!myActiveObjects.IsBound (theObj))
701   {
702     Handle(AIS_LocalStatus) aStatus = new AIS_LocalStatus
703       (Standard_True, Standard_False, -1, -1, theObj->HasHilightMode() ? theObj->HilightMode() : 0);
704     myActiveObjects.Bind (theObj, aStatus);
705   }
706   const Handle(AIS_LocalStatus)& aStatus = myActiveObjects (theObj);
707   myMainPM->Color (theObj, theStyle, aStatus->HilightMode());
708   aStatus->SubIntensityOn();
709   aStatus->SetHilightStyle (theStyle);
710 }
711
712 //=======================================================================
713 //function : Unhilight
714 //purpose  : 
715 //=======================================================================
716
717 void AIS_LocalContext::Unhilight(const Handle(AIS_InteractiveObject)& anObject)
718 {
719   if(!myActiveObjects.IsBound(anObject)) return;
720   
721   // chieck if by hazard the object is somewhere else...
722   Standard_Integer Indx;
723   Standard_DISABLE_DEPRECATION_WARNINGS
724   Standard_Boolean IsSomeWhereElse  = 
725     myCTX->IsInLocal(anObject,Indx) && Indx != myCTX->IndexOfCurrentLocal();
726   Standard_ENABLE_DEPRECATION_WARNINGS
727   
728   const Handle(AIS_LocalStatus)& Att = myActiveObjects(anObject);
729   myMainPM->Unhighlight (anObject);
730   if(Att->IsTemporary() && Att->DisplayMode()==-1)
731     if(!IsSomeWhereElse)
732       myMainPM->SetVisibility (anObject, Att->HilightMode(), Standard_False);
733
734   Att->SubIntensityOff();
735   Att->SetHilightStyle (Handle(Prs3d_Drawer)());
736 }
737
738
739 //=======================================================================
740 //function : IsIn
741 //purpose  : 
742 //=======================================================================
743
744 Standard_Boolean AIS_LocalContext::
745 IsIn(const Handle(AIS_InteractiveObject)& anObject) const 
746 {
747   return myActiveObjects.IsBound(anObject);
748 }
749
750 //=======================================================================
751 //function : IsHilighted
752 //purpose  : 
753 //=======================================================================
754
755 Standard_Boolean AIS_LocalContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject) const 
756 {
757   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
758   return myActiveObjects(anObject)->IsSubIntensityOn();
759 }
760
761 Standard_Boolean AIS_LocalContext::HighlightStyle (const Handle(AIS_InteractiveObject)& theObject,
762                                                    Handle(Prs3d_Drawer)& theStyle) const
763 {
764   if (!myActiveObjects.IsBound (theObject))
765     return Standard_False;
766
767   if (myActiveObjects (theObject)->IsSubIntensityOn())
768   {
769     theStyle = myActiveObjects (theObject)->HilightStyle();
770     return Standard_True;
771   }
772
773   return Standard_False;
774 }
775
776
777 void AIS_LocalContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anObject,
778                                           const Standard_Integer Prior)
779 {
780   if(!myActiveObjects.IsBound(anObject)) return;
781   const Handle(AIS_LocalStatus)& STAT = myActiveObjects(anObject);
782   if(STAT->DisplayMode()==-1) return;
783   myMainPM->SetDisplayPriority(anObject,STAT->DisplayMode(),Prior);
784   if(STAT->IsSubIntensityOn())
785     myMainPM->SetDisplayPriority(anObject,STAT->HilightMode(),Prior);
786   
787   
788 }
789
790 //=======================================================================
791 //function : DisplayedObjects
792 //purpose  : 
793 //=======================================================================
794 Standard_Integer AIS_LocalContext::DisplayedObjects(TColStd_MapOfTransient& theMap) const
795 {
796   Standard_Integer NbDisp(0);
797   for(AIS_DataMapIteratorOfDataMapOfSelStat it(myActiveObjects);it.More();it.Next()){
798     const Handle(SelectMgr_SelectableObject)& SO = it.Key();
799     if(!theMap.Contains(SO))
800       if(it.Value()->DisplayMode()!=-1){
801         theMap.Add(SO);
802         NbDisp++;
803       }
804   }
805   return NbDisp;
806 }
807
808
809 //=======================================================================
810 //function : IsDisplayed
811 //purpose  : 
812 //=======================================================================
813
814 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject) const 
815 {
816   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
817   return (myActiveObjects(anObject)->DisplayMode()!=-1);
818 }
819
820 //=======================================================================
821 //function : IsDisplayed
822 //purpose  : 
823 //=======================================================================
824
825 Standard_Boolean AIS_LocalContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
826                                                   const Standard_Integer aMode) const 
827 {
828   if(!myActiveObjects.IsBound(anObject)) return Standard_False;
829   return (myActiveObjects(anObject)->DisplayMode()==aMode);
830 }
831
832 //=======================================================================
833 //function : SelectionModes
834 //purpose  : 
835 //=======================================================================
836
837 const TColStd_ListOfInteger& AIS_LocalContext::
838 SelectionModes(const Handle(AIS_InteractiveObject)& anObject) const 
839 {
840   return myActiveObjects(anObject)->SelectionModes(); 
841 }
842
843 //=======================================================================
844 //function : Status
845 //purpose  : 
846 //=======================================================================
847
848 TCollection_AsciiString AIS_LocalContext::Status() const 
849 {
850   TCollection_AsciiString t;
851   return t;
852 }
853
854 const Handle(AIS_LocalStatus)& AIS_LocalContext::Status(const Handle(AIS_InteractiveObject)& anObject) const 
855 {
856   return myActiveObjects(anObject);
857 }
858
859 //=======================================================================
860 //function : LoadContextObjects
861 //purpose  : 
862 //=======================================================================
863
864 void AIS_LocalContext::LoadContextObjects()
865 {
866   if (!myLoadDisplayed)
867   {
868     return;
869   }
870
871   AIS_ListOfInteractive LL;
872   myCTX->DisplayedObjects(LL,Standard_True);
873   for (AIS_ListIteratorOfListOfInteractive It (LL); It.More(); It.Next())
874   {
875     const Handle(AIS_InteractiveObject)& anObj = It.Value();
876     Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
877     Att->SetDecomposition((anObj->AcceptShapeDecomposition() && myAcceptStdMode));
878     Att->SetTemporary(Standard_False);
879     Att->SetHilightMode(anObj->HasHilightMode()? anObj->HilightMode(): 0);
880     for (SelectMgr_SequenceOfSelection::Iterator aSelIter (anObj->Selections()); aSelIter.More(); aSelIter.Next())
881     {
882       const Handle(SelectMgr_Selection)& aSel = aSelIter.Value();
883       aSel->SetSelectionState (SelectMgr_SOS_Deactivated);
884     }
885     myActiveObjects.Bind(anObj,Att);
886   }
887 }
888
889 void AIS_LocalContext::UnloadContextObjects()
890 {
891   AIS_ListIteratorOfListOfInteractive It;
892   if(myLoadDisplayed) 
893   {
894     AIS_ListOfInteractive LL;
895     myCTX->DisplayedObjects(LL,Standard_True);
896     
897     for (It.Initialize(LL);It.More();It.Next())
898     {
899       myActiveObjects.UnBind(It.Value());
900     }
901   }
902 }
903 //=======================================================================
904 //function : Process
905 //purpose  : 
906 //=======================================================================
907
908 void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject)
909
910   if(!myActiveObjects.IsBound(anObject)) return;
911   if(myActiveObjects(anObject)->Decomposed())
912     ActivateStandardModes(anObject);
913   else
914     {
915       TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
916       for(;It.More();It.Next())
917         myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS);
918     }
919 }
920
921 //=======================================================================
922 //function : Process
923 //purpose  : 
924 //=======================================================================
925
926 void AIS_LocalContext::Process()
927
928
929   myMainVS->Clear();
930   
931   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
932   
933   for(;It.More();It.Next()){
934     myCTX->SelectionManager()->Load(It.Key(),myMainVS);
935     if(It.Value()->Decomposed()) 
936       ActivateStandardModes(It.Key());
937     else if( myCTX->GetAutoActivateSelection() )
938     {
939       It.Value()->AddSelectionMode(0);
940       myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS);
941     }
942   }
943
944 }
945
946 //=======================================================================
947 //function : ActivateModes
948 //purpose  : 
949 //=======================================================================
950
951 void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject)
952
953   if(!myActiveObjects.IsBound(anObject)) return;
954   
955   TColStd_ListIteratorOfListOfInteger itl (myListOfStandardMode);
956
957   const Handle(AIS_LocalStatus)&  LS = myActiveObjects(anObject);
958   if(LS->Decomposed()){
959     for(;itl.More();itl.Next()){
960       myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS);
961       LS->AddSelectionMode(itl.Value());
962     }
963   }
964 }
965
966
967 //=======================================================================
968 //function : ClearObjects
969 //purpose  : 
970 //=======================================================================
971
972 void AIS_LocalContext::ClearObjects()
973 {
974   AIS_DataMapIteratorOfDataMapOfSelStat It(myActiveObjects);
975   for(;It.More();It.Next())
976     {
977       Handle(AIS_InteractiveObject) SO =
978         Handle(AIS_InteractiveObject)::DownCast(It.Key());
979       
980       const Handle(AIS_LocalStatus)& CurAtt = It.Value();
981       //TColStd_ListIteratorOfListOfInteger ItL;
982       // if object is temporary the presentations managed by myMainPM are removed
983       AIS_DisplayStatus TheDS = myCTX->DisplayStatus(SO);
984       
985       if(TheDS != AIS_DS_Displayed)
986       {
987         if (myMainPM->IsDisplayed(SO,CurAtt->DisplayMode()))
988         {
989           if (CurAtt->IsSubIntensityOn() && myMainPM->IsHighlighted (SO, CurAtt->HilightMode()))
990           {
991             myMainPM->Unhighlight (SO);
992           }
993           myMainPM->Erase (SO, CurAtt->DisplayMode());
994         }
995
996         if (CurAtt->IsTemporary())
997         {
998           myMainPM->Erase (SO, CurAtt->DisplayMode());
999           //myMainPM->Clear(SO,CurAtt->DisplayMode());
1000         }
1001       }
1002       else {
1003         if (CurAtt->IsSubIntensityOn())
1004         {
1005           myCTX->SubIntensityOff(SO, Standard_False);
1006         }
1007         Standard_Integer DiMo = SO->HasDisplayMode()?
1008           SO->DisplayMode():myCTX->DisplayMode();
1009         if(CurAtt->DisplayMode()!=-1 &&
1010            CurAtt->DisplayMode()!= DiMo)
1011           myMainPM->Erase(SO,CurAtt->DisplayMode());
1012       }
1013       
1014       TColStd_ListIteratorOfListOfInteger aSelModeIter (CurAtt->SelectionModes());
1015       for ( ; aSelModeIter.More(); aSelModeIter.Next())
1016       {
1017         Standard_Integer aSelMode = aSelModeIter.Value();
1018         mySM->Deactivate (SO, aSelMode, myMainVS);
1019       }
1020
1021     }
1022   ClearSelected( Standard_False );
1023
1024   // Clear selection structures for temporary objects, created in local context
1025   for (AIS_DataMapIteratorOfDataMapOfSelStat anIter (myActiveObjects); anIter.More(); anIter.Next())
1026   {
1027     if (anIter.Value()->IsTemporary())
1028     {
1029       mySM->Remove (anIter.Key(), myMainVS);
1030     }
1031   }
1032
1033   myActiveObjects.Clear();
1034 }
1035
1036
1037 Standard_Boolean AIS_LocalContext::IsDecompositionOn() const 
1038 {return !myListOfStandardMode.IsEmpty();}
1039
1040
1041
1042
1043 //=======================================================================
1044 //function : HasAlreadyFilters
1045 //purpose  : 
1046 //=======================================================================
1047
1048 Standard_Boolean AIS_LocalContext::
1049 HasFilters(const TopAbs_ShapeEnum aType) const 
1050 {
1051   return myFilters->ActsOn(aType);
1052 }
1053
1054 void AIS_LocalContext::ClearDetected()
1055 {
1056   for(Standard_Integer I=1;I<=myMapOfOwner->Extent();I++)
1057   {
1058     if(!myMapOfOwner->FindKey (I).IsNull())
1059     {
1060       if(myMapOfOwner->FindKey (I)->IsHilighted(myMainPM))
1061         myMapOfOwner->FindKey (I)->Unhilight(myMainPM);
1062       else
1063       {
1064         const Handle(SelectMgr_SelectableObject)& SO = 
1065           myMapOfOwner->FindKey (I)->Selectable();
1066         if(myActiveObjects.IsBound(SO))
1067         {
1068           const Handle(AIS_LocalStatus)& Att = myActiveObjects(SO);
1069
1070           if(Att->IsTemporary() &&
1071              Att->DisplayMode()==-1 && 
1072              Att->SelectionModes().IsEmpty())
1073           {
1074             myMapOfOwner->FindKey (I)->Clear(myMainPM);
1075           }
1076         }
1077       }
1078     }
1079   }
1080 }
1081
1082 //=======================================================================
1083 //function : BeginImmediateDraw
1084 //purpose  :
1085 //=======================================================================
1086 Standard_Boolean AIS_LocalContext::BeginImmediateDraw()
1087 {
1088   if (myMainPM->IsImmediateModeOn())
1089   {
1090     myMainPM->BeginImmediateDraw();
1091     return Standard_True;
1092   }
1093   return Standard_False;
1094 }
1095
1096 //=======================================================================
1097 //function : ImmediateAdd
1098 //purpose  :
1099 //=======================================================================
1100 Standard_Boolean AIS_LocalContext::ImmediateAdd (const Handle(AIS_InteractiveObject)& theObj,
1101                                                  const Standard_Integer               theMode)
1102 {
1103   if (!myMainPM->IsImmediateModeOn())
1104   {
1105     return Standard_False;
1106   }
1107
1108   myMainPM->AddToImmediateList (myMainPM->Presentation (theObj, theMode)->Presentation());
1109   return Standard_True;
1110 }
1111
1112 //=======================================================================
1113 //function : EndImmediateDraw
1114 //purpose  :
1115 //=======================================================================
1116 Standard_Boolean AIS_LocalContext::EndImmediateDraw (const Handle(V3d_Viewer)& theViewer)
1117 {
1118   if (!myMainPM->IsImmediateModeOn())
1119   {
1120     return Standard_False;
1121   }
1122
1123   myMainPM->EndImmediateDraw (theViewer);
1124   return Standard_True;
1125 }
1126
1127 // =======================================================================
1128 // function : ClearImmediateDraw
1129 // purpose  :
1130 // =======================================================================
1131 void AIS_LocalContext::ClearImmediateDraw()
1132 {
1133   myMainPM->ClearImmediateDraw();
1134 }
1135
1136 //=======================================================================
1137 //function : IsImmediateModeOn
1138 //purpose  :
1139 //=======================================================================
1140 Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
1141 {
1142   return myMainPM->IsImmediateModeOn();
1143 }
1144
1145 void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
1146
1147   myMainVS->SetPixelTolerance(aPrecision);
1148 }
1149
1150 Standard_Integer AIS_LocalContext::PixelTolerance() const {
1151
1152   return myMainVS->PixelTolerance();
1153 }
1154
1155 //=======================================================================
1156 //function : SetSelectionSensitivity
1157 //purpose  : Allows to manage sensitivity of a particular selection of interactive object theObject
1158 //=======================================================================
1159 void AIS_LocalContext::SetSelectionSensitivity (const Handle(AIS_InteractiveObject)& theObject,
1160                                                 const Standard_Integer theMode,
1161                                                 const Standard_Integer theNewSensitivity)
1162 {
1163   mySM->SetSelectionSensitivity (theObject, theMode, theNewSensitivity);
1164 }