diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 4347e18cc3..7846949071 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -248,8 +248,6 @@ bool Field::is_matched(const std::string& string, const std::string& pattern) return std::regex_match(string, regex_pattern); } -static wxString na_value() { return _(L("N/A")); } - void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true*/) { switch (m_opt.type) { @@ -287,7 +285,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true } double val; - bool is_na_value = m_opt.nullable && str == na_value(); + bool is_na_value = m_opt.nullable && str == m_na_value; const char dec_sep = is_decimal_separator_point() ? '.' : ','; const char dec_sep_alt = dec_sep == '.' ? ',' : '.'; @@ -827,7 +825,6 @@ bool TextCtrl::value_was_changed() void TextCtrl::propagate_value() { - if (!is_defined_input_value(text_ctrl(), m_opt.type)) { // BBS // on_kill_focus() cause a call of OptionsGroup::reload_config(), // Thus, do it only when it's really needed (when undefined value was input) @@ -840,11 +837,10 @@ void TextCtrl::propagate_value() void TextCtrl::set_value(const boost::any& value, bool change_event/* = false*/) { m_disable_change_event = !change_event; if (m_opt.nullable) { - const bool m_is_na_val = boost::any_cast(value) == na_value(); - if (!m_is_na_val) + if (boost::any_cast(value) != _(L("N/A"))) m_last_meaningful_value = value; - text_ctrl()->SetValue(m_is_na_val ? na_value() : - boost::any_cast(value)); // BBS + + text_ctrl()->SetValue(boost::any_cast(value)); // BBS } else text_ctrl()->SetValue(value.empty() ? "" : boost::any_cast(value)); // BBS // BBS: null value @@ -866,9 +862,14 @@ void TextCtrl::set_last_meaningful_value() propagate_value(); } +void TextCtrl::update_na_value(const boost::any& value) +{ + m_na_value = boost::any_cast(value); +} + void TextCtrl::set_na_value() { - text_ctrl()->SetValue(na_value()); // BBS + text_ctrl()->SetValue(m_na_value); // BBS propagate_value(); } @@ -978,10 +979,16 @@ void CheckBox::set_value(const boost::any& value, bool change_event) { m_disable_change_event = !change_event; if (m_opt.nullable) { - m_is_na_val = boost::any_cast(value) == ConfigOptionBoolsNullable::nil_value(); + const bool is_value_unsigned_char = value.type() == typeid(unsigned char); + m_is_na_val = is_value_unsigned_char && + boost::any_cast(value) == ConfigOptionBoolsNullable::nil_value(); if (!m_is_na_val) - m_last_meaningful_value = value; - dynamic_cast<::CheckBox*>(window)->SetValue(m_is_na_val ? false : boost::any_cast(value) != 0); // BBS + m_last_meaningful_value = is_value_unsigned_char ? value : static_cast(boost::any_cast(value)); + + const auto bool_value = is_value_unsigned_char ? + boost::any_cast(value) != 0 : + boost::any_cast(value); + dynamic_cast<::CheckBox*>(window)->SetValue(m_is_na_val ? false : bool_value); // BBS } else if (!value.empty()) // BBS: null value dynamic_cast<::CheckBox*>(window)->SetValue(boost::any_cast(value)); // BBS diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 3b974b7ad0..2cc89f240a 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -10,6 +10,7 @@ #include #include #include +#include "I18N.hpp" #include #include @@ -225,6 +226,8 @@ class Field : public UndoValueUIManager { virtual void set_last_meaningful_value() {} virtual void set_na_value() {} + virtual void update_na_value(const boost::any& value) {} + /// Gets a boost::any representing this control. /// subclasses should overload with a specific version virtual boost::any& get_value() = 0; @@ -283,6 +286,7 @@ class Field : public UndoValueUIManager { bool bEnterPressed = false; + wxString m_na_value = _(L("N/A")); friend class OptionsGroup; }; @@ -324,6 +328,8 @@ class TextCtrl : public Field { void set_last_meaningful_value() override; void set_na_value() override; + void update_na_value(const boost::any& value) override; + boost::any& get_value() override; void msw_rescale() override; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e3bf206bb1..b87e98c10e 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3117,15 +3117,25 @@ void TabFilament::add_filament_overrides_page() line.near_label_widget = [this, optgroup_wk = ConfigOptionsGroupWkp(optgroup), opt_key, opt_index](wxWindow* parent) { wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, ""); - check_box->Bind(wxEVT_CHECKBOX, [optgroup_wk, opt_key, opt_index](wxCommandEvent& evt) { + check_box->Bind( + wxEVT_CHECKBOX, + [this, optgroup_wk, opt_key, opt_index](wxCommandEvent& evt) { const bool is_checked = evt.IsChecked(); if (auto optgroup_sh = optgroup_wk.lock(); optgroup_sh) { if (Field *field = optgroup_sh->get_fieldc(opt_key, opt_index); field != nullptr) { field->toggle(is_checked); - if (is_checked) + + if (is_checked) { + field->update_na_value(_(L("N/A"))); field->set_last_meaningful_value(); - else + } + else { + const std::string printer_opt_key = opt_key.substr(strlen("filament_")); + const auto printer_config = m_preset_bundle->printers.get_edited_preset().config; + const boost::any printer_config_value = optgroup_sh->get_config_value(printer_config, printer_opt_key, opt_index); + field->update_na_value(printer_config_value); field->set_na_value(); + } } } }, check_box->GetId()); @@ -3162,7 +3172,7 @@ void TabFilament::add_filament_overrides_page() append_single_option_line(opt_key, extruder_idx); } -void TabFilament::update_filament_overrides_page() +void TabFilament::update_filament_overrides_page(const DynamicPrintConfig* printers_config) { if (!m_active_page || m_active_page->title() != "Setting Overrides") return; @@ -3213,22 +3223,30 @@ void TabFilament::update_filament_overrides_page() m_overrides_options[opt_key]->SetValue(is_checked); Field* field = optgroup->get_fieldc(opt_key, extruder_idx); - if (field != nullptr) { - if (opt_key == "filament_long_retractions_when_cut") { - int machine_enabled_level = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; - bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; - toggle_line(opt_key, machine_enabled); - field->toggle(is_checked && machine_enabled); - } - else if (opt_key == "filament_retraction_distances_when_cut") { - int machine_enabled_level = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; - bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; - bool filament_enabled = m_config->option("filament_long_retractions_when_cut")->values[extruder_idx] == 1; - toggle_line(opt_key, filament_enabled && machine_enabled); - field->toggle(is_checked && filament_enabled && machine_enabled); + if (field == nullptr) continue; + + if (opt_key == "filament_long_retractions_when_cut") { + int machine_enabled_level = printers_config->option( + "enable_long_retraction_when_cut")->value; + bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; + toggle_line(opt_key, machine_enabled); + field->toggle(is_checked && machine_enabled); + } else if (opt_key == "filament_retraction_distances_when_cut") { + int machine_enabled_level = printers_config->option( + "enable_long_retraction_when_cut")->value; + bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; + bool filament_enabled = m_config->option("filament_long_retractions_when_cut")->values[extruder_idx] == 1; + toggle_line(opt_key, filament_enabled && machine_enabled); + field->toggle(is_checked && filament_enabled && machine_enabled); + } else { + if (!is_checked) { + const std::string printer_opt_key = opt_key.substr(strlen("filament_")); + boost::any printer_config_value = optgroup->get_config_value(*printers_config, printer_opt_key, extruder_idx); + field->update_na_value(printer_config_value); + field->set_value(printer_config_value, false); } - else - field->toggle(is_checked); + + field->toggle(is_checked); } } } @@ -3602,7 +3620,7 @@ void TabFilament::toggle_options() toggle_line("filament_diameter", !is_pellet_printer); } if (m_active_page->title() == L("Setting Overrides")) - update_filament_overrides_page(); + update_filament_overrides_page(&cfg); if (m_active_page->title() == L("Multimaterial")) { // Orca: hide specific settings for BBL printers diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 0550c6291d..cab9990bb4 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -554,7 +554,7 @@ class TabFilament : public Tab ogStaticText* m_cooling_description_line {nullptr}; void add_filament_overrides_page(); - void update_filament_overrides_page(); + void update_filament_overrides_page(const DynamicPrintConfig* printers_config); void update_volumetric_flow_preset_hints(); std::map m_overrides_options;