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 WNT_WindowData* aWinData = (WNT_WindowData* )GetWindowLongPtr ((HWND )(aWin->HWindow()), GWLP_USERDATA);
122 aWinData->WNT_WDriver_Ptr = (void* )this;
123 aWinData->WNT_VMgr = myViewManager;
124 #elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
125 const Handle(Cocoa_Window) aWin = Handle(Cocoa_Window)::DownCast (theWindow);
126 MyCView.DefWindow.XWindow = (Aspect_Drawable )aWin->HView();
127 MyCView.DefWindow.XParentWindow = NULL;
128 //MyCView.DefWindow.XParentWindow = aWin->HParentWindow();
130 const Handle(Xw_Window) aWin = Handle(Xw_Window)::DownCast (theWindow);
131 MyCView.DefWindow.XWindow = aWin->XWindow();
132 //MyCView.DefWindow.XParentWindow = aWin->XParentWindow();
135 Standard_Integer Width, Height;
136 theWindow->Size (Width, Height);
137 MyCView.DefWindow.dx = float(Width);
138 MyCView.DefWindow.dy = float(Height);
140 Standard_Real R, G, B;
141 MyBackground = MyWindow->Background ();
142 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
143 MyCView.DefWindow.Background.r = float (R);
144 MyCView.DefWindow.Background.g = float (G);
145 MyCView.DefWindow.Background.b = float (B);
148 if (!myGraphicDriver->View (MyCView))
150 Visual3d_ViewDefinitionError::Raise ("Association failed");
153 MyGradientBackground = MyWindow->GradientBackground();
154 SetGradientBackground(MyGradientBackground,1);
156 Standard_Boolean AWait = Standard_False; // => immediate update
157 myGraphicDriver->SetVisualisation (MyCView);
158 myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
159 myGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn());
160 myGraphicDriver->ClipLimit (MyCView, AWait);
161 myGraphicDriver->Environment (MyCView);
163 // Make view manager z layer list consistent with the view's list.
164 myViewManager->InstallZLayers (this);
166 // Update planses of model clipping
169 // Update light sources
172 // Association view-window does not cause the display
173 // of structures that can be displayed in the new view.
174 // In fact, association view-window is done, but the
175 // display is produced only if the view is activated (Activate).
179 // =======================================================================
182 // =======================================================================
183 Handle(Aspect_Window) Visual3d_View::Window() const
187 Visual3d_ViewDefinitionError::Raise ("Window not defined");
192 // =======================================================================
193 // function : IsDefined
195 // =======================================================================
196 Standard_Boolean Visual3d_View::IsDefined() const
198 return MyCView.DefWindow.IsDefined != 0;
201 // =======================================================================
202 // function : IsDeleted
204 // =======================================================================
205 Standard_Boolean Visual3d_View::IsDeleted() const
207 return MyCView.IsDeleted != 0;
210 // =======================================================================
211 // function : Destroy
213 // =======================================================================
214 void Visual3d_View::Destroy()
216 // Since myViewManager can be already destroyed,
217 // avoid attempts to access it in SetBackground()
218 myViewManager = NULL;
222 // =======================================================================
225 // =======================================================================
226 void Visual3d_View::Remove()
234 myStructsToCompute.Clear();
235 myStructsComputed .Clear();
236 myStructsDisplayed.Clear();
238 Aspect_GradientBackground aBlackGrad;
239 SetBackground (Aspect_Background (Quantity_NOC_BLACK));
240 SetGradientBackground (aBlackGrad, Standard_False);
242 if (myViewManager != NULL)
244 myViewManager->UnIdentification (MyCView.ViewId);
247 myGraphicDriver->RemoveView (MyCView);
250 MyCView.IsDeleted = 1;
251 MyCView.DefWindow.IsDefined = 0;
256 // =======================================================================
257 // function : Resized
259 // =======================================================================
260 void Visual3d_View::Resized()
266 else if (!IsDefined())
268 Visual3d_ViewDefinitionError::Raise ("Window not defined");
270 MyWindow->DoResize();
274 // =======================================================================
275 // function : SetRatio
277 // =======================================================================
278 void Visual3d_View::SetRatio()
285 const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
286 myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
288 Standard_Integer aWidth, aHeight;
289 MyWindow->Size (aWidth, aHeight);
290 if (aWidth > 0 && aHeight > 0)
292 Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight;
294 MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
295 MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
297 myGraphicDriver->RatioWindow (MyCView);
299 // Update camera aspect
300 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
301 if (!aCamera.IsNull())
303 aCamera->SetAspect (aRatio);
306 if (!myDefaultCamera.IsNull())
308 myDefaultCamera->SetAspect (aRatio);
312 myViewManager->SetUpdateMode (anUpdateMode);
313 Update (anUpdateMode);
316 // =======================================================================
317 // function : UpdateLights
319 // =======================================================================
320 void Visual3d_View::UpdateLights()
328 if (MyContext.Model() == Visual3d_TOM_NONE)
330 // activate only a white ambient light
331 Graphic3d_CLight aCLight;
332 aCLight.Type = Visual3d_TOLS_AMBIENT;
333 aCLight.IsHeadlight = Standard_False;
334 aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
336 MyCView.Context.NbActiveLight = 1;
337 MyCView.Context.ActiveLight = &aCLight;
338 myGraphicDriver->SetLight (MyCView);
339 MyCView.Context.ActiveLight = NULL;
343 MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
344 myGraphicDriver->InquireLightLimit());
345 if (MyCView.Context.NbActiveLight < 1)
347 myGraphicDriver->SetLight (MyCView);
351 // parcing of light sources
352 MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
353 for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
355 MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
357 myGraphicDriver->SetLight (MyCView);
358 delete[] MyCView.Context.ActiveLight;
359 MyCView.Context.ActiveLight = NULL;
362 // =======================================================================
363 // function : UpdatePlanes
365 // =======================================================================
366 void Visual3d_View::UpdatePlanes()
368 MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
369 if (IsDeleted() || !IsDefined())
374 myGraphicDriver->SetClipPlanes (MyCView);
377 // =======================================================================
378 // function : SetBackground
380 // =======================================================================
381 void Visual3d_View::SetBackground (const Aspect_Background& theBack)
387 else if (!IsDefined())
389 Visual3d_ViewDefinitionError::Raise ("Window not defined");
392 // At this level, only GL can update the background.
393 // It is not necessary to call MyWindow->SetBackground (ABack); as
394 // this method starts update of window background by X
395 // (if the windowing is X)
397 Standard_Real R, G, B;
398 MyBackground = theBack;
399 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
400 MyCView.DefWindow.Background.r = float (R);
401 MyCView.DefWindow.Background.g = float (G);
402 MyCView.DefWindow.Background.b = float (B);
404 myGraphicDriver->Background (MyCView);
406 if (myViewManager != NULL)
408 Update (myViewManager->UpdateMode());
412 // =======================================================================
413 // function : SetGradientBackground
415 // =======================================================================
416 void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
417 const Standard_Boolean theToUpdate)
423 else if (!IsDefined())
425 Visual3d_ViewDefinitionError::Raise ("Window not defined");
428 MyGradientBackground = theBack;
429 Quantity_Color aCol1, aCol2;
430 MyGradientBackground.Colors (aCol1, aCol2);
431 myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
435 Update (Aspect_TOU_ASAP);
437 else if (myViewManager != NULL)
439 Update (myViewManager->UpdateMode());
443 // =======================================================================
444 // function : SetBackgroundImage
446 // =======================================================================
447 void Visual3d_View::SetBackgroundImage (const Standard_CString theFileName,
448 const Aspect_FillMethod theFillStyle,
449 const Standard_Boolean theToUpdate)
457 Visual3d_ViewDefinitionError::Raise ("Window not defined");
460 myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
462 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
465 // =======================================================================
466 // function : SetBgImageStyle
468 // =======================================================================
469 void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
470 const Standard_Boolean theToUpdate)
478 Visual3d_ViewDefinitionError::Raise ("Window not defined");
481 myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
483 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
486 // =======================================================================
487 // function : Background
489 // =======================================================================
490 Aspect_Background Visual3d_View::Background() const
495 // =======================================================================
496 // function : SetBgGradientStyle
498 // =======================================================================
499 void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
500 const Standard_Boolean theToUpdate)
506 else if (!IsDefined())
508 Visual3d_ViewDefinitionError::Raise ("Window not defined");
511 myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
513 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
516 // =======================================================================
517 // function : GradientBackground
519 // =======================================================================
520 Aspect_GradientBackground Visual3d_View::GradientBackground() const
522 return MyGradientBackground;
525 // =======================================================================
526 // function : DefaultCamera
528 // =======================================================================
529 const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
531 return myDefaultCamera;
534 // =======================================================================
537 // =======================================================================
538 const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
540 return MyCView.Context.Camera;
543 // =======================================================================
544 // function : SetCamera
546 // =======================================================================
547 void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
549 MyCView.Context.Camera = theCamera;
551 myGraphicDriver->SetCamera (MyCView);
553 Update (myViewManager->UpdateMode());
556 // =======================================================================
557 // function : SetViewOrientationDefault
559 // =======================================================================
560 void Visual3d_View::SetViewOrientationDefault()
562 if (myDefaultCamera.IsNull())
564 myDefaultCamera = new Graphic3d_Camera();
567 myDefaultCamera->CopyOrientationData (MyCView.Context.Camera);
570 // =======================================================================
571 // function : ViewOrientationReset
573 // =======================================================================
574 void Visual3d_View::ViewOrientationReset()
581 if (!myDefaultCamera.IsNull())
583 MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
586 Update (myViewManager->UpdateMode());
589 // =======================================================================
590 // function : SetViewMappingDefault
592 // =======================================================================
593 void Visual3d_View::SetViewMappingDefault()
595 if (myDefaultCamera.IsNull())
597 myDefaultCamera = new Graphic3d_Camera();
599 myDefaultCamera->CopyMappingData (MyCView.Context.Camera);
602 // =======================================================================
603 // function : ViewMappingReset
605 // =======================================================================
606 void Visual3d_View::ViewMappingReset()
613 if (!myDefaultCamera.IsNull())
615 MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
618 Update (myViewManager->UpdateMode());
621 // =======================================================================
622 // function : SetContext
624 // =======================================================================
625 void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
632 // To manage display only in case of change of visualisation mode
633 const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
634 const bool isModelChanged = theViewCtx.Model() != MyContext.Model();
636 // To manage antialiasing only in case of change
637 const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
638 const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
640 // To manage the depth cueing only in case of change
641 const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
642 const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
644 const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
645 const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
646 const Standard_Real aDepthCueingBackPlaneOld = MyContext.DepthCueingBackPlane();
647 const Standard_Real aDepthCueingBackPlaneNew = theViewCtx.DepthCueingBackPlane();
649 // To manage the Zclipping only in case of change
650 const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
651 const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
652 const Standard_Boolean aBackZClippingModeOld = MyContext.BackZClippingIsOn();
653 const Standard_Boolean aBackZClippingModeNew = theViewCtx.BackZClippingIsOn();
655 const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
656 const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
657 const Standard_Real aZClippingBackPlaneOld = MyContext.ZClippingBackPlane();
658 const Standard_Real aZClippingBackPlaneNew = theViewCtx.ZClippingBackPlane();
660 const bool isTextEnvChanged = theViewCtx.TextureEnv() != MyContext.TextureEnv();
661 const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
663 MyContext = theViewCtx;
667 Standard_Boolean toWait = Standard_False; // => immediate update
670 // management of visualization modes and types of shading.
674 myGraphicDriver->SetVisualisation (MyCView);
677 // management of antialiasing
678 if (anAliasingModeOld != anAliasingModeNew)
680 myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
683 // management of depth_cueing
684 if (aDepthCueingModeOld != aDepthCueingModeNew
685 || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
686 || aDepthCueingBackPlaneOld != aDepthCueingBackPlaneNew)
688 if (aDepthCueingModeNew
689 && aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
691 Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
693 myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
696 // management of Zclipping
697 if (aFrontZClippingModeOld != aFrontZClippingModeNew
698 || aBackZClippingModeOld != aBackZClippingModeNew
699 || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
700 || aZClippingBackPlaneOld != aZClippingBackPlaneNew)
702 if (aBackZClippingModeNew
703 && aFrontZClippingModeNew
704 && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
706 Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
709 myGraphicDriver->ClipLimit (MyCView, toWait);
712 // management of textures
714 || isSurfDetailChanged)
716 myGraphicDriver->Environment (MyCView);
719 UpdatePlanes(); // Update of planes of model clipping
720 UpdateLights(); // Update of light sources
723 if (isVisModeChanged)
725 // Change of context =>
726 // Remove structures that cannot be displayed in the new visualisation mode.
727 // It is not necessary to warn ViewManager as this structure should not disappear from
728 // the list of structures displayed in it.
729 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
730 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
732 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
733 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
734 if (anAnswer == Visual3d_TOA_NO
735 || anAnswer == Visual3d_TOA_COMPUTE)
737 aStructs.Append (aStruct);
740 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
742 Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
746 // Change of context =>
747 // Display structures that can be displayed with the new visualisation mode.
748 // All structures with status Displayed are removed from the ViewManager
749 // and displayed in the view directly, if the structure is not already
750 // displayed and if the view accepts it in its context.
751 Graphic3d_MapOfStructure aMapDisplayed;
752 myViewManager->DisplayedStructures (aMapDisplayed);
753 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
755 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
756 if (IsDisplayed (aStruct))
761 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
762 if (anAnswer == Visual3d_TOA_YES
763 || anAnswer == Visual3d_TOA_COMPUTE)
765 aStructs.Append (aStruct);
769 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
771 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
775 Update (myViewManager->UpdateMode());
778 // =======================================================================
779 // function : Context
781 // =======================================================================
782 const Visual3d_ContextView& Visual3d_View::Context() const
787 // =======================================================================
788 // function : DisplayedStructures
790 // =======================================================================
791 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
798 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
800 theStructures.Add (aStructIter.Key());
804 // =======================================================================
805 // function : Activate
807 // =======================================================================
808 void Visual3d_View::Activate()
814 else if (!IsDefined())
816 Visual3d_ViewDefinitionError::Raise ("Window not defined");
821 myGraphicDriver->ActivateView (MyCView);
822 myGraphicDriver->Background (MyCView);
823 myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
827 // Activation of a new view =>
828 // Display structures that can be displayed in this new view.
829 // All structures with status
830 // Displayed in ViewManager are returned and displayed in
831 // the view directly, if the structure is not already
832 // displayed and if the view accepts it in its context.
833 Graphic3d_MapOfStructure aDisplayedStructs;
834 myViewManager->DisplayedStructures (aDisplayedStructs);
835 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
837 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
838 if (IsDisplayed (aStruct))
843 // If the structure can be displayed in the new context of the view, it is displayed.
844 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
845 if (anAnswer == Visual3d_TOA_YES
846 || anAnswer == Visual3d_TOA_COMPUTE)
848 Display (aStruct, Aspect_TOU_WAIT);
853 // If the activation/desactivation of ZBuffer should be automatic
854 // depending on the presence or absence of facets.
855 if (myViewManager->ZBufferAuto())
857 const Standard_Boolean containsFacet = ContainsFacet();
858 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
859 if (containsFacet && !hasZBuffer)
861 SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
863 else if (!containsFacet && hasZBuffer)
865 SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
869 Update (myViewManager->UpdateMode());
872 // =======================================================================
873 // function : IsActive
875 // =======================================================================
876 Standard_Boolean Visual3d_View::IsActive() const
882 // =======================================================================
883 // function : Deactivate
885 // =======================================================================
886 void Visual3d_View::Deactivate()
892 else if (!IsDefined())
894 Visual3d_ViewDefinitionError::Raise ("Window not defined");
899 myGraphicDriver->DeactivateView (MyCView);
901 // Deactivation of a view =>
902 // Removal of structures displayed in this view.
903 // All structures with status
904 // Displayed in ViewManager are returned and removed from
905 // the view directly, if the structure is not already
906 // displayed and if the view accepts it in its context.
907 Graphic3d_MapOfStructure aDisplayedStructs;
908 myViewManager->DisplayedStructures (aDisplayedStructs);
909 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
911 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
912 if (IsDisplayed (aStruct))
917 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
918 if (anAnswer == Visual3d_TOA_YES
919 || anAnswer == Visual3d_TOA_COMPUTE)
921 Erase (aStruct, Aspect_TOU_WAIT);
925 Update (myViewManager->UpdateMode());
926 MyCView.Active = 0; // No action currently possible in the view
930 // =======================================================================
933 // =======================================================================
934 void Visual3d_View::Redraw()
936 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
939 // =======================================================================
942 // =======================================================================
943 void Visual3d_View::Redraw (const Standard_Integer theX,
944 const Standard_Integer theY,
945 const Standard_Integer theWidth,
946 const Standard_Integer theHeight)
948 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
949 theX, theY, theWidth, theHeight);
952 // =======================================================================
955 // =======================================================================
956 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
957 const Handle(Visual3d_Layer)& theOverLayer)
959 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
962 // =======================================================================
965 // =======================================================================
966 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
967 const Handle(Visual3d_Layer)& theOverLayer,
968 const Standard_Integer theX,
969 const Standard_Integer theY,
970 const Standard_Integer theWidth,
971 const Standard_Integer theHeight)
976 || !MyWindow->IsMapped())
981 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
982 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
983 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
984 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
986 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
988 if (myGraphicDriver->IsDeviceLost())
990 myViewManager->RecomputeStructures();
991 myViewManager->RecomputeStructures (myImmediateStructures);
992 myGraphicDriver->ResetDeviceLostFlag();
995 // set up Z buffer state before redrawing
996 if (myViewManager->ZBufferAuto())
998 const Standard_Boolean hasFacet = ContainsFacet();
999 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
1000 // if the view contains facets and if ZBuffer is not active
1001 if (hasFacet && !hasZBuffer)
1003 SetZBufferActivity (1);
1005 // if the view contains only facets and if ZBuffer is active
1006 if (!hasFacet && hasZBuffer)
1008 SetZBufferActivity (0);
1012 if (myStructuresUpdated)
1015 myStructuresUpdated = Standard_False;
1018 myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
1019 if (!myGraphicDriver->IsDeviceLost())
1026 // =======================================================================
1027 // function : RedrawImmediate
1029 // =======================================================================
1030 void Visual3d_View::RedrawImmediate()
1032 RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
1035 // =======================================================================
1036 // function : RedrawImmediate
1038 // =======================================================================
1039 void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
1040 const Handle(Visual3d_Layer)& theOverLayer)
1045 || !MyWindow->IsMapped())
1050 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
1051 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
1052 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
1053 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
1054 myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
1057 // =======================================================================
1058 // function : Invalidate
1060 // =======================================================================
1061 void Visual3d_View::Invalidate()
1063 myGraphicDriver->Invalidate (MyCView);
1066 // =======================================================================
1067 // function : Update
1069 // =======================================================================
1070 void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
1072 myStructuresUpdated = Standard_True;
1073 if (theUpdateMode == Aspect_TOU_ASAP)
1076 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
1080 // =======================================================================
1081 // function : Update
1083 // =======================================================================
1084 void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
1085 const Handle(Visual3d_Layer)& theOverLayer)
1088 myStructuresUpdated = Standard_True;
1089 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
1092 // ========================================================================
1093 // function : SetAutoZFitMode
1095 // ========================================================================
1096 void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
1097 const Standard_Real theScaleFactor)
1099 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
1100 myAutoZFitScaleFactor = theScaleFactor;
1101 myAutoZFitIsOn = theIsOn;
1104 // ========================================================================
1105 // function : AutoZFitMode
1107 // ========================================================================
1108 Standard_Boolean Visual3d_View::AutoZFitMode() const
1110 return myAutoZFitIsOn;
1113 // ========================================================================
1114 // function : AutoZFitScaleFactor
1116 // ========================================================================
1117 Standard_Real Visual3d_View::AutoZFitScaleFactor() const
1119 return myAutoZFitScaleFactor;
1122 // ========================================================================
1123 // function : AutoZFit
1125 // ========================================================================
1126 void Visual3d_View::AutoZFit()
1128 if (!AutoZFitMode())
1133 ZFitAll (myAutoZFitScaleFactor);
1136 // ========================================================================
1137 // function : ZFitAll
1139 // ========================================================================
1140 void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
1142 Standard_Real aMinMax[6]; // applicative min max boundaries
1143 MinMaxValues (aMinMax[0], aMinMax[1], aMinMax[2],
1144 aMinMax[3], aMinMax[4], aMinMax[5],
1147 Standard_Real aGraphicBB[6]; // real graphical boundaries (not accounting infinite flag).
1148 MinMaxValues (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1149 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5],
1153 Bnd_Box aGraphicBox;
1155 aMinMaxBox.Update (aMinMax[0], aMinMax[1], aMinMax[2],
1156 aMinMax[3], aMinMax[4], aMinMax[5]);
1158 aGraphicBox.Update (aGraphicBB[0], aGraphicBB[1], aGraphicBB[2],
1159 aGraphicBB[3], aGraphicBB[4], aGraphicBB[5]);
1161 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1162 aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
1165 // ========================================================================
1166 // function : AcceptDisplay
1168 // ========================================================================
1169 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
1171 const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
1172 switch (theStruct->Visual())
1174 case Graphic3d_TOS_ALL:
1176 return Visual3d_TOA_YES; // The structure accepts any type of view
1178 case Graphic3d_TOS_SHADING:
1180 return ViewType == Visual3d_TOV_SHADING
1184 case Graphic3d_TOS_WIREFRAME:
1186 return ViewType == Visual3d_TOV_WIREFRAME
1190 case Graphic3d_TOS_COMPUTED:
1192 return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
1193 ? Visual3d_TOA_COMPUTE
1197 return Visual3d_TOA_NO;
1200 // ========================================================================
1201 // function : ChangeDisplayPriority
1203 // ========================================================================
1204 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
1205 const Standard_Integer /*theOldPriority*/,
1206 const Standard_Integer theNewPriority)
1211 || !IsDisplayed (theStruct))
1216 if (!myIsInComputedMode)
1218 myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
1222 const Standard_Integer anIndex = IsComputed (theStruct);
1223 const Graphic3d_CStructure& aCStruct = anIndex != 0
1224 ? *(myStructsComputed.Value (anIndex)->CStructure())
1225 : *theStruct->CStructure();
1226 myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
1229 // ========================================================================
1232 // ========================================================================
1233 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
1234 const Standard_Boolean theWithDestruction)
1236 const Standard_Integer anIndex = IsComputed (theStruct);
1239 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
1240 aCompStruct->GraphicClear (theWithDestruction);
1241 aCompStruct->SetHLRValidation (Standard_False);
1245 // ========================================================================
1246 // function : Connect
1248 // ========================================================================
1249 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
1250 const Handle(Graphic3d_Structure)& theDaughter)
1252 Standard_Integer anIndexM = IsComputed (theMother);
1253 Standard_Integer anIndexD = IsComputed (theDaughter);
1257 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1258 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1259 aStructM->GraphicConnect (aStructD);
1263 // ========================================================================
1264 // function : Disconnect
1266 // ========================================================================
1267 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
1268 const Handle(Graphic3d_Structure)& theDaughter)
1270 Standard_Integer anIndexM = IsComputed (theMother);
1271 Standard_Integer anIndexD = IsComputed (theDaughter);
1275 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1276 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1277 aStructM->GraphicDisconnect (aStructD);
1281 // ========================================================================
1282 // function : DisplayImmediate
1284 // ========================================================================
1285 Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
1286 const Standard_Boolean theIsSingleView)
1288 if (!myImmediateStructures.Add (theStructure))
1290 return Standard_False;
1293 if (theIsSingleView)
1295 Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
1297 for (int i=1;i<=aViews->Length();i++)
1299 if (aViews->Value(i).Access() != this)
1301 aViews->Value(i)->EraseImmediate (theStructure);
1306 myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
1307 return Standard_True;
1310 // ========================================================================
1311 // function : EraseImmediate
1313 // ========================================================================
1314 Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
1316 const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
1319 myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
1325 // ========================================================================
1326 // function : ClearImmediate
1328 // ========================================================================
1329 Standard_Boolean Visual3d_View::ClearImmediate()
1331 if (myImmediateStructures.IsEmpty())
1333 return Standard_False;
1336 for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
1338 myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
1340 myImmediateStructures.Clear();
1341 return Standard_True;
1344 // ========================================================================
1345 // function : Display
1347 // ========================================================================
1348 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
1350 Display (theStruct, myViewManager->UpdateMode());
1353 // ========================================================================
1354 // function : Display
1356 // ========================================================================
1357 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
1358 const Aspect_TypeOfUpdate theUpdateMode)
1367 // If Display on a structure present in the list of calculated structures while it is not
1368 // or more, of calculated type =>
1369 // - removes it as well as the associated old computed
1370 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
1371 Standard_Integer anIndex = IsComputed (theStruct);
1373 && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
1375 myStructsToCompute.Remove (anIndex);
1376 myStructsComputed .Remove (anIndex);
1380 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1381 if (anAnswer == Visual3d_TOA_NO)
1386 if (!ComputedMode())
1388 anAnswer = Visual3d_TOA_YES;
1391 if (anAnswer == Visual3d_TOA_YES)
1393 if (IsDisplayed (theStruct))
1398 theStruct->CalculateBoundBox();
1399 myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
1400 myStructsDisplayed.Add (theStruct);
1401 Update (theUpdateMode);
1404 else if (anAnswer != Visual3d_TOA_COMPUTE)
1411 // Already computed, is COMPUTED still valid?
1412 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
1413 if (anOldStruct->HLRValidation())
1415 // Case COMPUTED valid
1417 if (!IsDisplayed (theStruct))
1419 myStructsDisplayed.Add (theStruct);
1420 myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
1421 Update (theUpdateMode);
1427 // Case COMPUTED invalid
1428 // Is there another valid representation?
1429 // Find in the sequence of already calculated structures
1430 // 1/ Structure having the same Owner as <AStructure>
1431 // 2/ That is not <AStructure>
1432 // 3/ The COMPUTED which of is valid
1433 const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
1436 // Case of COMPUTED invalid, WITH a valid of replacement
1438 if (!IsDisplayed (theStruct))
1440 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
1441 myStructsComputed.SetValue (anIndex, aNewStruct);
1442 myStructsDisplayed.Add (theStruct);
1443 myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
1444 Update (theUpdateMode);
1450 // Case COMPUTED invalid, WITHOUT a valid of replacement
1451 // COMPUTED is removed if displayed
1452 if (IsDisplayed (theStruct))
1454 myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
1460 // Compute + Validation
1461 Handle(Graphic3d_Structure) aStruct;
1462 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1463 theStruct->Transform (aTrsf);
1466 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1467 for (Standard_Integer ii = 0; ii <= 3; ++ii)
1469 for (Standard_Integer jj = 0; jj <= 3; ++jj)
1471 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
1475 aStruct = myStructsComputed.Value (anIndex);
1476 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1477 if (theStruct->IsTransformed())
1479 theStruct->Compute (this, aTrsf, aStruct);
1483 theStruct->Compute (this, aStruct);
1488 aStruct = theStruct->IsTransformed()
1489 ? theStruct->Compute (this, aTrsf)
1490 : theStruct->Compute (this);
1493 aStruct->SetHLRValidation (Standard_True);
1495 // TOCOMPUTE and COMPUTED associated to sequences are added
1496 myStructsToCompute.Append (theStruct);
1497 myStructsComputed .Append (aStruct);
1499 // The previous are removed if necessary
1502 myStructsToCompute.Remove (anIndex);
1503 myStructsComputed .Remove (anIndex);
1506 // Of which type will be the computed?
1507 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1508 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1509 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1510 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
1511 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1512 if (!toComputeShading && !toComputeWireframe)
1514 anAnswer = Visual3d_TOA_NO;
1518 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
1519 anAnswer = AcceptDisplay (aStruct);
1522 if (theStruct->IsHighlighted())
1524 aStruct->SetHighlightColor (theStruct->HighlightColor());
1525 aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1528 // It is displayed only if the calculated structure
1529 // has a proper type corresponding to the one of the view.
1530 if (anAnswer != Visual3d_TOA_NO)
1532 if (!IsDisplayed (theStruct))
1534 myStructsDisplayed.Add (theStruct);
1536 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
1537 Update (theUpdateMode);
1541 // ========================================================================
1544 // ========================================================================
1545 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
1549 Erase (theStruct, myViewManager->UpdateMode());
1553 // ========================================================================
1556 // ========================================================================
1557 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
1558 const Aspect_TypeOfUpdate theUpdateMode)
1561 || !IsDisplayed (theStruct))
1566 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1567 if (!ComputedMode())
1569 anAnswer = Visual3d_TOA_YES;
1572 if (anAnswer != Visual3d_TOA_COMPUTE)
1574 myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
1576 else if (anAnswer == Visual3d_TOA_COMPUTE
1577 && myIsInComputedMode)
1579 const Standard_Integer anIndex = IsComputed (theStruct);
1582 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1583 myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
1586 myStructsDisplayed.Remove (theStruct);
1587 Update (theUpdateMode);
1590 // ========================================================================
1591 // function : Highlight
1593 // ========================================================================
1594 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
1595 const Aspect_TypeOfHighlightMethod theMethod)
1597 const Standard_Integer anIndex = IsComputed (theStruct);
1600 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1601 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1602 aCompStruct->GraphicHighlight (theMethod);
1606 // ========================================================================
1607 // function : SetTransform
1609 // ========================================================================
1610 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
1611 const TColStd_Array2OfReal& theTrsf)
1613 const Standard_Integer anIndex = IsComputed (theStruct);
1616 // Test is somewhat light !
1617 // trsf is transferred only if it is :
1620 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
1621 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
1622 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
1624 ReCompute (theStruct);
1628 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1629 aCompStruct->GraphicTransform (theTrsf);
1633 theStruct->CalculateBoundBox();
1634 if (!theStruct->IsMutable()
1635 && !theStruct->CStructure()->IsForHighlight
1636 && !theStruct->CStructure()->IsInfinite)
1638 const Standard_Integer aLayerId = theStruct->GetZLayer();
1639 myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
1643 // ========================================================================
1644 // function : UnHighlight
1646 // ========================================================================
1647 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
1649 Standard_Integer anIndex = IsComputed (theStruct);
1652 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1653 aCompStruct->GraphicUnHighlight();
1657 // ========================================================================
1658 // function : IsComputed
1660 // ========================================================================
1661 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
1663 const Standard_Integer aStructId = theStruct->Identification();
1664 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1665 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1667 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1668 if (aStruct->Identification() == aStructId)
1676 // ========================================================================
1677 // function : IsDisplayed
1679 // ========================================================================
1680 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
1683 && myStructsDisplayed.Contains (theStruct);
1686 // ========================================================================
1687 // function : ContainsFacet
1689 // ========================================================================
1690 Standard_Boolean Visual3d_View::ContainsFacet() const
1692 return ContainsFacet (myStructsDisplayed);
1695 // ========================================================================
1696 // function : ContainsFacet
1698 // ========================================================================
1699 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
1701 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
1703 if (aStructIter.Key()->ContainsFacet())
1705 return Standard_True;
1708 return Standard_False;
1711 // ========================================================================
1712 // function : MinMaxValues
1714 // ========================================================================
1715 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1716 Standard_Real& theYMin,
1717 Standard_Real& theZMin,
1718 Standard_Real& theXMax,
1719 Standard_Real& theYMax,
1720 Standard_Real& theZMax,
1721 const Standard_Boolean theToIgnoreInfiniteFlag) const
1723 MinMaxValues (myStructsDisplayed,
1724 theXMin, theYMin, theZMin,
1725 theXMax, theYMax, theZMax,
1726 theToIgnoreInfiniteFlag);
1729 // ========================================================================
1730 // function : MinMaxValues
1732 // ========================================================================
1733 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1734 Standard_Real& theXMin,
1735 Standard_Real& theYMin,
1736 Standard_Real& theZMin,
1737 Standard_Real& theXMax,
1738 Standard_Real& theYMax,
1739 Standard_Real& theZMax,
1740 const Standard_Boolean theToIgnoreInfiniteFlag) const
1742 if (theSet.IsEmpty ())
1744 theXMin = RealFirst();
1745 theYMin = RealFirst();
1746 theZMin = RealFirst();
1748 theXMax = RealLast();
1749 theYMax = RealLast();
1750 theZMax = RealLast();
1754 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1755 Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet);
1757 theXMin = RealLast();
1758 theYMin = RealLast();
1759 theZMin = RealLast();
1761 theXMax = RealFirst ();
1762 theYMax = RealFirst ();
1763 theZMax = RealFirst ();
1765 for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next())
1767 const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
1769 if (!aStructure->IsVisible())
1772 if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
1774 //XMin, YMin .... ZMax are initialized by means of infinite line data
1775 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, Standard_False);
1776 if (aXm != RealFirst() && aXm < theXMin)
1780 if (aYm != RealFirst() && aYm < theYMin)
1784 if (aZm != RealFirst() && aZm < theZMin)
1788 if (aXM != RealLast() && aXM > theXMax)
1792 if (aYM != RealLast() && aYM > theYMax)
1796 if (aZM != RealLast() && aZM > theZMax)
1802 // Only non-empty and non-infinite structures
1803 // are taken into account for calculation of MinMax
1804 if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty())
1806 aStructure->MinMaxValues (aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
1808 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
1809 //"FitAll" operation ignores object with transform persitence parameter
1810 if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None )
1812 theXMin = Min (aXm, theXMin);
1813 theYMin = Min (aYm, theYMin);
1814 theZMin = Min (aZm, theZMin);
1815 theXMax = Max (aXM, theXMax);
1816 theYMax = Max (aYM, theYMax);
1817 theZMax = Max (aZM, theZMax);
1822 // The following cases are relevant
1823 // For exemple if all structures are empty or infinite
1824 if (theXMax < theXMin) { aXm = theXMin; theXMin = theXMax; theXMax = aXm; }
1825 if (theYMax < theYMin) { aYm = theYMin; theYMin = theYMax; theYMax = aYm; }
1826 if (theZMax < theZMin) { aZm = theZMin; theZMin = theZMax; theZMax = aZm; }
1830 // ========================================================================
1831 // function : MinMaxValues
1833 // ========================================================================
1834 void Visual3d_View::MinMaxValues (Standard_Real& theXMin,
1835 Standard_Real& theYMin,
1836 Standard_Real& theXMax,
1837 Standard_Real& theYMax,
1838 const Standard_Boolean theToIgnoreInfiniteFlag) const
1840 MinMaxValues (myStructsDisplayed,
1843 theToIgnoreInfiniteFlag);
1846 // ========================================================================
1847 // function : MinMaxValues
1849 // ========================================================================
1850 void Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1851 Standard_Real& theXMin,
1852 Standard_Real& theYMin,
1853 Standard_Real& theXMax,
1854 Standard_Real& theYMax,
1855 const Standard_Boolean theToIgnoreInfiniteFlag) const
1857 Standard_Real aXm, aYm, aZm, aXM, aYM, aZM;
1858 Standard_Real aXp, aYp, aZp;
1860 MinMaxValues (theSet, aXm, aYm, aZm, aXM, aYM, aZM, theToIgnoreInfiniteFlag);
1862 Projects (aXm, aYm, aZm, aXp, aYp, aZp);
1866 Projects (aXM, aYM, aZM, aXp, aYp, aZp);
1870 if (theXMax < theXMin) { aXp = theXMax; theXMax = theXMin; theXMin = aXp; }
1871 if (theYMax < theYMin) { aYp = theYMax; theYMax = theYMin; theYMin = aYp; }
1874 // =======================================================================
1875 // function : NumberOfDisplayedStructures
1877 // =======================================================================
1878 Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
1880 return myStructsDisplayed.Extent();
1883 // =======================================================================
1884 // function : Projects
1886 // =======================================================================
1887 void Visual3d_View::Projects (const Standard_Real theX,
1888 const Standard_Real theY,
1889 const Standard_Real theZ,
1890 Standard_Real& thePX,
1891 Standard_Real& thePY,
1892 Standard_Real& thePZ) const
1894 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1896 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1897 Standard_Real aXSize = aViewSpaceDimensions.X();
1898 Standard_Real aYSize = aViewSpaceDimensions.Y();
1899 Standard_Real aZSize = aViewSpaceDimensions.Z();
1901 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1903 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1904 thePX = aPoint.X() * aXSize * 0.5;
1905 thePY = aPoint.Y() * aYSize * 0.5;
1906 thePZ = aPoint.Z() * aZSize * 0.5;
1909 // =======================================================================
1910 // function : Identification
1912 // =======================================================================
1913 Standard_Integer Visual3d_View::Identification() const
1915 return MyCView.ViewId;
1918 // =======================================================================
1919 // function : ZBufferIsActivated
1921 // =======================================================================
1922 Standard_Boolean Visual3d_View::ZBufferIsActivated() const
1928 return Standard_False;
1931 if (MyCView.Context.ZBufferActivity == -1)
1933 // not forced by the programmer => depends on the type of visualisation
1934 return MyContext.Visualization () == Visual3d_TOV_SHADING;
1936 return MyCView.Context.ZBufferActivity != 0; // 0 or 1 => forced by the programmer
1939 // =======================================================================
1940 // function : SetTransparency
1942 // =======================================================================
1943 void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
1952 myGraphicDriver->Transparency (MyCView, theActivity);
1955 // =======================================================================
1956 // function : SetZBufferActivity
1958 // =======================================================================
1959 void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
1962 || MyCView.Context.ZBufferActivity == theActivity
1969 MyCView.Context.ZBufferActivity = theActivity;
1970 myGraphicDriver->SetVisualisation (MyCView);
1973 // =======================================================================
1974 // function : UpdateView
1976 // =======================================================================
1977 void Visual3d_View::UpdateView()
1979 MyCView.Context.Aliasing = MyContext.AliasingIsOn();
1980 MyCView.Context.BackZClipping = MyContext.BackZClippingIsOn();
1981 MyCView.Context.FrontZClipping = MyContext.FrontZClippingIsOn();
1982 MyCView.Context.DepthCueing = MyContext.DepthCueingIsOn();
1984 MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
1985 MyCView.Context.ZClipBackPlane = float (MyContext.ZClippingBackPlane());
1986 MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
1987 MyCView.Context.DepthBackPlane = float (MyContext.DepthCueingBackPlane());
1989 MyCView.Context.Model = MyContext.Model();
1990 MyCView.Context.Visualization = MyContext.Visualization();
1992 MyCView.Context.TextureEnv = MyContext.TextureEnv();
1993 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
1996 // =======================================================================
1997 // function : Compute
1999 // =======================================================================
2000 void Visual3d_View::Compute()
2002 // force HLRValidation to False on all structures calculated in the view
2003 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
2004 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
2006 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
2009 if (!ComputedMode())
2014 // Change of orientation or of projection type =>
2015 // Remove structures that were calculated for the previous orientation.
2016 // Recalculation of new structures.
2017 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
2018 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2020 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
2021 if (anAnswer == Visual3d_TOA_COMPUTE)
2023 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
2027 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
2029 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
2033 // =======================================================================
2034 // function : ReCompute
2036 // =======================================================================
2037 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
2039 theStruct->CalculateBoundBox();
2040 if (!theStruct->IsMutable()
2041 && !theStruct->CStructure()->IsForHighlight
2042 && !theStruct->CStructure()->IsInfinite)
2044 const Standard_Integer aLayerId = theStruct->DisplayPriority();
2045 myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
2052 || !MyWindow->IsMapped()
2053 || !theStruct->IsDisplayed())
2058 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
2059 if (anAnswer != Visual3d_TOA_COMPUTE)
2064 const Standard_Integer anIndex = IsComputed (theStruct);
2070 // compute + validation
2071 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
2072 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
2074 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
2076 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
2079 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2080 theStruct->Transform (aTrsf);
2082 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
2083 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
2084 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
2085 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
2086 : theStruct->Compute (this, aCompStruct);
2087 aCompStruct->SetHLRValidation (Standard_True);
2089 // of which type will be the computed?
2090 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2091 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2092 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2093 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2094 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2095 if (toComputeWireframe)
2097 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2099 else if (toComputeShading)
2101 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2104 if (theStruct->IsHighlighted())
2106 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
2107 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2110 // The previous calculation is removed and the new one is dislayed
2111 myGraphicDriver->EraseStructure (MyCView, *aCompStructOld->CStructure());
2112 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
2114 // why not just replace existing items?
2115 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
2116 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
2118 // hlhsr and the new associated compute are added
2119 myStructsToCompute.Append (theStruct);
2120 myStructsComputed .Append (aCompStruct);
2122 // hlhsr and the new associated compute are removed
2123 myStructsToCompute.Remove (anIndex);
2124 myStructsComputed .Remove (anIndex);
2127 // =======================================================================
2128 // function : GraphicDriver
2130 // =======================================================================
2131 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
2133 return myGraphicDriver;
2136 // =======================================================================
2137 // function : HaveTheSameOwner
2139 // =======================================================================
2140 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
2142 // Find in the sequence of already calculated structures
2143 // 1/ Structure with the same Owner as <AStructure>
2144 // 2/ Which is not <AStructure>
2145 // 3/ COMPUTED which of is valid
2146 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
2147 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
2149 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
2150 if (aStructToComp->Owner() == theStruct->Owner()
2151 && aStructToComp->Identification() != theStruct->Identification())
2153 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
2154 if (aStructComp->HLRValidation())
2163 // =======================================================================
2166 // =======================================================================
2167 Standard_Address Visual3d_View::CView() const
2169 return Standard_Address (&MyCView);
2172 // =======================================================================
2173 // function : ZBufferTriedronSetup
2175 // =======================================================================
2176 void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
2177 const Quantity_NameOfColor theYColor,
2178 const Quantity_NameOfColor theZColor,
2179 const Standard_Real theSizeRatio,
2180 const Standard_Real theAxisDiametr,
2181 const Standard_Integer theNbFacettes)
2183 myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
2184 theSizeRatio, theAxisDiametr, theNbFacettes);
2187 // =======================================================================
2188 // function : TriedronDisplay
2190 // =======================================================================
2191 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
2192 const Quantity_NameOfColor theColor,
2193 const Standard_Real theScale,
2194 const Standard_Boolean theAsWireframe)
2196 myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
2199 // =======================================================================
2200 // function : TriedronErase
2202 // =======================================================================
2203 void Visual3d_View::TriedronErase()
2205 myGraphicDriver->TriedronErase (MyCView);
2208 // =======================================================================
2209 // function : TriedronEcho
2211 // =======================================================================
2212 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
2214 myGraphicDriver->TriedronEcho (MyCView, theType);
2217 static Standard_Boolean checkFloat (const Standard_Real theValue)
2219 return theValue > -FLT_MAX
2220 && theValue < FLT_MAX;
2223 static void SetMinMaxValuesCallback (Visual3d_View* theView)
2225 Graphic3d_Vec3d aMin, aMax;
2226 theView->MinMaxValues (aMin.x(), aMin.y(), aMin.z(),
2227 aMax.x(), aMax.y(), aMax.z());
2228 if (checkFloat (aMin.x()) && checkFloat (aMin.y()) && checkFloat (aMin.z())
2229 && checkFloat (aMax.x()) && checkFloat (aMax.y()) && checkFloat (aMax.z()))
2231 const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
2232 aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.x(), (Standard_ShortReal )aMin.y(), (Standard_ShortReal )aMin.z(),
2233 (Standard_ShortReal )aMax.x(), (Standard_ShortReal )aMax.y(), (Standard_ShortReal )aMax.z());
2237 // =======================================================================
2238 // function : GetGraduatedTrihedron
2240 // =======================================================================
2241 Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
2242 TCollection_ExtendedString& theYName,
2243 TCollection_ExtendedString& theZName,
2244 Standard_Boolean& theToDrawXName,
2245 Standard_Boolean& theToDrawYName,
2246 Standard_Boolean& theToDrawZName,
2247 Standard_Boolean& theToDrawXValues,
2248 Standard_Boolean& theToDrawYValues,
2249 Standard_Boolean& theToDrawZValues,
2250 Standard_Boolean& theToDrawGrid,
2251 Standard_Boolean& theToDrawAxes,
2252 Standard_Integer& theNbX,
2253 Standard_Integer& theNbY,
2254 Standard_Integer& theNbZ,
2255 Standard_Integer& theXOffset,
2256 Standard_Integer& theYOffset,
2257 Standard_Integer& theZOffset,
2258 Standard_Integer& theXAxisOffset,
2259 Standard_Integer& theYAxisOffset,
2260 Standard_Integer& theZAxisOffset,
2261 Standard_Boolean& theToDrawXTickMarks,
2262 Standard_Boolean& theToDrawYTickMarks,
2263 Standard_Boolean& theToDrawZTickMarks,
2264 Standard_Integer& theXTickMarkLength,
2265 Standard_Integer& theYTickMarkLength,
2266 Standard_Integer& theZTickMarkLength,
2267 Quantity_Color& theGridColor,
2268 Quantity_Color& theXNameColor,
2269 Quantity_Color& theYNameColor,
2270 Quantity_Color& theZNameColor,
2271 Quantity_Color& theXColor,
2272 Quantity_Color& theYColor,
2273 Quantity_Color& theZColor,
2274 TCollection_AsciiString& theFontOfNames,
2275 Font_FontAspect& theStyleOfNames,
2276 Standard_Integer& theSizeOfNames,
2277 TCollection_AsciiString& theFontOfValues,
2278 Font_FontAspect& theStyleOfValues,
2279 Standard_Integer& theSizeOfValues) const
2281 if (!MyGTrihedron.ptrVisual3dView)
2283 return Standard_False;
2286 theXName = MyGTrihedron.xname;
2287 theYName = MyGTrihedron.yname;
2288 theZName = MyGTrihedron.zname;
2289 theToDrawXName = MyGTrihedron.xdrawname;
2290 theToDrawYName = MyGTrihedron.ydrawname;
2291 theToDrawZName = MyGTrihedron.zdrawname;
2292 theToDrawXValues = MyGTrihedron.xdrawvalues;
2293 theToDrawYValues = MyGTrihedron.ydrawvalues;
2294 theToDrawZValues = MyGTrihedron.zdrawvalues;
2295 theToDrawGrid = MyGTrihedron.drawgrid;
2296 theToDrawAxes = MyGTrihedron.drawaxes;
2297 theNbX = MyGTrihedron.nbx;
2298 theNbY = MyGTrihedron.nby;
2299 theNbZ = MyGTrihedron.nbz;
2300 theXOffset = MyGTrihedron.xoffset;
2301 theYOffset = MyGTrihedron.yoffset;
2302 theZOffset = MyGTrihedron.zoffset;
2303 theXAxisOffset = MyGTrihedron.xaxisoffset;
2304 theYAxisOffset = MyGTrihedron.yaxisoffset;
2305 theZAxisOffset = MyGTrihedron.zaxisoffset;
2306 theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
2307 theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
2308 theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
2309 theXTickMarkLength = MyGTrihedron.xtickmarklength;
2310 theYTickMarkLength = MyGTrihedron.ytickmarklength;
2311 theZTickMarkLength = MyGTrihedron.ztickmarklength;
2312 theGridColor = MyGTrihedron.gridcolor;
2313 theXNameColor = MyGTrihedron.xnamecolor;
2314 theYNameColor = MyGTrihedron.ynamecolor;
2315 theZNameColor = MyGTrihedron.znamecolor;
2316 theXColor = MyGTrihedron.xcolor;
2317 theYColor = MyGTrihedron.ycolor;
2318 theZColor = MyGTrihedron.zcolor;
2319 theFontOfNames = MyGTrihedron.fontOfNames;
2320 theStyleOfNames = MyGTrihedron.styleOfNames;
2321 theSizeOfNames = MyGTrihedron.sizeOfNames;
2322 theFontOfValues = MyGTrihedron.fontOfValues;
2323 theStyleOfValues = MyGTrihedron.styleOfValues;
2324 theSizeOfValues = MyGTrihedron.sizeOfValues;
2325 return Standard_True;
2328 // =======================================================================
2329 // function : GraduatedTrihedronDisplay
2331 // =======================================================================
2332 void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
2333 const TCollection_ExtendedString& theYName,
2334 const TCollection_ExtendedString& theZName,
2335 const Standard_Boolean theToDrawXName,
2336 const Standard_Boolean theToDrawYName,
2337 const Standard_Boolean theToDrawZName,
2338 const Standard_Boolean theToDrawXValues,
2339 const Standard_Boolean theToDrawYValues,
2340 const Standard_Boolean theToDrawZValues,
2341 const Standard_Boolean theToDrawGrid,
2342 const Standard_Boolean theToDrawAxes,
2343 const Standard_Integer theNbX,
2344 const Standard_Integer theNbY,
2345 const Standard_Integer theNbZ,
2346 const Standard_Integer theXOffset,
2347 const Standard_Integer theYOffset,
2348 const Standard_Integer theZOffset,
2349 const Standard_Integer theXAxisOffset,
2350 const Standard_Integer theYAxisOffset,
2351 const Standard_Integer theZAxisOffset,
2352 const Standard_Boolean theToDrawXTickMarks,
2353 const Standard_Boolean theToDrawYTickMarks,
2354 const Standard_Boolean theToDrawZTickMarks,
2355 const Standard_Integer theXTickMarkLength,
2356 const Standard_Integer theYTickMarkLength,
2357 const Standard_Integer theZTickMarkLength,
2358 const Quantity_Color& theGridColor,
2359 const Quantity_Color& theXNameColor,
2360 const Quantity_Color& theYNameColor,
2361 const Quantity_Color& theZNameColor,
2362 const Quantity_Color& theXColor,
2363 const Quantity_Color& theYColor,
2364 const Quantity_Color& theZColor,
2365 const TCollection_AsciiString& theFontOfNames,
2366 const Font_FontAspect theStyleOfNames,
2367 const Standard_Integer theSizeOfNames,
2368 const TCollection_AsciiString& theFontOfValues,
2369 const Font_FontAspect theStyleOfValues,
2370 const Standard_Integer theSizeOfValues)
2372 MyGTrihedron.xname = theXName;
2373 MyGTrihedron.yname = theYName;
2374 MyGTrihedron.zname = theZName;
2375 MyGTrihedron.xdrawname = theToDrawXName;
2376 MyGTrihedron.ydrawname = theToDrawYName;
2377 MyGTrihedron.zdrawname = theToDrawZName;
2378 MyGTrihedron.xdrawvalues = theToDrawXValues;
2379 MyGTrihedron.ydrawvalues = theToDrawYValues;
2380 MyGTrihedron.zdrawvalues = theToDrawZValues;
2381 MyGTrihedron.drawgrid = theToDrawGrid;
2382 MyGTrihedron.drawaxes = theToDrawAxes;
2383 MyGTrihedron.nbx = theNbX;
2384 MyGTrihedron.nby = theNbY;
2385 MyGTrihedron.nbz = theNbZ;
2386 MyGTrihedron.xoffset = theXOffset;
2387 MyGTrihedron.yoffset = theYOffset;
2388 MyGTrihedron.zoffset = theZOffset;
2389 MyGTrihedron.xaxisoffset = theXAxisOffset;
2390 MyGTrihedron.yaxisoffset = theYAxisOffset;
2391 MyGTrihedron.zaxisoffset = theZAxisOffset;
2392 MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
2393 MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
2394 MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
2395 MyGTrihedron.xtickmarklength = theXTickMarkLength;
2396 MyGTrihedron.ytickmarklength = theYTickMarkLength;
2397 MyGTrihedron.ztickmarklength = theZTickMarkLength;
2398 MyGTrihedron.gridcolor = theGridColor;
2399 MyGTrihedron.xnamecolor = theXNameColor;
2400 MyGTrihedron.ynamecolor = theYNameColor;
2401 MyGTrihedron.znamecolor = theZNameColor;
2402 MyGTrihedron.xcolor = theXColor;
2403 MyGTrihedron.ycolor = theYColor;
2404 MyGTrihedron.zcolor = theZColor;
2405 MyGTrihedron.fontOfNames = theFontOfNames;
2406 MyGTrihedron.styleOfNames = theStyleOfNames;
2407 MyGTrihedron.sizeOfNames = theSizeOfNames;
2408 MyGTrihedron.fontOfValues = theFontOfValues;
2409 MyGTrihedron.styleOfValues = theStyleOfValues;
2410 MyGTrihedron.sizeOfValues = theSizeOfValues;
2412 MyGTrihedron.ptrVisual3dView = this;
2413 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
2414 myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
2417 // =======================================================================
2418 // function : GraduatedTrihedronErase
2420 // =======================================================================
2421 void Visual3d_View::GraduatedTrihedronErase()
2423 MyGTrihedron.ptrVisual3dView = NULL;
2424 myGraphicDriver->GraduatedTrihedronErase (MyCView);
2427 // =======================================================================
2428 // function : UnderLayer
2430 // =======================================================================
2431 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
2433 return myViewManager->UnderLayer();
2436 // =======================================================================
2437 // function : OverLayer
2439 // =======================================================================
2440 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
2442 return myViewManager->OverLayer();
2445 // =======================================================================
2446 // function : LightLimit
2448 // =======================================================================
2449 Standard_Integer Visual3d_View::LightLimit() const
2451 return myGraphicDriver->InquireLightLimit();
2454 // =======================================================================
2455 // function : PlaneLimit
2457 // =======================================================================
2458 Standard_Integer Visual3d_View::PlaneLimit() const
2460 return myGraphicDriver->InquirePlaneLimit();
2463 // =======================================================================
2464 // function : ViewManager
2466 // =======================================================================
2467 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
2469 return myViewManager;
2472 // =======================================================================
2473 // function : SetComputedMode
2475 // =======================================================================
2476 void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
2478 if (( theMode && myIsInComputedMode)
2479 || (!theMode && !myIsInComputedMode))
2484 myIsInComputedMode = theMode;
2485 if (!myIsInComputedMode)
2487 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2489 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2490 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2491 if (anAnswer != Visual3d_TOA_COMPUTE)
2496 const Standard_Integer anIndex = IsComputed (aStruct);
2499 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
2500 myGraphicDriver->EraseStructure (MyCView, *aStructComp->CStructure());
2501 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
2507 for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
2509 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
2510 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2511 if (anAnswer != Visual3d_TOA_COMPUTE)
2516 const Standard_Integer anIndex = IsComputed (aStruct);
2519 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2520 myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
2522 Display (aStruct, Aspect_TOU_WAIT);
2523 if (aStruct->IsHighlighted())
2525 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
2526 if (!aCompStruct->IsHighlighted())
2528 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2529 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2535 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2536 aStruct->Transform (aTrsf);
2537 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
2538 aCompStruct->SetHLRValidation (Standard_True);
2540 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2541 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2542 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2543 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2544 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2545 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2546 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2548 if (aStruct->IsHighlighted())
2550 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2551 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2554 Standard_Boolean hasResult = Standard_False;
2555 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
2556 const Standard_Integer aStructId = aStruct->Identification();
2557 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
2559 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
2561 hasResult = Standard_True;
2562 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
2569 myStructsToCompute.Append (aStruct);
2570 myStructsComputed .Append (aCompStruct);
2573 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2574 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
2577 Update (myViewManager->UpdateMode());
2580 // =======================================================================
2581 // function : ComputedMode
2583 // =======================================================================
2584 Standard_Boolean Visual3d_View::ComputedMode() const
2586 return myIsInComputedMode;
2589 // =======================================================================
2590 // function : SetBackFacingModel
2592 // =======================================================================
2593 void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
2598 case Visual3d_TOBM_AUTOMATIC:
2599 MyCView.Backfacing = 0;
2601 case Visual3d_TOBM_FORCE:
2602 MyCView.Backfacing = 1;
2604 case Visual3d_TOBM_DISABLE:
2605 MyCView.Backfacing = -1;
2608 myGraphicDriver->SetBackFacingModel (MyCView);
2611 // =======================================================================
2612 // function : BackFacingModel
2614 // =======================================================================
2615 Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
2617 switch (MyCView.Backfacing)
2619 case 0: return Visual3d_TOBM_AUTOMATIC;
2620 case 1: return Visual3d_TOBM_FORCE;
2622 return Visual3d_TOBM_DISABLE;
2625 // =======================================================================
2626 // function : EnableDepthTest
2628 // =======================================================================
2629 void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
2631 myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
2634 // =======================================================================
2635 // function : IsDepthTestEnabled
2637 // =======================================================================
2638 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
2640 return myGraphicDriver->IsDepthTestEnabled (MyCView);
2643 // =======================================================================
2644 // function : ReadDepths
2646 // =======================================================================
2647 void Visual3d_View::ReadDepths (const Standard_Integer theX,
2648 const Standard_Integer theY,
2649 const Standard_Integer theWidth,
2650 const Standard_Integer theHeight,
2651 const Standard_Address theBuffer) const
2653 myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
2656 // =======================================================================
2657 // function : FBOCreate
2659 // =======================================================================
2660 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
2661 const Standard_Integer theHeight)
2663 return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
2666 // =======================================================================
2667 // function : FBORelease
2669 // =======================================================================
2670 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
2672 myGraphicDriver->FBORelease( MyCView, theFBOPtr );
2675 // =======================================================================
2676 // function : FBOGetDimensions
2678 // =======================================================================
2679 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
2680 Standard_Integer& theWidth, Standard_Integer& theHeight,
2681 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
2683 myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
2684 theWidth, theHeight,
2685 theWidthMax, theHeightMax );
2688 // =======================================================================
2689 // function : FBOChangeViewport
2691 // =======================================================================
2692 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
2693 const Standard_Integer theWidth, const Standard_Integer theHeight)
2695 myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
2696 theWidth, theHeight );
2699 // =======================================================================
2700 // function : BufferDump
2702 // =======================================================================
2703 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
2704 const Graphic3d_BufferType& theBufferType)
2706 return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
2709 // =======================================================================
2710 // function : EnableGLLight
2712 // =======================================================================
2713 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
2715 myGraphicDriver->SetGLLightEnabled( MyCView, enable );
2718 // =======================================================================
2719 // function : IsGLLightEnabled
2721 // =======================================================================
2722 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
2724 return myGraphicDriver->IsGLLightEnabled( MyCView );
2727 // =======================================================================
2728 // function : Export
2730 // =======================================================================
2731 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
2732 const Graphic3d_ExportFormat theFormat,
2733 const Graphic3d_SortType theSortType,
2734 const Standard_Real thePrecision,
2735 const Standard_Address theProgressBarFunc,
2736 const Standard_Address theProgressObject) const
2738 Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
2739 Handle(Visual3d_Layer) anOverLayer = myViewManager->OverLayer();
2741 Aspect_CLayer2d anOverCLayer;
2742 Aspect_CLayer2d anUnderCLayer;
2743 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2745 if (!anOverLayer.IsNull())
2746 anOverCLayer = anOverLayer->CLayer();
2747 if (!anUnderLayer.IsNull())
2748 anUnderCLayer = anUnderLayer->CLayer();
2750 Standard_Integer aWidth, aHeight;
2751 Window()->Size (aWidth, aHeight);
2753 return myGraphicDriver->Export (theFileName, theFormat, theSortType,
2754 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
2755 thePrecision, theProgressBarFunc, theProgressObject);
2758 // =======================================================================
2759 // function : SetZLayerSettings
2761 // =======================================================================
2762 void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
2763 const Graphic3d_ZLayerSettings& theSettings)
2765 myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
2768 // =======================================================================
2769 // function : AddZLayer
2771 // =======================================================================
2772 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
2774 myGraphicDriver->AddZLayer (MyCView, theLayerId);
2777 // =======================================================================
2778 // function : RemoveZLayer
2780 // =======================================================================
2781 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
2783 myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
2786 // =======================================================================
2787 // function : ChangeZLayer
2789 // =======================================================================
2790 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
2791 const Standard_Integer theLayerId)
2793 myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
2796 // =======================================================================
2799 // =======================================================================
2800 Standard_Boolean Visual3d_View::Print (const Aspect_Handle thePrintDC,
2801 const Standard_Boolean theToShowBackground,
2802 const Standard_CString theFilename,
2803 const Aspect_PrintAlgo thePrintAlgorithm,
2804 const Standard_Real theScaleFactor) const
2806 return Print (myViewManager->UnderLayer(),
2807 myViewManager->OverLayer(),
2808 thePrintDC, theToShowBackground,
2809 theFilename, thePrintAlgorithm,
2813 // =======================================================================
2816 // =======================================================================
2817 Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
2818 const Handle(Visual3d_Layer)& theOverLayer,
2819 const Aspect_Handle thePrintDC,
2820 const Standard_Boolean theToShowBackground,
2821 const Standard_CString theFilename,
2822 const Aspect_PrintAlgo thePrintAlgorithm,
2823 const Standard_Real theScaleFactor) const
2828 || !MyWindow->IsMapped())
2830 return Standard_False;
2833 Aspect_CLayer2d anOverCLayer;
2834 Aspect_CLayer2d anUnderCLayer;
2835 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2836 if (!theOverLayer.IsNull()) anOverCLayer = theOverLayer->CLayer();
2837 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
2838 return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
2839 thePrintDC, theToShowBackground, theFilename,
2840 thePrintAlgorithm, theScaleFactor);