1 // Created by: NW,JPB,CAL
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef _Graphic3d_AspectText3d_HeaderFile
17 #define _Graphic3d_AspectText3d_HeaderFile
19 #include <Aspect_TypeOfStyleText.hxx>
20 #include <Aspect_TypeOfDisplayText.hxx>
21 #include <Graphic3d_AspectTextDefinitionError.hxx>
22 #include <Graphic3d_ShaderProgram.hxx>
23 #include <Font_FontAspect.hxx>
24 #include <Font_NameOfFont.hxx>
25 #include <MMgt_TShared.hxx>
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>
33 //! Creates and updates a group of attributes for
34 //! text primitives. This group contains the color,
35 //! font, expansion factor (height/width ratio), and
36 //! inter-character space.
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.
43 class Graphic3d_AspectText3d : public Standard_Transient
45 DEFINE_STANDARD_RTTIEXT(Graphic3d_AspectText3d, Standard_Transient)
48 //! Creates a context table for text primitives
49 //! defined with the following default values:
51 //! Color : NOC_YELLOW
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();
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")
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);
71 //! Return the text color.
72 const Quantity_Color& Color() const { return myColor.GetRGB(); }
74 //! Return the text color.
75 const Quantity_ColorRGBA& ColorRGBA() const { return myColor; }
77 //! Modifies the color.
78 void SetColor (const Quantity_Color& theColor) { myColor.SetRGB (theColor); }
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.
83 void SetExpansionFactor (const Standard_Real theFactor)
87 Graphic3d_AspectTextDefinitionError::Raise ("Bad value for TextScaleFactor");
93 const TCollection_AsciiString& Font() const { return myFont; }
95 //! Modifies the font.
96 void SetFont (const TCollection_AsciiString& theFont)
98 myFont = !theFont.IsEmpty() ? theFont : TCollection_AsciiString (Font_NOF_ASCII_MONO);
101 //! Modifies the font.
102 void SetFont (const Standard_CString theFont)
104 SetFont (TCollection_AsciiString (theFont));
107 //! Return the space between characters.
108 Standard_Real Space() const { return mySpace; }
110 //! Modifies the space between the characters.
111 void SetSpace (const Standard_Real theSpace) { mySpace = theSpace; }
113 //! Return the text style.
114 Aspect_TypeOfStyleText Style() const { return myStyle; }
116 //! Modifies the style of the text.
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; }
125 //! Return display type.
126 Aspect_TypeOfDisplayText DisplayType() const { return myDisplayType; }
128 //! Define the display type of the text.
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.
135 void SetDisplayType (const Aspect_TypeOfDisplayText theDisplayType) { myDisplayType = theDisplayType; }
137 //! Return subtitle color.
138 const Quantity_ColorRGBA& ColorSubTitleRGBA() const { return myColorSubTitle; }
140 //! Return subtitle color.
141 const Quantity_Color& ColorSubTitle() const { return myColorSubTitle.GetRGB(); }
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); }
147 //! Returns TRUE when the Text Zoomable is on.
148 bool GetTextZoomable() const { return myTextZoomable; }
150 //! Turns usage of text zoomable on/off
151 void SetTextZoomable (const bool theFlag) { myTextZoomable = theFlag; }
153 //! Returns Angle of degree
154 Standard_Real GetTextAngle() const { return myTextAngle; }
156 //! Turns usage of text rotated
157 void SetTextAngle (const Standard_Real theAngle) { myTextAngle = theAngle; }
159 //! Returns text FontAspect
160 Font_FontAspect GetTextFontAspect() const { return myTextFontAspect; }
162 //! Turns usage of Aspect text
163 void SetTextFontAspect (const Font_FontAspect theFontAspect) { myTextFontAspect = theFontAspect; }
165 //! Return the shader program.
166 const Handle(Graphic3d_ShaderProgram)& ShaderProgram() const { return myProgram; }
168 //! Sets up OpenGL/GLSL shader program.
169 void SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram) { myProgram = theProgram; }
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
180 theColor = myColor.GetRGB();
181 theFont = myFont.ToCString();
182 theExpansionFactor = myFactor;
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
196 theColor = myColor.GetRGB();
197 theFont = myFont.ToCString();
198 theExpansionFactor= myFactor;
201 theDisplayType = myDisplayType;
202 theColorSubTitle = myColorSubTitle.GetRGB();
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
217 theColor = myColor.GetRGB();
218 theFont = myFont.ToCString();
219 theExpansionFactor= myFactor;
222 theDisplayType = myDisplayType;
223 theColorSubTitle = myColorSubTitle.GetRGB();
225 theTextZoomable = myTextZoomable;
226 theTextAngle = myTextAngle;
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
242 theColor = myColor.GetRGB();
243 theFont = myFont.ToCString();
244 theExpansionFactor= myFactor;
247 theDisplayType = myDisplayType;
248 theColorSubTitle = myColorSubTitle.GetRGB();
250 theTextZoomable = myTextZoomable;
251 theTextAngle = myTextAngle;
252 theTextFontAspect = myTextFontAspect;
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;
265 Standard_Real myTextAngle;
266 Font_FontAspect myTextFontAspect;
267 Handle(Graphic3d_ShaderProgram) myProgram;
271 DEFINE_STANDARD_HANDLE(Graphic3d_AspectText3d, Standard_Transient)
273 #endif // _Graphic3d_AspectText3d_HeaderFile