| 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_SOFCCOLORGRADIENT_H |
| 24 |
#define GUI_SOFCCOLORGRADIENT_H |
| 25 |
|
| 26 |
#include <vector> |
| 27 |
#include <Inventor/SbBox2f.h> |
| 28 |
#include <Inventor/nodes/SoSeparator.h> |
| 29 |
|
| 30 |
#include "SoFCColorBar.h" |
| 31 |
|
| 32 |
|
| 33 |
class SoCoordinate3; |
| 34 |
class SoIndexedFaceSet; |
| 35 |
class SoMaterial; |
| 36 |
class SoMaterialBinding; |
| 37 |
class SoMFString; |
| 38 |
class SoTransparencyType; |
| 39 |
class SbVec2s; |
| 40 |
|
| 41 |
namespace Gui |
| 42 |
{ |
| 43 |
|
| 44 |
class GuiExport SoFCColorGradient: public SoFCColorBarBase |
| 45 |
{ |
| 46 |
using inherited = SoFCColorBarBase; |
| 47 |
|
| 48 |
SO_NODE_HEADER(Gui::SoFCColorGradient); |
| 49 |
|
| 50 |
public: |
| 51 |
static void initClass(); |
| 52 |
static void finish(); |
| 53 |
SoFCColorGradient(); |
| 54 |
|
| 55 |
/** |
| 56 |
* Sets the range of the colorbar from the maximum \a fMax to the minimum \a fMin. |
| 57 |
* \a prec indicates the post decimal positions, \a prec should be in between 0 and 6. |
| 58 |
*/ |
| 59 |
void setRange(float fMin, float fMax, int prec = 3) override; |
| 60 |
/** |
| 61 |
* Returns the associated color to the value \a fVal. |
| 62 |
*/ |
| 63 |
Base::Color getColor(float fVal) const override |
| 64 |
{ |
| 65 |
return _cColGrad.getColor(fVal); |
| 66 |
} |
| 67 |
void setOutsideGrayed(bool bVal) override |
| 68 |
{ |
| 69 |
_cColGrad.setOutsideGrayed(bVal); |
| 70 |
} |
| 71 |
/** |
| 72 |
* Returns always true if the gradient is in mode to show colors to arbitrary values of \a fVal, |
| 73 |
* otherwise true is returned if \a fVal is within the specified parameter range, if not false |
| 74 |
* is returned. |
| 75 |
*/ |
| 76 |
bool isVisible(float fVal) const override; |
| 77 |
/** Returns the current minimum of the parameter range. */ |
| 78 |
float getMinValue() const override |
| 79 |
{ |
| 80 |
return _cColGrad.getMinValue(); |
| 81 |
} |
| 82 |
/** Returns the current maximum of the parameter range. */ |
| 83 |
float getMaxValue() const override |
| 84 |
{ |
| 85 |
return _cColGrad.getMaxValue(); |
| 86 |
} |
| 87 |
/** |
| 88 |
* Opens a dialog to customize the current settings of the color gradient bar. |
| 89 |
*/ |
| 90 |
void customize(SoFCColorBarBase*) override; |
| 91 |
/** Returns the name of the color bar. */ |
| 92 |
const char* getColorBarName() const override; |
| 93 |
|
| 94 |
protected: |
| 95 |
void applyFormat(const SoLabelTextFormat& fmt) override; |
| 96 |
/** |
| 97 |
* Sets the current viewer size this color gradient is embedded into, to recalculate its new |
| 98 |
* position. |
| 99 |
*/ |
| 100 |
void setViewportSize(const SbVec2s& size) override; |
| 101 |
|
| 102 |
~SoFCColorGradient() override; |
| 103 |
/** |
| 104 |
* Sets the color model of the underlying color gradient to \a index. |
| 105 |
*/ |
| 106 |
void setColorModel(std::size_t index); |
| 107 |
/** |
| 108 |
* Sets the color style of the underlying color gradient to \a tStyle. \a tStyle either can |
| 109 |
* be \c FLOW or \c ZERO_BASED |
| 110 |
*/ |
| 111 |
void setColorStyle(App::ColorBarStyle tStyle); |
| 112 |
/** Rebuild the gradient bar. */ |
| 113 |
void rebuildGradient(); |
| 114 |
/** Returns a list of \a count labels within the range [\a fMin, \a fMax]. */ |
| 115 |
std::vector<float> getMarkerValues(float fMin, float fMax, int count) const; |
| 116 |
|
| 117 |
private: |
| 118 |
bool isZeroBased(float fMin, float fMax) const; |
| 119 |
/** Sets the new labels. */ |
| 120 |
int getNumColors() const; |
| 121 |
void setMarkerLabel(const SoMFString& label); |
| 122 |
void modifyPoints(const SbBox2f&); |
| 123 |
void setCoordSize(int numPoints); |
| 124 |
SoIndexedFaceSet* createFaceSet(int numFaces) const; |
| 125 |
SoTransparencyType* createTransparencyType() const; |
| 126 |
SoMaterial* createMaterial() const; |
| 127 |
SoMaterialBinding* createMaterialBinding() const; |
| 128 |
|
| 129 |
private: |
| 130 |
SoCoordinate3* coords; |
| 131 |
SoSeparator* labels; |
| 132 |
SbBox2f _bbox; |
| 133 |
int _precision {3}; |
| 134 |
App::ColorGradient _cColGrad; |
| 135 |
}; |
| 136 |
|
| 137 |
} // namespace Gui |
| 138 |
|
| 139 |
|
| 140 |
#endif // GUI_SOFCCOLORGRADIENT_H |