From 1aaa4845c53e45070bc91038c1b349554b65ea72 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 16 Nov 2021 13:44:31 +0100 Subject: [PATCH] Partially ported https://github.com/supermerill/SuperSlicer/commit/ff195fc9(Add max_literal to setting def, to set the threshold for popup warning for float% fields) from @SuperSlicer (related to https://github.com/prusa3d/PrusaSlicer/issues/2829#issuecomment-955606863) --- src/libslic3r/Config.hpp | 2 ++ src/libslic3r/PrintConfig.cpp | 13 +++++++++++++ src/slic3r/GUI/Field.cpp | 3 +-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index dd121c90a..429f5901c 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -1764,6 +1764,8 @@ public: // By setting min=0, only nonnegative input is allowed. int min = INT_MIN; int max = INT_MAX; + // To check if it's not a typo and a % is missing + double max_literal = 1; ConfigOptionMode mode = comSimple; // Legacy names for this configuration option. // Used when parsing legacy configuration file. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 5a14f8348..6315bdc52 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -374,6 +374,7 @@ void PrintConfigDef::init_fff_params() "Detour length could be specified either as an absolute value or as percentage (for example 50%) of a direct travel path."); def->sidetext = L("mm or % (zero to disable)"); def->min = 0; + def->max_literal = 1000; def->mode = comExpert; def->set_default_value(new ConfigOptionFloatOrPercent(0., false)); @@ -720,6 +721,7 @@ void PrintConfigDef::init_fff_params() "If expressed as percentage (for example 200%), it will be computed over layer height."); def->sidetext = L("mm or %"); def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -831,6 +833,7 @@ void PrintConfigDef::init_fff_params() def->sidetext = L("mm or %"); def->min = 0; def->max = 1000; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -1181,6 +1184,7 @@ void PrintConfigDef::init_fff_params() def->sidetext = L("mm or %"); def->ratio_over = "first_layer_height"; def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(200, true)); @@ -1200,6 +1204,7 @@ void PrintConfigDef::init_fff_params() "(for example: 40%) it will scale the default speeds."); def->sidetext = L("mm/s or %"); def->min = 0; + def->max_literal = 20; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(30, false)); @@ -1374,6 +1379,7 @@ void PrintConfigDef::init_fff_params() "Set this parameter to zero to disable anchoring perimeters connected to a single infill line."); def->sidetext = L("mm or %"); def->ratio_over = "infill_extrusion_width"; + def->max_literal = 1000; def->gui_type = ConfigOptionDef::GUIType::f_enum_open; def->enum_values.push_back("0"); def->enum_values.push_back("1"); @@ -1401,6 +1407,7 @@ void PrintConfigDef::init_fff_params() "Set this parameter to zero to disable anchoring."); def->sidetext = def_infill_anchor_min->sidetext; def->ratio_over = def_infill_anchor_min->ratio_over; + def->max_literal = def_infill_anchor_min->max_literal; def->gui_type = def_infill_anchor_min->gui_type; def->enum_values = def_infill_anchor_min->enum_values; def->enum_labels.push_back(L("0 (not anchored)")); @@ -1429,6 +1436,7 @@ void PrintConfigDef::init_fff_params() "If expressed as percentage (for example 90%) it will be computed over layer height."); def->sidetext = L("mm or %"); def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -1928,6 +1936,7 @@ void PrintConfigDef::init_fff_params() def->sidetext = L("mm or %"); def->aliases = { "perimeters_extrusion_width" }; def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -2300,6 +2309,7 @@ void PrintConfigDef::init_fff_params() "If expressed as percentage (for example 90%) it will be computed over layer height."); def->sidetext = L("mm or %"); def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -2474,6 +2484,7 @@ void PrintConfigDef::init_fff_params() def->sidetext = L("mm or %"); def->ratio_over = "external_perimeter_extrusion_width"; def->min = 0; + def->max_literal = 10; def->mode = comAdvanced; // Default is half the external perimeter width. def->set_default_value(new ConfigOptionFloatOrPercent(50, true)); @@ -2560,6 +2571,7 @@ void PrintConfigDef::init_fff_params() "If expressed as percentage (for example 90%) it will be computed over layer height."); def->sidetext = L("mm or %"); def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); @@ -2793,6 +2805,7 @@ void PrintConfigDef::init_fff_params() "If expressed as percentage (for example 90%) it will be computed over layer height."); def->sidetext = L("mm or %"); def->min = 0; + def->max_literal = 50; def->mode = comAdvanced; def->set_default_value(new ConfigOptionFloatOrPercent(0, false)); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 0a5635630..f7ed84238 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -315,7 +315,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true set_value(double_to_string(val), true); } else if (((m_opt.sidetext.rfind("mm/s") != std::string::npos && val > m_opt.max) || - (m_opt.sidetext.rfind("mm ") != std::string::npos && val > 1)) && + (m_opt.sidetext.rfind("mm ") != std::string::npos && val > /*1*/m_opt.max_literal)) && (m_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast(m_value))) { if (!check_value) { @@ -330,7 +330,6 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true const wxString msg_text = from_u8((boost::format(_utf8(L("Do you mean %s%% instead of %s %s?\n" "Select YES if you want to change this value to %s%%, \n" "or NO if you are sure that %s %s is a correct value."))) % stVal % stVal % sidetext % stVal % stVal % sidetext).str()); -// wxMessageDialog dialog(m_parent, msg_text, _(L("Parameter validation")) + ": " + m_opt_id , wxICON_WARNING | wxYES | wxNO); WarningDialog dialog(m_parent, msg_text, _L("Parameter validation") + ": " + m_opt_id, wxYES | wxNO); if ((!infill_anchors || val > 100) && dialog.ShowModal() == wxID_YES) { set_value(from_u8((boost::format("%s%%") % stVal).str()), false/*true*/);