0027068: Coding - eliminate VC++ 14 compiler warnings in MFC samples
[occt.git] / src / AIS / AIS_ColorScale.hxx
... / ...
CommitLineData
1// Created on: 2015-02-03
2// Copyright (c) 2015 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
15#ifndef _AIS_ColorScale_HeaderFile
16#define _AIS_ColorScale_HeaderFile
17
18#include <AIS_InteractiveObject.hxx>
19#include <Aspect_TypeOfColorScaleData.hxx>
20#include <Aspect_TypeOfColorScalePosition.hxx>
21#include <Aspect_SequenceOfColor.hxx>
22#include <Standard.hxx>
23#include <Standard_DefineHandle.hxx>
24#include <TCollection_ExtendedString.hxx>
25#include <TColStd_SequenceOfExtendedString.hxx>
26
27
28//! Class for drawing a custom color scale
29class AIS_ColorScale : public AIS_InteractiveObject {
30
31public:
32
33 //! Default constructor.
34 Standard_EXPORT AIS_ColorScale();
35
36 //! Calculate color according passed value; returns true if value is in range or false, if isn't
37 Standard_EXPORT Standard_Boolean FindColor (const Standard_Real theValue, Quantity_Color& theColor) const;
38
39 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);
40
41 //! Returns minimal value of color scale;
42 Standard_EXPORT Standard_Real GetMin() const { return myMin; }
43
44 //! Returns maximal value of color scale;
45 Standard_EXPORT Standard_Real GetMax() const { return myMax; }
46
47 //! Returns minimal and maximal values of color scale;
48 Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
49
50 //! Returns the type of labels;
51 //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
52 //! Aspect_TOCSD_USER - user specified label is used
53 Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
54
55 //! Returns the type of colors;
56 //! Aspect_TOCSD_AUTO - value between Red and Blue
57 //! Aspect_TOCSD_USER - user specified color from color map
58 Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
59
60 //! Returns the number of color scale intervals;
61 Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; }
62
63 //! Returns the color scale title string;
64 Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; }
65
66 //! Returns the format for numbers.
67 //! The same like format for function printf().
68 //! Used if GetLabelType() is TOCSD_AUTO;
69 Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; }
70
71 //! Returns the user specified label with index <anIndex>.
72 //! Returns empty string if label not defined.
73 Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
74
75 //! Returns the user specified color from color map with index <anIndex>.
76 //! Returns default color if index out of range in color map.
77 Standard_EXPORT Quantity_Color GetColor (const Standard_Integer theIndex) const;
78
79 //! Returns the user specified labels.
80 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
81
82 //! Returns the user specified colors.
83 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
84
85 //! Returns the position of labels concerning color filled rectangles.
86 Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
87
88 //! Returns the position of color scale title.
89 Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
90
91 //! Returns true if the labels and colors used in reversed order.
92 Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
93
94 //! Returns true if the labels placed at border of color filled rectangles.
95 Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
96
97 //! Returns true if the color scale has logarithmic intervals
98 Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
99
100 //! Sets the minimal value of color scale.
101 Standard_EXPORT void SetMin (const Standard_Real theMin);
102
103 //! Sets the maximal value of color scale.
104 Standard_EXPORT void SetMax (const Standard_Real theMax);
105
106 //! Sets the minimal and maximal value of color scale.
107 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
108
109 //! Sets the type of labels.
110 //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
111 //! Aspect_TOCSD_USER - user specified label is used
112 Standard_EXPORT void SetLabelType (const Aspect_TypeOfColorScaleData theType);
113
114 //! Sets the type of colors.
115 //! Aspect_TOCSD_AUTO - value between Red and Blue
116 //! Aspect_TOCSD_USER - user specified color from color map
117 Standard_EXPORT void SetColorType (const Aspect_TypeOfColorScaleData theType);
118
119 //! Sets the number of color scale intervals.
120 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
121
122 //! Sets the color scale title string.
123 Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
124
125 //! Sets the color scale auto label format specification.
126 Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
127
128 //! Sets the color scale label at index. Index started from 1.
129 Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex = -1);
130
131 //! Sets the color scale color at index. Index started from 1.
132 Standard_EXPORT void SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex = -1);
133
134 //! Sets the color scale labels.
135 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
136
137 //! Sets the color scale colors.
138 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
139
140 //! Sets the color scale labels position concerning color filled rectangles.
141 Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
142
143 //! Sets the color scale title position.
144 Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
145
146 //! Sets true if the labels and colors used in reversed order.
147 Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
148
149 //! Sets true if the labels placed at border of color filled rectangles.
150 Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
151
152 //! Sets true if the color scale has logarithmic intervals.
153 void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; };
154
155 //! Returns the size of color scale.
156 Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
157
158 //! Returns the width of color scale.
159 Standard_EXPORT Standard_Integer GetWidth() const { return myWidth; }
160
161 //! Returns the height of color scale.
162 Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; }
163
164 //! Returns the background color of color scale.
165 const Quantity_Color& GetBgColor() const { return myBgColor; }
166
167 //! Sets the size of color scale.
168 Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
169
170 //! Sets the width of color scale.
171 Standard_EXPORT void SetWidth (const Standard_Integer theWidth);
172
173 //! Sets the height of color scale.
174 Standard_EXPORT void SetHeight (const Standard_Integer theHeight);
175
176 //! Sets the background color of color scale.
177 void SetBGColor (const Quantity_Color& theBgColor) { myBgColor = theBgColor; };
178
179 //! Returns the position of color scale.
180 Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
181
182 //! Returns the X position of color scale.
183 Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
184
185 //! Returns the height of color scale.
186 Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
187
188 //! Sets the position of color scale.
189 Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
190
191 //! Sets the X position of color scale.
192 Standard_EXPORT void SetXPosition (const Standard_Integer theX);
193
194 //! Sets the Y position of color scale.
195 Standard_EXPORT void SetYPosition (const Standard_Integer theY);
196
197 //! Returns the height of text of color scale.
198 Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
199
200 //! Sets the height of text of color scale.
201 Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
202
203 //! Returns the width of text.
204 //! @param theText [in] the text of which to calculate width.
205 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
206
207 //! Returns the height of text.
208 //! @param theText [in] the text of which to calculate height.
209 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
210
211 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
212
213
214 DEFINE_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject)
215
216protected:
217
218 //! Draws a frame.
219 //! @param theX [in] the X coordinate of frame position.
220 //! @param theY [in] the Y coordinate of frame position.
221 //! @param theWidth [in] the width of frame.
222 //! @param theHeight [in] the height of frame.
223 //! @param theColor [in] the color of frame.
224 Standard_EXPORT void DrawFrame (const Handle(Prs3d_Presentation)& thePresentation,
225 const Standard_Integer theX, const Standard_Integer theY,
226 const Standard_Integer theWidth, const Standard_Integer theHeight,
227 const Quantity_Color& theColor);
228
229 //! Draws a text.
230 //! @param theText [in] the text to draw.
231 //! @param theX [in] the X coordinate of text position.
232 //! @param theY [in] the Y coordinate of text position.
233 //! @param theColor [in] the color of text.
234 Standard_EXPORT void DrawText (const Handle(Prs3d_Presentation)& thePresentation,
235 const TCollection_ExtendedString& theText,
236 const Standard_Integer theX, const Standard_Integer theY,
237 const Quantity_Color& theColor);
238
239private:
240
241 //! Returns the size of color scale.
242 //! @param theWidth [out] the width of color scale.
243 //! @param theHeight [out] the height of color scale.
244 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
245
246 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
247 const Handle(Prs3d_Presentation)& thePresentation,
248 const Standard_Integer theMode) Standard_OVERRIDE;
249
250 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
251 const Standard_Integer /*aMode*/) Standard_OVERRIDE
252 {}
253
254 //! Returns the format of text.
255 TCollection_AsciiString Format() const;
256
257 //! Returns the value of given interval.
258 Standard_Real GetNumber (const Standard_Integer theIndex) const;
259
260 //! Returns the value of given logarithmic interval.
261 Standard_Real GetLogNumber (const Standard_Integer theIndex) const;
262
263 //! Returns the color's hue for the given value in the given interval.
264 //! @param theValue [in] the current value of interval.
265 //! @param theMin [in] the min value of interval.
266 //! @param theMax [in] the max value of interval.
267 static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax);
268
269private:
270
271 Standard_Real myMin;
272 Standard_Real myMax;
273 TCollection_ExtendedString myTitle;
274 TCollection_AsciiString myFormat;
275 Standard_Integer myInterval;
276 Aspect_TypeOfColorScaleData myColorType;
277 Aspect_TypeOfColorScaleData myLabelType;
278 Standard_Boolean myAtBorder;
279 Standard_Boolean myReversed;
280 Standard_Boolean myIsLogarithmic;
281 Aspect_SequenceOfColor myColors;
282 TColStd_SequenceOfExtendedString myLabels;
283 Aspect_TypeOfColorScalePosition myLabelPos;
284 Aspect_TypeOfColorScalePosition myTitlePos;
285 Standard_Integer myXPos;
286 Standard_Integer myYPos;
287 Standard_Integer myWidth;
288 Standard_Integer myHeight;
289 Standard_Integer myTextHeight;
290 Quantity_Color myBgColor;
291};
292#endif