From c357e42610e01960a257dcbd4890ab5c6a2bf144 Mon Sep 17 00:00:00 2001 From: apl Date: Tue, 22 Sep 2015 11:49:33 +0300 Subject: [PATCH] 0024776: Visualization - inherit OpenGl_View from Graphic3d_CView Expose interface of OpenGl_View (OpenGL graphics rendering methods) to client code and collecting all high-level API methods of application views in V3d_View class. 1) Exposing interface of OpenGl_View: The OpenGl_View inherits from new class Graphic3d_CView. Graphic3d_CView is an interface class that declares abstract methods for managing displayed structures, display properties and a base layer code that implements computation and management of HLR (or more broadly speaking view-depended) structures. In new implementation it takes place of eliminated Visual3d_View. As before the instance of Graphic3d_CView is still completely managed by V3d_View classes. It can be accessed through V3d_View interface but normally this should not be required as all its methods are completely wrapped. In more details, a concrete specialization of Graphic3d_CView is created and returned by graphical driver on request. Right after creation the views is directly used for setting rendering properties and adding graphical structures to be displayed. The rendering of graphics is possible after mapping a window and activating the view. The direct setting of properties makes obsolete usage of intermediate structures with display parameter like Visual3d_ContextView and etc (the whole package of Visual3d become redundant). 2) Collecting all high-level API methods of application views in V3d package: The patch includes elimination of Visual3d layer. All of its methods that could be previously used by application are now exposed and should be accessed on the level of V3d entities. - Introduced new class Graphic3d_CView. This is a base class for render views. Made possible to specialize concrete instances of the class by graphical driver. - Moved all methods managing rendering views into interface of Graphic3d_CView. The corresponding methods were removed from interface of graphical driver. 3) Eliminated Visual3d package: - Logic of managing display of structures was put from Visual3d_ViewManager into Graphic3d_StructureManager. - Removed Visual3d_View class. Logic of managing computed structures was put into base layer of Graphi3d_CView. - Removed all intermediate structures for storing view parameters e.g. Visual3d_ContextView. All settings are kept by instances of Graphic3d_CView - Removed Visual3d_Light intermediate class. All light properties are still stored in Graphic3d_CLight structure. The structure is directly access by instance of V3d_Light classes. - Moved all needed enumerations into Graphic3d package. 4) Update package D3DHost to new changes. 5) Update code of OCCT samples to new changes. --- adm/UDLIST | 1 - samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp | 4 +- samples/mfc/standard/03_Viewer2d/src/StdAfx.h | 1 - samples/mfc/standard/Common/OCC_3dView.cpp | 2 - samples/mfc/standard/Common/OCC_BaseDoc.cpp | 2 +- samples/mfc/standard/Common/StdAfx.h | 1 - samples/qt/Common/src/View.cxx | 3 +- src/AIS/AIS_InteractiveContext.cxx | 20 +- src/AIS/AIS_InteractiveContext_1.cxx | 1 - src/AIS/AIS_InteractiveContext_2.cxx | 2 +- src/AIS/AIS_LocalContext.cxx | 1 - src/AIS/AIS_LocalContext_1.cxx | 1 - src/Aspect/Aspect_GraphicCallbackProc.hxx | 1 + src/D3DHost/D3DHost_GraphicDriver.cxx | 59 +- src/D3DHost/D3DHost_GraphicDriver.hxx | 10 +- ...D3DHost_Workspace.cxx => D3DHost_View.cxx} | 161 +- ...D3DHost_Workspace.hxx => D3DHost_View.hxx} | 61 +- src/D3DHost/FILES | 4 +- src/Graphic3d/FILES | 7 + src/Graphic3d/Graphic3d_CAspectFillArea.hxx | 2 +- src/Graphic3d/Graphic3d_CAspectLine.hxx | 2 +- src/Graphic3d/Graphic3d_CAspectMarker.hxx | 2 +- src/Graphic3d/Graphic3d_CAspectText.hxx | 2 +- src/Graphic3d/Graphic3d_CLight.hxx | 25 +- src/Graphic3d/Graphic3d_CStructure.hxx | 1 + src/Graphic3d/Graphic3d_CView.cxx | 1079 ++++++++ src/Graphic3d/Graphic3d_CView.hxx | 624 ++++- src/Graphic3d/Graphic3d_Camera.cxx | 43 +- .../Graphic3d_GraduatedTrihedron.hxx | 8 +- src/Graphic3d/Graphic3d_GraphicDriver.cxx | 8 +- src/Graphic3d/Graphic3d_GraphicDriver.hxx | 233 +- src/Graphic3d/Graphic3d_Group.cxx | 5 +- src/Graphic3d/Graphic3d_MaterialAspect.hxx | 8 - src/Graphic3d/Graphic3d_Structure.cxx | 7 +- src/Graphic3d/Graphic3d_StructureManager.cxx | 373 ++- src/Graphic3d/Graphic3d_StructureManager.hxx | 300 +-- src/Graphic3d/Graphic3d_TextureEnv.hxx | 2 +- .../Graphic3d_TypeOfAnswer.hxx} | 14 +- .../Graphic3d_TypeOfBackfacingModel.hxx} | 14 +- .../Graphic3d_TypeOfLightSource.hxx} | 16 +- .../Graphic3d_TypeOfShadingModel.hxx} | 24 +- .../Graphic3d_TypeOfSurfaceDetail.hxx} | 14 +- .../Graphic3d_TypeOfVisualization.hxx} | 12 +- src/InterfaceGraphic/FILES | 2 - .../InterfaceGraphic_Aspect.hxx | 58 - .../InterfaceGraphic_Visual3d.hxx | 74 - src/OpenGl/FILES | 13 +- src/OpenGl/OpenGl_CView.hxx | 31 - src/OpenGl/OpenGl_Context.cxx | 86 +- src/OpenGl/OpenGl_Context.hxx | 4 + src/OpenGl/OpenGl_GraduatedTrihedron.cxx | 85 +- src/OpenGl/OpenGl_GraduatedTrihedron.hxx | 19 +- src/OpenGl/OpenGl_GraphicDriver.cxx | 541 ++-- src/OpenGl/OpenGl_GraphicDriver.hxx | 196 +- src/OpenGl/OpenGl_GraphicDriver_4.cxx | 114 - src/OpenGl/OpenGl_GraphicDriver_7.cxx | 599 ----- src/OpenGl/OpenGl_GraphicDriver_713.cxx | 48 - src/OpenGl/OpenGl_GraphicDriver_Export.cxx | 141 - src/OpenGl/OpenGl_Group.cxx | 1 + src/OpenGl/OpenGl_Layer.cxx | 6 +- src/OpenGl/OpenGl_LayerList.cxx | 13 +- src/OpenGl/OpenGl_LayerList.hxx | 2 +- src/OpenGl/OpenGl_Light.hxx | 21 +- .../OpenGl_MapOfZLayerSettings.hxx} | 8 +- src/OpenGl/OpenGl_ShaderManager.cxx | 40 +- src/OpenGl/OpenGl_ShaderManager.hxx | 20 +- src/OpenGl/OpenGl_ShaderStates.hxx | 10 +- src/OpenGl/OpenGl_Text.cxx | 2 +- src/OpenGl/OpenGl_Trihedron.cxx | 2 +- src/OpenGl/OpenGl_Trihedron.hxx | 2 +- src/OpenGl/OpenGl_View.cxx | 705 ++++- src/OpenGl/OpenGl_View.hxx | 621 ++++- src/OpenGl/OpenGl_View_2.cxx | 1001 ------- ..._Workspace_2.cxx => OpenGl_View_Print.cxx} | 176 +- src/OpenGl/OpenGl_View_Raytrace.cxx | 72 +- src/OpenGl/OpenGl_View_Redraw.cxx | 1781 +++++++++++++ src/OpenGl/OpenGl_Window.cxx | 139 +- src/OpenGl/OpenGl_Window.hxx | 21 +- src/OpenGl/OpenGl_Window_1.mm | 51 +- src/OpenGl/OpenGl_Workspace.cxx | 1374 ++++------ src/OpenGl/OpenGl_Workspace.hxx | 191 +- src/OpenGl/OpenGl_Workspace_5.cxx | 461 ---- src/OpenGl/OpenGl_telem_util.cxx | 1 - src/PrsMgr/PrsMgr_Presentation.cxx | 3 +- src/PrsMgr/PrsMgr_PresentationManager.cxx | 9 +- src/PrsMgr/PrsMgr_PresentationManager.hxx | 32 +- src/PrsMgr/PrsMgr_PresentationManager.lxx | 2 - src/QABugs/QABugs_8.cxx | 1 - src/StdSelect/StdSelect_ViewerSelector3d.cxx | 6 +- src/TKV3d/CMakeLists.txt | 1 - src/TKV3d/PACKAGES | 1 - src/V3d/V3d.cxx | 4 +- src/V3d/V3d.hxx | 5 +- src/V3d/V3d_AmbientLight.cxx | 20 +- src/V3d/V3d_AmbientLight.hxx | 33 +- src/V3d/V3d_CircularGrid.cxx | 3 +- src/V3d/V3d_DirectionalLight.cxx | 269 +- src/V3d/V3d_DirectionalLight.hxx | 120 +- src/V3d/V3d_Light.cxx | 171 +- src/V3d/V3d_Light.hxx | 134 +- src/V3d/V3d_Plane.cxx | 4 +- src/V3d/V3d_PositionLight.cxx | 253 +- src/V3d/V3d_PositionLight.hxx | 117 +- src/V3d/V3d_PositionalLight.cxx | 234 +- src/V3d/V3d_PositionalLight.hxx | 122 +- src/V3d/V3d_RectangularGrid.cxx | 3 +- src/V3d/V3d_SpotLight.cxx | 342 ++- src/V3d/V3d_SpotLight.hxx | 146 +- src/V3d/V3d_TypeOfShadingModel.hxx | 8 +- src/V3d/V3d_View.cxx | 1264 +++++---- src/V3d/V3d_View.hxx | 776 +++--- src/V3d/V3d_View_1.cxx | 282 +- src/V3d/V3d_View_2.cxx | 180 +- src/V3d/V3d_View_3.cxx | 105 +- src/V3d/V3d_View_4.cxx | 108 +- src/V3d/V3d_View_5.cxx | 29 +- src/V3d/V3d_View_Print.cxx | 116 +- src/V3d/V3d_Viewer.cxx | 295 +- src/V3d/V3d_Viewer.hxx | 140 +- src/V3d/V3d_Viewer_1.cxx | 1 - src/V3d/V3d_Viewer_2.cxx | 6 +- src/V3d/V3d_Viewer_3.cxx | 3 +- src/V3d/V3d_Viewer_4.cxx | 14 +- src/ViewerTest/ViewerTest_ObjectCommands.cxx | 1 - src/ViewerTest/ViewerTest_OpenGlCommands.cxx | 7 +- src/ViewerTest/ViewerTest_ViewerCommands.cxx | 43 +- src/Visual3d/FILES | 38 - src/Visual3d/Visual3d_ClipDefinitionError.hxx | 37 - src/Visual3d/Visual3d_ContextPick.cxx | 105 - src/Visual3d/Visual3d_ContextPick.hxx | 115 - .../Visual3d_ContextPickDefinitionError.hxx | 37 - src/Visual3d/Visual3d_ContextView.cxx | 318 --- src/Visual3d/Visual3d_ContextView.hxx | 255 -- .../Visual3d_DepthCueingDefinitionError.hxx | 37 - src/Visual3d/Visual3d_HSequenceOfLight.hxx | 27 - src/Visual3d/Visual3d_HSequenceOfView.hxx | 27 - .../Visual3d_LayerDefinitionError.hxx | 37 - src/Visual3d/Visual3d_Light.cxx | 444 ---- src/Visual3d/Visual3d_Light.hxx | 257 -- .../Visual3d_LightDefinitionError.hxx | 37 - src/Visual3d/Visual3d_NListOfLayerItem.hxx | 24 - src/Visual3d/Visual3d_PickError.hxx | 37 - src/Visual3d/Visual3d_SequenceOfLight.hxx | 26 - src/Visual3d/Visual3d_SequenceOfView.hxx | 26 - src/Visual3d/Visual3d_TransformError.hxx | 37 - src/Visual3d/Visual3d_TypeOfOrder.hxx | 29 - src/Visual3d/Visual3d_TypeOfProjection.hxx | 33 - src/Visual3d/Visual3d_View.cxx | 2364 ----------------- src/Visual3d/Visual3d_View.hxx | 622 ----- src/Visual3d/Visual3d_ViewDefinitionError.hxx | 37 - src/Visual3d/Visual3d_ViewManager.cxx | 741 ------ src/Visual3d/Visual3d_ViewManager.hxx | 245 -- .../Visual3d_ViewManagerDefinitionError.hxx | 37 - src/Visual3d/Visual3d_ViewManagerPtr.hxx | 23 - .../Visual3d_ViewMappingDefinitionError.hxx | 37 - ...isual3d_ViewOrientationDefinitionError.hxx | 37 - src/Visual3d/Visual3d_ViewPtr.hxx | 23 - .../Visual3d_ZClippingDefinitionError.hxx | 37 - tests/bugs/vis/bug25671 | 1 + 159 files changed, 9701 insertions(+), 13791 deletions(-) rename src/D3DHost/{D3DHost_Workspace.cxx => D3DHost_View.cxx} (66%) rename src/D3DHost/{D3DHost_Workspace.hxx => D3DHost_View.hxx} (55%) create mode 100644 src/Graphic3d/Graphic3d_CView.cxx rename src/{Visual3d/Visual3d_TypeOfAnswer.hxx => Graphic3d/Graphic3d_TypeOfAnswer.hxx} (81%) rename src/{Visual3d/Visual3d_TypeOfBackfacingModel.hxx => Graphic3d/Graphic3d_TypeOfBackfacingModel.hxx} (77%) rename src/{Visual3d/Visual3d_TypeOfLightSource.hxx => Graphic3d/Graphic3d_TypeOfLightSource.hxx} (76%) rename src/{Visual3d/Visual3d_TypeOfModel.hxx => Graphic3d/Graphic3d_TypeOfShadingModel.hxx} (56%) rename src/{Visual3d/Visual3d_TypeOfSurfaceDetail.hxx => Graphic3d/Graphic3d_TypeOfSurfaceDetail.hxx} (78%) rename src/{Visual3d/Visual3d_TypeOfVisualization.hxx => Graphic3d/Graphic3d_TypeOfVisualization.hxx} (78%) delete mode 100644 src/InterfaceGraphic/InterfaceGraphic_Aspect.hxx delete mode 100644 src/InterfaceGraphic/InterfaceGraphic_Visual3d.hxx delete mode 100644 src/OpenGl/OpenGl_CView.hxx delete mode 100644 src/OpenGl/OpenGl_GraphicDriver_4.cxx delete mode 100644 src/OpenGl/OpenGl_GraphicDriver_7.cxx delete mode 100644 src/OpenGl/OpenGl_GraphicDriver_713.cxx delete mode 100644 src/OpenGl/OpenGl_GraphicDriver_Export.cxx rename src/{Visual3d/Visual3d_MapOfZLayerSettings.hxx => OpenGl/OpenGl_MapOfZLayerSettings.hxx} (81%) delete mode 100644 src/OpenGl/OpenGl_View_2.cxx rename src/OpenGl/{OpenGl_Workspace_2.cxx => OpenGl_View_Print.cxx} (82%) create mode 100644 src/OpenGl/OpenGl_View_Redraw.cxx delete mode 100644 src/OpenGl/OpenGl_Workspace_5.cxx delete mode 100755 src/Visual3d/FILES delete mode 100644 src/Visual3d/Visual3d_ClipDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ContextPick.cxx delete mode 100644 src/Visual3d/Visual3d_ContextPick.hxx delete mode 100644 src/Visual3d/Visual3d_ContextPickDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ContextView.cxx delete mode 100644 src/Visual3d/Visual3d_ContextView.hxx delete mode 100644 src/Visual3d/Visual3d_DepthCueingDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_HSequenceOfLight.hxx delete mode 100644 src/Visual3d/Visual3d_HSequenceOfView.hxx delete mode 100644 src/Visual3d/Visual3d_LayerDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_Light.cxx delete mode 100644 src/Visual3d/Visual3d_Light.hxx delete mode 100644 src/Visual3d/Visual3d_LightDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_NListOfLayerItem.hxx delete mode 100644 src/Visual3d/Visual3d_PickError.hxx delete mode 100644 src/Visual3d/Visual3d_SequenceOfLight.hxx delete mode 100644 src/Visual3d/Visual3d_SequenceOfView.hxx delete mode 100644 src/Visual3d/Visual3d_TransformError.hxx delete mode 100644 src/Visual3d/Visual3d_TypeOfOrder.hxx delete mode 100644 src/Visual3d/Visual3d_TypeOfProjection.hxx delete mode 100644 src/Visual3d/Visual3d_View.cxx delete mode 100644 src/Visual3d/Visual3d_View.hxx delete mode 100644 src/Visual3d/Visual3d_ViewDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ViewManager.cxx delete mode 100644 src/Visual3d/Visual3d_ViewManager.hxx delete mode 100644 src/Visual3d/Visual3d_ViewManagerDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ViewManagerPtr.hxx delete mode 100644 src/Visual3d/Visual3d_ViewMappingDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ViewOrientationDefinitionError.hxx delete mode 100644 src/Visual3d/Visual3d_ViewPtr.hxx delete mode 100644 src/Visual3d/Visual3d_ZClippingDefinitionError.hxx diff --git a/adm/UDLIST b/adm/UDLIST index 29d3f31286..c6ecf10e18 100644 --- a/adm/UDLIST +++ b/adm/UDLIST @@ -212,7 +212,6 @@ n StdPrs n StdSelect n TColQuantity n V3d -n Visual3d n Voxel n WNT n Xw diff --git a/samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp b/samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp index 44a637ae4e..a1a237a356 100644 --- a/samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp +++ b/samples/CSharp/OCCTProxy_D3D/OCCTProxyD3D.cpp @@ -10,10 +10,10 @@ #include #include #include +#include //for object display #include #include -#include #include #include //topology @@ -106,7 +106,7 @@ public: aWNTWindow->SetPos (0, 0, theWinSizeX, theWinSizeY); myView()->MustBeResized(); myView()->Invalidate(); - return System::IntPtr(myGraphicDriver()->D3dColorSurface (myView()->View())); + return System::IntPtr(Handle(D3DHost_View)::DownCast (myView()->View())->D3dColorSurface()); } /// diff --git a/samples/mfc/standard/03_Viewer2d/src/StdAfx.h b/samples/mfc/standard/03_Viewer2d/src/StdAfx.h index 25e3a10bd3..65799e0025 100755 --- a/samples/mfc/standard/03_Viewer2d/src/StdAfx.h +++ b/samples/mfc/standard/03_Viewer2d/src/StdAfx.h @@ -148,7 +148,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/mfc/standard/Common/OCC_3dView.cpp b/samples/mfc/standard/Common/OCC_3dView.cpp index 4842ba166c..8c5c577e91 100755 --- a/samples/mfc/standard/Common/OCC_3dView.cpp +++ b/samples/mfc/standard/Common/OCC_3dView.cpp @@ -8,8 +8,6 @@ #include "OCC_3dBaseDoc.h" #include -#include - #include #include diff --git a/samples/mfc/standard/Common/OCC_BaseDoc.cpp b/samples/mfc/standard/Common/OCC_BaseDoc.cpp index bf58d76345..1ceb699358 100755 --- a/samples/mfc/standard/Common/OCC_BaseDoc.cpp +++ b/samples/mfc/standard/Common/OCC_BaseDoc.cpp @@ -42,7 +42,7 @@ void OCC_BaseDoc::ExportView (const Handle(V3d_View)& theView) const else if (!(aFileExt.CompareNoCase (L"svg"))) anExportFormat = Graphic3d_EF_SVG; else anExportFormat = Graphic3d_EF_PGF; - theView->View()->Export (aFileName.ToCString(), anExportFormat); + theView->Export (aFileName.ToCString(), anExportFormat); } else { diff --git a/samples/mfc/standard/Common/StdAfx.h b/samples/mfc/standard/Common/StdAfx.h index 36d25e7f3c..0f0303b3cd 100755 --- a/samples/mfc/standard/Common/StdAfx.h +++ b/samples/mfc/standard/Common/StdAfx.h @@ -114,7 +114,6 @@ #include #include -#include #include #include #include diff --git a/samples/qt/Common/src/View.cxx b/samples/qt/Common/src/View.cxx index 0a8a56f685..929a6c0a7b 100755 --- a/samples/qt/Common/src/View.cxx +++ b/samples/qt/Common/src/View.cxx @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -1147,7 +1146,7 @@ bool View::dump(Standard_CString theFile) exFormat = Graphic3d_EF_PGF; try { - myView->View()->Export( theFile, exFormat ); + myView->Export( theFile, exFormat ); } catch(...) { diff --git a/src/AIS/AIS_InteractiveContext.cxx b/src/AIS/AIS_InteractiveContext.cxx index 158f8971bd..aa5f229309 100644 --- a/src/AIS/AIS_InteractiveContext.cxx +++ b/src/AIS/AIS_InteractiveContext.cxx @@ -61,8 +61,6 @@ #include #include #include -#include -#include //#include namespace @@ -93,7 +91,7 @@ namespace AIS_InteractiveContext::AIS_InteractiveContext(const Handle(V3d_Viewer)& MainViewer): mgrSelector(new SelectMgr_SelectionManager()), -myMainPM(new PrsMgr_PresentationManager3d(MainViewer->Viewer())), +myMainPM(new PrsMgr_PresentationManager3d(MainViewer->StructureManager())), myMainVwr(MainViewer), myMainSel(new StdSelect_ViewerSelector3d()), myWasLastMain(Standard_False), @@ -353,8 +351,8 @@ void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO const Standard_Boolean theIsVisibleInView, const AIS_DisplayStatus theStatus) const { - const Graphic3d_CView* aCView = reinterpret_cast(theView->View()->CView()); - const Standard_Integer aViewId = aCView->ViewId; + Handle(Graphic3d_CView) aViewImpl = theView->View(); + const Standard_Integer aViewId = aViewImpl->Identification(); for (AIS_DataMapIteratorOfDataMapOfIOStatus anObjIter (myObjects); anObjIter.More(); anObjIter.Next()) { if (theStatus != AIS_DS_None @@ -364,7 +362,7 @@ void AIS_InteractiveContext::ObjectsForView (AIS_ListOfInteractive& theListOfIO continue; } - Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (anObjIter.Key()); + Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (anObjIter.Key()); const Standard_Boolean isVisible = anAffinity->IsVisible (aViewId); if (isVisible == theIsVisibleInView) { @@ -406,9 +404,9 @@ void AIS_InteractiveContext::SetViewAffinity (const Handle(AIS_InteractiveObject return; } - Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->ObjectAffinity (theIObj); - const Graphic3d_CView* aCView = reinterpret_cast(theView->View()->CView()); - anAffinity->SetVisible (aCView->ViewId, theIsVisible == Standard_True); + Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->ObjectAffinity (theIObj); + Handle(Graphic3d_CView) aViewImpl = theView->View(); + anAffinity->SetVisible (aViewImpl->Identification(), theIsVisible == Standard_True); if (theIsVisible) { theView->View()->ChangeHiddenObjects()->Remove (theIObj.get()); @@ -470,7 +468,7 @@ void AIS_InteractiveContext::Display (const Handle(AIS_InteractiveObject)& theIO { Handle(AIS_GlobalStatus) aStatus = new AIS_GlobalStatus (AIS_DS_Displayed, theDispMode, theSelectionMode); myObjects.Bind (theIObj, aStatus); - Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->Viewer()->RegisterObject (theIObj); + Handle(Graphic3d_ViewAffinity) anAffinity = myMainVwr->StructureManager()->RegisterObject (theIObj); myMainPM->Display(theIObj, theDispMode); if (theSelectionMode != -1) { @@ -2532,7 +2530,7 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t mgrSelector->Remove (anObj); myObjects.UnBind (theIObj); - myMainVwr->Viewer()->UnregisterObject (theIObj); + myMainVwr->StructureManager()->UnregisterObject (theIObj); for (myMainVwr->InitDefinedViews(); myMainVwr->MoreDefinedViews(); myMainVwr->NextDefinedViews()) { myMainVwr->DefinedView()->View()->ChangeHiddenObjects()->Remove (theIObj.get()); diff --git a/src/AIS/AIS_InteractiveContext_1.cxx b/src/AIS/AIS_InteractiveContext_1.cxx index 5cc781494a..81cdbf3c79 100644 --- a/src/AIS/AIS_InteractiveContext_1.cxx +++ b/src/AIS/AIS_InteractiveContext_1.cxx @@ -52,7 +52,6 @@ #include #include #include -#include typedef NCollection_DataMap > AIS_MapOfObjSelectedOwners; diff --git a/src/AIS/AIS_InteractiveContext_2.cxx b/src/AIS/AIS_InteractiveContext_2.cxx index 9b92c5feff..30e50ceceb 100644 --- a/src/AIS/AIS_InteractiveContext_2.cxx +++ b/src/AIS/AIS_InteractiveContext_2.cxx @@ -687,7 +687,7 @@ Standard_Integer AIS_InteractiveContext::PurgeDisplay() //======================================================================= Standard_Integer AIS_InteractiveContext::PurgeViewer(const Handle(V3d_Viewer)& Vwr) { - Handle(Graphic3d_StructureManager) GSM = Vwr->Viewer(); + Handle(Graphic3d_StructureManager) GSM = Vwr->StructureManager(); Standard_Integer NbCleared(0); Graphic3d_MapOfStructure SOS; GSM->DisplayedStructures(SOS); diff --git a/src/AIS/AIS_LocalContext.cxx b/src/AIS/AIS_LocalContext.cxx index d4c400f9f0..1d992a8a3e 100644 --- a/src/AIS/AIS_LocalContext.cxx +++ b/src/AIS/AIS_LocalContext.cxx @@ -47,7 +47,6 @@ #include #include #include -#include #include static TCollection_AsciiString AIS_Local_SelName(const Standard_Address address, diff --git a/src/AIS/AIS_LocalContext_1.cxx b/src/AIS/AIS_LocalContext_1.cxx index a52a2e403b..d04e392cb2 100644 --- a/src/AIS/AIS_LocalContext_1.cxx +++ b/src/AIS/AIS_LocalContext_1.cxx @@ -52,7 +52,6 @@ #include #include #include -#include static Standard_Integer GetHiMod(const Handle(AIS_InteractiveObject)& IO) { diff --git a/src/Aspect/Aspect_GraphicCallbackProc.hxx b/src/Aspect/Aspect_GraphicCallbackProc.hxx index 94a9e1a274..f6bb079fae 100644 --- a/src/Aspect/Aspect_GraphicCallbackProc.hxx +++ b/src/Aspect/Aspect_GraphicCallbackProc.hxx @@ -19,6 +19,7 @@ #include #include #include +#include #include // The flags below provide additional information to define the moment when diff --git a/src/D3DHost/D3DHost_GraphicDriver.cxx b/src/D3DHost/D3DHost_GraphicDriver.cxx index 23ece91194..50c3a337b3 100644 --- a/src/D3DHost/D3DHost_GraphicDriver.cxx +++ b/src/D3DHost/D3DHost_GraphicDriver.cxx @@ -16,10 +16,7 @@ #include #include - -#include -#include -#include +#include #ifdef _MSC_VER #pragma comment (lib, "D3D9.lib") @@ -48,57 +45,19 @@ D3DHost_GraphicDriver::~D3DHost_GraphicDriver() // function : View // purpose : // ======================================================================= -Standard_Boolean D3DHost_GraphicDriver::View (Graphic3d_CView& theCView) +Handle(Graphic3d_CView) D3DHost_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr) { - Handle(OpenGl_Context) aShareCtx = GetSharedContext(); - OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; - if (aCView != NULL - && myMapOfView.Contains (aCView->View)) - { - Handle(D3DHost_Workspace) anOldWS = Handle(D3DHost_Workspace)::DownCast (aCView->WS); - Handle(D3DHost_Workspace) aWS = new D3DHost_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); - theCView.ptrFBO = aWS->D3dWglBuffer().operator->(); - aCView->WS = aWS; - aWS->SetActiveView (aCView->View, theCView.ViewId); - - myMapOfWS.Remove (anOldWS); - myMapOfWS.Add (aWS); - return Standard_True; - } + Handle(D3DHost_View) aView = new D3DHost_View (theMgr, this, myCaps, myDeviceLostFlag, &myStateCounter); - Handle(D3DHost_Workspace) aWS = new D3DHost_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); - Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context, &myStateCounter); - myMapOfWS .Add (aWS); myMapOfView.Add (aView); - aCView = new OpenGl_CView(); - aCView->View = aView; - aCView->WS = aWS; - theCView.ptrFBO = aWS->D3dWglBuffer().operator->(); - theCView.ptrView = aCView; - aWS->SetActiveView (aCView->View, theCView.ViewId); - return Standard_True; -} - -// ======================================================================= -// function : D3dColorSurface -// purpose : -// ======================================================================= -IDirect3DSurface9* D3DHost_GraphicDriver::D3dColorSurface (const Handle(Visual3d_View)& theView) const -{ - Graphic3d_CView* aCView = (Graphic3d_CView* )(theView->CView()); - if (aCView == NULL - || aCView->ptrView == NULL) - { - return NULL; - } - - Handle(D3DHost_Workspace) aWS = Handle(D3DHost_Workspace)::DownCast (((OpenGl_CView* )aCView->ptrView)->WS); - if (aWS.IsNull() - || aWS->D3dWglBuffer().IsNull()) + for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next()) { - return NULL; + const Graphic3d_ZLayerId aLayerID = aLayerIt.Value(); + const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID); + aView->AddZLayer (aLayerID); + aView->SetZLayerSettings (aLayerID, aSettings); } - return aWS->D3dWglBuffer()->D3dColorSurface(); + return aView; } diff --git a/src/D3DHost/D3DHost_GraphicDriver.hxx b/src/D3DHost/D3DHost_GraphicDriver.hxx index 092017c9c3..1cf41cf28e 100644 --- a/src/D3DHost/D3DHost_GraphicDriver.hxx +++ b/src/D3DHost/D3DHost_GraphicDriver.hxx @@ -18,9 +18,6 @@ #include -class Visual3d_View; -struct IDirect3DSurface9; - //! This class defines D3D host for an OpenGl graphic driver class D3DHost_GraphicDriver : public OpenGl_GraphicDriver { @@ -32,11 +29,8 @@ public: //! Destructor. Standard_EXPORT virtual ~D3DHost_GraphicDriver(); - //! Create new view. - Standard_EXPORT virtual Standard_Boolean View (Graphic3d_CView& theCView); - - //! Return D3D surface for specified view. - Standard_EXPORT IDirect3DSurface9* D3dColorSurface (const Handle(Visual3d_View)& theCView) const; + //! Create instance of D3D host view. + Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE; public: diff --git a/src/D3DHost/D3DHost_Workspace.cxx b/src/D3DHost/D3DHost_View.cxx similarity index 66% rename from src/D3DHost/D3DHost_Workspace.cxx rename to src/D3DHost/D3DHost_View.cxx index 2277a9540a..e499b4539c 100644 --- a/src/D3DHost/D3DHost_Workspace.cxx +++ b/src/D3DHost/D3DHost_View.cxx @@ -13,17 +13,16 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include - -#include +#include +#include #include // ======================================================================= // function : d3dFormatError // purpose : // ======================================================================= -TCollection_AsciiString D3DHost_Workspace::d3dFormatError (HRESULT theErrCode) +TCollection_AsciiString D3DHost_View::d3dFormatError (HRESULT theErrCode) { switch (theErrCode) { @@ -38,15 +37,15 @@ TCollection_AsciiString D3DHost_Workspace::d3dFormatError (HRESULT theErrCode) } // ======================================================================= -// function : D3DHost_Workspace +// function : D3DHost_View // purpose : // ======================================================================= -D3DHost_Workspace::D3DHost_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, - Aspect_RenderingContext theGContext, - const Handle(OpenGl_Caps)& theCaps, - const Handle(OpenGl_Context)& theShareCtx) -: OpenGl_Workspace (theDriver, theCWindow, theGContext, theCaps, theShareCtx), +D3DHost_View::D3DHost_View (const Handle(Graphic3d_StructureManager)& theMgr, + const Handle(D3DHost_GraphicDriver)& theDriver, + const Handle(OpenGl_Caps)& theCaps, + Standard_Boolean& theDeviceLostFlag, + OpenGl_StateCounter* theCounter) +: OpenGl_View (theMgr, theDriver, theCaps, theDeviceLostFlag, theCounter), myD3dLib (NULL), myD3dDevice (NULL), myRefreshRate (D3DPRESENT_RATE_DEFAULT), @@ -64,20 +63,17 @@ D3DHost_Workspace::D3DHost_Workspace (const Handle(OpenGl_GraphicDriver)& theDri myD3dParams.AutoDepthStencilFormat = D3DFMT_D16_LOCKABLE; myD3dParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; myD3dParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; - - d3dInit (theCWindow); - d3dCreateRenderTarget(); } // ======================================================================= -// function : ~D3DHost_Workspace +// function : ~D3DHost_View // purpose : // ======================================================================= -D3DHost_Workspace::~D3DHost_Workspace() +D3DHost_View::~D3DHost_View() { if (!myD3dWglFbo.IsNull()) { - myD3dWglFbo->Release (myGlContext.operator->()); + myD3dWglFbo->Release (myWorkspace->GetGlContext().operator->()); myD3dWglFbo.Nullify(); } if (myD3dDevice != NULL) @@ -92,11 +88,40 @@ D3DHost_Workspace::~D3DHost_Workspace() } } +// ======================================================================= +// function : SetWindow +// purpose : +// ======================================================================= +void D3DHost_View::SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext, + const Aspect_GraphicCallbackProc& theDisplayCB, + const Standard_Address theClientData) +{ + if (!myD3dWglFbo.IsNull()) + { + myD3dWglFbo->Release (myWorkspace->GetGlContext().operator->()); + myD3dWglFbo.Nullify(); + } + if (myD3dDevice != NULL) + { + myD3dDevice->Release(); + myD3dDevice = NULL; + } + + OpenGl_View::SetWindow (theWindow, theContext, theDisplayCB, theClientData); + + if (!myWindow.IsNull()) + { + d3dInit(); + d3dCreateRenderTarget(); + } +} + // ======================================================================= // function : d3dInitLib // purpose : // ======================================================================= -bool D3DHost_Workspace::d3dInitLib() +bool D3DHost_View::d3dInitLib() { if (myD3dLib == NULL) { @@ -127,15 +152,15 @@ bool D3DHost_Workspace::d3dInitLib() // function : d3dInit // purpose : // ======================================================================= -bool D3DHost_Workspace::d3dInit (const CALL_DEF_WINDOW& theCWindow) +bool D3DHost_View::d3dInit() { if (!d3dInitLib()) { - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_ERROR_ARB, - 0, - GL_DEBUG_SEVERITY_HIGH_ARB, - "Direct3DCreate9 failed!"); + myWorkspace->GetGlContext()->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_ERROR_ARB, + 0, + GL_DEBUG_SEVERITY_HIGH_ARB, + "Direct3DCreate9 failed!"); return false; } @@ -148,13 +173,13 @@ bool D3DHost_Workspace::d3dInit (const CALL_DEF_WINDOW& theCWindow) myRefreshRate = myCurrMode.RefreshRate; } myD3dParams.Windowed = TRUE; - myD3dParams.BackBufferWidth = theCWindow.dx; - myD3dParams.BackBufferHeight = theCWindow.dy; - myD3dParams.hDeviceWindow = (HWND )theCWindow.XWindow; + myD3dParams.BackBufferWidth = myWindow->Width(); + myD3dParams.BackBufferHeight = myWindow->Height(); + myD3dParams.hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle(); // create the Video Device HRESULT isOK = myD3dLib->CreateDevice (anAdapterId, D3DDEVTYPE_HAL, - (HWND )theCWindow.XWindow, + (HWND )myWindow->PlatformWindow()->NativeHandle(), D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, &myD3dParams, &myD3dDevice); if (isOK < 0) @@ -169,7 +194,7 @@ bool D3DHost_Workspace::d3dInit (const CALL_DEF_WINDOW& theCWindow) // function : d3dReset // purpose : // ======================================================================= -bool D3DHost_Workspace::d3dReset (const CALL_DEF_WINDOW& theCWindow) +bool D3DHost_View::d3dReset() { if (myD3dDevice == NULL) { @@ -177,9 +202,9 @@ bool D3DHost_Workspace::d3dReset (const CALL_DEF_WINDOW& theCWindow) } myD3dParams.Windowed = TRUE; - myD3dParams.BackBufferWidth = theCWindow.dx; - myD3dParams.BackBufferHeight = theCWindow.dy; - myD3dParams.hDeviceWindow = (HWND )theCWindow.XWindow; + myD3dParams.BackBufferWidth = myWindow->Width(); + myD3dParams.BackBufferHeight = myWindow->Height(); + myD3dParams.hDeviceWindow = (HWND )myWindow->PlatformWindow()->NativeHandle(); myD3dParams.FullScreen_RefreshRateInHz = !myD3dParams.Windowed ? myRefreshRate : 0; HRESULT isOK = myD3dDevice->Reset(&myD3dParams); @@ -190,13 +215,17 @@ bool D3DHost_Workspace::d3dReset (const CALL_DEF_WINDOW& theCWindow) // function : d3dCreateRenderTarget // purpose : // ======================================================================= -bool D3DHost_Workspace::d3dCreateRenderTarget() +bool D3DHost_View::d3dCreateRenderTarget() { if (myD3dWglFbo.IsNull()) { myD3dWglFbo = new D3DHost_FrameBuffer(); } - if (!myD3dWglFbo->Init (myGlContext, myD3dDevice, myIsD3dEx, myWidth, myHeight)) + if (!myD3dWglFbo->Init (myWorkspace->GetGlContext(), + myD3dDevice, + myIsD3dEx, + myWindow->Width(), + myWindow->Height())) { return false; } @@ -209,7 +238,7 @@ bool D3DHost_Workspace::d3dCreateRenderTarget() // function : d3dBeginRender // purpose : // ======================================================================= -void D3DHost_Workspace::d3dBeginRender() +void D3DHost_View::d3dBeginRender() { if (myD3dDevice == NULL) { @@ -225,7 +254,7 @@ void D3DHost_Workspace::d3dBeginRender() // function : d3dEndRender // purpose : // ======================================================================= -void D3DHost_Workspace::d3dEndRender() +void D3DHost_View::d3dEndRender() { if (myD3dDevice != NULL) { @@ -237,7 +266,7 @@ void D3DHost_Workspace::d3dEndRender() // function : d3dSwap // purpose : // ======================================================================= -bool D3DHost_Workspace::d3dSwap() +bool D3DHost_View::d3dSwap() { if (myD3dDevice == NULL) { @@ -249,11 +278,11 @@ bool D3DHost_Workspace::d3dSwap() { TCollection_ExtendedString aMsg = TCollection_ExtendedString() + "Direct3D9, Present device failed, " + d3dFormatError (isOK); - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_ERROR_ARB, - 0, - GL_DEBUG_SEVERITY_HIGH_ARB, - aMsg); + myWorkspace->GetGlContext()->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_ERROR_ARB, + 0, + GL_DEBUG_SEVERITY_HIGH_ARB, + aMsg); } return isOK == D3D_OK; } @@ -262,20 +291,21 @@ bool D3DHost_Workspace::d3dSwap() // function : Redraw // purpose : // ======================================================================= -void D3DHost_Workspace::Redraw (const Graphic3d_CView& theCView) +void D3DHost_View::Redraw() { - if (!Activate() + if (!myWorkspace->Activate() || myD3dDevice == NULL) { return; } + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); myToFlipOutput = Standard_True; - myD3dWglFbo->LockSurface (myGlContext); - OpenGl_Workspace::Redraw (theCView); - myD3dWglFbo->UnlockSurface (myGlContext); + myD3dWglFbo->LockSurface (aCtx); + OpenGl_View::Redraw(); + myD3dWglFbo->UnlockSurface (aCtx); myToFlipOutput = Standard_False; - if (myGlContext->caps->buffersNoSwap) + if (aCtx->caps->buffersNoSwap) { return; } @@ -296,27 +326,28 @@ void D3DHost_Workspace::Redraw (const Graphic3d_CView& theCView) // function : RedrawImmediate // purpose : // ======================================================================= -void D3DHost_Workspace::RedrawImmediate (const Graphic3d_CView& theCView) +void D3DHost_View::RedrawImmediate() { + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); if (!myTransientDrawToFront || !myBackBufferRestored - || (myGlContext->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid())) + || (aCtx->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid())) { - Redraw (theCView); + Redraw(); return; } - else if (!Activate() + else if (!myWorkspace->Activate() || myD3dDevice == NULL) { return; } myToFlipOutput = Standard_True; - myD3dWglFbo->LockSurface (myGlContext); - OpenGl_Workspace::RedrawImmediate (theCView); - myD3dWglFbo->UnlockSurface (myGlContext); + myD3dWglFbo->LockSurface (aCtx); + OpenGl_View::RedrawImmediate(); + myD3dWglFbo->UnlockSurface (aCtx); myToFlipOutput = Standard_False; - if (myGlContext->caps->buffersNoSwap) + if (aCtx->caps->buffersNoSwap) { return; } @@ -337,24 +368,24 @@ void D3DHost_Workspace::RedrawImmediate (const Graphic3d_CView& theCView) // function : Resize // purpose : // ======================================================================= -void D3DHost_Workspace::Resize (const CALL_DEF_WINDOW& theCWindow) +void D3DHost_View::Resized() { - const Standard_Integer aWidthOld = myWidth; - const Standard_Integer aHeightOld = myHeight; - OpenGl_Workspace::Resize (theCWindow); - if (aWidthOld == myWidth - && aHeightOld == myHeight) + const Standard_Integer aWidthOld = myWindow->Width(); + const Standard_Integer aHeightOld = myWindow->Height(); + OpenGl_View::Resized(); + if (aWidthOld == myWindow->Width() + && aHeightOld == myWindow->Height()) { return; } if (!myD3dWglFbo.IsNull()) { - myD3dWglFbo->Release (myGlContext.operator->()); + myD3dWglFbo->Release (myWorkspace->GetGlContext().operator->()); } - if (!myGlContext->caps->buffersNoSwap) + if (!myWorkspace->GetGlContext()->caps->buffersNoSwap) { - d3dReset (theCWindow); + d3dReset(); } d3dCreateRenderTarget(); } diff --git a/src/D3DHost/D3DHost_Workspace.hxx b/src/D3DHost/D3DHost_View.hxx similarity index 55% rename from src/D3DHost/D3DHost_Workspace.hxx rename to src/D3DHost/D3DHost_View.hxx index 748010bf63..1c2d4cf78b 100644 --- a/src/D3DHost/D3DHost_Workspace.hxx +++ b/src/D3DHost/D3DHost_View.hxx @@ -13,38 +13,52 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _D3DHost_Workspace_HeaderFile -#define _D3DHost_Workspace_HeaderFile +#ifndef _D3DHost_View_HeaderFile +#define _D3DHost_View_HeaderFile #include -#include #include +#include +#include + +class D3DHost_GraphicDriver; -//! The D3D host containing OpenGL viewer. -class D3DHost_Workspace : public OpenGl_Workspace +//! The D3D host view implementation that overrides rendering methods. +class D3DHost_View : public OpenGl_View { public: - //! Main constructor. - Standard_EXPORT D3DHost_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, - Aspect_RenderingContext theGContext, - const Handle(OpenGl_Caps)& theCaps, - const Handle(OpenGl_Context)& theShareCtx); - - //! Destroy D3D connection and OpenGL workspace. - Standard_EXPORT virtual ~D3DHost_Workspace(); + //! Constructor. + Standard_EXPORT D3DHost_View (const Handle(Graphic3d_StructureManager)& theMgr, + const Handle(D3DHost_GraphicDriver)& theDriver, + const Handle(OpenGl_Caps)& theCaps, + Standard_Boolean& theDeviceLostFlag, + OpenGl_StateCounter* theCounter); + + //! Default destructor. + Standard_EXPORT virtual ~D3DHost_View(); + + //! Creates and maps rendering window to the view. + //! @param theWindow [in] the window. + //! @param theContext [in] the rendering context. If NULL the context will be created internally. + //! @param theDisplayCB [in] the display callback function. If is not a NULL value, then the callback will be + //! invoked at the end of the OCC graphic traversal and just before the swap of buffers. + //! @param theClientData [in] the client data for the callback. + Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext, + const Aspect_GraphicCallbackProc& theDisplayCB, + const Standard_Address theClientData) Standard_OVERRIDE; //! Resizes the window. - Standard_EXPORT virtual void Resize (const CALL_DEF_WINDOW& theCWindow) Standard_OVERRIDE; + Standard_EXPORT virtual void Resized() Standard_OVERRIDE; //! Redraw the all content. - Standard_EXPORT virtual void Redraw (const Graphic3d_CView& theCView) Standard_OVERRIDE; + Standard_EXPORT virtual void Redraw() Standard_OVERRIDE; //! Redraw only immediate layer. - Standard_EXPORT virtual void RedrawImmediate (const Graphic3d_CView& theCView) Standard_OVERRIDE; + Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE; public: @@ -57,6 +71,9 @@ public: //! Return D3D/WGL FBO. const Handle(D3DHost_FrameBuffer)& D3dWglBuffer() const { return myD3dWglFbo; } + //! Return D3D surface. + IDirect3DSurface9* D3dColorSurface() const { return myD3dWglFbo->D3dColorSurface(); } + protected: //! Auxiliary method. @@ -66,11 +83,11 @@ protected: Standard_EXPORT bool d3dInitLib(); //! Initialize Direct3D output device. - Standard_EXPORT bool d3dInit (const CALL_DEF_WINDOW& theCWindow); + Standard_EXPORT bool d3dInit(); //! Reset Direct3D output settings. Could be used to switch windowed/fullscreen modes. //! Use very carefully! Most objects should be released before and recreated after! - Standard_EXPORT bool d3dReset (const CALL_DEF_WINDOW& theCWindow); + Standard_EXPORT bool d3dReset(); //! (Re-)create D3D surface. Standard_EXPORT bool d3dCreateRenderTarget(); @@ -97,10 +114,10 @@ protected: public: - DEFINE_STANDARD_RTTI(D3DHost_Workspace, OpenGl_Workspace) + DEFINE_STANDARD_RTTI(D3DHost_View, OpenGl_View) }; -DEFINE_STANDARD_HANDLE(D3DHost_Workspace, OpenGl_Workspace) +DEFINE_STANDARD_HANDLE(D3DHost_View, OpenGl_View) -#endif // _D3DHost_Workspace_HeaderFile +#endif // #ifndef _D3DHost_View_HeaderFile diff --git a/src/D3DHost/FILES b/src/D3DHost/FILES index fce5140e8a..2fc633e978 100644 --- a/src/D3DHost/FILES +++ b/src/D3DHost/FILES @@ -2,5 +2,5 @@ D3DHost_GraphicDriver.hxx D3DHost_GraphicDriver.cxx D3DHost_FrameBuffer.hxx D3DHost_FrameBuffer.cxx -D3DHost_Workspace.hxx -D3DHost_Workspace.cxx +D3DHost_View.hxx +D3DHost_View.cxx diff --git a/src/Graphic3d/FILES b/src/Graphic3d/FILES index 3cbda2dc6e..6cfa10ed2b 100755 --- a/src/Graphic3d/FILES +++ b/src/Graphic3d/FILES @@ -56,6 +56,7 @@ Graphic3d_CStructure.hxx Graphic3d_CStructurePtr.hxx Graphic3d_CTexture.hxx Graphic3d_CUserDraw.hxx +Graphic3d_CView.cxx Graphic3d_CView.hxx Graphic3d_CycleError.hxx Graphic3d_DataStructure.pxx @@ -145,19 +146,25 @@ Graphic3d_TransformError.hxx Graphic3d_TransformPers.hxx Graphic3d_TransformUtils.hxx Graphic3d_TransModeFlags.hxx +Graphic3d_TypeOfAnswer.hxx +Graphic3d_TypeOfBackfacingModel.hxx Graphic3d_TypeOfBackground.hxx Graphic3d_TypeOfComposition.hxx Graphic3d_TypeOfConnection.hxx +Graphic3d_TypeOfLightSource.hxx Graphic3d_TypeOfMaterial.hxx Graphic3d_TypeOfPolygon.hxx Graphic3d_TypeOfPrimitive.hxx Graphic3d_TypeOfPrimitiveArray.hxx Graphic3d_TypeOfReflection.hxx Graphic3d_TypeOfShaderObject.hxx +Graphic3d_TypeOfShadingModel.hxx Graphic3d_TypeOfStructure.hxx +Graphic3d_TypeOfSurfaceDetail.hxx Graphic3d_TypeOfTexture.hxx Graphic3d_TypeOfTextureFilter.hxx Graphic3d_TypeOfTextureMode.hxx +Graphic3d_TypeOfVisualization.hxx Graphic3d_Vec.hxx Graphic3d_Vec2.hxx Graphic3d_Vec3.hxx diff --git a/src/Graphic3d/Graphic3d_CAspectFillArea.hxx b/src/Graphic3d/Graphic3d_CAspectFillArea.hxx index 14956a92b5..ad29d59f45 100644 --- a/src/Graphic3d/Graphic3d_CAspectFillArea.hxx +++ b/src/Graphic3d/Graphic3d_CAspectFillArea.hxx @@ -15,9 +15,9 @@ #ifndef _Graphic3d_CAspectFillArea_HeaderFile #define _Graphic3d_CAspectFillArea_HeaderFile -#include #include #include +#include class Graphic3d_CAspectFillArea { diff --git a/src/Graphic3d/Graphic3d_CAspectLine.hxx b/src/Graphic3d/Graphic3d_CAspectLine.hxx index 45b97017bc..2a2315348f 100644 --- a/src/Graphic3d/Graphic3d_CAspectLine.hxx +++ b/src/Graphic3d/Graphic3d_CAspectLine.hxx @@ -15,9 +15,9 @@ #ifndef _Graphic3d_CAspectLine_HeaderFile #define _Graphic3d_CAspectLine_HeaderFile -#include #include #include +#include class Graphic3d_CAspectLine { diff --git a/src/Graphic3d/Graphic3d_CAspectMarker.hxx b/src/Graphic3d/Graphic3d_CAspectMarker.hxx index f57b69bda5..3378f15ad9 100644 --- a/src/Graphic3d/Graphic3d_CAspectMarker.hxx +++ b/src/Graphic3d/Graphic3d_CAspectMarker.hxx @@ -16,10 +16,10 @@ #define _Graphic3d_CAspectMarker_HeaderFile #include -#include #include #include #include +#include class Graphic3d_CAspectMarker { diff --git a/src/Graphic3d/Graphic3d_CAspectText.hxx b/src/Graphic3d/Graphic3d_CAspectText.hxx index 036adcabae..572e5beaf1 100644 --- a/src/Graphic3d/Graphic3d_CAspectText.hxx +++ b/src/Graphic3d/Graphic3d_CAspectText.hxx @@ -15,9 +15,9 @@ #ifndef _Graphic3d_CAspectText_HeaderFile #define _Graphic3d_CAspectText_HeaderFile -#include #include #include +#include class Graphic3d_CAspectText { diff --git a/src/Graphic3d/Graphic3d_CLight.hxx b/src/Graphic3d/Graphic3d_CLight.hxx index bc8646f939..c11200bd90 100644 --- a/src/Graphic3d/Graphic3d_CLight.hxx +++ b/src/Graphic3d/Graphic3d_CLight.hxx @@ -14,9 +14,10 @@ #ifndef _Graphic3d_CLight_HeaderFile #define _Graphic3d_CLight_HeaderFile -#include -#include +#include #include +#include +#include //! Light definition struct Graphic3d_CLight @@ -24,14 +25,14 @@ struct Graphic3d_CLight public: - Graphic3d_Vec4 Color; //!< light color - Graphic3d_Vec4 Position; //!< light position - Graphic3d_Vec4 Direction; //!< direction of directional/spot light - Graphic3d_Vec4 Params; //!< packed light parameters - Standard_Integer Type; //!< Visual3d_TypeOfLightSource enumeration - Standard_Boolean IsHeadlight; //!< flag to mark head light - Standard_ShortReal Smoothness; //!< radius (cone angle) for point (directional) light - Standard_ShortReal Intensity; //!< intensity multiplier for light + Graphic3d_Vec4 Color; //!< light color + Graphic3d_Vec4 Position; //!< light position + Graphic3d_Vec4 Direction; //!< direction of directional/spot light + Graphic3d_Vec4 Params; //!< packed light parameters + Graphic3d_TypeOfLightSource Type; //!< Graphic3d_TypeOfLightSource enumeration + Standard_Boolean IsHeadlight; //!< flag to mark head light + Standard_ShortReal Smoothness; //!< radius (cone angle) for point (directional) light + Standard_ShortReal Intensity; //!< intensity multiplier for light //! Const attenuation factor of positional light source Standard_ShortReal ConstAttenuation() const { return Params.x(); } @@ -62,7 +63,7 @@ public: Position (0.0f, 0.0f, 0.0f, 1.0f), Direction (0.0f, 0.0f, 0.0f, 0.0f), Params (0.0f, 0.0f, 0.0f, 0.0f), - Type (0), + Type (Graphic3d_TOLS_AMBIENT), IsHeadlight (Standard_False), Smoothness (0.0f), Intensity (1.0f) @@ -76,4 +77,6 @@ public: }; +typedef NCollection_List Graphic3d_ListOfCLight; + #endif // Graphic3d_CLight_HeaderFile diff --git a/src/Graphic3d/Graphic3d_CStructure.hxx b/src/Graphic3d/Graphic3d_CStructure.hxx index adff5b20eb..126835e07e 100644 --- a/src/Graphic3d/Graphic3d_CStructure.hxx +++ b/src/Graphic3d/Graphic3d_CStructure.hxx @@ -24,6 +24,7 @@ #include #include #include +#include class Graphic3d_GraphicDriver; class Graphic3d_StructureManager; diff --git a/src/Graphic3d/Graphic3d_CView.cxx b/src/Graphic3d/Graphic3d_CView.cxx new file mode 100644 index 0000000000..5568201086 --- /dev/null +++ b/src/Graphic3d/Graphic3d_CView.cxx @@ -0,0 +1,1079 @@ +// Copyright (c) 2015 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include + +//======================================================================= +//function : Constructor +//purpose : +//======================================================================= +Graphic3d_CView::Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr) +: myStructureManager (theMgr), + myHiddenObjects (new Graphic3d_NMapOfTransient()), + myIsInComputedMode (Standard_False), + myIsActive (Standard_False), + myIsRemoved (Standard_False), + myVisualization (Graphic3d_TOV_WIREFRAME) +{ + myId = myStructureManager->Identification (this); +} + +//======================================================================= +//function : Destructor +//purpose : +//======================================================================= +Graphic3d_CView::~Graphic3d_CView() +{ + if (!IsRemoved()) + { + myStructureManager->UnIdentification (this); + } +} + +// ======================================================================= +// function : Activate +// purpose : +// ======================================================================= +void Graphic3d_CView::Activate() +{ + if (!IsActive()) + { + myIsActive = Standard_True; + + // Activation of a new view => + // Display structures that can be displayed in this new view. + // All structures with status + // Displayed in ViewManager are returned and displayed in + // the view directly, if the structure is not already + // displayed and if the view accepts it in its context. + Graphic3d_MapOfStructure aDisplayedStructs; + myStructureManager->DisplayedStructures (aDisplayedStructs); + for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next()) + { + const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); + if (IsDisplayed (aStruct)) + { + continue; + } + + // If the structure can be displayed in the new context of the view, it is displayed. + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); + if (anAnswer == Graphic3d_TOA_YES + || anAnswer == Graphic3d_TOA_COMPUTE) + { + Display (aStruct, Aspect_TOU_WAIT); + } + } + } + + Update (myStructureManager->UpdateMode()); +} + +// ======================================================================= +// function : Deactivate +// purpose : +// ======================================================================= +void Graphic3d_CView::Deactivate() +{ + if (IsActive()) + { + // Deactivation of a view => + // Removal of structures displayed in this view. + // All structures with status + // Displayed in ViewManager are returned and removed from + // the view directly, if the structure is not already + // displayed and if the view accepts it in its context. + Graphic3d_MapOfStructure aDisplayedStructs; + myStructureManager->DisplayedStructures (aDisplayedStructs); + for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next()) + { + const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); + if (!IsDisplayed (aStruct)) + { + continue; + } + + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); + if (anAnswer == Graphic3d_TOA_YES + || anAnswer == Graphic3d_TOA_COMPUTE) + { + Erase (aStruct, Aspect_TOU_WAIT); + } + } + + Update (myStructureManager->UpdateMode()); + myIsActive = Standard_False; + } +} + +// ======================================================================== +// function : Remove +// purpose : +// ======================================================================== +void Graphic3d_CView::Remove() +{ + if (IsRemoved()) + { + return; + } + + Graphic3d_MapOfStructure aDisplayedStructs (myStructsDisplayed); + + for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next()) + { + Erase (aStructIter.Value(), Aspect_TOU_WAIT); + } + + myStructsToCompute.Clear(); + myStructsComputed .Clear(); + myStructsDisplayed.Clear(); + + if (!myStructureManager.IsNull()) + { + myStructureManager->UnIdentification (this); + } + + myIsActive = Standard_False; + myIsRemoved = Standard_True; +} + +// ======================================================================== +// function : SetComputedMode +// purpose : +// ======================================================================== +void Graphic3d_CView::SetComputedMode (const Standard_Boolean theMode) +{ + if (( theMode && myIsInComputedMode) + || (!theMode && !myIsInComputedMode)) + { + return; + } + + myIsInComputedMode = theMode; + if (!myIsInComputedMode) + { + for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) + { + const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); + if (anAnswer != Graphic3d_TOA_COMPUTE) + { + continue; + } + + const Standard_Integer anIndex = IsComputed (aStruct); + if (anIndex != 0) + { + const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex); + eraseStructure (aStructComp->CStructure()); + displayStructure (aStruct->CStructure(), aStruct->DisplayPriority()); + } + } + return; + } + + for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next()) + { + Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key(); + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); + if (anAnswer != Graphic3d_TOA_COMPUTE) + { + continue; + } + + const Standard_Integer anIndex = IsComputed (aStruct); + if (anIndex != 0) + { + eraseStructure (aStruct->CStructure()); + displayStructure (myStructsComputed.Value (anIndex)->CStructure(), aStruct->DisplayPriority()); + + Display (aStruct, Aspect_TOU_WAIT); + if (aStruct->IsHighlighted()) + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex); + if (!aCompStruct->IsHighlighted()) + { + aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False); + } + } + } + else + { + TColStd_Array2OfReal aTrsf (0, 3, 0, 3); + aStruct->Transform (aTrsf); + Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this); + aCompStruct->SetHLRValidation (Standard_True); + + const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME + && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING; + const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING + && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME; + if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME); + if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING); + + if (aStruct->IsHighlighted()) + { + aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False); + } + + Standard_Boolean hasResult = Standard_False; + const Standard_Integer aNbToCompute = myStructsToCompute.Length(); + const Standard_Integer aStructId = aStruct->Identification(); + for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter) + { + if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId) + { + hasResult = Standard_True; + myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct; + break; + } + } + + if (!hasResult) + { + myStructsToCompute.Append (aStruct); + myStructsComputed .Append (aCompStruct); + } + + eraseStructure (aStruct->CStructure()); + displayStructure (aCompStruct->CStructure(), aStruct->DisplayPriority()); + } + } + Update (myStructureManager->UpdateMode()); +} + +// ======================================================================= +// function : ReCompute +// purpose : +// ======================================================================= +void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct) +{ + theStruct->CalculateBoundBox(); + if (!theStruct->IsMutable() + && !theStruct->CStructure()->IsForHighlight + && !theStruct->CStructure()->IsInfinite) + { + const Standard_Integer aLayerId = theStruct->DisplayPriority(); + InvalidateBVHData (aLayerId); + } + + if (!ComputedMode() + || !IsActive() + || !theStruct->IsDisplayed()) + { + return; + } + + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual()); + if (anAnswer != Graphic3d_TOA_COMPUTE) + { + return; + } + + const Standard_Integer anIndex = IsComputed (theStruct); + if (anIndex == 0) + { + return; + } + + // compute + validation + TColStd_Array2OfReal anIdent (0, 3, 0, 3); + for (Standard_Integer aRow = 0; aRow <= 3; ++aRow) + { + for (Standard_Integer aCol = 0; aCol <= 3; ++aCol) + { + anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0); + } + } + TColStd_Array2OfReal aTrsf (0, 3, 0, 3); + theStruct->Transform (aTrsf); + + Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex); + Handle(Graphic3d_Structure) aCompStruct = aCompStructOld; + aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); + theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct) + : theStruct->Compute (this, aCompStruct); + aCompStruct->SetHLRValidation (Standard_True); + + // of which type will be the computed? + const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME + && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING; + const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING + && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME; + if (toComputeWireframe) + { + aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME); + } + else if (toComputeShading) + { + aCompStruct->SetVisual (Graphic3d_TOS_SHADING); + } + + if (theStruct->IsHighlighted()) + { + aCompStruct->Highlight (Aspect_TOHM_COLOR, theStruct->HighlightColor(), Standard_False); + } + + // The previous calculation is removed and the new one is displayed + eraseStructure (aCompStructOld->CStructure()); + displayStructure (aCompStruct->CStructure(), theStruct->DisplayPriority()); + + // why not just replace existing items? + //myStructsToCompute.ChangeValue (anIndex) = theStruct; + //myStructsComputed .ChangeValue (anIndex) = aCompStruct; + + // hlhsr and the new associated compute are added + myStructsToCompute.Append (theStruct); + myStructsComputed .Append (aCompStruct); + + // hlhsr and the new associated compute are removed + myStructsToCompute.Remove (anIndex); + myStructsComputed .Remove (anIndex); +} + +// ======================================================================= +// function : Update +// purpose : +// ======================================================================= +void Graphic3d_CView::Update (const Aspect_TypeOfUpdate theUpdateMode) +{ + myMinMax.Invalidate(); + if (theUpdateMode == Aspect_TOU_ASAP) + { + Compute(); + Redraw(); + } +} + +// ======================================================================= +// function : ContainsFacet +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_CView::ContainsFacet() const +{ + for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) + { + if (aStructIter.Key()->ContainsFacet()) + { + return Standard_True; + } + } + return Standard_False; +} + +// ======================================================================= +// function : ContainsFacet +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_CView::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const +{ + for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next()) + { + if (aStructIter.Key()->ContainsFacet()) + { + return Standard_True; + } + } + return Standard_False; +} + +// ======================================================================= +// function : DisplayedStructures +// purpose : +// ======================================================================= +void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const +{ + for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) + { + theStructures.Add (aStructIter.Key()); + } +} + +//! Auxiliary method for MinMaxValues() method +inline void addStructureBndBox (const Handle(Graphic3d_Structure)& theStruct, + const Standard_Boolean theToIgnoreInfiniteFlag, + Bnd_Box& theBndBox) +{ + if (!theStruct->IsVisible()) + { + return; + } + else if (theStruct->IsInfinite() + && !theToIgnoreInfiniteFlag) + { + // XMin, YMin .... ZMax are initialized by means of infinite line data + const Bnd_Box aBox = theStruct->MinMaxValues (Standard_False); + if (!aBox.IsWhole() + && !aBox.IsVoid()) + { + theBndBox.Add (aBox); + } + return; + } + + // Only non-empty and non-infinite structures + // are taken into account for calculation of MinMax + if (theStruct->IsEmpty() + || theStruct->TransformPersistenceMode() != Graphic3d_TMF_None) + { + return; + } + + // "FitAll" operation ignores object with transform persistence parameter + const Bnd_Box aBox = theStruct->MinMaxValues (theToIgnoreInfiniteFlag); + + // To prevent float overflow at camera parameters calculation and further + // rendering, bounding boxes with at least one vertex coordinate out of + // float range are skipped by view fit algorithms + if (Abs (aBox.CornerMax().X()) >= ShortRealLast() || + Abs (aBox.CornerMax().Y()) >= ShortRealLast() || + Abs (aBox.CornerMax().Z()) >= ShortRealLast() || + Abs (aBox.CornerMin().X()) >= ShortRealLast() || + Abs (aBox.CornerMin().Y()) >= ShortRealLast() || + Abs (aBox.CornerMin().Z()) >= ShortRealLast()) + return; + + theBndBox.Add (aBox); +} + +// ======================================================================= +// function : MinMaxValues +// purpose : +// ======================================================================= +Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const +{ + if (myMinMax.IsOutdated (theToIgnoreInfiniteFlag)) + { + myMinMax.BoundingBox (theToIgnoreInfiniteFlag) = MinMaxValues (myStructsDisplayed, theToIgnoreInfiniteFlag); + myMinMax.IsOutdated (theToIgnoreInfiniteFlag) = Standard_False; + } + + return myMinMax.BoundingBox (theToIgnoreInfiniteFlag); +} + +// ======================================================================= +// function : MinMaxValues +// purpose : +// ======================================================================= +Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet, + const Standard_Boolean theToIgnoreInfiniteFlag) const +{ + Bnd_Box aResult; + const Standard_Integer aViewId = Identification(); + for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next()) + { + const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key(); + if (!aStructIter.Value()->IsVisible()) + { + continue; + } + else if (!aStructIter.Value()->CStructure()->ViewAffinity.IsNull() + && !aStructIter.Value()->CStructure()->ViewAffinity->IsVisible (aViewId)) + { + continue; + } + + addStructureBndBox (aStructure, theToIgnoreInfiniteFlag, aResult); + } + return aResult; +} + +// ======================================================================= +// function : acceptDisplay +// purpose : +// ======================================================================= +Graphic3d_TypeOfAnswer Graphic3d_CView::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const +{ + switch (theStructType) + { + case Graphic3d_TOS_ALL: + { + return Graphic3d_TOA_YES; // The structure accepts any type of view + } + case Graphic3d_TOS_SHADING: + { + return myVisualization == Graphic3d_TOV_SHADING + ? Graphic3d_TOA_YES + : Graphic3d_TOA_NO; + } + case Graphic3d_TOS_WIREFRAME: + { + return myVisualization == Graphic3d_TOV_WIREFRAME + ? Graphic3d_TOA_YES + : Graphic3d_TOA_NO; + } + case Graphic3d_TOS_COMPUTED: + { + return (myVisualization == Graphic3d_TOV_SHADING || myVisualization == Graphic3d_TOV_WIREFRAME) + ? Graphic3d_TOA_COMPUTE + : Graphic3d_TOA_NO; + } + } + return Graphic3d_TOA_NO; +} + +// ======================================================================= +// function : Compute +// purpose : +// ======================================================================= +void Graphic3d_CView::Compute() +{ + // force HLRValidation to False on all structures calculated in the view + const Standard_Integer aNbCompStructs = myStructsComputed.Length(); + for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter) + { + myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False); + } + + if (!ComputedMode()) + { + return; + } + + // Change of orientation or of projection type => + // Remove structures that were calculated for the previous orientation. + // Recalculation of new structures. + NCollection_Sequence aStructsSeq; + for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) + { + const Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual()); + if (anAnswer == Graphic3d_TOA_COMPUTE) + { + aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated + } + } + + for (NCollection_Sequence::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next()) + { + Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT); + } +} + +// ======================================================================= +// function : Clear +// purpose : +// ======================================================================= +void Graphic3d_CView::Clear (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Boolean theWithDestruction) +{ + const Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0) + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex); + aCompStruct->GraphicClear (theWithDestruction); + aCompStruct->SetHLRValidation (Standard_False); + } +} + +// ======================================================================= +// function : Connect +// purpose : +// ======================================================================= +void Graphic3d_CView::Connect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter) +{ + Standard_Integer anIndexM = IsComputed (theMother); + Standard_Integer anIndexD = IsComputed (theDaughter); + if (anIndexM != 0 + && anIndexD != 0) + { + const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM); + const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD); + aStructM->GraphicConnect (aStructD); + } +} + +// ======================================================================= +// function : Disconnect +// purpose : +// ======================================================================= +void Graphic3d_CView::Disconnect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter) +{ + Standard_Integer anIndexM = IsComputed (theMother); + Standard_Integer anIndexD = IsComputed (theDaughter); + if (anIndexM != 0 + && anIndexD != 0) + { + const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM); + const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD); + aStructM->GraphicDisconnect (aStructD); + } +} + +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure) +{ + Display (theStructure, myStructureManager->UpdateMode()); +} + +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfUpdate theUpdateMode) +{ + if (!IsActive()) + { + return; + } + + // If Display on a structure present in the list of calculated structures while it is not + // or more, of calculated type => + // - removes it as well as the associated old computed + // THis happens when hlhsr becomes again of type e non computed after SetVisual. + Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0 + && theStructure->Visual() != Graphic3d_TOS_COMPUTED) + { + myStructsToCompute.Remove (anIndex); + myStructsComputed .Remove (anIndex); + anIndex = 0; + } + + Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual()); + if (anAnswer == Graphic3d_TOA_NO) + { + return; + } + + if (!ComputedMode()) + { + anAnswer = Graphic3d_TOA_YES; + } + + if (anAnswer == Graphic3d_TOA_YES) + { + if (!myStructsDisplayed.Add (theStructure)) + { + return; + } + + theStructure->CalculateBoundBox(); + displayStructure (theStructure->CStructure(), theStructure->DisplayPriority()); + Update (theUpdateMode); + return; + } + else if (anAnswer != Graphic3d_TOA_COMPUTE) + { + return; + } + + if (anIndex != 0) + { + // Already computed, is COMPUTED still valid? + const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex); + if (anOldStruct->HLRValidation()) + { + // Case COMPUTED valid, to be displayed + if (!myStructsDisplayed.Add (theStructure)) + { + return; + } + + displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority()); + Update (theUpdateMode); + return; + } + else + { + // Case COMPUTED invalid + // Is there another valid representation? + // Find in the sequence of already calculated structures + // 1/ Structure having the same Owner as + // 2/ That is not + // 3/ The COMPUTED which of is valid + const Standard_Integer aNewIndex = HaveTheSameOwner (theStructure); + if (aNewIndex != 0) + { + // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed + if (!myStructsDisplayed.Add (theStructure)) + { + return; + } + + const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex); + myStructsComputed.SetValue (anIndex, aNewStruct); + displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority()); + Update (theUpdateMode); + return; + } + else + { + // Case COMPUTED invalid, WITHOUT a valid of replacement + // COMPUTED is removed if displayed + if (myStructsDisplayed.Contains (theStructure)) + { + eraseStructure (anOldStruct->CStructure()); + } + } + } + } + + // Compute + Validation + Handle(Graphic3d_Structure) aStruct; + TColStd_Array2OfReal aTrsf (0, 3, 0, 3); + theStructure->Transform (aTrsf); + if (anIndex != 0) + { + TColStd_Array2OfReal anIdent (0, 3, 0, 3); + for (Standard_Integer ii = 0; ii <= 3; ++ii) + { + for (Standard_Integer jj = 0; jj <= 3; ++jj) + { + anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0); + } + } + + aStruct = myStructsComputed.Value (anIndex); + aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); + if (theStructure->IsTransformed()) + { + theStructure->Compute (this, aTrsf, aStruct); + } + else + { + theStructure->Compute (this, aStruct); + } + } + else + { + aStruct = theStructure->IsTransformed() + ? theStructure->Compute (this, aTrsf) + : theStructure->Compute (this); + } + + aStruct->SetHLRValidation (Standard_True); + + // TOCOMPUTE and COMPUTED associated to sequences are added + myStructsToCompute.Append (theStructure); + myStructsComputed .Append (aStruct); + + // The previous are removed if necessary + if (anIndex != 0) + { + myStructsToCompute.Remove (anIndex); + myStructsComputed .Remove (anIndex); + } + + // Of which type will be the computed? + const Standard_Boolean toComputeWireframe = myVisualization == Graphic3d_TOV_WIREFRAME + && theStructure->ComputeVisual() != Graphic3d_TOS_SHADING; + const Standard_Boolean toComputeShading = myVisualization == Graphic3d_TOV_SHADING + && theStructure->ComputeVisual() != Graphic3d_TOS_WIREFRAME; + if (!toComputeShading && !toComputeWireframe) + { + anAnswer = Graphic3d_TOA_NO; + } + else + { + aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING); + anAnswer = acceptDisplay (aStruct->Visual()); + } + + if (theStructure->IsHighlighted()) + { + aStruct->Highlight (Aspect_TOHM_COLOR, theStructure->HighlightColor(), Standard_False); + } + + // It is displayed only if the calculated structure + // has a proper type corresponding to the one of the view. + if (anAnswer == Graphic3d_TOA_NO) + { + return; + } + + myStructsDisplayed.Add (theStructure); + displayStructure (aStruct->CStructure(), theStructure->DisplayPriority()); + + Update (theUpdateMode); +} + +// ======================================================================= +// function : Erase +// purpose : +// ======================================================================= +void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure) +{ + Erase (theStructure, myStructureManager->UpdateMode()); +} + +// ======================================================================= +// function : Erase +// purpose : +// ======================================================================= +void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfUpdate theUpdateMode) +{ + if (!IsDisplayed (theStructure)) + { + return; + } + + Graphic3d_TypeOfAnswer anAnswer = acceptDisplay (theStructure->Visual()); + if (!ComputedMode()) + { + anAnswer = Graphic3d_TOA_YES; + } + + if (anAnswer != Graphic3d_TOA_COMPUTE) + { + eraseStructure (theStructure->CStructure()); + } + else if (anAnswer == Graphic3d_TOA_COMPUTE && myIsInComputedMode) + { + const Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0) + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); + eraseStructure (aCompStruct->CStructure()); + } + } + myStructsDisplayed.Remove (theStructure); + Update (theUpdateMode); +} + +// ======================================================================= +// function : Highlight +// purpose : +// ======================================================================= +void Graphic3d_CView::Highlight (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfHighlightMethod theMethod) +{ + const Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0) + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); + aCompStruct->Highlight (theMethod, theStructure->HighlightColor(), Standard_False); + } +} + +// ======================================================================= +// function : SetTransform +// purpose : +// ======================================================================= +void Graphic3d_CView::SetTransform (const Handle(Graphic3d_Structure)& theStructure, + const TColStd_Array2OfReal& theTrsf) +{ + const Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0) + { + // Test is somewhat light ! + // trsf is transferred only if it is : + // a translation + // a scale + if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0 + || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0 + || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0) + { + ReCompute (theStructure); + } + else + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); + aCompStruct->GraphicTransform (theTrsf); + } + } + + theStructure->CalculateBoundBox(); + if (!theStructure->IsMutable() + && !theStructure->CStructure()->IsForHighlight + && !theStructure->CStructure()->IsInfinite) + { + const Graphic3d_ZLayerId aLayerId = theStructure->GetZLayer(); + InvalidateBVHData (aLayerId); + } +} + +// ======================================================================= +// function : UnHighlight +// purpose : +// ======================================================================= +void Graphic3d_CView::UnHighlight (const Handle(Graphic3d_Structure)& theStructure) +{ + Standard_Integer anIndex = IsComputed (theStructure); + if (anIndex != 0) + { + const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); + aCompStruct->GraphicUnHighlight(); + } +} + +// ======================================================================== +// function : IsComputed +// purpose : +// ======================================================================== +Standard_Boolean Graphic3d_CView::IsComputed (const Standard_Integer theStructId, + Handle(Graphic3d_Structure)& theComputedStruct) const +{ + theComputedStruct.Nullify(); + if (!ComputedMode()) + return Standard_False; + + const Standard_Integer aNbStructs = myStructsToCompute.Length(); + for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter) + { + if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId) + { + theComputedStruct = myStructsComputed (aStructIter); + return Standard_True; + } + } + return Standard_False; +} + +// ======================================================================= +// function : IsComputed +// purpose : +// ======================================================================= +Standard_Integer Graphic3d_CView::IsComputed (const Handle(Graphic3d_Structure)& theStructure) const +{ + const Standard_Integer aStructId = theStructure->Identification(); + const Standard_Integer aNbStructs = myStructsToCompute.Length(); + for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter) + { + const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter); + if (aStruct->Identification() == aStructId) + { + return aStructIter; + } + } + return 0; +} + +// ======================================================================= +// function : IsDisplayed +// purpose : +// ======================================================================= +Standard_Boolean Graphic3d_CView::IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const +{ + return myStructsDisplayed.Contains (theStructure); +} + +// ======================================================================= +// function : ChangePriority +// purpose : +// ======================================================================= +void Graphic3d_CView::ChangePriority (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Integer /*theOldPriority*/, + const Standard_Integer theNewPriority) +{ + if (!IsActive() + || !IsDisplayed (theStructure)) + { + return; + } + + if (!myIsInComputedMode) + { + changePriority (theStructure->CStructure(), theNewPriority); + return; + } + + const Standard_Integer anIndex = IsComputed (theStructure); + const Handle(Graphic3d_CStructure)& aCStruct = anIndex != 0 + ? myStructsComputed.Value (anIndex)->CStructure() + : theStructure->CStructure(); + + changePriority (aCStruct, theNewPriority); +} + +// ======================================================================= +// function : ChangeZLayer +// purpose : +// ======================================================================= +void Graphic3d_CView::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, + const Graphic3d_ZLayerId theLayerId) +{ + if (!IsActive() + || !IsDisplayed (theStructure)) + { + return; + } + + if (!myIsInComputedMode) + { + changeZLayer (theStructure->CStructure(), theLayerId); + return; + } + + const Standard_Integer anIndex = IsComputed (theStructure); + Handle(Graphic3d_CStructure) aCStruct = anIndex != 0 + ? myStructsComputed.Value (anIndex)->CStructure() + : theStructure->CStructure(); + + changeZLayer (aCStruct, theLayerId); +} + +// ======================================================================= +// function : HaveTheSameOwner +// purpose : +// ======================================================================= +Standard_Integer Graphic3d_CView::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const +{ + // Find in the sequence of already calculated structures + // 1/ Structure with the same Owner as + // 2/ Which is not + // 3/ COMPUTED which of is valid + const Standard_Integer aNbToCompStructs = myStructsToCompute.Length(); + for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter) + { + const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter); + if (aStructToComp->Owner() == theStructure->Owner() + && aStructToComp->Identification() != theStructure->Identification()) + { + const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter); + if (aStructComp->HLRValidation()) + { + return aStructIter; + } + } + } + return 0; +} + +// ======================================================================= +// function : CopySettings +// purpose : +// ======================================================================= +void Graphic3d_CView::CopySettings (const Handle(Graphic3d_CView)& theOther) +{ + ChangeRenderingParams() = theOther->RenderingParams(); + SetAntialiasingEnabled (theOther->IsAntialiasingEnabled()); + SetBackground (theOther->Background()); + SetGradientBackground (theOther->GradientBackground()); + SetBackgroundImage (theOther->BackgroundImage()); + SetBackgroundImageStyle (theOther->BackgroundImageStyle()); + SetTextureEnv (theOther->TextureEnv()); + SetCullingEnabled (theOther->IsCullingEnabled()); + SetShadingModel (theOther->ShadingModel()); + SetSurfaceDetailType (theOther->SurfaceDetailType()); + SetBackfacingModel (theOther->BackfacingModel()); + SetCamera (new Graphic3d_Camera (theOther->Camera())); + SetBackZClippingOn (theOther->BackZClippingIsOn()); + SetFrontZClippingOn (theOther->FrontZClippingIsOn()); + SetZClippingBackPlane (theOther->ZClippingBackPlane()); + SetZClippingFrontPlane (theOther->ZClippingFrontPlane()); + SetDepthCueingOn (theOther->DepthCueingIsOn()); + SetDepthCueingBackPlane (theOther->DepthCueingBackPlane()); + SetDepthCueingFrontPlane (theOther->DepthCueingFrontPlane()); + SetGLLightEnabled (theOther->IsGLLightEnabled()); + SetLights (theOther->Lights()); + SetClipPlanes (theOther->ClipPlanes()); +} diff --git a/src/Graphic3d/Graphic3d_CView.hxx b/src/Graphic3d/Graphic3d_CView.hxx index 7b2201f68a..ec55376985 100644 --- a/src/Graphic3d/Graphic3d_CView.hxx +++ b/src/Graphic3d/Graphic3d_CView.hxx @@ -1,4 +1,4 @@ -// Copyright (c) 1999-2014 OPEN CASCADE SAS +// Copyright (c) 2015 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -14,128 +14,578 @@ #ifndef _Graphic3d_CView_HeaderFile #define _Graphic3d_CView_HeaderFile -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include - #include +#include +#include +#include +#include +#include +#include +#include +#include #include - -class CALL_DEF_VIEWCONTEXT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class Graphic3d_CView; +class Graphic3d_GraphicDriver; +class Graphic3d_StructureManager; + +DEFINE_STANDARD_HANDLE (Graphic3d_CView, Graphic3d_DataStructureManager) + +//! Base class of a graphical view that carries out rendering process for a concrete +//! implementation of graphical driver. Provides virtual interfaces for redrawing its +//! contents, management of displayed structures and render settings. The source code +//! of the class itself implements functionality related to management of +//! computed (HLR or "view-dependent") structures. +class Graphic3d_CView : public Graphic3d_DataStructureManager { - public: - CALL_DEF_VIEWCONTEXT() - : Aliasing (0), - BackZClipping (0), - FrontZClipping (0), - DepthCueing (0), - ZClipFrontPlane (0.0f), - ZClipBackPlane (0.0f), - DepthFrontPlane (0.0f), - DepthBackPlane (0.0f), - Model (0), - Visualization (0), - NbActiveLight (0), - ActiveLight (NULL), - SurfaceDetail (0), - ClipPlanes() - { - // - } + //! Constructor. + Standard_EXPORT Graphic3d_CView (const Handle(Graphic3d_StructureManager)& theMgr); + + //! Destructor. + Standard_EXPORT virtual ~Graphic3d_CView(); + + //! Returns the identification number of the view. + Standard_Integer Identification() const { return myId; } + + //! Activates the view. Map the associated window on the screen and post the view in this window. + //! Warning: Raises ViewDefinitionError if the associated window isn't defined. + Standard_EXPORT virtual void Activate(); + + //! Deactivates the view. Unmap the associated window on the screen and unpost the view in this window. + //! Warning: Raises ViewDefinitionError if the associated window isn't defined. + Standard_EXPORT virtual void Deactivate(); + + //! Returns the activity flag of the view. + Standard_Boolean IsActive() const { return myIsActive; } + + //! Erases the view and removes from graphic driver. + //! No more graphic operations are allowed in this view after the call. + Standard_EXPORT virtual void Remove(); + + //! Returns true if the view was removed. + Standard_Boolean IsRemoved() const { return myIsRemoved; } public: - int Aliasing; + //! Returns visualization type of the view. + Graphic3d_TypeOfVisualization VisualizationType() const { return myVisualization; } - int BackZClipping; - int FrontZClipping; + //! Sets visualization type of the view. + void SetVisualizationType (const Graphic3d_TypeOfVisualization theType) { myVisualization = theType; } - int DepthCueing; + //! Switches computed HLR mode in the view + Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode); - float ZClipFrontPlane; - float ZClipBackPlane; + //! Returns the computed HLR mode state + Standard_Boolean ComputedMode() const { return myIsInComputedMode; } - float DepthFrontPlane; - float DepthBackPlane; + //! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED. + Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure); - int Model; - int Visualization; + //! Updates screen in function of modifications of the structures. + Standard_EXPORT void Update (const Aspect_TypeOfUpdate theUpdateMode); - int NbActiveLight; - Graphic3d_CLight* ActiveLight; + //! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles. + Standard_EXPORT Standard_Boolean ContainsFacet() const; - Handle(Graphic3d_TextureEnv) TextureEnv; - int SurfaceDetail; + //! Returns Standard_True if one of the structures in the set contains Polygons, Triangles or Quadrangles. + Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& theSet) const; - Graphic3d_SequenceOfHClipPlane ClipPlanes; + //! Returns the set of structures displayed in this view. + Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const; - Handle(Graphic3d_Camera) Camera; -}; + //! Returns number of displayed structures in the view. + Standard_Integer NumberOfDisplayedStructures() const { return myStructsDisplayed.Extent(); } -class Graphic3d_CView -{ + //! Returns map of objects hidden within this specific view (not viewer-wise). + const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const { return myHiddenObjects; } + + //! Returns map of objects hidden within this specific view (not viewer-wise). + Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects() { return myHiddenObjects; } + + //! Returns Standard_True in case if the structure with the given is + //! in list of structures to be computed and stores computed struct to . + Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId, + Handle(Graphic3d_Structure)& theComputedStruct) const; + + //! Returns the coordinates of the boundary box of all + //! structures displayed in the view. + //! If is TRUE, then the boundary box + //! also includes minimum and maximum limits of graphical elements + //! forming parts of infinite structures. + Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const; + + //! Returns the coordinates of the boundary box of all structures in the set . + //! If is TRUE, then the boundary box + //! also includes minimum and maximum limits of graphical elements + //! forming parts of infinite structures. + Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet, + const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const; + + //! Returns the structure manager handle which manage structures associated with this view. + const Handle(Graphic3d_StructureManager)& StructureManager() const { return myStructureManager; } + +private: + + friend class Graphic3d_StructureManager; + + //! Is it possible to display the structure in the view? + Standard_EXPORT Graphic3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const; + + //! Computes the new presentation of the structures displayed in this view with the type Graphic3d_TOS_COMPUTED. + Standard_EXPORT void Compute(); + + //! Clears the structure in this view. + Standard_EXPORT void Clear (const Handle(Graphic3d_Structure)& theStructure, const Standard_Boolean theWithDestruction); + + //! Connects the structures. + Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter); + + //! Disconnects the structures. + Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter); + + //! Displays the structure in the view. + Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure); + + //! Display the structure in the view. + Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfUpdate theUpdateMode); + + //! Erases the structure from the view. + Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure); + + //! Erases the structure from the view. + Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfUpdate theUpdateMode); + + //! Highlights the structure in the view. + Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfHighlightMethod theMethod); + + //! Transforms the structure in the view. + Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& theStructure, + const TColStd_Array2OfReal& theTrsf); + + //! Suppress the highlighting on the structure + //! in the view . + Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& theStructure); + + //! Returns an index != 0 if the structure have another structure computed for the view . + Standard_EXPORT Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& theStructure) const; + + //! Returns true if the structure is displayed in the view. + Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& theStructure) const; + + //! Changes the display priority of the structure. + Standard_EXPORT void ChangePriority (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Integer theOldPriority, + const Standard_Integer theNewPriority); + + //! Change Z layer of already displayed structure in the view. + Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, + const Graphic3d_ZLayerId theLayerId); + + //! Returns an index != 0 if the structure have the same owner than another structure + //! in the sequence of the computed structures. + Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStructure) const; public: - Graphic3d_CView() - : WsId (-1), - ViewId (0), - ptrView (NULL), - IsDeleted (0), - IsOpen (0), - Active (0), - ptrUnderLayer (NULL), - ptrOverLayer (NULL), - Backfacing (0), - GContext (NULL), - GDisplayCB (NULL), - GClientData (NULL), - ptrFBO (NULL), - WasRedrawnGL (0), - IsCullingEnabled (Standard_True) - { - memset (&DefWindow, 0, sizeof(DefWindow)); - } + //! Redraw content of the view. + virtual void Redraw() = 0; + + //! Redraw immediate content of the view. + virtual void RedrawImmediate() = 0; + + //! Invalidates content of the view but does not redraw it. + virtual void Invalidate() = 0; + + //! Return true if view content cache has been invalidated. + virtual Standard_Boolean IsInvalidated() = 0; + + //! Handle changing size of the rendering window. + virtual void Resized() = 0; + + //! @param theDrawToFrontBuffer Advanced option to modify rendering mode: + //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image. + //! Fast, so preferred for interactive work (used by default). + //! However these extra drawings will be missed in image dump since it is performed from back buffer. + //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen + //! in run-time (in case of slow hardware) and/or tearing may appear. + //! So this is strongly recommended to draw only simple (fast) structures. + //! 2. FALSE. Drawing immediate mode structures to the back buffer. + //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync + //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read + //! from the back buffer. + //! @return previous mode. + virtual Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) = 0; + + //! Creates and maps rendering window to the view. + //! @param theView [in] the view to associate with the window. + //! @param theWindow [in] the window. + //! @param theContext [in] the rendering context. If NULL the context will be created internally. + //! @param theDisplayCB [in] the display callback function. If is not a NULL value, then the callback will be + //! invoked at the end of the OCC graphic traversal and just before the swap of buffers. + //! @param theClientData [in] the client data for the callback. + virtual void SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext = NULL, + const Aspect_GraphicCallbackProc& theDisplayCB = NULL, + const Standard_Address theClientData = NULL) = 0; + + //! Returns the window associated to the view. + virtual Handle(Aspect_Window) Window() const = 0; + + //! Returns True if the window associated to the view is defined. + virtual Standard_Boolean IsDefined() const = 0; + + //! Displays z-buffer trihedron. + virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Standard_Real theScale = 0.02, + const Standard_Boolean theAsWireframe = Standard_True) = 0; + + //! Erases z-buffer trihedron. + virtual void TriedronErase() = 0; + + //! Setup parameters of z-buffer trihedron. + virtual void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED, + const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN, + const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1, + const Standard_Real theSizeRatio = 0.8, + const Standard_Real theAxisDiametr = 0.05, + const Standard_Integer theNbFacettes = 12) = 0; + + //! Displays trihedron echo. + virtual void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE) = 0; + + //! Returns data of a graduated trihedron + virtual const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() = 0; + + //! Displays Graduated Trihedron. + virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) = 0; + + //! Erases Graduated Trihedron. + virtual void GraduatedTrihedronErase() = 0; + + //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object. + //! @param theMin [in] the minimum point of scene. + //! @param theMax [in] the maximum point of scene. + virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) = 0; + + //! Reads depths of shown pixels of the given rectangle. + virtual void ReadDepths (const Standard_Integer theX, + const Standard_Integer theY, + const Standard_Integer theWidth, + const Standard_Integer theHeight, + const Standard_Address theBuffer) const = 0; + + //! Dump active rendering buffer into specified memory buffer. + virtual Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0; + + //! Print the contents of the view to the printer. + //! @param thePrinterDC pass the PrinterDeviceContext (HDC) + //! @param theToShowBackground when set to FALSE then print the view without background + //! color (background is white) else set to TRUE for printing + //! with current background color + //! @param theFileName if != NULL, then the view will be printed to a file + //! @param thePrintAlgorithm select print algorithm: stretch, tile + //! @param theScaleFactor scaling coefficient, used internally to scale the printings + //! accordingly to the scale factor selected in the printer properties dialog + //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if + //! the print operation failed due to the printer errors, or lack of system memory. This might be related + //! to insufficient memory or some internal errors. + //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver). + //! Warning: This function can reuse FBO assigned to the view, please take it into account + //! if you use it for your purposes. + virtual Standard_Boolean Print (const Aspect_Handle thePrinterDC, + const Standard_Boolean theToShowBackground, + const Standard_CString theFileName, + const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH, + const Standard_Real theScaleFactor = 1.0) = 0; + + //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). + //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits + //! on printing to laser printer). Notice however that results may differ a lot and + //! do not contain some elements. + virtual Standard_Boolean Export (const Standard_CString theFileName, + const Graphic3d_ExportFormat theFormat, + const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) = 0; + + //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated. + virtual void InvalidateBVHData (const Standard_Integer theLayerId) = 0; + + //! Add a new top-level z layer with ID for + //! the view. Z layers allow drawing structures in higher layers + //! in foreground of structures in lower layers. To add a structure + //! to desired layer on display it is necessary to set the layer + //! ID for the structure. + virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0; + + //! Remove Z layer from the specified view. All structures + //! displayed at the moment in layer will be displayed in default layer + //! ( the bottom-level z layer ). To unset layer ID from associated + //! structures use method UnsetZLayer (...). + virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0; + + //! Sets the settings for a single Z layer of specified view. + virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, + const Graphic3d_ZLayerSettings& theSettings) = 0; + + //! Returns pointer to an assigned framebuffer object. + virtual Graphic3d_PtrFrameBuffer FBO() const = 0; + + //! Sets framebuffer object for offscreen rendering. + virtual void SetFBO (const Graphic3d_PtrFrameBuffer theFBO) = 0; + + //! Generate offscreen FBO in the graphic library. + //! If not supported on hardware returns NULL. + virtual Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, + const Standard_Integer theHeight) = 0; + + //! Remove offscreen FBO from the graphic library + virtual void FBORelease (Graphic3d_PtrFrameBuffer& theFBOPtr) = 0; + + //! Read offscreen FBO configuration. + virtual void FBOGetDimensions (const Graphic3d_PtrFrameBuffer theFBOPtr, + Standard_Integer& theWidth, + Standard_Integer& theHeight, + Standard_Integer& theWidthMax, + Standard_Integer& theHeightMax) = 0; + + //! Change offscreen FBO viewport. + virtual void FBOChangeViewport (Graphic3d_PtrFrameBuffer& theFBOPtr, + const Standard_Integer theWidth, + const Standard_Integer theHeight) = 0; public: - int WsId; - int ViewId; - void* ptrView; + //! Copy visualization settings from another view. + //! Method is used for cloning views in viewer when its required to create view + //! with same view properties. + Standard_EXPORT virtual void CopySettings (const Handle(Graphic3d_CView)& theOther); + + //! Returns current rendering parameters and effect settings. + const Graphic3d_RenderingParams& RenderingParams() const { return myRenderParams; } + + //! Returns reference to current rendering parameters and effect settings. + Graphic3d_RenderingParams& ChangeRenderingParams() { return myRenderParams; } + + //! Returns true if anti-aliasing is enabled for the view. + virtual Standard_Boolean IsAntialiasingEnabled() const = 0; + + //! Enable or disable anti-aliasing in the view. + virtual void SetAntialiasingEnabled (const Standard_Boolean theIsEnabled) = 0; + + //! Returns background fill color. + virtual Aspect_Background Background() const = 0; + + //! Sets background fill color. + virtual void SetBackground (const Aspect_Background& theBackground) = 0; + + //! Returns gradient background fill colors. + virtual Aspect_GradientBackground GradientBackground() const = 0; + + //! Sets gradient background fill colors. + virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) = 0; + + //! Returns background image texture file path. + virtual TCollection_AsciiString BackgroundImage() = 0; + + //! Sets background image texture file path. + virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) = 0; + + //! Returns background image fill style. + virtual Aspect_FillMethod BackgroundImageStyle() const = 0; + + //! Sets background image fill style. + virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) = 0; + + //! Returns environment texture set for the view. + virtual Handle(Graphic3d_TextureEnv) TextureEnv() const = 0; + + //! Sets environment texture for the view. + virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) = 0; + + //! Returns the state of frustum culling optimization. + virtual Standard_Boolean IsCullingEnabled() const = 0; + + //! Enables or disables frustum culling optimization. + virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) = 0; + + //! Returns shading model of the view. + virtual Graphic3d_TypeOfShadingModel ShadingModel() const = 0; + + //! Sets shading model of the view. + virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) = 0; + + //! Returns surface detail type of the view. + virtual Graphic3d_TypeOfSurfaceDetail SurfaceDetailType() const = 0; + + //! Sets surface detail type of the view. + virtual void SetSurfaceDetailType (const Graphic3d_TypeOfSurfaceDetail theType) = 0; - int IsDeleted; - int IsOpen; + //! Return backfacing model used for the view. + virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const = 0; - int Active; + //! Sets backfacing model for the view. + virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) = 0; - CALL_DEF_VIEWCONTEXT Context; + //! Returns camera object of the view. + virtual const Handle(Graphic3d_Camera)& Camera() const = 0; - CALL_DEF_WINDOW DefWindow; + //! Sets camera used by the view. + virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) = 0; - void* ptrUnderLayer; - void* ptrOverLayer; + //! Returns the activity of back z-clipping plane. + virtual Standard_Boolean BackZClippingIsOn() const = 0; - int Backfacing; + //! Activates the back Z-clipping plane. + virtual void SetBackZClippingOn (const Standard_Boolean theIsOn) = 0; - Aspect_RenderingContext GContext; - Aspect_GraphicCallbackProc GDisplayCB; - void* GClientData; + //! Returns the definition of the back Z-clipping plane. + virtual Standard_Real ZClippingBackPlane() const = 0; - void* ptrFBO; + //! Sets the definition of the back Z-clipping plane. + virtual void SetZClippingBackPlane (const Standard_Real theValue) = 0; - //! Was the window redrawn by standard OpenGL? - mutable int WasRedrawnGL; + //! Returns the activity of front z-clipping plane. + virtual Standard_Boolean FrontZClippingIsOn() const = 0; - //! Specifies rendering parameters and effects. - Graphic3d_RenderingParams RenderParams; + //! Activates the front Z-clipping plane. + virtual void SetFrontZClippingOn (const Standard_Boolean theIsOn) = 0; - //! Enables/disables frustum culling. - Standard_Boolean IsCullingEnabled; + //! Returns the definition of the front Z-clipping plane. + virtual Standard_Real ZClippingFrontPlane() const = 0; + //! Sets the definition of the front Z-clipping plane. + virtual void SetZClippingFrontPlane (const Standard_Real theValue) = 0; + + //! Returns the activity of depth cueing. + virtual Standard_Boolean DepthCueingIsOn() const = 0; + + //! Sets the activity of depth cueing. + virtual void SetDepthCueingOn (const Standard_Boolean theIsOn) = 0; + + //! Returns the back depth cueing plane. + virtual Standard_Real DepthCueingBackPlane() const = 0; + + //! Set the back depth cueing plane. + virtual void SetDepthCueingBackPlane (const Standard_Real theValue) = 0; + + //! Returns the front depth cueing plane. + virtual Standard_Real DepthCueingFrontPlane() const = 0; + + //! Set the front depth cueing plane. + virtual void SetDepthCueingFrontPlane (const Standard_Real theValue) = 0; + + //! Returns true if GL lighting is enabled. + virtual Standard_Boolean IsGLLightEnabled() const = 0; + + //! Sets GL lighting enabled or disable state. + virtual void SetGLLightEnabled (const Standard_Boolean theIsEnabled) = 0; + + //! Returns list of lights of the view. + virtual const Graphic3d_ListOfCLight& Lights() const = 0; + + //! Sets list of lights for the view. + virtual void SetLights (const Graphic3d_ListOfCLight& theLights) = 0; + + //! Returns list of clip planes set for the view. + virtual const Graphic3d_SequenceOfHClipPlane& ClipPlanes() const = 0; + + //! Sets list of clip planes for the view. + virtual void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) = 0; + +private: + + //! Adds the structure to display lists of the view. + virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure, + const Standard_Integer thePriority) = 0; + + //! Erases the structure from display lists of the view. + virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) = 0; + + //! Change Z layer of a structure already presented in view. + virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure, + const Graphic3d_ZLayerId theNewLayerId) = 0; + + //! Changes the priority of a structure within its Z layer in the specified view. + virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure, + const Standard_Integer theNewPriority) = 0; + +protected: + + struct CachedMinMax + { + CachedMinMax() { Invalidate(); } + + Bnd_Box& BoundingBox (const Standard_Boolean theToIgnoreInfiniteFlag) + { + return !theToIgnoreInfiniteFlag ? myBoundingBox[0] : myBoundingBox[1]; + } + Standard_Boolean& IsOutdated (const Standard_Boolean theToIgnoreInfiniteFlag) + { + return !theToIgnoreInfiniteFlag ? myIsOutdated[0] : myIsOutdated[1]; + } + void Invalidate() + { + myIsOutdated[0] = Standard_True; + myIsOutdated[1] = Standard_True; + } + + Standard_Boolean myIsOutdated [2]; + Bnd_Box myBoundingBox[2]; + }; + +protected: + + Standard_Integer myId; + Graphic3d_RenderingParams myRenderParams; + Handle(Graphic3d_StructureManager) myStructureManager; + Graphic3d_SequenceOfStructure myStructsToCompute; + Graphic3d_SequenceOfStructure myStructsComputed; + Graphic3d_MapOfStructure myStructsDisplayed; + Handle(Graphic3d_NMapOfTransient) myHiddenObjects; + Standard_Boolean myIsInComputedMode; + Standard_Boolean myIsActive; + Standard_Boolean myIsRemoved; + Graphic3d_TypeOfVisualization myVisualization; + mutable CachedMinMax myMinMax; + +private: + + DEFINE_STANDARD_RTTI (Graphic3d_CView, Graphic3d_DataStructureManager) }; -#endif // Graphic3d_CView_HeaderFile +#endif // _Graphic3d_CView_HeaderFile diff --git a/src/Graphic3d/Graphic3d_Camera.cxx b/src/Graphic3d/Graphic3d_Camera.cxx index f6c043c534..11e120bfc7 100644 --- a/src/Graphic3d/Graphic3d_Camera.cxx +++ b/src/Graphic3d/Graphic3d_Camera.cxx @@ -235,6 +235,11 @@ gp_Dir Graphic3d_Camera::Direction() const // ======================================================================= void Graphic3d_Camera::SetScale (const Standard_Real theScale) { + if (Scale() == theScale) + { + return; + } + myScale = theScale; switch (myProjType) @@ -281,7 +286,7 @@ Standard_Real Graphic3d_Camera::Scale() const // ======================================================================= void Graphic3d_Camera::SetProjectionType (const Projection theProjectionType) { - Projection anOldType = myProjType; + Projection anOldType = ProjectionType(); if (anOldType == theProjectionType) { @@ -311,7 +316,13 @@ void Graphic3d_Camera::SetProjectionType (const Projection theProjectionType) // ======================================================================= void Graphic3d_Camera::SetFOVy (const Standard_Real theFOVy) { + if (FOVy() == theFOVy) + { + return; + } + myFOVy = theFOVy; + InvalidateProjection(); } @@ -329,6 +340,12 @@ void Graphic3d_Camera::SetZRange (const Standard_Real theZNear, Standard_ASSERT_RAISE (theZFar > 0.0, "Only positive Z-Far is allowed for perspective camera"); } + if (ZNear() == theZNear + && ZFar () == theZFar) + { + return; + } + myZNear = theZNear; myZFar = theZFar; @@ -341,7 +358,13 @@ void Graphic3d_Camera::SetZRange (const Standard_Real theZNear, // ======================================================================= void Graphic3d_Camera::SetAspect (const Standard_Real theAspect) { + if (Aspect() == theAspect) + { + return; + } + myAspect = theAspect; + InvalidateProjection(); } @@ -351,8 +374,15 @@ void Graphic3d_Camera::SetAspect (const Standard_Real theAspect) // ======================================================================= void Graphic3d_Camera::SetZFocus(const FocusType theType, const Standard_Real theZFocus) { + if (ZFocusType() == theType + && ZFocus () == theZFocus) + { + return; + } + myZFocusType = theType; - myZFocus = theZFocus; + myZFocus = theZFocus; + InvalidateProjection(); } @@ -362,8 +392,15 @@ void Graphic3d_Camera::SetZFocus(const FocusType theType, const Standard_Real th // ======================================================================= void Graphic3d_Camera::SetIOD (const IODType theType, const Standard_Real theIOD) { + if (IODType() == theType + && IOD () == theIOD) + { + return; + } + myIODType = theType; - myIOD = theIOD; + myIOD = theIOD; + InvalidateProjection(); } diff --git a/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx index 13eb392af4..7d9b759ac7 100644 --- a/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx +++ b/src/Graphic3d/Graphic3d_GraduatedTrihedron.hxx @@ -24,7 +24,7 @@ #include #include -class Visual3d_View; +class Graphic3d_CView; //! Class that stores style for one graduated trihedron axis such as colors, lengths and customization flags. //! It is used in Graphic3d_GraduatedTrihedron. @@ -111,7 +111,7 @@ class Graphic3d_GraduatedTrihedron { public: - typedef void (*MinMaxValuesCallback) (Visual3d_View*); + typedef void (*MinMaxValuesCallback) (Graphic3d_CView*); public: @@ -138,7 +138,7 @@ public: myAxes (0) = Graphic3d_AxisAspect ("X", Quantity_NOC_RED, Quantity_NOC_RED); myAxes (1) = Graphic3d_AxisAspect ("Y", Quantity_NOC_GREEN, Quantity_NOC_GREEN); myAxes (2) = Graphic3d_AxisAspect ("Z", Quantity_NOC_BLUE1, Quantity_NOC_BLUE1); - PtrVisual3dView = NULL; + PtrView = NULL; } public: @@ -196,7 +196,7 @@ public: public: MinMaxValuesCallback CubicAxesCallback; //!< Callback function to define boundary box of displayed objects - Visual3d_View* PtrVisual3dView; + Graphic3d_CView* PtrView; protected: diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.cxx b/src/Graphic3d/Graphic3d_GraphicDriver.cxx index 8c54362f8c..ac6bbd33db 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.cxx +++ b/src/Graphic3d/Graphic3d_GraphicDriver.cxx @@ -14,7 +14,6 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include #include #include @@ -79,10 +78,9 @@ void Graphic3d_GraphicDriver::PrintCStructure (const Graphic3d_CStructure& ACStr void Graphic3d_GraphicDriver::PrintCView (const Graphic3d_CView& ACView, const Standard_Integer AField) const { if (AField) { - cout << "\tws id " << ACView.WsId << ", " - << "view id " << ACView.ViewId << "\n"; - cout << "\tXwindow id " << ACView.DefWindow.XWindow << ", " - << "activity " << ACView.Active << "\n"; + cout << "view id " << ACView.Identification() << "\n"; + cout << "\tXwindow id " << (ACView.Window().IsNull() ? 0 : ACView.Window()->NativeHandle()) << ", " + << "activity " << ACView.IsActive() << "\n"; cout << flush; } diff --git a/src/Graphic3d/Graphic3d_GraphicDriver.hxx b/src/Graphic3d/Graphic3d_GraphicDriver.hxx index 12c0333d7c..3bc5fa9e61 100644 --- a/src/Graphic3d/Graphic3d_GraphicDriver.hxx +++ b/src/Graphic3d/Graphic3d_GraphicDriver.hxx @@ -49,14 +49,17 @@ #include #include #include +#include + +class Graphic3d_CView; +class Graphic3d_GraphicDriver; class Graphic3d_TransformError; class Graphic3d_Structure; class Graphic3d_StructureManager; +class Graphic3d_ViewManager; class Quantity_Color; class TCollection_AsciiString; - -class Graphic3d_GraphicDriver; DEFINE_STANDARD_HANDLE(Graphic3d_GraphicDriver, MMgt_TShared) //! This class allows the definition of a graphic driver @@ -68,218 +71,63 @@ public: //! call_togl_inquirelight - Standard_EXPORT virtual Standard_Integer InquireLightLimit() = 0; + virtual Standard_Integer InquireLightLimit() = 0; //! call_togl_inquireplane - Standard_EXPORT virtual Standard_Integer InquirePlaneLimit() = 0; + virtual Standard_Integer InquirePlaneLimit() = 0; //! call_togl_inquireview - Standard_EXPORT virtual Standard_Integer InquireViewLimit() = 0; - - //! call_togl_displaystructure - Standard_EXPORT virtual void DisplayStructure (const Graphic3d_CView& theCView, const Handle(Graphic3d_Structure)& theStructure, const Standard_Integer thePriority) = 0; - - //! call_togl_erasestructure - Standard_EXPORT virtual void EraseStructure (const Graphic3d_CView& theCView, const Handle(Graphic3d_Structure)& theStructure) = 0; - - //! call_togl_removestructure - Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) = 0; + virtual Standard_Integer InquireViewLimit() = 0; //! Creates new empty graphic structure - Standard_EXPORT virtual Handle(Graphic3d_CStructure) Structure (const Handle(Graphic3d_StructureManager)& theManager) = 0; - - //! call_togl_activateview - Standard_EXPORT virtual void ActivateView (const Graphic3d_CView& ACView) = 0; - - //! call_togl_antialiasing - Standard_EXPORT virtual void AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) = 0; - - //! call_togl_background - Standard_EXPORT virtual void Background (const Graphic3d_CView& ACView) = 0; - - //! call_togl_gradient_background - Standard_EXPORT virtual void GradientBackground (const Graphic3d_CView& ACView, const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod FillStyle) = 0; - - Standard_EXPORT virtual void BackgroundImage (const Standard_CString FileName, const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle) = 0; - - Standard_EXPORT virtual void SetBgImageStyle (const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle) = 0; - - Standard_EXPORT virtual void SetBgGradientStyle (const Graphic3d_CView& ACView, const Aspect_GradientFillMethod FillStyle) = 0; - - //! call_togl_cliplimit - Standard_EXPORT virtual void ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) = 0; + virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) = 0; - //! call_togl_deactivateview - Standard_EXPORT virtual void DeactivateView (const Graphic3d_CView& ACView) = 0; + //! Removes structure from graphic driver and releases its resources. + virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) = 0; - //! call_togl_cliplimit - Standard_EXPORT virtual void DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) = 0; + //! Creates new view for this graphic driver. + virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) = 0; - //! call_togl_ratio_window - Standard_EXPORT virtual void RatioWindow (const Graphic3d_CView& ACView) = 0; - - //! Redraw content of the view - Standard_EXPORT virtual void Redraw (const Graphic3d_CView& theCView, const Standard_Integer theX = 0, const Standard_Integer theY = 0, const Standard_Integer theWidth = 0, const Standard_Integer theHeight = 0) = 0; - - //! Redraw layer of immediate presentations - Standard_EXPORT virtual void RedrawImmediate (const Graphic3d_CView& theCView) = 0; - - //! Invalidates content of the view but does not redraw it - Standard_EXPORT virtual void Invalidate (const Graphic3d_CView& theCView) = 0; - - //! Returns true if cached view content has been invalidated. - Standard_EXPORT virtual Standard_Boolean IsInvalidated (const Graphic3d_CView& theCView) const = 0; + //! Removes view from graphic driver and releases its resources. + virtual void RemoveView (const Handle(Graphic3d_CView)& theView) = 0; - //! call_togl_removeview - Standard_EXPORT virtual void RemoveView (const Graphic3d_CView& ACView) = 0; - - //! call_togl_setlight - Standard_EXPORT virtual void SetLight (const Graphic3d_CView& ACView) = 0; - - //! Pass clip planes to the associated graphic driver view. - Standard_EXPORT virtual void SetClipPlanes (const Graphic3d_CView& theCView) = 0; - - //! Inform graphic driver if camera assigned to view changes. - Standard_EXPORT virtual void SetCamera (const Graphic3d_CView& theCView) = 0; - - //! call_togl_setvisualisation - Standard_EXPORT virtual void SetVisualisation (const Graphic3d_CView& ACView) = 0; - - //! call_togl_view - Standard_EXPORT virtual Standard_Boolean View (Graphic3d_CView& ACView) = 0; - - Standard_EXPORT virtual void Environment (const Graphic3d_CView& ACView) = 0; - //! enables/disables usage of OpenGL vertex buffer arrays while drawing primitiev arrays - Standard_EXPORT virtual void EnableVBO (const Standard_Boolean status) = 0; + virtual void EnableVBO (const Standard_Boolean status) = 0; //! Returns information about GPU memory usage. - Standard_EXPORT virtual Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes, TCollection_AsciiString& theInfo) const = 0; - - //! call_togl_ztriedron_setup - Standard_EXPORT virtual void ZBufferTriedronSetup (const Graphic3d_CView& theCView, const Quantity_NameOfColor XColor = Quantity_NOC_RED, const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, const Standard_Real SizeRatio = 0.8, const Standard_Real AxisDiametr = 0.05, const Standard_Integer NbFacettes = 12) = 0; - - //! call_togl_triedron_display - Standard_EXPORT virtual void TriedronDisplay (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const Standard_Boolean AsWireframe = Standard_True) = 0; - - //! call_togl_triedron_erase - Standard_EXPORT virtual void TriedronErase (const Graphic3d_CView& ACView) = 0; + virtual Standard_Boolean MemoryInfo (Standard_Size& theFreeBytes, TCollection_AsciiString& theInfo) const = 0; - //! call_togl_triedron_echo - Standard_EXPORT virtual void TriedronEcho (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE) = 0; - - //! call_togl_graduatedtrihedron_display - Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_CView& theView, const Graphic3d_GraduatedTrihedron& theCubic) = 0; - - //! call_togl_graduatedtrihedron_erase - Standard_EXPORT virtual void GraduatedTrihedronErase (const Graphic3d_CView& theView) = 0; - - //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron - //! stored in graphic view object. - //! @param theView [in] current graphic view - //! @param theMin [in] the minimum point of scene. - //! @param theMax [in] the maximum point of scene. - Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) = 0; - - //! @param theDrawToFrontBuffer Advanced option to modify rendering mode: - //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image. - //! Fast, so preferred for interactive work (used by default). - //! However these extra drawings will be missed in image dump since it is performed from back buffer. - //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen - //! in run-time (in case of slow hardware) and/or tearing may appear. - //! So this is strongly recommended to draw only simple (fast) structures. - //! 2. FALSE. Drawing immediate mode structures to the back buffer. - //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync is turned on. - //! But it works in any case and is especially useful for view dump because the dump image is read from the back buffer. - //! @return previous mode. - Standard_EXPORT virtual Standard_Boolean SetImmediateModeDrawToFront (const Graphic3d_CView& theCView, const Standard_Boolean theDrawToFrontBuffer) = 0; - - Standard_EXPORT virtual Standard_ShortReal DefaultTextHeight() const = 0; + virtual Standard_ShortReal DefaultTextHeight() const = 0; //! call_togl_textsize2d - Standard_EXPORT virtual void TextSize (const Standard_CString AText, const Standard_ShortReal AHeight, Standard_ShortReal& AWidth, Standard_ShortReal& AnAscent, Standard_ShortReal& ADescent) const = 0; - - //! call_togl_backfacing - Standard_EXPORT virtual void SetBackFacingModel (const Graphic3d_CView& aView) = 0; - - //! Reads depths of shown pixels of the given - //! rectangle (glReadPixels with GL_DEPTH_COMPONENT) - Standard_EXPORT virtual void ReadDepths (const Graphic3d_CView& view, const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height, const Standard_Address buffer) const = 0; - - //! Generate offscreen FBO in the graphic library. - //! If not supported on hardware returns NULL. - Standard_EXPORT virtual Graphic3d_PtrFrameBuffer FBOCreate (const Graphic3d_CView& view, const Standard_Integer width, const Standard_Integer height) = 0; - - //! Remove offscreen FBO from the graphic library - Standard_EXPORT virtual void FBORelease (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr) = 0; - - //! Read offscreen FBO configuration. - Standard_EXPORT virtual void FBOGetDimensions (const Graphic3d_CView& view, const Graphic3d_PtrFrameBuffer fboPtr, Standard_Integer& width, Standard_Integer& height, Standard_Integer& widthMax, Standard_Integer& heightMax) = 0; - - //! Change offscreen FBO viewport. - Standard_EXPORT virtual void FBOChangeViewport (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr, const Standard_Integer width, const Standard_Integer height) = 0; - - //! Dump active rendering buffer into specified memory buffer. - Standard_EXPORT virtual Standard_Boolean BufferDump (const Graphic3d_CView& theCView, Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) = 0; - - //! call_togl_gllight - Standard_EXPORT virtual void SetGLLightEnabled (const Graphic3d_CView& view, const Standard_Boolean isEnabled) const = 0; - - //! call_togl_isgllight - Standard_EXPORT virtual Standard_Boolean IsGLLightEnabled (const Graphic3d_CView& view) const = 0; - - //! print the contents of all layers of the view to the printer. - //! : Pass the PrinterDeviceContext (HDC), - //! : When set to FALSE then print the view without background color - //! (background is white) - //! else set to TRUE for printing with current background color. - //! : If != NULL, then the view will be printed to a file. - //! : Select print algorithm: stretch, tile. - //! : Scaling coefficient, used internally to scale the - //! printings accordingly to the scale factor selected in the printer - //! properties dialog. - //! Returns Standard_True if the data is passed to the printer, otherwise - //! Standard_False if the print operation failed due to the printer errors, - //! or insufficient system memory available. - Standard_EXPORT virtual Standard_Boolean Print (const Graphic3d_CView& ACView, const Aspect_Handle hPrnDC, const Standard_Boolean showBackground, const Standard_CString filename, const Aspect_PrintAlgo printAlgorithm = Aspect_PA_STRETCH, const Standard_Real theScaleFactor = 1.0) const = 0; - + virtual void TextSize (const Standard_CString AText, const Standard_ShortReal AHeight, Standard_ShortReal& AWidth, Standard_ShortReal& AnAscent, Standard_ShortReal& ADescent) const = 0; - //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). - //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits on printing to laser printer). - //! Notice however that results may differ a lot and do not contain some elements. - Standard_EXPORT virtual Standard_Boolean Export (const Standard_CString theFileName, const Graphic3d_ExportFormat theFormat, const Graphic3d_SortType theSortType, const Standard_Integer theWidth, const Standard_Integer theHeight, const Graphic3d_CView& theView, const Standard_Real thePrecision = 0.005, const Standard_Address theProgressBarFunc = NULL, const Standard_Address theProgressObject = NULL) = 0; - - - //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated. - Standard_EXPORT virtual void InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId) = 0; - //! Add a new top-level z layer with ID for //! the view. Z layers allow drawing structures in higher layers //! in foreground of structures in lower layers. To add a structure //! to desired layer on display it is necessary to set the layer //! ID for the structure. - Standard_EXPORT virtual void AddZLayer (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId) = 0; - - //! Remove Z layer from the specified view. All structures - //! displayed at the moment in layer will be displayed in default layer - //! ( the bottom-level z layer ). To unset layer ID from associated - //! structures use method UnsetZLayer (...). - Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId) = 0; - - //! Unset Z layer ID for all structures. The structure - //! indexes will be set to default layer ( the bottom-level z layer - //! with ID = 0 ). - Standard_EXPORT virtual void UnsetZLayer (const Graphic3d_ZLayerId theLayerId) = 0; + virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0; - //! Change Z layer of a structure already presented in view. - Standard_EXPORT virtual void ChangeZLayer (const Graphic3d_CStructure& theCStructure, const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theNewLayerId) = 0; - - //! Sets the settings for a single Z layer of specified view. - Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_CView& theCView, const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0; + //! Removes Z layer. All structures displayed at the moment in layer will be displayed in + //! default layer (the bottom-level z layer). By default, there are always default + //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0 + //! (reserved for default layers that can not be removed). + virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0; + + //! Returns list of Z layers defined for the graphical driver. + virtual void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const = 0; + + //! Sets the settings for a single Z layer. + virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0; + + //! Returns the settings of a single Z layer. + virtual Graphic3d_ZLayerSettings ZLayerSettings (const Graphic3d_ZLayerId theLayerId) = 0; + + //! Returns view associated with the window if it is exists and is activated. + //! Returns Standard_True if the view associated to the window exists. + virtual Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) = 0; - //! Changes the priority of a structure within its Z layer in the specified view. - Standard_EXPORT virtual void ChangePriority (const Graphic3d_CStructure& theCStructure, const Graphic3d_CView& theCView, const Standard_Integer theNewPriority) = 0; - Standard_EXPORT void PrintBoolean (const Standard_CString AComment, const Standard_Boolean AValue) const; Standard_EXPORT void PrintCLight (const Graphic3d_CLight& ACLight, const Standard_Integer AField) const; @@ -311,15 +159,12 @@ public: Standard_EXPORT void ResetDeviceLostFlag(); - - - DEFINE_STANDARD_RTTI(Graphic3d_GraphicDriver,MMgt_TShared) protected: - //! Initialises the Driver + //! Initializes the Driver Standard_EXPORT Graphic3d_GraphicDriver(const Handle(Aspect_DisplayConnection)& theDisp); Standard_Integer MyTraceLevel; diff --git a/src/Graphic3d/Graphic3d_Group.cxx b/src/Graphic3d/Graphic3d_Group.cxx index b44c6d7794..4000c7c717 100644 --- a/src/Graphic3d/Graphic3d_Group.cxx +++ b/src/Graphic3d/Graphic3d_Group.cxx @@ -259,10 +259,7 @@ void Graphic3d_Group::Update() const return; } - if (myStructure->StructureManager()->UpdateMode() == Aspect_TOU_ASAP) - { - myStructure->StructureManager()->Update(); - } + myStructure->StructureManager()->Update (myStructure->StructureManager()->UpdateMode()); } // ======================================================================= diff --git a/src/Graphic3d/Graphic3d_MaterialAspect.hxx b/src/Graphic3d/Graphic3d_MaterialAspect.hxx index 55812d2aea..0d2505252e 100644 --- a/src/Graphic3d/Graphic3d_MaterialAspect.hxx +++ b/src/Graphic3d/Graphic3d_MaterialAspect.hxx @@ -95,14 +95,6 @@ public: //! one of reflection modes (ambient, diffuse, specular or emissive) //! enabled. See also SetReflectionModeOn() and SetReflectionModeOff() methods. //! - //! NOTE: In order for transparency specified through this method to - //! take effect, it is necessary to enable transparency - //! in the viewer. This can be done either directly - - //! see Visual3d_ViewManager::SetTransparency(Standard_Boolean), - //! or indirectly - by calling AIS_InteractiveObject::SetTransparency() - //! before an object is added to an interactive context, or by - //! calling AIS_InteractiveContext::SetTransparency() for a given - //! interactive object already displayed. //! Category: Methods to modify the class definition //! Warning: Raises MaterialDefinitionError if is a //! negative value or greater than 1.0. diff --git a/src/Graphic3d/Graphic3d_Structure.cxx b/src/Graphic3d/Graphic3d_Structure.cxx index a6403b4109..655499a29b 100644 --- a/src/Graphic3d/Graphic3d_Structure.cxx +++ b/src/Graphic3d/Graphic3d_Structure.cxx @@ -53,7 +53,7 @@ Graphic3d_Structure::Graphic3d_Structure (const Handle(Graphic3d_StructureManage myOwner (NULL), myVisual (Graphic3d_TOS_ALL) { - myCStructure = theManager->GraphicDriver()->Structure (theManager); + myCStructure = theManager->GraphicDriver()->CreateStructure (theManager); // default aspects Handle(Graphic3d_AspectLine3d) aAspectLine3d = new Graphic3d_AspectLine3d(); @@ -2033,10 +2033,7 @@ void Graphic3d_Structure::Update() const return; } - if (myStructureManager->UpdateMode() == Aspect_TOU_ASAP) - { - myStructureManager->Update(); - } + myStructureManager->Update (myStructureManager->UpdateMode()); } //============================================================================= diff --git a/src/Graphic3d/Graphic3d_StructureManager.cxx b/src/Graphic3d/Graphic3d_StructureManager.cxx index f7fafe78ed..7f506e6e7c 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.cxx +++ b/src/Graphic3d/Graphic3d_StructureManager.cxx @@ -42,6 +42,7 @@ static Standard_Integer StructureManager_CurrentId = 0; #include Graphic3d_StructureManager::Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver) +: myViewGenId (0, 31) { Standard_Real Coef; @@ -81,17 +82,17 @@ Standard_Integer Limit = Graphic3d_StructureManager::Limit (); Aspect_GenId theGenId( Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId)), Standard_Integer (Structure_IDMIN+Coef*(StructureManager_CurrentId+1)-1)); - MyStructGenId = theGenId; + myStructGenId = theGenId; - MyId = StructureManager_CurrentId; + myId = StructureManager_CurrentId; - MyAspectLine3d = new Graphic3d_AspectLine3d (); - MyAspectText3d = new Graphic3d_AspectText3d (); - MyAspectMarker3d = new Graphic3d_AspectMarker3d (); - MyAspectFillArea3d = new Graphic3d_AspectFillArea3d (); + myAspectLine3d = new Graphic3d_AspectLine3d (); + myAspectText3d = new Graphic3d_AspectText3d (); + myAspectMarker3d = new Graphic3d_AspectMarker3d (); + myAspectFillArea3d = new Graphic3d_AspectFillArea3d (); - MyUpdateMode = Aspect_TOU_WAIT; - MyGraphicDriver = theDriver; + myUpdateMode = Aspect_TOU_WAIT; + myGraphicDriver = theDriver; } @@ -99,103 +100,150 @@ Standard_Integer Limit = Graphic3d_StructureManager::Limit (); void Graphic3d_StructureManager::Destroy () { - MyDisplayedStructure.Clear (); - MyHighlightedStructure.Clear (); - StructureManager_ArrayId[MyId] = 0; + myDisplayedStructure.Clear (); + myHighlightedStructure.Clear (); + myDefinedViews.Clear(); + StructureManager_ArrayId[myId] = 0; } -//-Methods, in order - -void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate AType) { +// ======================================================================== +// function : SetUpdateMode +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::SetUpdateMode (const Aspect_TypeOfUpdate theType) +{ + myUpdateMode = theType; +} - MyUpdateMode = AType; +// ======================================================================== +// function : UpdateMode +// purpose : +// ======================================================================== +Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const +{ + return myUpdateMode; +} +// ======================================================================== +// function : Update +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Update (theMode); + } } -Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode () const { +// ======================================================================== +// function : Remove +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Remove() +{ + // clear all structures whilst views are alive for correct GPU memory management + myDisplayedStructure.Clear(); + myHighlightedStructure.Clear(); - return (MyUpdateMode); + // clear list of managed views + myDefinedViews.Clear(); +} +// ======================================================================== +// function : Erase +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Erase() +{ + for (Graphic3d_MapIteratorOfMapOfStructure anIt (myDisplayedStructure); anIt.More(); anIt.Next()) + { + anIt.Key()->Erase(); + } } + + + + void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX) { - MyAspectLine3d = CTX; + myAspectLine3d = CTX; } void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX) { - MyAspectFillArea3d = CTX; + myAspectFillArea3d = CTX; } void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX) { - MyAspectText3d = CTX; + myAspectText3d = CTX; } void Graphic3d_StructureManager::SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX) { - MyAspectMarker3d = CTX; + myAspectMarker3d = CTX; } void Graphic3d_StructureManager::PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const { - CTXL = MyAspectLine3d; - CTXT = MyAspectText3d; - CTXM = MyAspectMarker3d; - CTXF = MyAspectFillArea3d; + CTXL = myAspectLine3d; + CTXT = myAspectText3d; + CTXM = myAspectMarker3d; + CTXF = myAspectFillArea3d; } Handle(Graphic3d_AspectLine3d) Graphic3d_StructureManager::Line3dAspect () const { - return (MyAspectLine3d); + return (myAspectLine3d); } Handle(Graphic3d_AspectText3d) Graphic3d_StructureManager::Text3dAspect () const { - return (MyAspectText3d); + return (myAspectText3d); } Handle(Graphic3d_AspectMarker3d) Graphic3d_StructureManager::Marker3dAspect () const { - return (MyAspectMarker3d); + return (myAspectMarker3d); } Handle(Graphic3d_AspectFillArea3d) Graphic3d_StructureManager::FillArea3dAspect () const { - return (MyAspectFillArea3d); + return (myAspectFillArea3d); } -void Graphic3d_StructureManager::Remove (const Standard_Integer AnId) { +void Graphic3d_StructureManager::Remove (const Standard_Integer theId) { - MyStructGenId.Free (AnId); + myStructGenId.Free (theId); } void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure& SG) const { - SG.Assign(MyDisplayedStructure); + SG.Assign(myDisplayedStructure); - //JMBStandard_Integer Length = MyDisplayedStructure.Length (); + //JMBStandard_Integer Length = myDisplayedStructure.Length (); //JMBfor (Standard_Integer i=1; i<=Length; i++) - //JMB SG.Add (MyDisplayedStructure.Value (i)); + //JMB SG.Add (myDisplayedStructure.Value (i)); } Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const { -Standard_Integer Length = MyDisplayedStructure.Extent (); +Standard_Integer Length = myDisplayedStructure.Extent (); return (Length); @@ -203,19 +251,19 @@ Standard_Integer Length = MyDisplayedStructure.Extent (); //Handle(Graphic3d_Structure) Graphic3d_StructureManager::DisplayedStructure (const Standard_Integer AnIndex) const { -//return (MyDisplayedStructure.Value (AnIndex)); +//return (myDisplayedStructure.Value (AnIndex)); //} void Graphic3d_StructureManager::HighlightedStructures (Graphic3d_MapOfStructure& SG) const { - SG.Assign(MyHighlightedStructure); + SG.Assign(myHighlightedStructure); } Standard_Integer Graphic3d_StructureManager::NewIdentification () { -Standard_Integer Id = MyStructGenId.Next (); +Standard_Integer Id = myStructGenId.Next (); return Id; @@ -228,7 +276,7 @@ Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const St Handle(Graphic3d_Structure) StructNull; - Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); + Graphic3d_MapIteratorOfMapOfStructure it( myDisplayedStructure); Handle(Graphic3d_Structure) SGfound; @@ -250,7 +298,7 @@ Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const St Standard_Integer Graphic3d_StructureManager::Identification () const { - return (MyId); + return (myId); } @@ -268,7 +316,7 @@ Standard_Integer Graphic3d_StructureManager::CurrentId () { const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const { - return (MyGraphicDriver); + return (myGraphicDriver); } @@ -277,7 +325,7 @@ void Graphic3d_StructureManager::RecomputeStructures() // Go through all unique structures including child (connected) ones and ensure that they are computed. Graphic3d_MapOfStructure aStructNetwork; - for (Graphic3d_MapIteratorOfMapOfStructure anIter(MyDisplayedStructure); anIter.More(); anIter.Next()) + for (Graphic3d_MapIteratorOfMapOfStructure anIter(myDisplayedStructure); anIter.More(); anIter.Next()) { Handle(Graphic3d_Structure) aStructure = anIter.Key(); anIter.Key()->Network (anIter.Key(), Graphic3d_TOC_DESCENDANT, aStructNetwork); @@ -320,3 +368,244 @@ Handle(Graphic3d_ViewAffinity) Graphic3d_StructureManager::ObjectAffinity (const myRegisteredObjects.Find (theObject.operator->(), aResult); return aResult; } + +// ======================================================================== +// function : Identification +// purpose : +// ======================================================================== +Standard_Integer Graphic3d_StructureManager::Identification (Graphic3d_CView* theView) +{ + if (myDefinedViews.Contains (theView)) + { + return theView->Identification(); + } + + myDefinedViews.Add (theView); + return myViewGenId.Next(); +} + +// ======================================================================== +// function : UnIdentification +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::UnIdentification (Graphic3d_CView* theView) +{ + if (myDefinedViews.Contains (theView)) + { + myDefinedViews.Swap (myDefinedViews.FindIndex (theView), myDefinedViews.Size()); + myDefinedViews.RemoveLast(); + myViewGenId.Free (theView->Identification()); + } +} + +// ======================================================================== +// function : DefinedViews +// purpose : +// ======================================================================== +const Graphic3d_IndexedMapOfView& Graphic3d_StructureManager::DefinedViews() const +{ + return myDefinedViews; +} + +// ======================================================================== +// function : MaxNumOfViews +// purpose : +// ======================================================================== +Standard_Integer Graphic3d_StructureManager::MaxNumOfViews() const +{ + return myViewGenId.Upper() - myViewGenId.Lower() + 1; +} + +// ======================================================================== +// function : ReCompute +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure) +{ + if (!myDisplayedStructure.Contains (theStructure)) + { + return; + } + + // Recompute structure for all defined views + for (Standard_Integer aViewIt = 1; aViewIt <= myDefinedViews.Extent(); ++aViewIt) + { + ReCompute (theStructure, myDefinedViews (aViewIt)); + } +} + +// ======================================================================== +// function : ReCompute +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::ReCompute (const Handle(Graphic3d_Structure)& theStructure, + const Handle(Graphic3d_DataStructureManager)& theProjector) +{ + Handle(Graphic3d_CView) aView = Handle(Graphic3d_CView)::DownCast (theProjector); + + if (aView.IsNull() + || !myDefinedViews.Contains (aView.operator->()) + || !myDisplayedStructure.Contains (theStructure)) + { + return; + } + + aView->ReCompute (theStructure); +} + +// ======================================================================== +// function : Clear +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Clear (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Boolean theWithDestruction) +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Clear (theStructure, theWithDestruction); + } +} + +// ======================================================================== +// function : Connect +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Connect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter) +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Connect (theMother, theDaughter); + } +} + +// ======================================================================== +// function : Disconnect +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Disconnect (const Handle(Graphic3d_Structure)& theMother, + const Handle(Graphic3d_Structure)& theDaughter) +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Disconnect (theMother, theDaughter); + } +} + +// ======================================================================== +// function : Display +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Display (const Handle(Graphic3d_Structure)& theStructure) +{ + myDisplayedStructure.Add (theStructure); + + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Display (theStructure); + } +} + +// ======================================================================== +// function : Erase +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Erase (const Handle(Graphic3d_Structure)& theStructure) +{ + myDisplayedStructure .Remove(theStructure); + myHighlightedStructure.Remove (theStructure); + + // Erase structure in all defined views + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Erase (theStructure); + } +} + +// ======================================================================== +// function : Erase +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::Highlight (const Handle(Graphic3d_Structure)& theStructure, + const Aspect_TypeOfHighlightMethod theMethod) +{ + myHighlightedStructure.Add (theStructure); + + // Highlight in all defined views + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->Highlight (theStructure, theMethod); + } +} + +// ======================================================================== +// function : UnHighlight +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::UnHighlight (const Handle(Graphic3d_Structure)& theStructure) +{ + myHighlightedStructure.Remove (theStructure); + + // UnHighlight in all defined views + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->UnHighlight (theStructure); + } +} + +// ======================================================================== +// function : UnHighlight +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::UnHighlight() +{ + for (Graphic3d_MapIteratorOfMapOfStructure anIt (myHighlightedStructure); anIt.More(); anIt.Next()) + { + anIt.Key()->UnHighlight(); + } +} + +// ======================================================================== +// function : SetTransform +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::SetTransform (const Handle(Graphic3d_Structure)& theStructure, + const TColStd_Array2OfReal& theTrsf) +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->SetTransform (theStructure, theTrsf); + } +} + +// ======================================================================== +// function : ChangeDisplayPriority +// purpose : +// ======================================================================== +void Graphic3d_StructureManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure, + const Standard_Integer theOldPriority, + const Standard_Integer theNewPriority) +{ + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->ChangePriority (theStructure, theOldPriority, theNewPriority); + } +} + +//======================================================================= +//function : ChangeZLayer +//purpose : +//======================================================================= +void Graphic3d_StructureManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, + const Graphic3d_ZLayerId theLayerId) +{ + if (!myDisplayedStructure.Contains (theStructure)) + { + return; + } + + for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->ChangeZLayer (theStructure, theLayerId); + } +} diff --git a/src/Graphic3d/Graphic3d_StructureManager.hxx b/src/Graphic3d/Graphic3d_StructureManager.hxx index 1f2149dd00..fadac9e993 100644 --- a/src/Graphic3d/Graphic3d_StructureManager.hxx +++ b/src/Graphic3d/Graphic3d_StructureManager.hxx @@ -17,22 +17,26 @@ #ifndef _Graphic3d_StructureManager_HeaderFile #define _Graphic3d_StructureManager_HeaderFile -#include -#include - -#include +#include +#include #include -#include +#include #include -#include -#include +#include +#include #include #include +#include +#include +#include #include -#include -#include +#include +#include #include -#include +#include + +typedef NCollection_IndexedMap Graphic3d_IndexedMapOfView; + class Graphic3d_AspectLine3d; class Graphic3d_AspectText3d; class Graphic3d_AspectMarker3d; @@ -43,7 +47,6 @@ class Graphic3d_Structure; class Graphic3d_DataStructureManager; class Standard_Transient; - class Graphic3d_StructureManager; DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, MMgt_TShared) @@ -55,226 +58,209 @@ DEFINE_STANDARD_HANDLE(Graphic3d_StructureManager, MMgt_TShared) //! Destroy, Highlight, Visible class Graphic3d_StructureManager : public MMgt_TShared { - public: - + //! Initializes the ViewManager. + //! Currently creating of more than 100 viewer instances + //! is not supported and leads to InitializationError and + //! initialization failure. + //! This limitation might be addressed in some future OCCT releases. + //! Warning: Raises InitialisationError if the initialization + //! of the ViewManager failed. + Standard_EXPORT Graphic3d_StructureManager (const Handle(Graphic3d_GraphicDriver)& theDriver); + //! Deletes the manager . Standard_EXPORT virtual void Destroy(); ~Graphic3d_StructureManager() { Destroy(); } - + //! Modifies the default attributes for lines //! in the visualiser. Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectLine3d)& CTX); - + //! Modifies the default attributes for faces //! in the visualiser. Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectFillArea3d)& CTX); - + //! Modifies the default attributes for text //! in the visualiser. Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectText3d)& CTX); - + //! Modifies the default attributes for markers //! in the visualiser. Standard_EXPORT void SetPrimitivesAspect (const Handle(Graphic3d_AspectMarker3d)& CTX); - + //! Modifies the screen update mode. //! - //! TOU_ASAP as soon as possible - //! TOU_WAIT on demand (with the Update function) + //! TOU_ASAP - as soon as possible + //! TOU_WAIT - on demand (with the Update function) //! Note : Dynamic Operations and Update Mode //! Use SetUpdateMode to control when changes to //! the display are made. Use one of the following //! functions to update one or more views: - //! - Update all views of the viewer: Visual3d_ViewManager::Update () - //! - Update one view of the viewer: Visual3d_View::Update () Use one of - //! the following functions to update the entire display: - //! - Redraw all structures in all views: Visual3d_ViewManager::Redraw () - //! - Redraw all structures in one view: Visual3d_View::Redraw () Update) - Standard_EXPORT void SetUpdateMode (const Aspect_TypeOfUpdate AType); - - //! Updates screen in function of modifications of - //! the structures. - //! Warning: Not necessary if the update mode is TOU_ASAP. - Standard_EXPORT virtual void Update() const = 0; - + //! - Update all views of the viewer: Graphic3d_StructureManager::Update() + //! - Update one view of the viewer: Graphic3d_View::Update() + //! Use one of the following functions to update the entire display: + //! - Redraw all structures in all views: Graphic3d_StructureManager::Redraw() + //! - Redraw all structures in one view: Graphic3d_View::Redraw() + Standard_EXPORT void SetUpdateMode (const Aspect_TypeOfUpdate theType); + + //! Returns the screen update mode. + //! + //! TOU_ASAP as soon as possible + //! TOU_WAIT on demand (Update) + Standard_EXPORT Aspect_TypeOfUpdate UpdateMode() const; + + //! Updates screen in function of modifications of the structures. + Standard_EXPORT virtual void Update (const Aspect_TypeOfUpdate theMode = Aspect_TOU_ASAP) const; + + //! Deletes and erases the 3D structure manager. + Standard_EXPORT virtual void Remove(); + + //! Erases all the structures. + Standard_EXPORT virtual void Erase(); + //! Returns the set of structures displayed in //! visualiser . Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& SG) const; - + //! Returns the set of highlighted structures //! in a visualiser . Standard_EXPORT void HighlightedStructures (Graphic3d_MapOfStructure& SG) const; - + //! Returns the values of the current default attributes. Standard_EXPORT Handle(Graphic3d_AspectFillArea3d) FillArea3dAspect() const; - + //! Returns maximum number of managers defineable. Standard_EXPORT static Standard_Integer Limit(); - + //! Returns the values of the current default attributes. Standard_EXPORT Handle(Graphic3d_AspectLine3d) Line3dAspect() const; - + //! Returns the values of the current default attributes. Standard_EXPORT Handle(Graphic3d_AspectMarker3d) Marker3dAspect() const; - + //! Returns the values of the current default attributes. Standard_EXPORT void PrimitivesAspect (Handle(Graphic3d_AspectLine3d)& CTXL, Handle(Graphic3d_AspectText3d)& CTXT, Handle(Graphic3d_AspectMarker3d)& CTXM, Handle(Graphic3d_AspectFillArea3d)& CTXF) const; - + //! Returns the values of the current default attributes. Standard_EXPORT Handle(Graphic3d_AspectText3d) Text3dAspect() const; - - //! Returns the screen update mode. - //! - //! TOU_ASAP as soon as possible - //! TOU_WAIT on demand (Update) - Standard_EXPORT Aspect_TypeOfUpdate UpdateMode() const; - - //! Changes the display priority of the structure . - Standard_EXPORT virtual void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) = 0; - - //! Change Z layer for structure. The z layer mechanism allows - //! to display structures in higher layers in overlay of structures in - //! lower layers. - Standard_EXPORT virtual void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, const Graphic3d_ZLayerId theLayerId) = 0; - - //! Sets the settings for a single Z layer for all managed views. - Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) = 0; - - //! Returns the settings of a single Z layer. - Standard_EXPORT virtual Graphic3d_ZLayerSettings ZLayerSettings (const Graphic3d_ZLayerId theLayerId) = 0; - - //! Add a new top-level Z layer and get its ID as - //! value. The method returns Standard_False if the layer - //! can not be created. The z layer mechanism allows to display - //! structures in higher layers in overlay of structures in lower layers. - Standard_EXPORT virtual Standard_Boolean AddZLayer (Graphic3d_ZLayerId& theLayerId) = 0; - - //! Remove Z layer with ID . Method returns - //! Standard_False if the layer can not be removed or doesn't exists. - //! By default, there is always a default bottom-level layer that can't - //! be removed. - Standard_EXPORT virtual Standard_Boolean RemoveZLayer (const Graphic3d_ZLayerId theLayerId) = 0; - - //! Return all Z layer ids in sequence ordered by level - //! from lowest layer to highest. The first layer ID in sequence is - //! the default layer that can't be removed. - Standard_EXPORT virtual void GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const = 0; - + //! Returns a current identifier available. Standard_EXPORT static Standard_Integer CurrentId(); - - //! Forces a new construction of the structure - //! if is displayed and TOS_COMPUTED. - Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& AStructure) = 0; - - //! Forces a new construction of the structure - //! if is displayed in and TOS_COMPUTED. - Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& AStructure, const Handle(Graphic3d_DataStructureManager)& AProjector) = 0; - - //! Clears the structure . - Standard_EXPORT virtual void Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) = 0; - - //! Connects the structures and . - Standard_EXPORT virtual void Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) = 0; - - //! Disconnects the structures and . - Standard_EXPORT virtual void Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) = 0; - - //! Display the structure . - Standard_EXPORT virtual void Display (const Handle(Graphic3d_Structure)& AStructure) = 0; - - //! Erases the structure . - Standard_EXPORT virtual void Erase (const Handle(Graphic3d_Structure)& AStructure) = 0; - - //! Highlights the structure . - Standard_EXPORT virtual void Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) = 0; - - //! Transforms the structure . - Standard_EXPORT virtual void SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) = 0; - + + //! Forces a new construction of the structure. + //! if is displayed and TOS_COMPUTED. + Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& theStructure); + + //! Forces a new construction of the structure. + //! if is displayed in and TOS_COMPUTED. + Standard_EXPORT virtual void ReCompute (const Handle(Graphic3d_Structure)& theStructure, const Handle(Graphic3d_DataStructureManager)& theProjector); + + //! Clears the structure. + Standard_EXPORT virtual void Clear (const Handle(Graphic3d_Structure)& theStructure, const Standard_Boolean theWithDestruction); + + //! Connects the structures. + Standard_EXPORT virtual void Connect (const Handle(Graphic3d_Structure)& theMother, const Handle(Graphic3d_Structure)& theDaughter); + + //! Disconnects the structures. + Standard_EXPORT virtual void Disconnect (const Handle(Graphic3d_Structure)& theMother, const Handle(Graphic3d_Structure)& theDaughter); + + //! Display the structure. + Standard_EXPORT virtual void Display (const Handle(Graphic3d_Structure)& theStructure); + + //! Erases the structure. + Standard_EXPORT virtual void Erase (const Handle(Graphic3d_Structure)& theStructure); + + //! Highlights the structure. + Standard_EXPORT virtual void Highlight (const Handle(Graphic3d_Structure)& theStructure, const Aspect_TypeOfHighlightMethod theMethod); + + //! Transforms the structure. + Standard_EXPORT virtual void SetTransform (const Handle(Graphic3d_Structure)& theStructure, const TColStd_Array2OfReal& theTrsf); + + //! Changes the display priority of the structure . + Standard_EXPORT virtual void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStructure, const Standard_Integer theOldPriority, const Standard_Integer theNewPriority); + + //! Change Z layer for structure. The Z layer mechanism allows to display structures in higher + //! layers in overlay of structures in lower layers. + Standard_EXPORT virtual void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, const Graphic3d_ZLayerId theLayerId); + //! Returns the graphic driver of . Standard_EXPORT const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const; - + + //! Attaches the view to this structure manager and sets its identification number within the manager. + Standard_EXPORT Standard_Integer Identification (Graphic3d_CView* theView); + + //! Detach the view from this structure manager and release its identification. + Standard_EXPORT void UnIdentification (Graphic3d_CView* theView); + + //! Returns the group of views defined in the structure manager. + Standard_EXPORT const Graphic3d_IndexedMapOfView& DefinedViews() const; + + //! Returns the theoretical maximum number of definable views in the manager. + //! Warning: It's not possible to accept an infinite number of definable views because each + //! view must have an identification and we have different managers. + Standard_EXPORT Standard_Integer MaxNumOfViews() const; + //! Returns the identification number of the manager. Standard_EXPORT virtual Standard_Integer Identification() const; - + //! Returns the structure with the identification number . Standard_EXPORT virtual Handle(Graphic3d_Structure) Identification (const Standard_Integer AId) const; - + //! Returns a new identification number for a new structure in the manager. Standard_EXPORT Standard_Integer NewIdentification(); - - //! Suppresses the highlighting on all the structures in . - Standard_EXPORT virtual void UnHighlight() = 0; - + //! Suppress the highlighting on the structure . - Standard_EXPORT virtual void UnHighlight (const Handle(Graphic3d_Structure)& AStructure) = 0; - + Standard_EXPORT virtual void UnHighlight (const Handle(Graphic3d_Structure)& AStructure); + + //! Suppresses the highlighting on all the structures in . + Standard_EXPORT virtual void UnHighlight(); + Standard_EXPORT void RecomputeStructures(); - + //! Recomputes all structures from theStructures. Standard_EXPORT void RecomputeStructures (const Graphic3d_MapOfStructure& theStructures); - + Standard_EXPORT Handle(Graphic3d_ViewAffinity) RegisterObject (const Handle(Standard_Transient)& theObject); - + Standard_EXPORT void UnregisterObject (const Handle(Standard_Transient)& theObject); - - Standard_EXPORT Handle(Graphic3d_ViewAffinity) ObjectAffinity (const Handle(Standard_Transient)& theObject) const; -friend class Graphic3d_Structure; + Standard_EXPORT Handle(Graphic3d_ViewAffinity) ObjectAffinity (const Handle(Standard_Transient)& theObject) const; + friend class Graphic3d_Structure; DEFINE_STANDARD_RTTI(Graphic3d_StructureManager,MMgt_TShared) protected: - - //! Initialises the ViewManager. - //! Currently creating of more than 100 viewer instances - //! is not supported and leads to InitializationError and - //! initialisation failure. - //! This limitation might be addressed in some future OCCT releases. - //! Warning: Raises InitialisationError if the initialisation - //! of the ViewManager failed. - Standard_EXPORT Graphic3d_StructureManager(const Handle(Graphic3d_GraphicDriver)& theDriver); - //! Returns the number of structures displayed in - //! visualiser . - //! Returns the structure displayed in visualiser . + //! visualizer . + //! Returns the structure displayed in visualizer . Standard_EXPORT Standard_Integer NumberOfDisplayedStructures() const; - Standard_Integer MyId; - Aspect_TypeOfUpdate MyUpdateMode; - Handle(Graphic3d_AspectLine3d) MyAspectLine3d; - Handle(Graphic3d_AspectText3d) MyAspectText3d; - Handle(Graphic3d_AspectMarker3d) MyAspectMarker3d; - Handle(Graphic3d_AspectFillArea3d) MyAspectFillArea3d; - Graphic3d_MapOfStructure MyDisplayedStructure; - Graphic3d_MapOfObject myRegisteredObjects; - Graphic3d_MapOfStructure MyHighlightedStructure; - Aspect_GenId MyStructGenId; - Handle(Graphic3d_GraphicDriver) MyGraphicDriver; - - private: - - //! Frees the identifieur . - Standard_EXPORT void Remove (const Standard_Integer AnId); - + //! Frees the identifier of a structure. + void Remove (const Standard_Integer theId); +protected: + Standard_Integer myId; + Aspect_GenId myStructGenId; + Aspect_GenId myViewGenId; + Aspect_TypeOfUpdate myUpdateMode; + Handle(Graphic3d_AspectLine3d) myAspectLine3d; + Handle(Graphic3d_AspectText3d) myAspectText3d; + Handle(Graphic3d_AspectMarker3d) myAspectMarker3d; + Handle(Graphic3d_AspectFillArea3d) myAspectFillArea3d; + Graphic3d_MapOfStructure myDisplayedStructure; + Graphic3d_MapOfStructure myHighlightedStructure; + Graphic3d_MapOfObject myRegisteredObjects; + Handle(Graphic3d_GraphicDriver) myGraphicDriver; + Graphic3d_IndexedMapOfView myDefinedViews; }; - - - - - - #endif // _Graphic3d_StructureManager_HeaderFile diff --git a/src/Graphic3d/Graphic3d_TextureEnv.hxx b/src/Graphic3d/Graphic3d_TextureEnv.hxx index 70c62d9041..d94a2cba3b 100644 --- a/src/Graphic3d/Graphic3d_TextureEnv.hxx +++ b/src/Graphic3d/Graphic3d_TextureEnv.hxx @@ -31,7 +31,7 @@ class TCollection_AsciiString; class Graphic3d_TextureEnv; DEFINE_STANDARD_HANDLE(Graphic3d_TextureEnv, Graphic3d_TextureRoot) -//! This class provides environment texture usable only in Visual3d_ContextView +//! This class provides environment texture. class Graphic3d_TextureEnv : public Graphic3d_TextureRoot { diff --git a/src/Visual3d/Visual3d_TypeOfAnswer.hxx b/src/Graphic3d/Graphic3d_TypeOfAnswer.hxx similarity index 81% rename from src/Visual3d/Visual3d_TypeOfAnswer.hxx rename to src/Graphic3d/Graphic3d_TypeOfAnswer.hxx index 305188fb98..1f72e9a403 100644 --- a/src/Visual3d/Visual3d_TypeOfAnswer.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfAnswer.hxx @@ -14,8 +14,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfAnswer_HeaderFile -#define _Visual3d_TypeOfAnswer_HeaderFile +#ifndef _Graphic3d_TypeOfAnswer_HeaderFile +#define _Graphic3d_TypeOfAnswer_HeaderFile //! The answer of the method AcceptDisplay //! AcceptDisplay means is it possible to display the @@ -23,11 +23,11 @@ //! TOA_YES yes //! TOA_NO no //! TOA_COMPUTE yes but we have to compute the representation -enum Visual3d_TypeOfAnswer +enum Graphic3d_TypeOfAnswer { -Visual3d_TOA_YES, -Visual3d_TOA_NO, -Visual3d_TOA_COMPUTE + Graphic3d_TOA_YES, + Graphic3d_TOA_NO, + Graphic3d_TOA_COMPUTE }; -#endif // _Visual3d_TypeOfAnswer_HeaderFile +#endif // _Graphic3d_TypeOfAnswer_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfBackfacingModel.hxx b/src/Graphic3d/Graphic3d_TypeOfBackfacingModel.hxx similarity index 77% rename from src/Visual3d/Visual3d_TypeOfBackfacingModel.hxx rename to src/Graphic3d/Graphic3d_TypeOfBackfacingModel.hxx index 6659744c01..0182d945ed 100644 --- a/src/Visual3d/Visual3d_TypeOfBackfacingModel.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfBackfacingModel.hxx @@ -14,19 +14,19 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfBackfacingModel_HeaderFile -#define _Visual3d_TypeOfBackfacingModel_HeaderFile +#ifndef _Graphic3d_TypeOfBackfacingModel_HeaderFile +#define _Graphic3d_TypeOfBackfacingModel_HeaderFile //! Modes of display of back faces in the view //! //! TOBM_AUTOMATIC graphic's structure setting is in use //! TOBM_FORCE force display of back faces //! TOBM_DISABLE disable display of back faces -enum Visual3d_TypeOfBackfacingModel +enum Graphic3d_TypeOfBackfacingModel { -Visual3d_TOBM_AUTOMATIC, -Visual3d_TOBM_FORCE, -Visual3d_TOBM_DISABLE + Graphic3d_TOBM_AUTOMATIC, + Graphic3d_TOBM_FORCE, + Graphic3d_TOBM_DISABLE }; -#endif // _Visual3d_TypeOfBackfacingModel_HeaderFile +#endif // _Graphic3d_TypeOfBackfacingModel_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfLightSource.hxx b/src/Graphic3d/Graphic3d_TypeOfLightSource.hxx similarity index 76% rename from src/Visual3d/Visual3d_TypeOfLightSource.hxx rename to src/Graphic3d/Graphic3d_TypeOfLightSource.hxx index d1dea0ac33..17a923a8ed 100644 --- a/src/Visual3d/Visual3d_TypeOfLightSource.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfLightSource.hxx @@ -14,8 +14,8 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfLightSource_HeaderFile -#define _Visual3d_TypeOfLightSource_HeaderFile +#ifndef _Graphic3d_TypeOfLightSource_HeaderFile +#define _Graphic3d_TypeOfLightSource_HeaderFile //! Definition of all the type of light sources //! @@ -23,12 +23,12 @@ //! TOLS_DIRECTIONAL directional light //! TOLS_POSITIONAL positional light //! TOLS_SPOT spot light -enum Visual3d_TypeOfLightSource +enum Graphic3d_TypeOfLightSource { -Visual3d_TOLS_AMBIENT, -Visual3d_TOLS_DIRECTIONAL, -Visual3d_TOLS_POSITIONAL, -Visual3d_TOLS_SPOT + Graphic3d_TOLS_AMBIENT, + Graphic3d_TOLS_DIRECTIONAL, + Graphic3d_TOLS_POSITIONAL, + Graphic3d_TOLS_SPOT }; -#endif // _Visual3d_TypeOfLightSource_HeaderFile +#endif // _Graphic3d_TypeOfLightSource_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfModel.hxx b/src/Graphic3d/Graphic3d_TypeOfShadingModel.hxx similarity index 56% rename from src/Visual3d/Visual3d_TypeOfModel.hxx rename to src/Graphic3d/Graphic3d_TypeOfShadingModel.hxx index f51e0749a0..b889d4c8b3 100644 --- a/src/Visual3d/Visual3d_TypeOfModel.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfShadingModel.hxx @@ -14,20 +14,20 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfModel_HeaderFile -#define _Visual3d_TypeOfModel_HeaderFile +#ifndef _Graphic3d_TypeOfShadingModel_HeaderFile +#define _Graphic3d_TypeOfShadingModel_HeaderFile //! Definition of the rendering (colour shading) model -//! Visual3d_TOM_NONE No lighting, only white ambient light -//! Visual3d_TOM_FACET No interpolation, constant shading (Flat Shading) -//! Visual3d_TOM_VERTEX Interpolation of color based on normals (Gouraud Shading) -//! Visual3d_TOM_FRAGMENT Interpolation of color based on normals (Phong Shading) -enum Visual3d_TypeOfModel +//! Graphic3d_TOSM_NONE No lighting, only white ambient light +//! Graphic3d_TOSM_FACET No interpolation, constant shading (Flat Shading) +//! Graphic3d_TOSM_VERTEX Interpolation of color based on normals (Gouraud Shading) +//! Graphic3d_TOSM_FRAGMENT Interpolation of color based on normals (Phong Shading) +enum Graphic3d_TypeOfShadingModel { -Visual3d_TOM_NONE, -Visual3d_TOM_FACET, -Visual3d_TOM_VERTEX, -Visual3d_TOM_FRAGMENT + Graphic3d_TOSM_NONE, + Graphic3d_TOSM_FACET, + Graphic3d_TOSM_VERTEX, + Graphic3d_TOSM_FRAGMENT }; -#endif // _Visual3d_TypeOfModel_HeaderFile +#endif // _Graphic3d_TypeOfShadingModel_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfSurfaceDetail.hxx b/src/Graphic3d/Graphic3d_TypeOfSurfaceDetail.hxx similarity index 78% rename from src/Visual3d/Visual3d_TypeOfSurfaceDetail.hxx rename to src/Graphic3d/Graphic3d_TypeOfSurfaceDetail.hxx index b288b623cb..7e965dc52c 100644 --- a/src/Visual3d/Visual3d_TypeOfSurfaceDetail.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfSurfaceDetail.hxx @@ -14,19 +14,19 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfSurfaceDetail_HeaderFile -#define _Visual3d_TypeOfSurfaceDetail_HeaderFile +#ifndef _Graphic3d_TypeOfSurfaceDetail_HeaderFile +#define _Graphic3d_TypeOfSurfaceDetail_HeaderFile //! Modes of visualisation of objects in a view //! //! TOD_NONE no texture mapping //! TOD_ENVIRONMENT only environnement mapping //! TOD_ALL environnement + texture mapping -enum Visual3d_TypeOfSurfaceDetail +enum Graphic3d_TypeOfSurfaceDetail { -Visual3d_TOD_NONE, -Visual3d_TOD_ENVIRONMENT, -Visual3d_TOD_ALL + Graphic3d_TOD_NONE, + Graphic3d_TOD_ENVIRONMENT, + Graphic3d_TOD_ALL }; -#endif // _Visual3d_TypeOfSurfaceDetail_HeaderFile +#endif // _Graphic3d_TypeOfSurfaceDetail_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfVisualization.hxx b/src/Graphic3d/Graphic3d_TypeOfVisualization.hxx similarity index 78% rename from src/Visual3d/Visual3d_TypeOfVisualization.hxx rename to src/Graphic3d/Graphic3d_TypeOfVisualization.hxx index f19d6b1118..ec3cf0f7e9 100644 --- a/src/Visual3d/Visual3d_TypeOfVisualization.hxx +++ b/src/Graphic3d/Graphic3d_TypeOfVisualization.hxx @@ -14,17 +14,17 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_TypeOfVisualization_HeaderFile -#define _Visual3d_TypeOfVisualization_HeaderFile +#ifndef _Graphic3d_TypeOfVisualization_HeaderFile +#define _Graphic3d_TypeOfVisualization_HeaderFile //! Modes of visualisation of objects in a view //! //! TOV_WIREFRAME wireframe visualisation //! TOV_SHADING shaded visualisation -enum Visual3d_TypeOfVisualization +enum Graphic3d_TypeOfVisualization { -Visual3d_TOV_WIREFRAME, -Visual3d_TOV_SHADING + Graphic3d_TOV_WIREFRAME, + Graphic3d_TOV_SHADING }; -#endif // _Visual3d_TypeOfVisualization_HeaderFile +#endif // _Graphic3d_TypeOfVisualization_HeaderFile diff --git a/src/InterfaceGraphic/FILES b/src/InterfaceGraphic/FILES index 20cd2657e7..6d9bfeb378 100755 --- a/src/InterfaceGraphic/FILES +++ b/src/InterfaceGraphic/FILES @@ -1,6 +1,4 @@ InterfaceGraphic.hxx -InterfaceGraphic_Aspect.hxx InterfaceGraphic_Graphic3d.hxx InterfaceGraphic_telem.hxx InterfaceGraphic_tgl_all.hxx -InterfaceGraphic_Visual3d.hxx diff --git a/src/InterfaceGraphic/InterfaceGraphic_Aspect.hxx b/src/InterfaceGraphic/InterfaceGraphic_Aspect.hxx deleted file mode 100644 index 533bd925aa..0000000000 --- a/src/InterfaceGraphic/InterfaceGraphic_Aspect.hxx +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef InterfaceGraphic_AspectHeader -#define InterfaceGraphic_AspectHeader - -#include -#include - -/* WINDOW */ - -typedef struct { - - int IsDefined; - - Aspect_Drawable XWindow; - Aspect_Drawable XParentWindow; - - int dx, dy; - int left, top; - - struct { - float r, g, b; - } Background; - -} CALL_DEF_WINDOW; - - -typedef struct { - int listIndex; - void* layerData; -} CALL_DEF_PTRLAYER, *call_def_ptrLayer; - - -/* LAYER */ - -typedef struct { - CALL_DEF_PTRLAYER* ptrLayer; - int layerType; - int attach; - int sizeDependent; - float ortho[4]; - float viewport[2]; - -} CALL_DEF_LAYER; - -#endif /* InterfaceGraphic_AspectHeader */ diff --git a/src/InterfaceGraphic/InterfaceGraphic_Visual3d.hxx b/src/InterfaceGraphic/InterfaceGraphic_Visual3d.hxx deleted file mode 100644 index 240a8fe8c2..0000000000 --- a/src/InterfaceGraphic/InterfaceGraphic_Visual3d.hxx +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef InterfaceGraphic_Visual3dHeader -#define InterfaceGraphic_Visual3dHeader - -#include -#include -#include -#include -#include - -typedef float CALL_DEF_MATRIX4X4[4][4]; - -/* SOMMET */ - -typedef struct { - - float x, y, z; - -} CALL_DEF_VERTEX; - -/* ORIENTATION */ - -typedef struct { - - CALL_DEF_VERTEX ViewReferencePoint; - CALL_DEF_VERTEX ViewReferencePlane; - CALL_DEF_VERTEX ViewReferenceUp; - float ViewScaleX; - float ViewScaleY; - float ViewScaleZ; - - float ModelViewMatrix[4][4]; - - unsigned IsCustomMatrix; - -} CALL_DEF_VIEWORIENTATION; - - -/* MAPPING */ - -typedef struct { - - int Projection; - - CALL_DEF_VERTEX ProjectionReferencePoint; - - float ViewPlaneDistance; - float BackPlaneDistance; - float FrontPlaneDistance; - - struct { - float um, vm, uM, vM; - } WindowLimit; - - float ProjectionMatrix[4][4]; - - unsigned IsCustomMatrix; - -} CALL_DEF_VIEWMAPPING; - -#endif /* InterfaceGraphic_Visual3dHeader */ diff --git a/src/OpenGl/FILES b/src/OpenGl/FILES index 2a784b8087..650941a09c 100755 --- a/src/OpenGl/FILES +++ b/src/OpenGl/FILES @@ -28,20 +28,20 @@ OpenGl_PrimitiveArray.hxx OpenGl_PrimitiveArray.cxx OpenGl_Workspace.hxx OpenGl_Workspace.cxx -OpenGl_Workspace_2.cxx -OpenGl_Workspace_5.cxx OpenGl_View.hxx OpenGl_View.cxx -OpenGl_View_2.cxx +OpenGl_View_Print.cxx +OpenGl_View_Raytrace.cxx +OpenGl_View_Redraw.cxx OpenGl_Light.hxx OpenGl_Trihedron.hxx OpenGl_Trihedron.cxx OpenGl_GraduatedTrihedron.hxx OpenGl_GraduatedTrihedron.cxx +OpenGl_MapOfZLayerSettings.hxx OpenGl_Matrix.hxx OpenGl_Matrix.cxx OpenGl_MatrixState.hxx -OpenGl_CView.hxx OpenGl_NamedStatus.hxx OpenGl_TextParam.hxx OpenGl_PrinterContext.hxx @@ -113,10 +113,6 @@ OpenGl_LayerList.hxx OpenGl_LayerFilter.hxx OpenGl_GraphicDriver.cxx OpenGl_GraphicDriver.hxx -OpenGl_GraphicDriver_4.cxx -OpenGl_GraphicDriver_7.cxx -OpenGl_GraphicDriver_713.cxx -OpenGl_GraphicDriver_Export.cxx OpenGl_IndexBuffer.cxx OpenGl_IndexBuffer.hxx OpenGl_Layer.cxx @@ -151,6 +147,5 @@ OpenGl_VertexBuffer.lxx OpenGl_VertexBufferCompat.cxx OpenGl_VertexBufferCompat.hxx OpenGl_VertexBufferEditor.hxx -OpenGl_View_Raytrace.cxx OpenGl_TextBuilder.hxx OpenGl_TextBuilder.cxx \ No newline at end of file diff --git a/src/OpenGl/OpenGl_CView.hxx b/src/OpenGl/OpenGl_CView.hxx deleted file mode 100644 index ec443f7842..0000000000 --- a/src/OpenGl/OpenGl_CView.hxx +++ /dev/null @@ -1,31 +0,0 @@ -// Created on: 2011-09-20 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef OpenGl_CView_Header -#define OpenGl_CView_Header - -#include - -#include -#include - -struct OpenGl_CView -{ - Handle(OpenGl_Workspace) WS; - Handle(OpenGl_View) View; - DEFINE_STANDARD_ALLOC -}; - -#endif //OpenGl_CView_Header diff --git a/src/OpenGl/OpenGl_Context.cxx b/src/OpenGl/OpenGl_Context.cxx index 5a1a4e7d97..53ef7a2630 100644 --- a/src/OpenGl/OpenGl_Context.cxx +++ b/src/OpenGl/OpenGl_Context.cxx @@ -220,7 +220,7 @@ OpenGl_Context::~OpenGl_Context() myUnusedResources->RemoveFirst(); } } - else + else if (myShaderManager->IsSameContext (this)) { myShaderManager->SetContext (NULL); } @@ -2722,3 +2722,87 @@ void OpenGl_Context::ApplyProjectionMatrix() myShaderManager->UpdateProjectionStateTo (ProjectionState.Current()); } } + + +// ======================================================================= +// function : EnableFeatures +// purpose : +// ======================================================================= +void OpenGl_Context::EnableFeatures() const +{ + // +} + +// ======================================================================= +// function : DisableFeatures +// purpose : +// ======================================================================= +void OpenGl_Context::DisableFeatures() const +{ +#if !defined(GL_ES_VERSION_2_0) + glPixelTransferi (GL_MAP_COLOR, GL_FALSE); +#endif + + /* + * Disable stuff that's likely to slow down glDrawPixels. + * (Omit as much of this as possible, when you know in advance + * that the OpenGL state will already be set correctly.) + */ + glDisable(GL_DITHER); + glDisable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glDisable(GL_TEXTURE_2D); + glDisable(GL_STENCIL_TEST); + +#if !defined(GL_ES_VERSION_2_0) + glDisable(GL_LIGHTING); + glDisable(GL_ALPHA_TEST); + glDisable(GL_FOG); + glDisable(GL_LOGIC_OP); + glDisable(GL_TEXTURE_1D); + + glPixelTransferi(GL_MAP_COLOR, GL_FALSE); + glPixelTransferi(GL_RED_SCALE, 1); + glPixelTransferi(GL_RED_BIAS, 0); + glPixelTransferi(GL_GREEN_SCALE, 1); + glPixelTransferi(GL_GREEN_BIAS, 0); + glPixelTransferi(GL_BLUE_SCALE, 1); + glPixelTransferi(GL_BLUE_BIAS, 0); + glPixelTransferi(GL_ALPHA_SCALE, 1); + glPixelTransferi(GL_ALPHA_BIAS, 0); + + /* + * Disable extensions that could slow down glDrawPixels. + * (Actually, you should check for the presence of the proper + * extension before making these calls. I've omitted that + * code for simplicity.) + */ + + if ((myGlVerMajor >= 1) && (myGlVerMinor >= 2)) + { +#ifdef GL_EXT_convolution + if (CheckExtension ("GL_CONVOLUTION_1D_EXT")) + glDisable(GL_CONVOLUTION_1D_EXT); + + if (CheckExtension ("GL_CONVOLUTION_2D_EXT")) + glDisable(GL_CONVOLUTION_2D_EXT); + + if (CheckExtension ("GL_SEPARABLE_2D_EXT")) + glDisable(GL_SEPARABLE_2D_EXT); +#endif + +#ifdef GL_EXT_histogram + if (CheckExtension ("GL_SEPARABLE_2D_EXT")) + glDisable(GL_HISTOGRAM_EXT); + + if (CheckExtension ("GL_MINMAX_EXT")) + glDisable(GL_MINMAX_EXT); +#endif + +#ifdef GL_EXT_texture3D + if (CheckExtension ("GL_TEXTURE_3D_EXT")) + glDisable(GL_TEXTURE_3D_EXT); +#endif + } +#endif +} diff --git a/src/OpenGl/OpenGl_Context.hxx b/src/OpenGl/OpenGl_Context.hxx index e4573eb1bc..98a7fa979d 100644 --- a/src/OpenGl/OpenGl_Context.hxx +++ b/src/OpenGl/OpenGl_Context.hxx @@ -573,6 +573,10 @@ public: //! @name methods to alter or retrieve current state return myIsGlDebugCtx; } + Standard_EXPORT void EnableFeatures() const; + + Standard_EXPORT void DisableFeatures() const; + private: //! Wrapper to system function to retrieve GL function pointer by name. diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx index 1eb00d2a89..a836256821 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.cxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.cxx @@ -15,8 +15,6 @@ #include #include -#include -#include #include @@ -50,7 +48,8 @@ namespace // ======================================================================= OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron() : myMin (0.0f, 0.0f, 0.0f), - myMax (100.0f, 100.0f, 100.0f) + myMax (100.0f, 100.0f, 100.0f), + myIsInitialized (Standard_False) { // } @@ -59,38 +58,10 @@ OpenGl_GraduatedTrihedron::OpenGl_GraduatedTrihedron() // function : SetValues // purpose : // ======================================================================= -void OpenGl_GraduatedTrihedron::SetValues (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_GraduatedTrihedron& theData) +void OpenGl_GraduatedTrihedron::SetValues (const Graphic3d_GraduatedTrihedron& theData) { - Release (theCtx.operator->()); - myData = theData; - - // Initialize text label parameters for x, y, and z axes - myAxes[0] = Axis (myData.XAxisAspect(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); - myAxes[1] = Axis (myData.YAxisAspect(), OpenGl_Vec3 (0.0f, 1.0f, 0.0f)); - myAxes[2] = Axis (myData.ZAxisAspect(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - - // Initialize constant primitives: text, arrows. - myAxes[0].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - myAxes[1].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); - myAxes[2].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); - for (Standard_Integer anIt = 0; anIt < 3; ++anIt) - { - myAxes[anIt].Label.SetFontSize (theCtx, theData.NamesSize()); - } - - myLabelValues.SetFontSize (theCtx, theData.ValuesSize()); - - myAspectLabels.SetFontAspect (theData.NamesFontAspect()); - myAspectLabels.ChangeFontName() = theData.NamesFont(); - - myAspectValues.SetFontAspect (theData.ValuesFontAspect()); - myAspectValues.ChangeFontName() = theData.ValuesFont(); - - // Grid aspect - myGridLineAspect.ChangeColor().rgb[0] = (Standard_ShortReal) theData.GridColor().Red(); - myGridLineAspect.ChangeColor().rgb[1] = (Standard_ShortReal) theData.GridColor().Green(); - myGridLineAspect.ChangeColor().rgb[2] = (Standard_ShortReal) theData.GridColor().Blue(); + myData = theData; + myIsInitialized = Standard_False; } // ======================================================================= @@ -114,6 +85,45 @@ void OpenGl_GraduatedTrihedron::Release (OpenGl_Context* theCtx) myLabelValues.Release (theCtx); } +// ======================================================================= +// function : initResources +// purpose : +// ======================================================================= +void OpenGl_GraduatedTrihedron::initGlResources (const Handle(OpenGl_Context)& theCtx) const +{ + myAxes[0].Release (theCtx.operator->()); + myAxes[1].Release (theCtx.operator->()); + myAxes[2].Release (theCtx.operator->()); + myLabelValues.Release (theCtx.operator->()); + + // Initialize text label parameters for x, y, and z axes + myAxes[0] = Axis (myData.XAxisAspect(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); + myAxes[1] = Axis (myData.YAxisAspect(), OpenGl_Vec3 (0.0f, 1.0f, 0.0f)); + myAxes[2] = Axis (myData.ZAxisAspect(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); + + // Initialize constant primitives: text, arrows. + myAxes[0].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); + myAxes[1].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (0.0f, 0.0f, 1.0f)); + myAxes[2].InitArrow (theCtx, myData.ArrowsLength(), OpenGl_Vec3 (1.0f, 0.0f, 0.0f)); + for (Standard_Integer anIt = 0; anIt < 3; ++anIt) + { + myAxes[anIt].Label.SetFontSize (theCtx, myData.NamesSize()); + } + + myLabelValues.SetFontSize (theCtx, myData.ValuesSize()); + + myAspectLabels.SetFontAspect (myData.NamesFontAspect()); + myAspectLabels.ChangeFontName() = myData.NamesFont(); + + myAspectValues.SetFontAspect (myData.ValuesFontAspect()); + myAspectValues.ChangeFontName() = myData.ValuesFont(); + + // Grid aspect + myGridLineAspect.ChangeColor().rgb[0] = (Standard_ShortReal) myData.GridColor().Red(); + myGridLineAspect.ChangeColor().rgb[1] = (Standard_ShortReal) myData.GridColor().Green(); + myGridLineAspect.ChangeColor().rgb[2] = (Standard_ShortReal) myData.GridColor().Blue(); +} + // ======================================================================= // method : getNormal // purpose : Normal of the view (not normalized!) @@ -546,6 +556,11 @@ void OpenGl_GraduatedTrihedron::renderTickmarkLabels (const Handle(OpenGl_Worksp void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorkspace) const { const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + if (!myIsInitialized) + { + initGlResources (theWorkspace->GetGlContext()); + myIsInitialized = Standard_True; + } // Update boundary box OpenGl_Vec3 anOldMin = myMin; @@ -553,7 +568,7 @@ void OpenGl_GraduatedTrihedron::Render (const Handle(OpenGl_Workspace)& theWorks if (myData.CubicAxesCallback) { - myData.CubicAxesCallback (myData.PtrVisual3dView); + myData.CubicAxesCallback (myData.PtrView); if (!myAxes[0].Line.IsInitialized() || !myAxes[1].Line.IsInitialized() || !myAxes[2].Line.IsInitialized() diff --git a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx index 97d852a289..00e686bb9c 100755 --- a/src/OpenGl/OpenGl_GraduatedTrihedron.hxx +++ b/src/OpenGl/OpenGl_GraduatedTrihedron.hxx @@ -26,7 +26,6 @@ #include #include -class Visual3d_View; class OpenGl_View; //! This class allows to render Graduated Trihedron, i.e. trihedron with grid. @@ -54,8 +53,7 @@ public: virtual void Release (OpenGl_Context* theCtx); //! Setup configuration. - void SetValues (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_GraduatedTrihedron& theData); + void SetValues (const Graphic3d_GraduatedTrihedron& theData); //! Sets up-to-date values of scene bounding box. //! Can be used in callback mechanism to get up-to-date values. @@ -131,6 +129,10 @@ private: private: + //! Initialize or update GL resources for rendering trihedron. + //! @param theContext [in] the GL context. + void initGlResources (const Handle(OpenGl_Context)& theContext) const; + //! Gets normal of the view out of user. //! @param theContext [in] OpenGL Context //! @param theNormal [out] normal of the view out of user @@ -211,11 +213,9 @@ protected: //! @name Scene bounding box values protected: - Axis myAxes[3]; //!< Axes for trihedron - - Graphic3d_GraduatedTrihedron myData; - - OpenGl_AspectLine myGridLineAspect; //!< Color grid properties + mutable Axis myAxes[3]; //!< Axes for trihedron + mutable Graphic3d_GraduatedTrihedron myData; + mutable OpenGl_AspectLine myGridLineAspect; //!< Color grid properties protected: //! @name Labels properties @@ -225,6 +225,8 @@ protected: //! @name Labels properties private: + mutable Standard_Boolean myIsInitialized; + enum AxisFlags { XOO_XYO = 1 << 1, @@ -237,7 +239,6 @@ private: XOZ_XYZ = 1 << 8, XYO_XYZ = 1 << 9 }; - }; #endif //_OpenGl_GraduatedTrihedron_Header diff --git a/src/OpenGl/OpenGl_GraphicDriver.cxx b/src/OpenGl/OpenGl_GraphicDriver.cxx index c95df9cc1b..8a3e2106cb 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.cxx +++ b/src/OpenGl/OpenGl_GraphicDriver.cxx @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -26,10 +25,19 @@ #include #include +#include #include #include #include +#if defined(_WIN32) + #include +#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) + #include +#else + #include +#endif + #if !defined(_WIN32) && !defined(__ANDROID__) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) #include // XOpenDisplay() #endif @@ -38,7 +46,6 @@ #include #endif - namespace { static const Handle(OpenGl_Context) TheNullGlCtx; @@ -59,7 +66,6 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio #endif myCaps (new OpenGl_Caps()), myMapOfView (1, NCollection_BaseAllocator::CommonBaseAllocator()), - myMapOfWS (1, NCollection_BaseAllocator::CommonBaseAllocator()), myMapOfStructure (1, NCollection_BaseAllocator::CommonBaseAllocator()), myUserDrawCallback (NULL) { @@ -89,6 +95,46 @@ OpenGl_GraphicDriver::OpenGl_GraphicDriver (const Handle(Aspect_DisplayConnectio { Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_GraphicDriver: default context can not be initialized!"); } + + // default layers are always presented in display layer sequence it can not be removed + Graphic3d_ZLayerSettings anUnderlaySettings; + anUnderlaySettings.Flags = 0; + anUnderlaySettings.IsImmediate = false; + myLayerIds.Add (Graphic3d_ZLayerId_BotOSD); + myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD); + myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, anUnderlaySettings); + + Graphic3d_ZLayerSettings aDefSettings; + aDefSettings.Flags = Graphic3d_ZLayerDepthTest + | Graphic3d_ZLayerDepthWrite; + aDefSettings.IsImmediate = false; + myLayerIds.Add (Graphic3d_ZLayerId_Default); + myLayerSeq.Append (Graphic3d_ZLayerId_Default); + myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aDefSettings); + + Graphic3d_ZLayerSettings aTopSettings; + aTopSettings.Flags = Graphic3d_ZLayerDepthTest + | Graphic3d_ZLayerDepthWrite; + aTopSettings.IsImmediate = true; + myLayerIds.Add (Graphic3d_ZLayerId_Top); + myLayerSeq.Append (Graphic3d_ZLayerId_Top); + myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aTopSettings); + + Graphic3d_ZLayerSettings aTopmostSettings; + aTopmostSettings.Flags = Graphic3d_ZLayerDepthTest + | Graphic3d_ZLayerDepthWrite + | Graphic3d_ZLayerDepthClear; + aTopmostSettings.IsImmediate = true; + myLayerIds.Add (Graphic3d_ZLayerId_Topmost); + myLayerSeq.Append (Graphic3d_ZLayerId_Topmost); + myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aTopmostSettings); + + Graphic3d_ZLayerSettings anOsdSettings; + anOsdSettings.Flags = 0; + anOsdSettings.IsImmediate = true; + myLayerIds.Add (Graphic3d_ZLayerId_TopOSD); + myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD); + myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, anOsdSettings); } // ======================================================================= @@ -107,11 +153,17 @@ OpenGl_GraphicDriver::~OpenGl_GraphicDriver() void OpenGl_GraphicDriver::ReleaseContext() { Handle(OpenGl_Context) aCtxShared; - for (NCollection_Map::Iterator aWindowIter (myMapOfWS); - aWindowIter.More(); aWindowIter.Next()) + for (NCollection_Map::Iterator aViewIter (myMapOfView); + aViewIter.More(); aViewIter.Next()) { - const Handle(OpenGl_Workspace)& aWindow = aWindowIter.ChangeValue(); - const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext(); + const Handle(OpenGl_View)& aView = aViewIter.ChangeValue(); + const Handle(OpenGl_Window)& aWindow = aView->GlWindow(); + if (aWindow.IsNull()) + { + continue; + } + + const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext(); if (aCtx->MakeCurrent() && aCtxShared.IsNull()) { @@ -138,12 +190,17 @@ void OpenGl_GraphicDriver::ReleaseContext() } myDeviceLostFlag = myDeviceLostFlag || !myMapOfStructure.IsEmpty(); - for (NCollection_Map::Iterator aWindowIter (myMapOfWS); - aWindowIter.More(); aWindowIter.Next()) + for (NCollection_Map::Iterator aViewIter (myMapOfView); + aViewIter.More(); aViewIter.Next()) { - const Handle(OpenGl_Workspace)& aWindow = aWindowIter.ChangeValue(); - const Handle(OpenGl_Context)& aCtx = aWindow->GetGlContext(); - aCtx->forcedRelease(); + const Handle(OpenGl_View)& aView = aViewIter.ChangeValue(); + const Handle(OpenGl_Window)& aWindow = aView->GlWindow(); + if (aWindow.IsNull()) + { + continue; + } + + aWindow->GetGlContext()->forcedRelease(); } #if defined(HAVE_EGL) || defined(__ANDROID__) @@ -364,13 +421,24 @@ void OpenGl_GraphicDriver::EnableVBO (const Standard_Boolean theToTurnOn) // ======================================================================= const Handle(OpenGl_Context)& OpenGl_GraphicDriver::GetSharedContext() const { - if (myMapOfWS.IsEmpty()) + if (myMapOfView.IsEmpty()) { return TheNullGlCtx; } - NCollection_Map::Iterator anIter (myMapOfWS); - return anIter.Value()->GetGlContext(); + NCollection_Map::Iterator anIter (myMapOfView); + for (; anIter.More(); anIter.Next()) + { + Handle(OpenGl_Window) aWindow = anIter.Value()->GlWindow(); + if (aWindow.IsNull()) + { + continue; + } + + return aWindow->GetGlContext(); + } + + return TheNullGlCtx; } // ======================================================================= @@ -392,272 +460,345 @@ Standard_Boolean OpenGl_GraphicDriver::MemoryInfo (Standard_Size& theF } // ======================================================================= -// function : SetImmediateModeDrawToFront +// function : SetBuffersNoSwap // purpose : // ======================================================================= -Standard_Boolean OpenGl_GraphicDriver::SetImmediateModeDrawToFront (const Graphic3d_CView& theCView, - const Standard_Boolean theDrawToFrontBuffer) +void OpenGl_GraphicDriver::SetBuffersNoSwap (const Standard_Boolean theIsNoSwap) { - if (theCView.ViewId == -1) - { - return Standard_False; - } - - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - { - return aCView->WS->SetImmediateModeDrawToFront (theDrawToFrontBuffer); - } - return Standard_False; + myCaps->buffersNoSwap = theIsNoSwap; } // ======================================================================= -// function : Print +// function : TextSize // purpose : // ======================================================================= -Standard_Boolean OpenGl_GraphicDriver::Print (const Graphic3d_CView& theCView, - const Aspect_Handle thePrintDC, - const Standard_Boolean theToShowBackground, - const Standard_CString theFilename, - const Aspect_PrintAlgo thePrintAlgorithm, - const Standard_Real theScaleFactor) const +void OpenGl_GraphicDriver::TextSize (const Standard_CString theText, + const Standard_ShortReal theHeight, + Standard_ShortReal& theWidth, + Standard_ShortReal& theAscent, + Standard_ShortReal& theDescent) const { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView == NULL - || !myPrintContext.IsNull()) + const Handle(OpenGl_Context)& aCtx = GetSharedContext(); + if (aCtx.IsNull()) { - return Standard_False; + return; } - Standard_Boolean isPrinted = Standard_False; - myPrintContext = new OpenGl_PrinterContext(); -#ifdef _WIN32 - isPrinted = aCView->WS->Print (myPrintContext, - theCView, - thePrintDC, - theToShowBackground, - theFilename, - thePrintAlgorithm, - theScaleFactor); -#else - Standard_NotImplemented::Raise ("OpenGl_GraphicDriver::Print is implemented only on Windows"); -#endif - myPrintContext.Nullify(); - return isPrinted; + const Standard_ShortReal aHeight = (theHeight < 2.0f) ? DefaultTextHeight() : theHeight; + OpenGl_TextParam aTextParam; + aTextParam.Height = (int )aHeight; + OpenGl_AspectText aTextAspect; + CALL_DEF_CONTEXTTEXT aDefaultContextText = + { + 1, //IsDef + 1, //IsSet + "Courier", //Font + 0.3F, //Space + 1.F, //Expan + { 1.F, 1.F, 1.F }, //Color + (int)Aspect_TOST_NORMAL, //Style + (int)Aspect_TODT_NORMAL, //DisplayType + { 1.F, 1.F, 1.F }, //ColorSubTitle + 0, //TextZoomable + 0.F, //TextAngle + (int)Font_FA_Regular //TextFontAspect + }; + aTextAspect.SetAspect(aDefaultContextText); + TCollection_ExtendedString anExtText = theText; + NCollection_String aText = (Standard_Utf16Char* )anExtText.ToExtString(); + OpenGl_Text::StringSize (aCtx, aText, aTextAspect, aTextParam, theWidth, theAscent, theDescent); } -// ======================================================================= -// function : ZBufferTriedronSetup -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::ZBufferTriedronSetup (const Graphic3d_CView& theCView, - const Quantity_NameOfColor theXColor, - const Quantity_NameOfColor theYColor, - const Quantity_NameOfColor theZColor, - const Standard_Real theSizeRatio, - const Standard_Real theAxisDiametr, - const Standard_Integer theNbFacets) +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= +void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_ZLayerId theLayerId) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView == NULL) + if (theLayerId < 1) { - return; + Standard_ASSERT_RAISE (theLayerId > 0, + "OpenGl_GraphicDriver::AddZLayer, " + "negative and zero IDs are reserved"); } - OpenGl_Trihedron& aTrih = aCView->View->ChangeTrihedron(); - aTrih.SetArrowsColors (theXColor, theYColor, theZColor); - aTrih.SetSizeRatio (theSizeRatio); - aTrih.SetNbFacets (theNbFacets); - aTrih.SetArrowDiameter (theAxisDiametr); -} + myLayerIds.Add (theLayerId); + myLayerSeq.Append (theLayerId); -// ======================================================================= -// function : TriedronDisplay -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::TriedronDisplay (const Graphic3d_CView& theCView, - const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) + // Default z-layer settings + myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings()); + + // Add layer to all views + NCollection_Map::Iterator aViewIt (myMapOfView); + for (; aViewIt.More(); aViewIt.Next()) { - aCView->View->TriedronDisplay (thePosition, theColor, theScale, theAsWireframe); + aViewIt.Value()->AddZLayer (theLayerId); } } -// ======================================================================= -// function : TriedronErase -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::TriedronErase (const Graphic3d_CView& theCView) +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= +void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) + Standard_ASSERT_RAISE (theLayerId > 0, + "OpenGl_GraphicDriver::AddZLayer, " + "negative and zero IDs are reserved" + "and can not be removed"); + + Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId), + "OpenGl_GraphicDriver::RemoveZLayer, " + "Layer with theLayerId does not exist"); + + // Remove layer from all of the views + NCollection_Map::Iterator aViewIt (myMapOfView); + for (; aViewIt.More(); aViewIt.Next()) + { + aViewIt.Value()->RemoveZLayer (theLayerId); + } + + // Unset Z layer for all of the structures. + NCollection_DataMap::Iterator aStructIt (myMapOfStructure); + for( ; aStructIt.More (); aStructIt.Next ()) { - aCView->View->TriedronErase (aCView->WS->GetGlContext()); + OpenGl_Structure* aStruct = aStructIt.ChangeValue (); + if (aStruct->ZLayer() == theLayerId) + aStruct->SetZLayer (Graphic3d_ZLayerId_Default); } + + // Remove index + for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++) + { + if (myLayerSeq (aIdx) == theLayerId) + { + myLayerSeq.Remove (aIdx); + break; + } + } + + myMapOfZLayerSettings.UnBind (theLayerId); + myLayerIds.Remove (theLayerId); } -// ======================================================================= -// function : TriedronEcho -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::TriedronEcho (const Graphic3d_CView& , - const Aspect_TypeOfTriedronEcho ) +//======================================================================= +//function : ZLayers +//purpose : +//======================================================================= +void OpenGl_GraphicDriver::ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const { - // do nothing + theLayerSeq.Assign (myLayerSeq); } -// ======================================================================= -// function : Environment -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::Environment (const Graphic3d_CView& theCView) +//======================================================================= +//function : SetZLayerSettings +//purpose : +//======================================================================= +void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, + const Graphic3d_ZLayerSettings& theSettings) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView == NULL) + // Change Z layer settings in all managed views + NCollection_Map::Iterator aViewIt (myMapOfView); + for (; aViewIt.More(); aViewIt.Next()) { - return; + aViewIt.Value()->SetZLayerSettings (theLayerId, theSettings); } - aCView->View->SetTextureEnv (aCView->WS->GetGlContext(), theCView.Context.TextureEnv); - aCView->View->SetSurfaceDetail ((Visual3d_TypeOfSurfaceDetail)theCView.Context.SurfaceDetail); + if (myMapOfZLayerSettings.IsBound (theLayerId)) + { + myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings; + } + else + { + myMapOfZLayerSettings.Bind (theLayerId, theSettings); + } } -// ======================================================================= -// function : BackgroundImage -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::BackgroundImage (const Standard_CString theFileName, - const Graphic3d_CView& theCView, - const Aspect_FillMethod theFillStyle) +//======================================================================= +//function : ZLayerSettings +//purpose : +//======================================================================= +Graphic3d_ZLayerSettings OpenGl_GraphicDriver::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - { - aCView->View->CreateBackgroundTexture (theFileName, theFillStyle); - } + Standard_ASSERT_RAISE (myLayerIds.Contains (theLayerId), + "OpenGl_GraphicDriver::ZLayerSettings, " + "Layer with theLayerId does not exist"); + + return myMapOfZLayerSettings.Find (theLayerId); } // ======================================================================= -// function : SetBgImageStyle +// function : Structure // purpose : // ======================================================================= -void OpenGl_GraphicDriver::SetBgImageStyle (const Graphic3d_CView& theCView, - const Aspect_FillMethod theFillStyle) +Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - { - aCView->View->SetBackgroundTextureStyle (theFillStyle); - } + Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager); + myMapOfStructure.Bind (aStructure->Id, aStructure.operator->()); + return aStructure; } // ======================================================================= -// function : SetBgGradientStyle +// function : Structure // purpose : // ======================================================================= -void OpenGl_GraphicDriver::SetBgGradientStyle (const Graphic3d_CView& theCView, - const Aspect_GradientFillMethod theFillType) +void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) + OpenGl_Structure* aStructure = NULL; + if (!myMapOfStructure.Find (theCStructure->Id, aStructure)) { - aCView->View->SetBackgroundGradientType (theFillType); + return; } + + myMapOfStructure.UnBind (theCStructure->Id); + aStructure->Release (GetSharedContext()); + theCStructure.Nullify(); } // ======================================================================= -// function : GraduatedTrihedronDisplay +// function : View // purpose : // ======================================================================= -void OpenGl_GraphicDriver::GraduatedTrihedronDisplay (const Graphic3d_CView& theCView, - const Graphic3d_GraduatedTrihedron& theCubic) +Handle(Graphic3d_CView) OpenGl_GraphicDriver::CreateView (const Handle(Graphic3d_StructureManager)& theMgr) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) + Handle(OpenGl_View) aView = new OpenGl_View (theMgr, this, myCaps, myDeviceLostFlag, &myStateCounter); + + myMapOfView.Add (aView); + + for (TColStd_SequenceOfInteger::Iterator aLayerIt (myLayerSeq); aLayerIt.More(); aLayerIt.Next()) { - aCView->View->GraduatedTrihedronDisplay (aCView->WS->GetGlContext(), theCubic); + const Graphic3d_ZLayerId aLayerID = aLayerIt.Value(); + const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID); + aView->AddZLayer (aLayerID); + aView->SetZLayerSettings (aLayerID, aSettings); } + + return aView; } // ======================================================================= -// function : GraduatedTrihedronErase +// function : RemoveView // purpose : // ======================================================================= -void OpenGl_GraphicDriver::GraduatedTrihedronErase (const Graphic3d_CView& theCView) +void OpenGl_GraphicDriver::RemoveView (const Handle(Graphic3d_CView)& theView) { - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) + Handle(OpenGl_Context) aCtx = GetSharedContext(); + Handle(OpenGl_View) aView = Handle(OpenGl_View)::DownCast (theView); + if (aView.IsNull()) { - aCView->View->GraduatedTrihedronErase (aCView->WS->GetGlContext()); + return; } -} -// ======================================================================= -// function : GraduatedTrihedronMinMaxValues -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, - const Graphic3d_Vec3 theMin, - const Graphic3d_Vec3 theMax) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; - if (aCView != NULL) + if (!myMapOfView.Remove (aView)) + { + return; + } + + Handle(OpenGl_Window) aWindow = aView->GlWindow(); + if (!aWindow.IsNull() + && aWindow->GetGlContext()->MakeCurrent()) { - aCView->View->ChangeGraduatedTrihedron().SetMinMax (theMin, theMax); + aCtx = aWindow->GetGlContext(); + } + else + { + // try to hijack another context if any + const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext(); + if (!anOtherCtx.IsNull() + && anOtherCtx != aWindow->GetGlContext()) + { + aCtx = anOtherCtx; + aCtx->MakeCurrent(); + } + } + + aView->ReleaseGlResources (aCtx); + if (myMapOfView.IsEmpty()) + { + // The last view removed but some objects still present. + // Release GL resources now without object destruction. + for (NCollection_DataMap::Iterator aStructIt (myMapOfStructure); + aStructIt.More (); aStructIt.Next()) + { + OpenGl_Structure* aStruct = aStructIt.ChangeValue(); + aStruct->ReleaseGlResources (aCtx); + } + myDeviceLostFlag = !myMapOfStructure.IsEmpty(); } } // ======================================================================= -// function : SetBuffersNoSwap +// function : Window // purpose : // ======================================================================= -void OpenGl_GraphicDriver::SetBuffersNoSwap (const Standard_Boolean theIsNoSwap) +Handle(OpenGl_Window) OpenGl_GraphicDriver::CreateRenderWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext) { - myCaps->buffersNoSwap = theIsNoSwap; + Handle(OpenGl_Context) aShareCtx = GetSharedContext(); + Handle(OpenGl_Window) aWindow = new OpenGl_Window (this, theWindow, theContext, myCaps, aShareCtx); + return aWindow; } -// ======================================================================= -// function : TextSize -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::TextSize (const Standard_CString theText, - const Standard_ShortReal theHeight, - Standard_ShortReal& theWidth, - Standard_ShortReal& theAscent, - Standard_ShortReal& theDescent) const +//======================================================================= +//function : ViewExists +//purpose : +//======================================================================= +Standard_Boolean OpenGl_GraphicDriver::ViewExists (const Handle(Aspect_Window)& AWindow, Handle(Graphic3d_CView)& theView) { - const Handle(OpenGl_Context)& aCtx = GetSharedContext(); - if (aCtx.IsNull()) + Standard_Boolean isExist = Standard_False; + + // Parse the list of views to find + // a view with the specified window + +#if defined(_WIN32) + const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow); + Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow (); +#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) + const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow); + #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE + UIView* TheSpecifiedWindowId = THEWindow->HView(); + #else + NSView* TheSpecifiedWindowId = THEWindow->HView(); + #endif +#elif defined(__ANDROID__) + int TheSpecifiedWindowId = -1; +#else + const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow); + int TheSpecifiedWindowId = int (THEWindow->XWindow ()); +#endif + + NCollection_Map::Iterator aViewIt (myMapOfView); + for(; aViewIt.More(); aViewIt.Next()) { - return; + const Handle(OpenGl_View)& aView = aViewIt.Value(); + if (aView->IsDefined() && aView->IsActive()) + { + const Handle(Aspect_Window) AspectWindow = aView->Window(); + +#if defined(_WIN32) + const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow); + Aspect_Handle TheWindowIdOfView = theWindow->HWindow (); +#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) + const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow); + #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE + UIView* TheWindowIdOfView = theWindow->HView(); + #else + NSView* TheWindowIdOfView = theWindow->HView(); + #endif +#elif defined(__ANDROID__) + int TheWindowIdOfView = 0; +#else + const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow); + int TheWindowIdOfView = int (theWindow->XWindow ()); +#endif // WNT + // Comparaison on window IDs + if (TheWindowIdOfView == TheSpecifiedWindowId) + { + isExist = Standard_True; + theView = aView; + } + } } - const Standard_ShortReal aHeight = (theHeight < 2.0f) ? DefaultTextHeight() : theHeight; - OpenGl_TextParam aTextParam; - aTextParam.Height = (int )aHeight; - OpenGl_AspectText aTextAspect; - CALL_DEF_CONTEXTTEXT aDefaultContextText = - { - 1, //IsDef - 1, //IsSet - "Courier", //Font - 0.3F, //Space - 1.F, //Expan - { 1.F, 1.F, 1.F }, //Color - (int)Aspect_TOST_NORMAL, //Style - (int)Aspect_TODT_NORMAL, //DisplayType - { 1.F, 1.F, 1.F }, //ColorSubTitle - 0, //TextZoomable - 0.F, //TextAngle - (int)Font_FA_Regular //TextFontAspect - }; - aTextAspect.SetAspect(aDefaultContextText); - TCollection_ExtendedString anExtText = theText; - NCollection_String aText = (Standard_Utf16Char* )anExtText.ToExtString(); - OpenGl_Text::StringSize (aCtx, aText, aTextAspect, aTextParam, theWidth, theAscent, theDescent); + return isExist; } diff --git a/src/OpenGl/OpenGl_GraphicDriver.hxx b/src/OpenGl/OpenGl_GraphicDriver.hxx index 7308ec5716..b92e9e3f60 100644 --- a/src/OpenGl/OpenGl_GraphicDriver.hxx +++ b/src/OpenGl/OpenGl_GraphicDriver.hxx @@ -17,15 +17,6 @@ #define _OpenGl_GraphicDriver_HeaderFile #include -#include -#include - -#include - -#include -#include -#include -#include #include #include @@ -35,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -51,12 +43,18 @@ #include #include #include - +#include +#include +#include +#include +#include #include -#include #include #include +#include +#include +class Aspect_Window; class Graphic3d_Vector; class Quantity_Color; class Graphic3d_Vertex; @@ -66,6 +64,7 @@ class OpenGl_Element; class OpenGl_Structure; class OpenGl_Text; class OpenGl_View; +class OpenGl_Window; //! Tool class to implement consistent state counter //! for objects inside the same driver instance. @@ -83,6 +82,7 @@ private: }; class OpenGl_GraphicDriver; + DEFINE_STANDARD_HANDLE(OpenGl_GraphicDriver,Graphic3d_GraphicDriver) //! This class defines an OpenGl graphic driver @@ -118,159 +118,49 @@ public: Standard_EXPORT Standard_Integer InquireLightLimit (); Standard_EXPORT Standard_Integer InquireViewLimit (); -public: // Methods for graphical structures +public: - Standard_EXPORT void DisplayStructure (const Graphic3d_CView& theCView, - const Handle(Graphic3d_Structure)& theStructure, - const Standard_Integer thePriority); - Standard_EXPORT void EraseStructure (const Graphic3d_CView& theCView, - const Handle(Graphic3d_Structure)& theStructure); - Standard_EXPORT void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure); - Standard_EXPORT Handle(Graphic3d_CStructure) Structure (const Handle(Graphic3d_StructureManager)& theManager); + Standard_EXPORT virtual Handle(Graphic3d_CStructure) CreateStructure (const Handle(Graphic3d_StructureManager)& theManager) Standard_OVERRIDE; - Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Graphic3d_CView& theCView, - const Standard_Boolean theDrawToFrontBuffer); + Standard_EXPORT virtual void RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) Standard_OVERRIDE; -public: + Standard_EXPORT virtual Handle(Graphic3d_CView) CreateView (const Handle(Graphic3d_StructureManager)& theMgr) Standard_OVERRIDE; - Standard_EXPORT void ActivateView (const Graphic3d_CView& ACView); - Standard_EXPORT void AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag); - Standard_EXPORT void Background (const Graphic3d_CView& ACView); - Standard_EXPORT void GradientBackground (const Graphic3d_CView& ACView, const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod FillStyle); - Standard_EXPORT void BackgroundImage (const Standard_CString FileName, const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle); - Standard_EXPORT void SetBgImageStyle (const Graphic3d_CView& ACView, const Aspect_FillMethod FillStyle); - Standard_EXPORT void SetBgGradientStyle (const Graphic3d_CView& ACView, const Aspect_GradientFillMethod FillStyle); - Standard_EXPORT void ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait); - Standard_EXPORT void DeactivateView (const Graphic3d_CView& ACView); - Standard_EXPORT void DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag); - Standard_EXPORT void RatioWindow (const Graphic3d_CView& ACView); - Standard_EXPORT void Redraw (const Graphic3d_CView& theCView, - const Standard_Integer theX = 0, - const Standard_Integer theY = 0, - const Standard_Integer theWidth = 0, - const Standard_Integer theHeight = 0); - Standard_EXPORT void RedrawImmediate (const Graphic3d_CView& theCView); - Standard_EXPORT void Invalidate (const Graphic3d_CView& theCView); - Standard_EXPORT Standard_Boolean IsInvalidated (const Graphic3d_CView& theCView) const; - Standard_EXPORT void RemoveView (const Graphic3d_CView& ACView); - Standard_EXPORT void SetLight (const Graphic3d_CView& ACView); - Standard_EXPORT void SetClipPlanes (const Graphic3d_CView& theCView); - Standard_EXPORT void SetCamera (const Graphic3d_CView& theCView); - Standard_EXPORT void SetVisualisation (const Graphic3d_CView& ACView); - Standard_EXPORT Standard_Boolean View (Graphic3d_CView& ACView); - Standard_EXPORT void Environment (const Graphic3d_CView& ACView); - Standard_EXPORT void ZBufferTriedronSetup (const Graphic3d_CView& theCView, - const Quantity_NameOfColor XColor = Quantity_NOC_RED, - const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, - const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, - const Standard_Real SizeRatio = 0.8, - const Standard_Real AxisDiametr = 0.05, - const Standard_Integer NbFacettes = 12); - Standard_EXPORT void TriedronDisplay (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const Standard_Boolean AsWireframe = Standard_True); - Standard_EXPORT void TriedronErase (const Graphic3d_CView& ACView); - Standard_EXPORT void TriedronEcho (const Graphic3d_CView& ACView, const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE); - - //! Displays Graduated trihedron - //! @param theView [in] the graphic view - //! @param theCubic [in] Graduated Trihedon parameters. - //! @sa OpenGl_GraduatedTrihedron - //! @sa Graphic3d_GraduatedTrihedron - Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_CView& theView, const Graphic3d_GraduatedTrihedron& theCubic); - - //! Erases Graduated Trihedron from the view. - //! theView [in] graphic view - //! @sa OpenGl_GraduatedTrihedron - Standard_EXPORT void GraduatedTrihedronErase (const Graphic3d_CView& theView); - - //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron - //! stored in graphic view object. - //! @param theView [in] current graphic view - //! @param theMin [in] the minimum point of scene. - //! @param theMax [in] the maximum point of scene. - //! @sa OpenGl_GraduatedTrihedron - Standard_EXPORT void GraduatedTrihedronMinMaxValues (const Graphic3d_CView& theView, - const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax); + Standard_EXPORT virtual void RemoveView (const Handle(Graphic3d_CView)& theView) Standard_OVERRIDE; + + Standard_EXPORT virtual Handle(OpenGl_Window) CreateRenderWindow (const Handle(Aspect_Window)& theWindow, const Aspect_RenderingContext theContext); + +public: Standard_EXPORT void TextSize (const Standard_CString AText,const Standard_ShortReal AHeight,Standard_ShortReal& AWidth,Standard_ShortReal& AnAscent,Standard_ShortReal& ADescent) const; - Standard_EXPORT void SetBackFacingModel (const Graphic3d_CView& aView); - - //! Print the contents of all layers of the view to the printer. - //! @param thePrinterDC pass the PrinterDeviceContext (HDC) - //! @param theToShowBackground when set to FALSE then print the view without background color (background is white) else set to TRUE for printing with current background color - //! @param theFileName if != NULL, then the view will be printed to a file - //! @param thePrintAlgorithm select print algorithm: stretch, tile - //! @param theScaleFactor scaling coefficient, used internally to scale the printings accordingly to the scale factor selected in the printer properties dialog - //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if the print operation failed due to the printer errors, - //! or lack of system memory. This might be related to insufficient memory or some internal errors. - //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver). - //! Warning: This function can reuse FBO assigned to the view, please take it into account if you use it for your purposes. - Standard_EXPORT Standard_Boolean Print (const Graphic3d_CView& theCView, - const Aspect_Handle thePrinterDC, - const Standard_Boolean theToShowBackground, - const Standard_CString theFileName, - const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH, - const Standard_Real theScaleFactor = 1.0) const; - - //! Reads depths of shown pixels of the given rectangle (glReadPixels with GL_DEPTH_COMPONENT) - Standard_EXPORT void ReadDepths (const Graphic3d_CView& view,const Standard_Integer x,const Standard_Integer y,const Standard_Integer width,const Standard_Integer height,const Standard_Address buffer) const; - - //! Generate offscreen FBO (needs OpenGL2+ hardware). - //! If not supported on hardware returns NULL. - Standard_EXPORT Graphic3d_PtrFrameBuffer FBOCreate (const Graphic3d_CView& view, const Standard_Integer width, const Standard_Integer height); - - //! Remove offscreen FBO - Standard_EXPORT void FBORelease (const Graphic3d_CView& view, Graphic3d_PtrFrameBuffer& fboPtr); - - //! Dump active rendering buffer into specified memory buffer. - Standard_EXPORT Standard_Boolean BufferDump (const Graphic3d_CView& theCView, - Image_PixMap& theImage, - const Graphic3d_BufferType& theBufferType); - - Standard_EXPORT void SetGLLightEnabled (const Graphic3d_CView& view,const Standard_Boolean isEnabled) const; - - Standard_EXPORT Standard_Boolean IsGLLightEnabled (const Graphic3d_CView& view) const; Standard_EXPORT Standard_Integer InquirePlaneLimit(); Standard_EXPORT Standard_ShortReal DefaultTextHeight() const; - Standard_EXPORT void FBOGetDimensions(const Graphic3d_CView& view,const Graphic3d_PtrFrameBuffer fboPtr,Standard_Integer& width,Standard_Integer& height,Standard_Integer& widthMax,Standard_Integer& heightMax); + Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& theWindow, Handle(Graphic3d_CView)& theView) Standard_OVERRIDE; - Standard_EXPORT void FBOChangeViewport(const Graphic3d_CView& view,Graphic3d_PtrFrameBuffer& fboPtr,const Standard_Integer width,const Standard_Integer height); - - Standard_EXPORT Standard_Boolean Export(const Standard_CString theFileName,const Graphic3d_ExportFormat theFormat,const Graphic3d_SortType theSortType,const Standard_Integer theWidth,const Standard_Integer theHeight,const Graphic3d_CView& theView,const Standard_Real thePrecision = 0.005,const Standard_Address theProgressBarFunc = NULL,const Standard_Address theProgressObject = NULL); - - //! Add a new top-level z layer with ID theLayerId for the view. Z layers allow drawing structures in higher layers in foreground of structures in lower layers. - //! To add a structure to desired layer on display it is necessary to set the layer index for the structure. - Standard_EXPORT void AddZLayer (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId); +public: - //! Remove Z layer from the specified view. - //! All structures displayed at the moment in layer will be displayed in default layer (the bottom-level z layer). - //! To unset layer index from associated structures use method UnsetZLayer (...). - Standard_EXPORT void RemoveZLayer (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId); + //! Adds a new top-level z layer with ID theLayerId for all views. Z layers allow drawing structures in higher layers + //! in foreground of structures in lower layers. To add a structure to desired layer on display it is necessary to + //! set the layer index for the structure. The passed theLayerId should be not less than 0 (reserved for default layers). + Standard_EXPORT void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - //! Unset Z layer ID for all structures. - //! The structure indexes will be set to default layer (the bottom-level z layer with ID = 0). - Standard_EXPORT void UnsetZLayer (const Graphic3d_ZLayerId theLayerId); + //! Removes Z layer. All structures displayed at the moment in layer will be displayed in + //! default layer (the bottom-level z layer). By default, there are always default + //! bottom-level layer that can't be removed. The passed theLayerId should be not less than 0 + //! (reserved for default layers that can not be removed). + Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - //! Change Z layer of a structure already presented in view. - //! It is recommended to update z layer of already displayed structures with this method before setting new z layer index to the structure. - //! This is usually done by viewer manager. - Standard_EXPORT void ChangeZLayer (const Graphic3d_CStructure& theCStructure, - const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theNewLayerId); + //! Returns list of Z layers defined for the graphical driver. + Standard_EXPORT void ZLayers (TColStd_SequenceOfInteger& theLayerSeq) const Standard_OVERRIDE; - //! Sets the settings for a single Z layer of specified view. - Standard_EXPORT void SetZLayerSettings (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings); + //! Sets the settings for a single Z layer. + Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE; - //! Changes priority of a structure within its Z layer for the specified view. - Standard_EXPORT void ChangePriority (const Graphic3d_CStructure& theCStructure, - const Graphic3d_CView& theCView, - const Standard_Integer theNewPriority); + //! Returns the settings of a single Z layer. + Standard_EXPORT virtual Graphic3d_ZLayerSettings ZLayerSettings (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; public: @@ -311,10 +201,6 @@ public: //! Could return NULL-handle if no window created by this driver. Standard_EXPORT const Handle(OpenGl_Context)& GetSharedContext() const; - //! Marks BVH tree for given priority list as dirty and - //! marks primitive set for rebuild. - Standard_EXPORT void InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId); - #if defined(HAVE_EGL) || defined(__ANDROID__) Aspect_Display getRawGlDisplay() const { return myEglDisplay; } Aspect_RenderingContext getRawGlContext() const { return myEglContext; } @@ -336,11 +222,15 @@ protected: Handle(OpenGl_Caps) myCaps; NCollection_Map myMapOfView; - NCollection_Map myMapOfWS; NCollection_DataMap myMapOfStructure; - mutable Handle(OpenGl_PrinterContext) myPrintContext; OpenGl_UserDrawCallback_t myUserDrawCallback; +public: + + TColStd_MapOfInteger myLayerIds; + TColStd_SequenceOfInteger myLayerSeq; + OpenGl_MapOfZLayerSettings myMapOfZLayerSettings; + public: //! State counter for OpenGl structures. diff --git a/src/OpenGl/OpenGl_GraphicDriver_4.cxx b/src/OpenGl/OpenGl_GraphicDriver_4.cxx deleted file mode 100644 index cc021b0655..0000000000 --- a/src/OpenGl/OpenGl_GraphicDriver_4.cxx +++ /dev/null @@ -1,114 +0,0 @@ -// Created on: 2011-10-20 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include -#include - -void OpenGl_GraphicDriver::DisplayStructure (const Graphic3d_CView& theCView, - const Handle(Graphic3d_Structure)& theStructure, - const Standard_Integer thePriority) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView == NULL) - return; - - aCView->View->DisplayStructure (theStructure, thePriority); -} - -void OpenGl_GraphicDriver::EraseStructure (const Graphic3d_CView& theCView, - const Handle(Graphic3d_Structure)& theStructure) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView == NULL) - return; - - aCView->View->EraseStructure (theStructure); -} - -void OpenGl_GraphicDriver::RemoveStructure (Handle(Graphic3d_CStructure)& theCStructure) -{ - OpenGl_Structure* aStructure = NULL; - if (!myMapOfStructure.Find (theCStructure->Id, aStructure)) - { - return; - } - - myMapOfStructure.UnBind (theCStructure->Id); - aStructure->Release (GetSharedContext()); - theCStructure.Nullify(); -} - -Handle(Graphic3d_CStructure) OpenGl_GraphicDriver::Structure (const Handle(Graphic3d_StructureManager)& theManager) -{ - Handle(OpenGl_Structure) aStructure = new OpenGl_Structure (theManager); - myMapOfStructure.Bind (aStructure->Id, aStructure.operator->()); - return aStructure; -} - -//======================================================================= -//function : ChangeZLayer -//purpose : -//======================================================================= - -void OpenGl_GraphicDriver::ChangeZLayer (const Graphic3d_CStructure& theCStructure, - const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theNewLayerId) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; - - if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView) - return; - - OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); - - aCView->View->ChangeZLayer (aStructure, theNewLayerId); -} - -//======================================================================= -//function : UnsetZLayer -//purpose : -//======================================================================= - -void OpenGl_GraphicDriver::UnsetZLayer (const Graphic3d_ZLayerId theLayerId) -{ - NCollection_DataMap::Iterator aStructIt (myMapOfStructure); - for( ; aStructIt.More (); aStructIt.Next ()) - { - OpenGl_Structure* aStruct = aStructIt.ChangeValue (); - if (aStruct->ZLayer() == theLayerId) - aStruct->SetZLayer (Graphic3d_ZLayerId_Default); - } -} - -//======================================================================= -//function : ChangePriority -//purpose : -//======================================================================= -void OpenGl_GraphicDriver::ChangePriority (const Graphic3d_CStructure& theCStructure, - const Graphic3d_CView& theCView, - const Standard_Integer theNewPriority) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; - - if (!myMapOfStructure.IsBound (theCStructure.Id) || !aCView) - return; - - OpenGl_Structure* aStructure = myMapOfStructure.Find (theCStructure.Id); - - aCView->View->ChangePriority (aStructure, theNewPriority); -} diff --git a/src/OpenGl/OpenGl_GraphicDriver_7.cxx b/src/OpenGl/OpenGl_GraphicDriver_7.cxx deleted file mode 100644 index 7f1c6be869..0000000000 --- a/src/OpenGl/OpenGl_GraphicDriver_7.cxx +++ /dev/null @@ -1,599 +0,0 @@ -// Created on: 2011-10-20 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include - -#include -#include -#include - -/*----------------------------------------------------------------------*/ - -void OpenGl_GraphicDriver::ActivateView (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->WS->SetActiveView(aCView->View, ACView.ViewId); -} - -void OpenGl_GraphicDriver::AntiAliasing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->View->SetAntiAliasing(AFlag); -} - -void OpenGl_GraphicDriver::Background (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - aCView->WS->SetBackgroundColor(ACView.DefWindow.Background.r,ACView.DefWindow.Background.g,ACView.DefWindow.Background.b); - } -} - -void OpenGl_GraphicDriver::GradientBackground (const Graphic3d_CView& ACView, - const Quantity_Color& AColor1, - const Quantity_Color& AColor2, - const Aspect_GradientFillMethod AType) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - aCView->View->SetBackgroundGradient(AColor1,AColor2,AType); - } -} - -void OpenGl_GraphicDriver::ClipLimit (const Graphic3d_CView& ACView, const Standard_Boolean AWait) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - aCView->View->SetClipLimit(ACView); - if (!AWait) - { - aCView->WS->Resize(ACView.DefWindow); - } - } -} - -void OpenGl_GraphicDriver::DeactivateView (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - const Handle(OpenGl_View) aDummyView; - aCView->WS->SetActiveView (aDummyView, -1); - } -} - -void OpenGl_GraphicDriver::DepthCueing (const Graphic3d_CView& ACView, const Standard_Boolean AFlag) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->View->SetFog(ACView, AFlag); -} - -void OpenGl_GraphicDriver::RatioWindow (const Graphic3d_CView& theCView) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - aCView->WS->Resize (theCView.DefWindow); -} - -void OpenGl_GraphicDriver::Redraw (const Graphic3d_CView& ACView, - const Standard_Integer /*x*/, - const Standard_Integer /*y*/, - const Standard_Integer /*width*/, - const Standard_Integer /*height*/) -{ - if (ACView.RenderParams.Method == Graphic3d_RM_RAYTRACING - && !myCaps->vboDisable - && !myCaps->keepArrayData) - { - if (ACView.WasRedrawnGL) - { - myDeviceLostFlag = Standard_True; - } - - myCaps->keepArrayData = Standard_True; - } - - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - /*if( width <= 0 || height <= 0 ) - aCView->WS->Redraw(ACView, ACUnderLayer, ACOverLayer); - else - aCView->WS->RedrawArea(ACView, ACUnderLayer, ACOverLayer, x, y, width, height);*/ - // Always do full redraw - aCView->WS->Redraw(ACView); - } -} - -void OpenGl_GraphicDriver::RedrawImmediate (const Graphic3d_CView& theCView) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - { - aCView->WS->RedrawImmediate (theCView); - } -} - -void OpenGl_GraphicDriver::Invalidate (const Graphic3d_CView& theCView) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView != NULL) - { - aCView->WS->Invalidate(); - } -} - -Standard_Boolean OpenGl_GraphicDriver::IsInvalidated (const Graphic3d_CView& theCView) const -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - return aCView == NULL - || aCView->WS->IsInvalidated(); -} - -Graphic3d_PtrFrameBuffer OpenGl_GraphicDriver::FBOCreate (const Graphic3d_CView& ACView, const Standard_Integer theWidth, const Standard_Integer theHeight) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - return aCView->WS->FBOCreate(theWidth, theHeight); - return (Graphic3d_PtrFrameBuffer)NULL; -} - -Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, - const Standard_Integer theHeight) -{ - // activate OpenGL context - if (!Activate()) - return NULL; - - // create the FBO - const Handle(OpenGl_Context)& aCtx = GetGlContext(); - OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer(); - if (!aFrameBuffer->Init (aCtx, theWidth, theHeight)) - { - aFrameBuffer->Release (aCtx.operator->()); - delete aFrameBuffer; - return NULL; - } - return (Graphic3d_PtrFrameBuffer )aFrameBuffer; -} - -void OpenGl_GraphicDriver::FBORelease (const Graphic3d_CView& ACView, Graphic3d_PtrFrameBuffer& theFBOPtr) -{ - if (theFBOPtr == NULL) - return; - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - aCView->WS->FBORelease(theFBOPtr); - theFBOPtr = NULL; - } -} - -void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr) -{ - // activate OpenGL context - if (!Activate() - || theFBOPtr == NULL) - { - return; - } - - // release the object - OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr; - if (aFrameBuffer != NULL) - { - aFrameBuffer->Release (GetGlContext().operator->()); - } - delete aFrameBuffer; -} - -void OpenGl_GraphicDriver::FBOGetDimensions (const Graphic3d_CView& , - const Graphic3d_PtrFrameBuffer theFBOPtr, - Standard_Integer& theWidth, Standard_Integer& theHeight, - Standard_Integer& theWidthMax, Standard_Integer& theHeightMax) -{ - if (theFBOPtr == NULL) - { - return; - } - const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr; - theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size - theHeight = aFrameBuffer->GetVPSizeY(); - theWidthMax = aFrameBuffer->GetSizeX(); // texture size - theHeightMax = aFrameBuffer->GetSizeY(); -} - -void OpenGl_GraphicDriver::FBOChangeViewport (const Graphic3d_CView& , - Graphic3d_PtrFrameBuffer& theFBOPtr, - const Standard_Integer theWidth, const Standard_Integer theHeight) -{ - if (theFBOPtr == NULL) - { - return; - } - OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr; - aFrameBuffer->ChangeViewport (theWidth, theHeight); -} - -inline bool getDataFormat (const Image_PixMap& theData, - GLenum& thePixelFormat, - GLenum& theDataType) -{ - thePixelFormat = GL_RGB; - theDataType = GL_UNSIGNED_BYTE; - switch (theData.Format()) - { - #if !defined(GL_ES_VERSION_2_0) - case Image_PixMap::ImgGray: - thePixelFormat = GL_DEPTH_COMPONENT; - theDataType = GL_UNSIGNED_BYTE; - return true; - case Image_PixMap::ImgGrayF: - thePixelFormat = GL_DEPTH_COMPONENT; - theDataType = GL_FLOAT; - return true; - case Image_PixMap::ImgBGR: - thePixelFormat = GL_BGR; - theDataType = GL_UNSIGNED_BYTE; - return true; - case Image_PixMap::ImgBGRA: - case Image_PixMap::ImgBGR32: - thePixelFormat = GL_BGRA; - theDataType = GL_UNSIGNED_BYTE; - return true; - case Image_PixMap::ImgBGRF: - thePixelFormat = GL_BGR; - theDataType = GL_FLOAT; - return true; - case Image_PixMap::ImgBGRAF: - thePixelFormat = GL_BGRA; - theDataType = GL_FLOAT; - return true; - #else - case Image_PixMap::ImgGray: - case Image_PixMap::ImgGrayF: - case Image_PixMap::ImgBGR: - case Image_PixMap::ImgBGRA: - case Image_PixMap::ImgBGR32: - case Image_PixMap::ImgBGRF: - case Image_PixMap::ImgBGRAF: - return false; - #endif - case Image_PixMap::ImgRGB: - thePixelFormat = GL_RGB; - theDataType = GL_UNSIGNED_BYTE; - return true; - case Image_PixMap::ImgRGBA: - case Image_PixMap::ImgRGB32: - thePixelFormat = GL_RGBA; - theDataType = GL_UNSIGNED_BYTE; - return true; - case Image_PixMap::ImgRGBF: - thePixelFormat = GL_RGB; - theDataType = GL_FLOAT; - return true; - case Image_PixMap::ImgRGBAF: - thePixelFormat = GL_RGBA; - theDataType = GL_FLOAT; - return true; - case Image_PixMap::ImgAlpha: - case Image_PixMap::ImgAlphaF: - return false; // GL_ALPHA is no more supported in core context - case Image_PixMap::ImgUNKNOWN: - return false; - } - return false; -} - -Standard_Boolean OpenGl_GraphicDriver::BufferDump (const Graphic3d_CView& theCView, - Image_PixMap& theImage, - const Graphic3d_BufferType& theBufferType) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - return (aCView != NULL) && aCView->WS->BufferDump ((OpenGl_FrameBuffer* )theCView.ptrFBO, theImage, theBufferType); -} - -//! Compute aligned number greater or equal to specified one -inline Standard_Size getAligned (const Standard_Size theNumber, - const Standard_Size theAlignment) -{ - return theNumber + theAlignment - 1 - (theNumber - 1) % theAlignment; -} - -Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr, - Image_PixMap& theImage, - const Graphic3d_BufferType& theBufferType) -{ - GLenum aFormat, aType; - if (theImage.IsEmpty() - || !getDataFormat (theImage, aFormat, aType) - || !Activate()) - { - return Standard_False; - } -#if !defined(GL_ES_VERSION_2_0) - GLint aReadBufferPrev = GL_BACK; - if (theBufferType == Graphic3d_BT_Depth - && aFormat != GL_DEPTH_COMPONENT) - { - return Standard_False; - } -#endif - - // bind FBO if used - if (theFBOPtr != NULL && theFBOPtr->IsValid()) - { - theFBOPtr->BindBuffer (GetGlContext()); - } - else - { - #if !defined(GL_ES_VERSION_2_0) - glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev); - GLint aDrawBufferPrev = GL_BACK; - glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev); - glReadBuffer (aDrawBufferPrev); - #endif - } - - // setup alignment - const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL - glPixelStorei (GL_PACK_ALIGNMENT, anAligment); - bool isBatchCopy = !theImage.IsTopDown(); - - const GLint anExtraBytes = GLint(theImage.RowExtraBytes()); - GLint aPixelsWidth = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes()); - Standard_Size aSizeRowBytesEstim = getAligned (theImage.SizePixelBytes() * aPixelsWidth, anAligment); - if (anExtraBytes < anAligment) - { - aPixelsWidth = 0; - } - else if (aSizeRowBytesEstim != theImage.SizeRowBytes()) - { - aPixelsWidth = 0; - isBatchCopy = false; - } -#if !defined(GL_ES_VERSION_2_0) - glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth); -#else - if (aPixelsWidth != 0) - { - isBatchCopy = false; - } -#endif - - if (!isBatchCopy) - { - // copy row by row - for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) - { - // Image_PixMap rows indexation always starts from the upper corner - // while order in memory depends on the flag and processed by ChangeRow() method - glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow)); - } - } - else - { - glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData()); - } - - glPixelStorei (GL_PACK_ALIGNMENT, 1); -#if !defined(GL_ES_VERSION_2_0) - glPixelStorei (GL_PACK_ROW_LENGTH, 0); -#endif - - if (theFBOPtr != NULL && theFBOPtr->IsValid()) - { - theFBOPtr->UnbindBuffer (GetGlContext()); - } - else - { - #if !defined(GL_ES_VERSION_2_0) - glReadBuffer (aReadBufferPrev); - #endif - } - return Standard_True; -} - -void OpenGl_GraphicDriver::RemoveView (const Graphic3d_CView& theCView) -{ - Handle(OpenGl_Context) aCtx = GetSharedContext(); - OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; - if (aCView == NULL - || aCView->View.IsNull() - || aCView->WS.IsNull()) - { - return; - } - - Handle(OpenGl_View) aView = aCView->View; - Handle(OpenGl_Workspace) aWindow = aCView->WS; - if (!myMapOfWS .Remove (aWindow) - || !myMapOfView.Remove (aView)) - { - return; - } - - if (aWindow->GetGlContext()->MakeCurrent()) - { - aCtx = aWindow->GetGlContext(); - } - else - { - // try to hijack another context if any - const Handle(OpenGl_Context)& anOtherCtx = GetSharedContext(); - if (!anOtherCtx.IsNull() - && anOtherCtx != aWindow->GetGlContext()) - { - aCtx = anOtherCtx; - aCtx->MakeCurrent(); - } - } - - aView->ReleaseGlResources (aCtx); - if (myMapOfWS.IsEmpty()) - { - // The last view removed but some objects still present. - // Release GL resources now without object destruction. - for (NCollection_DataMap::Iterator aStructIt (myMapOfStructure); - aStructIt.More (); aStructIt.Next()) - { - OpenGl_Structure* aStruct = aStructIt.ChangeValue(); - aStruct->ReleaseGlResources (aCtx); - } - myDeviceLostFlag = !myMapOfStructure.IsEmpty(); - } - - delete aCView; - ((Graphic3d_CView *)&theCView)->ptrView = NULL; - - aCtx.Nullify(); - aView.Nullify(); - aWindow.Nullify(); -} - -void OpenGl_GraphicDriver::SetLight (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->View->SetLights(ACView.Context); -} - -void OpenGl_GraphicDriver::SetClipPlanes (const Graphic3d_CView& theCView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; - if (aCView) - { - aCView->View->SetClipPlanes (theCView.Context.ClipPlanes); - } -} - -//======================================================================= -//function : SetCamera -//purpose : -//======================================================================= -void OpenGl_GraphicDriver::SetCamera (const Graphic3d_CView& theCView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; - if (aCView) - { - aCView->View->SetCamera (theCView.Context.Camera); - } -} - -void OpenGl_GraphicDriver::SetVisualisation (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - { - aCView->View->SetVisualisation(ACView.Context); - } -} - -// ======================================================================= -// function : InvalidateBVHData -// purpose : -// ======================================================================= -void OpenGl_GraphicDriver::InvalidateBVHData (Graphic3d_CView& theCView, const Standard_Integer theLayerId) -{ - OpenGl_CView *aCView = (OpenGl_CView *)theCView.ptrView; - if(aCView) - { - aCView->View->InvalidateBVHData (theLayerId); - } -} - -Standard_Boolean OpenGl_GraphicDriver::View (Graphic3d_CView& theCView) -{ - Handle(OpenGl_Context) aShareCtx = GetSharedContext(); - OpenGl_CView* aCView = (OpenGl_CView* )theCView.ptrView; - if (aCView != NULL - && myMapOfView.Contains (aCView->View)) - { - Handle(OpenGl_Workspace) anOldWS = aCView->WS; - Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); - aCView->WS = aWS; - aWS->SetActiveView (aCView->View, theCView.ViewId); - - myMapOfWS.Remove (anOldWS); - myMapOfWS.Add (aWS); - return Standard_True; - } - - Handle(OpenGl_Workspace) aWS = new OpenGl_Workspace (this, theCView.DefWindow, theCView.GContext, myCaps, aShareCtx); - Handle(OpenGl_View) aView = new OpenGl_View (theCView.Context, &myStateCounter); - myMapOfWS .Add (aWS); - myMapOfView.Add (aView); - - aCView = new OpenGl_CView(); - aCView->View = aView; - aCView->WS = aWS; - theCView.ptrView = aCView; - aWS->SetActiveView (aCView->View, theCView.ViewId); - - return Standard_True; -} - -void OpenGl_GraphicDriver::SetBackFacingModel (const Graphic3d_CView& ACView) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->View->SetBackfacing(ACView.Backfacing); -} - -//======================================================================= -//function : AddZLayer -//purpose : -//======================================================================= - -void OpenGl_GraphicDriver::AddZLayer (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId) -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)theCView.ptrView; - if (aCView) - aCView->View->AddZLayer (theLayerId); -} - -//======================================================================= -//function : RemoveZLayer -//purpose : -//======================================================================= -void OpenGl_GraphicDriver::RemoveZLayer (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId) -{ - const OpenGl_CView* aCView = (const OpenGl_CView *)theCView.ptrView; - if (aCView) - aCView->View->RemoveZLayer (theLayerId); -} - -//======================================================================= -//function : SetZLayerSettings -//purpose : -//======================================================================= -Standard_EXPORT void OpenGl_GraphicDriver::SetZLayerSettings (const Graphic3d_CView& theCView, - const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings) -{ - const OpenGl_CView* aCView = (const OpenGl_CView* )theCView.ptrView; - if (aCView) - aCView->View->SetZLayerSettings (theLayerId, theSettings); -} diff --git a/src/OpenGl/OpenGl_GraphicDriver_713.cxx b/src/OpenGl/OpenGl_GraphicDriver_713.cxx deleted file mode 100644 index c9d86da885..0000000000 --- a/src/OpenGl/OpenGl_GraphicDriver_713.cxx +++ /dev/null @@ -1,48 +0,0 @@ -// Created on: 2011-10-20 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include - -#include - -void OpenGl_GraphicDriver::ReadDepths( const Graphic3d_CView& ACView, - const Standard_Integer x, - const Standard_Integer y, - const Standard_Integer width, - const Standard_Integer height, - const Standard_Address buffer ) const -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->WS->ReadDepths(x, y, width, height, (float*) buffer); -} - -void OpenGl_GraphicDriver::SetGLLightEnabled( const Graphic3d_CView& ACView, const Standard_Boolean isEnabled ) const -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - aCView->WS->UseGLLight() = isEnabled; -} - -Standard_Boolean OpenGl_GraphicDriver::IsGLLightEnabled( const Graphic3d_CView& ACView ) const -{ - const OpenGl_CView *aCView = (const OpenGl_CView *)ACView.ptrView; - if (aCView) - return aCView->WS->UseGLLight(); - return Standard_False; -} diff --git a/src/OpenGl/OpenGl_GraphicDriver_Export.cxx b/src/OpenGl/OpenGl_GraphicDriver_Export.cxx deleted file mode 100644 index 98e9727f90..0000000000 --- a/src/OpenGl/OpenGl_GraphicDriver_Export.cxx +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include -#include - -#include - -#ifdef HAVE_GL2PS -#include -#endif - -/************************************************************************/ -/* Print Methods */ -/************************************************************************/ - -#ifdef HAVE_GL2PS -Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString theFileName, - const Graphic3d_ExportFormat theFormat, - const Graphic3d_SortType theSortType, - const Standard_Integer theWidth, - const Standard_Integer theHeight, - const Graphic3d_CView& theView, - const Standard_Real /*thePrecision*/, - const Standard_Address /*theProgressBarFunc*/, - const Standard_Address /*theProgressObject*/) -{ - // gl2psBeginPage() will call OpenGL functions - // so we should activate correct GL context before redraw scene call - const OpenGl_CView* aCView = (const OpenGl_CView* )theView.ptrView; - if (aCView == NULL || !aCView->WS->GetGlContext()->MakeCurrent()) - { - return Standard_False; - } - - Standard_Integer aFormat = -1; - Standard_Integer aSortType = Graphic3d_ST_BSP_Tree; - switch (theFormat) - { - case Graphic3d_EF_PostScript: - aFormat = GL2PS_PS; - break; - case Graphic3d_EF_EnhPostScript: - aFormat = GL2PS_EPS; - break; - case Graphic3d_EF_TEX: - aFormat = GL2PS_TEX; - break; - case Graphic3d_EF_PDF: - aFormat = GL2PS_PDF; - break; - case Graphic3d_EF_SVG: - aFormat = GL2PS_SVG; - break; - case Graphic3d_EF_PGF: - aFormat = GL2PS_PGF; - break; - case Graphic3d_EF_EMF: - //aFormat = GL2PS_EMF; - aFormat = GL2PS_PGF + 1; // 6 - break; - default: - // unsupported format - return Standard_False; - } - - switch (theSortType) - { - case Graphic3d_ST_Simple: - aSortType = GL2PS_SIMPLE_SORT; - break; - case Graphic3d_ST_BSP_Tree: - aSortType = GL2PS_BSP_SORT; - break; - } - - GLint aViewport[4]; - aViewport[0] = 0; - aViewport[1] = 0; - aViewport[2] = theWidth; - aViewport[3] = theHeight; - - GLint aBufferSize = 1024 * 1024; - GLint anErrCode = GL2PS_SUCCESS; - - // gl2ps uses standard write functions and do not check locale - Standard_CLocaleSentry aLocaleSentry; - - while (aBufferSize > 0) - { - // current patch for EMF support in gl2ps uses WinAPI functions to create file - FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL; - anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType, - GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/, - GL_RGBA, 0, NULL, - 0, 0, 0, aBufferSize, aFileH, theFileName); - if (anErrCode != GL2PS_SUCCESS) - { - // initialization failed - if (aFileH != NULL) - fclose (aFileH); - break; - } - Redraw (theView); - - anErrCode = gl2psEndPage(); - if (aFileH != NULL) - fclose (aFileH); - - if (anErrCode == GL2PS_OVERFLOW) - aBufferSize *= 2; - else - break; - } - return anErrCode == GL2PS_SUCCESS; -} -#else -Standard_Boolean OpenGl_GraphicDriver::Export (const Standard_CString /*theFileName*/, - const Graphic3d_ExportFormat /*theFormat*/, - const Graphic3d_SortType /*theSortType*/, - const Standard_Integer /*theWidth*/, - const Standard_Integer /*theHeight*/, - const Graphic3d_CView& /*theView*/, - const Standard_Real /*thePrecision*/, - const Standard_Address /*theProgressBarFunc*/, - const Standard_Address /*theProgressObject*/) -{ - return Standard_False; -} -#endif diff --git a/src/OpenGl/OpenGl_Group.cxx b/src/OpenGl/OpenGl_Group.cxx index 162f2d42a6..33868355bb 100644 --- a/src/OpenGl/OpenGl_Group.cxx +++ b/src/OpenGl/OpenGl_Group.cxx @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/src/OpenGl/OpenGl_Layer.cxx b/src/OpenGl/OpenGl_Layer.cxx index 9f142bbcf5..d902414013 100644 --- a/src/OpenGl/OpenGl_Layer.cxx +++ b/src/OpenGl/OpenGl_Layer.cxx @@ -135,7 +135,7 @@ void OpenGl_Layer::InvalidateBVHData() void OpenGl_Layer::renderAll (const Handle(OpenGl_Workspace)& theWorkspace) const { const Standard_Integer aNbPriorities = myArray.Length(); - const Standard_Integer aViewId = theWorkspace->ActiveViewId(); + const Standard_Integer aViewId = theWorkspace->View()->Identification(); for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) { const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter); @@ -189,11 +189,11 @@ void OpenGl_Layer::renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace) } } - OpenGl_BVHTreeSelector& aSelector = theWorkspace->ActiveView()->BVHTreeSelector(); + OpenGl_BVHTreeSelector& aSelector = theWorkspace->View()->BVHTreeSelector(); traverse (aSelector); const Standard_Integer aNbPriorities = myArray.Length(); - const Standard_Integer aViewId = theWorkspace->ActiveViewId(); + const Standard_Integer aViewId = theWorkspace->View()->Identification(); for (Standard_Integer aPriorityIter = 0; aPriorityIter < aNbPriorities; ++aPriorityIter) { const OpenGl_IndexedMapOfStructure& aStructures = myArray (aPriorityIter); diff --git a/src/OpenGl/OpenGl_LayerList.cxx b/src/OpenGl/OpenGl_LayerList.cxx index 6b1c11d650..dfa89b5353 100644 --- a/src/OpenGl/OpenGl_LayerList.cxx +++ b/src/OpenGl/OpenGl_LayerList.cxx @@ -160,10 +160,9 @@ void OpenGl_LayerList::AddStructure (const OpenGl_Structure* theStruct, //purpose : //======================================================================= -void OpenGl_LayerList::RemoveStructure (const Handle(Graphic3d_Structure)& theStructure) +void OpenGl_LayerList::RemoveStructure (const OpenGl_Structure* theStructure) { - const OpenGl_Structure* aStruct = reinterpret_cast (theStructure->CStructure().operator->()); - const Graphic3d_ZLayerId aLayerId = aStruct->ZLayer(); + const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer(); Standard_Integer aSeqPos = myLayers.Lower(); myLayerIds.Find (aLayerId, aSeqPos); @@ -174,7 +173,7 @@ void OpenGl_LayerList::RemoveStructure (const Handle(Graphic3d_Structure)& theSt // remove structure from associated list // if the structure is not found there, // scan through layers and remove it - if (aLayer.Remove (aStruct, aPriority)) + if (aLayer.Remove (theStructure, aPriority)) { --myNbStructures; if (aLayer.LayerSettings().IsImmediate) @@ -182,7 +181,7 @@ void OpenGl_LayerList::RemoveStructure (const Handle(Graphic3d_Structure)& theSt --myImmediateNbStructures; } - if (aStruct->IsRaytracable()) + if (theStructure->IsRaytracable()) { ++myModificationState; } @@ -200,7 +199,7 @@ void OpenGl_LayerList::RemoveStructure (const Handle(Graphic3d_Structure)& theSt continue; } - if (aLayerEx.Remove (aStruct, aPriority)) + if (aLayerEx.Remove (theStructure, aPriority)) { --myNbStructures; if (aLayerEx.LayerSettings().IsImmediate) @@ -208,7 +207,7 @@ void OpenGl_LayerList::RemoveStructure (const Handle(Graphic3d_Structure)& theSt --myImmediateNbStructures; } - if (aStruct->IsRaytracable()) + if (theStructure->IsRaytracable()) { ++myModificationState; } diff --git a/src/OpenGl/OpenGl_LayerList.hxx b/src/OpenGl/OpenGl_LayerList.hxx index 41efccdcde..ec05a3ed46 100644 --- a/src/OpenGl/OpenGl_LayerList.hxx +++ b/src/OpenGl/OpenGl_LayerList.hxx @@ -63,7 +63,7 @@ public: Standard_Boolean isForChangePriority = Standard_False); //! Remove structure from structure list and return its previous priority - void RemoveStructure (const Handle(Graphic3d_Structure)& theStructure); + void RemoveStructure (const OpenGl_Structure* theStructure); //! Change structure z layer //! If the new layer is not presented, the structure will be displayed diff --git a/src/OpenGl/OpenGl_Light.hxx b/src/OpenGl/OpenGl_Light.hxx index 2c392f67fe..99319d883e 100644 --- a/src/OpenGl/OpenGl_Light.hxx +++ b/src/OpenGl/OpenGl_Light.hxx @@ -17,12 +17,27 @@ #define OpenGl_Light_Header #include -#include #include #define OpenGLMaxLights 8 -typedef Graphic3d_CLight OpenGl_Light; -typedef NCollection_List OpenGl_ListOfLight; +typedef Graphic3d_CLight OpenGl_Light; +typedef Graphic3d_ListOfCLight OpenGl_ListOfLight; + +static inline OpenGl_ListOfLight& OpenGl_NoShadingLight() +{ + static OpenGl_ListOfLight aLights; + if (aLights.IsEmpty()) + { + OpenGl_Light aLight; + aLight.Type = Graphic3d_TOLS_AMBIENT; + aLight.IsHeadlight = Standard_False; + aLight.Color.r() = 1.; + aLight.Color.g() = 1.; + aLight.Color.b() = 1.; + aLights.Append (aLight); + } + return aLights; +} #endif // OpenGl_Light_Header diff --git a/src/Visual3d/Visual3d_MapOfZLayerSettings.hxx b/src/OpenGl/OpenGl_MapOfZLayerSettings.hxx similarity index 81% rename from src/Visual3d/Visual3d_MapOfZLayerSettings.hxx rename to src/OpenGl/OpenGl_MapOfZLayerSettings.hxx index af99f593d6..09977a00e7 100644 --- a/src/Visual3d/Visual3d_MapOfZLayerSettings.hxx +++ b/src/OpenGl/OpenGl_MapOfZLayerSettings.hxx @@ -11,14 +11,14 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#ifndef _Visual3d_MapOfZLayerSettings_HeaderFile -#define _Visual3d_MapOfZLayerSettings_HeaderFile +#ifndef _OpenGl_MapOfZLayerSettings_HeaderFile +#define _OpenGl_MapOfZLayerSettings_HeaderFile #include #include #include #include -typedef NCollection_DataMap Visual3d_MapOfZLayerSettings; +typedef NCollection_DataMap OpenGl_MapOfZLayerSettings; -#endif // _Visual3d_MapOfZLayerSettings_HeaderFile +#endif // _OpenGl_MapOfZLayerSettings_HeaderFile diff --git a/src/OpenGl/OpenGl_ShaderManager.cxx b/src/OpenGl/OpenGl_ShaderManager.cxx index b8cdeb01ff..d1648192f0 100644 --- a/src/OpenGl/OpenGl_ShaderManager.cxx +++ b/src/OpenGl/OpenGl_ShaderManager.cxx @@ -206,7 +206,7 @@ const char THE_FRAG_CLIP_PLANES[] = // purpose : Creates new empty shader manager // ======================================================================= OpenGl_ShaderManager::OpenGl_ShaderManager (OpenGl_Context* theContext) -: myShadingModel (Visual3d_TOM_VERTEX), +: myShadingModel (Graphic3d_TOSM_VERTEX), myContext (theContext), myLastView (NULL) { @@ -340,7 +340,7 @@ Standard_Boolean OpenGl_ShaderManager::IsEmpty() const // ======================================================================= void OpenGl_ShaderManager::switchLightPrograms() { - TCollection_AsciiString aKey (myShadingModel == Visual3d_TOM_FRAGMENT ? "p_" : "g_"); + TCollection_AsciiString aKey (myShadingModel == Graphic3d_TOSM_FRAGMENT ? "p_" : "g_"); const OpenGl_ListOfLight* aLights = myLightSourceState.LightSources(); if (aLights != NULL) { @@ -348,15 +348,15 @@ void OpenGl_ShaderManager::switchLightPrograms() { switch (aLightIter.Value().Type) { - case Visual3d_TOLS_AMBIENT: + case Graphic3d_TOLS_AMBIENT: break; // skip ambient - case Visual3d_TOLS_DIRECTIONAL: + case Graphic3d_TOLS_DIRECTIONAL: aKey += "d"; break; - case Visual3d_TOLS_POSITIONAL: + case Graphic3d_TOLS_POSITIONAL: aKey += "p"; break; - case Visual3d_TOLS_SPOT: + case Graphic3d_TOLS_SPOT: aKey += "s"; break; } @@ -385,7 +385,7 @@ void OpenGl_ShaderManager::UpdateLightSourceStateTo (const OpenGl_ListOfLight* t // function : SetShadingModel // purpose : // ======================================================================= -void OpenGl_ShaderManager::SetShadingModel (const Visual3d_TypeOfModel theModel) +void OpenGl_ShaderManager::SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) { myShadingModel = theModel; switchLightPrograms(); @@ -530,7 +530,7 @@ void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgr for (OpenGl_ListOfLight::Iterator anIter (*myLightSourceState.LightSources()); anIter.More(); anIter.Next()) { const OpenGl_Light& aLight = anIter.Value(); - if (aLight.Type == Visual3d_TOLS_AMBIENT) + if (aLight.Type == Graphic3d_TOLS_AMBIENT) { anAmbient += aLight.Color; continue; @@ -546,10 +546,10 @@ void OpenGl_ShaderManager::PushLightSourceState (const Handle(OpenGl_ShaderProgr OpenGl_ShaderLightParameters& aLightParams = aLightParamsArray[aLightsNb]; aLightParams.Color = aLight.Color; - aLightParams.Position = aLight.Type == Visual3d_TOLS_DIRECTIONAL + aLightParams.Position = aLight.Type == Graphic3d_TOLS_DIRECTIONAL ? -aLight.Direction : aLight.Position; - if (aLight.Type == Visual3d_TOLS_SPOT) + if (aLight.Type == Graphic3d_TOLS_SPOT) { aLightParams.Direction = aLight.Direction; } @@ -826,7 +826,7 @@ const OpenGl_SurfaceDetailState& OpenGl_ShaderManager::SurfaceDetailState() cons // function : UpdateSurfaceDetailStateTo // purpose : Updates state of OCCT surface detail // ======================================================================= -void OpenGl_ShaderManager::UpdateSurfaceDetailStateTo (const Visual3d_TypeOfSurfaceDetail theDetail) +void OpenGl_ShaderManager::UpdateSurfaceDetailStateTo (const Graphic3d_TypeOfSurfaceDetail theDetail) { mySurfaceDetailState.Set (theDetail); mySurfaceDetailState.Update(); @@ -1327,7 +1327,7 @@ Standard_Boolean OpenGl_ShaderManager::prepareStdProgramFlat (Handle(OpenGl_Shad // ======================================================================= TCollection_AsciiString OpenGl_ShaderManager::stdComputeLighting (const Standard_Boolean theHasVertColor) { - bool aLightsMap[Visual3d_TOLS_SPOT + 1] = { false, false, false, false }; + bool aLightsMap[Graphic3d_TOLS_SPOT + 1] = { false, false, false, false }; TCollection_AsciiString aLightsFunc, aLightsLoop; const OpenGl_ListOfLight* aLights = myLightSourceState.LightSources(); if (aLights != NULL) @@ -1337,16 +1337,16 @@ TCollection_AsciiString OpenGl_ShaderManager::stdComputeLighting (const Standard { switch (aLightIter.Value().Type) { - case Visual3d_TOLS_AMBIENT: + case Graphic3d_TOLS_AMBIENT: --anIndex; break; // skip ambient - case Visual3d_TOLS_DIRECTIONAL: + case Graphic3d_TOLS_DIRECTIONAL: aLightsLoop = aLightsLoop + EOL" directionalLight (" + anIndex + ", theNormal, theView, theIsFront);"; break; - case Visual3d_TOLS_POSITIONAL: + case Graphic3d_TOLS_POSITIONAL: aLightsLoop = aLightsLoop + EOL" pointLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);"; break; - case Visual3d_TOLS_SPOT: + case Graphic3d_TOLS_SPOT: aLightsLoop = aLightsLoop + EOL" spotLight (" + anIndex + ", theNormal, theView, aPoint, theIsFront);"; break; } @@ -1360,10 +1360,10 @@ TCollection_AsciiString OpenGl_ShaderManager::stdComputeLighting (const Standard aTypeBit = true; switch (aLightIter.Value().Type) { - case Visual3d_TOLS_AMBIENT: break; - case Visual3d_TOLS_DIRECTIONAL: aLightsFunc += THE_FUNC_directionalLight; break; - case Visual3d_TOLS_POSITIONAL: aLightsFunc += THE_FUNC_pointLight; break; - case Visual3d_TOLS_SPOT: aLightsFunc += THE_FUNC_spotLight; break; + case Graphic3d_TOLS_AMBIENT: break; + case Graphic3d_TOLS_DIRECTIONAL: aLightsFunc += THE_FUNC_directionalLight; break; + case Graphic3d_TOLS_POSITIONAL: aLightsFunc += THE_FUNC_pointLight; break; + case Graphic3d_TOLS_SPOT: aLightsFunc += THE_FUNC_spotLight; break; } } } diff --git a/src/OpenGl/OpenGl_ShaderManager.hxx b/src/OpenGl/OpenGl_ShaderManager.hxx index f9abcf7ec6..f5e4d30052 100644 --- a/src/OpenGl/OpenGl_ShaderManager.hxx +++ b/src/OpenGl/OpenGl_ShaderManager.hxx @@ -18,6 +18,8 @@ #include #include +#include +#include #include #include @@ -29,7 +31,7 @@ #include #include #include -#include + class OpenGl_View; @@ -257,7 +259,7 @@ public: Standard_EXPORT const OpenGl_SurfaceDetailState& SurfaceDetailState() const; //! Updates state of OCCT surface detail. - Standard_EXPORT void UpdateSurfaceDetailStateTo (const Visual3d_TypeOfSurfaceDetail theDetail); + Standard_EXPORT void UpdateSurfaceDetailStateTo (const Graphic3d_TypeOfSurfaceDetail theDetail); public: @@ -272,8 +274,14 @@ public: myContext = theCtx; } + //! Returns true when provided context is the same as used one by shader manager. + bool IsSameContext (OpenGl_Context* theCtx) const + { + return myContext == theCtx; + } + //! Sets shading model. - Standard_EXPORT void SetShadingModel(const Visual3d_TypeOfModel theModel); + Standard_EXPORT void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel); //! Sets last view manger used with. //! Helps to handle matrix states in multi-view configurations. @@ -301,7 +309,7 @@ protected: { aBits |= OpenGl_PO_ClipPlanes; } - if (theEnableEnvMap && mySurfaceDetailState.Detail() == Visual3d_TOD_ENVIRONMENT) + if (theEnableEnvMap && mySurfaceDetailState.Detail() == Graphic3d_TOD_ENVIRONMENT) { // Environment map overwrites material texture aBits |= OpenGl_PO_TextureEnv; @@ -355,7 +363,7 @@ protected: Standard_Boolean prepareStdProgramLight (Handle(OpenGl_ShaderProgram)& theProgram, const Standard_Integer theBits) { - return myShadingModel == Visual3d_TOM_FRAGMENT + return myShadingModel == Graphic3d_TOSM_FRAGMENT ? prepareStdProgramPhong (theProgram, theBits) : prepareStdProgramGouraud (theProgram, theBits); } @@ -385,7 +393,7 @@ protected: protected: - Visual3d_TypeOfModel myShadingModel; //!< lighting shading model + Graphic3d_TypeOfShadingModel myShadingModel; //!< lighting shading model OpenGl_ShaderProgramList myProgramList; //!< The list of shader programs Handle(OpenGl_SetOfShaderPrograms) myLightPrograms; //!< pointer to active lighting programs matrix OpenGl_SetOfShaderPrograms myFlatPrograms; //!< programs matrix without lighting diff --git a/src/OpenGl/OpenGl_ShaderStates.hxx b/src/OpenGl/OpenGl_ShaderStates.hxx index 12e390fb39..4f8dae0742 100755 --- a/src/OpenGl/OpenGl_ShaderStates.hxx +++ b/src/OpenGl/OpenGl_ShaderStates.hxx @@ -16,12 +16,12 @@ #ifndef _OpenGl_State_HeaderFile #define _OpenGl_State_HeaderFile +#include #include #include #include #include #include -#include //! Defines interface for OpenGL state. class OpenGl_StateInterface @@ -189,21 +189,21 @@ class OpenGl_SurfaceDetailState : public OpenGl_StateInterface public: //! Creates new surface detail state. - OpenGl_SurfaceDetailState (const Visual3d_TypeOfSurfaceDetail theDetail = Visual3d_TOD_NONE) + OpenGl_SurfaceDetailState (const Graphic3d_TypeOfSurfaceDetail theDetail = Graphic3d_TOD_NONE) : myDetail (theDetail) { // } //! Sets new surface detail. - void Set (const Visual3d_TypeOfSurfaceDetail theDetail) { myDetail = theDetail; } + void Set (const Graphic3d_TypeOfSurfaceDetail theDetail) { myDetail = theDetail; } //! Returns surface detail. - const Visual3d_TypeOfSurfaceDetail Detail() const { return myDetail; } + const Graphic3d_TypeOfSurfaceDetail Detail() const { return myDetail; } private: - Visual3d_TypeOfSurfaceDetail myDetail; //!< OCCT surface detail + Graphic3d_TypeOfSurfaceDetail myDetail; //!< OCCT surface detail }; diff --git a/src/OpenGl/OpenGl_Text.cxx b/src/OpenGl/OpenGl_Text.cxx index 61462c749e..babd557c13 100644 --- a/src/OpenGl/OpenGl_Text.cxx +++ b/src/OpenGl/OpenGl_Text.cxx @@ -416,7 +416,7 @@ void OpenGl_Text::Render (const Handle(OpenGl_Workspace)& theWorkspace) const aTextAspect, aTextAspect->ShaderProgramRes (aCtx)); } - myOrientationMatrix = theWorkspace->ActiveView()->Camera()->OrientationMatrix(); + myOrientationMatrix = theWorkspace->View()->Camera()->OrientationMatrix(); myProjMatrix.Convert (aCtx->ProjectionState.Current()); // use highlight color or colors from aspect diff --git a/src/OpenGl/OpenGl_Trihedron.cxx b/src/OpenGl/OpenGl_Trihedron.cxx index 60f34bdb6d..e25d821d24 100644 --- a/src/OpenGl/OpenGl_Trihedron.cxx +++ b/src/OpenGl/OpenGl_Trihedron.cxx @@ -40,7 +40,7 @@ namespace void OpenGl_Trihedron::resetTransformations (const Handle(OpenGl_Workspace)& theWorkspace) const { const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - const Handle(OpenGl_View)& aView = theWorkspace->ActiveView(); + const OpenGl_View* aView = theWorkspace->View(); GLdouble anU = 1.0; GLdouble aV = 1.0; if (aView->Height() < aView->Width()) diff --git a/src/OpenGl/OpenGl_Trihedron.hxx b/src/OpenGl/OpenGl_Trihedron.hxx index 0bdf1d53b9..934d903fc5 100755 --- a/src/OpenGl/OpenGl_Trihedron.hxx +++ b/src/OpenGl/OpenGl_Trihedron.hxx @@ -74,7 +74,7 @@ public: protected: - //! Invalidate Primitve Arrays. + //! Invalidate Primitive Arrays. void invalidate(); void redraw(const Handle(OpenGl_Workspace)& theWorkspace) const; diff --git a/src/OpenGl/OpenGl_View.cxx b/src/OpenGl/OpenGl_View.cxx index f7f155acfa..b2f76c59a1 100644 --- a/src/OpenGl/OpenGl_View.cxx +++ b/src/OpenGl/OpenGl_View.cxx @@ -13,67 +13,109 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include #include #include #include #include #include #include -#include +#include #include +#include -#include -#include - +#ifdef HAVE_GL2PS +#include +#endif /*----------------------------------------------------------------------*/ namespace { - static const OPENGL_ZCLIP myDefaultZClip = { { Standard_True, 0.F }, { Standard_True, 1.F } }; - static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } }; + static const OPENGL_ZCLIP myDefaultZClip = { { Standard_False, 0.F }, { Standard_False, 1.F } }; + static const OPENGL_FOG myDefaultFog = { Standard_False, 0.F, 1.F, { { 0.F, 0.F, 0.F, 1.F } } }; + static const TEL_COLOUR myDefaultBg = { { 0.F, 0.F, 0.F, 1.F } }; } -/*----------------------------------------------------------------------*/ - -OpenGl_View::OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, - OpenGl_StateCounter* theCounter) -: mySurfaceDetail(Visual3d_TOD_ALL), - myBackfacing(0), - //shield_indicator = TOn, - //shield_colour = { { 0.F, 0.F, 0.F, 1.F } }, - //border_indicator = TOff, - //border_colour = { { 0.F, 0.F, 0.F, 1.F } }, - //active_status = TOn, - myZClip(myDefaultZClip), - myCamera(AContext.Camera), - myFog(myDefaultFog), - myToShowTrihedron (false), - myToShowGradTrihedron (false), - myVisualization(AContext.Visualization), - myShadingModel ((Visual3d_TypeOfModel )AContext.Model), - myAntiAliasing(Standard_False), - myWorldViewProjState(), - myStateCounter (theCounter), +// ======================================================================= +// function : Constructor +// purpose : +// ======================================================================= +OpenGl_View::OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr, + const Handle(OpenGl_GraphicDriver)& theDriver, + const Handle(OpenGl_Caps)& theCaps, + Standard_Boolean& theDeviceLostFlag, + OpenGl_StateCounter* theCounter) +: Graphic3d_CView (theMgr), + myDriver (theDriver.operator->()), + myCaps (theCaps), + myDeviceLostFlag (theDeviceLostFlag), + myWasRedrawnGL (Standard_False), + myAntiAliasing (Standard_False), + myCulling (Standard_True), + myShadingModel (Graphic3d_TOSM_FACET), + mySurfaceDetail (Graphic3d_TOD_ALL), + myBackfacing (Graphic3d_TOBM_AUTOMATIC), + myBgColor (myDefaultBg), + myFog (myDefaultFog), + myZClip (myDefaultZClip), + myCamera (new Graphic3d_Camera()), + myFBO (NULL), + myUseGLLight (Standard_True), + myToShowTrihedron (false), + myToShowGradTrihedron (false), + myStateCounter (theCounter), myLastLightSourceState (0, 0), + myFrameCounter (0), + myHasFboBlit (Standard_True), + myTransientDrawToFront (Standard_True), + myBackBufferRestored (Standard_False), + myIsImmediateDrawn (Standard_False), myTextureParams (new OpenGl_AspectFace()), myBgGradientArray (new OpenGl_BackgroundArray (Graphic3d_TOB_GRADIENT)), myBgTextureArray (new OpenGl_BackgroundArray (Graphic3d_TOB_TEXTURE)), // ray-tracing fields initialization - myRaytraceInitStatus (OpenGl_RT_NONE), - myIsRaytraceDataValid (Standard_False), + myRaytraceInitStatus (OpenGl_RT_NONE), + myIsRaytraceDataValid (Standard_False), myIsRaytraceWarnTextures (Standard_False), myToUpdateEnvironmentMap (Standard_False), myLayerListState (0) { - myCurrLightSourceState = myStateCounter->Increment(); -} + myWorkspace = new OpenGl_Workspace (this, NULL); -/*----------------------------------------------------------------------*/ + // AA mode + const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE"); + if (anAaEnv != NULL) + { + int v; + if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasing = v; + } + + myCurrLightSourceState = myStateCounter->Increment(); + myMainSceneFbos[0] = new OpenGl_FrameBuffer(); + myMainSceneFbos[1] = new OpenGl_FrameBuffer(); + myImmediateSceneFbos[0] = new OpenGl_FrameBuffer(); + myImmediateSceneFbos[1] = new OpenGl_FrameBuffer(); + myDisplayCallback.Func = NULL; + myDisplayCallback.Data = NULL; +} + +// ======================================================================= +// function : Destructor +// purpose : +// ======================================================================= OpenGl_View::~OpenGl_View() { ReleaseGlResources (NULL); // ensure ReleaseGlResources() was called within valid context @@ -82,6 +124,10 @@ OpenGl_View::~OpenGl_View() OpenGl_Element::Destroy (NULL, myTextureParams); } +// ======================================================================= +// function : ReleaseGlResources +// purpose : +// ======================================================================= void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) { myTrihedron .Release (theCtx.operator->()); @@ -106,140 +152,595 @@ void OpenGl_View::ReleaseGlResources (const Handle(OpenGl_Context)& theCtx) myBgTextureArray->Release (theCtx.operator->()); } + myMainSceneFbos[0] ->Release (theCtx.operator->()); + myMainSceneFbos[1] ->Release (theCtx.operator->()); + myImmediateSceneFbos[0]->Release (theCtx.operator->()); + myImmediateSceneFbos[1]->Release (theCtx.operator->()); + myFullScreenQuad .Release (theCtx.operator->()); + myFullScreenQuadFlip .Release (theCtx.operator->()); + releaseRaytraceResources (theCtx); } -void OpenGl_View::SetTextureEnv (const Handle(OpenGl_Context)& theCtx, - const Handle(Graphic3d_TextureEnv)& theTexture) +// ======================================================================= +// function : Remove +// purpose : +// ======================================================================= +void OpenGl_View::Remove() { - if (!myTextureEnv.IsNull()) + if (IsRemoved()) { - theCtx->DelayedRelease (myTextureEnv); - myTextureEnv.Nullify(); + return; } - if (theTexture.IsNull()) + myDriver->RemoveView (this); + myWindow.Nullify(); + + Graphic3d_CView::Remove(); +} + +// ======================================================================= +// function : SetTextureEnv +// purpose : +// ======================================================================= +void OpenGl_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) +{ + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + if (!aCtx.IsNull() && !myTextureEnv.IsNull()) + { + aCtx->DelayedRelease (myTextureEnv); + } + + myToUpdateEnvironmentMap = Standard_True; + myTextureEnvData = theTextureEnv; + myTextureEnv.Nullify(); + initTextureEnv (aCtx); +} + +// ======================================================================= +// function : initTextureEnv +// purpose : +// ======================================================================= +void OpenGl_View::initTextureEnv (const Handle(OpenGl_Context)& theContext) +{ + if (myTextureEnvData.IsNull() + || theContext.IsNull() + || !theContext->MakeCurrent()) { return; } - myTextureEnv = new OpenGl_Texture (theTexture->GetParams()); - Handle(Image_PixMap) anImage = theTexture->GetImage(); + myTextureEnv = new OpenGl_Texture (myTextureEnvData->GetParams()); + Handle(Image_PixMap) anImage = myTextureEnvData->GetImage(); if (!anImage.IsNull()) - myTextureEnv->Init (theCtx, *anImage.operator->(), theTexture->Type()); + { + myTextureEnv->Init (theContext, *anImage.operator->(), myTextureEnvData->Type()); + } +} - myToUpdateEnvironmentMap = Standard_True; +// ======================================================================= +// function : SetImmediateModeDrawToFront +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_View::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) +{ + const Standard_Boolean aPrevMode = myTransientDrawToFront; + myTransientDrawToFront = theDrawToFrontBuffer; + return aPrevMode; } -void OpenGl_View::SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail theMode) +// ======================================================================= +// function : SetWindow +// purpose : +// ======================================================================= +void OpenGl_View::SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext, + const Aspect_GraphicCallbackProc& theDisplayCB, + const Standard_Address theClientData) { - mySurfaceDetail = theMode; + myWindow = myDriver->CreateRenderWindow (theWindow, theContext); + Standard_ASSERT_RAISE (!myWindow.IsNull(), + "OpenGl_View::SetWindow, " + "Failed to create OpenGl window."); + myDisplayCallback.Func = theDisplayCB; + myDisplayCallback.Data = theClientData; + + myWorkspace = new OpenGl_Workspace (this, myWindow); + myWorldViewProjState.Reset(); myToUpdateEnvironmentMap = Standard_True; + myHasFboBlit = Standard_True; + Invalidate(); + + // Environment texture resource does not support lazy initialization. + initTextureEnv (myWorkspace->GetGlContext()); +} + +// ======================================================================= +// function : Resized +// purpose : +// ======================================================================= +void OpenGl_View::Resized() +{ + if (myWindow.IsNull()) + return; + + myWindow->Resize(); +} + +// ======================================================================= +// function : TriedronDisplay +// purpose : +// ======================================================================= +void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, + const Quantity_NameOfColor theColor, + const Standard_Real theScale, + const Standard_Boolean theAsWireframe) +{ + myToShowTrihedron = true; + myTrihedron.SetWireframe (theAsWireframe); + myTrihedron.SetPosition (thePosition); + myTrihedron.SetScale (theScale); + myTrihedron.SetLabelsColor (theColor); } // ======================================================================= -// function : SetBackfacing +// function : TriedronErase // purpose : // ======================================================================= -void OpenGl_View::SetBackfacing (const Standard_Integer theMode) +void OpenGl_View::TriedronErase() { - myBackfacing = theMode; + myToShowTrihedron = false; + myTrihedron.Release (myWorkspace->GetGlContext().operator->()); +} + +// ======================================================================= +// function : ZBufferTriedronSetup +// purpose : +// ======================================================================= +void OpenGl_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor, + const Quantity_NameOfColor theYColor, + const Quantity_NameOfColor theZColor, + const Standard_Real theSizeRatio, + const Standard_Real theAxisDiametr, + const Standard_Integer theNbFacettes) +{ + myTrihedron.SetArrowsColors (theXColor, theYColor, theZColor); + myTrihedron.SetSizeRatio (theSizeRatio); + myTrihedron.SetNbFacets (theNbFacettes); + myTrihedron.SetArrowDiameter (theAxisDiametr); } // ======================================================================= -// function : SetLights +// function : TriedronEcho // purpose : // ======================================================================= -void OpenGl_View::SetLights (const CALL_DEF_VIEWCONTEXT& theViewCtx) +void OpenGl_View::TriedronEcho (const Aspect_TypeOfTriedronEcho /*theType*/) { - myLights.Clear(); - for (Standard_Integer aLightIt = 0; aLightIt < theViewCtx.NbActiveLight; ++aLightIt) + // do nothing +} + +// ======================================================================= +// function : SetMinMaxValuesCallback +// purpose : +// ======================================================================= +static void SetMinMaxValuesCallback (Graphic3d_CView* theView) +{ + OpenGl_View* aView = dynamic_cast(theView); + if (aView == NULL) + return; + + Bnd_Box aBox = theView->MinMaxValues(); + if (!aBox.IsVoid()) { - myLights.Append (theViewCtx.ActiveLight[aLightIt]); + gp_Pnt aMin = aBox.CornerMin(); + gp_Pnt aMax = aBox.CornerMax(); + + Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z()); + Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z()); + aView->GraduatedTrihedronMinMaxValues (aMinVec, aMaxVec); } - myCurrLightSourceState = myStateCounter->Increment(); } -/*----------------------------------------------------------------------*/ +// ======================================================================= +// function : GraduatedTrihedronDisplay +// purpose : +// ======================================================================= +void OpenGl_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) +{ + myGTrihedronData = theTrihedronData; + myGTrihedronData.PtrView = this; + myGTrihedronData.CubicAxesCallback = SetMinMaxValuesCallback; + myGraduatedTrihedron.SetValues (myGTrihedronData); + myToShowGradTrihedron = true; +} -//call_togl_setvisualisation -void OpenGl_View::SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext) +// ======================================================================= +// function : GraduatedTrihedronErase +// purpose : +// ======================================================================= +void OpenGl_View::GraduatedTrihedronErase() { - myVisualization = AContext.Visualization; - myShadingModel = (Visual3d_TypeOfModel )AContext.Model; + myGTrihedronData.PtrView = NULL; + myGraduatedTrihedron.Release (myWorkspace->GetGlContext().operator->()); + myToShowGradTrihedron = false; } -/*----------------------------------------------------------------------*/ +// ======================================================================= +// function : GraduatedTrihedronMinMaxValues +// purpose : +// ======================================================================= +void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) +{ + myGraduatedTrihedron.SetMinMax (theMin, theMax); +} -//call_togl_cliplimit -void OpenGl_View::SetClipLimit (const Graphic3d_CView& theCView) +// ======================================================================= +// function : ReadDepths +// purpose : +// ======================================================================= +void OpenGl_View::ReadDepths (const Standard_Integer theX, + const Standard_Integer theY, + const Standard_Integer theWidth, + const Standard_Integer theHeight, + const Standard_Address theBuffer) const { - myZClip.Back.Limit = theCView.Context.ZClipBackPlane; - myZClip.Front.Limit = theCView.Context.ZClipFrontPlane; + if (myWindow.IsNull()) + return; - myZClip.Back.IsOn = (theCView.Context.BackZClipping != 0); - myZClip.Front.IsOn = (theCView.Context.FrontZClipping != 0); + myWindow->ReadDepths (theX, theY, theWidth, theHeight, (float*)theBuffer); } -/*----------------------------------------------------------------------*/ +// ======================================================================= +// function : BufferDump +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType) +{ + return myWorkspace->BufferDump (myFBO, theImage, theBufferType); +} + +// ======================================================================= +// function : Background +// purpose : +// ======================================================================= +Aspect_Background OpenGl_View::Background() const +{ + return Aspect_Background (Quantity_Color (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], Quantity_TOC_RGB)); +} + +// ======================================================================= +// function : SetBackground +// purpose : +// ======================================================================= +void OpenGl_View::SetBackground (const Aspect_Background& theBackground) +{ + Quantity_Color aBgColor = theBackground.Color(); + myBgColor.rgb[0] = static_cast (aBgColor.Red()); + myBgColor.rgb[1] = static_cast (aBgColor.Green()); + myBgColor.rgb[2] = static_cast (aBgColor.Blue()); + myFog.Color = myBgColor; +} + +// ======================================================================= +// function : GradientBackground +// purpose : +// ======================================================================= +Aspect_GradientBackground OpenGl_View::GradientBackground() const +{ + Quantity_Color aColor1, aColor2; + aColor1.SetValues (myBgGradientArray->GradientColor (0).r(), + myBgGradientArray->GradientColor (0).g(), + myBgGradientArray->GradientColor (0).b(), Quantity_TOC_RGB); + aColor2.SetValues (myBgGradientArray->GradientColor (1).r(), + myBgGradientArray->GradientColor (1).g(), + myBgGradientArray->GradientColor (1).b(), Quantity_TOC_RGB); + return Aspect_GradientBackground (aColor1, aColor2, myBgGradientArray->GradientFillMethod()); +} -void OpenGl_View::SetFog (const Graphic3d_CView& theCView, - const Standard_Boolean theFlag) +// ======================================================================= +// function : SetGradientBackground +// purpose : +// ======================================================================= +void OpenGl_View::SetGradientBackground (const Aspect_GradientBackground& theBackground) { - if (!theFlag) + Quantity_Color aColor1, aColor2; + theBackground.Colors (aColor1, aColor2); + myBgGradientArray->SetGradientParameters (aColor1, aColor2, theBackground.BgGradientFillMethod()); +} + +// ======================================================================= +// function : SetBackgroundImage +// purpose : +// ======================================================================= +void OpenGl_View::SetBackgroundImage (const TCollection_AsciiString& theFilePath) +{ + // Prepare aspect for texture storage + myBackgroundImagePath = theFilePath; + Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); + Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath)); + aTextureMap->EnableRepeat(); + aTextureMap->DisableModulate(); + aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL, + Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f), + Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); + anAspect->SetTextureMap (aTextureMap); + anAspect->SetInteriorStyle (Aspect_IS_SOLID); + // Enable texture mapping + if (aTextureMap->IsDone()) { - myFog.IsOn = Standard_False; + anAspect->SetTextureMapOn(); } else { - myFog.IsOn = Standard_True; + anAspect->SetTextureMapOff(); + return; + } - myFog.Front = theCView.Context.DepthFrontPlane; - myFog.Back = theCView.Context.DepthBackPlane; + // Set texture parameters + myTextureParams->SetAspect (anAspect); +} - myFog.Color.rgb[0] = theCView.DefWindow.Background.r; - myFog.Color.rgb[1] = theCView.DefWindow.Background.g; - myFog.Color.rgb[2] = theCView.DefWindow.Background.b; - myFog.Color.rgb[3] = 1.0f; - } +// ======================================================================= +// function : BackgroundImageStyle +// purpose : +// ======================================================================= +Aspect_FillMethod OpenGl_View::BackgroundImageStyle() const +{ + return myBgTextureArray->TextureFillMethod(); } -/*----------------------------------------------------------------------*/ +// ======================================================================= +// function : SetBackgroundImageStyle +// purpose : +// ======================================================================= +void OpenGl_View::SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) +{ + myBgTextureArray->SetTextureFillMethod (theFillStyle); +} -void OpenGl_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe) +//======================================================================= +//function : AddZLayer +//purpose : +//======================================================================= +void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId) { - myToShowTrihedron = true; - myTrihedron.SetWireframe (theAsWireframe); - myTrihedron.SetPosition (thePosition); - myTrihedron.SetScale (theScale); - myTrihedron.SetLabelsColor (theColor); + myZLayers.AddLayer (theLayerId); } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : RemoveZLayer +//purpose : +//======================================================================= +void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) +{ + myZLayers.RemoveLayer (theLayerId); +} -void OpenGl_View::TriedronErase (const Handle(OpenGl_Context)& theCtx) +//======================================================================= +//function : SetZLayerSettings +//purpose : +//======================================================================= +void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, + const Graphic3d_ZLayerSettings& theSettings) { - myToShowTrihedron = false; - myTrihedron.Release (theCtx.operator->()); + myZLayers.SetLayerSettings (theLayerId, theSettings); } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : FBO +//purpose : +//======================================================================= +Graphic3d_PtrFrameBuffer OpenGl_View::FBO() const +{ + return reinterpret_cast (myFBO); +} -void OpenGl_View::GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_GraduatedTrihedron& theData) +//======================================================================= +//function : SetFBO +//purpose : +//======================================================================= +void OpenGl_View::SetFBO (const Graphic3d_PtrFrameBuffer theFBO) { - myToShowGradTrihedron = true; - myGraduatedTrihedron.SetValues (theCtx, theData); + myFBO = reinterpret_cast (theFBO); } -/*----------------------------------------------------------------------*/ +//======================================================================= +//function : FBOCreate +//purpose : +//======================================================================= +Graphic3d_PtrFrameBuffer OpenGl_View::FBOCreate (const Standard_Integer theWidth, + const Standard_Integer theHeight) +{ + return myWorkspace->FBOCreate (theWidth, theHeight); +} -void OpenGl_View::GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx) +//======================================================================= +//function : FBORelease +//purpose : +//======================================================================= +void OpenGl_View::FBORelease (Graphic3d_PtrFrameBuffer& theFBOPtr) { - myToShowGradTrihedron = false; - myGraduatedTrihedron.Release (theCtx.operator->()); + myWorkspace->FBORelease (theFBOPtr); +} + +//======================================================================= +//function : FBOGetDimensions +//purpose : +//======================================================================= +void OpenGl_View::FBOGetDimensions (const Graphic3d_PtrFrameBuffer theFBOPtr, + Standard_Integer& theWidth, + Standard_Integer& theHeight, + Standard_Integer& theWidthMax, + Standard_Integer& theHeightMax) +{ + const OpenGl_FrameBuffer* aFrameBuffer = (const OpenGl_FrameBuffer* )theFBOPtr; + theWidth = aFrameBuffer->GetVPSizeX(); // current viewport size + theHeight = aFrameBuffer->GetVPSizeY(); + theWidthMax = aFrameBuffer->GetSizeX(); // texture size + theHeightMax = aFrameBuffer->GetSizeY(); +} + +//======================================================================= +//function : FBOChangeViewport +//purpose : +//======================================================================= +void OpenGl_View::FBOChangeViewport (Graphic3d_PtrFrameBuffer& theFBOPtr, + const Standard_Integer theWidth, + const Standard_Integer theHeight) +{ + OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theFBOPtr; + aFrameBuffer->ChangeViewport (theWidth, theHeight); +} + +// ======================================================================= +// function : Export +// purpose : +// ======================================================================= +#ifdef HAVE_GL2PS +Standard_Boolean OpenGl_View::Export (const Standard_CString theFileName, + const Graphic3d_ExportFormat theFormat, + const Graphic3d_SortType theSortType) +{ + // gl2psBeginPage() will call OpenGL functions + // so we should activate correct GL context before redraw scene call + if (!myWorkspace->Activate()) + { + return Standard_False; + } + + Standard_Integer aFormat = -1; + Standard_Integer aSortType = Graphic3d_ST_BSP_Tree; + switch (theFormat) + { + case Graphic3d_EF_PostScript: + aFormat = GL2PS_PS; + break; + case Graphic3d_EF_EnhPostScript: + aFormat = GL2PS_EPS; + break; + case Graphic3d_EF_TEX: + aFormat = GL2PS_TEX; + break; + case Graphic3d_EF_PDF: + aFormat = GL2PS_PDF; + break; + case Graphic3d_EF_SVG: + aFormat = GL2PS_SVG; + break; + case Graphic3d_EF_PGF: + aFormat = GL2PS_PGF; + break; + case Graphic3d_EF_EMF: + //aFormat = GL2PS_EMF; + aFormat = GL2PS_PGF + 1; // 6 + break; + default: + // unsupported format + return Standard_False; + } + + switch (theSortType) + { + case Graphic3d_ST_Simple: + aSortType = GL2PS_SIMPLE_SORT; + break; + case Graphic3d_ST_BSP_Tree: + aSortType = GL2PS_BSP_SORT; + break; + } + + GLint aViewport[4]; + aViewport[0] = 0; + aViewport[1] = 0; + aViewport[2] = myWindow->Width(); + aViewport[3] = myWindow->Height(); + + GLint aBufferSize = 1024 * 1024; + GLint anErrCode = GL2PS_SUCCESS; + + // gl2ps uses standard write functions and do not check locale + Standard_CLocaleSentry aLocaleSentry; + + while (aBufferSize > 0) + { + // current patch for EMF support in gl2ps uses WinAPI functions to create file + FILE* aFileH = (theFormat != Graphic3d_EF_EMF) ? fopen (theFileName, "wb") : NULL; + anErrCode = gl2psBeginPage ("", "", aViewport, aFormat, aSortType, + GL2PS_DRAW_BACKGROUND | GL2PS_OCCLUSION_CULL | GL2PS_BEST_ROOT/* | GL2PS_SIMPLE_LINE_OFFSET*/, + GL_RGBA, 0, NULL, + 0, 0, 0, aBufferSize, aFileH, theFileName); + if (anErrCode != GL2PS_SUCCESS) + { + // initialization failed + if (aFileH != NULL) + fclose (aFileH); + break; + } + Redraw(); + + anErrCode = gl2psEndPage(); + if (aFileH != NULL) + fclose (aFileH); + + if (anErrCode == GL2PS_OVERFLOW) + aBufferSize *= 2; + else + break; + } + return anErrCode == GL2PS_SUCCESS; +} +#else +Standard_Boolean OpenGl_View::Export (const Standard_CString /*theFileName*/, + const Graphic3d_ExportFormat /*theFormat*/, + const Graphic3d_SortType /*theSortType*/) +{ + return Standard_False; +} +#endif + +//======================================================================= +//function : displayStructure +//purpose : +//======================================================================= +void OpenGl_View::displayStructure (const Handle(Graphic3d_CStructure)& theStructure, + const Standard_Integer thePriority) +{ + const OpenGl_Structure* aStruct = reinterpret_cast (theStructure.operator->()); + const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer(); + myZLayers.AddStructure (aStruct, aZLayer, thePriority); +} + +//======================================================================= +//function : eraseStructure +//purpose : +//======================================================================= +void OpenGl_View::eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) +{ + const OpenGl_Structure* aStruct = reinterpret_cast (theStructure.operator->()); + myZLayers.RemoveStructure (aStruct); +} + +//======================================================================= +//function : changeZLayer +//purpose : +//======================================================================= +void OpenGl_View::changeZLayer (const Handle(Graphic3d_CStructure)& theStructure, + const Graphic3d_ZLayerId theNewLayerId) +{ + const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer(); + const OpenGl_Structure* aStruct = reinterpret_cast (theStructure.operator->()); + myZLayers.ChangeLayer (aStruct, anOldLayer, theNewLayerId); +} + +//======================================================================= +//function : changePriority +//purpose : +//======================================================================= +void OpenGl_View::changePriority (const Handle(Graphic3d_CStructure)& theStructure, + const Standard_Integer theNewPriority) +{ + const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer(); + const OpenGl_Structure* aStruct = reinterpret_cast (theStructure.operator->()); + myZLayers.ChangePriority (aStruct, aLayerId, theNewPriority); } diff --git a/src/OpenGl/OpenGl_View.hxx b/src/OpenGl/OpenGl_View.hxx index 557201d1f9..60f56eb41d 100644 --- a/src/OpenGl/OpenGl_View.hxx +++ b/src/OpenGl/OpenGl_View.hxx @@ -29,25 +29,32 @@ #include #include -#include #include #include #include +#include +#include #include #include -#include -#include #include #include #include +#include +#include +#include #include #include #include +#include +#include #include -#include +#include +#include +#include +#include struct OPENGL_ZCLIP { @@ -70,96 +77,370 @@ struct OPENGL_FOG }; struct OpenGl_Matrix; -class OpenGl_Structure; -class OpenGl_StateCounter; +class Graphic3d_StructureManager; +class OpenGl_GraphicDriver; +class OpenGl_StateCounter; +class OpenGl_RaytraceMaterial; +class OpenGl_TriangleSet; +class OpenGl_Workspace; class OpenGl_View; -DEFINE_STANDARD_HANDLE(OpenGl_View,MMgt_TShared) +DEFINE_STANDARD_HANDLE(OpenGl_View,Graphic3d_CView) -class OpenGl_View : public MMgt_TShared +//! Implementation of OpenGl view. +class OpenGl_View : public Graphic3d_CView { - public: - Standard_EXPORT OpenGl_View (const CALL_DEF_VIEWCONTEXT &AContext, OpenGl_StateCounter* theCounter); - Standard_EXPORT virtual ~OpenGl_View (); + +public: + + //! Constructor. + Standard_EXPORT OpenGl_View (const Handle(Graphic3d_StructureManager)& theMgr, + const Handle(OpenGl_GraphicDriver)& theDriver, + const Handle(OpenGl_Caps)& theCaps, + Standard_Boolean& theDeviceLostFlag, + OpenGl_StateCounter* theCounter); + + //! Default destructor. + Standard_EXPORT virtual ~OpenGl_View(); Standard_EXPORT void ReleaseGlResources (const Handle(OpenGl_Context)& theCtx); - void SetTextureEnv (const Handle(OpenGl_Context)& theCtx, - const Handle(Graphic3d_TextureEnv)& theTexture); - void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail AMode); - void SetBackfacing (const Standard_Integer AMode); - void SetLights (const CALL_DEF_VIEWCONTEXT &AContext); - void SetAntiAliasing (const Standard_Boolean AMode) { myAntiAliasing = AMode; } - void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane &thePlanes) { myClipPlanes = thePlanes; } - void SetVisualisation (const CALL_DEF_VIEWCONTEXT &AContext); + //! Deletes and erases the view. + Standard_EXPORT virtual void Remove() Standard_OVERRIDE; + + //! @param theDrawToFrontBuffer Advanced option to modify rendering mode: + //! 1. TRUE. Drawing immediate mode structures directly to the front buffer over the scene image. + //! Fast, so preferred for interactive work (used by default). + //! However these extra drawings will be missed in image dump since it is performed from back buffer. + //! Notice that since no pre-buffering used the V-Sync will be ignored and rendering could be seen + //! in run-time (in case of slow hardware) and/or tearing may appear. + //! So this is strongly recommended to draw only simple (fast) structures. + //! 2. FALSE. Drawing immediate mode structures to the back buffer. + //! The complete scene is redrawn first, so this mode is slower if scene contains complex data and/or V-Sync + //! is turned on. But it works in any case and is especially useful for view dump because the dump image is read + //! from the back buffer. + //! @return previous mode. + Standard_EXPORT Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) Standard_OVERRIDE; + + //! Creates and maps rendering window to the view. + //! @param theView [in] the view to associate with the window. + //! @param theWindow [in] the window. + //! @param theContext [in] the rendering context. If NULL the context will be created internally. + //! @param theDisplayCB [in] the display callback function. If is not a NULL value, then the callback will be + //! invoked at the end of the OCC graphic traversal and just before the swap of buffers. + //! @param theClientData [in] the client data for the callback. + Standard_EXPORT virtual void SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext, + const Aspect_GraphicCallbackProc& theDisplayCB, + const Standard_Address theClientData) Standard_OVERRIDE; + + //! Returns window associated with the view. + virtual Handle(Aspect_Window) Window() const Standard_OVERRIDE { return myWindow->PlatformWindow(); } + + //! Returns True if the window associated to the view is defined. + virtual Standard_Boolean IsDefined() const { return !myWindow.IsNull(); } + + //! Handle changing size of the rendering window. + Standard_EXPORT virtual void Resized() Standard_OVERRIDE; + + //! Redraw content of the view. + Standard_EXPORT virtual void Redraw() Standard_OVERRIDE; + + //! Redraw immediate content of the view. + Standard_EXPORT virtual void RedrawImmediate() Standard_OVERRIDE; + + //! Marks BVH tree for given priority list as dirty and marks primitive set for rebuild. + Standard_EXPORT virtual void Invalidate() Standard_OVERRIDE; + + //! Return true if view content cache has been invalidated. + virtual Standard_Boolean IsInvalidated() Standard_OVERRIDE { return myBackBufferRestored; } + + //! Displays z-buffer trihedron. + Standard_EXPORT virtual void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Standard_Real theScale = 0.02, + const Standard_Boolean theAsWireframe = Standard_True) Standard_OVERRIDE; + + //! Erases z-buffer trihedron. + Standard_EXPORT virtual void TriedronErase() Standard_OVERRIDE; + + //! Setup parameters of z-buffer trihedron. + Standard_EXPORT virtual void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED, + const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN, + const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1, + const Standard_Real theSizeRatio = 0.8, + const Standard_Real theAxisDiametr = 0.05, + const Standard_Integer theNbFacettes = 12) Standard_OVERRIDE; + + //! Displays trihedron echo. + Standard_EXPORT virtual void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE) Standard_OVERRIDE; + + //! Returns data of a graduated trihedron + const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() { return myGTrihedronData; } + + //! Displays Graduated Trihedron. + Standard_EXPORT virtual void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) Standard_OVERRIDE; + + //! Erases Graduated Trihedron. + Standard_EXPORT virtual void GraduatedTrihedronErase() Standard_OVERRIDE; + + //! Sets minimum and maximum points of scene bounding box for Graduated Trihedron stored in graphic view object. + //! @param theMin [in] the minimum point of scene. + //! @param theMax [in] the maximum point of scene. + Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE; + + //! Reads depths of shown pixels of the given rectangle. + Standard_EXPORT virtual void ReadDepths (const Standard_Integer theX, + const Standard_Integer theY, + const Standard_Integer theWidth, + const Standard_Integer theHeight, + const Standard_Address theBuffer) const Standard_OVERRIDE; + + //! Dump active rendering buffer into specified memory buffer. + Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage, + const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE; + + //! Print the contents of the view to the printer. + //! @param thePrinterDC pass the PrinterDeviceContext (HDC) + //! @param theToShowBackground when set to FALSE then print the view without background + //! color (background is white) else set to TRUE for printing + //! with current background color + //! @param theFileName if != NULL, then the view will be printed to a file + //! @param thePrintAlgorithm select print algorithm: stretch, tile + //! @param theScaleFactor scaling coefficient, used internally to scale the printings + //! accordingly to the scale factor selected in the printer properties dialog + //! @return Standard_True if the data is passed to the printer, otherwise Standard_False if + //! the print operation failed due to the printer errors, or lack of system memory. This might be related + //! to insufficient memory or some internal errors. + //! All this errors are indicated by the message boxes (on level of OpenGl_GraphicDriver). + //! Warning: This function can reuse FBO assigned to the view, please take it into account + //! if you use it for your purposes. + Standard_EXPORT virtual Standard_Boolean Print (const Aspect_Handle thePrinterDC, + const Standard_Boolean theToShowBackground, + const Standard_CString theFileName, + const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH, + const Standard_Real theScaleFactor = 1.0) Standard_OVERRIDE; + + //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). + //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits + //! on printing to laser printer). Notice however that results may differ a lot and + //! do not contain some elements. + Standard_EXPORT virtual Standard_Boolean Export (const Standard_CString theFileName, + const Graphic3d_ExportFormat theFormat, + const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree) Standard_OVERRIDE; + + //! Marks BVH tree and the set of BVH primitives of correspondent priority list with id theLayerId as outdated. + Standard_EXPORT virtual void InvalidateBVHData (const Standard_Integer theLayerId) Standard_OVERRIDE; + + //! Insert a new top-level z layer with the given ID. + Standard_EXPORT virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; + + //! Remove a z layer with the given ID. + Standard_EXPORT virtual void RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - const Handle(Graphic3d_Camera)& Camera() { return myCamera; } - void SetCamera (const Handle(Graphic3d_Camera)& theCamera) { myCamera = theCamera; } + //! Sets the settings for a single Z layer of specified view. + Standard_EXPORT virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, + const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE; - void SetClipLimit (const Graphic3d_CView& theCView); + //! Returns pointer to an assigned framebuffer object. + Standard_EXPORT virtual Graphic3d_PtrFrameBuffer FBO() const Standard_OVERRIDE; - void SetFog (const Graphic3d_CView& theCView, const Standard_Boolean theFlag); + //! Sets framebuffer object for offscreen rendering. + Standard_EXPORT virtual void SetFBO (const Graphic3d_PtrFrameBuffer theFBO) Standard_OVERRIDE; - OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; } - void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe); - void TriedronErase (const Handle(OpenGl_Context)& theCtx); + //! Generate offscreen FBO in the graphic library. + //! If not supported on hardware returns NULL. + Standard_EXPORT virtual Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, + const Standard_Integer theHeight) Standard_OVERRIDE; - OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; } - void GraduatedTrihedronDisplay (const Handle(OpenGl_Context)& theCtx, - const Graphic3d_GraduatedTrihedron& theCubic); - void GraduatedTrihedronErase (const Handle(OpenGl_Context)& theCtx); + //! Remove offscreen FBO from the graphic library + Standard_EXPORT virtual void FBORelease (Graphic3d_PtrFrameBuffer& theFBOPtr) Standard_OVERRIDE; - Standard_Real Height () const { return myCamera->ViewDimensions().X(); } - Standard_Real Width () const { return myCamera->ViewDimensions().Y(); } + //! Read offscreen FBO configuration. + Standard_EXPORT virtual void FBOGetDimensions (const Graphic3d_PtrFrameBuffer theFBOPtr, + Standard_Integer& theWidth, + Standard_Integer& theHeight, + Standard_Integer& theWidthMax, + Standard_Integer& theHeightMax) Standard_OVERRIDE; + + //! Change offscreen FBO viewport. + Standard_EXPORT virtual void FBOChangeViewport (Graphic3d_PtrFrameBuffer& theFBOPtr, + const Standard_Integer theWidth, + const Standard_Integer theHeight) Standard_OVERRIDE; - Standard_Integer Backfacing () const { return myBackfacing; } +public: - //! Add structure to display list with specified priority. - //! The structure will be added to associated with it z layer. - //! If the z layer is not presented in the view, the structure will - //! be displayed in default bottom-level z layer. - void DisplayStructure (const Handle(Graphic3d_Structure)& theStructure, - const Standard_Integer thePriority); + //! Returns true if anti-aliasing is enabled for the view. + Standard_Boolean virtual IsAntialiasingEnabled() const Standard_OVERRIDE { return myAntiAliasing; } - //! Erase structure from display list. - void EraseStructure (const Handle(Graphic3d_Structure)& theStructure); + //! Enable or disable anti-aliasing in the view. + virtual void SetAntialiasingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myAntiAliasing = theIsEnabled; } - //! Insert a new top-level z layer with ID - void AddZLayer (const Graphic3d_ZLayerId theLayerId); + //! Returns background fill color. + Standard_EXPORT virtual Aspect_Background Background() const Standard_OVERRIDE; - //! Remove a z layer with ID - void RemoveZLayer (const Graphic3d_ZLayerId theLayerId); + //! Sets background fill color. + Standard_EXPORT virtual void SetBackground (const Aspect_Background& theBackground) Standard_OVERRIDE; - //! Display structure in z layer with ID - //! If the layer with ID is not presented in the view, - //! the structure will be displayed in default bottom-level layer. - void ChangeZLayer (const OpenGl_Structure* theStructure, - const Graphic3d_ZLayerId theNewLayerId); + //! Returns gradient background fill colors. + Standard_EXPORT virtual Aspect_GradientBackground GradientBackground() const Standard_OVERRIDE; - //! Sets the settings for a single Z layer of specified view. - void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings); + //! Sets gradient background fill colors. + Standard_EXPORT virtual void SetGradientBackground (const Aspect_GradientBackground& theBackground) Standard_OVERRIDE; + + //! Returns background image texture file path. + Standard_EXPORT virtual TCollection_AsciiString BackgroundImage() Standard_OVERRIDE { return myBackgroundImagePath; } + + //! Sets background image texture file path. + Standard_EXPORT virtual void SetBackgroundImage (const TCollection_AsciiString& theFilePath) Standard_OVERRIDE; + + //! Returns background image fill style. + Standard_EXPORT virtual Aspect_FillMethod BackgroundImageStyle() const Standard_OVERRIDE; + + //! Sets background image fill style. + Standard_EXPORT virtual void SetBackgroundImageStyle (const Aspect_FillMethod theFillStyle) Standard_OVERRIDE; + + //! Returns environment texture set for the view. + Standard_EXPORT virtual Handle(Graphic3d_TextureEnv) TextureEnv() const Standard_OVERRIDE { return myTextureEnvData; } + + //! Sets environment texture for the view. + Standard_EXPORT virtual void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTextureEnv) Standard_OVERRIDE; + + //! Returns the state of frustum culling optimization. + virtual Standard_Boolean IsCullingEnabled() const Standard_OVERRIDE { return myCulling; } + + //! Enables or disables frustum culling optimization. + virtual void SetCullingEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myCulling = theIsEnabled; } + + //! Returns shading model of the view. + virtual Graphic3d_TypeOfShadingModel ShadingModel() const Standard_OVERRIDE { return myShadingModel; } + + //! Sets shading model of the view. + virtual void SetShadingModel (const Graphic3d_TypeOfShadingModel theModel) Standard_OVERRIDE { myShadingModel = theModel; } + + //! Returns surface detail type of the view. + virtual Graphic3d_TypeOfSurfaceDetail SurfaceDetailType() const Standard_OVERRIDE { return mySurfaceDetail; } + + //! Sets surface detail type of the view. + virtual void SetSurfaceDetailType (const Graphic3d_TypeOfSurfaceDetail theType) Standard_OVERRIDE + { + mySurfaceDetail = theType; + myToUpdateEnvironmentMap = Standard_True; + } + + //! Return backfacing model used for the view. + virtual Graphic3d_TypeOfBackfacingModel BackfacingModel() const Standard_OVERRIDE { return myBackfacing; } + + //! Sets backfacing model for the view. + virtual void SetBackfacingModel (const Graphic3d_TypeOfBackfacingModel theModel) Standard_OVERRIDE { myBackfacing = theModel; } + + //! Returns camera object of the view. + virtual const Handle(Graphic3d_Camera)& Camera() const Standard_OVERRIDE { return myCamera; } + + //! Sets camera used by the view. + virtual void SetCamera (const Handle(Graphic3d_Camera)& theCamera) Standard_OVERRIDE { myCamera = theCamera; } + + //! Returns the activity of back z-clipping plane. + virtual Standard_Boolean BackZClippingIsOn() const Standard_OVERRIDE { return myZClip.Back.IsOn; } + + //! Activates the back Z-clipping plane. + virtual void SetBackZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myZClip.Back.IsOn = theIsOn; } + + //! Returns the definition of the back Z-clipping plane. + virtual Standard_Real ZClippingBackPlane() const Standard_OVERRIDE { return myZClip.Back.Limit; } + + //! Sets the definition of the back Z-clipping plane. + virtual void SetZClippingBackPlane (const Standard_Real theValue) Standard_OVERRIDE + { + myZClip.Back.Limit = static_cast (theValue); + } + + //! Returns the activity of front z-clipping plane. + virtual Standard_Boolean FrontZClippingIsOn() const Standard_OVERRIDE { return myZClip.Front.IsOn; } + + //! Activates the front Z-clipping plane. + virtual void SetFrontZClippingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE{ myZClip.Front.IsOn = theIsOn; } + + //! Returns the definition of the front Z-clipping plane. + virtual Standard_Real ZClippingFrontPlane() const Standard_OVERRIDE { return myZClip.Front.Limit; } + + //! Sets the definition of the front Z-clipping plane. + virtual void SetZClippingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE + { + myZClip.Front.Limit = static_cast (theValue); + } + + //! Returns the activity of depth cueing. + virtual Standard_Boolean DepthCueingIsOn() const Standard_OVERRIDE { return myFog.IsOn; } + + //! Sets the activity of depth cueing. + virtual void SetDepthCueingOn (const Standard_Boolean theIsOn) Standard_OVERRIDE { myFog.IsOn = theIsOn; } - //! Changes the priority of a structure within its ZLayer - void ChangePriority (const OpenGl_Structure* theStructure, - const Standard_Integer theNewPriority); + //! Returns the back depth cueing plane. + virtual Standard_Real DepthCueingBackPlane() const Standard_OVERRIDE { return myFog.Back; } - void CreateBackgroundTexture (const Standard_CString AFileName, - const Aspect_FillMethod AFillStyle); + //! Set the back depth cueing plane. + virtual void SetDepthCueingBackPlane (const Standard_Real theValue) Standard_OVERRIDE + { + myFog.Back = static_cast (theValue); + } + + //! Returns the front depth cueing plane. + virtual Standard_Real DepthCueingFrontPlane() const Standard_OVERRIDE { return myFog.Front; } + + //! Set the front depth cueing plane. + virtual void SetDepthCueingFrontPlane (const Standard_Real theValue) Standard_OVERRIDE + { + myFog.Front = static_cast (theValue); + } + + //! Returns true if GL lighting is enabled. + virtual Standard_Boolean IsGLLightEnabled() const Standard_OVERRIDE { return myUseGLLight; } + + //! Sets GL lighting enabled or disable state. + virtual void SetGLLightEnabled (const Standard_Boolean theIsEnabled) Standard_OVERRIDE { myUseGLLight = theIsEnabled; } + + //! Returns list of lights of the view. + virtual const Graphic3d_ListOfCLight& Lights() const Standard_OVERRIDE { return myLights; } + + //! Sets list of lights for the view. + virtual void SetLights (const Graphic3d_ListOfCLight& theLights) Standard_OVERRIDE + { + myLights = theLights; + myCurrLightSourceState = myStateCounter->Increment(); + } + + //! Returns list of clip planes set for the view. + virtual const Graphic3d_SequenceOfHClipPlane& ClipPlanes() const Standard_OVERRIDE { return myClipPlanes; } + + //! Sets list of clip planes for the view. + virtual void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) Standard_OVERRIDE { myClipPlanes = thePlanes; } + +public: + + //! Returns background color. + const TEL_COLOUR& BackgroundColor() const { return myBgColor; } + + //! Change trihedron. + OpenGl_Trihedron& ChangeTrihedron() { return myTrihedron; } + + //! Change graduated trihedron. + OpenGl_GraduatedTrihedron& ChangeGraduatedTrihedron() { return myGraduatedTrihedron; } + + void SetTextureEnv (const Handle(OpenGl_Context)& theCtx, + const Handle(Graphic3d_TextureEnv)& theTexture); + + //! Returns height of view volume. + Standard_Real Height () const { return myCamera->ViewDimensions().X(); } + + //! Returns width of view volume. + Standard_Real Width () const { return myCamera->ViewDimensions().Y(); } void SetBackgroundTextureStyle (const Aspect_FillMethod FillStyle); + void SetBackgroundGradient (const Quantity_Color& AColor1, const Quantity_Color& AColor2, const Aspect_GradientFillMethod AType); - void SetBackgroundGradientType (const Aspect_GradientFillMethod AType); - void Render (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theReadDrawFbo, - Graphic3d_Camera::Projection theProjection, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate); + void SetBackgroundGradientType (const Aspect_GradientFillMethod AType); void DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace); @@ -169,82 +450,144 @@ class OpenGl_View : public MMgt_TShared //! Returns list of openGL light sources. const OpenGl_ListOfLight& LightList() const { return myLights; } - //! Returns OpenGL environment map. - const Handle(OpenGl_Texture)& TextureEnv() const { return myTextureEnv; } + //! Returns OpenGL window implementation. + const Handle(OpenGl_Window) GlWindow() const { return myWindow; } - //! Returns visualization mode for objects in the view. - Visual3d_TypeOfSurfaceDetail SurfaceDetail() const { return mySurfaceDetail; } + //! Returns OpenGL environment map. + const Handle(OpenGl_Texture)& GlTextureEnv() const { return myTextureEnv; } //! Returns selector for BVH tree, providing a possibility to store information //! about current view volume and to detect which objects are overlapping it. OpenGl_BVHTreeSelector& BVHTreeSelector() { return myBVHSelector; } - //! Marks BVH tree for given priority list as dirty and - //! marks primitive set for rebuild. - void InvalidateBVHData (const Standard_Integer theLayerId); - //! Returns true if there are immediate structures to display bool HasImmediateStructures() const { return myZLayers.NbImmediateStructures() != 0; } -protected: +protected: //! @name Internal methods for managing GL resources + + //! Initializes OpenGl resource for environment texture. + void initTextureEnv (const Handle(OpenGl_Context)& theContext); + +protected: //! @name Internal redrawing sub-routines + + //! Redraws view for the given monographic camera projection, or left/right eye. + void redraw (const Graphic3d_Camera::Projection theProjection, OpenGl_FrameBuffer* theReadDrawFbo); - void RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate); + //! Redraws view for the given monographic camera projection, or left/right eye. + //! + //! Method will blit snapshot containing main scene (myMainSceneFbos or BackBuffer) + //! into presentation buffer (myMainSceneFbos -> offscreen FBO or + //! myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer), + //! and redraw immediate structures on top. + //! + //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.), + //! the first step (blitting) will be skipped. + //! + //! @return false if immediate structures has been rendered directly into FrontBuffer + //! and Buffer Swap should not be called. + bool redrawImmediate (const Graphic3d_Camera::Projection theProjection, + OpenGl_FrameBuffer* theReadFbo, + OpenGl_FrameBuffer* theDrawFbo, + const Standard_Boolean theIsPartialUpdate = Standard_False); - void RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace); + //! Copy content of Back buffer to the Front buffer. + void copyBackToFront(); - //! Redraw contents of model scene: clipping planes, - //! lights, structures. The peculiar properties of "scene" is that - //! it requires empty Z-Buffer and uses projection and orientation - //! matrices supplied by 3d view. - void RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate); + //! Initialize blit quad. + OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip); - Handle(OpenGl_LineAttributes) myLineAttribs; - Handle(OpenGl_Texture) myTextureEnv; - Visual3d_TypeOfSurfaceDetail mySurfaceDetail; - Standard_Integer myBackfacing; + //! Blit image from/to specified buffers. + bool blitBuffers (OpenGl_FrameBuffer* theReadFbo, + OpenGl_FrameBuffer* theDrawFbo, + const Standard_Boolean theToFlip = Standard_False); - OPENGL_ZCLIP myZClip; + //! Setup default FBO. + void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL); - Graphic3d_SequenceOfHClipPlane myClipPlanes; - - Handle(Graphic3d_Camera) myCamera; + //! Blend together views pair into stereo image. + void drawStereoPair(); - OPENGL_FOG myFog; - OpenGl_Trihedron myTrihedron; - OpenGl_GraduatedTrihedron myGraduatedTrihedron; - bool myToShowTrihedron; - bool myToShowGradTrihedron; + //! Invokes display callback. + void displayCallback (const Standard_Integer theReason); - //View_LABViewContext - int myVisualization; - Visual3d_TypeOfModel myShadingModel; //!< lighting shading model +protected: //! @name Rendering of GL graphics (with prepared drawing buffer). - //View_LABLight - OpenGl_ListOfLight myLights; + //! Renders the graphical contents of the view into the preprepared window or framebuffer. + //! @param theProjection [in] the projection that should be used for rendering. + //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. + //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. + void render (Graphic3d_Camera::Projection theProjection, + OpenGl_FrameBuffer* theReadDrawFbo, + const Standard_Boolean theToDrawImmediate); - //View_LABPlane - //View_LABAliasing - Standard_Boolean myAntiAliasing; + //! Renders the graphical scene. + //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. + //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. + void renderScene (OpenGl_FrameBuffer* theReadDrawFbo, + const Standard_Boolean theToDrawImmediate); - //View_LABDepthCueing - fixed index used + //! Render set of structures presented in the view. + //! @param theReadDrawFbo [in] the framebuffer for rendering graphics. + //! @param theToDrawImmediate [in] the flag indicates whether the rendering performs in immediate mode. + void renderStructs (OpenGl_FrameBuffer* theReadDrawFbo, + const Standard_Boolean theToDrawImmediate); - OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers + //! Renders trihedron. + void renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace); - //! Modification state - Graphic3d_WorldViewProjState myWorldViewProjState; - OpenGl_StateCounter* myStateCounter; +private: - Standard_Size myCurrLightSourceState; + //! Adds the structure to display lists of the view. + Standard_EXPORT virtual void displayStructure (const Handle(Graphic3d_CStructure)& theStructure, + const Standard_Integer thePriority) Standard_OVERRIDE; + + //! Erases the structure from display lists of the view. + Standard_EXPORT virtual void eraseStructure (const Handle(Graphic3d_CStructure)& theStructure) Standard_OVERRIDE; + + //! Change Z layer of a structure already presented in view. + Standard_EXPORT virtual void changeZLayer (const Handle(Graphic3d_CStructure)& theCStructure, + const Graphic3d_ZLayerId theNewLayerId) Standard_OVERRIDE; + + //! Changes the priority of a structure within its Z layer in the specified view. + Standard_EXPORT virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure, + const Standard_Integer theNewPriority) Standard_OVERRIDE; + +protected: + + OpenGl_GraphicDriver* myDriver; + Handle(OpenGl_Window) myWindow; + Handle(OpenGl_Workspace) myWorkspace; + Handle(OpenGl_Caps) myCaps; + Standard_Boolean& myDeviceLostFlag; + Standard_Boolean myWasRedrawnGL; + + Standard_Boolean myAntiAliasing; + Standard_Boolean myCulling; + Graphic3d_TypeOfShadingModel myShadingModel; + Graphic3d_TypeOfSurfaceDetail mySurfaceDetail; + Graphic3d_TypeOfBackfacingModel myBackfacing; + TEL_COLOUR myBgColor; + OPENGL_FOG myFog; + OPENGL_ZCLIP myZClip; + Graphic3d_SequenceOfHClipPlane myClipPlanes; + Handle(Graphic3d_Camera) myCamera; + OpenGl_FrameBuffer* myFBO; + Standard_Boolean myUseGLLight; + Standard_Boolean myToShowTrihedron; + Standard_Boolean myToShowGradTrihedron; + TCollection_AsciiString myBackgroundImagePath; + Handle(Graphic3d_TextureEnv) myTextureEnvData; + Graphic3d_GraduatedTrihedron myGTrihedronData; + + OpenGl_ListOfLight myLights; + OpenGl_LayerList myZLayers; //!< main list of displayed structure, sorted by layers + + Graphic3d_WorldViewProjState myWorldViewProjState; //!< camera modification state + OpenGl_StateCounter* myStateCounter; + Standard_Size myCurrLightSourceState; typedef std::pair StateInfo; @@ -255,6 +598,32 @@ protected: //! Is needed for selection of overlapping objects and storage of the current view volume OpenGl_BVHTreeSelector myBVHSelector; + OpenGl_Trihedron myTrihedron; + OpenGl_GraduatedTrihedron myGraduatedTrihedron; + + Handle(OpenGl_Texture) myTextureEnv; + + struct + { + Aspect_GraphicCallbackProc Func; + Standard_Address Data; + } myDisplayCallback; + +protected: //! @name Rendering properties + + //! Two framebuffers (left and right views) store cached main presentation + //! of the view (without presentation of immediate layers). + Handle(OpenGl_FrameBuffer) myMainSceneFbos[2]; + Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; //!< Additional buffers for immediate layer in stereo mode. + OpenGl_VertexBuffer myFullScreenQuad; //!< Vertices for full-screen quad rendering. + OpenGl_VertexBuffer myFullScreenQuadFlip; + Standard_Boolean myToFlipOutput; //!< Flag to draw result image upside-down + unsigned int myFrameCounter; //!< redraw counter, for debugging + Standard_Boolean myHasFboBlit; + Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer) + Standard_Boolean myBackBufferRestored; + Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data + protected: //! @name Background parameters OpenGl_AspectFace* myTextureParams; //!< Stores texture and its parameters for textured background @@ -564,8 +933,7 @@ protected: //! @name methods related to ray-tracing const Handle(OpenGl_ShaderObject)& theFragShader); //! Initializes OpenGL/GLSL shader programs. - Standard_Boolean initRaytraceResources (const Graphic3d_CView& theCView, - const Handle(OpenGl_Context)& theGlContext); + Standard_Boolean initRaytraceResources (const Handle(OpenGl_Context)& theGlContext); //! Releases OpenGL/GLSL shader programs. void releaseRaytraceResources (const Handle(OpenGl_Context)& theGlContext); @@ -589,16 +957,14 @@ protected: //! @name methods related to ray-tracing void unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlContext); //! Sets uniform state for the given ray-tracing shader program. - Standard_Boolean setUniformState (const Graphic3d_CView& theCView, - const OpenGl_Vec3* theOrigins, + Standard_Boolean setUniformState (const OpenGl_Vec3* theOrigins, const OpenGl_Vec3* theDirects, const OpenGl_Mat4& theUnviewMat, const Standard_Integer theProgramId, const Handle(OpenGl_Context)& theGlContext); //! Runs ray-tracing shader programs. - Standard_Boolean runRaytraceShaders (const Graphic3d_CView& theCView, - const Standard_Integer theSizeX, + Standard_Boolean runRaytraceShaders (const Standard_Integer theSizeX, const Standard_Integer theSizeY, const OpenGl_Vec3* theOrigins, const OpenGl_Vec3* theDirects, @@ -607,8 +973,7 @@ protected: //! @name methods related to ray-tracing const Handle(OpenGl_Context)& theGlContext); //! Redraws the window using OpenGL/GLSL ray-tracing. - Standard_Boolean raytrace (const Graphic3d_CView& theCView, - const Standard_Integer theSizeX, + Standard_Boolean raytrace (const Standard_Integer theSizeX, const Standard_Integer theSizeY, OpenGl_FrameBuffer* theReadDrawFbo, const Handle(OpenGl_Context)& theGlContext); @@ -718,10 +1083,10 @@ protected: //! @name fields related to ray-tracing public: DEFINE_STANDARD_ALLOC - DEFINE_STANDARD_RTTI(OpenGl_View, MMgt_TShared) // Type definition + DEFINE_STANDARD_RTTI(OpenGl_View, Graphic3d_CView) // Type definition + friend class OpenGl_GraphicDriver; friend class OpenGl_Workspace; - }; #endif // _OpenGl_View_Header diff --git a/src/OpenGl/OpenGl_View_2.cxx b/src/OpenGl/OpenGl_View_2.cxx deleted file mode 100644 index ce3f312246..0000000000 --- a/src/OpenGl/OpenGl_View_2.cxx +++ /dev/null @@ -1,1001 +0,0 @@ -// Created on: 2011-09-20 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define EPSI 0.0001 - -namespace -{ - - static const GLfloat THE_DEFAULT_AMBIENT[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - static const GLfloat THE_DEFAULT_SPOT_DIR[3] = { 0.0f, 0.0f, -1.0f }; - static const GLfloat THE_DEFAULT_SPOT_EXPONENT = 0.0f; - static const GLfloat THE_DEFAULT_SPOT_CUTOFF = 180.0f; - -}; - -extern void InitLayerProp (const int theListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx - -/*----------------------------------------------------------------------*/ -/* -* Fonctions privees -*/ - -#if !defined(GL_ES_VERSION_2_0) -/*-----------------------------------------------------------------*/ -/* -* Set des lumieres -*/ -static void bindLight (const OpenGl_Light& theLight, - GLenum& theLightGlId, - Graphic3d_Vec4& theAmbientColor, - const Handle(OpenGl_Workspace)& theWorkspace) -{ - // Only 8 lights in OpenGL... - if (theLightGlId > GL_LIGHT7) - { - return; - } - - if (theLight.Type == Visual3d_TOLS_AMBIENT) - { - // add RGBA intensity of the ambient light - theAmbientColor += theLight.Color; - return; - } - - const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - - // the light is a headlight? - if (theLight.IsHeadlight) - { - - aContext->WorldViewState.Push(); - aContext->WorldViewState.SetIdentity(); - - aContext->ApplyWorldViewMatrix(); - } - - // setup light type - switch (theLight.Type) - { - case Visual3d_TOLS_DIRECTIONAL: - { - // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one - const OpenGl_Vec4 anInfDir = -theLight.Direction; - - // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE. - glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); - glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_POSITION, anInfDir.GetData()); - glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR); - glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT); - glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF); - break; - } - case Visual3d_TOLS_POSITIONAL: - { - // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE - glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); - glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData()); - glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR); - glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT); - glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF); - glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation()); - glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation()); - glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0); - break; - } - case Visual3d_TOLS_SPOT: - { - glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); - glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); - glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData()); - glLightfv (theLightGlId, GL_SPOT_DIRECTION, theLight.Direction.GetData()); - glLightf (theLightGlId, GL_SPOT_EXPONENT, theLight.Concentration() * 128.0f); - glLightf (theLightGlId, GL_SPOT_CUTOFF, (theLight.Angle() * 180.0f) / GLfloat(M_PI)); - glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation()); - glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation()); - glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f); - break; - } - } - - // restore matrix in case of headlight - if (theLight.IsHeadlight) - { - aContext->WorldViewState.Pop(); - } - - glEnable (theLightGlId++); -} -#endif - -/*----------------------------------------------------------------------*/ - -void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace) -{ - const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); - - if ((theWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) != 0 // no background - || (!myBgTextureArray->IsDefined() // no texture - && !myBgGradientArray->IsDefined())) // no gradient - { - return; - } - - const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False); - if (wasUsedZBuffer) - { - aCtx->core11fwd->glDisable (GL_DEPTH_TEST); - } - - aCtx->ProjectionState.Push(); - aCtx->WorldViewState.Push(); - aCtx->ModelWorldState.Push(); - aCtx->ProjectionState.SetIdentity(); - aCtx->WorldViewState.SetIdentity(); - aCtx->ModelWorldState.SetIdentity(); - aCtx->ApplyProjectionMatrix(); - aCtx->ApplyModelViewMatrix(); - - // Drawing background gradient if: - // - gradient fill type is not Aspect_GFM_NONE and - // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode - if (myBgGradientArray->IsDefined() - && (!myTextureParams->DoTextureMap() - || myBgTextureArray->TextureFillMethod() == Aspect_FM_CENTERED - || myBgTextureArray->TextureFillMethod() == Aspect_FM_NONE)) - { - #if !defined(GL_ES_VERSION_2_0) - GLint aShadingModelOld = GL_SMOOTH; - if (aCtx->core11 != NULL) - { - aCtx->core11fwd->glDisable (GL_LIGHTING); - aCtx->core11fwd->glGetIntegerv (GL_SHADE_MODEL, &aShadingModelOld); - aCtx->core11->glShadeModel (GL_SMOOTH); - } - #endif - - if (myBgGradientArray->IsDataChanged()) - { - myBgGradientArray->Init (theWorkspace); - } - - myBgGradientArray->Render (theWorkspace); - - #if !defined(GL_ES_VERSION_2_0) - if (aCtx->core11 != NULL) - { - aCtx->core11->glShadeModel (aShadingModelOld); - } - #endif - } - - // Drawing background image if it is defined - // (texture is defined and fill type is not Aspect_FM_NONE) - if (myBgTextureArray->IsDefined() - && myTextureParams->DoTextureMap()) - { - aCtx->core11fwd->glDisable (GL_BLEND); - - const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams); - - if (myBgTextureArray->IsDataChanged() - || myBgTextureArray->IsViewSizeChanged (theWorkspace)) - { - myBgTextureArray->Init (theWorkspace); - } - - myBgTextureArray->Render (theWorkspace); - - // restore aspects - theWorkspace->SetAspectFace (anOldAspectFace); - } - - aCtx->ModelWorldState.Pop(); - aCtx->WorldViewState.Pop(); - aCtx->ProjectionState.Pop(); - aCtx->ApplyProjectionMatrix(); - aCtx->ApplyModelViewMatrix(); - - if (wasUsedZBuffer) - { - theWorkspace->SetUseZBuffer (Standard_True); - aCtx->core11fwd->glEnable (GL_DEPTH_TEST); - } -} - -/*----------------------------------------------------------------------*/ - -//call_func_redraw_all_structs_proc -void OpenGl_View::Render (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theOutputFBO, - Graphic3d_Camera::Projection theProjection, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate) -{ - // ================================== - // Step 1: Prepare for redraw - // ================================== - - const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - -#if !defined(GL_ES_VERSION_2_0) - // Disable current clipping planes - if (aContext->core11 != NULL) - { - const Standard_Integer aMaxPlanes = aContext->MaxClipPlanes(); - for (Standard_Integer aClipPlaneId = GL_CLIP_PLANE0; aClipPlaneId < GL_CLIP_PLANE0 + aMaxPlanes; ++aClipPlaneId) - { - aContext->core11fwd->glDisable (aClipPlaneId); - } - } -#endif - - Graphic3d_WorldViewProjState aWVPState = myCamera->WorldViewProjState(); - - // Update states of OpenGl_BVHTreeSelector (frustum culling algorithm). - myBVHSelector.SetViewVolume (myCamera); - - const Handle(OpenGl_ShaderManager)& aManager = aContext->ShaderManager(); - if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState) - { - aManager->UpdateLightSourceStateTo (&myLights); - myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()); - } - - if (myWorldViewProjState != aWVPState) - { - aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF()); - aContext->WorldViewState.SetCurrent (myCamera->OrientationMatrixF()); - aContext->ApplyProjectionMatrix(); - aContext->ApplyWorldViewMatrix(); - myWorldViewProjState = aWVPState; - } - - if (aManager->ModelWorldState().Index() == 0) - { - aContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4()); - } - - - // ==================================== - // Step 2: Redraw background - // ==================================== - - // Render background - if (!theToDrawImmediate) - { - DrawBackground (theWorkspace); - } - -#if !defined(GL_ES_VERSION_2_0) - // Switch off lighting by default - if (aContext->core11 != NULL) - { - glDisable(GL_LIGHTING); - } -#endif - - // ================================= - // Step 3: Redraw main plane - // ================================= - - // Setup face culling - GLboolean isCullFace = GL_FALSE; - if ( myBackfacing ) - { - isCullFace = glIsEnabled( GL_CULL_FACE ); - if ( myBackfacing < 0 ) - { - glEnable( GL_CULL_FACE ); - glCullFace( GL_BACK ); - } - else - glDisable( GL_CULL_FACE ); - } - -#if !defined(GL_ES_VERSION_2_0) - // if the view is scaled normal vectors are scaled to unit - // length for correct displaying of shaded objects - const gp_Pnt anAxialScale = myCamera->AxialScale(); - if (anAxialScale.X() != 1.F || - anAxialScale.Y() != 1.F || - anAxialScale.Z() != 1.F) - { - aContext->SetGlNormalizeEnabled (Standard_True); - } - else - { - aContext->SetGlNormalizeEnabled (Standard_False); - } - - // Apply Fog - if (myFog.IsOn - && aContext->core11 != NULL) - { - Standard_Real aFogFrontConverted = (Standard_Real )myFog.Front + myCamera->Distance(); - if (myCamera->ZFar() < aFogFrontConverted) - { - aFogFrontConverted = myCamera->ZFar(); - myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance()); - } - - Standard_Real aFogBackConverted = (Standard_Real )myFog.Back + myCamera->Distance(); - if (myCamera->ZFar() < aFogFrontConverted) - { - aFogBackConverted = myCamera->ZFar(); - myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance()); - } - - if (aFogFrontConverted > aFogBackConverted) - { - myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance()); - myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance()); - } - - glFogi(GL_FOG_MODE, GL_LINEAR); - glFogf(GL_FOG_START, (Standard_ShortReal )aFogFrontConverted); - glFogf(GL_FOG_END, (Standard_ShortReal )aFogBackConverted); - glFogfv(GL_FOG_COLOR, myFog.Color.rgb); - glEnable(GL_FOG); - } - else if (aContext->core11 != NULL) - { - glDisable (GL_FOG); - } - - // Apply InteriorShadingMethod - if (aContext->core11 != NULL) - { - aContext->core11->glShadeModel (myShadingModel == Visual3d_TOM_FACET - || myShadingModel == Visual3d_TOM_NONE ? GL_FLAT : GL_SMOOTH); - } -#endif - - aManager->SetShadingModel (myShadingModel); - - // Apply AntiAliasing - if (myAntiAliasing) - theWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING; - else - theWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING; - - if (!aManager->IsEmpty()) - { - aManager->UpdateClippingState(); - } - - // Redraw 3d scene - if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye) - { - aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoLeftF()); - aContext->ApplyProjectionMatrix(); - } - else if (theProjection == Graphic3d_Camera::Projection_MonoRightEye) - { - aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF()); - aContext->ApplyProjectionMatrix(); - } - RedrawScene (thePrintContext, theWorkspace, theOutputFBO, theCView, theToDrawImmediate); - - // =============================== - // Step 4: Trihedron - // =============================== - - // Resetting GL parameters according to the default aspects - // in order to synchronize GL state with the graphic driver state - // before drawing auxiliary stuff (trihedrons, overlayer) - // and invoking optional callbacks - theWorkspace->ResetAppliedAspect(); - - aContext->ChangeClipping().RemoveAll(); - - if (!aManager->IsEmpty()) - { - aManager->ResetMaterialStates(); - aManager->RevertClippingState(); - - // We need to disable (unbind) all shaders programs to ensure - // that all objects without specified aspect will be drawn - // correctly (such as background) - aContext->BindProgram (NULL); - } - - // Render trihedron - if (!theToDrawImmediate) - { - RedrawTrihedron (theWorkspace); - - // Restore face culling - if ( myBackfacing ) - { - if ( isCullFace ) - { - glEnable ( GL_CULL_FACE ); - glCullFace ( GL_BACK ); - } - else - glDisable ( GL_CULL_FACE ); - } - } - - // ============================================================== - // Step 5: Keep shader manager informed about last View - // ============================================================== - - if (!aManager.IsNull()) - { - aManager->SetLastView (this); - } -} - -// ======================================================================= -// function : InvalidateBVHData -// purpose : -// ======================================================================= -void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) -{ - myZLayers.InvalidateBVHData (theLayerId); -} - -/*----------------------------------------------------------------------*/ - -//ExecuteViewDisplay -void OpenGl_View::RenderStructs (const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate) -{ - if ( myZLayers.NbStructures() <= 0 ) - return; - - const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); - - if ( (theWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 ) - { - #if !defined(GL_ES_VERSION_2_0) - const int anAntiAliasingMode = theWorkspace->AntiAliasingMode(); - #endif - - if ( !myAntiAliasing ) - { - #if !defined(GL_ES_VERSION_2_0) - if (aCtx->core11 != NULL) - { - glDisable (GL_POINT_SMOOTH); - } - glDisable(GL_LINE_SMOOTH); - if( anAntiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH); - #endif - glBlendFunc (GL_ONE, GL_ZERO); - glDisable (GL_BLEND); - } - else - { - #if !defined(GL_ES_VERSION_2_0) - if (aCtx->core11 != NULL) - { - glEnable(GL_POINT_SMOOTH); - } - glEnable(GL_LINE_SMOOTH); - if( anAntiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH); - #endif - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - } - } - - Standard_Boolean toRenderGL = theToDrawImmediate || - theCView.RenderParams.Method != Graphic3d_RM_RAYTRACING || - myRaytraceInitStatus == OpenGl_RT_FAIL || - aCtx->IsFeedback(); - - if (!toRenderGL) - { - toRenderGL = !initRaytraceResources (theCView, aCtx) || - !updateRaytraceGeometry (OpenGl_GUM_CHECK, theWorkspace->ActiveViewId(), aCtx); - - toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL - - if (!toRenderGL) - { - const Standard_Integer aSizeX = theReadDrawFbo != NULL ? - theReadDrawFbo->GetVPSizeX() : theWorkspace->Width(); - const Standard_Integer aSizeY = theReadDrawFbo != NULL ? - theReadDrawFbo->GetVPSizeY() : theWorkspace->Height(); - - if (myOpenGlFBO.IsNull()) - myOpenGlFBO = new OpenGl_FrameBuffer; - - if (myOpenGlFBO->GetVPSizeX() != aSizeX - || myOpenGlFBO->GetVPSizeY() != aSizeY) - { - myOpenGlFBO->Init (aCtx, aSizeX, aSizeY); - } - - if (myRaytraceFilter.IsNull()) - myRaytraceFilter = new OpenGl_RaytraceFilter; - - myRaytraceFilter->SetPrevRenderFilter (theWorkspace->GetRenderFilter()); - - if (theReadDrawFbo != NULL) - theReadDrawFbo->UnbindBuffer (aCtx); - - // Prepare preliminary OpenGL output - if (aCtx->arbFBOBlit != NULL) - { - // Render bottom OSD layer - myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Bottom); - - theWorkspace->SetRenderFilter (myRaytraceFilter); - { - if (theReadDrawFbo != NULL) - { - theReadDrawFbo->BindReadBuffer (aCtx); - } - else - { - aCtx->arbFBO->glBindFramebuffer (GL_READ_FRAMEBUFFER, 0); - } - - myOpenGlFBO->BindDrawBuffer (aCtx); - - aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aSizeX, aSizeY, - 0, 0, aSizeX, aSizeY, - GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, - GL_NEAREST); - - // Render non-polygonal elements in default layer - myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Default); - } - theWorkspace->SetRenderFilter (myRaytraceFilter->PrevRenderFilter()); - } - - if (theReadDrawFbo != NULL) - { - theReadDrawFbo->BindBuffer (aCtx); - } - else - { - aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, 0); - } - - // Ray-tracing polygonal primitive arrays - raytrace (theCView, aSizeX, aSizeY, theReadDrawFbo, aCtx); - - // Render upper (top and topmost) OpenGL layers - myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_Upper); - } - } - - // Redraw 3D scene using OpenGL in standard - // mode or in case of ray-tracing failure - if (toRenderGL) - { - myZLayers.Render (theWorkspace, theToDrawImmediate, OpenGl_LF_All); - - // Set flag that scene was redrawn by standard pipeline - theCView.WasRedrawnGL = Standard_True; - } -} - -/*----------------------------------------------------------------------*/ - -void OpenGl_View::RedrawTrihedron (const Handle(OpenGl_Workspace) &theWorkspace) -{ - // display global trihedron - if (myToShowTrihedron) - { - myTrihedron.Render (theWorkspace); - } - if (myToShowGradTrihedron) - { - myGraduatedTrihedron.Render (theWorkspace); - } -} - -/*----------------------------------------------------------------------*/ - -//call_togl_create_bg_texture -void OpenGl_View::CreateBackgroundTexture (const Standard_CString theFilePath, - const Aspect_FillMethod theFillStyle) -{ - // Prepare aspect for texture storage - Handle(Graphic3d_AspectFillArea3d) anAspect = new Graphic3d_AspectFillArea3d(); - Handle(Graphic3d_Texture2Dmanual) aTextureMap = new Graphic3d_Texture2Dmanual (TCollection_AsciiString (theFilePath)); - aTextureMap->EnableRepeat(); - aTextureMap->DisableModulate(); - aTextureMap->GetParams()->SetGenMode (Graphic3d_TOTM_MANUAL, - Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f), - Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); - anAspect->SetTextureMap (aTextureMap); - anAspect->SetInteriorStyle (Aspect_IS_SOLID); - // Enable texture mapping - if (aTextureMap->IsDone()) - { - anAspect->SetTextureMapOn(); - } - else - { - anAspect->SetTextureMapOff(); - return; - - } - - // Set texture parameters - myTextureParams->SetAspect (anAspect); - - myBgTextureArray->SetTextureParameters (theFillStyle); -} - -/*----------------------------------------------------------------------*/ - -//call_togl_set_bg_texture_style -void OpenGl_View::SetBackgroundTextureStyle (const Aspect_FillMethod theFillStyle) -{ - myBgTextureArray->SetTextureFillMethod (theFillStyle); -} - -/*----------------------------------------------------------------------*/ - -//call_togl_gradient_background -void OpenGl_View::SetBackgroundGradient (const Quantity_Color& theColor1, - const Quantity_Color& theColor2, - const Aspect_GradientFillMethod theType) -{ - myBgGradientArray->SetGradientParameters (theColor1, theColor2, theType); -} - -/*----------------------------------------------------------------------*/ - -//call_togl_set_gradient_type -void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod theType) -{ - myBgGradientArray->SetGradientFillMethod (theType); -} - -//======================================================================= -//function : AddZLayer -//purpose : -//======================================================================= - -void OpenGl_View::AddZLayer (const Graphic3d_ZLayerId theLayerId) -{ - myZLayers.AddLayer (theLayerId); -} - -//======================================================================= -//function : RemoveZLayer -//purpose : -//======================================================================= - -void OpenGl_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) -{ - myZLayers.RemoveLayer (theLayerId); -} - -//======================================================================= -//function : DisplayStructure -//purpose : -//======================================================================= - -void OpenGl_View::DisplayStructure (const Handle(Graphic3d_Structure)& theStructure, - const Standard_Integer thePriority) -{ - const OpenGl_Structure* aStruct = reinterpret_cast (theStructure->CStructure().operator->()); - const Graphic3d_ZLayerId aZLayer = aStruct->ZLayer(); - myZLayers.AddStructure (aStruct, aZLayer, thePriority); -} - -//======================================================================= -//function : EraseStructure -//purpose : -//======================================================================= - -void OpenGl_View::EraseStructure (const Handle(Graphic3d_Structure)& theStructure) -{ - myZLayers.RemoveStructure (theStructure); -} - -//======================================================================= -//function : ChangeZLayer -//purpose : -//======================================================================= - -void OpenGl_View::ChangeZLayer (const OpenGl_Structure* theStructure, - const Graphic3d_ZLayerId theNewLayerId) -{ - const Graphic3d_ZLayerId anOldLayer = theStructure->ZLayer(); - myZLayers.ChangeLayer (theStructure, anOldLayer, theNewLayerId); -} - -//======================================================================= -//function : SetZLayerSettings -//purpose : -//======================================================================= -void OpenGl_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings) -{ - myZLayers.SetLayerSettings (theLayerId, theSettings); -} - -//======================================================================= -//function : ChangePriority -//purpose : -//======================================================================= -void OpenGl_View::ChangePriority (const OpenGl_Structure *theStructure, - const Standard_Integer theNewPriority) -{ - const Graphic3d_ZLayerId aLayerId = theStructure->ZLayer(); - myZLayers.ChangePriority (theStructure, aLayerId, theNewPriority); -} - -//======================================================================= -//function : RedrawScene -//purpose : -//======================================================================= - -void OpenGl_View::RedrawScene (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Handle(OpenGl_Workspace)& theWorkspace, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_CView& theCView, - const Standard_Boolean theToDrawImmediate) -{ - const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); - - if (myZClip.Back.IsOn || myZClip.Front.IsOn) - { - Handle(Graphic3d_ClipPlane) aPlaneBack; - Handle(Graphic3d_ClipPlane) aPlaneFront; - - if (myZClip.Back.IsOn) - { - Standard_Real aClipBackConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance(); - if (myCamera->ZFar() < aClipBackConverted) - { - aClipBackConverted = myCamera->ZFar(); - myZClip.Back.Limit = (Standard_ShortReal )(aClipBackConverted - myCamera->Distance()); - } - const Graphic3d_ClipPlane::Equation aBackEquation (0.0, 0.0, 1.0, (Standard_ShortReal )aClipBackConverted); - aPlaneBack = new Graphic3d_ClipPlane (aBackEquation); - } - - if (myZClip.Front.IsOn) - { - Standard_Real aClipFrontConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance(); - if (myCamera->ZNear() > aClipFrontConverted) - { - aClipFrontConverted = myCamera->ZNear(); - myZClip.Front.Limit = (Standard_ShortReal )(aClipFrontConverted - myCamera->Distance()); - } - const Graphic3d_ClipPlane::Equation aFrontEquation (0.0, 0.0, -1.0, (Standard_ShortReal )-aClipFrontConverted); - aPlaneFront = new Graphic3d_ClipPlane (aFrontEquation); - } - - // Specify slicing planes with identity transformation - if (!aPlaneBack.IsNull() || !aPlaneFront.IsNull()) - { - Graphic3d_SequenceOfHClipPlane aSlicingPlanes; - if (!aPlaneBack.IsNull()) - { - aSlicingPlanes.Append (aPlaneBack); - } - - if (!aPlaneFront.IsNull()) - { - aSlicingPlanes.Append (aPlaneFront); - } - - // add planes at loaded view matrix state - aContext->ChangeClipping().AddView (aSlicingPlanes, theWorkspace); - } - } - -#ifdef _WIN32 - // set printing scale/tiling transformation - if (!thePrintContext.IsNull()) - { - aContext->ProjectionState.Push(); - aContext->ProjectionState.SetCurrent (thePrintContext->ProjTransformation() * aContext->ProjectionState.Current()); - aContext->ApplyProjectionMatrix(); - } -#endif - - // Specify clipping planes in view transformation space - if (!myClipPlanes.IsEmpty()) - { - Graphic3d_SequenceOfHClipPlane aUserPlanes; - Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes); - for (; aClippingIt.More(); aClippingIt.Next()) - { - const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); - if (aClipPlane->IsOn()) - { - aUserPlanes.Append (aClipPlane); - } - } - - if (!aUserPlanes.IsEmpty()) - { - aContext->ChangeClipping().AddWorld (aUserPlanes); - } - - if (!aContext->ShaderManager()->IsEmpty()) - { - aContext->ShaderManager()->UpdateClippingState(); - } - } - -#if !defined(GL_ES_VERSION_2_0) - // Apply Lights - if (aContext->core11 != NULL) - { - // setup lights - Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0], - THE_DEFAULT_AMBIENT[1], - THE_DEFAULT_AMBIENT[2], - THE_DEFAULT_AMBIENT[3]); - GLenum aLightGlId = GL_LIGHT0; - for (OpenGl_ListOfLight::Iterator aLightIt (myLights); - aLightIt.More(); aLightIt.Next()) - { - bindLight (aLightIt.Value(), aLightGlId, anAmbientColor, theWorkspace); - } - - // apply accumulated ambient color - anAmbientColor.a() = 1.0f; - glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData()); - - if (aLightGlId != GL_LIGHT0) - { - glEnable (GL_LIGHTING); - } - // switch off unused lights - for (; aLightGlId <= GL_LIGHT7; ++aLightGlId) - { - glDisable (aLightGlId); - } - } -#endif - - // Clear status bitfields - theWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO); - - // Update state of surface detail level - theWorkspace->GetGlContext()->ShaderManager()->UpdateSurfaceDetailStateTo (mySurfaceDetail); - - // Added PCT for handling of textures - switch (mySurfaceDetail) - { - case Visual3d_TOD_NONE: - theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; - theWorkspace->DisableTexture(); - // Render the view - RenderStructs (theWorkspace, theReadDrawFbo, theCView, theToDrawImmediate); - break; - - case Visual3d_TOD_ENVIRONMENT: - theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; - if (theCView.RenderParams.Method != Graphic3d_RM_RAYTRACING) - { - theWorkspace->EnableTexture (myTextureEnv); - } - // Render the view - RenderStructs (theWorkspace, theReadDrawFbo, theCView, theToDrawImmediate); - theWorkspace->DisableTexture(); - break; - - case Visual3d_TOD_ALL: - // First pass - theWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX; - // Render the view - RenderStructs (theWorkspace, theReadDrawFbo, theCView, theToDrawImmediate); - theWorkspace->DisableTexture(); - - // Second pass - if (theWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) - { - theWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO; - if (theCView.RenderParams.Method != Graphic3d_RM_RAYTRACING) - { - theWorkspace->EnableTexture (myTextureEnv); - } - - // Remember OpenGl properties - GLint aSaveBlendDst = GL_ONE_MINUS_SRC_ALPHA, aSaveBlendSrc = GL_SRC_ALPHA; - GLint aSaveZbuffFunc; - GLboolean aSaveZbuffWrite; - glGetBooleanv (GL_DEPTH_WRITEMASK, &aSaveZbuffWrite); - glGetIntegerv (GL_DEPTH_FUNC, &aSaveZbuffFunc); - #if !defined(GL_ES_VERSION_2_0) - glGetIntegerv (GL_BLEND_DST, &aSaveBlendDst); - glGetIntegerv (GL_BLEND_SRC, &aSaveBlendSrc); - #endif - GLboolean wasZbuffEnabled = glIsEnabled (GL_DEPTH_TEST); - GLboolean wasBlendEnabled = glIsEnabled (GL_BLEND); - - // Change the properties for second rendering pass - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - - glDepthFunc (GL_EQUAL); - glDepthMask (GL_FALSE); - glEnable (GL_DEPTH_TEST); - - theWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; - - // Render the view - RenderStructs (theWorkspace, theReadDrawFbo, theCView, theToDrawImmediate); - theWorkspace->DisableTexture(); - - // Restore properties back - glBlendFunc (aSaveBlendSrc, aSaveBlendDst); - if (!wasBlendEnabled) - glDisable (GL_BLEND); - - glDepthFunc (aSaveZbuffFunc); - glDepthMask (aSaveZbuffWrite); - if (!wasZbuffEnabled) - glDisable (GL_DEPTH_FUNC); - } - break; - } - - // Apply restored view matrix. - aContext->ApplyWorldViewMatrix(); - -#ifdef _WIN32 - // set printing scale/tiling transformation - if (!thePrintContext.IsNull()) - { - aContext->ProjectionState.Pop(); - aContext->ApplyProjectionMatrix(); - } -#endif - -} diff --git a/src/OpenGl/OpenGl_Workspace_2.cxx b/src/OpenGl/OpenGl_View_Print.cxx similarity index 82% rename from src/OpenGl/OpenGl_Workspace_2.cxx rename to src/OpenGl/OpenGl_View_Print.cxx index cbf0b56742..93b9db1cdb 100644 --- a/src/OpenGl/OpenGl_Workspace_2.cxx +++ b/src/OpenGl/OpenGl_View_Print.cxx @@ -24,6 +24,8 @@ #include #include +#include + #if (defined(_WIN32) || defined(__WIN32__)) && defined(HAVE_FREEIMAGE) #include #include @@ -38,10 +40,10 @@ #ifndef HAVE_FREEIMAGE -// --------------------------------------------------------------- -// Function: initBitmapBuffer -// Purpose: init device independent bitmap to hold printing data -// --------------------------------------------------------------- + // ======================================================================= +// function : initBitmapBuffer +// purpose : init device independent bitmap to hold printing data +// ======================================================================= static void initBitmapBuffer (const HDC theMemoryDC, HBITMAP &theMemoryBmp, const Standard_Integer theBmpWidth, @@ -70,10 +72,10 @@ static void initBitmapBuffer (const HDC theMemoryDC, #else /* HAVE_FREEIMAGE */ -// --------------------------------------------------------------- -// Function: imagePasteDC -// Purpose: copy the data from image buffer to the device context -// --------------------------------------------------------------- +// ======================================================================= +// function : imagePasteDC +// purpose : copy the data from image buffer to the device context +// ======================================================================= static bool imagePasteDC(HDC theDstDC, FipHandle theImage, int theOffsetX, int theOffsetY, int theWidth, int theHeight, int theLeft = 0, int theTop = 0) @@ -133,10 +135,10 @@ static bool imagePasteDC(HDC theDstDC, FipHandle theImage, int theOffsetX, return true; } -// --------------------------------------------------------------- -// Function: imageStretchDC -// Purpose: copy pixels from image to dc by stretching them -// --------------------------------------------------------------- +// ======================================================================= +// function : imageStretchDC +// purpose : copy pixels from image to dc by stretching them +// ======================================================================= static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX, int theOffsetY, int theWidth, int theHeight) { @@ -165,10 +167,10 @@ static bool imageStretchDC(HDC theDstDC, FipHandle theImage, int theOffsetX, #endif /* HAVE_FREEIMAGE */ -// --------------------------------------------------------------- -// Function: getNearestPowOfTwo -// Purpose: get the nearest power of two for theNumber -// --------------------------------------------------------------- +// ======================================================================= +// function : getNearestPowOfTwo +// purpose : get the nearest power of two for theNumber +// ======================================================================= static GLsizei getNearestPowOfTwo (const GLsizei theNumber) { GLsizei aLast = 1; @@ -176,10 +178,10 @@ static GLsizei getNearestPowOfTwo (const GLsizei theNumber) return aLast; } -// --------------------------------------------------------------- -// Function: getMaxFrameSize -// Purpose: get the maximum possible frame size -// --------------------------------------------------------------- +// ======================================================================= +// function : getMaxFrameSize +// purpose : get the maximum possible frame size +// ======================================================================= static void getMaxFrameSize(Standard_Integer& theWidth, Standard_Integer& theHeight) { @@ -197,11 +199,11 @@ static void getMaxFrameSize(Standard_Integer& theWidth, theHeight = (Standard_Integer)aMaxY; } -// --------------------------------------------------------------- -// Function: fitDimensionsRatio -// Purpose: calculate correct width/height ratio for theWidth and -// theHeight parameters -// --------------------------------------------------------------- +// ======================================================================= +// function : fitDimensionsRatio +// purpose : calculate correct width/height ratio for theWidth and +// theHeight parameters +// ======================================================================= static void fitDimensionsRatio (Standard_Integer& theWidth, Standard_Integer& theHeight, const Standard_Real theViewRatio) @@ -214,11 +216,11 @@ static void fitDimensionsRatio (Standard_Integer& theWidth, theHeight = (Standard_Integer)(theWidth/theViewRatio); } -// --------------------------------------------------------------- -// Function: initBufferStretch -// Purpose: calculate initialization sizes for frame buffer -// when the stretch algorithm is selected -// --------------------------------------------------------------- +// ======================================================================= +// function : initBufferStretch +// purpose : calculate initialization sizes for frame buffer +// when the stretch algorithm is selected +// ======================================================================= static void initBufferStretch (Standard_Integer& theFrameWidth, Standard_Integer& theFrameHeight, const int theViewWidth, @@ -246,11 +248,12 @@ static void initBufferStretch (Standard_Integer& theFrameWidth, theFrameHeight = (Standard_Integer)(theFrameHeight/aHeightRate); } } -// --------------------------------------------------------------- -// Function: initBufferTiling -// Purpose: calculate initialization sizes for frame buffer -// when the tile algorithm is selected -// --------------------------------------------------------------- + +// ======================================================================= +// function : initBufferTiling +// purpose : calculate initialization sizes for frame buffer +// when the tile algorithm is selected +// ======================================================================= static void initBufferTiling (Standard_Integer& theFrameWidth, Standard_Integer &theFrameHeight, const int theViewWidth, @@ -266,36 +269,28 @@ static void initBufferTiling (Standard_Integer& theFrameWidth, #endif /* _WIN32 */ -// --------------------------------------------------------------- -// --------------------------------------------------------------- - -//call_togl_print - -Standard_Boolean OpenGl_Workspace::Print - (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Graphic3d_CView& ACView, - const Aspect_Handle hPrintDC,// const Aspect_Drawable hPrintDC, - const Standard_Boolean showBackground, - const Standard_CString filename, - const Aspect_PrintAlgo printAlgorithm, - const Standard_Real theScaleFactor) +// ======================================================================= +// function : Print +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_View::Print (const Aspect_Handle thePrinterDC, + const Standard_Boolean theToShowBackground, + const Standard_CString theFileName, + const Aspect_PrintAlgo thePrintAlgorithm, + const Standard_Real theScaleFactor) { - if (thePrintContext.IsNull()) - { - return Standard_False; - } - #ifdef _WIN32 - - if (!Activate()) + if (!myWorkspace->Activate()) { //MessageBox (NULL, "Print failed: can't setup the view for printing.", // "The operation couldn't be completed.", MB_OK); return Standard_False; } + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + // printer page dimensions - HDC hPrnDC = (HDC) hPrintDC; + HDC hPrnDC = (HDC) thePrinterDC; int devWidth = GetDeviceCaps (hPrnDC, HORZRES); int devHeight = GetDeviceCaps (hPrnDC, VERTRES); @@ -318,8 +313,8 @@ Standard_Boolean OpenGl_Workspace::Print Standard_Integer tempHeight = (Standard_Integer) devHeight; // view dimensions - int viewWidth = myWidth; - int viewHeight = myHeight; + int viewWidth = myWindow->Width(); + int viewHeight = myWindow->Height(); if (viewWidth == 0 || viewHeight == 0) { //MessageBox (NULL, "Print failed: can't setup the view for printing.", @@ -348,11 +343,11 @@ Standard_Boolean OpenGl_Workspace::Print // Frame buffer initialization OpenGl_FrameBuffer* aFrameBuffer = NULL; - OpenGl_FrameBuffer* aPrevBuffer = (OpenGl_FrameBuffer*) ACView.ptrFBO; + OpenGl_FrameBuffer* aPrevBuffer = (OpenGl_FrameBuffer*)myFBO; Standard_Integer aFrameWidth (0), aFrameHeight (0), aPrevBufferX (0), aPrevBufferY (0); - bool IsTiling = (printAlgorithm == 1); + bool IsTiling = (thePrintAlgorithm == Aspect_PA_TILE); // try to use existing frame buffer if (aPrevBuffer) @@ -384,7 +379,7 @@ Standard_Boolean OpenGl_Workspace::Print fipImage* anImagePtr = new fipImage (FIT_BITMAP, aFrameWidth, aFrameHeight, 24); - // if allocated succesfully + // if allocated successfully if (anImagePtr->isValid()) { aViewImage = anImagePtr; @@ -445,14 +440,14 @@ Standard_Boolean OpenGl_Workspace::Print initBufferTiling (aFrameWidth, aFrameHeight, width, height); // try to initialize framebuffer - if (aFrameBuffer->Init (GetGlContext(), aFrameWidth, aFrameHeight)) + if (aFrameBuffer->Init (aCtx, aFrameWidth, aFrameHeight)) { #ifdef HAVE_FREEIMAGE // try to allocate fipImage and necessary resources fipImage* anImagePtr = new fipImage (FIT_BITMAP, aFrameWidth, aFrameHeight, 24); - // if allocated succesfully + // if allocated successfully if (anImagePtr->isValid()) { aViewImage = anImagePtr; @@ -463,7 +458,7 @@ Standard_Boolean OpenGl_Workspace::Print if (!aViewBuffer) { - aFrameBuffer->Release (GetGlContext().operator->()); + aFrameBuffer->Release (aCtx.operator->()); aViewBuffer = NULL; aViewImage = NULL; } @@ -477,7 +472,7 @@ Standard_Boolean OpenGl_Workspace::Print { if (hViewBitmap) DeleteObject (hViewBitmap); - aFrameBuffer->Release (GetGlContext().operator->()); + aFrameBuffer->Release (aCtx.operator->()); hViewBitmap = NULL; } else @@ -497,7 +492,7 @@ Standard_Boolean OpenGl_Workspace::Print if (aMaxWidth <= 1 || aMaxHeight <= 1) { MessageBox (NULL, "Print failed: can't allocate buffer for printing.", - "The operation couldn't be completed.", MB_OK); + "The operation couldn't be completed.", MB_OK); if (aFrameBuffer) delete aFrameBuffer; @@ -511,11 +506,10 @@ Standard_Boolean OpenGl_Workspace::Print } // setup printing context and viewport - myPrintContext = thePrintContext; + myWorkspace->PrinterContext() = new OpenGl_PrinterContext(); + myWorkspace->PrinterContext()->SetLayerViewport ((GLsizei )aFrameWidth, (GLsizei )aFrameHeight); GLint aViewPortBack[4]; GLint anAlignBack = 1; - myPrintContext->SetLayerViewport ((GLsizei )aFrameWidth, - (GLsizei )aFrameHeight); glGetIntegerv (GL_VIEWPORT, aViewPortBack); glGetIntegerv (GL_PACK_ALIGNMENT, &anAlignBack); glPixelStorei (GL_PACK_ALIGNMENT, 4); @@ -525,10 +519,10 @@ Standard_Boolean OpenGl_Workspace::Print DOCINFO di; if (GetObjectType (hPrnDC) == OBJ_DC) { - // Initalize printing procedure + // Initialize printing procedure di.cbSize = sizeof(DOCINFO); di.lpszDocName = "Open Cascade Document - print v3d view"; - di.lpszOutput = filename; + di.lpszOutput = theFileName; // if can't print the document if (StartDoc (hPrnDC, &di) <= 0 || StartPage (hPrnDC) <= 0) @@ -544,7 +538,7 @@ Standard_Boolean OpenGl_Workspace::Print DeleteDC (hMemDC); #endif - myPrintContext.Nullify(); + myWorkspace->PrinterContext().Nullify(); return Standard_False; } } @@ -557,24 +551,25 @@ Standard_Boolean OpenGl_Workspace::Print bool isDone = true; // Set up status for printing - if (!showBackground) - NamedStatus |= OPENGL_NS_WHITEBACK; + if (!theToShowBackground) + { + myWorkspace->NamedStatus |= OPENGL_NS_WHITEBACK; + } // switch to mono camera for image dump - const Graphic3d_Camera::Projection aProjectType = myView->Camera()->ProjectionType() != Graphic3d_Camera::Projection_Stereo - ? myView->Camera()->ProjectionType() + const Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType() != Graphic3d_Camera::Projection_Stereo + ? myCamera->ProjectionType() : Graphic3d_Camera::Projection_Perspective; if (!IsTiling) { - myPrintContext->SetScale ((GLfloat )aFrameWidth /viewWidth, - (GLfloat )aFrameHeight/viewHeight); - redraw1 (ACView, aFrameBuffer, aProjectType); + myWorkspace->PrinterContext()->SetScale ((GLfloat )aFrameWidth /viewWidth, (GLfloat )aFrameHeight/viewHeight); + redraw (aProjectType, aFrameBuffer); if (!myTransientDrawToFront) { // render to FBO only if allowed to render to back buffer myBackBufferRestored = Standard_True; myIsImmediateDrawn = Standard_False; - redrawImmediate (ACView, NULL, aProjectType, aFrameBuffer); + redrawImmediate (aProjectType, NULL, aFrameBuffer); myBackBufferRestored = Standard_False; myIsImmediateDrawn = Standard_False; } @@ -631,8 +626,7 @@ Standard_Boolean OpenGl_Workspace::Print // calculate and set the text scaling factor for printing context GLfloat aScaleRatex = (GLfloat)aFrameWidth /viewWidth; GLfloat aScaleRatey = (GLfloat)aFrameHeight/viewHeight; - myPrintContext->SetScale (aScaleRatex * (GLfloat )aScalex, - aScaleRatey * (GLfloat )aScaley); + myWorkspace->PrinterContext()->SetScale (aScaleRatex * (GLfloat )aScalex, aScaleRatey * (GLfloat )aScaley); // initialize projection matrix for printer context TColStd_Array2OfReal aProj (0, 3, 0, 3); @@ -674,7 +668,7 @@ Standard_Boolean OpenGl_Workspace::Print // set projection matrix aProj(0,0) = aScalex; aProj(1,1) = aScaley; - myPrintContext->SetProjTransformation (aProj); + myWorkspace->PrinterContext()->SetProjTransformation (aProj); // calculate cropped frame rect aTop = (j == 0) ? aPxCropy : 0; @@ -682,13 +676,13 @@ Standard_Boolean OpenGl_Workspace::Print aFrameHeight; // draw to the offscreen buffer and capture the result - redraw1 (ACView, aFrameBuffer, aProjectType); + redraw (aProjectType, aFrameBuffer); if (!myTransientDrawToFront) { // render to FBO only if forces to render to back buffer myBackBufferRestored = Standard_True; myIsImmediateDrawn = Standard_False; - redrawImmediate (ACView, NULL, aProjectType, aFrameBuffer); + redrawImmediate (aProjectType, NULL, aFrameBuffer); myBackBufferRestored = Standard_False; myIsImmediateDrawn = Standard_False; } @@ -738,7 +732,7 @@ Standard_Boolean OpenGl_Workspace::Print // return OpenGl to the previous state glPixelStorei (GL_PACK_ALIGNMENT, anAlignBack); - aFrameBuffer->UnbindBuffer (GetGlContext()); + aFrameBuffer->UnbindBuffer (aCtx); glViewport (aViewPortBack[0], aViewPortBack[1], aViewPortBack[2], aViewPortBack[3]); if (aPrevBuffer) @@ -747,7 +741,7 @@ Standard_Boolean OpenGl_Workspace::Print } else { - aFrameBuffer->Release (GetGlContext().operator->()); + aFrameBuffer->Release (aCtx.operator->()); delete aFrameBuffer; } @@ -762,13 +756,13 @@ Standard_Boolean OpenGl_Workspace::Print #endif // Reset status after printing - NamedStatus &= ~OPENGL_NS_WHITEBACK; - - myPrintContext.Nullify(); + myWorkspace->NamedStatus &= ~OPENGL_NS_WHITEBACK; + myWorkspace->PrinterContext().Nullify(); return (Standard_Boolean) isDone; #else // not _WIN32 - myPrintContext.Nullify(); + Standard_NotImplemented::Raise ("OpenGl_View::Print is implemented only on Windows"); + myWorkspace->PrinterContext().Nullify(); return Standard_False; #endif } diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index 9cceefb265..6c4b1979f0 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -13,14 +13,11 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include +#include -#include +#include #include #include -#include -#include - #include #include @@ -1234,7 +1231,7 @@ Handle(OpenGl_ShaderProgram) OpenGl_View::initProgram (const Handle(OpenGl_Conte // function : initRaytraceResources // purpose : Initializes OpenGL/GLSL shader programs // ======================================================================= -Standard_Boolean OpenGl_View::initRaytraceResources (const Graphic3d_CView& theCView, const Handle(OpenGl_Context)& theGlContext) +Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context)& theGlContext) { if (myRaytraceInitStatus == OpenGl_RT_FAIL) { @@ -1269,9 +1266,9 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Graphic3d_CView& theC } } - if (theCView.RenderParams.RaytracingDepth != myRaytraceParameters.NbBounces) + if (myRenderParams.RaytracingDepth != myRaytraceParameters.NbBounces) { - myRaytraceParameters.NbBounces = theCView.RenderParams.RaytracingDepth; + myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth; aToRebuildShaders = Standard_True; } @@ -1281,15 +1278,15 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Graphic3d_CView& theC aToRebuildShaders = Standard_True; } - if (theCView.RenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows) + if (myRenderParams.IsTransparentShadowEnabled != myRaytraceParameters.TransparentShadows) { - myRaytraceParameters.TransparentShadows = theCView.RenderParams.IsTransparentShadowEnabled; + myRaytraceParameters.TransparentShadows = myRenderParams.IsTransparentShadowEnabled; aToRebuildShaders = Standard_True; } - if (theCView.RenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination) + if (myRenderParams.IsGlobalIlluminationEnabled != myRaytraceParameters.GlobalIllumination) { - myRaytraceParameters.GlobalIllumination = theCView.RenderParams.IsGlobalIlluminationEnabled; + myRaytraceParameters.GlobalIllumination = myRenderParams.IsGlobalIlluminationEnabled; aToRebuildShaders = Standard_True; } @@ -1347,7 +1344,7 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Graphic3d_CView& theC return safeFailBack ("Ray-tracing requires EXT_framebuffer_blit extension", theGlContext); } - myRaytraceParameters.NbBounces = theCView.RenderParams.RaytracingDepth; + myRaytraceParameters.NbBounces = myRenderParams.RaytracingDepth; TCollection_AsciiString aFolder = Graphic3d_ShaderProgram::ShadersFolder(); @@ -2071,11 +2068,12 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the myRaytraceGeometry.Ambient = BVH_Vec4f (0.0f, 0.0f, 0.0f, 0.0f); - for (OpenGl_ListOfLight::Iterator aLightIter (myLights); aLightIter.More(); aLightIter.Next()) + OpenGl_ListOfLight::Iterator aLightIter (myShadingModel == Graphic3d_TOSM_NONE ? OpenGl_NoShadingLight() : myLights); + for (; aLightIter.More(); aLightIter.Next()) { const OpenGl_Light& aLight = aLightIter.Value(); - if (aLight.Type == Visual3d_TOLS_AMBIENT) + if (aLight.Type == Graphic3d_TOLS_AMBIENT) { myRaytraceGeometry.Ambient += BVH_Vec4f (aLight.Color.r() * aLight.Intensity, aLight.Color.g() * aLight.Intensity, @@ -2094,7 +2092,7 @@ Standard_Boolean OpenGl_View::updateRaytraceLightSources (const OpenGl_Mat4& the -aLight.Direction.z(), 0.0f); - if (aLight.Type != Visual3d_TOLS_DIRECTIONAL) + if (aLight.Type != Graphic3d_TOLS_DIRECTIONAL) { aPosition = BVH_Vec4f (aLight.Position.x(), aLight.Position.y(), @@ -2168,7 +2166,7 @@ Standard_Boolean OpenGl_View::updateRaytraceEnvironmentMap (const Handle(OpenGl_ { aResult &= theGlContext->BindProgram (aProgram); - if (!myTextureEnv.IsNull() && mySurfaceDetail != Visual3d_TOD_NONE) + if (!myTextureEnv.IsNull() && mySurfaceDetail != Graphic3d_TOD_NONE) { myTextureEnv->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_EnvironmentMapTexture); @@ -2195,8 +2193,7 @@ Standard_Boolean OpenGl_View::updateRaytraceEnvironmentMap (const Handle(OpenGl_ // function : setUniformState // purpose : Sets uniform state for the given ray-tracing shader program // ======================================================================= -Standard_Boolean OpenGl_View::setUniformState (const Graphic3d_CView& theCView, - const OpenGl_Vec3* theOrigins, +Standard_Boolean OpenGl_View::setUniformState (const OpenGl_Vec3* theOrigins, const OpenGl_Vec3* theDirects, const OpenGl_Mat4& theUnviewMat, const Standard_Integer theProgramId, @@ -2245,14 +2242,14 @@ Standard_Boolean OpenGl_View::setUniformState (const Graphic3d_CView& the // Set run-time rendering options theProgram->SetUniform (theGlContext, - myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], theCView.RenderParams.IsShadowEnabled ? 1 : 0); + myUniformLocations[theProgramId][OpenGl_RT_uShadowsEnabled], myRenderParams.IsShadowEnabled ? 1 : 0); theProgram->SetUniform (theGlContext, - myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], theCView.RenderParams.IsReflectionEnabled ? 1 : 0); + myUniformLocations[theProgramId][OpenGl_RT_uReflectEnabled], myRenderParams.IsReflectionEnabled ? 1 : 0); - if (theCView.RenderParams.IsGlobalIlluminationEnabled) + if (myRenderParams.IsGlobalIlluminationEnabled) { theProgram->SetUniform (theGlContext, - myUniformLocations[theProgramId][OpenGl_RT_uBlockedRngEnabled], theCView.RenderParams.CoherentPathTracingMode ? 1 : 0); + myUniformLocations[theProgramId][OpenGl_RT_uBlockedRngEnabled], myRenderParams.CoherentPathTracingMode ? 1 : 0); } // Set array of 64-bit texture handles @@ -2275,9 +2272,9 @@ Standard_Boolean OpenGl_View::setUniformState (const Graphic3d_CView& the } else { - const OpenGl_Vec4 aBackColor (theCView.DefWindow.Background.r, - theCView.DefWindow.Background.g, - theCView.DefWindow.Background.b, + const OpenGl_Vec4 aBackColor (myBgColor.rgb[0], + myBgColor.rgb[1], + myBgColor.rgb[2], 1.0f); theProgram->SetUniform (theGlContext, myUniformLocations[theProgramId][OpenGl_RT_uBackColorTop], aBackColor); @@ -2286,7 +2283,7 @@ Standard_Boolean OpenGl_View::setUniformState (const Graphic3d_CView& the } theProgram->SetUniform (theGlContext, - myUniformLocations[theProgramId][OpenGl_RT_uSphereMapForBack], theCView.RenderParams.UseEnvironmentMapBackground ? 1 : 0); + myUniformLocations[theProgramId][OpenGl_RT_uSphereMapForBack], myRenderParams.UseEnvironmentMapBackground ? 1 : 0); return Standard_True; } @@ -2345,8 +2342,7 @@ void OpenGl_View::unbindRaytraceTextures (const Handle(OpenGl_Context)& theGlCon // function : runRaytraceShaders // purpose : Runs ray-tracing shader programs // ======================================================================= -Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& theCView, - const Standard_Integer theSizeX, +Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer theSizeX, const Standard_Integer theSizeY, const OpenGl_Vec3* theOrigins, const OpenGl_Vec3* theDirects, @@ -2381,7 +2377,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& aRenderFramebuffer->BindBuffer (theGlContext); } - else if (theCView.RenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used + else if (myRenderParams.IsAntialiasingEnabled) // if 2-pass ray-tracing is used { myRaytraceFBO1->BindBuffer (theGlContext); @@ -2390,8 +2386,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& Standard_Boolean aResult = theGlContext->BindProgram (myRaytraceProgram); - aResult &= setUniformState (theCView, - theOrigins, + aResult &= setUniformState (theOrigins, theDirects, theUnviewMat, 0, // ID of RT program @@ -2438,14 +2433,13 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& ++myAccumFrames; } - else if (theCView.RenderParams.IsAntialiasingEnabled) + else if (myRenderParams.IsAntialiasingEnabled) { myRaytraceFBO1->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture); aResult &= theGlContext->BindProgram (myPostFSAAProgram); - aResult &= setUniformState (theCView, - theOrigins, + aResult &= setUniformState (theOrigins, theDirects, theUnviewMat, 1, // ID of FSAA program @@ -2521,13 +2515,12 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& // function : raytrace // purpose : Redraws the window using OpenGL/GLSL ray-tracing // ======================================================================= -Standard_Boolean OpenGl_View::raytrace (const Graphic3d_CView& theCView, - const Standard_Integer theSizeX, +Standard_Boolean OpenGl_View::raytrace (const Standard_Integer theSizeX, const Standard_Integer theSizeY, OpenGl_FrameBuffer* theReadDrawFbo, const Handle(OpenGl_Context)& theGlContext) { - if (!initRaytraceResources (theCView, theGlContext)) + if (!initRaytraceResources (theGlContext)) { return Standard_False; } @@ -2582,8 +2575,7 @@ Standard_Boolean OpenGl_View::raytrace (const Graphic3d_CView& theCView, 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, "Error: Failed to acquire OpenGL image textures"); } - Standard_Boolean aResult = runRaytraceShaders (theCView, - theSizeX, + Standard_Boolean aResult = runRaytraceShaders (theSizeX, theSizeY, aOrigins, aDirects, diff --git a/src/OpenGl/OpenGl_View_Redraw.cxx b/src/OpenGl/OpenGl_View_Redraw.cxx new file mode 100644 index 0000000000..31ea1d6e9d --- /dev/null +++ b/src/OpenGl/OpenGl_View_Redraw.cxx @@ -0,0 +1,1781 @@ +// Created on: 2011-09-20 +// Created by: Sergey ZERCHANINOV +// Copyright (c) 2011-2014 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define EPSI 0.0001 + +namespace +{ + static const GLfloat THE_DEFAULT_AMBIENT[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + static const GLfloat THE_DEFAULT_SPOT_DIR[3] = { 0.0f, 0.0f, -1.0f }; + static const GLfloat THE_DEFAULT_SPOT_EXPONENT = 0.0f; + static const GLfloat THE_DEFAULT_SPOT_CUTOFF = 180.0f; +} + +extern void InitLayerProp (const int theListId); //szvgl: defined in OpenGl_GraphicDriver_Layer.cxx + +#if !defined(GL_ES_VERSION_2_0) + +//======================================================================= +//function : bindLight +//purpose : +//======================================================================= +static void bindLight (const OpenGl_Light& theLight, + GLenum& theLightGlId, + Graphic3d_Vec4& theAmbientColor, + const Handle(OpenGl_Workspace)& theWorkspace) +{ + // Only 8 lights in OpenGL... + if (theLightGlId > GL_LIGHT7) + { + return; + } + + if (theLight.Type == Graphic3d_TOLS_AMBIENT) + { + // add RGBA intensity of the ambient light + theAmbientColor += theLight.Color; + return; + } + + const Handle(OpenGl_Context)& aContext = theWorkspace->GetGlContext(); + + // the light is a headlight? + if (theLight.IsHeadlight) + { + aContext->WorldViewState.Push(); + aContext->WorldViewState.SetIdentity(); + + aContext->ApplyWorldViewMatrix(); + } + + // setup light type + switch (theLight.Type) + { + case Graphic3d_TOLS_AMBIENT : break; // handled by separate if-clause at beginning of method + case Graphic3d_TOLS_DIRECTIONAL: + { + // if the last parameter of GL_POSITION, is zero, the corresponding light source is a Directional one + const OpenGl_Vec4 anInfDir = -theLight.Direction; + + // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE. + glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); + glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_POSITION, anInfDir.GetData()); + glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR); + glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT); + glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF); + break; + } + case Graphic3d_TOLS_POSITIONAL: + { + // to create a realistic effect, set the GL_SPECULAR parameter to the same value as the GL_DIFFUSE + glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); + glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData()); + glLightfv (theLightGlId, GL_SPOT_DIRECTION, THE_DEFAULT_SPOT_DIR); + glLightf (theLightGlId, GL_SPOT_EXPONENT, THE_DEFAULT_SPOT_EXPONENT); + glLightf (theLightGlId, GL_SPOT_CUTOFF, THE_DEFAULT_SPOT_CUTOFF); + glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation()); + glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation()); + glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0); + break; + } + case Graphic3d_TOLS_SPOT: + { + glLightfv (theLightGlId, GL_AMBIENT, THE_DEFAULT_AMBIENT); + glLightfv (theLightGlId, GL_DIFFUSE, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_SPECULAR, theLight.Color.GetData()); + glLightfv (theLightGlId, GL_POSITION, theLight.Position.GetData()); + glLightfv (theLightGlId, GL_SPOT_DIRECTION, theLight.Direction.GetData()); + glLightf (theLightGlId, GL_SPOT_EXPONENT, theLight.Concentration() * 128.0f); + glLightf (theLightGlId, GL_SPOT_CUTOFF, (theLight.Angle() * 180.0f) / GLfloat(M_PI)); + glLightf (theLightGlId, GL_CONSTANT_ATTENUATION, theLight.ConstAttenuation()); + glLightf (theLightGlId, GL_LINEAR_ATTENUATION, theLight.LinearAttenuation()); + glLightf (theLightGlId, GL_QUADRATIC_ATTENUATION, 0.0f); + break; + } + } + + // restore matrix in case of headlight + if (theLight.IsHeadlight) + { + aContext->WorldViewState.Pop(); + } + + glEnable (theLightGlId++); +} +#endif + +//======================================================================= +//function : DrawBackground +//purpose : +//======================================================================= +void OpenGl_View::DrawBackground (const Handle(OpenGl_Workspace)& theWorkspace) +{ + const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext(); + + if ((theWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) != 0 // no background + || (!myBgTextureArray->IsDefined() // no texture + && !myBgGradientArray->IsDefined())) // no gradient + { + return; + } + + const Standard_Boolean wasUsedZBuffer = theWorkspace->SetUseZBuffer (Standard_False); + if (wasUsedZBuffer) + { + aCtx->core11fwd->glDisable (GL_DEPTH_TEST); + } + + aCtx->ProjectionState.Push(); + aCtx->WorldViewState.Push(); + aCtx->ModelWorldState.Push(); + aCtx->ProjectionState.SetIdentity(); + aCtx->WorldViewState.SetIdentity(); + aCtx->ModelWorldState.SetIdentity(); + aCtx->ApplyProjectionMatrix(); + aCtx->ApplyModelViewMatrix(); + + // Drawing background gradient if: + // - gradient fill type is not Aspect_GFM_NONE and + // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode + if (myBgGradientArray->IsDefined() + && (!myTextureParams->DoTextureMap() + || myBgTextureArray->TextureFillMethod() == Aspect_FM_CENTERED + || myBgTextureArray->TextureFillMethod() == Aspect_FM_NONE)) + { + #if !defined(GL_ES_VERSION_2_0) + GLint aShadingModelOld = GL_SMOOTH; + if (aCtx->core11 != NULL) + { + aCtx->core11fwd->glDisable (GL_LIGHTING); + aCtx->core11fwd->glGetIntegerv (GL_SHADE_MODEL, &aShadingModelOld); + aCtx->core11->glShadeModel (GL_SMOOTH); + } + #endif + + if (myBgGradientArray->IsDataChanged()) + { + myBgGradientArray->Init (theWorkspace); + } + + myBgGradientArray->Render (theWorkspace); + + #if !defined(GL_ES_VERSION_2_0) + if (aCtx->core11 != NULL) + { + aCtx->core11->glShadeModel (aShadingModelOld); + } + #endif + } + + // Drawing background image if it is defined + // (texture is defined and fill type is not Aspect_FM_NONE) + if (myBgTextureArray->IsDefined() + && myTextureParams->DoTextureMap()) + { + aCtx->core11fwd->glDisable (GL_BLEND); + + const OpenGl_AspectFace* anOldAspectFace = theWorkspace->SetAspectFace (myTextureParams); + + if (myBgTextureArray->IsDataChanged() + || myBgTextureArray->IsViewSizeChanged (theWorkspace)) + { + myBgTextureArray->Init (theWorkspace); + } + + myBgTextureArray->Render (theWorkspace); + + // restore aspects + theWorkspace->SetAspectFace (anOldAspectFace); + } + + aCtx->ModelWorldState.Pop(); + aCtx->WorldViewState.Pop(); + aCtx->ProjectionState.Pop(); + aCtx->ApplyProjectionMatrix(); + aCtx->ApplyModelViewMatrix(); + + if (wasUsedZBuffer) + { + theWorkspace->SetUseZBuffer (Standard_True); + aCtx->core11fwd->glEnable (GL_DEPTH_TEST); + } +} + +//======================================================================= +//function : Redraw +//purpose : +//======================================================================= +void OpenGl_View::Redraw() +{ + if (myRenderParams.Method == Graphic3d_RM_RAYTRACING + && !myCaps->vboDisable + && !myCaps->keepArrayData) + { + if (myWasRedrawnGL) + { + myDeviceLostFlag = Standard_True; + } + + myCaps->keepArrayData = Standard_True; + } + + if (!myWorkspace->Activate()) + { + return; + } + + myWindow->SetSwapInterval(); + + ++myFrameCounter; + const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode; + Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType(); + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + + // release pending GL resources + aCtx->ReleaseDelayed(); + + // fetch OpenGl context state + aCtx->FetchState(); + + OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )myFBO; + bool toSwap = aCtx->IsRender() + && !aCtx->caps->buffersNoSwap + && aFrameBuffer == NULL; + + Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWindow->Width(); + Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myWindow->Height(); + + if ( aFrameBuffer == NULL + && !aCtx->DefaultFrameBuffer().IsNull() + && aCtx->DefaultFrameBuffer()->IsValid()) + { + aFrameBuffer = aCtx->DefaultFrameBuffer().operator->(); + } + + if (myHasFboBlit + && (myTransientDrawToFront || aProjectType == Graphic3d_Camera::Projection_Stereo)) + { + if (myMainSceneFbos[0]->GetVPSizeX() != aSizeX + || myMainSceneFbos[0]->GetVPSizeY() != aSizeY) + { + // prepare FBOs containing main scene + // for further blitting and rendering immediate presentations on top + if (aCtx->core20fwd != NULL) + { + myMainSceneFbos[0]->Init (aCtx, aSizeX, aSizeY); + } + if (!aCtx->caps->useSystemBuffer && myMainSceneFbos[0]->IsValid()) + { + myImmediateSceneFbos[0]->InitLazy (aCtx, aSizeX, aSizeY); + } + } + } + else + { + myMainSceneFbos [0]->Release (aCtx.operator->()); + myMainSceneFbos [1]->Release (aCtx.operator->()); + myImmediateSceneFbos[0]->Release (aCtx.operator->()); + myImmediateSceneFbos[1]->Release (aCtx.operator->()); + myMainSceneFbos [0]->ChangeViewport (0, 0); + myMainSceneFbos [1]->ChangeViewport (0, 0); + myImmediateSceneFbos[0]->ChangeViewport (0, 0); + myImmediateSceneFbos[1]->ChangeViewport (0, 0); + } + + if (aProjectType == Graphic3d_Camera::Projection_Stereo + && myMainSceneFbos[0]->IsValid()) + { + myMainSceneFbos[1]->InitLazy (aCtx, aSizeX, aSizeY); + if (!myMainSceneFbos[1]->IsValid()) + { + // no enough memory? + aProjectType = Graphic3d_Camera::Projection_Perspective; + } + else if (!myTransientDrawToFront) + { + // + } + else if (!aCtx->HasStereoBuffers() || aStereoMode != Graphic3d_StereoMode_QuadBuffer) + { + myImmediateSceneFbos[0]->InitLazy (aCtx, aSizeX, aSizeY); + myImmediateSceneFbos[1]->InitLazy (aCtx, aSizeX, aSizeY); + if (!myImmediateSceneFbos[0]->IsValid() + || !myImmediateSceneFbos[1]->IsValid()) + { + aProjectType = Graphic3d_Camera::Projection_Perspective; + } + } + } + + if (aProjectType == Graphic3d_Camera::Projection_Stereo) + { + OpenGl_FrameBuffer* aMainFbos[2] = + { + myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL, + myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL + }; + OpenGl_FrameBuffer* anImmFbos[2] = + { + myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, + myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL + }; + + if (!myTransientDrawToFront) + { + anImmFbos[0] = aMainFbos[0]; + anImmFbos[1] = aMainFbos[1]; + } + else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip + || aStereoMode == Graphic3d_StereoMode_QuadBuffer) + { + anImmFbos[0] = NULL; + anImmFbos[1] = NULL; + } + + #if !defined(GL_ES_VERSION_2_0) + aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); + #endif + redraw (Graphic3d_Camera::Projection_MonoLeftEye, aMainFbos[0]); + myBackBufferRestored = Standard_True; + myIsImmediateDrawn = Standard_False; + #if !defined(GL_ES_VERSION_2_0) + aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); + #endif + if (!redrawImmediate (aProjectType, aMainFbos[0], anImmFbos[0])) + { + toSwap = false; + } + else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip && toSwap) + { + aCtx->SwapBuffers(); + } + + #if !defined(GL_ES_VERSION_2_0) + aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK); + #endif + redraw (Graphic3d_Camera::Projection_MonoRightEye, aMainFbos[1]); + myBackBufferRestored = Standard_True; + myIsImmediateDrawn = Standard_False; + if (!redrawImmediate (aProjectType, aMainFbos[1], anImmFbos[1])) + { + toSwap = false; + } + + if (anImmFbos[0] != NULL) + { + bindDefaultFbo (aFrameBuffer); + drawStereoPair(); + } + } + else + { + OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; + OpenGl_FrameBuffer* anImmFbo = aFrameBuffer; + if (!aCtx->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid()) + { + anImmFbo = myImmediateSceneFbos[0].operator->(); + } + + #if !defined(GL_ES_VERSION_2_0) + if (aMainFbo == NULL + && aFrameBuffer == NULL) + { + aCtx->SetReadDrawBuffer (GL_BACK); + } + #endif + redraw (aProjectType, aMainFbo != NULL ? aMainFbo : aFrameBuffer); + myBackBufferRestored = Standard_True; + myIsImmediateDrawn = Standard_False; + if (!redrawImmediate (aProjectType, aMainFbo, anImmFbo)) + { + toSwap = false; + } + + if (anImmFbo != NULL + && anImmFbo != aFrameBuffer) + { + blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput); + } + } + +#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE) + if (OpenGl_AVIWriter_AllowWriting (myWindow->PlatformWindow()->NativeHandle())) + { + GLint params[4]; + glGetIntegerv (GL_VIEWPORT, params); + int nWidth = params[2] & ~0x7; + int nHeight = params[3] & ~0x7; + + const int nBitsPerPixel = 24; + GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8]; + + glPixelStorei (GL_PACK_ALIGNMENT, 1); + glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData); + OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel); + delete[] aDumpData; + } +#endif + + // bind default FBO + bindDefaultFbo(); + + // Swap the buffers + if (toSwap) + { + aCtx->SwapBuffers(); + if (!myMainSceneFbos[0]->IsValid()) + { + myBackBufferRestored = Standard_False; + } + } + else + { + aCtx->core11fwd->glFlush(); + } + + // reset render mode state + aCtx->FetchState(); + + myWasRedrawnGL = Standard_True; +} + +// ======================================================================= +// function : RedrawImmediate +// purpose : +// ======================================================================= +void OpenGl_View::RedrawImmediate() +{ + if (!myWorkspace->Activate()) + return; + + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + if (!myTransientDrawToFront + || !myBackBufferRestored + || (aCtx->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid())) + { + Redraw(); + return; + } + + const Graphic3d_StereoMode aStereoMode = myRenderParams.StereoMode; + Graphic3d_Camera::Projection aProjectType = myCamera->ProjectionType(); + OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )myFBO; + + if ( aFrameBuffer == NULL + && !aCtx->DefaultFrameBuffer().IsNull() + && aCtx->DefaultFrameBuffer()->IsValid()) + { + aFrameBuffer = aCtx->DefaultFrameBuffer().operator->(); + } + + if (aProjectType == Graphic3d_Camera::Projection_Stereo) + { + if (myMainSceneFbos[0]->IsValid() + && !myMainSceneFbos[1]->IsValid()) + { + aProjectType = Graphic3d_Camera::Projection_Perspective; + } + } + + bool toSwap = false; + if (aProjectType == Graphic3d_Camera::Projection_Stereo) + { + OpenGl_FrameBuffer* aMainFbos[2] = + { + myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL, + myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL + }; + OpenGl_FrameBuffer* anImmFbos[2] = + { + myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, + myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL + }; + if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip + || aStereoMode == Graphic3d_StereoMode_QuadBuffer) + { + anImmFbos[0] = NULL; + anImmFbos[1] = NULL; + } + + if (aCtx->arbFBO != NULL) + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } + #if !defined(GL_ES_VERSION_2_0) + if (anImmFbos[0] == NULL) + { + aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); + } + #endif + toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoLeftEye, + aMainFbos[0], + anImmFbos[0], + Standard_True) || toSwap; + if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip + && toSwap + && !aCtx->caps->buffersNoSwap) + { + aCtx->SwapBuffers(); + } + + if (aCtx->arbFBO != NULL) + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } + #if !defined(GL_ES_VERSION_2_0) + if (anImmFbos[1] == NULL) + { + aCtx->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK); + } + #endif + toSwap = redrawImmediate (Graphic3d_Camera::Projection_MonoRightEye, + aMainFbos[1], + anImmFbos[1], + Standard_True) || toSwap; + if (anImmFbos[0] != NULL) + { + bindDefaultFbo (aFrameBuffer); + drawStereoPair(); + } + } + else + { + OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; + OpenGl_FrameBuffer* anImmFbo = aFrameBuffer; + if (!aCtx->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid()) + { + anImmFbo = myImmediateSceneFbos[0].operator->(); + } + #if !defined(GL_ES_VERSION_2_0) + if (aMainFbo == NULL) + { + aCtx->SetReadDrawBuffer (GL_BACK); + } + #endif + toSwap = redrawImmediate (aProjectType, + aMainFbo, + anImmFbo, + Standard_True) || toSwap; + if (anImmFbo != NULL + && anImmFbo != aFrameBuffer) + { + blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput); + } + } + + // bind default FBO + bindDefaultFbo(); + + if (toSwap && !aCtx->caps->buffersNoSwap) + { + aCtx->SwapBuffers(); + } + else + { + aCtx->core11fwd->glFlush(); + } + + myWasRedrawnGL = Standard_True; +} + +// ======================================================================= +// function : redraw +// purpose : +// ======================================================================= +void OpenGl_View::redraw (const Graphic3d_Camera::Projection theProjection, OpenGl_FrameBuffer* theReadDrawFbo) +{ + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + if (theReadDrawFbo != NULL) + { + theReadDrawFbo->BindBuffer (aCtx); + theReadDrawFbo->SetupViewport (aCtx); + } + else + { + aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height()); + } + + // request reset of material + myWorkspace->NamedStatus |= OPENGL_NS_RESMAT; + myWorkspace->UseZBuffer() = Standard_True; + myWorkspace->UseDepthWrite() = Standard_True; + GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; + glDepthFunc (GL_LEQUAL); + glDepthMask (GL_TRUE); + glEnable (GL_DEPTH_TEST); + +#if !defined(GL_ES_VERSION_2_0) + glClearDepth (1.0); +#else + glClearDepthf (1.0f); +#endif + + if (myWorkspace->NamedStatus & OPENGL_NS_WHITEBACK) + { + // set background to white + glClearColor (1.0f, 1.0f, 1.0f, 1.0f); + } + else + { + glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f); + } + + glClear (toClear); + + render (theProjection, theReadDrawFbo, Standard_False); +} + +// ======================================================================= +// function : redrawMonoImmediate +// purpose : +// ======================================================================= +bool OpenGl_View::redrawImmediate (const Graphic3d_Camera::Projection theProjection, + OpenGl_FrameBuffer* theReadFbo, + OpenGl_FrameBuffer* theDrawFbo, + const Standard_Boolean theIsPartialUpdate) +{ + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + GLboolean toCopyBackToFront = GL_FALSE; + if (!myTransientDrawToFront) + { + myBackBufferRestored = Standard_False; + } + else if (theReadFbo != NULL + && theReadFbo->IsValid() + && aCtx->IsRender()) + { + if (!blitBuffers (theReadFbo, theDrawFbo)) + { + return true; + } + } + else if (theDrawFbo == NULL) + { + #if !defined(GL_ES_VERSION_2_0) + aCtx->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront); + #endif + if (toCopyBackToFront) + { + if (!HasImmediateStructures() + && !theIsPartialUpdate) + { + // prefer Swap Buffers within Redraw in compatibility mode (without FBO) + return true; + } + copyBackToFront(); + } + else + { + myBackBufferRestored = Standard_False; + } + } + else + { + myBackBufferRestored = Standard_False; + } + myIsImmediateDrawn = Standard_True; + + myWorkspace->UseZBuffer() = Standard_True; + myWorkspace->UseDepthWrite() = Standard_True; + glDepthFunc (GL_LEQUAL); + glDepthMask (GL_TRUE); + glEnable (GL_DEPTH_TEST); +#if !defined(GL_ES_VERSION_2_0) + glClearDepth (1.0); +#else + glClearDepthf (1.0f); +#endif + + render (theProjection, theDrawFbo, Standard_True); + + return !toCopyBackToFront; +} + +//======================================================================= +//function : Render +//purpose : +//======================================================================= +void OpenGl_View::render (Graphic3d_Camera::Projection theProjection, + OpenGl_FrameBuffer* theOutputFBO, + const Standard_Boolean theToDrawImmediate) +{ + // ================================== + // Step 1: Prepare for render + // ================================== + + const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext(); + +#if !defined(GL_ES_VERSION_2_0) + // Disable current clipping planes + if (aContext->core11 != NULL) + { + const Standard_Integer aMaxPlanes = aContext->MaxClipPlanes(); + for (Standard_Integer aClipPlaneId = GL_CLIP_PLANE0; aClipPlaneId < GL_CLIP_PLANE0 + aMaxPlanes; ++aClipPlaneId) + { + aContext->core11fwd->glDisable (aClipPlaneId); + } + } +#endif + + // Update states of OpenGl_BVHTreeSelector (frustum culling algorithm). + myBVHSelector.SetViewVolume (myCamera); + + const Handle(OpenGl_ShaderManager)& aManager = aContext->ShaderManager(); + if (StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()) != myLastLightSourceState) + { + aManager->UpdateLightSourceStateTo (myShadingModel == Graphic3d_TOSM_NONE ? &OpenGl_NoShadingLight() : &myLights); + myLastLightSourceState = StateInfo (myCurrLightSourceState, aManager->LightSourceState().Index()); + } + + // Update matrices if camera has changed. + Graphic3d_WorldViewProjState aWVPState = myCamera->WorldViewProjState(); + const Standard_Boolean isCameraChanged = myWorldViewProjState != aWVPState; + const Standard_Boolean isSameView = aManager->IsSameView (this); + if (isCameraChanged) + { + aContext->ProjectionState.SetCurrent (myCamera->ProjectionMatrixF()); + aContext->WorldViewState .SetCurrent (myCamera->OrientationMatrixF()); + } + + // Apply new matrix state if camera has changed or this view differs from the one + // that was previously used for configuring matrices of shader manager + // (ApplyProjectionMatrix and ApplyWorldViewMatrix will affect the manager). + if (isCameraChanged || !isSameView) + { + aContext->ApplyProjectionMatrix(); + aContext->ApplyWorldViewMatrix(); + } + + if (aManager->ModelWorldState().Index() == 0) + { + aContext->ShaderManager()->UpdateModelWorldStateTo (OpenGl_Mat4()); + } + + myWorldViewProjState = aWVPState; + + // ==================================== + // Step 2: Redraw background + // ==================================== + + // Render background + if (!theToDrawImmediate) + { + DrawBackground (myWorkspace); + } + +#if !defined(GL_ES_VERSION_2_0) + // Switch off lighting by default + if (aContext->core11 != NULL) + { + glDisable(GL_LIGHTING); + } +#endif + + // ================================= + // Step 3: Redraw main plane + // ================================= + + // Setup face culling + GLboolean isCullFace = GL_FALSE; + if (myBackfacing != Graphic3d_TOBM_AUTOMATIC) + { + isCullFace = glIsEnabled (GL_CULL_FACE); + if (myBackfacing == Graphic3d_TOBM_DISABLE) + { + glEnable (GL_CULL_FACE); + glCullFace (GL_BACK); + } + else + glDisable (GL_CULL_FACE); + } + +#if !defined(GL_ES_VERSION_2_0) + // if the view is scaled normal vectors are scaled to unit + // length for correct displaying of shaded objects + const gp_Pnt anAxialScale = myCamera->AxialScale(); + if (anAxialScale.X() != 1.F || + anAxialScale.Y() != 1.F || + anAxialScale.Z() != 1.F) + { + aContext->SetGlNormalizeEnabled (Standard_True); + } + else + { + aContext->SetGlNormalizeEnabled (Standard_False); + } + + // Apply Fog + if (myFog.IsOn + && aContext->core11 != NULL) + { + Standard_Real aFogFrontConverted = (Standard_Real )myFog.Front + myCamera->Distance(); + if (myCamera->ZFar() < aFogFrontConverted) + { + aFogFrontConverted = myCamera->ZFar(); + myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance()); + } + + Standard_Real aFogBackConverted = (Standard_Real )myFog.Back + myCamera->Distance(); + if (myCamera->ZFar() < aFogFrontConverted) + { + aFogBackConverted = myCamera->ZFar(); + myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance()); + } + + if (aFogFrontConverted > aFogBackConverted) + { + myFog.Front = (Standard_ShortReal )(aFogFrontConverted - myCamera->Distance()); + myFog.Back = (Standard_ShortReal )(aFogBackConverted - myCamera->Distance()); + } + + glFogi(GL_FOG_MODE, GL_LINEAR); + glFogf(GL_FOG_START, (Standard_ShortReal )aFogFrontConverted); + glFogf(GL_FOG_END, (Standard_ShortReal )aFogBackConverted); + glFogfv(GL_FOG_COLOR, myFog.Color.rgb); + glEnable(GL_FOG); + } + else if (aContext->core11 != NULL) + { + glDisable (GL_FOG); + } + + // Apply InteriorShadingMethod + if (aContext->core11 != NULL) + { + aContext->core11->glShadeModel (myShadingModel == Graphic3d_TOSM_FACET + || myShadingModel == Graphic3d_TOSM_NONE ? GL_FLAT : GL_SMOOTH); + } +#endif + + aManager->SetShadingModel (myShadingModel); + + // Apply AntiAliasing + if (myAntiAliasing) + myWorkspace->NamedStatus |= OPENGL_NS_ANTIALIASING; + else + myWorkspace->NamedStatus &= ~OPENGL_NS_ANTIALIASING; + + if (!aManager->IsEmpty()) + { + aManager->UpdateClippingState(); + } + + // Redraw 3d scene + if (theProjection == Graphic3d_Camera::Projection_MonoLeftEye) + { + aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoLeftF()); + aContext->ApplyProjectionMatrix(); + } + else if (theProjection == Graphic3d_Camera::Projection_MonoRightEye) + { + aContext->ProjectionState.SetCurrent (myCamera->ProjectionStereoRightF()); + aContext->ApplyProjectionMatrix(); + } + renderScene (theOutputFBO, theToDrawImmediate); + + // =============================== + // Step 4: Trihedron + // =============================== + + // Resetting GL parameters according to the default aspects + // in order to synchronize GL state with the graphic driver state + // before drawing auxiliary stuff (trihedrons, overlayer) + // and invoking optional callbacks + myWorkspace->ResetAppliedAspect(); + + aContext->ChangeClipping().RemoveAll(); + + if (!aManager->IsEmpty()) + { + aManager->ResetMaterialStates(); + aManager->RevertClippingState(); + + // We need to disable (unbind) all shaders programs to ensure + // that all objects without specified aspect will be drawn + // correctly (such as background) + aContext->BindProgram (NULL); + } + + // Render trihedron + if (!theToDrawImmediate) + { + renderTrihedron (myWorkspace); + + // Restore face culling + if (myBackfacing != Graphic3d_TOBM_AUTOMATIC) + { + if (isCullFace) + { + glEnable (GL_CULL_FACE); + glCullFace (GL_BACK); + } + else + glDisable (GL_CULL_FACE); + } + } + + // ============================================================== + // Step 5: Invoke callback after redraw + // ============================================================== + + displayCallback (0); + + // ============================================================== + // Step 6: Keep shader manager informed about last View + // ============================================================== + + if (!aManager.IsNull()) + { + aManager->SetLastView (this); + } +} + +// ======================================================================= +// function : InvalidateBVHData +// purpose : +// ======================================================================= +void OpenGl_View::InvalidateBVHData (const Graphic3d_ZLayerId theLayerId) +{ + myZLayers.InvalidateBVHData (theLayerId); +} + +//======================================================================= +//function : renderStructs +//purpose : +//======================================================================= +void OpenGl_View::renderStructs (OpenGl_FrameBuffer* theReadDrawFbo, + const Standard_Boolean theToDrawImmediate) +{ + if ( myZLayers.NbStructures() <= 0 ) + return; + + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + if ( (myWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) == 0 ) + { + #if !defined(GL_ES_VERSION_2_0) + const int anAntiAliasingMode = myWorkspace->AntiAliasingMode(); + #endif + + if ( !myAntiAliasing ) + { + #if !defined(GL_ES_VERSION_2_0) + if (aCtx->core11 != NULL) + { + glDisable (GL_POINT_SMOOTH); + } + glDisable(GL_LINE_SMOOTH); + if( anAntiAliasingMode & 2 ) glDisable(GL_POLYGON_SMOOTH); + #endif + glBlendFunc (GL_ONE, GL_ZERO); + glDisable (GL_BLEND); + } + else + { + #if !defined(GL_ES_VERSION_2_0) + if (aCtx->core11 != NULL) + { + glEnable(GL_POINT_SMOOTH); + } + glEnable(GL_LINE_SMOOTH); + if( anAntiAliasingMode & 2 ) glEnable(GL_POLYGON_SMOOTH); + #endif + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); + } + } + + Standard_Boolean toRenderGL = theToDrawImmediate || + myRenderParams.Method != Graphic3d_RM_RAYTRACING || + myRaytraceInitStatus == OpenGl_RT_FAIL || + aCtx->IsFeedback(); + + if (!toRenderGL) + { + toRenderGL = !initRaytraceResources (aCtx) || + !updateRaytraceGeometry (OpenGl_GUM_CHECK, myId, aCtx); + + toRenderGL |= !myIsRaytraceDataValid; // if no ray-trace data use OpenGL + + if (!toRenderGL) + { + const Standard_Integer aSizeX = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeX() : myWindow->Width(); + const Standard_Integer aSizeY = theReadDrawFbo != NULL ? theReadDrawFbo->GetVPSizeY() : myWindow->Height(); + + if (myOpenGlFBO.IsNull()) + myOpenGlFBO = new OpenGl_FrameBuffer; + + if (myOpenGlFBO->GetVPSizeX() != aSizeX + || myOpenGlFBO->GetVPSizeY() != aSizeY) + { + myOpenGlFBO->Init (aCtx, aSizeX, aSizeY); + } + + if (myRaytraceFilter.IsNull()) + myRaytraceFilter = new OpenGl_RaytraceFilter; + + myRaytraceFilter->SetPrevRenderFilter (myWorkspace->GetRenderFilter()); + + if (theReadDrawFbo != NULL) + theReadDrawFbo->UnbindBuffer (aCtx); + + // Prepare preliminary OpenGL output + if (aCtx->arbFBOBlit != NULL) + { + // Render bottom OSD layer + myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Bottom); + + myWorkspace->SetRenderFilter (myRaytraceFilter); + { + if (theReadDrawFbo != NULL) + { + theReadDrawFbo->BindReadBuffer (aCtx); + } + else + { + aCtx->arbFBO->glBindFramebuffer (GL_READ_FRAMEBUFFER, 0); + } + + myOpenGlFBO->BindDrawBuffer (aCtx); + + aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, aSizeX, aSizeY, + 0, 0, aSizeX, aSizeY, + GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, + GL_NEAREST); + + // Render non-polygonal elements in default layer + myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Default); + } + myWorkspace->SetRenderFilter (myRaytraceFilter->PrevRenderFilter()); + } + + if (theReadDrawFbo != NULL) + { + theReadDrawFbo->BindBuffer (aCtx); + } + else + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, 0); + } + + // Ray-tracing polygonal primitive arrays + raytrace (aSizeX, aSizeY, theReadDrawFbo, aCtx); + + // Render upper (top and topmost) OpenGL layers + myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_Upper); + } + } + + // Redraw 3D scene using OpenGL in standard + // mode or in case of ray-tracing failure + if (toRenderGL) + { + myZLayers.Render (myWorkspace, theToDrawImmediate, OpenGl_LF_All); + + // Set flag that scene was redrawn by standard pipeline + myWasRedrawnGL = Standard_True; + } +} + +//======================================================================= +//function : renderTrihedron +//purpose : +//======================================================================= +void OpenGl_View::renderTrihedron (const Handle(OpenGl_Workspace) &theWorkspace) +{ + // display global trihedron + if (myToShowTrihedron) + { + myTrihedron.Render (theWorkspace); + } + if (myToShowGradTrihedron) + { + myGraduatedTrihedron.Render (theWorkspace); + } +} + +// ======================================================================= +// function : Invalidate +// purpose : +// ======================================================================= +void OpenGl_View::Invalidate() +{ + myBackBufferRestored = Standard_False; +} + +//======================================================================= +//function : renderScene +//purpose : +//======================================================================= +void OpenGl_View::renderScene (OpenGl_FrameBuffer* theReadDrawFbo, + const Standard_Boolean theToDrawImmediate) +{ + const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext(); + + if (myZClip.Back.IsOn || myZClip.Front.IsOn) + { + Handle(Graphic3d_ClipPlane) aPlaneBack; + Handle(Graphic3d_ClipPlane) aPlaneFront; + + if (myZClip.Back.IsOn) + { + Standard_Real aClipBackConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance(); + if (myCamera->ZFar() < aClipBackConverted) + { + aClipBackConverted = myCamera->ZFar(); + myZClip.Back.Limit = (Standard_ShortReal )(aClipBackConverted - myCamera->Distance()); + } + const Graphic3d_ClipPlane::Equation aBackEquation (0.0, 0.0, 1.0, (Standard_ShortReal )aClipBackConverted); + aPlaneBack = new Graphic3d_ClipPlane (aBackEquation); + } + + if (myZClip.Front.IsOn) + { + Standard_Real aClipFrontConverted = (Standard_Real )myZClip.Front.Limit + myCamera->Distance(); + if (myCamera->ZNear() > aClipFrontConverted) + { + aClipFrontConverted = myCamera->ZNear(); + myZClip.Front.Limit = (Standard_ShortReal )(aClipFrontConverted - myCamera->Distance()); + } + const Graphic3d_ClipPlane::Equation aFrontEquation (0.0, 0.0, -1.0, (Standard_ShortReal )-aClipFrontConverted); + aPlaneFront = new Graphic3d_ClipPlane (aFrontEquation); + } + + // Specify slicing planes with identity transformation + if (!aPlaneBack.IsNull() || !aPlaneFront.IsNull()) + { + Graphic3d_SequenceOfHClipPlane aSlicingPlanes; + if (!aPlaneBack.IsNull()) + { + aSlicingPlanes.Append (aPlaneBack); + } + + if (!aPlaneFront.IsNull()) + { + aSlicingPlanes.Append (aPlaneFront); + } + + // add planes at loaded view matrix state + aContext->ChangeClipping().AddView (aSlicingPlanes, myWorkspace); + } + } + +#ifdef _WIN32 + // set printing scale/tiling transformation + Handle(OpenGl_PrinterContext) aPrintContext = myWorkspace->PrinterContext(); + if (!aPrintContext.IsNull()) + { + aContext->ProjectionState.Push(); + aContext->ProjectionState.SetCurrent (aPrintContext->ProjTransformation() * aContext->ProjectionState.Current()); + aContext->ApplyProjectionMatrix(); + } +#endif + + // Specify clipping planes in view transformation space + if (!myClipPlanes.IsEmpty()) + { + Graphic3d_SequenceOfHClipPlane aUserPlanes; + Graphic3d_SequenceOfHClipPlane::Iterator aClippingIt (myClipPlanes); + for (; aClippingIt.More(); aClippingIt.Next()) + { + const Handle(Graphic3d_ClipPlane)& aClipPlane = aClippingIt.Value(); + if (aClipPlane->IsOn()) + { + aUserPlanes.Append (aClipPlane); + } + } + + if (!aUserPlanes.IsEmpty()) + { + aContext->ChangeClipping().AddWorld (aUserPlanes); + } + + if (!aContext->ShaderManager()->IsEmpty()) + { + aContext->ShaderManager()->UpdateClippingState(); + } + } + +#if !defined(GL_ES_VERSION_2_0) + // Apply Lights + if (aContext->core11 != NULL) + { + // setup lights + Graphic3d_Vec4 anAmbientColor (THE_DEFAULT_AMBIENT[0], + THE_DEFAULT_AMBIENT[1], + THE_DEFAULT_AMBIENT[2], + THE_DEFAULT_AMBIENT[3]); + GLenum aLightGlId = GL_LIGHT0; + + OpenGl_ListOfLight::Iterator aLightIt (myShadingModel == Graphic3d_TOSM_NONE ? OpenGl_NoShadingLight() : myLights); + for (; aLightIt.More(); aLightIt.Next()) + { + bindLight (aLightIt.Value(), aLightGlId, anAmbientColor, myWorkspace); + } + + // apply accumulated ambient color + anAmbientColor.a() = 1.0f; + glLightModelfv (GL_LIGHT_MODEL_AMBIENT, anAmbientColor.GetData()); + + if (aLightGlId != GL_LIGHT0) + { + glEnable (GL_LIGHTING); + } + // switch off unused lights + for (; aLightGlId <= GL_LIGHT7; ++aLightGlId) + { + glDisable (aLightGlId); + } + } +#endif + + // Clear status bitfields + myWorkspace->NamedStatus &= ~(OPENGL_NS_2NDPASSNEED | OPENGL_NS_2NDPASSDO); + + // Update state of surface detail level + myWorkspace->GetGlContext()->ShaderManager()->UpdateSurfaceDetailStateTo (mySurfaceDetail); + + // Added PCT for handling of textures + switch (mySurfaceDetail) + { + case Graphic3d_TOD_NONE: + myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; + myWorkspace->DisableTexture(); + // Render the view + renderStructs (theReadDrawFbo, theToDrawImmediate); + break; + + case Graphic3d_TOD_ENVIRONMENT: + myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; + if (myRenderParams.Method != Graphic3d_RM_RAYTRACING) + { + myWorkspace->EnableTexture (myTextureEnv); + } + // Render the view + renderStructs (theReadDrawFbo, theToDrawImmediate); + myWorkspace->DisableTexture(); + break; + + case Graphic3d_TOD_ALL: + // First pass + myWorkspace->NamedStatus &= ~OPENGL_NS_FORBIDSETTEX; + // Render the view + renderStructs (theReadDrawFbo, theToDrawImmediate); + myWorkspace->DisableTexture(); + + // Second pass + if (myWorkspace->NamedStatus & OPENGL_NS_2NDPASSNEED) + { + myWorkspace->NamedStatus |= OPENGL_NS_2NDPASSDO; + if (myRenderParams.Method != Graphic3d_RM_RAYTRACING) + { + myWorkspace->EnableTexture (myTextureEnv); + } + + // Remember OpenGl properties + GLint aSaveBlendDst = GL_ONE_MINUS_SRC_ALPHA, aSaveBlendSrc = GL_SRC_ALPHA; + GLint aSaveZbuffFunc; + GLboolean aSaveZbuffWrite; + glGetBooleanv (GL_DEPTH_WRITEMASK, &aSaveZbuffWrite); + glGetIntegerv (GL_DEPTH_FUNC, &aSaveZbuffFunc); + #if !defined(GL_ES_VERSION_2_0) + glGetIntegerv (GL_BLEND_DST, &aSaveBlendDst); + glGetIntegerv (GL_BLEND_SRC, &aSaveBlendSrc); + #endif + GLboolean wasZbuffEnabled = glIsEnabled (GL_DEPTH_TEST); + GLboolean wasBlendEnabled = glIsEnabled (GL_BLEND); + + // Change the properties for second rendering pass + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); + + glDepthFunc (GL_EQUAL); + glDepthMask (GL_FALSE); + glEnable (GL_DEPTH_TEST); + + myWorkspace->NamedStatus |= OPENGL_NS_FORBIDSETTEX; + + // Render the view + renderStructs (theReadDrawFbo, theToDrawImmediate); + myWorkspace->DisableTexture(); + + // Restore properties back + glBlendFunc (aSaveBlendSrc, aSaveBlendDst); + if (!wasBlendEnabled) + glDisable (GL_BLEND); + + glDepthFunc (aSaveZbuffFunc); + glDepthMask (aSaveZbuffWrite); + if (!wasZbuffEnabled) + glDisable (GL_DEPTH_FUNC); + } + break; + } + + // Apply restored view matrix. + aContext->ApplyWorldViewMatrix(); + +#ifdef _WIN32 + // set printing scale/tiling transformation + if (!aPrintContext.IsNull()) + { + aContext->ProjectionState.Pop(); + aContext->ApplyProjectionMatrix(); + } +#endif +} + +// ======================================================================= +// function : bindDefaultFbo +// purpose : +// ======================================================================= +void OpenGl_View::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo) +{ + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + OpenGl_FrameBuffer* anFbo = (theCustomFbo != NULL && theCustomFbo->IsValid()) + ? theCustomFbo + : (!aCtx->DefaultFrameBuffer().IsNull() + && aCtx->DefaultFrameBuffer()->IsValid() + ? aCtx->DefaultFrameBuffer().operator->() + : NULL); + if (anFbo != NULL) + { + anFbo->BindBuffer (aCtx); + } + else + { + #if !defined(GL_ES_VERSION_2_0) + aCtx->SetReadDrawBuffer (GL_BACK); + #else + if (aCtx->arbFBO != NULL) + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } + #endif + } + aCtx->core11fwd->glViewport (0, 0, myWindow->Width(), myWindow->Height()); +} + +// ======================================================================= +// function : initBlitQuad +// purpose : +// ======================================================================= +OpenGl_VertexBuffer* OpenGl_View::initBlitQuad (const Standard_Boolean theToFlip) +{ + OpenGl_VertexBuffer* aVerts = NULL; + if (!theToFlip) + { + aVerts = &myFullScreenQuad; + if (!aVerts->IsValid()) + { + OpenGl_Vec4 aQuad[4] = + { + OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f), + OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f), + OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f), + OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f) + }; + aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData()); + } + } + else + { + aVerts = &myFullScreenQuadFlip; + if (!aVerts->IsValid()) + { + OpenGl_Vec4 aQuad[4] = + { + OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 1.0f), + OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 0.0f), + OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 1.0f), + OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 0.0f) + }; + aVerts->Init (myWorkspace->GetGlContext(), 4, 4, aQuad[0].GetData()); + } + } + return aVerts; +} + +// ======================================================================= +// function : blitBuffers +// purpose : +// ======================================================================= +bool OpenGl_View::blitBuffers (OpenGl_FrameBuffer* theReadFbo, + OpenGl_FrameBuffer* theDrawFbo, + const Standard_Boolean theToFlip) +{ + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + if (theReadFbo == NULL || aCtx->IsFeedback()) + { + return false; + } + else if (theReadFbo == theDrawFbo) + { + return true; + } + + // clear destination before blitting + if (theDrawFbo != NULL + && theDrawFbo->IsValid()) + { + theDrawFbo->BindBuffer (aCtx); + } + else + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } +#if !defined(GL_ES_VERSION_2_0) + aCtx->core20fwd->glClearDepth (1.0); +#else + aCtx->core20fwd->glClearDepthf (1.0f); +#endif + aCtx->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + +/*#if !defined(GL_ES_VERSION_2_0) + if (aCtx->arbFBOBlit != NULL) + { + theReadFbo->BindReadBuffer (aCtx); + if (theDrawFbo != NULL + && theDrawFbo->IsValid()) + { + theDrawFbo->BindDrawBuffer (aCtx); + } + else + { + aCtx->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } + // we don't copy stencil buffer here... does it matter for performance? + aCtx->arbFBOBlit->glBlitFramebuffer (0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(), + 0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(), + GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); + + if (theDrawFbo != NULL + && theDrawFbo->IsValid()) + { + theDrawFbo->BindBuffer (aCtx); + } + else + { + aCtx->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + } + } + else +#endif*/ + { + aCtx->core20fwd->glDepthFunc (GL_ALWAYS); + aCtx->core20fwd->glDepthMask (GL_TRUE); + aCtx->core20fwd->glEnable (GL_DEPTH_TEST); + + myWorkspace->DisableTexture(); + + OpenGl_VertexBuffer* aVerts = initBlitQuad (theToFlip); + const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager(); + if (aVerts->IsValid() + && aManager->BindFboBlitProgram()) + { + theReadFbo->ColorTexture() ->Bind (aCtx, GL_TEXTURE0 + 0); + theReadFbo->DepthStencilTexture()->Bind (aCtx, GL_TEXTURE0 + 1); + aVerts->BindVertexAttrib (aCtx, Graphic3d_TOA_POS); + + aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); + + aVerts->UnbindVertexAttrib (aCtx, Graphic3d_TOA_POS); + theReadFbo->DepthStencilTexture()->Unbind (aCtx, GL_TEXTURE0 + 1); + theReadFbo->ColorTexture() ->Unbind (aCtx, GL_TEXTURE0 + 0); + } + else + { + TCollection_ExtendedString aMsg = TCollection_ExtendedString() + + "Error! FBO blitting has failed"; + aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_ERROR_ARB, + 0, + GL_DEBUG_SEVERITY_HIGH_ARB, + aMsg); + myHasFboBlit = Standard_False; + theReadFbo->Release (aCtx.operator->()); + return true; + } + } + return true; +} + +// ======================================================================= +// function : drawStereoPair +// purpose : +// ======================================================================= +void OpenGl_View::drawStereoPair() +{ + OpenGl_FrameBuffer* aPair[2] = + { + myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, + myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL + }; + if (aPair[0] == NULL + || aPair[1] == NULL + || !myTransientDrawToFront) + { + aPair[0] = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; + aPair[1] = myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL; + } + + if (aPair[0] == NULL + || aPair[1] == NULL) + { + return; + } + + struct + { + Standard_Integer left; + Standard_Integer top; + Standard_Integer right; + Standard_Integer bottom; + Standard_Integer dx() { return right - left; } + Standard_Integer dy() { return bottom - top; } + } aGeom; + + myWindow->PlatformWindow()->Position (aGeom.left, aGeom.top, aGeom.right, aGeom.bottom); + + Standard_Boolean toReverse = myRenderParams.ToReverseStereo; + const Standard_Boolean isOddY = (aGeom.top + aGeom.dy()) % 2 == 1; + const Standard_Boolean isOddX = aGeom.left % 2 == 1; + if (isOddY + && (myRenderParams.StereoMode == Graphic3d_StereoMode_RowInterlaced + || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard)) + { + toReverse = !toReverse; + } + if (isOddX + && (myRenderParams.StereoMode == Graphic3d_StereoMode_ColumnInterlaced + || myRenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard)) + { + toReverse = !toReverse; + } + + if (toReverse) + { + std::swap (aPair[0], aPair[1]); + } + + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + aCtx->core20fwd->glDepthFunc (GL_ALWAYS); + aCtx->core20fwd->glDepthMask (GL_TRUE); + aCtx->core20fwd->glEnable (GL_DEPTH_TEST); + + myWorkspace->DisableTexture(); + OpenGl_VertexBuffer* aVerts = initBlitQuad (myToFlipOutput); + + const Handle(OpenGl_ShaderManager)& aManager = aCtx->ShaderManager(); + if (aVerts->IsValid() + && aManager->BindStereoProgram (myRenderParams.StereoMode)) + { + if (myRenderParams.StereoMode == Graphic3d_StereoMode_Anaglyph) + { + OpenGl_Mat4 aFilterL, aFilterR; + aFilterL.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); + aFilterR.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); + switch (myRenderParams.AnaglyphFilter) + { + case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple: + { + aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); + aFilterR.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); + aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); + break; + } + case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized: + { + aFilterL.SetRow (0, Graphic3d_Vec4 ( 0.4154f, 0.4710f, 0.16666667f, 0.0f)); + aFilterL.SetRow (1, Graphic3d_Vec4 (-0.0458f, -0.0484f, -0.0257f, 0.0f)); + aFilterL.SetRow (2, Graphic3d_Vec4 (-0.0547f, -0.0615f, 0.0128f, 0.0f)); + aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); + aFilterR.SetRow (0, Graphic3d_Vec4 (-0.01090909f, -0.03636364f, -0.00606061f, 0.0f)); + aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.37560000f, 0.73333333f, 0.01111111f, 0.0f)); + aFilterR.SetRow (2, Graphic3d_Vec4 (-0.06510000f, -0.12870000f, 1.29710000f, 0.0f)); + aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); + break; + } + case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple: + { + aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); + aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); + aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); + break; + } + case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: + { + aFilterL.SetRow (0, Graphic3d_Vec4 ( 1.062f, -0.205f, 0.299f, 0.0f)); + aFilterL.SetRow (1, Graphic3d_Vec4 (-0.026f, 0.908f, 0.068f, 0.0f)); + aFilterL.SetRow (2, Graphic3d_Vec4 (-0.038f, -0.173f, 0.022f, 0.0f)); + aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); + aFilterR.SetRow (0, Graphic3d_Vec4 (-0.016f, -0.123f, -0.017f, 0.0f)); + aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.006f, 0.062f, -0.017f, 0.0f)); + aFilterR.SetRow (2, Graphic3d_Vec4 ( 0.094f, 0.185f, 0.911f, 0.0f)); + aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); + break; + } + case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple: + { + aFilterR.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); + aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); + aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); + break; + } + case Graphic3d_RenderingParams::Anaglyph_UserDefined: + { + aFilterL = myRenderParams.AnaglyphLeft; + aFilterR = myRenderParams.AnaglyphRight; + break; + } + } + aCtx->ActiveProgram()->SetUniform (aCtx, "uMultL", aFilterL); + aCtx->ActiveProgram()->SetUniform (aCtx, "uMultR", aFilterR); + } + + aPair[0]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 0); + aPair[1]->ColorTexture()->Bind (aCtx, GL_TEXTURE0 + 1); + aVerts->BindVertexAttrib (aCtx, 0); + + aCtx->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); + + aVerts->UnbindVertexAttrib (aCtx, 0); + aPair[1]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 1); + aPair[0]->ColorTexture()->Unbind (aCtx, GL_TEXTURE0 + 0); + } + else + { + TCollection_ExtendedString aMsg = TCollection_ExtendedString() + + "Error! Anaglyph has failed"; + aCtx->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_ERROR_ARB, + 0, + GL_DEBUG_SEVERITY_HIGH_ARB, + aMsg); + } +} + +// ======================================================================= +// function : copyBackToFront +// purpose : +// ======================================================================= +void OpenGl_View::copyBackToFront() +{ +#if !defined(GL_ES_VERSION_2_0) + + OpenGl_Mat4 aProjectMat; + Graphic3d_TransformUtils::Ortho2D (aProjectMat, + 0.f, static_cast (myWindow->Width()), 0.f, static_cast (myWindow->Height())); + + Handle(OpenGl_Context) aCtx = myWorkspace->GetGlContext(); + aCtx->WorldViewState.Push(); + aCtx->ProjectionState.Push(); + + aCtx->WorldViewState.SetIdentity(); + aCtx->ProjectionState.SetCurrent (aProjectMat); + + aCtx->ApplyProjectionMatrix(); + aCtx->ApplyWorldViewMatrix(); + + aCtx->DisableFeatures(); + + switch (aCtx->DrawBuffer()) + { + case GL_BACK_LEFT: + { + aCtx->SetReadBuffer (GL_BACK_LEFT); + aCtx->SetDrawBuffer (GL_FRONT_LEFT); + break; + } + case GL_BACK_RIGHT: + { + aCtx->SetReadBuffer (GL_BACK_RIGHT); + aCtx->SetDrawBuffer (GL_FRONT_RIGHT); + break; + } + default: + { + aCtx->SetReadBuffer (GL_BACK); + aCtx->SetDrawBuffer (GL_FRONT); + break; + } + } + + glRasterPos2i (0, 0); + glCopyPixels (0, 0, myWindow->Width() + 1, myWindow->Height() + 1, GL_COLOR); + //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH); + + aCtx->EnableFeatures(); + + aCtx->WorldViewState.Pop(); + aCtx->ProjectionState.Pop(); + aCtx->ApplyProjectionMatrix(); + + // read/write from front buffer now + aCtx->SetReadBuffer (aCtx->DrawBuffer()); +#endif + myIsImmediateDrawn = Standard_False; +} + +// ======================================================================= +// function : displayCallback +// purpose : +// ======================================================================= +void OpenGl_View::displayCallback (const Standard_Integer theReason) +{ + if (myDisplayCallback.Func == NULL) + { + return; + } + + Aspect_GraphicCallbackStruct aCallData; + aCallData.reason = theReason; + aCallData.glContext = myWorkspace->GetGlContext(); + aCallData.wsID = -1; + aCallData.viewID = myId; + aCallData.IsCoreProfile = (myWorkspace->GetGlContext()->core11 == NULL); + myDisplayCallback.Func (myWindow->PlatformWindow()->NativeHandle(), myDisplayCallback.Data, &aCallData); +} diff --git a/src/OpenGl/OpenGl_Window.cxx b/src/OpenGl/OpenGl_Window.cxx index 997e45bf45..4d99800c67 100644 --- a/src/OpenGl/OpenGl_Window.cxx +++ b/src/OpenGl/OpenGl_Window.cxx @@ -131,20 +131,16 @@ namespace // purpose : // ======================================================================= OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, + const Handle(Aspect_Window)& thePlatformWindow, Aspect_RenderingContext theGContext, const Handle(OpenGl_Caps)& theCaps, const Handle(OpenGl_Context)& theShareCtx) : myGlContext (new OpenGl_Context (theCaps)), myOwnGContext (theGContext == 0), - myWidth (theCWindow.dx), - myHeight (theCWindow.dy), + myPlatformWindow (thePlatformWindow), mySwapInterval (theCaps->swapInterval) { - myBgColor.rgb[0] = theCWindow.Background.r; - myBgColor.rgb[1] = theCWindow.Background.g; - myBgColor.rgb[2] = theCWindow.Background.b; - myBgColor.rgb[3] = 1.0f; + myPlatformWindow->Size (myWidth, myHeight); Standard_Boolean isCoreProfile = Standard_False; @@ -164,7 +160,10 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, if (theGContext == (EGLContext )EGL_NO_CONTEXT) { // create new surface - anEglSurf = eglCreateWindowSurface (anEglDisplay, anEglConfig, (EGLNativeWindowType )theCWindow.XWindow, NULL); + anEglSurf = eglCreateWindowSurface (anEglDisplay, + anEglConfig, + (EGLNativeWindowType )myPlatformWindow->NativeHandle(), + NULL); if (anEglSurf == EGL_NO_SURFACE) { Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window, EGL is unable to create surface for window!"); @@ -189,7 +188,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, myGlContext->Init ((Aspect_Drawable )anEglSurf, (Aspect_Display )anEglDisplay, (Aspect_RenderingContext )anEglContext, isCoreProfile); #elif defined(_WIN32) (void )theDriver; - HWND aWindow = (HWND )theCWindow.XWindow; + HWND aWindow = (HWND )myPlatformWindow->NativeHandle(); HDC aWindowDC = GetDC (aWindow); HGLRC aGContext = (HGLRC )theGContext; @@ -438,7 +437,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, myGlContext->Init ((Aspect_Handle )aWindow, (Aspect_Handle )aWindowDC, (Aspect_RenderingContext )aGContext, isCoreProfile); #else - Window aParent = (Window )theCWindow.XWindow; + Window aParent = (Window )myPlatformWindow->NativeHandle(); Window aWindow = 0; Display* aDisp = theDriver->GetDisplayConnection()->GetDisplay(); @@ -634,10 +633,11 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, Colormap cmap = XCreateColormap (aDisp, aParent, aVis->visual, AllocNone); + Quantity_Color aBgColor = myPlatformWindow->Background().Color(); XColor color; - color.red = (unsigned short) (myBgColor.rgb[0] * 0xFFFF); - color.green = (unsigned short) (myBgColor.rgb[1] * 0xFFFF); - color.blue = (unsigned short) (myBgColor.rgb[2] * 0xFFFF); + color.red = (unsigned short) (aBgColor.Red() * 0xFFFF); + color.green = (unsigned short) (aBgColor.Green() * 0xFFFF); + color.blue = (unsigned short) (aBgColor.Blue() * 0xFFFF); color.flags = DoRed | DoGreen | DoBlue; XAllocColor (aDisp, cmap, &color); @@ -751,7 +751,7 @@ Standard_Boolean OpenGl_Window::Activate() // function : Resize // purpose : call_subr_resize // ======================================================================= -void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow) +void OpenGl_Window::Resize() { #if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__) Display* aDisp = (Display* )myGlContext->myDisplay; @@ -759,12 +759,16 @@ void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow) return; #endif + Standard_Integer aWidth = 0; + Standard_Integer aHeight = 0; + myPlatformWindow->Size (aWidth, aHeight); + // If the size is not changed - do nothing - if ((myWidth == theCWindow.dx) && (myHeight == theCWindow.dy)) + if ((myWidth == aWidth) && (myHeight == aHeight)) return; - myWidth = theCWindow.dx; - myHeight = theCWindow.dy; + myWidth = aWidth; + myHeight = aHeight; #if !defined(_WIN32) && !defined(HAVE_EGL) && !defined(__ANDROID__) XResizeWindow (aDisp, myGlContext->myWindow, (unsigned int )myWidth, (unsigned int )myHeight); @@ -802,9 +806,9 @@ void OpenGl_Window::ReadDepths (const Standard_Integer theX, const Standard_ #if !defined(GL_ES_VERSION_2_0) glRasterPos2i (theX, theY); - DisableFeatures(); + myGlContext->DisableFeatures(); glReadPixels (theX, theY, theWidth, theHeight, GL_DEPTH_COMPONENT, GL_FLOAT, theDepths); - EnableFeatures(); + myGlContext->EnableFeatures(); #endif myGlContext->WorldViewState.Pop(); @@ -813,19 +817,6 @@ void OpenGl_Window::ReadDepths (const Standard_Integer theX, const Standard_ myGlContext->ApplyProjectionMatrix(); } -// ======================================================================= -// function : SetBackgroundColor -// purpose : call_subr_set_background -// ======================================================================= -void OpenGl_Window::SetBackgroundColor (const Standard_ShortReal theR, - const Standard_ShortReal theG, - const Standard_ShortReal theB) -{ - myBgColor.rgb[0] = theR; - myBgColor.rgb[1] = theG; - myBgColor.rgb[2] = theB; -} - #if !defined(__APPLE__) || defined(MACOSX_USE_GLX) // ======================================================================= @@ -866,87 +857,17 @@ void OpenGl_Window::Init() #endif } -#endif // !__APPLE__ - -// ======================================================================= -// function : EnableFeatures -// purpose : -// ======================================================================= -void OpenGl_Window::EnableFeatures() const -{ - // -} - // ======================================================================= -// function : DisableFeatures +// function : SetSwapInterval // purpose : // ======================================================================= -void OpenGl_Window::DisableFeatures() const +void OpenGl_Window::SetSwapInterval() { -#if !defined(GL_ES_VERSION_2_0) - glPixelTransferi (GL_MAP_COLOR, GL_FALSE); -#endif - - /* - * Disable stuff that's likely to slow down glDrawPixels. - * (Omit as much of this as possible, when you know in advance - * that the OpenGL state will already be set correctly.) - */ - glDisable(GL_DITHER); - glDisable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glDisable(GL_TEXTURE_2D); - glDisable(GL_STENCIL_TEST); - -#if !defined(GL_ES_VERSION_2_0) - glDisable(GL_LIGHTING); - glDisable(GL_ALPHA_TEST); - glDisable(GL_FOG); - glDisable(GL_LOGIC_OP); - glDisable(GL_TEXTURE_1D); - - glPixelTransferi(GL_MAP_COLOR, GL_FALSE); - glPixelTransferi(GL_RED_SCALE, 1); - glPixelTransferi(GL_RED_BIAS, 0); - glPixelTransferi(GL_GREEN_SCALE, 1); - glPixelTransferi(GL_GREEN_BIAS, 0); - glPixelTransferi(GL_BLUE_SCALE, 1); - glPixelTransferi(GL_BLUE_BIAS, 0); - glPixelTransferi(GL_ALPHA_SCALE, 1); - glPixelTransferi(GL_ALPHA_BIAS, 0); - - /* - * Disable extensions that could slow down glDrawPixels. - * (Actually, you should check for the presence of the proper - * extension before making these calls. I've omitted that - * code for simplicity.) - */ - - if ((myGlContext->myGlVerMajor >= 1) && (myGlContext->myGlVerMinor >= 2)) + if (mySwapInterval != myGlContext->caps->swapInterval) { -#ifdef GL_EXT_convolution - if (myGlContext->CheckExtension ("GL_CONVOLUTION_1D_EXT")) - glDisable(GL_CONVOLUTION_1D_EXT); - - if (myGlContext->CheckExtension ("GL_CONVOLUTION_2D_EXT")) - glDisable(GL_CONVOLUTION_2D_EXT); - - if (myGlContext->CheckExtension ("GL_SEPARABLE_2D_EXT")) - glDisable(GL_SEPARABLE_2D_EXT); -#endif - -#ifdef GL_EXT_histogram - if (myGlContext->CheckExtension ("GL_SEPARABLE_2D_EXT")) - glDisable(GL_HISTOGRAM_EXT); - - if (myGlContext->CheckExtension ("GL_MINMAX_EXT")) - glDisable(GL_MINMAX_EXT); -#endif - -#ifdef GL_EXT_texture3D - if (myGlContext->CheckExtension ("GL_TEXTURE_3D_EXT")) - glDisable(GL_TEXTURE_3D_EXT); -#endif + mySwapInterval = myGlContext->caps->swapInterval; + myGlContext->SetSwapInterval (mySwapInterval); } -#endif } + +#endif // !__APPLE__ diff --git a/src/OpenGl/OpenGl_Window.hxx b/src/OpenGl/OpenGl_Window.hxx index 1b4616cb38..4fd070f0d9 100644 --- a/src/OpenGl/OpenGl_Window.hxx +++ b/src/OpenGl/OpenGl_Window.hxx @@ -16,12 +16,12 @@ #ifndef _OpenGl_Window_Header #define _OpenGl_Window_Header +#include +#include #include -#include #include #include - #if defined(__APPLE__) #import #endif @@ -48,7 +48,7 @@ public: //! Main constructor - prepare GL context for specified window. Standard_EXPORT OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, + const Handle(Aspect_Window)& thePlatformWindow, Aspect_RenderingContext theGContext, const Handle(OpenGl_Caps)& theCaps, const Handle(OpenGl_Context)& theShareCtx); @@ -57,38 +57,34 @@ public: Standard_EXPORT virtual ~OpenGl_Window(); //! Resizes the window. - Standard_EXPORT virtual void Resize (const CALL_DEF_WINDOW& theCWindow); + Standard_EXPORT virtual void Resize(); //! Reads depth component for current scene into specified buffer. void ReadDepths (const Standard_Integer theX, const Standard_Integer theY, const Standard_Integer theWidth, const Standard_Integer theHeight, float* theDepths); - Standard_EXPORT void SetBackgroundColor (const Standard_ShortReal theR, - const Standard_ShortReal theG, - const Standard_ShortReal theB); + Handle(Aspect_Window) PlatformWindow() { return myPlatformWindow; } Standard_Integer Width() const { return myWidth; } Standard_Integer Height() const { return myHeight; } - const TEL_COLOUR& BackgroundColor() const { return myBgColor; } const Handle(OpenGl_Context)& GetGlContext() const { return myGlContext; } -protected: - //! Activates GL context and setup viewport. Standard_EXPORT void Init(); //! Makes GL context for this window active in current thread Standard_EXPORT virtual Standard_Boolean Activate(); - Standard_EXPORT void EnableFeatures() const; - Standard_EXPORT void DisableFeatures() const; + //! Sets swap interval for this window according to the context's settings. + Standard_EXPORT void SetSwapInterval(); protected: Handle(OpenGl_Context) myGlContext; Standard_Boolean myOwnGContext; //!< set to TRUE if GL context was not created by this class + Handle(Aspect_Window) myPlatformWindow; //!< software platform window wrapper #if defined(__APPLE__) #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE UIView* myUIView; @@ -98,7 +94,6 @@ protected: #endif Standard_Integer myWidth; //!< window width in pixels Standard_Integer myHeight; //!< window height in pixels - TEL_COLOUR myBgColor; //!< background color Standard_Integer mySwapInterval;//!< last assigned swap interval (VSync) for this window diff --git a/src/OpenGl/OpenGl_Window_1.mm b/src/OpenGl/OpenGl_Window_1.mm index 41e692a8e6..2e85cca3e2 100644 --- a/src/OpenGl/OpenGl_Window_1.mm +++ b/src/OpenGl/OpenGl_Window_1.mm @@ -54,33 +54,30 @@ // purpose : // ======================================================================= OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, + const Handle(Aspect_Window)& thePlatformWindow, Aspect_RenderingContext theGContext, const Handle(OpenGl_Caps)& theCaps, const Handle(OpenGl_Context)& theShareCtx) : myGlContext (new OpenGl_Context (theCaps)), myOwnGContext (theGContext == 0), -#if defined(__APPLE__) -#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE + myPlatformWindow (thePlatformWindow), +#if defined(__APPLE__) && defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE myUIView (NULL), #endif - myWidthPt (theCWindow.dx), - myHeightPt (theCWindow.dy), -#endif - myWidth (theCWindow.dx), - myHeight (theCWindow.dy), mySwapInterval (theCaps->swapInterval) { - myBgColor.rgb[0] = theCWindow.Background.r; - myBgColor.rgb[1] = theCWindow.Background.g; - myBgColor.rgb[2] = theCWindow.Background.b; - myBgColor.rgb[3] = 1.0f; + myPlatformWindow->Size (myWidth, myHeight); + +#if defined(__APPLE__) + myWidthPt = myWidth; + myHeightPt = myHeight; +#endif #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE EAGLContext* aGLContext = theGContext; if (aGLContext == NULL) { - void* aViewPtr = (void* )theCWindow.XWindow; + void* aViewPtr = (void* )myPlatformWindow->NativeHandle(); myUIView = (__bridge UIView* )aViewPtr; CAEAGLLayer* anEaglLayer = (CAEAGLLayer* )myUIView.layer; @@ -204,7 +201,7 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, aMsg); } - NSView* aView = (NSView* )theCWindow.XWindow; + NSView* aView = (NSView* )myPlatformWindow->NativeHandle(); [aGLContext setView: aView]; isCore = (aTryCore == 1); } @@ -248,17 +245,20 @@ OpenGl_Window::~OpenGl_Window() // function : Resize // purpose : call_subr_resize // ======================================================================= -void OpenGl_Window::Resize (const CALL_DEF_WINDOW& theCWindow) +void OpenGl_Window::Resize() { // If the size is not changed - do nothing - if (myWidthPt == theCWindow.dx - && myHeightPt == theCWindow.dy) + Standard_Integer aWidthPt = 0; + Standard_Integer aHeightPt = 0; + myPlatformWindow->Size (aWidthPt, aHeightPt); + if (myWidthPt == aWidthPt + && myHeightPt == aHeightPt) { return; } - myWidthPt = theCWindow.dx; - myHeightPt = theCWindow.dy; + myWidthPt = aWidthPt; + myHeightPt = aHeightPt; Init(); } @@ -354,4 +354,17 @@ void OpenGl_Window::Init() #endif } +// ======================================================================= +// function : SetSwapInterval +// purpose : +// ======================================================================= +void OpenGl_Window::SetSwapInterval() +{ + if (mySwapInterval != myGlContext->caps->swapInterval) + { + mySwapInterval = myGlContext->caps->swapInterval; + myGlContext->SetSwapInterval (mySwapInterval); + } +} + #endif // __APPLE__ diff --git a/src/OpenGl/OpenGl_Workspace.cxx b/src/OpenGl/OpenGl_Workspace.cxx index e0a14a404b..6195c66264 100644 --- a/src/OpenGl/OpenGl_Workspace.cxx +++ b/src/OpenGl/OpenGl_Workspace.cxx @@ -13,11 +13,11 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include -#include +#include #include +#include #include #include #include @@ -25,22 +25,26 @@ #include #include #include +#include +#include #include #include -#include #include #include -#include +#include #include -#include #include -#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE) - #include +#ifdef HAVE_GL2PS + #include + /* OCC22216 NOTE: linker dependency can be switched off by undefining macro. + Pragma comment for gl2ps.lib is defined only here. */ + #ifdef _MSC_VER + #pragma comment( lib, "gl2ps.lib" ) + #endif #endif - namespace { static const TEL_COLOUR THE_WHITE_COLOR = { { 1.0f, 1.0f, 1.0f, 1.0f } }; @@ -136,28 +140,15 @@ void OpenGl_Material::Init (const OPENGL_SURF_PROP& theProp) // function : OpenGl_Workspace // purpose : // ======================================================================= -OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, - Aspect_RenderingContext theGContext, - const Handle(OpenGl_Caps)& theCaps, - const Handle(OpenGl_Context)& theShareCtx) -: OpenGl_Window (theDriver, theCWindow, theGContext, theCaps, theShareCtx), - NamedStatus (0), +OpenGl_Workspace::OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow) +: NamedStatus (0), HighlightColor (&THE_WHITE_COLOR), - // - myHasFboBlit (Standard_True), - myToFlipOutput (Standard_False), - // - myViewId (-1), - myAntiAliasingMode (3), - myTransientDrawToFront (Standard_True), - myBackBufferRestored (Standard_False), - myIsImmediateDrawn (Standard_False), + myView (theView), + myWindow (theWindow), + myGlContext (!theWindow.IsNull() ? theWindow->GetGlContext() : NULL), myUseZBuffer (Standard_True), myUseDepthWrite (Standard_True), myUseGLLight (Standard_True), - myIsCullingEnabled (Standard_False), - myFrameCounter (0), // AspectLine_set (&myDefaultAspectLine), AspectLine_applied (NULL), @@ -175,44 +166,35 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive myModelViewMatrix (myDefaultMatrix), PolygonOffset_applied (THE_DEFAULT_POFFSET) { - myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - myMainSceneFbos[0] = new OpenGl_FrameBuffer(); - myMainSceneFbos[1] = new OpenGl_FrameBuffer(); - myImmediateSceneFbos[0] = new OpenGl_FrameBuffer(); - myImmediateSceneFbos[1] = new OpenGl_FrameBuffer(); - - if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs)) + if (!myGlContext.IsNull() && myGlContext->MakeCurrent()) { - // share and register for release once the resource is no longer used - myLineAttribs = new OpenGl_LineAttributes(); - myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs); - myLineAttribs->Init (myGlContext); - } + myGlContext->core11fwd->glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - // General initialization of the context + if (!myGlContext->GetResource ("OpenGl_LineAttributes", myLineAttribs)) + { + // share and register for release once the resource is no longer used + myLineAttribs = new OpenGl_LineAttributes(); + myGlContext->ShareResource ("OpenGl_LineAttributes", myLineAttribs); + myLineAttribs->Init (myGlContext); + } -#if !defined(GL_ES_VERSION_2_0) - if (myGlContext->core11 != NULL) - { - // Eviter d'avoir les faces mal orientees en noir. - // Pourrait etre utiliser pour detecter les problemes d'orientation - glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + // General initialization of the context - // Optimisation pour le Fog et l'antialiasing - glHint (GL_FOG_HINT, GL_FASTEST); - glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST); - } + #if !defined(GL_ES_VERSION_2_0) + if (myGlContext->core11 != NULL) + { + // Eviter d'avoir les faces mal orientees en noir. + // Pourrait etre utiliser pour detecter les problemes d'orientation + glLightModeli ((GLenum )GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); - glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST); -#endif + // Optimisation pour le Fog et l'antialiasing + glHint (GL_FOG_HINT, GL_FASTEST); + glHint (GL_POINT_SMOOTH_HINT, GL_FASTEST); + } - // AA mode - const char* anAaEnv = ::getenv ("CALL_OPENGL_ANTIALIASING_MODE"); - if (anAaEnv != NULL) - { - int v; - if (sscanf (anAaEnv, "%d", &v) > 0) myAntiAliasingMode = v; + glHint (GL_LINE_SMOOTH_HINT, GL_FASTEST); + glHint (GL_POLYGON_SMOOTH_HINT, GL_FASTEST); + #endif } myDefaultCappingAlgoFilter = new OpenGl_CappingAlgoFilter(); @@ -222,38 +204,6 @@ OpenGl_Workspace::OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDrive myFrontCulling.ChangeEdge() = 0; } -// ======================================================================= -// function : SetActiveView -// purpose : -// ======================================================================= -void OpenGl_Workspace::SetActiveView (const Handle(OpenGl_View)& theView, - const Standard_Integer theViewId) -{ - myView = theView; - myViewId = theViewId; -} - -// ======================================================================= -// function : SetImmediateModeDrawToFront -// purpose : -// ======================================================================= -Standard_Boolean OpenGl_Workspace::SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer) -{ - const Standard_Boolean aPrevMode = myTransientDrawToFront; - myTransientDrawToFront = theDrawToFrontBuffer; - return aPrevMode; -} - -inline void nullifyGlResource (Handle(OpenGl_Resource)& theResource, - const Handle(OpenGl_Context)& theCtx) -{ - if (!theResource.IsNull()) - { - theResource->Release (theCtx.operator->()); - theResource.Nullify(); - } -} - // ======================================================================= // function : ~OpenGl_Workspace // purpose : @@ -265,14 +215,6 @@ OpenGl_Workspace::~OpenGl_Workspace() myLineAttribs.Nullify(); myGlContext->ReleaseResource ("OpenGl_LineAttributes", Standard_True); } - - nullifyGlResource (myMainSceneFbos[0], myGlContext); - nullifyGlResource (myMainSceneFbos[1], myGlContext); - nullifyGlResource (myImmediateSceneFbos[0], myGlContext); - nullifyGlResource (myImmediateSceneFbos[1], myGlContext); - - myFullScreenQuad .Release (myGlContext.operator->()); - myFullScreenQuadFlip.Release (myGlContext.operator->()); } // ======================================================================= @@ -281,8 +223,10 @@ OpenGl_Workspace::~OpenGl_Workspace() // ======================================================================= Standard_Boolean OpenGl_Workspace::Activate() { - if (!OpenGl_Window::Activate()) + if (myWindow.IsNull() || !myWindow->Activate()) + { return Standard_False; + } ViewMatrix_applied = &myDefaultMatrix; StructureMatrix_applied = &myDefaultMatrix; @@ -482,12 +426,12 @@ void OpenGl_Workspace::setTextureParams (Handle(OpenGl_Texture)& } case Graphic3d_TOTM_SPRITE: { - if (GetGlContext()->core20fwd != NULL) + if (myGlContext->core20fwd != NULL) { glEnable (GL_POINT_SPRITE); glTexEnvi (GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE); anEnvMode = GL_REPLACE; - GetGlContext()->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); + myGlContext->core15->glPointParameteri (GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); } break; } @@ -684,899 +628,715 @@ Handle(OpenGl_Texture) OpenGl_Workspace::EnableTexture (const Handle(OpenGl_Text } // ======================================================================= -// function : bindDefaultFbo +// function : TelUpdatePolygonOffsets // purpose : // ======================================================================= -void OpenGl_Workspace::bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo) +static void TelUpdatePolygonOffsets (const TEL_POFFSET_PARAM& theOffsetData) { - OpenGl_FrameBuffer* anFbo = (theCustomFbo != NULL && theCustomFbo->IsValid()) - ? theCustomFbo - : (!myGlContext->DefaultFrameBuffer().IsNull() - && myGlContext->DefaultFrameBuffer()->IsValid() - ? myGlContext->DefaultFrameBuffer().operator->() - : NULL); - if (anFbo != NULL) + if ((theOffsetData.mode & Aspect_POM_Fill) == Aspect_POM_Fill) { - anFbo->BindBuffer (myGlContext); + glEnable (GL_POLYGON_OFFSET_FILL); } else { - #if !defined(GL_ES_VERSION_2_0) - myGlContext->SetReadDrawBuffer (GL_BACK); - #else - if (myGlContext->arbFBO != NULL) - { - myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); - } - #endif + glDisable (GL_POLYGON_OFFSET_FILL); } - myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight); -} -// ======================================================================= -// function : initBlitQuad -// purpose : -// ======================================================================= -OpenGl_VertexBuffer* OpenGl_Workspace::initBlitQuad (const Standard_Boolean theToFlip) -{ - OpenGl_VertexBuffer* aVerts = NULL; - if (!theToFlip) +#if !defined(GL_ES_VERSION_2_0) + if ((theOffsetData.mode & Aspect_POM_Line) == Aspect_POM_Line) { - aVerts = &myFullScreenQuad; - if (!aVerts->IsValid()) - { - OpenGl_Vec4 aQuad[4] = - { - OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 0.0f), - OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 1.0f), - OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 0.0f), - OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 1.0f) - }; - aVerts->Init (myGlContext, 4, 4, aQuad[0].GetData()); - } + glEnable (GL_POLYGON_OFFSET_LINE); } else { - aVerts = &myFullScreenQuadFlip; - if (!aVerts->IsValid()) - { - OpenGl_Vec4 aQuad[4] = - { - OpenGl_Vec4( 1.0f, -1.0f, 1.0f, 1.0f), - OpenGl_Vec4( 1.0f, 1.0f, 1.0f, 0.0f), - OpenGl_Vec4(-1.0f, -1.0f, 0.0f, 1.0f), - OpenGl_Vec4(-1.0f, 1.0f, 0.0f, 0.0f) - }; - aVerts->Init (myGlContext, 4, 4, aQuad[0].GetData()); - } + glDisable (GL_POLYGON_OFFSET_LINE); } - return aVerts; + + if ((theOffsetData.mode & Aspect_POM_Point) == Aspect_POM_Point) + { + glEnable (GL_POLYGON_OFFSET_POINT); + } + else + { + glDisable (GL_POLYGON_OFFSET_POINT); + } +#endif + + glPolygonOffset (theOffsetData.factor, theOffsetData.units); } // ======================================================================= -// function : blitBuffers +// function : updateMaterial // purpose : // ======================================================================= -bool OpenGl_Workspace::blitBuffers (OpenGl_FrameBuffer* theReadFbo, - OpenGl_FrameBuffer* theDrawFbo, - const Standard_Boolean theToFlip) +void OpenGl_Workspace::updateMaterial (const int theFlag) { - if (theReadFbo == NULL || myGlContext->IsFeedback()) - { - return false; - } - else if (theReadFbo == theDrawFbo) + // Case of hidden line + if (AspectFace_set->InteriorStyle() == Aspect_IS_HIDDENLINE) { - return true; + myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect + myAspectFaceHl.ChangeIntFront().matcol = myView->BackgroundColor(); + myAspectFaceHl.ChangeIntFront().color_mask = 0; + myAspectFaceHl.ChangeIntFront().color_mask = 0; + + AspectFace_set = &myAspectFaceHl; + return; } - // clear destination before blitting - if (theDrawFbo != NULL - && theDrawFbo->IsValid()) + const OPENGL_SURF_PROP* aProps = &AspectFace_set->IntFront(); + GLenum aFace = GL_FRONT_AND_BACK; + if (theFlag == TEL_BACK_MATERIAL) { - theDrawFbo->BindBuffer (myGlContext); + aFace = GL_BACK; + aProps = &AspectFace_set->IntBack(); } - else + else if (AspectFace_set->DistinguishingMode() == TOn + && !(NamedStatus & OPENGL_NS_RESMAT)) { - myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + aFace = GL_FRONT; } -#if !defined(GL_ES_VERSION_2_0) - myGlContext->core20fwd->glClearDepth (1.0); -#else - myGlContext->core20fwd->glClearDepthf (1.0f); -#endif - myGlContext->core20fwd->glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); -/*#if !defined(GL_ES_VERSION_2_0) - if (myGlContext->arbFBOBlit != NULL) + myMatTmp.Init (*aProps); + + // handling transparency + if (NamedStatus & OPENGL_NS_2NDPASSDO) { - theReadFbo->BindReadBuffer (myGlContext); - if (theDrawFbo != NULL - && theDrawFbo->IsValid()) - { - theDrawFbo->BindDrawBuffer (myGlContext); - } - else + // second pass + myMatTmp.Diffuse.a() = aProps->env_reflexion; + } + else + { + if (aProps->env_reflexion != 0.0f) { - myGlContext->arbFBO->glBindFramebuffer (GL_DRAW_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + // if the material reflects the environment scene, the second pass is needed + NamedStatus |= OPENGL_NS_2NDPASSNEED; } - // we don't copy stencil buffer here... does it matter for performance? - myGlContext->arbFBOBlit->glBlitFramebuffer (0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(), - 0, 0, theReadFbo->GetVPSizeX(), theReadFbo->GetVPSizeY(), - GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST); - if (theDrawFbo != NULL - && theDrawFbo->IsValid()) + if (aProps->trans != 1.0f) { - theDrawFbo->BindBuffer (myGlContext); + // render transparent + myMatTmp.Diffuse.a() = aProps->trans; + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); + if (myUseDepthWrite) + { + glDepthMask (GL_FALSE); + } } else { - myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); + // render opaque + if ((NamedStatus & OPENGL_NS_ANTIALIASING) == 0) + { + glBlendFunc (GL_ONE, GL_ZERO); + glDisable (GL_BLEND); + } + if (myUseDepthWrite) + { + glDepthMask (GL_TRUE); + } } } - else -#endif*/ + + // do not update material properties in case of zero reflection mode, + // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway. + if (aProps->color_mask == 0) { - myGlContext->core20fwd->glDepthFunc (GL_ALWAYS); - myGlContext->core20fwd->glDepthMask (GL_TRUE); - myGlContext->core20fwd->glEnable (GL_DEPTH_TEST); + return; + } - DisableTexture(); + // reset material + if (NamedStatus & OPENGL_NS_RESMAT) + { + #if !defined(GL_ES_VERSION_2_0) + if (myGlContext->core11 != NULL) + { + myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData()); + myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData()); + myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData()); + myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData()); + myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine()); + } + #endif - OpenGl_VertexBuffer* aVerts = initBlitQuad (theToFlip); - const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager(); - if (aVerts->IsValid() - && aManager->BindFboBlitProgram()) + if (theFlag == TEL_FRONT_MATERIAL) + { + myMatFront = myMatTmp; + myMatBack = myMatTmp; + } + else { - theReadFbo->ColorTexture() ->Bind (myGlContext, GL_TEXTURE0 + 0); - theReadFbo->DepthStencilTexture()->Bind (myGlContext, GL_TEXTURE0 + 1); - aVerts->BindVertexAttrib (myGlContext, Graphic3d_TOA_POS); + myMatBack = myMatTmp; + } - myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); + NamedStatus &= ~OPENGL_NS_RESMAT; + return; + } - aVerts->UnbindVertexAttrib (myGlContext, Graphic3d_TOA_POS); - theReadFbo->DepthStencilTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1); - theReadFbo->ColorTexture() ->Unbind (myGlContext, GL_TEXTURE0 + 0); + // reduce updates + OpenGl_Material& anOld = (theFlag == TEL_FRONT_MATERIAL) + ? myMatFront + : myMatBack; +#if !defined(GL_ES_VERSION_2_0) + if (myGlContext->core11 != NULL) + { + if (myMatTmp.Ambient.r() != anOld.Ambient.r() + || myMatTmp.Ambient.g() != anOld.Ambient.g() + || myMatTmp.Ambient.b() != anOld.Ambient.b()) + { + myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData()); } - else + if (myMatTmp.Diffuse.r() != anOld.Diffuse.r() + || myMatTmp.Diffuse.g() != anOld.Diffuse.g() + || myMatTmp.Diffuse.b() != anOld.Diffuse.b() + || fabs (myMatTmp.Diffuse.a() - anOld.Diffuse.a()) > 0.01f) { - TCollection_ExtendedString aMsg = TCollection_ExtendedString() - + "Error! FBO blitting has failed"; - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_ERROR_ARB, - 0, - GL_DEBUG_SEVERITY_HIGH_ARB, - aMsg); - myHasFboBlit = Standard_False; - theReadFbo->Release (myGlContext.operator->()); - return true; + myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData()); + } + if (myMatTmp.Specular.r() != anOld.Specular.r() + || myMatTmp.Specular.g() != anOld.Specular.g() + || myMatTmp.Specular.b() != anOld.Specular.b()) + { + myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData()); + } + if (myMatTmp.Emission.r() != anOld.Emission.r() + || myMatTmp.Emission.g() != anOld.Emission.g() + || myMatTmp.Emission.b() != anOld.Emission.b()) + { + myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData()); + } + if (myMatTmp.Shine() != anOld.Shine()) + { + myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine()); } } - return true; +#endif + anOld = myMatTmp; + if (aFace == GL_FRONT_AND_BACK) + { + myMatBack = myMatTmp; + } } // ======================================================================= -// function : drawStereoPair +// function : SetAspectLine // purpose : // ======================================================================= -void OpenGl_Workspace::drawStereoPair (const Graphic3d_CView& theCView) +const OpenGl_AspectLine * OpenGl_Workspace::SetAspectLine(const OpenGl_AspectLine *AnAspect) { - OpenGl_FrameBuffer* aPair[2] = - { - myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, - myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL - }; - if (aPair[0] == NULL - || aPair[1] == NULL - || !myTransientDrawToFront) - { - aPair[0] = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; - aPair[1] = myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL; - } + const OpenGl_AspectLine *AspectLine_old = AspectLine_set; + AspectLine_set = AnAspect; + return AspectLine_old; +} - if (aPair[0] == NULL - || aPair[1] == NULL) - { - return; - } +// ======================================================================= +// function : SetAspectFace +// purpose : +// ======================================================================= +const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace(const OpenGl_AspectFace *AnAspect) +{ + const OpenGl_AspectFace *AspectFace_old = AspectFace_set; + AspectFace_set = AnAspect; + return AspectFace_old; +} - Standard_Boolean toReverse = theCView.RenderParams.ToReverseStereo; - const Standard_Boolean isOddY = (theCView.DefWindow.top + theCView.DefWindow.dy) % 2 == 1; - const Standard_Boolean isOddX = theCView.DefWindow.left % 2 == 1; - if (isOddY - && (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_RowInterlaced - || theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard)) - { - toReverse = !toReverse; - } - if (isOddX - && (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ColumnInterlaced - || theCView.RenderParams.StereoMode == Graphic3d_StereoMode_ChessBoard)) - { - toReverse = !toReverse; - } +// ======================================================================= +// function : SetAspectMarker +// purpose : +// ======================================================================= +const OpenGl_AspectMarker * OpenGl_Workspace::SetAspectMarker(const OpenGl_AspectMarker *AnAspect) +{ + const OpenGl_AspectMarker *AspectMarker_old = AspectMarker_set; + AspectMarker_set = AnAspect; + return AspectMarker_old; +} - if (toReverse) +// ======================================================================= +// function : SetAspectText +// purpose : +// ======================================================================= +const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectText *AnAspect) +{ + const OpenGl_AspectText *AspectText_old = AspectText_set; + AspectText_set = AnAspect; + return AspectText_old; +} + +// ======================================================================= +// function : AspectLine +// purpose : +// ======================================================================= +const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean theWithApply) +{ + if (theWithApply) { - std::swap (aPair[0], aPair[1]); + AspectLine_applied = AspectLine_set; } - myGlContext->core20fwd->glDepthFunc (GL_ALWAYS); - myGlContext->core20fwd->glDepthMask (GL_TRUE); - myGlContext->core20fwd->glEnable (GL_DEPTH_TEST); + return AspectLine_set; +} - DisableTexture(); - OpenGl_VertexBuffer* aVerts = initBlitQuad (myToFlipOutput); +// ======================================================================= +// function : AspectFace +// purpose : +// ======================================================================= +const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean theToApply) +{ + if (!theToApply) + { + return AspectFace_set; + } - const Handle(OpenGl_ShaderManager)& aManager = myGlContext->ShaderManager(); - if (aVerts->IsValid() - && aManager->BindStereoProgram (theCView.RenderParams.StereoMode)) + if (myView->BackfacingModel() == Graphic3d_TOBM_AUTOMATIC) { - if (theCView.RenderParams.StereoMode == Graphic3d_StereoMode_Anaglyph) + // manage back face culling mode, disable culling when clipping is enabled + TelCullMode aCullingMode = (myGlContext->Clipping().IsClippingOrCappingOn() + || AspectFace_set->InteriorStyle() == Aspect_IS_HATCH) + ? TelCullNone + : (TelCullMode )AspectFace_set->CullingMode(); + if (aCullingMode != TelCullNone + && !(NamedStatus & OPENGL_NS_2NDPASSDO)) { - OpenGl_Mat4 aFilterL, aFilterR; - aFilterL.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); - aFilterR.SetDiagonal (Graphic3d_Vec4 (0.0f, 0.0f, 0.0f, 0.0f)); - switch (theCView.RenderParams.AnaglyphFilter) + // disable culling in case of translucent shading aspect + if (AspectFace_set->IntFront().trans != 1.0f) { - case Graphic3d_RenderingParams::Anaglyph_RedCyan_Simple: - { - aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); - aFilterR.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); - aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); - break; - } - case Graphic3d_RenderingParams::Anaglyph_RedCyan_Optimized: - { - aFilterL.SetRow (0, Graphic3d_Vec4 ( 0.4154f, 0.4710f, 0.16666667f, 0.0f)); - aFilterL.SetRow (1, Graphic3d_Vec4 (-0.0458f, -0.0484f, -0.0257f, 0.0f)); - aFilterL.SetRow (2, Graphic3d_Vec4 (-0.0547f, -0.0615f, 0.0128f, 0.0f)); - aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); - aFilterR.SetRow (0, Graphic3d_Vec4 (-0.01090909f, -0.03636364f, -0.00606061f, 0.0f)); - aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.37560000f, 0.73333333f, 0.01111111f, 0.0f)); - aFilterR.SetRow (2, Graphic3d_Vec4 (-0.06510000f, -0.12870000f, 1.29710000f, 0.0f)); - aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); - break; - } - case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Simple: - { - aFilterL.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); - aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); - aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); - break; - } - case Graphic3d_RenderingParams::Anaglyph_YellowBlue_Optimized: + aCullingMode = TelCullNone; + } + } + if (myCullingMode != aCullingMode) + { + myCullingMode = aCullingMode; + switch (myCullingMode) + { + case TelCullNone: + case TelCullUndefined: { - aFilterL.SetRow (0, Graphic3d_Vec4 ( 1.062f, -0.205f, 0.299f, 0.0f)); - aFilterL.SetRow (1, Graphic3d_Vec4 (-0.026f, 0.908f, 0.068f, 0.0f)); - aFilterL.SetRow (2, Graphic3d_Vec4 (-0.038f, -0.173f, 0.022f, 0.0f)); - aFilterL.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); - aFilterR.SetRow (0, Graphic3d_Vec4 (-0.016f, -0.123f, -0.017f, 0.0f)); - aFilterR.SetRow (1, Graphic3d_Vec4 ( 0.006f, 0.062f, -0.017f, 0.0f)); - aFilterR.SetRow (2, Graphic3d_Vec4 ( 0.094f, 0.185f, 0.911f, 0.0f)); - aFilterR.SetRow (3, Graphic3d_Vec4 ( 0.0f, 0.0f, 0.0f, 0.0f)); + glDisable (GL_CULL_FACE); break; } - case Graphic3d_RenderingParams::Anaglyph_GreenMagenta_Simple: + case TelCullFront: { - aFilterR.SetRow (0, Graphic3d_Vec4 (1.0f, 0.0f, 0.0f, 0.0f)); - aFilterL.SetRow (1, Graphic3d_Vec4 (0.0f, 1.0f, 0.0f, 0.0f)); - aFilterR.SetRow (2, Graphic3d_Vec4 (0.0f, 0.0f, 1.0f, 0.0f)); + glCullFace (GL_FRONT); + glEnable (GL_CULL_FACE); break; } - case Graphic3d_RenderingParams::Anaglyph_UserDefined: + case TelCullBack: { - aFilterL = theCView.RenderParams.AnaglyphLeft; - aFilterR = theCView.RenderParams.AnaglyphRight; + glCullFace (GL_BACK); + glEnable (GL_CULL_FACE); break; } } - myGlContext->ActiveProgram()->SetUniform (myGlContext, "uMultL", aFilterL); - myGlContext->ActiveProgram()->SetUniform (myGlContext, "uMultR", aFilterR); } - - aPair[0]->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + 0); - aPair[1]->ColorTexture()->Bind (myGlContext, GL_TEXTURE0 + 1); - aVerts->BindVertexAttrib (myGlContext, 0); - - myGlContext->core20fwd->glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); - - aVerts->UnbindVertexAttrib (myGlContext, 0); - aPair[1]->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + 1); - aPair[0]->ColorTexture()->Unbind (myGlContext, GL_TEXTURE0 + 0); - } - else - { - TCollection_ExtendedString aMsg = TCollection_ExtendedString() - + "Error! Anaglyph has failed"; - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_ERROR_ARB, - 0, - GL_DEBUG_SEVERITY_HIGH_ARB, - aMsg); - } -} - -// ======================================================================= -// function : Redraw -// purpose : -// ======================================================================= -void OpenGl_Workspace::Redraw (const Graphic3d_CView& theCView) -{ - if (!Activate()) - { - return; - } - - if (mySwapInterval != myGlContext->caps->swapInterval) - { - mySwapInterval = myGlContext->caps->swapInterval; - myGlContext->SetSwapInterval (mySwapInterval); } - ++myFrameCounter; - myIsCullingEnabled = theCView.IsCullingEnabled; - const Graphic3d_StereoMode aStereoMode = theCView.RenderParams.StereoMode; - const Handle(Graphic3d_Camera)& aCamera = myView->Camera(); - Graphic3d_Camera::Projection aProjectType = aCamera->ProjectionType(); - - // release pending GL resources - myGlContext->ReleaseDelayed(); - - // fetch OpenGl context state - myGlContext->FetchState(); - - OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO; - bool toSwap = myGlContext->IsRender() - && !myGlContext->caps->buffersNoSwap - && aFrameBuffer == NULL; - - Standard_Integer aSizeX = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeX() : myWidth; - Standard_Integer aSizeY = aFrameBuffer != NULL ? aFrameBuffer->GetVPSizeY() : myHeight; - - if ( aFrameBuffer == NULL - && !myGlContext->DefaultFrameBuffer().IsNull() - && myGlContext->DefaultFrameBuffer()->IsValid()) + if (AspectFace_set == AspectFace_applied) { - aFrameBuffer = myGlContext->DefaultFrameBuffer().operator->(); + return AspectFace_set; } - if (myHasFboBlit - && (myTransientDrawToFront || aProjectType == Graphic3d_Camera::Projection_Stereo)) +#if !defined(GL_ES_VERSION_2_0) + const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle(); + if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle() != anIntstyle) { - if (myMainSceneFbos[0]->GetVPSizeX() != aSizeX - || myMainSceneFbos[0]->GetVPSizeY() != aSizeY) + switch (anIntstyle) { - // prepare FBOs containing main scene - // for further blitting and rendering immediate presentations on top - if (myGlContext->core20fwd != NULL) + case Aspect_IS_EMPTY: + case Aspect_IS_HOLLOW: { - myMainSceneFbos[0]->Init (myGlContext, aSizeX, aSizeY); + glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); + break; } - if (!myGlContext->caps->useSystemBuffer && myMainSceneFbos[0]->IsValid()) + case Aspect_IS_HATCH: { - myImmediateSceneFbos[0]->InitLazy (myGlContext, aSizeX, aSizeY); + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + myLineAttribs->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch() : TEL_HS_SOLID); + break; } - } - } - else - { - myMainSceneFbos [0]->Release (myGlContext.operator->()); - myMainSceneFbos [1]->Release (myGlContext.operator->()); - myImmediateSceneFbos[0]->Release (myGlContext.operator->()); - myImmediateSceneFbos[1]->Release (myGlContext.operator->()); - myMainSceneFbos [0]->ChangeViewport (0, 0); - myMainSceneFbos [1]->ChangeViewport (0, 0); - myImmediateSceneFbos[0]->ChangeViewport (0, 0); - myImmediateSceneFbos[1]->ChangeViewport (0, 0); - } - - if (aProjectType == Graphic3d_Camera::Projection_Stereo - && myMainSceneFbos[0]->IsValid()) - { - myMainSceneFbos[1]->InitLazy (myGlContext, aSizeX, aSizeY); - if (!myMainSceneFbos[1]->IsValid()) - { - // no enough memory? - aProjectType = Graphic3d_Camera::Projection_Perspective; - } - else if (!myTransientDrawToFront) - { - // - } - else if (!myGlContext->HasStereoBuffers() - || aStereoMode != Graphic3d_StereoMode_QuadBuffer) - { - myImmediateSceneFbos[0]->InitLazy (myGlContext, aSizeX, aSizeY); - myImmediateSceneFbos[1]->InitLazy (myGlContext, aSizeX, aSizeY); - if (!myImmediateSceneFbos[0]->IsValid() - || !myImmediateSceneFbos[1]->IsValid()) + case Aspect_IS_SOLID: + case Aspect_IS_HIDDENLINE: + { + glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); + if (myGlContext->core11 != NULL) + { + glDisable (GL_POLYGON_STIPPLE); + } + break; + } + case Aspect_IS_POINT: { - aProjectType = Graphic3d_Camera::Projection_Perspective; + glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); + break; } } } - if (aProjectType == Graphic3d_Camera::Projection_Stereo) + if (anIntstyle == Aspect_IS_HATCH) { - OpenGl_FrameBuffer* aMainFbos[2] = - { - myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL, - myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL - }; - OpenGl_FrameBuffer* anImmFbos[2] = - { - myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, - myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL - }; - - if (!myTransientDrawToFront) - { - anImmFbos[0] = aMainFbos[0]; - anImmFbos[1] = aMainFbos[1]; - } - else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip - || aStereoMode == Graphic3d_StereoMode_QuadBuffer) - { - anImmFbos[0] = NULL; - anImmFbos[1] = NULL; - } - - #if !defined(GL_ES_VERSION_2_0) - myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); - #endif - redraw1 (theCView, aMainFbos[0], Graphic3d_Camera::Projection_MonoLeftEye); - myBackBufferRestored = Standard_True; - myIsImmediateDrawn = Standard_False; - #if !defined(GL_ES_VERSION_2_0) - myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); - #endif - if (!redrawImmediate (theCView, aMainFbos[0], aProjectType, anImmFbos[0])) - { - toSwap = false; - } - else if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip - && toSwap) + const Tint hatchstyle = AspectFace_set->Hatch(); + if (AspectFace_applied == NULL || AspectFace_applied->Hatch() != hatchstyle) { - myGlContext->SwapBuffers(); - } - - #if !defined(GL_ES_VERSION_2_0) - myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK); - #endif - redraw1 (theCView, aMainFbos[1], Graphic3d_Camera::Projection_MonoRightEye); - myBackBufferRestored = Standard_True; - myIsImmediateDrawn = Standard_False; - if (!redrawImmediate (theCView, aMainFbos[1], aProjectType, anImmFbos[1])) - { - toSwap = false; + myLineAttribs->SetTypeOfHatch (hatchstyle); } + } +#endif - if (anImmFbos[0] != NULL) + // Aspect_POM_None means: do not change current settings + if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None) + { + if (PolygonOffset_applied.mode != AspectFace_set->PolygonOffset().mode + || PolygonOffset_applied.factor != AspectFace_set->PolygonOffset().factor + || PolygonOffset_applied.units != AspectFace_set->PolygonOffset().units) { - bindDefaultFbo (aFrameBuffer); - drawStereoPair (theCView); + SetPolygonOffset (AspectFace_set->PolygonOffset().mode, + AspectFace_set->PolygonOffset().factor, + AspectFace_set->PolygonOffset().units); } } - else + + updateMaterial (TEL_FRONT_MATERIAL); + if (AspectFace_set->DistinguishingMode() == TOn) { - OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; - OpenGl_FrameBuffer* anImmFbo = aFrameBuffer; - if (!myGlContext->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid()) - { - anImmFbo = myImmediateSceneFbos[0].operator->(); - } + updateMaterial (TEL_BACK_MATERIAL); + } - #if !defined(GL_ES_VERSION_2_0) - if (aMainFbo == NULL - && aFrameBuffer == NULL) - { - myGlContext->SetReadDrawBuffer (GL_BACK); - } - #endif - redraw1 (theCView, aMainFbo != NULL ? aMainFbo : aFrameBuffer, aProjectType); - myBackBufferRestored = Standard_True; - myIsImmediateDrawn = Standard_False; - if (!redrawImmediate (theCView, aMainFbo, aProjectType, anImmFbo)) + if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) + { + if (AspectFace_set->DoTextureMap()) { - toSwap = false; + EnableTexture (AspectFace_set->TextureRes (myGlContext), + AspectFace_set->TextureParams()); } - - if (anImmFbo != NULL - && anImmFbo != aFrameBuffer) + else { - blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput); + DisableTexture(); } } -#if defined(_WIN32) && defined(HAVE_VIDEOCAPTURE) - if (OpenGl_AVIWriter_AllowWriting (theCView.DefWindow.XWindow)) - { - GLint params[4]; - glGetIntegerv (GL_VIEWPORT, params); - int nWidth = params[2] & ~0x7; - int nHeight = params[3] & ~0x7; - - const int nBitsPerPixel = 24; - GLubyte* aDumpData = new GLubyte[nWidth * nHeight * nBitsPerPixel / 8]; + AspectFace_applied = AspectFace_set; + return AspectFace_set; +} - glPixelStorei (GL_PACK_ALIGNMENT, 1); - glReadPixels (0, 0, nWidth, nHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, aDumpData); - OpenGl_AVIWriter_AVIWriter (aDumpData, nWidth, nHeight, nBitsPerPixel); - delete[] aDumpData; - } -#endif +//======================================================================= +//function : SetPolygonOffset +//purpose : +//======================================================================= +void OpenGl_Workspace::SetPolygonOffset (int theMode, + Standard_ShortReal theFactor, + Standard_ShortReal theUnits) +{ + PolygonOffset_applied.mode = theMode; + PolygonOffset_applied.factor = theFactor; + PolygonOffset_applied.units = theUnits; - // bind default FBO - bindDefaultFbo(); + TelUpdatePolygonOffsets (PolygonOffset_applied); +} - // Swap the buffers - if (toSwap) +// ======================================================================= +// function : AspectMarker +// purpose : +// ======================================================================= +const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply) +{ + if (theToApply && (AspectMarker_set != AspectMarker_applied)) { - GetGlContext()->SwapBuffers(); - if (!myMainSceneFbos[0]->IsValid()) + if (!AspectMarker_applied || (AspectMarker_set->Scale() != AspectMarker_applied->Scale())) { - myBackBufferRestored = Standard_False; + #if !defined(GL_ES_VERSION_2_0) + glPointSize (AspectMarker_set->Scale()); + #ifdef HAVE_GL2PS + gl2psPointSize (AspectMarker_set->Scale()); + #endif + #endif } + AspectMarker_applied = AspectMarker_set; } - else - { - myGlContext->core11fwd->glFlush(); - } - - // reset render mode state - myGlContext->FetchState(); + return AspectMarker_set; } // ======================================================================= -// function : redraw1 +// function : AspectText // purpose : // ======================================================================= -void OpenGl_Workspace::redraw1 (const Graphic3d_CView& theCView, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_Camera::Projection theProjection) +const OpenGl_AspectText* OpenGl_Workspace::AspectText (const Standard_Boolean theWithApply) { - if (myView.IsNull()) + if (theWithApply) { - return; - } - - if (theReadDrawFbo != NULL) - { - theReadDrawFbo->BindBuffer (myGlContext); - theReadDrawFbo->SetupViewport (myGlContext); - } - else - { - myGlContext->core11fwd->glViewport (0, 0, myWidth, myHeight); + AspectText_applied = AspectText_set; + TextParam_applied = TextParam_set; } - // request reset of material - NamedStatus |= OPENGL_NS_RESMAT; - - myUseZBuffer = Standard_True; - myUseDepthWrite = Standard_True; - GLbitfield toClear = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; - glDepthFunc (GL_LEQUAL); - glDepthMask (GL_TRUE); - glEnable (GL_DEPTH_TEST); - -#if !defined(GL_ES_VERSION_2_0) - glClearDepth (1.0); -#else - glClearDepthf (1.0f); -#endif - - if (NamedStatus & OPENGL_NS_WHITEBACK) - { - // set background to white - glClearColor (1.0f, 1.0f, 1.0f, 1.0f); - } - else - { - glClearColor (myBgColor.rgb[0], myBgColor.rgb[1], myBgColor.rgb[2], 0.0f); - } - - glClear (toClear); - - Handle(OpenGl_Workspace) aWS (this); - myView->Render (myPrintContext, aWS, theReadDrawFbo, theProjection, theCView, Standard_False); + return AspectText_set; } // ======================================================================= -// function : copyBackToFront +// function : Width // purpose : // ======================================================================= -void OpenGl_Workspace::copyBackToFront() +Standard_Integer OpenGl_Workspace::Width() const { -#if !defined(GL_ES_VERSION_2_0) - - OpenGl_Mat4 aProjectMat; - Graphic3d_TransformUtils::Ortho2D (aProjectMat, - 0.f, static_cast (myWidth), 0.f, static_cast (myHeight)); - - myGlContext->WorldViewState.Push(); - myGlContext->ProjectionState.Push(); - - myGlContext->WorldViewState.SetIdentity(); - myGlContext->ProjectionState.SetCurrent (aProjectMat); - - myGlContext->ApplyProjectionMatrix(); - myGlContext->ApplyWorldViewMatrix(); - - DisableFeatures(); - - switch (myGlContext->DrawBuffer()) - { - case GL_BACK_LEFT: - { - myGlContext->SetReadBuffer (GL_BACK_LEFT); - myGlContext->SetDrawBuffer (GL_FRONT_LEFT); - break; - } - case GL_BACK_RIGHT: - { - myGlContext->SetReadBuffer (GL_BACK_RIGHT); - myGlContext->SetDrawBuffer (GL_FRONT_RIGHT); - break; - } - default: - { - myGlContext->SetReadBuffer (GL_BACK); - myGlContext->SetDrawBuffer (GL_FRONT); - break; - } - } + return !myView->GlWindow().IsNull() ? myView->GlWindow()->Width() : 0; +} - glRasterPos2i (0, 0); - glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_COLOR); - //glCopyPixels (0, 0, myWidth + 1, myHeight + 1, GL_DEPTH); +// ======================================================================= +// function : Height +// purpose : +// ======================================================================= +Standard_Integer OpenGl_Workspace::Height() const +{ + return !myView->GlWindow().IsNull() ? myView->GlWindow()->Height() : 0; +} - EnableFeatures(); +// ======================================================================= +// function : UseGLLight +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_Workspace::UseGLLight() const +{ + return myView->IsGLLightEnabled(); +} - myGlContext->WorldViewState.Pop(); - myGlContext->ProjectionState.Pop(); - myGlContext->ApplyProjectionMatrix(); +// ======================================================================= +// function : AntiAliasingMode +// purpose : +// ======================================================================= +Standard_Integer OpenGl_Workspace::AntiAliasingMode() const +{ + return myView->IsAntialiasingEnabled(); +} - // read/write from front buffer now - myGlContext->SetReadBuffer (myGlContext->DrawBuffer()); -#endif - myIsImmediateDrawn = Standard_False; +// ======================================================================= +// function : IsCullingEnabled +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_Workspace::IsCullingEnabled() const +{ + return myView->IsCullingEnabled(); } // ======================================================================= -// function : DisplayCallback +// function : FBOCreate // purpose : // ======================================================================= -void OpenGl_Workspace::DisplayCallback (const Graphic3d_CView& theCView, - Standard_Integer theReason) +Graphic3d_PtrFrameBuffer OpenGl_Workspace::FBOCreate (const Standard_Integer theWidth, + const Standard_Integer theHeight) { - if (theCView.GDisplayCB == NULL) + // activate OpenGL context + if (!Activate()) + return NULL; + + // create the FBO + const Handle(OpenGl_Context)& aCtx = GetGlContext(); + OpenGl_FrameBuffer* aFrameBuffer = new OpenGl_FrameBuffer(); + if (!aFrameBuffer->Init (aCtx, theWidth, theHeight)) { - return; + aFrameBuffer->Release (aCtx.operator->()); + delete aFrameBuffer; + return NULL; } - - Aspect_GraphicCallbackStruct aCallData; - aCallData.reason = theReason; - aCallData.glContext = myGlContext; - aCallData.wsID = theCView.WsId; - aCallData.viewID = theCView.ViewId; - aCallData.IsCoreProfile = (myGlContext->core11 == NULL); - theCView.GDisplayCB (theCView.DefWindow.XWindow, theCView.GClientData, &aCallData); + return (Graphic3d_PtrFrameBuffer )aFrameBuffer; } // ======================================================================= -// function : RedrawImmediate +// function : FBORelease // purpose : // ======================================================================= -void OpenGl_Workspace::RedrawImmediate (const Graphic3d_CView& theCView) +void OpenGl_Workspace::FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr) { - if (!myTransientDrawToFront - || !myBackBufferRestored - || (myGlContext->caps->buffersNoSwap && !myMainSceneFbos[0]->IsValid())) + // activate OpenGL context + if (!Activate() + || theFBOPtr == NULL) { - Redraw (theCView); return; } - else if (!Activate()) + + // release the object + OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer*)theFBOPtr; + if (aFrameBuffer != NULL) { - return; + aFrameBuffer->Release (GetGlContext().operator->()); } + delete aFrameBuffer; +} - const Handle(Graphic3d_Camera)& aCamera = myView->Camera(); - Graphic3d_Camera::Projection aProjectType = aCamera->ProjectionType(); - OpenGl_FrameBuffer* aFrameBuffer = (OpenGl_FrameBuffer* )theCView.ptrFBO; - if ( aFrameBuffer == NULL - && !myGlContext->DefaultFrameBuffer().IsNull() - && myGlContext->DefaultFrameBuffer()->IsValid()) +inline bool getDataFormat (const Image_PixMap& theData, + GLenum& thePixelFormat, + GLenum& theDataType) +{ + thePixelFormat = GL_RGB; + theDataType = GL_UNSIGNED_BYTE; + switch (theData.Format()) { - aFrameBuffer = myGlContext->DefaultFrameBuffer().operator->(); + #if !defined(GL_ES_VERSION_2_0) + case Image_PixMap::ImgGray: + thePixelFormat = GL_DEPTH_COMPONENT; + theDataType = GL_UNSIGNED_BYTE; + return true; + case Image_PixMap::ImgGrayF: + thePixelFormat = GL_DEPTH_COMPONENT; + theDataType = GL_FLOAT; + return true; + case Image_PixMap::ImgBGR: + thePixelFormat = GL_BGR; + theDataType = GL_UNSIGNED_BYTE; + return true; + case Image_PixMap::ImgBGRA: + case Image_PixMap::ImgBGR32: + thePixelFormat = GL_BGRA; + theDataType = GL_UNSIGNED_BYTE; + return true; + case Image_PixMap::ImgBGRF: + thePixelFormat = GL_BGR; + theDataType = GL_FLOAT; + return true; + case Image_PixMap::ImgBGRAF: + thePixelFormat = GL_BGRA; + theDataType = GL_FLOAT; + return true; + #else + case Image_PixMap::ImgGray: + case Image_PixMap::ImgGrayF: + case Image_PixMap::ImgBGR: + case Image_PixMap::ImgBGRA: + case Image_PixMap::ImgBGR32: + case Image_PixMap::ImgBGRF: + case Image_PixMap::ImgBGRAF: + return false; + #endif + case Image_PixMap::ImgRGB: + thePixelFormat = GL_RGB; + theDataType = GL_UNSIGNED_BYTE; + return true; + case Image_PixMap::ImgRGBA: + case Image_PixMap::ImgRGB32: + thePixelFormat = GL_RGBA; + theDataType = GL_UNSIGNED_BYTE; + return true; + case Image_PixMap::ImgRGBF: + thePixelFormat = GL_RGB; + theDataType = GL_FLOAT; + return true; + case Image_PixMap::ImgRGBAF: + thePixelFormat = GL_RGBA; + theDataType = GL_FLOAT; + return true; + case Image_PixMap::ImgAlpha: + case Image_PixMap::ImgAlphaF: + return false; // GL_ALPHA is no more supported in core context + case Image_PixMap::ImgUNKNOWN: + return false; } + return false; +} - const Graphic3d_StereoMode aStereoMode = theCView.RenderParams.StereoMode; - if (aProjectType == Graphic3d_Camera::Projection_Stereo) +// ======================================================================= +// function : getAligned +// purpose : +// ======================================================================= +inline Standard_Size getAligned (const Standard_Size theNumber, + const Standard_Size theAlignment) +{ + return theNumber + theAlignment - 1 - (theNumber - 1) % theAlignment; +} + +// ======================================================================= +// function : BufferDump +// purpose : +// ======================================================================= +Standard_Boolean OpenGl_Workspace::BufferDump (OpenGl_FrameBuffer* theFBOPtr, + Image_PixMap& theImage, + const Graphic3d_BufferType& theBufferType) +{ + GLenum aFormat, aType; + if (theImage.IsEmpty() + || !getDataFormat (theImage, aFormat, aType) + || !Activate()) { - if (myMainSceneFbos[0]->IsValid() - && !myMainSceneFbos[1]->IsValid()) - { - aProjectType = Graphic3d_Camera::Projection_Perspective; - } + return Standard_False; } - - bool toSwap = false; - if (aProjectType == Graphic3d_Camera::Projection_Stereo) +#if !defined(GL_ES_VERSION_2_0) + GLint aReadBufferPrev = GL_BACK; + if (theBufferType == Graphic3d_BT_Depth + && aFormat != GL_DEPTH_COMPONENT) { - OpenGl_FrameBuffer* aMainFbos[2] = - { - myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL, - myMainSceneFbos[1]->IsValid() ? myMainSceneFbos[1].operator->() : NULL - }; - OpenGl_FrameBuffer* anImmFbos[2] = - { - myImmediateSceneFbos[0]->IsValid() ? myImmediateSceneFbos[0].operator->() : NULL, - myImmediateSceneFbos[1]->IsValid() ? myImmediateSceneFbos[1].operator->() : NULL - }; - if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip - || aStereoMode == Graphic3d_StereoMode_QuadBuffer) - { - anImmFbos[0] = NULL; - anImmFbos[1] = NULL; - } - - if (myGlContext->arbFBO != NULL) - { - myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); - } - #if !defined(GL_ES_VERSION_2_0) - if (anImmFbos[0] == NULL) - { - myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_LEFT : GL_BACK); - } - #endif - toSwap = redrawImmediate (theCView, - aMainFbos[0], - Graphic3d_Camera::Projection_MonoLeftEye, - anImmFbos[0], - Standard_True) || toSwap; - if (aStereoMode == Graphic3d_StereoMode_SoftPageFlip - && toSwap - && !myGlContext->caps->buffersNoSwap) - { - myGlContext->SwapBuffers(); - } + return Standard_False; + } +#endif - if (myGlContext->arbFBO != NULL) - { - myGlContext->arbFBO->glBindFramebuffer (GL_FRAMEBUFFER, OpenGl_FrameBuffer::NO_FRAMEBUFFER); - } - #if !defined(GL_ES_VERSION_2_0) - if (anImmFbos[1] == NULL) - { - myGlContext->SetReadDrawBuffer (aStereoMode == Graphic3d_StereoMode_QuadBuffer ? GL_BACK_RIGHT : GL_BACK); - } - #endif - toSwap = redrawImmediate (theCView, - aMainFbos[1], - Graphic3d_Camera::Projection_MonoRightEye, - anImmFbos[1], - Standard_True) || toSwap; - if (anImmFbos[0] != NULL) - { - bindDefaultFbo (aFrameBuffer); - drawStereoPair (theCView); - } + // bind FBO if used + if (theFBOPtr != NULL && theFBOPtr->IsValid()) + { + theFBOPtr->BindBuffer (GetGlContext()); } else { - OpenGl_FrameBuffer* aMainFbo = myMainSceneFbos[0]->IsValid() ? myMainSceneFbos[0].operator->() : NULL; - OpenGl_FrameBuffer* anImmFbo = aFrameBuffer; - if (!myGlContext->caps->useSystemBuffer && myImmediateSceneFbos[0]->IsValid()) - { - anImmFbo = myImmediateSceneFbos[0].operator->(); - } #if !defined(GL_ES_VERSION_2_0) - if (aMainFbo == NULL) - { - myGlContext->SetReadDrawBuffer (GL_BACK); - } + glGetIntegerv (GL_READ_BUFFER, &aReadBufferPrev); + GLint aDrawBufferPrev = GL_BACK; + glGetIntegerv (GL_DRAW_BUFFER, &aDrawBufferPrev); + glReadBuffer (aDrawBufferPrev); #endif - toSwap = redrawImmediate (theCView, - aMainFbo, - aProjectType, - anImmFbo, - Standard_True) || toSwap; - if (anImmFbo != NULL - && anImmFbo != aFrameBuffer) - { - blitBuffers (anImmFbo, aFrameBuffer, myToFlipOutput); - } } - // bind default FBO - bindDefaultFbo(); + // setup alignment + const GLint anAligment = Min (GLint(theImage.MaxRowAligmentBytes()), 8); // limit to 8 bytes for OpenGL + glPixelStorei (GL_PACK_ALIGNMENT, anAligment); + bool isBatchCopy = !theImage.IsTopDown(); - if (toSwap - && !myGlContext->caps->buffersNoSwap) + const GLint anExtraBytes = GLint(theImage.RowExtraBytes()); + GLint aPixelsWidth = GLint(theImage.SizeRowBytes() / theImage.SizePixelBytes()); + Standard_Size aSizeRowBytesEstim = getAligned (theImage.SizePixelBytes() * aPixelsWidth, anAligment); + if (anExtraBytes < anAligment) { - myGlContext->SwapBuffers(); + aPixelsWidth = 0; } - else - { - myGlContext->core11fwd->glFlush(); - } -} - -// ======================================================================= -// function : redrawImmediate -// purpose : -// ======================================================================= -bool OpenGl_Workspace::redrawImmediate (const Graphic3d_CView& theCView, - OpenGl_FrameBuffer* theReadFbo, - const Graphic3d_Camera::Projection theProjection, - OpenGl_FrameBuffer* theDrawFbo, - const Standard_Boolean theIsPartialUpdate) -{ - GLboolean toCopyBackToFront = GL_FALSE; - if (!myTransientDrawToFront) + else if (aSizeRowBytesEstim != theImage.SizeRowBytes()) { - myBackBufferRestored = Standard_False; + aPixelsWidth = 0; + isBatchCopy = false; } - else if (theReadFbo != NULL - && theReadFbo->IsValid() - && myGlContext->IsRender()) +#if !defined(GL_ES_VERSION_2_0) + glPixelStorei (GL_PACK_ROW_LENGTH, aPixelsWidth); +#else + if (aPixelsWidth != 0) { - if (!blitBuffers (theReadFbo, theDrawFbo)) - { - return true; - } + isBatchCopy = false; } - else if (theDrawFbo == NULL) +#endif + + if (!isBatchCopy) { - #if !defined(GL_ES_VERSION_2_0) - myGlContext->core11fwd->glGetBooleanv (GL_DOUBLEBUFFER, &toCopyBackToFront); - #endif - if (toCopyBackToFront) + // copy row by row + for (Standard_Size aRow = 0; aRow < theImage.SizeY(); ++aRow) { - if (!myView->HasImmediateStructures() - && !theIsPartialUpdate) - { - // prefer Swap Buffers within Redraw in compatibility mode (without FBO) - return true; - } - copyBackToFront(); - } - else - { - myBackBufferRestored = Standard_False; + // Image_PixMap rows indexation always starts from the upper corner + // while order in memory depends on the flag and processed by ChangeRow() method + glReadPixels (0, GLint(theImage.SizeY() - aRow - 1), GLsizei (theImage.SizeX()), 1, aFormat, aType, theImage.ChangeRow (aRow)); } } else { - myBackBufferRestored = Standard_False; + glReadPixels (0, 0, GLsizei (theImage.SizeX()), GLsizei (theImage.SizeY()), aFormat, aType, theImage.ChangeData()); } - myIsImmediateDrawn = Standard_True; - - Handle(OpenGl_Workspace) aWS (this); - myUseZBuffer = Standard_True; - myUseDepthWrite = Standard_True; - glDepthFunc (GL_LEQUAL); - glDepthMask (GL_TRUE); - glEnable (GL_DEPTH_TEST); + glPixelStorei (GL_PACK_ALIGNMENT, 1); #if !defined(GL_ES_VERSION_2_0) - glClearDepth (1.0); -#else - glClearDepthf (1.0f); + glPixelStorei (GL_PACK_ROW_LENGTH, 0); #endif - myView->Render (myPrintContext, aWS, theDrawFbo, theProjection, - theCView, Standard_True); - - return !toCopyBackToFront; + if (theFBOPtr != NULL && theFBOPtr->IsValid()) + { + theFBOPtr->UnbindBuffer (GetGlContext()); + } + else + { + #if !defined(GL_ES_VERSION_2_0) + glReadBuffer (aReadBufferPrev); + #endif + } + return Standard_True; } - // ======================================================================= // function : CanRender // purpose : diff --git a/src/OpenGl/OpenGl_Workspace.hxx b/src/OpenGl/OpenGl_Workspace.hxx index 8206494841..fb977c5738 100644 --- a/src/OpenGl/OpenGl_Workspace.hxx +++ b/src/OpenGl/OpenGl_Workspace.hxx @@ -16,51 +16,29 @@ #ifndef _OpenGl_Workspace_Header #define _OpenGl_Workspace_Header -#include -#include - -#include - -#include -#include -#include -#include -#include #include #include -#include -#include -#include - #include -#include - -#include #include +#include #include +#include #include #include #include -#include -#include #include -#include -#include -#include - - #include #include +#include #include +#include +#include class OpenGl_AspectLine; class OpenGl_AspectMarker; class OpenGl_AspectText; -class OpenGl_FrameBuffer; -class OpenGl_Structure; -class OpenGl_TriangleSet; class OpenGl_Element; class OpenGl_View; class Image_PixMap; @@ -129,66 +107,39 @@ public: }; class OpenGl_Workspace; -DEFINE_STANDARD_HANDLE(OpenGl_Workspace,OpenGl_Window) +DEFINE_STANDARD_HANDLE(OpenGl_Workspace,Standard_Transient) -//! Represents window with GL context. +//! Rendering workspace. //! Provides methods to render primitives and maintain GL state. -class OpenGl_Workspace : public OpenGl_Window +class OpenGl_Workspace : public Standard_Transient { public: - //! Main constructor - prepare GL context for specified window. - Standard_EXPORT OpenGl_Workspace (const Handle(OpenGl_GraphicDriver)& theDriver, - const CALL_DEF_WINDOW& theCWindow, - Aspect_RenderingContext theGContext, - const Handle(OpenGl_Caps)& theCaps, - const Handle(OpenGl_Context)& theShareCtx); + //! Constructor of rendering workspace. + Standard_EXPORT OpenGl_Workspace (OpenGl_View* theView, const Handle(OpenGl_Window)& theWindow); //! Destructor Standard_EXPORT virtual ~OpenGl_Workspace(); - Standard_EXPORT void SetActiveView (const Handle(OpenGl_View)& theView, - const Standard_Integer theViewId); - - const Handle(OpenGl_View)& ActiveView() const { return myView; } + //! Activate rendering context. + Standard_EXPORT Standard_Boolean Activate(); - Standard_Integer ActiveViewId() const { return myViewId; } + OpenGl_View* View() const { return myView; } - //! Redraw the window. - Standard_EXPORT virtual void Redraw (const Graphic3d_CView& theCView); + const Handle(OpenGl_Context)& GetGlContext() { return myGlContext; } - Standard_Boolean SetImmediateModeDrawToFront (const Standard_Boolean theDrawToFrontBuffer); - Standard_EXPORT virtual void RedrawImmediate (const Graphic3d_CView& theCView); + Standard_EXPORT Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); - //! Mark cached view content invalid (e.g. complete view redraw should be performed on next frame). - void Invalidate() { myBackBufferRestored = Standard_False; } - - //! Return true if view content cache has been invalidated. - Standard_Boolean IsInvalidated() const { return !myBackBufferRestored; } - - //! Special method to perform printing. - //! System-specific and currently only Win platform implemented. - Standard_Boolean Print (const Handle(OpenGl_PrinterContext)& thePrintContext, - const Graphic3d_CView& theCView, - const Aspect_Handle theHPrintDC, - const Standard_Boolean theToShowBackground, - const Standard_CString theFileName, - const Aspect_PrintAlgo thePrintAlgorithm, - const Standard_Real theScaleFactor); - - const Handle(OpenGl_PrinterContext)& PrinterContext() const - { - return myPrintContext; - } + Standard_EXPORT void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr); - void DisplayCallback (const Graphic3d_CView& theCView, int theReason); - - Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight); - void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr); Standard_Boolean BufferDump (OpenGl_FrameBuffer* theFBOPtr, Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType); + Standard_EXPORT Standard_Integer Width() const; + + Standard_EXPORT Standard_Integer Height() const; + //! Setup Z-buffer usage flag (without affecting GL state!). //! Returns previously set flag. Standard_Boolean SetUseZBuffer (const Standard_Boolean theToUse) @@ -198,15 +149,26 @@ public: return wasUsed; } - Standard_Boolean& UseZBuffer() { return myUseZBuffer; } + Handle(OpenGl_PrinterContext)& PrinterContext() { return myPrintContext; } + + //! @return true if usage of Z buffer is enabled. + Standard_Boolean& UseZBuffer() { return myUseZBuffer; } + + //! @return true if depth writing is enabled. Standard_Boolean& UseDepthWrite() { return myUseDepthWrite; } - Standard_Boolean& UseGLLight() { return myUseGLLight; } - Standard_Integer AntiAliasingMode() const { return myAntiAliasingMode; } + //! @return true if usage of GL light is enabled. + Standard_EXPORT Standard_Boolean UseGLLight() const; - //// RELATED TO STATUS //// + //! @return true if antialiasing is enabled. + Standard_EXPORT Standard_Integer AntiAliasingMode() const; - Standard_Integer NamedStatus; + //! @return true if clipping algorithm enabled + Standard_EXPORT Standard_Boolean IsCullingEnabled() const; + + Standard_Integer NamedStatus; + + //// RELATED TO STATUS //// const TEL_COLOUR* HighlightColor; @@ -263,9 +225,6 @@ public: //! Returns currently applied polygon offset params. const TEL_POFFSET_PARAM& AppliedPolygonOffset() { return PolygonOffset_applied; } - //! @return true if clipping algorithm enabled - inline Standard_Boolean IsCullingEnabled() const { return myIsCullingEnabled; } - //! Returns capping algorithm rendering filter. const Handle(OpenGl_CappingAlgoFilter)& DefaultCappingAlgoFilter() const { @@ -286,43 +245,6 @@ public: protected: - //! Copy content of Back buffer to the Front buffer - void copyBackToFront(); - - //! Initialize blit quad. - Standard_EXPORT OpenGl_VertexBuffer* initBlitQuad (const Standard_Boolean theToFlip); - - //! Blit image from/to specified buffers. - Standard_EXPORT bool blitBuffers (OpenGl_FrameBuffer* theReadFbo, - OpenGl_FrameBuffer* theDrawFbo, - const Standard_Boolean theToFlip = Standard_False); - - Standard_EXPORT virtual Standard_Boolean Activate(); - - void redraw1 (const Graphic3d_CView& theCView, - OpenGl_FrameBuffer* theReadDrawFbo, - const Graphic3d_Camera::Projection theProjection); - - //! Setup default FBO. - void bindDefaultFbo (OpenGl_FrameBuffer* theCustomFbo = NULL); - - //! Blend together views pair into stereo image. - void drawStereoPair (const Graphic3d_CView& theCView); - - //! Blit snapshot containing main scene (myMainSceneFbos or BackBuffer) - //! into presentation buffer (myMainSceneFbos -> offscreen FBO or myMainSceneFbos -> BackBuffer or BackBuffer -> FrontBuffer), - //! and redraw immediate structures on top. - //! - //! When scene caching is disabled (myTransientDrawToFront, no double buffer in window, etc.), - //! the first step (blitting) will be skipped. - //! - //! @return false if immediate structures has been rendered directly into FrontBuffer and Buffer Swap should not be called. - bool redrawImmediate (const Graphic3d_CView& theCView, - OpenGl_FrameBuffer* theReadFbo, - const Graphic3d_Camera::Projection theProjection, - OpenGl_FrameBuffer* theDrawFbo, - const Standard_Boolean theIsPartialUpdate = Standard_False); - void updateMaterial (const int theFlag); void setTextureParams (Handle(OpenGl_Texture)& theTexture, @@ -330,36 +252,15 @@ protected: protected: //! @name protected fields - //! Two framebuffers (left and right views) store cached main presentation - //! of the view (without presentation of immediate layers). - Handle(OpenGl_FrameBuffer) myMainSceneFbos[2]; - //! Additional buffers for immediate layer in stereo mode. - Handle(OpenGl_FrameBuffer) myImmediateSceneFbos[2]; - //! Special flag which is invalidated when myMainSceneFbos can not be blitted for some reason (e.g. driver bugs). - Standard_Boolean myHasFboBlit; - - //! Flag to draw result image upside-down - Standard_Boolean myToFlipOutput; - - //! Vertices for full-screen quad rendering. - OpenGl_VertexBuffer myFullScreenQuad; - OpenGl_VertexBuffer myFullScreenQuadFlip; - - Handle(OpenGl_PrinterContext) myPrintContext; - Handle(OpenGl_View) myView; - Handle(OpenGl_LineAttributes) myLineAttribs; - Standard_Integer myViewId; - Standard_Integer myAntiAliasingMode; - Standard_Boolean myTransientDrawToFront; //!< optimization flag for immediate mode (to render directly to the front buffer) - Standard_Boolean myBackBufferRestored; - Standard_Boolean myIsImmediateDrawn; //!< flag indicates that immediate mode buffer contains some data - Standard_Boolean myUseZBuffer; - Standard_Boolean myUseDepthWrite; - Standard_Boolean myUseGLLight; - Standard_Boolean myIsCullingEnabled; //!< frustum culling flag - - unsigned int myFrameCounter; //!< redraw counter, for debugging - + OpenGl_View* myView; + Handle(OpenGl_Window) myWindow; + Handle(OpenGl_Context) myGlContext; + Handle(OpenGl_PrinterContext) myPrintContext; + Handle(OpenGl_LineAttributes) myLineAttribs; + Standard_Integer myAntiAliasingMode; + Standard_Boolean myUseZBuffer; + Standard_Boolean myUseDepthWrite; + Standard_Boolean myUseGLLight; Handle(OpenGl_CappingAlgoFilter) myDefaultCappingAlgoFilter; OpenGl_AspectFace myNoneCulling; OpenGl_AspectFace myFrontCulling; @@ -391,7 +292,7 @@ protected: //! @name fields related to status public: //! @name type definition - DEFINE_STANDARD_RTTI(OpenGl_Workspace, OpenGl_Window) + DEFINE_STANDARD_RTTI(OpenGl_Workspace, Standard_Transient) DEFINE_STANDARD_ALLOC }; diff --git a/src/OpenGl/OpenGl_Workspace_5.cxx b/src/OpenGl/OpenGl_Workspace_5.cxx deleted file mode 100644 index 485857690b..0000000000 --- a/src/OpenGl/OpenGl_Workspace_5.cxx +++ /dev/null @@ -1,461 +0,0 @@ -// Created on: 2011-08-05 -// Created by: Sergey ZERCHANINOV -// Copyright (c) 2011-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef HAVE_GL2PS - #include - /* OCC22216 NOTE: linker dependency can be switched off by undefining macro. - Pragma comment for gl2ps.lib is defined only here. */ - #ifdef _MSC_VER - #pragma comment( lib, "gl2ps.lib" ) - #endif -#endif - -/*----------------------------------------------------------------------*/ - -static void TelUpdatePolygonOffsets (const TEL_POFFSET_PARAM& theOffsetData) -{ - if ((theOffsetData.mode & Aspect_POM_Fill) == Aspect_POM_Fill) - { - glEnable (GL_POLYGON_OFFSET_FILL); - } - else - { - glDisable (GL_POLYGON_OFFSET_FILL); - } - -#if !defined(GL_ES_VERSION_2_0) - if ((theOffsetData.mode & Aspect_POM_Line) == Aspect_POM_Line) - { - glEnable (GL_POLYGON_OFFSET_LINE); - } - else - { - glDisable (GL_POLYGON_OFFSET_LINE); - } - - if ((theOffsetData.mode & Aspect_POM_Point) == Aspect_POM_Point) - { - glEnable (GL_POLYGON_OFFSET_POINT); - } - else - { - glDisable (GL_POLYGON_OFFSET_POINT); - } -#endif - - glPolygonOffset (theOffsetData.factor, theOffsetData.units); -} - -/*----------------------------------------------------------------------*/ - -void OpenGl_Workspace::updateMaterial (const int theFlag) -{ - // Case of hidden line - if (AspectFace_set->InteriorStyle() == Aspect_IS_HIDDENLINE) - { - myAspectFaceHl = *AspectFace_set; // copy all values including line edge aspect - myAspectFaceHl.ChangeIntFront().matcol = BackgroundColor(); - myAspectFaceHl.ChangeIntFront().color_mask = 0; - myAspectFaceHl.ChangeIntFront().color_mask = 0; - - AspectFace_set = &myAspectFaceHl; - return; - } - - const OPENGL_SURF_PROP* aProps = &AspectFace_set->IntFront(); - GLenum aFace = GL_FRONT_AND_BACK; - if (theFlag == TEL_BACK_MATERIAL) - { - aFace = GL_BACK; - aProps = &AspectFace_set->IntBack(); - } - else if (AspectFace_set->DistinguishingMode() == TOn - && !(NamedStatus & OPENGL_NS_RESMAT)) - { - aFace = GL_FRONT; - } - - myMatTmp.Init (*aProps); - - // handling transparency - if (NamedStatus & OPENGL_NS_2NDPASSDO) - { - // second pass - myMatTmp.Diffuse.a() = aProps->env_reflexion; - } - else - { - if (aProps->env_reflexion != 0.0f) - { - // if the material reflects the environment scene, the second pass is needed - NamedStatus |= OPENGL_NS_2NDPASSNEED; - } - - if (aProps->trans != 1.0f) - { - // render transparent - myMatTmp.Diffuse.a() = aProps->trans; - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - if (myUseDepthWrite) - { - glDepthMask (GL_FALSE); - } - } - else - { - // render opaque - if ((NamedStatus & OPENGL_NS_ANTIALIASING) == 0) - { - glBlendFunc (GL_ONE, GL_ZERO); - glDisable (GL_BLEND); - } - if (myUseDepthWrite) - { - glDepthMask (GL_TRUE); - } - } - } - - // do not update material properties in case of zero reflection mode, - // because GL lighting will be disabled by OpenGl_PrimitiveArray::DrawArray() anyway. - if (aProps->color_mask == 0) - { - return; - } - - // reset material - if (NamedStatus & OPENGL_NS_RESMAT) - { - #if !defined(GL_ES_VERSION_2_0) - if (myGlContext->core11 != NULL) - { - myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData()); - myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData()); - myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData()); - myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData()); - myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine()); - } - #endif - - if (theFlag == TEL_FRONT_MATERIAL) - { - myMatFront = myMatTmp; - myMatBack = myMatTmp; - } - else - { - myMatBack = myMatTmp; - } - - NamedStatus &= ~OPENGL_NS_RESMAT; - return; - } - - // reduce updates - OpenGl_Material& anOld = (theFlag == TEL_FRONT_MATERIAL) - ? myMatFront - : myMatBack; -#if !defined(GL_ES_VERSION_2_0) - if (myGlContext->core11 != NULL) - { - if (myMatTmp.Ambient.r() != anOld.Ambient.r() - || myMatTmp.Ambient.g() != anOld.Ambient.g() - || myMatTmp.Ambient.b() != anOld.Ambient.b()) - { - myGlContext->core11->glMaterialfv (aFace, GL_AMBIENT, myMatTmp.Ambient.GetData()); - } - if (myMatTmp.Diffuse.r() != anOld.Diffuse.r() - || myMatTmp.Diffuse.g() != anOld.Diffuse.g() - || myMatTmp.Diffuse.b() != anOld.Diffuse.b() - || fabs (myMatTmp.Diffuse.a() - anOld.Diffuse.a()) > 0.01f) - { - myGlContext->core11->glMaterialfv (aFace, GL_DIFFUSE, myMatTmp.Diffuse.GetData()); - } - if (myMatTmp.Specular.r() != anOld.Specular.r() - || myMatTmp.Specular.g() != anOld.Specular.g() - || myMatTmp.Specular.b() != anOld.Specular.b()) - { - myGlContext->core11->glMaterialfv (aFace, GL_SPECULAR, myMatTmp.Specular.GetData()); - } - if (myMatTmp.Emission.r() != anOld.Emission.r() - || myMatTmp.Emission.g() != anOld.Emission.g() - || myMatTmp.Emission.b() != anOld.Emission.b()) - { - myGlContext->core11->glMaterialfv (aFace, GL_EMISSION, myMatTmp.Emission.GetData()); - } - if (myMatTmp.Shine() != anOld.Shine()) - { - myGlContext->core11->glMaterialf (aFace, GL_SHININESS, myMatTmp.Shine()); - } - } -#endif - anOld = myMatTmp; - if (aFace == GL_FRONT_AND_BACK) - { - myMatBack = myMatTmp; - } -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectLine * OpenGl_Workspace::SetAspectLine(const OpenGl_AspectLine *AnAspect) -{ - const OpenGl_AspectLine *AspectLine_old = AspectLine_set; - AspectLine_set = AnAspect; - return AspectLine_old; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectFace * OpenGl_Workspace::SetAspectFace(const OpenGl_AspectFace *AnAspect) -{ - const OpenGl_AspectFace *AspectFace_old = AspectFace_set; - AspectFace_set = AnAspect; - return AspectFace_old; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectMarker * OpenGl_Workspace::SetAspectMarker(const OpenGl_AspectMarker *AnAspect) -{ - const OpenGl_AspectMarker *AspectMarker_old = AspectMarker_set; - AspectMarker_set = AnAspect; - return AspectMarker_old; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectText * OpenGl_Workspace::SetAspectText(const OpenGl_AspectText *AnAspect) -{ - const OpenGl_AspectText *AspectText_old = AspectText_set; - AspectText_set = AnAspect; - return AspectText_old; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectLine * OpenGl_Workspace::AspectLine(const Standard_Boolean theWithApply) -{ - if (theWithApply) - { - AspectLine_applied = AspectLine_set; - } - - return AspectLine_set; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectFace* OpenGl_Workspace::AspectFace (const Standard_Boolean theToApply) -{ - if (!theToApply) - { - return AspectFace_set; - } - - if (!ActiveView()->Backfacing()) - { - // manage back face culling mode, disable culling when clipping is enabled - TelCullMode aCullingMode = (myGlContext->Clipping().IsClippingOrCappingOn() - || AspectFace_set->InteriorStyle() == Aspect_IS_HATCH) - ? TelCullNone - : (TelCullMode )AspectFace_set->CullingMode(); - if (aCullingMode != TelCullNone - && !(NamedStatus & OPENGL_NS_2NDPASSDO)) - { - // disable culling in case of translucent shading aspect - if (AspectFace_set->IntFront().trans != 1.0f) - { - aCullingMode = TelCullNone; - } - } - if (myCullingMode != aCullingMode) - { - myCullingMode = aCullingMode; - switch (myCullingMode) - { - case TelCullNone: - case TelCullUndefined: - { - glDisable (GL_CULL_FACE); - break; - } - case TelCullFront: - { - glCullFace (GL_FRONT); - glEnable (GL_CULL_FACE); - break; - } - case TelCullBack: - { - glCullFace (GL_BACK); - glEnable (GL_CULL_FACE); - break; - } - } - } - } - - if (AspectFace_set == AspectFace_applied) - { - return AspectFace_set; - } - -#if !defined(GL_ES_VERSION_2_0) - const Aspect_InteriorStyle anIntstyle = AspectFace_set->InteriorStyle(); - if (AspectFace_applied == NULL || AspectFace_applied->InteriorStyle() != anIntstyle) - { - switch (anIntstyle) - { - case Aspect_IS_EMPTY: - case Aspect_IS_HOLLOW: - { - glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); - break; - } - case Aspect_IS_HATCH: - { - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - myLineAttribs->SetTypeOfHatch (AspectFace_applied != NULL ? AspectFace_applied->Hatch() : TEL_HS_SOLID); - break; - } - case Aspect_IS_SOLID: - case Aspect_IS_HIDDENLINE: - { - glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); - if (myGlContext->core11 != NULL) - { - glDisable (GL_POLYGON_STIPPLE); - } - break; - } - case Aspect_IS_POINT: - { - glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); - break; - } - } - } - - if (anIntstyle == Aspect_IS_HATCH) - { - const Tint hatchstyle = AspectFace_set->Hatch(); - if (AspectFace_applied == NULL || AspectFace_applied->Hatch() != hatchstyle) - { - myLineAttribs->SetTypeOfHatch (hatchstyle); - } - } -#endif - - // Aspect_POM_None means: do not change current settings - if ((AspectFace_set->PolygonOffset().mode & Aspect_POM_None) != Aspect_POM_None) - { - if (PolygonOffset_applied.mode != AspectFace_set->PolygonOffset().mode - || PolygonOffset_applied.factor != AspectFace_set->PolygonOffset().factor - || PolygonOffset_applied.units != AspectFace_set->PolygonOffset().units) - { - SetPolygonOffset (AspectFace_set->PolygonOffset().mode, - AspectFace_set->PolygonOffset().factor, - AspectFace_set->PolygonOffset().units); - } - } - - updateMaterial (TEL_FRONT_MATERIAL); - if (AspectFace_set->DistinguishingMode() == TOn) - { - updateMaterial (TEL_BACK_MATERIAL); - } - - if ((NamedStatus & OPENGL_NS_FORBIDSETTEX) == 0) - { - if (AspectFace_set->DoTextureMap()) - { - EnableTexture (AspectFace_set->TextureRes (myGlContext), - AspectFace_set->TextureParams()); - } - else - { - DisableTexture(); - } - } - - AspectFace_applied = AspectFace_set; - return AspectFace_set; -} - -//======================================================================= -//function : SetPolygonOffset -//purpose : -//======================================================================= -void OpenGl_Workspace::SetPolygonOffset (int theMode, - Standard_ShortReal theFactor, - Standard_ShortReal theUnits) -{ - PolygonOffset_applied.mode = theMode; - PolygonOffset_applied.factor = theFactor; - PolygonOffset_applied.units = theUnits; - - TelUpdatePolygonOffsets (PolygonOffset_applied); -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectMarker* OpenGl_Workspace::AspectMarker (const Standard_Boolean theToApply) -{ - if (theToApply && (AspectMarker_set != AspectMarker_applied)) - { - if (!AspectMarker_applied || (AspectMarker_set->Scale() != AspectMarker_applied->Scale())) - { - #if !defined(GL_ES_VERSION_2_0) - glPointSize (AspectMarker_set->Scale()); - #ifdef HAVE_GL2PS - gl2psPointSize (AspectMarker_set->Scale()); - #endif - #endif - } - AspectMarker_applied = AspectMarker_set; - } - return AspectMarker_set; -} - -/*----------------------------------------------------------------------*/ - -const OpenGl_AspectText* OpenGl_Workspace::AspectText (const Standard_Boolean theWithApply) -{ - if (theWithApply) - { - AspectText_applied = AspectText_set; - TextParam_applied = TextParam_set; - } - - return AspectText_set; -} diff --git a/src/OpenGl/OpenGl_telem_util.cxx b/src/OpenGl/OpenGl_telem_util.cxx index 5262c49c66..a43d2ee3ca 100644 --- a/src/OpenGl/OpenGl_telem_util.cxx +++ b/src/OpenGl/OpenGl_telem_util.cxx @@ -68,7 +68,6 @@ when a face has confused or aligned points. #include #include -#include #define GPRECIS 0.000001 Tint TelGetPolygonNormal(tel_point pnts, Tint* indexs, Tint npnt, Tfloat *norm ) { diff --git a/src/PrsMgr/PrsMgr_Presentation.cxx b/src/PrsMgr/PrsMgr_Presentation.cxx index 482b222b9e..2daec0fd87 100644 --- a/src/PrsMgr/PrsMgr_Presentation.cxx +++ b/src/PrsMgr/PrsMgr_Presentation.cxx @@ -27,7 +27,6 @@ #include #include #include -#include namespace { @@ -374,7 +373,7 @@ void PrsMgr_Presentation::Compute (const Handle(Graphic3d_DataStructureManager)& //======================================================================= Handle(Prs3d_Projector) PrsMgr_Presentation::Projector (const Handle(Graphic3d_DataStructureManager)& theProjector) { - Handle(Graphic3d_Camera) aCamera (Handle(Visual3d_View)::DownCast (theProjector)->Camera()); + Handle(Graphic3d_Camera) aCamera = Handle(Graphic3d_CView)::DownCast (theProjector)->Camera(); const gp_Dir aDir = aCamera->Direction().Reversed(); const gp_Pnt anAt = aCamera->Center(); const gp_Dir anUp = aCamera->Up(); diff --git a/src/PrsMgr/PrsMgr_PresentationManager.cxx b/src/PrsMgr/PrsMgr_PresentationManager.cxx index 6f30314125..c7f134fa0e 100644 --- a/src/PrsMgr/PrsMgr_PresentationManager.cxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.cxx @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -28,14 +27,12 @@ #include #include #include -#include -#include // ======================================================================= // function : PrsMgr_PresentationManager // purpose : // ======================================================================= -PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Visual3d_ViewManager)& theStructureManager) +PrsMgr_PresentationManager::PrsMgr_PresentationManager (const Handle(Graphic3d_StructureManager)& theStructureManager) : myStructureManager (theStructureManager), myImmediateModeOn (0), mySelectionColor (Quantity_NOC_GRAY99) @@ -346,7 +343,7 @@ void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& the { for (theViewer->InitActiveViews(); theViewer->MoreActiveViews(); theViewer->NextActiveViews()) { - const Handle(Visual3d_View)& aView = theViewer->ActiveView()->View(); + const Handle(Graphic3d_CView)& aView = theViewer->ActiveView()->View(); for (PrsMgr_ListOfPresentations::Iterator anIter (myImmediateList); anIter.More(); anIter.Next()) { const Handle(Prs3d_Presentation)& aPrs = anIter.Value(); @@ -365,7 +362,7 @@ void PrsMgr_PresentationManager::displayImmediate (const Handle(V3d_Viewer)& the aShadowPrs->Highlight (Aspect_TOHM_COLOR, aPrs->HighlightColor()); myViewDependentImmediateList.Append (aShadowPrs); } - // handles custom highlight presentations which were defined in overriden + // handles custom highlight presentations which were defined in overridden // HilightOwnerWithColor method of a custom AIS objects and maintain its // visibility in different views on their own else if (aShadowPrs.IsNull()) diff --git a/src/PrsMgr/PrsMgr_PresentationManager.hxx b/src/PrsMgr/PrsMgr_PresentationManager.hxx index 92937405b7..aa9a36376d 100644 --- a/src/PrsMgr/PrsMgr_PresentationManager.hxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.hxx @@ -17,27 +17,25 @@ #ifndef _PrsMgr_PresentationManager_HeaderFile #define _PrsMgr_PresentationManager_HeaderFile -#include -#include - -#include +#include +#include +#include +#include #include #include -#include -#include #include -#include -#include -class Visual3d_ViewManager; -class V3d_Viewer; -class Standard_NoSuchObject; -class PrsMgr_PresentableObject; -class Prs3d_Presentation; +#include +#include +#include +#include + class Geom_Transformation; -class Graphic3d_StructureManager; +class Prs3d_Presentation; class Prs3d_ShadingAspect; +class PrsMgr_PresentableObject; class PrsMgr_Presentation; - +class Standard_NoSuchObject; +class V3d_Viewer; class PrsMgr_PresentationManager; DEFINE_STANDARD_HANDLE(PrsMgr_PresentationManager, MMgt_TShared) @@ -54,7 +52,7 @@ public: //! Creates a framework to manage displays and graphic entities with the 3D view theStructureManager. - Standard_EXPORT PrsMgr_PresentationManager(const Handle(Visual3d_ViewManager)& theStructureManager); + Standard_EXPORT PrsMgr_PresentationManager(const Handle(Graphic3d_StructureManager)& theStructureManager); //! Displays the presentation of the object in the given Presentation manager with the given mode. //! The mode should be enumerated by the object which inherits PresentableObject. @@ -175,7 +173,7 @@ protected: //! Removes a presentation of the presentable object thePrsObject to this framework. thePrsObject has the display mode theMode. Standard_EXPORT Standard_Boolean RemovePresentation (const Handle(PrsMgr_PresentableObject)& thePrsObject, const Standard_Integer theMode = 0); - Handle(Visual3d_ViewManager) myStructureManager; + Handle(Graphic3d_StructureManager) myStructureManager; Standard_Integer myImmediateModeOn; PrsMgr_ListOfPresentations myImmediateList; PrsMgr_ListOfPresentations myViewDependentImmediateList; diff --git a/src/PrsMgr/PrsMgr_PresentationManager.lxx b/src/PrsMgr/PrsMgr_PresentationManager.lxx index c84c980d64..9724f0c77f 100644 --- a/src/PrsMgr/PrsMgr_PresentationManager.lxx +++ b/src/PrsMgr/PrsMgr_PresentationManager.lxx @@ -14,8 +14,6 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. -#include - inline Standard_Boolean PrsMgr_PresentationManager::IsImmediateModeOn() const { return myImmediateModeOn > 0; diff --git a/src/QABugs/QABugs_8.cxx b/src/QABugs/QABugs_8.cxx index f3dfa55551..3681c5196a 100644 --- a/src/QABugs/QABugs_8.cxx +++ b/src/QABugs/QABugs_8.cxx @@ -26,7 +26,6 @@ #include #include -#include #include diff --git a/src/StdSelect/StdSelect_ViewerSelector3d.cxx b/src/StdSelect/StdSelect_ViewerSelector3d.cxx index 593f421d8a..4239c923b3 100644 --- a/src/StdSelect/StdSelect_ViewerSelector3d.cxx +++ b/src/StdSelect/StdSelect_ViewerSelector3d.cxx @@ -183,7 +183,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theVi { const Handle (SelectMgr_SelectableObject)& anObj = mySelectableObjects.GetObjectById (anObjectIdx); - Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->Viewer()); + Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); for (anObj->Init(); anObj->More(); anObj->Next()) { @@ -200,7 +200,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(V3d_View)& theVi { const Handle (SelectMgr_SelectableObject)& anObj = mySelectableObjectsTrsfPers.GetObjectById (anObjectIdx); - Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->Viewer()); + Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); if (!anObj->TransformPersistence().Flags || (anObj->TransformPersistence().Flags & Graphic3d_TMF_2d)) { @@ -261,7 +261,7 @@ void StdSelect_ViewerSelector3d::DisplaySensitive (const Handle(SelectMgr_Select ClearSensitive (theView); } - Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->Viewer()); + Handle(Graphic3d_Structure) aStruct = new Graphic3d_Structure (theView->Viewer()->StructureManager()); ComputeSensitivePrs (aStruct, theSel, theTrsf, Graphic3d_TransformPers()); diff --git a/src/TKV3d/CMakeLists.txt b/src/TKV3d/CMakeLists.txt index 5944aaf7f3..bc733536f6 100644 --- a/src/TKV3d/CMakeLists.txt +++ b/src/TKV3d/CMakeLists.txt @@ -3,7 +3,6 @@ project(TKV3d) set (TOOLKIT_MODULES V3d Graphic3d - Visual3d Select3D Prs3d StdPrs diff --git a/src/TKV3d/PACKAGES b/src/TKV3d/PACKAGES index 5b64db5741..fa60906e4c 100755 --- a/src/TKV3d/PACKAGES +++ b/src/TKV3d/PACKAGES @@ -1,6 +1,5 @@ V3d Graphic3d -Visual3d Select3D Prs3d StdPrs diff --git a/src/V3d/V3d.cxx b/src/V3d/V3d.cxx index a2e0854e68..8e385ff301 100644 --- a/src/V3d/V3d.cxx +++ b/src/V3d/V3d.cxx @@ -35,8 +35,6 @@ #include #include #include -#include -#include Graphic3d_Vector V3d::GetProjAxis(const V3d_TypeOfOrientation Orientation) { Standard_Real Xpn=0,Ypn=0,Zpn=0 ; @@ -238,7 +236,7 @@ void V3d::DrawSphere(const Handle(V3d_Viewer)& aViewer,const Quantity_Length ray { const Standard_Boolean inf = ray < 0; const Standard_Real aRadius = Standard_ShortReal(Abs(ray)); - Handle(Graphic3d_Structure) Struct = new Graphic3d_Structure(aViewer->Viewer()) ; + Handle(Graphic3d_Structure) Struct = new Graphic3d_Structure(aViewer->StructureManager()); Handle(Graphic3d_Group) Group = Struct->NewGroup(); Handle(Graphic3d_AspectLine3d) LineAttrib = new Graphic3d_AspectLine3d() ; diff --git a/src/V3d/V3d.hxx b/src/V3d/V3d.hxx index d6052af361..503b485b3c 100644 --- a/src/V3d/V3d.hxx +++ b/src/V3d/V3d.hxx @@ -32,7 +32,6 @@ class V3d_View; class V3d_Viewer; class V3d_Viewer; class V3d_View; -class V3d_LayerMgr; class V3d_Light; class V3d_AmbientLight; class V3d_PositionLight; @@ -47,8 +46,7 @@ class V3d_ColorScaleLayerItem; //! This package contains the set of commands and services //! of the 3D Viewer. It provides a set of high level commands -//! to control the views and viewing modes. This package is -//! complementary to the Visual3D graphic package. +//! to control the views and viewing modes. class V3d { public: @@ -100,7 +98,6 @@ private: friend class V3d_Viewer; friend class V3d_View; -friend class V3d_LayerMgr; friend class V3d_Light; friend class V3d_AmbientLight; friend class V3d_PositionLight; diff --git a/src/V3d/V3d_AmbientLight.cxx b/src/V3d/V3d_AmbientLight.cxx index 335c56e7a4..6a074487d5 100644 --- a/src/V3d/V3d_AmbientLight.cxx +++ b/src/V3d/V3d_AmbientLight.cxx @@ -15,16 +15,16 @@ // Modified 30-03-98 : ZOV ; PRO6774 (reconstruction of the class hierarchy and suppressing useless methods) -#include -#include #include -#include -#include -V3d_AmbientLight::V3d_AmbientLight(const Handle(V3d_Viewer)& VM, const Quantity_NameOfColor Name):V3d_Light(VM) { - - Quantity_Color C(Name) ; - MyType = V3d_AMBIENT ; - MyLight = new Visual3d_Light(C) ; +// ======================================================================= +// function : V3d_AmbientLight +// purpose : +// ======================================================================= +V3d_AmbientLight::V3d_AmbientLight (const Handle(V3d_Viewer)& theViewer, + const Quantity_NameOfColor theColor) +: V3d_Light (theViewer) +{ + SetType (V3d_AMBIENT); + SetColor (theColor); } - diff --git a/src/V3d/V3d_AmbientLight.hxx b/src/V3d/V3d_AmbientLight.hxx index 0cc300516e..52ac7e928e 100644 --- a/src/V3d/V3d_AmbientLight.hxx +++ b/src/V3d/V3d_AmbientLight.hxx @@ -17,14 +17,9 @@ #ifndef _V3d_AmbientLight_HeaderFile #define _V3d_AmbientLight_HeaderFile -#include -#include - #include -#include -class V3d_Viewer; - +class V3d_Viewer; class V3d_AmbientLight; DEFINE_STANDARD_HANDLE(V3d_AmbientLight, V3d_Light) @@ -34,32 +29,12 @@ class V3d_AmbientLight : public V3d_Light public: - - //! Constructs an ambient light source in the viewer VM. + //! Constructs an ambient light source in the viewer. //! The default Color of this light source is WHITE. - Standard_EXPORT V3d_AmbientLight(const Handle(V3d_Viewer)& VM, const Quantity_NameOfColor Color = Quantity_NOC_WHITE); - - - + Standard_EXPORT V3d_AmbientLight (const Handle(V3d_Viewer)& theViewer, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE); DEFINE_STANDARD_RTTI(V3d_AmbientLight,V3d_Light) - -protected: - - - - -private: - - - - }; - - - - - - #endif // _V3d_AmbientLight_HeaderFile diff --git a/src/V3d/V3d_CircularGrid.cxx b/src/V3d/V3d_CircularGrid.cxx index 085b34d4ba..d9a1059e71 100644 --- a/src/V3d/V3d_CircularGrid.cxx +++ b/src/V3d/V3d_CircularGrid.cxx @@ -38,7 +38,6 @@ #include #include #include -#include /*----------------------------------------------------------------------*/ /* @@ -52,7 +51,7 @@ V3d_CircularGrid::V3d_CircularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor) : Aspect_CircularGrid (1.,8), - myStructure (new Graphic3d_Structure (aViewer->Viewer ())), + myStructure (new Graphic3d_Structure (aViewer->StructureManager())), myGroup (myStructure->NewGroup()), myViewer (aViewer), myCurAreDefined (Standard_False) diff --git a/src/V3d/V3d_DirectionalLight.cxx b/src/V3d/V3d_DirectionalLight.cxx index 679b8db08a..733c12a16e 100644 --- a/src/V3d/V3d_DirectionalLight.cxx +++ b/src/V3d/V3d_DirectionalLight.cxx @@ -51,92 +51,149 @@ #include #include #include -#include -#include -#include - -//-Constructors -V3d_DirectionalLight::V3d_DirectionalLight(const Handle(V3d_Viewer)& VM, const -V3d_TypeOfOrientation Direction,const Quantity_NameOfColor Name,const Standard_Boolean Headlight):V3d_PositionLight(VM) { - Quantity_Color C(Name) ; - Graphic3d_Vertex T(0.,0.,0.) ; - Graphic3d_Vertex P ; - Graphic3d_Vector V = V3d::GetProjAxis(Direction) ; - - MyType = V3d_DIRECTIONAL ; - MyLight = new Visual3d_Light(C,V, Headlight) ; - // The initial target is chosen at random - MyTarget = T; -// Position is found - P.SetCoord(-V.X(),-V.Y(),-V.Z()); - MyDisplayPosition = P; +// ======================================================================= +// function : V3d_DirectionalLight +// purpose : +// ======================================================================= +V3d_DirectionalLight::V3d_DirectionalLight (const Handle(V3d_Viewer)& theViewer, + const V3d_TypeOfOrientation theDirection, + const Quantity_NameOfColor theColor, + const Standard_Boolean theIsHeadlight) +: V3d_PositionLight (theViewer) +{ + Graphic3d_Vector aV = V3d::GetProjAxis (theDirection); + SetType (V3d_DIRECTIONAL); + SetColor (theColor); + SetHeadlight (theIsHeadlight); + SetTarget (0., 0., 0.); + SetPosition (-aV.X(), -aV.Y(), -aV.Z()); } -V3d_DirectionalLight::V3d_DirectionalLight(const Handle(V3d_Viewer)& VM,const Standard_Real Xt,const Standard_Real Yt,const Standard_Real Zt,const Standard_Real Xp,const Standard_Real Yp,const Standard_Real Zp,const Quantity_NameOfColor Name,const Standard_Boolean Headlight):V3d_PositionLight(VM) { - Quantity_Color C(Name) ; - Graphic3d_Vertex T(Xt,Yt,Zt) ; - Graphic3d_Vertex P(Xp,Yp,Zp) ; - Graphic3d_Vector V(P,T); - - MyType = V3d_DIRECTIONAL ; - V.Normalize(); - MyLight = new Visual3d_Light(C,V, Headlight) ; - MyTarget = T; - MyDisplayPosition = P; +// ======================================================================= +// function : V3d_DirectionalLight +// purpose : +// ======================================================================= +V3d_DirectionalLight::V3d_DirectionalLight (const Handle(V3d_Viewer)& theViewer, + const Standard_Real theXt, + const Standard_Real theYt, + const Standard_Real theZt, + const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp, + const Quantity_NameOfColor theColor, + const Standard_Boolean theIsHeadlight) +: V3d_PositionLight (theViewer) +{ + SetType (V3d_DIRECTIONAL); + SetColor (theColor); + SetHeadlight (theIsHeadlight); + SetTarget (theXt, theYt, theZt); + SetPosition (theXp, theYp, theZp); } -//-Methods, in order - // ======================================================================= // function : SetSmoothAngle // purpose : // ======================================================================= void V3d_DirectionalLight::SetSmoothAngle (const Standard_Real theValue) { - MyLight->SetSmoothAngle (theValue); -} + V3d_BadValue_Raise_if (theValue < 0.0 || theValue > M_PI / 2.0, + "Bad value for smoothing angle"); -void V3d_DirectionalLight::SetDirection(const V3d_TypeOfOrientation Direction) { + myLight.Smoothness = static_cast (theValue); +} - Graphic3d_Vector V = V3d::GetProjAxis(Direction) ; - MyLight->SetDirection(V) ; +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +void V3d_DirectionalLight::SetDirection (const V3d_TypeOfOrientation theDirection) +{ + Graphic3d_Vector aV = V3d::GetProjAxis (theDirection); + SetDirection (aV.X(), aV.Y(), aV.Z()); } -void V3d_DirectionalLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) { +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +void V3d_DirectionalLight::SetDirection (const Standard_Real theVx, + const Standard_Real theVy, + const Standard_Real theVz) +{ + V3d_BadValue_Raise_if (Sqrt (theVx * theVx + theVy * theVy + theVz * theVz) <= 0., + "V3d_DirectionalLight::SetDirection, " + "null vector" ); - V3d_BadValue_Raise_if( sqrt( Vx*Vx + Vy*Vy + Vz*Vz ) <= 0.,"V3d_DirectionalLight::SetDirection, null vector" ); + Graphic3d_Vector aV (theVx, theVy, theVz); + aV.Normalize(); - Graphic3d_Vector V(Vx,Vy,Vz) ; - V.Normalize() ; - MyLight->SetDirection(V) ; + myLight.Direction.x() = static_cast (aV.X()); + myLight.Direction.y() = static_cast (aV.Y()); + myLight.Direction.z() = static_cast (aV.Z()); } -void V3d_DirectionalLight::SetDisplayPosition(const Standard_Real X, const Standard_Real Y, const Standard_Real Z) { +// ======================================================================= +// function : SetDisplayPosition +// purpose : +// ======================================================================= +void V3d_DirectionalLight::SetDisplayPosition (const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ) +{ + myDisplayPosition.SetCoord(theX, theY, theZ); - Standard_Real Xt,Yt,Zt; + Standard_Real aXt, aYt, aZt; + Target (aXt, aYt, aZt); - MyDisplayPosition.SetCoord(X,Y,Z) ; - MyTarget.Coord(Xt,Yt,Zt); - SetDirection(Xt-X,Yt-Y,Zt-Z); + Standard_Real aXd = aXt - theX; + Standard_Real aYd = aYt - theY; + Standard_Real aZd = aZt - theZ; + if (!Graphic3d_Vector (aXd, aYd, aZd).LengthZero()) + { + SetDirection (aXd, aYd, aZd); + } } -void V3d_DirectionalLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) { - - SetDisplayPosition (Xp,Yp,Zp); +// ======================================================================= +// function : SetPosition +// purpose : +// ======================================================================= +void V3d_DirectionalLight::SetPosition (const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp) +{ + SetDisplayPosition (theXp, theYp, theZp); } -void V3d_DirectionalLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const { - - DisplayPosition (Xp,Yp,Zp) ; +// ======================================================================= +// function : Position +// purpose : +// ======================================================================= +void V3d_DirectionalLight::Position (Standard_Real& theXp, + Standard_Real& theYp, + Standard_Real& theZp) const +{ + DisplayPosition (theXp, theYp, theZp) ; } -void V3d_DirectionalLight::DisplayPosition(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const { - - MyDisplayPosition.Coord(Xp,Yp,Zp) ; +// ======================================================================= +// function : DisplayPosition +// purpose : +// ======================================================================= +void V3d_DirectionalLight::DisplayPosition (Standard_Real& theXp, + Standard_Real& theYp, + Standard_Real& theZp) const +{ + myDisplayPosition.Coord (theXp, theYp, theZp) ; } -void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const +// ======================================================================= +// function : DisplayPosition +// purpose : +// ======================================================================= +void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& theSymbol, const Handle(V3d_View)& theView) const { Standard_Real Xi,Yi,Zi,Xf,Yf,Zf,Rayon,PXT,PYT,X,Y,Z,XT,YT,ZT; Standard_Real A,B,C,Dist,Beta,CosBeta,SinBeta,Coef,X1,Y1,Z1; @@ -144,15 +201,15 @@ void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Standard_Integer IXP,IYP,j; TColStd_Array2OfReal MatRot(0,2,0,2); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); this->DisplayPosition(Xi,Yi,Zi); Rayon = this->Radius(); - aView->Project(Xi,Yi,Zi,PXT,PYT); - aView->Convert(PXT,PYT,IXP,IYP); + theView->Project(Xi,Yi,Zi,PXT,PYT); + theView->Convert(PXT,PYT,IXP,IYP); // Coordinated 3d in the plane of projection of the source. - aView->Convert(IXP,IYP,XT,YT,ZT); - aView->Convert(PXT,PYT+Rayon,IXP,IYP); - aView->Convert(IXP,IYP,X,Y,Z); + theView->Convert(IXP,IYP,XT,YT,ZT); + theView->Convert(PXT,PYT+Rayon,IXP,IYP); + theView->Convert(IXP,IYP,X,Y,Z); X = X+Xi-XT; Y = Y+Yi-YT; Z = Z+Zi-ZT; Dist = Sqrt( Square(X-Xi) + Square(Y-Yi) + Square(Z-Zi) ); // Axis of rotation. @@ -161,7 +218,7 @@ void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const C = (Z-Zi)/Dist; // A sphere is drawn - V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); + V3d::CircleInPlane(theSymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); for( j=1 ; j<=3 ; j++ ) { Beta = j * M_PI / 4.; CosBeta = Cos(Beta); @@ -184,7 +241,7 @@ void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Y1 = VX * MatRot(1,0) + VY * MatRot(1,1) + VZ * MatRot(1,2); Z1 = VX * MatRot(2,0) + VY * MatRot(2,1) + VZ * MatRot(2,2); VX = X1 + Xi - Xf ; VY = Y1 + Yi - Yf ; VZ = Z1 + Zi - Zf; - V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); + V3d::CircleInPlane(theSymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); } // The arrow is drawn @@ -195,14 +252,18 @@ void V3d_DirectionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(Graphic3d_ArrayOfSegments) aPrims = new Graphic3d_ArrayOfSegments(2); aPrims->AddVertex(Standard_ShortReal(Xi),Standard_ShortReal(Yi),Standard_ShortReal(Zi)); aPrims->AddVertex(Standard_ShortReal(X),Standard_ShortReal(Y),Standard_ShortReal(Z)); - gsymbol->AddPrimitiveArray(aPrims); + theSymbol->AddPrimitiveArray(aPrims); - V3d::ArrowOfRadius(gsymbol, X, Y, Z, DX, DY, DZ, M_PI / 15., Rayon / 20.); + V3d::ArrowOfRadius(theSymbol, X, Y, Z, DX, DY, DZ, M_PI / 15., Rayon / 20.); } -void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, - const V3d_TypeOfRepresentation TPres) { - +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void V3d_DirectionalLight::Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theTPres) +{ Standard_Real X,Y,Z,Rayon; Standard_Real X0,Y0,Z0,VX,VY,VZ; Standard_Real X1,Y1,Z1; @@ -216,37 +277,37 @@ void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, // Creation of a structure of non-markable elements (target, meridian and // parallel). - Pres = TPres; - Handle(V3d_Viewer) TheViewer = aView->Viewer(); + Pres = theTPres; + Handle(V3d_Viewer) TheViewer = theView->Viewer(); UpdSov = TheViewer->UpdateMode(); TheViewer->SetUpdateMode(V3d_WAIT); - if (!MyGraphicStructure.IsNull()) { - MyGraphicStructure->Disconnect(MyGraphicStructure1); - MyGraphicStructure->Clear(); - MyGraphicStructure1->Clear(); - if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; + if (!myGraphicStructure.IsNull()) { + myGraphicStructure->Disconnect(myGraphicStructure1); + myGraphicStructure->Clear(); + myGraphicStructure1->Clear(); + if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation; } else { if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; - Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure = slight; - Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure1 = snopick; + Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure = slight; + Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure1 = snopick; } - Handle(Graphic3d_Group) glight = MyGraphicStructure->NewGroup(); + Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup(); Handle(Graphic3d_Group) gsphere; if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { - gsphere = MyGraphicStructure->NewGroup(); + gsphere = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) gnopick = MyGraphicStructure1->NewGroup(); + Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup(); - X0 = MyTarget.X(); - Y0 = MyTarget.Y(); - Z0 = MyTarget.Z(); + X0 = myTarget.X(); + Y0 = myTarget.Y(); + Z0 = myTarget.Z(); //Display of the position of the light. @@ -255,14 +316,14 @@ void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); Asp1->SetColor(Col1); glight->SetPrimitivesAspect(Asp1); - this->Symbol(glight,aView); + this->Symbol(glight,theView); // Display of the markable sphere (limit at the circle). if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { Rayon = this->Radius(); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); //Display of the meridian @@ -273,7 +334,7 @@ void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, gnopick->SetPrimitivesAspect(Asp2); // Definition of the axis of circle - aView->Up(DXRef,DYRef,DZRef); + theView->Up(DXRef,DYRef,DZRef); this->DisplayPosition(X,Y,Z); DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; VX = DYRef*DZini - DZRef*DYini; @@ -285,8 +346,8 @@ void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, // Display of the parallel // Definition of the axis of circle - aView->Proj(VX,VY,VZ); - aView->Up(X1,Y1,Z1); + theView->Proj(VX,VY,VZ); + theView->Up(X1,Y1,Z1); DXRef = VY * Z1 - VZ * Y1; DYRef = VZ * X1 - VX * Z1; DZRef = VX * Y1 - VY * X1; @@ -300,18 +361,22 @@ void V3d_DirectionalLight::Display( const Handle(V3d_View)& aView, } - MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); + myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT); // cout << "MyGraphicStructure exploration \n" << flush; MyGraphicStructure->Exploration(); - MyTypeOfRepresentation = Pres; - MyGraphicStructure->Display(); + myTypeOfRepresentation = Pres; + myGraphicStructure->Display(); TheViewer->SetUpdateMode(UpdSov); } -void V3d_DirectionalLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const { - - Quantity_Color C ; - Graphic3d_Vector V ; - - MyLight->Values(C,V) ; - V.Coord(Vx,Vy,Vz) ; +// ======================================================================= +// function : Direction +// purpose : +// ======================================================================= +void V3d_DirectionalLight::Direction (Standard_Real& theVx, + Standard_Real& theVy, + Standard_Real& theVz) const +{ + theVx = myLight.Direction.x(); + theVy = myLight.Direction.y(); + theVz = myLight.Direction.z(); } diff --git a/src/V3d/V3d_DirectionalLight.hxx b/src/V3d/V3d_DirectionalLight.hxx index d60ac0a5e0..6d13f78244 100644 --- a/src/V3d/V3d_DirectionalLight.hxx +++ b/src/V3d/V3d_DirectionalLight.hxx @@ -17,64 +17,62 @@ #ifndef _V3d_DirectionalLight_HeaderFile #define _V3d_DirectionalLight_HeaderFile -#include -#include - -#include #include #include -#include -#include -#include -#include -#include -#include -class V3d_BadValue; -class V3d_Viewer; -class V3d_View; -class Graphic3d_Group; - +class V3d_Viewer; class V3d_DirectionalLight; DEFINE_STANDARD_HANDLE(V3d_DirectionalLight, V3d_PositionLight) -//! Create and modify a directional light source -//! in a viewer. +//! Directional light source for a viewer. class V3d_DirectionalLight : public V3d_PositionLight { - public: - //! Creates a directional light source in the viewer. - Standard_EXPORT V3d_DirectionalLight(const Handle(V3d_Viewer)& VM, const V3d_TypeOfOrientation Direction = V3d_XposYposZpos, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Standard_Boolean Headlight = Standard_False); - + Standard_EXPORT V3d_DirectionalLight (const Handle(V3d_Viewer)& theViewer, + const V3d_TypeOfOrientation theDirection = V3d_XposYposZpos, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Standard_Boolean theIsHeadlight = Standard_False); + //! Creates a directional light source in the viewer. - //! Xt,Yt,Zt : Coordinate of light source Target. - //! Xp,Yp,Zp : Coordinate of light source Position. + //! theXt, theYt, theZt : Coordinate of light source Target. + //! theXp, theYp, theZp : Coordinate of light source Position. //! The others parameters describe before. - Standard_EXPORT V3d_DirectionalLight(const Handle(V3d_Viewer)& VM, const V3d_Coordinate Xt, const V3d_Coordinate Yt, const V3d_Coordinate Zt, const V3d_Coordinate Xp, const V3d_Coordinate Yp, const V3d_Coordinate Zp, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Standard_Boolean Headlight = Standard_False); - - //! Defines the direction of the light source - //! by a predefined orientation. - Standard_EXPORT void SetDirection (const V3d_TypeOfOrientation Direction); - - //! Defines the direction of the light source by the predefined - //! vector Xm,Ym,Zm. + Standard_EXPORT V3d_DirectionalLight (const Handle(V3d_Viewer)& theViewer, + const V3d_Coordinate theXt, + const V3d_Coordinate theYt, + const V3d_Coordinate theZt, + const V3d_Coordinate theXp, + const V3d_Coordinate theYp, + const V3d_Coordinate theZp, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Standard_Boolean theIsHeadlight = Standard_False); + + //! Defines the direction of the light source by a predefined orientation. + Standard_EXPORT void SetDirection (const V3d_TypeOfOrientation theDirection); + + //! Defines the direction of the light source by the predefined vector theXm, theYm, theZm. //! Warning: raises BadValue from V3d if the vector is null. - Standard_EXPORT void SetDirection (const Quantity_Parameter Xm, const Quantity_Parameter Ym, const Quantity_Parameter Zm); - + Standard_EXPORT void SetDirection (const Quantity_Parameter theXm, + const Quantity_Parameter theYm, + const Quantity_Parameter theZm); + //! Defines the point of light source representation. - Standard_EXPORT void SetDisplayPosition (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z); - + Standard_EXPORT void SetDisplayPosition (const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ); + //! Calls SetDisplayPosition method. - Standard_EXPORT virtual void SetPosition (const V3d_Coordinate Xp, const V3d_Coordinate Yp, const V3d_Coordinate Zp) Standard_OVERRIDE; - + Standard_EXPORT virtual void SetPosition (const V3d_Coordinate theXp, + const V3d_Coordinate theYp, + const V3d_Coordinate theZp) Standard_OVERRIDE; + //! Modifies the smoothing angle (in radians) Standard_EXPORT void SetSmoothAngle (const Standard_Real theValue); - + //! Display the graphic structure of light source - //! in the choosen view. We have three type of representation + //! in the chosen view. We have three type of representation //! - SIMPLE : Only the light source is displayed. //! - PARTIAL : The light source and the light space are //! displayed. @@ -82,43 +80,35 @@ public: //! We can choose the "SAMELAST" as parameter of representation //! In this case the graphic structure representation will be //! the last displayed. - Standard_EXPORT void Display (const Handle(V3d_View)& aView, const V3d_TypeOfRepresentation Representation) Standard_OVERRIDE; - - //! Calls DisplayPosition method. - Standard_EXPORT virtual void Position (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const Standard_OVERRIDE; - - //! Returns the choosen position to represent the light - //! source. - Standard_EXPORT void DisplayPosition (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - - //! Returns the Vx,Vy,Vz direction of the light source. - Standard_EXPORT void Direction (Quantity_Parameter& Vx, Quantity_Parameter& Vy, Quantity_Parameter& Vz) const; + Standard_EXPORT void Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theRepresentation) Standard_OVERRIDE; + //! Calls DisplayPosition method. + Standard_EXPORT virtual void Position (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const Standard_OVERRIDE; + //! Returns the chosen position to represent the light source. + Standard_EXPORT void DisplayPosition (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const; + //! Returns the theVx, theVy, theVz direction of the light source. + Standard_EXPORT void Direction (Quantity_Parameter& theVx, + Quantity_Parameter& theVy, + Quantity_Parameter& theVz) const; DEFINE_STANDARD_RTTI(V3d_DirectionalLight,V3d_PositionLight) -protected: - - - - private: - //! Defines the representation of the directional light source. - Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const Standard_OVERRIDE; - - Graphic3d_Vertex MyDisplayPosition; + Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& theSymbol, + const Handle(V3d_View)& theView) const Standard_OVERRIDE; +private: + Graphic3d_Vertex myDisplayPosition; }; - - - - - - #endif // _V3d_DirectionalLight_HeaderFile diff --git a/src/V3d/V3d_Light.cxx b/src/V3d/V3d_Light.cxx index bf0335133a..ac08b91a32 100644 --- a/src/V3d/V3d_Light.cxx +++ b/src/V3d/V3d_Light.cxx @@ -32,71 +32,102 @@ #include #include #include -#include -//-Declarations -//-Aliases -//-Global data definitions -//-Local data definitions -//-Constructors -V3d_Light::V3d_Light(const Handle(V3d_Viewer)& VM) { - - MyType = V3d_AMBIENT ; - VM->AddLight(this) ; +// ======================================================================= +// function : V3d_Light +// purpose : +// ======================================================================= +V3d_Light::V3d_Light (const Handle(V3d_Viewer)& theViewer) +{ + SetType (V3d_AMBIENT); + theViewer->AddLight (this); } -//-Methods, in order - -Handle(Visual3d_Light) V3d_Light::Light() const { - - return MyLight ; +// ======================================================================= +// function : SetType +// purpose : +// ======================================================================= +void V3d_Light::SetType (const V3d_TypeOfLight theType) +{ + myLight.Type = (Graphic3d_TypeOfLightSource)theType; } -void V3d_Light::SetColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) { - Standard_Real V1 = v1 ; - Standard_Real V2 = v2 ; - Standard_Real V3 = v3 ; - - if( V1 < 0. ) V1 = 0. ; else if( V1 > 1. ) V1 = 1. ; - if( V2 < 0. ) V2 = 0. ; else if( V2 > 1. ) V2 = 1. ; - if( V3 < 0. ) V3 = 0. ; else if( V3 > 1. ) V3 = 1. ; - - - Quantity_Color C(V1,V2,V3,Type) ; - MyLight->SetColor(C) ; +// ======================================================================= +// function : SetColor +// purpose : +// ======================================================================= +void V3d_Light::SetColor (const Quantity_TypeOfColor theType, + const Standard_Real theValue1, + const Standard_Real theValue2, + const Standard_Real theValue3) +{ + Standard_Real aValue1 = Max (0., Min (1., theValue1)); + Standard_Real aValue2 = Max (0., Min (1., theValue2)); + Standard_Real aValue3 = Max (0., Min (1., theValue3)); + Quantity_Color aColor (aValue1, aValue2, aValue3, theType); + SetColor (aColor); } -void V3d_Light::SetColor(const Quantity_NameOfColor Name) { - Quantity_Color C(Name) ; - MyLight->SetColor(C) ; +// ======================================================================= +// function : SetColor +// purpose : +// ======================================================================= +void V3d_Light::SetColor (const Quantity_NameOfColor theName) +{ + SetColor (Quantity_Color (theName)); } -void V3d_Light::SetColor(const Quantity_Color& aColor) { - MyLight->SetColor(aColor) ; +// ======================================================================= +// function : SetColor +// purpose : +// ======================================================================= +void V3d_Light::SetColor (const Quantity_Color& theColor) +{ + myLight.Color.r() = static_cast (theColor.Red()); + myLight.Color.g() = static_cast (theColor.Green()); + myLight.Color.b() = static_cast (theColor.Blue()); } -void V3d_Light::Color(const Quantity_TypeOfColor Type, Standard_Real& V1, Standard_Real& V2, Standard_Real& V3) const { - - Quantity_Color C ; - C = MyLight->Color() ; - C.Values(V1,V2,V3,Type) ; +// ======================================================================= +// function : Color +// purpose : +// ======================================================================= +void V3d_Light::Color (const Quantity_TypeOfColor theType, + Standard_Real& theValue1, + Standard_Real& theValue2, + Standard_Real& theValue3) const +{ + Color().Values (theValue1, theValue2, theValue3, theType); } -void V3d_Light::Color(Quantity_NameOfColor& Name) const{ - - Quantity_Color C ; - C = MyLight->Color() ; - Name = C.Name(); +// ======================================================================= +// function : Color +// purpose : +// ======================================================================= +void V3d_Light::Color (Quantity_NameOfColor& theName) const +{ + theName = Color().Name(); } -Quantity_Color V3d_Light::Color() const{ - - return MyLight->Color(); +// ======================================================================= +// function : Color +// purpose : +// ======================================================================= +Quantity_Color V3d_Light::Color() const +{ + return Quantity_Color (Standard_Real (myLight.Color.r()), + Standard_Real (myLight.Color.g()), + Standard_Real (myLight.Color.b()), + Quantity_TOC_RGB); } -V3d_TypeOfLight V3d_Light::Type() const { - - return MyType; +// ======================================================================= +// function : Type +// purpose : +// ======================================================================= +V3d_TypeOfLight V3d_Light::Type() const +{ + return (V3d_TypeOfLight)myLight.Type; } // ======================================================================= @@ -105,7 +136,11 @@ V3d_TypeOfLight V3d_Light::Type() const { // ======================================================================= void V3d_Light::SetIntensity (const Standard_Real theValue) { - MyLight->SetIntensity (theValue); + Standard_ASSERT_RAISE (theValue > 0., + "V3d_Light::SetIntensity, " + "Negative value for intensity"); + + myLight.Intensity = static_cast (theValue); } // ======================================================================= @@ -114,7 +149,7 @@ void V3d_Light::SetIntensity (const Standard_Real theValue) // ======================================================================= Standard_Real V3d_Light::Intensity() const { - return MyLight->Intensity(); + return myLight.Intensity; } // ======================================================================= @@ -123,18 +158,31 @@ Standard_Real V3d_Light::Intensity() const // ======================================================================= Standard_Real V3d_Light::Smoothness() const { - return MyLight->Smoothness(); + return myLight.Smoothness; } -Standard_Boolean V3d_Light::Headlight() const { - return MyLight->Headlight(); +// ======================================================================= +// function : Headlight +// purpose : +// ======================================================================= +Standard_Boolean V3d_Light::Headlight() const +{ + return myLight.IsHeadlight; } +// ======================================================================= +// function : SetHeadlight +// purpose : +// ======================================================================= void V3d_Light::SetHeadlight (const Standard_Boolean theValue) { - MyLight->SetHeadlight (theValue); + myLight.IsHeadlight = theValue; } +// ======================================================================= +// function : SymetricPointOnSphere +// purpose : +// ======================================================================= void V3d_Light::SymetricPointOnSphere (const Handle(V3d_View)& aView, const Graphic3d_Vertex &Center, const Graphic3d_Vertex &aPoint, const Standard_Real Rayon, Standard_Real& X, Standard_Real& Y, Standard_Real& Z, Standard_Real& VX, Standard_Real& VY, Standard_Real& VZ ) { Standard_Real X0,Y0,Z0,XP,YP,ZP; @@ -176,7 +224,16 @@ void V3d_Light::SymetricPointOnSphere (const Handle(V3d_View)& aView, const Grap } } -Standard_Boolean V3d_Light::IsDisplayed() const { - if( MyGraphicStructure.IsNull() ) return Standard_False; - return MyGraphicStructure->IsDisplayed(); +// ======================================================================= +// function : IsDisplayed +// purpose : +// ======================================================================= +Standard_Boolean V3d_Light::IsDisplayed() const +{ + if (myGraphicStructure.IsNull()) + { + return Standard_False; + } + + return myGraphicStructure->IsDisplayed(); } diff --git a/src/V3d/V3d_Light.hxx b/src/V3d/V3d_Light.hxx index 7cdb1d4844..048c8717a1 100644 --- a/src/V3d/V3d_Light.hxx +++ b/src/V3d/V3d_Light.hxx @@ -17,26 +17,23 @@ #ifndef _V3d_Light_HeaderFile #define _V3d_Light_HeaderFile -#include -#include - -#include +#include +#include #include -#include -#include -#include #include +#include +#include +#include #include #include -#include +#include #include -class Visual3d_Light; +#include +#include + class Graphic3d_Structure; -class V3d_BadValue; -class V3d_Viewer; class Quantity_Color; -class V3d_View; - +class V3d_Viewer; class V3d_Light; DEFINE_STANDARD_HANDLE(V3d_Light, MMgt_TShared) @@ -45,101 +42,84 @@ DEFINE_STANDARD_HANDLE(V3d_Light, MMgt_TShared) //! (base class for AmbientLight and PositionLight) class V3d_Light : public MMgt_TShared { - public: - - //! Defines the colour of a light source - //! according to the type of colour definition - //! and the three corresponding values. - Standard_EXPORT void SetColor (const Quantity_TypeOfColor Type, const Quantity_Parameter V1, const Quantity_Parameter V2, const Quantity_Parameter V3); - - //! Defines the colour of a light source by giving - //! the name of the colour in the form Quantity_NOC_xxxx . - Standard_EXPORT void SetColor (const Quantity_NameOfColor Name); - - //! Defines the colour of a light source by giving - //! the basic colour. - Standard_EXPORT void SetColor (const Quantity_Color& Name); - - //! Returns the colour of the light source depending of - //! the color type. - Standard_EXPORT void Color (const Quantity_TypeOfColor Type, Quantity_Parameter& V1, Quantity_Parameter& V2, Quantity_Parameter& V3) const; - - //! Returns the colour of the light source. - Standard_EXPORT void Color (Quantity_NameOfColor& Name) const; - - //! Returns the colour of the light source. + //! Defines the color of a light source according to the type of color + //! definition and the three corresponding values. + Standard_EXPORT void SetColor (const Quantity_TypeOfColor theType, + const Quantity_Parameter theValue1, + const Quantity_Parameter theValue2, + const Quantity_Parameter theValue3); + + //! Defines the color of a light source by giving + //! the name of the color in the form Quantity_NOC_xxxx. + Standard_EXPORT void SetColor (const Quantity_NameOfColor theName); + + //! Defines the color of a light source by giving the basic color. + Standard_EXPORT void SetColor (const Quantity_Color& theColor); + + //! Returns the color of the light source depending of the color type. + Standard_EXPORT void Color (const Quantity_TypeOfColor theType, + Quantity_Parameter& theValue1, + Quantity_Parameter& theValue2, + Quantity_Parameter& theValue3) const; + + //! Returns the color of the light source. + Standard_EXPORT void Color (Quantity_NameOfColor& theName) const; + + //! Returns the color of the light source. Standard_EXPORT Quantity_Color Color() const; - + //! Returns the Type of the Light Standard_EXPORT V3d_TypeOfLight Type() const; - + //! returns true if the light is a headlight Standard_EXPORT Standard_Boolean Headlight() const; - + //! Setup headlight flag. Standard_EXPORT void SetHeadlight (const Standard_Boolean theValue); - + //! Modifies the intensity of light source. Standard_EXPORT void SetIntensity (const Standard_Real theValue); - + //! returns the intensity of light source Standard_EXPORT Standard_Real Intensity() const; - + //! returns the smoothness of light source Standard_EXPORT Standard_Real Smoothness() const; - + //! Returns TRUE when a light representation is displayed Standard_EXPORT Standard_Boolean IsDisplayed() const; - -friend - //! Activates MyLight in the view. - Standard_EXPORT void V3d_View::SetLightOn (const Handle(V3d_Light)& MyLight); -friend - //! Activates all the lights defined in this view. - Standard_EXPORT void V3d_View::SetLightOn(); -friend - //! Desactivate MyLight in this view. - Standard_EXPORT void V3d_View::SetLightOff (const Handle(V3d_Light)& MyLight); -friend - //! Deactivate all the Lights defined in this view. - Standard_EXPORT void V3d_View::SetLightOff(); - +friend + //! Updates the lights of the view. The view is redrawn. + Standard_EXPORT void V3d_View::UpdateLights() const; DEFINE_STANDARD_RTTI(V3d_Light,MMgt_TShared) protected: - - Standard_EXPORT V3d_Light(const Handle(V3d_Viewer)& VM); - + Standard_EXPORT V3d_Light (const Handle(V3d_Viewer)& theViewer); + + //! Sets type of the light. + Standard_EXPORT void SetType (const V3d_TypeOfLight theType); + //! Returns the symetric point coordinates of "aPoint" //! on the sphere of center "Center" and radius "Radius". //! VX,VY,VZ is the project vector of view. Standard_EXPORT static void SymetricPointOnSphere (const Handle(V3d_View)& aView, const Graphic3d_Vertex& Center, const Graphic3d_Vertex& aPoint, const Quantity_Parameter Radius, V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z, Quantity_Parameter& VX, Quantity_Parameter& VY, Quantity_Parameter& VZ); - V3d_TypeOfLight MyType; - Handle(Visual3d_Light) MyLight; - Handle(Graphic3d_Structure) MyGraphicStructure; - Handle(Graphic3d_Structure) MyGraphicStructure1; - - -private: - - - //! Returns the Light of the associated Visual3d. - Standard_EXPORT Handle(Visual3d_Light) Light() const; +protected: + //! Return light properties associated to this light source. + //! Hidden method exposed only to V3d_View. + Standard_EXPORT const Graphic3d_CLight& Light() const { return myLight; } +protected: + Graphic3d_CLight myLight; + Handle(Graphic3d_Structure) myGraphicStructure; + Handle(Graphic3d_Structure) myGraphicStructure1; }; - - - - - - #endif // _V3d_Light_HeaderFile diff --git a/src/V3d/V3d_Plane.cxx b/src/V3d/V3d_Plane.cxx index 6d454408cf..f600d1f694 100755 --- a/src/V3d/V3d_Plane.cxx +++ b/src/V3d/V3d_Plane.cxx @@ -17,10 +17,8 @@ #include #include #include -#include #include - // ======================================================================= // function : V3d_Plane // purpose : @@ -63,7 +61,7 @@ void V3d_Plane::Display (const Handle(V3d_View)& theView, myGraphicStructure->Clear(); } - myGraphicStructure = new Graphic3d_Structure (aViewer->Viewer()); + myGraphicStructure = new Graphic3d_Structure (aViewer->StructureManager()); Handle(Graphic3d_Group) aGroup = myGraphicStructure->NewGroup(); Handle(Graphic3d_AspectFillArea3d) anAsp = new Graphic3d_AspectFillArea3d(); Graphic3d_MaterialAspect aPlastic (Graphic3d_NOM_PLASTIC); diff --git a/src/V3d/V3d_PositionLight.cxx b/src/V3d/V3d_PositionLight.cxx index 169c065dbc..bcce84f4ca 100644 --- a/src/V3d/V3d_PositionLight.cxx +++ b/src/V3d/V3d_PositionLight.cxx @@ -37,84 +37,107 @@ #include #include #include -#include -#include -#include -V3d_PositionLight::V3d_PositionLight(const Handle(V3d_Viewer)& VM) : V3d_Light(VM) { +// ======================================================================= +// function : V3d_PositionLight +// purpose : +// ======================================================================= +V3d_PositionLight::V3d_PositionLight (const Handle(V3d_Viewer)& theViewer) +: V3d_Light(theViewer) +{ } -void V3d_PositionLight::SetTarget(const Standard_Real X, const Standard_Real Y, const Standard_Real Z) { - +// ======================================================================= +// function : SetTarget +// purpose : +// ======================================================================= +void V3d_PositionLight::SetTarget (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ) +{ Standard_Real Xc,Yc,Zc, Xp,Yp,Zp; // Recalculation of the position - MyTarget.Coord(Xc,Yc,Zc); + myTarget.Coord(Xc,Yc,Zc); Position (Xp,Yp,Zp) ; - Xp = Xp + (X - Xc); - Yp = Yp + (Y - Yc); - Zp = Zp + (Z - Zc); + Xp = Xp + (theX - Xc); + Yp = Yp + (theY - Yc); + Zp = Zp + (theZ - Zc); // Affectation - MyTarget.SetCoord(X,Y,Z); + myTarget.SetCoord(theX,theY,theZ); SetPosition(Xp,Yp,Zp) ; } -void V3d_PositionLight::SetRadius(const Standard_Real Radius) { - - V3d_BadValue_Raise_if( Radius <= 0. , "V3d_PositionLight::SetRadius, bad radius"); - V3d_BadValue_Raise_if( MyType == V3d_DIRECTIONAL , "V3d_PositionLight::SetRadius, bad light type"); +// ======================================================================= +// function : SetRadius +// purpose : +// ======================================================================= +void V3d_PositionLight::SetRadius (const Standard_Real theRadius) +{ + V3d_BadValue_Raise_if( theRadius <= 0. , "V3d_PositionLight::SetRadius, bad radius"); + V3d_BadValue_Raise_if( Type() == V3d_DIRECTIONAL , "V3d_PositionLight::SetRadius, bad light type"); Standard_Real X0,Y0,Z0, Xn,Yn,Zn, Xp,Yp,Zp; // The target point remains unchanged, only the position of the light is modified // by preserving the direction. Position (Xp,Yp,Zp); - Graphic3d_Vector D(MyTarget, Graphic3d_Vertex(Xp, Yp, Zp)); + Graphic3d_Vector D(myTarget, Graphic3d_Vertex(Xp, Yp, Zp)); D.Normalize(); D.Coord(Xn,Yn,Zn); - MyTarget.Coord(X0,Y0,Z0); - Xn = X0 + Radius*Xn; - Yn = Y0 + Radius*Yn; - Zn = Z0 + Radius*Zn; + myTarget.Coord(X0,Y0,Z0); + Xn = X0 + theRadius*Xn; + Yn = Y0 + theRadius*Yn; + Zn = Z0 + theRadius*Zn; SetPosition(Xn,Yn,Zn) ; } -void V3d_PositionLight::OnHideFace(const Handle(V3d_View)& aView) { - +// ======================================================================= +// function : OnHideFace +// purpose : +// ======================================================================= +void V3d_PositionLight::OnHideFace (const Handle(V3d_View)& theView) +{ Standard_Real Xp,Yp,Zp, X,Y,Z, VX,VY,VZ; Position (Xp,Yp,Zp); - V3d_Light::SymetricPointOnSphere (aView, - MyTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); + V3d_Light::SymetricPointOnSphere (theView, + myTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); // This is a visible point if ((VX*(X-Xp) < 0.) && (VY*(Y-Yp) < 0.) && (VZ*(Z-Zp) < 0.)) SetPosition (X,Y,Z); } -void V3d_PositionLight::OnSeeFace(const Handle(V3d_View)& aView) { - +// ======================================================================= +// function : OnSeeFace +// purpose : +// ======================================================================= +void V3d_PositionLight::OnSeeFace (const Handle(V3d_View)& theView) +{ Standard_Real Xp,Yp,Zp, X,Y,Z, VX,VY,VZ; Position (Xp,Yp,Zp); - V3d_Light::SymetricPointOnSphere (aView, - MyTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); + V3d_Light::SymetricPointOnSphere (theView, + myTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); // This is a hidden point if ((VX*(X-Xp) > 0.) && (VY*(Y-Yp) > 0.) && (VZ*(Z-Zp) > 0.)) SetPosition (X,Y,Z); } -Standard_Boolean V3d_PositionLight::SeeOrHide(const Handle(V3d_View)& aView) const { - +// ======================================================================= +// function : SeeOrHide +// purpose : +// ======================================================================= +Standard_Boolean V3d_PositionLight::SeeOrHide (const Handle(V3d_View)& theView) const +{ Standard_Real Xp,Yp,Zp, X,Y,Z, VX,VY,VZ; Position (Xp,Yp,Zp); - V3d_Light::SymetricPointOnSphere (aView, - MyTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); + V3d_Light::SymetricPointOnSphere (theView, + myTarget, Graphic3d_Vertex(Xp,Yp,Yp), Radius(), X,Y,Z, VX,VY,VZ); // Is it a visible or a hidden point return ( (VX*(X-Xp) > 0.) || (VY*(Y-Yp) > 0.) || (VZ*(Z-Zp) > 0.) )? @@ -124,13 +147,20 @@ Standard_Boolean V3d_PositionLight::SeeOrHide(const Handle(V3d_View)& aView) con Standard_True; } -void V3d_PositionLight::Target(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const { - - MyTarget.Coord(Xp,Yp,Zp) ; +// ======================================================================= +// function : Target +// purpose : +// ======================================================================= +void V3d_PositionLight::Target (Standard_Real& theXp, Standard_Real& theYp, Standard_Real& theZp) const +{ + myTarget.Coord (theXp, theYp, theZp); } -void V3d_PositionLight::Display( const Handle(V3d_View)& aView, - const V3d_TypeOfRepresentation TPres ) +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void V3d_PositionLight::Display (const Handle(V3d_View)& theView, const V3d_TypeOfRepresentation theTPres) { Graphic3d_Vertex PText ; Standard_Real X,Y,Z,Rayon; @@ -146,45 +176,45 @@ void V3d_PositionLight::Display( const Handle(V3d_View)& aView, // Creation of a structure snopick of non-markable elements (target, meridian and // parallel). - Pres = TPres; - Handle(V3d_Viewer) TheViewer = aView->Viewer(); + Pres = theTPres; + Handle(V3d_Viewer) TheViewer = theView->Viewer(); UpdSov = TheViewer->UpdateMode(); TheViewer->SetUpdateMode(V3d_WAIT); - if (!MyGraphicStructure.IsNull()) { - MyGraphicStructure->Disconnect(MyGraphicStructure1); - MyGraphicStructure->Clear(); - MyGraphicStructure1->Clear(); - if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; + if (!myGraphicStructure.IsNull()) { + myGraphicStructure->Disconnect(myGraphicStructure1); + myGraphicStructure->Clear(); + myGraphicStructure1->Clear(); + if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation; } else { if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; - Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure = slight; - Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure1 = snopick; + Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure = slight; + Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure1 = snopick; } Handle(Graphic3d_Group) gradius, gExtArrow, gIntArrow; - if (MyType != V3d_DIRECTIONAL + if (Type() != V3d_DIRECTIONAL && Pres == V3d_COMPLETE) { - gradius = MyGraphicStructure->NewGroup(); - gExtArrow = MyGraphicStructure->NewGroup(); - gIntArrow = MyGraphicStructure->NewGroup(); + gradius = myGraphicStructure->NewGroup(); + gExtArrow = myGraphicStructure->NewGroup(); + gIntArrow = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) glight = MyGraphicStructure->NewGroup(); + Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup(); Handle(Graphic3d_Group) gsphere; if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { - gsphere = MyGraphicStructure->NewGroup(); + gsphere = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) gnopick = MyGraphicStructure1->NewGroup(); + Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup(); - X0 = MyTarget.X(); - Y0 = MyTarget.Y(); - Z0 = MyTarget.Z(); + X0 = myTarget.X(); + Y0 = myTarget.Y(); + Z0 = myTarget.Z(); // Display of the light position. @@ -193,17 +223,17 @@ void V3d_PositionLight::Display( const Handle(V3d_View)& aView, Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); Asp1->SetColor(Col1); glight->SetPrimitivesAspect(Asp1); - this->Symbol(glight,aView); + this->Symbol(glight,theView); // Display of the marking sphere (limit at the circle). if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { Rayon = this->Radius(); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); - if (MyType != V3d_DIRECTIONAL) { + if (Type() != V3d_DIRECTIONAL) { //Display of the radius of the sphere (line + text) @@ -228,7 +258,7 @@ void V3d_PositionLight::Display( const Handle(V3d_View)& aView, gnopick->SetPrimitivesAspect(Asp2); // Definition of the axis of circle - aView->Up(DXRef,DYRef,DZRef); + theView->Up(DXRef,DYRef,DZRef); this->Position(X,Y,Z); DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; VX = DYRef*DZini - DZRef*DYini; @@ -240,8 +270,8 @@ void V3d_PositionLight::Display( const Handle(V3d_View)& aView, // Display of the parallel // Definition of the axis of circle - aView->Proj(VX,VY,VZ); - aView->Up(X1,Y1,Z1); + theView->Proj(VX,VY,VZ); + theView->Up(X1,Y1,Z1); DXRef = VY * Z1 - VZ * Y1; DYRef = VZ * X1 - VX * Z1; DZRef = VX * Y1 - VY * X1; @@ -254,18 +284,21 @@ void V3d_PositionLight::Display( const Handle(V3d_View)& aView, V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); } - MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); - MyTypeOfRepresentation = Pres; - MyGraphicStructure->Display(); + myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT); + myTypeOfRepresentation = Pres; + myGraphicStructure->Display(); TheViewer->SetUpdateMode(UpdSov); } - -void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, - const V3d_TypeOfPickLight WhatPick, - const Standard_Integer Xpix, - const Standard_Integer Ypix) { - +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void V3d_PositionLight::Tracking (const Handle(V3d_View)& theView, + const V3d_TypeOfPickLight theWhatPick, + const Standard_Integer theXpix, + const Standard_Integer theYpix) +{ // Quantity_Color Col ; Standard_Real xPos, yPos, zPos; Standard_Real XPp,YPp,PXT,PYT,X,Y,Z,Rayon,Ylim; @@ -276,15 +309,15 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, Standard_Real Xi,Yi,Zi,DeltaX,DeltaY,DeltaZ,Lambda; Standard_Integer IPX,IPY; - aView->Convert(Xpix,Ypix,XPp,YPp); - X0 = MyTarget.X(); - Y0 = MyTarget.Y(); - Z0 = MyTarget.Z(); - aView->Project(X0,Y0,Z0,PXT,PYT); - aView->Convert(PXT,PYT,IPX,IPY); + theView->Convert(theXpix,theYpix,XPp,YPp); + X0 = myTarget.X(); + Y0 = myTarget.Y(); + Z0 = myTarget.Z(); + theView->Project(X0,Y0,Z0,PXT,PYT); + theView->Convert(PXT,PYT,IPX,IPY); // Coord 3d in the plane of projection of the target. - aView->Convert(IPX,IPY,XT,YT,ZT); - switch (WhatPick) { + theView->Convert(IPX,IPY,XT,YT,ZT); + switch (theWhatPick) { case V3d_POSITIONLIGHT : // The Coordinates should remain inside of the sphere Rayon = Radius(); @@ -295,7 +328,7 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, YMaxTrack = PYT + Ylim; if (XPp >= XMinTrack && XPp <= XMaxTrack) { if (YPp >= YMinTrack && YPp <= YMaxTrack) { - aView->ProjReferenceAxe(Xpix,Ypix,XP,YP,ZP,VX,VY,VZ); + theView->ProjReferenceAxe(theXpix,theYpix,XP,YP,ZP,VX,VY,VZ); DeltaX = X0 - XP; DeltaY = Y0 - YP; DeltaZ = Z0 - ZP; @@ -319,36 +352,36 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, Z = ZP + Lambda*VZ; SetPosition(X,Y,Z); - if (MyType == V3d_SPOT) + if (Type() == V3d_SPOT) ((V3d_SpotLight*)this)->SetDirection(X0-X,Y0-Y,Z0-Z); - Display(aView,MyTypeOfRepresentation); - (aView->Viewer())->UpdateLights(); + Display(theView,myTypeOfRepresentation); + (theView->Viewer())->UpdateLights(); } } } break; case V3d_SPACELIGHT : - aView->Convert(PXT,PYT,IPX,IPY); + theView->Convert(PXT,PYT,IPX,IPY); // In this case Xpix,Ypix correspond to a distance, relative // to the translation that is planned to be performed on the sphere. - aView->Convert(IPX+Xpix,IPY+Ypix,X,Y,Z); + theView->Convert(IPX+theXpix,IPY+theYpix,X,Y,Z); X = X+X0-XT; Y = Y+Y0-YT; Z = Z+Z0-ZT; SetTarget(X,Y,Z); - Display(aView,MyTypeOfRepresentation); - (aView->Viewer())->UpdateLights(); + Display(theView,myTypeOfRepresentation); + (theView->Viewer())->UpdateLights(); break; case V3d_ExtRADIUSLIGHT : - if (MyType == V3d_DIRECTIONAL) + if (Type() == V3d_DIRECTIONAL) break; // it is attempted to preserve the target direction position of the // source ==> the point is projected on the target source direction. this->Position(Xi,Yi,Zi); - aView->Project(Xi,Yi,Zi,PXP,PYP); + theView->Project(Xi,Yi,Zi,PXP,PYP); DX = PXP - PXT; DY = PYP - PYT; A1 = DY/DX ; B1 = PYT - A1*PXT; @@ -362,18 +395,18 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, Rayon = Radius(); Rayon = Rayon * Rap; SetRadius(Rayon); - Display(aView,MyTypeOfRepresentation); - (aView->Viewer())->UpdateLights(); + Display(theView,myTypeOfRepresentation); + (theView->Viewer())->UpdateLights(); } break; case V3d_IntRADIUSLIGHT : - if (MyType == V3d_DIRECTIONAL) + if (Type() == V3d_DIRECTIONAL) break; // it is attempted to preserve the target direction position of the // source ==> the point is projected on the target source direction. Position(Xi,Yi,Zi); - aView->Project(Xi,Yi,Zi,PXP,PYP); + theView->Project(Xi,Yi,Zi,PXP,PYP); DX = PXP - PXT; DY = PYP - PYT; A1 = DY/DX ; B1 = PYT - A1*PXT; @@ -389,7 +422,7 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, // the source should remain at a fixed position, // only the target is modified. Position (xPos, yPos, zPos); - Graphic3d_Vector Dir(Graphic3d_Vertex(xPos,yPos,zPos), MyTarget); + Graphic3d_Vector Dir(Graphic3d_Vertex(xPos,yPos,zPos), myTarget); Dir.Normalize(); Dir.Coord(X,Y,Z); X = Xi + Rayon*X; @@ -397,9 +430,9 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, Z = Zi + Rayon*Z; // the source should remain at a fixed position, // only the target is modified. - MyTarget.SetCoord(X,Y,Z); - Display(aView,MyTypeOfRepresentation); - (aView->Viewer())->UpdateLights(); + myTarget.SetCoord(X,Y,Z); + Display(theView,myTypeOfRepresentation); + (theView->Viewer())->UpdateLights(); } break; @@ -411,19 +444,27 @@ void V3d_PositionLight::Tracking( const Handle(V3d_View)& aView, } } -Standard_Real V3d_PositionLight::Radius() const { - +// ======================================================================= +// function : Radius +// purpose : +// ======================================================================= +Standard_Real V3d_PositionLight::Radius() const +{ Standard_Real Xp,Yp,Zp, Xc,Yc,Zc; Position (Xp,Yp,Zp); - MyTarget.Coord(Xc,Yc,Zc); + myTarget.Coord(Xc,Yc,Zc); return Sqrt (Square(Xc - Xp) + Square(Yc - Yp) + Square(Zc - Zp)); } -void V3d_PositionLight::Erase() { - - if (!MyGraphicStructure.IsNull()) MyGraphicStructure->Erase(); - if (!MyGraphicStructure1.IsNull()) MyGraphicStructure1->Erase(); +// ======================================================================= +// function : Radius +// purpose : +// ======================================================================= +void V3d_PositionLight::Erase() +{ + if (!myGraphicStructure.IsNull()) myGraphicStructure->Erase(); + if (!myGraphicStructure1.IsNull()) myGraphicStructure1->Erase(); } diff --git a/src/V3d/V3d_PositionLight.hxx b/src/V3d/V3d_PositionLight.hxx index 7496ba360f..819ad46c09 100644 --- a/src/V3d/V3d_PositionLight.hxx +++ b/src/V3d/V3d_PositionLight.hxx @@ -17,60 +17,54 @@ #ifndef _V3d_PositionLight_HeaderFile #define _V3d_PositionLight_HeaderFile -#include -#include - #include -#include -#include -#include #include +#include +#include #include -#include -#include -class V3d_BadValue; -class V3d_Viewer; -class V3d_View; -class Graphic3d_Group; - +#include +class V3d_View; +class V3d_Viewer; class V3d_PositionLight; DEFINE_STANDARD_HANDLE(V3d_PositionLight, V3d_Light) -//! Base class for Positional, Spot and Directional Light classes +//! Base class for Positional, Spot and Directional Light classes. class V3d_PositionLight : public V3d_Light { - public: - //! Defines the position of the light source. Should be redefined! - Standard_EXPORT virtual void SetPosition (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z) = 0; - - //! Defines the target of the light (the center - //! of the sphere) - Standard_EXPORT void SetTarget (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z); - + Standard_EXPORT virtual void SetPosition (const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ) = 0; + + //! Defines the target of the light (the center of the sphere). + Standard_EXPORT void SetTarget (const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ); + //! Define the radius. - Standard_EXPORT void SetRadius (const Quantity_Parameter Radius); - - //! Calculate the position of the light, on the hide face - //! of the picking sphere. - Standard_EXPORT void OnHideFace (const Handle(V3d_View)& aView); - - //! Calculate the position of the light, on the seen face - //! of the picking sphere. - Standard_EXPORT void OnSeeFace (const Handle(V3d_View)& aView); - + Standard_EXPORT void SetRadius (const Quantity_Parameter theRadius); + + //! Calculate the position of the light, on the hide face of the picking sphere. + Standard_EXPORT void OnHideFace (const Handle(V3d_View)& theView); + + //! Calculate the position of the light, on the seen face of the picking sphere. + Standard_EXPORT void OnSeeFace (const Handle(V3d_View)& theView); + //! Tracking the light position, or the light space, //! or the radius of the light space, that depends of - //! initial picking "WhatPick" (see the pick method). - //! If WhatPick is SPACELIGHT, then the parameters - //! Xpix, Ypix are the coordinates of a translation vector. - Standard_EXPORT void Tracking (const Handle(V3d_View)& aView, const V3d_TypeOfPickLight WathPick, const Standard_Integer Xpix, const Standard_Integer Ypix); - + //! initial picking "theWhatPick" (see the pick method). + //! If theWhatPick is SPACELIGHT, then the parameters + //! theXpix, theYpix are the coordinates of a translation vector. + Standard_EXPORT void Tracking (const Handle(V3d_View)& theView, + const V3d_TypeOfPickLight theWathPick, + const Standard_Integer theXpix, + const Standard_Integer theYpix); + //! Display the graphic structure of light source - //! in the choosen view. We have three type of representation + //! in the chosen view. We have three type of representation //! - SIMPLE : Only the light source is displayed. //! - PARTIAL : The light source and the light space are //! displayed. @@ -79,53 +73,44 @@ public: //! We can choose the "SAMELAST" as parameter of representation //! In this case the graphic structure representation will be //! the last displayed. - Standard_EXPORT virtual void Display (const Handle(V3d_View)& aView, const V3d_TypeOfRepresentation Representation = V3d_SIMPLE); - + Standard_EXPORT virtual void Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theRepresentation = V3d_SIMPLE); + //! Erase the graphic structure of light source. Standard_EXPORT void Erase(); - + //! Returns the radius of the picking sphere. Standard_EXPORT Quantity_Parameter Radius() const; - + //! Returns the visibility status //! If True the source is visible. //! If False it's hidden. - Standard_EXPORT Standard_Boolean SeeOrHide (const Handle(V3d_View)& aView) const; - - //! Returns the position of the light source. - Standard_EXPORT virtual void Position (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const = 0; - - //! Returns the position of the target of the light source. - Standard_EXPORT void Target (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - + Standard_EXPORT Standard_Boolean SeeOrHide (const Handle(V3d_View)& theView) const; + //! Returns the position of the light source. + Standard_EXPORT virtual void Position (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const = 0; + //! Returns the position of the target of the light source. + Standard_EXPORT void Target (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const; DEFINE_STANDARD_RTTI(V3d_PositionLight,V3d_Light) protected: - - Standard_EXPORT V3d_PositionLight(const Handle(V3d_Viewer)& VM); - - Graphic3d_Vertex MyTarget; - V3d_TypeOfRepresentation MyTypeOfRepresentation; + Standard_EXPORT V3d_PositionLight (const Handle(V3d_Viewer)& theViewer); + Graphic3d_Vertex myTarget; + V3d_TypeOfRepresentation myTypeOfRepresentation; private: - //! Defines representation of the light source. - Standard_EXPORT virtual void Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const = 0; - - - + Standard_EXPORT virtual void Symbol (const Handle(Graphic3d_Group)& theSymbol, + const Handle(V3d_View)& theView) const = 0; }; - - - - - - #endif // _V3d_PositionLight_HeaderFile diff --git a/src/V3d/V3d_PositionalLight.cxx b/src/V3d/V3d_PositionalLight.cxx index 34a3169f64..2ad5d03fd0 100644 --- a/src/V3d/V3d_PositionalLight.cxx +++ b/src/V3d/V3d_PositionalLight.cxx @@ -52,101 +52,136 @@ #include #include #include -#include -#include -#include - -//-Declarations -//-Constructors -V3d_PositionalLight::V3d_PositionalLight(const Handle(V3d_Viewer)& VM, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2):V3d_PositionLight(VM) { - - Quantity_Color C(Name) ; - Graphic3d_Vertex P(X,Y,Z) ; - Graphic3d_Vertex T(0.,0.,0.); - - V3d_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, - "V3d_PositionalLight, bad coefficients"); - - MyType = V3d_POSITIONAL ; - MyLight = new Visual3d_Light(C,P,A1,A2) ; - MyTarget = T; +// ======================================================================= +// function : V3d_PositionalLight +// purpose : +// ======================================================================= +V3d_PositionalLight::V3d_PositionalLight (const Handle(V3d_Viewer)& theViewer, + const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + const Quantity_NameOfColor theColor, + const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation) +: V3d_PositionLight (theViewer) +{ + SetType (V3d_POSITIONAL); + SetColor (Quantity_Color (theColor)); + SetTarget (0., 0., 0.); + SetPosition (theX, theY, theZ); + SetAttenuation (theConstAttenuation, theLinearAttenuation); } -V3d_PositionalLight::V3d_PositionalLight(const Handle(V3d_Viewer)& VM, const Standard_Real Xt, const Standard_Real Yt, const Standard_Real Zt, const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2):V3d_PositionLight(VM) { - - Quantity_Color C(Name) ; - Graphic3d_Vertex T(Xt,Yt,Zt) ; - Graphic3d_Vertex P(Xp,Yp,Zp) ; - - V3d_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, - "V3d_PositionalLight, bad coefficients"); - - MyType = V3d_POSITIONAL ; - MyLight = new Visual3d_Light(C,P,A1,A2) ; - MyTarget = T; - // Graphic structure is initialized during the display. - +// ======================================================================= +// function : V3d_PositionalLight +// purpose : +// ======================================================================= +V3d_PositionalLight::V3d_PositionalLight (const Handle(V3d_Viewer)& theViewer, + const Standard_Real theXt, + const Standard_Real theYt, + const Standard_Real theZt, + const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp, + const Quantity_NameOfColor theColor, + const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation) +: V3d_PositionLight (theViewer) +{ + SetType (V3d_POSITIONAL); + SetColor (Quantity_Color (theColor)); + SetTarget (theXt, theYt, theZt); + SetPosition (theXp, theYp, theZp); + SetAttenuation (theConstAttenuation, theLinearAttenuation); } -//-Methods, in order - // ======================================================================= // function : SetSmoothRadius // purpose : // ======================================================================= void V3d_PositionalLight::SetSmoothRadius (const Standard_Real theValue) { - MyLight->SetSmoothRadius (theValue); -} + V3d_BadValue_Raise_if (theValue < 0.0, + "V3d_PositionalLight::SetSmoothRadius," + "Bad value for smoothing radius"); -void V3d_PositionalLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) { - MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp)); + myLight.Smoothness = static_cast (theValue); } -void V3d_PositionalLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) { - - - V3d_BadValue_Raise_if ( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1, - "V3d_PositionalLight::SetAttenuation, bad coefficients"); - - MyLight->SetAttenuation1(A1) ; - MyLight->SetAttenuation2(A2) ; +// ======================================================================= +// function : SetPosition +// purpose : +// ======================================================================= +void V3d_PositionalLight::SetPosition (const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp) +{ + myLight.Position.x() = static_cast (theXp); + myLight.Position.y() = static_cast (theYp); + myLight.Position.z() = static_cast (theZp); } -void V3d_PositionalLight::Position(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)const { - Quantity_Color C ; - Graphic3d_Vertex P ; - Standard_Real A1,A2 ; - - MyLight->Values(C,P,A1,A2) ; - P.Coord(X,Y,Z) ; +// ======================================================================= +// function : SetAttenuation +// purpose : +// ======================================================================= +void V3d_PositionalLight::SetAttenuation (const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation) +{ + V3d_BadValue_Raise_if (theConstAttenuation < 0. + || theConstAttenuation > 1. + || theLinearAttenuation < 0. + || theLinearAttenuation > 1., + "V3d_PositionalLight::SetAttenuation, bad coefficients"); + + myLight.ChangeConstAttenuation() = static_cast (theConstAttenuation); + myLight.ChangeLinearAttenuation() = static_cast (theLinearAttenuation); } -void V3d_PositionalLight::Attenuation(Standard_Real& A1, Standard_Real& A2)const { - Quantity_Color C ; - Graphic3d_Vertex P ; - - MyLight->Values(C,P,A1,A2) ; +// ======================================================================= +// function : Position +// purpose : +// ======================================================================= +void V3d_PositionalLight::Position (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const +{ + theX = myLight.Position.x(); + theY = myLight.Position.y(); + theZ = myLight.Position.z(); } -void V3d_PositionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const { +// ======================================================================= +// function : Attenuation +// purpose : +// ======================================================================= +void V3d_PositionalLight::Attenuation (Standard_Real& theConstAttenuation, + Standard_Real& theLinearAttenuation) const +{ + theConstAttenuation = myLight.ConstAttenuation(); + theLinearAttenuation = myLight.LinearAttenuation(); +} +// ======================================================================= +// function : Symbol +// purpose : +// ======================================================================= +void V3d_PositionalLight::Symbol (const Handle(Graphic3d_Group)& theSymbol, const Handle(V3d_View)& theView) const +{ Standard_Real Xi,Yi,Zi,Xf,Yf,Zf,Rayon,PXT,PYT,X,Y,Z,XT,YT,ZT; Standard_Real A,B,C,Dist,Beta,CosBeta,SinBeta,Coef,X1,Y1,Z1; Standard_Real VX,VY,VZ; Standard_Integer IXP,IYP,j; TColStd_Array2OfReal MatRot(0,2,0,2); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); this->Position(Xi,Yi,Zi); Rayon = this->Radius(); - aView->Project(Xi,Yi,Zi,PXT,PYT); - aView->Convert(PXT,PYT,IXP,IYP); + theView->Project(Xi,Yi,Zi,PXT,PYT); + theView->Convert(PXT,PYT,IXP,IYP); // 3D Coordinate in the plane of projection of the source. - aView->Convert(IXP,IYP,XT,YT,ZT); - aView->Convert(PXT,PYT+Rayon,IXP,IYP); - aView->Convert(IXP,IYP,X,Y,Z); + theView->Convert(IXP,IYP,XT,YT,ZT); + theView->Convert(PXT,PYT+Rayon,IXP,IYP); + theView->Convert(IXP,IYP,X,Y,Z); X = X+Xi-XT; Y = Y+Yi-YT; Z = Z+Zi-ZT; Dist = Sqrt( Square(X-Xi) + Square(Y-Yi) + Square(Z-Zi) ); // Axis of rotation. @@ -155,7 +190,7 @@ void V3d_PositionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const C = (Z-Zi)/Dist; // A sphere is drawn - V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); + V3d::CircleInPlane(theSymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); for( j=1 ; j<=3 ; j++ ) { Beta = j * M_PI / 4.; CosBeta = Cos(Beta); @@ -178,13 +213,16 @@ void V3d_PositionalLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, const Y1 = VX * MatRot(1,0) + VY * MatRot(1,1) + VZ * MatRot(1,2); Z1 = VX * MatRot(2,0) + VY * MatRot(2,1) + VZ * MatRot(2,2); VX = X1 + Xi - Xf ; VY = Y1 + Yi - Yf ; VZ = Z1 + Zi - Zf; - V3d::CircleInPlane(gsymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); + V3d::CircleInPlane(theSymbol,Xi,Yi,Zi,VX,VY,VZ,Rayon/40.); } } - -void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, - const V3d_TypeOfRepresentation TPres ) +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void V3d_PositionalLight::Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theRepresentation) { Graphic3d_Vertex PText ; Standard_Real X,Y,Z,Rayon; @@ -200,44 +238,44 @@ void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, // Creation of a structure snopick of non-markable elements (target, meridian and // parallel). - Pres = TPres; - Handle(V3d_Viewer) TheViewer = aView->Viewer(); + Pres = theRepresentation; + Handle(V3d_Viewer) TheViewer = theView->Viewer(); UpdSov = TheViewer->UpdateMode(); TheViewer->SetUpdateMode(V3d_WAIT); - if (!MyGraphicStructure.IsNull()) { - MyGraphicStructure->Disconnect(MyGraphicStructure1); - MyGraphicStructure->Clear(); - MyGraphicStructure1->Clear(); - if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; + if (!myGraphicStructure.IsNull()) { + myGraphicStructure->Disconnect(myGraphicStructure1); + myGraphicStructure->Clear(); + myGraphicStructure1->Clear(); + if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation; } else { if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; - Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure = slight; - Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure1 = snopick; + Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure = slight; + Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure1 = snopick; } Handle(Graphic3d_Group) gradius, gExtArrow, gIntArrow; if (Pres == V3d_COMPLETE) { - gradius = MyGraphicStructure->NewGroup(); - gExtArrow = MyGraphicStructure->NewGroup(); - gIntArrow = MyGraphicStructure->NewGroup(); + gradius = myGraphicStructure->NewGroup(); + gExtArrow = myGraphicStructure->NewGroup(); + gIntArrow = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) glight = MyGraphicStructure->NewGroup(); + Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup(); Handle(Graphic3d_Group) gsphere; if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { - gsphere = MyGraphicStructure->NewGroup(); + gsphere = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) gnopick = MyGraphicStructure1->NewGroup(); + Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup(); - X0 = MyTarget.X(); - Y0 = MyTarget.Y(); - Z0 = MyTarget.Z(); + X0 = myTarget.X(); + Y0 = myTarget.Y(); + Z0 = myTarget.Z(); // Display of the position of the light. @@ -246,14 +284,14 @@ void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); Asp1->SetColor(Col1); glight->SetPrimitivesAspect(Asp1); - this->Symbol(glight,aView); + this->Symbol(glight,theView); // Display of the markable sphere (limit at the cercle). if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { Rayon = this->Radius(); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); // Display of the radius of the sphere (line + text) @@ -278,7 +316,7 @@ void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, gnopick->SetPrimitivesAspect(Asp2); // Definition of the axis of circle - aView->Up(DXRef,DYRef,DZRef); + theView->Up(DXRef,DYRef,DZRef); this->Position(X,Y,Z); DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; VX = DYRef*DZini - DZRef*DYini; @@ -290,8 +328,8 @@ void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, // Display of the parallel // Definition of the axis of circle - aView->Proj(VX,VY,VZ); - aView->Up(X1,Y1,Z1); + theView->Proj(VX,VY,VZ); + theView->Up(X1,Y1,Z1); DXRef = VY * Z1 - VZ * Y1; DYRef = VZ * X1 - VX * Z1; DZRef = VX * Y1 - VY * X1; @@ -304,8 +342,8 @@ void V3d_PositionalLight::Display( const Handle(V3d_View)& aView, V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); } - MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); - MyTypeOfRepresentation = Pres; - MyGraphicStructure->Display(); + myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT); + myTypeOfRepresentation = Pres; + myGraphicStructure->Display(); TheViewer->SetUpdateMode(UpdSov); } diff --git a/src/V3d/V3d_PositionalLight.hxx b/src/V3d/V3d_PositionalLight.hxx index a91230c4ca..061fd99054 100644 --- a/src/V3d/V3d_PositionalLight.hxx +++ b/src/V3d/V3d_PositionalLight.hxx @@ -17,20 +17,8 @@ #ifndef _V3d_PositionalLight_HeaderFile #define _V3d_PositionalLight_HeaderFile -#include -#include - -#include -#include -#include #include -#include -#include -class V3d_BadValue; -class V3d_Viewer; -class V3d_View; -class Graphic3d_Group; - +#include class V3d_PositionalLight; DEFINE_STANDARD_HANDLE(V3d_PositionalLight, V3d_PositionLight) @@ -39,52 +27,64 @@ DEFINE_STANDARD_HANDLE(V3d_PositionalLight, V3d_PositionLight) //! (positional) light source. class V3d_PositionalLight : public V3d_PositionLight { - public: - - //! Creates an isolated light source X,Y,Z in the viewer. - //! It is also defined by the color Color and - //! two attenuation factors Attenuation1, Attenuation2. + //! Creates an isolated light source theX, theY, theZ in the viewer. + //! It is also defined by the color theColor and + //! two attenuation factors theConstAttentuation, theLinearAttentuation. //! The resulting attenuation factor determining the //! illumination of a surface depends on the following //! formula : - //! F = 1/(A1 + A2*Length) - //! A1,A2 being the two factors of attenuation + //! F = 1/(ConstAttenuation + LinearAttenuation*Length) //! Length is the distance of the isolated source - //! from the surface. - //! Warning! raises BadValue from V3d - //! if one of the attenuation coefficients is not between 0 et 1. - Standard_EXPORT V3d_PositionalLight(const Handle(V3d_Viewer)& VM, const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Quantity_Coefficient Attenuation1 = 1.0, const Quantity_Coefficient Attenuation2 = 0.0); - - //! Creates a light source of the Positional type - //! in the viewer. - //! Xt,Yt,Zt : Coordinate of Target light source. - //! Xp,Yp,Zp : Coordinate of Position light source. + //! from the surface. //! Warning! raises BadValue from V3d + //! if one of the attenuation coefficients is not in range [0, 1]. + Standard_EXPORT V3d_PositionalLight (const Handle(V3d_Viewer)& theViewer, + const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Quantity_Coefficient theConstAttenuation = 1.0, + const Quantity_Coefficient theLinearAttenuation = 0.0); + + //! Creates a light source of the Positional type in the viewer. + //! theXt, theYt, theZt : Coordinate of Target light source. + //! theXp, theYp, theZp : Coordinate of Position light source. //! The light source is also defined by the color Color - //! and two attenuation factors Attenuation1, - //! Attenuation2 that determine the illumination of a + //! and two attenuation factors theConstAttentuation, + //! theLinearAttentuation that determine the illumination of a //! surface using the following formula : - //! F = 1/(A1 + A2*Length) where: - //! - A1,A2 are the two attenuation factors, and - //! - Length is the distance from the isolated source. - //! Warning! raises BadValue from V3d + //! F = 1/(ConstAttenuation + LinearAttenuation*Length) + //! Length is the distance of the isolated source + //! from the surface. //! Warning! raises BadValue from V3d //! if one of the attenuation coefficients is not between 0 et 1. - Standard_EXPORT V3d_PositionalLight(const Handle(V3d_Viewer)& VM, const V3d_Coordinate Xt, const V3d_Coordinate Yt, const V3d_Coordinate Zt, const V3d_Coordinate Xp, const V3d_Coordinate Yp, const V3d_Coordinate Zp, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Quantity_Coefficient Attenuation1 = 1.0, const Quantity_Coefficient Attenuation2 = 0.0); - + Standard_EXPORT V3d_PositionalLight (const Handle(V3d_Viewer)& theViewer, + const V3d_Coordinate theXt, + const V3d_Coordinate theYt, + const V3d_Coordinate theZt, + const V3d_Coordinate theXp, + const V3d_Coordinate theYp, + const V3d_Coordinate theZp, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Quantity_Coefficient theConstAttenuation = 1.0, + const Quantity_Coefficient theLinearAttenuation = 0.0); + //! Defines the position of the light source. - Standard_EXPORT virtual void SetPosition (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z) Standard_OVERRIDE; - + Standard_EXPORT virtual void SetPosition (const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ) Standard_OVERRIDE; + //! Defines the attenuation factors. //! Warning: raises BadValue from V3d //! if one of the attenuation coefficients is not between 0 et 1. - Standard_EXPORT void SetAttenuation (const Quantity_Coefficient A1, const Quantity_Coefficient A2); - + Standard_EXPORT void SetAttenuation (const Quantity_Coefficient theConstAttenuation, + const Quantity_Coefficient theLinearAttenuation); + //! Modifies the smoothing radius Standard_EXPORT void SetSmoothRadius (const Standard_Real theValue); - + //! Display the graphic structure of light source - //! in the choosen view. We have three type of representation + //! in the chosen view. We have three type of representation //! - SIMPLE : Only the light source is displayed. //! - PARTIAL : The light source and the light space are //! displayed. @@ -93,39 +93,25 @@ public: //! We can choose the "SAMELAST" as parameter of representation //! In this case the graphic structure representation will be //! the last displayed. - Standard_EXPORT void Display (const Handle(V3d_View)& aView, const V3d_TypeOfRepresentation Representation) Standard_OVERRIDE; - - //! Returns the position of the light source. - Standard_EXPORT void Position (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const Standard_OVERRIDE; - - //! Returns the attenuation factors A1,A2 of the light - //! source used at construction time. - Standard_EXPORT void Attenuation (Quantity_Coefficient& A1, Quantity_Coefficient& A2) const; - + Standard_EXPORT void Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theRepresentation) Standard_OVERRIDE; + //! Returns the position of the light source. + Standard_EXPORT void Position (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const Standard_OVERRIDE; + //! Returns the attenuation factors. + Standard_EXPORT void Attenuation (Quantity_Coefficient& theConstAttenuation, + Quantity_Coefficient& theLinearAttenuation) const; DEFINE_STANDARD_RTTI(V3d_PositionalLight,V3d_PositionLight) -protected: - - - - private: - //! Defined the representation of the positional light source. - Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const Standard_OVERRIDE; - - - + Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& theSymbol, + const Handle(V3d_View)& theView) const Standard_OVERRIDE; }; - - - - - - #endif // _V3d_PositionalLight_HeaderFile diff --git a/src/V3d/V3d_RectangularGrid.cxx b/src/V3d/V3d_RectangularGrid.cxx index 3ea13ba99d..5959f6fbea 100644 --- a/src/V3d/V3d_RectangularGrid.cxx +++ b/src/V3d/V3d_RectangularGrid.cxx @@ -40,7 +40,6 @@ #include #include #include -#include /*----------------------------------------------------------------------*/ /* @@ -53,7 +52,7 @@ V3d_RectangularGrid::V3d_RectangularGrid (const V3d_ViewerPointer& aViewer, const Quantity_Color& aColor, const Quantity_Color& aTenthColor) : Aspect_RectangularGrid (1.,1.), - myStructure (new Graphic3d_Structure (aViewer->Viewer ())), + myStructure (new Graphic3d_Structure (aViewer->StructureManager())), myGroup (myStructure->NewGroup()), myViewer (aViewer), myCurAreDefined (Standard_False) diff --git a/src/V3d/V3d_SpotLight.cxx b/src/V3d/V3d_SpotLight.cxx index 307a9ca26a..25e54010e6 100644 --- a/src/V3d/V3d_SpotLight.cxx +++ b/src/V3d/V3d_SpotLight.cxx @@ -47,144 +47,204 @@ #include #include #include -#include -#include -#include -V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real X, const Standard_Real Y, const Standard_Real Z, const V3d_TypeOfOrientation Direction, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) { - - V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 - || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle"); - - Quantity_Color C(Name) ; - Graphic3d_Vector D = V3d::GetProjAxis(Direction) ; - Graphic3d_Vertex P(X,Y,Z) ; - Graphic3d_Vertex T; - - MyType = V3d_SPOT ; - MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ; - // The target is fixed, starting from the light position and the direction. - T.SetCoord(X + D.X(), Y + D.Y(), Z + D.Z()); - MyTarget = T; -} - -V3d_SpotLight::V3d_SpotLight(const Handle(V3d_Viewer)& VM, const Standard_Real Xt, const Standard_Real Yt, const Standard_Real Zt, const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp, const Quantity_NameOfColor Name, const Standard_Real A1, const Standard_Real A2, const Standard_Real CN, const Standard_Real AN):V3d_PositionLight(VM) { - - V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 - || AN < 0. || AN > M_PI, "V3d_SpotLight, bad coefficient or angle"); - - Quantity_Color C(Name) ; - Graphic3d_Vertex T(Xt,Yt,Zt) ; - Graphic3d_Vertex P(Xp,Yp,Zp) ; - Graphic3d_Vector D(P,T); - - MyType = V3d_SPOT ; - D.Normalize(); - MyLight = new Visual3d_Light(C,P,D,CN,A1,A2,AN) ; - MyTarget = T; - // La Structure graphique sera initialisee lors de l'affichage. +// ======================================================================= +// function : V3d_SpotLight +// purpose : +// ======================================================================= +V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer, + const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + const V3d_TypeOfOrientation theDirection, + const Quantity_NameOfColor theColor, + const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation, + const Standard_Real theConcentration, + const Standard_Real theAngle) +: V3d_PositionLight (theViewer) +{ + Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection); + SetType (V3d_SPOT); + SetColor (theColor); + SetTarget (theX + aDir.X(), theY + aDir.Y(), theZ + aDir.Z()); + SetPosition (theX, theY, theZ); + SetDirection (aDir.X(), aDir.Y(), aDir.Z()); + SetAttenuation (theConstAttenuation, theLinearAttenuation); + SetConcentration (theConcentration); + SetAngle (theAngle); } - -//-Methods, in order - -void V3d_SpotLight::SetPosition(const Standard_Real Xp, const Standard_Real Yp, const Standard_Real Zp) { - MyLight->SetPosition (Graphic3d_Vertex (Xp,Yp,Zp)); +// ======================================================================= +// function : V3d_SpotLight +// purpose : +// ======================================================================= +V3d_SpotLight::V3d_SpotLight (const Handle(V3d_Viewer)& theViewer, + const Standard_Real theXt, + const Standard_Real theYt, + const Standard_Real theZt, + const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp, + const Quantity_NameOfColor theColor, + const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation, + const Standard_Real theConcentration, + const Standard_Real theAngle) +: V3d_PositionLight (theViewer) +{ + SetType (V3d_SPOT); + SetColor (theColor); + SetTarget (theXt, theYt, theZt); + SetPosition (theXp, theYp, theZp); + SetDirection (theXt - theXp, theYt - theYp, theZt - theZp); + SetAttenuation (theConstAttenuation, theLinearAttenuation); + SetConcentration (theConcentration); + SetAngle (theAngle); } -void V3d_SpotLight::SetDirection(const Standard_Real Vx, const Standard_Real Vy, const Standard_Real Vz) { - - Graphic3d_Vector D ; - D.SetCoord(Vx,Vy,Vz) ; D.Normalize() ; - MyLight->SetDirection(D) ; +// ======================================================================= +// function : SetPosition +// purpose : +// ======================================================================= +void V3d_SpotLight::SetPosition (const Standard_Real theXp, + const Standard_Real theYp, + const Standard_Real theZp) +{ + myLight.Position.x() = static_cast (theXp); + myLight.Position.y() = static_cast (theYp); + myLight.Position.z() = static_cast (theZp); } -void V3d_SpotLight::SetDirection(const V3d_TypeOfOrientation Direction) { - - Graphic3d_Vector D = V3d::GetProjAxis(Direction) ; - MyLight->SetDirection(D) ; +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +void V3d_SpotLight::SetDirection (const Standard_Real theVx, + const Standard_Real theVy, + const Standard_Real theVz) +{ + myLight.Direction.x() = static_cast (theVx); + myLight.Direction.y() = static_cast (theVy); + myLight.Direction.z() = static_cast (theVz); } -void V3d_SpotLight::SetAttenuation(const Standard_Real A1, const Standard_Real A2) { - - V3d_BadValue_Raise_if( A1 < 0 || A1 > 1. || A2 < 0 || A2 > 1 , - "V3d_SpotLight::SetAttenuation, bad coefficients"); - - MyLight->SetAttenuation1(A1) ; - MyLight->SetAttenuation2(A2) ; +// ======================================================================= +// function : SetDirection +// purpose : +// ======================================================================= +void V3d_SpotLight::SetDirection (const V3d_TypeOfOrientation theDirection) +{ + Graphic3d_Vector aDir = V3d::GetProjAxis (theDirection); + SetDirection (aDir.X(), aDir.Y(), aDir.Z()); } -void V3d_SpotLight::SetConcentration(const Standard_Real C) { - - - V3d_BadValue_Raise_if( C < 0 || C > 1., - "V3d_SpotLight::SetConcentration, bad coefficient"); - - MyLight->SetConcentration(C) ; +// ======================================================================= +// function : SetAttenuation +// purpose : +// ======================================================================= +void V3d_SpotLight::SetAttenuation (const Standard_Real theConstAttenuation, + const Standard_Real theLinearAttenuation) +{ + V3d_BadValue_Raise_if (theConstAttenuation < 0. || + theConstAttenuation > 1. || + theLinearAttenuation < 0. || + theLinearAttenuation > 1 , + "V3d_SpotLight::SetAttenuation, " + "bad coefficients"); + + myLight.ChangeConstAttenuation() = static_cast (theConstAttenuation); + myLight.ChangeLinearAttenuation() = static_cast (theLinearAttenuation); } -void V3d_SpotLight::SetAngle(const Standard_Real Angle) { - - V3d_BadValue_Raise_if( Angle <= 0. || Angle >= M_PI, - "V3d_SpotLight::SetAngle, bad angle"); - MyLight->SetAngle(Angle) ; +// ======================================================================= +// function : SetConcentration +// purpose : +// ======================================================================= +void V3d_SpotLight::SetConcentration (const Standard_Real theConcentration) +{ + V3d_BadValue_Raise_if (theConcentration < 0. || + theConcentration > 1., + "V3d_SpotLight::SetConcentration, " + "bad coefficient"); + myLight.ChangeConcentration() = static_cast (theConcentration); } -void V3d_SpotLight::Direction(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz)const { - - Quantity_Color C ; - Graphic3d_Vector D ; - Graphic3d_Vertex P ; - Standard_Real CN,A1,A2,AN ; +// ======================================================================= +// function : SetAngle +// purpose : +// ======================================================================= +void V3d_SpotLight::SetAngle (const Standard_Real theAngle) +{ + V3d_BadValue_Raise_if (theAngle <= 0. || + theAngle >= M_PI, + "V3d_SpotLight::SetAngle, " + "bad angle"); - MyLight->Values(C,P,D,CN,A1,A2,AN) ; - D.Coord(Vx,Vy,Vz) ; + myLight.ChangeAngle() = static_cast (theAngle); } -void V3d_SpotLight::Position(Standard_Real& Xp, Standard_Real& Yp, Standard_Real& Zp)const { - - Quantity_Color C ; - Graphic3d_Vector D ; - Graphic3d_Vertex P ; - Standard_Real CN,A1,A2,AN ; +// ======================================================================= +// function : Direction +// purpose : +// ======================================================================= +void V3d_SpotLight::Direction (Standard_Real& theVx, + Standard_Real& theVy, + Standard_Real& theVz) const +{ + theVx = myLight.Direction.x(); + theVy = myLight.Direction.y(); + theVz = myLight.Direction.z(); +} - MyLight->Values(C,P,D,CN,A1,A2,AN) ; - P.Coord(Xp,Yp,Zp) ; +// ======================================================================= +// function : Direction +// purpose : +// ======================================================================= +void V3d_SpotLight::Position (Standard_Real& theXp, + Standard_Real& theYp, + Standard_Real& theZp) const +{ + theXp = myLight.Position.x(); + theYp = myLight.Position.y(); + theZp = myLight.Position.z(); } -void V3d_SpotLight::Attenuation(Standard_Real& A1, Standard_Real& A2) const { - Quantity_Color C ; - Graphic3d_Vector D ; - Graphic3d_Vertex P ; - Standard_Real CN,AN ; - - MyLight->Values(C,P,D,CN,A1,A2,AN) ; +// ======================================================================= +// function : Attenuation +// purpose : +// ======================================================================= +void V3d_SpotLight::Attenuation (Standard_Real& theConstAttenuation, + Standard_Real& theLinearAttenuation) const +{ + theConstAttenuation = myLight.ConstAttenuation(); + theLinearAttenuation = myLight.LinearAttenuation(); } -Standard_Real V3d_SpotLight::Concentration()const +// ======================================================================= +// function : Concentration +// purpose : +// ======================================================================= +Standard_Real V3d_SpotLight::Concentration ()const { - Quantity_Color C ; - Graphic3d_Vector D ; - Graphic3d_Vertex P ; - Standard_Real AN,A1,A2,CN ; - - MyLight->Values(C,P,D,CN,A1,A2,AN) ; - return CN ; + return myLight.Concentration(); } +// ======================================================================= +// function : Concentration +// purpose : +// ======================================================================= Standard_Real V3d_SpotLight::Angle()const { - Quantity_Color C ; - Graphic3d_Vector D ; - Graphic3d_Vertex P ; - Standard_Real CN,A1,A2,AN ; - - MyLight->Values(C,P,D,CN,A1,A2,AN) ; - return AN ; + return myLight.Angle(); } -void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, +// ======================================================================= +// function : Symbol +// purpose : +// ======================================================================= +void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& theSymbol, const Handle(V3d_View)& ) const { Standard_Real X,Y,Z; @@ -192,11 +252,15 @@ void V3d_SpotLight::Symbol (const Handle(Graphic3d_Group)& gsymbol, this->Position(X,Y,Z); this->Direction(DX,DY,DZ); - V3d::ArrowOfRadius(gsymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.); + V3d::ArrowOfRadius(theSymbol,X,Y,Z,-DX,-DY,-DZ,M_PI/8.,this->Radius()/15.); } - -void V3d_SpotLight::Display( const Handle(V3d_View)& aView, - const V3d_TypeOfRepresentation TPres) + +// ======================================================================= +// function : Display +// purpose : +// ======================================================================= +void V3d_SpotLight::Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theTPres) { Graphic3d_Vertex PText ; Standard_Real X,Y,Z,Rayon; @@ -212,44 +276,44 @@ void V3d_SpotLight::Display( const Handle(V3d_View)& aView, // Creation of a structure snopick of non-markable elements (target, meridian and // parallel).// - Pres = TPres; - Handle(V3d_Viewer) TheViewer = aView->Viewer(); + Pres = theTPres; + Handle(V3d_Viewer) TheViewer = theView->Viewer(); UpdSov = TheViewer->UpdateMode(); TheViewer->SetUpdateMode(V3d_WAIT); - if (!MyGraphicStructure.IsNull()) { - MyGraphicStructure->Disconnect(MyGraphicStructure1); - MyGraphicStructure->Clear(); - MyGraphicStructure1->Clear(); - if (Pres == V3d_SAMELAST) Pres = MyTypeOfRepresentation; + if (!myGraphicStructure.IsNull()) { + myGraphicStructure->Disconnect(myGraphicStructure1); + myGraphicStructure->Clear(); + myGraphicStructure1->Clear(); + if (Pres == V3d_SAMELAST) Pres = myTypeOfRepresentation; } else { if (Pres == V3d_SAMELAST) Pres = V3d_SIMPLE; - Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure = slight; - Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->Viewer()); - MyGraphicStructure1 = snopick; + Handle(Graphic3d_Structure) slight = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure = slight; + Handle(Graphic3d_Structure) snopick = new Graphic3d_Structure(TheViewer->StructureManager()); + myGraphicStructure1 = snopick; } Handle(Graphic3d_Group) gradius, gExtArrow, gIntArrow; if (Pres == V3d_COMPLETE) { - gradius = MyGraphicStructure->NewGroup(); - gExtArrow = MyGraphicStructure->NewGroup(); - gIntArrow = MyGraphicStructure->NewGroup(); + gradius = myGraphicStructure->NewGroup(); + gExtArrow = myGraphicStructure->NewGroup(); + gIntArrow = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) glight = MyGraphicStructure->NewGroup(); + Handle(Graphic3d_Group) glight = myGraphicStructure->NewGroup(); Handle(Graphic3d_Group) gsphere; if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { - gsphere = MyGraphicStructure->NewGroup(); + gsphere = myGraphicStructure->NewGroup(); } - Handle(Graphic3d_Group) gnopick = MyGraphicStructure1->NewGroup(); + Handle(Graphic3d_Group) gnopick = myGraphicStructure1->NewGroup(); - X0 = MyTarget.X(); - Y0 = MyTarget.Y(); - Z0 = MyTarget.Z(); + X0 = myTarget.X(); + Y0 = myTarget.Y(); + Z0 = myTarget.Z(); //Display of the position of the light. @@ -258,14 +322,14 @@ void V3d_SpotLight::Display( const Handle(V3d_View)& aView, Handle(Graphic3d_AspectLine3d) Asp1 = new Graphic3d_AspectLine3d(); Asp1->SetColor(Col1); glight->SetPrimitivesAspect(Asp1); - this->Symbol(glight,aView); + this->Symbol(glight,theView); // Display of the reference sphere (limited by circle). if (Pres == V3d_COMPLETE || Pres == V3d_PARTIAL) { Rayon = this->Radius(); - aView->Proj(VX,VY,VZ); + theView->Proj(VX,VY,VZ); V3d::CircleInPlane(gsphere,X0,Y0,Z0,VX,VY,VZ,Rayon); // Display of the radius of the sphere (line + text) @@ -290,7 +354,7 @@ void V3d_SpotLight::Display( const Handle(V3d_View)& aView, gnopick->SetPrimitivesAspect(Asp2); // Definition of the axis of the circle - aView->Up(DXRef,DYRef,DZRef); + theView->Up(DXRef,DYRef,DZRef); this->Position(X,Y,Z); DXini = X-X0; DYini = Y-Y0; DZini = Z-Z0; VX = DYRef*DZini - DZRef*DYini; @@ -302,8 +366,8 @@ void V3d_SpotLight::Display( const Handle(V3d_View)& aView, // Display of the parallel // Definition of the axis of the circle - aView->Proj(VX,VY,VZ); - aView->Up(X1,Y1,Z1); + theView->Proj(VX,VY,VZ); + theView->Up(X1,Y1,Z1); DXRef = VY * Z1 - VZ * Y1; DYRef = VZ * X1 - VX * Z1; DZRef = VX * Y1 - VY * X1; @@ -316,8 +380,8 @@ void V3d_SpotLight::Display( const Handle(V3d_View)& aView, V3d::CircleInPlane(gnopick,X0,Y0,Z0,VX,VY,VZ,Rayon); } - MyGraphicStructure->Connect(MyGraphicStructure1,Graphic3d_TOC_DESCENDANT); - MyTypeOfRepresentation = Pres; - MyGraphicStructure->Display(); + myGraphicStructure->Connect(myGraphicStructure1,Graphic3d_TOC_DESCENDANT); + myTypeOfRepresentation = Pres; + myGraphicStructure->Display(); TheViewer->SetUpdateMode(UpdSov); } diff --git a/src/V3d/V3d_SpotLight.hxx b/src/V3d/V3d_SpotLight.hxx index d712dee65f..1d58e82e06 100644 --- a/src/V3d/V3d_SpotLight.hxx +++ b/src/V3d/V3d_SpotLight.hxx @@ -17,85 +17,94 @@ #ifndef _V3d_SpotLight_HeaderFile #define _V3d_SpotLight_HeaderFile -#include -#include - #include -#include #include -#include -#include -#include -#include -#include -class V3d_BadValue; -class V3d_Viewer; -class V3d_View; -class Graphic3d_Group; - +class V3d_Viewer; class V3d_SpotLight; DEFINE_STANDARD_HANDLE(V3d_SpotLight, V3d_PositionLight) //! Creation and modification of a spot. class V3d_SpotLight : public V3d_PositionLight { - public: - //! Creates a light source of the Spot type in the viewer. //! The attenuation factor F which determines //! the illumination of a surface depends on the following formula : - //! F = 1/(A1 + A2*Length) - //! A1,A2 being the 2 factors of attenuation + //! F = 1/(theConstAttenuation + theLinearAttenuation*Length) //! Length is the distance from the source to the surface. //! The default values (1.0,0.0) correspond to a minimum - //! of attenuation . + //! of attenuation. //! The concentration factor determines the dispersion //! of the light on the surface, the default value - //! (1.0) corresponds to a minimum of dispersion . + //! (1.0) corresponds to a minimum of dispersion. //! Warning! raises BadValue from V3d - - //! If one of the coefficients is not between 0 and 1 . - //! If the lighting angle is <= 0 ou > PI . - Standard_EXPORT V3d_SpotLight(const Handle(V3d_Viewer)& VM, const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, const V3d_TypeOfOrientation Direction = V3d_XnegYnegZpos, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Quantity_Coefficient Attenuation1 = 1.0, const Quantity_Coefficient Attenuation2 = 0.0, const Quantity_Coefficient Concentration = 1.0, const Quantity_PlaneAngle Angle = 0.523599); + //! If one of the coefficients is not between 0 and 1. + //! If the lighting angle is <= 0 or > PI. + Standard_EXPORT V3d_SpotLight (const Handle(V3d_Viewer)& theViewer, + const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ, + const V3d_TypeOfOrientation theDirection = V3d_XnegYnegZpos, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Quantity_Coefficient theConstAttenuation = 1.0, + const Quantity_Coefficient theLinearAttenuation = 0.0, + const Quantity_Coefficient theConcentration = 1.0, + const Quantity_PlaneAngle theAngle = 0.523599); //! Creates a light source of the Spot type in the viewer. - //! Xt,Yt,Zt : Coordinate of light source Target. - //! Xp,Yp,Zp : Coordinate of light source Position. + //! theXt, theYt, theZt : Coordinate of light source Target. + //! theXp, theYp, theZp : Coordinate of light source Position. //! The others parameters describe before. //! Warning! raises BadValue from V3d - - //! If one of the coefficients is not between 0 and 1 . - //! If the lighting angle is <= 0 ou > PI . - Standard_EXPORT V3d_SpotLight(const Handle(V3d_Viewer)& VM, const V3d_Coordinate Xt, const V3d_Coordinate Yt, const V3d_Coordinate Zt, const V3d_Coordinate Xp, const V3d_Coordinate Yp, const V3d_Coordinate Zp, const Quantity_NameOfColor Color = Quantity_NOC_WHITE, const Quantity_Coefficient Attenuation1 = 1.0, const Quantity_Coefficient Attenuation2 = 0.0, const Quantity_Coefficient Concentration = 1.0, const Quantity_PlaneAngle Angle = 0.523599); - + //! If one of the coefficients is not between 0 and 1. + //! If the lighting angle is <= 0 or > PI. + Standard_EXPORT V3d_SpotLight (const Handle(V3d_Viewer)& theViewer, + const V3d_Coordinate theXt, + const V3d_Coordinate theYt, + const V3d_Coordinate theZt, + const V3d_Coordinate theXp, + const V3d_Coordinate theYp, + const V3d_Coordinate theZp, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Quantity_Coefficient theConstAttenuation = 1.0, + const Quantity_Coefficient theLinearAttenuation = 0.0, + const Quantity_Coefficient theConcentration = 1.0, + const Quantity_PlaneAngle theAngle = 0.523599); + //! Defines the position of the light source. - Standard_EXPORT virtual void SetPosition (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z) Standard_OVERRIDE; - + Standard_EXPORT virtual void SetPosition (const V3d_Coordinate theX, + const V3d_Coordinate theY, + const V3d_Coordinate theZ) Standard_OVERRIDE; + //! Defines the direction of the light source. //! If the normal vector is NULL. - Standard_EXPORT void SetDirection (const Quantity_Parameter Vx, const Quantity_Parameter Vy, const Quantity_Parameter Vz); - + Standard_EXPORT void SetDirection (const Quantity_Parameter theVx, + const Quantity_Parameter theVy, + const Quantity_Parameter theVz); + //! Defines the direction of the light source //! according to a predefined directional vector. - Standard_EXPORT void SetDirection (const V3d_TypeOfOrientation Orientation); - + Standard_EXPORT void SetDirection (const V3d_TypeOfOrientation theOrientation); + //! Defines the coefficients of attenuation. //! Warning! raises BadValue from V3d - //! if one of the coefficient is <0 ou >1 . - Standard_EXPORT void SetAttenuation (const Quantity_Coefficient A1, const Quantity_Coefficient A2); - + //! if one of the coefficient is < 0 or > 1. + Standard_EXPORT void SetAttenuation (const Quantity_Coefficient theConstAttenuation, + const Quantity_Coefficient theLinearAttenuation); + //! Defines the coefficient of concentration. - //! if the coefficient is <0 ou >1 . - Standard_EXPORT void SetConcentration (const Quantity_Coefficient C); - + //! if the coefficient is < 0 or > 1. + Standard_EXPORT void SetConcentration (const Quantity_Coefficient theConcentration); + //! Defines the spot angle in RADIANS. //! Warning: raises BadValue from from V3d - //! If the angle is <= 0 ou > PI . - Standard_EXPORT void SetAngle (const Quantity_PlaneAngle Angle); - + //! If the angle is <= 0 or > PI. + Standard_EXPORT void SetAngle (const Quantity_PlaneAngle theAngle); + //! Display the graphic structure of light source - //! in the choosen view. We have three type of representation + //! in the chosen view. We have three type of representation //! - SIMPLE : Only the light source is displayed. //! - PARTIAL : The light source and the light space are //! displayed. @@ -104,46 +113,35 @@ public: //! We can choose the "SAMELAST" as parameter of representation //! In this case the graphic structure representation will be //! the last displayed. - Standard_EXPORT void Display (const Handle(V3d_View)& aView, const V3d_TypeOfRepresentation Representation) Standard_OVERRIDE; - - //! Returns the direction of the light source defined by Vx,Vy,Vz. - Standard_EXPORT void Direction (Quantity_Parameter& Vx, Quantity_Parameter& Vy, Quantity_Parameter& Vz) const; - + Standard_EXPORT void Display (const Handle(V3d_View)& theView, + const V3d_TypeOfRepresentation theRepresentation) Standard_OVERRIDE; + + //! Returns the direction of the light source defined by theVx, theVy, theVz. + Standard_EXPORT void Direction (Quantity_Parameter& theVx, + Quantity_Parameter& theVy, + Quantity_Parameter& theVz) const; + //! Returns the position of the light source. - Standard_EXPORT void Position (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const Standard_OVERRIDE; - + Standard_EXPORT void Position (V3d_Coordinate& theX, + V3d_Coordinate& theY, + V3d_Coordinate& theZ) const Standard_OVERRIDE; + //! Returns the attenuation factors A1,A2 of the light source. - Standard_EXPORT void Attenuation (Quantity_Coefficient& A1, Quantity_Coefficient& A2) const; - + Standard_EXPORT void Attenuation (Quantity_Coefficient& theConstAttentuation, + Quantity_Coefficient& theLinearAttentuation) const; + Standard_EXPORT Quantity_Coefficient Concentration() const; - + //! Returns the spot angle. Standard_EXPORT Quantity_PlaneAngle Angle() const; - - - DEFINE_STANDARD_RTTI(V3d_SpotLight,V3d_PositionLight) -protected: - - - - private: - //! Defines the representation of the spot light source. - Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& gsymbol, const Handle(V3d_View)& aView) const Standard_OVERRIDE; - - - + Standard_EXPORT void Symbol (const Handle(Graphic3d_Group)& theSymbol, + const Handle(V3d_View)& theView) const Standard_OVERRIDE; }; - - - - - - #endif // _V3d_SpotLight_HeaderFile diff --git a/src/V3d/V3d_TypeOfShadingModel.hxx b/src/V3d/V3d_TypeOfShadingModel.hxx index 806023767f..10832e1348 100644 --- a/src/V3d/V3d_TypeOfShadingModel.hxx +++ b/src/V3d/V3d_TypeOfShadingModel.hxx @@ -19,10 +19,10 @@ //! Defines the type of shading for the graphic object: -//! - V3d_COLOR: simple surface color (Visual3d_TOM_NONE), -//! - V3d_FLAT: flat shading (Visual3d_TOM_FACET), -//! - V3d_GOURAUD: Gouraud shading (Visual3d_TOM_VERTEX), -//! - V3d_PHONG: Phong shading (Visual3d_TOM_FRAGMENT). +//! - V3d_COLOR: simple surface color (Graphic3d_TOM_NONE), +//! - V3d_FLAT: flat shading (Graphic3d_TOM_FACET), +//! - V3d_GOURAUD: Gouraud shading (Graphic3d_TOM_VERTEX), +//! - V3d_PHONG: Phong shading (Graphic3d_TOM_FRAGMENT). enum V3d_TypeOfShadingModel { V3d_COLOR, diff --git a/src/V3d/V3d_View.cxx b/src/V3d/V3d_View.cxx index 909b38ac6c..dbabd2dac6 100644 --- a/src/V3d/V3d_View.cxx +++ b/src/V3d/V3d_View.cxx @@ -92,6 +92,7 @@ To solve the problem (for lack of a better solution) I make 2 passes. #include #include #include +#include #include #include #include @@ -101,9 +102,6 @@ To solve the problem (for lack of a better solution) I make 2 passes. #include #include #include -#include -#include -#include #define V3d_FLAG_COMPUTATION 0x00000004 @@ -126,207 +124,143 @@ namespace //function : Constructor //purpose : //============================================================================= -V3d_View::V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type ) : - MyViewer(VM.operator->()), +V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType) +: MyViewer (theViewer.operator->()), MyActiveLights(), - MyViewContext (), myActiveLightsIterator(), - SwitchSetFront(Standard_False), + SwitchSetFront (Standard_False), MyTrsf (1, 4, 1, 4) { - myImmediateUpdate = Standard_False; - MyView = new Visual3d_View(MyViewer->Viewer()); - - // { Begin to retrieve the definition from ViewContext. - // Step MyViewContext = MyView->Context() ; - // to permit MyView->SetContext to compare - // the old and the new context. - // No problem for MyViewMapping, MyViewOrientation - // as MyView->SetViewMapping and MyView->SetViewOrientation - // don't try to optimize the modifications introduced to - // viewmapping and vieworientation. - - // Aliasing - if ((MyView->Context ()).AliasingIsOn ()) - MyViewContext.SetAliasingOn (); - else - MyViewContext.SetAliasingOff (); - - // DepthCueing - MyViewContext.SetDepthCueingBackPlane - ((MyView->Context ()).DepthCueingBackPlane ()); - MyViewContext.SetDepthCueingFrontPlane - ((MyView->Context ()).DepthCueingFrontPlane ()); - - if ((MyView->Context ()).DepthCueingIsOn ()) - MyViewContext.SetDepthCueingOn (); - else - MyViewContext.SetDepthCueingOff (); - - // ZClipping - MyViewContext.SetZClippingBackPlane - ((MyView->Context ()).ZClippingBackPlane ()); - MyViewContext.SetZClippingFrontPlane - ((MyView->Context ()).ZClippingFrontPlane ()); - - if ((MyView->Context ()).FrontZClippingIsOn ()) - MyViewContext.SetFrontZClippingOn (); - else - MyViewContext.SetFrontZClippingOff (); + myView = theViewer->Driver()->CreateView (theViewer->StructureManager()); - if ((MyView->Context ()).BackZClippingIsOn ()) - MyViewContext.SetBackZClippingOn (); - else - MyViewContext.SetBackZClippingOff (); - - // Visualization and Shading Model - MyViewContext.SetModel ((MyView->Context ()).Model ()); - MyViewContext.SetVisualization ((MyView->Context ()).Visualization ()); - - // Texture Mapping - MyViewContext.SetSurfaceDetail (MyView->Context ().SurfaceDetail ()); - MyViewContext.SetTextureEnv (MyView->Context ().TextureEnv ()); - // } End of retrieval of the definition of ViewContext. - - MyBackground = VM->GetBackgroundColor() ; - MyGradientBackground = VM->GetGradientBackground() ; + myView->SetBackground (theViewer->GetBackgroundColor()); + myView->SetGradientBackground (theViewer->GetGradientBackground()); // camera init Handle(Graphic3d_Camera) aCamera = new Graphic3d_Camera(); aCamera->SetFOVy (45.0); aCamera->SetIOD (Graphic3d_Camera::IODType_Relative, 0.05); aCamera->SetZFocus (Graphic3d_Camera::FocusType_Relative, 1.0); - SetCamera (aCamera); + aCamera->SetProjectionType ((theType == V3d_ORTHOGRAPHIC) + ? Graphic3d_Camera::Projection_Orthographic + : Graphic3d_Camera::Projection_Perspective); + myDefaultCamera = new Graphic3d_Camera(); + + myImmediateUpdate = Standard_False; + SetAntialiasingOff(); + SetAutoZFitMode (Standard_True, 1.0); + SetBackFacingModel (V3d_TOBM_AUTOMATIC); + SetCamera (aCamera); SetAxis (0.,0.,0.,1.,1.,1.); - SetVisualization (VM->DefaultVisualization()); - SetShadingModel (VM->DefaultShadingModel()); - SetSurfaceDetail (VM->DefaultSurfaceDetail()); + SetVisualization (theViewer->DefaultVisualization()); + SetShadingModel (theViewer->DefaultShadingModel()); + SetSurfaceDetail (theViewer->DefaultSurfaceDetail()); SetTwist (0.); SetAt (0.,0.,0.); - SetProj (VM->DefaultViewProj()); - SetSize (VM->DefaultViewSize()); - Standard_Real zsize = VM->DefaultViewSize(); + SetProj (theViewer->DefaultViewProj()); + SetSize (theViewer->DefaultViewSize()); + Standard_Real zsize = theViewer->DefaultViewSize(); SetZSize (2.*zsize); + SetZClippingType (V3d_OFF); SetZClippingDepth (0.); SetZClippingWidth (zsize); + SetZCueingOff(); SetZCueingDepth (0.); SetZCueingWidth (zsize); - SetDepth (VM->DefaultViewSize()/2.0); + SetDepth (theViewer->DefaultViewSize() / 2.0); SetViewMappingDefault(); SetViewOrientationDefault(); - VM->AddView (this); + theViewer->AddView (this); Init(); myImmediateUpdate = Standard_True; - - aCamera->SetProjectionType ((Type == V3d_ORTHOGRAPHIC) - ? Graphic3d_Camera::Projection_Orthographic - : Graphic3d_Camera::Projection_Perspective); } //============================================================================= //function : Constructor //purpose : //============================================================================= -V3d_View::V3d_View(const Handle(V3d_Viewer)& theVM,const Handle(V3d_View)& theView) : - MyViewer(theVM.operator->()), +V3d_View::V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView) +: MyViewer (theViewer.operator->()), MyActiveLights(), - MyViewContext (), myActiveLightsIterator(), SwitchSetFront(Standard_False), MyTrsf (1, 4, 1, 4) { - Handle(Visual3d_View) aFromView = theView->View(); - - myImmediateUpdate = Standard_False; - MyView = new Visual3d_View (MyViewer->Viewer()); - - for (theView->InitActiveLights(); theView->MoreActiveLights(); theView->NextActiveLights()) - { - MyActiveLights.Append (theView->ActiveLight()); - } + myView = theViewer->Driver()->CreateView (theViewer->StructureManager()); - MyViewContext = aFromView->Context() ; + myView->CopySettings (theView->View()); - SetCamera (new Graphic3d_Camera (theView->Camera())); - View()->SetAutoZFitMode (theView->View()->AutoZFitMode(), theView->View()->AutoZFitScaleFactor()); - - MyBackground = aFromView->Background() ; - MyGradientBackground = aFromView->GradientBackground(); - - MyView->SetContext (MyViewContext) ; + myDefaultCamera = new Graphic3d_Camera(); + myImmediateUpdate = Standard_False; + SetAutoZFitMode (theView->AutoZFitMode(), theView->AutoZFitScaleFactor()); SetAxis (0.0, 0.0, 0.0, 1.0, 1.0, 1.0); - SetViewMappingDefault(); SetViewOrientationDefault(); - theVM->AddView (this); - + theViewer->AddView (this); Init(); - myImmediateUpdate = Standard_True; } //============================================================================= -//function : SetMagnify +//function : Destructor //purpose : //============================================================================= -void V3d_View::SetMagnify(const Handle(Aspect_Window)& TheWindow, - const Handle(V3d_View)& aPreviousView, - const Standard_Integer x1, - const Standard_Integer y1, - const Standard_Integer x2, - const Standard_Integer y2) -{ - if( !MyView->IsDefined() ) { - Standard_Real a,b,c,d; - aPreviousView->Convert(x1,y1,a,b); - aPreviousView->Convert(x2,y2,c,d); - MyView->SetWindow(TheWindow) ; - FitAll(TheWindow,a,b,c,d); - MyView->SetContext(MyViewContext) ; - MyView->SetBackground(MyBackground) ; - MyViewer->SetViewOn(this) ; - MyWindow = TheWindow; - MyView->Redraw() ; - SetViewMappingDefault(); +V3d_View::~V3d_View() +{ + if (!myView->IsRemoved()) + { + myView->Remove(); } } //============================================================================= -//function : SetWindow +//function : SetMagnify //purpose : //============================================================================= -void V3d_View::SetWindow(const Handle(Aspect_Window)& TheWindow) +void V3d_View::SetMagnify (const Handle(Aspect_Window)& theWindow, + const Handle(V3d_View)& thePreviousView, + const Standard_Integer theX1, + const Standard_Integer theY1, + const Standard_Integer theX2, + const Standard_Integer theY2) { - MyView->SetWindow(TheWindow) ; - // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw() - MyWindow = TheWindow; - // SetWindow carries out SetRatio and modifies - MyView->SetContext(MyViewContext) ; - MyView->SetBackground(MyBackground) ; - MyView->SetGradientBackground (MyGradientBackground, Standard_False); - MyViewer->SetViewOn(this) ; - MyView->Redraw() ; + if (!myView->IsRemoved() && !myView->IsDefined()) + { + Standard_Real aU1, aV1, aU2, aV2; + thePreviousView->Convert (theX1, theY1, aU1, aV1); + thePreviousView->Convert (theX2, theY2, aU2, aV2); + myView->SetWindow (theWindow); + FitAll (theWindow, aU1, aV1, aU2, aV2); + MyViewer->SetViewOn (this); + MyWindow = theWindow; + SetRatio(); + Redraw(); + SetViewMappingDefault(); + } } //============================================================================= //function : SetWindow //purpose : //============================================================================= -void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow, - const Aspect_RenderingContext aContext, - const Aspect_GraphicCallbackProc& aDisplayCB, - const Standard_Address aClientData) +void V3d_View::SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext, + const Aspect_GraphicCallbackProc& theDisplayCB, + const Standard_Address theClientData) { + if (myView->IsRemoved()) + { + return; + } + // method V3d_View::SetWindow() should assign the field MyWindow before calling Redraw() - MyWindow = aWindow; - MyView->SetWindow(aWindow, aContext, aDisplayCB, aClientData) ; - MyView->SetContext(MyViewContext) ; - MyView->SetBackground(MyBackground) ; - MyView->SetGradientBackground (MyGradientBackground, Standard_False); - MyViewer->SetViewOn(this) ; - MyView->Redraw() ; + MyWindow = theWindow; + myView->SetWindow (theWindow, theContext, theDisplayCB, theClientData); + MyViewer->SetViewOn (this); + SetRatio(); + Redraw(); } //============================================================================= @@ -336,7 +270,7 @@ void V3d_View::SetWindow(const Handle(Aspect_Window)& aWindow, void V3d_View::Remove() const { MyViewer->DelView (this); - MyView->Remove(); + myView->Remove(); Handle(Aspect_Window)& aWin = const_cast (MyWindow); aWin.Nullify(); } @@ -347,7 +281,13 @@ void V3d_View::Remove() const //============================================================================= void V3d_View::Update() const { - if( MyView->IsDefined() ) MyView->Update (Aspect_TOU_ASAP) ; + if (!myView->IsDefined() + || !myView->IsActive()) + { + return; + } + + myView->Update (Aspect_TOU_ASAP); } //============================================================================= @@ -356,7 +296,31 @@ void V3d_View::Update() const //============================================================================= void V3d_View::Redraw() const { - if( MyView->IsDefined() ) MyView->Redraw() ; + if (!myView->IsDefined() + || !myView->IsActive()) + { + return; + } + + Handle(Graphic3d_GraphicDriver) aGraphicDriver = MyViewer->Driver(); + Handle(Graphic3d_StructureManager) aStructureMgr = MyViewer->StructureManager(); + for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter) + { + if (aGraphicDriver->IsDeviceLost()) + { + aStructureMgr->RecomputeStructures(); + aGraphicDriver->ResetDeviceLostFlag(); + } + + AutoZFit(); + + myView->Redraw(); + + if (!aGraphicDriver->IsDeviceLost()) + { + return; + } + } } //============================================================================= @@ -365,10 +329,13 @@ void V3d_View::Redraw() const //============================================================================= void V3d_View::RedrawImmediate() const { - if (MyView->IsDefined()) + if (!myView->IsDefined() + || !myView->IsActive()) { - MyView->RedrawImmediate(); + return; } + + myView->RedrawImmediate(); } //============================================================================= @@ -377,10 +344,12 @@ void V3d_View::RedrawImmediate() const //============================================================================= void V3d_View::Invalidate() const { - if (MyView->IsDefined()) + if (!myView->IsDefined()) { - MyView->Invalidate(); + return; } + + myView->Invalidate(); } //============================================================================= @@ -389,36 +358,64 @@ void V3d_View::Invalidate() const //============================================================================= Standard_Boolean V3d_View::IsInvalidated() const { - return !MyView->IsDefined() - || MyView->IsInvalidated(); + return !myView->IsDefined() + || myView->IsInvalidated(); } -//============================================================================= -//function : AutoZFit -//purpose : -//============================================================================= -void V3d_View::AutoZFit() +// ======================================================================== +// function : SetAutoZFitMode +// purpose : +// ======================================================================== +void V3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn, + const Standard_Real theScaleFactor) +{ + Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed."); + myAutoZFitScaleFactor = theScaleFactor; + myAutoZFitIsOn = theIsOn; +} + +// ======================================================================== +// function : AutoZFitMode +// purpose : +// ======================================================================== +Standard_Boolean V3d_View::AutoZFitMode() const +{ + return myAutoZFitIsOn; +} + +// ======================================================================== +// function : AutoZFitScaleFactor +// purpose : +// ======================================================================== +Standard_Real V3d_View::AutoZFitScaleFactor() const { - View()->AutoZFit(); + return myAutoZFitScaleFactor; } //============================================================================= -//function : ZFitAll +//function : AutoZFit //purpose : //============================================================================= -void V3d_View::ZFitAll (const Standard_Real theScaleFactor) +void V3d_View::AutoZFit() const { - View()->ZFitAll (theScaleFactor); + if (!AutoZFitMode()) + { + return; + } + + ZFitAll (myAutoZFitScaleFactor); } //============================================================================= -//function : Redraw +//function : ZFitAll //purpose : //============================================================================= -void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc, - const Standard_Integer width,const Standard_Integer height) const +void V3d_View::ZFitAll (const Standard_Real theScaleFactor) const { - if( MyView->IsDefined() ) MyView->Redraw(xc,yc,width,height) ; + Bnd_Box aMinMaxBox = myView->MinMaxValues (Standard_False); // applicative min max boundaries + Bnd_Box aGraphicBox = myView->MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag). + + myView->Camera()->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox); } //============================================================================= @@ -428,8 +425,8 @@ void V3d_View::Redraw(const Standard_Integer xc,const Standard_Integer yc, Standard_Boolean V3d_View::IsEmpty() const { Standard_Boolean TheStatus = Standard_True ; - if( MyView->IsDefined() ) { - Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; + if( myView->IsDefined() ) { + Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ; if( Nstruct > 0 ) TheStatus = Standard_False ; } return (TheStatus) ; @@ -441,7 +438,15 @@ Standard_Boolean V3d_View::IsEmpty() const //============================================================================= void V3d_View::UpdateLights() const { - MyView->SetContext(MyViewContext); + Graphic3d_ListOfCLight aLights; + + for (TColStd_ListIteratorOfListOfTransient anIt (MyActiveLights); anIt.More(); anIt.Next()) + { + aLights.Append (Handle(V3d_Light)::DownCast (anIt.Value())->Light()); + } + + myView->SetLights (aLights); + Update(); } @@ -451,9 +456,12 @@ void V3d_View::UpdateLights() const //============================================================================= void V3d_View::DoMapping() { - if( MyView->IsDefined() ) { - (MyView->Window())->DoMapping() ; + if (!myView->IsDefined()) + { + return; } + + myView->Window()->DoMapping(); } //============================================================================= @@ -462,112 +470,133 @@ void V3d_View::DoMapping() //============================================================================= void V3d_View::MustBeResized() { - if( MyView->IsDefined() ) { - MyView->Resized() ; - MyView->Redraw(); + if (!myView->IsDefined()) + { + return; } + + myView->Resized(); + + SetRatio(); + + Redraw(); } //============================================================================= //function : SetBackgroundColor //purpose : //============================================================================= -void V3d_View::SetBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) +void V3d_View::SetBackgroundColor (const Quantity_TypeOfColor theType, + const Standard_Real theV1, + const Standard_Real theV2, + const Standard_Real theV3) { - Standard_Real V1 = Max( Min( v1, 1.0 ), 0.0 ); - Standard_Real V2 = Max( Min( v2, 1.0 ), 0.0 ); - Standard_Real V3 = Max( Min( v3, 1.0 ), 0.0 ); + Standard_Real aV1 = Max (Min (theV1, 1.0), 0.0); + Standard_Real aV2 = Max (Min (theV2, 1.0), 0.0); + Standard_Real aV3 = Max (Min (theV3, 1.0), 0.0); - Quantity_Color C( V1, V2, V3, Type ); - SetBackgroundColor( C ); + SetBackgroundColor (Quantity_Color (aV1, aV2, aV3, theType)); } //============================================================================= //function : SetBackgroundColor //purpose : //============================================================================= -void V3d_View::SetBackgroundColor(const Quantity_Color &Color) +void V3d_View::SetBackgroundColor (const Quantity_Color& theColor) { - MyBackground.SetColor( Color ); - if ( MyView->IsDefined() ) - MyView->SetBackground( MyBackground ); + myView->SetBackground (Aspect_Background (theColor)); + + if (myImmediateUpdate) + { + Redraw(); + } } //============================================================================= //function : SetBackgroundColor //purpose : //============================================================================= -void V3d_View::SetBackgroundColor(const Quantity_NameOfColor Name) +void V3d_View::SetBackgroundColor (const Quantity_NameOfColor theName) { - Quantity_Color C( Name ); - SetBackgroundColor( C ); + SetBackgroundColor (Quantity_Color (theName)); } //============================================================================= //function : SetBgGradientColors //purpose : //============================================================================= -void V3d_View::SetBgGradientColors( const Quantity_Color& Color1, - const Quantity_Color& Color2, - const Aspect_GradientFillMethod FillStyle, - const Standard_Boolean status) +void V3d_View::SetBgGradientColors (const Quantity_Color& theColor1, + const Quantity_Color& theColor2, + const Aspect_GradientFillMethod theFillStyle, + const Standard_Boolean theToUpdate) { - MyGradientBackground.SetColors(Color1, Color2, FillStyle); - if ( MyView->IsDefined() ) - MyView->SetGradientBackground( MyGradientBackground, status ); + Aspect_GradientBackground aGradientBg (theColor1, theColor2, theFillStyle); + + myView->SetGradientBackground (aGradientBg); + + if (myImmediateUpdate || theToUpdate) + { + Redraw(); + } } //============================================================================= //function : SetBgGradientColors //purpose : //============================================================================= -void V3d_View::SetBgGradientColors( const Quantity_NameOfColor Color1, - const Quantity_NameOfColor Color2, - const Aspect_GradientFillMethod FillStyle, - const Standard_Boolean status ) +void V3d_View::SetBgGradientColors (const Quantity_NameOfColor theColor1, + const Quantity_NameOfColor theColor2, + const Aspect_GradientFillMethod theFillStyle, + const Standard_Boolean theToUpdate) { - Quantity_Color C1( Color1 ); - Quantity_Color C2( Color2 ); - MyGradientBackground.SetColors( C1, C2, FillStyle ); - if ( MyView->IsDefined() ) - MyView->SetGradientBackground( MyGradientBackground, status ); + Quantity_Color aColor1 (theColor1); + Quantity_Color aColor2 (theColor2); + + SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate); } //============================================================================= //function : SetBgGradientStyle //purpose : //============================================================================= -void V3d_View::SetBgGradientStyle( const Aspect_GradientFillMethod FillStyle, - const Standard_Boolean update) +void V3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, const Standard_Boolean theToUpdate) { - Quantity_Color Color1, Color2; - MyGradientBackground.Colors( Color1, Color2 ); - MyGradientBackground.SetColors( Color1, Color2, FillStyle ); - if( MyView->IsDefined() ) - MyView->SetBgGradientStyle( FillStyle, update ) ; + Quantity_Color aColor1; + Quantity_Color aColor2; + GradientBackground().Colors (aColor1, aColor2); + + SetBgGradientColors (aColor1, aColor2, theFillStyle, theToUpdate); } //============================================================================= //function : SetBackgroundImage //purpose : //============================================================================= -void V3d_View::SetBackgroundImage( const Standard_CString FileName, - const Aspect_FillMethod FillStyle, - const Standard_Boolean update ) +void V3d_View::SetBackgroundImage (const Standard_CString theFileName, + const Aspect_FillMethod theFillStyle, + const Standard_Boolean theToUpdate) { - if( MyView->IsDefined() ) - MyView->SetBackgroundImage( FileName, FillStyle, update ) ; + myView->SetBackgroundImage (theFileName); + myView->SetBackgroundImageStyle (theFillStyle); + + if (myImmediateUpdate || theToUpdate) + { + Redraw(); + } } //============================================================================= //function : SetBgImageStyle //purpose : //============================================================================= -void V3d_View::SetBgImageStyle( const Aspect_FillMethod FillStyle, - const Standard_Boolean update ) +void V3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, const Standard_Boolean theToUpdate) { - if( MyView->IsDefined() ) - MyView->SetBgImageStyle( FillStyle, update ) ; + myView->SetBackgroundImageStyle (theFillStyle); + + if (myImmediateUpdate || theToUpdate) + { + Redraw(); + } } //============================================================================= @@ -589,40 +618,46 @@ void V3d_View::SetAxis(const Standard_Real X, const Standard_Real Y, const Stand //function : SetShadingModel //purpose : //============================================================================= -void V3d_View::SetShadingModel(const V3d_TypeOfShadingModel Model) +void V3d_View::SetShadingModel (const V3d_TypeOfShadingModel theShadingModel) { - MyViewContext.SetModel((Visual3d_TypeOfModel) Model) ; - MyView->SetContext(MyViewContext) ; + myView->SetShadingModel (static_cast (theShadingModel)); } //============================================================================= //function : SetSurfaceDetail //purpose : //============================================================================= -void V3d_View::SetSurfaceDetail(const V3d_TypeOfSurfaceDetail Model) +void V3d_View::SetSurfaceDetail (const V3d_TypeOfSurfaceDetail theSurfaceDetail) { - MyViewContext.SetSurfaceDetail((Visual3d_TypeOfSurfaceDetail) Model) ; - MyView->SetContext(MyViewContext) ; + myView->SetSurfaceDetailType (static_cast (theSurfaceDetail)); } //============================================================================= //function : SetTextureEnv //purpose : //============================================================================= -void V3d_View::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) +void V3d_View::SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture) { - MyViewContext.SetTextureEnv(ATexture) ; - MyView->SetContext(MyViewContext) ; + myView->SetTextureEnv (theTexture); + + if (myImmediateUpdate) + { + Redraw(); + } } //============================================================================= //function : SetVisualization //purpose : //============================================================================= -void V3d_View::SetVisualization(const V3d_TypeOfVisualization Mode) +void V3d_View::SetVisualization (const V3d_TypeOfVisualization theType) { - MyViewContext.SetVisualization((Visual3d_TypeOfVisualization) Mode); - MyView->SetContext(MyViewContext) ; + myView->SetVisualizationType (static_cast (theType)); + + if (myImmediateUpdate) + { + Redraw(); + } } //============================================================================= @@ -638,14 +673,22 @@ void V3d_View::SetFront() a.YDirection().Coord(xu,yu,zu); a.Location().Coord(xo,yo,zo); - myCamera->SetCenter (gp_Pnt (xo, yo, zo)); + Handle(Graphic3d_Camera) aCamera = Camera(); + + aCamera->SetCenter (gp_Pnt (xo, yo, zo)); + if(SwitchSetFront) - myCamera->SetDirection (gp_Dir (vx, vy, vz)); + { + aCamera->SetDirection (gp_Dir (vx, vy, vz)); + } else - myCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed()); - myCamera->SetUp (gp_Dir (xu, yu, zu)); + { + aCamera->SetDirection (gp_Dir (vx, vy, vz).Reversed()); + } + + aCamera->SetUp (gp_Dir (xu, yu, zu)); - View()->AutoZFit(); + AutoZFit(); SwitchSetFront = !SwitchSetFront; @@ -672,16 +715,18 @@ void V3d_View::Rotate (const Standard_Real ax, if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI; else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI; + Handle(Graphic3d_Camera) aCamera = Camera(); + if (Start) { - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); // rotate camera around 3 initial axes gp_Dir aBackDir (gp_Vec (myCamStartOpCenter, myCamStartOpEye)); @@ -697,9 +742,9 @@ void V3d_View::Rotate (const Standard_Real ax, aTrsf.Multiply (aRot[1]); aTrsf.Multiply (aRot[2]); - myCamera->Transform (aTrsf); + aCamera->Transform (aTrsf); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -723,25 +768,27 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; + Handle(Graphic3d_Camera) aCamera = Camera(); + if (Start) { myGravityReferencePoint.SetCoord (X, Y, Z); - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } const Graphic3d_Vertex& aVref = myGravityReferencePoint; - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); // rotate camera around 3 initial axes gp_Pnt aRCenter (aVref.X(), aVref.Y(), aVref.Z()); - gp_Dir aZAxis (myCamera->Direction().Reversed()); - gp_Dir aYAxis (myCamera->Up()); + gp_Dir aZAxis (aCamera->Direction().Reversed()); + gp_Dir aYAxis (aCamera->Up()); gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); gp_Trsf aRot[3], aTrsf; @@ -752,9 +799,9 @@ void V3d_View::Rotate(const Standard_Real ax, const Standard_Real ay, const Stan aTrsf.Multiply (aRot[1]); aTrsf.Multiply (aRot[2]); - myCamera->Transform (aTrsf); + aCamera->Transform (aTrsf); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -790,12 +837,14 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; + Handle(Graphic3d_Camera) aCamera = Camera(); + if (Start) { myGravityReferencePoint.SetCoord (X, Y, Z); - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); switch (Axe) { case V3d_X : @@ -809,16 +858,16 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, break ; } - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } const Graphic3d_Vertex& aVref = myGravityReferencePoint; - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); // rotate camera around passed axis gp_Trsf aRotation; @@ -828,9 +877,10 @@ void V3d_View::Rotate(const V3d_TypeOfAxe Axe, const Standard_Real angle, (Axe == V3d_Z) ? 1.0 : 0.0); aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); - myCamera->Transform (aRotation); - View()->AutoZFit(); + aCamera->Transform (aRotation); + + AutoZFit(); ImmediateUpdate(); } @@ -846,26 +896,29 @@ void V3d_View::Rotate(const Standard_Real angle, const Standard_Boolean Start) if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; + Handle(Graphic3d_Camera) aCamera = Camera(); + if( Start ) { - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } const Graphic3d_Vertex& aPnt = MyDefaultViewPoint; const Graphic3d_Vector& anAxis = MyDefaultViewAxis; - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); gp_Trsf aRotation; gp_Pnt aRCenter (aPnt.X(), aPnt.Y(), aPnt.Z()); gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z()); aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); - myCamera->Transform (aRotation); - View()->AutoZFit(); + aCamera->Transform (aRotation); + + AutoZFit(); ImmediateUpdate(); } @@ -887,20 +940,22 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa if( Az > 0. ) while ( Az > DEUXPI ) Az -= DEUXPI ; else if( Az < 0. ) while ( Az < -DEUXPI ) Az += DEUXPI ; + Handle(Graphic3d_Camera) aCamera = Camera(); + if( Start ) { - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); // rotate camera around 3 initial axes - gp_Pnt aRCenter = myCamera->Eye(); - gp_Dir aZAxis (myCamera->Direction().Reversed()); - gp_Dir aYAxis (myCamera->Up()); + gp_Pnt aRCenter = aCamera->Eye(); + gp_Dir aZAxis (aCamera->Direction().Reversed()); + gp_Dir aYAxis (aCamera->Up()); gp_Dir aXAxis (aYAxis.Crossed (aZAxis)); gp_Trsf aRot[3], aTrsf; @@ -911,9 +966,9 @@ void V3d_View::Turn(const Standard_Real ax, const Standard_Real ay, const Standa aTrsf.Multiply (aRot[1]); aTrsf.Multiply (aRot[2]); - myCamera->Transform (aTrsf); + aCamera->Transform (aTrsf); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -948,25 +1003,28 @@ void V3d_View::Turn(const Standard_Real angle, const Standard_Boolean Start) if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; + Handle(Graphic3d_Camera) aCamera = Camera(); + if( Start ) { - myCamStartOpUp = myCamera->Up(); - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpUp = aCamera->Up(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } - myCamera->SetUp (myCamStartOpUp); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetUp (myCamStartOpUp); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); const Graphic3d_Vector& anAxis = MyDefaultViewAxis; gp_Trsf aRotation; - gp_Pnt aRCenter = myCamera->Eye(); + gp_Pnt aRCenter = aCamera->Eye(); gp_Dir aRAxis (anAxis.X(), anAxis.Y(), anAxis.Z()); aRotation.SetRotation (gp_Ax1 (aRCenter, aRAxis), Angle); - myCamera->Transform (aRotation); - View()->AutoZFit(); + aCamera->Transform (aRotation); + + AutoZFit(); ImmediateUpdate(); } @@ -983,7 +1041,9 @@ void V3d_View::SetTwist(const Standard_Real angle) if( Angle > 0. ) while ( Angle > DEUXPI ) Angle -= DEUXPI ; else if( Angle < 0. ) while ( Angle < -DEUXPI ) Angle += DEUXPI ; - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_Dir aReferencePlane (aCamera->Direction().Reversed()); gp_Dir anUp; anUp = gp_Dir (0.0, 0.0, 1.0); @@ -1003,8 +1063,8 @@ void V3d_View::SetTwist(const Standard_Real angle) V3d_BadValue_Raise_if( !TheStatus,"V3d_ViewSetTwist, alignment of Eye,At,Up,"); - gp_Pnt aRCenter = myCamera->Center(); - gp_Dir aZAxis (myCamera->Direction().Reversed()); + gp_Pnt aRCenter = aCamera->Center(); + gp_Dir aZAxis (aCamera->Direction().Reversed()); gp_Trsf aTrsf; aTrsf.SetRotation (gp_Ax1 (aRCenter, aZAxis), Angle); @@ -1012,10 +1072,10 @@ void V3d_View::SetTwist(const Standard_Real angle) Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); - myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); - myCamera->Transform (aTrsf); + aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); + aCamera->Transform (aTrsf); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1030,10 +1090,13 @@ void V3d_View::SetEye(const Standard_Real X,const Standard_Real Y,const Standard Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); - myCamera->SetEye (gp_Pnt (X, Y, Z)); + Handle(Graphic3d_Camera) aCamera = Camera(); + + aCamera->SetEye (gp_Pnt (X, Y, Z)); + SetTwist (aTwistBefore); - View()->AutoZFit(); + AutoZFit(); SetImmediateUpdate (wasUpdateEnabled); @@ -1048,22 +1111,24 @@ void V3d_View::SetDepth(const Standard_Real Depth) { V3d_BadValue_Raise_if (Depth == 0. ,"V3d_View::SetDepth, bad depth"); + Handle(Graphic3d_Camera) aCamera = Camera(); + if( Depth > 0. ) { // Move eye using center (target) as anchor. - myCamera->SetDistance (Depth); + aCamera->SetDistance (Depth); } else { // Move the view ref point instead of the eye. - gp_Vec aDir (myCamera->Direction()); - gp_Pnt aCameraEye = myCamera->Eye(); + gp_Vec aDir (aCamera->Direction()); + gp_Pnt aCameraEye = aCamera->Eye(); gp_Pnt aCameraCenter = aCameraEye.Translated (aDir.Multiplied (Abs (Depth))); - myCamera->SetCenter (aCameraCenter); + aCamera->SetCenter (aCameraCenter); } - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1081,11 +1146,11 @@ void V3d_View::SetProj( const Standard_Real Vx,const Standard_Real Vy, const Sta Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); - myCamera->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed()); + Camera()->SetDirection (gp_Dir (Vx, Vy, Vz).Reversed()); SetTwist(aTwistBefore); - View()->AutoZFit(); + AutoZFit(); SetImmediateUpdate (wasUpdateEnabled); @@ -1116,18 +1181,20 @@ void V3d_View::SetProj( const V3d_TypeOfOrientation Orientation ) const Graphic3d_Vector& aBck = V3d::GetProjAxis (Orientation); // retain camera panning from origin when switching projection - gp_Pnt anOriginVCS = myCamera->ConvertWorld2View (gp::Origin()); + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_Pnt anOriginVCS = aCamera->ConvertWorld2View (gp::Origin()); Standard_Real aPanX = anOriginVCS.X(); Standard_Real aPanY = anOriginVCS.Y(); - myCamera->SetCenter (gp_Pnt (0, 0, 0)); - myCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed()); - myCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn)); - myCamera->OrthogonalizeUp(); + aCamera->SetCenter (gp_Pnt (0, 0, 0)); + aCamera->SetDirection (gp_Dir (aBck.X(), aBck.Y(), aBck.Z()).Reversed()); + aCamera->SetUp (gp_Dir (Xpn, Ypn, Zpn)); + aCamera->OrthogonalizeUp(); Panning (aPanX, aPanY); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1142,11 +1209,11 @@ void V3d_View::SetAt(const Standard_Real X,const Standard_Real Y,const Standard_ Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); - myCamera->SetCenter (gp_Pnt (X, Y, Z)); + Camera()->SetCenter (gp_Pnt (X, Y, Z)); SetTwist (aTwistBefore); - View()->AutoZFit(); + AutoZFit(); SetImmediateUpdate (wasUpdateEnabled); @@ -1163,7 +1230,9 @@ void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standar V3d_BadValue_Raise_if( Sqrt(Vx*Vx + Vy*Vy + Vz*Vz) <= 0. , "V3d_View::SetUp, nullUp vector"); - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_Dir aReferencePlane (aCamera->Direction().Reversed()); gp_Dir anUp (Vx, Vy, Vz); TheStatus = ScreenAxis(aReferencePlane,anUp, @@ -1188,9 +1257,9 @@ void V3d_View::SetUp(const Standard_Real Vx,const Standard_Real Vy,const Standar Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); - myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); + aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1203,7 +1272,9 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) { Standard_Boolean TheStatus ; - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_Dir aReferencePlane (aCamera->Direction().Reversed()); gp_Dir anUp; const Graphic3d_Vector& aViewReferenceUp = V3d::GetProjAxis(Orientation) ; @@ -1231,9 +1302,9 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) Standard_Real myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ; myYscreenAxis.Coord (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ); - myCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); + aCamera->SetUp (gp_Dir (myYscreenAxisX, myYscreenAxisY, myYscreenAxisZ)); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1244,9 +1315,16 @@ void V3d_View::SetUp( const V3d_TypeOfOrientation Orientation ) //============================================================================= void V3d_View::SetViewOrientationDefault() { - MyView->SetViewOrientationDefault() ; + myDefaultCamera->CopyOrientationData (Camera()); +} - ImmediateUpdate(); +//======================================================================= +//function : SetViewMappingDefault +//purpose : +//======================================================================= +void V3d_View::SetViewMappingDefault() +{ + myDefaultCamera->CopyMappingData (Camera()); } //============================================================================= @@ -1255,7 +1333,22 @@ void V3d_View::SetViewOrientationDefault() //============================================================================= void V3d_View::ResetViewOrientation() { - MyView->ViewOrientationReset() ; + Camera()->CopyOrientationData (myDefaultCamera); + + AutoZFit(); + + ImmediateUpdate(); +} + +//======================================================================= +//function : ResetViewMapping +//purpose : +//======================================================================= +void V3d_View::ResetViewMapping() +{ + Camera()->CopyMappingData (myDefaultCamera); + + AutoZFit(); ImmediateUpdate(); } @@ -1264,21 +1357,18 @@ void V3d_View::ResetViewOrientation() //function : Reset //purpose : //============================================================================= -void V3d_View::Reset( const Standard_Boolean update ) +void V3d_View::Reset (const Standard_Boolean theToUpdate) { - Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); - - if (!aDefaultCamera.IsNull()) - { - myCamera->CopyMappingData (aDefaultCamera); - myCamera->CopyOrientationData (aDefaultCamera); + Camera()->Copy (myDefaultCamera); - View()->AutoZFit(); - } + AutoZFit(); SwitchSetFront = Standard_False; - if( myImmediateUpdate || update ) Update(); + if (myImmediateUpdate || theToUpdate) + { + Update(); + } } //======================================================================= @@ -1290,7 +1380,7 @@ void V3d_View::SetCenter (const Standard_Integer theXp, { Standard_Real aXv, aYv; Convert (theXp, theYp, aXv, aYv); - Translate (myCamera, aXv, aYv); + Translate (Camera(), aXv, aYv); ImmediateUpdate(); } @@ -1303,9 +1393,11 @@ void V3d_View::SetSize (const Standard_Real theSize) { V3d_BadValue_Raise_if (theSize <= 0.0, "V3d_View::SetSize, Window Size is NULL"); - myCamera->SetScale (myCamera->Aspect() >= 1.0 ? theSize / myCamera->Aspect() : theSize); + Handle(Graphic3d_Camera) aCamera = Camera(); + + aCamera->SetScale (aCamera->Aspect() >= 1.0 ? theSize / aCamera->Aspect() : theSize); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1314,19 +1406,19 @@ void V3d_View::SetSize (const Standard_Real theSize) //function : SetZSize //purpose : //============================================================================= -void V3d_View::SetZSize(const Standard_Real Size) +void V3d_View::SetZSize (const Standard_Real theSize) { - Standard_Real Zmax = Size/2.; + Handle(Graphic3d_Camera) aCamera = Camera(); - Standard_Real aDistance = myCamera->Distance(); + Standard_Real Zmax = theSize / 2.; - if( Size <= 0. ) { + Standard_Real aDistance = aCamera->Distance(); + + if (theSize <= 0.) + { Zmax = aDistance; } - Standard_Real Front = MyViewContext.ZClippingFrontPlane(); - Standard_Real Back = MyViewContext.ZClippingBackPlane(); - // ShortReal precision factor used to add meaningful tolerance to // ZNear, ZFar values in order to avoid equality after type conversion // to ShortReal matrices type. @@ -1337,7 +1429,7 @@ void V3d_View::SetZSize(const Standard_Real Size) aZNear -= Abs (aZNear) * aPrecision; aZFar += Abs (aZFar) * aPrecision; - if (!myCamera->IsOrthographic()) + if (!aCamera->IsOrthographic()) { if (aZFar < aPrecision) { @@ -1358,14 +1450,11 @@ void V3d_View::SetZSize(const Standard_Real Size) aZFar = aZNear + Abs (aZFar) * aPrecision; } - myCamera->SetZRange (aZNear, aZFar); + aCamera->SetZRange (aZNear, aZFar); - if (MyViewContext.FrontZClippingIsOn() || - MyViewContext.BackZClippingIsOn()) + if (myImmediateUpdate) { - MyViewContext.SetZClippingFrontPlane (Front); - MyViewContext.SetZClippingBackPlane (Back); - MyView->SetContext (MyViewContext); + Redraw(); } } @@ -1377,14 +1466,16 @@ void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start) { V3d_BadValue_Raise_if( Coef <= 0.,"V3d_View::SetZoom, bad coefficient"); + Handle(Graphic3d_Camera) aCamera = Camera(); + if (Start) { - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } - Standard_Real aViewWidth = myCamera->ViewDimensions().X(); - Standard_Real aViewHeight = myCamera->ViewDimensions().Y(); + Standard_Real aViewWidth = aCamera->ViewDimensions().X(); + Standard_Real aViewHeight = aCamera->ViewDimensions().Y(); // ensure that zoom will not be too small or too big Standard_Real coef = Coef; @@ -1405,10 +1496,11 @@ void V3d_View::SetZoom(const Standard_Real Coef,const Standard_Boolean Start) coef = aViewHeight / 1e12; } - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); - myCamera->SetScale (myCamera->Scale() / Coef); - View()->AutoZFit(); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); + aCamera->SetScale (aCamera->Scale() / Coef); + + AutoZFit(); ImmediateUpdate(); } @@ -1421,21 +1513,13 @@ void V3d_View::SetScale( const Standard_Real Coef ) { V3d_BadValue_Raise_if( Coef <= 0. ,"V3d_View::SetScale, bad coefficient"); - Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); + Handle(Graphic3d_Camera) aCamera = Camera(); - // Strange behavior for the sake of compatibility. - if (!aDefaultCamera.IsNull()) - { - myCamera->SetAspect (aDefaultCamera->Aspect()); - Standard_Real aDefaultScale = aDefaultCamera->Scale(); - myCamera->SetScale (aDefaultScale / Coef); - } - else - { - myCamera->SetScale (myCamera->Scale() / Coef); - } + Standard_Real aDefaultScale = myDefaultCamera->Scale(); + aCamera->SetAspect (myDefaultCamera->Aspect()); + aCamera->SetScale (aDefaultScale / Coef); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } @@ -1448,8 +1532,33 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co { V3d_BadValue_Raise_if( Sx <= 0. || Sy <= 0. || Sz <= 0.,"V3d_View::SetAxialScale, bad coefficient"); - myCamera->SetAxialScale (gp_XYZ (Sx, Sy, Sz)); - View()->AutoZFit(); + Camera()->SetAxialScale (gp_XYZ (Sx, Sy, Sz)); + + AutoZFit(); +} + +//============================================================================= +//function : SetRatio +//purpose : +//============================================================================= +void V3d_View::SetRatio() +{ + if (MyWindow.IsNull()) + { + return; + } + + Standard_Integer aWidth = 0; + Standard_Integer aHeight = 0; + MyWindow->Size (aWidth, aHeight); + if (aWidth > 0 && aHeight > 0) + { + Standard_Real aRatio = static_cast (aWidth) / + static_cast (aHeight); + + Camera() ->SetAspect (aRatio); + myDefaultCamera->SetAspect (aRatio); + } } //============================================================================= @@ -1458,7 +1567,7 @@ void V3d_View::SetAxialScale( const Standard_Real Sx, const Standard_Real Sy, co //============================================================================= void V3d_View::FitAll (const Quantity_Coefficient theMargin, const Standard_Boolean theToUpdate) { - FitAll (MyView->MinMaxValues(), theMargin, theToUpdate); + FitAll (myView->MinMaxValues(), theMargin, theToUpdate); } //============================================================================= @@ -1469,17 +1578,17 @@ void V3d_View::FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMarg { Standard_ASSERT_RAISE(theMargin >= 0.0 && theMargin < 1.0, "Invalid margin coefficient"); - if (MyView->NumberOfDisplayedStructures() == 0) + if (myView->NumberOfDisplayedStructures() == 0) { return; } - if (!FitMinMax (myCamera, theBox, theMargin, 10.0 * Precision::Confusion())) + if (!FitMinMax (Camera(), theBox, theMargin, 10.0 * Precision::Confusion())) { return; } - View()->AutoZFit(); + AutoZFit(); if (myImmediateUpdate || theToUpdate) { @@ -1498,46 +1607,46 @@ void V3d_View::DepthFitAll(const Quantity_Coefficient Aspect, Standard_Real Umin,Vmin,Wmin,Umax,Vmax,Wmax ; Standard_Real Dx,Dy,Dz,Size; - Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; + Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ; if((Nstruct <= 0) || (Aspect < 0.) || (Margin < 0.) || (Margin > 1.)) { ImmediateUpdate(); return ; } - Bnd_Box aBox = MyView->MinMaxValues(); + Bnd_Box aBox = myView->MinMaxValues(); if (aBox.IsVoid()) { ImmediateUpdate(); return ; } aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); - MyView->Projects(Xmin,Ymin,Zmin,U,V,W) ; - MyView->Projects(Xmax,Ymax,Zmax,U1,V1,W1) ; + Project (Xmin,Ymin,Zmin,U,V,W) ; + Project (Xmax,Ymax,Zmax,U1,V1,W1) ; Umin = Min(U,U1) ; Umax = Max(U,U1) ; Vmin = Min(V,V1) ; Vmax = Max(V,V1) ; Wmin = Min(W,W1) ; Wmax = Max(W,W1) ; - MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; + Project (Xmin,Ymin,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; + Project (Xmax,Ymin,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; + Project (Xmax,Ymin,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; + Project (Xmax,Ymax,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; + Project (Xmin,Ymax,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; + Project (Xmin,Ymax,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; @@ -1593,14 +1702,16 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp, { Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); - if (!myCamera->IsOrthographic()) + Handle(Graphic3d_Camera) aCamera = Camera(); + + if (!aCamera->IsOrthographic()) { // normalize view coordinates Standard_Integer aWinWidth, aWinHeight; MyWindow->Size (aWinWidth, aWinHeight); // z coordinate of camera center - Standard_Real aDepth = myCamera->Project (myCamera->Center()).Z(); + Standard_Real aDepth = aCamera->Project (aCamera->Center()).Z(); // camera projection coordinate are in NDC which are normalized [-1, 1] Standard_Real aUMin = (2.0 / aWinWidth) * theMinXp - 1.0; @@ -1611,22 +1722,22 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp, // compute camera panning gp_Pnt aScreenCenter (0.0, 0.0, aDepth); gp_Pnt aFitCenter ((aUMin + aUMax) * 0.5, (aVMin + aVMax) * 0.5, aDepth); - gp_Pnt aPanTo = myCamera->ConvertProj2View (aFitCenter); - gp_Pnt aPanFrom = myCamera->ConvertProj2View (aScreenCenter); + gp_Pnt aPanTo = aCamera->ConvertProj2View (aFitCenter); + gp_Pnt aPanFrom = aCamera->ConvertProj2View (aScreenCenter); gp_Vec aPanVec (aPanFrom, aPanTo); // compute section size gp_Pnt aFitTopRight (aUMax, aVMax, aDepth); gp_Pnt aFitBotLeft (aUMin, aVMin, aDepth); - gp_Pnt aViewBotLeft = myCamera->ConvertProj2View (aFitBotLeft); - gp_Pnt aViewTopRight = myCamera->ConvertProj2View (aFitTopRight); + gp_Pnt aViewBotLeft = aCamera->ConvertProj2View (aFitBotLeft); + gp_Pnt aViewTopRight = aCamera->ConvertProj2View (aFitTopRight); Standard_Real aUSize = aViewTopRight.X() - aViewBotLeft.X(); Standard_Real aVSize = aViewTopRight.Y() - aViewBotLeft.Y(); - Translate (myCamera, aPanVec.X(), -aPanVec.Y()); - Scale (myCamera, aUSize, aVSize); - View()->AutoZFit(); + Translate (aCamera, aPanVec.X(), -aPanVec.Y()); + Scale (aCamera, aUSize, aVSize); + AutoZFit(); } else { @@ -1641,28 +1752,6 @@ void V3d_View::WindowFit (const Standard_Integer theMinXp, ImmediateUpdate(); } -//======================================================================= -//function : SetViewMappingDefault -//purpose : -//======================================================================= -void V3d_View::SetViewMappingDefault() -{ - MyView->SetViewMappingDefault(); - - ImmediateUpdate(); -} - -//======================================================================= -//function : ResetViewMapping -//purpose : -//======================================================================= -void V3d_View::ResetViewMapping() -{ - MyView->ViewMappingReset(); - - Update(); -} - //======================================================================= //function : ConvertToGrid //purpose : @@ -1713,12 +1802,12 @@ Standard_Real V3d_View::Convert(const Standard_Integer Vp) const { Standard_Integer aDxw, aDyw ; - V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); MyWindow->Size (aDxw, aDyw); Standard_Real aValue; - gp_Pnt aViewDims = myCamera->ViewDimensions(); + gp_Pnt aViewDims = Camera()->ViewDimensions(); aValue = aViewDims.X() * (Standard_Real)Vp / (Standard_Real)aDxw; return aValue; @@ -1735,12 +1824,12 @@ void V3d_View::Convert(const Standard_Integer Xp, { Standard_Integer aDxw, aDyw; - V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); MyWindow->Size (aDxw, aDyw); gp_Pnt aPoint (Xp * 2.0 / aDxw - 1.0, (aDyw - Yp) * 2.0 / aDyw - 1.0, 0.0); - aPoint = myCamera->ConvertProj2View (aPoint); + aPoint = Camera()->ConvertProj2View (aPoint); Xv = aPoint.X(); Yv = aPoint.Y(); @@ -1752,12 +1841,12 @@ void V3d_View::Convert(const Standard_Integer Xp, //======================================================================= Standard_Integer V3d_View::Convert(const Standard_Real Vv) const { - V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); Standard_Integer aDxw, aDyw; MyWindow->Size (aDxw, aDyw); - gp_Pnt aViewDims = myCamera->ViewDimensions(); + gp_Pnt aViewDims = Camera()->ViewDimensions(); Standard_Integer aValue = RealToInt (aDxw * Vv / (aViewDims.X())); return aValue; @@ -1772,13 +1861,13 @@ void V3d_View::Convert(const Standard_Real Xv, Standard_Integer& Xp, Standard_Integer& Yp) const { - V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); Standard_Integer aDxw, aDyw; MyWindow->Size (aDxw, aDyw); gp_Pnt aPoint (Xv, Yv, 0.0); - aPoint = myCamera->ConvertView2Proj (aPoint); + aPoint = Camera()->ConvertView2Proj (aPoint); aPoint = gp_Pnt ((aPoint.X() + 1.0) * aDxw / 2.0, aDyw - (aPoint.Y() + 1.0) * aDyw / 2.0, 0.0); Xp = RealToInt (aPoint.X()); @@ -1795,7 +1884,7 @@ void V3d_View::Convert(const Standard_Integer Xp, Standard_Real& Y, Standard_Real& Z) const { - V3d_UnMapped_Raise_if (!MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); Standard_Integer aHeight, aWidth; MyWindow->Size (aWidth, aHeight); @@ -1803,7 +1892,7 @@ void V3d_View::Convert(const Standard_Integer Xp, Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0; Standard_Real aZ = 2.0 * 0.0 - 1.0; - gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ)); + gp_Pnt aResult = Camera()->UnProject (gp_Pnt (anX, anY, aZ)); X = aResult.X(); Y = aResult.Y(); @@ -1823,7 +1912,7 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp, Standard_Real& Dy, Standard_Real& Dz) const { - V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); Standard_Integer aHeight, aWidth; MyWindow->Size (aWidth, aHeight); @@ -1831,7 +1920,9 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp, Standard_Real anY = 2.0 * (aHeight - 1 - Yp) / aHeight - 1.0; Standard_Real aZ = 2.0 * 0.0 - 1.0; - gp_Pnt aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ)); + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_Pnt aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ)); X = aResult.X(); Y = aResult.Y(); @@ -1840,7 +1931,7 @@ void V3d_View::ConvertWithProj(const Standard_Integer Xp, Graphic3d_Vertex aVrp; aVrp.SetCoord (X, Y, Z); - aResult = myCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0)); + aResult = aCamera->UnProject (gp_Pnt (anX, anY, aZ - 10.0)); Graphic3d_Vec3d aNormDir; aNormDir.x() = X - aResult.X(); @@ -1863,11 +1954,11 @@ void V3d_View::Convert(const Standard_Real X, Standard_Integer& Xp, Standard_Integer& Yp) const { - V3d_UnMapped_Raise_if( !MyView->IsDefined(), "view has no window"); + V3d_UnMapped_Raise_if (!myView->IsDefined(), "view has no window"); Standard_Integer aHeight, aWidth; MyWindow->Size (aWidth, aHeight); - gp_Pnt aPoint = myCamera->Project (gp_Pnt (X, Y, Z)); + gp_Pnt aPoint = Camera()->Project (gp_Pnt (X, Y, Z)); Xp = RealToInt ((aPoint.X() + 1) * 0.5 * aWidth); Yp = RealToInt (aHeight - 1 - (aPoint.Y() + 1) * 0.5 * aHeight); @@ -1877,14 +1968,40 @@ void V3d_View::Convert(const Standard_Real X, //function : Project //purpose : //======================================================================= -void V3d_View::Project(const Standard_Real X, - const Standard_Real Y, - const Standard_Real Z, - Standard_Real &Xp, - Standard_Real &Yp) const +void V3d_View::Project (const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + Standard_Real& theXp, + Standard_Real& theYp) const { - Standard_Real Zp; - MyView->Projects (X, Y, Z, Xp, Yp, Zp); + Standard_Real aZp; + Project (theX, theY, theZ, theXp, theYp, aZp); +} + +//======================================================================= +//function : Project +//purpose : +//======================================================================= +void V3d_View::Project (const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + Standard_Real& theXp, + Standard_Real& theYp, + Standard_Real& theZp) const +{ + Handle(Graphic3d_Camera) aCamera = Camera(); + + gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions(); + Standard_Real aXSize = aViewSpaceDimensions.X(); + Standard_Real aYSize = aViewSpaceDimensions.Y(); + Standard_Real aZSize = aViewSpaceDimensions.Z(); + + gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ)); + + // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ] + theXp = aPoint.X() * aXSize * 0.5; + theYp = aPoint.Y() * aYSize * 0.5; + theZp = aPoint.Z() * aZSize * 0.5; } //======================================================================= @@ -1906,16 +2023,16 @@ void V3d_View::BackgroundColor(const Quantity_TypeOfColor Type, //======================================================================= Quantity_Color V3d_View::BackgroundColor() const { - return MyBackground.Color() ; + return myView->Background().Color() ; } //======================================================================= //function : GradientBackgroundColors //purpose : //======================================================================= -void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& Color2) const +void V3d_View::GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const { - MyGradientBackground.Colors(Color1, Color2); + myView->GradientBackground().Colors (theColor1, theColor2); } //======================================================================= @@ -1924,7 +2041,7 @@ void V3d_View::GradientBackgroundColors(Quantity_Color& Color1,Quantity_Color& C //======================================================================= Aspect_GradientBackground V3d_View::GradientBackground() const { - return MyGradientBackground; + return myView->GradientBackground(); } //======================================================================= @@ -1933,22 +2050,7 @@ Aspect_GradientBackground V3d_View::GradientBackground() const //======================================================================= Standard_Real V3d_View::Scale() const { - Handle(Graphic3d_Camera) aDefaultCamera = MyView->DefaultCamera(); - - Standard_Real aCameraScale; - - // Strange behavior for the sake of compatibility. - if (!aDefaultCamera.IsNull()) - { - Standard_Real aDefaultScale = aDefaultCamera->Scale(); - aCameraScale = aDefaultScale / myCamera->Scale(); - } - else - { - aCameraScale = myCamera->Scale(); - } - - return aCameraScale; + return myDefaultCamera->Scale() / Camera()->Scale(); } //======================================================================= @@ -1957,7 +2059,7 @@ Standard_Real V3d_View::Scale() const //======================================================================= void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const { - gp_Pnt anAxialScale = myCamera->AxialScale(); + gp_Pnt anAxialScale = Camera()->AxialScale(); Sx = anAxialScale.X(); Sy = anAxialScale.Y(); Sz = anAxialScale.Z(); @@ -1969,7 +2071,7 @@ void V3d_View::AxialScale(Standard_Real& Sx, Standard_Real& Sy, Standard_Real& S //======================================================================= void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const { - gp_Pnt aViewDims = myCamera->ViewDimensions(); + gp_Pnt aViewDims = Camera()->ViewDimensions(); Width = aViewDims.X(); Height = aViewDims.Y(); @@ -1981,7 +2083,7 @@ void V3d_View::Size(Standard_Real& Width, Standard_Real& Height) const //======================================================================= Standard_Real V3d_View::ZSize() const { - gp_Pnt aViewDims = myCamera->ViewDimensions(); + gp_Pnt aViewDims = Camera()->ViewDimensions(); return aViewDims.Z(); } @@ -1998,34 +2100,34 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Umin, Standard_Real Wmin,Wmax,U,V,W ; Standard_Real Xmin,Ymin,Zmin,Xmax,Ymax,Zmax ; // CAL 6/11/98 - Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; + Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ; if( Nstruct ) { - Bnd_Box aBox = MyView->MinMaxValues(); + Bnd_Box aBox = myView->MinMaxValues(); aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); - MyView->Projects(Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; - MyView->Projects(Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; - MyView->Projects(Xmin,Ymin,Zmax,U,V,W) ; + Project (Xmin,Ymin,Zmin,Umin,Vmin,Wmin) ; + Project (Xmax,Ymax,Zmax,Umax,Vmax,Wmax) ; + Project (Xmin,Ymin,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymin,Zmax,U,V,W) ; + Project (Xmax,Ymin,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymin,Zmin,U,V,W) ; + Project (Xmax,Ymin,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmax,Ymax,Zmin,U,V,W) ; + Project (Xmax,Ymax,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmin,Ymax,Zmax,U,V,W) ; + Project (Xmin,Ymax,Zmax,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; - MyView->Projects(Xmin,Ymax,Zmin,U,V,W) ; + Project (Xmin,Ymax,Zmin,U,V,W) ; Umin = Min(U,Umin) ; Umax = Max(U,Umax) ; Vmin = Min(V,Vmin) ; Vmax = Max(V,Vmax) ; Wmin = Min(W,Wmin) ; Wmax = Max(W,Wmax) ; @@ -2046,10 +2148,10 @@ Standard_Integer V3d_View::MinMax(Standard_Real& Xmin, { // CAL 6/11/98 // Standard_Integer Nstruct = (MyView->DisplayedStructures())->Extent() ; - Standard_Integer Nstruct = MyView->NumberOfDisplayedStructures() ; + Standard_Integer Nstruct = myView->NumberOfDisplayedStructures() ; if( Nstruct ) { - Bnd_Box aBox = MyView->MinMaxValues(); + Bnd_Box aBox = myView->MinMaxValues(); aBox.Get (Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); } return Nstruct ; @@ -2064,7 +2166,7 @@ void V3d_View::Gravity (Standard_Real& theX, Standard_Real& theZ) const { Graphic3d_MapOfStructure aSetOfStructures; - MyView->DisplayedStructures (aSetOfStructures); + myView->DisplayedStructures (aSetOfStructures); Standard_Boolean hasSelection = Standard_False; for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aSetOfStructures); @@ -2112,7 +2214,7 @@ void V3d_View::Gravity (Standard_Real& theX, for (Standard_Integer aPntIt = 0; aPntIt < THE_NB_BOUND_POINTS; ++aPntIt) { const gp_Pnt& aBndPnt = aPnts[aPntIt]; - const gp_Pnt aProjected = myCamera->Project (aBndPnt); + const gp_Pnt aProjected = Camera()->Project (aBndPnt); if (Abs (aProjected.X()) <= 1.0 && Abs (aProjected.Y()) <= 1.0) { @@ -2173,7 +2275,7 @@ void V3d_View::Gravity (Standard_Real& theX, //======================================================================= void V3d_View::Eye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const { - gp_Pnt aCameraEye = myCamera->Eye(); + gp_Pnt aCameraEye = Camera()->Eye(); X = aCameraEye.X(); Y = aCameraEye.Y(); Z = aCameraEye.Z(); @@ -2223,7 +2325,7 @@ void V3d_View::ProjReferenceAxe(const Standard_Integer Xpix, //============================================================================= Standard_Real V3d_View::Depth() const { - return myCamera->Distance(); + return Camera()->Distance(); } //============================================================================= @@ -2232,7 +2334,7 @@ Standard_Real V3d_View::Depth() const //============================================================================= void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) const { - gp_Dir aCameraDir = myCamera->Direction().Reversed(); + gp_Dir aCameraDir = Camera()->Direction().Reversed(); Dx = aCameraDir.X(); Dy = aCameraDir.Y(); Dz = aCameraDir.Z(); @@ -2244,7 +2346,7 @@ void V3d_View::Proj(Standard_Real& Dx, Standard_Real& Dy, Standard_Real& Dz) con //============================================================================= void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const { - gp_Pnt aCameraCenter = myCamera->Center(); + gp_Pnt aCameraCenter = Camera()->Center(); X = aCameraCenter.X(); Y = aCameraCenter.Y(); Z = aCameraCenter.Z(); @@ -2256,7 +2358,7 @@ void V3d_View::At(Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const //============================================================================= void V3d_View::Up(Standard_Real& Vx, Standard_Real& Vy, Standard_Real& Vz) const { - gp_Dir aCameraUp = myCamera->Up(); + gp_Dir aCameraUp = Camera()->Up(); Vx = aCameraUp.X(); Vy = aCameraUp.Y(); Vz = aCameraUp.Z(); @@ -2273,7 +2375,7 @@ Standard_Real V3d_View::Twist() const Graphic3d_Vector Xaxis,Yaxis,Zaxis ; Standard_Boolean TheStatus ; - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); + gp_Dir aReferencePlane (Camera()->Direction().Reversed()); gp_Dir anUp; Proj(Xpn,Ypn,Zpn); @@ -2315,8 +2417,7 @@ Standard_Real V3d_View::Twist() const //============================================================================= V3d_TypeOfShadingModel V3d_View::ShadingModel() const { - V3d_TypeOfShadingModel SM = (V3d_TypeOfShadingModel)MyViewContext.Model() ; - return SM ; + return static_cast (myView->ShadingModel()); } //============================================================================= @@ -2325,8 +2426,7 @@ V3d_TypeOfShadingModel V3d_View::ShadingModel() const //============================================================================= V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const { - V3d_TypeOfSurfaceDetail SM = (V3d_TypeOfSurfaceDetail)MyViewContext.SurfaceDetail() ; - return SM ; + return static_cast (myView->SurfaceDetailType()); } //============================================================================= @@ -2335,8 +2435,7 @@ V3d_TypeOfSurfaceDetail V3d_View::SurfaceDetail() const //============================================================================= Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const { - Handle(Graphic3d_TextureEnv) SM = MyViewContext.TextureEnv() ; - return SM ; + return myView->TextureEnv(); } //============================================================================= @@ -2345,9 +2444,7 @@ Handle(Graphic3d_TextureEnv) V3d_View::TextureEnv() const //============================================================================= V3d_TypeOfVisualization V3d_View::Visualization() const { - V3d_TypeOfVisualization V = - (V3d_TypeOfVisualization)MyViewContext.Visualization() ; - return V ; + return static_cast (myView->VisualizationType()); } //============================================================================= @@ -2356,8 +2453,7 @@ V3d_TypeOfVisualization V3d_View::Visualization() const //============================================================================= Standard_Boolean V3d_View::Antialiasing() const { - Standard_Boolean A = MyViewContext.AliasingIsOn() ; - return A ; + return myView->IsAntialiasingEnabled(); } //============================================================================= @@ -2366,7 +2462,7 @@ Standard_Boolean V3d_View::Antialiasing() const //============================================================================= Handle(V3d_Viewer) V3d_View::Viewer() const { - return MyViewer ; + return MyViewer; } //============================================================================= @@ -2375,8 +2471,7 @@ Handle(V3d_Viewer) V3d_View::Viewer() const //============================================================================= Standard_Boolean V3d_View::IfWindow() const { - Standard_Boolean TheStatus = MyView->IsDefined() ; - return TheStatus ; + return myView->IsDefined(); } //============================================================================= @@ -2394,7 +2489,7 @@ Handle(Aspect_Window) V3d_View::Window() const //============================================================================= V3d_TypeOfView V3d_View::Type() const { - return myCamera->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE; + return Camera()->IsOrthographic() ? V3d_ORTHOGRAPHIC : V3d_PERSPECTIVE; } //============================================================================= @@ -2403,14 +2498,16 @@ V3d_TypeOfView V3d_View::Type() const //============================================================================= void V3d_View::SetFocale( const Standard_Real focale ) { - if (myCamera->IsOrthographic()) + Handle(Graphic3d_Camera) aCamera = Camera(); + + if (aCamera->IsOrthographic()) { return; } - Standard_Real aFOVyRad = ATan (focale / (myCamera->Distance() * 2.0)); + Standard_Real aFOVyRad = ATan (focale / (aCamera->Distance() * 2.0)); - myCamera->SetFOVy (aFOVyRad * (360 / M_PI)); + aCamera->SetFOVy (aFOVyRad * (360 / M_PI)); ImmediateUpdate(); } @@ -2421,21 +2518,23 @@ void V3d_View::SetFocale( const Standard_Real focale ) //============================================================================= Standard_Real V3d_View::Focale() const { - if (myCamera->IsOrthographic()) + Handle(Graphic3d_Camera) aCamera = Camera(); + + if (aCamera->IsOrthographic()) { return 0.0; } - return myCamera->Distance() * 2.0 * Tan(myCamera->FOVy() * M_PI / 360.0); + return aCamera->Distance() * 2.0 * Tan (aCamera->FOVy() * M_PI / 360.0); } //============================================================================= //function : View //purpose : //============================================================================= -Handle(Visual3d_View) V3d_View::View() const +Handle(Graphic3d_CView) V3d_View::View() const { - return MyView ; + return myView; } //============================================================================= @@ -2524,20 +2623,22 @@ void V3d_View::Panning (const Standard_Real theDXv, { Standard_ASSERT_RAISE (theZoomFactor > 0.0, "Bad zoom factor"); + Handle(Graphic3d_Camera) aCamera = Camera(); + if (theToStart) { - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); } Standard_Boolean wasUpdateEnabled = SetImmediateUpdate (Standard_False); - gp_Pnt aViewDims = myCamera->ViewDimensions(); + gp_Pnt aViewDims = aCamera->ViewDimensions(); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); - Translate (myCamera, -theDXv, -theDYv); - Scale (myCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); + Translate (aCamera, -theDXv, -theDYv); + Scale (aCamera, aViewDims.X() / theZoomFactor, aViewDims.Y() / theZoomFactor); SetImmediateUpdate (wasUpdateEnabled); @@ -2592,8 +2693,10 @@ void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX, V3d_BadValue_Raise_if (aDZoom <= 0.0, "V3d_View::ZoomAtPoint, bad coefficient"); - Standard_Real aViewWidth = myCamera->ViewDimensions().X(); - Standard_Real aViewHeight = myCamera->ViewDimensions().Y(); + Handle(Graphic3d_Camera) aCamera = Camera(); + + Standard_Real aViewWidth = aCamera->ViewDimensions().X(); + Standard_Real aViewHeight = aCamera->ViewDimensions().Y(); // ensure that zoom will not be too small or too big. Standard_Real aCoef = aDZoom; @@ -2621,10 +2724,10 @@ void V3d_View::ZoomAtPoint (const Standard_Integer theMouseStartX, V3d_Coordinate aDxv = aZoomAtPointXv / aCoef; V3d_Coordinate aDyv = aZoomAtPointYv / aCoef; - myCamera->SetScale (myCamera->Scale() / aCoef); - Translate (myCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv); + aCamera->SetScale (aCamera->Scale() / aCoef); + Translate (aCamera, aZoomAtPointXv - aDxv, aZoomAtPointYv - aDyv); - View()->AutoZFit(); + AutoZFit(); SetImmediateUpdate (wasUpdateEnabled); @@ -2677,10 +2780,13 @@ void V3d_View::FitAll(const Handle(Aspect_Window)& aWindow, aFitSizeU = aFitSizeV * aWinAspect; } - myCamera->SetAspect (aWinAspect); - Translate (myCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5); - Scale (myCamera, aFitSizeU, aFitSizeV); - View()->AutoZFit(); + Handle(Graphic3d_Camera) aCamera = Camera(); + + aCamera->SetAspect (aWinAspect); + Translate (aCamera, (Xmin + Xmax) * 0.5, (Ymin + Ymax) * 0.5); + Scale (aCamera, aFitSizeU, aFitSizeV); + + AutoZFit(); ImmediateUpdate(); } @@ -2739,19 +2845,19 @@ void V3d_View::Rotation(const Standard_Integer X, //function : SetComputedMode //purpose : //============================================================================= -void V3d_View::SetComputedMode (const Standard_Boolean aMode) +void V3d_View::SetComputedMode (const Standard_Boolean theMode) { - if (aMode) + if (theMode) { if (myComputedMode) { - MyView->SetComputedMode (Standard_True); + myView->SetComputedMode (Standard_True); Update(); } - } - else + } + else { - MyView->SetComputedMode (Standard_False); + myView->SetComputedMode (Standard_False); Update(); } } @@ -2762,16 +2868,16 @@ void V3d_View::SetComputedMode (const Standard_Boolean aMode) //============================================================================= Standard_Boolean V3d_View::ComputedMode() const { - return MyView->ComputedMode(); + return myView->ComputedMode(); } //============================================================================= //function : SetBackFacingModel //purpose : //============================================================================= -void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel) +void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel theModel) { - MyView->SetBackFacingModel (Visual3d_TypeOfBackfacingModel(aModel)); + myView->SetBackfacingModel (static_cast (theModel)); Redraw(); } @@ -2781,17 +2887,33 @@ void V3d_View::SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel) //============================================================================= V3d_TypeOfBackfacingModel V3d_View::BackFacingModel() const { - return V3d_TypeOfBackfacingModel(MyView -> BackFacingModel ()); + return static_cast (myView->BackfacingModel()); } +//============================================================================= +//function : Init +//purpose : +//============================================================================= void V3d_View::Init() { myComputedMode = MyViewer->ComputedMode(); - if( !myComputedMode || !MyViewer->DefaultComputedMode() ) { - SetComputedMode(Standard_False); + if (!myComputedMode || !MyViewer->DefaultComputedMode()) + { + SetComputedMode (Standard_False); } } +//============================================================================= +//function : Export +//purpose : +//============================================================================= +Standard_Boolean V3d_View::Export (const Standard_CString theFileName, + const Graphic3d_ExportFormat theFormat, + const Graphic3d_SortType theSortType) +{ + return myView->Export (theFileName, theFormat, theSortType); +} + //============================================================================= //function : Dump //purpose : @@ -2817,21 +2939,19 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, const Standard_Boolean theToKeepAspect, const V3d_StereoDumpOptions theStereoOptions) { - Graphic3d_CView* cView = (Graphic3d_CView* )MyView->CView(); - // always prefer hardware accelerated offscreen buffer Graphic3d_PtrFrameBuffer aFBOPtr = NULL; - Graphic3d_PtrFrameBuffer aPrevFBOPtr = (Graphic3d_PtrFrameBuffer )cView->ptrFBO; + Graphic3d_PtrFrameBuffer aPrevFBOPtr = myView->FBO(); Standard_Integer aFBOVPSizeX (theWidth), aFBOVPSizeY (theHeight), aFBOSizeXMax (0), aFBOSizeYMax (0); Standard_Integer aPrevFBOVPSizeX (0), aPrevFBOVPSizeY (0), aPrevFBOSizeXMax (0), aPrevFBOSizeYMax (0); if (aPrevFBOPtr != NULL) { - MyView->FBOGetDimensions (aPrevFBOPtr, + myView->FBOGetDimensions (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY, aPrevFBOSizeXMax, aPrevFBOSizeYMax); if (aFBOVPSizeX <= aPrevFBOSizeXMax && aFBOVPSizeY <= aPrevFBOSizeYMax) { - MyView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY); + myView->FBOChangeViewport (aPrevFBOPtr, aFBOVPSizeX, aFBOVPSizeY); aFBOPtr = aPrevFBOPtr; } } @@ -2839,19 +2959,19 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, if (aFBOPtr == NULL) { // Try to create hardware accelerated buffer - aFBOPtr = MyView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY); + aFBOPtr = myView->FBOCreate (aFBOVPSizeX, aFBOVPSizeY); if (aFBOPtr != NULL) { - MyView->FBOGetDimensions (aFBOPtr, + myView->FBOGetDimensions (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY, aFBOSizeXMax, aFBOSizeYMax); // reduce viewport in case of hardware limits if (aFBOVPSizeX > aFBOSizeXMax) aFBOVPSizeX = aFBOSizeXMax; if (aFBOVPSizeY > aFBOSizeYMax) aFBOVPSizeY = aFBOSizeYMax; - MyView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY); + myView->FBOChangeViewport (aFBOPtr, aFBOVPSizeX, aFBOVPSizeY); } } - cView->ptrFBO = aFBOPtr; + myView->SetFBO (aFBOPtr); // If hardware accelerated buffer - try to use onscreen buffer // Results may be bad! @@ -2871,25 +2991,27 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, Handle(Graphic3d_Camera) aStoreMapping = new Graphic3d_Camera(); - aStoreMapping->Copy (myCamera); + Handle(Graphic3d_Camera) aCamera = Camera(); + + aStoreMapping->Copy (aCamera); - if (myCamera->IsStereo()) + if (aCamera->IsStereo()) { switch (theStereoOptions) { case V3d_SDO_MONO: { - myCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); + aCamera->SetProjectionType (Graphic3d_Camera::Projection_Perspective); break; } case V3d_SDO_LEFT_EYE: { - myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); + aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoLeftEye); break; } case V3d_SDO_RIGHT_EYE: { - myCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); + aCamera->SetProjectionType (Graphic3d_Camera::Projection_MonoRightEye); break; } case V3d_SDO_BLENDED: @@ -2900,27 +3022,23 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, } // render immediate structures into back buffer rather than front - Handle(Graphic3d_GraphicDriver) aDriver = Handle(Graphic3d_GraphicDriver)::DownCast (MyView->GraphicDriver()); - const Standard_Boolean aPrevImmediateMode = aDriver.IsNull() ? Standard_True : aDriver->SetImmediateModeDrawToFront (*cView, Standard_False); + const Standard_Boolean aPrevImmediateMode = myView->SetImmediateModeDrawToFront (Standard_False); const Standard_Boolean toAutoUpdate = myImmediateUpdate; myImmediateUpdate = Standard_False; - View()->AutoZFit(); + AutoZFit(); myImmediateUpdate = toAutoUpdate; if (theToKeepAspect) { - myCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY); + aCamera->SetAspect ((Standard_Real) aFBOVPSizeX / aFBOVPSizeY); } Redraw(); - if (!aDriver.IsNull()) - { - aDriver->SetImmediateModeDrawToFront (*cView, aPrevImmediateMode); - } + myView->SetImmediateModeDrawToFront (aPrevImmediateMode); - myCamera->Copy (aStoreMapping); + aCamera->Copy (aStoreMapping); Standard_Boolean isSuccess = Standard_True; @@ -2940,26 +3058,38 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap& theImage, isSuccess = isSuccess && theImage.InitZero (aFormat, aFBOVPSizeX, aFBOVPSizeY); } - isSuccess = isSuccess && MyView->BufferDump (theImage, theBufferType); + isSuccess = isSuccess && myView->BufferDump (theImage, theBufferType); // FBO now useless, free resources if (aFBOPtr != aPrevFBOPtr) { - MyView->FBORelease (aFBOPtr); + myView->FBORelease (aFBOPtr); } else if (aPrevFBOPtr != NULL) { - MyView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY); + myView->FBOChangeViewport (aPrevFBOPtr, aPrevFBOVPSizeX, aPrevFBOVPSizeY); } - cView->ptrFBO = aPrevFBOPtr; + myView->SetFBO (aPrevFBOPtr); + return isSuccess; } +//============================================================================= +//function : ImmediateUpdate +//purpose : +//============================================================================= void V3d_View::ImmediateUpdate() const { - if (myImmediateUpdate) Update(); + if (myImmediateUpdate) + { + Update(); + } } +//============================================================================= +//function : SetImmediateUpdate +//purpose : +//============================================================================= Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmediateUpdate) { Standard_Boolean aPreviousMode = myImmediateUpdate; @@ -2973,11 +3103,9 @@ Standard_Boolean V3d_View::SetImmediateUpdate (const Standard_Boolean theImmedia // ======================================================================= void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera) { - Standard_ASSERT_RAISE (!theCamera.IsNull(), "Void camera is not allowed"); + myView->SetCamera (theCamera); - myCamera = theCamera; - - MyView->SetCamera (theCamera); + ImmediateUpdate(); } // ======================================================================= @@ -2986,7 +3114,7 @@ void V3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera) // ======================================================================= const Handle(Graphic3d_Camera)& V3d_View::Camera() const { - return myCamera; + return myView->Camera(); } // ======================================================================= @@ -3198,8 +3326,7 @@ void V3d_View::Translate (const Handle(Graphic3d_Camera)& theCamera, // ======================================================================= Standard_Boolean V3d_View::IsCullingEnabled() const { - Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView(); - return aView->IsCullingEnabled; + return myView->IsCullingEnabled(); } // ======================================================================= @@ -3208,6 +3335,5 @@ Standard_Boolean V3d_View::IsCullingEnabled() const // ======================================================================= void V3d_View::SetFrustumCulling (const Standard_Boolean theToClip) { - Graphic3d_CView* aView = (Graphic3d_CView* )MyView->CView(); - aView->IsCullingEnabled = theToClip; + myView->SetCullingEnabled (theToClip); } diff --git a/src/V3d/V3d_View.hxx b/src/V3d/V3d_View.hxx index 2d3944f205..53f71e58f0 100644 --- a/src/V3d/V3d_View.hxx +++ b/src/V3d/V3d_View.hxx @@ -17,81 +17,85 @@ #ifndef _V3d_View_HeaderFile #define _V3d_View_HeaderFile -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -#include +#include + +#include #include #include + +#include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include + +#include + #include -#include -#include -#include -#include -#include -#include -#include + +#include +#include +#include #include -#include +#include +#include +#include +#include + +#include +#include +#include #include -#include +#include +#include +#include + +#include +#include + #include +#include +#include +#include + +#include +#include #include #include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -class Visual3d_View; -class Aspect_Window; +#include +#include + class Aspect_Grid; -class V3d_LayerMgr; -class Graphic3d_Structure; +class Aspect_Window; +class Bnd_Box; class Graphic3d_Group; -class V3d_BadValue; -class Standard_TypeMismatch; -class Standard_MultiplyDefined; -class V3d_UnMapped; -class V3d_Viewer; -class Quantity_Color; +class Graphic3d_Structure; class Graphic3d_TextureEnv; -class V3d_Light; -class Bnd_Box; -class Aspect_GradientBackground; -class gp_Dir; class Graphic3d_Vector; -class gp_Ax3; - +class Quantity_Color; +class Standard_MultiplyDefined; +class Standard_TypeMismatch; +class V3d_BadValue; +class V3d_Light; +class V3d_UnMapped; class V3d_View; DEFINE_STANDARD_HANDLE(V3d_View, MMgt_TShared) @@ -118,21 +122,15 @@ class V3d_View : public MMgt_TShared public: - //! Initializes the view. - Standard_EXPORT V3d_View(const Handle(V3d_Viewer)& VM, const V3d_TypeOfView Type = V3d_ORTHOGRAPHIC); - + Standard_EXPORT V3d_View (const Handle(V3d_Viewer)& theViewer, const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC); + //! Initializes the view by copying. - Standard_EXPORT V3d_View(const Handle(V3d_Viewer)& theVM, const Handle(V3d_View)& theView); - - //! Activates the view in the window specified and Map the - //! Window to the screen. - //! Warning! raises MultiplyDefined from Standard - //! if the view is already activated in a window. - //! Warning: The view is centered and resized to preserve - //! the height/width ratio of the window. - Standard_EXPORT void SetWindow (const Handle(Aspect_Window)& IdWin); - + Standard_EXPORT V3d_View (const Handle(V3d_Viewer)& theViewer, const Handle(V3d_View)& theView); + + //! Default destructor. + Standard_EXPORT virtual ~V3d_View(); + //! Activates the view in the specified Window //! If is not NULL the graphic context is used //! to draw something in this view. @@ -145,204 +143,226 @@ public: //! if the view is already activated in a window. //! Warning: The view is centered and resized to preserve //! the height/width ratio of the window. - Standard_EXPORT void SetWindow (const Handle(Aspect_Window)& aWindow, const Aspect_RenderingContext aContext, const Aspect_GraphicCallbackProc& aDisplayCB, const Standard_Address aClientData); - - Standard_EXPORT void SetMagnify (const Handle(Aspect_Window)& IdWin, const Handle(V3d_View)& aPreviousView, const Standard_Integer x1, const Standard_Integer y1, const Standard_Integer x2, const Standard_Integer y2); - + Standard_EXPORT void SetWindow (const Handle(Aspect_Window)& theWindow, + const Aspect_RenderingContext theContext = NULL, + const Aspect_GraphicCallbackProc& theDisplayCB = NULL, + const Standard_Address theClientData = NULL); + + Standard_EXPORT void SetMagnify (const Handle(Aspect_Window)& theWindow, + const Handle(V3d_View)& thePreviousView, + const Standard_Integer theX1, + const Standard_Integer theY1, + const Standard_Integer theX2, + const Standard_Integer theY2); + //! Destroys the view. Standard_EXPORT void Remove() const; - + //! Deprecated, Redraw() should be used instead. Standard_EXPORT void Update() const; - + //! Redisplays the view even if there has not //! been any modification. //! Must be called if the view is shown. //! (Ex: DeIconification ) . Standard_EXPORT void Redraw() const; - + //! Updates layer of immediate presentations. Standard_EXPORT void RedrawImmediate() const; - + //! Invalidates view content but does not redraw it. Standard_EXPORT void Invalidate() const; //! Returns true if cached view content has been invalidated. Standard_EXPORT Standard_Boolean IsInvalidated() const; - //! Redisplays the view area after esxposure. - //! [x,y] define the min xy area position - //! [width,height] the size of the area in pixel unit. - Standard_EXPORT void Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height) const; - //! Must be called when the window supporting the //! view changes size. //! if the view is not mapped on a window. //! Warning: The view is centered and resized to preserve //! the height/width ratio of the window. Standard_EXPORT void MustBeResized(); - + //! Must be called when the window supporting the //! view is mapped or unmapped. Standard_EXPORT void DoMapping(); - + //! Returns the status of the view regarding //! the displayed structures inside //! Returns True is The View is empty Standard_EXPORT Standard_Boolean IsEmpty() const; - + //! Updates the lights of the view. The view is redrawn. Standard_EXPORT void UpdateLights() const; - + + //! Sets the automatic z-fit mode and its parameters. + //! The auto z-fit has extra parameters which can controlled from application level + //! to ensure that the size of viewing volume will be sufficiently large to cover + //! the depth of unmanaged objects, for example, transformation persistent ones. + //! @param theScaleFactor [in] the scale factor for Z-range. + //! The range between Z-min, Z-max projection volume planes + //! evaluated by z fitting method will be scaled using this coefficient. + //! Program error exception is thrown if negative or zero value + //! is passed. + Standard_EXPORT void SetAutoZFitMode (const Standard_Boolean theIsOn, const Standard_Real theScaleFactor = 1.0); + + //! returns TRUE if automatic z-fit mode is turned on. + Standard_EXPORT Standard_Boolean AutoZFitMode() const; + + //! returns scale factor parameter of automatic z-fit mode. + Standard_EXPORT Standard_Real AutoZFitScaleFactor() const; + //! If automatic z-range fitting is turned on, adjusts Z-min and Z-max //! projection volume planes with call to ZFitAll. - Standard_EXPORT void AutoZFit(); - + Standard_EXPORT void AutoZFit() const; + //! Change Z-min and Z-max planes of projection volume to match the //! displayed objects. - Standard_EXPORT void ZFitAll (const Standard_Real theScaleFactor = 1.0); - - //! Defines the background colour of the view - //! by supplying : - //! the colour definition type, - //! and the three corresponding values. - Standard_EXPORT void SetBackgroundColor (const Quantity_TypeOfColor Type, const Quantity_Parameter V1, const Quantity_Parameter V2, const Quantity_Parameter V3); - - //! Defines the background colour of the view - //! by supplying : - //! the colour object. - Standard_EXPORT void SetBackgroundColor (const Quantity_Color& Color); - - //! Defines the background colour of the view - //! by supplying : - //! the colour name in the form Quantity_NOC_xxxx . - Standard_EXPORT void SetBackgroundColor (const Quantity_NameOfColor Name); - - //! Defines the gradient background colours of the view - //! by supplying : - //! two colour objects, - //! and fill method (horizontal by default) - Standard_EXPORT void SetBgGradientColors (const Quantity_Color& Color1, const Quantity_Color& Color2, const Aspect_GradientFillMethod FillStyle = Aspect_GFM_HOR, const Standard_Boolean update = Standard_False); - - //! Defines the gradient background colours of the view - //! by supplying : - //! two colour names in the form Quantity_NOC_xxxx, - //! and fill method (horizontal by default) - Standard_EXPORT void SetBgGradientColors (const Quantity_NameOfColor Color1, const Quantity_NameOfColor Color2, const Aspect_GradientFillMethod FillStyle = Aspect_GFM_HOR, const Standard_Boolean update = Standard_False); - - //! Defines the gradient background fill method of the view - Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod AMethod = Aspect_GFM_HOR, const Standard_Boolean update = Standard_False); - - //! Defines the background texture of the view - //! by supplying : - //! texture image file name, - //! and fill method (centered by default) - Standard_EXPORT void SetBackgroundImage (const Standard_CString FileName, const Aspect_FillMethod FillStyle = Aspect_FM_CENTERED, const Standard_Boolean update = Standard_False); - - //! Defines the textured background fill method of the view - Standard_EXPORT void SetBgImageStyle (const Aspect_FillMethod FillStyle, const Standard_Boolean update = Standard_False); - + Standard_EXPORT void ZFitAll (const Standard_Real theScaleFactor = 1.0) const; + + //! Defines the background color of the view by the color definition type and the three corresponding values. + Standard_EXPORT void SetBackgroundColor (const Quantity_TypeOfColor theType, + const Quantity_Parameter theV1, + const Quantity_Parameter theV2, + const Quantity_Parameter theV3); + + //! Defines the background color of the view. + Standard_EXPORT void SetBackgroundColor (const Quantity_Color& theColor); + + //! Defines the background color of the view by supplying the color name in the form Quantity_NOC_xxxx. + Standard_EXPORT void SetBackgroundColor (const Quantity_NameOfColor theName); + + //! Defines the gradient background colors of the view by supplying the colors + //! and the fill method (horizontal by default). + Standard_EXPORT void SetBgGradientColors (const Quantity_Color& theColor1, + const Quantity_Color& theColor2, + const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR, + const Standard_Boolean theToUpdate = Standard_False); + + //! Defines the gradient background colors of the view by supplying the color names + //! and the fill method (horizontal by default). + Standard_EXPORT void SetBgGradientColors (const Quantity_NameOfColor theColor1, + const Quantity_NameOfColor theColor2, + const Aspect_GradientFillMethod theFillStyle = Aspect_GFM_HOR, + const Standard_Boolean theToUpdate = Standard_False); + + //! Defines the gradient background fill method of the view. + Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod theMethod = Aspect_GFM_HOR, + const Standard_Boolean theToUpdate = Standard_False); + + //! Defines the background texture of the view by supplying the texture image file name + //! and fill method (centered by default). + Standard_EXPORT void SetBackgroundImage (const Standard_CString theFileName, + const Aspect_FillMethod theFillStyle = Aspect_FM_CENTERED, + const Standard_Boolean theToUpdate = Standard_False); + + //! Defines the textured background fill method of the view. + Standard_EXPORT void SetBgImageStyle (const Aspect_FillMethod theFillStyle, + const Standard_Boolean theToUpdate = Standard_False); + //! Definition of an axis from its origin and //! its orientation . //! This will be the current axis for rotations and movements. //! Warning! raises BadValue from V3d if the vector normal is NULL. . Standard_EXPORT void SetAxis (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, const Quantity_Parameter Vx, const Quantity_Parameter Vy, const Quantity_Parameter Vz); - - //! Defines the shading model for the - //! visualisation ZBUFFER mode. - //! Various models are available. - Standard_EXPORT void SetShadingModel (const V3d_TypeOfShadingModel Model); - - //! select the kind of rendering for texture mapping - //! no texture mapping by default - Standard_EXPORT void SetSurfaceDetail (const V3d_TypeOfSurfaceDetail SurfaceDetail); - - //! set the environment texture to use - //! no environment texture by default - Standard_EXPORT void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& ATexture); - - //! Defines the visualisation mode in the view. - Standard_EXPORT void SetVisualization (const V3d_TypeOfVisualization Mode); - + + //! Defines the shading model for the visualization. Various models are available. + Standard_EXPORT void SetShadingModel (const V3d_TypeOfShadingModel theShadingModel); + + //! Selects the kind of rendering for texture mapping. No texture mapping by default. + Standard_EXPORT void SetSurfaceDetail (const V3d_TypeOfSurfaceDetail theSurfaceDetail); + + //! Sets the environment texture to use. No environment texture by default. + Standard_EXPORT void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& theTexture); + + //! Defines the visualization type in the view. + Standard_EXPORT void SetVisualization (const V3d_TypeOfVisualization theType); + //! Activates antialiasing in the view. Standard_EXPORT void SetAntialiasingOn(); - - //! Desactivates antialiasing in the view. + + //! Deactivates antialiasing in the view. Standard_EXPORT void SetAntialiasingOff(); - + //! Defines the depth of the medium clipping plane. - Standard_EXPORT void SetZClippingDepth (const Quantity_Length Depth); - - //! Defines the thicknes around the medium clippling plane. . - Standard_EXPORT void SetZClippingWidth (const Quantity_Length Width); - + Standard_EXPORT void SetZClippingDepth (const Quantity_Length theDepth); + + //! Defines the thickness around the medium clipping plane. + Standard_EXPORT void SetZClippingWidth (const Quantity_Length theWidth); + //! Defines the type of ZClipping. - Standard_EXPORT void SetZClippingType (const V3d_TypeOfZclipping Type); - + Standard_EXPORT void SetZClippingType (const V3d_TypeOfZclipping theType); + //! Defines the depth of the medium plane. - Standard_EXPORT void SetZCueingDepth (const Quantity_Length Depth); - + Standard_EXPORT void SetZCueingDepth (const Quantity_Length theDepth); + //! Defines the thickness around the medium plane. - Standard_EXPORT void SetZCueingWidth (const Quantity_Length Width); - + Standard_EXPORT void SetZCueingWidth (const Quantity_Length theWidth); + //! Activates ZCueing in the view. Standard_EXPORT void SetZCueingOn(); - - //! Desactivates ZCueing in the view. + + //! Deactivates ZCueing in the view. Standard_EXPORT void SetZCueingOff(); - - //! Activates MyLight in the view. - Standard_EXPORT void SetLightOn (const Handle(V3d_Light)& MyLight); - + + //! Activates theLight in the view. + Standard_EXPORT void SetLightOn (const Handle(V3d_Light)& theLight); + //! Activates all the lights defined in this view. Standard_EXPORT void SetLightOn(); - - //! Desactivate MyLight in this view. - Standard_EXPORT void SetLightOff (const Handle(V3d_Light)& MyLight); - + + //! Deactivate theLight in this view. + Standard_EXPORT void SetLightOff (const Handle(V3d_Light)& theLight); + //! Deactivate all the Lights defined in this view. Standard_EXPORT void SetLightOff(); - + //! Returns TRUE when the light is active in this view. - Standard_EXPORT Standard_Boolean IsActiveLight (const Handle(V3d_Light)& aLight) const; - + Standard_EXPORT Standard_Boolean IsActiveLight (const Handle(V3d_Light)& theLight) const; + //! sets the immediate update mode and returns the previous one. Standard_EXPORT Standard_Boolean SetImmediateUpdate (const Standard_Boolean theImmediateUpdate); - + //! Customization of the ZBUFFER Triedron. //! XColor,YColor,ZColor - colors of axis - //! SizeRatio - ratio of decreasing of the trihedron size when its phisical + //! SizeRatio - ratio of decreasing of the trihedron size when its physical //! position comes out of the view //! AxisDiametr - diameter relatively to axis length - //! NbFacettes - number of facettes of cylinders and cones - Standard_EXPORT void ZBufferTriedronSetup (const Quantity_NameOfColor XColor = Quantity_NOC_RED, const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, const Standard_Real SizeRatio = 0.8, const Standard_Real AxisDiametr = 0.05, const Standard_Integer NbFacettes = 12); - + //! NbFacettes - number of facets of cylinders and cones + Standard_EXPORT void ZBufferTriedronSetup (const Quantity_NameOfColor theXColor = Quantity_NOC_RED, + const Quantity_NameOfColor theYColor = Quantity_NOC_GREEN, + const Quantity_NameOfColor theZColor = Quantity_NOC_BLUE1, + const Standard_Real theSizeRatio = 0.8, + const Standard_Real theAxisDiametr = 0.05, + const Standard_Integer theNbFacettes = 12); + //! Display of the Triedron. //! Initialize position, color and length of Triedron axes. //! The scale is a percent of the window width. - Standard_EXPORT void TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const V3d_TypeOfVisualization AMode = V3d_WIREFRAME); - + Standard_EXPORT void TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition = Aspect_TOTP_CENTER, + const Quantity_NameOfColor theColor = Quantity_NOC_WHITE, + const Standard_Real theScale = 0.02, + const V3d_TypeOfVisualization theMode = V3d_WIREFRAME); + //! Erases the Triedron. Standard_EXPORT void TriedronErase(); - + //! Highlights the echo zone of the Triedron. - Standard_EXPORT void TriedronEcho (const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE); - + Standard_EXPORT void TriedronEcho (const Aspect_TypeOfTriedronEcho theType = Aspect_TOTE_NONE); + //! Returns data of a graduated trihedron. Standard_EXPORT const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() const; - + //! Displays a graduated trihedron. - Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrigedronData); - + Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData); + //! Erases a graduated trihedron from the view. Standard_EXPORT void GraduatedTrihedronErase(); - - Standard_EXPORT void SetLayerMgr (const Handle(V3d_LayerMgr)& aMgr); - + //! modify the Projection of the view perpendicularly to //! the privileged plane of the viewer. Standard_EXPORT void SetFront(); - + //! Rotates the eye about the coordinate system of //! reference of the screen //! for which the origin is the view point of the projection, @@ -352,7 +372,7 @@ public: //! If the eye, the view point, or the high point are //! aligned or confused. Standard_EXPORT void Rotate (const Quantity_PlaneAngle Ax, const Quantity_PlaneAngle Ay, const Quantity_PlaneAngle Az, const Standard_Boolean Start = Standard_True); - + //! Rotates the eye about the coordinate system of //! reference of the screen //! for which the origin is Gravity point {X,Y,Z}, @@ -361,119 +381,119 @@ public: //! If the eye, the view point, or the high point are //! aligned or confused. Standard_EXPORT void Rotate (const Quantity_PlaneAngle Ax, const Quantity_PlaneAngle Ay, const Quantity_PlaneAngle Az, const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, const Standard_Boolean Start = Standard_True); - + //! Rotates the eye about one of the coordinate axes of //! of the view for which the origin is the Gravity point{X,Y,Z} //! with an relative angular value in RADIANS with //! respect to the initial position expressed by //! Start = Standard_True Standard_EXPORT void Rotate (const V3d_TypeOfAxe Axe, const Quantity_PlaneAngle Angle, const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, const Standard_Boolean Start = Standard_True); - + //! Rotates the eye about one of the coordinate axes of //! of the view for which the origin is the view point of the //! projection with an relative angular value in RADIANS with //! respect to the initial position expressed by //! Start = Standard_True Standard_EXPORT void Rotate (const V3d_TypeOfAxe Axe, const Quantity_PlaneAngle Angle, const Standard_Boolean Start = Standard_True); - + //! Rotates the eye around the current axis a relative //! angular value in RADIANS with respect to the initial //! position expressed by Start = Standard_True Standard_EXPORT void Rotate (const Quantity_PlaneAngle Angle, const Standard_Boolean Start = Standard_True); - + //! Movement of the eye parallel to the coordinate system //! of reference of the screen a distance relative to the //! initial position expressed by Start = Standard_True. Standard_EXPORT void Move (const Quantity_Length Dx, const Quantity_Length Dy, const Quantity_Length Dz, const Standard_Boolean Start = Standard_True); - + //! Movement of the eye parallel to one of the axes of the //! coordinate system of reference of the view a distance //! relative to the initial position expressed by //! Start = Standard_True. Standard_EXPORT void Move (const V3d_TypeOfAxe Axe, const Quantity_Length Length, const Standard_Boolean Start = Standard_True); - + //! Movement of the eye parllel to the current axis //! a distance relative to the initial position //! expressed by Start = Standard_True Standard_EXPORT void Move (const Quantity_Length Length, const Standard_Boolean Start = Standard_True); - + //! Movement of the ye and the view point parallel to the //! frame of reference of the screen a distance relative //! to the initial position expressed by //! Start = Standard_True Standard_EXPORT void Translate (const Quantity_Length Dx, const Quantity_Length Dy, const Quantity_Length Dz, const Standard_Boolean Start = Standard_True); - + //! Movement of the eye and the view point parallel to one //! of the axes of the fame of reference of the view a //! distance relative to the initial position //! expressed by Start = Standard_True Standard_EXPORT void Translate (const V3d_TypeOfAxe Axe, const Quantity_Length Length, const Standard_Boolean Start = Standard_True); - + //! Movement of the eye and view point parallel to //! the current axis a distance relative to the initial //! position expressed by Start = Standard_True Standard_EXPORT void Translate (const Quantity_Length Length, const Standard_Boolean Start = Standard_True); - + //! places the point of the view corresponding //! at the pixel position x,y at the center of the window //! and updates the view. Standard_EXPORT void Place (const Standard_Integer theXp, const Standard_Integer theYp, const Quantity_Factor theZoomFactor = 1); - + //! Rotation of the view point around the frame of reference //! of the screen for which the origin is the eye of the //! projection with a relative angular value in RADIANS //! with respect to the initial position expressed by //! Start = Standard_True Standard_EXPORT void Turn (const Quantity_PlaneAngle Ax, const Quantity_PlaneAngle Ay, const Quantity_PlaneAngle Az, const Standard_Boolean Start = Standard_True); - + //! Rotation of the view point around one of the axes of the //! frame of reference of the view for which the origin is //! the eye of the projection with an angular value in //! RADIANS relative to the initial position expressed by //! Start = Standard_True Standard_EXPORT void Turn (const V3d_TypeOfAxe Axe, const Quantity_PlaneAngle Angle, const Standard_Boolean Start = Standard_True); - + //! Rotation of the view point around the current axis an //! angular value in RADIANS relative to the initial //! position expressed by Start = Standard_True Standard_EXPORT void Turn (const Quantity_PlaneAngle Angle, const Standard_Boolean Start = Standard_True); - + //! Defines the angular position of the high point of //! the reference frame of the view with respect to the //! Y screen axis with an absolute angular value in //! RADIANS. Standard_EXPORT void SetTwist (const Quantity_PlaneAngle Angle); - + //! Defines the position of the eye.. Standard_EXPORT void SetEye (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z); - + //! Defines the Depth of the eye from the view point //! without update the projection . Standard_EXPORT void SetDepth (const Quantity_Length Depth); - + //! Defines the orientation of the projection. Standard_EXPORT void SetProj (const Quantity_Parameter Vx, const Quantity_Parameter Vy, const Quantity_Parameter Vz); - + //! Defines the orientation of the projection . Standard_EXPORT void SetProj (const V3d_TypeOfOrientation Orientation); - + //! Defines the position of the view point. Standard_EXPORT void SetAt (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z); - + //! Defines the orientation of the high point. Standard_EXPORT void SetUp (const Quantity_Parameter Vx, const Quantity_Parameter Vy, const Quantity_Parameter Vz); - + //! Defines the orientation(SO) of the high point. Standard_EXPORT void SetUp (const V3d_TypeOfOrientation Orientation); - + //! Saves the current state of the orientation of the view //! which will be the return state at ResetViewOrientation. Standard_EXPORT void SetViewOrientationDefault(); - + //! Resets the orientation of the view. //! Updates the view Standard_EXPORT void ResetViewOrientation(); - + //! Translates the center of the view along "x" and "y" axes of //! view projection. Can be used to perform interactive panning operation. //! In that case the DXv, DXy parameters specify panning relative to the @@ -486,7 +506,7 @@ public: //! passing {0, 0} for {theDXv, theDYv} will return view to initial state. //! Performs update of view. Standard_EXPORT void Panning (const Standard_Real theDXv, const Standard_Real theDYv, const Quantity_Factor theZoomFactor = 1, const Standard_Boolean theToStart = Standard_True); - + //! Relocates center of screen to the point, determined by //! {Xp, Yp} pixel coordinates relative to the bottom-left corner of //! screen. To calculate pixel coordinates for any point from world @@ -494,29 +514,29 @@ public: //! @param theXp [in] the x coordinate. //! @param theYp [in] the y coordinate. Standard_EXPORT void SetCenter (const Standard_Integer theXp, const Standard_Integer theYp); - + //! Defines the view projection size in its maximum dimension, //! keeping the inital height/width ratio unchanged. Standard_EXPORT void SetSize (const Quantity_Length theSize); - + //! Defines the Depth size of the view //! Front Plane will be set to Size/2. //! Back Plane will be set to -Size/2. //! Any Object located Above the Front Plane or //! behind the Back Plane will be Clipped . //! NOTE than the XY Size of the View is NOT modified . - Standard_EXPORT void SetZSize (const Quantity_Length Size); - + Standard_EXPORT void SetZSize (const Quantity_Length SetZSize); + //! Zooms the view by a factor relative to the initial //! value expressed by Start = Standard_True //! Updates the view. Standard_EXPORT void SetZoom (const Quantity_Factor Coef, const Standard_Boolean Start = Standard_True); - + //! Zooms the view by a factor relative to the value //! initialised by SetViewMappingDefault(). //! Updates the view. Standard_EXPORT void SetScale (const Quantity_Factor Coef); - + //! Sets anisotropic (axial) scale factors , , for view . //! Anisotropic scaling operation is performed through multiplying //! the current view orientation matrix by a scaling matrix: @@ -526,7 +546,7 @@ public: //! || 0 0 0 1 || //! Updates the view. Standard_EXPORT void SetAxialScale (const Standard_Real Sx, const Standard_Real Sy, const Standard_Real Sz); - + //! Adjust view parameters to fit the displayed scene, respecting height / width ratio. //! The Z clipping range (depth range) is fitted if AutoZFit flag is TRUE. //! Throws program error exception if margin coefficient is < 0 or >= 1. @@ -534,7 +554,7 @@ public: //! @param theMargin [in] the margin coefficient for view borders. //! @param theToUpdate [in] flag to perform view update. Standard_EXPORT void FitAll (const Quantity_Coefficient theMargin = 0.01, const Standard_Boolean theToUpdate = Standard_True); - + //! Adjust view parameters to fit the displayed scene, respecting height / width ratio //! according to the custom bounding box given. //! Throws program error exception if margin coefficient is < 0 or >= 1. @@ -543,19 +563,19 @@ public: //! @param theMargin [in] the margin coefficient for view borders. //! @param theToUpdate [in] flag to perform view update. Standard_EXPORT void FitAll (const Bnd_Box& theBox, const Quantity_Coefficient theMargin = 0.01, const Standard_Boolean theToUpdate = Standard_True); - + //! Adjusts the viewing volume so as not to clip the displayed objects by front and back //! and back clipping planes. Also sets depth value automatically depending on the //! calculated Z size and Aspect parameter. //! NOTE than the original XY size of the view is NOT modified . Standard_EXPORT void DepthFitAll (const Quantity_Coefficient Aspect = 0.01, const Quantity_Coefficient Margin = 0.01); - + //! Centers the defined projection window so that it occupies //! the maximum space while respecting the initial //! height/width ratio. //! NOTE than the original Z size of the view is NOT modified . Standard_EXPORT void FitAll (const Standard_Real theMinXv, const Standard_Real theMinYv, const Standard_Real theMaxXv, const Standard_Real theMaxYv); - + //! Centers the defined PIXEL window so that it occupies //! the maximum space while respecting the initial height/width ratio. //! NOTE than the original Z size of the view is NOT modified. @@ -564,48 +584,47 @@ public: //! @param theMaxXp [in] pixel coordinates of maximal corner on x screen axis. //! @param theMaxYp [in] pixel coordinates of maximal corner on y screen axis. Standard_EXPORT void WindowFit (const Standard_Integer theMinXp, const Standard_Integer theMinYp, const Standard_Integer theMaxXp, const Standard_Integer theMaxYp); - + //! Saves the current view mapping. This will be the //! state returned from ResetViewmapping. Standard_EXPORT void SetViewMappingDefault(); - + //! Resets the centering of the view. //! Updates the view Standard_EXPORT void ResetViewMapping(); - - //! Resets the centering and the orientation of the view - //! Updates the view - Standard_EXPORT void Reset (const Standard_Boolean update = Standard_True); - + + //! Resets the centering and the orientation of the view. + Standard_EXPORT void Reset (const Standard_Boolean theToUpdate = Standard_True); + //! Converts the PIXEL value //! to a value in the projection plane. Standard_EXPORT Quantity_Length Convert (const Standard_Integer Vp) const; - + //! Converts the point PIXEL into a point projected //! in the reference frame of the projection plane. Standard_EXPORT void Convert (const Standard_Integer Xp, const Standard_Integer Yp, V3d_Coordinate& Xv, V3d_Coordinate& Yv) const; - + //! Converts tha value of the projection plane into //! a PIXEL value. Standard_EXPORT Standard_Integer Convert (const Quantity_Length Vv) const; - + //! Converts the point defined in the reference frame //! of the projection plane into a point PIXEL. Standard_EXPORT void Convert (const V3d_Coordinate Xv, const V3d_Coordinate Yv, Standard_Integer& Xp, Standard_Integer& Yp) const; - + //! Converts the projected point into a point //! in the reference frame of the view corresponding //! to the intersection with the projection plane //! of the eye/view point vector. Standard_EXPORT void Convert (const Standard_Integer Xp, const Standard_Integer Yp, V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - + //! Converts the projected point into a point //! in the reference frame of the view corresponding //! to the intersection with the projection plane //! of the eye/view point vector and returns the //! projection ray for further computations. Standard_EXPORT void ConvertWithProj (const Standard_Integer Xp, const Standard_Integer Yp, V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z, Quantity_Parameter& Vx, Quantity_Parameter& Vy, Quantity_Parameter& Vz) const; - + //! Converts the projected point into the nearest grid point //! in the reference frame of the view corresponding //! to the intersection with the projection plane @@ -626,92 +645,107 @@ public: //! 2.4) Else this is the standard case //! } else myView->Convert(x,y,X,Y,Z); Standard_EXPORT void ConvertToGrid (const Standard_Integer Xp, const Standard_Integer Yp, V3d_Coordinate& Xg, V3d_Coordinate& Yg, V3d_Coordinate& Zg) const; - + //! Converts the point into the nearest grid point //! and display the grid marker. Standard_EXPORT void ConvertToGrid (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, V3d_Coordinate& Xg, V3d_Coordinate& Yg, V3d_Coordinate& Zg) const; - + //! Projects the point defined in the reference frame of //! the view into the projected point in the associated window. Standard_EXPORT void Convert (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, Standard_Integer& Xp, Standard_Integer& Yp) const; - + //! Converts the point defined in the user space of - //! the view to the projected view plane point at z 0. - Standard_EXPORT void Project (const V3d_Coordinate X, const V3d_Coordinate Y, const V3d_Coordinate Z, V3d_Coordinate& Xp, V3d_Coordinate& Yp) const; - + //! the view to the projection plane at the depth + //! relative to theZ. + Standard_EXPORT void Project (const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + Standard_Real& theXp, + Standard_Real& theYp) const; + + //! Converts the point defined in the user space of + //! the view to the projection plane at the depth + //! relative to theZ. + Standard_EXPORT void Project (const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + Standard_Real& theXp, + Standard_Real& theYp, + Standard_Real& theZp) const; + //! Returns the Background color values of the view //! depending of the color Type. Standard_EXPORT void BackgroundColor (const Quantity_TypeOfColor Type, Quantity_Parameter& V1, Quantity_Parameter& V2, Quantity_Parameter& V3) const; - + //! Returns the Background color object of the view. Standard_EXPORT Quantity_Color BackgroundColor() const; - - //! Returns the gradient background colour objects of the view. - Standard_EXPORT void GradientBackgroundColors (Quantity_Color& Color1, Quantity_Color& Color2) const; - + + //! Returns the gradient background colors of the view. + Standard_EXPORT void GradientBackgroundColors (Quantity_Color& theColor1, Quantity_Color& theColor2) const; + //! Returns the gradient background of the view. Standard_EXPORT Aspect_GradientBackground GradientBackground() const; - + //! Returns the current value of the zoom expressed with //! respect to SetViewMappingDefault(). Standard_EXPORT Quantity_Factor Scale() const; - + //! Returns the current values of the anisotropic (axial) scale factors. Standard_EXPORT void AxialScale (Standard_Real& Sx, Standard_Real& Sy, Standard_Real& Sz) const; - + //! Returns the height and width of the view. Standard_EXPORT void Size (Quantity_Length& Width, Quantity_Length& Height) const; - + //! Returns the Depth of the view . Standard_EXPORT Standard_Real ZSize() const; - + //! Returns the position of the eye. Standard_EXPORT void Eye (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - + //! Returns the position of point which emanating the //! projections. Standard_EXPORT void FocalReferencePoint (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - + //! Returns the coordinate of the point (Xpix,Ypix) //! in the view (XP,YP,ZP), and the projection vector of the //! view passing by the point (for PerspectiveView). Standard_EXPORT void ProjReferenceAxe (const Standard_Integer Xpix, const Standard_Integer Ypix, V3d_Coordinate& XP, V3d_Coordinate& YP, V3d_Coordinate& ZP, V3d_Coordinate& VX, V3d_Coordinate& VY, V3d_Coordinate& VZ) const; - + //! Returns the Distance between the Eye and View Point. Standard_EXPORT Quantity_Length Depth() const; - + //! Returns the projection vector. Standard_EXPORT void Proj (Quantity_Parameter& Vx, Quantity_Parameter& Vy, Quantity_Parameter& Vz) const; - + //! Returns the position of the view point. Standard_EXPORT void At (V3d_Coordinate& X, V3d_Coordinate& Y, V3d_Coordinate& Z) const; - + //! Returns the vector giving the position of the high point. Standard_EXPORT void Up (Quantity_Parameter& Vx, Quantity_Parameter& Vy, Quantity_Parameter& Vz) const; - + //! Returns in RADIANS the orientation of the view around //! the visual axis measured from the Y axis of the screen. Standard_EXPORT Quantity_PlaneAngle Twist() const; - + //! Returns the current shading model. Standard_EXPORT V3d_TypeOfShadingModel ShadingModel() const; - + Standard_EXPORT V3d_TypeOfSurfaceDetail SurfaceDetail() const; - + Standard_EXPORT Handle(Graphic3d_TextureEnv) TextureEnv() const; - + //! Returns the current visualisation mode. Standard_EXPORT V3d_TypeOfVisualization Visualization() const; - + //! Indicates if the antialiasing is active (True) or //! inactive (False). Standard_EXPORT Standard_Boolean Antialiasing() const; - + //! Returns activity and information on the Zcueing. //! : Depth of plane. //! : Thickness around the plane. - Standard_EXPORT Standard_Boolean ZCueing (Quantity_Length& Depth, Quantity_Length& Width) const; - + Standard_EXPORT Standard_Boolean ZCueing (Quantity_Length& theDepth, Quantity_Length& theWidth) const; + //! Returns current information on the ZClipping. //! : Depth of plane. //! : Thickness around the plane. @@ -719,36 +753,39 @@ public: //! "FRONT" //! "SLICE" //! "OFF" - Standard_EXPORT V3d_TypeOfZclipping ZClipping (Quantity_Length& Depth, Quantity_Length& Width) const; - + Standard_EXPORT V3d_TypeOfZclipping ZClipping (Quantity_Length& theDepth, Quantity_Length& theWidth) const; + //! Returns True if One light more can be //! activated in this View. Standard_EXPORT Standard_Boolean IfMoreLights() const; - + //! initializes an iteration on the active Lights. Standard_EXPORT void InitActiveLights(); - + //! returns true if there are more active Light(s) to return. Standard_EXPORT Standard_Boolean MoreActiveLights() const; - + //! Go to the next active Light //! (if there is not, ActiveLight will raise an exception) Standard_EXPORT void NextActiveLights(); - + Standard_EXPORT Handle(V3d_Light) ActiveLight() const; - + + //! Returns the MAX number of light associated to the view. + Standard_EXPORT Standard_Integer LightLimit() const; + //! Returns the viewer in which the view has been created. Standard_EXPORT Handle(V3d_Viewer) Viewer() const; - + //! Returns True if MyView is associated with a window . Standard_EXPORT Standard_Boolean IfWindow() const; - + //! Returns the Aspect Window associated with the view. Standard_EXPORT Handle(Aspect_Window) Window() const; - + //! Returns the Type of the View Standard_EXPORT V3d_TypeOfView Type() const; - + //! Translates the center of the view along "x" and "y" axes of //! view projection. Can be used to perform interactive panning operation. //! In that case the DXp, DXp parameters specify panning relative to the @@ -761,7 +798,7 @@ public: //! panning parameter should return view panning to initial state. //! Performs update of view. Standard_EXPORT void Pan (const Standard_Integer theDXp, const Standard_Integer theDYp, const Quantity_Factor theZoomFactor = 1, const Standard_Boolean theToStart = Standard_True); - + //! Zoom the view according to a zoom factor computed //! from the distance between the 2 mouse position. //! @param theXp1 [in] the x coordinate of first mouse position, in pixels. @@ -769,21 +806,21 @@ public: //! @param theXp2 [in] the x coordinate of second mouse position, in pixels. //! @param theYp2 [in] the y coordinate of second mouse position, in pixels. Standard_EXPORT void Zoom (const Standard_Integer theXp1, const Standard_Integer theYp1, const Standard_Integer theXp2, const Standard_Integer theYp2); - + //! Defines starting point for ZoomAtPoint view operation. //! @param theXp [in] the x mouse coordinate, in pixels. //! @param theYp [in] the y mouse coordinate, in pixels. Standard_EXPORT void StartZoomAtPoint (const Standard_Integer theXp, const Standard_Integer theYp); - + //! Zooms the model at a pixel defined by the method StartZoomAtPoint(). Standard_EXPORT void ZoomAtPoint (const Standard_Integer theMouseStartX, const Standard_Integer theMouseStartY, const Standard_Integer theMouseEndX, const Standard_Integer theMouseEndY); - + //! Performs anisotropic scaling of view along the given . //! The scale factor is calculated on a basis of //! the mouse pointer displacement . //! The calculated scale factor is then passed to SetAxialScale(Sx, Sy, Sz) method. Standard_EXPORT void AxialScale (const Standard_Integer Dx, const Standard_Integer Dy, const V3d_TypeOfAxe Axis); - + //! Begin the rotation of the view around the screen axis //! according to the mouse position . //! Warning: Enable rotation around the Z screen axis when @@ -793,64 +830,60 @@ public: //! inside the circular threshold area and to rotate around Z screen axis //! outside this area. Standard_EXPORT void StartRotation (const Standard_Integer X, const Standard_Integer Y, const Quantity_Ratio zRotationThreshold = 0.0); - + //! Continues the rotation of the view //! with an angle computed from the last and new mouse position . Standard_EXPORT void Rotation (const Standard_Integer X, const Standard_Integer Y); - + //! Change View Plane Distance for Perspective Views //! Warning! raises TypeMismatch from Standard if the view //! is not a perspective view. Standard_EXPORT void SetFocale (const Quantity_Length Focale); - + //! Returns the View Plane Distance for Perspective Views Standard_EXPORT Quantity_Length Focale() const; - - //! Returns the associated Visual3d view. - Standard_EXPORT Handle(Visual3d_View) View() const; - - //! Switches computed HLR mode in the view - Standard_EXPORT void SetComputedMode (const Standard_Boolean aMode); - - //! Returns the computed HLR mode state + + //! Returns the associated Graphic3d view. + Standard_EXPORT Handle(Graphic3d_CView) View() const; + + //! Switches computed HLR mode in the view. + Standard_EXPORT void SetComputedMode (const Standard_Boolean theMode); + + //! Returns the computed HLR mode state. Standard_EXPORT Standard_Boolean ComputedMode() const; - + //! idem than WindowFit Standard_EXPORT void WindowFitAll (const Standard_Integer Xmin, const Standard_Integer Ymin, const Standard_Integer Xmax, const Standard_Integer Ymax); - + //! Defines or Updates the definition of the //! grid in Standard_EXPORT void SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid); - - //! Defines or Updates the graphic definition of the - //! grid in - Standard_EXPORT void SetGridGraphicValues (const Handle(Aspect_Grid)& aGrid); - + //! Defines or Updates the activity of the //! grid in Standard_EXPORT void SetGridActivity (const Standard_Boolean aFlag); - + //! dump the full contents of the view at the same //! scale in the file . The file name //! extension must be one of ".png",".bmp",".jpg",".gif". //! Returns FALSE when the dump has failed Standard_EXPORT Standard_Boolean Dump (const Standard_CString theFile, const Graphic3d_BufferType& theBufferType = Graphic3d_BT_RGB); - + //! print the contents of the view to printer with preview. - //! : If you have already an PrinterDeviceContext (HDC), + //! : If you have already an PrinterDeviceContext (HDC), //! then you can pass it to the print routines. //! If you don't have an PrinterDeviceContext, then this parameter should //! be NULL. - //! : If hPrnDC == NULL, then you can force the print routines to + //! : If thePrintDC == NULL, then you can force the print routines to //! open a Print Dialog box. //! If you want to do this, then set showDialog to TRUE //! If you don't want to see a dialog (only possible, if you have a hPrnDC - //! or the dialog box was opened once before) then set to FALSE. - //! : When set to FALSE then print the view without background color + //! or the dialog box was opened once before) then set to FALSE. + //! : When set to FALSE then print the view without background color //! (background is white) //! else set to TRUE for printing with current background color. - //! : If != NULL, then the view will be printed to a file. - //! : If you want to select the print algorithm, then you can + //! : If != NULL, then the view will be printed to a file. + //! : If you want to select the print algorithm, then you can //! specify one of existing algorithms: Aspect_PA_STRETCH, Aspect_PA_TILE. //! Returns Standard_True if the data is passed to the printer, otherwise //! Standard_False if the print operation failed. This might be related to @@ -860,8 +893,20 @@ public: //! view on level of OpenGl_GraphicDriver; Please take it into account if //! you use it for your purposes; //! Warning: Works only under Windows. - Standard_EXPORT Standard_Boolean Print (const Aspect_Handle hPrnDC = 0, const Standard_Boolean showDialog = Standard_True, const Standard_Boolean showBackground = Standard_True, const Standard_CString filename = NULL, const Aspect_PrintAlgo printAlgorithm = Aspect_PA_STRETCH) const; - + Standard_EXPORT Standard_Boolean Print (const Aspect_Handle thePrintDC = 0, + const Standard_Boolean theShowDialog = Standard_True, + const Standard_Boolean theShowBackground = Standard_True, + const Standard_CString theFilename = NULL, + const Aspect_PrintAlgo thePrintAlgorithm = Aspect_PA_STRETCH) const; + + //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). + //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits + //! on printing to laser printer). Notice however that results may differ a lot and + //! do not contain some elements. + Standard_EXPORT Standard_Boolean Export (const Standard_CString theFileName, + const Graphic3d_ExportFormat theFormat, + const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree); + //! Dumps the full contents of the view //! to a pixmap of pixel size * and //! buffer type . If is true @@ -873,7 +918,7 @@ public: //! flags are to be used for dumping then left or //! right eye projections. Standard_EXPORT Standard_Boolean ToPixMap (Image_PixMap& theImage, const Standard_Integer theWidth, const Standard_Integer theHeight, const Graphic3d_BufferType& theBufferType = Graphic3d_BT_RGB, const Standard_Boolean theToKeepAspect = Standard_True, const V3d_StereoDumpOptions theStereoOptions = V3d_SDO_MONO); - + //! Manages display of the back faces //! When is TOBM_AUTOMATIC the object backfaces //! are displayed only for surface objects and @@ -883,63 +928,65 @@ public: //! are always displayed both for surfaces or solids. //! is TOBM_NEVER_DISPLAYED the object backfaces //! are never displayed. - Standard_EXPORT void SetBackFacingModel (const V3d_TypeOfBackfacingModel aModel = V3d_TOBM_AUTOMATIC); - + Standard_EXPORT void SetBackFacingModel (const V3d_TypeOfBackfacingModel theModel = V3d_TOBM_AUTOMATIC); + //! Returns current state of the back faces display Standard_EXPORT V3d_TypeOfBackfacingModel BackFacingModel() const; - + //! turns on/off opengl lighting, currently used in triedron displaying - Standard_EXPORT void EnableGLLight (const Standard_Boolean enable = Standard_True) const; - + Standard_EXPORT void EnableGLLight (const Standard_Boolean theIsEnabled = Standard_True) const; + //! returns the current state of the gl lighting //! currently used in triedron displaying Standard_EXPORT Standard_Boolean IsGLLightEnabled() const; - + //! Adds clip plane to the view. The composition of clip planes truncates the //! rendering space to convex volume. Number of supported clip planes can be consulted - //! by PlaneLimit method of associated Visual3d_View. Please be aware that the planes - //! which exceed the limit are ignored during rendering. + //! by PlaneLimit method of associated Graphic3d_GraphicDriver. + //! Please be aware that the planes which exceed the limit are ignored during rendering. //! @param thePlane [in] the clip plane to be added to view. Standard_EXPORT virtual void AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane); - + //! Removes clip plane from the view. //! @param thePlane [in] the clip plane to be removed from view. Standard_EXPORT virtual void RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane); - + //! Sets sequence of clip planes to the view. The planes that have been set //! before are removed from the view. The composition of clip planes //! truncates the rendering space to convex volume. Number of supported - //! clip planes can be consulted by PlaneLimit method of associated - //! Visual3d_View. Please be aware that the planes which exceed the limit - //! are ignored during rendering. + //! clip planes can be consulted by InquirePlaneLimit method of + //! Graphic3d_GraphicDriver. Please be aware that the planes that + //! exceed the limit are ignored during rendering. //! @param thePlanes [in] the clip planes to set. Standard_EXPORT void SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes); - + //! Get clip planes. //! @return sequence clip planes that have been set for the view Standard_EXPORT const Graphic3d_SequenceOfHClipPlane& GetClipPlanes() const; - + + //! Returns the MAX number of clipping planes associated to the view. + Standard_EXPORT Standard_Integer PlaneLimit() const; + //! Change camera used by view. Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera); - + //! Returns camera object of the view. //! @return: handle to camera object, or NULL if 3D view does not use //! the camera approach. Standard_EXPORT const Handle(Graphic3d_Camera)& Camera() const; - + //! Returns current rendering parameters and effect settings. Standard_EXPORT const Graphic3d_RenderingParams& RenderingParams() const; - + //! Returns reference to current rendering parameters and effect settings. Standard_EXPORT Graphic3d_RenderingParams& ChangeRenderingParams(); - + //! @return flag value of objects culling mechanism Standard_EXPORT Standard_Boolean IsCullingEnabled() const; - + //! Turn on/off automatic culling of objects outside frustrum (ON by default) Standard_EXPORT void SetFrustumCulling (const Standard_Boolean theMode); - friend //! Activates all of the views of a viewer attached //! to a window. @@ -964,9 +1011,8 @@ friend protected: - Standard_EXPORT void ImmediateUpdate() const; - + //! Transform camera eye, center and scale to fit in the //! passed bounding box specified in WCS. //! @param theCamera [in] the camera. @@ -983,30 +1029,22 @@ protected: //! center of camera is adjusted. //! @return TRUE if the fit all operation can be done. Standard_EXPORT Standard_Boolean FitMinMax (const Handle(Graphic3d_Camera)& theCamera, const Bnd_Box& theBox, const Standard_Real theMargin, const Standard_Real theResolution = 0.0, const Standard_Boolean theToEnlargeIfLine = Standard_True) const; - + //! Scales camera to fit the view frame of defined width and height //! keeping the aspect. For orthogonal camera the method changes scale, //! for perspective adjusts Eye location about the Center point. //! @param theSizeXv [in] size of viewport frame on "x" axis. //! @param theSizeYv [in] size of viewport frame on "y" axis. Standard_EXPORT void Scale (const Handle(Graphic3d_Camera)& theCamera, const Standard_Real theSizeXv, const Standard_Real theSizeYv) const; - - Standard_EXPORT void Translate (const Handle(Graphic3d_Camera)& theCamera, const Standard_Real theDXv, const Standard_Real theDYv) const; - - Standard_Real myOldMouseX; - Standard_Real myOldMouseY; - gp_Dir myCamStartOpUp; - gp_Pnt myCamStartOpEye; - Standard_Real myCamStartOpBnd[6]; - gp_Pnt myCamStartOpCenter; - Handle(Graphic3d_Camera) myCamera; - Handle(Visual3d_View) MyView; - Standard_Boolean myImmediateUpdate; + Standard_EXPORT void Translate (const Handle(Graphic3d_Camera)& theCamera, const Standard_Real theDXv, const Standard_Real theDYv) const; private: - + //! Modifies the aspect ratio of the camera when + //! the associated window is defined or resized. + Standard_EXPORT void SetRatio(); + //! Change the scale factor and position of the view //! such as the bounding box is contains //! in the view. @@ -1036,11 +1074,23 @@ private: //! Returns a new vertex when the grid is activated. Standard_EXPORT Graphic3d_Vertex Compute (const Graphic3d_Vertex& AVertex) const; +protected: + + Standard_Real myOldMouseX; + Standard_Real myOldMouseY; + gp_Dir myCamStartOpUp; + gp_Pnt myCamStartOpEye; + Standard_Real myCamStartOpBnd[6]; + gp_Pnt myCamStartOpCenter; + Handle(Graphic3d_Camera) myCamera; + Handle(Graphic3d_Camera) myDefaultCamera; + Handle(Graphic3d_CView) myView; + Standard_Boolean myImmediateUpdate; + +private: + V3d_ViewerPointer MyViewer; V3d_ListOfTransient MyActiveLights; - Visual3d_ContextView MyViewContext; - Aspect_Background MyBackground; - Aspect_GradientBackground MyGradientBackground; Graphic3d_Vector MyDefaultViewAxis; Graphic3d_Vertex MyDefaultViewPoint; Handle(Aspect_Window) MyWindow; @@ -1066,14 +1116,8 @@ private: Graphic3d_Vector myZscreenAxis; Graphic3d_Vector myViewAxis; Graphic3d_Vertex myGravityReferencePoint; - - + Standard_Boolean myAutoZFitIsOn; + Standard_Real myAutoZFitScaleFactor; }; - - - - - - #endif // _V3d_View_HeaderFile diff --git a/src/V3d/V3d_View_1.cxx b/src/V3d/V3d_View_1.cxx index c4ddef6605..21e2a48111 100644 --- a/src/V3d/V3d_View_1.cxx +++ b/src/V3d/V3d_View_1.cxx @@ -38,154 +38,186 @@ #include #include #include -#include -/*----------------------------------------------------------------------*/ -void V3d_View::SetAntialiasingOn() { - MyViewContext.SetAliasingOn() ; - MyView->SetContext(MyViewContext) ; +// ======================================================================= +// function : SetAntialiasingOn +// purpose : +// ======================================================================= +void V3d_View::SetAntialiasingOn() +{ + myView->SetAntialiasingEnabled (Standard_True); } -void V3d_View::SetAntialiasingOff() { - MyViewContext.SetAliasingOff() ; - MyView->SetContext(MyViewContext) ; +// ======================================================================= +// function : SetAntialiasingOff +// purpose : +// ======================================================================= +void V3d_View::SetAntialiasingOff() +{ + myView->SetAntialiasingEnabled (Standard_False); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZClippingDepth(const Standard_Real Depth) { - Standard_Real Front,Back,Width ; - - Front = MyViewContext.ZClippingFrontPlane() ; - Back = MyViewContext.ZClippingBackPlane() ; - Width = Front - Back ; - Front = Depth + Width/2. ; - Back = Depth - Width/2. ; - MyViewContext.SetZClippingBackPlane(Back) ; - MyViewContext.SetZClippingFrontPlane(Front) ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZClippingDepth +//purpose : +//============================================================================= +void V3d_View::SetZClippingDepth (const Standard_Real theDepth) +{ + Standard_Real aFront = 0., aBack = 0., aWidth = 0.; + + aFront = myView->ZClippingFrontPlane(); + aBack = myView->ZClippingBackPlane(); + aWidth = aFront - aBack; + aFront = theDepth + aWidth / 2.; + aBack = theDepth - aWidth / 2.; + myView->SetZClippingBackPlane (aBack); + myView->SetZClippingFrontPlane (aFront); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZClippingWidth(const Standard_Real Width) { - Standard_Real Front,Back,Depth ; - V3d_BadValue_Raise_if( Width <= 0.,"V3d_View::SetZClippingWidth, bad width"); - - Front = MyViewContext.ZClippingFrontPlane() ; - Back = MyViewContext.ZClippingBackPlane() ; - Depth = (Front + Back)/2. ; - Front = Depth + Width/2. ; - Back = Depth - Width/2. ; - MyViewContext.SetZClippingBackPlane(Back) ; - MyViewContext.SetZClippingFrontPlane(Front) ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZClippingWidth +//purpose : +//============================================================================= +void V3d_View::SetZClippingWidth (const Standard_Real theWidth) +{ + Standard_Real aFront = 0., aBack = 0., aDepth = 0.; + V3d_BadValue_Raise_if (theWidth <= 0., "V3d_View::SetZClippingWidth, bad width"); + + aFront = myView->ZClippingFrontPlane(); + aBack = myView->ZClippingBackPlane(); + aDepth = (aFront + aBack) / 2.; + aFront = aDepth + theWidth / 2.; + aBack = aDepth - theWidth / 2.; + myView->SetZClippingBackPlane (aBack); + myView->SetZClippingFrontPlane (aFront); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZClippingType(const V3d_TypeOfZclipping Type) { - - switch (Type) { - case V3d_OFF : - MyViewContext.SetZClippingOff() ; - break ; - case V3d_BACK : - MyViewContext.SetBackZClippingOn() ; - MyViewContext.SetFrontZClippingOff() ; - break ; - case V3d_FRONT : - MyViewContext.SetFrontZClippingOn() ; - MyViewContext.SetBackZClippingOff() ; - break ; - case V3d_SLICE : - MyViewContext.SetZClippingOn() ; - break ; +//============================================================================= +//function : SetZClippingType +//purpose : +//============================================================================= +void V3d_View::SetZClippingType (const V3d_TypeOfZclipping theType) +{ + switch (theType) + { + case V3d_OFF : + myView->SetFrontZClippingOn (Standard_False); + myView->SetBackZClippingOn (Standard_False); + break; + + case V3d_BACK : + myView->SetBackZClippingOn (Standard_True); + myView->SetFrontZClippingOn (Standard_False); + break; + + case V3d_FRONT : + myView->SetFrontZClippingOn (Standard_True); + myView->SetBackZClippingOn (Standard_False); + break; + + case V3d_SLICE : + myView->SetFrontZClippingOn (Standard_False); + myView->SetBackZClippingOn (Standard_False); + break; } - MyView->SetContext(MyViewContext) ; } -/*----------------------------------------------------------------------*/ +//============================================================================= +//function : ZClipping +//purpose : +//============================================================================= +V3d_TypeOfZclipping V3d_View::ZClipping (Standard_Real& theDepth, Standard_Real& theWidth) const +{ + V3d_TypeOfZclipping aType = V3d_OFF; + + Standard_Real aBack = myView->ZClippingBackPlane(); + Standard_Real aFront = myView->ZClippingFrontPlane(); + Standard_Boolean isBackOn = myView->BackZClippingIsOn(); + Standard_Boolean isFrontOn = myView->FrontZClippingIsOn(); + + theWidth = aFront - aBack ; + theDepth = (aFront + aBack) / 2.0; + if (isBackOn) + { + if (isFrontOn) + { + aType = V3d_SLICE; + } + else + { + aType = V3d_BACK; + } + } + else if (isFrontOn) + { + aType = V3d_FRONT; + } -V3d_TypeOfZclipping V3d_View::ZClipping(Standard_Real& Depth, Standard_Real& Width) const { - V3d_TypeOfZclipping T = V3d_OFF ; - Standard_Real Front,Back ; - Standard_Boolean Aback,Afront ; - - Back = MyViewContext.ZClippingBackPlane() ; - Front = MyViewContext.ZClippingFrontPlane() ; - Aback = MyViewContext.BackZClippingIsOn() ; - Afront = MyViewContext.FrontZClippingIsOn() ; - Width = Front - Back ; - Depth = (Front + Back)/2. ; - if( Aback ) { - if( Afront ) T = V3d_SLICE ; - else T = V3d_BACK ; - } else if( Afront ) T = V3d_FRONT ; - - return T ; + return aType; } - -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZCueingDepth(const Standard_Real Depth) { - Standard_Real Front,Back,Width ; - - Front = MyViewContext.DepthCueingFrontPlane() ; - Back = MyViewContext.DepthCueingBackPlane() ; - Width = Front - Back ; - Front = Depth + Width/2. ; - Back = Depth - Width/2. ; - MyViewContext.SetDepthCueingBackPlane(Back) ; - MyViewContext.SetDepthCueingFrontPlane(Front) ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZCueingDepth +//purpose : +//============================================================================= +void V3d_View::SetZCueingDepth (const Standard_Real theDepth) +{ + Standard_Real aFront = myView->DepthCueingFrontPlane(); + Standard_Real aBack = myView->DepthCueingBackPlane(); + Standard_Real aWidth = aFront - aBack; + aFront = theDepth + aWidth / 2.; + aBack = theDepth - aWidth / 2.; + myView->SetDepthCueingBackPlane (aBack); + myView->SetDepthCueingFrontPlane (aFront); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZCueingWidth(const Standard_Real Width) { - Standard_Real Front,Back,Depth ; - V3d_BadValue_Raise_if( Width <= 0.,"V3d_View::SetZCueingWidth, bad width"); - - Front = MyViewContext.DepthCueingFrontPlane() ; - Back = MyViewContext.DepthCueingBackPlane() ; - Depth = (Front + Back)/2. ; - Front = Depth + Width/2. ; - Back = Depth - Width/2. ; - MyViewContext.SetDepthCueingBackPlane(Back) ; - MyViewContext.SetDepthCueingFrontPlane(Front) ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZCueingWidth +//purpose : +//============================================================================= +void V3d_View::SetZCueingWidth (const Standard_Real theWidth) +{ + V3d_BadValue_Raise_if (theWidth <= 0., "V3d_View::SetZCueingWidth, bad width"); + + Standard_Real aFront = myView->DepthCueingFrontPlane(); + Standard_Real aBack = myView->DepthCueingBackPlane(); + Standard_Real aDepth = (aFront + aBack) / 2.0; + aFront = aDepth + theWidth / 2.0; + aBack = aDepth - theWidth / 2.0; + myView->SetDepthCueingBackPlane (aBack); + myView->SetDepthCueingFrontPlane (aFront); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZCueingOn() { - - MyViewContext.SetDepthCueingOn() ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZCueingOn +//purpose : +//============================================================================= +void V3d_View::SetZCueingOn() +{ + myView->SetDepthCueingOn (Standard_True); } -/*----------------------------------------------------------------------*/ - -void V3d_View::SetZCueingOff() { - - MyViewContext.SetDepthCueingOff() ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetZCueingOff +//purpose : +//============================================================================= +void V3d_View::SetZCueingOff() +{ + myView->SetDepthCueingOn (Standard_False); } -/*----------------------------------------------------------------------*/ - -Standard_Boolean V3d_View::ZCueing(Standard_Real& Depth, Standard_Real& Width)const { - Standard_Boolean Z = MyViewContext.DepthCueingIsOn() ; - Standard_Real Front,Back ; +//============================================================================= +//function : ZCueing +//purpose : +//============================================================================= +Standard_Boolean V3d_View::ZCueing (Standard_Real& theDepth, Standard_Real& theWidth) const +{ + Standard_Boolean isOn = myView->DepthCueingIsOn(); + Standard_Real aFront = myView->DepthCueingFrontPlane(); + Standard_Real aBack = myView->DepthCueingBackPlane(); -Back = MyViewContext.DepthCueingBackPlane() ; - Front = MyViewContext.DepthCueingFrontPlane() ; - Width = Front - Back ; - Depth = (Front + Back)/2. ; + theWidth = aFront - aBack ; + theDepth = (aFront + aBack) / 2.; - return Z ; + return isOn; } - -/*----------------------------------------------------------------------*/ diff --git a/src/V3d/V3d_View_2.cxx b/src/V3d/V3d_View_2.cxx index 2fc1430d77..bfbd368143 100644 --- a/src/V3d/V3d_View_2.cxx +++ b/src/V3d/V3d_View_2.cxx @@ -21,9 +21,6 @@ 24-12-97 : FMN ; Suppression de GEOMLITE 23-11-00 : GG ; Add IsActiveLight() and IsActivePlane() methods ************************************************************************/ -// Use myView->PlaneLimit() instead Visual3d_ClipPlane::Limit() -// Use myView->LightLimit() instead Visual3d_Light::Limit() -/*----------------------------------------------------------------------*/ /* * Includes */ @@ -35,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -47,77 +45,138 @@ #include #include #include -#include -#include - -/*----------------------------------------------------------------------*/ -void V3d_View::SetLightOn( const Handle(V3d_Light)& TheLight ) { - - if( !MyActiveLights.Contains(TheLight)){ - V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyView->LightLimit(), - "too many lights"); - MyActiveLights.Append(TheLight) ; - MyViewContext.SetLightOn(TheLight->Light()); - MyView->SetContext(MyViewContext); + +//============================================================================= +//function : SetLightOn +//purpose : +//============================================================================= +void V3d_View::SetLightOn (const Handle(V3d_Light)& theLight) +{ + if (!MyActiveLights.Contains (theLight)) + { + V3d_BadValue_Raise_if (MyActiveLights.Extent() >= LightLimit(), + "V3d_View::SetLightOn, " + "too many lights"); + MyActiveLights.Append (theLight); + UpdateLights(); } } -void V3d_View::SetLightOff( const Handle(V3d_Light)& TheLight ) { - - Standard_TypeMismatch_Raise_if(MyViewer->IsGlobalLight(TheLight),"the light is global"); - - MyActiveLights.Remove(TheLight); - MyViewContext.SetLightOff(TheLight->Light()) ; - MyView->SetContext(MyViewContext) ; +//============================================================================= +//function : SetLightOff +//purpose : +//============================================================================= +void V3d_View::SetLightOff (const Handle(V3d_Light)& theLight) +{ + Standard_TypeMismatch_Raise_if (MyViewer->IsGlobalLight (theLight), + "V3d_View::SetLightOff, " + "the light is global"); + MyActiveLights.Remove (theLight); + UpdateLights(); } -Standard_Boolean V3d_View::IsActiveLight(const Handle(V3d_Light)& aLight) const { - if( aLight.IsNull() ) return Standard_False; - return MyActiveLights.Contains(aLight); +//============================================================================= +//function : IsActiveLight +//purpose : +//============================================================================= +Standard_Boolean V3d_View::IsActiveLight (const Handle(V3d_Light)& theLight) const +{ + if (theLight.IsNull()) + { + return Standard_False; + } + return MyActiveLights.Contains(theLight); } -void V3d_View::SetLightOn( ) { - - for(MyViewer->InitDefinedLights();MyViewer->MoreDefinedLights();MyViewer->NextDefinedLights()){ - if(!MyActiveLights.Contains(MyViewer->DefinedLight())){ - MyActiveLights.Append(MyViewer->DefinedLight()) ; - MyViewContext.SetLightOn(MyViewer->DefinedLight()->Light()); +//============================================================================= +//function : SetLightOn +//purpose : +//============================================================================= +void V3d_View::SetLightOn() +{ + for (MyViewer->InitDefinedLights(); MyViewer->MoreDefinedLights(); MyViewer->NextDefinedLights()) + { + if (!MyActiveLights.Contains (MyViewer->DefinedLight())) + { + MyActiveLights.Append (MyViewer->DefinedLight()); } } - MyView->SetContext(MyViewContext) ; - + UpdateLights(); } -void V3d_View::SetLightOff( ) { - +//============================================================================= +//function : SetLightOff +//purpose : +//============================================================================= +void V3d_View::SetLightOff() +{ InitActiveLights(); - while(MoreActiveLights()) { - if (!MyViewer->IsGlobalLight(ActiveLight())) { - MyActiveLights.Remove(ActiveLight()); - MyViewContext.SetLightOff(ActiveLight()->Light()); + while(MoreActiveLights()) + { + if (!MyViewer->IsGlobalLight (ActiveLight())) + { + MyActiveLights.Remove (ActiveLight()); } else + { NextActiveLights(); + } } - MyView->SetContext(MyViewContext) ; - + UpdateLights(); } -void V3d_View::InitActiveLights() { -myActiveLightsIterator.Initialize(MyActiveLights); +//============================================================================= +//function : InitActiveLights +//purpose : +//============================================================================= +void V3d_View::InitActiveLights() +{ + myActiveLightsIterator.Initialize(MyActiveLights); } -Standard_Boolean V3d_View::MoreActiveLights () const { + +//============================================================================= +//function : MoreActiveLights +//purpose : +//============================================================================= +Standard_Boolean V3d_View::MoreActiveLights() const +{ return myActiveLightsIterator.More(); } -void V3d_View::NextActiveLights () { + +//============================================================================= +//function : NextActiveLights +//purpose : +//============================================================================= +void V3d_View::NextActiveLights() +{ myActiveLightsIterator.Next(); } -Handle(V3d_Light) V3d_View::ActiveLight() const { - return (Handle(V3d_Light)&)(myActiveLightsIterator.Value());} -Standard_Boolean V3d_View::IfMoreLights() const { +//============================================================================= +//function : ActiveLight +//purpose : +//============================================================================= +Handle(V3d_Light) V3d_View::ActiveLight() const +{ + return (Handle(V3d_Light)&)(myActiveLightsIterator.Value()); +} + +//============================================================================= +//function : IfMoreLights +//purpose : +//============================================================================= +Standard_Boolean V3d_View::IfMoreLights() const +{ + return MyActiveLights.Extent() < LightLimit(); +} - return MyActiveLights.Extent() < MyView->LightLimit(); +//======================================================================= +//function : LightLimit +//purpose : +//======================================================================= +Standard_Integer V3d_View::LightLimit() const +{ + return Viewer()->Driver()->InquireLightLimit(); } //======================================================================= @@ -126,8 +185,9 @@ Standard_Boolean V3d_View::IfMoreLights() const { //======================================================================= void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) { - MyViewContext.ChangeClipPlanes().Append (thePlane); - MyView->SetContext (MyViewContext); + Graphic3d_SequenceOfHClipPlane aSeqOfPlanes = GetClipPlanes(); + aSeqOfPlanes.Append (thePlane); + SetClipPlanes (aSeqOfPlanes); } //======================================================================= @@ -136,7 +196,7 @@ void V3d_View::AddClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) //======================================================================= void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) { - Graphic3d_SequenceOfHClipPlane& aSeqOfPlanes = MyViewContext.ChangeClipPlanes(); + Graphic3d_SequenceOfHClipPlane aSeqOfPlanes = GetClipPlanes(); Graphic3d_SequenceOfHClipPlane::Iterator aPlaneIt (aSeqOfPlanes); for (; aPlaneIt.More(); aPlaneIt.Next()) { @@ -145,7 +205,7 @@ void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) continue; aSeqOfPlanes.Remove (aPlaneIt); - MyView->SetContext (MyViewContext); + SetClipPlanes (aSeqOfPlanes); return; } } @@ -156,8 +216,7 @@ void V3d_View::RemoveClipPlane (const Handle(Graphic3d_ClipPlane)& thePlane) //======================================================================= void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) { - MyViewContext.ChangeClipPlanes() = thePlanes; - MyView->SetContext (MyViewContext); + myView->SetClipPlanes (thePlanes); } //======================================================================= @@ -166,5 +225,14 @@ void V3d_View::SetClipPlanes (const Graphic3d_SequenceOfHClipPlane& thePlanes) //======================================================================= const Graphic3d_SequenceOfHClipPlane& V3d_View::GetClipPlanes() const { - return MyViewContext.ClipPlanes(); + return myView->ClipPlanes(); +} + +//======================================================================= +//function : PlaneLimit +//purpose : +//======================================================================= +Standard_Integer V3d_View::PlaneLimit() const +{ + return Viewer()->Driver()->InquirePlaneLimit(); } diff --git a/src/V3d/V3d_View_3.cxx b/src/V3d/V3d_View_3.cxx index cfd2178c3c..462c182f21 100644 --- a/src/V3d/V3d_View_3.cxx +++ b/src/V3d/V3d_View_3.cxx @@ -30,17 +30,24 @@ #include #include #include -#include -/*----------------------------------------------------------------------*/ -void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) { - +//============================================================================= +//function : Move +//purpose : +//============================================================================= +void V3d_View::Move (const Standard_Real Dx, + const Standard_Real Dy, + const Standard_Real Dz, + const Standard_Boolean Start) +{ + Handle(Graphic3d_Camera) aCamera = Camera(); + if( Start ) { - myCamStartOpEye = myCamera->Eye(); + myCamStartOpEye = aCamera->Eye(); - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); - gp_Dir anUp (myCamera->Up()); + gp_Dir aReferencePlane (aCamera->Direction().Reversed()); + gp_Dir anUp (aCamera->Up()); if (!ScreenAxis (aReferencePlane, anUp, myXscreenAxis, myYscreenAxis, myZscreenAxis)) { V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up"); @@ -53,40 +60,49 @@ void V3d_View::Move(const Standard_Real Dx, const Standard_Real Dy, const Standa myYscreenAxis.Coord (YX,YY,YZ); myZscreenAxis.Coord (ZX,ZY,ZZ); - myCamera->SetEye (myCamStartOpEye); + aCamera->SetEye (myCamStartOpEye); - myCamera->SetEye (myCamera->Eye().XYZ() + aCamera->SetEye (aCamera->Eye().XYZ() + Dx * gp_Pnt (XX, XY, XZ).XYZ() + Dy * gp_Pnt (YX, YY, YZ).XYZ() + Dz * gp_Pnt (ZX, ZY, ZZ).XYZ() ); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } -void V3d_View::Move(const Standard_Real Length, const Standard_Boolean Start) { +//============================================================================= +//function : Move +//purpose : +//============================================================================= +void V3d_View::Move (const Standard_Real Length, const Standard_Boolean Start) +{ + Handle(Graphic3d_Camera) aCamera = Camera(); - if( Start ) + if( Start ) { - myCamStartOpEye = myCamera->Eye(); + myCamStartOpEye = aCamera->Eye(); } - myCamera->SetEye (myCamStartOpEye); + aCamera->SetEye (myCamStartOpEye); Standard_Real Vx, Vy, Vz; MyDefaultViewAxis.Coord (Vx, Vy, Vz) ; - myCamera->SetEye (myCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ()); + aCamera->SetEye (aCamera->Eye().XYZ() + Length * gp_Pnt (Vx, Vy, Vz).XYZ()); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } -void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) { - - +//============================================================================= +//function : Move +//purpose : +//============================================================================= +void V3d_View::Move (const V3d_TypeOfAxe Axe , const Standard_Real Length, const Standard_Boolean Start) +{ switch (Axe) { case V3d_X : Move(Length,0.,0.,Start); @@ -100,15 +116,24 @@ void V3d_View::Move(const V3d_TypeOfAxe Axe , const Standard_Real Length, const } } -void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const Standard_Real Dz, const Standard_Boolean Start) { +//============================================================================= +//function : Translate +//purpose : +//============================================================================= +void V3d_View::Translate (const Standard_Real Dx, + const Standard_Real Dy, + const Standard_Real Dz, + const Standard_Boolean Start) +{ + Handle(Graphic3d_Camera) aCamera = Camera(); - if( Start ) + if( Start ) { - myCamStartOpEye = myCamera->Eye(); - myCamStartOpCenter = myCamera->Center(); + myCamStartOpEye = aCamera->Eye(); + myCamStartOpCenter = aCamera->Center(); - gp_Dir aReferencePlane (myCamera->Direction().Reversed()); - gp_Dir anUp (myCamera->Up()); + gp_Dir aReferencePlane (aCamera->Direction().Reversed()); + gp_Dir anUp (aCamera->Up()); if (!ScreenAxis (aReferencePlane, anUp, myXscreenAxis,myYscreenAxis,myZscreenAxis)) V3d_BadValue::Raise ("V3d_View::Translate, alignment of Eye,At,Up"); @@ -120,26 +145,30 @@ void V3d_View::Translate(const Standard_Real Dx, const Standard_Real Dy, const S myYscreenAxis.Coord (YX,YY,YZ); myZscreenAxis.Coord (ZX,ZY,ZZ); - myCamera->SetEye (myCamStartOpEye); - myCamera->SetCenter (myCamStartOpCenter); + aCamera->SetEye (myCamStartOpEye); + aCamera->SetCenter (myCamStartOpCenter); - myCamera->SetCenter (myCamera->Center().XYZ() + aCamera->SetCenter (aCamera->Center().XYZ() - Dx * gp_Pnt (XX, XY, XZ).XYZ() - Dy * gp_Pnt (YX, YY, YZ).XYZ() - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ() ); - myCamera->SetEye (myCamera->Eye().XYZ() + aCamera->SetEye (aCamera->Eye().XYZ() - Dx * gp_Pnt (XX, XY, XZ).XYZ() - Dy * gp_Pnt (YX, YY, YZ).XYZ() - Dz * gp_Pnt (ZX, ZY, ZZ).XYZ() ); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } +//============================================================================= +//function : Translate +//purpose : +//============================================================================= void V3d_View::Translate(const V3d_TypeOfAxe Axe, const Standard_Real Length,const Standard_Boolean Start) { switch (Axe) { @@ -172,18 +201,24 @@ void V3d_View::Place (const Standard_Integer theXp, Pan (aWinCXp - theXp, -(aWinCYp - theYp), theZoomFactor / Scale()); } -void V3d_View::Translate(const Standard_Real theLength, const Standard_Boolean theStart) { +//======================================================================= +//function : Place +//purpose : +//======================================================================= +void V3d_View::Translate (const Standard_Real theLength, const Standard_Boolean theStart) +{ + Handle(Graphic3d_Camera) aCamera = Camera(); - Standard_Real aVx, aVy, aVz ; + Standard_Real aVx, aVy, aVz; if (theStart) { - myCamStartOpCenter = myCamera->Center() ; + myCamStartOpCenter = aCamera->Center() ; } MyDefaultViewAxis.Coord (aVx, aVy, aVz); gp_Pnt aNewCenter (myCamStartOpCenter.XYZ() - gp_Pnt (aVx, aVy, aVz).XYZ() * theLength); - myCamera->SetCenter (aNewCenter); + aCamera->SetCenter (aNewCenter); - View()->AutoZFit(); + AutoZFit(); ImmediateUpdate(); } diff --git a/src/V3d/V3d_View_4.cxx b/src/V3d/V3d_View_4.cxx index 7c2e9ad0f0..1d26602faa 100644 --- a/src/V3d/V3d_View_4.cxx +++ b/src/V3d/V3d_View_4.cxx @@ -35,13 +35,14 @@ #include #include #include -#include #define MYEPSILON1 0.0001 // Comparison with 0.0 #define MYEPSILON2 M_PI / 180. // Delta between 2 angles -/*----------------------------------------------------------------------*/ - +//============================================================================= +//function : SetGrid +//purpose : +//============================================================================= void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid) { MyPlane = aPlane; @@ -112,17 +113,20 @@ void V3d_View::SetGrid (const gp_Ax3& aPlane, const Handle(Aspect_Grid)& aGrid) } } +//============================================================================= +//function : SetGridActivity +//purpose : +//============================================================================= void V3d_View::SetGridActivity (const Standard_Boolean AFlag) { if (AFlag) MyGrid->Activate (); else MyGrid->Deactivate (); } -void V3d_View::SetGridGraphicValues (const Handle(Aspect_Grid)& ) -{ -} - - +//============================================================================= +//function : toPolarCoords +//purpose : +//============================================================================= void toPolarCoords (const Standard_Real theX, const Standard_Real theY, Standard_Real& theR, Standard_Real& thePhi) { @@ -130,6 +134,10 @@ void toPolarCoords (const Standard_Real theX, const Standard_Real theY, thePhi = ATan2 (theY, theX); } +//============================================================================= +//function : toCartesianCoords +//purpose : +//============================================================================= void toCartesianCoords (const Standard_Real theR, const Standard_Real thePhi, Standard_Real& theX, Standard_Real& theY) { @@ -137,13 +145,18 @@ void toCartesianCoords (const Standard_Real theR, const Standard_Real thePhi, theY = theR * Sin (thePhi); } +//============================================================================= +//function : Compute +//purpose : +//============================================================================= Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const { Graphic3d_Vertex CurPoint, NewPoint; Standard_Real X1, Y1, Z1, X2, Y2, Z2; Standard_Real XPp, YPp; + Handle(Graphic3d_Camera) aCamera = Camera(); - gp_Dir aRefPlane = myCamera->Direction().Reversed(); + gp_Dir aRefPlane = aCamera->Direction().Reversed(); X1 = aRefPlane.X(); Y1 = aRefPlane.Y(); Z1 = aRefPlane.Z(); MyPlane.Direction ().Coord (X2, Y2, Z2); @@ -193,9 +206,9 @@ Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const AVertex.Coord (x1, y1, z1); // project ray from camera onto grid plane - gp_Vec aProjection = myCamera->IsOrthographic() - ? gp_Vec (myCamera->Direction()) - : gp_Vec (myCamera->Eye(), gp_Pnt (x1, y1, z1)).Normalized(); + gp_Vec aProjection = aCamera->IsOrthographic() + ? gp_Vec (aCamera->Direction()) + : gp_Vec (aCamera->Eye(), gp_Pnt (x1, y1, z1)).Normalized(); gp_Vec aPointOrigin = gp_Vec (gp_Pnt (x1, y1, z1), gp_Pnt (x0, y0, z0)); Standard_Real aT = aPointOrigin.Dot (aPlaneNormal) / aProjection.Dot (aPlaneNormal); aPointOnPlane = gp_Vec (x1, y1, z1) + aProjection * aT; @@ -249,45 +262,78 @@ Graphic3d_Vertex V3d_View::Compute (const Graphic3d_Vertex & AVertex) const return NewPoint; } -// Triedron methods : the Triedron is a non-zoomable object. - -void V3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor XColor, - const Quantity_NameOfColor YColor, - const Quantity_NameOfColor ZColor, - const Standard_Real SizeRatio, - const Standard_Real AxisDiametr, - const Standard_Integer NbFacettes) +//============================================================================= +//function : ZBufferTriedronSetup +//purpose : +//============================================================================= +void V3d_View::ZBufferTriedronSetup(const Quantity_NameOfColor theXColor, + const Quantity_NameOfColor theYColor, + const Quantity_NameOfColor theZColor, + const Standard_Real theSizeRatio, + const Standard_Real theAxisDiametr, + const Standard_Integer theNbFacettes) { - MyView->ZBufferTriedronSetup(XColor, YColor, ZColor, SizeRatio, AxisDiametr, NbFacettes); + myView->ZBufferTriedronSetup (theXColor, + theYColor, + theZColor, + theSizeRatio, + theAxisDiametr, + theNbFacettes); } -void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition, - const Quantity_NameOfColor AColor, const Standard_Real AScale, const V3d_TypeOfVisualization AMode ) +//============================================================================= +//function : TriedronDisplay +//purpose : +//============================================================================= +void V3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, + const Quantity_NameOfColor theColor, + const Standard_Real theScale, + const V3d_TypeOfVisualization theMode) { - MyView->TriedronDisplay (APosition, AColor, AScale, (AMode == V3d_WIREFRAME)); + myView->TriedronDisplay (thePosition, theColor, theScale, (theMode == V3d_WIREFRAME)); } -void V3d_View::TriedronErase ( ) +//============================================================================= +//function : TriedronErase +//purpose : +//============================================================================= +void V3d_View::TriedronErase() { - MyView->TriedronErase ( ); + myView->TriedronErase(); } -void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho AType ) +//============================================================================= +//function : TriedronEcho +//purpose : +//============================================================================= +void V3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType) { - MyView->TriedronEcho (AType); + myView->TriedronEcho (theType); } +//============================================================================= +//function : GetGraduatedTrihedron +//purpose : +//============================================================================= const Graphic3d_GraduatedTrihedron& V3d_View::GetGraduatedTrihedron() const { - return MyView->GetGraduatedTrihedron(); + return myView->GetGraduatedTrihedron(); } +//============================================================================= +//function : GraduatedTrihedronDisplay +//purpose : +//============================================================================= void V3d_View::GraduatedTrihedronDisplay(const Graphic3d_GraduatedTrihedron& theTrihedronData) { - MyView->GraduatedTrihedronDisplay(theTrihedronData); + myView->GraduatedTrihedronDisplay (theTrihedronData); } +//============================================================================= +//function : GraduatedTrihedronErase +//purpose : +//============================================================================= void V3d_View::GraduatedTrihedronErase() { - MyView->GraduatedTrihedronErase(); + myView->GraduatedTrihedronErase(); } diff --git a/src/V3d/V3d_View_5.cxx b/src/V3d/V3d_View_5.cxx index 1f4feedabc..43379e54e2 100644 --- a/src/V3d/V3d_View_5.cxx +++ b/src/V3d/V3d_View_5.cxx @@ -42,26 +42,39 @@ #include #include #include -#include -//BUC61044 25/10/01 SAV ; added functionality to control gl depth testing from higher API -//BUC61045 25/10/01 SAV ; added functionality to control gl lighting from higher API -void V3d_View::EnableGLLight( const Standard_Boolean enable ) const +//============================================================================= +//function : EnableGLLight +//purpose : +//============================================================================= +void V3d_View::EnableGLLight (const Standard_Boolean theIsEnabled) const { - MyView->EnableGLLight( enable ); + myView->SetGLLightEnabled (theIsEnabled); } +//============================================================================= +//function : IsGLLightEnabled +//purpose : +//============================================================================= Standard_Boolean V3d_View::IsGLLightEnabled() const { - return MyView->IsGLLightEnabled(); + return myView->IsGLLightEnabled(); } +//============================================================================= +//function : RenderingParams +//purpose : +//============================================================================= const Graphic3d_RenderingParams& V3d_View::RenderingParams() const { - return static_cast (MyView->CView())->RenderParams; + return myView->RenderingParams(); } +//============================================================================= +//function : ChangeRenderingParams +//purpose : +//============================================================================= Graphic3d_RenderingParams& V3d_View::ChangeRenderingParams() { - return static_cast (MyView->CView())->RenderParams; + return myView->ChangeRenderingParams(); } diff --git a/src/V3d/V3d_View_Print.cxx b/src/V3d/V3d_View_Print.cxx index af7722cf66..c0316af23e 100644 --- a/src/V3d/V3d_View_Print.cxx +++ b/src/V3d/V3d_View_Print.cxx @@ -43,7 +43,6 @@ #include #include #include -#include #ifdef WNT struct Device @@ -79,63 +78,61 @@ Device::~Device() } #endif -/************************************************************************/ -/* Print Method */ -/************************************************************************/ - -Standard_Boolean V3d_View::Print (const Aspect_Handle hPrnDC, - const Standard_Boolean showDialog, - const Standard_Boolean showBackground, - const Standard_CString filename, - const Aspect_PrintAlgo printAlgorithm) const +//============================================================================= +//function : SetGrid +//purpose : +//============================================================================= +Standard_Boolean V3d_View::Print (const Aspect_Handle thePrintDC, + const Standard_Boolean theShowDialog, + const Standard_Boolean theShowBackground, + const Standard_CString theFilename, + const Aspect_PrintAlgo thePrintAlgorithm) const { #ifdef WNT - if( MyView->IsDefined() ) - { - if (hPrnDC != NULL) - { - return MyView->Print(hPrnDC, showBackground, - filename, printAlgorithm) ; - - } - - if (device._pd.hDC == NULL || showDialog ) - { - if (device._pd.hDC) - DeleteDC(device._pd.hDC); - if ( !showDialog ) - { - device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT; - } - else - { - device._pd.Flags = PD_RETURNDC | PD_NOSELECTION; - } - - BOOL ispd; - ispd = PrintDlg((LPPRINTDLG)(&(device._pd))); - - if (!ispd) - { - return Standard_False; - } - - if (!(device._pd.hDC)) - { - if (device._pd.hDevNames) - { - GlobalFree(device._pd.hDevNames); - device._pd.hDevNames = NULL; - } - if (device._pd.hDevMode) - { - GlobalFree(device._pd.hDevMode); - device._pd.hDevMode = NULL; - } - MessageBox(0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP); - return Standard_False; - } - } + if (myView->IsDefined()) + { + if (thePrintDC != NULL) + { + return myView->Print (thePrintDC, theShowBackground, theFilename, thePrintAlgorithm); + } + + if (device._pd.hDC == NULL || theShowDialog) + { + if (device._pd.hDC) + DeleteDC (device._pd.hDC); + if (!theShowDialog) + { + device._pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_RETURNDEFAULT; + } + else + { + device._pd.Flags = PD_RETURNDC | PD_NOSELECTION; + } + + BOOL ispd; + ispd = PrintDlg((LPPRINTDLG)(&(device._pd))); + + if (!ispd) + { + return Standard_False; + } + + if (!(device._pd.hDC)) + { + if (device._pd.hDevNames) + { + GlobalFree (device._pd.hDevNames); + device._pd.hDevNames = NULL; + } + if (device._pd.hDevMode) + { + GlobalFree (device._pd.hDevMode); + device._pd.hDevMode = NULL; + } + MessageBox (0, "Couldn't create Printer Device Context", "Error", MB_OK | MB_ICONSTOP); + return Standard_False; + } + } // process scale factor accordingly to the new printing approach DEVMODE* aMode = (LPDEVMODE)GlobalLock(device._pd.hDevMode); @@ -143,11 +140,10 @@ Standard_Boolean V3d_View::Print (const Aspect_Handle hPrnDC, // convert percents to multiplication factor, 100% = 1.0 Standard_Real aScaleFactor = (Standard_Real) aMode->dmScale / 100.0; GlobalUnlock (device._pd.hDevMode); - return MyView->Print(device._pd.hDC, showBackground, - filename, printAlgorithm, aScaleFactor) ; - } + return myView->Print (device._pd.hDC, theShowBackground, theFilename, thePrintAlgorithm, aScaleFactor); + } #else - Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows"); + Standard_NotImplemented::Raise ("V3d_View::Print is implemented only on Windows"); #endif return Standard_False; } diff --git a/src/V3d/V3d_Viewer.cxx b/src/V3d/V3d_Viewer.cxx index a3f69aa01b..497ad06a34 100644 --- a/src/V3d/V3d_Viewer.cxx +++ b/src/V3d/V3d_Viewer.cxx @@ -15,12 +15,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -29,12 +31,11 @@ #include #include #include -#include -#include -#include -/*----------------------------------------------------------------------*/ -//-Constructor: +// ======================================================================== +// function : V3d_Viewer +// purpose : +// ======================================================================== V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver, const Standard_ExtString theName, const Standard_CString theDomain, @@ -51,6 +52,7 @@ V3d_Viewer::V3d_Viewer (const Handle(Graphic3d_GraphicDriver)& theDriver, myDriver (theDriver), myName (TCollection_ExtendedString (theName)), myDomain (TCollection_AsciiString (theDomain)), +myStructureManager (new Graphic3d_StructureManager (theDriver)), MyDefinedViews(), MyActiveViews(), MyDefinedLights(), @@ -65,13 +67,9 @@ myPrivilegedPlane (gp_Ax3 (gp_Pnt (0.,0.,0), gp_Dir (0.,0.,1.), gp_Dir (1.,0.,0. myDisplayPlane (Standard_False), myDisplayPlaneLength (theViewSize), myGridEcho (Standard_True), -myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast()) +myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast()), +myZLayerGenId (1, IntegerLast()) { - MyViewer = new Visual3d_ViewManager (theDriver); - // san (16/09/2010): It has been decided to turn depth test ON - // by default, as this is important for new font rendering - // (without it, there are numerous texture rendering artefacts) - MyViewer->SetZBufferAuto (Standard_False); SetUpdateMode (theUpdateMode); SetDefaultViewSize (theViewSize); SetDefaultViewProj (theViewProj); @@ -90,92 +88,169 @@ myGridEchoLastVert (ShortRealLast(), ShortRealLast(), ShortRealLast()) myGridType = Aspect_GT_Rectangular; } -//-Methods, in order - - +// ======================================================================== +// function : CreateView +// purpose : +// ======================================================================== Handle(V3d_View) V3d_Viewer::CreateView () { return new V3d_View(this, MyDefaultTypeOfView); } -void V3d_Viewer::SetViewOn( ) { - - for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ - SetViewOn(ActiveView());}; +// ======================================================================== +// function : SetViewOn +// purpose : +// ======================================================================== +void V3d_Viewer::SetViewOn() +{ + for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()) + { + SetViewOn (ActiveView()); + } } -void V3d_Viewer::SetViewOff( ) { - - for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()){ - SetViewOff(ActiveView());}; +// ======================================================================== +// function : SetViewOff +// purpose : +// ======================================================================== +void V3d_Viewer::SetViewOff() +{ + for (InitDefinedViews();MoreDefinedViews();NextDefinedViews()) + { + SetViewOff (ActiveView()); + } } -void V3d_Viewer::SetViewOn( const Handle(V3d_View)& TheView ) { - - Handle(Visual3d_View) MyView = TheView->View() ; - if( MyView->IsDefined() && !IsActive(TheView)) { - MyActiveViews.Append(TheView) ; - MyView->Activate(); - for (InitActiveLights();MoreActiveLights();NextActiveLights()){ - TheView->SetLightOn(ActiveLight());} - // Grid - TheView->SetGrid (myPrivilegedPlane, Grid ()); - TheView->SetGridActivity (Grid ()->IsActive ()); - // Update - MyView->Redraw() ; +// ======================================================================== +// function : SetViewOn +// purpose : +// ======================================================================== +void V3d_Viewer::SetViewOn (const Handle(V3d_View)& theView) +{ + Handle(Graphic3d_CView) aViewImpl = theView->View(); + if (aViewImpl->IsDefined() && !IsActive (theView)) + { + MyActiveViews.Append (theView); + aViewImpl->Activate(); + for (InitActiveLights();MoreActiveLights();NextActiveLights()) + { + theView->SetLightOn (ActiveLight()); + } + + theView->SetGrid (myPrivilegedPlane, Grid ()); + theView->SetGridActivity (Grid ()->IsActive ()); + theView->Redraw(); } } -void V3d_Viewer::SetViewOff( const Handle(V3d_View)& TheView ) { - - Handle(Visual3d_View) MyView =TheView->View(); - if( MyView->IsDefined() && IsActive(TheView) ) { - MyActiveViews.Remove(TheView); - MyView->Deactivate() ; +// ======================================================================== +// function : SetViewOff +// purpose : +// ======================================================================== +void V3d_Viewer::SetViewOff (const Handle(V3d_View)& theView) +{ + Handle(Graphic3d_CView) aViewImpl = theView->View(); + if (aViewImpl->IsDefined() && IsActive (theView)) + { + MyActiveViews.Remove (theView); + aViewImpl->Deactivate() ; } } -Standard_Boolean V3d_Viewer::ComputedMode() const { +// ======================================================================== +// function : ComputedMode +// purpose : +// ======================================================================== +Standard_Boolean V3d_Viewer::ComputedMode() const +{ return myComputedMode; } -Standard_Boolean V3d_Viewer::DefaultComputedMode() const { +// ======================================================================== +// function : DefaultComputedMode +// purpose : +// ======================================================================== +Standard_Boolean V3d_Viewer::DefaultComputedMode() const +{ return myDefaultComputedMode; } +// ======================================================================== +// function : Update +// purpose : +// ======================================================================== void V3d_Viewer::Update() { - MyViewer->Update(); + // Redraw() is still here for compatibility with old code. + // See comments, the method is deprecated - Redraw() should + // be used instead. + Redraw(); } +// ======================================================================== +// function : Redraw +// purpose : +// ======================================================================== void V3d_Viewer::Redraw()const { - MyViewer->Redraw(); + TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); + for (; anIt.More(); anIt.Next()) + { + Handle(V3d_View)::DownCast (anIt.Value())->Redraw(); + } } +// ======================================================================== +// function : RedrawImmediate +// purpose : +// ======================================================================== void V3d_Viewer::RedrawImmediate() const { - MyViewer->RedrawImmediate(); + TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); + for (; anIt.More(); anIt.Next()) + { + Handle(V3d_View)::DownCast (anIt.Value())->RedrawImmediate(); + } } +// ======================================================================== +// function : Invalidate +// purpose : +// ======================================================================== void V3d_Viewer::Invalidate() const { - MyViewer->Invalidate(); + TColStd_ListIteratorOfListOfTransient anIt (MyDefinedViews); + for (; anIt.More(); anIt.Next()) + { + Handle(V3d_View)::DownCast (anIt.Value())->Invalidate(); + } } -void V3d_Viewer::Remove() { - - MyViewer->Remove(); +// ======================================================================== +// function : Remove +// purpose : +// ======================================================================== +void V3d_Viewer::Remove() +{ + myStructureManager->Remove(); } -void V3d_Viewer::Erase() const { - - MyViewer->Erase(); +// ======================================================================== +// function : Erase +// purpose : +// ======================================================================== +void V3d_Viewer::Erase() const +{ + myStructureManager->Erase(); } -void V3d_Viewer::UnHighlight() const { - - //FMN MyViewer->UnHighlight(); +// ======================================================================== +// function : UnHighlight +// purpose : +// ======================================================================== +void V3d_Viewer::UnHighlight() const +{ + myStructureManager->UnHighlight(); } void V3d_Viewer::SetDefaultBackgroundColor(const Quantity_TypeOfColor Type, const Standard_Real v1, const Standard_Real v2, const Standard_Real v3) { @@ -236,12 +311,6 @@ void V3d_Viewer::SetDefaultVisualization(const V3d_TypeOfVisualization Type) { MyVisualization = Type ; } -void V3d_Viewer::SetZBufferManagment(const Standard_Boolean Automatic) { - MyViewer->SetZBufferAuto (Automatic); -} -Standard_Boolean V3d_Viewer::ZBufferManagment() const { - return MyViewer->ZBufferAuto(); -} void V3d_Viewer::SetDefaultShadingModel(const V3d_TypeOfShadingModel Type) { @@ -260,10 +329,13 @@ void V3d_Viewer::SetDefaultAngle(const Quantity_PlaneAngle Angle) { void V3d_Viewer::SetDefaultTypeOfView(const V3d_TypeOfView Type) { MyDefaultTypeOfView = Type;} - -void V3d_Viewer::SetUpdateMode(const V3d_TypeOfUpdate Mode) { - - MyViewer->SetUpdateMode((Aspect_TypeOfUpdate)Mode) ; +// ======================================================================== +// function : SetUpdateMode +// purpose : +// ======================================================================== +void V3d_Viewer::SetUpdateMode (const V3d_TypeOfUpdate theMode) +{ + myStructureManager->SetUpdateMode (static_cast (theMode)); } void V3d_Viewer::DefaultBackgroundColor(const Quantity_TypeOfColor Type,Standard_Real &V1,Standard_Real &V2,Standard_Real &V3) const @@ -306,24 +378,32 @@ Quantity_PlaneAngle V3d_Viewer::DefaultAngle() const { return MyDefaultAngle; } -V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const { - - V3d_TypeOfUpdate Mode = (V3d_TypeOfUpdate) MyViewer->UpdateMode() ; - return Mode ; +// ======================================================================== +// function : UpdateMode +// purpose : +// ======================================================================== +V3d_TypeOfUpdate V3d_Viewer::UpdateMode() const +{ + return static_cast (myStructureManager->UpdateMode()); } Standard_Boolean V3d_Viewer::IfMoreViews() const { Standard_Boolean TheStatus = Standard_False ; #ifdef NEW - if( MyActiveViews->Length() < Visual3d_View::Limit() ) + if (MyActiveViews->Length() < myDriver->InquireViewLimit()) #endif /*NEW*/ TheStatus = Standard_True ; return TheStatus ; } -Handle(Visual3d_ViewManager) V3d_Viewer::Viewer() const { - return MyViewer ; +// ======================================================================== +// function : StructureManager +// purpose : +// ======================================================================== +Handle(Graphic3d_StructureManager) V3d_Viewer::StructureManager() const +{ + return myStructureManager; } Aspect_Background V3d_Viewer::GetBackgroundColor() const { @@ -347,61 +427,79 @@ void V3d_Viewer::DelView( const Handle(V3d_View)& TheView ) { } //======================================================================= -//function : SetZLayerSettings +//function : AddZLayer //purpose : //======================================================================= - -void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, - const Graphic3d_ZLayerSettings& theSettings) +Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) { - MyViewer->SetZLayerSettings (theLayerId, theSettings); + try + { + OCC_CATCH_SIGNALS + theLayerId = myZLayerGenId.Next(); + } + catch (Aspect_IdentDefinitionError) + { + // new index can't be generated + return Standard_False; + } + + myLayerIds.Add (theLayerId); + myDriver->AddZLayer (theLayerId); + + return Standard_True; } //======================================================================= -//function : ZLayerSettings -//purpose : +//function : RemoveZLayer +//purpose : //======================================================================= - -Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId) +Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) { - return MyViewer->ZLayerSettings (theLayerId); + if (!myLayerIds.Contains (theLayerId) + || theLayerId < myZLayerGenId.Lower() + || theLayerId > myZLayerGenId.Upper()) + { + return Standard_False; + } + + myDriver->RemoveZLayer (theLayerId); + myLayerIds.Remove (theLayerId); + myZLayerGenId.Free (theLayerId); + + return Standard_True; } //======================================================================= -//function : AddZLayer +//function : GetAllZLayers //purpose : //======================================================================= - -Standard_Boolean V3d_Viewer::AddZLayer (Standard_Integer& theLayerId) +void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const { - return MyViewer->AddZLayer (theLayerId); + myDriver->ZLayers (theLayerSeq); } //======================================================================= -//function : RemoveZLayer -//purpose : +//function : SetZLayerSettings +//purpose : //======================================================================= - -Standard_Boolean V3d_Viewer::RemoveZLayer (const Standard_Integer theLayerId) +void V3d_Viewer::SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings) { - return MyViewer->RemoveZLayer (theLayerId); + myDriver->SetZLayerSettings (theLayerId, theSettings); } //======================================================================= -//function : GetAllZLayers +//function : ZLayerSettings //purpose : //======================================================================= - -void V3d_Viewer::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const +Graphic3d_ZLayerSettings V3d_Viewer::ZLayerSettings (const Standard_Integer theLayerId) { - MyViewer->GetAllZLayers (theLayerSeq); + return myDriver->ZLayerSettings (theLayerId); } //======================================================================= //function : Domain //purpose : //======================================================================= - Standard_CString V3d_Viewer::Domain() const { return myDomain.ToCString(); @@ -411,7 +509,6 @@ Standard_CString V3d_Viewer::Domain() const //function : Driver //purpose : //======================================================================= - const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const { return myDriver; @@ -421,7 +518,6 @@ const Handle(Graphic3d_GraphicDriver)& V3d_Viewer::Driver() const //function : NextName //purpose : //======================================================================= - Standard_ExtString V3d_Viewer::NextName() const { TCollection_ExtendedString aNextName = TCollection_ExtendedString (myName.ToExtString()); @@ -434,7 +530,6 @@ Standard_ExtString V3d_Viewer::NextName() const //function : IncrCount //purpose : //======================================================================= - void V3d_Viewer::IncrCount() { myNextCount++; diff --git a/src/V3d/V3d_Viewer.hxx b/src/V3d/V3d_Viewer.hxx index 26973b2d0c..29fcb98fab 100644 --- a/src/V3d/V3d_Viewer.hxx +++ b/src/V3d/V3d_Viewer.hxx @@ -17,55 +17,59 @@ #ifndef _V3d_Viewer_HeaderFile #define _V3d_Viewer_HeaderFile +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + #include +#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include #include +#include + #include -#include -#include -#include #include -#include #include #include -#include +#include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + #include -#include -#include +#include #include -#include -#include -#include -#include +#include +#include + +class Aspect_Grid; +class Graphic3d_AspectMarker3d; class Graphic3d_GraphicDriver; -class Visual3d_ViewManager; -class V3d_Light; -class Graphic3d_Structure; -class V3d_RectangularGrid; -class V3d_CircularGrid; class Graphic3d_Group; -class Graphic3d_AspectMarker3d; +class Graphic3d_Structure; class V3d_BadValue; +class V3d_CircularGrid; +class V3d_Light; +class V3d_RectangularGrid; class V3d_View; class Quantity_Color; -class gp_Ax3; -class Aspect_Grid; -class Aspect_Background; -class Aspect_GradientBackground; - class V3d_Viewer; DEFINE_STANDARD_HANDLE(V3d_Viewer, MMgt_TShared) @@ -169,23 +173,9 @@ public: //! in the viewer. Standard_EXPORT void SetDefaultViewProj (const V3d_TypeOfOrientation Orientation); - //! Gives the default visualisation mode.. + //! Gives the default visualization mode.. Standard_EXPORT void SetDefaultVisualization (const V3d_TypeOfVisualization Type); - - //! defines the strategy concerning the ZBuffer activity. - //! If Automatic is true, ZBuffer will be activated or - //! deactivated depending on the fact that faces exist or - //! not in the Viewer. This will optimize the response time - //! in the case where only wireframe objects are displayed. - //! If Automatic is False, ZBuffer will be activated or - //! deactivated depending on the choice of SetVisualization - //! in each View. - //! Note that by default, the ZBufferManagment is not automatic. - Standard_EXPORT void SetZBufferManagment (const Standard_Boolean Automatic); - - //! returns the ZBuffer stategy choice. - Standard_EXPORT Standard_Boolean ZBufferManagment() const; - + //! Gives the default type of SHADING. Standard_EXPORT void SetDefaultShadingModel (const V3d_TypeOfShadingModel Type); @@ -198,7 +188,7 @@ public: //! up the viewer. This can be immediate or //! deferred . In this latter case, the views are //! updated when the method Update(me) is called. - Standard_EXPORT void SetUpdateMode (const V3d_TypeOfUpdate Mode); + Standard_EXPORT void SetUpdateMode (const V3d_TypeOfUpdate theMode); Standard_EXPORT void SetDefaultTypeOfView (const V3d_TypeOfView Type); @@ -214,7 +204,7 @@ public: //! Activates all the lights defined in this viewer. Standard_EXPORT void SetLightOn(); - //! Desactivate MyLight in this viewer. + //! Deactivates MyLight in this viewer. Standard_EXPORT void SetLightOff (const Handle(V3d_Light)& MyLight); //! Deactivate all the Lights defined in this viewer. @@ -314,8 +304,8 @@ public: Standard_EXPORT Handle(V3d_Light) DefinedLight() const; - //! Returns the viewer associated to Visual3d . - Standard_EXPORT Handle(Visual3d_ViewManager) Viewer() const; + //! Returns the structure manager associated to this viewer. + Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const; //! Returns the Selected Light. Standard_EXPORT Handle(V3d_Light) CurrentSelectedLight() const; @@ -417,13 +407,7 @@ public: //! Temporarly hide grid echo. Standard_EXPORT void HideGridEcho (const Handle(V3d_View)& theView); - - //! Sets the settings for a single Z layer. - Standard_EXPORT void SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings); - - //! Returns the settings of a single Z layer. - Standard_EXPORT Graphic3d_ZLayerSettings ZLayerSettings (const Standard_Integer theLayerId); - + //! Add a new top-level Z layer to all managed views and get //! its ID as value. The Z layers are controlled entirely //! by viewer, it is not possible to add a layer to a @@ -431,41 +415,41 @@ public: //! not be created. The layer mechanism allows to display structures //! in higher layers in overlay of structures in lower layers. Standard_EXPORT Standard_Boolean AddZLayer (Standard_Integer& theLayerId); - + //! Remove Z layer with ID . Method returns //! Standard_False if the layer can not be removed or doesn't exists. //! By default, there are always default bottom-level layer that can't //! be removed. Standard_EXPORT Standard_Boolean RemoveZLayer (const Standard_Integer theLayerId); - + //! Return all Z layer ids in sequence ordered by overlay level //! from lowest layer to highest ( foreground ). The first layer ID //! in sequence is the default layer that can't be removed. Standard_EXPORT void GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const; - + + //! Sets the settings for a single Z layer. + Standard_EXPORT void SetZLayerSettings (const Standard_Integer theLayerId, const Graphic3d_ZLayerSettings& theSettings); + + //! Returns the settings of a single Z layer. + Standard_EXPORT Graphic3d_ZLayerSettings ZLayerSettings (const Standard_Integer theLayerId); + Standard_EXPORT const Handle(Graphic3d_GraphicDriver)& Driver() const; - + Standard_EXPORT Standard_ExtString NextName() const; - - Standard_EXPORT Standard_CString Domain() const; + Standard_EXPORT Standard_CString Domain() const; friend class V3d_View; friend class V3d_Light; - DEFINE_STANDARD_RTTI(V3d_Viewer,MMgt_TShared) protected: - Standard_EXPORT void IncrCount(); - - private: - //! Returns the default background colour. Standard_EXPORT Aspect_Background GetBackgroundColor() const; @@ -480,11 +464,13 @@ private: Standard_EXPORT Standard_Boolean IsActive (const Handle(V3d_View)& aView) const; +private: + Standard_Integer myNextCount; Handle(Graphic3d_GraphicDriver) myDriver; TCollection_ExtendedString myName; TCollection_AsciiString myDomain; - Handle(Visual3d_ViewManager) MyViewer; + Handle(Graphic3d_StructureManager) myStructureManager; V3d_ListOfTransient MyDefinedViews; V3d_ListOfTransient MyActiveViews; V3d_ListOfTransient MyDefinedLights; @@ -517,14 +503,8 @@ private: Handle(Graphic3d_Group) myGridEchoGroup; Handle(Graphic3d_AspectMarker3d) myGridEchoAspect; Graphic3d_Vertex myGridEchoLastVert; - - + TColStd_MapOfInteger myLayerIds; + Aspect_GenId myZLayerGenId; }; - - - - - - #endif // _V3d_Viewer_HeaderFile diff --git a/src/V3d/V3d_Viewer_1.cxx b/src/V3d/V3d_Viewer_1.cxx index 7020697ec5..e1d8220d0e 100644 --- a/src/V3d/V3d_Viewer_1.cxx +++ b/src/V3d/V3d_Viewer_1.cxx @@ -28,7 +28,6 @@ #include #include #include -#include void V3d_Viewer::InitActiveViews() { myActiveViewsIterator.Initialize(MyActiveViews); diff --git a/src/V3d/V3d_Viewer_2.cxx b/src/V3d/V3d_Viewer_2.cxx index ef0e60c65e..df66692001 100644 --- a/src/V3d/V3d_Viewer_2.cxx +++ b/src/V3d/V3d_Viewer_2.cxx @@ -31,8 +31,6 @@ #include #include #include -#include -#include void V3d_Viewer::UpdateLights() { @@ -45,7 +43,7 @@ void V3d_Viewer::SetLightOn( const Handle(V3d_Light)& TheLight ) { if(!MyActiveLights.Contains(TheLight)) { -// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(), +// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyDriver->InquireLightLimit(), // "too many lights"); MyActiveLights.Append(TheLight) ; } @@ -66,7 +64,7 @@ void V3d_Viewer::SetLightOn() { for (InitDefinedLights();MoreDefinedLights();NextDefinedLights()) { if(!MyActiveLights.Contains(DefinedLight())) { -// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= Visual3d_Light::Limit(), +// V3d_BadValue_Raise_if( MyActiveLights.Extent() >= MyDriver->InquireLightLimit(), // "too many lights"); MyActiveLights.Append(DefinedLight()); for (InitActiveViews();MoreActiveViews();NextActiveViews()) { diff --git a/src/V3d/V3d_Viewer_3.cxx b/src/V3d/V3d_Viewer_3.cxx index e2c2075c31..f7f661f65f 100644 --- a/src/V3d/V3d_Viewer_3.cxx +++ b/src/V3d/V3d_Viewer_3.cxx @@ -49,7 +49,6 @@ #include #include #include -#include /*----------------------------------------------------------------------*/ /* @@ -104,7 +103,7 @@ void V3d_Viewer::DisplayPrivilegedPlane(const Standard_Boolean OnOff, const Quan if(myDisplayPlane) { if(myPlaneStructure.IsNull()) { - myPlaneStructure = new Graphic3d_Structure(MyViewer); + myPlaneStructure = new Graphic3d_Structure(StructureManager()); myPlaneStructure->SetInfiniteState(Standard_True); myPlaneStructure->Display(); } diff --git a/src/V3d/V3d_Viewer_4.cxx b/src/V3d/V3d_Viewer_4.cxx index 2bbafa3ef2..0d782eff3f 100644 --- a/src/V3d/V3d_Viewer_4.cxx +++ b/src/V3d/V3d_Viewer_4.cxx @@ -28,8 +28,6 @@ #include #include #include -#include -#include // ======================================================================= // function : Grid @@ -206,10 +204,6 @@ void V3d_Viewer::SetRectangularGridGraphicValues (const Quantity_Length theXSize const Quantity_Length theOffSet) { myRGrid->SetGraphicValues (theXSize, theYSize, theOffSet); - for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) - { - ActiveView()->SetGridGraphicValues (myRGrid); - } Update(); } @@ -231,10 +225,6 @@ void V3d_Viewer::SetCircularGridGraphicValues (const Quantity_Length theRadius, const Quantity_Length theOffSet) { myCGrid->SetGraphicValues (theRadius, theOffSet); - for (InitActiveViews(); MoreActiveViews(); NextActiveViews()) - { - ActiveView()->SetGridGraphicValues (myCGrid); - } Update(); } @@ -267,7 +257,7 @@ void V3d_Viewer::SetGridEcho (const Handle(Graphic3d_AspectMarker3d)& theMarker) { if (myGridEchoStructure.IsNull()) { - myGridEchoStructure = new Graphic3d_Structure (Viewer()); + myGridEchoStructure = new Graphic3d_Structure (StructureManager()); myGridEchoGroup = myGridEchoStructure->NewGroup(); } @@ -298,7 +288,7 @@ void V3d_Viewer::ShowGridEcho (const Handle(V3d_View)& theView, if (myGridEchoStructure.IsNull()) { - myGridEchoStructure = new Graphic3d_Structure (Viewer()); + myGridEchoStructure = new Graphic3d_Structure (StructureManager()); myGridEchoGroup = myGridEchoStructure->NewGroup(); myGridEchoAspect = new Graphic3d_AspectMarker3d (Aspect_TOM_STAR, Quantity_Color (Quantity_NOC_GRAY90), 3.0); diff --git a/src/ViewerTest/ViewerTest_ObjectCommands.cxx b/src/ViewerTest/ViewerTest_ObjectCommands.cxx index e93e7018f4..a83f43d849 100644 --- a/src/ViewerTest/ViewerTest_ObjectCommands.cxx +++ b/src/ViewerTest/ViewerTest_ObjectCommands.cxx @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index 738ccc6465..5269f20c83 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -428,8 +427,8 @@ static int VImmediateFront (Draw_Interpretor& /*theDI*/, return 1; } - Graphic3d_CView* aCView = (Graphic3d_CView* )(ViewerTest::CurrentView()->View()->CView()); - aDriver->SetImmediateModeDrawToFront (*aCView, atoi(theArgVec[1]) != 0); + ViewerTest::CurrentView()->View()->SetImmediateModeDrawToFront (atoi(theArgVec[1]) != 0); + return 0; } @@ -452,7 +451,7 @@ static int VGlInfo (Draw_Interpretor& theDI, if (theArgNb <= 1) { - Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->View()->GraphicDriver()); + Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (aView->Viewer()->Driver()); if (aDriver.IsNull()) { std::cerr << "Error: view does not use OpenGL.\n"; diff --git a/src/ViewerTest/ViewerTest_ViewerCommands.cxx b/src/ViewerTest/ViewerTest_ViewerCommands.cxx index e248376c13..8fb76db93e 100644 --- a/src/ViewerTest/ViewerTest_ViewerCommands.cxx +++ b/src/ViewerTest/ViewerTest_ViewerCommands.cxx @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include #include @@ -2608,7 +2606,7 @@ static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const if (theArgsNb == 1) { - aCurrentView->View()->ZFitAll(); + aCurrentView->ZFitAll(); aCurrentView->Redraw(); return 0; } @@ -2620,7 +2618,7 @@ static int VZFit (Draw_Interpretor& /*theDi*/, Standard_Integer theArgsNb, const aScale = Draw::Atoi (theArgVec[1]); } - aCurrentView->View()->ZFitAll (aScale); + aCurrentView->ZFitAll (aScale); aCurrentView->Redraw(); return 0; @@ -3166,7 +3164,7 @@ static int VZBuffTrihedron (Draw_Interpretor& /*theDI*/, aView->ZBufferTriedronSetup (anArrowColorX.Name(), anArrowColorY.Name(), anArrowColorZ.Name(), aSizeRatio, anArrowDiam, aNbFacets); aView->TriedronDisplay (aPosition, aLabelsColor.Name(), aScale, aVisType); - aView->View()->ZFitAll(); + aView->ZFitAll(); return 0; } @@ -3392,8 +3390,9 @@ static int VExport(Draw_Interpretor& di, Standard_Integer argc, const char** arg return 1; } - try { - if (!V3dView->View()->Export (argv[1], anExpFormat)) + try + { + if (!V3dView->Export (argv[1], anExpFormat)) { di << "Error: export of image to " << aFormatStr << " failed!\n"; } @@ -4297,15 +4296,15 @@ static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, { if (isTileSizeProvided) { - Graphic3d_CView* aCView = static_cast (ViewerTest::CurrentView()->View()->CView()); - Graphic3d_PtrFrameBuffer anOldBuffer = static_cast (aCView->ptrFBO); - aCView->ptrFBO = aView->View()->FBOCreate (aTileWidth, aTileHeight); + Handle(Graphic3d_CView) aGraphicView = ViewerTest::CurrentView()->View(); + Graphic3d_PtrFrameBuffer anOldBuffer = aGraphicView->FBO(); + Graphic3d_PtrFrameBuffer aNewBuffer = aGraphicView->FBOCreate (aTileWidth, aTileHeight); + aGraphicView->SetFBO (aNewBuffer); isPrinted = aView->Print (anDC, 1, 1, 0, Aspect_PA_TILE); - Graphic3d_PtrFrameBuffer aNewBuffer = static_cast (aCView->ptrFBO); - aView->View()->FBORelease (aNewBuffer); - aCView->ptrFBO = anOldBuffer; + aGraphicView->FBORelease (aNewBuffer); + aGraphicView->SetFBO (anOldBuffer); } else { @@ -4313,7 +4312,7 @@ static int VPrintView (Draw_Interpretor& di, Standard_Integer argc, } } - // succesfully printed into an intermediate buffer + // successfully printed into an intermediate buffer if (isPrinted) { Image_PixMap aWrapper; @@ -4574,9 +4573,9 @@ static int VZLayer (Draw_Interpretor& di, Standard_Integer argc, const char** ar return 0; } -// The Visual3d_LayerItem line item for "vlayerline" command -// it provides a presentation of line with user-defined -// linewidth, linetype and transparency. +// The interactive presentation of 2d layer item +// for "vlayerline" command it provides a presentation of +// line with user-defined linewidth, linetype and transparency. class V3d_LineItem : public AIS_InteractiveObject { public: @@ -6984,7 +6983,7 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const return 1; } - Standard_Real aScale = aCurrentView->View()->AutoZFitScaleFactor(); + Standard_Real aScale = aCurrentView->AutoZFitScaleFactor(); if (theArgsNb > 3) { @@ -6995,7 +6994,7 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const if (theArgsNb < 2) { theDi << "Auto z-fit mode: " << "\n" - << "On: " << (aCurrentView->View()->AutoZFitMode() ? "enabled" : "disabled") << "\n" + << "On: " << (aCurrentView->AutoZFitMode() ? "enabled" : "disabled") << "\n" << "Scale: " << aScale << "\n"; return 0; } @@ -7007,8 +7006,8 @@ static int VAutoZFit (Draw_Interpretor& theDi, Standard_Integer theArgsNb, const aScale = Draw::Atoi (theArgVec[2]); } - aCurrentView->View()->SetAutoZFitMode (isOn, aScale); - aCurrentView->View()->AutoZFit(); + aCurrentView->SetAutoZFitMode (isOn, aScale); + aCurrentView->AutoZFit(); aCurrentView->Redraw(); return 0; @@ -7222,7 +7221,7 @@ static int VCamera (Draw_Interpretor& theDI, } } - aView->View()->AutoZFit(); + aView->AutoZFit(); aView->Redraw(); return 0; diff --git a/src/Visual3d/FILES b/src/Visual3d/FILES deleted file mode 100755 index 4b243a4744..0000000000 --- a/src/Visual3d/FILES +++ /dev/null @@ -1,38 +0,0 @@ -Visual3d_ClipDefinitionError.hxx -Visual3d_ContextPick.cxx -Visual3d_ContextPick.hxx -Visual3d_ContextPickDefinitionError.hxx -Visual3d_ContextView.cxx -Visual3d_ContextView.hxx -Visual3d_DepthCueingDefinitionError.hxx -Visual3d_HSequenceOfLight.hxx -Visual3d_HSequenceOfView.hxx -Visual3d_LayerDefinitionError.hxx -Visual3d_Light.cxx -Visual3d_Light.hxx -Visual3d_LightDefinitionError.hxx -Visual3d_MapOfZLayerSettings.hxx -Visual3d_NListOfLayerItem.hxx -Visual3d_PickError.hxx -Visual3d_SequenceOfLight.hxx -Visual3d_SequenceOfView.hxx -Visual3d_TransformError.hxx -Visual3d_TypeOfAnswer.hxx -Visual3d_TypeOfBackfacingModel.hxx -Visual3d_TypeOfLightSource.hxx -Visual3d_TypeOfModel.hxx -Visual3d_TypeOfOrder.hxx -Visual3d_TypeOfProjection.hxx -Visual3d_TypeOfSurfaceDetail.hxx -Visual3d_TypeOfVisualization.hxx -Visual3d_View.cxx -Visual3d_View.hxx -Visual3d_ViewDefinitionError.hxx -Visual3d_ViewManager.cxx -Visual3d_ViewManager.hxx -Visual3d_ViewManagerDefinitionError.hxx -Visual3d_ViewManagerPtr.hxx -Visual3d_ViewMappingDefinitionError.hxx -Visual3d_ViewOrientationDefinitionError.hxx -Visual3d_ViewPtr.hxx -Visual3d_ZClippingDefinitionError.hxx diff --git a/src/Visual3d/Visual3d_ClipDefinitionError.hxx b/src/Visual3d/Visual3d_ClipDefinitionError.hxx deleted file mode 100644 index 910f18de80..0000000000 --- a/src/Visual3d/Visual3d_ClipDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ClipDefinitionError_HeaderFile -#define _Visual3d_ClipDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ClipDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ClipDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ClipDefinitionError - #define Visual3d_ClipDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ClipDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ClipDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ClipDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ClipDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ContextPick.cxx b/src/Visual3d/Visual3d_ContextPick.cxx deleted file mode 100644 index 41abb60554..0000000000 --- a/src/Visual3d/Visual3d_ContextPick.cxx +++ /dev/null @@ -1,105 +0,0 @@ -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -//-Version -//-Design Declaration des variables specifiques aux contextes -// de reperage. -//-Warning Un contexte de reperage est defini par : -// - l'ouverture de la fenetre -// - la profondeur demandee -// - l'ordre de parcours des structures -//-References -//-Language C++ 2.0 -//-Declarations -// for the class - -#include -#include - -//-Aliases -//-Global data definitions -// -- ouverture ou taille de la fenetre de reperage -// MyAperture : Standard_Real; -// -- profondeur ou nombre de structures a reperer -// MyDepth : Standard_Integer; -// -- ordre de parcours des structures reperees -// MyOrder : TypeOfOrder; -//-Constructors -//-Destructors -//-Methods, in order -Visual3d_ContextPick::Visual3d_ContextPick (): -MyAperture (4.0), -MyDepth (10), -MyOrder (Visual3d_TOO_TOPFIRST) { -} - -Visual3d_ContextPick::Visual3d_ContextPick (const Standard_Real Aperture, const Standard_Integer Depth, const Visual3d_TypeOfOrder Order): -MyAperture (Aperture), -MyDepth (Depth), -MyOrder (Order) { - - if (Aperture <= 0.0) - Visual3d_ContextPickDefinitionError::Raise - ("Bad value for PickAperture"); - - if (Depth <= 0) - Visual3d_ContextPickDefinitionError::Raise - ("Bad value for PickDepth"); - -} - -void Visual3d_ContextPick::SetAperture (const Standard_Real Aperture) { - - if (Aperture <= 0.0) - Visual3d_ContextPickDefinitionError::Raise - ("Bad value for PickAperture"); - - MyAperture = Aperture; - -} - -Standard_Real Visual3d_ContextPick::Aperture () const { - - return (MyAperture); - -} - -void Visual3d_ContextPick::SetDepth (const Standard_Integer Depth) { - - if (Depth <= 0) - Visual3d_ContextPickDefinitionError::Raise - ("Bad value for PickDepth"); - - MyDepth = Depth; - -} - -Standard_Integer Visual3d_ContextPick::Depth () const { - - return (MyDepth); - -} - -void Visual3d_ContextPick::SetOrder (const Visual3d_TypeOfOrder Order) { - - MyOrder = Order; - -} - -Visual3d_TypeOfOrder Visual3d_ContextPick::Order () const { - - return (MyOrder); - -} diff --git a/src/Visual3d/Visual3d_ContextPick.hxx b/src/Visual3d/Visual3d_ContextPick.hxx deleted file mode 100644 index 8b96bc6851..0000000000 --- a/src/Visual3d/Visual3d_ContextPick.hxx +++ /dev/null @@ -1,115 +0,0 @@ -// Created on: 1991-11-25 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ContextPick_HeaderFile -#define _Visual3d_ContextPick_HeaderFile - -#include -#include -#include - -#include -#include -#include -class Visual3d_ContextPickDefinitionError; - - -//! This class allows the creation and update of -//! a pick context for one view of the viewer. -//! A context allows the control of different parameters -//! before the activation of a pick. -//! -//! * the pick aperture. -//! * the depth of pick, the number of sub-structures selected. -//! * the order of picking, the possibility to traverse -//! the pick structures starting from the root -//! or the leaves. -class Visual3d_ContextPick -{ -public: - - DEFINE_STANDARD_ALLOC - - - //! Creates a context from default values - //! - //! Aperture : 4.0 - //! Depth : 10 - //! Order : TOO_TOPFIRST - Standard_EXPORT Visual3d_ContextPick(); - - //! Creates a context with the values defined - //! Warning: Raises ContextPickDefinitionError if or - //! is a negative value. - Standard_EXPORT Visual3d_ContextPick(const Standard_Real Aperture, const Standard_Integer Depth, const Visual3d_TypeOfOrder Order); - - //! Modifies the size of the pick window. - //! Category: Methods to modifies the class definition - //! Warning: Raises ContextPickDefinitionError if is - //! a negative value. - Standard_EXPORT void SetAperture (const Standard_Real Aperture); - - //! Modifies the pick depth a priori. - //! Category: Methods to modifies the class definition - //! Warning: Raises ContextPickDefinitionError if is - //! a negative value. - Standard_EXPORT void SetDepth (const Standard_Integer Depth); - - //! Modifies the order of picking. - //! - //! TypeOfOrder : TOO_TOPFIRST - //! TOO_BOTTOMFIRST - Standard_EXPORT void SetOrder (const Visual3d_TypeOfOrder Order); - - //! Returns the size of the pick window . - Standard_EXPORT Standard_Real Aperture() const; - - //! Returns the effective pick depth of . - Standard_EXPORT Standard_Integer Depth() const; - - //! Returns the order of picking of . - //! - //! TypeOfOrder : TOO_TOPFIRST - //! TOO_BOTTOMFIRST - Standard_EXPORT Visual3d_TypeOfOrder Order() const; - - - - -protected: - - - - - -private: - - - - Standard_Real MyAperture; - Standard_Integer MyDepth; - Visual3d_TypeOfOrder MyOrder; - - -}; - - - - - - - -#endif // _Visual3d_ContextPick_HeaderFile diff --git a/src/Visual3d/Visual3d_ContextPickDefinitionError.hxx b/src/Visual3d/Visual3d_ContextPickDefinitionError.hxx deleted file mode 100644 index 1fdbd91887..0000000000 --- a/src/Visual3d/Visual3d_ContextPickDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ContextPickDefinitionError_HeaderFile -#define _Visual3d_ContextPickDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ContextPickDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ContextPickDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ContextPickDefinitionError - #define Visual3d_ContextPickDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ContextPickDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ContextPickDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ContextPickDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ContextPickDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ContextView.cxx b/src/Visual3d/Visual3d_ContextView.cxx deleted file mode 100644 index 6ae228e887..0000000000 --- a/src/Visual3d/Visual3d_ContextView.cxx +++ /dev/null @@ -1,318 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -/*********************************************************************** - FUNCTION : - ---------- - Class Visual3d_ContextView.cxx : - Declaration of variables specific to view contexts. - A view context is defined by : - - the activity of aliasing - - the activity of depth-cueing - - the activity of Z clipping - - the activity of defined light sources - - the required type of visualization - - the model of shading if required -************************************************************************/ -/*----------------------------------------------------------------------*/ -/* - * Includes - */ - -#include -#include -#include -#include -#include -#include -#include - -/*----------------------------------------------------------------------*/ -Visual3d_ContextView::Visual3d_ContextView (): -AliasingIsActive (Standard_False), -ZcueingIsActive (Standard_False), -FrontZclippingIsActive (Standard_False), -BackZclippingIsActive (Standard_False), -MyZclippingFrontPlane (Standard_ShortReal (1.0)), -MyZclippingBackPlane (Standard_ShortReal (0.0)), -MyDepthCueingFrontPlane (Standard_ShortReal (1.0)), -MyDepthCueingBackPlane (Standard_ShortReal (0.0)), -MyModel (Visual3d_TOM_NONE), -MyVisual (Visual3d_TOV_WIREFRAME), -MyLights (), -MyTextureEnv(), -MySurfaceDetail(Visual3d_TOD_ALL), -myClipPlanes() -{ -} - -/*----------------------------------------------------------------------*/ - -void Visual3d_ContextView::SetAliasingOn () { - - AliasingIsActive = Standard_True; - -} - -void Visual3d_ContextView::SetAliasingOff () { - - AliasingIsActive = Standard_False; - -} - -Standard_Boolean Visual3d_ContextView::AliasingIsOn () const { - - return (AliasingIsActive); - -} - -void Visual3d_ContextView::SetZClippingOn () { - - BackZclippingIsActive = Standard_True; - FrontZclippingIsActive = Standard_True; - -} - -void Visual3d_ContextView::SetZClippingOff () { - - BackZclippingIsActive = Standard_False; - FrontZclippingIsActive = Standard_False; - -} - -Standard_Boolean Visual3d_ContextView::BackZClippingIsOn () const { - - return (BackZclippingIsActive); - -} - -void Visual3d_ContextView::SetBackZClippingOn () { - - BackZclippingIsActive = Standard_True; - -} - -void Visual3d_ContextView::SetBackZClippingOff () { - - BackZclippingIsActive = Standard_False; - -} - -Standard_Boolean Visual3d_ContextView::FrontZClippingIsOn () const { - - return (FrontZclippingIsActive); - -} - -void Visual3d_ContextView::SetFrontZClippingOn () { - - FrontZclippingIsActive = Standard_True; - -} - -void Visual3d_ContextView::SetFrontZClippingOff () { - - FrontZclippingIsActive = Standard_False; - -} - -void Visual3d_ContextView::SetZClippingFrontPlane (const Standard_Real AFront) { - - MyZclippingFrontPlane = Standard_ShortReal (AFront); - -} - -Standard_Real Visual3d_ContextView::ZClippingFrontPlane () const { - - return (Standard_Real (MyZclippingFrontPlane)); - -} - -void Visual3d_ContextView::SetDepthCueingFrontPlane (const Standard_Real AFront) { - - MyDepthCueingFrontPlane = Standard_ShortReal (AFront); - -} - -Standard_Real Visual3d_ContextView::DepthCueingFrontPlane () const { - - return (Standard_Real (MyDepthCueingFrontPlane)); - -} - -void Visual3d_ContextView::SetZClippingBackPlane (const Standard_Real ABack) { - - MyZclippingBackPlane = Standard_ShortReal (ABack); - -} - -Standard_Real Visual3d_ContextView::ZClippingBackPlane () const { - - return (Standard_Real (MyZclippingBackPlane)); - -} - -void Visual3d_ContextView::SetDepthCueingBackPlane (const Standard_Real ABack) { - - MyDepthCueingBackPlane = Standard_ShortReal (ABack); - -} - -Standard_Real Visual3d_ContextView::DepthCueingBackPlane () const { - - return (Standard_Real (MyDepthCueingBackPlane)); - -} - -void Visual3d_ContextView::SetDepthCueingOn () { - - ZcueingIsActive = Standard_True; - -} - -void Visual3d_ContextView::SetDepthCueingOff () { - - ZcueingIsActive = Standard_False; - -} - -Standard_Boolean Visual3d_ContextView::DepthCueingIsOn () const { - - return (ZcueingIsActive); - -} - -void Visual3d_ContextView::SetModel (const Visual3d_TypeOfModel AModel) { - - MyModel = AModel; - -} - -Visual3d_TypeOfModel Visual3d_ContextView::Model () const { - - return (MyModel); - -} - -void Visual3d_ContextView::SetVisualization (const Visual3d_TypeOfVisualization AVisual) { - - MyVisual = AVisual; - -} - -Visual3d_TypeOfVisualization Visual3d_ContextView::Visualization () const { - - return (MyVisual); - -} - -void Visual3d_ContextView::SetLightOn (const Handle(Visual3d_Light)& ALight) { - -Standard_Integer LengthL = MyLights.Length (); -Standard_Integer indexL = 0; - - // Find light in - // the sequence of already active lights - for (Standard_Integer i=1; i<=LengthL && indexL==0; i++) - if ((void *) (MyLights.Value (i)) == - (void *) (ALight.operator->())) indexL = i; - - // This is the activation of a new light - if (indexL == 0) - MyLights.Append ((void *) ALight.operator->()); - -} - -void Visual3d_ContextView::SetLightOff (const Handle(Visual3d_Light)& ALight) { - -Standard_Integer LengthL = MyLights.Length (); -Standard_Integer indexL = 0; - - // Find light in - // the sequence of already active lights - for (Standard_Integer i=1; i<=LengthL && indexL==0; i++) - if ((void *) (MyLights.Value (i)) == - (void *) (ALight.operator->())) indexL = i; - - // This is the activation of a new light - if (indexL != 0) MyLights.Remove (indexL); - -} - -Handle(Visual3d_HSequenceOfLight) Visual3d_ContextView::ActivatedLights () const { - -Handle(Visual3d_HSequenceOfLight) SG = new Visual3d_HSequenceOfLight(); -Standard_Integer Length = MyLights.Length (); - - for (Standard_Integer i=1; i<=Length; i++) - SG->Append((Visual3d_Light *) (MyLights.Value (i))); - - return (SG); - -} - -Standard_Integer Visual3d_ContextView::NumberOfActivatedLights () const { - -Standard_Integer Length = MyLights.Length (); - - return (Length); - -} - -Handle(Visual3d_Light) Visual3d_ContextView::ActivatedLight (const Standard_Integer AnIndex) const { - - return (Visual3d_Light *) (MyLights.Value (AnIndex)); - -} - -void Visual3d_ContextView::SetSurfaceDetail(const Visual3d_TypeOfSurfaceDetail TOSD) -{ - MySurfaceDetail = TOSD; -} - - -void Visual3d_ContextView::SetTextureEnv(const Handle(Graphic3d_TextureEnv)& ATexture) -{ - MyTextureEnv = ATexture; -} - - -Handle(Graphic3d_TextureEnv) Visual3d_ContextView::TextureEnv() const -{ - return MyTextureEnv; -} - - -Visual3d_TypeOfSurfaceDetail Visual3d_ContextView::SurfaceDetail() const -{ - return MySurfaceDetail; -} - -//======================================================================= -//function : ClipPlanes -//purpose : -//======================================================================= -const Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ClipPlanes() const -{ - return myClipPlanes; -} - -//======================================================================= -//function : ChangeClipPlanes -//purpose : -//======================================================================= -Graphic3d_SequenceOfHClipPlane& Visual3d_ContextView::ChangeClipPlanes() -{ - return myClipPlanes; -} diff --git a/src/Visual3d/Visual3d_ContextView.hxx b/src/Visual3d/Visual3d_ContextView.hxx deleted file mode 100644 index e1383c1b5e..0000000000 --- a/src/Visual3d/Visual3d_ContextView.hxx +++ /dev/null @@ -1,255 +0,0 @@ -// Created on: 1991-09-05 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ContextView_HeaderFile -#define _Visual3d_ContextView_HeaderFile - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -class Graphic3d_TextureEnv; -class Visual3d_ClipDefinitionError; -class Visual3d_DepthCueingDefinitionError; -class Visual3d_LightDefinitionError; -class Visual3d_ZClippingDefinitionError; -class Visual3d_Light; - - -//! This class manages the creation and update of -//! a visualization context for one view in the viewer. -//! A context is defined by : -//! Antialiasing. -//! ZClipping. -//! Depth-cueing. -//! The type of visualization. -//! The light sources. -class Visual3d_ContextView -{ -public: - - DEFINE_STANDARD_ALLOC - - - //! Creates a context from default values - //! - //! Aliasing : OFF - //! BackZClipping : OFF - //! FrontZClipping : OFF - //! Depth-cueing : OFF - //! Light source : 0 - //! Clipping plane : 0 - //! Type Of Visualization : TOV_WIREFRAME - //! Type Of Model : TOM_NONE - //! Type Of SurfaceDetail : TOSD_NONE - Standard_EXPORT Visual3d_ContextView(); - - //! Selects the kind of rendering - //! default to: TOSD_NONE - Standard_EXPORT void SetSurfaceDetail (const Visual3d_TypeOfSurfaceDetail TOSD); - - //! Sets the environment texture to use - //! no environment texture by default - Standard_EXPORT void SetTextureEnv (const Handle(Graphic3d_TextureEnv)& ATexture); - - //! Activates antialiasing. - //! Antialiasing can be activated on all the structures - //! in the view - Standard_EXPORT void SetAliasingOn(); - - //! Deactivates the antialiasing. - Standard_EXPORT void SetAliasingOff(); - - //! Modifies the back depth-cueing plane. - //! Category: Methods to modify the class definition - //! Warning: Raises DepthCueingDefinitionError if - //! is front of and DepthCueing is ON. - Standard_EXPORT void SetDepthCueingBackPlane (const Standard_Real ABack); - - //! Modifies the front depth-cueing plane. - //! Category: Methods to modify the class definition - //! Warning: Raises DepthCueingDefinitionError if is - //! front of and DepthCueing is ON. - Standard_EXPORT void SetDepthCueingFrontPlane (const Standard_Real ABack); - - //! Activates the depth-cueing. - //! Depth-cueing can be activated on all structures - //! present in the view. - //! Category: Methods to modify the class definition - //! Warning: Raises DepthCueingDefinitionError if is - //! front of . - Standard_EXPORT void SetDepthCueingOn(); - - //! Deactivates the depth-cueing. - Standard_EXPORT void SetDepthCueingOff(); - - //! Returns sequence of clip planes. - //! @return sequence of clip planes. - Standard_EXPORT const Graphic3d_SequenceOfHClipPlane& ClipPlanes() const; - - //! Change clip planes. - //! @return sequence of clip planes. - Standard_EXPORT Graphic3d_SequenceOfHClipPlane& ChangeClipPlanes(); - - //! Activates the light source - Standard_EXPORT void SetLightOn (const Handle(Visual3d_Light)& ALight); - - //! Deactivates the light source - Standard_EXPORT void SetLightOff (const Handle(Visual3d_Light)& ALight); - - //! Modifies the shading model when the type of visualization is TOV_SHADING - Standard_EXPORT void SetModel (const Visual3d_TypeOfModel AModel); - - //! Modifies the mode of visualization. - //! - //! TypeOfVisualization : TOV_WIREFRAME - //! TOV_SHADING - Standard_EXPORT void SetVisualization (const Visual3d_TypeOfVisualization AVisual); - - //! Modifies the back Z-clipping plane. - //! Category: Methods to modify the class definition - //! Warning: Raises ZClippingDefinitionError if is - //! front of and ZClipping is ON. - Standard_EXPORT void SetZClippingBackPlane (const Standard_Real ABack); - - //! Modifies the front Z-clipping plane. - //! Category: Methods to modify the class definition - //! Warning: Raises ZClippingDefinitionError if is - //! front of and ZClipping is ON. - Standard_EXPORT void SetZClippingFrontPlane (const Standard_Real AFront); - - //! Activates the Z-clipping planes defined by - //! SetZClippingFrontPlane and SetZClippingBackPlane. - //! Category: Methods to modify the class definition - //! Warning: Raises ZClippingDefinitionError if is - //! front of . - Standard_EXPORT void SetZClippingOn(); - - //! Deactivates the Z-clipping planes defined by - //! SetFrontPlane and SetBackPlane. - Standard_EXPORT void SetZClippingOff(); - - //! Activates the front Z-clipping plane defined by - //! SetFrontPlane method. - Standard_EXPORT void SetFrontZClippingOn(); - - //! Deactivates the front Z-clipping plane defined by - //! SetFrontPlane method. - Standard_EXPORT void SetFrontZClippingOff(); - - //! Activates the back Z-clipping plane defined by - //! SetBackPlane method. - //! Category: Methods to modify the class definition - //! Warning: Raises ZClippingDefinitionError if is - //! front of . - Standard_EXPORT void SetBackZClippingOn(); - - //! Deactivates the back Z-clipping plane defined by - //! SetBackPlane method. - Standard_EXPORT void SetBackZClippingOff(); - - //! Returns the group of active light sources - //! in the view of context . - Standard_EXPORT Handle(Visual3d_HSequenceOfLight) ActivatedLights() const; - - //! Returns the number of active light sources - //! in the view of context . - Standard_EXPORT Standard_Integer NumberOfActivatedLights() const; - - Standard_EXPORT Handle(Visual3d_Light) ActivatedLight (const Standard_Integer AnIndex) const; - - //! Returns the activity of the aliasing. - Standard_EXPORT Standard_Boolean AliasingIsOn() const; - - //! Returns the activity of the ZClipping. - Standard_EXPORT Standard_Boolean BackZClippingIsOn() const; - - //! Returns the definition of the back depth-cueing plane. - Standard_EXPORT Standard_Real DepthCueingBackPlane() const; - - //! Returns the definition of the front depth-cueing plane. - Standard_EXPORT Standard_Real DepthCueingFrontPlane() const; - - //! Returns the activity of the depth-cueing. - Standard_EXPORT Standard_Boolean DepthCueingIsOn() const; - - //! Returns the activity of the ZClipping. - Standard_EXPORT Standard_Boolean FrontZClippingIsOn() const; - - //! Returns the shading model. - Standard_EXPORT Visual3d_TypeOfModel Model() const; - - //! Returns the mode of visualization. - Standard_EXPORT Visual3d_TypeOfVisualization Visualization() const; - - //! Returns the definition of the back Z-clipping plane. - Standard_EXPORT Standard_Real ZClippingBackPlane() const; - - //! Returns the definition of the front Z-clipping plane. - Standard_EXPORT Standard_Real ZClippingFrontPlane() const; - - Standard_EXPORT Visual3d_TypeOfSurfaceDetail SurfaceDetail() const; - - Standard_EXPORT Handle(Graphic3d_TextureEnv) TextureEnv() const; - - - - -protected: - - - - - -private: - - - - Standard_Boolean AliasingIsActive; - Standard_Boolean ZcueingIsActive; - Standard_Boolean FrontZclippingIsActive; - Standard_Boolean BackZclippingIsActive; - Standard_ShortReal MyZclippingFrontPlane; - Standard_ShortReal MyZclippingBackPlane; - Standard_ShortReal MyDepthCueingFrontPlane; - Standard_ShortReal MyDepthCueingBackPlane; - Visual3d_TypeOfModel MyModel; - Visual3d_TypeOfVisualization MyVisual; - TColStd_SequenceOfAddress MyLights; - Handle(Graphic3d_TextureEnv) MyTextureEnv; - Visual3d_TypeOfSurfaceDetail MySurfaceDetail; - Graphic3d_SequenceOfHClipPlane myClipPlanes; - - -}; - - - - - - - -#endif // _Visual3d_ContextView_HeaderFile diff --git a/src/Visual3d/Visual3d_DepthCueingDefinitionError.hxx b/src/Visual3d/Visual3d_DepthCueingDefinitionError.hxx deleted file mode 100644 index 554d216670..0000000000 --- a/src/Visual3d/Visual3d_DepthCueingDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_DepthCueingDefinitionError_HeaderFile -#define _Visual3d_DepthCueingDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_DepthCueingDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_DepthCueingDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_DepthCueingDefinitionError - #define Visual3d_DepthCueingDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_DepthCueingDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_DepthCueingDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_DepthCueingDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_DepthCueingDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_HSequenceOfLight.hxx b/src/Visual3d/Visual3d_HSequenceOfLight.hxx deleted file mode 100644 index 21beec3e8e..0000000000 --- a/src/Visual3d/Visual3d_HSequenceOfLight.hxx +++ /dev/null @@ -1,27 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef Visual3d_HSequenceOfLight_HeaderFile -#define Visual3d_HSequenceOfLight_HeaderFile - -#include -#include -#include - -DEFINE_HSEQUENCE(Visual3d_HSequenceOfLight, Visual3d_SequenceOfLight) - - -#endif diff --git a/src/Visual3d/Visual3d_HSequenceOfView.hxx b/src/Visual3d/Visual3d_HSequenceOfView.hxx deleted file mode 100644 index bf0fb3ad0d..0000000000 --- a/src/Visual3d/Visual3d_HSequenceOfView.hxx +++ /dev/null @@ -1,27 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef Visual3d_HSequenceOfView_HeaderFile -#define Visual3d_HSequenceOfView_HeaderFile - -#include -#include -#include - -DEFINE_HSEQUENCE(Visual3d_HSequenceOfView, Visual3d_SequenceOfView) - - -#endif diff --git a/src/Visual3d/Visual3d_LayerDefinitionError.hxx b/src/Visual3d/Visual3d_LayerDefinitionError.hxx deleted file mode 100644 index 31a1d1bfeb..0000000000 --- a/src/Visual3d/Visual3d_LayerDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_LayerDefinitionError_HeaderFile -#define _Visual3d_LayerDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_LayerDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_LayerDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_LayerDefinitionError - #define Visual3d_LayerDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_LayerDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_LayerDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_LayerDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_LayerDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_Light.cxx b/src/Visual3d/Visual3d_Light.cxx deleted file mode 100644 index 14ac9007d8..0000000000 --- a/src/Visual3d/Visual3d_Light.cxx +++ /dev/null @@ -1,444 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - - -#include -#include -#include -#include -#include -#include -#include - -// ======================================================================= -// function : Visual3d_Light -// purpose : -// ======================================================================= -Visual3d_Light::Visual3d_Light() -{ - myCLight.Type = Visual3d_TOLS_AMBIENT; -} - -// ======================================================================= -// function : Visual3d_Light -// purpose : -// ======================================================================= -Visual3d_Light::Visual3d_Light (const Quantity_Color& theColor) -{ - myCLight.Type = Visual3d_TOLS_AMBIENT; - myCLight.Color.r() = Standard_ShortReal (theColor.Red()); - myCLight.Color.g() = Standard_ShortReal (theColor.Green()); - myCLight.Color.b() = Standard_ShortReal (theColor.Blue()); -} - -// ======================================================================= -// function : Visual3d_Light -// purpose : -// ======================================================================= -Visual3d_Light::Visual3d_Light (const Quantity_Color& theColor, - const Graphic3d_Vector& theDirection, - const Standard_Boolean theIsHeadlight, - const Standard_Real theSmoothAngle, - const Standard_Real theIntensity) -{ - Visual3d_LightDefinitionError_Raise_if (theDirection.LengthZero(), - "Bad value for LightDirection"); - myCLight.Type = Visual3d_TOLS_DIRECTIONAL; - myCLight.IsHeadlight = theIsHeadlight; - myCLight.Color.r() = Standard_ShortReal (theColor.Red()); - myCLight.Color.g() = Standard_ShortReal (theColor.Green()); - myCLight.Color.b() = Standard_ShortReal (theColor.Blue()); - - Standard_Real X, Y, Z; - theDirection.Coord (X, Y, Z); - const Standard_Real aNorm = Sqrt (X * X + Y * Y + Z * Z); - myCLight.Direction.x() = Standard_ShortReal (X / aNorm); - myCLight.Direction.y() = Standard_ShortReal (Y / aNorm); - myCLight.Direction.z() = Standard_ShortReal (Z / aNorm); - - myCLight.Smoothness = static_cast (theSmoothAngle); - myCLight.Intensity = static_cast (theIntensity); -} - -// ======================================================================= -// function : Visual3d_Light -// purpose : -// ======================================================================= -Visual3d_Light::Visual3d_Light (const Quantity_Color& theColor, - const Graphic3d_Vertex& thePosition, - const Standard_Real theFact1, - const Standard_Real theFact2, - const Standard_Real theSmoothRadius, - const Standard_Real theIntensity) -{ - Visual3d_LightDefinitionError_Raise_if ((theFact1 == 0.0 && theFact2 == 0.0) - || (theFact1 < 0.0 || theFact1 > 1.0) - || (theFact2 < 0.0 || theFact2 > 1.0), - "Bad value for LightAttenuation"); - myCLight.Type = Visual3d_TOLS_POSITIONAL; - myCLight.IsHeadlight = Standard_False; - myCLight.Color.r() = Standard_ShortReal (theColor.Red()); - myCLight.Color.g() = Standard_ShortReal (theColor.Green()); - myCLight.Color.b() = Standard_ShortReal (theColor.Blue()); - myCLight.Position.x() = Standard_ShortReal (thePosition.X()); - myCLight.Position.y() = Standard_ShortReal (thePosition.Y()); - myCLight.Position.z() = Standard_ShortReal (thePosition.Z()); - myCLight.ChangeConstAttenuation() = Standard_ShortReal (theFact1); - myCLight.ChangeLinearAttenuation() = Standard_ShortReal (theFact2); - myCLight.Smoothness = static_cast (theSmoothRadius); - myCLight.Intensity = static_cast (theIntensity); -} - -// ======================================================================= -// function : Visual3d_Light -// purpose : -// ======================================================================= -Visual3d_Light::Visual3d_Light (const Quantity_Color& theColor, - const Graphic3d_Vertex& thePos, - const Graphic3d_Vector& theDir, - const Standard_Real theConcentration, - const Standard_Real theFact1, - const Standard_Real theFact2, - const Standard_Real theAngleCone) -{ - Visual3d_LightDefinitionError_Raise_if (theDir.LengthZero(), - "Bad value for LightDirection"); - Visual3d_LightDefinitionError_Raise_if (theConcentration < 0.0 || theConcentration > 1.0, - "Bad value for LightConcentration"); - Visual3d_LightDefinitionError_Raise_if ((theFact1 == 0.0 && theFact2 == 0.0) - || (theFact1 < 0.0 || theFact1 > 1.0) - || (theFact2 < 0.0 || theFact2 > 1.0), - "Bad value for LightAttenuation"); - Visual3d_LightDefinitionError_Raise_if (!Visual3d_Light::IsValid (theAngleCone), - "Bad value for LightAngle"); - myCLight.Type = Visual3d_TOLS_SPOT; - myCLight.IsHeadlight = Standard_False; - myCLight.Color.r() = Standard_ShortReal (theColor.Red()); - myCLight.Color.g() = Standard_ShortReal (theColor.Green()); - myCLight.Color.b() = Standard_ShortReal (theColor.Blue()); - myCLight.Position.x() = Standard_ShortReal (thePos.X()); - myCLight.Position.y() = Standard_ShortReal (thePos.Y()); - myCLight.Position.z() = Standard_ShortReal (thePos.Z()); - - Standard_Real X, Y, Z; - theDir.Coord (X, Y, Z); - myCLight.Direction.x() = Standard_ShortReal (X); - myCLight.Direction.y() = Standard_ShortReal (Y); - myCLight.Direction.z() = Standard_ShortReal (Z); - - myCLight.ChangeConcentration() = Standard_ShortReal (theConcentration); - myCLight.ChangeConstAttenuation() = Standard_ShortReal (theFact1); - myCLight.ChangeLinearAttenuation() = Standard_ShortReal (theFact2); - myCLight.ChangeAngle() = Standard_ShortReal (theAngleCone); -} - -// ======================================================================= -// function : Color -// purpose : -// ======================================================================= -Quantity_Color Visual3d_Light::Color() const -{ - return Quantity_Color (Standard_Real (myCLight.Color.r()), - Standard_Real (myCLight.Color.g()), - Standard_Real (myCLight.Color.b()), - Quantity_TOC_RGB); -} - -// ======================================================================= -// function : LightType -// purpose : -// ======================================================================= -Visual3d_TypeOfLightSource Visual3d_Light::LightType() const -{ - return (Visual3d_TypeOfLightSource )myCLight.Type; -} - -// ======================================================================= -// function : Headlight -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_Light::Headlight() const -{ - return myCLight.IsHeadlight; -} - -// ======================================================================= -// function : SetHeadlight -// purpose : -// ======================================================================= -void Visual3d_Light::SetHeadlight (const Standard_Boolean theValue) -{ - myCLight.IsHeadlight = theValue; -} - -// ======================================================================= -// function : Values -// purpose : -// ======================================================================= -void Visual3d_Light::Values (Quantity_Color& theColor) const -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_AMBIENT, - "Light Type != Visual3d_TOLS_AMBIENT"); - theColor.SetValues (Standard_Real (myCLight.Color.r()), - Standard_Real (myCLight.Color.g()), - Standard_Real (myCLight.Color.b()), - Quantity_TOC_RGB); -} - -// ======================================================================= -// function : Values -// purpose : -// ======================================================================= -void Visual3d_Light::Values (Quantity_Color& theColor, - Graphic3d_Vector& theDir) const -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_DIRECTIONAL, - "Light Type != Visual3d_TOLS_DIRECTIONAL"); - theColor.SetValues (Standard_Real (myCLight.Color.r()), - Standard_Real (myCLight.Color.g()), - Standard_Real (myCLight.Color.b()), - Quantity_TOC_RGB); - theDir.SetCoord (Standard_Real (myCLight.Direction.x()), - Standard_Real (myCLight.Direction.y()), - Standard_Real (myCLight.Direction.z())); -} - -// ======================================================================= -// function : Values -// purpose : -// ======================================================================= -void Visual3d_Light::Values (Quantity_Color& theColor, - Graphic3d_Vertex& thePos, - Standard_Real& theFact1, - Standard_Real& theFact2) const -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_POSITIONAL, - "Light Type != Visual3d_TOLS_POSITIONAL"); - theColor.SetValues (Standard_Real (myCLight.Color.r()), - Standard_Real (myCLight.Color.g()), - Standard_Real (myCLight.Color.b()), - Quantity_TOC_RGB); - thePos.SetCoord (Standard_Real (myCLight.Position.x()), - Standard_Real (myCLight.Position.y()), - Standard_Real (myCLight.Position.z())); - theFact1 = Standard_Real (myCLight.ConstAttenuation()); - theFact2 = Standard_Real (myCLight.LinearAttenuation()); -} - -// ======================================================================= -// function : Values -// purpose : -// ======================================================================= -void Visual3d_Light::Values (Quantity_Color& theColor, - Graphic3d_Vertex& thePos, - Graphic3d_Vector& theDir, - Standard_Real& theConcentration, - Standard_Real& theFact1, - Standard_Real& theFact2, - Standard_Real& theAngleCone) const -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_SPOT, - "Light Type != Visual3d_TOLS_SPOT"); - theColor.SetValues (Standard_Real (myCLight.Color.r()), - Standard_Real (myCLight.Color.g()), - Standard_Real (myCLight.Color.b()), - Quantity_TOC_RGB); - thePos.SetCoord (Standard_Real (myCLight.Position.x()), - Standard_Real (myCLight.Position.y()), - Standard_Real (myCLight.Position.z())); - theDir.SetCoord (Standard_Real (myCLight.Direction.x()), - Standard_Real (myCLight.Direction.y()), - Standard_Real (myCLight.Direction.z())); - theConcentration = Standard_Real (myCLight.Concentration()); - theFact1 = Standard_Real (myCLight.ConstAttenuation()); - theFact2 = Standard_Real (myCLight.LinearAttenuation()); - theAngleCone = Standard_Real (myCLight.Angle()); -} - -// ======================================================================= -// function : SetAngle -// purpose : -// ======================================================================= -void Visual3d_Light::SetAngle (const Standard_Real theAngleCone) -{ - Visual3d_LightDefinitionError_Raise_if (!Visual3d_Light::IsValid (theAngleCone), - "Bad value for LightAngle"); - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_SPOT, - "Light Type != Visual3d_TOLS_SPOT"); - myCLight.ChangeAngle() = Standard_ShortReal (theAngleCone); -} - -// ======================================================================= -// function : SetAttenuation1 -// purpose : -// ======================================================================= -void Visual3d_Light::SetAttenuation1 (const Standard_Real theFact1) -{ - Visual3d_LightDefinitionError_Raise_if (theFact1 < 0.0 || theFact1 > 1.0, - "Bad value for LightAttenuation"); - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_POSITIONAL - && myCLight.Type != Visual3d_TOLS_SPOT, - "Light Type != Visual3d_TOLS_SPOT and != Visual3d_TOLS_POSITIONAL"); - myCLight.ChangeConstAttenuation() = Standard_ShortReal (theFact1); -} - -// ======================================================================= -// function : SetAttenuation2 -// purpose : -// ======================================================================= -void Visual3d_Light::SetAttenuation2 (const Standard_Real theFact2) -{ - Visual3d_LightDefinitionError_Raise_if (theFact2 < 0.0 || theFact2 > 1.0, - "Bad value for LightAttenuation"); - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_POSITIONAL - && myCLight.Type != Visual3d_TOLS_SPOT, - "Light Type != Visual3d_TOLS_SPOT and != Visual3d_TOLS_POSITIONAL"); - myCLight.ChangeLinearAttenuation() = Standard_ShortReal (theFact2); -} - -// ======================================================================= -// function : SetColor -// purpose : -// ======================================================================= -void Visual3d_Light::SetColor (const Quantity_Color& theColor) -{ - myCLight.Color.r() = float (theColor.Red()); - myCLight.Color.g() = float (theColor.Green()); - myCLight.Color.b() = float (theColor.Blue()); -} - -// ======================================================================= -// function : SetConcentration -// purpose : -// ======================================================================= -void Visual3d_Light::SetConcentration (const Standard_Real theConcentration) -{ - Visual3d_LightDefinitionError_Raise_if (theConcentration < 0.0 || theConcentration > 1.0, - "Bad value for LightConcentration"); - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_SPOT, - "Light Type != Visual3d_TOLS_SPOT"); - myCLight.ChangeConcentration() = Standard_ShortReal (theConcentration); -} - -// ======================================================================= -// function : SetDirection -// purpose : -// ======================================================================= -void Visual3d_Light::SetDirection (const Graphic3d_Vector& theDir) -{ - Visual3d_LightDefinitionError_Raise_if (theDir.LengthZero(), - "Bad value for LightDirection"); - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_SPOT - && myCLight.Type != Visual3d_TOLS_DIRECTIONAL, - "Light Type != Visual3d_TOLS_DIRECTIONAL and != Visual3d_TOLS_SPOT"); - Standard_Real X, Y, Z; - theDir.Coord (X, Y, Z); - const Standard_Real aNorm = Sqrt (X * X + Y * Y + Z * Z); - myCLight.Direction.x() = float (X / aNorm); - myCLight.Direction.y() = float (Y / aNorm); - myCLight.Direction.z() = float (Z / aNorm); -} - -// ======================================================================= -// function : SetPosition -// purpose : -// ======================================================================= -void Visual3d_Light::SetPosition (const Graphic3d_Vertex& thePos) -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_SPOT - && myCLight.Type != Visual3d_TOLS_POSITIONAL, - "Light Type != Visual3d_TOLS_POSITIONAL and != Visual3d_TOLS_SPOT"); - myCLight.Position.x() = float (thePos.X()); - myCLight.Position.y() = float (thePos.Y()); - myCLight.Position.z() = float (thePos.Z()); -} - -// ======================================================================= -// function : SetSmoothAngle -// purpose : -// ======================================================================= -void Visual3d_Light::SetSmoothAngle (const Standard_Real theValue) -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_DIRECTIONAL, - "Light Type != Visual3d_TOLS_DIRECTIONAL"); - - Visual3d_LightDefinitionError_Raise_if (theValue < 0.0 || theValue > M_PI / 2.0, - "Bad value for smoothing angle"); - - myCLight.Smoothness = static_cast (theValue); -} - -// ======================================================================= -// function : SetSmoothRadius -// purpose : -// ======================================================================= -void Visual3d_Light::SetSmoothRadius (const Standard_Real theValue) -{ - Visual3d_LightDefinitionError_Raise_if (myCLight.Type != Visual3d_TOLS_POSITIONAL, - "Light Type != Visual3d_TOLS_POSITIONAL"); - - Visual3d_LightDefinitionError_Raise_if (theValue < 0.0, - "Bad value for smoothing radius"); - - myCLight.Smoothness = static_cast (theValue); -} - -// ======================================================================= -// function : SetIntensity -// purpose : -// ======================================================================= -void Visual3d_Light::SetIntensity (const Standard_Real theValue) -{ - Visual3d_LightDefinitionError_Raise_if (theValue <= 0.0, - "Bad value for intensity"); - - myCLight.Intensity = static_cast (theValue); -} - -// ======================================================================= -// function : Intensity -// purpose : -// ======================================================================= -Standard_Real Visual3d_Light::Intensity() const -{ - return static_cast (myCLight.Intensity); -} - -// ======================================================================= -// function : Smoothness -// purpose : -// ======================================================================= -Standard_Real Visual3d_Light::Smoothness() const -{ - return static_cast (myCLight.Smoothness); -} - -// ======================================================================= -// function : IsValid -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_Light::IsValid (const Standard_Real theAngle) -{ - return (theAngle < M_PI) - && (theAngle >= 0.0); -} - -// ======================================================================= -// function : CLight -// purpose : -// ======================================================================= -const Graphic3d_CLight& Visual3d_Light::CLight() const -{ - return myCLight; -} diff --git a/src/Visual3d/Visual3d_Light.hxx b/src/Visual3d/Visual3d_Light.hxx deleted file mode 100644 index 8b167c6529..0000000000 --- a/src/Visual3d/Visual3d_Light.hxx +++ /dev/null @@ -1,257 +0,0 @@ -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_Light_HeaderFile -#define _Visual3d_Light_HeaderFile - -#include -#include - -#include -#include -#include -#include -#include -#include -class Visual3d_LightDefinitionError; -class Visual3d_View; -class Quantity_Color; -class Graphic3d_Vector; - - -class Visual3d_Light; -DEFINE_STANDARD_HANDLE(Visual3d_Light, MMgt_TShared) - -//! This class defines and updates light sources. -//! There is no limit to the number of light sources defined. -//! Only the number of active sources is limited. -//! -//! TypeOfLightSource = TOLS_AMBIENT -//! TOLS_DIRECTIONAL -//! TOLS_POSITIONAL -//! TOLS_SPOT -//! -//! Angle is a radian value. -//! Concentration, Attenuation are in the [0,1] interval. -class Visual3d_Light : public MMgt_TShared -{ - -public: - - - //! Creates a light from default values. - //! Light sources are created in a visualiser - //! and are activated in one of its views. - //! - //! Type = TOLS_AMBIENT - //! Color = WHITE - Standard_EXPORT Visual3d_Light(); - - //! Creates an AMBIENT light source. - //! Light sources are created in a visualiser - //! and are activated in one of its views. - Standard_EXPORT Visual3d_Light(const Quantity_Color& Color); - - //! Creates a DIRECTIONAL light source. - //! Light sources are created in a visualiser - //! and are activated in one of its views. - //! Warning: Raises LightDefinitionError if is null. - Standard_EXPORT Visual3d_Light(const Quantity_Color& theColor, const Graphic3d_Vector& theDirection, const Standard_Boolean theHeadlight = Standard_False, const Standard_Real theSmoothAngle = 0.0, const Standard_Real theIntensity = 1.0); - - //! Creates a POSITIONAL light source. - //! Light sources are created in a visualiser - //! and are activated in one of its views. - //! Warning: Raises LightDefinitionError - //! if and are null. - //! if is a negative value or greater than 1.0. - //! if is a negative value or greater than 1.0. - Standard_EXPORT Visual3d_Light(const Quantity_Color& theColor, const Graphic3d_Vertex& thePosition, const Standard_Real theFact1, const Standard_Real theFact2, const Standard_Real theSmoothRadius = 0.0, const Standard_Real theIntensity = 1.0); - - //! Creates a SPOT light source. - //! Light sources are created in a visualiser - //! and are activated in one of its views. - //! specifies the intensity distribution of - //! the light. - //! specifies the angle (radians) of the cone - //! created by the spot. - //! the global attenuation is equal : - //! 1 / (Fact1 + Fact2 * (norm(ObjectPosition - LightPosition))) - //! Warning: Raises LightDefinitionError - //! if is null. - //! if is a negative value or greater than 1.0. - //! if and are null. - //! if is a negative value or greater than 1.0. - //! if is a negative value or greater than 1.0. - //! if is a negative value or greater than PI/2. - Standard_EXPORT Visual3d_Light(const Quantity_Color& Color, const Graphic3d_Vertex& Position, const Graphic3d_Vector& Direction, const Standard_Real Concentration, const Standard_Real Fact1, const Standard_Real Fact2, const Standard_Real AngleCone); - - //! Modifies the angle (radians) of the cone created by the spot. - //! Works only on TOLS_SPOT lights. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_SPOT. - //! if is a negative value or greater than PI/2. - Standard_EXPORT void SetAngle (const Standard_Real AngleCone); - - //! Modifies the attenuation factor of the light. - //! Works only on the TOLS_POSITIONAL and TOLS_SPOT lights. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_SPOT or TOLS_POSITIONAL. - //! if is a negative value or greater than 1.0. - Standard_EXPORT void SetAttenuation1 (const Standard_Real Fact1); - - //! Modifies the attenuation factor of the light. - //! Works only on the TOLS_POSITIONAL and TOLS_SPOT lights. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_POSITIONAL or TOLS_SPOT. - //! if is a negative value or greater than 1.0.. - Standard_EXPORT void SetAttenuation2 (const Standard_Real Fact2); - - //! Modifies the colour of the light. - Standard_EXPORT void SetColor (const Quantity_Color& Color); - - //! Modifies the intensity distribution of the light. - //! Works only on the TOLS_SPOT lights. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_SPOT. - //! if is a negative value or greater than 1.0. - Standard_EXPORT void SetConcentration (const Standard_Real Concentration); - - //! Modifies the light direction. - //! Works only on the TOLS_DIRECTIONAL and TOLS_SPOT lights. - //! Default z - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_DIRECTIONAL - //! or TOLS_SPOT. - //! if is null. - Standard_EXPORT void SetDirection (const Graphic3d_Vector& Direction); - - //! Modifies the position of the light. - //! Works only on the TOLS_POSITIONAL and TOLS_SPOT lights. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_POSITIONAL or TOLS_SPOT. - Standard_EXPORT void SetPosition (const Graphic3d_Vertex& Position); - - //! Modifies the smoothing angle (in radians) of - //! DIRECTIONAL light source. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_DIRECTIONAL - //! if is negative or greater than PI / 2. - Standard_EXPORT void SetSmoothAngle (const Standard_Real theValue); - - //! Modifies the smoothing radius of - //! POSITIONAL light source. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_POSITIONAL - //! if is negative. - Standard_EXPORT void SetSmoothRadius (const Standard_Real theValue); - - //! Modifies the intensity of light source. - //! Category: Methods to modify the class definition - //! Warning: Raises LightDefinitionError - //! if is negative or equal to zero. - Standard_EXPORT void SetIntensity (const Standard_Real theValue); - - //! returns the intensity of light source - Standard_EXPORT Standard_Real Intensity() const; - - //! returns the smoothness of light source - Standard_EXPORT Standard_Real Smoothness() const; - - //! Returns the headlight state of the light - Standard_EXPORT Standard_Boolean Headlight() const; - - //! Setup headlight flag. - Standard_EXPORT void SetHeadlight (const Standard_Boolean theValue); - - //! Returns the colour of the light . - Standard_EXPORT Quantity_Color Color() const; - - //! Returns the light type of . - //! - //! TypeOfLightSource = TOLS_AMBIENT - //! TOLS_DIRECTIONAL - //! TOLS_POSITIONAL - //! TOLS_SPOT - Standard_EXPORT Visual3d_TypeOfLightSource LightType() const; - - //! Returns the definition of if is - //! a light source of the TOLS_AMBIENT type. - //! Category: Inquire methods - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_AMBIENT. - Standard_EXPORT void Values (Quantity_Color& Color) const; - - //! Returns the definition of if is - //! a light source of the TOLS_DIRECTIONAL type. - //! Category: Inquire methods - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_DIRECTIONAL. - Standard_EXPORT void Values (Quantity_Color& Color, Graphic3d_Vector& Direction) const; - - //! Returns the definition of if is - //! a light source of the TOLS_POSITIONAL type. - //! Category: Inquire methods - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_POSITIONAL. - Standard_EXPORT void Values (Quantity_Color& Color, Graphic3d_Vertex& Position, Standard_Real& Fact1, Standard_Real& Fact2) const; - - //! Returns the definition of if is - //! a light source of the TOLS_SPOT type. - //! Category: Inquire methods - //! Warning: Raises LightDefinitionError - //! if the type of the light is not TOLS_SPOT. - Standard_EXPORT void Values (Quantity_Color& Color, Graphic3d_Vertex& Position, Graphic3d_Vector& Direction, Standard_Real& Concentration, Standard_Real& Fact1, Standard_Real& Fact2, Standard_Real& AngleCone) const; - - //! Returns the light defintion. - Standard_EXPORT const Graphic3d_CLight& CLight() const; - - -friend class Visual3d_View; - - - DEFINE_STANDARD_RTTI(Visual3d_Light,MMgt_TShared) - -protected: - - - - -private: - - - //! Returns True if is a valid - //! spot light spread angle. - Standard_EXPORT static Standard_Boolean IsValid (const Standard_Real AAngle); - - Graphic3d_CLight myCLight; - - -}; - - - - - - - -#endif // _Visual3d_Light_HeaderFile diff --git a/src/Visual3d/Visual3d_LightDefinitionError.hxx b/src/Visual3d/Visual3d_LightDefinitionError.hxx deleted file mode 100644 index 5f5caf3b32..0000000000 --- a/src/Visual3d/Visual3d_LightDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_LightDefinitionError_HeaderFile -#define _Visual3d_LightDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_LightDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_LightDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_LightDefinitionError - #define Visual3d_LightDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_LightDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_LightDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_LightDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_LightDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_NListOfLayerItem.hxx b/src/Visual3d/Visual3d_NListOfLayerItem.hxx deleted file mode 100644 index bd8a875602..0000000000 --- a/src/Visual3d/Visual3d_NListOfLayerItem.hxx +++ /dev/null @@ -1,24 +0,0 @@ -// Created on: 2009-03-20 -// Created by: Alexander A. BORODIN -// Copyright (c) 2009-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_NListOfLayerItem_HeaderFile -#define _Visual3d_NListOfLayerItem_HeaderFile - -#include -#include - -typedef NCollection_List Visual3d_NListOfLayerItem; - -#endif diff --git a/src/Visual3d/Visual3d_PickError.hxx b/src/Visual3d/Visual3d_PickError.hxx deleted file mode 100644 index 58a4e228c2..0000000000 --- a/src/Visual3d/Visual3d_PickError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_PickError_HeaderFile -#define _Visual3d_PickError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_PickError; -DEFINE_STANDARD_HANDLE(Visual3d_PickError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_PickError - #define Visual3d_PickError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_PickError::Raise(MESSAGE); -#else - #define Visual3d_PickError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_PickError, Standard_OutOfRange) - -#endif // _Visual3d_PickError_HeaderFile diff --git a/src/Visual3d/Visual3d_SequenceOfLight.hxx b/src/Visual3d/Visual3d_SequenceOfLight.hxx deleted file mode 100644 index 545e68afdb..0000000000 --- a/src/Visual3d/Visual3d_SequenceOfLight.hxx +++ /dev/null @@ -1,26 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef Visual3d_SequenceOfLight_HeaderFile -#define Visual3d_SequenceOfLight_HeaderFile - -#include -#include - -typedef NCollection_Sequence Visual3d_SequenceOfLight; - - -#endif diff --git a/src/Visual3d/Visual3d_SequenceOfView.hxx b/src/Visual3d/Visual3d_SequenceOfView.hxx deleted file mode 100644 index cf4c509de0..0000000000 --- a/src/Visual3d/Visual3d_SequenceOfView.hxx +++ /dev/null @@ -1,26 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef Visual3d_SequenceOfView_HeaderFile -#define Visual3d_SequenceOfView_HeaderFile - -#include -#include - -typedef NCollection_Sequence Visual3d_SequenceOfView; - - -#endif diff --git a/src/Visual3d/Visual3d_TransformError.hxx b/src/Visual3d/Visual3d_TransformError.hxx deleted file mode 100644 index 2708cdfa74..0000000000 --- a/src/Visual3d/Visual3d_TransformError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_TransformError_HeaderFile -#define _Visual3d_TransformError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_TransformError; -DEFINE_STANDARD_HANDLE(Visual3d_TransformError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_TransformError - #define Visual3d_TransformError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_TransformError::Raise(MESSAGE); -#else - #define Visual3d_TransformError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_TransformError, Standard_OutOfRange) - -#endif // _Visual3d_TransformError_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfOrder.hxx b/src/Visual3d/Visual3d_TypeOfOrder.hxx deleted file mode 100644 index dd053a854f..0000000000 --- a/src/Visual3d/Visual3d_TypeOfOrder.hxx +++ /dev/null @@ -1,29 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_TypeOfOrder_HeaderFile -#define _Visual3d_TypeOfOrder_HeaderFile - -//! Definition of the order of selection -//! TOO_TOPFIRST the root structure first -//! TOO_BOTTOMFIRST the leaf structure first -enum Visual3d_TypeOfOrder -{ -Visual3d_TOO_TOPFIRST, -Visual3d_TOO_BOTTOMFIRST -}; - -#endif // _Visual3d_TypeOfOrder_HeaderFile diff --git a/src/Visual3d/Visual3d_TypeOfProjection.hxx b/src/Visual3d/Visual3d_TypeOfProjection.hxx deleted file mode 100644 index 60d726cb33..0000000000 --- a/src/Visual3d/Visual3d_TypeOfProjection.hxx +++ /dev/null @@ -1,33 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_TypeOfProjection_HeaderFile -#define _Visual3d_TypeOfProjection_HeaderFile - -//! Definition of the type of 3D projection -//! -//! TOP_PERSPECTIVE perspective projection (centre of -//! projection at a distance finite from -//! plane of projection) -//! TOP_PARALLEL parallel projection (point of -//! projection at infinity) -enum Visual3d_TypeOfProjection -{ -Visual3d_TOP_PERSPECTIVE, -Visual3d_TOP_PARALLEL -}; - -#endif // _Visual3d_TypeOfProjection_HeaderFile diff --git a/src/Visual3d/Visual3d_View.cxx b/src/Visual3d/Visual3d_View.cxx deleted file mode 100644 index 6c96cda55d..0000000000 --- a/src/Visual3d/Visual3d_View.cxx +++ /dev/null @@ -1,2364 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifdef _WIN32 - #include -#endif - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_WIN32) - #include -#elif (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) - #include -#else - #include -#endif - -#include - -// ======================================================================= -// function : Visual3d_View -// purpose : -// ======================================================================= -Visual3d_View::Visual3d_View (const Handle(Visual3d_ViewManager)& theMgr) -: myViewManager (theMgr.operator->()), - myIsInComputedMode (Standard_False), - myAutoZFitIsOn (Standard_True), - myAutoZFitScaleFactor (1.0), - myStructuresUpdated (Standard_True) -{ - myHiddenObjects = new Graphic3d_NMapOfTransient(); - - MyCView.ViewId = theMgr->Identification (this); - MyCView.Active = 0; - MyCView.IsDeleted = 0; - MyCView.WsId = -1; - MyCView.DefWindow.IsDefined = 0; - MyCView.Context.NbActiveLight = 0; - - MyCView.Backfacing = 0; - MyCView.ptrUnderLayer = 0; - MyCView.ptrOverLayer = 0; - MyCView.GContext = 0; - MyCView.GDisplayCB = 0; - MyCView.GClientData = 0; - - myGraphicDriver = myViewManager->GraphicDriver(); -} - -// ======================================================================= -// function : SetWindow -// purpose : -// ======================================================================= -void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow, - const Aspect_RenderingContext theContext, - const Aspect_GraphicCallbackProc& theDisplayCB, - const Standard_Address theClientData) -{ - if (IsDeleted()) - { - return; - } - - MyCView.GContext = theContext; - MyCView.GDisplayCB = theDisplayCB; - MyCView.GClientData = theClientData; - SetWindow (theWindow); -} - -// ======================================================================= -// function : SetWindow -// purpose : -// ======================================================================= -void Visual3d_View::SetWindow (const Handle(Aspect_Window)& theWindow) -{ - if (IsDeleted()) - { - return; - } - - MyWindow = theWindow; - MyCView.WsId = MyCView.ViewId; - MyCView.DefWindow.IsDefined = 1; - MyCView.DefWindow.XWindow = theWindow->NativeHandle(); - MyCView.DefWindow.XParentWindow = theWindow->NativeParentHandle(); - - Standard_Integer aWidth = 0, aHeight = 0, aLeft = 0, aTop = 0; - theWindow->Position (aLeft, aTop, aWidth, aHeight); - theWindow->Size (aWidth, aHeight); - MyCView.DefWindow.left = aLeft; - MyCView.DefWindow.top = aTop; - MyCView.DefWindow.dx = aWidth; - MyCView.DefWindow.dy = aHeight; - - Standard_Real R, G, B; - MyBackground = MyWindow->Background (); - MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB); - MyCView.DefWindow.Background.r = float (R); - MyCView.DefWindow.Background.g = float (G); - MyCView.DefWindow.Background.b = float (B); - - UpdateView(); - if (!myGraphicDriver->View (MyCView)) - { - Visual3d_ViewDefinitionError::Raise ("Association failed"); - } - - MyGradientBackground = MyWindow->GradientBackground(); - SetGradientBackground(MyGradientBackground,1); - - Standard_Boolean AWait = Standard_False; // => immediate update - myGraphicDriver->SetVisualisation (MyCView); - myGraphicDriver->AntiAliasing (MyCView, MyContext.AliasingIsOn()); - myGraphicDriver->DepthCueing (MyCView, MyContext.DepthCueingIsOn()); - myGraphicDriver->ClipLimit (MyCView, AWait); - myGraphicDriver->Environment (MyCView); - - // Make view manager z layer list consistent with the view's list. - myViewManager->InstallZLayers (this); - - // Update planses of model clipping - UpdatePlanes(); - - // Update light sources - UpdateLights(); - - // Association view-window does not cause the display - // of structures that can be displayed in the new view. - // In fact, association view-window is done, but the - // display is produced only if the view is activated (Activate). - SetRatio(); - - // invalidate camera - const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera; - if (!aCamera.IsNull()) - { - aCamera->InvalidateProjection(); - aCamera->InvalidateOrientation(); - } -} - -// ======================================================================= -// function : Window -// purpose : -// ======================================================================= -Handle(Aspect_Window) Visual3d_View::Window() const -{ - if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - return MyWindow; -} - -// ======================================================================= -// function : IsDefined -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::IsDefined() const -{ - return MyCView.DefWindow.IsDefined != 0; -} - -// ======================================================================= -// function : IsDeleted -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::IsDeleted() const -{ - return MyCView.IsDeleted != 0; -} - -// ======================================================================= -// function : Destroy -// purpose : -// ======================================================================= -void Visual3d_View::Destroy() -{ - // Since myViewManager can be already destroyed, - // avoid attempts to access it in SetBackground() - myViewManager = NULL; - Remove(); -} - -// ======================================================================= -// function : Remove -// purpose : -// ======================================================================= -void Visual3d_View::Remove() -{ - if (IsDeleted() - || !IsDefined()) - { - return; - } - - myStructsToCompute.Clear(); - myStructsComputed .Clear(); - myStructsDisplayed.Clear(); - - Aspect_GradientBackground aBlackGrad; - SetBackground (Aspect_Background (Quantity_NOC_BLACK)); - SetGradientBackground (aBlackGrad, Standard_False); - - if (myViewManager != NULL) - { - myViewManager->UnIdentification (MyCView.ViewId); - } - - myGraphicDriver->RemoveView (MyCView); - - MyCView.WsId = -1; - MyCView.IsDeleted = 1; - MyCView.DefWindow.IsDefined = 0; - - MyWindow.Nullify(); -} - -// ======================================================================= -// function : Resized -// purpose : -// ======================================================================= -void Visual3d_View::Resized() -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - MyWindow->DoResize(); - SetRatio(); -} - -// ======================================================================= -// function : SetRatio -// purpose : -// ======================================================================= -void Visual3d_View::SetRatio() -{ - if (IsDeleted()) - { - return; - } - - const Aspect_TypeOfUpdate anUpdateMode = myViewManager->UpdateMode(); - myViewManager->SetUpdateMode (Aspect_TOU_WAIT); - - Standard_Integer aWidth = 0, aHeight = 0, aLeft = 0, aTop = 0; - MyWindow->Position (aLeft, aTop, aWidth, aHeight); - MyCView.DefWindow.left = aLeft; - MyCView.DefWindow.top = aTop; - - MyWindow->Size (aWidth, aHeight); - if (aWidth > 0 && aHeight > 0) - { - Standard_Real aRatio = (Standard_Real)aWidth / (Standard_Real)aHeight; - - MyCView.DefWindow.dx = aWidth; - MyCView.DefWindow.dy = aHeight; - - myGraphicDriver->RatioWindow (MyCView); - - // Update camera aspect - const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera; - if (!aCamera.IsNull()) - { - aCamera->SetAspect (aRatio); - } - - if (!myDefaultCamera.IsNull()) - { - myDefaultCamera->SetAspect (aRatio); - } - } - - myViewManager->SetUpdateMode (anUpdateMode); - Update (anUpdateMode); -} - -// ======================================================================= -// function : UpdateLights -// purpose : -// ======================================================================= -void Visual3d_View::UpdateLights() -{ - if (IsDeleted() - || !IsDefined()) - { - return; - } - - if (MyContext.Model() == Visual3d_TOM_NONE) - { - // activate only a white ambient light - Graphic3d_CLight aCLight; - aCLight.Type = Visual3d_TOLS_AMBIENT; - aCLight.IsHeadlight = Standard_False; - aCLight.Color.r() = aCLight.Color.g() = aCLight.Color.b() = 1.0f; - - MyCView.Context.NbActiveLight = 1; - MyCView.Context.ActiveLight = &aCLight; - myGraphicDriver->SetLight (MyCView); - MyCView.Context.ActiveLight = NULL; - return; - } - - MyCView.Context.NbActiveLight = Min (MyContext.NumberOfActivatedLights(), - myGraphicDriver->InquireLightLimit()); - if (MyCView.Context.NbActiveLight < 1) - { - myGraphicDriver->SetLight (MyCView); - return; - } - - // parcing of light sources - MyCView.Context.ActiveLight = new Graphic3d_CLight[MyCView.Context.NbActiveLight]; - for (Standard_Integer aLightIter = 0; aLightIter < MyCView.Context.NbActiveLight; ++aLightIter) - { - MyCView.Context.ActiveLight[aLightIter] = MyContext.ActivatedLight (aLightIter + 1)->CLight(); - } - myGraphicDriver->SetLight (MyCView); - delete[] MyCView.Context.ActiveLight; - MyCView.Context.ActiveLight = NULL; -} - -// ======================================================================= -// function : UpdatePlanes -// purpose : -// ======================================================================= -void Visual3d_View::UpdatePlanes() -{ - MyCView.Context.ClipPlanes = MyContext.ClipPlanes(); - if (IsDeleted() || !IsDefined()) - { - return; - } - - myGraphicDriver->SetClipPlanes (MyCView); -} - -// ======================================================================= -// function : SetBackground -// purpose : -// ======================================================================= -void Visual3d_View::SetBackground (const Aspect_Background& theBack) -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - // At this level, only GL can update the background. - // It is not necessary to call MyWindow->SetBackground (ABack); as - // this method starts update of window background by X - // (if the windowing is X) - - Standard_Real R, G, B; - MyBackground = theBack; - MyBackground.Color().Values (R, G, B, Quantity_TOC_RGB); - MyCView.DefWindow.Background.r = float (R); - MyCView.DefWindow.Background.g = float (G); - MyCView.DefWindow.Background.b = float (B); - - myGraphicDriver->Background (MyCView); - - if (myViewManager != NULL) - { - Update (myViewManager->UpdateMode()); - } -} - -// ======================================================================= -// function : SetGradientBackground -// purpose : -// ======================================================================= -void Visual3d_View::SetGradientBackground (const Aspect_GradientBackground& theBack, - const Standard_Boolean theToUpdate) -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - MyGradientBackground = theBack; - Quantity_Color aCol1, aCol2; - MyGradientBackground.Colors (aCol1, aCol2); - myGraphicDriver->GradientBackground (MyCView, aCol1, aCol2, MyGradientBackground.BgGradientFillMethod()); - - if (theToUpdate) - { - Update (Aspect_TOU_ASAP); - } - else if (myViewManager != NULL) - { - Update (myViewManager->UpdateMode()); - } -} - -// ======================================================================= -// function : SetBackgroundImage -// purpose : -// ======================================================================= -void Visual3d_View::SetBackgroundImage (const Standard_CString theFileName, - const Aspect_FillMethod theFillStyle, - const Standard_Boolean theToUpdate) -{ - if (IsDeleted()) - { - return; - } - if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - myGraphicDriver->BackgroundImage (theFileName, MyCView, theFillStyle); - - Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : SetBgImageStyle -// purpose : -// ======================================================================= -void Visual3d_View::SetBgImageStyle (const Aspect_FillMethod theFillStyle, - const Standard_Boolean theToUpdate) -{ - if (IsDeleted()) - { - return; - } - if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - myGraphicDriver->SetBgImageStyle (MyCView, theFillStyle); - - Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : Background -// purpose : -// ======================================================================= -Aspect_Background Visual3d_View::Background() const -{ - return MyBackground; -} - -// ======================================================================= -// function : SetBgGradientStyle -// purpose : -// ======================================================================= -void Visual3d_View::SetBgGradientStyle (const Aspect_GradientFillMethod theFillStyle, - const Standard_Boolean theToUpdate) -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - myGraphicDriver->SetBgGradientStyle (MyCView, theFillStyle); - - Update (theToUpdate ? Aspect_TOU_ASAP : myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : GradientBackground -// purpose : -// ======================================================================= -Aspect_GradientBackground Visual3d_View::GradientBackground() const -{ - return MyGradientBackground; -} - -// ======================================================================= -// function : DefaultCamera -// purpose : -// ======================================================================= -const Handle(Graphic3d_Camera)& Visual3d_View::DefaultCamera() const -{ - return myDefaultCamera; -} - -// ======================================================================= -// function : Camera -// purpose : -// ======================================================================= -const Handle(Graphic3d_Camera)& Visual3d_View::Camera() const -{ - return MyCView.Context.Camera; -} - -// ======================================================================= -// function : SetCamera -// purpose : -// ======================================================================= -void Visual3d_View::SetCamera (const Handle(Graphic3d_Camera)& theCamera) -{ - MyCView.Context.Camera = theCamera; - - myGraphicDriver->SetCamera (MyCView); - - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : SetViewOrientationDefault -// purpose : -// ======================================================================= -void Visual3d_View::SetViewOrientationDefault() -{ - if (myDefaultCamera.IsNull()) - { - myDefaultCamera = new Graphic3d_Camera(); - } - - myDefaultCamera->CopyOrientationData (MyCView.Context.Camera); -} - -// ======================================================================= -// function : ViewOrientationReset -// purpose : -// ======================================================================= -void Visual3d_View::ViewOrientationReset() -{ - if (IsDeleted()) - { - return; - } - - if (!myDefaultCamera.IsNull()) - { - MyCView.Context.Camera->CopyOrientationData (myDefaultCamera); - } - - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : SetViewMappingDefault -// purpose : -// ======================================================================= -void Visual3d_View::SetViewMappingDefault() -{ - if (myDefaultCamera.IsNull()) - { - myDefaultCamera = new Graphic3d_Camera(); - } - myDefaultCamera->CopyMappingData (MyCView.Context.Camera); -} - -// ======================================================================= -// function : ViewMappingReset -// purpose : -// ======================================================================= -void Visual3d_View::ViewMappingReset() -{ - if (IsDeleted()) - { - return; - } - - if (!myDefaultCamera.IsNull()) - { - MyCView.Context.Camera->CopyMappingData (myDefaultCamera); - } - - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : SetContext -// purpose : -// ======================================================================= -void Visual3d_View::SetContext (const Visual3d_ContextView& theViewCtx) -{ - if (IsDeleted()) - { - return; - } - - // To manage display only in case of change of visualisation mode - const bool isVisModeChanged = theViewCtx.Visualization() != MyContext.Visualization(); - const bool isModelChanged = theViewCtx.Model() != MyContext.Model(); - - // To manage antialiasing only in case of change - const Standard_Boolean anAliasingModeOld = MyContext.AliasingIsOn(); - const Standard_Boolean anAliasingModeNew = theViewCtx.AliasingIsOn(); - - // To manage the depth cueing only in case of change - const Standard_Boolean aDepthCueingModeOld = MyContext.DepthCueingIsOn(); - const Standard_Boolean aDepthCueingModeNew = theViewCtx.DepthCueingIsOn(); - - const Standard_Real aDepthCueingFrontPlaneOld = MyContext.DepthCueingFrontPlane(); - const Standard_Real aDepthCueingFrontPlaneNew = theViewCtx.DepthCueingFrontPlane(); - const Standard_Real aDepthCueingBackPlaneOld = MyContext.DepthCueingBackPlane(); - const Standard_Real aDepthCueingBackPlaneNew = theViewCtx.DepthCueingBackPlane(); - - // To manage the Zclipping only in case of change - const Standard_Boolean aFrontZClippingModeOld = MyContext.FrontZClippingIsOn(); - const Standard_Boolean aFrontZClippingModeNew = theViewCtx.FrontZClippingIsOn(); - const Standard_Boolean aBackZClippingModeOld = MyContext.BackZClippingIsOn(); - const Standard_Boolean aBackZClippingModeNew = theViewCtx.BackZClippingIsOn(); - - const Standard_Real aZClippingFrontPlaneOld = MyContext.ZClippingFrontPlane(); - const Standard_Real aZClippingFrontPlaneNew = theViewCtx.ZClippingFrontPlane(); - const Standard_Real aZClippingBackPlaneOld = MyContext.ZClippingBackPlane(); - const Standard_Real aZClippingBackPlaneNew = theViewCtx.ZClippingBackPlane(); - - const bool isTextEnvChanged = theViewCtx.TextureEnv() != MyContext.TextureEnv(); - const bool isSurfDetailChanged = theViewCtx.SurfaceDetail() != MyContext.SurfaceDetail(); - - MyContext = theViewCtx; - - UpdateView(); - - Standard_Boolean toWait = Standard_False; // => immediate update - if (IsDefined()) - { - // management of visualization modes and types of shading. - if (isVisModeChanged - || isModelChanged) - { - myGraphicDriver->SetVisualisation (MyCView); - } - - // management of antialiasing - if (anAliasingModeOld != anAliasingModeNew) - { - myGraphicDriver->AntiAliasing (MyCView, anAliasingModeNew); - } - - // management of depth_cueing - if (aDepthCueingModeOld != aDepthCueingModeNew - || aDepthCueingFrontPlaneOld != aDepthCueingFrontPlaneNew - || aDepthCueingBackPlaneOld != aDepthCueingBackPlaneNew) - { - if (aDepthCueingModeNew - && aDepthCueingBackPlaneNew >= aDepthCueingFrontPlaneNew) - { - Visual3d_DepthCueingDefinitionError::Raise ("Bad value for DepthCueingPlanes position"); - } - myGraphicDriver->DepthCueing (MyCView, aDepthCueingModeNew); - } - - // management of Zclipping - if (aFrontZClippingModeOld != aFrontZClippingModeNew - || aBackZClippingModeOld != aBackZClippingModeNew - || aZClippingFrontPlaneOld != aZClippingFrontPlaneNew - || aZClippingBackPlaneOld != aZClippingBackPlaneNew) - { - if (aBackZClippingModeNew - && aFrontZClippingModeNew - && aZClippingBackPlaneNew >= aZClippingFrontPlaneNew) - { - Visual3d_ZClippingDefinitionError::Raise ("Bad value for ZClippingPlanes position"); - } - - myGraphicDriver->ClipLimit (MyCView, toWait); - } - - // management of textures - if (isTextEnvChanged - || isSurfDetailChanged) - { - myGraphicDriver->Environment (MyCView); - } - - UpdatePlanes(); // Update of planes of model clipping - UpdateLights(); // Update of light sources - } - - if (isVisModeChanged) - { - // Change of context => - // Remove structures that cannot be displayed in the new visualisation mode. - // It is not necessary to warn ViewManager as this structure should not disappear from - // the list of structures displayed in it. - NCollection_Sequence aStructs; - for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer == Visual3d_TOA_NO - || anAnswer == Visual3d_TOA_COMPUTE) - { - aStructs.Append (aStruct); - } - } - for (NCollection_Sequence::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next()) - { - Erase (aStructIter.ChangeValue(), Aspect_TOU_WAIT); - } - aStructs.Clear(); - - // Change of context => - // Display structures that can be displayed with the new visualisation mode. - // All structures with status Displayed are removed from the ViewManager - // and displayed in the view directly, if the structure is not already - // displayed and if the view accepts it in its context. - Graphic3d_MapOfStructure aMapDisplayed; - myViewManager->DisplayedStructures (aMapDisplayed); - for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aMapDisplayed); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); - if (IsDisplayed (aStruct)) - { - continue; - } - - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer == Visual3d_TOA_YES - || anAnswer == Visual3d_TOA_COMPUTE) - { - aStructs.Append (aStruct); - } - } - - for (NCollection_Sequence::Iterator aStructIter (aStructs); aStructIter.More(); aStructIter.Next()) - { - Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT); - } - } - - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : Context -// purpose : -// ======================================================================= -const Visual3d_ContextView& Visual3d_View::Context() const -{ - return MyContext; -} - -// ======================================================================= -// function : DisplayedStructures -// purpose : -// ======================================================================= -void Visual3d_View::DisplayedStructures (Graphic3d_MapOfStructure& theStructures) const -{ - if (IsDeleted()) - { - return; - } - - for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) - { - theStructures.Add (aStructIter.Key()); - } -} - -// ======================================================================= -// function : Activate -// purpose : -// ======================================================================= -void Visual3d_View::Activate() -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - if (!IsActive()) - { - myGraphicDriver->ActivateView (MyCView); - myGraphicDriver->Background (MyCView); - - MyCView.Active = 1; - - // Activation of a new view => - // Display structures that can be displayed in this new view. - // All structures with status - // Displayed in ViewManager are returned and displayed in - // the view directly, if the structure is not already - // displayed and if the view accepts it in its context. - Graphic3d_MapOfStructure aDisplayedStructs; - myViewManager->DisplayedStructures (aDisplayedStructs); - for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); - if (IsDisplayed (aStruct)) - { - continue; - } - - // If the structure can be displayed in the new context of the view, it is displayed. - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer == Visual3d_TOA_YES - || anAnswer == Visual3d_TOA_COMPUTE) - { - Display (aStruct, Aspect_TOU_WAIT); - } - } - } - - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : IsActive -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::IsActive() const -{ - return !IsDeleted() - && MyCView.Active; -} - -// ======================================================================= -// function : Deactivate -// purpose : -// ======================================================================= -void Visual3d_View::Deactivate() -{ - if (IsDeleted()) - { - return; - } - else if (!IsDefined()) - { - Visual3d_ViewDefinitionError::Raise ("Window not defined"); - } - - if (IsActive()) - { - myGraphicDriver->DeactivateView (MyCView); - - // Deactivation of a view => - // Removal of structures displayed in this view. - // All structures with status - // Displayed in ViewManager are returned and removed from - // the view directly, if the structure is not already - // displayed and if the view accepts it in its context. - Graphic3d_MapOfStructure aDisplayedStructs; - myViewManager->DisplayedStructures (aDisplayedStructs); - for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (aDisplayedStructs); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); - if (IsDisplayed (aStruct)) - { - continue; - } - - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer == Visual3d_TOA_YES - || anAnswer == Visual3d_TOA_COMPUTE) - { - Erase (aStruct, Aspect_TOU_WAIT); - } - } - - Update (myViewManager->UpdateMode()); - MyCView.Active = 0; // No action currently possible in the view - } -} - -// ======================================================================= -// function : Redraw -// purpose : -// ======================================================================= -void Visual3d_View::Redraw() -{ - Redraw (0, 0, 0, 0); -} - -// ======================================================================= -// function : Redraw -// purpose : -// ======================================================================= -void Visual3d_View::Redraw (const Standard_Integer theX, - const Standard_Integer theY, - const Standard_Integer theWidth, - const Standard_Integer theHeight) -{ - if (IsDeleted() - || !IsDefined() - || !IsActive() - || !MyWindow->IsMapped()) - { - return; - } - - for (Standard_Integer aRetryIter = 0; aRetryIter < 2; ++aRetryIter) - { - if (myGraphicDriver->IsDeviceLost()) - { - myViewManager->RecomputeStructures(); - myGraphicDriver->ResetDeviceLostFlag(); - } - - if (myStructuresUpdated) - { - AutoZFit(); - myStructuresUpdated = Standard_False; - } - - myGraphicDriver->Redraw (MyCView, theX, theY, theWidth, theHeight); - if (!myGraphicDriver->IsDeviceLost()) - { - return; - } - } -} - -// ======================================================================= -// function : RedrawImmediate -// purpose : -// ======================================================================= -void Visual3d_View::RedrawImmediate () -{ - if (IsDeleted() - || !IsDefined() - || !IsActive() - || !MyWindow->IsMapped()) - { - return; - } - - myGraphicDriver->RedrawImmediate (MyCView); -} - -// ======================================================================= -// function : Invalidate -// purpose : -// ======================================================================= -void Visual3d_View::Invalidate() -{ - myGraphicDriver->Invalidate (MyCView); -} - -// ======================================================================= -// function : IsInvalidated -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::IsInvalidated() const -{ - return myGraphicDriver->IsInvalidated (MyCView); -} - -// ======================================================================= -// function : Update -// purpose : -// ======================================================================= -void Visual3d_View::Update (Aspect_TypeOfUpdate theUpdateMode) -{ - myStructuresUpdated = Standard_True; - if (theUpdateMode == Aspect_TOU_ASAP) - { - Compute(); - Redraw (0, 0, 0, 0); - } -} - -// ======================================================================= -// function : Update -// purpose : -// ======================================================================= -void Visual3d_View::Update () -{ - Compute(); - myStructuresUpdated = Standard_True; - Redraw (0, 0, 0, 0); -} - -// ======================================================================== -// function : SetAutoZFitMode -// purpose : -// ======================================================================== -void Visual3d_View::SetAutoZFitMode (const Standard_Boolean theIsOn, - const Standard_Real theScaleFactor) -{ - Standard_ASSERT_RAISE (theScaleFactor > 0.0, "Zero or negative scale factor is not allowed."); - myAutoZFitScaleFactor = theScaleFactor; - myAutoZFitIsOn = theIsOn; -} - -// ======================================================================== -// function : AutoZFitMode -// purpose : -// ======================================================================== -Standard_Boolean Visual3d_View::AutoZFitMode() const -{ - return myAutoZFitIsOn; -} - -// ======================================================================== -// function : AutoZFitScaleFactor -// purpose : -// ======================================================================== -Standard_Real Visual3d_View::AutoZFitScaleFactor() const -{ - return myAutoZFitScaleFactor; -} - -// ======================================================================== -// function : AutoZFit -// purpose : -// ======================================================================== -void Visual3d_View::AutoZFit() -{ - if (!AutoZFitMode()) - { - return; - } - - ZFitAll (myAutoZFitScaleFactor); -} - -// ======================================================================== -// function : ZFitAll -// purpose : -// ======================================================================== -void Visual3d_View::ZFitAll (const Standard_Real theScaleFactor) -{ - Bnd_Box aMinMaxBox = MinMaxValues (Standard_False); // applicative min max boundaries - Bnd_Box aGraphicBox = MinMaxValues (Standard_True); // real graphical boundaries (not accounting infinite flag). - - const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera; - aCamera->ZFitAll (theScaleFactor, aMinMaxBox, aGraphicBox); -} - -// ======================================================================== -// function : acceptDisplay -// purpose : -// ======================================================================== -Visual3d_TypeOfAnswer Visual3d_View::acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const -{ - const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization(); - switch (theStructType) - { - case Graphic3d_TOS_ALL: - { - return Visual3d_TOA_YES; // The structure accepts any type of view - } - case Graphic3d_TOS_SHADING: - { - return aViewType == Visual3d_TOV_SHADING - ? Visual3d_TOA_YES - : Visual3d_TOA_NO; - } - case Graphic3d_TOS_WIREFRAME: - { - return aViewType == Visual3d_TOV_WIREFRAME - ? Visual3d_TOA_YES - : Visual3d_TOA_NO; - } - case Graphic3d_TOS_COMPUTED: - { - return (aViewType == Visual3d_TOV_SHADING || aViewType == Visual3d_TOV_WIREFRAME) - ? Visual3d_TOA_COMPUTE - : Visual3d_TOA_NO; - } - } - return Visual3d_TOA_NO; -} - -// ======================================================================== -// function : ChangeDisplayPriority -// purpose : -// ======================================================================== -void Visual3d_View::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& theStruct, - const Standard_Integer /*theOldPriority*/, - const Standard_Integer theNewPriority) -{ - if (IsDeleted() - || !IsDefined() - || !IsActive() - || !IsDisplayed (theStruct)) - { - return; - } - - if (!myIsInComputedMode) - { - myGraphicDriver->ChangePriority (*theStruct->CStructure(), MyCView, theNewPriority); - return; - } - - const Standard_Integer anIndex = IsComputed (theStruct); - const Graphic3d_CStructure& aCStruct = anIndex != 0 - ? *(myStructsComputed.Value (anIndex)->CStructure()) - : *theStruct->CStructure(); - myGraphicDriver->ChangePriority (aCStruct, MyCView, theNewPriority); -} - -// ======================================================================== -// function : Clear -// purpose : -// ======================================================================== -void Visual3d_View::Clear (const Handle(Graphic3d_Structure)& theStruct, - const Standard_Boolean theWithDestruction) -{ - const Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0) - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex); - aCompStruct->GraphicClear (theWithDestruction); - aCompStruct->SetHLRValidation (Standard_False); - } -} - -// ======================================================================== -// function : Connect -// purpose : -// ======================================================================== -void Visual3d_View::Connect (const Handle(Graphic3d_Structure)& theMother, - const Handle(Graphic3d_Structure)& theDaughter) -{ - Standard_Integer anIndexM = IsComputed (theMother); - Standard_Integer anIndexD = IsComputed (theDaughter); - if (anIndexM != 0 - && anIndexD != 0) - { - const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM); - const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD); - aStructM->GraphicConnect (aStructD); - } -} - -// ======================================================================== -// function : Disconnect -// purpose : -// ======================================================================== -void Visual3d_View::Disconnect (const Handle(Graphic3d_Structure)& theMother, - const Handle(Graphic3d_Structure)& theDaughter) -{ - Standard_Integer anIndexM = IsComputed (theMother); - Standard_Integer anIndexD = IsComputed (theDaughter); - if (anIndexM != 0 - && anIndexD != 0) - { - const Handle(Graphic3d_Structure)& aStructM = myStructsComputed.Value (anIndexM); - const Handle(Graphic3d_Structure)& aStructD = myStructsComputed.Value (anIndexD); - aStructM->GraphicDisconnect (aStructD); - } -} - -// ======================================================================== -// function : Display -// purpose : -// ======================================================================== -void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct) -{ - Display (theStruct, myViewManager->UpdateMode()); -} - -// ======================================================================== -// function : Display -// purpose : -// ======================================================================== -void Visual3d_View::Display (const Handle(Graphic3d_Structure)& theStruct, - const Aspect_TypeOfUpdate theUpdateMode) -{ - if (IsDeleted() - || !IsDefined() - || !IsActive()) - { - return; - } - - // If Display on a structure present in the list of calculated structures while it is not - // or more, of calculated type => - // - removes it as well as the associated old computed - // THis happens when hlhsr becomes again of type e non computed after SetVisual. - Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0 - && theStruct->Visual() != Graphic3d_TOS_COMPUTED) - { - myStructsToCompute.Remove (anIndex); - myStructsComputed .Remove (anIndex); - anIndex = 0; - } - - Visual3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual()); - if (anAnswer == Visual3d_TOA_NO) - { - return; - } - - if (!ComputedMode()) - { - anAnswer = Visual3d_TOA_YES; - } - - if (anAnswer == Visual3d_TOA_YES) - { - if (!myStructsDisplayed.Add (theStruct)) - { - return; - } - - theStruct->CalculateBoundBox(); - myGraphicDriver->DisplayStructure (MyCView, theStruct, theStruct->DisplayPriority()); - Update (theUpdateMode); - return; - } - else if (anAnswer != Visual3d_TOA_COMPUTE) - { - return; - } - - if (anIndex != 0) - { - // Already computed, is COMPUTED still valid? - const Handle(Graphic3d_Structure)& anOldStruct = myStructsComputed.Value (anIndex); - if (anOldStruct->HLRValidation()) - { - // Case COMPUTED valid, to be displayed - if (!myStructsDisplayed.Add (theStruct)) - { - return; - } - - myGraphicDriver->DisplayStructure (MyCView, anOldStruct, theStruct->DisplayPriority()); - Update (theUpdateMode); - return; - } - else - { - // Case COMPUTED invalid - // Is there another valid representation? - // Find in the sequence of already calculated structures - // 1/ Structure having the same Owner as - // 2/ That is not - // 3/ The COMPUTED which of is valid - const Standard_Integer aNewIndex = HaveTheSameOwner (theStruct); - if (aNewIndex != 0) - { - // Case of COMPUTED invalid, WITH a valid of replacement; to be displayed - if (!myStructsDisplayed.Add (theStruct)) - { - return; - } - - const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex); - myStructsComputed.SetValue (anIndex, aNewStruct); - myGraphicDriver->DisplayStructure (MyCView, aNewStruct, theStruct->DisplayPriority()); - Update (theUpdateMode); - return; - } - else - { - // Case COMPUTED invalid, WITHOUT a valid of replacement - // COMPUTED is removed if displayed - if (myStructsDisplayed.Contains (theStruct)) - { - myGraphicDriver->EraseStructure (MyCView, anOldStruct); - } - } - } - } - - // Compute + Validation - Handle(Graphic3d_Structure) aStruct; - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - theStruct->Transform (aTrsf); - if (anIndex != 0) - { - TColStd_Array2OfReal anIdent (0, 3, 0, 3); - for (Standard_Integer ii = 0; ii <= 3; ++ii) - { - for (Standard_Integer jj = 0; jj <= 3; ++jj) - { - anIdent (ii, jj) = (ii == jj ? 1.0 : 0.0); - } - } - - aStruct = myStructsComputed.Value (anIndex); - aStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); - if (theStruct->IsTransformed()) - { - theStruct->Compute (this, aTrsf, aStruct); - } - else - { - theStruct->Compute (this, aStruct); - } - } - else - { - aStruct = theStruct->IsTransformed() - ? theStruct->Compute (this, aTrsf) - : theStruct->Compute (this); - } - - aStruct->SetHLRValidation (Standard_True); - - // TOCOMPUTE and COMPUTED associated to sequences are added - myStructsToCompute.Append (theStruct); - myStructsComputed .Append (aStruct); - - // The previous are removed if necessary - if (anIndex != 0) - { - myStructsToCompute.Remove (anIndex); - myStructsComputed .Remove (anIndex); - } - - // Of which type will be the computed? - const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization(); - const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME - && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING; - const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING - && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME; - if (!toComputeShading && !toComputeWireframe) - { - anAnswer = Visual3d_TOA_NO; - } - else - { - aStruct->SetVisual (toComputeWireframe ? Graphic3d_TOS_WIREFRAME : Graphic3d_TOS_SHADING); - anAnswer = acceptDisplay (aStruct->Visual()); - } - - if (theStruct->IsHighlighted()) - { - aStruct->Highlight (Aspect_TOHM_COLOR, theStruct->HighlightColor(), Standard_False); - } - - // It is displayed only if the calculated structure - // has a proper type corresponding to the one of the view. - if (anAnswer == Visual3d_TOA_NO) - { - return; - } - - myStructsDisplayed.Add (theStruct); - myGraphicDriver->DisplayStructure (MyCView, aStruct, theStruct->DisplayPriority()); - - Update (theUpdateMode); -} - -// ======================================================================== -// function : Erase -// purpose : -// ======================================================================== -void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct) -{ - if (!IsDeleted()) - { - Erase (theStruct, myViewManager->UpdateMode()); - } -} - -// ======================================================================== -// function : Erase -// purpose : -// ======================================================================== -void Visual3d_View::Erase (const Handle(Graphic3d_Structure)& theStruct, - const Aspect_TypeOfUpdate theUpdateMode) -{ - if ( IsDeleted() - || !IsDisplayed (theStruct)) - { - return; - } - - Visual3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual()); - if (!ComputedMode()) - { - anAnswer = Visual3d_TOA_YES; - } - - if (anAnswer != Visual3d_TOA_COMPUTE) - { - myGraphicDriver->EraseStructure (MyCView, theStruct); - } - else if (anAnswer == Visual3d_TOA_COMPUTE - && myIsInComputedMode) - { - const Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0) - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); - myGraphicDriver->EraseStructure (MyCView, aCompStruct); - } - } - myStructsDisplayed.Remove (theStruct); - Update (theUpdateMode); -} - -// ======================================================================== -// function : Highlight -// purpose : -// ======================================================================== -void Visual3d_View::Highlight (const Handle(Graphic3d_Structure)& theStruct, - const Aspect_TypeOfHighlightMethod theMethod) -{ - const Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0) - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex); - aCompStruct->Highlight (theMethod, theStruct->HighlightColor(), Standard_False); - } -} - -// ======================================================================== -// function : IsComputed -// purpose : -// ======================================================================== -Standard_Boolean Visual3d_View::IsComputed (const Standard_Integer theStructId, - Handle(Graphic3d_Structure)& theComputedStruct) const -{ - theComputedStruct.Nullify(); - if (!ComputedMode()) - return Standard_False; - - const Standard_Integer aNbStructs = myStructsToCompute.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter) - { - if (myStructsToCompute.Value (aStructIter)->Identification() == theStructId) - { - theComputedStruct = myStructsComputed (aStructIter); - return Standard_True; - } - } - return Standard_False; -} - -// ======================================================================== -// function : SetTransform -// purpose : -// ======================================================================== -void Visual3d_View::SetTransform (const Handle(Graphic3d_Structure)& theStruct, - const TColStd_Array2OfReal& theTrsf) -{ - const Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0) - { - // Test is somewhat light ! - // trsf is transferred only if it is : - // a translation - // a scale - if (theTrsf (0, 1) != 0.0 || theTrsf (0, 2) != 0.0 - || theTrsf (1, 0) != 0.0 || theTrsf (1, 2) != 0.0 - || theTrsf (2, 0) != 0.0 || theTrsf (2, 1) != 0.0) - { - ReCompute (theStruct); - } - else - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); - aCompStruct->GraphicTransform (theTrsf); - } - } - - theStruct->CalculateBoundBox(); - if (!theStruct->IsMutable() - && !theStruct->CStructure()->IsForHighlight - && !theStruct->CStructure()->IsInfinite) - { - const Graphic3d_ZLayerId aLayerId = theStruct->GetZLayer(); - myGraphicDriver->InvalidateBVHData (MyCView, aLayerId); - } -} - -// ======================================================================== -// function : UnHighlight -// purpose : -// ======================================================================== -void Visual3d_View::UnHighlight (const Handle(Graphic3d_Structure)& theStruct) -{ - Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex != 0) - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.ChangeValue (anIndex); - aCompStruct->GraphicUnHighlight(); - } -} - -// ======================================================================== -// function : IsComputed -// purpose : -// ======================================================================== -Standard_Integer Visual3d_View::IsComputed (const Handle(Graphic3d_Structure)& theStruct) const -{ - const Standard_Integer aStructId = theStruct->Identification(); - const Standard_Integer aNbStructs = myStructsToCompute.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbStructs; ++aStructIter) - { - const Handle(Graphic3d_Structure)& aStruct = myStructsToCompute.Value (aStructIter); - if (aStruct->Identification() == aStructId) - { - return aStructIter; - } - } - return 0; -} - -// ======================================================================== -// function : IsDisplayed -// purpose : -// ======================================================================== -Standard_Boolean Visual3d_View::IsDisplayed (const Handle(Graphic3d_Structure)& theStruct) const -{ - return !IsDeleted() - && myStructsDisplayed.Contains (theStruct); -} - -// ======================================================================== -// function : ContainsFacet -// purpose : -// ======================================================================== -Standard_Boolean Visual3d_View::ContainsFacet() const -{ - for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) - { - if (aStructIter.Key()->ContainsFacet()) - { - return Standard_True; - } - } - return Standard_False; -} - -// ======================================================================== -// function : ContainsFacet -// purpose : -// ======================================================================== -Standard_Boolean Visual3d_View::ContainsFacet (const Graphic3d_MapOfStructure& theSet) const -{ - for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next()) - { - if (aStructIter.Key()->ContainsFacet()) - { - return Standard_True; - } - } - return Standard_False; -} - -// ======================================================================== -// function : MinMaxValues -// purpose : -// ======================================================================== -Bnd_Box Visual3d_View::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const -{ - Bnd_Box aResult = MinMaxValues (myStructsDisplayed, theToIgnoreInfiniteFlag); - return aResult; -} - -// ======================================================================== -// function : MinMaxValues -// purpose : -// ======================================================================== -Bnd_Box Visual3d_View::MinMaxValues (const Graphic3d_MapOfStructure& theSet, - const Standard_Boolean theToIgnoreInfiniteFlag) const -{ - Bnd_Box aResult; - const Standard_Integer aViewId = MyCView.ViewId; - for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key(); - if (!aStructure->IsVisible()|| aStructure->IsEmpty()) - { - continue; - } - else if (!aStructure->CStructure()->ViewAffinity.IsNull() - && !aStructure->CStructure()->ViewAffinity->IsVisible (aViewId)) - { - continue; - } - - // "FitAll" operation ignores object with transform persistence parameter - if (aStructure->TransformPersistence().Flags) - { - // Panning and 2d persistence apply changes to projection or/and its translation components. - // It makes them incompatible with z-fitting algorithm. Ignored by now. - if (!theToIgnoreInfiniteFlag || - (aStructure->TransformPersistence().Flags & Graphic3d_TMF_2d) || - (aStructure->TransformPersistence().Flags & Graphic3d_TMF_PanPers)) - { - continue; - } - } - - Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag); - - if (aBox.IsWhole() || aBox.IsVoid()) - { - continue; - } - - if (aStructure->TransformPersistence().Flags) - { - Standard_Integer aWidth, aHeight; - Window()->Size (aWidth, aHeight); - - const Graphic3d_Mat4d& aProjectionMat = MyCView.Context.Camera->ProjectionMatrix(); - const Graphic3d_Mat4d& aWorldViewMat = MyCView.Context.Camera->OrientationMatrix(); - - aStructure->TransformPersistence().Apply (aProjectionMat, aWorldViewMat, aWidth, aHeight, aBox); - } - - // To prevent float overflow at camera parameters calculation and further - // rendering, bounding boxes with at least one vertex coordinate out of - // float range are skipped by view fit algorithms - if (Abs (aBox.CornerMax().X()) >= ShortRealLast() || - Abs (aBox.CornerMax().Y()) >= ShortRealLast() || - Abs (aBox.CornerMax().Z()) >= ShortRealLast() || - Abs (aBox.CornerMin().X()) >= ShortRealLast() || - Abs (aBox.CornerMin().Y()) >= ShortRealLast() || - Abs (aBox.CornerMin().Z()) >= ShortRealLast()) - { - continue; - } - - aResult.Add (aBox); - } - return aResult; -} - -// ======================================================================= -// function : NumberOfDisplayedStructures -// purpose : -// ======================================================================= -Standard_Integer Visual3d_View::NumberOfDisplayedStructures() const -{ - return myStructsDisplayed.Extent(); -} - -// ======================================================================= -// function : Projects -// purpose : -// ======================================================================= -void Visual3d_View::Projects (const Standard_Real theX, - const Standard_Real theY, - const Standard_Real theZ, - Standard_Real& thePX, - Standard_Real& thePY, - Standard_Real& thePZ) const -{ - const Handle(Graphic3d_Camera)& aCamera = MyCView.Context.Camera; - - gp_XYZ aViewSpaceDimensions = aCamera->ViewDimensions(); - Standard_Real aXSize = aViewSpaceDimensions.X(); - Standard_Real aYSize = aViewSpaceDimensions.Y(); - Standard_Real aZSize = aViewSpaceDimensions.Z(); - - gp_Pnt aPoint = aCamera->Project (gp_Pnt (theX, theY, theZ)); - - // NDC [-1, 1] --> PROJ [ -size / 2, +size / 2 ] - thePX = aPoint.X() * aXSize * 0.5; - thePY = aPoint.Y() * aYSize * 0.5; - thePZ = aPoint.Z() * aZSize * 0.5; -} - -// ======================================================================= -// function : Identification -// purpose : -// ======================================================================= -Standard_Integer Visual3d_View::Identification() const -{ - return MyCView.ViewId; -} - -// ======================================================================= -// function : UpdateView -// purpose : -// ======================================================================= -void Visual3d_View::UpdateView() -{ - MyCView.Context.Aliasing = MyContext.AliasingIsOn(); - MyCView.Context.BackZClipping = MyContext.BackZClippingIsOn(); - MyCView.Context.FrontZClipping = MyContext.FrontZClippingIsOn(); - MyCView.Context.DepthCueing = MyContext.DepthCueingIsOn(); - - MyCView.Context.ZClipFrontPlane = float (MyContext.ZClippingFrontPlane()); - MyCView.Context.ZClipBackPlane = float (MyContext.ZClippingBackPlane()); - MyCView.Context.DepthFrontPlane = float (MyContext.DepthCueingFrontPlane()); - MyCView.Context.DepthBackPlane = float (MyContext.DepthCueingBackPlane()); - - MyCView.Context.Model = MyContext.Model(); - MyCView.Context.Visualization = MyContext.Visualization(); - - MyCView.Context.TextureEnv = MyContext.TextureEnv(); - MyCView.Context.SurfaceDetail = MyContext.SurfaceDetail(); -} - -// ======================================================================= -// function : Compute -// purpose : -// ======================================================================= -void Visual3d_View::Compute() -{ - // force HLRValidation to False on all structures calculated in the view - const Standard_Integer aNbCompStructs = myStructsComputed.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbCompStructs; ++aStructIter) - { - myStructsComputed.Value (aStructIter)->SetHLRValidation (Standard_False); - } - - if (!ComputedMode()) - { - return; - } - - // Change of orientation or of projection type => - // Remove structures that were calculated for the previous orientation. - // Recalculation of new structures. - NCollection_Sequence aStructsSeq; - for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) - { - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStructIter.Key()->Visual()); - if (anAnswer == Visual3d_TOA_COMPUTE) - { - aStructsSeq.Append (aStructIter.Key()); // if the structure was calculated, it is recalculated - } - } - - for (NCollection_Sequence::Iterator aStructIter (aStructsSeq); aStructIter.More(); aStructIter.Next()) - { - Display (aStructIter.ChangeValue(), Aspect_TOU_WAIT); - } -} - -// ======================================================================= -// function : ReCompute -// purpose : -// ======================================================================= -void Visual3d_View::ReCompute (const Handle(Graphic3d_Structure)& theStruct) -{ - theStruct->CalculateBoundBox(); - if (!theStruct->IsMutable() - && !theStruct->CStructure()->IsForHighlight - && !theStruct->CStructure()->IsInfinite) - { - const Standard_Integer aLayerId = theStruct->DisplayPriority(); - myGraphicDriver->InvalidateBVHData(MyCView, aLayerId); - } - - if (!ComputedMode() - || IsDeleted() - || !IsDefined() - || !IsActive() - || !MyWindow->IsMapped() - || !theStruct->IsDisplayed()) - { - return; - } - - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (theStruct->Visual()); - if (anAnswer != Visual3d_TOA_COMPUTE) - { - return; - } - - const Standard_Integer anIndex = IsComputed (theStruct); - if (anIndex == 0) - { - return; - } - - // compute + validation - TColStd_Array2OfReal anIdent (0, 3, 0, 3); - for (Standard_Integer aRow = 0; aRow <= 3; ++aRow) - { - for (Standard_Integer aCol = 0; aCol <= 3; ++aCol) - { - anIdent (aRow, aCol) = (aRow == aCol ? 1.0 : 0.0); - } - } - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - theStruct->Transform (aTrsf); - - Handle(Graphic3d_Structure) aCompStructOld = myStructsComputed.ChangeValue (anIndex); - Handle(Graphic3d_Structure) aCompStruct = aCompStructOld; - aCompStruct->SetTransform (anIdent, Graphic3d_TOC_REPLACE); - theStruct->IsTransformed() ? theStruct->Compute (this, aTrsf, aCompStruct) - : theStruct->Compute (this, aCompStruct); - aCompStruct->SetHLRValidation (Standard_True); - - // of which type will be the computed? - const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization(); - const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME - && theStruct->ComputeVisual() != Graphic3d_TOS_SHADING; - const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING - && theStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME; - if (toComputeWireframe) - { - aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME); - } - else if (toComputeShading) - { - aCompStruct->SetVisual (Graphic3d_TOS_SHADING); - } - - if (theStruct->IsHighlighted()) - { - aCompStruct->Highlight (Aspect_TOHM_COLOR, theStruct->HighlightColor(), Standard_False); - } - - // The previous calculation is removed and the new one is displayed - myGraphicDriver->EraseStructure (MyCView, aCompStructOld); - myGraphicDriver->DisplayStructure (MyCView, aCompStruct, theStruct->DisplayPriority()); - - // why not just replace existing items? - //myStructsToCompute.ChangeValue (anIndex) = theStruct; - //myStructsComputed .ChangeValue (anIndex) = aCompStruct; - - // hlhsr and the new associated compute are added - myStructsToCompute.Append (theStruct); - myStructsComputed .Append (aCompStruct); - - // hlhsr and the new associated compute are removed - myStructsToCompute.Remove (anIndex); - myStructsComputed .Remove (anIndex); -} - -// ======================================================================= -// function : GraphicDriver -// purpose : -// ======================================================================= -const Handle(Graphic3d_GraphicDriver)& Visual3d_View::GraphicDriver() const -{ - return myGraphicDriver; -} - -// ======================================================================= -// function : HaveTheSameOwner -// purpose : -// ======================================================================= -Standard_Integer Visual3d_View::HaveTheSameOwner (const Handle(Graphic3d_Structure)& theStruct) const -{ - // Find in the sequence of already calculated structures - // 1/ Structure with the same Owner as - // 2/ Which is not - // 3/ COMPUTED which of is valid - const Standard_Integer aNbToCompStructs = myStructsToCompute.Length(); - for (Standard_Integer aStructIter = 1; aStructIter <= aNbToCompStructs; ++aStructIter) - { - const Handle(Graphic3d_Structure)& aStructToComp = myStructsToCompute.Value (aStructIter); - if (aStructToComp->Owner() == theStruct->Owner() - && aStructToComp->Identification() != theStruct->Identification()) - { - const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (aStructIter); - if (aStructComp->HLRValidation()) - { - return aStructIter; - } - } - } - return 0; -} - -// ======================================================================= -// function : CView -// purpose : -// ======================================================================= -Standard_Address Visual3d_View::CView() const -{ - return Standard_Address (&MyCView); -} - -// ======================================================================= -// function : ZBufferTriedronSetup -// purpose : -// ======================================================================= -void Visual3d_View::ZBufferTriedronSetup (const Quantity_NameOfColor theXColor, - const Quantity_NameOfColor theYColor, - const Quantity_NameOfColor theZColor, - const Standard_Real theSizeRatio, - const Standard_Real theAxisDiametr, - const Standard_Integer theNbFacettes) -{ - myGraphicDriver->ZBufferTriedronSetup (MyCView, theXColor, theYColor, theZColor, - theSizeRatio, theAxisDiametr, theNbFacettes); -} - -// ======================================================================= -// function : TriedronDisplay -// purpose : -// ======================================================================= -void Visual3d_View::TriedronDisplay (const Aspect_TypeOfTriedronPosition thePosition, - const Quantity_NameOfColor theColor, - const Standard_Real theScale, - const Standard_Boolean theAsWireframe) -{ - myGraphicDriver->TriedronDisplay (MyCView, thePosition, theColor, theScale, theAsWireframe); -} - -// ======================================================================= -// function : TriedronErase -// purpose : -// ======================================================================= -void Visual3d_View::TriedronErase() -{ - myGraphicDriver->TriedronErase (MyCView); -} - -// ======================================================================= -// function : TriedronEcho -// purpose : -// ======================================================================= -void Visual3d_View::TriedronEcho (const Aspect_TypeOfTriedronEcho theType) -{ - myGraphicDriver->TriedronEcho (MyCView, theType); -} - -static void SetMinMaxValuesCallback (Visual3d_View* theView) -{ - Graphic3d_CView* aCView = (Graphic3d_CView* )(theView->CView()); - Bnd_Box aBox = theView->MinMaxValues(); - if (!aBox.IsVoid()) - { - gp_Pnt aMin = aBox.CornerMin(); - gp_Pnt aMax = aBox.CornerMax(); - - Graphic3d_Vec3 aMinVec ((Standard_ShortReal )aMin.X(), (Standard_ShortReal )aMin.Y(), (Standard_ShortReal )aMin.Z()); - Graphic3d_Vec3 aMaxVec ((Standard_ShortReal )aMax.X(), (Standard_ShortReal )aMax.Y(), (Standard_ShortReal )aMax.Z()); - const Handle(Graphic3d_GraphicDriver)& aDriver = theView->GraphicDriver(); - aDriver->GraduatedTrihedronMinMaxValues (*aCView, aMinVec, aMaxVec); - - } -} - -// ======================================================================= -// function : GetGraduatedTrihedron -// purpose : -// ======================================================================= -const Graphic3d_GraduatedTrihedron& Visual3d_View::GetGraduatedTrihedron() const -{ - return myGTrihedron; -} - -// ======================================================================= -// function : GraduatedTrihedronDisplay -// purpose : -// ======================================================================= -void Visual3d_View::GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrihedronData) -{ - myGTrihedron = theTrihedronData; - - myGTrihedron.PtrVisual3dView = this; - myGTrihedron.CubicAxesCallback = SetMinMaxValuesCallback; - - myGraphicDriver->GraduatedTrihedronDisplay (MyCView, myGTrihedron); -} - -// ======================================================================= -// function : GraduatedTrihedronErase -// purpose : -// ======================================================================= -void Visual3d_View::GraduatedTrihedronErase() -{ - myGTrihedron.PtrVisual3dView = NULL; - myGraphicDriver->GraduatedTrihedronErase (MyCView); -} - -// ======================================================================= -// function : LightLimit -// purpose : -// ======================================================================= -Standard_Integer Visual3d_View::LightLimit() const -{ - return myGraphicDriver->InquireLightLimit(); -} - -// ======================================================================= -// function : PlaneLimit -// purpose : -// ======================================================================= -Standard_Integer Visual3d_View::PlaneLimit() const -{ - return myGraphicDriver->InquirePlaneLimit(); -} - -// ======================================================================= -// function : ViewManager -// purpose : -// ======================================================================= -Handle(Visual3d_ViewManager) Visual3d_View::ViewManager() const -{ - return myViewManager; -} - -// ======================================================================= -// function : SetComputedMode -// purpose : -// ======================================================================= -void Visual3d_View::SetComputedMode (const Standard_Boolean theMode) -{ - if (( theMode && myIsInComputedMode) - || (!theMode && !myIsInComputedMode)) - { - return; - } - - myIsInComputedMode = theMode; - if (!myIsInComputedMode) - { - for (Graphic3d_MapOfStructure::Iterator aStructIter (myStructsDisplayed); aStructIter.More(); aStructIter.Next()) - { - const Handle(Graphic3d_Structure)& aStruct = aStructIter.Key(); - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer != Visual3d_TOA_COMPUTE) - { - continue; - } - - const Standard_Integer anIndex = IsComputed (aStruct); - if (anIndex != 0) - { - const Handle(Graphic3d_Structure)& aStructComp = myStructsComputed.Value (anIndex); - myGraphicDriver->EraseStructure (MyCView, aStructComp); - myGraphicDriver->DisplayStructure (MyCView, aStruct, aStruct->DisplayPriority()); - } - } - return; - } - - for (Graphic3d_MapOfStructure::Iterator aDispStructIter (myStructsDisplayed); aDispStructIter.More(); aDispStructIter.Next()) - { - Handle(Graphic3d_Structure) aStruct = aDispStructIter.Key(); - const Visual3d_TypeOfAnswer anAnswer = acceptDisplay (aStruct->Visual()); - if (anAnswer != Visual3d_TOA_COMPUTE) - { - continue; - } - - const Standard_Integer anIndex = IsComputed (aStruct); - if (anIndex != 0) - { - myGraphicDriver->EraseStructure (MyCView, aStruct); - myGraphicDriver->DisplayStructure (MyCView, myStructsComputed.Value (anIndex), aStruct->DisplayPriority()); - - Display (aStruct, Aspect_TOU_WAIT); - if (aStruct->IsHighlighted()) - { - const Handle(Graphic3d_Structure)& aCompStruct = myStructsComputed.Value (anIndex); - if (!aCompStruct->IsHighlighted()) - { - aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False); - } - } - } - else - { - TColStd_Array2OfReal aTrsf (0, 3, 0, 3); - aStruct->Transform (aTrsf); - Handle(Graphic3d_Structure) aCompStruct = aStruct->IsTransformed() ? aStruct->Compute (this, aTrsf) : aStruct->Compute (this); - aCompStruct->SetHLRValidation (Standard_True); - - const Visual3d_TypeOfVisualization aViewType = MyContext.Visualization(); - const Standard_Boolean toComputeWireframe = aViewType == Visual3d_TOV_WIREFRAME - && aStruct->ComputeVisual() != Graphic3d_TOS_SHADING; - const Standard_Boolean toComputeShading = aViewType == Visual3d_TOV_SHADING - && aStruct->ComputeVisual() != Graphic3d_TOS_WIREFRAME; - if (toComputeWireframe) aCompStruct->SetVisual (Graphic3d_TOS_WIREFRAME); - if (toComputeShading ) aCompStruct->SetVisual (Graphic3d_TOS_SHADING); - - if (aStruct->IsHighlighted()) - { - aCompStruct->Highlight (Aspect_TOHM_COLOR, aStruct->HighlightColor(), Standard_False); - } - - Standard_Boolean hasResult = Standard_False; - const Standard_Integer aNbToCompute = myStructsToCompute.Length(); - const Standard_Integer aStructId = aStruct->Identification(); - for (Standard_Integer aToCompStructIter = 1; aToCompStructIter <= aNbToCompute; ++aToCompStructIter) - { - if (myStructsToCompute.Value (aToCompStructIter)->Identification() == aStructId) - { - hasResult = Standard_True; - myStructsComputed.ChangeValue (aToCompStructIter) = aCompStruct; - break; - } - } - - if (!hasResult) - { - myStructsToCompute.Append (aStruct); - myStructsComputed .Append (aCompStruct); - } - - myGraphicDriver->EraseStructure (MyCView, aStruct); - myGraphicDriver->DisplayStructure (MyCView, aCompStruct, aStruct->DisplayPriority()); - } - } - Update (myViewManager->UpdateMode()); -} - -// ======================================================================= -// function : ComputedMode -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::ComputedMode() const -{ - return myIsInComputedMode; -} - -// ======================================================================= -// function : SetBackFacingModel -// purpose : -// ======================================================================= -void Visual3d_View::SetBackFacingModel (const Visual3d_TypeOfBackfacingModel theModel) -{ - switch (theModel) - { - default: - case Visual3d_TOBM_AUTOMATIC: - MyCView.Backfacing = 0; - break; - case Visual3d_TOBM_FORCE: - MyCView.Backfacing = 1; - break; - case Visual3d_TOBM_DISABLE: - MyCView.Backfacing = -1; - break; - } - myGraphicDriver->SetBackFacingModel (MyCView); -} - -// ======================================================================= -// function : BackFacingModel -// purpose : -// ======================================================================= -Visual3d_TypeOfBackfacingModel Visual3d_View::BackFacingModel() const -{ - switch (MyCView.Backfacing) - { - case 0: return Visual3d_TOBM_AUTOMATIC; - case 1: return Visual3d_TOBM_FORCE; - } - return Visual3d_TOBM_DISABLE; -} - -// ======================================================================= -// function : ReadDepths -// purpose : -// ======================================================================= -void Visual3d_View::ReadDepths (const Standard_Integer theX, - const Standard_Integer theY, - const Standard_Integer theWidth, - const Standard_Integer theHeight, - const Standard_Address theBuffer) const -{ - myGraphicDriver->ReadDepths (MyCView, theX, theY, theWidth, theHeight, theBuffer); -} - -// ======================================================================= -// function : FBOCreate -// purpose : -// ======================================================================= -Graphic3d_PtrFrameBuffer Visual3d_View::FBOCreate(const Standard_Integer theWidth, - const Standard_Integer theHeight) -{ - return myGraphicDriver->FBOCreate( MyCView, theWidth, theHeight ); -} - -// ======================================================================= -// function : FBORelease -// purpose : -// ======================================================================= -void Visual3d_View::FBORelease(Graphic3d_PtrFrameBuffer& theFBOPtr) -{ - myGraphicDriver->FBORelease( MyCView, theFBOPtr ); -} - -// ======================================================================= -// function : FBOGetDimensions -// purpose : -// ======================================================================= -void Visual3d_View::FBOGetDimensions(const Graphic3d_PtrFrameBuffer theFBOPtr, - Standard_Integer& theWidth, Standard_Integer& theHeight, - Standard_Integer& theWidthMax, Standard_Integer& theHeightMax) -{ - myGraphicDriver->FBOGetDimensions( MyCView, theFBOPtr, - theWidth, theHeight, - theWidthMax, theHeightMax ); -} - -// ======================================================================= -// function : FBOChangeViewport -// purpose : -// ======================================================================= -void Visual3d_View::FBOChangeViewport(Graphic3d_PtrFrameBuffer& theFBOPtr, - const Standard_Integer theWidth, const Standard_Integer theHeight) -{ - myGraphicDriver->FBOChangeViewport( MyCView, theFBOPtr, - theWidth, theHeight ); -} - -// ======================================================================= -// function : BufferDump -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::BufferDump (Image_PixMap& theImage, - const Graphic3d_BufferType& theBufferType) -{ - return myGraphicDriver->BufferDump (MyCView, theImage, theBufferType); -} - -// ======================================================================= -// function : EnableGLLight -// purpose : -// ======================================================================= -void Visual3d_View::EnableGLLight( const Standard_Boolean enable ) const -{ - myGraphicDriver->SetGLLightEnabled( MyCView, enable ); -} - -// ======================================================================= -// function : IsGLLightEnabled -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::IsGLLightEnabled() const -{ - return myGraphicDriver->IsGLLightEnabled( MyCView ); -} - -// ======================================================================= -// function : Export -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::Export (const Standard_CString theFileName, - const Graphic3d_ExportFormat theFormat, - const Graphic3d_SortType theSortType, - const Standard_Real thePrecision, - const Standard_Address theProgressBarFunc, - const Standard_Address theProgressObject) const -{ - Standard_Integer aWidth, aHeight; - Window()->Size (aWidth, aHeight); - - return myGraphicDriver->Export (theFileName, theFormat, theSortType, - aWidth, aHeight, MyCView, - thePrecision, theProgressBarFunc, theProgressObject); -} - -// ======================================================================= -// function : SetZLayerSettings -// purpose : -// ======================================================================= -void Visual3d_View::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings) -{ - myGraphicDriver->SetZLayerSettings (MyCView, theLayerId, theSettings); -} - -// ======================================================================= -// function : AddZLayer -// purpose : -// ======================================================================= -void Visual3d_View::AddZLayer (const Graphic3d_ZLayerId theLayerId) -{ - myGraphicDriver->AddZLayer (MyCView, theLayerId); -} - -// ======================================================================= -// function : RemoveZLayer -// purpose : -// ======================================================================= -void Visual3d_View::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) -{ - myGraphicDriver->RemoveZLayer (MyCView, theLayerId); -} - -// ======================================================================= -// function : ChangeZLayer -// purpose : -// ======================================================================= -void Visual3d_View::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, - const Graphic3d_ZLayerId theLayerId) -{ - myGraphicDriver->ChangeZLayer (*(theStructure->CStructure()), MyCView, theLayerId); -} - -// ======================================================================= -// function : Print -// purpose : -// ======================================================================= -Standard_Boolean Visual3d_View::Print (const Aspect_Handle thePrintDC, - const Standard_Boolean theToShowBackground, - const Standard_CString theFilename, - const Aspect_PrintAlgo thePrintAlgorithm, - const Standard_Real theScaleFactor) const -{ - if (IsDeleted() - || !IsDefined() - || !IsActive() - || !MyWindow->IsMapped()) - { - return Standard_False; - } - - return myGraphicDriver->Print (MyCView, thePrintDC, theToShowBackground, - theFilename, thePrintAlgorithm, theScaleFactor); -} - -//============================================================================= -//function : HiddenObjects -//purpose : -//============================================================================= -const Handle(Graphic3d_NMapOfTransient)& Visual3d_View::HiddenObjects() const -{ - return myHiddenObjects; -} - -//============================================================================= -//function : HiddenObjects -//purpose : -//============================================================================= -Handle(Graphic3d_NMapOfTransient)& Visual3d_View::ChangeHiddenObjects() -{ - return myHiddenObjects; -} diff --git a/src/Visual3d/Visual3d_View.hxx b/src/Visual3d/Visual3d_View.hxx deleted file mode 100644 index 961247bcdf..0000000000 --- a/src/Visual3d/Visual3d_View.hxx +++ /dev/null @@ -1,622 +0,0 @@ -// Created on: 1991-09-17 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_View_HeaderFile -#define _Visual3d_View_HeaderFile - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -class Aspect_Window; -class Graphic3d_GraphicDriver; -class Visual3d_TransformError; -class Visual3d_ViewDefinitionError; -class Visual3d_ViewManager; -class Visual3d_Layer; -class Aspect_Background; -class Aspect_GradientBackground; -class Visual3d_ContextView; -class Bnd_Box; -class Graphic3d_Structure; - - -class Visual3d_View; -DEFINE_STANDARD_HANDLE(Visual3d_View, Graphic3d_DataStructureManager) - -//! Creation and edition of a view in a 3D visualiser. -//! A 3D view is composed of an "orientation" part defined -//! by the position of the observer, the direction of view, -//! and a "mapping" part defined by the type of projection -//! (parallel or perspective) and by the window-viewport -//! couple which allows passage from the projected coordinate -//! space into the screen space. -//! Summary of 3D Viewing -//! To define a view, you must define: -//! - The view orientation transformation -//! - The view mapping transformation -//! - The view representation. -//! To activate a view, you must define: -//! - The associated window. -class Visual3d_View : public Graphic3d_DataStructureManager -{ - -public: - - - //! Creates a view in the viewer with a default - //! orientation and a default mapping. - Standard_EXPORT Visual3d_View(const Handle(Visual3d_ViewManager)& AManager); - - //! Activates the view . - //! Map the associated window on the screen and - //! post the view in this window. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void Activate(); - - //! Deactivates the view . - //! Unmap the associated window on the screen and - //! unpost the view in this window. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void Deactivate(); - - //! Deletes and erases the view . - Standard_EXPORT virtual void Destroy() Standard_OVERRIDE; -~Visual3d_View() -{ - Destroy(); -} - - //! Updates screen in all cases. - Standard_EXPORT void Redraw(); - - //! Updates layer of immediate presentations. - Standard_EXPORT void RedrawImmediate(); - - //! Updates screen area in all cases. - //! area is given by his xy min corner and size in pixel coordinates - Standard_EXPORT void Redraw (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height); - - //! Invalidates view content but does not redraw it. - Standard_EXPORT void Invalidate(); - - //! Returns true if cached view content has been invalidated. - Standard_EXPORT Standard_Boolean IsInvalidated() const; - - //! Deletes and erases the view . - //! Warning: No more graphic operations in after this call. - Standard_EXPORT void Remove(); - - //! Updates the view after the modification - //! of the associated window. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void Resized(); - - //! Modifies the default window background. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void SetBackground (const Aspect_Background& ABack); - - - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void SetBackgroundImage (const Standard_CString FileName, const Aspect_FillMethod FillStyle, const Standard_Boolean update); - - - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void SetBgImageStyle (const Aspect_FillMethod FillStyle, const Standard_Boolean update); - - //! Modifies the gradient window background. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void SetGradientBackground (const Aspect_GradientBackground& ABack, const Standard_Boolean update); - - - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT void SetBgGradientStyle (const Aspect_GradientFillMethod FillStyle, const Standard_Boolean update); - - //! Manages display of the back faces - Standard_EXPORT void SetBackFacingModel (const Visual3d_TypeOfBackfacingModel aModel); - - //! Returns current state of the back faces display - Standard_EXPORT Visual3d_TypeOfBackfacingModel BackFacingModel() const; - - //! Sets the context in the view . - Standard_EXPORT void SetContext (const Visual3d_ContextView& CTX); - - //! Saves the current mapping which will be the - //! reference value for the reset of the mapping - //! done by the ViewmappingReset method. - Standard_EXPORT void SetViewMappingDefault(); - - //! Saves the current orientation which will be the - //! reference value for the reset of the orientation - //! done by the ViewOrientationReset method. - Standard_EXPORT void SetViewOrientationDefault(); - - //! Associates the window to the view . - //! No new association if the window is already defined. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if it is impossible - //! to associate a view and a window. - //! (association already done or another problem) - //! Modifies the viewmapping of the associated view - //! when it calls the SetRatio method. - //! - //! After this call, each view is mapped in an unique window. - //! - //! Programming example : - //! - //! An example when we have 1 view and 1 window - //! ------------------------------------------- - //! - //! Handle(Aspect_DisplayConnection) aDisplayConnection; - //! - //! // Display connection initialization only needed on Linux platform - //! // and on Mac OS X, in cases when you use Xlib for windows drawing. - //! aDisplayConnection = new Aspect_DisplayConnection(); - //! - //! // Graphic driver initialization - //! Handle(Graphic3d_GraphicDriver) aGraphicDriver = - //! Graphic3d::InitGraphicDriver (aDisplayConnection); - //! - //! // Define a view manager - //! Handle(Visual3d_ViewManager) aVisualManager = new Visual3d_ViewManager (aGraphicDriver); - //! - //! // Define a view - //! Handle(Visual3d_View) aView = new Visual3d_View (aVisaulManager); - //! - //! // Define a window - //! Handle(Xw_Window) aWindow = new Xw_Window - //! (aDisplayConnection, "Graphic View 1", 0.695, 0.695, 0.600, 0.600, Quantity_NOC_MATRAGRAY); - //! - //! // Associate the view and the window - //! aView->SetWindow (aWindow); - //! - //! // Map the window - //! aWindow->Map (); - //! - //! // Activate the view - //! aView->Activate (); - Standard_EXPORT void SetWindow (const Handle(Aspect_Window)& AWindow); - - //! Associates the window and context - //! to the view . - //! If is not NULL the graphic context is used - //! directly to draw something in this view. - //! Otherwise an internal context is created. - //! If is not NULL then a user display CB is - //! call at the end of the OCC graphic traversal and just - //! before the swap of buffers. The is pass - //! to this call back. - //! No new association if the window is already defined. - //! Category: Methods to modify the class definition - //! Warning: Raises ViewDefinitionError if it is impossible - //! to associate a view and a window. - //! (association already done or another problem) - //! Modifies the viewmapping of the associated view - //! when it calls the SetRatio method. - //! - //! After this call, each view is mapped in an unique window. - Standard_EXPORT void SetWindow (const Handle(Aspect_Window)& AWindow, const Aspect_RenderingContext AContext, const Aspect_GraphicCallbackProc& ADisplayCB, const Standard_Address AClientData); - - //! Updates screen in function of modifications of - //! the structures. - Standard_EXPORT void Update (const Aspect_TypeOfUpdate theUpdateMode); - - //! Updates screen in function of modifications of - //! the structures. - Standard_EXPORT void Update (); - - //! Sets the automatic z-fit mode and its parameters. - //! The auto z-fit has extra parameters which can controlled from application level - //! to ensure that the size of viewing volume will be sufficiently large to cover - //! the depth of unmanaged objects, for example, transformation persistent ones. - //! @param theScaleFactor [in] the scale factor for Z-range. - //! The range between Z-min, Z-max projection volume planes - //! evaluated by z fitting method will be scaled using this coefficient. - //! Program error exception is thrown if negative or zero value - //! is passed. - Standard_EXPORT void SetAutoZFitMode (const Standard_Boolean theIsOn, const Standard_Real theScaleFactor = 1.0); - - //! returns TRUE if automatic z-fit mode is turned on. - Standard_EXPORT Standard_Boolean AutoZFitMode() const; - - //! returns scale factor parameter of automatic z-fit mode. - Standard_EXPORT Standard_Real AutoZFitScaleFactor() const; - - //! If automatic z-range fitting is turned on, adjusts Z-min and Z-max - //! projection volume planes with call to ZFitAll. - Standard_EXPORT void AutoZFit(); - - //! Change Z-min and Z-max planes of projection volume to match the - //! displayed objects. - Standard_EXPORT void ZFitAll (const Standard_Real theScaleFactor = 1.0); - - //! Sets the value of the mapping to be the same as - //! the mapping saved by the SetViewMappingDefaut method. - Standard_EXPORT void ViewMappingReset(); - - //! Sets the value of the orientation to be the same as the - //! orientation saved by the SetViewOrientationDefaut method. - Standard_EXPORT void ViewOrientationReset(); - - //! Switches computed HLR mode in the view - Standard_EXPORT void SetComputedMode (const Standard_Boolean aMode); - - //! Returns the computed HLR mode state - Standard_EXPORT Standard_Boolean ComputedMode() const; - - //! Customization of the ZBUFFER Triedron. - //! Initializes Colors of X Y and axis - //! Scale ratio defines decreasing of trihedron size when - //! its position is out of a View - Standard_EXPORT void ZBufferTriedronSetup (const Quantity_NameOfColor XColor = Quantity_NOC_RED, const Quantity_NameOfColor YColor = Quantity_NOC_GREEN, const Quantity_NameOfColor ZColor = Quantity_NOC_BLUE1, const Standard_Real SizeRatio = 0.8, const Standard_Real AxisDiametr = 0.05, const Standard_Integer NbFacettes = 12); - - //! Display of the Triedron. - //! Initialize position, color and length of Triedron axes. - //! The scale is a percent of the window width. - //! If AsWireframe is FALSE triedron is shown in shaded mode - //! AColor is not considered for ZBUFFER mode - Standard_EXPORT void TriedronDisplay (const Aspect_TypeOfTriedronPosition APosition = Aspect_TOTP_CENTER, const Quantity_NameOfColor AColor = Quantity_NOC_WHITE, const Standard_Real AScale = 0.02, const Standard_Boolean AsWireframe = Standard_True); - - //! Erases the Triedron. - Standard_EXPORT void TriedronErase(); - - //! Highlights the echo zone of the Triedron. - Standard_EXPORT void TriedronEcho (const Aspect_TypeOfTriedronEcho AType = Aspect_TOTE_NONE); - - //! Returns data of a graduated trihedron - Standard_EXPORT const Graphic3d_GraduatedTrihedron& GetGraduatedTrihedron() const; - - //! Displays a graduated trihedron. - Standard_EXPORT void GraduatedTrihedronDisplay (const Graphic3d_GraduatedTrihedron& theTrigedronData); - - //! Erases a graduated trihedron from the view. - Standard_EXPORT void GraduatedTrihedronErase(); - - //! Returns the value of the default window background. - Standard_EXPORT Aspect_Background Background() const; - - //! Returns the value of the window background. - Standard_EXPORT Aspect_GradientBackground GradientBackground() const; - - //! Returns Standard_True if one of the structures - //! displayed in the view contains Polygons, - //! Triangles or Quadrangles. - Standard_EXPORT Standard_Boolean ContainsFacet() const; - - //! Returns Standard_True if one of the structures - //! in the set contains Polygons, Triangles - //! or Quadrangles. - Standard_EXPORT Standard_Boolean ContainsFacet (const Graphic3d_MapOfStructure& ASet) const; - - //! Returns the current context of the view . - Standard_EXPORT const Visual3d_ContextView& Context() const; - - //! Returns the set of structures displayed in - //! the view . - Standard_EXPORT void DisplayedStructures (Graphic3d_MapOfStructure& SG) const; - - //! Returns the activity flag of the view . - Standard_EXPORT Standard_Boolean IsActive() const; - - //! Returns True if the window associated to the view - //! is defined. - Standard_EXPORT Standard_Boolean IsDefined() const; - - //! Returns Standard_True is the view is deleted. - //! is deleted after the call Remove (me). - Standard_EXPORT Standard_Boolean IsDeleted() const; - - //! Returns the coordinates of the boundary box of all - //! structures displayed in the view . - //! If is TRUE, then the boundary box - //! also includes minimum and maximum limits of graphical elements - //! forming parts of infinite structures. - Standard_EXPORT Bnd_Box MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const; - - //! Returns the coordinates of the boundary box of all - //! structures in the set . - //! If is TRUE, then the boundary box - //! also includes minimum and maximum limits of graphical elements - //! forming parts of infinite structures. - Standard_EXPORT Bnd_Box MinMaxValues (const Graphic3d_MapOfStructure& theSet, const Standard_Boolean theToIgnoreInfiniteFlag = Standard_False) const; - - //! Returns number of displayed structures in - //! the view . - Standard_EXPORT Standard_Integer NumberOfDisplayedStructures() const; - - //! Returns the coordinates of the projection of the - //! 3d coordinates , , . - Standard_EXPORT void Projects (const Standard_Real AX, const Standard_Real AY, const Standard_Real AZ, Standard_Real& APX, Standard_Real& APY, Standard_Real& APZ) const; - - //! @return the default camera of . - Standard_EXPORT const Handle(Graphic3d_Camera)& DefaultCamera() const; - - //! @return the camera of . - Standard_EXPORT const Handle(Graphic3d_Camera)& Camera() const; - - //! Set camera object to provide orientation and projection matrices - //! for graphic driver. - Standard_EXPORT void SetCamera (const Handle(Graphic3d_Camera)& theCamera); - - //! Returns the window associated to the view . - //! Warning: Raises ViewDefinitionError if the associated - //! window isn't defined. - Standard_EXPORT Handle(Aspect_Window) Window() const; - - //! Returns the MAX number of light associated to the view . - Standard_EXPORT Standard_Integer LightLimit() const; - - //! Returns the MAX number of clipping planes - //! associated to the view . - Standard_EXPORT Standard_Integer PlaneLimit() const; - - //! Returns the view manager handle which manage this view - Standard_EXPORT Handle(Visual3d_ViewManager) ViewManager() const; - - //! Computes the new presentation of the - //! structure displayed in - //! with the type Graphic3d_TOS_COMPUTED. - Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& AStructure); - - //! Returns the identification number of the view . - Standard_EXPORT Standard_Integer Identification() const; - - //! Returns the c structure associated to . - Standard_EXPORT Standard_Address CView() const; - - //! Returns the associated GraphicDriver. - Standard_EXPORT const Handle(Graphic3d_GraphicDriver)& GraphicDriver() const; - - //! print the contents of the view to printer. - //! : Pass the PrinterDeviceContext (HDC), - //! : When set to FALSE then print the view without background color - //! (background is white) - //! else set to TRUE for printing with current background color. - //! : If != NULL, then the view will be printed to a file. - //! : Select print algorithm: stretch, tile. - //! : Scaling coefficient, used internally to scale the - //! printings accordingly to the scale factor selected in the printer - //! properties dialog. - //! Returns Standard_True if the data is passed to the printer, otherwise - //! Standard_False if the print operation failed due to printer error - //! or insufficient memory. - //! Warning: Works only under Windows. - Standard_EXPORT Standard_Boolean Print (const Aspect_Handle hPrnDC, const Standard_Boolean showBackground, const Standard_CString filename, const Aspect_PrintAlgo printAlgorithm = Aspect_PA_STRETCH, const Standard_Real theScaleFactor = 1.0) const; - - //! Reads depths of shown pixels of the given rectangle - Standard_EXPORT void ReadDepths (const Standard_Integer x, const Standard_Integer y, const Standard_Integer width, const Standard_Integer height, const Standard_Address buffer) const; - - //! Generate offscreen FBO in the graphic library - Standard_EXPORT Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer width, const Standard_Integer height); - - //! Remove offscreen FBO from the graphic library - Standard_EXPORT void FBORelease (Graphic3d_PtrFrameBuffer& fboPtr); - - //! Read offscreen FBO configuration. - Standard_EXPORT void FBOGetDimensions (const Graphic3d_PtrFrameBuffer fboPtr, Standard_Integer& width, Standard_Integer& height, Standard_Integer& widthMax, Standard_Integer& heightMax); - - //! Change offscreen FBO viewport. - Standard_EXPORT void FBOChangeViewport (Graphic3d_PtrFrameBuffer& fboPtr, const Standard_Integer width, const Standard_Integer height); - - //! Dump active rendering buffer into specified memory buffer. - Standard_EXPORT Standard_Boolean BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType); - - //! turns on/off opengl lighting, currently used in triedron displaying - Standard_EXPORT void EnableGLLight (const Standard_Boolean enable) const; - - //! returns the current state of the gl lighting - //! currently used in triedron displaying - Standard_EXPORT Standard_Boolean IsGLLightEnabled() const; - - - //! Export scene into the one of the Vector graphics formats (SVG, PS, PDF...). - //! In contrast to Bitmaps, Vector graphics is scalable (so you may got quality benefits on printing to laser printer). - //! Notice however that results may differ a lot and do not contain some elements. - Standard_EXPORT Standard_Boolean Export (const Standard_CString theFileName, const Graphic3d_ExportFormat theFormat, const Graphic3d_SortType theSortType = Graphic3d_ST_BSP_Tree, const Standard_Real thePrecision = 0.005, const Standard_Address theProgressBarFunc = NULL, const Standard_Address theProgressObject = NULL) const; - - //! Returns map of objects hidden within this specific view (not viewer-wise). - Standard_EXPORT const Handle(Graphic3d_NMapOfTransient)& HiddenObjects() const; - - //! Returns map of objects hidden within this specific view (not viewer-wise). - Standard_EXPORT Handle(Graphic3d_NMapOfTransient)& ChangeHiddenObjects(); - - //! Returns Standard_True in case if the structure with the given is - //! in list of structures to be computed and stores computed struct to . - Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId, - Handle(Graphic3d_Structure)& theComputedStruct) const; - -friend class Visual3d_ViewManager; - - - DEFINE_STANDARD_RTTI(Visual3d_View,Graphic3d_DataStructureManager) - -protected: - - - - -private: - - - //! Is it possible to display the structure in the view? - Standard_EXPORT Visual3d_TypeOfAnswer acceptDisplay (const Graphic3d_TypeOfStructure theStructType) const; - - //! Computes the new presentation of the - //! Structures displayed in with the type - //! Graphic3d_TOS_COMPUTED. - Standard_EXPORT void Compute(); - - //! Changes the display priority of the structure . - Standard_EXPORT void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority); - - //! Sets the settings for a single Z layer of specified view. - Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings); - - //! Add a new top-level Z layer to the view with ID - //! . The z layer mechanism allows to display - //! structures in higher layers in overlay of structures in lower layers. - //! The layers in a particular view should be managed centrally - //! by its view manager so to avoid IDs mismatching and provide correct - //! display of graphics in all views. - Standard_EXPORT void AddZLayer (const Graphic3d_ZLayerId theLayerId); - - //! Remove z layer from the view by its ID. - Standard_EXPORT void RemoveZLayer (const Graphic3d_ZLayerId theLayerId); - - //! Change Z layer of already displayed structure in the view. - Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, const Graphic3d_ZLayerId theLayerId); - - //! Clears the structure to the view . - Standard_EXPORT void Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction); - - //! Connects the structures and . - Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter); - - //! Disconnects the structures and . - Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter); - - //! Display the structure to the view . - Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& AStructure); - - //! Display the structure to the view . - Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode); - - //! Erases the structure from the view . - Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& AStructure); - - //! Erases the structure from the view . - Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfUpdate AnUpdateMode); - - //! Highlights the structure in the view . - Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod); - - //! Transforms the structure in the view . - Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf); - - //! Suppress the highlighting on the structure - //! in the view . - Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& AStructure); - - //! Returns an index != 0 if the structure - //! have another structure computed for the view . - Standard_EXPORT Standard_Integer IsComputed (const Handle(Graphic3d_Structure)& AStructure) const; - - //! Returns true if the structure is - //! displayed in the view . - Standard_EXPORT Standard_Boolean IsDisplayed (const Handle(Graphic3d_Structure)& AStructure) const; - - //! Modifies the aspect ratio of the view when the - //! associated window is defined or resized. - Standard_EXPORT void SetRatio(); - - //! Updates the lights when the associated window is defined - //! and when the view is activated. - Standard_EXPORT void UpdateLights(); - - //! Updates the planes when the associated window is defined - //! and when the view is activated. - Standard_EXPORT void UpdatePlanes(); - - //! Updates the associated c structure before a call to the - //! graphic library. - Standard_EXPORT void UpdateView(); - - //! Returns an index != 0 if the structure - //! have the same owner than another structure in the - //! sequence of the computed structures. - Standard_EXPORT Standard_Integer HaveTheSameOwner (const Handle(Graphic3d_Structure)& AStructure) const; - - Visual3d_ViewManagerPtr myViewManager; - Graphic3d_CView MyCView; - Visual3d_ContextView MyContext; - Handle(Aspect_Window) MyWindow; - Graphic3d_SequenceOfStructure myStructsToCompute; - Graphic3d_SequenceOfStructure myStructsComputed; - Standard_Boolean myIsInComputedMode; - Handle(Graphic3d_GraphicDriver) myGraphicDriver; - Aspect_Background MyBackground; - Aspect_GradientBackground MyGradientBackground; - Graphic3d_MapOfStructure myStructsDisplayed; - Graphic3d_GraduatedTrihedron myGTrihedron; - Handle(Graphic3d_Camera) myDefaultCamera; - Standard_Boolean myAutoZFitIsOn; - Standard_Real myAutoZFitScaleFactor; - Standard_Boolean myStructuresUpdated; - Handle(Graphic3d_NMapOfTransient) myHiddenObjects; - - -}; - - - - - - - -#endif // _Visual3d_View_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewDefinitionError.hxx b/src/Visual3d/Visual3d_ViewDefinitionError.hxx deleted file mode 100644 index 92c4e8b55d..0000000000 --- a/src/Visual3d/Visual3d_ViewDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewDefinitionError_HeaderFile -#define _Visual3d_ViewDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ViewDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ViewDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ViewDefinitionError - #define Visual3d_ViewDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ViewDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ViewDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ViewDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ViewDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewManager.cxx b/src/Visual3d/Visual3d_ViewManager.cxx deleted file mode 100644 index 82a8b458cc..0000000000 --- a/src/Visual3d/Visual3d_ViewManager.cxx +++ /dev/null @@ -1,741 +0,0 @@ -// Copyright (c) 1995-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -/*********************************************************************** - - FONCTION : - ---------- - Classe Visual3d_ViewManager.cxx : - - Declaration of variables specific to visualisers - - HISTORIQUE DES MODIFICATIONS : - -------------------------------- - Mars 1992 : NW,JPB,CAL ; Creation. - 19-06-96 : FMN ; Suppression variables inutiles - 04-02-97 : FMN ; Suppression de PSOutput, XWDOutput ... - 06-05-97 : CAL ; Ajout du Clear sur les TOS_COMPUTED. - 19-09-97 : CAL ; Remplacement de Window->Position par Window->Size; - 24-10-97 : CAL ; Retrait de DownCast. - 20-11-97 : CAL ; Disparition de la dependance avec math - 01-12-97 : CAL ; Retrait du test IsActive sur l'Update et le Redraw - 31-12-97 : CAL ; Disparition de MathGra - 16-01-98 : CAL ; Ajout du SetTransform sur une TOS_COMPUTED - 11-03-98 : CAL ; Visual3d_ViewManager::Remove () - 20-05-98 : CAL ; Perfs. Connection entre structures COMPUTED. - 10-06-98 : CAL ; Modification des signatures de xxProjectRaster. - 10-06-98 : CAL ; Modification de la signature de ViewExists. - 01-12-98 : CAL ; S4062. Ajout des layers. - 02-12-98 : CAL ; Remove () ne detruit plus les vues. - -************************************************************************/ - -/*----------------------------------------------------------------------*/ -/* - * Constants - */ - -#define NO_DOWNCAST -#define NO_DESTROY - -/*----------------------------------------------------------------------*/ -/* - * Includes - */ -// for the class - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined (_WIN32) || defined(__WIN32__) -# include -#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) -# include -#else -# include -#include -#endif - -// views identifiers : possible range -#define View_IDMIN 1 -#define View_IDMAX 10000 - -Visual3d_ViewManager::Visual3d_ViewManager (const Handle(Graphic3d_GraphicDriver)& theDriver): -Graphic3d_StructureManager (theDriver), -MyDefinedView (), -MyViewGenId (0, 31), -MyZBufferAuto (Standard_False), -myZLayerGenId (1, IntegerLast()) -{ - MyGraphicDriver = theDriver; - - // default layers are always presented in display layer sequence it can not be removed - Graphic3d_ZLayerSettings anUnderlaySettings; - anUnderlaySettings.Flags = 0; - anUnderlaySettings.IsImmediate = false; - myLayerIds.Add (Graphic3d_ZLayerId_BotOSD); - myLayerSeq.Append (Graphic3d_ZLayerId_BotOSD); - myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_BotOSD, anUnderlaySettings); - - Graphic3d_ZLayerSettings aDefSettings; - aDefSettings.Flags = Graphic3d_ZLayerDepthTest - | Graphic3d_ZLayerDepthWrite; - aDefSettings.IsImmediate = false; - myLayerIds.Add (Graphic3d_ZLayerId_Default); - myLayerSeq.Append (Graphic3d_ZLayerId_Default); - myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Default, aDefSettings); - - Graphic3d_ZLayerSettings aTopSettings; - aTopSettings.Flags = Graphic3d_ZLayerDepthTest - | Graphic3d_ZLayerDepthWrite; - aTopSettings.IsImmediate = true; - myLayerIds.Add (Graphic3d_ZLayerId_Top); - myLayerSeq.Append (Graphic3d_ZLayerId_Top); - myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Top, aTopSettings); - - Graphic3d_ZLayerSettings aTopmostSettings; - aTopmostSettings.Flags = Graphic3d_ZLayerDepthTest - | Graphic3d_ZLayerDepthWrite - | Graphic3d_ZLayerDepthClear; - aTopmostSettings.IsImmediate = true; - myLayerIds.Add (Graphic3d_ZLayerId_Topmost); - myLayerSeq.Append (Graphic3d_ZLayerId_Topmost); - myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_Topmost, aTopmostSettings); - - Graphic3d_ZLayerSettings anOsdSettings; - anOsdSettings.Flags = 0; - anOsdSettings.IsImmediate = true; - myLayerIds.Add (Graphic3d_ZLayerId_TopOSD); - myLayerSeq.Append (Graphic3d_ZLayerId_TopOSD); - myMapOfZLayerSettings.Bind (Graphic3d_ZLayerId_TopOSD, anOsdSettings); -} - -//-Destructors - -void Visual3d_ViewManager::Destroy () { - - Remove (); -} - -//-Methods, in order - -void Visual3d_ViewManager::Remove () { - - // - // Destroy all defined views - // - - // clear all structures whilst views are alive for correct GPU memory management - MyDisplayedStructure.Clear(); - MyHighlightedStructure.Clear(); - - // clear list of managed views - MyDefinedView.Clear(); -} - -void Visual3d_ViewManager::ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) -{ - // - // Change structure priority in all defined views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->ChangeDisplayPriority(AStructure, OldPriority, NewPriority); - } -} - -void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure) { - - //Standard_Integer LengthD = MyDisplayedStructure.Extent() (); - - // Even if physically the structure cannot - // be displayed (pb of visualisation type) - // it has status Displayed. - - if (!MyDisplayedStructure.Contains(AStructure)) - return; - - // - // Recompute structure in all activated views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->ReCompute(AStructure); - } -} - -void Visual3d_ViewManager::ReCompute (const Handle(Graphic3d_Structure)& AStructure, - const Handle(Graphic3d_DataStructureManager)& AProjector) -{ - - if (! AProjector->IsKind (STANDARD_TYPE (Visual3d_View))) return; - -#ifdef DOWNCAST - Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); -#else - Handle(Visual3d_View) theView = Handle(Visual3d_View)::DownCast (AProjector); -#endif - Standard_Integer ViewId = theView->Identification (); - - // Even if physically the structure cannot - // be displayed (pb of visualisation type) - // it has status Displayed. - if (!MyDisplayedStructure.Contains(AStructure)) - return; - - // - // Recompute structure in all activated views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if ((MyDefinedView.Value(i))->Identification () == ViewId) - { - theView->ReCompute (AStructure); - } - } -} - -void Visual3d_ViewManager::Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) -{ - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Clear(AStructure, WithDestruction); - } -} - -void Visual3d_ViewManager::Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) -{ - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Connect (AMother, ADaughter); - } -} - -void Visual3d_ViewManager::Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) -{ - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Disconnect (AMother, ADaughter); - } -} - -void Visual3d_ViewManager::Display (const Handle(Graphic3d_Structure)& AStructure) -{ - // Even if physically the structure cannot - // be displayed (pb of visualisation type) - // it has status Displayed. - - MyDisplayedStructure.Add(AStructure); - - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Display(AStructure); - } -} - -void Visual3d_ViewManager::Erase (const Handle(Graphic3d_Structure)& AStructure) -{ - // Even if physically the structure cannot - // be displayed (pb of visualisation type) - // it has status Displayed. - - MyDisplayedStructure.Remove(AStructure); - - // - // Erase structure in all defined views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Erase (AStructure); - } - - MyHighlightedStructure.Remove (AStructure); -} - -void Visual3d_ViewManager::Erase () { - - Graphic3d_MapIteratorOfMapOfStructure it( MyDisplayedStructure); - - for (; it.More(); it.Next()) { - Handle(Graphic3d_Structure) SG = it.Key(); - SG->Erase(); - } - -} - -void Visual3d_ViewManager::Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) -{ - MyHighlightedStructure.Add(AStructure); - - // - // Highlight in all activated views - // - - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->Highlight (AStructure, AMethod); - } -} - -void Visual3d_ViewManager::SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) -{ - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->SetTransform (AStructure, ATrsf); - } -} - -void Visual3d_ViewManager::UnHighlight () { - - Graphic3d_MapIteratorOfMapOfStructure it(MyHighlightedStructure); - - for (; it.More(); it.Next()) { - Handle(Graphic3d_Structure) SG = it.Key(); - SG->UnHighlight (); - } - - -} - -void Visual3d_ViewManager::UnHighlight (const Handle(Graphic3d_Structure)& AStructure) -{ - MyHighlightedStructure.Remove(AStructure); - - // - // UnHighlight in all activated views - // - - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->UnHighlight (AStructure); - } -} - -void Visual3d_ViewManager::Redraw() const -{ - // redraw all activated views - if (MyDefinedView.Length() == 0) - { - return; - } - - for(int i=1; i<=MyDefinedView.Length(); i++) - { - MyDefinedView.Value(i)->Redraw (); - } -} - -void Visual3d_ViewManager::Update() const -{ - Redraw(); -} - -void Visual3d_ViewManager::RedrawImmediate() const -{ - if (MyDefinedView.Length() == 0) - { - return; - } - - // update all activated views - for(int i=1; i<=MyDefinedView.Length(); i++) - { - MyDefinedView.Value(i)->RedrawImmediate (); - } -} - -void Visual3d_ViewManager::Invalidate() const -{ - if (MyDefinedView.Length() == 0) - { - return; - } - - // update all activated views - for(int i=1; i<=MyDefinedView.Length(); i++) - { - MyDefinedView.Value(i)->Invalidate(); - } -} - -Handle(Visual3d_HSequenceOfView) Visual3d_ViewManager::ActivatedView () const -{ - - Handle(Visual3d_HSequenceOfView) SG = new Visual3d_HSequenceOfView(); - - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if ((MyDefinedView.Value(i))->IsActive ()) - { - SG->Append(MyDefinedView.Value(i)); - } - } - - return (SG); -} - -#ifdef IMPLEMENTED -Standard_Boolean Visual3d_ViewManager::ContainsComputedStructure () const -{ - Standard_Boolean Result = Standard_False; - - // - // Check all activated views - // - for(int i=1; (!Result) && i<=MyDefinedView.Length(); i++) - { - if ((MyDefinedView.Value(i))->IsActive()) - { - Result = (MyDefinedView.Value(i))->ContainsComputedStructure(); - } - } - - return Result; -} -#endif - -const Visual3d_SequenceOfView& Visual3d_ViewManager::DefinedViews() const -{ - return MyDefinedView; -} - -Standard_Boolean Visual3d_ViewManager::ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const -{ - Standard_Boolean Exist = Standard_False; - - // Parse the list of views to find - // a view with the specified window - -#if defined(_WIN32) - const Handle(WNT_Window) THEWindow = Handle(WNT_Window)::DownCast (AWindow); - Aspect_Handle TheSpecifiedWindowId = THEWindow->HWindow (); -#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) - const Handle(Cocoa_Window) THEWindow = Handle(Cocoa_Window)::DownCast (AWindow); - #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE - UIView* TheSpecifiedWindowId = THEWindow->HView(); - #else - NSView* TheSpecifiedWindowId = THEWindow->HView(); - #endif -#elif defined(__ANDROID__) - int TheSpecifiedWindowId = -1; -#else - const Handle(Xw_Window) THEWindow = Handle(Xw_Window)::DownCast (AWindow); - int TheSpecifiedWindowId = int (THEWindow->XWindow ()); -#endif - - for(int i=1; (!Exist) && i<=MyDefinedView.Length(); i++) - { - if ( ((MyDefinedView.Value(i))->IsDefined ()) && ((MyDefinedView.Value(i))->IsActive ()) ) - { - const Handle(Aspect_Window) AspectWindow = (MyDefinedView.Value(i))->Window(); - -#if defined(_WIN32) - const Handle(WNT_Window) theWindow = Handle(WNT_Window)::DownCast (AspectWindow); - Aspect_Handle TheWindowIdOfView = theWindow->HWindow (); -#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) - const Handle(Cocoa_Window) theWindow = Handle(Cocoa_Window)::DownCast (AspectWindow); - #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE - UIView* TheWindowIdOfView = theWindow->HView(); - #else - NSView* TheWindowIdOfView = theWindow->HView(); - #endif -#elif defined(__ANDROID__) - int TheWindowIdOfView = 0; -#else - const Handle(Xw_Window) theWindow = Handle(Xw_Window)::DownCast (AspectWindow); - int TheWindowIdOfView = int (theWindow->XWindow ()); -#endif // WNT - // Comparaison on window IDs - if (TheWindowIdOfView == TheSpecifiedWindowId) - { - Exist = Standard_True; - TheCView = *(Graphic3d_CView* )(MyDefinedView.Value(i))->CView(); - } - } - } - - return (Exist); -} - -void Visual3d_ViewManager::Activate () -{ - // - // Activates all deactivated views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if (! (MyDefinedView.Value(i))->IsActive()) - { - (MyDefinedView.Value(i))->Activate(); - } - } -} - -void Visual3d_ViewManager::Deactivate () -{ - // - // Deactivates all activated views - // - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if ((MyDefinedView.Value(i))->IsActive()) - { - (MyDefinedView.Value(i))->Deactivate(); - } - } - -} - -Standard_Integer Visual3d_ViewManager::MaxNumOfViews () const { - - // Retourne the planned of definable views for the current - // Visual3d_ViewManager. - return -(Standard_Integer ((View_IDMAX-View_IDMIN+1)/Visual3d_ViewManager::Limit ())); - -} - -Handle(Graphic3d_Structure) Visual3d_ViewManager::Identification (const Standard_Integer AId) const { - - return (Graphic3d_StructureManager::Identification (AId)); - -} - -Standard_Integer Visual3d_ViewManager::Identification () const { - - return (Graphic3d_StructureManager::Identification ()); - -} - -Standard_Integer Visual3d_ViewManager::Identification (const Handle(Visual3d_View)& AView) -{ - MyDefinedView.Append(AView); - return (MyViewGenId.Next ()); -} - -void Visual3d_ViewManager::UnIdentification (const Standard_Integer aViewId) -{ - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if ((MyDefinedView.Value(i))->Identification() == aViewId) - { - //remove the view from the list - MyDefinedView.Remove(i); - break; - } - } - - MyViewGenId.Free(aViewId); -} - -void Visual3d_ViewManager::SetZBufferAuto (const Standard_Boolean AFlag) -{ - MyZBufferAuto = AFlag; -} - -Standard_Boolean Visual3d_ViewManager::ZBufferAuto () const -{ - return (MyZBufferAuto); -} - -//======================================================================= -//function : ChangeZLayer -//purpose : -//======================================================================= - -void Visual3d_ViewManager::ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, - const Graphic3d_ZLayerId theLayerId) -{ - if (!myLayerIds.Contains (theLayerId) - || !MyDisplayedStructure.Contains (theStructure)) - { - return; - } - - // change display layer for structure in all views - for (int aViewIter = 1; aViewIter <= MyDefinedView.Length(); ++aViewIter) - { - MyDefinedView.Value (aViewIter)->ChangeZLayer (theStructure, theLayerId); - } -} - -//======================================================================= -//function : SetZLayerSettings -//purpose : -//======================================================================= -void Visual3d_ViewManager::SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, - const Graphic3d_ZLayerSettings& theSettings) -{ - // tell all managed views to set zlayer settings - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->SetZLayerSettings (theLayerId, theSettings); - } - - if (myMapOfZLayerSettings.IsBound (theLayerId)) - { - myMapOfZLayerSettings.ChangeFind (theLayerId) = theSettings; - } - else - { - myMapOfZLayerSettings.Bind (theLayerId, theSettings); - } - -} - -//======================================================================= -//function : ZLayerSettings -//purpose : -//======================================================================= -Graphic3d_ZLayerSettings Visual3d_ViewManager::ZLayerSettings (const Graphic3d_ZLayerId theLayerId) -{ - if (!myLayerIds.Contains (theLayerId)) - { - return Graphic3d_ZLayerSettings(); - } - - return myMapOfZLayerSettings.Find (theLayerId); -} - -//======================================================================= -//function : AddZLayer -//purpose : -//======================================================================= - -Standard_Boolean Visual3d_ViewManager::AddZLayer (Graphic3d_ZLayerId& theLayerId) -{ - try - { - OCC_CATCH_SIGNALS - theLayerId = myZLayerGenId.Next(); - myLayerIds.Add (theLayerId); - myLayerSeq.Append (theLayerId); - } - catch (Aspect_IdentDefinitionError) - { - // new index can't be generated - return Standard_False; - } - - // default z-layer settings - myMapOfZLayerSettings.Bind (theLayerId, Graphic3d_ZLayerSettings()); - - // tell all managed views to remove display layers - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->AddZLayer(theLayerId); - } - - return Standard_True; -} - -//======================================================================= -//function : RemoveZLayer -//purpose : -//======================================================================= - -Standard_Boolean Visual3d_ViewManager::RemoveZLayer (const Graphic3d_ZLayerId theLayerId) -{ - if (!myLayerIds.Contains (theLayerId) - || theLayerId < myZLayerGenId.Lower() - || theLayerId > myZLayerGenId.Upper()) - { - return Standard_False; - } - - // tell all managed views to remove display layers - for(int i=1; i<=MyDefinedView.Length(); i++) - { - (MyDefinedView.Value(i))->RemoveZLayer (theLayerId); - } - - MyGraphicDriver->UnsetZLayer (theLayerId); - - // remove index - for (int aIdx = 1; aIdx <= myLayerSeq.Length (); aIdx++) - { - if (myLayerSeq (aIdx) == theLayerId) - { - myLayerSeq.Remove (aIdx); - break; - } - } - - myMapOfZLayerSettings.UnBind (theLayerId); - - myLayerIds.Remove (theLayerId); - myZLayerGenId.Free (theLayerId); - - return Standard_True; -} - -//======================================================================= -//function : GetAllZLayers -//purpose : -//======================================================================= - -void Visual3d_ViewManager::GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const -{ - theLayerSeq.Assign (myLayerSeq); -} - -//======================================================================= -//function : InstallZLayers -//purpose : -//======================================================================= - -void Visual3d_ViewManager::InstallZLayers(const Handle(Visual3d_View)& theView) const -{ - Standard_Boolean isContainsView = Standard_False; - for(int i=1; i<=MyDefinedView.Length(); i++) - { - if(MyDefinedView.Value(i) == theView) - { - isContainsView = Standard_True; - break; - } - } - if (!isContainsView) - return; - - // erase and insert layers iteratively to provide the same layer order as - // in the view manager's sequence. This approach bases on the layer insertion - // order: the new layers are always appended to the end of the list - // inside of view, while layer remove operation doesn't affect the order. - // Starting from second layer : no need to change the default z layer. - for (Standard_Integer aSeqIdx = 1; aSeqIdx <= myLayerSeq.Length(); ++aSeqIdx) - { - const Graphic3d_ZLayerId aLayerID = myLayerSeq.Value (aSeqIdx); - const Graphic3d_ZLayerSettings& aSettings = myMapOfZLayerSettings.Find (aLayerID); - if (aLayerID < myZLayerGenId.Lower() - || aLayerID > myZLayerGenId.Upper()) - { - theView->SetZLayerSettings (aLayerID, aSettings); - continue; - } - - theView->RemoveZLayer (aLayerID); - theView->AddZLayer (aLayerID); - theView->SetZLayerSettings (aLayerID, aSettings); - } -} diff --git a/src/Visual3d/Visual3d_ViewManager.hxx b/src/Visual3d/Visual3d_ViewManager.hxx deleted file mode 100644 index 90a3286688..0000000000 --- a/src/Visual3d/Visual3d_ViewManager.hxx +++ /dev/null @@ -1,245 +0,0 @@ -// Created on: 1991-09-05 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewManager_HeaderFile -#define _Visual3d_ViewManager_HeaderFile - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -class Visual3d_Layer; -class Graphic3d_GraphicDriver; -class Visual3d_View; -class Graphic3d_Structure; -class Aspect_Window; -class Graphic3d_DataStructureManager; - - -class Visual3d_ViewManager; -DEFINE_STANDARD_HANDLE(Visual3d_ViewManager, Graphic3d_StructureManager) - -//! This class allows the definition of a manager to -//! which the views are associated. -//! It allows them to be globally manipulated. -class Visual3d_ViewManager : public Graphic3d_StructureManager -{ - -public: - - - //! Creates a 3D visualizer. - //! Currently creating of more than 100 viewer instances - //! is not supported and leads to InitializationError and - //! initialisation failure. - //! This limitation might be addressed in some future OCCT releases. - //! - //! Category: Methods to modify the class definition - Standard_EXPORT Visual3d_ViewManager(const Handle(Graphic3d_GraphicDriver)& theDriver); - - //! Activates all the views of the manager . - Standard_EXPORT void Activate(); - - //! Deactivates all the views of the manager . - Standard_EXPORT void Deactivate(); - - //! Deletes and erases the 3D visualiser . - Standard_EXPORT virtual void Destroy() Standard_OVERRIDE; -~Visual3d_ViewManager() -{ - Destroy(); -} - - //! Erases all of the structures displayed in the - //! visualiser . - Standard_EXPORT void Erase(); - - //! Redraws all the displayed structures. - Standard_EXPORT void Redraw() const; - - //! Updates layer of immediate presentations. - Standard_EXPORT void RedrawImmediate() const; - - //! Invalidates viewer content but does not redraw it. - Standard_EXPORT void Invalidate() const; - - //! Deletes and erases the 3D visualiser . - Standard_EXPORT void Remove(); - - //! Updates screen in function of modifications of the structures. - //! Category: Methods to modify the class definition - Standard_EXPORT void Update() const Standard_OVERRIDE; - - //! Returns the group of views activated in the visualiser . - Standard_EXPORT Handle(Visual3d_HSequenceOfView) ActivatedView() const; - - //! Returns the group of views defined in the visualiser . - Standard_EXPORT const Visual3d_SequenceOfView& DefinedViews() const; - - //! Returns the theoretical maximum number of - //! definable views in the view manager . - //! Warning: It's not possible to accept an infinite - //! number of definable views because each - //! view must have an identification and we - //! have different view managers. - Standard_EXPORT Standard_Integer MaxNumOfViews() const; - - //! Returns : - //! a new identification number for a new view - //! in the visualiser. - Standard_EXPORT Standard_Integer Identification (const Handle(Visual3d_View)& AView); - - //! Release a unique ID of the view reserved for the view on its creation. - Standard_EXPORT void UnIdentification (const Standard_Integer aViewId); - - //! Returns the structure with the identification number . - Standard_EXPORT Handle(Graphic3d_Structure) Identification (const Standard_Integer AId) const Standard_OVERRIDE; - - //! Returns the identification number of the visualiser. - Standard_EXPORT Standard_Integer Identification() const Standard_OVERRIDE; - - //! Changes the display priority of the structure . - Standard_EXPORT void ChangeDisplayPriority (const Handle(Graphic3d_Structure)& AStructure, const Standard_Integer OldPriority, const Standard_Integer NewPriority) Standard_OVERRIDE; - - //! Change Z layer for structure. The layer mechanism allows - //! to display structures in higher layers in overlay of structures in - //! lower layers. - Standard_EXPORT void ChangeZLayer (const Handle(Graphic3d_Structure)& theStructure, const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - - //! Sets the settings for a single Z layer for all managed views. - Standard_EXPORT void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId, const Graphic3d_ZLayerSettings& theSettings) Standard_OVERRIDE; - - //! Returns the settings of a single Z layer. - Standard_EXPORT Graphic3d_ZLayerSettings ZLayerSettings (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - - //! Add a new top-level Z layer and get its ID as - //! value. The method returns Standard_False if the layer - //! can not be created. The layer mechanism allows to display - //! structures in higher layers in overlay of structures in lower layers. - Standard_EXPORT Standard_Boolean AddZLayer (Graphic3d_ZLayerId& theLayerId) Standard_OVERRIDE; - - //! Remove Z layer with ID . Method returns - //! Standard_False if the layer can not be removed or doesn't exists. - //! By default, there are always default bottom-level layer that can't - //! be removed. - Standard_EXPORT Standard_Boolean RemoveZLayer (const Graphic3d_ZLayerId theLayerId) Standard_OVERRIDE; - - //! Return all Z layer ids in sequence ordered by overlay level - //! from lowest layer to highest ( foreground ). The first layer ID - //! in sequence is the default layer that can't be removed. - Standard_EXPORT void GetAllZLayers (TColStd_SequenceOfInteger& theLayerSeq) const Standard_OVERRIDE; - - //! Clears the structure . - Standard_EXPORT void Clear (const Handle(Graphic3d_Structure)& AStructure, const Standard_Boolean WithDestruction) Standard_OVERRIDE; - - //! Connects the structures and . - Standard_EXPORT void Connect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) Standard_OVERRIDE; - - //! Disconnects the structures and . - Standard_EXPORT void Disconnect (const Handle(Graphic3d_Structure)& AMother, const Handle(Graphic3d_Structure)& ADaughter) Standard_OVERRIDE; - - //! Display of the structure . - Standard_EXPORT void Display (const Handle(Graphic3d_Structure)& AStructure) Standard_OVERRIDE; - - //! Erases the structure . - Standard_EXPORT void Erase (const Handle(Graphic3d_Structure)& AStructure) Standard_OVERRIDE; - - //! Highlights the structure . - Standard_EXPORT void Highlight (const Handle(Graphic3d_Structure)& AStructure, const Aspect_TypeOfHighlightMethod AMethod) Standard_OVERRIDE; - - Standard_EXPORT void SetTransform (const Handle(Graphic3d_Structure)& AStructure, const TColStd_Array2OfReal& ATrsf) Standard_OVERRIDE; - - //! Suppress the highlighting on all the structures. - Standard_EXPORT void UnHighlight() Standard_OVERRIDE; - - //! Suppress the highlighting on the structure . - Standard_EXPORT void UnHighlight (const Handle(Graphic3d_Structure)& AStructure) Standard_OVERRIDE; - - //! Returns Standard_True if the view associated to the - //! window exists and is activated. - //! contains the internal identification of - //! the associated view. - Standard_EXPORT Standard_Boolean ViewExists (const Handle(Aspect_Window)& AWindow, Graphic3d_CView& TheCView) const; - - //! Forces a new construction of the structure - //! if is displayed and TOS_COMPUTED. - Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& AStructure) Standard_OVERRIDE; - - //! Forces a new construction of the structure - //! if is displayed in and TOS_COMPUTED. - Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& AStructure, const Handle(Graphic3d_DataStructureManager)& AProjector) Standard_OVERRIDE; - - //! Returns Standard_True if the zbuffer activity - //! is managed automatically. - //! Default Standard_False - Standard_EXPORT Standard_Boolean ZBufferAuto() const; - - //! if is Standard_True then the zbuffer activity - //! is managed automatically. - //! Default Standard_False - Standard_EXPORT void SetZBufferAuto (const Standard_Boolean AFlag); - -friend class Visual3d_View; -friend class Visual3d_Layer; - - - DEFINE_STANDARD_RTTI(Visual3d_ViewManager,Graphic3d_StructureManager) - -protected: - - - - -private: - - - //! Install z layers managed by the view manager into the - //! controlled view. This method used on the view initialization to - //! make the layer lists consistent. - Standard_EXPORT void InstallZLayers (const Handle(Visual3d_View)& theView) const; - - Visual3d_SequenceOfView MyDefinedView; - Aspect_GenId MyViewGenId; - Handle(Graphic3d_GraphicDriver) MyGraphicDriver; - Standard_Boolean MyZBufferAuto; - Aspect_GenId myZLayerGenId; - TColStd_MapOfInteger myLayerIds; - TColStd_SequenceOfInteger myLayerSeq; - Visual3d_MapOfZLayerSettings myMapOfZLayerSettings; - - -}; - - - - - - - -#endif // _Visual3d_ViewManager_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewManagerDefinitionError.hxx b/src/Visual3d/Visual3d_ViewManagerDefinitionError.hxx deleted file mode 100644 index d674961455..0000000000 --- a/src/Visual3d/Visual3d_ViewManagerDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewManagerDefinitionError_HeaderFile -#define _Visual3d_ViewManagerDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ViewManagerDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ViewManagerDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ViewManagerDefinitionError - #define Visual3d_ViewManagerDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ViewManagerDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ViewManagerDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ViewManagerDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ViewManagerDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewManagerPtr.hxx b/src/Visual3d/Visual3d_ViewManagerPtr.hxx deleted file mode 100644 index 09007eed03..0000000000 --- a/src/Visual3d/Visual3d_ViewManagerPtr.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewManagerPtr_HeaderFile -#define _Visual3d_ViewManagerPtr_HeaderFile - -class Visual3d_ViewManager; -typedef Visual3d_ViewManager* Visual3d_ViewManagerPtr; - -#endif // _Visual3d_ViewManagerPtr_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewMappingDefinitionError.hxx b/src/Visual3d/Visual3d_ViewMappingDefinitionError.hxx deleted file mode 100644 index 53da360e8c..0000000000 --- a/src/Visual3d/Visual3d_ViewMappingDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewMappingDefinitionError_HeaderFile -#define _Visual3d_ViewMappingDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ViewMappingDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ViewMappingDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ViewMappingDefinitionError - #define Visual3d_ViewMappingDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ViewMappingDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ViewMappingDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ViewMappingDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ViewMappingDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewOrientationDefinitionError.hxx b/src/Visual3d/Visual3d_ViewOrientationDefinitionError.hxx deleted file mode 100644 index fa37d7c42d..0000000000 --- a/src/Visual3d/Visual3d_ViewOrientationDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewOrientationDefinitionError_HeaderFile -#define _Visual3d_ViewOrientationDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ViewOrientationDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ViewOrientationDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ViewOrientationDefinitionError - #define Visual3d_ViewOrientationDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ViewOrientationDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ViewOrientationDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ViewOrientationDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ViewOrientationDefinitionError_HeaderFile diff --git a/src/Visual3d/Visual3d_ViewPtr.hxx b/src/Visual3d/Visual3d_ViewPtr.hxx deleted file mode 100644 index ddd1c97666..0000000000 --- a/src/Visual3d/Visual3d_ViewPtr.hxx +++ /dev/null @@ -1,23 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ViewPtr_HeaderFile -#define _Visual3d_ViewPtr_HeaderFile - -class Visual3d_View; -typedef Visual3d_View* Visual3d_ViewPtr; - -#endif // _Visual3d_ViewPtr_HeaderFile diff --git a/src/Visual3d/Visual3d_ZClippingDefinitionError.hxx b/src/Visual3d/Visual3d_ZClippingDefinitionError.hxx deleted file mode 100644 index 4df635cbbd..0000000000 --- a/src/Visual3d/Visual3d_ZClippingDefinitionError.hxx +++ /dev/null @@ -1,37 +0,0 @@ -// Created on: 1991-10-07 -// Created by: NW,JPB,CAL -// Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#ifndef _Visual3d_ZClippingDefinitionError_HeaderFile -#define _Visual3d_ZClippingDefinitionError_HeaderFile - -#include -#include -#include -#include - -class Visual3d_ZClippingDefinitionError; -DEFINE_STANDARD_HANDLE(Visual3d_ZClippingDefinitionError, Standard_OutOfRange) - -#if !defined No_Exception && !defined No_Visual3d_ZClippingDefinitionError - #define Visual3d_ZClippingDefinitionError_Raise_if(CONDITION, MESSAGE) \ - if (CONDITION) Visual3d_ZClippingDefinitionError::Raise(MESSAGE); -#else - #define Visual3d_ZClippingDefinitionError_Raise_if(CONDITION, MESSAGE) -#endif - -DEFINE_STANDARD_EXCEPTION(Visual3d_ZClippingDefinitionError, Standard_OutOfRange) - -#endif // _Visual3d_ZClippingDefinitionError_HeaderFile diff --git a/tests/bugs/vis/bug25671 b/tests/bugs/vis/bug25671 index b9deb0cb48..6bf7103f57 100644 --- a/tests/bugs/vis/bug25671 +++ b/tests/bugs/vis/bug25671 @@ -78,6 +78,7 @@ set view_znear 0 set view_zfar 150 vviewparams -scale $view_scale -eye {*}$view_eye -at {*}$view_at -proj {*}$view_proj -up {*}$view_up +vautozfit 0 vzrange $view_znear $view_zfar set vconvert_1_view [vconvert 1.0 view] -- 2.20.1