Debian Codegraph @

src/Gui/SoFCColorLegend.h

raw
1 /***************************************************************************
2 * Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_SOFCCOLORLEGEND_H
24 #define GUI_SOFCCOLORLEGEND_H
25
26 #include <Inventor/SbBox2f.h>
27 #include <Inventor/nodes/SoSeparator.h>
28
29 #include "SoFCColorBar.h"
30
31
32 class SoCoordinate3;
33 class SoMFString;
34 class SbVec2s;
35
36 namespace Gui
37 {
38
39 class GuiExport SoFCColorLegend: public SoFCColorBarBase
40 {
41 using inherited = SoFCColorBarBase;
42
43 SO_NODE_HEADER(Gui::SoFCColorLegend);
44
45 public:
46 static void initClass();
47 static void finish();
48 SoFCColorLegend();
49
50 void setLegendLabels(const App::ColorLegend& legend, int prec = 3);
51
52 /**
53 * Sets the range of the colorbar from the maximum \a fMax to the minimum \a fMin.
54 * \a prec indicates the post decimal positions, \a prec should be in between 0 and 6.
55 */
56 void setRange(float fMin, float fMax, int prec = 3) override;
57 /**
58 * Updates the node with the given color legend.
59 */
60 void setColorLegend(const App::ColorLegend& legend);
61
62 unsigned short getColorIndex(float fVal) const
63 {
64 return _currentLegend.getColorIndex(fVal);
65 }
66 Base::Color getColor(float fVal) const override
67 {
68 return _currentLegend.getColor(fVal);
69 }
70 void setOutsideGrayed(bool bVal) override
71 {
72 _currentLegend.setOutsideGrayed(bVal);
73 }
74 bool isVisible(float) const override
75 {
76 return false;
77 }
78 float getMinValue() const override
79 {
80 return _currentLegend.getMinValue();
81 }
82 float getMaxValue() const override
83 {
84 return _currentLegend.getMaxValue();
85 }
86 std::size_t countColors() const
87 {
88 return _currentLegend.hasNumberOfFields();
89 }
90
91 void customize(SoFCColorBarBase*) override
92 {}
93 const char* getColorBarName() const override;
94
95 // virtual void handleEvent(SoHandleEventAction * action);
96 // virtual void GLRenderBelowPath(SoGLRenderAction * action);
97 // virtual void GLRenderInPath(SoGLRenderAction * action);
98
99 protected:
100 void setViewportSize(const SbVec2s& size) override;
101 ~SoFCColorLegend() override;
102 // virtual void redrawHighlighted(SoAction * act, SbBool flag);
103 private:
104 void setMarkerLabel(const SoMFString& label);
105 void setMarkerValue(const SoMFString& value);
106 void modifyPoints(const SbBox2f&);
107 void arrangeLabels(const SbBox2f&);
108 void arrangeValues(const SbBox2f&);
109
110 private:
111 SoCoordinate3* coords;
112 SoSeparator* labelGroup;
113 SoSeparator* valueGroup;
114 SbBox2f _bbox;
115 App::ColorLegend _currentLegend;
116 };
117
118 } // namespace Gui
119
120
121 #endif // GUI_SOFCCOLORLEGEND_H