00dfc9bcc52481e0dc945588592238813dd605b6
[occt.git] / src / Graphic3d / Graphic3d_AspectText3d.cxx
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 //    30/11/98 ; FMN : S3819. Textes always visible.   
17 //-Version  
18 //-Design Declaration of variables specific to the context
19 //    of trace of texts 3d
20 //-Warning  A context of trace of text is defined by :
21 //    - the font used
22 //    - the color
23 //    - the scale
24 //    - the space between characters
25 //-References 
26 //-Language C++ 2.0
27 //-Declarations
28 // for the class
29
30 #include <Font_NameOfFont.hxx>
31 #include <Graphic3d_AspectText3d.hxx>
32 #include <Graphic3d_AspectTextDefinitionError.hxx>
33 #include <OSD_Environment.hxx>
34 #include <Quantity_Color.hxx>
35 #include <Standard_Type.hxx>
36 #include <TCollection_AsciiString.hxx>
37
38 IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_AspectText3d,MMgt_TShared)
39
40 //-Aliases
41 //-Global data definitions
42 //  -- la font utilisee
43 //  MyFont    : NameOfFont;
44 //  -- la couleur
45 //  MyColor   : Color;
46 //  -- l'echelle
47 //  MyFactor  : Standard_Real;
48 //  -- l'espace entre caracteres
49 //  MySpace   : Standard_Real;
50 //  -- le style
51 //  MyStyle   : TypeOfStyleText;
52 //  -- le display type
53 //  MyDisplayType : TypeOfDisplayText;
54 //  -- la couleur du sous-titrage et pour le fond en mode decalage.
55 //  MyColorSubTitle : Color;
56 //-Constructors
57 //-Destructors
58 //-Methods, in order
59 Graphic3d_AspectText3d::Graphic3d_AspectText3d ():
60 MyFont (Font_NOF_ASCII_MONO), MyColor (Quantity_NOC_YELLOW), MyFactor (1.0), MySpace (0.0), MyStyle (Aspect_TOST_NORMAL), MyDisplayType (Aspect_TODT_NORMAL), MyColorSubTitle (Quantity_NOC_WHITE) {
61   MyTextZoomable = Standard_False;
62   MyTextAngle = 0.0;
63   MyTextFontAspect = Font_FA_Regular;
64 }
65
66 Graphic3d_AspectText3d::Graphic3d_AspectText3d (
67   const Quantity_Color& AColor, 
68   const Standard_CString AFont, 
69   const Standard_Real AFactor, 
70   const Standard_Real ASpace,
71   const Aspect_TypeOfStyleText AStyle,
72   const Aspect_TypeOfDisplayText ADisplayType):
73 MyFont(AFont), MyColor (AColor), MyFactor (AFactor), MySpace (ASpace), MyStyle (AStyle), MyDisplayType(ADisplayType), MyColorSubTitle   (Quantity_NOC_WHITE) {
74   MyTextZoomable = Standard_False;
75   MyTextAngle = 0.0;
76   MyTextFontAspect = Font_FA_Regular;
77   if(MyFont.Length() == 0)
78     MyFont.AssignCat(Font_NOF_ASCII_MONO);
79
80   if (AFactor <= 0.0)
81     Graphic3d_AspectTextDefinitionError::Raise
82     ("Bad value for TextScaleFactor");
83
84 }
85
86 void Graphic3d_AspectText3d::SetColor (const Quantity_Color& AColor) {
87
88   MyColor = AColor;
89
90 }
91
92 void Graphic3d_AspectText3d::SetExpansionFactor (const Standard_Real AFactor) {
93
94   if (AFactor <= 0.0)
95     Graphic3d_AspectTextDefinitionError::Raise
96     ("Bad value for TextScaleFactor");
97
98   MyFactor = AFactor;
99
100 }
101
102 void Graphic3d_AspectText3d::SetFont (const Standard_CString AFont) {
103
104
105   TCollection_AsciiString aTemp("");
106   if( !strlen(AFont))
107     aTemp.AssignCat(Font_NOF_ASCII_MONO);
108   else
109     aTemp.AssignCat(AFont);
110   MyFont = aTemp;  
111 }
112
113 void Graphic3d_AspectText3d::SetSpace (const Standard_Real ASpace) {
114
115   MySpace = ASpace;
116
117 }
118
119 void Graphic3d_AspectText3d::SetStyle(const Aspect_TypeOfStyleText AStyle) {
120
121   MyStyle = AStyle;
122
123 }
124
125 void Graphic3d_AspectText3d::SetDisplayType(const Aspect_TypeOfDisplayText ADisplayType) {
126
127   MyDisplayType = ADisplayType;
128
129 }
130
131 void Graphic3d_AspectText3d::SetColorSubTitle (const Quantity_Color& AColor) {
132
133   MyColorSubTitle = AColor;
134
135
136 }
137
138
139 void Graphic3d_AspectText3d::SetTextZoomable(const Standard_Boolean AFlag) 
140 {
141
142   MyTextZoomable = AFlag;
143
144 }
145
146 Standard_Boolean Graphic3d_AspectText3d::GetTextZoomable() const
147 {
148   return MyTextZoomable;
149 }
150
151 void Graphic3d_AspectText3d::SetTextAngle(const Standard_Real AAngle) 
152 {
153   MyTextAngle = AAngle;
154 }
155
156 Standard_Real Graphic3d_AspectText3d::GetTextAngle() const
157 {
158   return MyTextAngle;
159 }
160
161 void Graphic3d_AspectText3d::SetTextFontAspect(const Font_FontAspect AFontAspect) 
162 {
163   MyTextFontAspect = AFontAspect;
164 }
165
166 Font_FontAspect Graphic3d_AspectText3d::GetTextFontAspect() const
167 {
168   return MyTextFontAspect;
169 }
170
171
172
173 void Graphic3d_AspectText3d::Values (Quantity_Color& AColor, Standard_CString& AFont, Standard_Real& AFactor, Standard_Real& ASpace) const {
174
175   AColor    = MyColor;
176   AFont     = MyFont.ToCString();
177   AFactor   = MyFactor;
178   ASpace    = MySpace;
179
180 }
181 void Graphic3d_AspectText3d::Values (Quantity_Color& AColor, Standard_CString& AFont, Standard_Real& AFactor, Standard_Real& ASpace, Aspect_TypeOfStyleText& AStyle,Aspect_TypeOfDisplayText& ADisplayType,Quantity_Color& AColorSubTitle) const {
182
183   AColor          = MyColor;
184   AFont           = MyFont.ToCString();
185   AFactor         = MyFactor;
186   ASpace          = MySpace;
187   AStyle          = MyStyle;
188   ADisplayType    = MyDisplayType;
189   AColorSubTitle  = MyColorSubTitle;
190
191 }
192 void Graphic3d_AspectText3d::Values (Quantity_Color& AColor, Standard_CString& AFont, Standard_Real& AFactor, Standard_Real& ASpace, Aspect_TypeOfStyleText& AStyle,Aspect_TypeOfDisplayText& ADisplayType,Quantity_Color& AColorSubTitle, Standard_Boolean& ATextZoomable,Standard_Real& ATextAngle ) const {
193
194   AColor          = MyColor;
195   AFont           = MyFont.ToCString();
196   AFactor         = MyFactor;
197   ASpace          = MySpace;
198   AStyle          = MyStyle;
199   ADisplayType    = MyDisplayType;
200   AColorSubTitle  = MyColorSubTitle;
201
202   ATextZoomable   = MyTextZoomable;  
203   ATextAngle      = MyTextAngle;  
204
205 }
206
207 void Graphic3d_AspectText3d::Values ( Quantity_Color& AColor, 
208                                       Standard_CString& AFont,
209                                       Standard_Real& AFactor, 
210                                       Standard_Real& ASpace,
211                                       Aspect_TypeOfStyleText& AStyle,
212                                       Aspect_TypeOfDisplayText& ADisplayType,
213                                       Quantity_Color& AColorSubTitle, 
214                                       Standard_Boolean& ATextZoomable,
215                                       Standard_Real& ATextAngle,
216                                       Font_FontAspect& ATextFontAspect ) const 
217 {
218
219   AColor          = MyColor;
220   AFont           = MyFont.ToCString();
221   AFactor         = MyFactor;
222   ASpace          = MySpace;
223   AStyle          = MyStyle;
224   ADisplayType    = MyDisplayType;
225   AColorSubTitle  = MyColorSubTitle;
226
227   ATextZoomable   = MyTextZoomable;  
228   ATextAngle      = MyTextAngle;  
229   ATextFontAspect = MyTextFontAspect;
230
231 }
232
233 void Graphic3d_AspectText3d::SetShaderProgram (const Handle(Graphic3d_ShaderProgram)& theProgram)
234 {
235   MyShaderProgram = theProgram;
236 }
237
238 const Handle(Graphic3d_ShaderProgram)& Graphic3d_AspectText3d::ShaderProgram() const
239 {
240   return MyShaderProgram;
241 }