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