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