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