From 23f96e30c3fd800bc40d5fb2934428a216281907 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 20 Feb 2018 12:30:13 +0100 Subject: [PATCH] Fixed wrong saving of "percent or millimeters" parameters --- xs/src/slic3r/GUI/Field.cpp | 15 ++++----------- xs/src/slic3r/GUI/Field.hpp | 2 +- xs/src/slic3r/GUI/GUI.cpp | 10 ++++++++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index e28e351a6..5eec47a54 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -53,7 +53,7 @@ namespace Slic3r { namespace GUI { return std::regex_match(string, regex_pattern); } - boost::any Field::get_value_by_opt_type(wxString str, ConfigOptionType type) + boost::any Field::get_value_by_opt_type(wxString str) { boost::any ret_val; switch (m_opt.type){ @@ -72,16 +72,9 @@ namespace Slic3r { namespace GUI { break; } case coString: case coStrings: + case coFloatOrPercent: ret_val = str.ToStdString(); break; - case coFloatOrPercent:{ - if (str.Last() == '%') - str.RemoveLast(); - double val; - str.ToCDouble(&val); - ret_val = val; - break; - } default: break; } @@ -165,7 +158,7 @@ namespace Slic3r { namespace GUI { boost::any TextCtrl::get_value() { wxString ret_str = static_cast(window)->GetValue(); - boost::any ret_val = get_value_by_opt_type(ret_str, m_opt.type); + boost::any ret_val = get_value_by_opt_type(ret_str); return ret_val; } @@ -420,7 +413,7 @@ boost::any Choice::get_value() wxString ret_str = static_cast(window)->GetValue(); if (m_opt.type != coEnum) - ret_val = get_value_by_opt_type(ret_str, m_opt.type); + ret_val = get_value_by_opt_type(ret_str); else { int ret_enum = static_cast(window)->GetSelection(); diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index c1f9f2de9..492629b41 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -85,7 +85,7 @@ public: virtual wxWindow* getWindow() { return nullptr; } bool is_matched(std::string string, std::string pattern); - boost::any get_value_by_opt_type(wxString str, ConfigOptionType type); + boost::any get_value_by_opt_type(wxString str); /// Factory method for generating new derived classes. template diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 3b8d34436..394aca9ad 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -384,8 +384,14 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b try{ switch (config.def()->get(opt_key)->type){ case coFloatOrPercent:{ - const auto &val = *config.option(opt_key); - config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(boost::any_cast(value), val.percent)); + std::string str = boost::any_cast(value); + bool percent = false; + if (str.back() == '%'){ + str.pop_back(); + percent = true; + } + double val = stod(str); + config.set_key_value(opt_key, new ConfigOptionFloatOrPercent(val, percent)); break;} case coPercent: config.set_key_value(opt_key, new ConfigOptionPercent(boost::any_cast(value)));