mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-11 02:57:39 +00:00
Fix: Correct range checking for int and float Config Options + QoL changes in tooltips (#11915)
* Fix float number not working properly for option min/max (#11211) * ConfigOptionDef: min/max values type are changed from INT to FLOAT. (cherry picked from commit f277bc80c22e0c9a067481a4301922e2c96aed47) * Fix infinite loop and crash when `fuzzy_skin_point_distance` = 0 (SoftFever/OrcaSlicer#11069) * Fix Linux build issue * Fix float comparison due to precision loss * Fix: Range check added for coInt options; Ranges and defaults added in tooltips --------- Co-authored-by: Noisyfox <timemanager.rick@gmail.com> Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
@@ -318,6 +318,24 @@ ConfigOption* ConfigOptionDef::create_default_option() const
|
||||
return this->create_empty_option();
|
||||
}
|
||||
|
||||
bool ConfigOptionDef::is_value_valid(const double value, const int max_precision /*= 4*/) const
|
||||
{
|
||||
// Special handling for the nil values
|
||||
// The nil value is a valid one only for nullable options
|
||||
if (std::isnan(value))
|
||||
return this->nullable;
|
||||
|
||||
// Special handling of 0
|
||||
if (this->min == 0.f && value < 0)
|
||||
return false;
|
||||
|
||||
const double ep = std::pow(0.1, max_precision);
|
||||
if (is_approx(value, (double) this->min, ep) || is_approx(value, (double) this->max, ep))
|
||||
return true;
|
||||
|
||||
return this->min <= value && value <= this->max;
|
||||
}
|
||||
|
||||
// Assignment of the serialization IDs is not thread safe. The Defs shall be initialized from the main thread!
|
||||
ConfigOptionDef* ConfigDef::add(const t_config_option_key &opt_key, ConfigOptionType type)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <assert.h>
|
||||
#include <map>
|
||||
#include <climits>
|
||||
#include <cfloat>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
@@ -2455,10 +2456,11 @@ public:
|
||||
// Optional width of an input field.
|
||||
int width = -1;
|
||||
// <min, max> limit of a numeric input.
|
||||
// If not set, the <min, max> is set to <INT_MIN, INT_MAX>
|
||||
// If not set, the <min, max> is set to <-FLT_MAX, FLT_MAX>
|
||||
// By setting min=0, only nonnegative input is allowed.
|
||||
int min = INT_MIN;
|
||||
int max = INT_MAX;
|
||||
float min = -FLT_MAX;
|
||||
float max = FLT_MAX;
|
||||
bool is_value_valid(const double value, const int max_precision = 4) const;
|
||||
// To check if it's not a typo and a % is missing
|
||||
double max_literal = 1;
|
||||
ConfigOptionMode mode = comSimple;
|
||||
|
||||
@@ -2159,9 +2159,9 @@ void PrintConfigDef::init_fff_params()
|
||||
"You may be able to tune this value to get a nice flat surface if there is slight overflow or underflow."
|
||||
"\n\nThe final object flow ratio is this value multiplied by the filament flow ratio.");
|
||||
def->mode = comAdvanced;
|
||||
def->max = 2;
|
||||
def->min = 0.01;
|
||||
def->set_default_value(new ConfigOptionFloat(1));
|
||||
def->max = 2.f;
|
||||
def->min = 0.01f;
|
||||
def->set_default_value(new ConfigOptionFloat(1.f));
|
||||
|
||||
def = this->add("enable_pressure_advance", coBools);
|
||||
def->label = L("Enable pressure advance");
|
||||
@@ -3051,9 +3051,10 @@ void PrintConfigDef::init_fff_params()
|
||||
def->category = L("Speed");
|
||||
def->tooltip = L("Marlin Firmware Junction Deviation (replaces the traditional XY Jerk setting).");
|
||||
def->sidetext = L("mm"); // milimeters, CIS languages need translation
|
||||
def->min = 0;
|
||||
def->min = 0.f;
|
||||
def->max = 0.5f;
|
||||
def->mode = comAdvanced;
|
||||
def->set_default_value(new ConfigOptionFloat(0));
|
||||
def->set_default_value(new ConfigOptionFloat(0.f));
|
||||
|
||||
def = this->add("outer_wall_jerk", coFloat);
|
||||
def->label = L("Outer wall");
|
||||
@@ -3312,10 +3313,10 @@ void PrintConfigDef::init_fff_params()
|
||||
def->category = L("Others");
|
||||
def->tooltip = L("The average distance between the random points introduced on each line segment.");
|
||||
def->sidetext = L("mm"); // milimeters, CIS languages need translation
|
||||
def->min = 0;
|
||||
def->max = 5;
|
||||
def->min = 0.01f; // point distance cannot be 0! Otherwise we get infinite loop + OOM due to infinite line division.
|
||||
def->max = 5.f;
|
||||
def->mode = comSimple;
|
||||
def->set_default_value(new ConfigOptionFloat(0.3));
|
||||
def->set_default_value(new ConfigOptionFloat(0.3f));
|
||||
|
||||
def = this->add("fuzzy_skin_first_layer", coBool);
|
||||
def->label = L("Apply fuzzy skin to first layer");
|
||||
@@ -3375,7 +3376,7 @@ void PrintConfigDef::init_fff_params()
|
||||
def->category = L("Others");
|
||||
def->tooltip = L("The base size of the coherent noise features, in mm. Higher values will result in larger features.");
|
||||
def->sidetext = L("mm"); // milimeters, CIS languages need translation
|
||||
def->min = 0.1;
|
||||
def->min = 0.1f;
|
||||
def->max = 500;
|
||||
def->mode = comAdvanced;
|
||||
def->set_default_value(new ConfigOptionFloat(1.0));
|
||||
@@ -3393,7 +3394,7 @@ void PrintConfigDef::init_fff_params()
|
||||
def->label = L("Fuzzy skin noise persistence");
|
||||
def->category = L("Others");
|
||||
def->tooltip = L("The decay rate for higher octaves of the coherent noise. Lower values will result in smoother noise.");
|
||||
def->min = 0.01;
|
||||
def->min = 0.01f;
|
||||
def->max = 1;
|
||||
def->mode = comAdvanced;
|
||||
def->set_default_value(new ConfigOptionFloat(0.5));
|
||||
@@ -4205,10 +4206,10 @@ void PrintConfigDef::init_fff_params()
|
||||
def->category = L("Machine limits");
|
||||
def->tooltip = L("Maximum junction deviation (M205 J, only apply if JD > 0 for Marlin Firmware\nIf your Marlin 2 printer uses Classic Jerk set this value to 0.)");
|
||||
def->sidetext = L("mm"); // milimeters, CIS languages need translation
|
||||
def->min = 0;
|
||||
def->max = 1;
|
||||
def->min = 0.f;
|
||||
def->max = 0.5f;
|
||||
def->mode = comAdvanced;
|
||||
def->set_default_value(new ConfigOptionFloats { 0.01});
|
||||
def->set_default_value(new ConfigOptionFloats{ 0.01f });
|
||||
|
||||
// M205 S... [mm/sec]
|
||||
def = this->add("machine_min_extruding_rate", coFloats);
|
||||
@@ -9767,13 +9768,13 @@ std::map<std::string, std::string> validate(const FullPrintConfig &cfg, bool und
|
||||
case coFloatOrPercent:
|
||||
{
|
||||
auto *fopt = static_cast<const ConfigOptionFloat*>(opt);
|
||||
out_of_range = fopt->value < optdef->min || fopt->value > optdef->max;
|
||||
out_of_range = !optdef->is_value_valid(fopt->value);
|
||||
break;
|
||||
}
|
||||
case coFloats:
|
||||
case coPercents:
|
||||
for (double v : static_cast<const ConfigOptionVector<double>*>(opt)->values)
|
||||
if (v < optdef->min || v > optdef->max) {
|
||||
if (!optdef->is_value_valid(v)) {
|
||||
out_of_range = true;
|
||||
break;
|
||||
}
|
||||
@@ -9781,12 +9782,12 @@ std::map<std::string, std::string> validate(const FullPrintConfig &cfg, bool und
|
||||
case coInt:
|
||||
{
|
||||
auto *iopt = static_cast<const ConfigOptionInt*>(opt);
|
||||
out_of_range = iopt->value < optdef->min || iopt->value > optdef->max;
|
||||
out_of_range = !optdef->is_value_valid(iopt->value);
|
||||
break;
|
||||
}
|
||||
case coInts:
|
||||
for (int v : static_cast<const ConfigOptionVector<int>*>(opt)->values)
|
||||
if (v < optdef->min || v > optdef->max) {
|
||||
if (!optdef->is_value_valid(v)) {
|
||||
out_of_range = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user