0025180: Visualization - Homogeneous transformation API in TKV3d
[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
180f89a2 27//! Class for drawing a custom color scale.
28//!
29//! The color scale consists of rectangular color bar (composed of fixed
30//! number of color intervals), optional labels, and title.
31//! The labels can be positioned either at the boundaries of the intervals,
32//! or at the middle of each interval.
33//! Colors and labels can be either defined automatically or set by the user.
34//! Automatic labels are calculated from numerical limits of the scale,
35//! its type (logarithmic or plain), and formatted by specified format string.
42cf5bc1 36
7a324550 37class AIS_ColorScale : public AIS_InteractiveObject {
42cf5bc1 38
39public:
40
7a324550 41 //! Default constructor.
42 Standard_EXPORT AIS_ColorScale();
43
42cf5bc1 44 //! Calculate color according passed value; returns true if value is in range or false, if isn't
45 Standard_EXPORT Standard_Boolean FindColor (const Standard_Real theValue, Quantity_Color& theColor) const;
7a324550 46
d5514578 47 //! Calculate color according passed value; returns true if value is in range or false, if isn't
42cf5bc1 48 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 49
42cf5bc1 50 //! Returns minimal value of color scale;
7a324550 51 Standard_EXPORT Standard_Real GetMin() const { return myMin; }
52
42cf5bc1 53 //! Returns maximal value of color scale;
7a324550 54 Standard_EXPORT Standard_Real GetMax() const { return myMax; }
55
42cf5bc1 56 //! Returns minimal and maximal values of color scale;
57 Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
7a324550 58
42cf5bc1 59 //! Returns the type of labels;
60 //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
61 //! Aspect_TOCSD_USER - user specified label is used
7a324550 62 Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
63
42cf5bc1 64 //! Returns the type of colors;
65 //! Aspect_TOCSD_AUTO - value between Red and Blue
66 //! Aspect_TOCSD_USER - user specified color from color map
7a324550 67 Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
68
42cf5bc1 69 //! Returns the number of color scale intervals;
7a324550 70 Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; }
71
42cf5bc1 72 //! Returns the color scale title string;
7a324550 73 Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; }
74
42cf5bc1 75 //! Returns the format for numbers.
76 //! The same like format for function printf().
77 //! Used if GetLabelType() is TOCSD_AUTO;
7a324550 78 Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; }
79
180f89a2 80 //! Returns the user specified label with index theIndex.
81 //! Index is in range from 1 to GetNumberOfIntervals() or to
82 //! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
42cf5bc1 83 //! Returns empty string if label not defined.
84 Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
7a324550 85
180f89a2 86 //! Returns the user specified color from color map with index <anIndex> (starts at 1).
87 //! Returns default color if index is out of range in color map.
88 Standard_EXPORT Quantity_Color GetIntervalColor (const Standard_Integer theIndex) const;
7a324550 89
42cf5bc1 90 //! Returns the user specified labels.
91 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
7a324550 92
42cf5bc1 93 //! Returns the user specified colors.
94 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
7a324550 95
42cf5bc1 96 //! Returns the position of labels concerning color filled rectangles.
7a324550 97 Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
98
42cf5bc1 99 //! Returns the position of color scale title.
7a324550 100 Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
101
42cf5bc1 102 //! Returns true if the labels and colors used in reversed order.
7a324550 103 Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
104
180f89a2 105 //! Returns true if the labels are placed at border of color intervals.
7a324550 106 Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
107
24a88697 108 //! Returns true if the color scale has logarithmic intervals
109 Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
110
42cf5bc1 111 //! Sets the minimal value of color scale.
112 Standard_EXPORT void SetMin (const Standard_Real theMin);
7a324550 113
42cf5bc1 114 //! Sets the maximal value of color scale.
115 Standard_EXPORT void SetMax (const Standard_Real theMax);
7a324550 116
42cf5bc1 117 //! Sets the minimal and maximal value of color scale.
118 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
7a324550 119
42cf5bc1 120 //! Sets the type of labels.
121 //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
122 //! Aspect_TOCSD_USER - user specified label is used
123 Standard_EXPORT void SetLabelType (const Aspect_TypeOfColorScaleData theType);
7a324550 124
42cf5bc1 125 //! Sets the type of colors.
126 //! Aspect_TOCSD_AUTO - value between Red and Blue
127 //! Aspect_TOCSD_USER - user specified color from color map
128 Standard_EXPORT void SetColorType (const Aspect_TypeOfColorScaleData theType);
7a324550 129
42cf5bc1 130 //! Sets the number of color scale intervals.
131 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
7a324550 132
42cf5bc1 133 //! Sets the color scale title string.
134 Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
7a324550 135
42cf5bc1 136 //! Sets the color scale auto label format specification.
137 Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
7a324550 138
180f89a2 139 //! Sets the color scale label at index.
140 //! Index is in range from 1 to GetNumberOfIntervals() or to
141 //! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
142 Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex);
7a324550 143
180f89a2 144 //! Sets the color of the specified interval.
145 //! Index is in range from 1 to GetNumberOfIntervals().
146 Standard_EXPORT void SetIntervalColor (const Quantity_Color& theColor, const Standard_Integer theIndex);
7a324550 147
42cf5bc1 148 //! Sets the color scale labels.
180f89a2 149 //! The length of the sequence should be equal to GetNumberOfIntervals() or to
150 //! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
42cf5bc1 151 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
7a324550 152
42cf5bc1 153 //! Sets the color scale colors.
180f89a2 154 //! The length of the sequence should be equal to GetNumberOfIntervals().
42cf5bc1 155 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
7a324550 156
180f89a2 157 //! Sets the color scale labels position relative to color bar.
42cf5bc1 158 Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
7a324550 159
42cf5bc1 160 //! Sets the color scale title position.
161 Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
7a324550 162
42cf5bc1 163 //! Sets true if the labels and colors used in reversed order.
164 Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
7a324550 165
180f89a2 166 //! Sets true if the labels are placed at border of color intervals (true by default).
167 //! If set to False, labels will be drawn at color intervals rather than at borders.
42cf5bc1 168 Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
7a324550 169
24a88697 170 //! Sets true if the color scale has logarithmic intervals.
171 void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; };
172
180f89a2 173 //! Returns the size of color bar.
174 Standard_EXPORT void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const;
7a324550 175
180f89a2 176 //! Returns the breadth of color bar.
177 Standard_EXPORT Standard_Integer GetBreadth() const { return myBreadth; }
7a324550 178
180f89a2 179 //! Returns the height of color bar.
b4b2ecca 180 Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; }
181
180f89a2 182 //! Sets the size of color bar.
b4b2ecca 183 Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
7a324550 184
180f89a2 185 //! Sets the width of color bar.
186 Standard_EXPORT void SetBreadth (const Standard_Integer theBreadth);
7a324550 187
180f89a2 188 //! Sets the height of color bar.
b4b2ecca 189 Standard_EXPORT void SetHeight (const Standard_Integer theHeight);
190
42cf5bc1 191 //! Returns the position of color scale.
192 Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
7a324550 193
42cf5bc1 194 //! Returns the X position of color scale.
b4b2ecca 195 Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
7a324550 196
42cf5bc1 197 //! Returns the height of color scale.
b4b2ecca 198 Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
7a324550 199
42cf5bc1 200 //! Sets the position of color scale.
b4b2ecca 201 Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
7a324550 202
42cf5bc1 203 //! Sets the X position of color scale.
b4b2ecca 204 Standard_EXPORT void SetXPosition (const Standard_Integer theX);
7a324550 205
42cf5bc1 206 //! Sets the Y position of color scale.
b4b2ecca 207 Standard_EXPORT void SetYPosition (const Standard_Integer theY);
7a324550 208
42cf5bc1 209 //! Returns the height of text of color scale.
7a324550 210 Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
211
42cf5bc1 212 //! Sets the height of text of color scale.
7a324550 213 Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
214
42cf5bc1 215 //! Returns the width of text.
216 //! @param theText [in] the text of which to calculate width.
7a324550 217 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
218
42cf5bc1 219 //! Returns the height of text.
220 //! @param theText [in] the text of which to calculate height.
7a324550 221 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
42cf5bc1 222
7a324550 223 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
42cf5bc1 224
225
92efcf78 226 DEFINE_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject)
42cf5bc1 227
228protected:
229
7a324550 230 //! Draws a frame.
231 //! @param theX [in] the X coordinate of frame position.
232 //! @param theY [in] the Y coordinate of frame position.
233 //! @param theWidth [in] the width of frame.
234 //! @param theHeight [in] the height of frame.
235 //! @param theColor [in] the color of frame.
7c65581d 236 Standard_EXPORT void drawFrame (const Handle(Prs3d_Presentation)& thePresentation,
7a324550 237 const Standard_Integer theX, const Standard_Integer theY,
238 const Standard_Integer theWidth, const Standard_Integer theHeight,
239 const Quantity_Color& theColor);
240
241 //! Draws a text.
242 //! @param theText [in] the text to draw.
243 //! @param theX [in] the X coordinate of text position.
244 //! @param theY [in] the Y coordinate of text position.
245 //! @param theColor [in] the color of text.
7c65581d 246 Standard_EXPORT void drawText (const Handle(Prs3d_Presentation)& thePresentation,
7a324550 247 const TCollection_ExtendedString& theText,
248 const Standard_Integer theX, const Standard_Integer theY,
249 const Quantity_Color& theColor);
250
251private:
252
42cf5bc1 253 //! Returns the size of color scale.
254 //! @param theWidth [out] the width of color scale.
255 //! @param theHeight [out] the height of color scale.
7a324550 256 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
42cf5bc1 257
7a324550 258 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
259 const Handle(Prs3d_Presentation)& thePresentation,
79104795 260 const Standard_Integer theMode) Standard_OVERRIDE;
42cf5bc1 261
7a324550 262 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
79104795 263 const Standard_Integer /*aMode*/) Standard_OVERRIDE
264 {}
42cf5bc1 265
42cf5bc1 266 //! Returns the format of text.
7a324550 267 TCollection_AsciiString Format() const;
268
180f89a2 269 //! Returns the upper value of given interval, or minimum for theIndex = 0.
270 Standard_Real GetIntervalValue (const Standard_Integer theIndex) const;
7a324550 271
42cf5bc1 272 //! Returns the color's hue for the given value in the given interval.
273 //! @param theValue [in] the current value of interval.
274 //! @param theMin [in] the min value of interval.
275 //! @param theMax [in] the max value of interval.
24a88697 276 static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax);
7a324550 277
278private:
42cf5bc1 279
280 Standard_Real myMin;
281 Standard_Real myMax;
282 TCollection_ExtendedString myTitle;
283 TCollection_AsciiString myFormat;
d5514578 284 Standard_Integer myInterval; //! Number of intervals
42cf5bc1 285 Aspect_TypeOfColorScaleData myColorType;
286 Aspect_TypeOfColorScaleData myLabelType;
287 Standard_Boolean myAtBorder;
288 Standard_Boolean myReversed;
24a88697 289 Standard_Boolean myIsLogarithmic;
d5514578 290 Aspect_SequenceOfColor myColors; //! Sequence of custom colors
42cf5bc1 291 TColStd_SequenceOfExtendedString myLabels;
292 Aspect_TypeOfColorScalePosition myLabelPos;
293 Aspect_TypeOfColorScalePosition myTitlePos;
b4b2ecca 294 Standard_Integer myXPos;
295 Standard_Integer myYPos;
180f89a2 296 Standard_Integer myBreadth;
b4b2ecca 297 Standard_Integer myHeight;
42cf5bc1 298 Standard_Integer myTextHeight;
b4b2ecca 299 Quantity_Color myBgColor;
42cf5bc1 300};
7a324550 301#endif