1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
19 #include <Visual3d_View.ixx>
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>
34 #include <TColStd_HArray2OfReal.hxx>
37 #include <WNT_Window.hxx>
38 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
39 #include <Cocoa_Window.hxx>
41 #include <Xw_Window.hxx>
46 // =======================================================================
47 // function : Visual3d_View
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)
57 MyCView.ViewId = theMgr->Identification (this);
59 MyCView.IsDeleted = 0;
61 MyCView.DefWindow.IsDefined = 0;
62 MyCView.Context.NbActiveLight = 0;
63 MyCView.Context.ZBufferActivity = -1;
65 MyCView.Backfacing = 0;
66 MyCView.ptrUnderLayer = 0;
67 MyCView.ptrOverLayer = 0;
69 MyCView.GDisplayCB = 0;
70 MyCView.GClientData = 0;
72 myGraphicDriver = myViewManager->GraphicDriver();
75 // =======================================================================
76 // function : SetWindow
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)
90 Visual3d_ViewDefinitionError::Raise ("Window already defined");
93 MyCView.GContext = theContext;
94 MyCView.GDisplayCB = theDisplayCB;
95 MyCView.GClientData = theClientData;
96 SetWindow (theWindow);
99 // =======================================================================
100 // function : SetWindow
102 // =======================================================================
103 void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow)
109 else if (IsDefined())
111 Visual3d_ViewDefinitionError::Raise ("Window already defined");
114 MyWindow = theWindow;
115 MyCView.WsId = MyCView.ViewId;
116 MyCView.DefWindow.IsDefined = 1;
118 const Handle(WNT_Window) aWin = Handle(WNT_Window)::DownCast (theWindow);
119 MyCView.DefWindow.XWindow = (HWND )(aWin->HWindow());
120 MyCView.DefWindow.XParentWindow = (HWND )(aWin->HParentWindow());
121 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
122 const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
123 MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
124 MyCView.DefWindow.XParentWindow = NULL;
125 //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
126 #elif defined(__ANDROID__)
129 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
130 MyCView.DefWindow.XWindow = aWin->XWindow();
131 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
134 Standard_Integer Width, Height;
135 theWindow->Size (Width, Height);
136 MyCView.DefWindow.dx = float(Width);
137 MyCView.DefWindow.dy = float(Height);
139 Standard_Real R, G, B;
140 MyBackground = MyWindow->Background ();
141 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
142 MyCView.DefWindow.Background.r = float (R);
143 MyCView.DefWindow.Background.g = float (G);
144 MyCView.DefWindow.Background.b = float (B);
147 if (!myGraphicDriver->View (MyCView))
149 Visual3d_ViewDefinitionError::Raise ("Association failed");
152 MyGradientBackground = MyWindow->GradientBackground();
153 SetGradientBackground(MyGradientBackground,1);
155 Standard_Boolean AWait = Standard_False; // => immediate update
156 myGraphicDriver->SetVisualisation (MyCView);
157 myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
158 myGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn());
159 myGraphicDriver->ClipLimit (MyCView, AWait);
160 myGraphicDriver->Environment (MyCView);
162 // Make view manager z layer list consistent with the view's list.
163 myViewManager->InstallZLayers (this);
165 // Update planses of model clipping
168 // Update light sources
171 // Association view-window does not cause the display
172 // of structures that can be displayed in the new view.
173 // In fact, association view-window is done, but the
174 // display is produced only if the view is activated (Activate).
178 // =======================================================================
181 // =======================================================================
182 Handle(Aspect_Window) Visual3d_View::Window() const
186 Visual3d_ViewDefinitionError::Raise ("Window not defined");
191 // =======================================================================
192 // function : IsDefined
194 // =======================================================================
195 Standard_Boolean Visual3d_View::IsDefined() const
197 return MyCView.DefWindow.IsDefined != 0;
200 // =======================================================================
201 // function : IsDeleted
203 // =======================================================================
204 Standard_Boolean Visual3d_View::IsDeleted() const
206 return MyCView.IsDeleted != 0;
209 // =======================================================================
210 // function : Destroy
212 // =======================================================================
213 void Visual3d_View::Destroy()
215 // Since myViewManager can be already destroyed,
216 // avoid attempts to access it in SetBackground()
217 myViewManager = NULL;
221 // =======================================================================
224 // =======================================================================
225 void Visual3d_View::Remove()
233 myStructsToCompute.Clear();
234 myStructsComputed .Clear();
235 myStructsDisplayed.Clear();
237 Aspect_GradientBackground aBlackGrad;
238 SetBackground (Aspect_Background (Quantity_NOC_BLACK));
239 SetGradientBackground (aBlackGrad, Standard_False);
241 if (myViewManager != NULL)
243 myViewManager->UnIdentification (MyCView.ViewId);
246 myGraphicDriver->RemoveView (MyCView);
249 MyCView.IsDeleted = 1;
250 MyCView.DefWindow.IsDefined = 0;
255 // =======================================================================
256 // function : Resized
258 // =======================================================================
259 void Visual3d_View::Resized()
265 else if (!IsDefined())
267 Visual3d_ViewDefinitionError::Raise ("Window not defined");
269 MyWindow->DoResize();
273 // =======================================================================
274 // function : SetRatio
276 // =======================================================================
277 void Visual3d_View::SetRatio()
284 const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
285 myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
287 Standard_Integer aWidth, aHeight;
288 MyWindow->Size (aWidth, aHeight);
289 if (aWidth > 0 && aHeight > 0)
291 Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight;
293 MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
294 MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
296 myGraphicDriver->RatioWindow (MyCView);
298 // Update camera aspect
299 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
300 if (!aCamera.IsNull())
302 aCamera->SetAspect (aRatio);
305 if (!myDefaultCamera.IsNull())
307 myDefaultCamera->SetAspect (aRatio);
311 myViewManager->SetUpdateMode (anUpdateMode);
312 Update (anUpdateMode);
315 // =======================================================================
316 // function : UpdateLights
318 // =======================================================================
319 void Visual3d_View::UpdateLights()
327 if (MyContext.Model() == Visual3d_TOM_NONE)
329 // activate only a white ambient light
330 Graphic3d_CLight aCLight;
331 aCLight.Type = Visual3d_TOLS_AMBIENT;
332 aCLight.IsHeadlight = Standard_False;
333 aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
335 MyCView.Context.NbActiveLight = 1;
336 MyCView.Context.ActiveLight = &aCLight;
337 myGraphicDriver->SetLight (MyCView);
338 MyCView.Context.ActiveLight = NULL;
342 MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
343 myGraphicDriver->InquireLightLimit());
344 if (MyCView.Context.NbActiveLight < 1)
346 myGraphicDriver->SetLight (MyCView);
350 // parcing of light sources
351 MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
352 for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
354 MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
356 myGraphicDriver->SetLight (MyCView);
357 delete[] MyCView.Context.ActiveLight;
358 MyCView.Context.ActiveLight = NULL;
361 // =======================================================================
362 // function : UpdatePlanes
364 // =======================================================================
365 void Visual3d_View::UpdatePlanes()
367 MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
368 if (IsDeleted() || !IsDefined())
373 myGraphicDriver->SetClipPlanes (MyCView);
376 // =======================================================================
377 // function : SetBackground
379 // =======================================================================
380 void Visual3d_View::SetBackground (const Aspect_Background& theBack)
386 else if (!IsDefined())
388 Visual3d_ViewDefinitionError::Raise ("Window not defined");
391 // At this level, only GL can update the background.
392 // It is not necessary to call MyWindow->SetBackground (ABack); as
393 // this method starts update of window background by X
394 // (if the windowing is X)
396 Standard_Real R, G, B;
397 MyBackground = theBack;
398 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
399 MyCView.DefWindow.Background.r = float (R);
400 MyCView.DefWindow.Background.g = float (G);
401 MyCView.DefWindow.Background.b = float (B);
403 myGraphicDriver->Background (MyCView);
405 if (myViewManager != NULL)
407 Update (myViewManager->UpdateMode());
411 // =======================================================================
412 // function : SetGradientBackground
414 // =======================================================================
415 void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
416 const Standard_Boolean theToUpdate)
422 else if (!IsDefined())
424 Visual3d_ViewDefinitionError::Raise ("Window not defined");
427 MyGradientBackground = theBack;
428 Quantity_Color aCol1, aCol2;
429 MyGradientBackground.Colors (aCol1, aCol2);
430 myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
434 Update (Aspect_TOU_ASAP);
436 else if (myViewManager != NULL)
438 Update (myViewManager->UpdateMode());
442 // =======================================================================
443 // function : SetBackgroundImage
445 // =======================================================================
446 void Visual3d_View::SetBackgroundImage (const Standard_CString theFileName,
447 const Aspect_FillMethod theFillStyle,
448 const Standard_Boolean theToUpdate)
456 Visual3d_ViewDefinitionError::Raise ("Window not defined");
459 myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
461 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
464 // =======================================================================
465 // function : SetBgImageStyle
467 // =======================================================================
468 void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
469 const Standard_Boolean theToUpdate)
477 Visual3d_ViewDefinitionError::Raise ("Window not defined");
480 myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
482 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
485 // =======================================================================
486 // function : Background
488 // =======================================================================
489 Aspect_Background Visual3d_View::Background() const
494 // =======================================================================
495 // function : SetBgGradientStyle
497 // =======================================================================
498 void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
499 const Standard_Boolean theToUpdate)
505 else if (!IsDefined())
507 Visual3d_ViewDefinitionError::Raise ("Window not defined");
510 myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
512 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
515 // =======================================================================
516 // function : GradientBackground
518 // =======================================================================
519 Aspect_GradientBackground Visual3d_View::GradientBackground() const
521 return MyGradientBackground;
524 // =======================================================================
525 // function : DefaultCamera
527 // =======================================================================
528 const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
530 return myDefaultCamera;
533 // =======================================================================
536 // =======================================================================
537 const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
539 return MyCView.Context.Camera;
542 // =======================================================================
543 // function : SetCamera
545 // =======================================================================
546 void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
548 MyCView.Context.Camera = theCamera;
550 myGraphicDriver->SetCamera (MyCView);
552 Update (myViewManager->UpdateMode());
555 // =======================================================================
556 // function : SetViewOrientationDefault
558 // =======================================================================
559 void Visual3d_View::SetViewOrientationDefault()
561 if (myDefaultCamera.IsNull())
563 myDefaultCamera = new Graphic3d_Camera();
566 myDefaultCamera->CopyOrientationData (MyCView.Context.Camera);
569 // =======================================================================
570 // function : ViewOrientationReset
572 // =======================================================================
573 void Visual3d_View::ViewOrientationReset()
580 if (!myDefaultCamera.IsNull())
582 MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
585 Update (myViewManager->UpdateMode());
588 // =======================================================================
589 // function : SetViewMappingDefault
591 // =======================================================================
592 void Visual3d_View::SetViewMappingDefault()
594 if (myDefaultCamera.IsNull())
596 myDefaultCamera = new Graphic3d_Camera();
598 myDefaultCamera->CopyMappingData (MyCView.Context.Camera);
601 // =======================================================================
602 // function : ViewMappingReset
604 // =======================================================================
605 void Visual3d_View::ViewMappingReset()
612 if (!myDefaultCamera.IsNull())
614 MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
617 Update (myViewManager->UpdateMode());
620 // =======================================================================
621 // function : SetContext
623 // =======================================================================
624 void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
631 // To manage display only in case of change of visualisation mode
632 const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
633 const bool isModelChanged = theViewCtx.Model() != MyContext.Model();
635 // To manage antialiasing only in case of change
636 const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
637 const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
639 // To manage the depth cueing only in case of change
640 const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
641 const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
643 const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
644 const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
645 const Standard_Real aDepthCueingBackPlaneOld = MyContext.DepthCueingBackPlane();
646 const Standard_Real aDepthCueingBackPlaneNew = theViewCtx.DepthCueingBackPlane();
648 // To manage the Zclipping only in case of change
649 const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
650 const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
651 const Standard_Boolean aBackZClippingModeOld = MyContext.BackZClippingIsOn();
652 const Standard_Boolean aBackZClippingModeNew = theViewCtx.BackZClippingIsOn();
654 const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
655 const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
656 const Standard_Real aZClippingBackPlaneOld = MyContext.ZClippingBackPlane();
657 const Standard_Real aZClippingBackPlaneNew = theViewCtx.ZClippingBackPlane();
659 const bool isTextEnvChanged = theViewCtx.TextureEnv() != MyContext.TextureEnv();
660 const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
662 MyContext = theViewCtx;
666 Standard_Boolean toWait = Standard_False; // => immediate update
669 // management of visualization modes and types of shading.
673 myGraphicDriver->SetVisualisation (MyCView);
676 // management of antialiasing
677 if (anAliasingModeOld != anAliasingModeNew)
679 myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
682 // management of depth_cueing
683 if (aDepthCueingModeOld != aDepthCueingModeNew
684 || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
685 || aDepthCueingBackPlaneOld != aDepthCueingBackPlaneNew)
687 if (aDepthCueingModeNew
688 && aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
690 Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
692 myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
695 // management of Zclipping
696 if (aFrontZClippingModeOld != aFrontZClippingModeNew
697 || aBackZClippingModeOld != aBackZClippingModeNew
698 || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
699 || aZClippingBackPlaneOld != aZClippingBackPlaneNew)
701 if (aBackZClippingModeNew
702 && aFrontZClippingModeNew
703 && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
705 Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
708 myGraphicDriver->ClipLimit (MyCView, toWait);
711 // management of textures
713 || isSurfDetailChanged)
715 myGraphicDriver->Environment (MyCView);
718 UpdatePlanes(); // Update of planes of model clipping
719 UpdateLights(); // Update of light sources
722 if (isVisModeChanged)
724 // Change of context =>
725 // Remove structures that cannot be displayed in the new visualisation mode.
726 // It is not necessary to warn ViewManager as this structure should not disappear from
727 // the list of structures displayed in it.
728 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
729 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
731 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
732 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
733 if (anAnswer == Visual3d_TOA_NO
734 || anAnswer == Visual3d_TOA_COMPUTE)
736 aStructs.Append (aStruct);
739 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
741 Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
745 // Change of context =>
746 // Display structures that can be displayed with the new visualisation mode.
747 // All structures with status Displayed are removed from the ViewManager
748 // and displayed in the view directly, if the structure is not already
749 // displayed and if the view accepts it in its context.
750 Graphic3d_MapOfStructure aMapDisplayed;
751 myViewManager->DisplayedStructures (aMapDisplayed);
752 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
754 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
755 if (IsDisplayed (aStruct))
760 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
761 if (anAnswer == Visual3d_TOA_YES
762 || anAnswer == Visual3d_TOA_COMPUTE)
764 aStructs.Append (aStruct);
768 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
770 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
774 Update (myViewManager->UpdateMode());
777 // =======================================================================
778 // function : Context
780 // =======================================================================
781 const Visual3d_ContextView& Visual3d_View::Context() const
786 // =======================================================================
787 // function : DisplayedStructures
789 // =======================================================================
790 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
797 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
799 theStructures.Add (aStructIter.Key());
803 // =======================================================================
804 // function : Activate
806 // =======================================================================
807 void Visual3d_View::Activate()
813 else if (!IsDefined())
815 Visual3d_ViewDefinitionError::Raise ("Window not defined");
820 myGraphicDriver->ActivateView (MyCView);
821 myGraphicDriver->Background (MyCView);
822 myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
826 // Activation of a new view =>
827 // Display structures that can be displayed in this new view.
828 // All structures with status
829 // Displayed in ViewManager are returned and displayed in
830 // the view directly, if the structure is not already
831 // displayed and if the view accepts it in its context.
832 Graphic3d_MapOfStructure aDisplayedStructs;
833 myViewManager->DisplayedStructures (aDisplayedStructs);
834 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
836 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
837 if (IsDisplayed (aStruct))
842 // If the structure can be displayed in the new context of the view, it is displayed.
843 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
844 if (anAnswer == Visual3d_TOA_YES
845 || anAnswer == Visual3d_TOA_COMPUTE)
847 Display (aStruct, Aspect_TOU_WAIT);
852 // If the activation/desactivation of ZBuffer should be automatic
853 // depending on the presence or absence of facets.
854 if (myViewManager->ZBufferAuto())
856 const Standard_Boolean containsFacet = ContainsFacet();
857 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
858 if (containsFacet && !hasZBuffer)
860 SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
862 else if (!containsFacet && hasZBuffer)
864 SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
868 Update (myViewManager->UpdateMode());
871 // =======================================================================
872 // function : IsActive
874 // =======================================================================
875 Standard_Boolean Visual3d_View::IsActive() const
881 // =======================================================================
882 // function : Deactivate
884 // =======================================================================
885 void Visual3d_View::Deactivate()
891 else if (!IsDefined())
893 Visual3d_ViewDefinitionError::Raise ("Window not defined");
898 myGraphicDriver->DeactivateView (MyCView);
900 // Deactivation of a view =>
901 // Removal of structures displayed in this view.
902 // All structures with status
903 // Displayed in ViewManager are returned and removed from
904 // the view directly, if the structure is not already
905 // displayed and if the view accepts it in its context.
906 Graphic3d_MapOfStructure aDisplayedStructs;
907 myViewManager->DisplayedStructures (aDisplayedStructs);
908 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
910 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
911 if (IsDisplayed (aStruct))
916 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
917 if (anAnswer == Visual3d_TOA_YES
918 || anAnswer == Visual3d_TOA_COMPUTE)
920 Erase (aStruct, Aspect_TOU_WAIT);
924 Update (myViewManager->UpdateMode());
925 MyCView.Active = 0; // No action currently possible in the view
929 // =======================================================================
932 // =======================================================================
933 void Visual3d_View::Redraw()
935 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
938 // =======================================================================
941 // =======================================================================
942 void Visual3d_View::Redraw (const Standard_Integer theX,
943 const Standard_Integer theY,
944 const Standard_Integer theWidth,
945 const Standard_Integer theHeight)
947 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
948 theX, theY, theWidth, theHeight);
951 // =======================================================================
954 // =======================================================================
955 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
956 const Handle(Visual3d_Layer)& theOverLayer)
958 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
961 // =======================================================================
964 // =======================================================================
965 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
966 const Handle(Visual3d_Layer)& theOverLayer,
967 const Standard_Integer theX,
968 const Standard_Integer theY,
969 const Standard_Integer theWidth,
970 const Standard_Integer theHeight)
975 || !MyWindow->IsMapped())
980 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
981 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
982 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
983 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
985 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
987 if (myGraphicDriver->IsDeviceLost())
989 myViewManager->RecomputeStructures();
990 myViewManager->RecomputeStructures (myImmediateStructures);
991 myGraphicDriver->ResetDeviceLostFlag();
994 // set up Z buffer state before redrawing
995 if (myViewManager->ZBufferAuto())
997 const Standard_Boolean hasFacet = ContainsFacet();
998 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
999 // if the view contains facets and if ZBuffer is not active
1000 if (hasFacet && !hasZBuffer)
1002 SetZBufferActivity (1);
1004 // if the view contains only facets and if ZBuffer is active
1005 if (!hasFacet && hasZBuffer)
1007 SetZBufferActivity (0);
1011 if (myStructuresUpdated)
1014 myStructuresUpdated = Standard_False;
1017 myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
1018 if (!myGraphicDriver->IsDeviceLost())
1025 // =======================================================================
1026 // function : RedrawImmediate
1028 // =======================================================================
1029 void Visual3d_View::RedrawImmediate()
1031 RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
1034 // =======================================================================
1035 // function : RedrawImmediate
1037 // =======================================================================
1038 void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
1039 const Handle(Visual3d_Layer)& theOverLayer)
1044 || !MyWindow->IsMapped())
1049 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
1050 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
1051 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
1052 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
1053 myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
1056 // =======================================================================
1057 // function : Invalidate
1059 // =======================================================================
1060 void Visual3d_View::Invalidate()
1062 myGraphicDriver->Invalidate (MyCView);
1065 // =======================================================================
1066 // function : Update
1068 // =======================================================================
1069 void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
1071 myStructuresUpdated = Standard_True;
1072 if (theUpdateMode == Aspect_TOU_ASAP)
1075 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
1079 // =======================================================================
1080 // function : Update
1082 // =======================================================================
1083 void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
1084 const Handle(Visual3d_Layer)& theOverLayer)
1087 myStructuresUpdated = Standard_True;
1088 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
1091 // ========================================================================
1092 // function : SetAutoZFitMode
1094 // ========================================================================
1095 void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
1096 const Standard_Real theScaleFactor)
1098 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
1099 myAutoZFitScaleFactor = theScaleFactor;
1100 myAutoZFitIsOn = theIsOn;
1103 // ========================================================================
1104 // function : AutoZFitMode
1106 // ========================================================================
1107 Standard_Boolean Visual3d_View::AutoZFitMode() const
1109 return myAutoZFitIsOn;
1112 // ========================================================================
1113 // function : AutoZFitScaleFactor
1115 // ========================================================================
1116 Standard_Real Visual3d_View::AutoZFitScaleFactor() const
1118 return myAutoZFitScaleFactor;
1121 // ========================================================================
1122 // function : AutoZFit
1124 // ========================================================================
1125 void Visual3d_View::AutoZFit()
1127 if (!AutoZFitMode())
1132 ZFitAll (myAutoZFitScaleFactor);
1135 // ========================================================================
1136 // function : ZFitAll
1138 // ========================================================================
1139 void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
1141 Standard_Real aMinMax[6]; // applicative min max boundaries
1142 MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
1143 aMinMax[3], aMinMax[4], aMinMax[5],
1146 Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
1147 MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1148 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
1152 Bnd_Box aGraphicBox;
1154 aMinMaxBox.Update (aMinMax[0], aMinMax[1], aMinMax[2],
1155 aMinMax[3], aMinMax[4], aMinMax[5]);
1157 aGraphicBox.Update (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1158 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]);
1160 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1161 aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
1164 // ========================================================================
1165 // function : AcceptDisplay
1167 // ========================================================================
1168 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
1170 const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
1171 switch (theStruct->Visual())
1173 case Graphic3d_TOS_ALL:
1175 return Visual3d_TOA_YES; // The structure accepts any type of view
1177 case Graphic3d_TOS_SHADING:
1179 return ViewType == Visual3d_TOV_SHADING
1183 case Graphic3d_TOS_WIREFRAME:
1185 return ViewType == Visual3d_TOV_WIREFRAME
1189 case Graphic3d_TOS_COMPUTED:
1191 return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
1192 ? Visual3d_TOA_COMPUTE
1196 return Visual3d_TOA_NO;
1199 // ========================================================================
1200 // function : ChangeDisplayPriority
1202 // ========================================================================
1203 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
1204 const Standard_Integer /*theOldPriority*/,
1205 const Standard_Integer theNewPriority)
1210 || !IsDisplayed (theStruct))
1215 if (!myIsInComputedMode)
1217 myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
1221 const Standard_Integer anIndex = IsComputed (theStruct);
1222 const Graphic3d_CStructure& aCStruct = anIndex != 0
1223 ? *(myStructsComputed.Value (anIndex)->CStructure())
1224 : *theStruct->CStructure();
1225 myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
1228 // ========================================================================
1231 // ========================================================================
1232 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
1233 const Standard_Boolean theWithDestruction)
1235 const Standard_Integer anIndex = IsComputed (theStruct);
1238 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
1239 aCompStruct->GraphicClear (theWithDestruction);
1240 aCompStruct->SetHLRValidation (Standard_False);
1244 // ========================================================================
1245 // function : Connect
1247 // ========================================================================
1248 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
1249 const Handle(Graphic3d_Structure)& theDaughter)
1251 Standard_Integer anIndexM = IsComputed (theMother);
1252 Standard_Integer anIndexD = IsComputed (theDaughter);
1256 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1257 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1258 aStructM->GraphicConnect (aStructD);
1262 // ========================================================================
1263 // function : Disconnect
1265 // ========================================================================
1266 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
1267 const Handle(Graphic3d_Structure)& theDaughter)
1269 Standard_Integer anIndexM = IsComputed (theMother);
1270 Standard_Integer anIndexD = IsComputed (theDaughter);
1274 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1275 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1276 aStructM->GraphicDisconnect (aStructD);
1280 // ========================================================================
1281 // function : DisplayImmediate
1283 // ========================================================================
1284 Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
1285 const Standard_Boolean theIsSingleView)
1287 if (!myImmediateStructures.Add (theStructure))
1289 return Standard_False;
1292 if (theIsSingleView)
1294 Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
1296 for (int i=1;i<=aViews->Length();i++)
1298 if (aViews->Value(i).Access() != this)
1300 aViews->Value(i)->EraseImmediate (theStructure);
1305 myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
1306 return Standard_True;
1309 // ========================================================================
1310 // function : EraseImmediate
1312 // ========================================================================
1313 Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
1315 const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
1318 myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
1324 // ========================================================================
1325 // function : ClearImmediate
1327 // ========================================================================
1328 Standard_Boolean Visual3d_View::ClearImmediate()
1330 if (myImmediateStructures.IsEmpty())
1332 return Standard_False;
1335 for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
1337 myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
1339 myImmediateStructures.Clear();
1340 return Standard_True;
1343 // ========================================================================
1344 // function : Display
1346 // ========================================================================
1347 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
1349 Display (theStruct, myViewManager->UpdateMode());
1352 // ========================================================================
1353 // function : Display
1355 // ========================================================================
1356 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
1357 const Aspect_TypeOfUpdate theUpdateMode)
1366 // If Display on a structure present in the list of calculated structures while it is not
1367 // or more, of calculated type =>
1368 // - removes it as well as the associated old computed
1369 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
1370 Standard_Integer anIndex = IsComputed (theStruct);
1372 && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
1374 myStructsToCompute.Remove (anIndex);
1375 myStructsComputed .Remove (anIndex);
1379 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1380 if (anAnswer == Visual3d_TOA_NO)
1385 if (!ComputedMode())
1387 anAnswer = Visual3d_TOA_YES;
1390 if (anAnswer == Visual3d_TOA_YES)
1392 if (IsDisplayed (theStruct))
1397 theStruct->CalculateBoundBox();
1398 myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
1399 myStructsDisplayed.Add (theStruct);
1400 Update (theUpdateMode);
1403 else if (anAnswer != Visual3d_TOA_COMPUTE)
1410 // Already computed, is COMPUTED still valid?
1411 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
1412 if (anOldStruct->HLRValidation())
1414 // Case COMPUTED valid
1416 if (!IsDisplayed (theStruct))
1418 myStructsDisplayed.Add (theStruct);
1419 myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
1420 Update (theUpdateMode);
1426 // Case COMPUTED invalid
1427 // Is there another valid representation?
1428 // Find in the sequence of already calculated structures
1429 // 1/ Structure having the same Owner as <AStructure>
1430 // 2/ That is not <AStructure>
1431 // 3/ The COMPUTED which of is valid
1432 const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
1435 // Case of COMPUTED invalid, WITH a valid of replacement
1437 if (!IsDisplayed (theStruct))
1439 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
1440 myStructsComputed.SetValue (anIndex, aNewStruct);
1441 myStructsDisplayed.Add (theStruct);
1442 myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
1443 Update (theUpdateMode);
1449 // Case COMPUTED invalid, WITHOUT a valid of replacement
1450 // COMPUTED is removed if displayed
1451 if (IsDisplayed (theStruct))
1453 myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
1459 // Compute + Validation
1460 Handle(Graphic3d_Structure) aStruct;
1461 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1462 theStruct->Transform (aTrsf);
1465 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1466 for (Standard_Integer ii = 0; ii <= 3; ++ii)
1468 for (Standard_Integer jj = 0; jj <= 3; ++jj)
1470 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
1474 aStruct = myStructsComputed.Value (anIndex);
1475 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1476 if (theStruct->IsTransformed())
1478 theStruct->Compute (this, aTrsf, aStruct);
1482 theStruct->Compute (this, aStruct);
1487 aStruct = theStruct->IsTransformed()
1488 ? theStruct->Compute (this, aTrsf)
1489 : theStruct->Compute (this);
1492 aStruct->SetHLRValidation (Standard_True);
1494 // TOCOMPUTE and COMPUTED associated to sequences are added
1495 myStructsToCompute.Append (theStruct);
1496 myStructsComputed .Append (aStruct);
1498 // The previous are removed if necessary
1501 myStructsToCompute.Remove (anIndex);
1502 myStructsComputed .Remove (anIndex);
1505 // Of which type will be the computed?
1506 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1507 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1508 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1509 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
1510 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1511 if (!toComputeShading && !toComputeWireframe)
1513 anAnswer = Visual3d_TOA_NO;
1517 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
1518 anAnswer = AcceptDisplay (aStruct);
1521 if (theStruct->IsHighlighted())
1523 aStruct->SetHighlightColor (theStruct->HighlightColor());
1524 aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1527 // It is displayed only if the calculated structure
1528 // has a proper type corresponding to the one of the view.
1529 if (anAnswer != Visual3d_TOA_NO)
1531 if (!IsDisplayed (theStruct))
1533 myStructsDisplayed.Add (theStruct);
1535 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
1536 Update (theUpdateMode);
1540 // ========================================================================
1543 // ========================================================================
1544 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
1548 Erase (theStruct, myViewManager->UpdateMode());
1552 // ========================================================================
1555 // ========================================================================
1556 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
1557 const Aspect_TypeOfUpdate theUpdateMode)
1560 || !IsDisplayed (theStruct))
1565 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1566 if (!ComputedMode())
1568 anAnswer = Visual3d_TOA_YES;
1571 if (anAnswer != Visual3d_TOA_COMPUTE)
1573 myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
1575 else if (anAnswer == Visual3d_TOA_COMPUTE
1576 && myIsInComputedMode)
1578 const Standard_Integer anIndex = IsComputed (theStruct);
1581 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1582 myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
1585 myStructsDisplayed.Remove (theStruct);
1586 Update (theUpdateMode);
1589 // ========================================================================
1590 // function : Highlight
1592 // ========================================================================
1593 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
1594 const Aspect_TypeOfHighlightMethod theMethod)
1596 const Standard_Integer anIndex = IsComputed (theStruct);
1599 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1600 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1601 aCompStruct->GraphicHighlight (theMethod);
1605 // ========================================================================
1606 // function : SetTransform
1608 // ========================================================================
1609 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
1610 const TColStd_Array2OfReal& theTrsf)
1612 const Standard_Integer anIndex = IsComputed (theStruct);
1615 // Test is somewhat light !
1616 // trsf is transferred only if it is :
1619 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
1620 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
1621 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
1623 ReCompute (theStruct);
1627 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1628 aCompStruct->GraphicTransform (theTrsf);
1632 theStruct->CalculateBoundBox();
1633 if (!theStruct->IsMutable()
1634 && !theStruct->CStructure()->IsForHighlight
1635 && !theStruct->CStructure()->IsInfinite)
1637 const Standard_Integer aLayerId = theStruct->GetZLayer();
1638 myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
1642 // ========================================================================
1643 // function : UnHighlight
1645 // ========================================================================
1646 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
1648 Standard_Integer anIndex = IsComputed (theStruct);
1651 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1652 aCompStruct->GraphicUnHighlight();
1656 // ========================================================================
1657 // function : IsComputed
1659 // ========================================================================
1660 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
1662 const Standard_Integer aStructId = theStruct->Identification();
1663 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1664 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1666 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1667 if (aStruct->Identification() == aStructId)
1675 // ========================================================================
1676 // function : IsDisplayed
1678 // ========================================================================
1679 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
1682 && myStructsDisplayed.Contains (theStruct);
1685 // ========================================================================
1686 // function : ContainsFacet
1688 // ========================================================================
1689 Standard_Boolean Visual3d_View::ContainsFacet() const
1691 return ContainsFacet (myStructsDisplayed);
1694 // ========================================================================
1695 // function : ContainsFacet
1697 // ========================================================================
1698 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
1700 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
1702 if (aStructIter.Key()->ContainsFacet())
1704 return Standard_True;
1707 return Standard_False;
1710 // ========================================================================
1711 // function : MinMaxValues
1713 // ========================================================================
1714 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1715 Standard_Real& theYMin,
1716 Standard_Real& theZMin,
1717 Standard_Real& theXMax,
1718 Standard_Real& theYMax,
1719 Standard_Real& theZMax,
1720 const Standard_Boolean theToIgnoreInfiniteFlag) const
1722 MinMaxValues (myStructsDisplayed,
1723 theXMin, theYMin, theZMin,
1724 theXMax, theYMax, theZMax,
1725 theToIgnoreInfiniteFlag);
1728 // ========================================================================
1729 // function : MinMaxValues
1731 // ========================================================================
1732 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1733 Standard_Real& theXMin,
1734 Standard_Real& theYMin,
1735 Standard_Real& theZMin,
1736 Standard_Real& theXMax,
1737 Standard_Real& theYMax,
1738 Standard_Real& theZMax,
1739 const Standard_Boolean theToIgnoreInfiniteFlag) const
1741 if (theSet.IsEmpty ())
1743 theXMin = RealFirst();
1744 theYMin = RealFirst();
1745 theZMin = RealFirst();
1747 theXMax = RealLast();
1748 theYMax = RealLast();
1749 theZMax = RealLast();
1753 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1754 Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet);
1756 theXMin = RealLast();
1757 theYMin = RealLast();
1758 theZMin = RealLast();
1760 theXMax = RealFirst ();
1761 theYMax = RealFirst ();
1762 theZMax = RealFirst ();
1764 for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next())
1766 const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
1768 if (!aStructure->IsVisible())
1771 if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
1773 //XMin, YMin .... ZMax are initialized by means of infinite line data
1774 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, Standard_False);
1775 if (aXm != RealFirst() && aXm < theXMin)
1779 if (aYm != RealFirst() && aYm < theYMin)
1783 if (aZm != RealFirst() && aZm < theZMin)
1787 if (aXM != RealLast() && aXM > theXMax)
1791 if (aYM != RealLast() && aYM > theYMax)
1795 if (aZM != RealLast() && aZM > theZMax)
1801 // Only non-empty and non-infinite structures
1802 // are taken into account for calculation of MinMax
1803 if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty())
1805 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
1807 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
1808 //"FitAll" operation ignores object with transform persitence parameter
1809 if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None )
1811 theXMin = Min (aXm, theXMin);
1812 theYMin = Min (aYm, theYMin);
1813 theZMin = Min (aZm, theZMin);
1814 theXMax = Max (aXM, theXMax);
1815 theYMax = Max (aYM, theYMax);
1816 theZMax = Max (aZM, theZMax);
1821 // The following cases are relevant
1822 // For exemple if all structures are empty or infinite
1823 if (theXMax < theXMin) { aXm = theXMin; theXMin = theXMax; theXMax = aXm; }
1824 if (theYMax < theYMin) { aYm = theYMin; theYMin = theYMax; theYMax = aYm; }
1825 if (theZMax < theZMin) { aZm = theZMin; theZMin = theZMax; theZMax = aZm; }
1829 // ========================================================================
1830 // function : MinMaxValues
1832 // ========================================================================
1833 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1834 Standard_Real& theYMin,
1835 Standard_Real& theXMax,
1836 Standard_Real& theYMax,
1837 const Standard_Boolean theToIgnoreInfiniteFlag) const
1839 MinMaxValues (myStructsDisplayed,
1842 theToIgnoreInfiniteFlag);
1845 // ========================================================================
1846 // function : MinMaxValues
1848 // ========================================================================
1849 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1850 Standard_Real& theXMin,
1851 Standard_Real& theYMin,
1852 Standard_Real& theXMax,
1853 Standard_Real& theYMax,
1854 const Standard_Boolean theToIgnoreInfiniteFlag) const
1856 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1857 Standard_Real aXp, aYp, aZp;
1859 MinMaxValues (theSet, aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
1861 Projects (aXm, aYm, aZm, aXp, aYp, aZp);
1865 Projects (aXM, aYM, aZM, aXp, aYp, aZp);
1869 if (theXMax < theXMin) { aXp = theXMax; theXMax = theXMin; theXMin = aXp; }
1870 if (theYMax < theYMin) { aYp = theYMax; theYMax = theYMin; theYMin = aYp; }
1873 // =======================================================================
1874 // function : NumberOfDisplayedStructures
1876 // =======================================================================
1877 Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
1879 return myStructsDisplayed.Extent();
1882 // =======================================================================
1883 // function : Projects
1885 // =======================================================================
1886 void Visual3d_View::Projects (const Standard_Real theX,
1887 const Standard_Real theY,
1888 const Standard_Real theZ,
1889 Standard_Real& thePX,
1890 Standard_Real& thePY,
1891 Standard_Real& thePZ) const
1893 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1895 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1896 Standard_Real aXSize = aViewSpaceDimensions.X();
1897 Standard_Real aYSize = aViewSpaceDimensions.Y();
1898 Standard_Real aZSize = aViewSpaceDimensions.Z();
1900 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1902 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1903 thePX = aPoint.X() * aXSize * 0.5;
1904 thePY = aPoint.Y() * aYSize * 0.5;
1905 thePZ = aPoint.Z() * aZSize * 0.5;
1908 // =======================================================================
1909 // function : Identification
1911 // =======================================================================
1912 Standard_Integer Visual3d_View::Identification() const
1914 return MyCView.ViewId;
1917 // =======================================================================
1918 // function : ZBufferIsActivated
1920 // =======================================================================
1921 Standard_Boolean Visual3d_View::ZBufferIsActivated() const
1927 return Standard_False;
1930 if (MyCView.Context.ZBufferActivity == -1)
1932 // not forced by the programmer => depends on the type of visualisation
1933 return MyContext.Visualization () == Visual3d_TOV_SHADING;
1935 return MyCView.Context.ZBufferActivity != 0; // 0 or 1 => forced by the programmer
1938 // =======================================================================
1939 // function : SetTransparency
1941 // =======================================================================
1942 void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
1951 myGraphicDriver->Transparency (MyCView, theActivity);
1954 // =======================================================================
1955 // function : SetZBufferActivity
1957 // =======================================================================
1958 void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
1961 || MyCView.Context.ZBufferActivity == theActivity
1968 MyCView.Context.ZBufferActivity = theActivity;
1969 myGraphicDriver->SetVisualisation (MyCView);
1972 // =======================================================================
1973 // function : UpdateView
1975 // =======================================================================
1976 void Visual3d_View::UpdateView()
1978 MyCView.Context.Aliasing = MyContext.AliasingIsOn();
1979 MyCView.Context.BackZClipping = MyContext.BackZClippingIsOn();
1980 MyCView.Context.FrontZClipping = MyContext.FrontZClippingIsOn();
1981 MyCView.Context.DepthCueing = MyContext.DepthCueingIsOn();
1983 MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
1984 MyCView.Context.ZClipBackPlane = float (MyContext.ZClippingBackPlane());
1985 MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
1986 MyCView.Context.DepthBackPlane = float (MyContext.DepthCueingBackPlane());
1988 MyCView.Context.Model = MyContext.Model();
1989 MyCView.Context.Visualization = MyContext.Visualization();
1991 MyCView.Context.TextureEnv = MyContext.TextureEnv();
1992 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
1995 // =======================================================================
1996 // function : Compute
1998 // =======================================================================
1999 void Visual3d_View::Compute()
2001 // force HLRValidation to False on all structures calculated in the view
2002 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
2003 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
2005 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
2008 if (!ComputedMode())
2013 // Change of orientation or of projection type =>
2014 // Remove structures that were calculated for the previous orientation.
2015 // Recalculation of new structures.
2016 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
2017 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2019 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
2020 if (anAnswer == Visual3d_TOA_COMPUTE)
2022 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
2026 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
2028 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
2032 // =======================================================================
2033 // function : ReCompute
2035 // =======================================================================
2036 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
2038 theStruct->CalculateBoundBox();
2039 if (!theStruct->IsMutable()
2040 && !theStruct->CStructure()->IsForHighlight
2041 && !theStruct->CStructure()->IsInfinite)
2043 const Standard_Integer aLayerId = theStruct->DisplayPriority();
2044 myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
2051 || !MyWindow->IsMapped()
2052 || !theStruct->IsDisplayed())
2057 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
2058 if (anAnswer != Visual3d_TOA_COMPUTE)
2063 const Standard_Integer anIndex = IsComputed (theStruct);
2069 // compute + validation
2070 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
2071 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
2073 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
2075 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
2078 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2079 theStruct->Transform (aTrsf);
2081 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
2082 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
2083 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
2084 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
2085 : theStruct->Compute (this, aCompStruct);
2086 aCompStruct->SetHLRValidation (Standard_True);
2088 // of which type will be the computed?
2089 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2090 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2091 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2092 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2093 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2094 if (toComputeWireframe)
2096 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2098 else if (toComputeShading)
2100 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2103 if (theStruct->IsHighlighted())
2105 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
2106 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2109 // The previous calculation is removed and the new one is dislayed
2110 myGraphicDriver->EraseStructure (MyCView, *aCompStructOld->CStructure());
2111 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
2113 // why not just replace existing items?
2114 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
2115 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
2117 // hlhsr and the new associated compute are added
2118 myStructsToCompute.Append (theStruct);
2119 myStructsComputed .Append (aCompStruct);
2121 // hlhsr and the new associated compute are removed
2122 myStructsToCompute.Remove (anIndex);
2123 myStructsComputed .Remove (anIndex);
2126 // =======================================================================
2127 // function : GraphicDriver
2129 // =======================================================================
2130 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
2132 return myGraphicDriver;
2135 // =======================================================================
2136 // function : HaveTheSameOwner
2138 // =======================================================================
2139 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
2141 // Find in the sequence of already calculated structures
2142 // 1/ Structure with the same Owner as <AStructure>
2143 // 2/ Which is not <AStructure>
2144 // 3/ COMPUTED which of is valid
2145 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
2146 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
2148 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
2149 if (aStructToComp->Owner() == theStruct->Owner()
2150 && aStructToComp->Identification() != theStruct->Identification())
2152 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
2153 if (aStructComp->HLRValidation())
2162 // =======================================================================
2165 // =======================================================================
2166 Standard_Address Visual3d_View::CView() const
2168 return Standard_Address (&MyCView);
2171 // =======================================================================
2172 // function : ZBufferTriedronSetup
2174 // =======================================================================
2175 void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
2176 const Quantity_NameOfColor theYColor,
2177 const Quantity_NameOfColor theZColor,
2178 const Standard_Real theSizeRatio,
2179 const Standard_Real theAxisDiametr,
2180 const Standard_Integer theNbFacettes)
2182 myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
2183 theSizeRatio, theAxisDiametr, theNbFacettes);
2186 // =======================================================================
2187 // function : TriedronDisplay
2189 // =======================================================================
2190 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
2191 const Quantity_NameOfColor theColor,
2192 const Standard_Real theScale,
2193 const Standard_Boolean theAsWireframe)
2195 myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
2198 // =======================================================================
2199 // function : TriedronErase
2201 // =======================================================================
2202 void Visual3d_View::TriedronErase()
2204 myGraphicDriver->TriedronErase (MyCView);
2207 // =======================================================================
2208 // function : TriedronEcho
2210 // =======================================================================
2211 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
2213 myGraphicDriver->TriedronEcho (MyCView, theType);
2216 static Standard_Boolean checkFloat (const Standard_Real theValue)
2218 return theValue > -FLT_MAX
2219 && theValue < FLT_MAX;
2222 static void SetMinMaxValuesCallback (Visual3d_View* theView)
2224 Graphic3d_Vec3d aMin, aMax;
2225 theView->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2226 aMax.x(), aMax.y(), aMax.z());
2227 if (checkFloat (aMin.x()) && checkFloat (aMin.y()) && checkFloat (aMin.z())
2228 && checkFloat (aMax.x()) && checkFloat (aMax.y()) && checkFloat (aMax.z()))
2230 const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
2231 aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.x(), (Standard_ShortReal )aMin.y(), (Standard_ShortReal )aMin.z(),
2232 (Standard_ShortReal )aMax.x(), (Standard_ShortReal )aMax.y(), (Standard_ShortReal )aMax.z());
2236 // =======================================================================
2237 // function : GetGraduatedTrihedron
2239 // =======================================================================
2240 Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
2241 TCollection_ExtendedString& theYName,
2242 TCollection_ExtendedString& theZName,
2243 Standard_Boolean& theToDrawXName,
2244 Standard_Boolean& theToDrawYName,
2245 Standard_Boolean& theToDrawZName,
2246 Standard_Boolean& theToDrawXValues,
2247 Standard_Boolean& theToDrawYValues,
2248 Standard_Boolean& theToDrawZValues,
2249 Standard_Boolean& theToDrawGrid,
2250 Standard_Boolean& theToDrawAxes,
2251 Standard_Integer& theNbX,
2252 Standard_Integer& theNbY,
2253 Standard_Integer& theNbZ,
2254 Standard_Integer& theXOffset,
2255 Standard_Integer& theYOffset,
2256 Standard_Integer& theZOffset,
2257 Standard_Integer& theXAxisOffset,
2258 Standard_Integer& theYAxisOffset,
2259 Standard_Integer& theZAxisOffset,
2260 Standard_Boolean& theToDrawXTickMarks,
2261 Standard_Boolean& theToDrawYTickMarks,
2262 Standard_Boolean& theToDrawZTickMarks,
2263 Standard_Integer& theXTickMarkLength,
2264 Standard_Integer& theYTickMarkLength,
2265 Standard_Integer& theZTickMarkLength,
2266 Quantity_Color& theGridColor,
2267 Quantity_Color& theXNameColor,
2268 Quantity_Color& theYNameColor,
2269 Quantity_Color& theZNameColor,
2270 Quantity_Color& theXColor,
2271 Quantity_Color& theYColor,
2272 Quantity_Color& theZColor,
2273 TCollection_AsciiString& theFontOfNames,
2274 Font_FontAspect& theStyleOfNames,
2275 Standard_Integer& theSizeOfNames,
2276 TCollection_AsciiString& theFontOfValues,
2277 Font_FontAspect& theStyleOfValues,
2278 Standard_Integer& theSizeOfValues) const
2280 if (!MyGTrihedron.ptrVisual3dView)
2282 return Standard_False;
2285 theXName = MyGTrihedron.xname;
2286 theYName = MyGTrihedron.yname;
2287 theZName = MyGTrihedron.zname;
2288 theToDrawXName = MyGTrihedron.xdrawname;
2289 theToDrawYName = MyGTrihedron.ydrawname;
2290 theToDrawZName = MyGTrihedron.zdrawname;
2291 theToDrawXValues = MyGTrihedron.xdrawvalues;
2292 theToDrawYValues = MyGTrihedron.ydrawvalues;
2293 theToDrawZValues = MyGTrihedron.zdrawvalues;
2294 theToDrawGrid = MyGTrihedron.drawgrid;
2295 theToDrawAxes = MyGTrihedron.drawaxes;
2296 theNbX = MyGTrihedron.nbx;
2297 theNbY = MyGTrihedron.nby;
2298 theNbZ = MyGTrihedron.nbz;
2299 theXOffset = MyGTrihedron.xoffset;
2300 theYOffset = MyGTrihedron.yoffset;
2301 theZOffset = MyGTrihedron.zoffset;
2302 theXAxisOffset = MyGTrihedron.xaxisoffset;
2303 theYAxisOffset = MyGTrihedron.yaxisoffset;
2304 theZAxisOffset = MyGTrihedron.zaxisoffset;
2305 theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
2306 theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
2307 theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
2308 theXTickMarkLength = MyGTrihedron.xtickmarklength;
2309 theYTickMarkLength = MyGTrihedron.ytickmarklength;
2310 theZTickMarkLength = MyGTrihedron.ztickmarklength;
2311 theGridColor = MyGTrihedron.gridcolor;
2312 theXNameColor = MyGTrihedron.xnamecolor;
2313 theYNameColor = MyGTrihedron.ynamecolor;
2314 theZNameColor = MyGTrihedron.znamecolor;
2315 theXColor = MyGTrihedron.xcolor;
2316 theYColor = MyGTrihedron.ycolor;
2317 theZColor = MyGTrihedron.zcolor;
2318 theFontOfNames = MyGTrihedron.fontOfNames;
2319 theStyleOfNames = MyGTrihedron.styleOfNames;
2320 theSizeOfNames = MyGTrihedron.sizeOfNames;
2321 theFontOfValues = MyGTrihedron.fontOfValues;
2322 theStyleOfValues = MyGTrihedron.styleOfValues;
2323 theSizeOfValues = MyGTrihedron.sizeOfValues;
2324 return Standard_True;
2327 // =======================================================================
2328 // function : GraduatedTrihedronDisplay
2330 // =======================================================================
2331 void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
2332 const TCollection_ExtendedString& theYName,
2333 const TCollection_ExtendedString& theZName,
2334 const Standard_Boolean theToDrawXName,
2335 const Standard_Boolean theToDrawYName,
2336 const Standard_Boolean theToDrawZName,
2337 const Standard_Boolean theToDrawXValues,
2338 const Standard_Boolean theToDrawYValues,
2339 const Standard_Boolean theToDrawZValues,
2340 const Standard_Boolean theToDrawGrid,
2341 const Standard_Boolean theToDrawAxes,
2342 const Standard_Integer theNbX,
2343 const Standard_Integer theNbY,
2344 const Standard_Integer theNbZ,
2345 const Standard_Integer theXOffset,
2346 const Standard_Integer theYOffset,
2347 const Standard_Integer theZOffset,
2348 const Standard_Integer theXAxisOffset,
2349 const Standard_Integer theYAxisOffset,
2350 const Standard_Integer theZAxisOffset,
2351 const Standard_Boolean theToDrawXTickMarks,
2352 const Standard_Boolean theToDrawYTickMarks,
2353 const Standard_Boolean theToDrawZTickMarks,
2354 const Standard_Integer theXTickMarkLength,
2355 const Standard_Integer theYTickMarkLength,
2356 const Standard_Integer theZTickMarkLength,
2357 const Quantity_Color& theGridColor,
2358 const Quantity_Color& theXNameColor,
2359 const Quantity_Color& theYNameColor,
2360 const Quantity_Color& theZNameColor,
2361 const Quantity_Color& theXColor,
2362 const Quantity_Color& theYColor,
2363 const Quantity_Color& theZColor,
2364 const TCollection_AsciiString& theFontOfNames,
2365 const Font_FontAspect theStyleOfNames,
2366 const Standard_Integer theSizeOfNames,
2367 const TCollection_AsciiString& theFontOfValues,
2368 const Font_FontAspect theStyleOfValues,
2369 const Standard_Integer theSizeOfValues)
2371 MyGTrihedron.xname = theXName;
2372 MyGTrihedron.yname = theYName;
2373 MyGTrihedron.zname = theZName;
2374 MyGTrihedron.xdrawname = theToDrawXName;
2375 MyGTrihedron.ydrawname = theToDrawYName;
2376 MyGTrihedron.zdrawname = theToDrawZName;
2377 MyGTrihedron.xdrawvalues = theToDrawXValues;
2378 MyGTrihedron.ydrawvalues = theToDrawYValues;
2379 MyGTrihedron.zdrawvalues = theToDrawZValues;
2380 MyGTrihedron.drawgrid = theToDrawGrid;
2381 MyGTrihedron.drawaxes = theToDrawAxes;
2382 MyGTrihedron.nbx = theNbX;
2383 MyGTrihedron.nby = theNbY;
2384 MyGTrihedron.nbz = theNbZ;
2385 MyGTrihedron.xoffset = theXOffset;
2386 MyGTrihedron.yoffset = theYOffset;
2387 MyGTrihedron.zoffset = theZOffset;
2388 MyGTrihedron.xaxisoffset = theXAxisOffset;
2389 MyGTrihedron.yaxisoffset = theYAxisOffset;
2390 MyGTrihedron.zaxisoffset = theZAxisOffset;
2391 MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
2392 MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
2393 MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
2394 MyGTrihedron.xtickmarklength = theXTickMarkLength;
2395 MyGTrihedron.ytickmarklength = theYTickMarkLength;
2396 MyGTrihedron.ztickmarklength = theZTickMarkLength;
2397 MyGTrihedron.gridcolor = theGridColor;
2398 MyGTrihedron.xnamecolor = theXNameColor;
2399 MyGTrihedron.ynamecolor = theYNameColor;
2400 MyGTrihedron.znamecolor = theZNameColor;
2401 MyGTrihedron.xcolor = theXColor;
2402 MyGTrihedron.ycolor = theYColor;
2403 MyGTrihedron.zcolor = theZColor;
2404 MyGTrihedron.fontOfNames = theFontOfNames;
2405 MyGTrihedron.styleOfNames = theStyleOfNames;
2406 MyGTrihedron.sizeOfNames = theSizeOfNames;
2407 MyGTrihedron.fontOfValues = theFontOfValues;
2408 MyGTrihedron.styleOfValues = theStyleOfValues;
2409 MyGTrihedron.sizeOfValues = theSizeOfValues;
2411 MyGTrihedron.ptrVisual3dView = this;
2412 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
2413 myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
2416 // =======================================================================
2417 // function : GraduatedTrihedronErase
2419 // =======================================================================
2420 void Visual3d_View::GraduatedTrihedronErase()
2422 MyGTrihedron.ptrVisual3dView = NULL;
2423 myGraphicDriver->GraduatedTrihedronErase (MyCView);
2426 // =======================================================================
2427 // function : UnderLayer
2429 // =======================================================================
2430 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
2432 return myViewManager->UnderLayer();
2435 // =======================================================================
2436 // function : OverLayer
2438 // =======================================================================
2439 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
2441 return myViewManager->OverLayer();
2444 // =======================================================================
2445 // function : LightLimit
2447 // =======================================================================
2448 Standard_Integer Visual3d_View::LightLimit() const
2450 return myGraphicDriver->InquireLightLimit();
2453 // =======================================================================
2454 // function : PlaneLimit
2456 // =======================================================================
2457 Standard_Integer Visual3d_View::PlaneLimit() const
2459 return myGraphicDriver->InquirePlaneLimit();
2462 // =======================================================================
2463 // function : ViewManager
2465 // =======================================================================
2466 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
2468 return myViewManager;
2471 // =======================================================================
2472 // function : SetComputedMode
2474 // =======================================================================
2475 void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
2477 if (( theMode && myIsInComputedMode)
2478 || (!theMode && !myIsInComputedMode))
2483 myIsInComputedMode = theMode;
2484 if (!myIsInComputedMode)
2486 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2488 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2489 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2490 if (anAnswer != Visual3d_TOA_COMPUTE)
2495 const Standard_Integer anIndex = IsComputed (aStruct);
2498 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
2499 myGraphicDriver->EraseStructure (MyCView, *aStructComp->CStructure());
2500 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
2506 for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
2508 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
2509 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2510 if (anAnswer != Visual3d_TOA_COMPUTE)
2515 const Standard_Integer anIndex = IsComputed (aStruct);
2518 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2519 myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
2521 Display (aStruct, Aspect_TOU_WAIT);
2522 if (aStruct->IsHighlighted())
2524 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
2525 if (!aCompStruct->IsHighlighted())
2527 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2528 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2534 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2535 aStruct->Transform (aTrsf);
2536 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
2537 aCompStruct->SetHLRValidation (Standard_True);
2539 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2540 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2541 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2542 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2543 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2544 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2545 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2547 if (aStruct->IsHighlighted())
2549 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2550 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2553 Standard_Boolean hasResult = Standard_False;
2554 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
2555 const Standard_Integer aStructId = aStruct->Identification();
2556 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
2558 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
2560 hasResult = Standard_True;
2561 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
2568 myStructsToCompute.Append (aStruct);
2569 myStructsComputed .Append (aCompStruct);
2572 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2573 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
2576 Update (myViewManager->UpdateMode());
2579 // =======================================================================
2580 // function : ComputedMode
2582 // =======================================================================
2583 Standard_Boolean Visual3d_View::ComputedMode() const
2585 return myIsInComputedMode;
2588 // =======================================================================
2589 // function : SetBackFacingModel
2591 // =======================================================================
2592 void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
2597 case Visual3d_TOBM_AUTOMATIC:
2598 MyCView.Backfacing = 0;
2600 case Visual3d_TOBM_FORCE:
2601 MyCView.Backfacing = 1;
2603 case Visual3d_TOBM_DISABLE:
2604 MyCView.Backfacing = -1;
2607 myGraphicDriver->SetBackFacingModel (MyCView);
2610 // =======================================================================
2611 // function : BackFacingModel
2613 // =======================================================================
2614 Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
2616 switch (MyCView.Backfacing)
2618 case 0: return Visual3d_TOBM_AUTOMATIC;
2619 case 1: return Visual3d_TOBM_FORCE;
2621 return Visual3d_TOBM_DISABLE;
2624 // =======================================================================
2625 // function : EnableDepthTest
2627 // =======================================================================
2628 void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
2630 myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
2633 // =======================================================================
2634 // function : IsDepthTestEnabled
2636 // =======================================================================
2637 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
2639 return myGraphicDriver->IsDepthTestEnabled (MyCView);
2642 // =======================================================================
2643 // function : ReadDepths
2645 // =======================================================================
2646 void Visual3d_View::ReadDepths (const Standard_Integer theX,
2647 const Standard_Integer theY,
2648 const Standard_Integer theWidth,
2649 const Standard_Integer theHeight,
2650 const Standard_Address theBuffer) const
2652 myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
2655 // =======================================================================
2656 // function : FBOCreate
2658 // =======================================================================
2659 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
2660 const Standard_Integer theHeight)
2662 return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
2665 // =======================================================================
2666 // function : FBORelease
2668 // =======================================================================
2669 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
2671 myGraphicDriver->FBORelease( MyCView, theFBOPtr );
2674 // =======================================================================
2675 // function : FBOGetDimensions
2677 // =======================================================================
2678 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
2679 Standard_Integer& theWidth, Standard_Integer& theHeight,
2680 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
2682 myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
2683 theWidth, theHeight,
2684 theWidthMax, theHeightMax );
2687 // =======================================================================
2688 // function : FBOChangeViewport
2690 // =======================================================================
2691 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
2692 const Standard_Integer theWidth, const Standard_Integer theHeight)
2694 myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
2695 theWidth, theHeight );
2698 // =======================================================================
2699 // function : BufferDump
2701 // =======================================================================
2702 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
2703 const Graphic3d_BufferType& theBufferType)
2705 return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
2708 // =======================================================================
2709 // function : EnableGLLight
2711 // =======================================================================
2712 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
2714 myGraphicDriver->SetGLLightEnabled( MyCView, enable );
2717 // =======================================================================
2718 // function : IsGLLightEnabled
2720 // =======================================================================
2721 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
2723 return myGraphicDriver->IsGLLightEnabled( MyCView );
2726 // =======================================================================
2727 // function : Export
2729 // =======================================================================
2730 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
2731 const Graphic3d_ExportFormat theFormat,
2732 const Graphic3d_SortType theSortType,
2733 const Standard_Real thePrecision,
2734 const Standard_Address theProgressBarFunc,
2735 const Standard_Address theProgressObject) const
2737 Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
2738 Handle(Visual3d_Layer) anOverLayer = myViewManager->OverLayer();
2740 Aspect_CLayer2d anOverCLayer;
2741 Aspect_CLayer2d anUnderCLayer;
2742 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2744 if (!anOverLayer.IsNull())
2745 anOverCLayer = anOverLayer->CLayer();
2746 if (!anUnderLayer.IsNull())
2747 anUnderCLayer = anUnderLayer->CLayer();
2749 Standard_Integer aWidth, aHeight;
2750 Window()->Size (aWidth, aHeight);
2752 return myGraphicDriver->Export (theFileName, theFormat, theSortType,
2753 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
2754 thePrecision, theProgressBarFunc, theProgressObject);
2757 // =======================================================================
2758 // function : SetZLayerSettings
2760 // =======================================================================
2761 void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
2762 const Graphic3d_ZLayerSettings& theSettings)
2764 myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
2767 // =======================================================================
2768 // function : AddZLayer
2770 // =======================================================================
2771 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
2773 myGraphicDriver->AddZLayer (MyCView, theLayerId);
2776 // =======================================================================
2777 // function : RemoveZLayer
2779 // =======================================================================
2780 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
2782 myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
2785 // =======================================================================
2786 // function : ChangeZLayer
2788 // =======================================================================
2789 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
2790 const Standard_Integer theLayerId)
2792 myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
2795 // =======================================================================
2798 // =======================================================================
2799 Standard_Boolean Visual3d_View::Print (const Aspect_Handle thePrintDC,
2800 const Standard_Boolean theToShowBackground,
2801 const Standard_CString theFilename,
2802 const Aspect_PrintAlgo thePrintAlgorithm,
2803 const Standard_Real theScaleFactor) const
2805 return Print (myViewManager->UnderLayer(),
2806 myViewManager->OverLayer(),
2807 thePrintDC, theToShowBackground,
2808 theFilename, thePrintAlgorithm,
2812 // =======================================================================
2815 // =======================================================================
2816 Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
2817 const Handle(Visual3d_Layer)& theOverLayer,
2818 const Aspect_Handle thePrintDC,
2819 const Standard_Boolean theToShowBackground,
2820 const Standard_CString theFilename,
2821 const Aspect_PrintAlgo thePrintAlgorithm,
2822 const Standard_Real theScaleFactor) const
2827 || !MyWindow->IsMapped())
2829 return Standard_False;
2832 Aspect_CLayer2d anOverCLayer;
2833 Aspect_CLayer2d anUnderCLayer;
2834 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2835 if (!theOverLayer.IsNull()) anOverCLayer = theOverLayer->CLayer();
2836 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
2837 return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
2838 thePrintDC, theToShowBackground, theFilename,
2839 thePrintAlgorithm, theScaleFactor);