0024326: Get rid of confusing extension line
[occt.git] / src / AIS / AIS_InteractiveContext.cxx
1 // Created on: 1997-01-17
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 // Modified by  XAB & Serguei Dec 97 (angle &deviation coeffts)
22
23 #define BUC60577        //GG_101099     Enable to compute correctly
24 //                      transparency with more than one object in the view.
25
26 #define BUC60632        //GG 15/03/00 Add protection on SetDisplayMode()
27 //                      method, compute only authorized presentation.
28
29 #define BUC60688        //GG 25/05/00 Add SetSensitivity() methods.
30
31 #define BUC60722  //GG 04/09/00 Always enable viewer update when erasing something
32
33 #define IMP051001       //GG Adds SetZDetected() and ZDetected() methods
34
35 #define OCC172          //SAV clear static map before destroying context.
36
37 #define OCC204          //SAV 26/02/02 : pass <updateviewer> flag to 
38 // AddOrRemoveCurrentObject method from ClearGlobal.
39
40 #define OCC4373         //SAN 10/11/03 : improve display mode management in
41 // Display( IO, updateviewer ) and 
42 // SetDisplayMode( IO, mode, updateviewer ) methods
43
44 #include <AIS_InteractiveContext.ixx>
45
46 //#include <AIS_DataMapIteratorOfDataMapOfInteractiveInteger.hxx>
47 #include <TColStd_ListIteratorOfListOfInteger.hxx>
48 #include <TColStd_MapIteratorOfMapOfTransient.hxx>
49 #include <AIS_LocalContext.hxx>
50 #include <AIS_LocalStatus.hxx>
51 #include <Precision.hxx>
52 #include <AIS_Selection.hxx>
53 #include <AIS_DataMapIteratorOfDataMapOfIOStatus.hxx>
54 #include <AIS_ConnectedShape.hxx>
55 #include <AIS_MultipleConnectedShape.hxx>
56 #include <AIS_DataMapIteratorOfDataMapOfILC.hxx>
57 #include <AIS_GlobalStatus.hxx>
58 #include <AIS_MapIteratorOfMapOfInteractive.hxx>
59 #include <PrsMgr_ModedPresentation.hxx>
60 #include <Visual3d_ViewManager.hxx>
61 #include <Prs3d_ShadingAspect.hxx>
62 #include <AIS_Shape.hxx>
63 #include <Graphic3d_AspectFillArea3d.hxx>
64 #include <HLRBRep.hxx>
65 #include <Prs3d_IsoAspect.hxx>
66 #include <Prs3d_DatumAspect.hxx>
67 #include <Prs3d_PlaneAspect.hxx>
68 #include <PrsMgr_PresentableObject.hxx>
69 #include <Standard_Atomic.hxx>
70 #include <UnitsAPI.hxx>
71
72 #include <AIS_Trihedron.hxx>
73 #include <Geom_Axis2Placement.hxx>
74 #include <OSD_Environment.hxx>
75
76 #include <AIS_ListIteratorOfListOfInteractive.hxx>
77
78 // In the method GetDefModes() the returned value of the selection mode 
79 // is always equal to 0 if it is -1.
80 #define BUC61051
81
82 // The local context is closed the method ::ResetOriginalState() sets the selection mode equal to 0
83 // in spite of the selection mode of the interactive object in Natural Point.
84 #define OCC166
85
86 static Standard_Boolean AISDebugModeOn()
87 {
88 //  static OSD_Environment aisdb("AISDEBUGMODE");
89 //  return !aisdb.Value().IsEmpty();
90   static Standard_Integer isDebugMode(-1);
91   if (isDebugMode < 0) {
92     isDebugMode = 1;
93     OSD_Environment aisdb("AISDEBUGMODE");
94     if (aisdb.Value().IsEmpty())
95       isDebugMode = 0;
96   }
97   return (isDebugMode != 0);
98 }
99
100 namespace
101 {
102   static volatile Standard_Integer THE_AIS_INDEX_SEL = 0;
103   static volatile Standard_Integer THE_AIS_INDEX_CUR = 0;
104
105   static TCollection_AsciiString AIS_Context_NewSelName()
106   {
107     return TCollection_AsciiString ("AIS_SelContext_")
108          + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_SEL));
109   }
110
111   static TCollection_AsciiString AIS_Context_NewCurName()
112   {
113     return TCollection_AsciiString ("AIS_CurContext_")
114          + TCollection_AsciiString (Standard_Atomic_Increment (&THE_AIS_INDEX_CUR));
115   }
116 };
117
118 //=======================================================================
119 //function : AIS_InteractiveContext
120 //purpose  : 
121 //=======================================================================
122
123 AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer):
124 mgrSelector(new SelectMgr_SelectionManager()),
125 myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())),
126 myMainVwr(MainViewer),
127 myMainSel(new StdSelect_ViewerSelector3d()),
128 myToHilightSelected( Standard_False ),
129 myFilters(new SelectMgr_OrFilter()),
130 myDefaultDrawer(new Prs3d_Drawer()),
131 myDefaultColor(Quantity_NOC_GOLDENROD),
132 myHilightColor(Quantity_NOC_CYAN1),
133 mySelectionColor(Quantity_NOC_GRAY80),
134 myPreselectionColor(Quantity_NOC_GREEN),
135 mySubIntensity(Quantity_NOC_GRAY40),
136 myDisplayMode(0),
137 myCurLocalIndex(0),
138 #ifdef IMP051001
139 myZDetectionFlag(0),
140 #endif
141 myIsAutoActivateSelMode( Standard_True )
142
143   InitAttributes();
144 }
145
146 void AIS_InteractiveContext::Delete() const
147 {
148   //Clear the static current selection. Else the memory
149   //is not release
150   AIS_Selection::ClearCurrentSelection();
151 #ifdef OCC172
152   // to avoid an exception
153   if ( AIS_Selection::Find( mySelectionName.ToCString() ) )
154     AIS_Selection::Remove( mySelectionName.ToCString() );
155
156   // to avoid an exception
157   if ( AIS_Selection::Find( myCurrentName.ToCString() ) )
158     AIS_Selection::Remove( myCurrentName.ToCString() );
159
160   // let's remove one reference explicitly. this operation's supposed to
161   // be performed when mgrSelector will be destroyed but anyway...
162   mgrSelector->Remove( myMainSel );
163 #endif
164   AIS_ListOfInteractive aList;
165   
166   AIS_DataMapIteratorOfDataMapOfIOStatus anIt(myObjects);
167   Handle(AIS_InteractiveContext) aNullContext;
168   for(; anIt.More() ; anIt.Next())
169   {
170     Handle(AIS_InteractiveObject) anObj = anIt.Key();
171     anObj->SetContext(aNullContext);
172     
173   }
174   MMgt_TShared::Delete();
175 }
176
177 //=======================================================================
178 //function : AIS_SelectionName
179 //purpose  : 
180 //=======================================================================
181 const TCollection_AsciiString& AIS_InteractiveContext::SelectionName() const 
182 {
183   if(!HasOpenedContext())
184     return mySelectionName;
185   return myLocalContexts(myCurLocalIndex)->SelectionName();
186
187
188
189
190
191 //=======================================================================
192 //function : UpdateCurrentViewer
193 //purpose  : 
194 //=======================================================================
195
196 void AIS_InteractiveContext::UpdateCurrentViewer()
197 {
198   if (!myMainVwr.IsNull())
199     myMainVwr->Update();
200 }
201
202
203 //=======================================================================
204 //function : DomainOfMainViewer
205 //purpose  : 
206 //=======================================================================
207
208 Standard_CString AIS_InteractiveContext::DomainOfMainViewer() const 
209 {
210   return myMainVwr->Domain();
211   
212 }
213
214 //=======================================================================
215 //function : DisplayedObjects
216 //purpose  : 
217 //=======================================================================
218
219 void AIS_InteractiveContext::DisplayedObjects(AIS_ListOfInteractive& aListOfIO,
220                                               const Standard_Boolean OnlyFromNeutral) const 
221 {
222 #ifdef DEBUG
223   cout<<"AIS_IC::DisplayedObjects"<<endl;
224 #endif
225
226   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
227   if(!HasOpenedContext() || OnlyFromNeutral){
228     for(;It.More();It.Next()){
229       if(It.Value()->GraphicStatus()==AIS_DS_Displayed)
230         aListOfIO.Append(It.Key());
231     }
232   }
233   else{
234     TColStd_MapOfTransient theMap;
235     // neutral point
236     for(;It.More();It.Next()){
237       if(It.Value()->GraphicStatus()==AIS_DS_Displayed)
238         theMap.Add(It.Key());
239     }
240 #ifdef DEBUG
241     cout<<"\tFrom Neutral Point : "<<theMap.Extent()<<endl;
242 #endif
243
244     //parse all local contexts...
245     Standard_Integer NbDisp;
246     for(AIS_DataMapIteratorOfDataMapOfILC it1(myLocalContexts);it1.More();it1.Next()){
247       const Handle(AIS_LocalContext)& LC = it1.Value();
248       NbDisp =  LC->DisplayedObjects(theMap);
249 #ifdef DEBUG
250       cout<<"\tIn Local Context "<<it1.Key()<<" : "<<NbDisp<<endl;
251 #endif
252       
253     }
254     Handle(AIS_InteractiveObject) curIO;
255     Handle(Standard_Transient) Tr;
256       for(TColStd_MapIteratorOfMapOfTransient it2(theMap);it2.More();it2.Next()){
257         Tr = it2.Key();
258         curIO = *((Handle(AIS_InteractiveObject)*) &Tr);
259         aListOfIO.Append(curIO);
260       }
261     }
262 }
263 //=======================================================================
264 //function : DisplayedObjects
265 //purpose  : 
266 //=======================================================================
267
268 void AIS_InteractiveContext::DisplayedObjects(const AIS_KindOfInteractive TheKind,
269                                               const Standard_Integer TheSign,
270                                               AIS_ListOfInteractive& aListOfIO,
271                                               const Standard_Boolean /*OnlyFromNeutral*/) const 
272 {
273   ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_Displayed, aListOfIO );
274 }
275
276 //=======================================================================
277 //function : ErasedObjects
278 //purpose  : 
279 //=======================================================================
280
281 void AIS_InteractiveContext::ErasedObjects(AIS_ListOfInteractive& theListOfIO) const 
282 {
283   ObjectsByDisplayStatus( AIS_DS_Erased, theListOfIO );
284 }
285
286 //=======================================================================
287 //function : ErasedObjects
288 //purpose  : 
289 //=======================================================================
290
291 void AIS_InteractiveContext::ErasedObjects(const AIS_KindOfInteractive TheKind,
292                                            const Standard_Integer TheSign,
293                                            AIS_ListOfInteractive& theListOfIO) const 
294 {
295   ObjectsByDisplayStatus( TheKind, TheSign, AIS_DS_Erased, theListOfIO );
296 }
297
298 //=======================================================================
299 //function : ObjectsByDisplayStatus
300 //purpose  : 
301 //=======================================================================
302
303 void AIS_InteractiveContext::ObjectsByDisplayStatus(const AIS_DisplayStatus theStatus,
304                                                     AIS_ListOfInteractive&  theListOfIO) const 
305 {
306   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
307   for(;It.More();It.Next()){
308     if(It.Value()->GraphicStatus() == theStatus)
309       theListOfIO.Append(It.Key());
310   }
311 }
312
313 //=======================================================================
314 //function : ObjectsByDisplayStatus
315 //purpose  : 
316 //=======================================================================
317
318 void AIS_InteractiveContext::ObjectsByDisplayStatus(const AIS_KindOfInteractive TheKind,
319                                                     const Standard_Integer TheSign,
320                                                     const AIS_DisplayStatus theStatus,
321                                                     AIS_ListOfInteractive& theListOfIO) const 
322 {
323   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
324   for(;It.More();It.Next()){
325     if(It.Value()->GraphicStatus()==theStatus){
326       if(It.Key()->Type()==TheKind){
327         if(TheSign ==-1)
328           theListOfIO.Append(It.Key());
329         else{
330           if(It.Key()->Signature()==TheSign)
331             theListOfIO.Append(It.Key());
332         }
333       }
334     }
335   }
336 }
337
338 //=======================================================================
339 //function : ObjectsInside
340 //purpose  : 
341 //=======================================================================
342
343 void AIS_InteractiveContext::ObjectsInside(AIS_ListOfInteractive& aListOfIO,
344                                            const AIS_KindOfInteractive TheKind,
345                                            const Standard_Integer TheSign) const 
346 {
347   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
348   if(TheKind==AIS_KOI_None && TheSign ==-1){
349     for(;It.More();It.Next()){
350         aListOfIO.Append(It.Key());
351     }
352   }
353   else{
354     for(;It.More();It.Next()){
355       if(It.Key()->Type()==TheKind){
356         if(TheSign ==-1)
357           aListOfIO.Append(It.Key());
358         else{
359           if(It.Key()->Signature()==TheSign)
360             aListOfIO.Append(It.Key());
361         }
362       }
363     }
364   }
365 }
366
367 //=======================================================================
368 //function : Display
369 //purpose  : 
370 //=======================================================================
371
372 void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj,
373                                      const Standard_Boolean updateviewer )
374 {
375   if(anIObj.IsNull()) return;
376   
377   Standard_Integer DispMode,HiMod,SelMode;
378   
379   GetDefModes(anIObj,DispMode,HiMod,SelMode);
380   
381   Handle (AIS_InteractiveContext) aThis = this;
382   if(!anIObj->HasInteractiveContext()) 
383     anIObj->SetContext(aThis);
384   
385   //NO LOCAL CONTEXT OPEN
386   if(!HasOpenedContext()) {
387 #ifndef OCC4373
388     // SAN : Do not return here. Perform advanced display mode analysis a bit later...
389     if(IsDisplayed(anIObj)) return;
390 #endif
391
392     // it did not yet exist
393     if(!myObjects.IsBound(anIObj)){
394       
395       Handle(AIS_GlobalStatus) STATUS= 
396 #ifdef OCC166
397         new AIS_GlobalStatus(AIS_DS_Displayed,DispMode,SelMode);
398 #else
399       new AIS_GlobalStatus(AIS_DS_Displayed,DispMode,0);
400 #endif
401       myObjects.Bind (anIObj,STATUS);
402       myMainPM->Display(anIObj,DispMode);
403       if( myIsAutoActivateSelMode )
404       {
405         if(!mgrSelector->Contains(anIObj))
406            mgrSelector->Load(anIObj);
407         mgrSelector->Activate(anIObj,SelMode,myMainSel);
408       }
409         
410      if(updateviewer) myMainVwr->Update();
411     }
412     // it is somewhere else...
413     else {
414       // CLE
415       // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
416       Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
417       // ENDCLE
418       if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
419       {
420         // SAN : erase presentations for all display modes different from <DispMode>;
421         //       then make sure <DispMode> is displayed and maybe highlighted;
422         //       Finally, activate selection mode <SelMode> if not yet activated.
423         TColStd_ListOfInteger aModesToRemove;
424         TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
425         for(;ItL.More();ItL.Next()){
426
427           Standard_Integer OldMode = ItL.Value();
428
429           if(OldMode!=DispMode){
430             aModesToRemove.Append(OldMode);
431             if(myMainPM->IsHighlighted(anIObj,OldMode))
432               myMainPM->Unhighlight(anIObj,OldMode);
433             myMainPM->Erase(anIObj,OldMode);
434           }
435         }
436
437         for(ItL.Initialize(aModesToRemove);ItL.More();ItL.Next())
438           STATUS->RemoveDisplayMode(ItL.Value());
439
440         if(!STATUS->IsDModeIn(DispMode))
441           STATUS->AddDisplayMode(DispMode);
442
443         myMainPM->Display(anIObj,DispMode);
444         if (STATUS->GraphicStatus() == AIS_DS_Erased)
445         {
446           STATUS->SetGraphicStatus(AIS_DS_Displayed);
447         }
448         if(STATUS->IsHilighted()){
449           myMainPM->Highlight(anIObj,HiMod);
450         }
451         if( myIsAutoActivateSelMode )
452         {
453            if(!mgrSelector->Contains(anIObj))
454               mgrSelector->Load(anIObj);
455            if(!mgrSelector->IsActivated(anIObj,SelMode))
456               mgrSelector->Activate(anIObj,SelMode,myMainSel);
457         }
458       }
459     } 
460     
461     if(anIObj->IsTransparent() && !myMainVwr->Viewer()->Transparency())
462       myMainVwr->Viewer()->SetTransparency(Standard_True);
463     if(updateviewer) myMainVwr->Update();
464   }
465   
466   //  LOCAL CONTEXT OPEN
467   else
468   {
469     myLocalContexts(myCurLocalIndex)->Display(anIObj,DispMode,anIObj->AcceptShapeDecomposition(),SelMode);
470     
471     if(anIObj->IsTransparent() && !myMainVwr->Viewer()->Transparency())
472       myMainVwr->Viewer()->SetTransparency(Standard_True);
473     
474     
475     if(updateviewer) myMainVwr->Update();
476   }
477 }
478
479 //=======================================================================
480 //function : Display
481 //purpose  : 
482 //=======================================================================
483
484 void AIS_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anIObj,
485                                     const Standard_Integer aDisplayMode, 
486                                     const Standard_Integer aSelectionMode, 
487                                     const Standard_Boolean updateviewer, 
488                                     const Standard_Boolean allowdecomposition)
489 {
490   if(anIObj.IsNull()) return;
491
492   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
493   
494   // if no local context...
495   if(!HasOpenedContext()) {
496     //    if(!anIObj->HasDisplayMode())
497     //      anIObj->SetDisplayMode(aDisplayMode);
498   
499     if(!myObjects.IsBound(anIObj)){
500       Handle(AIS_GlobalStatus) STATUS= 
501         new AIS_GlobalStatus(AIS_DS_Displayed,aDisplayMode,aSelectionMode);
502       myObjects.Bind (anIObj,STATUS);
503       myMainPM->Display(anIObj,aDisplayMode);
504       if(aSelectionMode!=-1){
505         if(!mgrSelector->Contains(anIObj))
506           mgrSelector->Load(anIObj,aSelectionMode);
507         mgrSelector->Activate(anIObj,aSelectionMode,myMainSel);
508       }
509       if(updateviewer) myMainVwr->Update();
510     }
511     //    anIObj->SelectionMode(aSelectionMode);
512     else{
513       // CLE
514       // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
515       Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
516       // ENDCLE
517       if(!STATUS->IsDModeIn(aDisplayMode)){
518         myMainPM->Display(anIObj,aDisplayMode);
519         STATUS->AddDisplayMode(aDisplayMode);
520         if(STATUS->IsSubIntensityOn())
521           myMainPM->Color(anIObj,mySubIntensity,aDisplayMode);
522       }
523       if(aSelectionMode!=-1){
524         STATUS->AddSelectionMode(aSelectionMode);
525         mgrSelector->Activate(anIObj,aSelectionMode,myMainSel);
526       }
527       if(updateviewer) myMainVwr->Update();
528       
529     }
530   }
531   else
532     {
533       myLocalContexts(myCurLocalIndex)->Display(anIObj,aDisplayMode,allowdecomposition,aSelectionMode);
534       if(updateviewer) myMainVwr->Update();
535     }  
536 }
537
538
539 //=======================================================================
540 //function : Load
541 //purpose  : 
542 //=======================================================================
543
544 void AIS_InteractiveContext::Load(const Handle(AIS_InteractiveObject)& anIObj,
545                                   const Standard_Integer SelMode,
546                                   const Standard_Boolean AllowDecomposition)
547 {
548   if(anIObj.IsNull()) return;
549   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
550   
551
552   if(!HasOpenedContext()) {
553     if(SelMode==-1 && !AllowDecomposition){
554       Standard_Integer DispMode,HiMod,SelModeDef;
555       
556       GetDefModes(anIObj,DispMode,HiMod,SelModeDef);
557       Handle(AIS_GlobalStatus) STATUS= 
558         new AIS_GlobalStatus(AIS_DS_Erased,DispMode,SelModeDef);
559       myObjects.Bind (anIObj,STATUS);      
560       return;
561     }
562   }
563   myLocalContexts(myCurLocalIndex)->Load(anIObj,AllowDecomposition,SelMode);
564 }
565
566
567 //=======================================================================
568 //function : Erase
569 //purpose  : 
570 //=======================================================================
571
572 void AIS_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anIObj, 
573                                    const Standard_Boolean updateviewer)
574 {
575   if(anIObj.IsNull()) return;
576   
577   if ( !anIObj->IsAutoHilight() )
578     anIObj->ClearSelected();
579   
580   if(!HasOpenedContext()){
581     EraseGlobal(anIObj,updateviewer);
582   }
583   else
584     {
585       // First it is checked if it is possible to remove in the current local context
586       // then one tries to remove in other local contexts, if they allow it...
587       
588       Standard_Boolean WasInCtx = myLocalContexts(myCurLocalIndex)->Erase(anIObj);
589 //      if(!WasInCtx) {
590       AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
591       for (;It.More();It.Next()){
592         if(It.Value()->AcceptErase())
593 #ifdef BUC60722
594           WasInCtx |= It.Value()->Erase(anIObj);
595 #else
596           WasInCtx = It.Value()->Erase(anIObj);
597 #endif
598       }
599       
600       if(!WasInCtx)
601         EraseGlobal(anIObj,updateviewer);
602       else
603         if(updateviewer) myMainVwr->Update();
604     }
605 }
606
607 //=======================================================================
608 //function : EraseAll
609 //purpose  : 
610 //=======================================================================
611
612 void AIS_InteractiveContext::EraseAll(const Standard_Boolean updateviewer)
613 {
614   if(!HasOpenedContext())
615   {
616     for (AIS_DataMapIteratorOfDataMapOfIOStatus ItM(myObjects); ItM.More(); ItM.Next())
617     {
618       if(ItM.Value()->GraphicStatus() == AIS_DS_Displayed)
619         Erase(ItM.Key(),Standard_False);
620     }
621     if(updateviewer)
622     {
623       myMainVwr->Update();
624     }
625   }
626 }
627
628 //=======================================================================
629 //function : DisplayAll
630 //purpose  : 
631 //=======================================================================
632
633 void AIS_InteractiveContext::DisplayAll(const Standard_Boolean updateviewer)
634 {
635   if(!HasOpenedContext()){
636
637     AIS_DisplayStatus aStatus;
638
639     if (!HasOpenedContext())
640     {
641       for (AIS_DataMapIteratorOfDataMapOfIOStatus ItM (myObjects); ItM.More(); ItM.Next())
642       {
643         aStatus = ItM.Value()->GraphicStatus();
644         if (aStatus == AIS_DS_Erased)
645           Display(ItM.Key(),Standard_False);
646       }
647       if(updateviewer)
648       {
649         myMainVwr->Update();
650       }
651     }
652   }
653   
654 }
655
656 //=======================================================================
657 //function : DisplaySelected
658 //purpose  : 
659 //=======================================================================
660
661 void AIS_InteractiveContext::DisplaySelected(const Standard_Boolean updateviewer)
662 {
663   
664   if (!HasOpenedContext())
665   {
666     Standard_Boolean found = Standard_False;
667     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
668     Handle(AIS_InteractiveObject) iObj;
669     for (sel->Init(); sel->More(); sel->Next())
670     {
671       iObj = Handle(AIS_InteractiveObject)::DownCast(sel->Value());
672       Display(iObj,Standard_False);
673       found = Standard_True;
674     }
675     if (found && updateviewer)
676     {
677       myMainVwr->Update();
678     }
679   }
680 }
681
682
683 //=======================================================================
684 //function : EraseSelected
685 //purpose  : 
686 //=======================================================================
687
688 void AIS_InteractiveContext::EraseSelected(const Standard_Boolean updateviewer)
689 {
690   if (!HasOpenedContext())
691   {
692     Standard_Boolean found = Standard_False;
693     Handle(AIS_Selection) sel = AIS_Selection::Selection(myCurrentName.ToCString());
694     Handle(AIS_InteractiveObject) iObj;
695     for (sel->Init();sel->More();sel->Next())
696     {
697       iObj = Handle(AIS_InteractiveObject)::DownCast(sel->Value());
698       Erase(iObj,Standard_False);
699       found = Standard_True;
700     }
701     if(found && updateviewer)
702     {
703       myMainVwr->Update();
704     }
705   }
706 }
707 //=======================================================================
708 //function : 
709 //purpose  : 
710 //=======================================================================
711
712 Standard_Boolean AIS_InteractiveContext::KeepTemporary(const Handle(AIS_InteractiveObject)& anIObj,
713                                                        const Standard_Integer WhichContext)
714 {
715   if(anIObj.IsNull()) return Standard_False;
716
717   if(!HasOpenedContext()) return Standard_False;
718   if(myObjects.IsBound(anIObj)) return Standard_False;
719   if(WhichContext!=-1 && !myLocalContexts.IsBound(WhichContext)) return Standard_False;
720   
721   // Protection : if one tries to preserve a temporary object
722   // which is not in the local active context... rob 11-06-97
723
724   Standard_Integer IsItInLocal = myCurLocalIndex;
725   Standard_Boolean Found(Standard_False);
726
727   while(IsItInLocal>0 && !Found){
728     if(!myLocalContexts.IsBound(IsItInLocal))
729       IsItInLocal--;
730     else if(myLocalContexts(IsItInLocal)->IsIn(anIObj))
731       Found = Standard_True;
732     else
733       IsItInLocal--;
734   }
735
736   if(!Found) return Standard_False;
737   
738
739 //  const Handle(AIS_LocalStatus)& LS = (WhichContext== -1) ? 
740 //    myLocalContexts(IsItInLocal)->Status(anIObj):myLocalContexts(WhichContext)->Status(anIObj);
741   // CLE
742   // const Handle(AIS_LocalStatus)& LS = myLocalContexts(IsItInLocal)->Status(anIObj);
743   Handle(AIS_LocalStatus) LS = myLocalContexts(IsItInLocal)->Status(anIObj);
744   // ENDCLE
745   
746   
747   if(LS->IsTemporary()){
748     Standard_Integer DM,HM,SM;
749     GetDefModes(anIObj,DM,HM,SM);
750     
751     SM = LS->SelectionModes().IsEmpty() ? SM : LS->SelectionModes().First();
752     if(LS->DisplayMode()!= DM ){
753       Standard_Integer LSM =  LS->SelectionModes().IsEmpty() ? -1 : LS->SelectionModes().First();
754       myLocalContexts(IsItInLocal)->Display(anIObj,DM,LS->Decomposed(),LSM);
755     }
756
757     Handle (AIS_GlobalStatus) GS = new AIS_GlobalStatus(AIS_DS_Displayed,
758                                                         DM,
759                                                         SM,
760                                                         Standard_False);
761 //    GS->SubIntensityOn();
762     myObjects.Bind(anIObj,GS);
763     mgrSelector->Load(anIObj);
764     mgrSelector->Activate(anIObj,SM,myMainSel);
765     
766     LS->SetTemporary(Standard_False);
767   }                                 
768   return Standard_True;
769 }
770
771
772 //=======================================================================
773 //purpose  : 
774 //=======================================================================
775
776 AIS_DisplayStatus AIS_InteractiveContext::DisplayStatus(const Handle(AIS_InteractiveObject)& anIObj) const 
777 {
778   if(anIObj.IsNull()) return AIS_DS_None;
779
780   if(myObjects.IsBound(anIObj))
781     return myObjects(anIObj)->GraphicStatus();
782
783   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
784   for(;ItM.More();ItM.Next()){
785     if(ItM.Value()->IsIn(anIObj))
786       return AIS_DS_Temporary;
787   }
788   
789   return AIS_DS_None;
790   
791 }
792
793
794
795
796 //=======================================================================
797 //function : DisplayedModes
798 //purpose  : 
799 //=======================================================================
800
801 const TColStd_ListOfInteger& AIS_InteractiveContext::
802 DisplayedModes(const Handle(AIS_InteractiveObject)& anIObj) const 
803 {
804   return myObjects(anIObj)->DisplayedModes();
805 }
806
807
808 //=======================================================================
809 //function : Remove
810 //purpose  : 
811 //=======================================================================
812 void AIS_InteractiveContext::Remove(const Handle(AIS_InteractiveObject)& anIObj,
813                                     const Standard_Boolean updateviewer)
814 {
815
816   if(anIObj.IsNull()) return;
817
818   if(!HasOpenedContext()){ 
819     ClearGlobal(anIObj,updateviewer);
820   }
821   else
822     {
823       Standard_Boolean  WasInCtx = myLocalContexts(myCurLocalIndex)->Remove(anIObj);
824       AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
825       for (;It.More() ;It.Next()){
826         if(It.Value()->AcceptErase())
827           WasInCtx = It.Value()->Remove(anIObj);
828         
829       }
830       //      if(!WasInCtx)
831       ClearGlobal(anIObj,updateviewer);
832 //      else
833 //      if(updateviewer) myMainVwr->Update();
834     }
835 }
836
837 //=======================================================================
838 //function : RemoveAll
839 //purpose  : 
840 //=======================================================================
841 void AIS_InteractiveContext::RemoveAll(const Standard_Boolean updateviewer)
842 {
843   AIS_ListOfInteractive aList;
844   ObjectsInside(aList);
845   AIS_ListIteratorOfListOfInteractive aListIterator;
846   for(aListIterator.Initialize(aList);aListIterator.More();aListIterator.Next()){
847     Remove(aListIterator.Value(), Standard_False);
848   }
849         
850   if(updateviewer)
851     myMainVwr->Update();
852 }
853
854 //=======================================================================
855 //function : Clear
856 //purpose  : 
857 //=======================================================================
858
859 void AIS_InteractiveContext::Clear(const Handle(AIS_InteractiveObject)& anIObj,
860                                    const Standard_Boolean updateviewer)
861 {
862   if(anIObj.IsNull()) return;
863
864   if(!HasOpenedContext()){ 
865     ClearGlobal(anIObj,updateviewer);
866   }
867   else
868     {
869       
870       Standard_Boolean  WasInCtx = myLocalContexts(myCurLocalIndex)->Remove(anIObj);
871       AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
872       for (;It.More() ;It.Next()){
873         if(It.Value()->AcceptErase())
874           WasInCtx = It.Value()->Remove(anIObj);
875         
876       }
877       if(!WasInCtx)
878         ClearGlobal(anIObj,updateviewer);
879       else
880         if(updateviewer) myMainVwr->Update();
881     }
882 }
883
884
885
886
887 //=======================================================================
888 //function : ClearPrs
889 //purpose  : 
890 //=======================================================================
891
892 void AIS_InteractiveContext::ClearPrs(const Handle(AIS_InteractiveObject)& anIObj,
893                                       const Standard_Integer aMode,
894                                       const Standard_Boolean updateviewer)
895 {
896   if(anIObj.IsNull()) return;
897
898   if(!HasOpenedContext()){
899     ClearGlobalPrs(anIObj,aMode,updateviewer);
900   }
901   else
902     {
903       Standard_Boolean  WasInCtx = myLocalContexts(myCurLocalIndex)->ClearPrs(anIObj,aMode);
904       AIS_DataMapIteratorOfDataMapOfILC It(myLocalContexts);
905       for (;It.More() ;It.Next()){
906         if(It.Value()->AcceptErase())
907           WasInCtx = It.Value()->ClearPrs(anIObj,aMode);
908       }
909       if(!WasInCtx)
910         ClearGlobalPrs(anIObj,aMode,updateviewer);
911       else
912         if(updateviewer) myMainVwr->Update();
913       
914     }
915 }
916
917 //=======================================================================
918 //function : Hilight
919 //purpose  : 
920 //=======================================================================
921
922 void AIS_InteractiveContext::Hilight(const Handle(AIS_InteractiveObject)& anIObj,
923                                      const Standard_Boolean updateviewer)
924 {
925   if(anIObj.IsNull()) return;
926
927   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
928   if (!HasOpenedContext())
929   {
930     if(!myObjects.IsBound(anIObj)) return;
931
932     // CLE
933     // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
934     // const TColStd_ListOfInteger& LL = STATUS->DisplayedModes();
935     Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
936
937     // ENDCLE
938     STATUS->SetHilightStatus (Standard_True);
939
940     if (STATUS->GraphicStatus() == AIS_DS_Displayed)
941     {
942       Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
943       myMainPM->Highlight (anIObj, aHilightMode);
944     }
945   }
946   else
947   {
948     myLocalContexts(myCurLocalIndex)->Hilight(anIObj);
949   }
950
951   if(updateviewer) myMainVwr->Update();
952 }
953 //=======================================================================
954 //function : Hilight
955 //purpose  : 
956 //=======================================================================
957
958 void AIS_InteractiveContext::HilightWithColor(const Handle(AIS_InteractiveObject)& anIObj,
959                                               const Quantity_NameOfColor aCol,
960                                               const Standard_Boolean updateviewer)
961 {
962   if(anIObj.IsNull()) return;
963
964   if(!anIObj->HasInteractiveContext()) anIObj->SetContext(this);
965
966   if (!HasOpenedContext())
967   {
968     if(!myObjects.IsBound(anIObj)) return;
969
970     const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
971     STATUS->SetHilightStatus (Standard_True);
972
973     if (STATUS->GraphicStatus() == AIS_DS_Displayed)
974     {
975       Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
976       myMainPM->Color (anIObj, aCol, aHilightMode);
977       STATUS->SetHilightColor (aCol);
978     }
979   }
980   else
981   {
982     myLocalContexts(myCurLocalIndex)->Hilight(anIObj,aCol);
983   }
984   if(updateviewer) myMainVwr->Update();
985 }
986
987 //=======================================================================
988 //function : Unhilight
989 //purpose  : 
990 //=======================================================================
991
992 void AIS_InteractiveContext::Unhilight(const Handle(AIS_InteractiveObject)& anIObj, const Standard_Boolean updateviewer)
993 {
994   if(anIObj.IsNull()) return;
995
996   if (!HasOpenedContext())
997   {
998     if(!myObjects.IsBound(anIObj)) return;
999
1000     const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
1001     STATUS->SetHilightStatus (Standard_False);
1002     STATUS->SetHilightColor(Quantity_NOC_WHITE);
1003
1004     if (STATUS->GraphicStatus() == AIS_DS_Displayed)
1005     {
1006       Standard_Integer aHilightMode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
1007       myMainPM->Unhighlight (anIObj, aHilightMode);
1008     }
1009   }
1010   else
1011   {
1012     myLocalContexts(myCurLocalIndex)->Unhilight(anIObj);
1013   }
1014   if(updateviewer) myMainVwr->Update();
1015 }
1016
1017 //=======================================================================
1018 //function : IsHilighted
1019 //purpose  : 
1020 //=======================================================================
1021
1022 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj) const 
1023 {
1024   if(anIObj.IsNull()) return Standard_False;
1025
1026   if (!HasOpenedContext()){
1027     if(!myObjects.IsBound(anIObj)) 
1028       return Standard_False;
1029     return myObjects(anIObj)->IsHilighted();
1030   }
1031   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1032   for(;ItM.More();ItM.Next()){
1033     if(ItM.Value()->IsHilighted(anIObj))
1034       return Standard_True;
1035   }
1036   return Standard_False;
1037 }
1038
1039 Standard_Boolean AIS_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anIObj,
1040                                                      Standard_Boolean& WithColor,
1041                                                      Quantity_NameOfColor& TheHiCol) const
1042 {
1043   if(!HasOpenedContext()){
1044     if(myObjects.IsBound(anIObj)){
1045       const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
1046       if(STAT->IsHilighted()){
1047         if(STAT->HilightColor()!=Quantity_NOC_WHITE){
1048           WithColor=Standard_True;
1049           TheHiCol = STAT->HilightColor();
1050         }
1051         else
1052           WithColor = Standard_False;
1053         return Standard_True;
1054       }
1055     }
1056     return Standard_False;
1057   }
1058   Standard_Integer MaxIndex = HighestIndex();
1059   for(Standard_Integer i=MaxIndex;i>=1 ; i--){
1060     if(myLocalContexts.IsBound(i)){
1061       if(myLocalContexts(i)->IsHilighted(anIObj,WithColor,TheHiCol))
1062         return Standard_True;
1063     }
1064     
1065   }
1066   return Standard_False;
1067 }
1068
1069
1070
1071 //=======================================================================
1072 //function : IsDisplayed
1073 //purpose  : 
1074 //=======================================================================
1075
1076 Standard_Boolean AIS_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj) const 
1077 {
1078   if(anIObj.IsNull()) return Standard_False;
1079
1080
1081   if(myObjects.IsBound(anIObj)) 
1082     if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed)
1083       return Standard_True;
1084   
1085   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1086   for(;ItM.More();ItM.Next()){
1087     if(ItM.Value()->IsDisplayed(anIObj))
1088       return Standard_True;
1089   }
1090   return Standard_False;
1091   
1092 }
1093
1094 //=======================================================================
1095 //function : IsDisplayed
1096 //purpose  : 
1097 //=======================================================================
1098
1099 Standard_Boolean AIS_InteractiveContext::
1100 IsDisplayed(const Handle(AIS_InteractiveObject)& anIObj,
1101             const Standard_Integer aMode) const 
1102 {
1103   if(anIObj.IsNull()) return Standard_False;
1104   if(myObjects.IsBound(anIObj)) {
1105     if(myObjects(anIObj)->GraphicStatus()==AIS_DS_Displayed &&
1106        myObjects(anIObj)->IsDModeIn(aMode)) 
1107       return Standard_True;
1108   }
1109   
1110   AIS_DataMapIteratorOfDataMapOfILC ItM(myLocalContexts);
1111   for(;ItM.More();ItM.Next()){
1112     if(ItM.Value()->IsDisplayed(anIObj,aMode))
1113       return Standard_True;
1114   }
1115   return Standard_False;
1116 }
1117
1118
1119 //=======================================================================
1120 //function : DisplayPriority
1121 //purpose  : 
1122 //=======================================================================
1123
1124 Standard_Integer AIS_InteractiveContext::
1125 DisplayPriority(const Handle(AIS_InteractiveObject)& anIObj) const 
1126 {
1127   if(anIObj.IsNull()) return -1;
1128
1129   if (myObjects.IsBound(anIObj))
1130   {
1131     Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
1132     if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
1133     {
1134       Standard_Integer aDispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : 
1135                                    (anIObj->AcceptDisplayMode(myDisplayMode)? myDisplayMode : 0);
1136       return myMainPM->DisplayPriority (anIObj, aDispMode);
1137     }
1138   }
1139   return 0;
1140 }
1141 //=======================================================================
1142 //function : SetDisplayPriority
1143 //purpose  : 
1144 //=======================================================================
1145
1146 void AIS_InteractiveContext::SetDisplayPriority(const Handle(AIS_InteractiveObject)& anIObj,
1147                                                const Standard_Integer aPriority)
1148 {
1149   if(anIObj.IsNull())
1150     return;
1151   if(!anIObj->HasInteractiveContext())
1152     anIObj->SetContext(this);
1153   if(myObjects.IsBound(anIObj))
1154   {
1155     Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
1156
1157     if (STATUS->GraphicStatus() == AIS_DS_Displayed || STATUS->GraphicStatus() == AIS_DS_Erased)
1158     {
1159       Standard_Integer aDisplayMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : 
1160                                       (anIObj->AcceptDisplayMode(myDisplayMode)? myDisplayMode : 0);
1161       myMainPM->SetDisplayPriority (anIObj, aDisplayMode, aPriority);
1162     }
1163   }
1164   else if (HasOpenedContext())
1165   {
1166     myLocalContexts(myCurLocalIndex)->SetDisplayPriority(anIObj,aPriority);
1167   }
1168 }
1169
1170 //=======================================================================
1171 //function : Redisplay
1172 //purpose  : 
1173 //=======================================================================
1174
1175 void AIS_InteractiveContext::Redisplay(const Handle(AIS_InteractiveObject)& anIObj,
1176                                       const Standard_Boolean updateviewer,
1177                                       const Standard_Boolean allmodes)
1178 {
1179   if(AISDebugModeOn()){
1180     cout<<"===>AIS_InteractiveContext::Redisplay de :";
1181     cout<<anIObj->DynamicType()->Name()<<endl;
1182   }
1183
1184   RecomputePrsOnly(anIObj,updateviewer,allmodes);
1185   RecomputeSelectionOnly(anIObj);
1186 }
1187
1188 //=======================================================================
1189 //function : Redisplay
1190 //purpose  : 
1191 //=======================================================================
1192
1193 void AIS_InteractiveContext::Redisplay(const AIS_KindOfInteractive KOI,
1194                                        const Standard_Integer /*Sign*/,
1195                                       const Standard_Boolean updateviewer)
1196 {
1197   Standard_Boolean found_viewer(Standard_False);
1198   // update
1199   for(AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);It.More();It.Next()){
1200     // CLE
1201     // const Handle(AIS_InteractiveObject)& IO = It.Key();
1202     Handle(AIS_InteractiveObject) IO = It.Key();
1203     // ENDCLE
1204     if(IO->Type()== KOI){ 
1205 #ifdef DEB
1206 //      Standard_Boolean good = (Sign==-1)? Standard_True : 
1207 //        ((IO->Signature()==Sign)? Standard_True:Standard_False);
1208 #endif
1209       Redisplay(IO,Standard_False);
1210       if (It.Value()->GraphicStatus() == AIS_DS_Displayed)
1211       {
1212         found_viewer = Standard_True;
1213       }
1214     }
1215   }
1216   // update viewer...
1217   if(updateviewer && found_viewer)
1218   {
1219     myMainVwr->Update();
1220   }
1221 }
1222
1223
1224 //=======================================================================
1225 //function : RecomputePrsOnly
1226 //purpose  : 
1227 //=======================================================================
1228
1229 void AIS_InteractiveContext::RecomputePrsOnly(const Handle(AIS_InteractiveObject)& anIObj,
1230                                               const Standard_Boolean updateviewer,
1231                                               const Standard_Boolean allmodes)
1232 {
1233   if(anIObj.IsNull()) return;
1234   anIObj->Update(allmodes);
1235
1236   if (!updateviewer)
1237   {
1238     return;
1239   }
1240
1241   if (HasOpenedContext() ||
1242      (myObjects.IsBound(anIObj) && myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed))
1243   {
1244     myMainVwr->Update();
1245   }
1246 }
1247 //=======================================================================
1248 //function : RecomputeSelectionOnly
1249 //purpose  : 
1250 //=======================================================================
1251 void AIS_InteractiveContext::RecomputeSelectionOnly(const Handle(AIS_InteractiveObject)& anIObj)
1252 {
1253   if(anIObj.IsNull()) return;
1254   mgrSelector->RecomputeSelection(anIObj);
1255
1256
1257
1258   TColStd_ListOfInteger LI;
1259   TColStd_ListIteratorOfListOfInteger Lit;
1260   ActivatedModes(anIObj,LI);
1261   if(!HasOpenedContext()){
1262     if(!myObjects.IsBound(anIObj)) return;
1263
1264     if (myObjects(anIObj)->GraphicStatus() == AIS_DS_Displayed)
1265     {
1266       for(Lit.Initialize(LI);Lit.More();Lit.Next())
1267       {
1268         mgrSelector->Activate(anIObj,Lit.Value(),myMainSel);
1269       }
1270     }
1271   }
1272 }
1273
1274 //=======================================================================
1275 //function : Update
1276 //purpose  : 
1277 //=======================================================================
1278
1279 void AIS_InteractiveContext::Update(const Handle(AIS_InteractiveObject)& anIObj,
1280                                     const Standard_Boolean updateviewer)
1281 {
1282   if(anIObj.IsNull()) return;
1283
1284   
1285
1286   TColStd_ListOfInteger LL;
1287   anIObj->ToBeUpdated(LL);
1288   TColStd_ListIteratorOfListOfInteger ITI(LL);
1289   Standard_Boolean wasupdated(Standard_False);
1290   
1291   for (;ITI.More();ITI.Next()){
1292     anIObj->Update(ITI.Value(),Standard_False);
1293     wasupdated = Standard_True;
1294   }
1295   
1296   if(wasupdated)
1297     mgrSelector->Update(anIObj);
1298   
1299   if(updateviewer){
1300     if(!myObjects.IsBound(anIObj)) return;
1301     switch(myObjects(anIObj)->GraphicStatus()){
1302     case AIS_DS_Displayed:
1303     case AIS_DS_Temporary:
1304       myMainVwr->Update();
1305       break;
1306     default:
1307       break;
1308     }
1309   }
1310 }
1311
1312
1313
1314 //=======================================================================
1315 //function : SetLocation
1316 //purpose  : 
1317 //=======================================================================
1318
1319 void AIS_InteractiveContext::SetLocation(const Handle(AIS_InteractiveObject)& anIObj,
1320                                          const TopLoc_Location& aLoc)
1321 {
1322   if(anIObj.IsNull()) return;
1323
1324
1325   if(anIObj->HasLocation() && aLoc.IsIdentity()){
1326     anIObj->ResetLocation();
1327     mgrSelector->Update(anIObj,Standard_False);
1328     return;
1329   }
1330   if(aLoc.IsIdentity()) return ;
1331
1332   // first reset the previous location to properly clean everything...
1333   if(anIObj->HasLocation())
1334     anIObj->ResetLocation();
1335
1336
1337   anIObj->SetLocation(aLoc);
1338   
1339   if(!HasOpenedContext())
1340     mgrSelector->Update(anIObj,Standard_False);
1341   else
1342     {
1343       // CLE
1344       // const Handle(StdSelect_ViewerSelector3d)& tempSel = myLocalContexts(myCurLocalIndex)->MainSelector();
1345       Handle(StdSelect_ViewerSelector3d) tempSel = myLocalContexts(myCurLocalIndex)->MainSelector();
1346       // ENDCLE
1347       mgrSelector->Update(anIObj,tempSel,Standard_False);
1348     }
1349 }
1350 //=======================================================================
1351 //function : ResetLocation
1352 //purpose  : 
1353 //=======================================================================
1354 void AIS_InteractiveContext::ResetLocation(const Handle(AIS_InteractiveObject)& anIObj)
1355 {
1356   if(anIObj.IsNull()) return;
1357
1358   anIObj->ResetLocation();
1359   mgrSelector->Update(anIObj,Standard_False);
1360 }
1361
1362 //=======================================================================
1363 //function : HasLocation
1364 //purpose  : 
1365 //=======================================================================
1366
1367 Standard_Boolean AIS_InteractiveContext::
1368 HasLocation(const Handle(AIS_InteractiveObject)& anIObj) const
1369 {
1370   if(anIObj.IsNull()) return Standard_False;
1371
1372   return anIObj->HasLocation();
1373 }
1374
1375 const TopLoc_Location& AIS_InteractiveContext::
1376 Location(const Handle(AIS_InteractiveObject)& anIObj) const
1377 {
1378   return anIObj->Location();
1379 }
1380
1381 //=======================================================================
1382 //function : SetDeviationCoefficient
1383 //purpose  : 
1384 //=======================================================================
1385
1386 void AIS_InteractiveContext::SetDeviationCoefficient(const Standard_Real aCoefficient)
1387 {
1388   myDefaultDrawer->SetDeviationCoefficient(aCoefficient);
1389 }
1390 //=======================================================================
1391 //function : SetDeviationAngle
1392 //purpose  : 
1393 //=======================================================================
1394
1395 void AIS_InteractiveContext::SetDeviationAngle(const Standard_Real anAngle)
1396 {
1397   myDefaultDrawer->SetDeviationCoefficient(anAngle);
1398 }
1399
1400 //=======================================================================
1401 //function : DeviationAngle
1402 //purpose  : Gets  deviationAngle
1403 //=======================================================================
1404
1405 Standard_Real AIS_InteractiveContext::DeviationAngle() const
1406 {
1407   //return M_PI/180.0e0 ;
1408     return myDefaultDrawer->DeviationAngle();
1409 }
1410
1411 //=======================================================================
1412 //function : DeviationCoefficient
1413 //purpose  : 
1414 //=======================================================================
1415
1416 Standard_Real AIS_InteractiveContext::DeviationCoefficient() const 
1417 {
1418   return myDefaultDrawer->DeviationCoefficient();
1419 }
1420 //=======================================================================
1421 //function : SetHLRDeviationCoefficient
1422 //purpose  : 
1423 //=======================================================================
1424
1425 void AIS_InteractiveContext::SetHLRDeviationCoefficient(const Standard_Real aCoefficient)
1426 {
1427   myDefaultDrawer->SetHLRDeviationCoefficient(aCoefficient);
1428 }
1429
1430 //=======================================================================
1431 //function : HLRDeviationCoefficient
1432 //purpose  : 
1433 //=======================================================================
1434
1435 Standard_Real AIS_InteractiveContext::HLRDeviationCoefficient() const 
1436 {
1437   return myDefaultDrawer->HLRDeviationCoefficient();
1438 }
1439
1440 //=======================================================================
1441 //function : SetHLRAngle
1442 //purpose  : 
1443 //=======================================================================
1444
1445 void AIS_InteractiveContext::SetHLRAngle(const Standard_Real anAngle)
1446 {
1447   myDefaultDrawer->SetHLRAngle(anAngle);
1448 }
1449
1450 //=======================================================================
1451 //function : SetHLRAngleAndDeviation
1452 //purpose  : compute with anangle a HLRAngle and a HLRDeviationCoefficient 
1453 //           and set them in myHLRAngle and in myHLRDeviationCoefficient
1454 //           of myDefaultDrawer 
1455 //=======================================================================
1456
1457 void AIS_InteractiveContext::SetHLRAngleAndDeviation(const Standard_Real anAngle)
1458 {
1459
1460   Standard_Real OutAngl,OutDefl;
1461   HLRBRep::PolyHLRAngleAndDeflection(anAngle,OutAngl,OutDefl);
1462
1463   myDefaultDrawer->SetHLRAngle(OutAngl);
1464   myDefaultDrawer->SetHLRDeviationCoefficient(OutDefl);
1465
1466 }
1467
1468 //=======================================================================
1469 //function : HLRAngle
1470 //purpose  : 
1471 //=======================================================================
1472
1473 Standard_Real AIS_InteractiveContext::HLRAngle() const 
1474 {
1475   return myDefaultDrawer->HLRAngle();
1476 }
1477
1478 //=======================================================================
1479 //function : SetDisplayMode
1480 //purpose  : 
1481 //=======================================================================
1482
1483 void AIS_InteractiveContext::SetDisplayMode(const AIS_DisplayMode aMode,
1484                                            const Standard_Boolean updateviewer)
1485 {
1486   if(aMode==myDisplayMode) return;
1487   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
1488
1489   for(;It.More();It.Next()){
1490     // CLE
1491     // const Handle(AIS_InteractiveObject)& anObj = It.Key();
1492     Handle(AIS_InteractiveObject) anObj = It.Key();
1493     // ENDCLE
1494     Standard_Boolean Processed = (anObj->IsKind(STANDARD_TYPE(AIS_Shape)) ||
1495                                   anObj->IsKind(STANDARD_TYPE(AIS_ConnectedShape)) ||
1496                                   anObj->IsKind(STANDARD_TYPE(AIS_MultipleConnectedShape)) );
1497     
1498     if ((!anObj->HasDisplayMode()) && Processed) 
1499       {
1500         if(anObj->AcceptDisplayMode(aMode)){
1501           // CLE
1502           // const Handle(AIS_GlobalStatus)& STATUS = It.Value();
1503           Handle(AIS_GlobalStatus) STATUS = It.Value();
1504           // ENDCLE
1505           if(STATUS->IsDModeIn(myDisplayMode))
1506             STATUS->RemoveDisplayMode(myDisplayMode);
1507           
1508           STATUS->AddDisplayMode(aMode);
1509           
1510           if(STATUS->GraphicStatus()== AIS_DS_Displayed){
1511             myMainPM->SetVisibility (anObj, myDisplayMode, Standard_False);
1512             myMainPM->Display(anObj, aMode);
1513             if(STATUS->IsSubIntensityOn())
1514               myMainPM->Color(anObj,mySubIntensity,aMode);
1515           }
1516           //  myDisplayMode = aMode;
1517         }
1518       }
1519     
1520   } 
1521   myDisplayMode = aMode;
1522   if(updateviewer) myMainVwr->Update();
1523 }
1524
1525 //=======================================================================
1526 //function : SetDisplayMode
1527 //purpose  : 
1528 //=======================================================================
1529
1530 void AIS_InteractiveContext::SetDisplayMode(const Handle(AIS_InteractiveObject)& anIObj, 
1531                                            const Standard_Integer aMode,
1532                                            const Standard_Boolean updateviewer)
1533 {
1534   
1535   if(!anIObj->HasInteractiveContext())
1536     anIObj->SetContext(this);
1537   if(!HasOpenedContext()){
1538     
1539     if(!myObjects.IsBound(anIObj)) 
1540       anIObj->SetDisplayMode(aMode);
1541     else if( anIObj->AcceptDisplayMode(aMode) ) 
1542     {
1543       // CLE
1544       // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
1545       Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
1546       // ENDCLE
1547       // SAN : erase presentations for all display modes different from <aMode>
1548       if(STATUS->GraphicStatus()==AIS_DS_Displayed){
1549         TColStd_ListOfInteger aModesToRemove;
1550         TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
1551         for(;ItL.More();ItL.Next()){
1552
1553           Standard_Integer OldMode = ItL.Value();
1554
1555           if(OldMode!=aMode){
1556             aModesToRemove.Append(OldMode);
1557             if(myMainPM->IsHighlighted(anIObj,OldMode))
1558               myMainPM->Unhighlight(anIObj,OldMode);
1559             myMainPM->SetVisibility (anIObj, OldMode, Standard_False);
1560           }
1561         }
1562
1563         for(ItL.Initialize(aModesToRemove);ItL.More();ItL.Next())
1564           STATUS->RemoveDisplayMode(ItL.Value());
1565
1566         if(!STATUS->IsDModeIn(aMode))
1567           STATUS->AddDisplayMode(aMode);
1568
1569         myMainPM->Display(anIObj,aMode);
1570         Standard_Integer DM,HM,SM;
1571         GetDefModes(anIObj,DM,HM,SM);
1572         if(STATUS->IsHilighted()){
1573           myMainPM->Highlight(anIObj,HM);
1574         }
1575         if(STATUS->IsSubIntensityOn()){
1576           myMainPM->Color(anIObj,mySubIntensity,aMode);
1577         }
1578         if(anIObj->IsTransparent() && !myMainVwr->Viewer()->Transparency())
1579           myMainVwr->Viewer()->SetTransparency(Standard_True);
1580         
1581         if(updateviewer) myMainVwr->Update();
1582       }
1583       anIObj->SetDisplayMode(aMode);
1584     }
1585   }
1586 }
1587
1588 //=======================================================================
1589 //function : UnsetDisplayMode
1590 //purpose  : 
1591 //=======================================================================
1592
1593 void AIS_InteractiveContext::
1594 UnsetDisplayMode(const Handle(AIS_InteractiveObject)& anIObj,
1595                  const Standard_Boolean updateviewer)
1596 {
1597   if(anIObj.IsNull()) return ;
1598   if(!anIObj->HasDisplayMode()) return;
1599   
1600   if(!myObjects.IsBound(anIObj))
1601     anIObj->UnsetDisplayMode();
1602   else
1603     {
1604       Standard_Integer OldMode = anIObj->DisplayMode();
1605       if(myDisplayMode==OldMode) return;
1606       const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
1607       STATUS->RemoveDisplayMode(OldMode);
1608       if(!STATUS->IsDModeIn(myDisplayMode))
1609         STATUS->AddDisplayMode(myDisplayMode);
1610       if(STATUS->GraphicStatus()==AIS_DS_Displayed){
1611         if(myMainPM->IsHighlighted(anIObj,OldMode))
1612           myMainPM->Unhighlight(anIObj,OldMode);
1613         myMainPM->SetVisibility (anIObj, OldMode, Standard_False);
1614         myMainPM->Display(anIObj,myDisplayMode);
1615         Standard_Integer DM,HM,SM;
1616         GetDefModes(anIObj,DM,HM,SM);
1617         if(STATUS->IsHilighted()){
1618           myMainPM->Highlight(anIObj,HM);
1619         }
1620         if(STATUS->IsSubIntensityOn()){
1621           myMainPM->Color(anIObj,mySubIntensity,myDisplayMode);
1622         }
1623         if(updateviewer) myMainVwr->Update();
1624       }
1625       anIObj->UnsetDisplayMode();
1626       
1627     }
1628 }
1629
1630 //=======================================================================
1631 //function : SetCurrentFacingModel
1632 //purpose  : 
1633 //=======================================================================
1634
1635 void AIS_InteractiveContext::SetCurrentFacingModel(
1636                         const Handle(AIS_InteractiveObject)& anIObj,
1637                         const Aspect_TypeOfFacingModel aModel)
1638 {
1639   if (  !anIObj.IsNull ()  )
1640     anIObj->SetCurrentFacingModel(aModel);
1641 }
1642
1643 //=======================================================================
1644 //function : SetColor
1645 //purpose  : 
1646 //=======================================================================
1647
1648 void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIObj, 
1649                                      const Quantity_NameOfColor aColor,
1650                                      const Standard_Boolean updateviewer)
1651 {
1652   SetColor(anIObj,Quantity_Color(aColor),updateviewer);
1653 }
1654
1655 void AIS_InteractiveContext::SetColor(const Handle(AIS_InteractiveObject)& anIObj, 
1656                                      const Quantity_Color &aColor,
1657                                      const Standard_Boolean updateviewer)
1658 {
1659   if(anIObj.IsNull()) return ;
1660  
1661   if(!anIObj->HasInteractiveContext())
1662     anIObj->SetContext(this);
1663   anIObj->SetColor(aColor);
1664   if(anIObj->RecomputeEveryPrs())
1665     anIObj->Redisplay();
1666   else
1667     {
1668       Standard_Integer NbDisp=0;
1669       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
1670       for (;ITI.More();ITI.Next())
1671         {
1672           anIObj->Update(ITI.Value(),Standard_False);
1673           NbDisp++;
1674         }
1675       anIObj->SetRecomputeOk();
1676 #ifdef DEB
1677       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1678 #endif
1679     }
1680
1681
1682 #ifdef DEB
1683 //   // pour isg
1684 //   if(anIObj->Type()==AIS_KOI_Datum && anIObj->Signature()==3){
1685 //     Handle(AIS_Trihedron) Tr = *((Handle(AIS_Trihedron)*)&anIObj);
1686 //     Standard_Real Lx = myDefaultDrawer->DatumAspect()->FirstAxisLength();
1687 //     gp_Trsf T; 
1688 //     gp_Dir D =Tr->Component()->XDirection();
1689 //     gp_Pnt O = Tr->Component()->Location();
1690 //     gp_Vec V(D);V*=Lx/5.;
1691 //     T.SetRotation(gp_Ax1(O,D),M_PI/6.);
1692 //     T.SetTranslationPart(V);
1693 //     TopLoc_Location L,IncLoc(T);
1694    
1695 //     for(Standard_Integer I=1;I<90;I++){
1696 //       if(anIObj->HasLocation())
1697 //      L = anIObj->Location() * IncLoc;
1698 //       else
1699 //      L = IncLoc;
1700 //       SetLocation(anIObj,L);
1701 //       UpdateCurrentViewer();
1702 //     }
1703 //      for(I=1;I<90;I++){
1704 //        L = anIObj->Location() /IncLoc;
1705 //       SetLocation(anIObj,L);
1706 //       UpdateCurrentViewer();
1707 //     }
1708 //    ResetLocation(anIObj);
1709 //   }
1710  #endif
1711   if(updateviewer) UpdateCurrentViewer();
1712 }
1713
1714 //=======================================================================
1715 //function : SetDeviationCoefficient
1716 //purpose  : 
1717 //=======================================================================
1718
1719 void AIS_InteractiveContext::SetDeviationCoefficient(
1720                                      const Handle(AIS_InteractiveObject)& anIObj, 
1721                                      const Standard_Real   aCoefficient,
1722                                      const Standard_Boolean updateviewer)
1723 {
1724 //  cout<<" Coefficient:"<< aCoefficient <<endl;
1725   if(anIObj.IsNull()) return ;
1726  
1727   if(!anIObj->HasInteractiveContext())
1728     anIObj->SetContext(this);
1729
1730   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1731   if(anIObj->Type()!=AIS_KOI_Object && anIObj->Type()!=AIS_KOI_Shape) return;
1732   if(anIObj->Signature()!=0) return;
1733   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnDeviationCoefficient(aCoefficient);
1734
1735
1736
1737   if(anIObj->RecomputeEveryPrs())
1738     anIObj->Redisplay();
1739   else
1740     {
1741       Standard_Integer NbDisp=0;
1742       TColStd_ListOfInteger LL;
1743       anIObj->ToBeUpdated(LL);
1744       TColStd_ListIteratorOfListOfInteger ITI(LL);
1745       for (;ITI.More();ITI.Next())
1746         {
1747           anIObj->Update(ITI.Value(),Standard_False);
1748           NbDisp++;
1749         }
1750       anIObj->SetRecomputeOk();
1751 #ifdef DEB
1752       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1753 #endif
1754     }
1755   if(updateviewer) UpdateCurrentViewer();
1756 }
1757
1758 //=======================================================================
1759 //function : SetHLRDeviationCoefficient
1760 //purpose  : 
1761 //=======================================================================
1762
1763 void AIS_InteractiveContext::SetHLRDeviationCoefficient(
1764                                      const Handle(AIS_InteractiveObject)& anIObj, 
1765                                      const Standard_Real    aCoefficient,
1766                                      const Standard_Boolean updateviewer)
1767 {
1768 //  cout<<" HLRCoefficient:"<< aCoefficient <<endl;
1769   if(anIObj.IsNull()) return ;
1770  
1771   if(!anIObj->HasInteractiveContext())
1772     anIObj->SetContext(this);
1773   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1774   if(anIObj->Type()!=AIS_KOI_Object && anIObj->Type()!=AIS_KOI_Shape) return;
1775   if(anIObj->Signature()!=0) return;
1776   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnHLRDeviationCoefficient(aCoefficient);
1777
1778
1779
1780   if(anIObj->RecomputeEveryPrs())
1781     anIObj->Redisplay();
1782   else
1783     {
1784       Standard_Integer NbDisp=0;
1785
1786       TColStd_ListOfInteger LL;
1787       anIObj->ToBeUpdated(LL);
1788       TColStd_ListIteratorOfListOfInteger ITI(LL);
1789       for (;ITI.More();ITI.Next())
1790         {
1791           anIObj->Update(ITI.Value(),Standard_False);
1792           NbDisp++;
1793         }
1794       anIObj->SetRecomputeOk();
1795 #ifdef DEB
1796       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1797 #endif
1798     }
1799   if(updateviewer) UpdateCurrentViewer();
1800 }
1801
1802
1803 //=======================================================================
1804 //function : SetDeviationAngle
1805 //purpose  : 
1806 //=======================================================================
1807
1808 void AIS_InteractiveContext::SetDeviationAngle(
1809                                      const Handle(AIS_InteractiveObject)& anIObj, 
1810                                      const Standard_Real   anAngle,
1811                                      const Standard_Boolean updateviewer)
1812 {
1813 //  cout<<" Angle:"<< anAngle <<endl;
1814   if(anIObj.IsNull()) return ;
1815  
1816   if(!anIObj->HasInteractiveContext())
1817     anIObj->SetContext(this);
1818   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1819   if(anIObj->Type()!=AIS_KOI_Shape) return;
1820   if(anIObj->Signature()!=0) return;
1821   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnDeviationAngle(anAngle);
1822
1823
1824   if(anIObj->RecomputeEveryPrs())
1825     anIObj->Redisplay();
1826   else
1827     {
1828       Standard_Integer NbDisp=0;
1829       TColStd_ListOfInteger LL;
1830       anIObj->ToBeUpdated(LL);
1831       TColStd_ListIteratorOfListOfInteger ITI(LL);
1832       for (;ITI.More();ITI.Next())
1833         {
1834           anIObj->Update(ITI.Value(),Standard_False);
1835           NbDisp++;
1836         }
1837       anIObj->SetRecomputeOk();
1838 #ifdef DEB
1839       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1840 #endif
1841     }
1842   if(updateviewer) UpdateCurrentViewer();
1843 }
1844 //=======================================================================
1845 //function : SetDeviationAngle
1846 //purpose  : 
1847 //=======================================================================
1848
1849 void AIS_InteractiveContext::SetAngleAndDeviation(
1850                                      const Handle(AIS_InteractiveObject)& anIObj, 
1851                                      const Standard_Real   anAngle,
1852                                      const Standard_Boolean updateviewer)
1853 {
1854 //  cout<<" Angle:"<< anAngle <<endl;
1855   if(anIObj.IsNull()) return ;
1856 //   Standard_Real anAngleRad = M_PI*anAngle/180; test rob...
1857   if(!anIObj->HasInteractiveContext())
1858     anIObj->SetContext(this);
1859
1860   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1861   if(anIObj->Type()!=AIS_KOI_Shape) return;
1862   if(anIObj->Signature()!=0) return;
1863   (*((Handle(AIS_Shape)*)&anIObj))->SetAngleAndDeviation(anAngle);
1864
1865
1866   if(anIObj->RecomputeEveryPrs())
1867     anIObj->Redisplay();
1868   else
1869     Update(anIObj,updateviewer);
1870 }
1871
1872 //=======================================================================
1873 //function : SetDeviationAngle
1874 //purpose  : 
1875 //=======================================================================
1876
1877 void AIS_InteractiveContext::SetHLRAngleAndDeviation(
1878                                      const Handle(AIS_InteractiveObject)& anIObj, 
1879                                      const Standard_Real   anAngle,
1880                                      const Standard_Boolean updateviewer)
1881 {
1882 //  cout<<" Angle:"<< anAngle <<endl;
1883
1884   if(anIObj.IsNull()) return ;
1885    if(!anIObj->HasInteractiveContext())
1886     anIObj->SetContext(this);
1887
1888   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1889   if(anIObj->Type()!=AIS_KOI_Shape) return;
1890   if(anIObj->Signature()!=0) return;
1891   (*((Handle(AIS_Shape)*)&anIObj))->SetHLRAngleAndDeviation(anAngle);
1892
1893
1894   if(anIObj->RecomputeEveryPrs())
1895     anIObj->Redisplay();
1896   else
1897     {
1898       Standard_Integer NbDisp=0;
1899
1900       TColStd_ListOfInteger LL;
1901       anIObj->ToBeUpdated(LL);
1902       TColStd_ListIteratorOfListOfInteger ITI(LL);
1903       for (;ITI.More();ITI.Next())
1904         {
1905           anIObj->Update(ITI.Value(),Standard_False);
1906           NbDisp++;
1907         }
1908       anIObj->SetRecomputeOk();
1909 #ifdef DEB
1910       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1911 #endif
1912     }
1913   if(updateviewer) UpdateCurrentViewer();
1914 }
1915
1916 //=======================================================================
1917 //function : SetHLRDeviationAngle
1918 //purpose  : 
1919 //=======================================================================
1920
1921 void AIS_InteractiveContext::SetHLRDeviationAngle(
1922                                      const Handle(AIS_InteractiveObject)& anIObj, 
1923                                      const Standard_Real   anAngle,
1924                                      const Standard_Boolean updateviewer)
1925 {
1926 //  cout<<" HLRAngle:"<< anAngle <<endl;
1927   if(anIObj.IsNull()) return ;
1928  
1929   if(!anIObj->HasInteractiveContext())
1930     anIObj->SetContext(this);
1931   // To be modified after the related methods of AIS_Shape are passed to InteractiveObject
1932   if( anIObj->Type()!=AIS_KOI_Shape) return;
1933   if(anIObj->Signature()!=0) return;
1934   (*((Handle(AIS_Shape)*)&anIObj))->SetOwnHLRDeviationAngle(anAngle);
1935
1936
1937   if(anIObj->RecomputeEveryPrs())
1938     anIObj->Redisplay();
1939   else
1940     {
1941       Standard_Integer NbDisp=0;
1942       TColStd_ListOfInteger LL;
1943       anIObj->ToBeUpdated(LL);
1944       TColStd_ListIteratorOfListOfInteger ITI(LL);
1945       for (;ITI.More();ITI.Next())
1946         {
1947           anIObj->Update(ITI.Value(),Standard_False);
1948           NbDisp++;
1949         }
1950       anIObj->SetRecomputeOk();
1951 #ifdef DEB
1952       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1953 #endif
1954     }
1955   if(updateviewer) UpdateCurrentViewer();
1956 }
1957
1958 //=======================================================================
1959 //function : UnsetColor
1960 //purpose  : 
1961 //=======================================================================
1962
1963 void AIS_InteractiveContext::UnsetColor(const Handle(AIS_InteractiveObject)& anIObj,
1964                                      const Standard_Boolean updateviewer)
1965 {
1966   if(anIObj.IsNull()) return ;
1967    anIObj->UnsetColor();
1968   if(anIObj->RecomputeEveryPrs())
1969     anIObj->Redisplay();
1970   else
1971     {
1972       Standard_Integer NbDisp =0;
1973       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
1974       for (;ITI.More();ITI.Next())
1975         {
1976           anIObj->Update(ITI.Value(),Standard_False);
1977           NbDisp++;
1978         }
1979 #ifdef DEB
1980       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
1981 #endif
1982       anIObj->SetRecomputeOk();
1983     }
1984   if(updateviewer) 
1985     UpdateCurrentViewer();
1986 }
1987
1988 //=======================================================================
1989 //function : HasColor
1990 //purpose  : 
1991 //=======================================================================
1992
1993 Standard_Boolean AIS_InteractiveContext::HasColor(const Handle(AIS_InteractiveObject)& anIObj) const 
1994 {
1995   return anIObj->HasColor();
1996
1997 }
1998
1999 //=======================================================================
2000 //function : Color
2001 //purpose  : 
2002 //=======================================================================
2003
2004 Quantity_NameOfColor AIS_InteractiveContext::Color(const Handle(AIS_InteractiveObject)& anIObj) const 
2005 {
2006   return anIObj->Color();
2007 }
2008
2009 void AIS_InteractiveContext::Color(const Handle(AIS_InteractiveObject)& anIObj,
2010                                    Quantity_Color &aColor) const
2011 {
2012   anIObj->Color(aColor);
2013 }
2014
2015 //=======================================================================
2016 //function : Width
2017 //purpose  : 
2018 //=======================================================================
2019
2020 Standard_Real AIS_InteractiveContext::Width(const Handle(AIS_InteractiveObject)& anIObj) const 
2021 {
2022   return anIObj->Width();
2023 }
2024
2025 //=======================================================================
2026 //function : SetWidth
2027 //purpose  : 
2028 //=======================================================================
2029
2030 void AIS_InteractiveContext::SetWidth(const Handle(AIS_InteractiveObject)& anIObj,
2031                                      const Standard_Real aValue,
2032                                      const Standard_Boolean updateviewer)
2033 {
2034   if(anIObj.IsNull()) return ;
2035  
2036   if(!anIObj->HasInteractiveContext())
2037     anIObj->SetContext(this);
2038   anIObj->SetWidth(aValue);
2039   if(anIObj->RecomputeEveryPrs())
2040     anIObj->Redisplay();
2041   else
2042     {
2043       Standard_Integer NbDisp=0;
2044       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2045       for (;ITI.More();ITI.Next())
2046         {
2047           anIObj->Update(ITI.Value(),Standard_False);
2048           NbDisp++;
2049         }
2050 #ifdef DEB
2051       cout<<"nb of modes to recalculate : "<<NbDisp<<endl;
2052 #endif
2053       anIObj->SetRecomputeOk();
2054     }
2055    if(updateviewer) 
2056     UpdateCurrentViewer();
2057 }
2058
2059 //=======================================================================
2060 //function : UnsetWidth
2061 //purpose  : 
2062 //=======================================================================
2063
2064 void AIS_InteractiveContext::UnsetWidth(const Handle(AIS_InteractiveObject)& anIObj,
2065                                        const Standard_Boolean updateviewer)
2066 {
2067   if(anIObj.IsNull()) return ;
2068    anIObj->UnsetWidth();
2069   if(anIObj->RecomputeEveryPrs())
2070     anIObj->Redisplay();
2071   else
2072     {
2073       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2074       for (;ITI.More();ITI.Next())
2075         {
2076           anIObj->Update(ITI.Value(),Standard_False);
2077         }
2078       anIObj->SetRecomputeOk();
2079     }
2080    if(updateviewer) 
2081     UpdateCurrentViewer();
2082 }
2083
2084 //=======================================================================
2085 //function : SetMaterial
2086 //purpose  : 
2087 //=======================================================================
2088
2089 void AIS_InteractiveContext::SetMaterial(const Handle(AIS_InteractiveObject)& anIObj,
2090 //POP pour K4L
2091                                         const Graphic3d_NameOfMaterial aName,
2092 //                                      const Graphic3d_NameOfPhysicalMaterial aName,
2093                                         const Standard_Boolean updateviewer)
2094 {
2095   if(!anIObj->HasInteractiveContext())
2096     anIObj->SetContext(this);
2097   anIObj->SetMaterial(aName);
2098   if(anIObj->RecomputeEveryPrs())
2099     anIObj->Redisplay();
2100   else
2101     {
2102       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2103       for (;ITI.More();ITI.Next())
2104         {
2105           anIObj->Update(ITI.Value(),Standard_False);
2106         }
2107       anIObj->SetRecomputeOk();
2108     }
2109    if(updateviewer)
2110     UpdateCurrentViewer();
2111
2112 }
2113
2114 //=======================================================================
2115 //function : UnsetMaterial
2116 //purpose  : 
2117 //=======================================================================
2118
2119 void AIS_InteractiveContext::UnsetMaterial(const Handle(AIS_InteractiveObject)& anIObj,
2120                                           const Standard_Boolean updateviewer)
2121 {
2122   if(anIObj.IsNull()) return ;
2123   anIObj->UnsetMaterial();
2124   if(anIObj->RecomputeEveryPrs())
2125     anIObj->Redisplay();
2126   else
2127     {
2128       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2129       for (;ITI.More();ITI.Next())
2130         {
2131           anIObj->Update(ITI.Value(),Standard_False);
2132         }
2133       anIObj->SetRecomputeOk();
2134     }
2135   if(updateviewer)
2136     UpdateCurrentViewer();
2137 }
2138
2139 //=======================================================================
2140 //function : SetTransparency
2141 //purpose  : 
2142 //=======================================================================
2143
2144 void AIS_InteractiveContext::SetTransparency(const Handle(AIS_InteractiveObject)& anIObj,
2145                                             const Standard_Real aValue,
2146                                             const Standard_Boolean updateviewer)
2147 {
2148   if(anIObj.IsNull()) return ;
2149    if(!anIObj->HasInteractiveContext())
2150     anIObj->SetContext(this);
2151
2152 #ifdef BUC60577 //right optimization
2153   if(!anIObj->IsTransparent() && aValue<=0.05) return;
2154 #else  
2155 //  if(!anIObj->IsTransparent() && aValue<=0.05) return;
2156 #endif
2157   if(aValue<=0.05){
2158     UnsetTransparency(anIObj,updateviewer);
2159     return;
2160   }
2161   
2162   if(!myMainVwr->Viewer()->Transparency())
2163     myMainVwr->Viewer()->SetTransparency(Standard_True);
2164   anIObj->SetTransparency(aValue);
2165   if(anIObj->RecomputeEveryPrs())
2166     anIObj->Redisplay();
2167   else
2168     {
2169       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2170       for (;ITI.More();ITI.Next())
2171         {
2172           anIObj->Update(ITI.Value(),Standard_False);
2173         }
2174       anIObj->SetRecomputeOk();
2175     }
2176    if(updateviewer)
2177     UpdateCurrentViewer();
2178 }
2179
2180 //=======================================================================
2181 //function : UnsetTransparency
2182 //purpose  : 
2183 //=======================================================================
2184
2185 void AIS_InteractiveContext::UnsetTransparency(const Handle(AIS_InteractiveObject)& anIObj,
2186                                               const Standard_Boolean updateviewer)
2187 {
2188   if(anIObj.IsNull()) return ;
2189    anIObj->UnsetTransparency();
2190   if(anIObj->RecomputeEveryPrs())
2191     anIObj->Redisplay();
2192   else
2193     {
2194       TColStd_ListIteratorOfListOfInteger ITI(anIObj->ListOfRecomputeModes());
2195       for (;ITI.More();ITI.Next())
2196         {
2197           anIObj->Update(ITI.Value(),Standard_False);
2198         }
2199       anIObj->SetRecomputeOk();
2200     }
2201
2202   // To Unset transparency in the viewer, if no other object is transparent ...(Speed)
2203   AIS_DataMapIteratorOfDataMapOfIOStatus It(myObjects);
2204   Standard_Boolean FoundTransp(Standard_False);
2205   for(;It.More() && !FoundTransp ;It.Next()){
2206     if(It.Key()->IsTransparent())
2207       FoundTransp = Standard_True;
2208   }
2209   if(!FoundTransp)
2210     myMainVwr->Viewer()->SetTransparency(Standard_False);
2211   
2212   
2213   if(updateviewer)
2214     UpdateCurrentViewer();
2215 }
2216
2217 //=======================================================================
2218 //function : SetSelectedAspect
2219 //purpose  : 
2220 //=======================================================================
2221 void AIS_InteractiveContext::SetSelectedAspect(
2222                                 const Handle(Prs3d_BasicAspect)& anAspect,
2223                                 const Standard_Boolean globalChange,
2224                                 const Standard_Boolean updateViewer)
2225 {
2226   if( !HasOpenedContext() ) {
2227     Standard_Boolean found = Standard_False;
2228     Handle(AIS_Selection) sel = 
2229                 AIS_Selection::Selection(myCurrentName.ToCString());
2230     Handle(AIS_InteractiveObject) object;
2231     for( sel->Init() ; sel->More() ; sel->Next()) {
2232       found = Standard_True;
2233       object = Handle(AIS_InteractiveObject)::DownCast(sel->Value());
2234       object->SetAspect(anAspect,globalChange);
2235     }
2236     if( found && updateViewer) {
2237       myMainVwr->Update();
2238     }
2239   }
2240 }
2241
2242 //=======================================================================
2243 //function : SetLocalAttributes
2244 //purpose  : 
2245 //=======================================================================
2246
2247 void AIS_InteractiveContext::SetLocalAttributes(const Handle(AIS_InteractiveObject)& anIObj, 
2248                                                 const Handle(AIS_Drawer)& aDrawer,
2249                                                 const Standard_Boolean updateviewer)
2250 {
2251   if(anIObj.IsNull()) return ;
2252   if(!anIObj->HasInteractiveContext())
2253     anIObj->SetContext(this);
2254   anIObj->SetAttributes(aDrawer);
2255   Update(anIObj,updateviewer);
2256   
2257 }
2258
2259 //=======================================================================
2260 //function : UnsetLocalAttributes
2261 //purpose  : 
2262 //=======================================================================
2263 void AIS_InteractiveContext::UnsetLocalAttributes(const Handle(AIS_InteractiveObject)& anIObj,
2264                                                   const Standard_Boolean updateviewer)
2265 {
2266   if(anIObj.IsNull()) return ;
2267   if(!anIObj->HasInteractiveContext())
2268     anIObj->SetContext(this);
2269   anIObj->UnsetAttributes();
2270   Update(anIObj,updateviewer);
2271 }
2272
2273
2274 //=======================================================================
2275 //function : Status
2276 //purpose  : 
2277 //=======================================================================
2278
2279 void AIS_InteractiveContext::Status(const Handle(AIS_InteractiveObject)& anIObj, TCollection_ExtendedString& astatus) const 
2280 {
2281   astatus = "";
2282
2283   if(anIObj.IsNull()) return ;
2284   if(myObjects.IsBound(anIObj)){
2285     astatus += "\t ____________________________________________";
2286     astatus += "\t| Known at Neutral Point:\n\tDisplayStatus:";
2287     const Handle(AIS_GlobalStatus)& ST = myObjects(anIObj);
2288     switch(ST->GraphicStatus()){
2289     case AIS_DS_Displayed:
2290       {
2291         astatus +="\t| -->Displayed\n";
2292         break;
2293       }
2294     case AIS_DS_Erased:
2295       {
2296         astatus +="\t| -->Erased\n";
2297         break;
2298       }
2299     default:
2300       break;
2301     }
2302     astatus += "\t| Active Display Modes in the MainViewer :\n";
2303     TColStd_ListIteratorOfListOfInteger ItL (ST->DisplayedModes());
2304     for(;ItL.More();ItL.Next()){
2305       astatus += "\t|\t Mode ";
2306       astatus += TCollection_AsciiString(ItL.Value());
2307       astatus+="\n";
2308     }   
2309     if(IsCurrent(anIObj)) astatus +="\t| Current\n";
2310     if(IsSelected(anIObj)) astatus +="\t| Selected\n";
2311
2312     astatus += "\t| Active Selection Modes in the MainViewer :\n";
2313     for(ItL.Initialize(ST->SelectionModes());ItL.More();ItL.Next()){
2314       astatus += "\t\t Mode ";
2315       astatus += TCollection_AsciiString(ItL.Value());
2316       astatus+="\n";
2317     }   
2318     astatus += "\t ____________________________________________";
2319       
2320     }
2321 }
2322
2323
2324 //=======================================================================
2325 //function : GetDefModes
2326 //purpose  : 
2327 //=======================================================================
2328
2329 void AIS_InteractiveContext::GetDefModes(const Handle(AIS_InteractiveObject)& anIObj,
2330                                      Standard_Integer& DispMode,
2331                                      Standard_Integer& HiMode,
2332                                      Standard_Integer& SelMode) const 
2333 {
2334   if(anIObj.IsNull()) return ;
2335   DispMode = anIObj->HasDisplayMode() ? anIObj->DisplayMode() : 
2336   (anIObj->AcceptDisplayMode(myDisplayMode)? myDisplayMode : 0);
2337   
2338   HiMode = anIObj->HasHilightMode()? anIObj->HilightMode():DispMode;
2339 #ifdef BUC61051
2340   SelMode = anIObj->HasSelectionMode()? anIObj->SelectionMode() : -1;
2341 #else
2342   SelMode = anIObj->HasSelectionMode()? anIObj->SelectionMode() : 0;
2343 #endif
2344 }
2345
2346
2347 //=======================================================================
2348 //function : EraseGlobal
2349 //purpose  : 
2350 //=======================================================================
2351
2352 void AIS_InteractiveContext::EraseGlobal(const Handle(AIS_InteractiveObject)& anIObj, 
2353                                          const Standard_Boolean updateviewer)
2354 {
2355   if(anIObj.IsNull()) return ;
2356   if(!myObjects.IsBound(anIObj)) return;
2357
2358   // CLE
2359   // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
2360   Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
2361   // ENDCLE
2362   Standard_Integer Dmode = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0;
2363   if(STATUS->GraphicStatus()==AIS_DS_Displayed){
2364     
2365     TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
2366     for(;ItL.More();ItL.Next()){
2367       if(myMainPM->IsHighlighted(anIObj,ItL.Value()))
2368         myMainPM->Unhighlight(anIObj,ItL.Value());
2369       myMainPM->SetVisibility (anIObj, ItL.Value(), Standard_False);
2370     }
2371     if(IsCurrent(anIObj) && !STATUS->IsDModeIn(Dmode))
2372       myMainPM->SetVisibility (anIObj, Dmode, Standard_False);
2373     
2374     for(ItL.Initialize(STATUS->SelectionModes());ItL.More();ItL.Next())
2375       mgrSelector->Deactivate(anIObj,ItL.Value(),myMainSel);
2376     if(updateviewer) myMainVwr->Update();
2377   }
2378   STATUS->SetGraphicStatus(AIS_DS_Erased);
2379   
2380 }
2381
2382 //=======================================================================
2383 //function : ClearGlobal
2384 //purpose  : 
2385 //=======================================================================
2386
2387 void AIS_InteractiveContext::ClearGlobal(const Handle(AIS_InteractiveObject)& anIObj, 
2388                                          const Standard_Boolean updateviewer)
2389 {
2390   if(anIObj.IsNull()) return ;
2391   if(!myObjects.IsBound(anIObj)) return;
2392   // CLE
2393   // const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
2394   Handle(AIS_GlobalStatus) STATUS = myObjects(anIObj);
2395   // ENDCLE
2396    TColStd_ListIteratorOfListOfInteger ItL (STATUS->DisplayedModes());
2397    for(;ItL.More();ItL.Next()){
2398      if(STATUS->IsHilighted()){
2399        if(IsCurrent(anIObj))
2400 #ifdef OCC204
2401          AddOrRemoveCurrentObject( anIObj, updateviewer );
2402 #else
2403          AddOrRemoveCurrentObject(anIObj);
2404 #endif
2405        else if(myMainPM->IsHighlighted(anIObj,ItL.Value()))
2406          myMainPM->Unhighlight(anIObj,ItL.Value());
2407      }
2408      myMainPM->Erase(anIObj,ItL.Value());
2409      myMainPM->Clear(anIObj,ItL.Value());
2410      if(anIObj->HasHilightMode()){
2411        Standard_Integer im = anIObj->HilightMode();
2412        myMainPM->Unhighlight(anIObj,im);
2413        myMainPM->Erase(anIObj,im);
2414   
2415      }
2416    }
2417
2418   //Object removes from Detected sequence
2419   Standard_Integer i = 1;
2420   for(i = 1; i < myAISDetectedSeq.Length(); i++)
2421   {
2422     Handle(AIS_InteractiveObject) anObj = DetectedCurrentObject();
2423     if( !anObj.IsNull() && anObj != anIObj )
2424       myAISDetectedSeq.Remove( i );
2425   }
2426
2427   if(myLastinMain == anIObj)
2428     myLastinMain.Nullify();
2429
2430   if(myLastPicked == anIObj)
2431     myLastPicked.Nullify();
2432
2433   // OCC21671: Remove IO from the selection manager in any case
2434   // to avoid memory leaks
2435   mgrSelector->Remove(anIObj);
2436
2437   if (updateviewer && (STATUS->GraphicStatus() == AIS_DS_Displayed))
2438   {
2439     myMainVwr->Update();
2440   }
2441
2442   myObjects.UnBind(anIObj);
2443   
2444 }
2445
2446 //=======================================================================
2447 //function : ClearGlobalPrs
2448 //purpose  : 
2449 //=======================================================================
2450
2451 void AIS_InteractiveContext::ClearGlobalPrs(const Handle(AIS_InteractiveObject)& anIObj, 
2452                                             const Standard_Integer aMode,
2453                                             const Standard_Boolean updateviewer)
2454 {
2455   if(anIObj.IsNull()) return ;
2456   if(!myObjects.IsBound(anIObj)) return;
2457   const Handle(AIS_GlobalStatus)& STATUS = myObjects(anIObj);
2458   
2459   Standard_Integer DM = anIObj->HasHilightMode() ? anIObj->HilightMode() : 0; 
2460   if(STATUS->IsDModeIn(aMode)){
2461     if(DM==aMode && myMainPM->IsHighlighted(anIObj,aMode))
2462       myMainPM->Unhighlight(anIObj,aMode);
2463     
2464     myMainPM->Erase(anIObj,aMode);
2465     myMainPM->Clear(anIObj,aMode);
2466   }
2467   
2468
2469   if(STATUS->GraphicStatus()==AIS_DS_Displayed && updateviewer)
2470     myMainVwr->Update();
2471 }
2472
2473 //=======================================================================
2474 //function : DrawHiddenLine
2475 //purpose  : 
2476 //=======================================================================
2477
2478 Standard_Boolean AIS_InteractiveContext::DrawHiddenLine () const {
2479
2480   return myDefaultDrawer->DrawHiddenLine();
2481 }
2482
2483 //=======================================================================
2484 //function : EnableDrawHiddenLine
2485 //purpose  : 
2486 //=======================================================================
2487
2488 void AIS_InteractiveContext::EnableDrawHiddenLine () const {
2489   myDefaultDrawer->EnableDrawHiddenLine();
2490 }
2491
2492 //=======================================================================
2493 //function : DisableDrawHiddenLine 
2494 //purpose  : 
2495 //=======================================================================
2496
2497 void AIS_InteractiveContext::DisableDrawHiddenLine () const {
2498   myDefaultDrawer->DisableDrawHiddenLine();
2499 }
2500
2501 //=======================================================================
2502 //function : HiddenLineAspect
2503 //purpose  : 
2504 //=======================================================================
2505
2506 Handle (Prs3d_LineAspect) AIS_InteractiveContext::HiddenLineAspect () const  {
2507   return myDefaultDrawer->HiddenLineAspect();
2508 }
2509
2510 //=======================================================================
2511 //function : SetHiddenLineAspect
2512 //purpose  : 
2513 //=======================================================================
2514
2515 void AIS_InteractiveContext::SetHiddenLineAspect ( const Handle(Prs3d_LineAspect)& anAspect) const {
2516   myDefaultDrawer->SetHiddenLineAspect(anAspect);
2517 }
2518
2519 //=======================================================================
2520 //function : SetIsoNumber
2521 //purpose  : 
2522 //=======================================================================
2523
2524 void AIS_InteractiveContext::SetIsoNumber(const Standard_Integer Nb,const AIS_TypeOfIso Type)
2525 {
2526   switch(Type){
2527   case AIS_TOI_IsoU:
2528     myDefaultDrawer->UIsoAspect()->SetNumber(Nb);
2529     break;
2530   case AIS_TOI_IsoV:
2531     myDefaultDrawer->VIsoAspect()->SetNumber(Nb);
2532     break;
2533   case AIS_TOI_Both:
2534     myDefaultDrawer->UIsoAspect()->SetNumber(Nb);
2535     myDefaultDrawer->VIsoAspect()->SetNumber(Nb);
2536     break;
2537  
2538   }
2539 }
2540 //=======================================================================
2541 //function : IsoNumber
2542 //purpose  : 
2543 //=======================================================================
2544
2545 Standard_Integer AIS_InteractiveContext::IsoNumber(const AIS_TypeOfIso Type)
2546 {
2547   
2548   switch(Type){
2549   case AIS_TOI_IsoU:
2550     return myDefaultDrawer->UIsoAspect()->Number();
2551   case AIS_TOI_IsoV:
2552     return myDefaultDrawer->VIsoAspect()->Number();
2553   case AIS_TOI_Both:
2554     return (myDefaultDrawer->UIsoAspect()->Number()==
2555             myDefaultDrawer->VIsoAspect()->Number()) ? 
2556               myDefaultDrawer->UIsoAspect()->Number(): -1;
2557   }
2558   return 0;
2559 }
2560
2561 //=======================================================================
2562 //function : IsoOnPlane
2563 //purpose  : 
2564 //=======================================================================
2565
2566 void AIS_InteractiveContext::IsoOnPlane(const Standard_Boolean SwitchOn)
2567 {
2568   myDefaultDrawer->SetIsoOnPlane(SwitchOn);
2569 }
2570
2571 //=======================================================================
2572 //function : IsoOnPlane
2573 //purpose  : 
2574 //=======================================================================
2575
2576 Standard_Boolean AIS_InteractiveContext::IsoOnPlane() const 
2577 {
2578   return myDefaultDrawer->IsoOnPlane();
2579 }
2580
2581 //=======================================================================
2582 //function : SetSelectionMode
2583 //purpose  : 
2584 //=======================================================================
2585
2586 void AIS_InteractiveContext::SetSelectionMode(const Handle_AIS_InteractiveObject&, const Standard_Integer )
2587 {
2588 }
2589
2590 //=======================================================================
2591 //function : UnsetSelectionMode
2592 //purpose  : 
2593 //=======================================================================
2594
2595 void AIS_InteractiveContext::UnsetSelectionMode(const Handle_AIS_InteractiveObject&)
2596 {
2597 }
2598
2599 //=======================================================================
2600 //function : SetSensitivityMode
2601 //purpose  : 
2602 //=======================================================================
2603
2604 void AIS_InteractiveContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) {
2605
2606   if( HasOpenedContext() )
2607         myLocalContexts(myCurLocalIndex)->SetSensitivityMode(aMode);
2608   else {
2609     myMainSel->SetSensitivityMode(aMode);
2610   }
2611 }
2612
2613 //=======================================================================
2614 //function : SensitivityMode
2615 //purpose  : 
2616 //=======================================================================
2617
2618 StdSelect_SensitivityMode AIS_InteractiveContext::SensitivityMode() const {
2619
2620   if( HasOpenedContext() )
2621         return myLocalContexts(myCurLocalIndex)->SensitivityMode();
2622   return myMainSel->SensitivityMode();
2623 }
2624
2625 //=======================================================================
2626 //function : SetSensitivity
2627 //purpose  : 
2628 //=======================================================================
2629
2630 void AIS_InteractiveContext::SetSensitivity(const Standard_Real aPrecision) {
2631
2632   if( HasOpenedContext() )
2633         myLocalContexts(myCurLocalIndex)->SetSensitivity(aPrecision);
2634   else {
2635     myMainSel->SetSensitivity(aPrecision);
2636   }
2637 }
2638
2639 //=======================================================================
2640 //function : Sensitivity
2641 //purpose  : 
2642 //=======================================================================
2643
2644 Standard_Real AIS_InteractiveContext::Sensitivity() const {
2645
2646   if( HasOpenedContext() )
2647         return myLocalContexts(myCurLocalIndex)->Sensitivity();
2648   return myMainSel->Sensitivity();
2649 }
2650
2651 //=======================================================================
2652 //function : SetPixelTolerance
2653 //purpose  : 
2654 //=======================================================================
2655
2656 void AIS_InteractiveContext::SetPixelTolerance(const Standard_Integer aPrecision) {
2657
2658   if( HasOpenedContext() )
2659         myLocalContexts(myCurLocalIndex)->SetPixelTolerance(aPrecision);
2660   else {
2661     myMainSel->SetPixelTolerance(aPrecision);
2662   }
2663 }
2664
2665 //=======================================================================
2666 //function : PixelTolerance
2667 //purpose  : 
2668 //=======================================================================
2669
2670 Standard_Integer AIS_InteractiveContext::PixelTolerance() const {
2671
2672   if( HasOpenedContext() )
2673         return myLocalContexts(myCurLocalIndex)->PixelTolerance();
2674   return myMainSel->PixelTolerance();
2675 }
2676
2677 //=======================================================================
2678 //function : IsInLocal
2679 //purpose  : 
2680 //=======================================================================
2681
2682 Standard_Boolean AIS_InteractiveContext::IsInLocal(const Handle_AIS_InteractiveObject& anIObj,
2683                                                    Standard_Integer& TheIndex) const 
2684 {
2685   if(anIObj.IsNull()) return Standard_False;
2686   // if it exists at neutral point 0 index is returned
2687   if(myObjects.IsBound(anIObj)) {
2688     TheIndex = 0;
2689     return Standard_False;
2690   }
2691   for(Standard_Integer I=1;I<=myLocalContexts.Extent();I++){
2692     if(myLocalContexts.IsBound(I)){
2693       if(myLocalContexts(I)->IsIn(anIObj)){
2694         TheIndex = I;
2695         return Standard_True;
2696         
2697       }
2698     }
2699   }
2700   TheIndex =-1;
2701   return Standard_False;
2702 }  
2703   
2704 //=======================================================================
2705 //function : InitAttributes
2706 //purpose  : 
2707 //=======================================================================
2708
2709 void AIS_InteractiveContext::InitAttributes()
2710 {
2711
2712   mgrSelector->Add(myMainSel);
2713   myCurrentName   = AIS_Context_NewCurName();
2714   mySelectionName = AIS_Context_NewSelName();
2715
2716   AIS_Selection::CreateSelection(mySelectionName.ToCString());
2717   AIS_Selection::CreateSelection(myCurrentName.ToCString());
2718
2719   
2720   myDefaultDrawer->SetShadingAspectGlobal(Standard_False);
2721   Graphic3d_MaterialAspect aMat(Graphic3d_NOM_BRASS);
2722   myDefaultDrawer->ShadingAspect()->SetMaterial(aMat);
2723
2724 //  myDefaultDrawer->ShadingAspect()->SetColor(Quantity_NOC_GRAY70);
2725   Handle (Prs3d_LineAspect) HLA = myDefaultDrawer->HiddenLineAspect();
2726   HLA->SetColor(Quantity_NOC_GRAY20);
2727   HLA->SetWidth(1);
2728   HLA->SetTypeOfLine(Aspect_TOL_DASH);
2729
2730   // tolerance to 4 pixels...
2731   SetPixelTolerance();
2732
2733   // Customizing the drawer for trihedrons and planes...
2734
2735   Handle (Prs3d_DatumAspect) DA = myDefaultDrawer->DatumAspect();
2736   Standard_Real aLength(100.);
2737   DA->SetAxisLength(aLength,aLength,aLength);
2738   Quantity_NameOfColor col = Quantity_NOC_LIGHTSTEELBLUE4;
2739   DA->FirstAxisAspect()->SetColor(col);
2740   DA->SecondAxisAspect()->SetColor(col);
2741   DA->ThirdAxisAspect()->SetColor(col);
2742
2743   Handle(Prs3d_PlaneAspect)PA = myDefaultDrawer->PlaneAspect();
2744   aLength =200.;
2745   PA->SetPlaneLength(aLength,aLength);
2746   PA->EdgesAspect()->SetColor(Quantity_NOC_SKYBLUE);
2747   
2748
2749 }
2750
2751
2752 //=======================================================================
2753 //function : TrihedronSize
2754 //purpose  : 
2755 //=======================================================================
2756 Standard_Real AIS_InteractiveContext::TrihedronSize() const
2757 {
2758   return myDefaultDrawer->DatumAspect()->FirstAxisLength();
2759 }
2760 //=======================================================================
2761 //function : SetTrihedronSize
2762 //purpose  : 
2763 //=======================================================================
2764 void AIS_InteractiveContext::SetTrihedronSize(const Standard_Real aVal,const Standard_Boolean /*updateviewer*/)
2765 {
2766   myDefaultDrawer->DatumAspect()->SetAxisLength(aVal,aVal,aVal);
2767   Redisplay(AIS_KOI_Datum,3,Standard_False);
2768   Redisplay(AIS_KOI_Datum,4,Standard_True);
2769 }
2770
2771
2772
2773 //=======================================================================
2774 //function : SetPlaneSize
2775 //purpose  : 
2776 //=======================================================================
2777 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real aValX,
2778                                           const Standard_Real aValY,
2779                                           const Standard_Boolean /*updateviewer*/)
2780 {
2781   myDefaultDrawer->PlaneAspect()->SetPlaneLength(aValX,aValY);
2782   Redisplay(AIS_KOI_Datum,7);
2783 }
2784
2785 //=======================================================================
2786 //function : SetPlaneSize
2787 //purpose  : 
2788 //=======================================================================
2789
2790 void AIS_InteractiveContext::SetPlaneSize(const Standard_Real aVal,
2791                                           const Standard_Boolean updateviewer)
2792 {
2793   SetPlaneSize(aVal,aVal,updateviewer);
2794 }
2795
2796 //=======================================================================
2797 //function : PlaneSize
2798 //purpose  : 
2799 //=======================================================================
2800
2801 Standard_Boolean AIS_InteractiveContext::PlaneSize(Standard_Real& LX,Standard_Real& LY) const
2802 {
2803   LX = myDefaultDrawer->PlaneAspect()->PlaneXLength();
2804   LY =  myDefaultDrawer->PlaneAspect()->PlaneYLength();
2805   return (Abs(LX-LY)<=Precision::Confusion());
2806 }
2807
2808
2809
2810 //=======================================================================
2811 //function :
2812 //purpose  : 
2813 //=======================================================================
2814 void AIS_InteractiveContext::SetAutoActivateSelection( const Standard_Boolean Auto )
2815 {
2816   myIsAutoActivateSelMode = Auto;
2817 }
2818
2819 //=======================================================================
2820 //function :
2821 //purpose  : 
2822 //=======================================================================
2823 Standard_Boolean AIS_InteractiveContext::GetAutoActivateSelection() const
2824 {
2825   return myIsAutoActivateSelMode;
2826 }
2827
2828 //=======================================================================
2829 //function : SetZLayer
2830 //purpose  : 
2831 //=======================================================================
2832
2833 void AIS_InteractiveContext::SetZLayer (const Handle(AIS_InteractiveObject)& theIObj,
2834                                         const Standard_Integer theLayerId)
2835 {
2836   if (theIObj.IsNull ())
2837     return;
2838
2839   if (myObjects.IsBound (theIObj))
2840   {
2841     if (myObjects (theIObj)->GraphicStatus() == AIS_DS_Displayed || myObjects (theIObj)->GraphicStatus() == AIS_DS_Erased)
2842     {
2843       theIObj->SetZLayer (myMainPM, theLayerId);
2844     }
2845   }
2846   else if (HasOpenedContext ())
2847   {
2848     myLocalContexts (myCurLocalIndex)->SetZLayer (theIObj, theLayerId);
2849   }
2850 }
2851
2852 //=======================================================================
2853 //function : GetZLayer
2854 //purpose  : 
2855 //=======================================================================
2856
2857 Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_InteractiveObject)& theIObj) const
2858 {
2859   if (theIObj.IsNull ())
2860     return -1;
2861
2862   if (myObjects.IsBound (theIObj))
2863   {
2864     return theIObj->GetZLayer (myMainPM);
2865   }
2866   else if (HasOpenedContext ())
2867   {
2868     return myLocalContexts (myCurLocalIndex)->GetZLayer (theIObj);
2869   }
2870
2871   return -1;
2872 }