1 // Created on: 2015-02-03
2 // Copyright (c) 2015 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _AIS_ColorScale_HeaderFile
16 #define _AIS_ColorScale_HeaderFile
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>
27 //! Class for drawing a custom color scale.
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.
37 class AIS_ColorScale : public AIS_InteractiveObject {
41 //! Default constructor.
42 Standard_EXPORT AIS_ColorScale();
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;
47 //! Calculate color according passed value; returns true if value is in range or false, if isn't
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);
50 //! Returns minimal value of color scale;
51 Standard_EXPORT Standard_Real GetMin() const { return myMin; }
53 //! Returns maximal value of color scale;
54 Standard_EXPORT Standard_Real GetMax() const { return myMax; }
56 //! Returns minimal and maximal values of color scale;
57 Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
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
62 Standard_EXPORT Aspect_TypeOfColorScaleData GetLabelType() const { return myLabelType; }
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
67 Standard_EXPORT Aspect_TypeOfColorScaleData GetColorType() const { return myColorType; }
69 //! Returns the number of color scale intervals;
70 Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; }
72 //! Returns the color scale title string;
73 Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; }
75 //! Returns the format for numbers.
76 //! The same like format for function printf().
77 //! Used if GetLabelType() is TOCSD_AUTO;
78 Standard_EXPORT TCollection_AsciiString GetFormat() const { return myFormat; }
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.
83 //! Returns empty string if label not defined.
84 Standard_EXPORT TCollection_ExtendedString GetLabel (const Standard_Integer theIndex) const;
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;
90 //! Returns the user specified labels.
91 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
93 //! Returns the user specified colors.
94 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
96 //! Returns the position of labels concerning color filled rectangles.
97 Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
99 //! Returns the position of color scale title.
100 Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
102 //! Returns true if the labels and colors used in reversed order.
103 Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
105 //! Returns true if the labels are placed at border of color intervals.
106 Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
108 //! Returns true if the color scale has logarithmic intervals
109 Standard_Boolean IsLogarithmic() const { return myIsLogarithmic; }
111 //! Sets the minimal value of color scale.
112 Standard_EXPORT void SetMin (const Standard_Real theMin);
114 //! Sets the maximal value of color scale.
115 Standard_EXPORT void SetMax (const Standard_Real theMax);
117 //! Sets the minimal and maximal value of color scale.
118 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
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);
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);
130 //! Sets the number of color scale intervals.
131 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
133 //! Sets the color scale title string.
134 Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
136 //! Sets the color scale auto label format specification.
137 Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
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);
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);
148 //! Sets the color scale labels.
149 //! The length of the sequence should be equal to GetNumberOfIntervals() or to
150 //! GetNumberOfIntervals() + 1 if IsLabelAtBorder() is true.
151 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
153 //! Sets the color scale colors.
154 //! The length of the sequence should be equal to GetNumberOfIntervals().
155 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
157 //! Sets the color scale labels position relative to color bar.
158 Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
160 //! Sets the color scale title position.
161 Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
163 //! Sets true if the labels and colors used in reversed order.
164 Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
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.
168 Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
170 //! Sets true if the color scale has logarithmic intervals.
171 void SetLogarithmic (const Standard_Boolean isLogarithmic) { myIsLogarithmic = isLogarithmic; };
173 //! Returns the size of color bar.
174 Standard_EXPORT void GetSize (Standard_Integer& theBreadth, Standard_Integer& theHeight) const;
176 //! Returns the breadth of color bar.
177 Standard_EXPORT Standard_Integer GetBreadth() const { return myBreadth; }
179 //! Returns the height of color bar.
180 Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; }
182 //! Sets the size of color bar.
183 Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
185 //! Sets the width of color bar.
186 Standard_EXPORT void SetBreadth (const Standard_Integer theBreadth);
188 //! Sets the height of color bar.
189 Standard_EXPORT void SetHeight (const Standard_Integer theHeight);
191 //! Returns the position of color scale.
192 Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
194 //! Returns the X position of color scale.
195 Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
197 //! Returns the height of color scale.
198 Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
200 //! Sets the position of color scale.
201 Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
203 //! Sets the X position of color scale.
204 Standard_EXPORT void SetXPosition (const Standard_Integer theX);
206 //! Sets the Y position of color scale.
207 Standard_EXPORT void SetYPosition (const Standard_Integer theY);
209 //! Returns the height of text of color scale.
210 Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
212 //! Sets the height of text of color scale.
213 Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
215 //! Returns the width of text.
216 //! @param theText [in] the text of which to calculate width.
217 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
219 //! Returns the height of text.
220 //! @param theText [in] the text of which to calculate height.
221 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
223 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
226 DEFINE_STANDARD_RTTIEXT(AIS_ColorScale,AIS_InteractiveObject)
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.
236 Standard_EXPORT void drawFrame (const Handle(Prs3d_Presentation)& thePresentation,
237 const Standard_Integer theX, const Standard_Integer theY,
238 const Standard_Integer theWidth, const Standard_Integer theHeight,
239 const Quantity_Color& theColor);
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.
246 Standard_EXPORT void drawText (const Handle(Prs3d_Presentation)& thePresentation,
247 const TCollection_ExtendedString& theText,
248 const Standard_Integer theX, const Standard_Integer theY,
249 const Quantity_Color& theColor);
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.
256 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
258 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
259 const Handle(Prs3d_Presentation)& thePresentation,
260 const Standard_Integer theMode) Standard_OVERRIDE;
262 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
263 const Standard_Integer /*aMode*/) Standard_OVERRIDE
266 //! Returns the format of text.
267 TCollection_AsciiString Format() const;
269 //! Returns the upper value of given interval, or minimum for theIndex = 0.
270 Standard_Real GetIntervalValue (const Standard_Integer theIndex) const;
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.
276 static Standard_Integer HueFromValue (const Standard_Integer theValue, const Standard_Integer theMin, const Standard_Integer theMax);
282 TCollection_ExtendedString myTitle;
283 TCollection_AsciiString myFormat;
284 Standard_Integer myInterval; //! Number of intervals
285 Aspect_TypeOfColorScaleData myColorType;
286 Aspect_TypeOfColorScaleData myLabelType;
287 Standard_Boolean myAtBorder;
288 Standard_Boolean myReversed;
289 Standard_Boolean myIsLogarithmic;
290 Aspect_SequenceOfColor myColors; //! Sequence of custom colors
291 TColStd_SequenceOfExtendedString myLabels;
292 Aspect_TypeOfColorScalePosition myLabelPos;
293 Aspect_TypeOfColorScalePosition myTitlePos;
294 Standard_Integer myXPos;
295 Standard_Integer myYPos;
296 Standard_Integer myBreadth;
297 Standard_Integer myHeight;
298 Standard_Integer myTextHeight;
299 Quantity_Color myBgColor;