42cf5bc1 |
1 | // Created on: 2004-06-22 |
2 | // Created by: STV |
3 | // Copyright (c) 2004-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 _Aspect_ColorScale_HeaderFile |
17 | #define _Aspect_ColorScale_HeaderFile |
18 | |
19 | #include <Standard.hxx> |
20 | #include <Standard_Type.hxx> |
21 | |
22 | #include <Standard_Real.hxx> |
23 | #include <TCollection_ExtendedString.hxx> |
24 | #include <TCollection_AsciiString.hxx> |
25 | #include <Standard_Integer.hxx> |
26 | #include <Aspect_TypeOfColorScaleData.hxx> |
27 | #include <Standard_Boolean.hxx> |
28 | #include <Aspect_SequenceOfColor.hxx> |
29 | #include <TColStd_SequenceOfExtendedString.hxx> |
30 | #include <Aspect_TypeOfColorScalePosition.hxx> |
31 | #include <MMgt_TShared.hxx> |
32 | class Quantity_Color; |
33 | class TCollection_ExtendedString; |
34 | class TCollection_AsciiString; |
35 | |
36 | |
37 | class Aspect_ColorScale; |
38 | DEFINE_STANDARD_HANDLE(Aspect_ColorScale, MMgt_TShared) |
39 | |
40 | //! Defines a color scale for viewer. |
41 | class Aspect_ColorScale : public MMgt_TShared |
42 | { |
43 | |
44 | public: |
45 | |
46 | |
47 | //! Calculate color according passed value; returns true if value is in range or false, if isn't |
48 | Standard_EXPORT Standard_Boolean FindColor (const Standard_Real theValue, Quantity_Color& theColor) const; |
49 | |
50 | Standard_EXPORT static Standard_Boolean FindColor (const Standard_Real theValue, const Standard_Real theMin, const Standard_Real theMax, const Standard_Integer theColorsCount, Quantity_Color& theColor); |
51 | |
52 | //! Returns minimal value of color scale; |
53 | Standard_EXPORT Standard_Real GetMin() const; |
54 | |
55 | //! Returns maximal value of color scale; |
56 | Standard_EXPORT Standard_Real GetMax() const; |
57 | |
58 | //! Returns minimal and maximal values of color scale; |
59 | Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const; |
60 | |
61 | //! Returns the type of labels; |
62 | //! Aspect_TOCSD_AUTO - labels as boundary values for intervals |
63 | //! Aspect_TOCSD_USER - user specified label is used |
64 | Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const; |
65 | |
66 | //! Returns the type of colors; |
67 | //! Aspect_TOCSD_AUTO - value between Red and Blue |
68 | //! Aspect_TOCSD_USER - user specified color from color map |
69 | Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const; |
70 | |
71 | //! Returns the number of color scale intervals; |
72 | Standard_EXPORT Standard_Integer GetNumberOfIntervals() const; |
73 | |
74 | //! Returns the color scale title string; |
75 | Standard_EXPORT TCollection_ExtendedString GetTitle() const; |
76 | |
77 | //! Returns the format for numbers. |
78 | //! The same like format for function printf(). |
79 | //! Used if GetLabelType() is TOCSD_AUTO; |
80 | Standard_EXPORT TCollection_AsciiString GetFormat() const; |
81 | |
82 | //! Returns the user specified label with index <anIndex>. |
83 | //! Returns empty string if label not defined. |
84 | Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const; |
85 | |
86 | //! Returns the user specified color from color map with index <anIndex>. |
87 | //! Returns default color if index out of range in color map. |
88 | Standard_EXPORT Quantity_Color GetColor (const Standard_Integer theIndex) const; |
89 | |
90 | //! Returns the user specified labels. |
91 | Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const; |
92 | |
93 | //! Returns the user specified colors. |
94 | Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const; |
95 | |
96 | //! Returns the position of labels concerning color filled rectangles. |
97 | Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const; |
98 | |
99 | //! Returns the position of color scale title. |
100 | Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const; |
101 | |
102 | //! Returns true if the labels and colors used in reversed order. |
103 | Standard_EXPORT Standard_Boolean IsReversed() const; |
104 | |
105 | //! Returns true if the labels placed at border of color filled rectangles. |
106 | Standard_EXPORT Standard_Boolean IsLabelAtBorder() const; |
107 | |
108 | //! Sets the minimal value of color scale. |
109 | Standard_EXPORT void SetMin (const Standard_Real theMin); |
110 | |
111 | //! Sets the maximal value of color scale. |
112 | Standard_EXPORT void SetMax (const Standard_Real theMax); |
113 | |
114 | //! Sets the minimal and maximal value of color scale. |
115 | Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax); |
116 | |
117 | //! Sets the type of labels. |
118 | //! Aspect_TOCSD_AUTO - labels as boundary values for intervals |
119 | //! Aspect_TOCSD_USER - user specified label is used |
120 | Standard_EXPORT void SetLabelType (const Aspect_TypeOfColorScaleData theType); |
121 | |
122 | //! Sets the type of colors. |
123 | //! Aspect_TOCSD_AUTO - value between Red and Blue |
124 | //! Aspect_TOCSD_USER - user specified color from color map |
125 | Standard_EXPORT void SetColorType (const Aspect_TypeOfColorScaleData theType); |
126 | |
127 | //! Sets the number of color scale intervals. |
128 | Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum); |
129 | |
130 | //! Sets the color scale title string. |
131 | Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle); |
132 | |
133 | //! Sets the color scale auto label format specification. |
134 | Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat); |
135 | |
136 | //! Sets the color scale label at index. Index started from 1. |
137 | Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex = -1); |
138 | |
139 | //! Sets the color scale color at index. Index started from 1. |
140 | Standard_EXPORT void SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex = -1); |
141 | |
142 | //! Sets the color scale labels. |
143 | Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq); |
144 | |
145 | //! Sets the color scale colors. |
146 | Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq); |
147 | |
148 | //! Sets the color scale labels position concerning color filled rectangles. |
149 | Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos); |
150 | |
151 | //! Sets the color scale title position. |
152 | Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos); |
153 | |
154 | //! Sets true if the labels and colors used in reversed order. |
155 | Standard_EXPORT void SetReversed (const Standard_Boolean theReverse); |
156 | |
157 | //! Sets true if the labels placed at border of color filled rectangles. |
158 | Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn); |
159 | |
160 | //! Returns the size of color scale. |
161 | Standard_EXPORT void GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const; |
162 | |
163 | //! Returns the width of color scale. |
164 | Standard_EXPORT Standard_Real GetWidth() const; |
165 | |
166 | //! Returns the height of color scale. |
167 | Standard_EXPORT Standard_Real GetHeight() const; |
168 | |
169 | //! Sets the size of color scale. |
170 | Standard_EXPORT void SetSize (const Standard_Real theWidth, const Standard_Real theHeight); |
171 | |
172 | //! Sets the width of color scale. |
173 | Standard_EXPORT void SetWidth (const Standard_Real theWidth); |
174 | |
175 | //! Sets the height of color scale. |
176 | Standard_EXPORT void SetHeight (const Standard_Real theHeight); |
177 | |
178 | //! Returns the position of color scale. |
179 | Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const; |
180 | |
181 | //! Returns the X position of color scale. |
182 | Standard_EXPORT Standard_Real GetXPosition() const; |
183 | |
184 | //! Returns the height of color scale. |
185 | Standard_EXPORT Standard_Real GetYPosition() const; |
186 | |
187 | //! Sets the position of color scale. |
188 | Standard_EXPORT void SetPosition (const Standard_Real theX, const Standard_Real theY); |
189 | |
190 | //! Sets the X position of color scale. |
191 | Standard_EXPORT void SetXPosition (const Standard_Real theX); |
192 | |
193 | //! Sets the Y position of color scale. |
194 | Standard_EXPORT void SetYPosition (const Standard_Real theY); |
195 | |
196 | //! Returns the height of text of color scale. |
197 | Standard_EXPORT Standard_Integer GetTextHeight() const; |
198 | |
199 | //! Sets the height of text of color scale. |
200 | Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight); |
201 | |
202 | //! Draws a rectangle. |
203 | //! @param theX [in] the X coordinate of rectangle position. |
204 | //! @param theY [in] the Y coordinate of rectangle position. |
205 | //! @param theWidth [in] the width of rectangle. |
206 | //! @param theHeight [in] the height of rectangle. |
207 | //! @param theColor [in] the color of rectangle. |
208 | //! @param theFilled [in] defines if rectangle must be filled. |
209 | Standard_EXPORT virtual void PaintRect (const Standard_Integer theX, const Standard_Integer theY, const Standard_Integer theWidth, const Standard_Integer theHeight, const Quantity_Color& theColor, const Standard_Boolean theFilled = Standard_False) = 0; |
210 | |
211 | //! Draws a text. |
212 | //! @param theText [in] the text to draw. |
213 | //! @param theX [in] the X coordinate of text position. |
214 | //! @param theY [in] the Y coordinate of text position. |
215 | //! @param theColor [in] the color of text. |
216 | Standard_EXPORT virtual void PaintText (const TCollection_ExtendedString& theText, const Standard_Integer theX, const Standard_Integer theY, const Quantity_Color& theColor) = 0; |
217 | |
218 | //! Returns the width of text. |
219 | //! @param theText [in] the text of which to calculate width. |
220 | Standard_EXPORT virtual Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const = 0; |
221 | |
222 | //! Returns the height of text. |
223 | //! @param theText [in] the text of which to calculate height. |
224 | Standard_EXPORT virtual Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const = 0; |
225 | |
226 | |
227 | |
228 | |
229 | DEFINE_STANDARD_RTTI(Aspect_ColorScale,MMgt_TShared) |
230 | |
231 | protected: |
232 | |
233 | |
234 | //! Default constructor. |
235 | Standard_EXPORT Aspect_ColorScale(); |
236 | |
237 | //! Returns the size of color scale. |
238 | //! @param theWidth [out] the width of color scale. |
239 | //! @param theHeight [out] the height of color scale. |
240 | Standard_EXPORT void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const; |
241 | |
242 | //! updates color scale parameters. |
243 | Standard_EXPORT virtual void UpdateColorScale(); |
244 | |
245 | //! Draws color scale. |
246 | //! @param theBgColor [in] background color |
247 | //! @param theX [in] the X coordinate of color scale position. |
248 | //! @param theY [in] the Y coordinate of color scale position. |
249 | //! @param theWidth [in] the width of color scale. |
250 | //! @param theHeight [in] the height of color scale. |
251 | Standard_EXPORT void DrawScale (const Quantity_Color& theBgColor, const Standard_Integer theX, const Standard_Integer theY, const Standard_Integer theWidth, const Standard_Integer theHeight); |
252 | |
253 | Standard_EXPORT virtual Standard_Boolean BeginPaint(); |
254 | |
255 | Standard_EXPORT virtual Standard_Boolean EndPaint(); |
256 | |
257 | |
258 | |
259 | private: |
260 | |
261 | |
262 | //! Returns the format of text. |
263 | Standard_EXPORT TCollection_AsciiString Format() const; |
264 | |
265 | //! Returns the value of given interval. |
266 | Standard_EXPORT Standard_Real GetNumber (const Standard_Integer theIndex) const; |
267 | |
268 | //! Returns the color's hue for the given value in the given interval. |
269 | //! @param theValue [in] the current value of interval. |
270 | //! @param theMin [in] the min value of interval. |
271 | //! @param theMax [in] the max value of interval. |
272 | Standard_EXPORT static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax); |
273 | |
274 | Standard_Real myMin; |
275 | Standard_Real myMax; |
276 | TCollection_ExtendedString myTitle; |
277 | TCollection_AsciiString myFormat; |
278 | Standard_Integer myInterval; |
279 | Aspect_TypeOfColorScaleData myColorType; |
280 | Aspect_TypeOfColorScaleData myLabelType; |
281 | Standard_Boolean myAtBorder; |
282 | Standard_Boolean myReversed; |
283 | Aspect_SequenceOfColor myColors; |
284 | TColStd_SequenceOfExtendedString myLabels; |
285 | Aspect_TypeOfColorScalePosition myLabelPos; |
286 | Aspect_TypeOfColorScalePosition myTitlePos; |
287 | Standard_Real myXPos; |
288 | Standard_Real myYPos; |
289 | Standard_Real myWidth; |
290 | Standard_Real myHeight; |
291 | Standard_Integer myTextHeight; |
292 | |
293 | |
294 | }; |
295 | |
296 | |
297 | |
298 | |
299 | |
300 | |
301 | |
302 | #endif // _Aspect_ColorScale_HeaderFile |