0025785: Visualization - introduce AIS_ColorScale presentation for Color Scale
[occt.git] / src / AIS / AIS_ColorScale.hxx
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
29 class AIS_ColorScale : public AIS_InteractiveObject {
30
31 public:
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   //! Sets the minimal value of color scale.
98   Standard_EXPORT void SetMin (const Standard_Real theMin);
99
100   //! Sets the maximal value of color scale.
101   Standard_EXPORT void SetMax (const Standard_Real theMax);
102
103   //! Sets the minimal and maximal value of color scale.
104   Standard_EXPORT void SetRange (const Standard_Real theMin, const Standard_Real theMax);
105
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);
110
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);
115
116   //! Sets the number of color scale intervals.
117   Standard_EXPORT void SetNumberOfIntervals (const Standard_Integer theNum);
118
119   //! Sets the color scale title string.
120   Standard_EXPORT void SetTitle (const TCollection_ExtendedString& theTitle);
121
122   //! Sets the color scale auto label format specification.
123   Standard_EXPORT void SetFormat (const TCollection_AsciiString& theFormat);
124
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);
127
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);
130
131   //! Sets the color scale labels.
132   Standard_EXPORT void SetLabels (const TColStd_SequenceOfExtendedString& theSeq);
133
134   //! Sets the color scale colors.
135   Standard_EXPORT void SetColors (const Aspect_SequenceOfColor& theSeq);
136
137   //! Sets the color scale labels position concerning color filled rectangles.
138   Standard_EXPORT void SetLabelPosition (const Aspect_TypeOfColorScalePosition thePos);
139
140   //! Sets the color scale title position.
141   Standard_EXPORT void SetTitlePosition (const Aspect_TypeOfColorScalePosition thePos);
142
143   //! Sets true if the labels and colors used in reversed order.
144   Standard_EXPORT void SetReversed (const Standard_Boolean theReverse);
145
146   //! Sets true if the labels placed at border of color filled rectangles.
147   Standard_EXPORT void SetLabelAtBorder (const Standard_Boolean theOn);
148
149   //! Returns the size of color scale.
150   Standard_EXPORT void GetSize (Standard_Real& theWidth, Standard_Real& theHeight) const;
151
152   //! Returns the width of color scale.
153   Standard_EXPORT Standard_Real GetWidth() const { return myWidth; }
154
155   //! Returns the height of color scale.
156   Standard_EXPORT Standard_Real GetHeight() const { return myHeight; }
157
158   //! Sets the size of color scale.
159   Standard_EXPORT void SetSize (const Standard_Real theWidth, const Standard_Real theHeight);
160
161   //! Sets the width of color scale.
162   Standard_EXPORT void SetWidth (const Standard_Real theWidth);
163
164   //! Sets the height of color scale.
165   Standard_EXPORT void SetHeight (const Standard_Real theHeight);
166
167   //! Returns the position of color scale.
168   Standard_EXPORT void GetPosition (Standard_Real& theX, Standard_Real& theY) const;
169
170   //! Returns the X position of color scale.
171   Standard_EXPORT Standard_Real GetXPosition() const { return myXPos; }
172
173   //! Returns the height of color scale.
174   Standard_EXPORT Standard_Real GetYPosition() const { return myYPos; }
175
176   //! Sets the position of color scale.
177   Standard_EXPORT void SetPosition (const Standard_Real theX, const Standard_Real theY);
178
179   //! Sets the X position of color scale.
180   Standard_EXPORT void SetXPosition (const Standard_Real theX);
181
182   //! Sets the Y position of color scale.
183   Standard_EXPORT void SetYPosition (const Standard_Real theY);
184
185   //! Returns the height of text of color scale.
186   Standard_EXPORT Standard_Integer GetTextHeight() const { return myTextHeight; }
187
188   //! Sets the height of text of color scale.
189   Standard_EXPORT void SetTextHeight (const Standard_Integer theHeight) { myTextHeight = theHeight; }
190
191   //! Returns the width of text.
192   //! @param theText [in] the text of which to calculate width.
193   Standard_EXPORT Standard_Integer TextWidth (const TCollection_ExtendedString& theText) const;
194
195   //! Returns the height of text.
196   //! @param theText [in] the text of which to calculate height.
197   Standard_EXPORT Standard_Integer TextHeight (const TCollection_ExtendedString& theText) const;
198
199   Standard_EXPORT void TextSize (const TCollection_ExtendedString& theText, const Standard_Integer theHeight, Standard_Integer& theWidth, Standard_Integer& theAscent, Standard_Integer& theDescent) const;
200
201
202   DEFINE_STANDARD_RTTI(AIS_ColorScale,AIS_InteractiveObject)
203
204 protected:
205
206   //! Draws a frame.
207   //! @param theX [in] the X coordinate of frame position.
208   //! @param theY [in] the Y coordinate of frame position.
209   //! @param theWidth [in] the width of frame.
210   //! @param theHeight [in] the height of frame.
211   //! @param theColor [in] the color of frame.
212   Standard_EXPORT void DrawFrame (const Handle(Prs3d_Presentation)& thePresentation,
213                        const Standard_Integer theX, const Standard_Integer theY,
214                        const Standard_Integer theWidth, const Standard_Integer theHeight,
215                        const Quantity_Color& theColor);
216
217   //! Draws a text.
218   //! @param theText [in] the text to draw.
219   //! @param theX [in] the X coordinate of text position.
220   //! @param theY [in] the Y coordinate of text position.
221   //! @param theColor [in] the color of text.
222   Standard_EXPORT void DrawText (const Handle(Prs3d_Presentation)& thePresentation,
223                   const TCollection_ExtendedString& theText,
224                   const Standard_Integer theX, const Standard_Integer theY,
225                   const Quantity_Color& theColor);
226
227 private:
228
229   //! Returns the size of color scale.
230   //! @param theWidth [out] the width of color scale.
231   //! @param theHeight [out] the height of color scale.
232   void SizeHint (Standard_Integer& theWidth, Standard_Integer& theHeight) const;
233
234   void Compute (const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
235                   const Handle(Prs3d_Presentation)& thePresentation,
236                   const Standard_Integer theMode);
237
238   void ComputeSelection (const Handle(SelectMgr_Selection)& /*aSelection*/,
239                            const Standard_Integer /*aMode*/){};
240
241   //! Returns the format of text.
242   TCollection_AsciiString Format() const;
243
244   //! Returns the value of given interval.
245   Standard_Real GetNumber (const Standard_Integer anIndex) const;
246
247   //! Returns the color's hue for the given value in the given interval.
248   //! @param theValue [in] the current value of interval.
249   //! @param theMin [in] the min value of interval.
250   //! @param theMax [in] the max value of interval.
251   static Standard_Integer HueFromValue (const Standard_Integer aValue, const Standard_Integer aMin, const Standard_Integer aMax);
252
253 private:
254
255   Standard_Real myMin;
256   Standard_Real myMax;
257   TCollection_ExtendedString myTitle;
258   TCollection_AsciiString myFormat;
259   Standard_Integer myInterval;
260   Aspect_TypeOfColorScaleData myColorType;
261   Aspect_TypeOfColorScaleData myLabelType;
262   Standard_Boolean myAtBorder;
263   Standard_Boolean myReversed;
264   Aspect_SequenceOfColor myColors;
265   TColStd_SequenceOfExtendedString myLabels;
266   Aspect_TypeOfColorScalePosition myLabelPos;
267   Aspect_TypeOfColorScalePosition myTitlePos;
268   Standard_Real myXPos;
269   Standard_Real myYPos;
270   Standard_Real myWidth;
271   Standard_Real myHeight;
272   Standard_Integer myTextHeight;
273 };
274 #endif