App/Gui: make color bar to handle very small values
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#endif
|
||||
|
||||
#include "ColorModel.h"
|
||||
#include <Base/Exception.h>
|
||||
|
||||
using namespace App;
|
||||
|
||||
@@ -107,7 +108,10 @@ void ColorField::set (const ColorModel &rclModel, float fMin, float fMax, std::s
|
||||
{
|
||||
colorModel = rclModel;
|
||||
this->fMin = std::min<float>(fMin, fMax);
|
||||
this->fMax = std::max<float>(this->fMin + CCR_EPS, fMax);
|
||||
this->fMax = std::max<float>(fMin, fMax);
|
||||
if (this->fMax <= this->fMin) {
|
||||
throw Base::ValueError("Maximum must be higher than minimum");
|
||||
}
|
||||
ctColors = std::max<std::size_t>(usCt, colorModel.getCountColors());
|
||||
rebuild();
|
||||
}
|
||||
@@ -206,7 +210,10 @@ std::vector<std::string> ColorGradient::getColorModelNames() const
|
||||
void ColorGradient::set (float fMin, float fMax, std::size_t usCt, TStyle tS, bool bOG)
|
||||
{
|
||||
_fMin = std::min<float>(fMin, fMax);
|
||||
_fMax = std::max<float>(_fMin + CCR_EPS, fMax);
|
||||
_fMax = std::max<float>(fMin, fMax);
|
||||
if (_fMax <= _fMin) {
|
||||
throw Base::ValueError("Maximum must be higher than minimum");
|
||||
}
|
||||
ctColors = std::max<std::size_t>(usCt, getMinColors());
|
||||
tStyle = tS;
|
||||
outsideGrayed = bOG;
|
||||
|
||||
@@ -31,8 +31,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define CCR_EPS 1.0e-5f
|
||||
|
||||
namespace App
|
||||
{
|
||||
|
||||
|
||||
@@ -122,10 +122,10 @@ bool DlgSettingsColorGradientImp::isOutInvisible() const
|
||||
void DlgSettingsColorGradientImp::setRange( float fMin, float fMax )
|
||||
{
|
||||
ui->floatLineEditMax->blockSignals(true);
|
||||
ui->floatLineEditMax->setText(QLocale().toString(fMax, 'f', numberOfDecimals()));
|
||||
ui->floatLineEditMax->setText(QLocale().toString(fMax, 'g', numberOfDecimals()));
|
||||
ui->floatLineEditMax->blockSignals(false);
|
||||
ui->floatLineEditMin->blockSignals(true);
|
||||
ui->floatLineEditMin->setText(QLocale().toString(fMin, 'f', numberOfDecimals()));
|
||||
ui->floatLineEditMin->setText(QLocale().toString(fMin, 'g', numberOfDecimals()));
|
||||
ui->floatLineEditMin->blockSignals(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -175,25 +175,24 @@ void SoFCColorGradient::setViewportSize( const SbVec2s& size )
|
||||
}
|
||||
}
|
||||
|
||||
void SoFCColorGradient::setRange( float fMin, float fMax, int prec )
|
||||
void SoFCColorGradient::setRange(float fMin, float fMax, int prec)
|
||||
{
|
||||
_cColGrad.setRange(fMin, fMax);
|
||||
|
||||
SoMFString label;
|
||||
|
||||
float fFac = (float)pow(10.0, (double)prec);
|
||||
float eps = std::pow(10.0f, static_cast<float>(-prec));
|
||||
float value = std::min<float>(fabs(fMin), fabs(fMax));
|
||||
std::ios::fmtflags flags = value < eps ? (std::ios::scientific | std::ios::showpoint | std::ios::showpos)
|
||||
: (std::ios::fixed | std::ios::showpoint | std::ios::showpos);
|
||||
|
||||
int i=0;
|
||||
std::vector<float> marks = getMarkerValues(fMin, fMax, _cColGrad.getCountColors());
|
||||
for ( std::vector<float>::iterator it = marks.begin(); it != marks.end(); ++it )
|
||||
{
|
||||
for (const auto& it : marks) {
|
||||
std::stringstream s;
|
||||
s.precision(prec);
|
||||
s.setf(std::ios::fixed | std::ios::showpoint | std::ios::showpos);
|
||||
float fValue = *it;
|
||||
if ( fabs(fValue*fFac) < 1.0 )
|
||||
fValue = 0.0f;
|
||||
s << fValue;
|
||||
s.setf(flags);
|
||||
s << it;
|
||||
label.set1Value(i++, s.str().c_str());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user