diff options
author | YuSanka <yusanka@gmail.com> | 2019-07-28 23:00:39 +0300 |
---|---|---|
committer | YuSanka <yusanka@gmail.com> | 2019-07-28 23:00:39 +0300 |
commit | 40a576a8adb73e755fcdb0a4a8d6331e1ffa098a (patch) | |
tree | 6449c71bc4c2bc2efc66b45c90d758ae01cbb5f9 /src | |
parent | ab2519cde43cb5de6547c1b43eff0894daaad5a2 (diff) |
Implemented update of the override filaments options from/to config
Diffstat (limited to 'src')
-rw-r--r-- | src/libslic3r/Config.hpp | 1 | ||||
-rw-r--r-- | src/slic3r/GUI/Field.cpp | 71 | ||||
-rw-r--r-- | src/slic3r/GUI/Field.hpp | 18 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI.cpp | 7 | ||||
-rw-r--r-- | src/slic3r/GUI/OptionsGroup.cpp | 49 | ||||
-rw-r--r-- | src/slic3r/GUI/Tab.cpp | 143 | ||||
-rw-r--r-- | src/slic3r/GUI/Tab.hpp | 5 |
7 files changed, 189 insertions, 105 deletions
diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 64fc69dd5..1615bcc8c 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -982,6 +982,7 @@ public: ConfigOptionBoolsTempl() : ConfigOptionVector<unsigned char>() {} explicit ConfigOptionBoolsTempl(size_t n, bool value) : ConfigOptionVector<unsigned char>(n, (unsigned char)value) {} explicit ConfigOptionBoolsTempl(std::initializer_list<bool> il) { values.reserve(il.size()); for (bool b : il) values.emplace_back((unsigned char)b); } + explicit ConfigOptionBoolsTempl(std::initializer_list<unsigned char> il) { values.reserve(il.size()); for (unsigned char b : il) values.emplace_back(b); } explicit ConfigOptionBoolsTempl(const std::vector<unsigned char>& vec) : ConfigOptionVector<unsigned char>(vec) {} explicit ConfigOptionBoolsTempl(std::vector<unsigned char>&& vec) : ConfigOptionVector<unsigned char>(std::move(vec)) {} diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index e84e9637f..cdf344574 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -255,6 +255,7 @@ void TextCtrl::BUILD() { m_opt.default_value->getFloat() : m_opt.get_default_value<ConfigOptionPercents>()->get_at(m_opt_idx); text_value = double_to_string(val); + m_last_meaningful_value = text_value; break; } case coString: @@ -324,24 +325,7 @@ void TextCtrl::BUILD() { } propagate_value(); }), temp->GetId()); - /* - temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) - { -#ifdef __WXGTK__ - if (bChangedValueEvent) -#endif //__WXGTK__ - if(is_defined_input_value()) - on_change_field(); - }), temp->GetId()); -#ifdef __WXGTK__ - // to correct value updating on GTK we should: - // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT - // and prevent value updating on wxEVT_KEY_DOWN - temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); - temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); -#endif //__WXGTK__ -*/ // select all text using Ctrl+A temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event) { @@ -362,6 +346,18 @@ void TextCtrl::propagate_value() on_kill_focus(); } +void TextCtrl::set_last_meaningful_value() +{ + dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(m_last_meaningful_value)); + propagate_value(); +} + +void TextCtrl::set_na_value() +{ + dynamic_cast<wxTextCtrl*>(window)->SetValue("nan"); + propagate_value(); +} + boost::any& TextCtrl::get_value() { wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue(); @@ -408,6 +404,8 @@ void CheckBox::BUILD() { m_opt.get_default_value<ConfigOptionBools>()->get_at(m_opt_idx) : false; + m_last_meaningful_value = static_cast<unsigned char>(check_value); + // Set Label as a string of at least one space simbol to correct system scaling of a CheckBox auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(" "), wxDefaultPosition, size); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); @@ -415,7 +413,10 @@ void CheckBox::BUILD() { temp->SetValue(check_value); if (m_opt.readonly) temp->Disable(); - temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + temp->Bind(wxEVT_CHECKBOX, ([this](wxCommandEvent e) { + m_is_na_val = false; + on_change_field(); + }), temp->GetId()); temp->SetToolTip(get_tooltip_text(check_value ? "true" : "false")); @@ -423,6 +424,38 @@ void CheckBox::BUILD() { window = dynamic_cast<wxWindow*>(temp); } +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<unsigned char>(value) == ConfigOptionBoolsNullable::nil_value(); + if (!m_is_na_val) + m_last_meaningful_value = value; + dynamic_cast<wxCheckBox*>(window)->SetValue(m_is_na_val ? false : boost::any_cast<unsigned char>(value) != 0); + } + else + dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<bool>(value)); + m_disable_change_event = false; +} + +void CheckBox::set_last_meaningful_value() +{ + if (m_opt.nullable) { + m_is_na_val = false; + dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<unsigned char>(m_last_meaningful_value) != 0); + on_change_field(); + } +} + +void CheckBox::set_na_value() +{ + if (m_opt.nullable) { + m_is_na_val = true; + dynamic_cast<wxCheckBox*>(window)->SetValue(false); + on_change_field(); + } +} + boost::any& CheckBox::get_value() { // boost::any m_value; @@ -430,7 +463,7 @@ boost::any& CheckBox::get_value() if (m_opt.type == coBool) m_value = static_cast<bool>(value); else - m_value = static_cast<unsigned char>(value); + m_value = m_is_na_val ? ConfigOptionBoolsNullable::nil_value() : static_cast<unsigned char>(value); return m_value; } diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 990c40e6f..6dbf4af06 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -123,6 +123,8 @@ public: /// subclasses should overload with a specific version /// Postcondition: Method does not fire the on_change event. virtual void set_value(const boost::any& value, bool change_event) = 0; + virtual void set_last_meaningful_value() {} + virtual void set_na_value() {} /// Gets a boost::any representing this control. /// subclasses should overload with a specific version @@ -247,6 +249,8 @@ protected: // current value boost::any m_value; + // last maeningful value + boost::any m_last_meaningful_value; int m_em_unit; @@ -289,9 +293,14 @@ public: virtual void set_value(const boost::any& value, bool change_event = false) { m_disable_change_event = !change_event; dynamic_cast<wxTextCtrl*>(window)->SetValue(boost::any_cast<wxString>(value)); + if (boost::any_cast<wxString>(value) != "nan") + m_last_meaningful_value = value; m_disable_change_event = false; } + virtual void set_last_meaningful_value() override; + virtual void set_na_value() override; + boost::any& get_value() override; void msw_rescale() override; @@ -303,6 +312,7 @@ public: class CheckBox : public Field { using Field::Field; + bool m_is_na_val {false}; public: CheckBox(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} CheckBox(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} @@ -316,11 +326,9 @@ public: dynamic_cast<wxCheckBox*>(window)->SetValue(value); m_disable_change_event = false; } - void set_value(const boost::any& value, bool change_event = false) { - m_disable_change_event = !change_event; - dynamic_cast<wxCheckBox*>(window)->SetValue(boost::any_cast<bool>(value)); - m_disable_change_event = false; - } + void set_value(const boost::any& value, bool change_event = false) override; + void set_last_meaningful_value() override; + void set_na_value() override; boost::any& get_value() override; void msw_rescale() override; diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 8f41ed5a3..826f2d6fc 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -148,6 +148,13 @@ void config_wizard(int reason) void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) { try{ + + if (config.def()->get(opt_key)->type == coBools && config.def()->get(opt_key)->nullable) { + ConfigOptionBoolsNullable* vec_new = new ConfigOptionBoolsNullable{ boost::any_cast<unsigned char>(value) }; + config.option<ConfigOptionBoolsNullable>(opt_key)->set_at(vec_new, opt_index, 0); + return; + } + switch (config.def()->get(opt_key)->type) { case coFloatOrPercent:{ std::string str = boost::any_cast<std::string>(value); diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index f4f97a47d..2aca87d87 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -372,30 +372,10 @@ void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const b auto option = m_options.at(opt_id).opt; - // get value -//! auto field_value = get_value(opt_id); - if (option.gui_flags.compare("serialized")==0) { - if (opt_index != -1) { - // die "Can't set serialized option indexed value" ; - } - change_opt_value(*m_config, opt_key, value); - } - else { - if (opt_index == -1) { - // change_opt_value(*m_config, opt_key, field_value); - //!? why field_value?? in this case changed value will be lose! No? - change_opt_value(*m_config, opt_key, value); - } - else { - change_opt_value(*m_config, opt_key, value, opt_index); -// auto value = m_config->get($opt_key); -// $value->[$opt_index] = $field_value; -// $self->config->set($opt_key, $value); - } - } + change_opt_value(*m_config, opt_key, value, opt_index == -1 ? 0 : opt_index); } - OptionsGroup::on_change_OG(opt_id, value); //!? Why doing this + OptionsGroup::on_change_OG(opt_id, value); } void ConfigOptionsGroup::back_to_initial_value(const std::string& opt_key) @@ -578,6 +558,31 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config boost::any ret; wxString text_value = wxString(""); const ConfigOptionDef* opt = config.def()->get(opt_key); + + if (opt->nullable) + { + switch (opt->type) + { + case coPercents: + case coFloats: { + double val = opt->type == coFloats ? + config.option<ConfigOptionFloatsNullable>(opt_key)->get_at(idx) : + config.option<ConfigOptionPercentsNullable>(opt_key)->get_at(idx); + ret = double_to_string(val); + } + break; + case coBools: + ret = config.option<ConfigOptionBoolsNullable>(opt_key)->values[idx]; + break; + case coInts: + ret = config.option<ConfigOptionIntsNullable>(opt_key)->get_at(idx); + break; + default: + break; + } + return ret; + } + switch (opt->type) { case coFloatOrPercent:{ const auto &value = *config.option<ConfigOptionFloatOrPercent>(opt_key); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 27f9fb0f3..780489670 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1491,89 +1491,114 @@ void TabPrint::OnActivate() Tab::OnActivate(); } -void TabFilament::add_overrides_page() +static void check_line(const bool is_checked, ConfigOptionsGroupShp optgroup, const std::string& opt_key, int opt_index) { - PageShp page = add_options_page(_(L("Overrides")), "wrench"); + Field* field = optgroup->get_fieldc(opt_key, opt_index); + if (field != nullptr) { + field->toggle(is_checked); + if (is_checked) + field->set_last_meaningful_value(); + else + field->set_na_value(); + } +}; - const DynamicPrintConfig& printer_cfg = wxGetApp().preset_bundle->printers.default_preset().config; +void TabFilament::add_filament_overrides_page() +{ + PageShp page = add_options_page(_(L("Filament Overrides")), "wrench"); - ConfigOptionsGroupShp optgroup = page->new_optgroup(_(L("Retraction"/*Overrides"*/))); + ConfigOptionsGroupShp optgroup = page->new_optgroup(_(L("Retraction"))); - auto append_single_option_line = [printer_cfg, optgroup, this](const std::string& opt_key, int opt_index) + auto append_single_option_line = [optgroup, this](const std::string& opt_key, int opt_index) { - const std::string opt_id = opt_index == -1 ? opt_key : opt_key + "#" + std::to_string(opt_index); - const Option& option = Option(*printer_cfg.def()->get(opt_key), opt_id); - - Line line = optgroup->create_single_option_line(option); + Line line = optgroup->create_single_option_line(optgroup->get_option(opt_key)); - line.near_label_widget = [optgroup, opt_id](wxWindow* parent) { + line.near_label_widget = [this, optgroup, opt_key, opt_index](wxWindow* parent) { wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, ""); - check_box->Bind(wxEVT_CHECKBOX, [optgroup, opt_id](wxCommandEvent& evt) - { - Field* field = optgroup->get_field(opt_id); - if (field != nullptr) - field->toggle(evt.IsChecked()); - }, check_box->GetId()); + check_box->Bind(wxEVT_CHECKBOX, [this, optgroup, opt_key, opt_index](wxCommandEvent& evt) { + check_line(evt.IsChecked(), optgroup, opt_key, opt_index); + }, check_box->GetId()); + + m_overrides_options[opt_key] = check_box; return check_box; }; optgroup->append_line(line); - - Field* field = optgroup->get_field(opt_id); - if (field != nullptr) - field->toggle(false); }; int extruder_idx = 0; // #ys_FIXME - append_single_option_line("retract_length", extruder_idx); - append_single_option_line("retract_lift", extruder_idx); + append_single_option_line("filament_retract_length", extruder_idx); + append_single_option_line("filament_retract_lift", extruder_idx); Line line = { _(L("Only lift Z")), "" }; - std::vector<std::string> opt_ids; - opt_ids.reserve(2); - for (const std::string& opt_key : { "retract_lift_above", "retract_lift_below" }) - { - const std::string opt_id = extruder_idx == -1 ? opt_key : opt_key + "#" + std::to_string(extruder_idx); - opt_ids.push_back(opt_id); - const Option& option = Option(*printer_cfg.def()->get(opt_key), opt_id); - - line.append_option(option); - } + std::vector<std::string> opt_keys = { "filament_retract_lift_above", "filament_retract_lift_below" }; + for (const std::string& opt_key : opt_keys) + line.append_option(optgroup->get_option(opt_key)); - line.near_label_widget = [optgroup, opt_ids](wxWindow* parent) { + line.near_label_widget = [this, optgroup, opt_keys, extruder_idx](wxWindow* parent) { wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, ""); - check_box->Bind(wxEVT_CHECKBOX, [optgroup, opt_ids](wxCommandEvent& evt) - { - Field* field = nullptr; - for (const std::string& opt_id : opt_ids) { - field = optgroup->get_field(opt_id); - if (field != nullptr) - field->toggle(evt.IsChecked()); - } - }, check_box->GetId()); + check_box->Bind(wxEVT_CHECKBOX, [optgroup, opt_keys, extruder_idx](wxCommandEvent& evt) { + const bool is_checked = evt.IsChecked(); + for (const std::string& opt_key : opt_keys) + check_line(is_checked, optgroup, opt_key, extruder_idx); + }, check_box->GetId()); + + for (const std::string& opt_key : opt_keys) + m_overrides_options[opt_key] = check_box; + return check_box; }; optgroup->append_line(line); - Field* field = nullptr; - for (const std::string& opt_id : opt_ids) { - field = optgroup->get_field(opt_id); - if (field != nullptr) - field->toggle(false); - } + append_single_option_line("filament_retract_speed", extruder_idx); + append_single_option_line("filament_deretract_speed", extruder_idx); + append_single_option_line("filament_retract_restart_extra", extruder_idx); + append_single_option_line("filament_retract_before_travel", extruder_idx); + append_single_option_line("filament_retract_layer_change", extruder_idx); + append_single_option_line("filament_wipe", extruder_idx); + append_single_option_line("filament_retract_before_wipe", extruder_idx); +} + +void TabFilament::update_filament_overrides_page() +{ + const auto page_it = std::find_if(m_pages.begin(), m_pages.end(), [](const PageShp page) {return page->title() == _(L("Filament Overrides")); }); + if (page_it == m_pages.end()) + return; + PageShp page = *page_it; + + const auto og_it = std::find_if(page->m_optgroups.begin(), page->m_optgroups.end(), [](const ConfigOptionsGroupShp og) {return og->title == _(L("Retraction")); }); + if (og_it == page->m_optgroups.end()) + return; + ConfigOptionsGroupShp optgroup = *og_it; + + std::vector<std::string> opt_keys = { "filament_retract_length", + "filament_retract_lift", + "filament_retract_lift_above", "filament_retract_lift_below", + "filament_retract_speed", + "filament_deretract_speed", + "filament_retract_restart_extra", + "filament_retract_before_travel", + "filament_retract_layer_change", + "filament_wipe", + "filament_retract_before_wipe" + }; + + int extruder_idx = 0; // #ys_FIXME - append_single_option_line("retract_speed", extruder_idx); - append_single_option_line("deretract_speed", extruder_idx); - append_single_option_line("retract_restart_extra", extruder_idx); - append_single_option_line("retract_before_travel", extruder_idx); - append_single_option_line("retract_layer_change", extruder_idx); - append_single_option_line("wipe", extruder_idx); - append_single_option_line("retract_before_wipe", extruder_idx); + for (const std::string& opt_key : opt_keys) + { + Field* field = optgroup->get_fieldc(opt_key, extruder_idx); + if (field != nullptr) { + const bool is_checked = !m_config->option(opt_key)->is_nil(); + m_overrides_options[opt_key]->SetValue(is_checked); + field->toggle(is_checked); + } + } } void TabFilament::build() @@ -1674,7 +1699,7 @@ void TabFilament::build() optgroup->append_line(line); - add_overrides_page(); + add_filament_overrides_page(); const int gcode_field_height = 15; // 150 @@ -1744,7 +1769,7 @@ void TabFilament::update() return; // ys_FIXME m_update_cnt++; -// Freeze(); + wxString text = from_u8(PresetHints::cooling_description(m_presets->get_edited_preset())); m_cooling_description_line->SetText(text); text = from_u8(PresetHints::maximum_volumetric_flow_description(*m_preset_bundle)); @@ -1759,7 +1784,9 @@ void TabFilament::update() for (auto el : { "min_fan_speed", "disable_fan_first_layers" }) get_field(el)->toggle(fan_always_on); -// Thaw(); + + update_filament_overrides_page(); + m_update_cnt--; if (m_update_cnt == 0) diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 7172f595a..6ff76f5c4 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -338,7 +338,10 @@ class TabFilament : public Tab ogStaticText* m_volumetric_speed_description_line; ogStaticText* m_cooling_description_line; - void add_overrides_page(); + void add_filament_overrides_page(); + void update_filament_overrides_page(); + + std::map<std::string, wxCheckBox*> m_overrides_options; public: TabFilament(wxNotebook* parent) : // Tab(parent, _(L("Filament Settings")), L("filament")) {} |