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;
117 MyCView.DefWindow.XWindow = theWindow->NativeHandle();
118 MyCView.DefWindow.XParentWindow = theWindow->NativeParentHandle();
120 Standard_Integer Width, Height;
121 theWindow->Size (Width, Height);
122 MyCView.DefWindow.dx = float(Width);
123 MyCView.DefWindow.dy = float(Height);
125 Standard_Real R, G, B;
126 MyBackground = MyWindow->Background ();
127 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
128 MyCView.DefWindow.Background.r = float (R);
129 MyCView.DefWindow.Background.g = float (G);
130 MyCView.DefWindow.Background.b = float (B);
133 if (!myGraphicDriver->View (MyCView))
135 Visual3d_ViewDefinitionError::Raise ("Association failed");
138 MyGradientBackground = MyWindow->GradientBackground();
139 SetGradientBackground(MyGradientBackground,1);
141 Standard_Boolean AWait = Standard_False; // => immediate update
142 myGraphicDriver->SetVisualisation (MyCView);
143 myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn());
144 myGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn());
145 myGraphicDriver->ClipLimit (MyCView, AWait);
146 myGraphicDriver->Environment (MyCView);
148 // Make view manager z layer list consistent with the view's list.
149 myViewManager->InstallZLayers (this);
151 // Update planses of model clipping
154 // Update light sources
157 // Association view-window does not cause the display
158 // of structures that can be displayed in the new view.
159 // In fact, association view-window is done, but the
160 // display is produced only if the view is activated (Activate).
164 // =======================================================================
167 // =======================================================================
168 Handle(Aspect_Window) Visual3d_View::Window() const
172 Visual3d_ViewDefinitionError::Raise ("Window not defined");
177 // =======================================================================
178 // function : IsDefined
180 // =======================================================================
181 Standard_Boolean Visual3d_View::IsDefined() const
183 return MyCView.DefWindow.IsDefined != 0;
186 // =======================================================================
187 // function : IsDeleted
189 // =======================================================================
190 Standard_Boolean Visual3d_View::IsDeleted() const
192 return MyCView.IsDeleted != 0;
195 // =======================================================================
196 // function : Destroy
198 // =======================================================================
199 void Visual3d_View::Destroy()
201 // Since myViewManager can be already destroyed,
202 // avoid attempts to access it in SetBackground()
203 myViewManager = NULL;
207 // =======================================================================
210 // =======================================================================
211 void Visual3d_View::Remove()
219 myStructsToCompute.Clear();
220 myStructsComputed .Clear();
221 myStructsDisplayed.Clear();
223 Aspect_GradientBackground aBlackGrad;
224 SetBackground (Aspect_Background (Quantity_NOC_BLACK));
225 SetGradientBackground (aBlackGrad, Standard_False);
227 if (myViewManager != NULL)
229 myViewManager->UnIdentification (MyCView.ViewId);
232 myGraphicDriver->RemoveView (MyCView);
235 MyCView.IsDeleted = 1;
236 MyCView.DefWindow.IsDefined = 0;
241 // =======================================================================
242 // function : Resized
244 // =======================================================================
245 void Visual3d_View::Resized()
251 else if (!IsDefined())
253 Visual3d_ViewDefinitionError::Raise ("Window not defined");
255 MyWindow->DoResize();
259 // =======================================================================
260 // function : SetRatio
262 // =======================================================================
263 void Visual3d_View::SetRatio()
270 const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode();
271 myViewManager->SetUpdateMode (Aspect_TOU_WAIT);
273 Standard_Integer aWidth, aHeight;
274 MyWindow->Size (aWidth, aHeight);
275 if (aWidth > 0 && aHeight > 0)
277 Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight;
279 MyCView.DefWindow.dx = Standard_ShortReal (aWidth);
280 MyCView.DefWindow.dy = Standard_ShortReal (aHeight);
282 myGraphicDriver->RatioWindow (MyCView);
284 // Update camera aspect
285 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
286 if (!aCamera.IsNull())
288 aCamera->SetAspect (aRatio);
291 if (!myDefaultCamera.IsNull())
293 myDefaultCamera->SetAspect (aRatio);
297 myViewManager->SetUpdateMode (anUpdateMode);
298 Update (anUpdateMode);
301 // =======================================================================
302 // function : UpdateLights
304 // =======================================================================
305 void Visual3d_View::UpdateLights()
313 if (MyContext.Model() == Visual3d_TOM_NONE)
315 // activate only a white ambient light
316 Graphic3d_CLight aCLight;
317 aCLight.Type = Visual3d_TOLS_AMBIENT;
318 aCLight.IsHeadlight = Standard_False;
319 aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f;
321 MyCView.Context.NbActiveLight = 1;
322 MyCView.Context.ActiveLight = &aCLight;
323 myGraphicDriver->SetLight (MyCView);
324 MyCView.Context.ActiveLight = NULL;
328 MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(),
329 myGraphicDriver->InquireLightLimit());
330 if (MyCView.Context.NbActiveLight < 1)
332 myGraphicDriver->SetLight (MyCView);
336 // parcing of light sources
337 MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight];
338 for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter)
340 MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight();
342 myGraphicDriver->SetLight (MyCView);
343 delete[] MyCView.Context.ActiveLight;
344 MyCView.Context.ActiveLight = NULL;
347 // =======================================================================
348 // function : UpdatePlanes
350 // =======================================================================
351 void Visual3d_View::UpdatePlanes()
353 MyCView.Context.ClipPlanes = MyContext.ClipPlanes();
354 if (IsDeleted() || !IsDefined())
359 myGraphicDriver->SetClipPlanes (MyCView);
362 // =======================================================================
363 // function : SetBackground
365 // =======================================================================
366 void Visual3d_View::SetBackground (const Aspect_Background& theBack)
372 else if (!IsDefined())
374 Visual3d_ViewDefinitionError::Raise ("Window not defined");
377 // At this level, only GL can update the background.
378 // It is not necessary to call MyWindow->SetBackground (ABack); as
379 // this method starts update of window background by X
380 // (if the windowing is X)
382 Standard_Real R, G, B;
383 MyBackground = theBack;
384 MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB);
385 MyCView.DefWindow.Background.r = float (R);
386 MyCView.DefWindow.Background.g = float (G);
387 MyCView.DefWindow.Background.b = float (B);
389 myGraphicDriver->Background (MyCView);
391 if (myViewManager != NULL)
393 Update (myViewManager->UpdateMode());
397 // =======================================================================
398 // function : SetGradientBackground
400 // =======================================================================
401 void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack,
402 const Standard_Boolean theToUpdate)
408 else if (!IsDefined())
410 Visual3d_ViewDefinitionError::Raise ("Window not defined");
413 MyGradientBackground = theBack;
414 Quantity_Color aCol1, aCol2;
415 MyGradientBackground.Colors (aCol1, aCol2);
416 myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod());
420 Update (Aspect_TOU_ASAP);
422 else if (myViewManager != NULL)
424 Update (myViewManager->UpdateMode());
428 // =======================================================================
429 // function : SetBackgroundImage
431 // =======================================================================
432 void Visual3d_View::SetBackgroundImage (const Standard_CString theFileName,
433 const Aspect_FillMethod theFillStyle,
434 const Standard_Boolean theToUpdate)
442 Visual3d_ViewDefinitionError::Raise ("Window not defined");
445 myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle);
447 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
450 // =======================================================================
451 // function : SetBgImageStyle
453 // =======================================================================
454 void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle,
455 const Standard_Boolean theToUpdate)
463 Visual3d_ViewDefinitionError::Raise ("Window not defined");
466 myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle);
468 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
471 // =======================================================================
472 // function : Background
474 // =======================================================================
475 Aspect_Background Visual3d_View::Background() const
480 // =======================================================================
481 // function : SetBgGradientStyle
483 // =======================================================================
484 void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle,
485 const Standard_Boolean theToUpdate)
491 else if (!IsDefined())
493 Visual3d_ViewDefinitionError::Raise ("Window not defined");
496 myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle);
498 Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode());
501 // =======================================================================
502 // function : GradientBackground
504 // =======================================================================
505 Aspect_GradientBackground Visual3d_View::GradientBackground() const
507 return MyGradientBackground;
510 // =======================================================================
511 // function : DefaultCamera
513 // =======================================================================
514 const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const
516 return myDefaultCamera;
519 // =======================================================================
522 // =======================================================================
523 const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const
525 return MyCView.Context.Camera;
528 // =======================================================================
529 // function : SetCamera
531 // =======================================================================
532 void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera)
534 MyCView.Context.Camera = theCamera;
536 myGraphicDriver->SetCamera (MyCView);
538 Update (myViewManager->UpdateMode());
541 // =======================================================================
542 // function : SetViewOrientationDefault
544 // =======================================================================
545 void Visual3d_View::SetViewOrientationDefault()
547 if (myDefaultCamera.IsNull())
549 myDefaultCamera = new Graphic3d_Camera();
552 myDefaultCamera->CopyOrientationData (MyCView.Context.Camera);
555 // =======================================================================
556 // function : ViewOrientationReset
558 // =======================================================================
559 void Visual3d_View::ViewOrientationReset()
566 if (!myDefaultCamera.IsNull())
568 MyCView.Context.Camera->CopyOrientationData (myDefaultCamera);
571 Update (myViewManager->UpdateMode());
574 // =======================================================================
575 // function : SetViewMappingDefault
577 // =======================================================================
578 void Visual3d_View::SetViewMappingDefault()
580 if (myDefaultCamera.IsNull())
582 myDefaultCamera = new Graphic3d_Camera();
584 myDefaultCamera->CopyMappingData (MyCView.Context.Camera);
587 // =======================================================================
588 // function : ViewMappingReset
590 // =======================================================================
591 void Visual3d_View::ViewMappingReset()
598 if (!myDefaultCamera.IsNull())
600 MyCView.Context.Camera->CopyMappingData (myDefaultCamera);
603 Update (myViewManager->UpdateMode());
606 // =======================================================================
607 // function : SetContext
609 // =======================================================================
610 void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx)
617 // To manage display only in case of change of visualisation mode
618 const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization();
619 const bool isModelChanged = theViewCtx.Model() != MyContext.Model();
621 // To manage antialiasing only in case of change
622 const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn();
623 const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn();
625 // To manage the depth cueing only in case of change
626 const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn();
627 const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn();
629 const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane();
630 const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane();
631 const Standard_Real aDepthCueingBackPlaneOld = MyContext.DepthCueingBackPlane();
632 const Standard_Real aDepthCueingBackPlaneNew = theViewCtx.DepthCueingBackPlane();
634 // To manage the Zclipping only in case of change
635 const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn();
636 const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn();
637 const Standard_Boolean aBackZClippingModeOld = MyContext.BackZClippingIsOn();
638 const Standard_Boolean aBackZClippingModeNew = theViewCtx.BackZClippingIsOn();
640 const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane();
641 const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane();
642 const Standard_Real aZClippingBackPlaneOld = MyContext.ZClippingBackPlane();
643 const Standard_Real aZClippingBackPlaneNew = theViewCtx.ZClippingBackPlane();
645 const bool isTextEnvChanged = theViewCtx.TextureEnv() != MyContext.TextureEnv();
646 const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail();
648 MyContext = theViewCtx;
652 Standard_Boolean toWait = Standard_False; // => immediate update
655 // management of visualization modes and types of shading.
659 myGraphicDriver->SetVisualisation (MyCView);
662 // management of antialiasing
663 if (anAliasingModeOld != anAliasingModeNew)
665 myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew);
668 // management of depth_cueing
669 if (aDepthCueingModeOld != aDepthCueingModeNew
670 || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew
671 || aDepthCueingBackPlaneOld != aDepthCueingBackPlaneNew)
673 if (aDepthCueingModeNew
674 && aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew)
676 Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position");
678 myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew);
681 // management of Zclipping
682 if (aFrontZClippingModeOld != aFrontZClippingModeNew
683 || aBackZClippingModeOld != aBackZClippingModeNew
684 || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew
685 || aZClippingBackPlaneOld != aZClippingBackPlaneNew)
687 if (aBackZClippingModeNew
688 && aFrontZClippingModeNew
689 && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew)
691 Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position");
694 myGraphicDriver->ClipLimit (MyCView, toWait);
697 // management of textures
699 || isSurfDetailChanged)
701 myGraphicDriver->Environment (MyCView);
704 UpdatePlanes(); // Update of planes of model clipping
705 UpdateLights(); // Update of light sources
708 if (isVisModeChanged)
710 // Change of context =>
711 // Remove structures that cannot be displayed in the new visualisation mode.
712 // It is not necessary to warn ViewManager as this structure should not disappear from
713 // the list of structures displayed in it.
714 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructs;
715 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
717 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
718 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
719 if (anAnswer == Visual3d_TOA_NO
720 || anAnswer == Visual3d_TOA_COMPUTE)
722 aStructs.Append (aStruct);
725 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
727 Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
731 // Change of context =>
732 // Display structures that can be displayed with the new visualisation mode.
733 // All structures with status Displayed are removed from the ViewManager
734 // and displayed in the view directly, if the structure is not already
735 // displayed and if the view accepts it in its context.
736 Graphic3d_MapOfStructure aMapDisplayed;
737 myViewManager->DisplayedStructures (aMapDisplayed);
738 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next())
740 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
741 if (IsDisplayed (aStruct))
746 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
747 if (anAnswer == Visual3d_TOA_YES
748 || anAnswer == Visual3d_TOA_COMPUTE)
750 aStructs.Append (aStruct);
754 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next())
756 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
760 Update (myViewManager->UpdateMode());
763 // =======================================================================
764 // function : Context
766 // =======================================================================
767 const Visual3d_ContextView& Visual3d_View::Context() const
772 // =======================================================================
773 // function : DisplayedStructures
775 // =======================================================================
776 void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const
783 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
785 theStructures.Add (aStructIter.Key());
789 // =======================================================================
790 // function : Activate
792 // =======================================================================
793 void Visual3d_View::Activate()
799 else if (!IsDefined())
801 Visual3d_ViewDefinitionError::Raise ("Window not defined");
806 myGraphicDriver->ActivateView (MyCView);
807 myGraphicDriver->Background (MyCView);
808 myGraphicDriver->Transparency (MyCView, myViewManager->Transparency());
812 // Activation of a new view =>
813 // Display structures that can be displayed in this new view.
814 // All structures with status
815 // Displayed in ViewManager are returned and displayed in
816 // the view directly, if the structure is not already
817 // displayed and if the view accepts it in its context.
818 Graphic3d_MapOfStructure aDisplayedStructs;
819 myViewManager->DisplayedStructures (aDisplayedStructs);
820 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
822 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
823 if (IsDisplayed (aStruct))
828 // If the structure can be displayed in the new context of the view, it is displayed.
829 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
830 if (anAnswer == Visual3d_TOA_YES
831 || anAnswer == Visual3d_TOA_COMPUTE)
833 Display (aStruct, Aspect_TOU_WAIT);
838 // If the activation/desactivation of ZBuffer should be automatic
839 // depending on the presence or absence of facets.
840 if (myViewManager->ZBufferAuto())
842 const Standard_Boolean containsFacet = ContainsFacet();
843 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
844 if (containsFacet && !hasZBuffer)
846 SetZBufferActivity (1); // If the view contains facets and if ZBuffer is not active
848 else if (!containsFacet && hasZBuffer)
850 SetZBufferActivity (0); // If the view does not contain facets and if ZBuffer is active
854 Update (myViewManager->UpdateMode());
857 // =======================================================================
858 // function : IsActive
860 // =======================================================================
861 Standard_Boolean Visual3d_View::IsActive() const
867 // =======================================================================
868 // function : Deactivate
870 // =======================================================================
871 void Visual3d_View::Deactivate()
877 else if (!IsDefined())
879 Visual3d_ViewDefinitionError::Raise ("Window not defined");
884 myGraphicDriver->DeactivateView (MyCView);
886 // Deactivation of a view =>
887 // Removal of structures displayed in this view.
888 // All structures with status
889 // Displayed in ViewManager are returned and removed from
890 // the view directly, if the structure is not already
891 // displayed and if the view accepts it in its context.
892 Graphic3d_MapOfStructure aDisplayedStructs;
893 myViewManager->DisplayedStructures (aDisplayedStructs);
894 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next())
896 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
897 if (IsDisplayed (aStruct))
902 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
903 if (anAnswer == Visual3d_TOA_YES
904 || anAnswer == Visual3d_TOA_COMPUTE)
906 Erase (aStruct, Aspect_TOU_WAIT);
910 Update (myViewManager->UpdateMode());
911 MyCView.Active = 0; // No action currently possible in the view
915 // =======================================================================
918 // =======================================================================
919 void Visual3d_View::Redraw()
921 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
924 // =======================================================================
927 // =======================================================================
928 void Visual3d_View::Redraw (const Standard_Integer theX,
929 const Standard_Integer theY,
930 const Standard_Integer theWidth,
931 const Standard_Integer theHeight)
933 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(),
934 theX, theY, theWidth, theHeight);
937 // =======================================================================
940 // =======================================================================
941 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
942 const Handle(Visual3d_Layer)& theOverLayer)
944 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
947 // =======================================================================
950 // =======================================================================
951 void Visual3d_View::Redraw (const Handle(Visual3d_Layer)& theUnderLayer,
952 const Handle(Visual3d_Layer)& theOverLayer,
953 const Standard_Integer theX,
954 const Standard_Integer theY,
955 const Standard_Integer theWidth,
956 const Standard_Integer theHeight)
961 || !MyWindow->IsMapped())
966 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
967 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
968 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
969 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
971 for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter)
973 if (myGraphicDriver->IsDeviceLost())
975 myViewManager->RecomputeStructures();
976 myViewManager->RecomputeStructures (myImmediateStructures);
977 myGraphicDriver->ResetDeviceLostFlag();
980 // set up Z buffer state before redrawing
981 if (myViewManager->ZBufferAuto())
983 const Standard_Boolean hasFacet = ContainsFacet();
984 const Standard_Boolean hasZBuffer = ZBufferIsActivated();
985 // if the view contains facets and if ZBuffer is not active
986 if (hasFacet && !hasZBuffer)
988 SetZBufferActivity (1);
990 // if the view contains only facets and if ZBuffer is active
991 if (!hasFacet && hasZBuffer)
993 SetZBufferActivity (0);
997 if (myStructuresUpdated)
1000 myStructuresUpdated = Standard_False;
1003 myGraphicDriver->Redraw (MyCView, anUnderCLayer, anOverCLayer, theX, theY, theWidth, theHeight);
1004 if (!myGraphicDriver->IsDeviceLost())
1011 // =======================================================================
1012 // function : RedrawImmediate
1014 // =======================================================================
1015 void Visual3d_View::RedrawImmediate()
1017 RedrawImmediate (myViewManager->UnderLayer(), myViewManager->OverLayer());
1020 // =======================================================================
1021 // function : RedrawImmediate
1023 // =======================================================================
1024 void Visual3d_View::RedrawImmediate (const Handle(Visual3d_Layer)& theUnderLayer,
1025 const Handle(Visual3d_Layer)& theOverLayer)
1030 || !MyWindow->IsMapped())
1035 Aspect_CLayer2d anOverCLayer, anUnderCLayer;
1036 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
1037 if (!theOverLayer .IsNull()) anOverCLayer = theOverLayer ->CLayer();
1038 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
1039 myGraphicDriver->RedrawImmediate (MyCView, anUnderCLayer, anOverCLayer);
1042 // =======================================================================
1043 // function : Invalidate
1045 // =======================================================================
1046 void Visual3d_View::Invalidate()
1048 myGraphicDriver->Invalidate (MyCView);
1051 // =======================================================================
1052 // function : Update
1054 // =======================================================================
1055 void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode)
1057 myStructuresUpdated = Standard_True;
1058 if (theUpdateMode == Aspect_TOU_ASAP)
1061 Redraw (myViewManager->UnderLayer(), myViewManager->OverLayer(), 0, 0, 0, 0);
1065 // =======================================================================
1066 // function : Update
1068 // =======================================================================
1069 void Visual3d_View::Update (const Handle(Visual3d_Layer)& theUnderLayer,
1070 const Handle(Visual3d_Layer)& theOverLayer)
1073 myStructuresUpdated = Standard_True;
1074 Redraw (theUnderLayer, theOverLayer, 0, 0, 0, 0);
1077 // ========================================================================
1078 // function : SetAutoZFitMode
1080 // ========================================================================
1081 void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn,
1082 const Standard_Real theScaleFactor)
1084 Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed.");
1085 myAutoZFitScaleFactor = theScaleFactor;
1086 myAutoZFitIsOn = theIsOn;
1089 // ========================================================================
1090 // function : AutoZFitMode
1092 // ========================================================================
1093 Standard_Boolean Visual3d_View::AutoZFitMode() const
1095 return myAutoZFitIsOn;
1098 // ========================================================================
1099 // function : AutoZFitScaleFactor
1101 // ========================================================================
1102 Standard_Real Visual3d_View::AutoZFitScaleFactor() const
1104 return myAutoZFitScaleFactor;
1107 // ========================================================================
1108 // function : AutoZFit
1110 // ========================================================================
1111 void Visual3d_View::AutoZFit()
1113 if (!AutoZFitMode())
1118 ZFitAll (myAutoZFitScaleFactor);
1121 // ========================================================================
1122 // function : ZFitAll
1124 // ========================================================================
1125 void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor)
1127 Bnd_Box aMinMaxBox = MinMaxValues (Standard_False); // applicative min max boundaries
1128 Bnd_Box aGraphicBox = MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag).
1130 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1131 aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox);
1134 // ========================================================================
1135 // function : AcceptDisplay
1137 // ========================================================================
1138 Visual3d_TypeOfAnswer Visual3d_View::AcceptDisplay (const Handle(Graphic3d_Structure)& theStruct) const
1140 const Visual3d_TypeOfVisualization ViewType = MyContext.Visualization();
1141 switch (theStruct->Visual())
1143 case Graphic3d_TOS_ALL:
1145 return Visual3d_TOA_YES; // The structure accepts any type of view
1147 case Graphic3d_TOS_SHADING:
1149 return ViewType == Visual3d_TOV_SHADING
1153 case Graphic3d_TOS_WIREFRAME:
1155 return ViewType == Visual3d_TOV_WIREFRAME
1159 case Graphic3d_TOS_COMPUTED:
1161 return (ViewType == Visual3d_TOV_SHADING || ViewType == Visual3d_TOV_WIREFRAME)
1162 ? Visual3d_TOA_COMPUTE
1166 return Visual3d_TOA_NO;
1169 // ========================================================================
1170 // function : ChangeDisplayPriority
1172 // ========================================================================
1173 void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct,
1174 const Standard_Integer /*theOldPriority*/,
1175 const Standard_Integer theNewPriority)
1180 || !IsDisplayed (theStruct))
1185 if (!myIsInComputedMode)
1187 myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority);
1191 const Standard_Integer anIndex = IsComputed (theStruct);
1192 const Graphic3d_CStructure& aCStruct = anIndex != 0
1193 ? *(myStructsComputed.Value (anIndex)->CStructure())
1194 : *theStruct->CStructure();
1195 myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority);
1198 // ========================================================================
1201 // ========================================================================
1202 void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct,
1203 const Standard_Boolean theWithDestruction)
1205 const Standard_Integer anIndex = IsComputed (theStruct);
1208 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
1209 aCompStruct->GraphicClear (theWithDestruction);
1210 aCompStruct->SetHLRValidation (Standard_False);
1214 // ========================================================================
1215 // function : Connect
1217 // ========================================================================
1218 void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother,
1219 const Handle(Graphic3d_Structure)& theDaughter)
1221 Standard_Integer anIndexM = IsComputed (theMother);
1222 Standard_Integer anIndexD = IsComputed (theDaughter);
1226 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1227 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1228 aStructM->GraphicConnect (aStructD);
1232 // ========================================================================
1233 // function : Disconnect
1235 // ========================================================================
1236 void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother,
1237 const Handle(Graphic3d_Structure)& theDaughter)
1239 Standard_Integer anIndexM = IsComputed (theMother);
1240 Standard_Integer anIndexD = IsComputed (theDaughter);
1244 const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM);
1245 const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD);
1246 aStructM->GraphicDisconnect (aStructD);
1250 // ========================================================================
1251 // function : DisplayImmediate
1253 // ========================================================================
1254 Standard_Boolean Visual3d_View::DisplayImmediate (const Handle(Graphic3d_Structure)& theStructure,
1255 const Standard_Boolean theIsSingleView)
1257 if (!myImmediateStructures.Add (theStructure))
1259 return Standard_False;
1262 if (theIsSingleView)
1264 Handle(Visual3d_HSequenceOfView) aViews = myViewManager->DefinedView();
1266 for (int i=1;i<=aViews->Length();i++)
1268 if (aViews->Value(i).Access() != this)
1270 aViews->Value(i)->EraseImmediate (theStructure);
1275 myGraphicDriver->DisplayImmediateStructure (MyCView, *theStructure->CStructure());
1276 return Standard_True;
1279 // ========================================================================
1280 // function : EraseImmediate
1282 // ========================================================================
1283 Standard_Boolean Visual3d_View::EraseImmediate (const Handle(Graphic3d_Structure)& theStructure)
1285 const Standard_Boolean isErased = myImmediateStructures.Remove (theStructure);
1288 myGraphicDriver->EraseImmediateStructure (MyCView, *theStructure->CStructure());
1294 // ========================================================================
1295 // function : ClearImmediate
1297 // ========================================================================
1298 Standard_Boolean Visual3d_View::ClearImmediate()
1300 if (myImmediateStructures.IsEmpty())
1302 return Standard_False;
1305 for (Graphic3d_MapIteratorOfMapOfStructure anIter (myImmediateStructures); anIter.More(); anIter.Next())
1307 myGraphicDriver->EraseImmediateStructure (MyCView, *anIter.Key()->CStructure());
1309 myImmediateStructures.Clear();
1310 return Standard_True;
1313 // ========================================================================
1314 // function : Display
1316 // ========================================================================
1317 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct)
1319 Display (theStruct, myViewManager->UpdateMode());
1322 // ========================================================================
1323 // function : Display
1325 // ========================================================================
1326 void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct,
1327 const Aspect_TypeOfUpdate theUpdateMode)
1336 // If Display on a structure present in the list of calculated structures while it is not
1337 // or more, of calculated type =>
1338 // - removes it as well as the associated old computed
1339 // THis happens when hlhsr becomes again of type e non computed after SetVisual.
1340 Standard_Integer anIndex = IsComputed (theStruct);
1342 && theStruct->Visual() != Graphic3d_TOS_COMPUTED)
1344 myStructsToCompute.Remove (anIndex);
1345 myStructsComputed .Remove (anIndex);
1349 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1350 if (anAnswer == Visual3d_TOA_NO)
1355 if (!ComputedMode())
1357 anAnswer = Visual3d_TOA_YES;
1360 if (anAnswer == Visual3d_TOA_YES)
1362 if (IsDisplayed (theStruct))
1367 theStruct->CalculateBoundBox();
1368 myGraphicDriver->DisplayStructure (MyCView, *theStruct->CStructure(), theStruct->DisplayPriority());
1369 myStructsDisplayed.Add (theStruct);
1370 Update (theUpdateMode);
1373 else if (anAnswer != Visual3d_TOA_COMPUTE)
1380 // Already computed, is COMPUTED still valid?
1381 const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex);
1382 if (anOldStruct->HLRValidation())
1384 // Case COMPUTED valid
1386 if (!IsDisplayed (theStruct))
1388 myStructsDisplayed.Add (theStruct);
1389 myGraphicDriver->DisplayStructure (MyCView, *anOldStruct->CStructure(), theStruct->DisplayPriority());
1390 Update (theUpdateMode);
1396 // Case COMPUTED invalid
1397 // Is there another valid representation?
1398 // Find in the sequence of already calculated structures
1399 // 1/ Structure having the same Owner as <AStructure>
1400 // 2/ That is not <AStructure>
1401 // 3/ The COMPUTED which of is valid
1402 const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct);
1405 // Case of COMPUTED invalid, WITH a valid of replacement
1407 if (!IsDisplayed (theStruct))
1409 const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
1410 myStructsComputed.SetValue (anIndex, aNewStruct);
1411 myStructsDisplayed.Add (theStruct);
1412 myGraphicDriver->DisplayStructure (MyCView, *aNewStruct->CStructure(), theStruct->DisplayPriority());
1413 Update (theUpdateMode);
1419 // Case COMPUTED invalid, WITHOUT a valid of replacement
1420 // COMPUTED is removed if displayed
1421 if (IsDisplayed (theStruct))
1423 myGraphicDriver->EraseStructure (MyCView, *anOldStruct->CStructure());
1429 // Compute + Validation
1430 Handle(Graphic3d_Structure) aStruct;
1431 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1432 theStruct->Transform (aTrsf);
1435 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1436 for (Standard_Integer ii = 0; ii <= 3; ++ii)
1438 for (Standard_Integer jj = 0; jj <= 3; ++jj)
1440 anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0);
1444 aStruct = myStructsComputed.Value (anIndex);
1445 aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1446 if (theStruct->IsTransformed())
1448 theStruct->Compute (this, aTrsf, aStruct);
1452 theStruct->Compute (this, aStruct);
1457 aStruct = theStruct->IsTransformed()
1458 ? theStruct->Compute (this, aTrsf)
1459 : theStruct->Compute (this);
1462 aStruct->SetHLRValidation (Standard_True);
1464 // TOCOMPUTE and COMPUTED associated to sequences are added
1465 myStructsToCompute.Append (theStruct);
1466 myStructsComputed .Append (aStruct);
1468 // The previous are removed if necessary
1471 myStructsToCompute.Remove (anIndex);
1472 myStructsComputed .Remove (anIndex);
1475 // Of which type will be the computed?
1476 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1477 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1478 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1479 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
1480 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1481 if (!toComputeShading && !toComputeWireframe)
1483 anAnswer = Visual3d_TOA_NO;
1487 aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING);
1488 anAnswer = AcceptDisplay (aStruct);
1491 if (theStruct->IsHighlighted())
1493 aStruct->SetHighlightColor (theStruct->HighlightColor());
1494 aStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1497 // It is displayed only if the calculated structure
1498 // has a proper type corresponding to the one of the view.
1499 if (anAnswer != Visual3d_TOA_NO)
1501 if (!IsDisplayed (theStruct))
1503 myStructsDisplayed.Add (theStruct);
1505 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), theStruct->DisplayPriority());
1506 Update (theUpdateMode);
1510 // ========================================================================
1513 // ========================================================================
1514 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct)
1518 Erase (theStruct, myViewManager->UpdateMode());
1522 // ========================================================================
1525 // ========================================================================
1526 void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct,
1527 const Aspect_TypeOfUpdate theUpdateMode)
1530 || !IsDisplayed (theStruct))
1535 Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1536 if (!ComputedMode())
1538 anAnswer = Visual3d_TOA_YES;
1541 if (anAnswer != Visual3d_TOA_COMPUTE)
1543 myGraphicDriver->EraseStructure (MyCView, *theStruct->CStructure());
1545 else if (anAnswer == Visual3d_TOA_COMPUTE
1546 && myIsInComputedMode)
1548 const Standard_Integer anIndex = IsComputed (theStruct);
1551 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1552 myGraphicDriver->EraseStructure (MyCView, *aCompStruct->CStructure());
1555 myStructsDisplayed.Remove (theStruct);
1556 Update (theUpdateMode);
1559 // ========================================================================
1560 // function : Highlight
1562 // ========================================================================
1563 void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct,
1564 const Aspect_TypeOfHighlightMethod theMethod)
1566 const Standard_Integer anIndex = IsComputed (theStruct);
1569 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1570 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1571 aCompStruct->GraphicHighlight (theMethod);
1575 // ========================================================================
1576 // function : SetTransform
1578 // ========================================================================
1579 void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct,
1580 const TColStd_Array2OfReal& theTrsf)
1582 const Standard_Integer anIndex = IsComputed (theStruct);
1585 // Test is somewhat light !
1586 // trsf is transferred only if it is :
1589 if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0
1590 || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0
1591 || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0)
1593 ReCompute (theStruct);
1597 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1598 aCompStruct->GraphicTransform (theTrsf);
1602 theStruct->CalculateBoundBox();
1603 if (!theStruct->IsMutable()
1604 && !theStruct->CStructure()->IsForHighlight
1605 && !theStruct->CStructure()->IsInfinite)
1607 const Standard_Integer aLayerId = theStruct->GetZLayer();
1608 myGraphicDriver->InvalidateBVHData (MyCView, aLayerId);
1612 // ========================================================================
1613 // function : UnHighlight
1615 // ========================================================================
1616 void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct)
1618 Standard_Integer anIndex = IsComputed (theStruct);
1621 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex);
1622 aCompStruct->GraphicUnHighlight();
1626 // ========================================================================
1627 // function : IsComputed
1629 // ========================================================================
1630 Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const
1632 const Standard_Integer aStructId = theStruct->Identification();
1633 const Standard_Integer aNbStructs = myStructsToCompute.Length();
1634 for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter)
1636 const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter);
1637 if (aStruct->Identification() == aStructId)
1645 // ========================================================================
1646 // function : IsDisplayed
1648 // ========================================================================
1649 Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const
1652 && myStructsDisplayed.Contains (theStruct);
1655 // ========================================================================
1656 // function : ContainsFacet
1658 // ========================================================================
1659 Standard_Boolean Visual3d_View::ContainsFacet() const
1661 return ContainsFacet (myStructsDisplayed);
1664 // ========================================================================
1665 // function : ContainsFacet
1667 // ========================================================================
1668 Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const
1670 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
1672 if (aStructIter.Key()->ContainsFacet())
1674 return Standard_True;
1677 return Standard_False;
1680 // ========================================================================
1681 // function : MinMaxValues
1683 // ========================================================================
1684 Bnd_Box Visual3d_View::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
1686 return MinMaxValues (myStructsDisplayed,
1687 theToIgnoreInfiniteFlag);
1690 // ========================================================================
1691 // function : MinMaxValues
1693 // ========================================================================
1694 Bnd_Box Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
1695 const Standard_Boolean theToIgnoreInfiniteFlag) const
1698 if (theSet.IsEmpty ())
1700 // Return an empty box.
1703 Graphic3d_MapIteratorOfMapOfStructure anIterator (theSet);
1704 for (anIterator.Initialize (theSet); anIterator.More(); anIterator.Next())
1706 const Handle(Graphic3d_Structure)& aStructure = anIterator.Key();
1708 if (!aStructure->IsVisible())
1711 if (aStructure->IsInfinite() && !theToIgnoreInfiniteFlag)
1713 //XMin, YMin .... ZMax are initialized by means of infinite line data
1714 Bnd_Box aBox = aStructure->MinMaxValues (Standard_False);
1715 if (!aBox.IsWhole() && !aBox.IsVoid())
1721 // Only non-empty and non-infinite structures
1722 // are taken into account for calculation of MinMax
1723 if ((!aStructure->IsInfinite() || theToIgnoreInfiniteFlag) && !aStructure->IsEmpty())
1725 Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
1727 /* ABD 29/10/04 Transform Persistence of Presentation( pan, zoom, rotate ) */
1728 //"FitAll" operation ignores object with transform persitence parameter
1729 if(aStructure->TransformPersistenceMode() == Graphic3d_TMF_None )
1738 // =======================================================================
1739 // function : NumberOfDisplayedStructures
1741 // =======================================================================
1742 Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const
1744 return myStructsDisplayed.Extent();
1747 // =======================================================================
1748 // function : Projects
1750 // =======================================================================
1751 void Visual3d_View::Projects (const Standard_Real theX,
1752 const Standard_Real theY,
1753 const Standard_Real theZ,
1754 Standard_Real& thePX,
1755 Standard_Real& thePY,
1756 Standard_Real& thePZ) const
1758 const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera;
1760 gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions();
1761 Standard_Real aXSize = aViewSpaceDimensions.X();
1762 Standard_Real aYSize = aViewSpaceDimensions.Y();
1763 Standard_Real aZSize = aViewSpaceDimensions.Z();
1765 gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ));
1767 // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ]
1768 thePX = aPoint.X() * aXSize * 0.5;
1769 thePY = aPoint.Y() * aYSize * 0.5;
1770 thePZ = aPoint.Z() * aZSize * 0.5;
1773 // =======================================================================
1774 // function : Identification
1776 // =======================================================================
1777 Standard_Integer Visual3d_View::Identification() const
1779 return MyCView.ViewId;
1782 // =======================================================================
1783 // function : ZBufferIsActivated
1785 // =======================================================================
1786 Standard_Boolean Visual3d_View::ZBufferIsActivated() const
1792 return Standard_False;
1795 if (MyCView.Context.ZBufferActivity == -1)
1797 // not forced by the programmer => depends on the type of visualisation
1798 return MyContext.Visualization () == Visual3d_TOV_SHADING;
1800 return MyCView.Context.ZBufferActivity != 0; // 0 or 1 => forced by the programmer
1803 // =======================================================================
1804 // function : SetTransparency
1806 // =======================================================================
1807 void Visual3d_View::SetTransparency (const Standard_Boolean theActivity)
1816 myGraphicDriver->Transparency (MyCView, theActivity);
1819 // =======================================================================
1820 // function : SetZBufferActivity
1822 // =======================================================================
1823 void Visual3d_View::SetZBufferActivity (const Standard_Integer theActivity)
1826 || MyCView.Context.ZBufferActivity == theActivity
1833 MyCView.Context.ZBufferActivity = theActivity;
1834 myGraphicDriver->SetVisualisation (MyCView);
1837 // =======================================================================
1838 // function : UpdateView
1840 // =======================================================================
1841 void Visual3d_View::UpdateView()
1843 MyCView.Context.Aliasing = MyContext.AliasingIsOn();
1844 MyCView.Context.BackZClipping = MyContext.BackZClippingIsOn();
1845 MyCView.Context.FrontZClipping = MyContext.FrontZClippingIsOn();
1846 MyCView.Context.DepthCueing = MyContext.DepthCueingIsOn();
1848 MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane());
1849 MyCView.Context.ZClipBackPlane = float (MyContext.ZClippingBackPlane());
1850 MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane());
1851 MyCView.Context.DepthBackPlane = float (MyContext.DepthCueingBackPlane());
1853 MyCView.Context.Model = MyContext.Model();
1854 MyCView.Context.Visualization = MyContext.Visualization();
1856 MyCView.Context.TextureEnv = MyContext.TextureEnv();
1857 MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail();
1860 // =======================================================================
1861 // function : Compute
1863 // =======================================================================
1864 void Visual3d_View::Compute()
1866 // force HLRValidation to False on all structures calculated in the view
1867 const Standard_Integer aNbCompStructs = myStructsComputed.Length();
1868 for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter)
1870 myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False);
1873 if (!ComputedMode())
1878 // Change of orientation or of projection type =>
1879 // Remove structures that were calculated for the previous orientation.
1880 // Recalculation of new structures.
1881 NCollection_Sequence<Handle(Graphic3d_Structure)> aStructsSeq;
1882 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
1884 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStructIter.Key());
1885 if (anAnswer == Visual3d_TOA_COMPUTE)
1887 aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated
1891 for (NCollection_Sequence<Handle(Graphic3d_Structure)>::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next())
1893 Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT);
1897 // =======================================================================
1898 // function : ReCompute
1900 // =======================================================================
1901 void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
1903 theStruct->CalculateBoundBox();
1904 if (!theStruct->IsMutable()
1905 && !theStruct->CStructure()->IsForHighlight
1906 && !theStruct->CStructure()->IsInfinite)
1908 const Standard_Integer aLayerId = theStruct->DisplayPriority();
1909 myGraphicDriver->InvalidateBVHData(MyCView, aLayerId);
1916 || !MyWindow->IsMapped()
1917 || !theStruct->IsDisplayed())
1922 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (theStruct);
1923 if (anAnswer != Visual3d_TOA_COMPUTE)
1928 const Standard_Integer anIndex = IsComputed (theStruct);
1934 // compute + validation
1935 TColStd_Array2OfReal anIdent (0, 3, 0, 3);
1936 for (Standard_Integer aRow = 0; aRow <= 3; ++aRow)
1938 for (Standard_Integer aCol = 0; aCol <= 3; ++aCol)
1940 anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0);
1943 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
1944 theStruct->Transform (aTrsf);
1946 Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex);
1947 Handle(Graphic3d_Structure) aCompStruct = aCompStructOld;
1948 aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE);
1949 theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct)
1950 : theStruct->Compute (this, aCompStruct);
1951 aCompStruct->SetHLRValidation (Standard_True);
1953 // of which type will be the computed?
1954 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
1955 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
1956 && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
1957 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
1958 && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
1959 if (toComputeWireframe)
1961 aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
1963 else if (toComputeShading)
1965 aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
1968 if (theStruct->IsHighlighted())
1970 aCompStruct->SetHighlightColor (theStruct->HighlightColor());
1971 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
1974 // The previous calculation is removed and the new one is dislayed
1975 myGraphicDriver->EraseStructure (MyCView, *aCompStructOld->CStructure());
1976 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), theStruct->DisplayPriority());
1978 // why not just replace existing items?
1979 //myStructsToCompute.ChangeValue (anIndex) = theStruct;
1980 //myStructsComputed .ChangeValue (anIndex) = aCompStruct;
1982 // hlhsr and the new associated compute are added
1983 myStructsToCompute.Append (theStruct);
1984 myStructsComputed .Append (aCompStruct);
1986 // hlhsr and the new associated compute are removed
1987 myStructsToCompute.Remove (anIndex);
1988 myStructsComputed .Remove (anIndex);
1991 // =======================================================================
1992 // function : GraphicDriver
1994 // =======================================================================
1995 const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const
1997 return myGraphicDriver;
2000 // =======================================================================
2001 // function : HaveTheSameOwner
2003 // =======================================================================
2004 Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const
2006 // Find in the sequence of already calculated structures
2007 // 1/ Structure with the same Owner as <AStructure>
2008 // 2/ Which is not <AStructure>
2009 // 3/ COMPUTED which of is valid
2010 const Standard_Integer aNbToCompStructs = myStructsToCompute.Length();
2011 for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter)
2013 const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter);
2014 if (aStructToComp->Owner() == theStruct->Owner()
2015 && aStructToComp->Identification() != theStruct->Identification())
2017 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter);
2018 if (aStructComp->HLRValidation())
2027 // =======================================================================
2030 // =======================================================================
2031 Standard_Address Visual3d_View::CView() const
2033 return Standard_Address (&MyCView);
2036 // =======================================================================
2037 // function : ZBufferTriedronSetup
2039 // =======================================================================
2040 void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor,
2041 const Quantity_NameOfColor theYColor,
2042 const Quantity_NameOfColor theZColor,
2043 const Standard_Real theSizeRatio,
2044 const Standard_Real theAxisDiametr,
2045 const Standard_Integer theNbFacettes)
2047 myGraphicDriver->ZBufferTriedronSetup (theXColor, theYColor, theZColor,
2048 theSizeRatio, theAxisDiametr, theNbFacettes);
2051 // =======================================================================
2052 // function : TriedronDisplay
2054 // =======================================================================
2055 void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition,
2056 const Quantity_NameOfColor theColor,
2057 const Standard_Real theScale,
2058 const Standard_Boolean theAsWireframe)
2060 myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe);
2063 // =======================================================================
2064 // function : TriedronErase
2066 // =======================================================================
2067 void Visual3d_View::TriedronErase()
2069 myGraphicDriver->TriedronErase (MyCView);
2072 // =======================================================================
2073 // function : TriedronEcho
2075 // =======================================================================
2076 void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType)
2078 myGraphicDriver->TriedronEcho (MyCView, theType);
2081 static void SetMinMaxValuesCallback (Visual3d_View* theView)
2083 Bnd_Box aBox = theView->MinMaxValues();
2086 gp_Pnt aMin = aBox.CornerMin();
2087 gp_Pnt aMax = aBox.CornerMax();
2088 const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver();
2089 aDriver->GraduatedTrihedronMinMaxValues ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z(),
2090 (Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z());
2094 // =======================================================================
2095 // function : GetGraduatedTrihedron
2097 // =======================================================================
2098 Standard_Boolean Visual3d_View::GetGraduatedTrihedron (TCollection_ExtendedString& theXName,
2099 TCollection_ExtendedString& theYName,
2100 TCollection_ExtendedString& theZName,
2101 Standard_Boolean& theToDrawXName,
2102 Standard_Boolean& theToDrawYName,
2103 Standard_Boolean& theToDrawZName,
2104 Standard_Boolean& theToDrawXValues,
2105 Standard_Boolean& theToDrawYValues,
2106 Standard_Boolean& theToDrawZValues,
2107 Standard_Boolean& theToDrawGrid,
2108 Standard_Boolean& theToDrawAxes,
2109 Standard_Integer& theNbX,
2110 Standard_Integer& theNbY,
2111 Standard_Integer& theNbZ,
2112 Standard_Integer& theXOffset,
2113 Standard_Integer& theYOffset,
2114 Standard_Integer& theZOffset,
2115 Standard_Integer& theXAxisOffset,
2116 Standard_Integer& theYAxisOffset,
2117 Standard_Integer& theZAxisOffset,
2118 Standard_Boolean& theToDrawXTickMarks,
2119 Standard_Boolean& theToDrawYTickMarks,
2120 Standard_Boolean& theToDrawZTickMarks,
2121 Standard_Integer& theXTickMarkLength,
2122 Standard_Integer& theYTickMarkLength,
2123 Standard_Integer& theZTickMarkLength,
2124 Quantity_Color& theGridColor,
2125 Quantity_Color& theXNameColor,
2126 Quantity_Color& theYNameColor,
2127 Quantity_Color& theZNameColor,
2128 Quantity_Color& theXColor,
2129 Quantity_Color& theYColor,
2130 Quantity_Color& theZColor,
2131 TCollection_AsciiString& theFontOfNames,
2132 Font_FontAspect& theStyleOfNames,
2133 Standard_Integer& theSizeOfNames,
2134 TCollection_AsciiString& theFontOfValues,
2135 Font_FontAspect& theStyleOfValues,
2136 Standard_Integer& theSizeOfValues) const
2138 if (!MyGTrihedron.ptrVisual3dView)
2140 return Standard_False;
2143 theXName = MyGTrihedron.xname;
2144 theYName = MyGTrihedron.yname;
2145 theZName = MyGTrihedron.zname;
2146 theToDrawXName = MyGTrihedron.xdrawname;
2147 theToDrawYName = MyGTrihedron.ydrawname;
2148 theToDrawZName = MyGTrihedron.zdrawname;
2149 theToDrawXValues = MyGTrihedron.xdrawvalues;
2150 theToDrawYValues = MyGTrihedron.ydrawvalues;
2151 theToDrawZValues = MyGTrihedron.zdrawvalues;
2152 theToDrawGrid = MyGTrihedron.drawgrid;
2153 theToDrawAxes = MyGTrihedron.drawaxes;
2154 theNbX = MyGTrihedron.nbx;
2155 theNbY = MyGTrihedron.nby;
2156 theNbZ = MyGTrihedron.nbz;
2157 theXOffset = MyGTrihedron.xoffset;
2158 theYOffset = MyGTrihedron.yoffset;
2159 theZOffset = MyGTrihedron.zoffset;
2160 theXAxisOffset = MyGTrihedron.xaxisoffset;
2161 theYAxisOffset = MyGTrihedron.yaxisoffset;
2162 theZAxisOffset = MyGTrihedron.zaxisoffset;
2163 theToDrawXTickMarks = MyGTrihedron.xdrawtickmarks;
2164 theToDrawYTickMarks = MyGTrihedron.ydrawtickmarks;
2165 theToDrawZTickMarks = MyGTrihedron.zdrawtickmarks;
2166 theXTickMarkLength = MyGTrihedron.xtickmarklength;
2167 theYTickMarkLength = MyGTrihedron.ytickmarklength;
2168 theZTickMarkLength = MyGTrihedron.ztickmarklength;
2169 theGridColor = MyGTrihedron.gridcolor;
2170 theXNameColor = MyGTrihedron.xnamecolor;
2171 theYNameColor = MyGTrihedron.ynamecolor;
2172 theZNameColor = MyGTrihedron.znamecolor;
2173 theXColor = MyGTrihedron.xcolor;
2174 theYColor = MyGTrihedron.ycolor;
2175 theZColor = MyGTrihedron.zcolor;
2176 theFontOfNames = MyGTrihedron.fontOfNames;
2177 theStyleOfNames = MyGTrihedron.styleOfNames;
2178 theSizeOfNames = MyGTrihedron.sizeOfNames;
2179 theFontOfValues = MyGTrihedron.fontOfValues;
2180 theStyleOfValues = MyGTrihedron.styleOfValues;
2181 theSizeOfValues = MyGTrihedron.sizeOfValues;
2182 return Standard_True;
2185 // =======================================================================
2186 // function : GraduatedTrihedronDisplay
2188 // =======================================================================
2189 void Visual3d_View::GraduatedTrihedronDisplay (const TCollection_ExtendedString& theXName,
2190 const TCollection_ExtendedString& theYName,
2191 const TCollection_ExtendedString& theZName,
2192 const Standard_Boolean theToDrawXName,
2193 const Standard_Boolean theToDrawYName,
2194 const Standard_Boolean theToDrawZName,
2195 const Standard_Boolean theToDrawXValues,
2196 const Standard_Boolean theToDrawYValues,
2197 const Standard_Boolean theToDrawZValues,
2198 const Standard_Boolean theToDrawGrid,
2199 const Standard_Boolean theToDrawAxes,
2200 const Standard_Integer theNbX,
2201 const Standard_Integer theNbY,
2202 const Standard_Integer theNbZ,
2203 const Standard_Integer theXOffset,
2204 const Standard_Integer theYOffset,
2205 const Standard_Integer theZOffset,
2206 const Standard_Integer theXAxisOffset,
2207 const Standard_Integer theYAxisOffset,
2208 const Standard_Integer theZAxisOffset,
2209 const Standard_Boolean theToDrawXTickMarks,
2210 const Standard_Boolean theToDrawYTickMarks,
2211 const Standard_Boolean theToDrawZTickMarks,
2212 const Standard_Integer theXTickMarkLength,
2213 const Standard_Integer theYTickMarkLength,
2214 const Standard_Integer theZTickMarkLength,
2215 const Quantity_Color& theGridColor,
2216 const Quantity_Color& theXNameColor,
2217 const Quantity_Color& theYNameColor,
2218 const Quantity_Color& theZNameColor,
2219 const Quantity_Color& theXColor,
2220 const Quantity_Color& theYColor,
2221 const Quantity_Color& theZColor,
2222 const TCollection_AsciiString& theFontOfNames,
2223 const Font_FontAspect theStyleOfNames,
2224 const Standard_Integer theSizeOfNames,
2225 const TCollection_AsciiString& theFontOfValues,
2226 const Font_FontAspect theStyleOfValues,
2227 const Standard_Integer theSizeOfValues)
2229 MyGTrihedron.xname = theXName;
2230 MyGTrihedron.yname = theYName;
2231 MyGTrihedron.zname = theZName;
2232 MyGTrihedron.xdrawname = theToDrawXName;
2233 MyGTrihedron.ydrawname = theToDrawYName;
2234 MyGTrihedron.zdrawname = theToDrawZName;
2235 MyGTrihedron.xdrawvalues = theToDrawXValues;
2236 MyGTrihedron.ydrawvalues = theToDrawYValues;
2237 MyGTrihedron.zdrawvalues = theToDrawZValues;
2238 MyGTrihedron.drawgrid = theToDrawGrid;
2239 MyGTrihedron.drawaxes = theToDrawAxes;
2240 MyGTrihedron.nbx = theNbX;
2241 MyGTrihedron.nby = theNbY;
2242 MyGTrihedron.nbz = theNbZ;
2243 MyGTrihedron.xoffset = theXOffset;
2244 MyGTrihedron.yoffset = theYOffset;
2245 MyGTrihedron.zoffset = theZOffset;
2246 MyGTrihedron.xaxisoffset = theXAxisOffset;
2247 MyGTrihedron.yaxisoffset = theYAxisOffset;
2248 MyGTrihedron.zaxisoffset = theZAxisOffset;
2249 MyGTrihedron.xdrawtickmarks = theToDrawXTickMarks;
2250 MyGTrihedron.ydrawtickmarks = theToDrawYTickMarks;
2251 MyGTrihedron.zdrawtickmarks = theToDrawZTickMarks;
2252 MyGTrihedron.xtickmarklength = theXTickMarkLength;
2253 MyGTrihedron.ytickmarklength = theYTickMarkLength;
2254 MyGTrihedron.ztickmarklength = theZTickMarkLength;
2255 MyGTrihedron.gridcolor = theGridColor;
2256 MyGTrihedron.xnamecolor = theXNameColor;
2257 MyGTrihedron.ynamecolor = theYNameColor;
2258 MyGTrihedron.znamecolor = theZNameColor;
2259 MyGTrihedron.xcolor = theXColor;
2260 MyGTrihedron.ycolor = theYColor;
2261 MyGTrihedron.zcolor = theZColor;
2262 MyGTrihedron.fontOfNames = theFontOfNames;
2263 MyGTrihedron.styleOfNames = theStyleOfNames;
2264 MyGTrihedron.sizeOfNames = theSizeOfNames;
2265 MyGTrihedron.fontOfValues = theFontOfValues;
2266 MyGTrihedron.styleOfValues = theStyleOfValues;
2267 MyGTrihedron.sizeOfValues = theSizeOfValues;
2269 MyGTrihedron.ptrVisual3dView = this;
2270 MyGTrihedron.cbCubicAxes = SetMinMaxValuesCallback;
2271 myGraphicDriver->GraduatedTrihedronDisplay (MyCView, MyGTrihedron);
2274 // =======================================================================
2275 // function : GraduatedTrihedronErase
2277 // =======================================================================
2278 void Visual3d_View::GraduatedTrihedronErase()
2280 MyGTrihedron.ptrVisual3dView = NULL;
2281 myGraphicDriver->GraduatedTrihedronErase (MyCView);
2284 // =======================================================================
2285 // function : UnderLayer
2287 // =======================================================================
2288 const Handle(Visual3d_Layer)& Visual3d_View::UnderLayer() const
2290 return myViewManager->UnderLayer();
2293 // =======================================================================
2294 // function : OverLayer
2296 // =======================================================================
2297 const Handle(Visual3d_Layer)& Visual3d_View::OverLayer() const
2299 return myViewManager->OverLayer();
2302 // =======================================================================
2303 // function : LightLimit
2305 // =======================================================================
2306 Standard_Integer Visual3d_View::LightLimit() const
2308 return myGraphicDriver->InquireLightLimit();
2311 // =======================================================================
2312 // function : PlaneLimit
2314 // =======================================================================
2315 Standard_Integer Visual3d_View::PlaneLimit() const
2317 return myGraphicDriver->InquirePlaneLimit();
2320 // =======================================================================
2321 // function : ViewManager
2323 // =======================================================================
2324 Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const
2326 return myViewManager;
2329 // =======================================================================
2330 // function : SetComputedMode
2332 // =======================================================================
2333 void Visual3d_View::SetComputedMode (const Standard_Boolean theMode)
2335 if (( theMode && myIsInComputedMode)
2336 || (!theMode && !myIsInComputedMode))
2341 myIsInComputedMode = theMode;
2342 if (!myIsInComputedMode)
2344 for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next())
2346 const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key();
2347 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2348 if (anAnswer != Visual3d_TOA_COMPUTE)
2353 const Standard_Integer anIndex = IsComputed (aStruct);
2356 const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex);
2357 myGraphicDriver->EraseStructure (MyCView, *aStructComp->CStructure());
2358 myGraphicDriver->DisplayStructure (MyCView, *aStruct->CStructure(), aStruct->DisplayPriority());
2364 for (Graphic3d_MapIteratorOfMapOfStructure aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next())
2366 Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key();
2367 const Visual3d_TypeOfAnswer anAnswer = AcceptDisplay (aStruct);
2368 if (anAnswer != Visual3d_TOA_COMPUTE)
2373 const Standard_Integer anIndex = IsComputed (aStruct);
2376 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2377 myGraphicDriver->DisplayStructure (MyCView, *(myStructsComputed.Value (anIndex)->CStructure()), aStruct->DisplayPriority());
2379 Display (aStruct, Aspect_TOU_WAIT);
2380 if (aStruct->IsHighlighted())
2382 const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex);
2383 if (!aCompStruct->IsHighlighted())
2385 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2386 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2392 TColStd_Array2OfReal aTrsf (0, 3, 0, 3);
2393 aStruct->Transform (aTrsf);
2394 Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this);
2395 aCompStruct->SetHLRValidation (Standard_True);
2397 const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization();
2398 const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME
2399 && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING;
2400 const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING
2401 && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME;
2402 if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME);
2403 if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING);
2405 if (aStruct->IsHighlighted())
2407 aCompStruct->SetHighlightColor (aStruct->HighlightColor());
2408 aCompStruct->GraphicHighlight (Aspect_TOHM_COLOR);
2411 Standard_Boolean hasResult = Standard_False;
2412 const Standard_Integer aNbToCompute = myStructsToCompute.Length();
2413 const Standard_Integer aStructId = aStruct->Identification();
2414 for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter)
2416 if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId)
2418 hasResult = Standard_True;
2419 myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct;
2426 myStructsToCompute.Append (aStruct);
2427 myStructsComputed .Append (aCompStruct);
2430 myGraphicDriver->EraseStructure (MyCView, *aStruct->CStructure());
2431 myGraphicDriver->DisplayStructure (MyCView, *aCompStruct->CStructure(), aStruct->DisplayPriority());
2434 Update (myViewManager->UpdateMode());
2437 // =======================================================================
2438 // function : ComputedMode
2440 // =======================================================================
2441 Standard_Boolean Visual3d_View::ComputedMode() const
2443 return myIsInComputedMode;
2446 // =======================================================================
2447 // function : SetBackFacingModel
2449 // =======================================================================
2450 void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel)
2455 case Visual3d_TOBM_AUTOMATIC:
2456 MyCView.Backfacing = 0;
2458 case Visual3d_TOBM_FORCE:
2459 MyCView.Backfacing = 1;
2461 case Visual3d_TOBM_DISABLE:
2462 MyCView.Backfacing = -1;
2465 myGraphicDriver->SetBackFacingModel (MyCView);
2468 // =======================================================================
2469 // function : BackFacingModel
2471 // =======================================================================
2472 Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const
2474 switch (MyCView.Backfacing)
2476 case 0: return Visual3d_TOBM_AUTOMATIC;
2477 case 1: return Visual3d_TOBM_FORCE;
2479 return Visual3d_TOBM_DISABLE;
2482 // =======================================================================
2483 // function : EnableDepthTest
2485 // =======================================================================
2486 void Visual3d_View::EnableDepthTest (const Standard_Boolean theToEnable) const
2488 myGraphicDriver->SetDepthTestEnabled (MyCView, theToEnable);
2491 // =======================================================================
2492 // function : IsDepthTestEnabled
2494 // =======================================================================
2495 Standard_Boolean Visual3d_View::IsDepthTestEnabled() const
2497 return myGraphicDriver->IsDepthTestEnabled (MyCView);
2500 // =======================================================================
2501 // function : ReadDepths
2503 // =======================================================================
2504 void Visual3d_View::ReadDepths (const Standard_Integer theX,
2505 const Standard_Integer theY,
2506 const Standard_Integer theWidth,
2507 const Standard_Integer theHeight,
2508 const Standard_Address theBuffer) const
2510 myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer);
2513 // =======================================================================
2514 // function : FBOCreate
2516 // =======================================================================
2517 Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth,
2518 const Standard_Integer theHeight)
2520 return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight );
2523 // =======================================================================
2524 // function : FBORelease
2526 // =======================================================================
2527 void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr)
2529 myGraphicDriver->FBORelease( MyCView, theFBOPtr );
2532 // =======================================================================
2533 // function : FBOGetDimensions
2535 // =======================================================================
2536 void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr,
2537 Standard_Integer& theWidth, Standard_Integer& theHeight,
2538 Standard_Integer& theWidthMax, Standard_Integer& theHeightMax)
2540 myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr,
2541 theWidth, theHeight,
2542 theWidthMax, theHeightMax );
2545 // =======================================================================
2546 // function : FBOChangeViewport
2548 // =======================================================================
2549 void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr,
2550 const Standard_Integer theWidth, const Standard_Integer theHeight)
2552 myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr,
2553 theWidth, theHeight );
2556 // =======================================================================
2557 // function : BufferDump
2559 // =======================================================================
2560 Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage,
2561 const Graphic3d_BufferType& theBufferType)
2563 return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType);
2566 // =======================================================================
2567 // function : EnableGLLight
2569 // =======================================================================
2570 void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const
2572 myGraphicDriver->SetGLLightEnabled( MyCView, enable );
2575 // =======================================================================
2576 // function : IsGLLightEnabled
2578 // =======================================================================
2579 Standard_Boolean Visual3d_View::IsGLLightEnabled() const
2581 return myGraphicDriver->IsGLLightEnabled( MyCView );
2584 // =======================================================================
2585 // function : Export
2587 // =======================================================================
2588 Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName,
2589 const Graphic3d_ExportFormat theFormat,
2590 const Graphic3d_SortType theSortType,
2591 const Standard_Real thePrecision,
2592 const Standard_Address theProgressBarFunc,
2593 const Standard_Address theProgressObject) const
2595 Handle(Visual3d_Layer) anUnderLayer = myViewManager->UnderLayer();
2596 Handle(Visual3d_Layer) anOverLayer = myViewManager->OverLayer();
2598 Aspect_CLayer2d anOverCLayer;
2599 Aspect_CLayer2d anUnderCLayer;
2600 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2602 if (!anOverLayer.IsNull())
2603 anOverCLayer = anOverLayer->CLayer();
2604 if (!anUnderLayer.IsNull())
2605 anUnderCLayer = anUnderLayer->CLayer();
2607 Standard_Integer aWidth, aHeight;
2608 Window()->Size (aWidth, aHeight);
2610 return myGraphicDriver->Export (theFileName, theFormat, theSortType,
2611 aWidth, aHeight, MyCView, anUnderCLayer, anOverCLayer,
2612 thePrecision, theProgressBarFunc, theProgressObject);
2615 // =======================================================================
2616 // function : SetZLayerSettings
2618 // =======================================================================
2619 void Visual3d_View::SetZLayerSettings (const Standard_Integer theLayerId,
2620 const Graphic3d_ZLayerSettings& theSettings)
2622 myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings);
2625 // =======================================================================
2626 // function : AddZLayer
2628 // =======================================================================
2629 void Visual3d_View::AddZLayer (const Standard_Integer theLayerId)
2631 myGraphicDriver->AddZLayer (MyCView, theLayerId);
2634 // =======================================================================
2635 // function : RemoveZLayer
2637 // =======================================================================
2638 void Visual3d_View::RemoveZLayer (const Standard_Integer theLayerId)
2640 myGraphicDriver->RemoveZLayer (MyCView, theLayerId);
2643 // =======================================================================
2644 // function : ChangeZLayer
2646 // =======================================================================
2647 void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure,
2648 const Standard_Integer theLayerId)
2650 myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId);
2653 // =======================================================================
2656 // =======================================================================
2657 Standard_Boolean Visual3d_View::Print (const Aspect_Handle thePrintDC,
2658 const Standard_Boolean theToShowBackground,
2659 const Standard_CString theFilename,
2660 const Aspect_PrintAlgo thePrintAlgorithm,
2661 const Standard_Real theScaleFactor) const
2663 return Print (myViewManager->UnderLayer(),
2664 myViewManager->OverLayer(),
2665 thePrintDC, theToShowBackground,
2666 theFilename, thePrintAlgorithm,
2670 // =======================================================================
2673 // =======================================================================
2674 Standard_Boolean Visual3d_View::Print (const Handle(Visual3d_Layer)& theUnderLayer,
2675 const Handle(Visual3d_Layer)& theOverLayer,
2676 const Aspect_Handle thePrintDC,
2677 const Standard_Boolean theToShowBackground,
2678 const Standard_CString theFilename,
2679 const Aspect_PrintAlgo thePrintAlgorithm,
2680 const Standard_Real theScaleFactor) const
2685 || !MyWindow->IsMapped())
2687 return Standard_False;
2690 Aspect_CLayer2d anOverCLayer;
2691 Aspect_CLayer2d anUnderCLayer;
2692 anOverCLayer.ptrLayer = anUnderCLayer.ptrLayer = NULL;
2693 if (!theOverLayer.IsNull()) anOverCLayer = theOverLayer->CLayer();
2694 if (!theUnderLayer.IsNull()) anUnderCLayer = theUnderLayer->CLayer();
2695 return myGraphicDriver->Print (MyCView, anUnderCLayer, anOverCLayer,
2696 thePrintDC, theToShowBackground, theFilename,
2697 thePrintAlgorithm, theScaleFactor);