42cf5bc1 |
1 | // Created by: NW,JPB,CAL |
2 | // Copyright (c) 1991-1999 Matra Datavision |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #ifndef _Graphic3d_AspectText3d_HeaderFile |
17 | #define _Graphic3d_AspectText3d_HeaderFile |
18 | |
42cf5bc1 |
19 | #include <Aspect_TypeOfStyleText.hxx> |
20 | #include <Aspect_TypeOfDisplayText.hxx> |
b6472664 |
21 | #include <Graphic3d_AspectTextDefinitionError.hxx> |
42cf5bc1 |
22 | #include <Graphic3d_ShaderProgram.hxx> |
b6472664 |
23 | #include <Font_FontAspect.hxx> |
24 | #include <Font_NameOfFont.hxx> |
42cf5bc1 |
25 | #include <MMgt_TShared.hxx> |
b6472664 |
26 | #include <Standard.hxx> |
27 | #include <Standard_Boolean.hxx> |
28 | #include <Standard_Real.hxx> |
29 | #include <Standard_Type.hxx> |
30 | #include <TCollection_AsciiString.hxx> |
31 | #include <Quantity_ColorRGBA.hxx> |
42cf5bc1 |
32 | |
33 | //! Creates and updates a group of attributes for |
b6472664 |
34 | //! text primitives. This group contains the color, |
42cf5bc1 |
35 | //! font, expansion factor (height/width ratio), and |
36 | //! inter-character space. |
37 | //! |
38 | //! NOTE: The font name is stored in the aspect instance |
39 | //! so it is safe to pass it as const char* to OpenGl package |
40 | //! without copying the string. However, the aspect should not |
41 | //! be deleted until the text drawn using this aspect is no longer |
42 | //! visible. The best practice is to keep the aspect in the object's drawer. |
b6472664 |
43 | class Graphic3d_AspectText3d : public Standard_Transient |
42cf5bc1 |
44 | { |
b6472664 |
45 | DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectText3d, Standard_Transient) |
42cf5bc1 |
46 | public: |
47 | |
42cf5bc1 |
48 | //! Creates a context table for text primitives |
49 | //! defined with the following default values: |
50 | //! |
b6472664 |
51 | //! Color : NOC_YELLOW |
42cf5bc1 |
52 | //! Font : NOF_ASCII_MONO |
53 | //! Expansion factor : 1. |
54 | //! Space between characters : 0. |
55 | //! The style : TOST_NORMAL |
56 | //! The display type : TODT_NORMAL |
57 | Standard_EXPORT Graphic3d_AspectText3d(); |
b6472664 |
58 | |
42cf5bc1 |
59 | //! Creates a context table for text primitives |
60 | //! defined with the specified values. |
61 | //! AFont may be to take means from User(example "Courier New") |
62 | //! or Font name defined in Font_NameOfFont(example Font_NOF_ASCII_MONO) |
63 | //! or use default font("Courier") |
b6472664 |
64 | Standard_EXPORT Graphic3d_AspectText3d (const Quantity_Color& theColor, |
65 | const Standard_CString theFont, |
66 | const Standard_Real theExpansionFactor, |
67 | const Standard_Real theSpace, |
68 | const Aspect_TypeOfStyleText theStyle = Aspect_TOST_NORMAL, |
69 | const Aspect_TypeOfDisplayText theDisplayType = Aspect_TODT_NORMAL); |
70 | |
71 | //! Return the text color. |
72 | const Quantity_Color& Color() const { return myColor.GetRGB(); } |
73 | |
74 | //! Return the text color. |
75 | const Quantity_ColorRGBA& ColorRGBA() const { return myColor; } |
76 | |
77 | //! Modifies the color. |
78 | void SetColor (const Quantity_Color& theColor) { myColor.SetRGB (theColor); } |
79 | |
42cf5bc1 |
80 | //! Modifies the expansion factor (height/width ratio) |
81 | //! If the factor is less than 1, the characters will |
82 | //! be higher than they are wide. |
b6472664 |
83 | void SetExpansionFactor (const Standard_Real theFactor) |
84 | { |
85 | if (theFactor <= 0.0) |
86 | { |
9775fa61 |
87 | throw Graphic3d_AspectTextDefinitionError("Bad value for TextScaleFactor"); |
b6472664 |
88 | } |
89 | myFactor = theFactor; |
90 | } |
91 | |
92 | //! Return the font. |
93 | const TCollection_AsciiString& Font() const { return myFont; } |
94 | |
95 | //! Modifies the font. |
96 | void SetFont (const TCollection_AsciiString& theFont) |
97 | { |
98 | myFont = !theFont.IsEmpty() ? theFont : TCollection_AsciiString (Font_NOF_ASCII_MONO); |
99 | } |
100 | |
101 | //! Modifies the font. |
102 | void SetFont (const Standard_CString theFont) |
103 | { |
104 | SetFont (TCollection_AsciiString (theFont)); |
105 | } |
106 | |
107 | //! Return the space between characters. |
108 | Standard_Real Space() const { return mySpace; } |
109 | |
42cf5bc1 |
110 | //! Modifies the space between the characters. |
b6472664 |
111 | void SetSpace (const Standard_Real theSpace) { mySpace = theSpace; } |
112 | |
113 | //! Return the text style. |
114 | Aspect_TypeOfStyleText Style() const { return myStyle; } |
115 | |
42cf5bc1 |
116 | //! Modifies the style of the text. |
b6472664 |
117 | //! * TOST_NORMAL |
118 | //! Default text. The text is displayed like any other graphic object. |
119 | //! This text can be hidden by another object that is nearest from the point of view. |
120 | //! * TOST_ANNOTATION |
121 | //! The text is always visible. |
122 | //! The text is displayed over the other object according to the priority. |
123 | void SetStyle (const Aspect_TypeOfStyleText theStyle) { myStyle = theStyle; } |
124 | |
125 | //! Return display type. |
126 | Aspect_TypeOfDisplayText DisplayType() const { return myDisplayType; } |
127 | |
42cf5bc1 |
128 | //! Define the display type of the text. |
129 | //! |
130 | //! TODT_NORMAL Default display. Text only. |
131 | //! TODT_SUBTITLE There is a subtitle under the text. |
132 | //! TODT_DEKALE The text is displayed with a 3D style. |
133 | //! TODT_BLEND The text is displayed in XOR. |
134 | //! TODT_DIMENSION Dimension line under text will be invisible. |
b6472664 |
135 | void SetDisplayType (const Aspect_TypeOfDisplayText theDisplayType) { myDisplayType = theDisplayType; } |
42cf5bc1 |
136 | |
b6472664 |
137 | //! Return subtitle color. |
138 | const Quantity_ColorRGBA& ColorSubTitleRGBA() const { return myColorSubTitle; } |
42cf5bc1 |
139 | |
b6472664 |
140 | //! Return subtitle color. |
141 | const Quantity_Color& ColorSubTitle() const { return myColorSubTitle.GetRGB(); } |
42cf5bc1 |
142 | |
b6472664 |
143 | //! Modifies the color of the subtitle for the TODT_SUBTITLE TextDisplayType |
144 | //! and the color of background for the TODT_DEKALE TextDisplayType. |
145 | void SetColorSubTitle (const Quantity_Color& theColor) { myColorSubTitle.SetRGB (theColor); } |
42cf5bc1 |
146 | |
b6472664 |
147 | //! Returns TRUE when the Text Zoomable is on. |
148 | bool GetTextZoomable() const { return myTextZoomable; } |
42cf5bc1 |
149 | |
b6472664 |
150 | //! Turns usage of text zoomable on/off |
151 | void SetTextZoomable (const bool theFlag) { myTextZoomable = theFlag; } |
42cf5bc1 |
152 | |
b6472664 |
153 | //! Returns Angle of degree |
154 | Standard_Real GetTextAngle() const { return myTextAngle; } |
42cf5bc1 |
155 | |
b6472664 |
156 | //! Turns usage of text rotated |
157 | void SetTextAngle (const Standard_Real theAngle) { myTextAngle = theAngle; } |
42cf5bc1 |
158 | |
b6472664 |
159 | //! Returns text FontAspect |
160 | Font_FontAspect GetTextFontAspect() const { return myTextFontAspect; } |
42cf5bc1 |
161 | |
b6472664 |
162 | //! Turns usage of Aspect text |
163 | void SetTextFontAspect (const Font_FontAspect theFontAspect) { myTextFontAspect = theFontAspect; } |
42cf5bc1 |
164 | |
b6472664 |
165 | //! Return the shader program. |
166 | const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; } |
42cf5bc1 |
167 | |
b6472664 |
168 | //! Sets up OpenGL/GLSL shader program. |
169 | void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; } |
42cf5bc1 |
170 | |
b6472664 |
171 | public: |
42cf5bc1 |
172 | |
b6472664 |
173 | //! Returns the current values of the group. |
174 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
175 | void Values (Quantity_Color& theColor, |
176 | Standard_CString& theFont, |
177 | Standard_Real& theExpansionFactor, |
178 | Standard_Real& theSpace) const |
179 | { |
180 | theColor = myColor.GetRGB(); |
181 | theFont = myFont.ToCString(); |
182 | theExpansionFactor = myFactor; |
183 | theSpace = mySpace; |
184 | } |
185 | |
186 | //! Returns the current values of the group. |
187 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
188 | void Values (Quantity_Color& theColor, |
189 | Standard_CString& theFont, |
190 | Standard_Real& theExpansionFactor, |
191 | Standard_Real& theSpace, |
192 | Aspect_TypeOfStyleText& theStyle, |
193 | Aspect_TypeOfDisplayText& theDisplayType, |
194 | Quantity_Color& theColorSubTitle) const |
195 | { |
196 | theColor = myColor.GetRGB(); |
197 | theFont = myFont.ToCString(); |
198 | theExpansionFactor= myFactor; |
199 | theSpace = mySpace; |
200 | theStyle = myStyle; |
201 | theDisplayType = myDisplayType; |
202 | theColorSubTitle = myColorSubTitle.GetRGB(); |
203 | } |
204 | |
205 | //! Returns the current values of the group. |
206 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
207 | void Values (Quantity_Color& theColor, |
208 | Standard_CString& theFont, |
209 | Standard_Real& theExpansionFactor, |
210 | Standard_Real& theSpace, |
211 | Aspect_TypeOfStyleText& theStyle, |
212 | Aspect_TypeOfDisplayText& theDisplayType, |
213 | Quantity_Color& theColorSubTitle, |
214 | Standard_Boolean& theTextZoomable, |
215 | Standard_Real& theTextAngle) const |
216 | { |
217 | theColor = myColor.GetRGB(); |
218 | theFont = myFont.ToCString(); |
219 | theExpansionFactor= myFactor; |
220 | theSpace = mySpace; |
221 | theStyle = myStyle; |
222 | theDisplayType = myDisplayType; |
223 | theColorSubTitle = myColorSubTitle.GetRGB(); |
42cf5bc1 |
224 | |
b6472664 |
225 | theTextZoomable = myTextZoomable; |
226 | theTextAngle = myTextAngle; |
227 | } |
42cf5bc1 |
228 | |
b6472664 |
229 | //! Returns the current values of the group. |
230 | Standard_DEPRECATED("Deprecated method Values() should be replaced by individual property getters") |
231 | void Values (Quantity_Color& theColor, |
232 | Standard_CString& theFont, |
233 | Standard_Real& theExpansionFactor, |
234 | Standard_Real& theSpace, |
235 | Aspect_TypeOfStyleText& theStyle, |
236 | Aspect_TypeOfDisplayText& theDisplayType, |
237 | Quantity_Color& theColorSubTitle, |
238 | Standard_Boolean& theTextZoomable, |
239 | Standard_Real& theTextAngle, |
240 | Font_FontAspect& theTextFontAspect) const |
241 | { |
242 | theColor = myColor.GetRGB(); |
243 | theFont = myFont.ToCString(); |
244 | theExpansionFactor= myFactor; |
245 | theSpace = mySpace; |
246 | theStyle = myStyle; |
247 | theDisplayType = myDisplayType; |
248 | theColorSubTitle = myColorSubTitle.GetRGB(); |
42cf5bc1 |
249 | |
b6472664 |
250 | theTextZoomable = myTextZoomable; |
251 | theTextAngle = myTextAngle; |
252 | theTextFontAspect = myTextFontAspect; |
253 | } |
42cf5bc1 |
254 | |
b6472664 |
255 | protected: |
256 | |
257 | TCollection_AsciiString myFont; |
258 | Quantity_ColorRGBA myColor; |
259 | Standard_Real myFactor; |
260 | Standard_Real mySpace; |
261 | Aspect_TypeOfStyleText myStyle; |
262 | Aspect_TypeOfDisplayText myDisplayType; |
263 | Quantity_ColorRGBA myColorSubTitle; |
264 | bool myTextZoomable; |
265 | Standard_Real myTextAngle; |
266 | Font_FontAspect myTextFontAspect; |
267 | Handle(Graphic3d_ShaderProgram) myProgram; |
42cf5bc1 |
268 | |
b6472664 |
269 | }; |
42cf5bc1 |
270 | |
b6472664 |
271 | DEFINE_STANDARD_HANDLE(Graphic3d_AspectText3d, Standard_Transient) |
42cf5bc1 |
272 | |
273 | #endif // _Graphic3d_AspectText3d_HeaderFile |