0023015: TKOpenGl redesign regression in text printing
[occt.git] / src / OpenGl / OpenGl_Workspace.hxx
CommitLineData
2166f0fa
SK
1// File: OpenGl_Workspace.hxx
2// Created: 20 September 2011
3// Author: Sergey ZERCHANINOV
4// Copyright: OPEN CASCADE 2011
5
6#ifndef _OpenGl_Workspace_Header
7#define _OpenGl_Workspace_Header
8
9#include <Handle_OpenGl_Workspace.hxx>
10#include <OpenGl_Window.hxx>
11
12#include <TColStd_Array2OfReal.hxx>
13#include <Quantity_Color.hxx>
14#include <Graphic3d_TypeOfComposition.hxx>
15
16#include <Graphic3d_CView.hxx>
17#include <Aspect_CLayer2d.hxx>
18#include <Aspect_Handle.hxx>
19#include <Aspect_PrintAlgo.hxx>
20#include <Graphic3d_PtrFrameBuffer.hxx>
21#include <Image_CRawBufferData.hxx>
22
23#include <InterfaceGraphic_Graphic3d.hxx>
24#include <InterfaceGraphic_Visual3d.hxx>
25
26#include <OpenGl_tsm.hxx>
27
28#include <OpenGl_Display.hxx>
29#include <OpenGl_Matrix.hxx>
30#include <OpenGl_NamedStatus.hxx>
31#include <OpenGl_TextParam.hxx>
32
33#include <Handle_OpenGl_View.hxx>
34
35class OpenGl_AspectLine;
36class OpenGl_AspectFace;
37class OpenGl_AspectMarker;
38class OpenGl_AspectText;
39class OpenGl_FrameBuffer;
40class OpenGl_Structure;
41
42//! Reprepsents window with GL context.
43//! Provides methods to render primitives and maintan GL state.
44class OpenGl_Workspace : public OpenGl_Window
45{
46public:
47
48 //! Main constructor - prepare GL context for specified window.
49 OpenGl_Workspace (const Handle(OpenGl_Display)& theDisplay,
50 const CALL_DEF_WINDOW& theCWindow,
51 Aspect_RenderingContext theGContext);
52
53 //! Destructor
54 virtual ~OpenGl_Workspace();
55
56 void SetActiveView (const Handle(OpenGl_View)& theView) { myView = theView; }
57 const Handle(OpenGl_View)& ActiveView () const { return myView; }
58
59 //! Redraw the window.
60 void Redraw (const Graphic3d_CView& theCView,
61 const Aspect_CLayer2d& theCUnderLayer,
62 const Aspect_CLayer2d& theCOverLayer);
63
64 //! Redraw window only if needed.
65 void Update (const Graphic3d_CView& theCView,
66 const Aspect_CLayer2d& theCUnderLayer,
67 const Aspect_CLayer2d& theCOverLayer)
68 {
69 if (!myIsUpdated)
70 Redraw (theCView, theCUnderLayer, theCOverLayer);
71 }
72
73 //! Special method to perform printing.
74 //! System-specific and currently only Win platform implemented.
75 Standard_Boolean Print (const Graphic3d_CView& theCView,
76 const Aspect_CLayer2d& theCUnderLayer,
77 const Aspect_CLayer2d& theCOverLayer,
78 const Aspect_Handle theHPrintDC,
79 const Standard_Boolean theToShowBackground,
80 const Standard_CString theFileName,
81 const Aspect_PrintAlgo thePrintAlgorithm,
82 const Standard_Real theScaleFactor);
83
84 void DisplayCallback (const Graphic3d_CView& theCView, int theReason);
85
86 // szvgl: defined in OpenGl_Workspace_1.cxx
87 void BeginAnimation (const Standard_Boolean theUseDegeneration,
88 const Standard_Boolean theUpdateAM);
89 void EndAnimation();
90 void EraseAnimation();
91
92 Standard_Boolean BeginAddMode();
93 void EndAddMode();
94 void ClearImmediatMode (const Graphic3d_CView& theCView,
95 const Standard_Boolean theToFlush);
96 void RedrawImmediatMode();
97 Standard_Boolean BeginImmediatMode (const Graphic3d_CView& theCView,
98 const Standard_Boolean theUseDepthTest,
99 const Standard_Boolean theRetainMode);
100 void EndImmediatMode();
101 void Transform (const TColStd_Array2OfReal& theMatrix, const Graphic3d_TypeOfComposition theType);
102 void DrawStructure (const OpenGl_Structure* theStructure);
103 void BeginPolyline();
104 void EndPolyline();
105 void Draw (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
106 void Move (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ);
107 void SetLineColor (const Standard_ShortReal theR, const Standard_ShortReal theG, const Standard_ShortReal theB);
108 void SetLineType (const Standard_Integer theType);
109 void SetLineWidth (const Standard_ShortReal theWidth);
110 void SetMinMax (const Standard_ShortReal X1, const Standard_ShortReal Y1, const Standard_ShortReal Z1,
111 const Standard_ShortReal X2, const Standard_ShortReal Y2, const Standard_ShortReal Z2);
112
113 Graphic3d_PtrFrameBuffer FBOCreate (const Standard_Integer theWidth, const Standard_Integer theHeight);
114 void FBORelease (Graphic3d_PtrFrameBuffer theFBOPtr);
115 Standard_Boolean BufferDump (OpenGl_FrameBuffer *theFBOPtr, Image_CRawBufferData& theBuffer);
116
117 //! Mark this window to be redrawn on next update.
118 void Invalidate() { myIsUpdated = Standard_False; }
119
120 void UseTransparency (const Standard_Boolean theFlag);
121 Standard_Boolean& UseZBuffer() { return myUseZBuffer; }
122 Standard_Boolean& UseDepthTest() { return myUseDepthTest; }
123 Standard_Boolean& UseGLLight() { return myUseGLLight; }
124
125 //// RELATED TO STATUS ////
126
127 Standard_Integer NamedStatus;
128
129 Standard_Integer DegenerateModel;
130 Standard_ShortReal SkipRatio;
131
132 const TEL_COLOUR* HighlightColor;
133
134 const OpenGl_Matrix* SetViewMatrix (const OpenGl_Matrix* );
135 const OpenGl_Matrix* SetStructureMatrix (const OpenGl_Matrix* );
136
137 const OpenGl_AspectLine* SetAspectLine (const OpenGl_AspectLine* theAspect);
138 const OpenGl_AspectFace* SetAspectFace (const OpenGl_AspectFace* theAspect);
139 const OpenGl_AspectMarker* SetAspectMarker (const OpenGl_AspectMarker* theAspect);
140 const OpenGl_AspectText* SetAspectText (const OpenGl_AspectText* theAspect);
141
142 void SetTextParam (const OpenGl_TextParam* theParam) { TextParam_set = theParam; }
143
144 const OpenGl_AspectLine* AspectLine (const Standard_Boolean theWithApply);
145 const OpenGl_AspectFace* AspectFace (const Standard_Boolean theWithApply);
146 const OpenGl_AspectMarker* AspectMarker (const Standard_Boolean theWithApply);
147 const OpenGl_AspectText* AspectText (const Standard_Boolean theWithApply);
148
34a44cbd 149 //! Clear the applied aspect state.
150 void ResetAppliedAspect();
151
2166f0fa
SK
152 //// RELATED TO FONTS ////
153
154 int FindFont (const char* theFontName,
155 const OSD_FontAspect theFontAspect,
156 const int theBestSize = -1,
157 const float theXScale = 1.0f,
158 const float theYScale = 1.0f)
159 {
160 return myDisplay->FindFont (theFontName, theFontAspect, theBestSize, theXScale, theYScale);
161 }
162
163 void StringSize (const wchar_t* theText, int& theWidth, int& theAscent, int& theDescent)
164 {
165 myDisplay->StringSize (theText, theWidth, theAscent, theDescent);
166 }
167
168 void RenderText (const wchar_t* theText, const int theIs2d,
169 const float theX, const float theY, const float theZ)
170 {
171 const OpenGl_AspectText* anAspect = AspectText (Standard_True);
172 myDisplay->RenderText (theText, theIs2d, theX, theY, theZ, anAspect, TextParam_applied);
173 }
174
175protected:
176
177 void CopyBuffers (Tint vid, int FrontToBack,
178 Tfloat xm, Tfloat ym, Tfloat zm,
179 Tfloat XM, Tfloat YM, Tfloat ZM,
180 Tint flag);
181
182 virtual Standard_Boolean Activate();
183
184 // TEMPORARY!!!
185 void Redraw1 (const Graphic3d_CView& theCView,
186 const Aspect_CLayer2d& theCUnderLayer,
187 const Aspect_CLayer2d& theCOverLayer,
188 const int theToSwap);
189
190protected:
191
192 Handle(OpenGl_View) myView; // WSViews - now just one view is supported
193 Standard_Boolean myIsUpdated; // WSUpdateState
194 Tint myTransientList; // WSTransient
195 Standard_Boolean myIsTransientOpen; // transientOpen
196 Tint myRetainMode; // WSRetainMode
197
198 Standard_Boolean myUseTransparency;
199 Standard_Boolean myUseZBuffer;
200 Standard_Boolean myUseDepthTest;
201 Standard_Boolean myUseGLLight;
202 Standard_Boolean myBackBufferRestored;
203
204 //// RELATED TO STATUS ////
205
206 void UpdateMaterial (const int flag);
207
208 const OpenGl_AspectLine *AspectLine_set, *AspectLine_applied;
209 const OpenGl_AspectFace *AspectFace_set, *AspectFace_applied;
210 const OpenGl_AspectMarker *AspectMarker_set, *AspectMarker_applied;
211 const OpenGl_AspectText *AspectText_set, *AspectText_applied;
212
213 const OpenGl_TextParam *TextParam_set, *TextParam_applied;
214
215 const OpenGl_Matrix* ViewMatrix_applied;
216 const OpenGl_Matrix* StructureMatrix_applied;
217
218 const TEL_POFFSET_PARAM* PolygonOffset_applied;
219
220public:
221
222 DEFINE_STANDARD_RTTI(OpenGl_Workspace) // Type definition
1c35b92f 223 DEFINE_STANDARD_ALLOC
2166f0fa
SK
224
225};
226
227#endif //_OpenGl_Workspace_Header