0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / AIS / AIS_ColorScale.hxx
CommitLineData
7a324550 1// Created on: 2015-02-03
2// Copyright (c) 2015 OPEN CASCADE SAS
42cf5bc1 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
7a324550 15#ifndef _AIS_ColorScale_HeaderFile
16#define _AIS_ColorScale_HeaderFile
42cf5bc1 17
7a324550 18#include <AIS_InteractiveObject.hxx>
42cf5bc1 19#include <Aspect_TypeOfColorScaleData.hxx>
7a324550 20#include <Aspect_TypeOfColorScalePosition.hxx>
42cf5bc1 21#include <Aspect_SequenceOfColor.hxx>
7a324550 22#include <Standard.hxx>
23#include <Standard_DefineHandle.hxx>
24#include <TCollection_ExtendedString.hxx>
42cf5bc1 25#include <TColStd_SequenceOfExtendedString.hxx>
42cf5bc1 26
42cf5bc1 27
7a324550 28//! Class for drawing a custom color scale
29class AIS_ColorScale : public AIS_InteractiveObject {
42cf5bc1 30
31public:
32
7a324550 33 //! Default constructor.
34 Standard_EXPORT AIS_ColorScale();
35
42cf5bc1 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;
7a324550 38
42cf5bc1 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);
7a324550 40
42cf5bc1 41 //! Returns minimal value of color scale;
7a324550 42 Standard_EXPORT Standard_Real GetMin() const { return myMin; }
43
42cf5bc1 44 //! Returns maximal value of color scale;
7a324550 45 Standard_EXPORT Standard_Real GetMax() const { return myMax; }
46
42cf5bc1 47 //! Returns minimal and maximal values of color scale;
48 Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
7a324550 49
42cf5bc1 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
7a324550 53 Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
54
42cf5bc1 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
7a324550 58 Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
59
42cf5bc1 60 //! Returns the number of color scale intervals;
7a324550 61 Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; }
62
42cf5bc1 63 //! Returns the color scale title string;
7a324550 64 Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; }
65
42cf5bc1 66 //! Returns the format for numbers.
67 //! The same like format for function printf().
68 //! Used if GetLabelType() is TOCSD_AUTO;
7a324550 69 Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; }
70
42cf5bc1 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;
7a324550 74
42cf5bc1 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;
7a324550 78
42cf5bc1 79 //! Returns the user specified labels.
80 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
7a324550 81
42cf5bc1 82 //! Returns the user specified colors.
83 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
7a324550 84
42cf5bc1 85 //! Returns the position of labels concerning color filled rectangles.
7a324550 86 Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
87
42cf5bc1 88 //! Returns the position of color scale title.
7a324550 89 Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
90
42cf5bc1 91 //! Returns true if the labels and colors used in reversed order.
7a324550 92 Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
93
42cf5bc1 94 //! Returns true if the labels placed at border of color filled rectangles.
7a324550 95 Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
96
24a88697 97 //! Returns true if the color scale has logarithmic intervals
98 Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
99
42cf5bc1 100 //! Sets the minimal value of color scale.
101 Standard_EXPORT void SetMin (const Standard_Real theMin);
7a324550 102
42cf5bc1 103 //! Sets the maximal value of color scale.
104 Standard_EXPORT void SetMax (const Standard_Real theMax);
7a324550 105
42cf5bc1 106 //! Sets the minimal and maximal value of color scale.
107 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
7a324550 108
42cf5bc1 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);
7a324550 113
42cf5bc1 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);
7a324550 118
42cf5bc1 119 //! Sets the number of color scale intervals.
120 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
7a324550 121
42cf5bc1 122 //! Sets the color scale title string.
123 Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
7a324550 124
42cf5bc1 125 //! Sets the color scale auto label format specification.
126 Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
7a324550 127
42cf5bc1 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);
7a324550 130
42cf5bc1 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);
7a324550 133
42cf5bc1 134 //! Sets the color scale labels.
135 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
7a324550 136
42cf5bc1 137 //! Sets the color scale colors.
138 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
7a324550 139
42cf5bc1 140 //! Sets the color scale labels position concerning color filled rectangles.
141 Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
7a324550 142
42cf5bc1 143 //! Sets the color scale title position.
144 Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
7a324550 145
42cf5bc1 146 //! Sets true if the labels and colors used in reversed order.
147 Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
7a324550 148
42cf5bc1 149 //! Sets true if the labels placed at border of color filled rectangles.
150 Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
7a324550 151
24a88697 152 //! Sets true if the color scale has logarithmic intervals.
153 void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; };
154
42cf5bc1 155 //! Returns the size of color scale.
b4b2ecca 156 Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
7a324550 157
42cf5bc1 158 //! Returns the width of color scale.
b4b2ecca 159 Standard_EXPORT Standard_Integer GetWidth() const { return myWidth; }
7a324550 160
42cf5bc1 161 //! Returns the height of color scale.
b4b2ecca 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; }
7a324550 166
42cf5bc1 167 //! Sets the size of color scale.
b4b2ecca 168 Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
7a324550 169
42cf5bc1 170 //! Sets the width of color scale.
b4b2ecca 171 Standard_EXPORT void SetWidth (const Standard_Integer theWidth);
7a324550 172
42cf5bc1 173 //! Sets the height of color scale.
b4b2ecca 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; };
7a324550 178
42cf5bc1 179 //! Returns the position of color scale.
180 Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
7a324550 181
42cf5bc1 182 //! Returns the X position of color scale.
b4b2ecca 183 Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
7a324550 184
42cf5bc1 185 //! Returns the height of color scale.
b4b2ecca 186 Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
7a324550 187
42cf5bc1 188 //! Sets the position of color scale.
b4b2ecca 189 Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
7a324550 190
42cf5bc1 191 //! Sets the X position of color scale.
b4b2ecca 192 Standard_EXPORT void SetXPosition (const Standard_Integer theX);
7a324550 193
42cf5bc1 194 //! Sets the Y position of color scale.
b4b2ecca 195 Standard_EXPORT void SetYPosition (const Standard_Integer theY);
7a324550 196
42cf5bc1 197 //! Returns the height of text of color scale.
7a324550 198 Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
199
42cf5bc1 200 //! Sets the height of text of color scale.
7a324550 201 Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
202
42cf5bc1 203 //! Returns the width of text.
204 //! @param theText [in] the text of which to calculate width.
7a324550 205 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
206
42cf5bc1 207 //! Returns the height of text.
208 //! @param theText [in] the text of which to calculate height.
7a324550 209 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
42cf5bc1 210
7a324550 211 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
42cf5bc1 212
213
92efcf78 214 DEFINE_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject)
42cf5bc1 215
216protected:
217
7a324550 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
42cf5bc1 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.
7a324550 244 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
42cf5bc1 245
7a324550 246 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
247 const Handle(Prs3d_Presentation)& thePresentation,
79104795 248 const Standard_Integer theMode) Standard_OVERRIDE;
42cf5bc1 249
7a324550 250 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 251 const Standard_Integer /*aMode*/) Standard_OVERRIDE
252 {}
42cf5bc1 253
42cf5bc1 254 //! Returns the format of text.
7a324550 255 TCollection_AsciiString Format() const;
256
42cf5bc1 257 //! Returns the value of given interval.
24a88697 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;
7a324550 262
42cf5bc1 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.
24a88697 267 static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax);
7a324550 268
269private:
42cf5bc1 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;
24a88697 280 Standard_Boolean myIsLogarithmic;
42cf5bc1 281 Aspect_SequenceOfColor myColors;
282 TColStd_SequenceOfExtendedString myLabels;
283 Aspect_TypeOfColorScalePosition myLabelPos;
284 Aspect_TypeOfColorScalePosition myTitlePos;
b4b2ecca 285 Standard_Integer myXPos;
286 Standard_Integer myYPos;
287 Standard_Integer myWidth;
288 Standard_Integer myHeight;
42cf5bc1 289 Standard_Integer myTextHeight;
b4b2ecca 290 Quantity_Color myBgColor;
42cf5bc1 291};
7a324550 292#endif