From 5205598cf7f0be10f6a9ee292b4e7e0c29053586 Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 22 Jun 2020 19:58:15 +0200 Subject: [PATCH] #183 allow min for floatAndPercent fields Have to modify the Fields.cpp function a bit. May need a better patch later on, as this one is only for min. Also, the current checks for float&percent are very strange. --- src/libslic3r/PrintConfig.cpp | 5 ---- src/slic3r/GUI/Field.cpp | 51 +++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index f91a54b31..59c2b20de 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2934,12 +2934,7 @@ void PrintConfigDef::init_fff_params() "for the first object layer. Can be a % of the extruding width used for the interface layers."); def->ratio_over = "top_infill_extrusion_width"; def->sidetext = L("mm"); - def->enum_labels.push_back((boost::format("0.2 (%1%)") % L("detachable")).str()); def->min = 0; - def->enum_values.push_back("0"); - def->enum_values.push_back("0.2"); - def->enum_labels.push_back(L("0 (soluble)")); - def->enum_labels.push_back(L("0.2 (detachable)")); def->mode = comAdvanced; def->aliases = { "support_material_contact_distance" }; def->set_default_value(new ConfigOptionFloatOrPercent(0.2, false)); diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index ef04482d9..fa90baef1 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -225,28 +225,39 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true } show_error(m_parent, _(L("Invalid numeric input."))); 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_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast(m_value))) - { - if (!check_value) { - m_value.clear(); - break; - } + } else { - const std::string sidetext = m_opt.sidetext.rfind("mm/s") != std::string::npos ? "mm/s" : "mm"; - const wxString stVal = double_to_string(val, 2); - 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); - if (dialog.ShowModal() == wxID_YES) { - set_value(from_u8((boost::format("%s%%") % stVal).str()), false/*true*/); - str += "%%"; + //at least check min, as we can want a 0 min + if (m_opt.min > val) + { + if (!check_value) { + m_value.clear(); + break; + } + show_error(m_parent, _(L("Input value is out of range"))); + if (m_opt.min > val) val = m_opt.min; + 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_value.empty() || std::string(str.ToUTF8().data()) != boost::any_cast(m_value))) + { + if (!check_value) { + m_value.clear(); + break; + } + + const std::string sidetext = m_opt.sidetext.rfind("mm/s") != std::string::npos ? "mm/s" : "mm"; + const wxString stVal = double_to_string(val, 2); + 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); + if (dialog.ShowModal() == wxID_YES) { + set_value(from_u8((boost::format("%s%%") % stVal).str()), false/*true*/); + str += "%%"; + } else + set_value(stVal, false); // it's no needed but can be helpful, when inputted value contained "," instead of "." } - else - set_value(stVal, false); // it's no needed but can be helpful, when inputted value contained "," instead of "." } }