0025332: Visualization - rewrite MinMaxValues methods to using of Bnd_Box
[occt.git] / src / Visual3d / Visual3d_View.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifdef _WIN32
16   #include <windows.h>
17 #endif
18
19 #include <Visual3d_View.ixx>
20
21 #include <Graphic3d_DataStructureManager.hxx>
22 #include <Graphic3d_GraphicDriver.hxx>
23 #include <Graphic3d_MapOfStructure.hxx>
24 #include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
25 #include <Graphic3d_Structure.hxx>
26 #include <Graphic3d_TextureEnv.hxx>
27 #include <Graphic3d_Vector.hxx>
28 #include <Graphic3d_Vertex.hxx>
29 #include <Visual3d_DepthCueingDefinitionError.hxx>
30 #include <Visual3d_Light.hxx>
31 #include <Visual3d_HSequenceOfView.hxx>
32 #include <Visual3d_ZClippingDefinitionError.hxx>
33 #include <OSD.hxx>
34 #include <TColStd_HArray2OfReal.hxx>
35
36 #if defined(_WIN32)
37   #include <WNT_Window.hxx>
38 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
39   #include <Cocoa_Window.hxx>
40 #else
41   #include <Xw_Window.hxx>
42 #endif
43
44 #include <float.h>
45
46 // =======================================================================
47 // function : Visual3d_View
48 // purpose  :
49 // =======================================================================
50 Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& theMgr)
51 : myViewManager         (theMgr.operator->()),
52   myIsInComputedMode    (Standard_False),
53   myAutoZFitIsOn        (Standard_True),
54   myAutoZFitScaleFactor (1.0),
55   myStructuresUpdated   (Standard_True)
56 {
57   MyCView.ViewId                  = theMgr->Identification (this);
58   MyCView.Active                  = 0;
59   MyCView.IsDeleted               = 0;
60   MyCView.WsId                    = -1;
61   MyCView.DefWindow.IsDefined     = 0;
62   MyCView.Context.NbActiveLight   = 0;
63   MyCView.Context.ZBufferActivity = -1;
64
65   MyCView.Backfacing    = 0;
66   MyCView.ptrUnderLayer = 0;
67   MyCView.ptrOverLayer  = 0;
68   MyCView.GContext      = 0;
69   MyCView.GDisplayCB    = 0;
70   MyCView.GClientData   = 0;
71
72   myGraphicDriver = myViewManager->GraphicDriver();
73 }
74
75 // =======================================================================
76 // function : SetWindow
77 // purpose  :
78 // =======================================================================
79 void Visual3d_View::SetWindow (const Handle(Aspect_Window)&      theWindow,
80                                const Aspect_RenderingContext     theContext,
81                                const Aspect_GraphicCallbackProc& theDisplayCB,
82                                const Standard_Address            theClientData)
83 {
84   if (IsDeleted())
85   {
86     return;
87   }
88   else if (IsDefined())
89   {
90     Visual3d_ViewDefinitionError::Raise ("Window already defined");
91   }
92
93   MyCView.GContext    = theContext;
94   MyCView.GDisplayCB  = theDisplayCB;
95   MyCView.GClientData = theClientData;
96   SetWindow (theWindow);
97 }
98
99 // =======================================================================
100 // function : SetWindow
101 // purpose  :
102 // =======================================================================
103 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
104 {
105   if (IsDeleted())
106   {
107     return;
108   }
109   else if (IsDefined())
110   {
111     Visual3d_ViewDefinitionError::Raise ("Window already defined");
112   }
113
114   MyWindow = theWindow;
115   MyCView.WsId = MyCView.ViewId;
116   MyCView.DefWindow.IsDefined = 1;
117   MyCView.DefWindow.XWindow       = theWindow->NativeHandle();
118   MyCView.DefWindow.XParentWindow = theWindow->NativeParentHandle();
119
120   Standard_Integer Width, Height;
121   theWindow->Size (Width, Height);
122   MyCView.DefWindow.dx = float(Width);
123   MyCView.DefWindow.dy = float(Height);
124
125   Standard_Real R, G, B;
126   MyBackground = MyWindow->Background ();
127   MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
128   MyCView.DefWindow.Background.r = float (R);
129   MyCView.DefWindow.Background.g = float (G);
130   MyCView.DefWindow.Background.b = float (B);
131
132   UpdateView();
133   if (!myGraphicDriver->View (MyCView))
134   {
135     Visual3d_ViewDefinitionError::Raise ("Association failed");
136   }
137
138   MyGradientBackground = MyWindow->GradientBackground();
139   SetGradientBackground(MyGradientBackground,1);
140
141   Standard_Boolean AWait = Standard_False; // => immediate update
142   myGraphicDriver->SetVisualisation (MyCView);
143   myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
144   myGraphicDriver->DepthCueing  (MyCView, MyContext.DepthCueingIsOn());
145   myGraphicDriver->ClipLimit    (MyCView, AWait);
146   myGraphicDriver->Environment  (MyCView);
147
148   // Make view manager z layer list consistent with the view's list.
149   myViewManager->InstallZLayers (this);
150
151   // Update planses of model clipping
152   UpdatePlanes();
153
154   // Update light sources
155   UpdateLights();
156
157   // Association view-window does not cause the display
158   // of structures that can be displayed in the new view.
159   // In fact, association view-window is done, but the
160   // display is produced only if the view is activated (Activate).
161   SetRatio();
162 }
163
164 // =======================================================================
165 // function : Window
166 // purpose  :
167 // =======================================================================
168 Handle(Aspect_Window) Visual3d_View::Window() const
169 {
170   if (!IsDefined())
171   {
172     Visual3d_ViewDefinitionError::Raise ("Window not defined");
173   }
174   return MyWindow;
175 }
176
177 // =======================================================================
178 // function : IsDefined
179 // purpose  :
180 // =======================================================================
181 Standard_Boolean Visual3d_View::IsDefined() const
182 {
183   return MyCView.DefWindow.IsDefined != 0;
184 }
185
186 // =======================================================================
187 // function : IsDeleted
188 // purpose  :
189 // =======================================================================
190 Standard_Boolean Visual3d_View::IsDeleted() const
191 {
192   return MyCView.IsDeleted != 0;
193 }
194
195 // =======================================================================
196 // function : Destroy
197 // purpose  :
198 // =======================================================================
199 void Visual3d_View::Destroy()
200 {
201   // Since myViewManager can be already destroyed,
202   // avoid attempts to access it in SetBackground()
203   myViewManager = NULL;
204   Remove();
205 }
206
207 // =======================================================================
208 // function : Remove
209 // purpose  :
210 // =======================================================================
211 void Visual3d_View::Remove()
212 {
213   if (IsDeleted()
214   || !IsDefined())
215   {
216     return;
217   }
218
219   myStructsToCompute.Clear();
220   myStructsComputed .Clear();
221   myStructsDisplayed.Clear();
222
223   Aspect_GradientBackground aBlackGrad;
224   SetBackground (Aspect_Background (Quantity_NOC_BLACK));
225   SetGradientBackground (aBlackGrad, Standard_False);
226
227   if (myViewManager != NULL)
228   {
229     myViewManager->UnIdentification (MyCView.ViewId);
230   }
231
232   myGraphicDriver->RemoveView (MyCView);
233
234   MyCView.WsId                = -1;
235   MyCView.IsDeleted           = 1;
236   MyCView.DefWindow.IsDefined = 0;
237
238   MyWindow.Nullify();
239 }
240
241 // =======================================================================
242 // function : Resized
243 // purpose  :
244 // =======================================================================
245 void Visual3d_View::Resized()
246 {
247   if (IsDeleted())
248   {
249     return;
250   }
251   else if (!IsDefined())
252   {
253     Visual3d_ViewDefinitionError::Raise ("Window not defined");
254   }
255   MyWindow->DoResize();
256   SetRatio();
257 }
258
259 // =======================================================================
260 // function : SetRatio
261 // purpose  :
262 // =======================================================================
263 void Visual3d_View::SetRatio()
264 {
265   if (IsDeleted())
266   {
267     return;
268   }
269
270   const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
271   myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
272
273   Standard_Integer aWidth, aHeight;
274   MyWindow->Size (aWidth, aHeight);
275   if (aWidth > 0 && aHeight > 0)
276   {
277     Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight; 
278
279     MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
280     MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
281
282     myGraphicDriver->RatioWindow (MyCView);
283
284     // Update camera aspect
285     const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
286     if (!aCamera.IsNull())
287     {
288       aCamera->SetAspect (aRatio);
289     }
290
291     if (!myDefaultCamera.IsNull())
292     {
293       myDefaultCamera->SetAspect (aRatio);
294     }
295   }
296
297   myViewManager->SetUpdateMode (anUpdateMode);
298   Update (anUpdateMode);
299 }
300
301 // =======================================================================
302 // function : UpdateLights
303 // purpose  :
304 // =======================================================================
305 void Visual3d_View::UpdateLights()
306 {
307   if (IsDeleted()
308    || !IsDefined())
309   {
310     return;
311   }
312
313   if (MyContext.Model() == Visual3d_TOM_NONE)
314   {
315     // activate only a white ambient light
316     Graphic3d_CLight aCLight;
317     aCLight.Type        = Visual3d_TOLS_AMBIENT;
318     aCLight.IsHeadlight = Standard_False;
319     aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
320
321     MyCView.Context.NbActiveLight = 1;
322     MyCView.Context.ActiveLight   = &aCLight;
323     myGraphicDriver->SetLight (MyCView);
324     MyCView.Context.ActiveLight   = NULL;
325     return;
326   }
327
328   MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
329                                        myGraphicDriver->InquireLightLimit());
330   if (MyCView.Context.NbActiveLight < 1)
331   {
332     myGraphicDriver->SetLight (MyCView);
333     return;
334   }
335
336   // parcing of light sources
337   MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
338   for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
339   {
340     MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
341   }
342   myGraphicDriver->SetLight (MyCView);
343   delete[] MyCView.Context.ActiveLight;
344   MyCView.Context.ActiveLight = NULL;
345 }
346
347 // =======================================================================
348 // function : UpdatePlanes
349 // purpose  :
350 // =======================================================================
351 void Visual3d_View::UpdatePlanes()
352 {
353   MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
354   if (IsDeleted() || !IsDefined())
355   {
356     return;
357   }
358
359   myGraphicDriver->SetClipPlanes (MyCView);
360 }
361
362 // =======================================================================
363 // function : SetBackground
364 // purpose  :
365 // =======================================================================
366 void Visual3d_View::SetBackground (const Aspect_Background& theBack)
367 {
368   if (IsDeleted())
369   {
370     return;
371   }
372   else if (!IsDefined())
373   {
374     Visual3d_ViewDefinitionError::Raise ("Window not defined");
375   }
376
377   // At this level, only GL can update the background.
378   // It is not necessary to call MyWindow->SetBackground (ABack); as
379   // this method starts update of window background by X
380   // (if the windowing is X)
381
382   Standard_Real R, G, B;
383   MyBackground = theBack;
384   MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
385   MyCView.DefWindow.Background.r = float (R);
386   MyCView.DefWindow.Background.g = float (G);
387   MyCView.DefWindow.Background.b = float (B);
388
389   myGraphicDriver->Background (MyCView);
390
391   if (myViewManager != NULL)
392   {
393     Update (myViewManager->UpdateMode());
394   }
395 }
396
397 // =======================================================================
398 // function : SetGradientBackground
399 // purpose  :
400 // =======================================================================
401 void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
402                                            const Standard_Boolean           theToUpdate)
403 {
404   if (IsDeleted())
405   {
406     return;
407   }
408   else if (!IsDefined())
409   {
410     Visual3d_ViewDefinitionError::Raise ("Window not defined");
411   }
412
413   MyGradientBackground = theBack;
414   Quantity_Color aCol1, aCol2;
415   MyGradientBackground.Colors (aCol1, aCol2);
416   myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
417
418   if (theToUpdate)
419   {
420      Update (Aspect_TOU_ASAP);
421   }
422   else if (myViewManager != NULL)
423   {
424     Update (myViewManager->UpdateMode());
425   }
426 }
427
428 // =======================================================================
429 // function : SetBackgroundImage
430 // purpose  :
431 // =======================================================================
432 void Visual3d_View::SetBackgroundImage (const Standard_CString  theFileName,
433                                         const Aspect_FillMethod theFillStyle,
434                                         const Standard_Boolean  theToUpdate)
435 {
436   if (IsDeleted())
437   {
438     return;
439   }
440   if (!IsDefined())
441   {
442     Visual3d_ViewDefinitionError::Raise ("Window not defined");
443   }
444
445   myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
446
447   Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
448 }
449
450 // =======================================================================
451 // function : SetBgImageStyle
452 // purpose  :
453 // =======================================================================
454 void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
455                                      const Standard_Boolean  theToUpdate)
456 {
457   if (IsDeleted())
458   {
459     return;
460   }
461   if (!IsDefined())
462   {
463     Visual3d_ViewDefinitionError::Raise ("Window not defined");
464   }
465
466   myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
467
468   Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
469 }
470
471 // =======================================================================
472 // function : Background
473 // purpose  :
474 // =======================================================================
475 Aspect_Background Visual3d_View::Background() const
476 {
477   return MyBackground;
478 }
479
480 // =======================================================================
481 // function : SetBgGradientStyle
482 // purpose  :
483 // =======================================================================
484 void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
485                                         const Standard_Boolean          theToUpdate)
486 {
487   if (IsDeleted())
488   {
489     return;
490   }
491   else if (!IsDefined())
492   {
493     Visual3d_ViewDefinitionError::Raise ("Window not defined");
494   }
495
496   myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
497
498   Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
499 }
500
501 // =======================================================================
502 // function : GradientBackground
503 // purpose  :
504 // =======================================================================
505 Aspect_GradientBackground Visual3d_View::GradientBackground() const
506 {
507   return MyGradientBackground;
508 }
509
510 // =======================================================================
511 // function : DefaultCamera
512 // purpose  :
513 // =======================================================================
514 const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
515 {
516   return myDefaultCamera;
517 }
518
519 // =======================================================================
520 // function : Camera
521 // purpose  :
522 // =======================================================================
523 const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
524 {
525   return MyCView.Context.Camera;
526 }
527
528 // =======================================================================
529 // function : SetCamera
530 // purpose  :
531 // =======================================================================
532 void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
533 {
534   MyCView.Context.Camera = theCamera;
535
536   myGraphicDriver->SetCamera (MyCView);
537
538   Update (myViewManager->UpdateMode());
539 }
540
541 // =======================================================================
542 // function : SetViewOrientationDefault
543 // purpose  :
544 // =======================================================================
545 void Visual3d_View::SetViewOrientationDefault()
546 {
547   if (myDefaultCamera.IsNull())
548   {
549     myDefaultCamera = new Graphic3d_Camera();
550   }
551
552   myDefaultCamera->CopyOrientationData (MyCView.Context.Camera);
553 }
554
555 // =======================================================================
556 // function : ViewOrientationReset
557 // purpose  :
558 // =======================================================================
559 void Visual3d_View::ViewOrientationReset()
560 {
561   if (IsDeleted())
562   {
563     return;
564   }
565
566   if (!myDefaultCamera.IsNull())
567   {
568     MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
569   }
570
571   Update (myViewManager->UpdateMode());
572 }
573
574 // =======================================================================
575 // function : SetViewMappingDefault
576 // purpose  :
577 // =======================================================================
578 void Visual3d_View::SetViewMappingDefault()
579 {
580   if (myDefaultCamera.IsNull())
581   {
582     myDefaultCamera = new Graphic3d_Camera();
583   }
584   myDefaultCamera->CopyMappingData (MyCView.Context.Camera);
585 }
586
587 // =======================================================================
588 // function : ViewMappingReset
589 // purpose  :
590 // =======================================================================
591 void Visual3d_View::ViewMappingReset()
592 {
593   if (IsDeleted())
594   {
595     return;
596   }
597
598   if (!myDefaultCamera.IsNull())
599   {
600     MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
601   }
602
603   Update (myViewManager->UpdateMode());
604 }
605
606 // =======================================================================
607 // function : SetContext
608 // purpose  :
609 // =======================================================================
610 void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
611 {
612   if (IsDeleted())
613   {
614     return;
615   }
616
617   // To manage display only in case of change of visualisation mode
618   const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
619   const bool isModelChanged   = theViewCtx.Model()         != MyContext.Model();
620
621   // To manage antialiasing only in case of change
622   const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
623   const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
624
625   // To manage the depth cueing only in case of change
626   const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
627   const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
628
629   const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
630   const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
631   const Standard_Real aDepthCueingBackPlaneOld  = MyContext.DepthCueingBackPlane();
632   const Standard_Real aDepthCueingBackPlaneNew  = theViewCtx.DepthCueingBackPlane();
633
634   // To manage the Zclipping only in case of change
635   const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
636   const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
637   const Standard_Boolean aBackZClippingModeOld  = MyContext.BackZClippingIsOn();
638   const Standard_Boolean aBackZClippingModeNew  = theViewCtx.BackZClippingIsOn();
639
640   const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
641   const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
642   const Standard_Real aZClippingBackPlaneOld  = MyContext.ZClippingBackPlane();
643   const Standard_Real aZClippingBackPlaneNew  = theViewCtx.ZClippingBackPlane();
644
645   const bool isTextEnvChanged    = theViewCtx.TextureEnv()    != MyContext.TextureEnv();
646   const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
647
648   MyContext = theViewCtx;
649
650   UpdateView();
651
652   Standard_Boolean toWait = Standard_False; // => immediate update
653   if (IsDefined())
654   {
655     // management of visualization modes and types of shading.
656     if (isVisModeChanged
657      || isModelChanged)
658     {
659       myGraphicDriver->SetVisualisation (MyCView);
660     }
661
662     // management of antialiasing
663     if (anAliasingModeOld != anAliasingModeNew)
664     {
665       myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
666     }
667
668     // management of depth_cueing
669     if (aDepthCueingModeOld       != aDepthCueingModeNew
670      || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
671      || aDepthCueingBackPlaneOld  != aDepthCueingBackPlaneNew)
672     {
673       if (aDepthCueingModeNew
674       &&  aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
675       {
676         Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
677       }
678       myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
679     }
680
681     // management of Zclipping
682     if (aFrontZClippingModeOld  != aFrontZClippingModeNew
683      || aBackZClippingModeOld   != aBackZClippingModeNew
684      || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
685      || aZClippingBackPlaneOld  != aZClippingBackPlaneNew)
686     {
687       if (aBackZClippingModeNew
688        && aFrontZClippingModeNew
689        && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
690       {
691         Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
692       }
693
694       myGraphicDriver->ClipLimit (MyCView, toWait);
695     }
696
697     // management of textures
698     if (isTextEnvChanged
699      || isSurfDetailChanged)
700     {
701       myGraphicDriver->Environment (MyCView);
702     }
703
704     UpdatePlanes(); // Update of planes of model clipping
705     UpdateLights(); // Update of light sources
706   }
707
708   if (isVisModeChanged)
709   {
710     // Change of context =>
711     // Remove structures that cannot be displayed in the new visualisation mode.
712     // It is not necessary to warn ViewManager as this structure should not disappear from
713     // the list of structures displayed in it.
714     NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
715     for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
716     {
717       const Handle(Graphic3d_Structure)& aStruct  = aStructIter.Key();
718       const Visual3d_TypeOfAnswer        anAnswer = AcceptDisplay (aStruct);
719       if (anAnswer == Visual3d_TOA_NO
720        || anAnswer == Visual3d_TOA_COMPUTE)
721       {
722         aStructs.Append (aStruct);
723       }
724     }
725     for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
726     {
727       Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
728     }
729     aStructs.Clear();
730
731     // Change of context =>
732     // Display structures that can be displayed with the new visualisation mode.
733     // All structures with status Displayed are removed from the ViewManager
734     // and displayed in the view directly, if the structure is not already
735     // displayed and if the view accepts it in its context.
736     Graphic3d_MapOfStructure aMapDisplayed;
737     myViewManager->DisplayedStructures (aMapDisplayed);
738     for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
739     {
740       const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
741       if (IsDisplayed (aStruct))
742       {
743         continue;
744       }
745
746       const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
747       if (anAnswer == Visual3d_TOA_YES
748        || anAnswer == Visual3d_TOA_COMPUTE)
749       {
750         aStructs.Append (aStruct);
751       }
752     }
753
754     for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
755     {
756       Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
757     }
758   }
759
760   Update (myViewManager->UpdateMode());
761 }
762
763 // =======================================================================
764 // function : Context
765 // purpose  :
766 // =======================================================================
767 const Visual3d_ContextView& Visual3d_View::Context() const
768 {
769   return MyContext;
770 }
771
772 // =======================================================================
773 // function : DisplayedStructures
774 // purpose  :
775 // =======================================================================
776 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
777 {
778   if (IsDeleted())
779   {
780     return;
781   }
782
783   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
784   {
785     theStructures.Add (aStructIter.Key());
786   }
787 }
788
789 // =======================================================================
790 // function : Activate
791 // purpose  :
792 // =======================================================================
793 void Visual3d_View::Activate()
794 {
795   if (IsDeleted())
796   {
797     return;
798   }
799   else if (!IsDefined())
800   {
801     Visual3d_ViewDefinitionError::Raise ("Window not defined");
802   }
803
804   if (!IsActive())
805   {
806     myGraphicDriver->ActivateView (MyCView);
807     myGraphicDriver->Background   (MyCView);
808     myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
809
810     MyCView.Active = 1;
811
812     // Activation of a new view =>
813     // Display structures that can be displayed in this new view.
814     // All structures with status
815     // Displayed in ViewManager are returned and displayed in
816     // the view directly, if the structure is not already
817     // displayed and if the view accepts it in its context.
818     Graphic3d_MapOfStructure aDisplayedStructs;
819     myViewManager->DisplayedStructures (aDisplayedStructs);
820     for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
821     {
822       const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
823       if (IsDisplayed (aStruct))
824       {
825         continue;
826       }
827
828       // If the structure can be displayed in the new context of the view, it is displayed.
829       const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
830       if (anAnswer == Visual3d_TOA_YES
831        || anAnswer == Visual3d_TOA_COMPUTE)
832       {
833         Display (aStruct, Aspect_TOU_WAIT);
834       }
835     }
836   }
837
838   // If the activation/desactivation of ZBuffer should be automatic
839   // depending on the presence or absence of facets.
840   if (myViewManager->ZBufferAuto())
841   {
842     const Standard_Boolean containsFacet = ContainsFacet();
843     const Standard_Boolean hasZBuffer    = ZBufferIsActivated();
844     if (containsFacet && !hasZBuffer)
845     {
846       SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
847     }
848     else if (!containsFacet && hasZBuffer)
849     {
850       SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
851     }
852   }
853
854   Update (myViewManager->UpdateMode());
855 }
856
857 // =======================================================================
858 // function : IsActive
859 // purpose  :
860 // =======================================================================
861 Standard_Boolean Visual3d_View::IsActive() const
862 {
863   return !IsDeleted()
864       &&  MyCView.Active;
865 }
866
867 // =======================================================================
868 // function : Deactivate
869 // purpose  :
870 // =======================================================================
871 void Visual3d_View::Deactivate()
872 {
873   if (IsDeleted())
874   {
875     return;
876   }
877   else if (!IsDefined())
878   {
879     Visual3d_ViewDefinitionError::Raise ("Window not defined");
880   }
881
882   if (IsActive())
883   {
884     myGraphicDriver->DeactivateView (MyCView);
885
886     // Deactivation of a view =>
887     // Removal of structures displayed in this view.
888     // All structures with status
889     // Displayed in ViewManager are returned and removed from
890     // the view directly, if the structure is not already
891     // displayed and if the view accepts it in its context.
892     Graphic3d_MapOfStructure aDisplayedStructs;
893     myViewManager->DisplayedStructures (aDisplayedStructs);
894     for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
895     {
896       const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
897       if (IsDisplayed (aStruct))
898       {
899         continue;
900       }
901
902       const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
903       if (anAnswer == Visual3d_TOA_YES
904        || anAnswer == Visual3d_TOA_COMPUTE)
905       {
906         Erase (aStruct, Aspect_TOU_WAIT);
907       }
908     }
909
910     Update (myViewManager->UpdateMode());
911     MyCView.Active = 0; // No action currently possible in the view
912   }
913 }
914
915 // =======================================================================
916 // function : Redraw
917 // purpose  :
918 // =======================================================================
919 void Visual3d_View::Redraw()
920 {
921   Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
922 }
923
924 // =======================================================================
925 // function : Redraw
926 // purpose  :
927 // =======================================================================
928 void Visual3d_View::Redraw (const Standard_Integer theX,
929                             const Standard_Integer theY,
930                             const Standard_Integer theWidth,
931                             const Standard_Integer theHeight)
932 {
933   Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
934           theX, theY, theWidth, theHeight);
935 }
936
937 // =======================================================================
938 // function : Redraw
939 // purpose  :
940 // =======================================================================
941 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
942                             const Handle(Visual3d_Layer)& theOverLayer)
943 {
944   Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
945 }
946
947 // =======================================================================
948 // function : Redraw
949 // purpose  :
950 // =======================================================================
951 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
952                             const Handle(Visual3d_Layer)& theOverLayer,
953                             const Standard_Integer        theX,
954                             const Standard_Integer        theY,
955                             const Standard_Integer        theWidth,
956                             const Standard_Integer        theHeight)
957 {
958   if (IsDeleted()
959    || !IsDefined()
960    || !IsActive()
961    || !MyWindow->IsMapped())
962   {
963     return;
964   }
965
966   Aspect_CLayer2d anOverCLayer, anUnderCLayer;
967   anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
968   if (!theOverLayer .IsNull()) anOverCLayer  = theOverLayer ->CLayer();
969   if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
970
971   for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
972   {
973     if (myGraphicDriver->IsDeviceLost())
974     {
975       myViewManager->RecomputeStructures();
976       myViewManager->RecomputeStructures (myImmediateStructures);
977       myGraphicDriver->ResetDeviceLostFlag();
978     }
979
980     // set up Z buffer state before redrawing
981     if (myViewManager->ZBufferAuto())
982     {
983       const Standard_Boolean hasFacet   = ContainsFacet();
984       const Standard_Boolean hasZBuffer = ZBufferIsActivated();
985       // if the view contains facets and if ZBuffer is not active
986       if (hasFacet && !hasZBuffer)
987       {
988         SetZBufferActivity (1);
989       }
990       // if the view contains only facets and if ZBuffer is active
991       if (!hasFacet && hasZBuffer)
992       {
993         SetZBufferActivity (0);
994       }
995     }
996
997     if (myStructuresUpdated)
998     {
999       AutoZFit();
1000       myStructuresUpdated = Standard_False;
1001     }
1002
1003     myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
1004     if (!myGraphicDriver->IsDeviceLost())
1005     {
1006       return;
1007     }
1008   }
1009 }
1010
1011 // =======================================================================
1012 // function : RedrawImmediate
1013 // purpose  :
1014 // =======================================================================
1015 void Visual3d_View::RedrawImmediate()
1016 {
1017   RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
1018 }
1019
1020 // =======================================================================
1021 // function : RedrawImmediate
1022 // purpose  :
1023 // =======================================================================
1024 void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
1025                                      const Handle(Visual3d_Layer)& theOverLayer)
1026 {
1027   if (IsDeleted()
1028    || !IsDefined()
1029    || !IsActive()
1030    || !MyWindow->IsMapped())
1031   {
1032     return;
1033   }
1034
1035   Aspect_CLayer2d anOverCLayer, anUnderCLayer;
1036   anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
1037   if (!theOverLayer .IsNull()) anOverCLayer  = theOverLayer ->CLayer();
1038   if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
1039   myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
1040 }
1041
1042 // =======================================================================
1043 // function : Invalidate
1044 // purpose  :
1045 // =======================================================================
1046 void Visual3d_View::Invalidate()
1047 {
1048   myGraphicDriver->Invalidate (MyCView);
1049 }
1050
1051 // =======================================================================
1052 // function : Update
1053 // purpose  :
1054 // =======================================================================
1055 void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
1056 {
1057   myStructuresUpdated = Standard_True;
1058   if (theUpdateMode == Aspect_TOU_ASAP)
1059   {
1060     Compute();
1061     Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
1062   }
1063 }
1064
1065 // =======================================================================
1066 // function : Update
1067 // purpose  :
1068 // =======================================================================
1069 void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
1070                             const Handle(Visual3d_Layer)& theOverLayer)
1071 {
1072   Compute();
1073   myStructuresUpdated = Standard_True;
1074   Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
1075 }
1076
1077 // ========================================================================
1078 // function : SetAutoZFitMode
1079 // purpose  :
1080 // ========================================================================
1081 void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
1082                                      const Standard_Real    theScaleFactor)
1083 {
1084   Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
1085   myAutoZFitScaleFactor = theScaleFactor;
1086   myAutoZFitIsOn = theIsOn;
1087 }
1088
1089 // ========================================================================
1090 // function : AutoZFitMode
1091 // purpose  :
1092 // ========================================================================
1093 Standard_Boolean Visual3d_View::AutoZFitMode() const
1094 {
1095   return myAutoZFitIsOn;
1096 }
1097
1098 // ========================================================================
1099 // function : AutoZFitScaleFactor
1100 // purpose  :
1101 // ========================================================================
1102 Standard_Real Visual3d_View::AutoZFitScaleFactor() const
1103 {
1104   return myAutoZFitScaleFactor;
1105 }
1106
1107 // ========================================================================
1108 // function : AutoZFit
1109 // purpose  :
1110 // ========================================================================
1111 void Visual3d_View::AutoZFit()
1112 {
1113   if (!AutoZFitMode())
1114   {
1115     return;
1116   }
1117
1118   ZFitAll (myAutoZFitScaleFactor);
1119 }
1120
1121 // ========================================================================
1122 // function : ZFitAll
1123 // purpose  :
1124 // ========================================================================
1125 void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
1126 {
1127   Bnd_Box aMinMaxBox = MinMaxValues (Standard_False); // applicative min max boundaries
1128   Bnd_Box aGraphicBox = MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag).
1129
1130   const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1131   aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
1132 }
1133
1134 // ========================================================================
1135 // function : AcceptDisplay
1136 // purpose  :
1137 // ========================================================================
1138 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
1139 {
1140   const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
1141   switch (theStruct->Visual())
1142   {
1143     case Graphic3d_TOS_ALL:
1144     {
1145       return Visual3d_TOA_YES; // The structure accepts any type of view
1146     }
1147     case Graphic3d_TOS_SHADING:
1148     {
1149       return ViewType == Visual3d_TOV_SHADING
1150            ? Visual3d_TOA_YES
1151            : Visual3d_TOA_NO;
1152     }
1153     case Graphic3d_TOS_WIREFRAME:
1154     {
1155       return ViewType == Visual3d_TOV_WIREFRAME
1156            ? Visual3d_TOA_YES
1157            : Visual3d_TOA_NO;
1158     }
1159     case Graphic3d_TOS_COMPUTED:
1160     {
1161       return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
1162            ?  Visual3d_TOA_COMPUTE
1163            :  Visual3d_TOA_NO;
1164     }
1165   }
1166   return Visual3d_TOA_NO;
1167 }
1168
1169 // ========================================================================
1170 // function : ChangeDisplayPriority
1171 // purpose  :
1172 // ========================================================================
1173 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
1174                                            const Standard_Integer           /*theOldPriority*/,
1175                                            const Standard_Integer             theNewPriority)
1176 {
1177   if (IsDeleted()
1178   || !IsDefined()
1179   || !IsActive()
1180   || !IsDisplayed (theStruct))
1181   {
1182     return;
1183   }
1184
1185   if (!myIsInComputedMode)
1186   {
1187     myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
1188     return;
1189   }
1190
1191   const Standard_Integer      anIndex  = IsComputed (theStruct);
1192   const Graphic3d_CStructure& aCStruct = anIndex != 0
1193                                        ? *(myStructsComputed.Value (anIndex)->CStructure())
1194                                        : *theStruct->CStructure();
1195   myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
1196 }
1197
1198 // ========================================================================
1199 // function : Clear
1200 // purpose  :
1201 // ========================================================================
1202 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
1203                            const Standard_Boolean             theWithDestruction)
1204 {
1205   const Standard_Integer anIndex = IsComputed (theStruct);
1206   if (anIndex != 0)
1207   {
1208     const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
1209     aCompStruct->GraphicClear (theWithDestruction);
1210     aCompStruct->SetHLRValidation (Standard_False);
1211   }
1212 }
1213
1214 // ========================================================================
1215 // function : Connect
1216 // purpose  :
1217 // ========================================================================
1218 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
1219                              const Handle(Graphic3d_Structure)& theDaughter)
1220 {
1221   Standard_Integer anIndexM = IsComputed (theMother);
1222   Standard_Integer anIndexD = IsComputed (theDaughter);
1223   if (anIndexM != 0
1224    && anIndexD != 0)
1225   {
1226     const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1227     const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1228     aStructM->GraphicConnect (aStructD);
1229   }
1230 }
1231
1232 // ========================================================================
1233 // function : Disconnect
1234 // purpose  :
1235 // ========================================================================
1236 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
1237                                 const Handle(Graphic3d_Structure)& theDaughter)
1238 {
1239   Standard_Integer anIndexM = IsComputed (theMother);
1240   Standard_Integer anIndexD = IsComputed (theDaughter);
1241   if (anIndexM != 0
1242    && anIndexD != 0)
1243   {
1244     const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1245     const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1246     aStructM->GraphicDisconnect (aStructD);
1247   }
1248 }
1249
1250 // ========================================================================
1251 // function : DisplayImmediate
1252 // purpose  :
1253 // ========================================================================
1254 Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
1255                                                   const Standard_Boolean             theIsSingleView)
1256 {
1257   if (!myImmediateStructures.Add (theStructure))
1258   {
1259     return Standard_False;
1260   }
1261
1262   if (theIsSingleView)
1263   {
1264     Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
1265
1266     for (int i=1;i<=aViews->Length();i++)
1267     {
1268       if (aViews->Value(i).Access() != this)
1269       {
1270         aViews->Value(i)->EraseImmediate (theStructure);
1271       }
1272     }
1273   }
1274
1275   myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
1276   return Standard_True;
1277 }
1278
1279 // ========================================================================
1280 // function : EraseImmediate
1281 // purpose  :
1282 // ========================================================================
1283 Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
1284 {
1285   const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
1286   if (isErased)
1287   {
1288     myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
1289   }
1290
1291   return isErased;
1292 }
1293
1294 // ========================================================================
1295 // function : ClearImmediate
1296 // purpose  :
1297 // ========================================================================
1298 Standard_Boolean Visual3d_View::ClearImmediate()
1299 {
1300   if (myImmediateStructures.IsEmpty())
1301   {
1302     return Standard_False;
1303   }
1304
1305   for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
1306   {
1307     myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
1308   }
1309   myImmediateStructures.Clear();
1310   return Standard_True;
1311 }
1312
1313 // ========================================================================
1314 // function : Display
1315 // purpose  :
1316 // ========================================================================
1317 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
1318 {
1319   Display (theStruct, myViewManager->UpdateMode());
1320 }
1321
1322 // ========================================================================
1323 // function : Display
1324 // purpose  :
1325 // ========================================================================
1326 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
1327                              const Aspect_TypeOfUpdate          theUpdateMode)
1328 {
1329   if (IsDeleted()
1330   || !IsDefined()
1331   || !IsActive())
1332   {
1333     return;
1334   }
1335
1336   // If Display on a structure present in the list of calculated structures while it is not
1337   // or more, of calculated type =>
1338   // - removes it as well as the associated old computed
1339   // THis happens when hlhsr becomes again of type e non computed after SetVisual.
1340   Standard_Integer anIndex = IsComputed (theStruct);
1341   if (anIndex != 0
1342    && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
1343   {
1344     myStructsToCompute.Remove (anIndex);
1345     myStructsComputed .Remove (anIndex);
1346     anIndex = 0;
1347   }
1348
1349   Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1350   if (anAnswer == Visual3d_TOA_NO)
1351   {
1352     return;
1353   }
1354
1355   if (!ComputedMode())
1356   {
1357     anAnswer = Visual3d_TOA_YES;
1358   }
1359
1360   if (anAnswer == Visual3d_TOA_YES)
1361   {
1362     if (IsDisplayed (theStruct))
1363     {
1364       return;
1365     }
1366
1367     theStruct->CalculateBoundBox();
1368     myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
1369     myStructsDisplayed.Add (theStruct);
1370     Update (theUpdateMode);
1371     return;
1372   }
1373   else if (anAnswer != Visual3d_TOA_COMPUTE)
1374   {
1375     return;
1376   }
1377
1378   if (anIndex != 0)
1379   {
1380     // Already computed, is COMPUTED still valid?
1381     const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
1382     if (anOldStruct->HLRValidation())
1383     {
1384       // Case COMPUTED valid
1385       // to be displayed
1386       if (!IsDisplayed (theStruct))
1387       {
1388         myStructsDisplayed.Add (theStruct);
1389         myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
1390         Update (theUpdateMode);
1391       }
1392       return;
1393     }
1394     else
1395     {
1396       // Case COMPUTED invalid
1397       // Is there another valid representation?
1398       // Find in the sequence of already calculated structures
1399       // 1/ Structure having the same Owner as <AStructure>
1400       // 2/ That is not <AStructure>
1401       // 3/ The COMPUTED which of is valid
1402       const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
1403       if (aNewIndex != 0)
1404       {
1405         // Case of COMPUTED invalid, WITH a valid of replacement
1406         // to be displayed
1407         if (!IsDisplayed (theStruct))
1408         {
1409           const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
1410           myStructsComputed.SetValue (anIndex, aNewStruct);
1411           myStructsDisplayed.Add (theStruct);
1412           myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
1413           Update (theUpdateMode);
1414         }
1415         return;
1416       }
1417       else
1418       {
1419         // Case COMPUTED invalid, WITHOUT a valid of replacement
1420         // COMPUTED is removed if displayed
1421         if (IsDisplayed (theStruct))
1422         {
1423           myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
1424         }
1425       }
1426     }
1427   }
1428
1429   // Compute + Validation
1430   Handle(Graphic3d_Structure) aStruct;
1431   TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1432   theStruct->Transform (aTrsf);
1433   if (anIndex != 0)
1434   {
1435     TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1436     for (Standard_Integer ii = 0; ii <= 3; ++ii)
1437     {
1438       for (Standard_Integer jj = 0; jj <= 3; ++jj)
1439       {
1440         anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
1441       }
1442     }
1443
1444     aStruct = myStructsComputed.Value (anIndex);
1445     aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1446     if (theStruct->IsTransformed())
1447     {
1448       theStruct->Compute (this, aTrsf, aStruct);
1449     }
1450     else
1451     {
1452       theStruct->Compute (this, aStruct);
1453     }
1454   }
1455   else
1456   {
1457     aStruct = theStruct->IsTransformed()
1458             ? theStruct->Compute (this, aTrsf)
1459             : theStruct->Compute (this);
1460   }
1461
1462   aStruct->SetHLRValidation (Standard_True);
1463
1464   // TOCOMPUTE and COMPUTED associated to sequences are added
1465   myStructsToCompute.Append (theStruct);
1466   myStructsComputed .Append (aStruct);
1467
1468   // The previous are removed if necessary
1469   if (anIndex != 0)
1470   {
1471     myStructsToCompute.Remove (anIndex);
1472     myStructsComputed .Remove (anIndex);
1473   }
1474
1475   // Of which type will be the computed?
1476   const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1477   const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1478                                            && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1479   const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
1480                                            && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1481   if (!toComputeShading && !toComputeWireframe)
1482   {
1483     anAnswer = Visual3d_TOA_NO;
1484   }
1485   else
1486   {
1487     aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
1488     anAnswer = AcceptDisplay (aStruct);
1489   }
1490
1491   if (theStruct->IsHighlighted())
1492   {
1493     aStruct->SetHighlightColor (theStruct->HighlightColor());
1494     aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1495   }
1496
1497   // It is displayed only if the calculated structure
1498   // has a proper type corresponding to the one of the view.
1499   if (anAnswer != Visual3d_TOA_NO)
1500   {
1501     if (!IsDisplayed (theStruct))
1502     {
1503       myStructsDisplayed.Add (theStruct);
1504     }
1505     myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
1506     Update (theUpdateMode);
1507   }
1508 }
1509
1510 // ========================================================================
1511 // function : Erase
1512 // purpose  :
1513 // ========================================================================
1514 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
1515 {
1516   if (!IsDeleted())
1517   {
1518     Erase (theStruct, myViewManager->UpdateMode());
1519   }
1520 }
1521
1522 // ========================================================================
1523 // function : Erase
1524 // purpose  :
1525 // ========================================================================
1526 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
1527                            const Aspect_TypeOfUpdate          theUpdateMode)
1528 {
1529   if (IsDeleted()
1530   || !IsDisplayed (theStruct))
1531   {
1532     return;
1533   }
1534
1535   Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1536   if (!ComputedMode())
1537   {
1538     anAnswer = Visual3d_TOA_YES;
1539   }
1540
1541   if (anAnswer != Visual3d_TOA_COMPUTE)
1542   {
1543     myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
1544   }
1545   else if (anAnswer == Visual3d_TOA_COMPUTE
1546        && myIsInComputedMode)
1547   {
1548     const Standard_Integer anIndex = IsComputed (theStruct);
1549     if (anIndex != 0)
1550     {
1551       const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1552       myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
1553     }
1554   }
1555   myStructsDisplayed.Remove (theStruct);
1556   Update (theUpdateMode);
1557 }
1558
1559 // ========================================================================
1560 // function : Highlight
1561 // purpose  :
1562 // ========================================================================
1563 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
1564                                const Aspect_TypeOfHighlightMethod theMethod)
1565 {
1566   const Standard_Integer anIndex = IsComputed (theStruct);
1567   if (anIndex != 0)
1568   {
1569     const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1570     aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1571     aCompStruct->GraphicHighlight (theMethod);
1572   }
1573 }
1574
1575 // ========================================================================
1576 // function : SetTransform
1577 // purpose  :
1578 // ========================================================================
1579 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
1580                                   const TColStd_Array2OfReal&        theTrsf)
1581 {
1582   const Standard_Integer anIndex = IsComputed (theStruct);
1583   if (anIndex != 0)
1584   {
1585     // Test is somewhat light !
1586     // trsf is transferred only if it is :
1587     // a translation
1588     // a scale
1589     if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
1590      || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
1591      || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
1592     {
1593       ReCompute (theStruct);
1594     }
1595     else
1596     {
1597       const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1598       aCompStruct->GraphicTransform (theTrsf);
1599     }
1600   }
1601
1602   theStruct->CalculateBoundBox();
1603   if (!theStruct->IsMutable()
1604    && !theStruct->CStructure()->IsForHighlight
1605    && !theStruct->CStructure()->IsInfinite)
1606   {
1607     const Standard_Integer aLayerId = theStruct->GetZLayer();
1608     myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
1609   }
1610 }
1611
1612 // ========================================================================
1613 // function : UnHighlight
1614 // purpose  :
1615 // ========================================================================
1616 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
1617 {
1618   Standard_Integer anIndex = IsComputed (theStruct);
1619   if (anIndex != 0)
1620   {
1621     const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1622     aCompStruct->GraphicUnHighlight();
1623   }
1624 }
1625
1626 // ========================================================================
1627 // function : IsComputed
1628 // purpose  :
1629 // ========================================================================
1630 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
1631 {
1632   const Standard_Integer aStructId  = theStruct->Identification();
1633   const Standard_Integer aNbStructs = myStructsToCompute.Length();
1634   for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1635   {
1636     const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1637     if (aStruct->Identification() == aStructId)
1638     {
1639       return aStructIter;
1640     }
1641   }
1642   return 0;
1643 }
1644
1645 // ========================================================================
1646 // function : IsDisplayed
1647 // purpose  :
1648 // ========================================================================
1649 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
1650 {
1651   return !IsDeleted()
1652       &&  myStructsDisplayed.Contains (theStruct);
1653 }
1654
1655 // ========================================================================
1656 // function : ContainsFacet
1657 // purpose  :
1658 // ========================================================================
1659 Standard_Boolean Visual3d_View::ContainsFacet() const
1660 {
1661   return ContainsFacet (myStructsDisplayed);
1662 }
1663
1664 // ========================================================================
1665 // function : ContainsFacet
1666 // purpose  :
1667 // ========================================================================
1668 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
1669 {
1670   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
1671   {
1672     if (aStructIter.Key()->ContainsFacet())
1673     {
1674       return Standard_True;
1675     }
1676   }
1677   return Standard_False;
1678 }
1679
1680 // ========================================================================
1681 // function : MinMaxValues
1682 // purpose  :
1683 // ========================================================================
1684 Bnd_Box Visual3d_View::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1685 {
1686   return MinMaxValues (myStructsDisplayed,
1687                        theToIgnoreInfiniteFlag);
1688 }
1689
1690 // ========================================================================
1691 // function : MinMaxValues
1692 // purpose  :
1693 // ========================================================================
1694 Bnd_Box Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1695                                      const Standard_Boolean theToIgnoreInfiniteFlag) const
1696 {
1697   Bnd_Box aResult;
1698   if (theSet.IsEmpty ())
1699   {
1700     // Return an empty box.
1701     return aResult;
1702   }
1703   Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet);
1704   for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next())
1705   {
1706     const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
1707
1708     if (!aStructure->IsVisible())
1709       continue;
1710
1711     if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
1712     {
1713       //XMin, YMin .... ZMax are initialized by means of infinite line data
1714       Bnd_Box aBox = aStructure->MinMaxValues (Standard_False);
1715       if (!aBox.IsWhole() && !aBox.IsVoid())
1716       {
1717         aResult.Add (aBox);
1718       }
1719     }
1720
1721     // Only non-empty and non-infinite structures
1722     // are taken into account for calculation of MinMax
1723     if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty())
1724     {
1725       Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
1726
1727       /* ABD 29/10/04  Transform Persistence of Presentation( pan, zoom, rotate ) */
1728       //"FitAll" operation ignores object with transform persitence parameter
1729       if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None )
1730       {
1731           aResult.Add (aBox);
1732       }
1733     }
1734   }
1735   return aResult;
1736 }
1737
1738 // =======================================================================
1739 // function : NumberOfDisplayedStructures
1740 // purpose  :
1741 // =======================================================================
1742 Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
1743 {
1744   return myStructsDisplayed.Extent();
1745 }
1746
1747 // =======================================================================
1748 // function : Projects
1749 // purpose  :
1750 // =======================================================================
1751 void Visual3d_View::Projects (const Standard_Real theX,
1752                               const Standard_Real theY,
1753                               const Standard_Real theZ,
1754                               Standard_Real& thePX,
1755                               Standard_Real& thePY,
1756                               Standard_Real& thePZ) const
1757 {
1758   const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1759
1760   gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1761   Standard_Real aXSize = aViewSpaceDimensions.X();
1762   Standard_Real aYSize = aViewSpaceDimensions.Y();
1763   Standard_Real aZSize = aViewSpaceDimensions.Z();
1764
1765   gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1766
1767   // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1768   thePX = aPoint.X() * aXSize * 0.5;
1769   thePY = aPoint.Y() * aYSize * 0.5;
1770   thePZ = aPoint.Z() * aZSize * 0.5;
1771 }
1772
1773 // =======================================================================
1774 // function : Identification
1775 // purpose  :
1776 // =======================================================================
1777 Standard_Integer Visual3d_View::Identification() const
1778 {
1779   return MyCView.ViewId;
1780 }
1781
1782 // =======================================================================
1783 // function : ZBufferIsActivated
1784 // purpose  :
1785 // =======================================================================
1786 Standard_Boolean Visual3d_View::ZBufferIsActivated() const
1787 {
1788   if (IsDeleted()
1789   || !IsDefined()
1790   || !IsActive())
1791   {
1792     return Standard_False;
1793   }
1794
1795   if (MyCView.Context.ZBufferActivity == -1)
1796   {
1797     // not forced by the programmer => depends on the type of visualisation
1798     return MyContext.Visualization () == Visual3d_TOV_SHADING;
1799   }
1800   return MyCView.Context.ZBufferActivity != 0; //  0 or 1 => forced by the programmer
1801 }
1802
1803 // =======================================================================
1804 // function : SetTransparency
1805 // purpose  :
1806 // =======================================================================
1807 void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
1808 {
1809   if (IsDeleted()
1810   || !IsDefined()
1811   || !IsActive())
1812   {
1813     return;
1814   }
1815
1816   myGraphicDriver->Transparency (MyCView, theActivity);
1817 }
1818
1819 // =======================================================================
1820 // function : SetZBufferActivity
1821 // purpose  :
1822 // =======================================================================
1823 void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
1824 {
1825   if (IsDeleted()
1826   ||  MyCView.Context.ZBufferActivity == theActivity
1827   || !IsDefined()
1828   || !IsActive())
1829   {
1830     return;
1831   }
1832
1833   MyCView.Context.ZBufferActivity = theActivity;
1834   myGraphicDriver->SetVisualisation (MyCView);
1835 }
1836
1837 // =======================================================================
1838 // function : UpdateView
1839 // purpose  :
1840 // =======================================================================
1841 void Visual3d_View::UpdateView()
1842 {
1843   MyCView.Context.Aliasing        = MyContext.AliasingIsOn();
1844   MyCView.Context.BackZClipping   = MyContext.BackZClippingIsOn();
1845   MyCView.Context.FrontZClipping  = MyContext.FrontZClippingIsOn();
1846   MyCView.Context.DepthCueing     = MyContext.DepthCueingIsOn();
1847
1848   MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
1849   MyCView.Context.ZClipBackPlane  = float (MyContext.ZClippingBackPlane());
1850   MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
1851   MyCView.Context.DepthBackPlane  = float (MyContext.DepthCueingBackPlane());
1852
1853   MyCView.Context.Model           = MyContext.Model();
1854   MyCView.Context.Visualization   = MyContext.Visualization();
1855
1856   MyCView.Context.TextureEnv      = MyContext.TextureEnv();
1857   MyCView.Context.SurfaceDetail   = MyContext.SurfaceDetail();
1858 }
1859
1860 // =======================================================================
1861 // function : Compute
1862 // purpose  :
1863 // =======================================================================
1864 void Visual3d_View::Compute()
1865 {
1866   // force HLRValidation to False on all structures calculated in the view
1867   const Standard_Integer aNbCompStructs = myStructsComputed.Length();
1868   for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
1869   {
1870     myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
1871   }
1872
1873   if (!ComputedMode())
1874   {
1875     return;
1876   }
1877
1878   // Change of orientation or of projection type =>
1879   // Remove structures that were calculated for the previous orientation.
1880   // Recalculation of new structures.
1881   NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
1882   for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
1883   {
1884     const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
1885     if (anAnswer == Visual3d_TOA_COMPUTE)
1886     {
1887       aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
1888     }
1889   }
1890
1891   for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
1892   {
1893     Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
1894   }
1895 }
1896
1897 // =======================================================================
1898 // function : ReCompute
1899 // purpose  :
1900 // =======================================================================
1901 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
1902 {
1903   theStruct->CalculateBoundBox();
1904   if (!theStruct->IsMutable()
1905    && !theStruct->CStructure()->IsForHighlight
1906    && !theStruct->CStructure()->IsInfinite)
1907   {
1908     const Standard_Integer aLayerId = theStruct->DisplayPriority();
1909     myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
1910   }
1911
1912   if (!ComputedMode()
1913    ||  IsDeleted()
1914    || !IsDefined()
1915    || !IsActive()
1916    || !MyWindow->IsMapped()
1917    || !theStruct->IsDisplayed())
1918   {
1919     return;
1920   }
1921
1922   const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1923   if (anAnswer != Visual3d_TOA_COMPUTE)
1924   {
1925     return;
1926   }
1927
1928   const Standard_Integer anIndex = IsComputed (theStruct);
1929   if (anIndex == 0)
1930   {
1931     return;
1932   }
1933
1934   // compute + validation
1935   TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1936   for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
1937   {
1938     for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
1939     {
1940       anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
1941     }
1942   }
1943   TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1944   theStruct->Transform (aTrsf);
1945
1946   Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
1947   Handle(Graphic3d_Structure) aCompStruct    = aCompStructOld;
1948   aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1949   theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
1950                              : theStruct->Compute (this,        aCompStruct);
1951   aCompStruct->SetHLRValidation (Standard_True);
1952
1953   // of which type will be the computed?
1954   const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1955   const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1956                                            && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1957   const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
1958                                            && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1959   if (toComputeWireframe)
1960   {
1961     aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
1962   }
1963   else if (toComputeShading)
1964   {
1965     aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
1966   }
1967
1968   if (theStruct->IsHighlighted())
1969   {
1970     aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1971     aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1972   }
1973
1974   // The previous calculation is removed and the new one is dislayed
1975   myGraphicDriver->EraseStructure   (MyCView, *aCompStructOld->CStructure());
1976   myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
1977
1978   // why not just replace existing items?
1979   //myStructsToCompute.ChangeValue (anIndex) = theStruct;
1980   //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
1981
1982   // hlhsr and the new associated compute are added
1983   myStructsToCompute.Append (theStruct);
1984   myStructsComputed .Append (aCompStruct);
1985
1986   // hlhsr and the new associated compute are removed
1987   myStructsToCompute.Remove (anIndex);
1988   myStructsComputed .Remove (anIndex);
1989 }
1990
1991 // =======================================================================
1992 // function : GraphicDriver
1993 // purpose  :
1994 // =======================================================================
1995 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
1996 {
1997   return myGraphicDriver;
1998 }
1999
2000 // =======================================================================
2001 // function : HaveTheSameOwner
2002 // purpose  :
2003 // =======================================================================
2004 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
2005 {
2006   // Find in the sequence of already calculated structures
2007   // 1/ Structure with the same Owner as <AStructure>
2008   // 2/ Which is not <AStructure>
2009   // 3/ COMPUTED which of is valid
2010   const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
2011   for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
2012   {
2013     const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
2014     if (aStructToComp->Owner()          == theStruct->Owner()
2015      && aStructToComp->Identification() != theStruct->Identification())
2016     {
2017       const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
2018       if (aStructComp->HLRValidation())
2019       {
2020         return aStructIter;
2021       }
2022     }
2023   }
2024   return 0;
2025 }
2026
2027 // =======================================================================
2028 // function : CView
2029 // purpose  :
2030 // =======================================================================
2031 Standard_Address Visual3d_View::CView() const
2032 {
2033   return Standard_Address (&MyCView);
2034 }
2035
2036 // =======================================================================
2037 // function : ZBufferTriedronSetup
2038 // purpose  :
2039 // =======================================================================
2040 void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
2041                                           const Quantity_NameOfColor theYColor,
2042                                           const Quantity_NameOfColor theZColor,
2043                                           const Standard_Real        theSizeRatio,
2044                                           const Standard_Real        theAxisDiametr,
2045                                           const Standard_Integer     theNbFacettes)
2046 {
2047   myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
2048                                          theSizeRatio, theAxisDiametr, theNbFacettes);
2049 }
2050
2051 // =======================================================================
2052 // function : TriedronDisplay
2053 // purpose  :
2054 // =======================================================================
2055 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
2056                                      const Quantity_NameOfColor          theColor,
2057                                      const Standard_Real                 theScale,
2058                                      const Standard_Boolean              theAsWireframe)
2059 {
2060   myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
2061 }
2062
2063 // =======================================================================
2064 // function : TriedronErase
2065 // purpose  :
2066 // =======================================================================
2067 void Visual3d_View::TriedronErase()
2068 {
2069   myGraphicDriver->TriedronErase (MyCView);
2070 }
2071
2072 // =======================================================================
2073 // function : TriedronEcho
2074 // purpose  :
2075 // =======================================================================
2076 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
2077 {
2078   myGraphicDriver->TriedronEcho (MyCView, theType);
2079 }
2080
2081 static void SetMinMaxValuesCallback (Visual3d_View* theView)
2082 {
2083   Bnd_Box aBox = theView->MinMaxValues();
2084   if (!aBox.IsVoid())
2085   {
2086     gp_Pnt aMin = aBox.CornerMin();
2087     gp_Pnt aMax = aBox.CornerMax();
2088     const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
2089     aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z(),
2090                                              (Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
2091   }
2092 }
2093
2094 // =======================================================================
2095 // function : GetGraduatedTrihedron
2096 // purpose  :
2097 // =======================================================================
2098 Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
2099                                                        TCollection_ExtendedString& theYName,
2100                                                        TCollection_ExtendedString& theZName,
2101                                                        Standard_Boolean&           theToDrawXName,
2102                                                        Standard_Boolean&           theToDrawYName,
2103                                                        Standard_Boolean&           theToDrawZName,
2104                                                        Standard_Boolean&           theToDrawXValues,
2105                                                        Standard_Boolean&           theToDrawYValues,
2106                                                        Standard_Boolean&           theToDrawZValues,
2107                                                        Standard_Boolean&           theToDrawGrid,
2108                                                        Standard_Boolean&           theToDrawAxes,
2109                                                        Standard_Integer&           theNbX,
2110                                                        Standard_Integer&           theNbY,
2111                                                        Standard_Integer&           theNbZ,
2112                                                        Standard_Integer&           theXOffset,
2113                                                        Standard_Integer&           theYOffset,
2114                                                        Standard_Integer&           theZOffset,
2115                                                        Standard_Integer&           theXAxisOffset,
2116                                                        Standard_Integer&           theYAxisOffset,
2117                                                        Standard_Integer&           theZAxisOffset,
2118                                                        Standard_Boolean&           theToDrawXTickMarks,
2119                                                        Standard_Boolean&           theToDrawYTickMarks,
2120                                                        Standard_Boolean&           theToDrawZTickMarks,
2121                                                        Standard_Integer&           theXTickMarkLength,
2122                                                        Standard_Integer&           theYTickMarkLength,
2123                                                        Standard_Integer&           theZTickMarkLength,
2124                                                        Quantity_Color&             theGridColor,
2125                                                        Quantity_Color&             theXNameColor,
2126                                                        Quantity_Color&             theYNameColor,
2127                                                        Quantity_Color&             theZNameColor,
2128                                                        Quantity_Color&             theXColor,
2129                                                        Quantity_Color&             theYColor,
2130                                                        Quantity_Color&             theZColor,
2131                                                        TCollection_AsciiString&    theFontOfNames,
2132                                                        Font_FontAspect&            theStyleOfNames,
2133                                                        Standard_Integer&           theSizeOfNames,
2134                                                        TCollection_AsciiString&    theFontOfValues,
2135                                                        Font_FontAspect&            theStyleOfValues,
2136                                                        Standard_Integer&           theSizeOfValues) const
2137 {
2138   if (!MyGTrihedron.ptrVisual3dView)
2139   {
2140     return Standard_False;
2141   }
2142
2143   theXName = MyGTrihedron.xname;
2144   theYName = MyGTrihedron.yname;
2145   theZName = MyGTrihedron.zname;
2146   theToDrawXName   = MyGTrihedron.xdrawname;
2147   theToDrawYName   = MyGTrihedron.ydrawname;
2148   theToDrawZName   = MyGTrihedron.zdrawname;
2149   theToDrawXValues = MyGTrihedron.xdrawvalues;
2150   theToDrawYValues = MyGTrihedron.ydrawvalues;
2151   theToDrawZValues = MyGTrihedron.zdrawvalues;
2152   theToDrawGrid    = MyGTrihedron.drawgrid;
2153   theToDrawAxes    = MyGTrihedron.drawaxes;
2154   theNbX = MyGTrihedron.nbx;
2155   theNbY = MyGTrihedron.nby;
2156   theNbZ = MyGTrihedron.nbz;
2157   theXOffset     = MyGTrihedron.xoffset;
2158   theYOffset     = MyGTrihedron.yoffset;
2159   theZOffset     = MyGTrihedron.zoffset;
2160   theXAxisOffset = MyGTrihedron.xaxisoffset;
2161   theYAxisOffset = MyGTrihedron.yaxisoffset;
2162   theZAxisOffset = MyGTrihedron.zaxisoffset;
2163   theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
2164   theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
2165   theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
2166   theXTickMarkLength  = MyGTrihedron.xtickmarklength;
2167   theYTickMarkLength  = MyGTrihedron.ytickmarklength;
2168   theZTickMarkLength  = MyGTrihedron.ztickmarklength;
2169   theGridColor  = MyGTrihedron.gridcolor;
2170   theXNameColor = MyGTrihedron.xnamecolor;
2171   theYNameColor = MyGTrihedron.ynamecolor;
2172   theZNameColor = MyGTrihedron.znamecolor;
2173   theXColor     = MyGTrihedron.xcolor;
2174   theYColor     = MyGTrihedron.ycolor;
2175   theZColor     = MyGTrihedron.zcolor;
2176   theFontOfNames   = MyGTrihedron.fontOfNames;
2177   theStyleOfNames  = MyGTrihedron.styleOfNames;
2178   theSizeOfNames   = MyGTrihedron.sizeOfNames;
2179   theFontOfValues  = MyGTrihedron.fontOfValues;
2180   theStyleOfValues = MyGTrihedron.styleOfValues;
2181   theSizeOfValues  = MyGTrihedron.sizeOfValues;
2182   return Standard_True;
2183 }
2184
2185 // =======================================================================
2186 // function : GraduatedTrihedronDisplay
2187 // purpose  :
2188 // =======================================================================
2189 void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
2190                                                const TCollection_ExtendedString& theYName,
2191                                                const TCollection_ExtendedString& theZName,
2192                                                const Standard_Boolean theToDrawXName,
2193                                                const Standard_Boolean theToDrawYName,
2194                                                const Standard_Boolean theToDrawZName,
2195                                                const Standard_Boolean theToDrawXValues,
2196                                                const Standard_Boolean theToDrawYValues,
2197                                                const Standard_Boolean theToDrawZValues,
2198                                                const Standard_Boolean theToDrawGrid,
2199                                                const Standard_Boolean theToDrawAxes,
2200                                                const Standard_Integer theNbX,
2201                                                const Standard_Integer theNbY,
2202                                                const Standard_Integer theNbZ,
2203                                                const Standard_Integer theXOffset,
2204                                                const Standard_Integer theYOffset,
2205                                                const Standard_Integer theZOffset,
2206                                                const Standard_Integer theXAxisOffset,
2207                                                const Standard_Integer theYAxisOffset,
2208                                                const Standard_Integer theZAxisOffset,
2209                                                const Standard_Boolean theToDrawXTickMarks,
2210                                                const Standard_Boolean theToDrawYTickMarks,
2211                                                const Standard_Boolean theToDrawZTickMarks,
2212                                                const Standard_Integer theXTickMarkLength,
2213                                                const Standard_Integer theYTickMarkLength,
2214                                                const Standard_Integer theZTickMarkLength,
2215                                                const Quantity_Color&  theGridColor,
2216                                                const Quantity_Color&  theXNameColor,
2217                                                const Quantity_Color&  theYNameColor,
2218                                                const Quantity_Color&  theZNameColor,
2219                                                const Quantity_Color&  theXColor,
2220                                                const Quantity_Color&  theYColor,
2221                                                const Quantity_Color&  theZColor,
2222                                                const TCollection_AsciiString& theFontOfNames,
2223                                                const Font_FontAspect  theStyleOfNames,
2224                                                const Standard_Integer theSizeOfNames,
2225                                                const TCollection_AsciiString& theFontOfValues,
2226                                                const Font_FontAspect  theStyleOfValues,
2227                                                const Standard_Integer theSizeOfValues)
2228 {
2229   MyGTrihedron.xname = theXName;
2230   MyGTrihedron.yname = theYName;
2231   MyGTrihedron.zname = theZName;
2232   MyGTrihedron.xdrawname = theToDrawXName;
2233   MyGTrihedron.ydrawname = theToDrawYName;
2234   MyGTrihedron.zdrawname = theToDrawZName;
2235   MyGTrihedron.xdrawvalues = theToDrawXValues;
2236   MyGTrihedron.ydrawvalues = theToDrawYValues;
2237   MyGTrihedron.zdrawvalues = theToDrawZValues;
2238   MyGTrihedron.drawgrid = theToDrawGrid;
2239   MyGTrihedron.drawaxes = theToDrawAxes;
2240   MyGTrihedron.nbx = theNbX;
2241   MyGTrihedron.nby = theNbY;
2242   MyGTrihedron.nbz = theNbZ;
2243   MyGTrihedron.xoffset = theXOffset;
2244   MyGTrihedron.yoffset = theYOffset;
2245   MyGTrihedron.zoffset = theZOffset;
2246   MyGTrihedron.xaxisoffset = theXAxisOffset;
2247   MyGTrihedron.yaxisoffset = theYAxisOffset;
2248   MyGTrihedron.zaxisoffset = theZAxisOffset;
2249   MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
2250   MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
2251   MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
2252   MyGTrihedron.xtickmarklength = theXTickMarkLength;
2253   MyGTrihedron.ytickmarklength = theYTickMarkLength;
2254   MyGTrihedron.ztickmarklength = theZTickMarkLength;
2255   MyGTrihedron.gridcolor  = theGridColor;
2256   MyGTrihedron.xnamecolor = theXNameColor;
2257   MyGTrihedron.ynamecolor = theYNameColor;
2258   MyGTrihedron.znamecolor = theZNameColor;
2259   MyGTrihedron.xcolor = theXColor;
2260   MyGTrihedron.ycolor = theYColor;
2261   MyGTrihedron.zcolor = theZColor;
2262   MyGTrihedron.fontOfNames   = theFontOfNames;
2263   MyGTrihedron.styleOfNames  = theStyleOfNames;
2264   MyGTrihedron.sizeOfNames   = theSizeOfNames;
2265   MyGTrihedron.fontOfValues  = theFontOfValues;
2266   MyGTrihedron.styleOfValues = theStyleOfValues;
2267   MyGTrihedron.sizeOfValues  = theSizeOfValues;
2268
2269   MyGTrihedron.ptrVisual3dView = this;
2270   MyGTrihedron.cbCubicAxes     = SetMinMaxValuesCallback;
2271   myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
2272 }
2273
2274 // =======================================================================
2275 // function : GraduatedTrihedronErase
2276 // purpose  :
2277 // =======================================================================
2278 void Visual3d_View::GraduatedTrihedronErase()
2279 {
2280   MyGTrihedron.ptrVisual3dView = NULL;
2281   myGraphicDriver->GraduatedTrihedronErase (MyCView);
2282 }
2283
2284 // =======================================================================
2285 // function : UnderLayer
2286 // purpose  :
2287 // =======================================================================
2288 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
2289 {
2290   return myViewManager->UnderLayer();
2291 }
2292
2293 // =======================================================================
2294 // function : OverLayer
2295 // purpose  :
2296 // =======================================================================
2297 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
2298 {
2299   return myViewManager->OverLayer();
2300 }
2301
2302 // =======================================================================
2303 // function : LightLimit
2304 // purpose  :
2305 // =======================================================================
2306 Standard_Integer Visual3d_View::LightLimit() const
2307 {
2308   return myGraphicDriver->InquireLightLimit();
2309 }
2310
2311 // =======================================================================
2312 // function : PlaneLimit
2313 // purpose  :
2314 // =======================================================================
2315 Standard_Integer Visual3d_View::PlaneLimit() const
2316 {
2317   return myGraphicDriver->InquirePlaneLimit();
2318 }
2319
2320 // =======================================================================
2321 // function : ViewManager
2322 // purpose  :
2323 // =======================================================================
2324 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
2325 {
2326   return myViewManager;
2327 }
2328
2329 // =======================================================================
2330 // function : SetComputedMode
2331 // purpose  :
2332 // =======================================================================
2333 void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
2334 {
2335   if (( theMode &&  myIsInComputedMode)
2336    || (!theMode && !myIsInComputedMode))
2337   {
2338     return;
2339   }
2340
2341   myIsInComputedMode = theMode;
2342   if (!myIsInComputedMode)
2343   {
2344     for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2345     {
2346       const Handle(Graphic3d_Structure)& aStruct  = aStructIter.Key();
2347       const Visual3d_TypeOfAnswer        anAnswer = AcceptDisplay (aStruct);
2348       if (anAnswer != Visual3d_TOA_COMPUTE)
2349       {
2350         continue;
2351       }
2352
2353       const Standard_Integer anIndex = IsComputed (aStruct);
2354       if (anIndex != 0)
2355       {
2356         const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
2357         myGraphicDriver->EraseStructure   (MyCView, *aStructComp->CStructure());
2358         myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
2359       }
2360     }
2361     return;
2362   }
2363
2364   for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
2365   {
2366     Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
2367     const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2368     if (anAnswer != Visual3d_TOA_COMPUTE)
2369     {
2370       continue;
2371     }
2372
2373     const Standard_Integer anIndex = IsComputed (aStruct);
2374     if (anIndex != 0)
2375     {
2376       myGraphicDriver->EraseStructure   (MyCView, *aStruct->CStructure());
2377       myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
2378
2379       Display (aStruct, Aspect_TOU_WAIT);
2380       if (aStruct->IsHighlighted())
2381       {
2382         const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
2383         if (!aCompStruct->IsHighlighted())
2384         {
2385           aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2386           aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2387         }
2388       }
2389     }
2390     else
2391     {
2392       TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2393       aStruct->Transform (aTrsf);
2394       Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
2395       aCompStruct->SetHLRValidation (Standard_True);
2396
2397       const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2398       const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2399                                                 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2400       const Standard_Boolean toComputeShading   = aViewType == Visual3d_TOV_SHADING
2401                                                 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2402       if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2403       if (toComputeShading  ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2404
2405       if (aStruct->IsHighlighted())
2406       {
2407         aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2408         aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2409       }
2410
2411       Standard_Boolean hasResult = Standard_False;
2412       const Standard_Integer aNbToCompute = myStructsToCompute.Length();
2413       const Standard_Integer aStructId    = aStruct->Identification();
2414       for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
2415       {
2416         if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
2417         {
2418           hasResult = Standard_True;
2419           myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
2420           break;
2421         }
2422       }
2423
2424       if (!hasResult)
2425       {
2426         myStructsToCompute.Append (aStruct);
2427         myStructsComputed .Append (aCompStruct);
2428       }
2429
2430       myGraphicDriver->EraseStructure   (MyCView, *aStruct->CStructure());
2431       myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
2432     }
2433   }
2434   Update (myViewManager->UpdateMode());
2435 }
2436
2437 // =======================================================================
2438 // function : ComputedMode
2439 // purpose  :
2440 // =======================================================================
2441 Standard_Boolean Visual3d_View::ComputedMode() const
2442 {
2443   return myIsInComputedMode;
2444 }
2445
2446 // =======================================================================
2447 // function : SetBackFacingModel
2448 // purpose  :
2449 // =======================================================================
2450 void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
2451 {
2452   switch (theModel)
2453   {
2454     default:
2455     case Visual3d_TOBM_AUTOMATIC:
2456       MyCView.Backfacing = 0;
2457       break;
2458     case Visual3d_TOBM_FORCE:
2459       MyCView.Backfacing = 1;
2460       break;
2461     case Visual3d_TOBM_DISABLE:
2462       MyCView.Backfacing = -1;
2463       break;
2464   }
2465   myGraphicDriver->SetBackFacingModel (MyCView);
2466 }
2467
2468 // =======================================================================
2469 // function : BackFacingModel
2470 // purpose  :
2471 // =======================================================================
2472 Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
2473 {
2474   switch (MyCView.Backfacing)
2475   {
2476     case 0: return Visual3d_TOBM_AUTOMATIC;
2477     case 1: return Visual3d_TOBM_FORCE;
2478   }
2479   return Visual3d_TOBM_DISABLE;
2480 }
2481
2482 // =======================================================================
2483 // function : EnableDepthTest
2484 // purpose  :
2485 // =======================================================================
2486 void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
2487 {
2488   myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
2489 }
2490
2491 // =======================================================================
2492 // function : IsDepthTestEnabled
2493 // purpose  :
2494 // =======================================================================
2495 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
2496 {
2497   return myGraphicDriver->IsDepthTestEnabled (MyCView);
2498 }
2499
2500 // =======================================================================
2501 // function : ReadDepths
2502 // purpose  :
2503 // =======================================================================
2504 void Visual3d_View::ReadDepths (const Standard_Integer theX,
2505                                 const Standard_Integer theY,
2506                                 const Standard_Integer theWidth,
2507                                 const Standard_Integer theHeight,
2508                                 const Standard_Address theBuffer) const
2509 {
2510   myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
2511 }
2512
2513 // =======================================================================
2514 // function : FBOCreate
2515 // purpose  :
2516 // =======================================================================
2517 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
2518                                                   const Standard_Integer theHeight)
2519 {
2520   return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
2521 }
2522
2523 // =======================================================================
2524 // function : FBORelease
2525 // purpose  :
2526 // =======================================================================
2527 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
2528 {
2529   myGraphicDriver->FBORelease( MyCView, theFBOPtr );
2530 }
2531
2532 // =======================================================================
2533 // function : FBOGetDimensions
2534 // purpose  :
2535 // =======================================================================
2536 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
2537                                      Standard_Integer& theWidth,    Standard_Integer& theHeight,
2538                                      Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
2539 {
2540   myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
2541                                      theWidth, theHeight,
2542                                      theWidthMax, theHeightMax );
2543 }
2544
2545 // =======================================================================
2546 // function : FBOChangeViewport
2547 // purpose  :
2548 // =======================================================================
2549 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
2550                                       const Standard_Integer theWidth, const Standard_Integer theHeight)
2551 {
2552   myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
2553                                      theWidth, theHeight );
2554 }
2555
2556 // =======================================================================
2557 // function : BufferDump
2558 // purpose  :
2559 // =======================================================================
2560 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap&               theImage,
2561                                             const Graphic3d_BufferType& theBufferType)
2562 {
2563   return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
2564 }
2565
2566 // =======================================================================
2567 // function : EnableGLLight
2568 // purpose  :
2569 // =======================================================================
2570 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
2571 {
2572   myGraphicDriver->SetGLLightEnabled( MyCView, enable );
2573 }
2574
2575 // =======================================================================
2576 // function : IsGLLightEnabled
2577 // purpose  :
2578 // =======================================================================
2579 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
2580 {
2581   return myGraphicDriver->IsGLLightEnabled( MyCView );
2582 }
2583
2584 // =======================================================================
2585 // function : Export
2586 // purpose  :
2587 // =======================================================================
2588 Standard_Boolean Visual3d_View::Export (const Standard_CString       theFileName,
2589                                         const Graphic3d_ExportFormat theFormat,
2590                                         const Graphic3d_SortType     theSortType,
2591                                         const Standard_Real          thePrecision,
2592                                         const Standard_Address       theProgressBarFunc,
2593                                         const Standard_Address       theProgressObject) const
2594 {
2595   Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
2596   Handle(Visual3d_Layer) anOverLayer  = myViewManager->OverLayer();
2597
2598   Aspect_CLayer2d anOverCLayer;
2599   Aspect_CLayer2d anUnderCLayer;
2600   anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2601
2602   if (!anOverLayer.IsNull())
2603     anOverCLayer = anOverLayer->CLayer();
2604   if (!anUnderLayer.IsNull())
2605     anUnderCLayer = anUnderLayer->CLayer();
2606
2607   Standard_Integer aWidth, aHeight;
2608   Window()->Size (aWidth, aHeight);
2609
2610   return myGraphicDriver->Export (theFileName, theFormat, theSortType,
2611                                   aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
2612                                   thePrecision, theProgressBarFunc, theProgressObject);
2613 }
2614
2615 // =======================================================================
2616 // function : SetZLayerSettings
2617 // purpose  :
2618 // =======================================================================
2619 void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
2620                                        const Graphic3d_ZLayerSettings& theSettings)
2621 {
2622   myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
2623 }
2624
2625 // =======================================================================
2626 // function : AddZLayer
2627 // purpose  :
2628 // =======================================================================
2629 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
2630 {
2631   myGraphicDriver->AddZLayer (MyCView, theLayerId);
2632 }
2633
2634 // =======================================================================
2635 // function : RemoveZLayer
2636 // purpose  :
2637 // =======================================================================
2638 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
2639 {
2640   myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
2641 }
2642
2643 // =======================================================================
2644 // function : ChangeZLayer
2645 // purpose  :
2646 // =======================================================================
2647 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
2648                                   const Standard_Integer theLayerId)
2649 {
2650   myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
2651 }
2652
2653 // =======================================================================
2654 // function : Print
2655 // purpose  :
2656 // =======================================================================
2657 Standard_Boolean Visual3d_View::Print (const Aspect_Handle    thePrintDC, 
2658                                        const Standard_Boolean theToShowBackground,
2659                                        const Standard_CString theFilename,
2660                                        const Aspect_PrintAlgo thePrintAlgorithm,
2661                                        const Standard_Real    theScaleFactor) const
2662 {
2663   return Print (myViewManager->UnderLayer(),
2664                 myViewManager->OverLayer(),
2665                 thePrintDC, theToShowBackground,
2666                 theFilename, thePrintAlgorithm, 
2667                 theScaleFactor);
2668 }
2669
2670 // =======================================================================
2671 // function : Print
2672 // purpose  :
2673 // =======================================================================
2674 Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
2675                                        const Handle(Visual3d_Layer)& theOverLayer,
2676                                        const Aspect_Handle           thePrintDC,
2677                                        const Standard_Boolean        theToShowBackground,
2678                                        const Standard_CString        theFilename,
2679                                        const Aspect_PrintAlgo        thePrintAlgorithm,
2680                                        const Standard_Real           theScaleFactor) const
2681 {
2682   if (IsDeleted()
2683   || !IsDefined()
2684   || !IsActive()
2685   || !MyWindow->IsMapped())
2686   {
2687     return Standard_False;
2688   }
2689
2690   Aspect_CLayer2d anOverCLayer;
2691   Aspect_CLayer2d anUnderCLayer;
2692   anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2693   if (!theOverLayer.IsNull())  anOverCLayer  = theOverLayer->CLayer();
2694   if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
2695   return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
2696                                  thePrintDC, theToShowBackground, theFilename,
2697                                  thePrintAlgorithm, theScaleFactor);
2698 }