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>
28 //! Class for drawing a custom color scale
29 class AIS_ColorScale : public AIS_InteractiveObject {
33 //! Default constructor.
34 Standard_EXPORT AIS_ColorScale();
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;
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);
41 //! Returns minimal value of color scale;
42 Standard_EXPORT Standard_Real GetMin() const { return myMin; }
44 //! Returns maximal value of color scale;
45 Standard_EXPORT Standard_Real GetMax() const { return myMax; }
47 //! Returns minimal and maximal values of color scale;
48 Standard_EXPORT void GetRange (Standard_Real& theMin, Standard_Real& theMax) const;
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; }
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; }
60 //! Returns the number of color scale intervals;
61 Standard_EXPORT Standard_Integer GetNumberOfIntervals() const { return myInterval; }
63 //! Returns the color scale title string;
64 Standard_EXPORT TCollection_ExtendedString GetTitle() const { return myTitle; }
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; }
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;
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;
79 //! Returns the user specified labels.
80 Standard_EXPORT void GetLabels (TColStd_SequenceOfExtendedString& theLabels) const;
82 //! Returns the user specified colors.
83 Standard_EXPORT void GetColors (Aspect_SequenceOfColor& theColors) const;
85 //! Returns the position of labels concerning color filled rectangles.
86 Standard_EXPORT Aspect_TypeOfColorScalePosition GetLabelPosition() const { return myLabelPos; }
88 //! Returns the position of color scale title.
89 Standard_EXPORT Aspect_TypeOfColorScalePosition GetTitlePosition() const { return myTitlePos; }
91 //! Returns true if the labels and colors used in reversed order.
92 Standard_EXPORT Standard_Boolean IsReversed() const { return myReversed; }
94 //! Returns true if the labels placed at border of color filled rectangles.
95 Standard_EXPORT Standard_Boolean IsLabelAtBorder() const { return myAtBorder; }
97 //! Sets the minimal value of color scale.
98 Standard_EXPORT void SetMin (const Standard_Real theMin);
100 //! Sets the maximal value of color scale.
101 Standard_EXPORT void SetMax (const Standard_Real theMax);
103 //! Sets the minimal and maximal value of color scale.
104 Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
106 //! Sets the type of labels.
107 //! Aspect_TOCSD_AUTO - labels as boundary values for intervals
108 //! Aspect_TOCSD_USER - user specified label is used
109 Standard_EXPORT void SetLabelType (const Aspect_TypeOfColorScaleData theType);
111 //! Sets the type of colors.
112 //! Aspect_TOCSD_AUTO - value between Red and Blue
113 //! Aspect_TOCSD_USER - user specified color from color map
114 Standard_EXPORT void SetColorType (const Aspect_TypeOfColorScaleData theType);
116 //! Sets the number of color scale intervals.
117 Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
119 //! Sets the color scale title string.
120 Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
122 //! Sets the color scale auto label format specification.
123 Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
125 //! Sets the color scale label at index. Index started from 1.
126 Standard_EXPORT void SetLabel (const TCollection_ExtendedString& theLabel, const Standard_Integer anIndex = -1);
128 //! Sets the color scale color at index. Index started from 1.
129 Standard_EXPORT void SetColor (const Quantity_Color& theColor, const Standard_Integer theIndex = -1);
131 //! Sets the color scale labels.
132 Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
134 //! Sets the color scale colors.
135 Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
137 //! Sets the color scale labels position concerning color filled rectangles.
138 Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
140 //! Sets the color scale title position.
141 Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
143 //! Sets true if the labels and colors used in reversed order.
144 Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
146 //! Sets true if the labels placed at border of color filled rectangles.
147 Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
149 //! Returns the size of color scale.
150 Standard_EXPORT void GetSize (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
152 //! Returns the width of color scale.
153 Standard_EXPORT Standard_Integer GetWidth() const { return myWidth; }
155 //! Returns the height of color scale.
156 Standard_EXPORT Standard_Integer GetHeight() const { return myHeight; }
158 //! Returns the background color of color scale.
159 const Quantity_Color& GetBgColor() const { return myBgColor; }
161 //! Sets the size of color scale.
162 Standard_EXPORT void SetSize (const Standard_Integer theWidth, const Standard_Integer theHeight);
164 //! Sets the width of color scale.
165 Standard_EXPORT void SetWidth (const Standard_Integer theWidth);
167 //! Sets the height of color scale.
168 Standard_EXPORT void SetHeight (const Standard_Integer theHeight);
170 //! Sets the background color of color scale.
171 void SetBGColor (const Quantity_Color& theBgColor) { myBgColor = theBgColor; };
173 //! Returns the position of color scale.
174 Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
176 //! Returns the X position of color scale.
177 Standard_EXPORT Standard_Integer GetXPosition() const { return myXPos; }
179 //! Returns the height of color scale.
180 Standard_EXPORT Standard_Integer GetYPosition() const { return myYPos; }
182 //! Sets the position of color scale.
183 Standard_EXPORT void SetPosition (const Standard_Integer theX, const Standard_Integer theY);
185 //! Sets the X position of color scale.
186 Standard_EXPORT void SetXPosition (const Standard_Integer theX);
188 //! Sets the Y position of color scale.
189 Standard_EXPORT void SetYPosition (const Standard_Integer theY);
191 //! Returns the height of text of color scale.
192 Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
194 //! Sets the height of text of color scale.
195 Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
197 //! Returns the width of text.
198 //! @param theText [in] the text of which to calculate width.
199 Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
201 //! Returns the height of text.
202 //! @param theText [in] the text of which to calculate height.
203 Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
205 Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
208 DEFINE_STANDARD_RTTI(AIS_ColorScale,AIS_InteractiveObject)
213 //! @param theX [in] the X coordinate of frame position.
214 //! @param theY [in] the Y coordinate of frame position.
215 //! @param theWidth [in] the width of frame.
216 //! @param theHeight [in] the height of frame.
217 //! @param theColor [in] the color of frame.
218 Standard_EXPORT void DrawFrame (const Handle(Prs3d_Presentation)& thePresentation,
219 const Standard_Integer theX, const Standard_Integer theY,
220 const Standard_Integer theWidth, const Standard_Integer theHeight,
221 const Quantity_Color& theColor);
224 //! @param theText [in] the text to draw.
225 //! @param theX [in] the X coordinate of text position.
226 //! @param theY [in] the Y coordinate of text position.
227 //! @param theColor [in] the color of text.
228 Standard_EXPORT void DrawText (const Handle(Prs3d_Presentation)& thePresentation,
229 const TCollection_ExtendedString& theText,
230 const Standard_Integer theX, const Standard_Integer theY,
231 const Quantity_Color& theColor);
235 //! Returns the size of color scale.
236 //! @param theWidth [out] the width of color scale.
237 //! @param theHeight [out] the height of color scale.
238 void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
240 void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
241 const Handle(Prs3d_Presentation)& thePresentation,
242 const Standard_Integer theMode);
244 void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
245 const Standard_Integer /*aMode*/){};
247 //! Returns the format of text.
248 TCollection_AsciiString Format() const;
250 //! Returns the value of given interval.
251 Standard_Real GetNumber (const Standard_Integer anIndex) const;
253 //! Returns the color's hue for the given value in the given interval.
254 //! @param theValue [in] the current value of interval.
255 //! @param theMin [in] the min value of interval.
256 //! @param theMax [in] the max value of interval.
257 static Standard_Integer HueFromValue (const Standard_Integer aValue, const Standard_Integer aMin, const Standard_Integer aMax);
263 TCollection_ExtendedString myTitle;
264 TCollection_AsciiString myFormat;
265 Standard_Integer myInterval;
266 Aspect_TypeOfColorScaleData myColorType;
267 Aspect_TypeOfColorScaleData myLabelType;
268 Standard_Boolean myAtBorder;
269 Standard_Boolean myReversed;
270 Aspect_SequenceOfColor myColors;
271 TColStd_SequenceOfExtendedString myLabels;
272 Aspect_TypeOfColorScalePosition myLabelPos;
273 Aspect_TypeOfColorScalePosition myTitlePos;
274 Standard_Integer myXPos;
275 Standard_Integer myYPos;
276 Standard_Integer myWidth;
277 Standard_Integer myHeight;
278 Standard_Integer myTextHeight;
279 Quantity_Color myBgColor;