From 215c2082d3bb011f5ba95cd03b8614abafb488e8 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 13 Apr 2018 18:22:06 +0200 Subject: [PATCH] Decorated "bed_shape" and "compatible_printers" labels --- xs/src/slic3r/GUI/OptionsGroup.cpp | 7 +++- xs/src/slic3r/GUI/OptionsGroup.hpp | 2 +- xs/src/slic3r/GUI/Tab.cpp | 62 ++++++++++++++++++++++-------- xs/src/slic3r/GUI/Tab.hpp | 2 + 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 8e2268965..168ffcdc9 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -97,7 +97,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co return field; } -void OptionsGroup::append_line(const Line& line) { +void OptionsGroup::append_line(const Line& line, wxStaticText** colored_Label/* = nullptr*/) { //! if (line.sizer != nullptr || (line.widget != nullptr && line.full_width > 0)){ if ( (line.sizer != nullptr || line.widget != nullptr) && line.full_width){ if (line.sizer != nullptr) { @@ -150,6 +150,7 @@ void OptionsGroup::append_line(const Line& line) { if (line.widget != nullptr) { auto wgt = line.widget(parent()); grid_sizer->Add(wgt, 0, wxEXPAND | wxBOTTOM | wxTOP, wxOSX ? 0 : 5); + if (colored_Label != nullptr) *colored_Label = label; return; } @@ -396,6 +397,10 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config ret = static_cast(config.opt_string(opt_key)); break; case coStrings: + if (opt_key.compare("compatible_printers") == 0){ + ret = config.option(opt_key)->values; + break; + } if (config.option(opt_key)->values.empty()) ret = text_value; else if (opt->gui_flags.compare("serialized") == 0){ diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index b5846f24d..dd6d48f46 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -93,7 +93,7 @@ public: /// but defining it as const means a lot of const_casts to deal with wx functions. inline wxWindow* parent() const { return m_parent; } - void append_line(const Line& line); + void append_line(const Line& line, wxStaticText** colored_Label = nullptr); Line create_single_option_line(const Option& option) const; void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index a9faf4c59..4f6580f24 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -326,6 +326,7 @@ void Tab::update_changed_ui() m_dirty_options = dirty_options; } + Freeze(); //update options "decoration" for (const auto opt_key : m_full_options_list) { @@ -347,6 +348,14 @@ void Tab::update_changed_ui() is_modified_value = false; icon = "bullet_white.png"; } + if (opt_key == "bed_shape" || opt_key == "compatible_printers") { + if (m_colored_Label != nullptr) { + m_colored_Label->SetForegroundColour(color); + m_colored_Label->Refresh(true); + } + continue; + } + Field* field = get_field(opt_key); if (field == nullptr) continue; field->m_is_nonsys_value = is_nonsys_value; @@ -358,6 +367,7 @@ void Tab::update_changed_ui() field->m_Label->Refresh(true); } } + Thaw(); wxTheApp->CallAfter([this]() { update_changed_tree_ui(); @@ -419,13 +429,20 @@ void Tab::update_sys_ui_after_sel_preset() m_sys_options.resize(0); } +void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page) +{ + if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) + sys_page = false; + if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) + modified_page = true; +} + void Tab::update_changed_tree_ui() { auto cur_item = m_treectrl->GetFirstVisibleItem(); auto selection = m_treectrl->GetItemText(m_treectrl->GetSelection()); while (cur_item){ auto title = m_treectrl->GetItemText(cur_item); - int i=0; for (auto page : m_pages) { if (page->title() != title) @@ -435,23 +452,20 @@ void Tab::update_changed_tree_ui() if (title == _("General")){ std::initializer_list optional_keys{ "extruders_count", "bed_shape" }; for (auto &opt_key : optional_keys) { - if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) - sys_page = false; - if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) - modified_page = true; + get_sys_and_mod_flags(opt_key, sys_page, modified_page); } } + if (title == _("Dependencies")){ + get_sys_and_mod_flags("compatible_printers", sys_page, modified_page); + } for (auto group : page->m_optgroups) { - for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { - const std::string& opt_key = it->first; - if (sys_page && find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) - sys_page = false; - if (!modified_page && find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) - modified_page = true; - } if (!sys_page && modified_page) break; + for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { + const std::string& opt_key = it->first; + get_sys_and_mod_flags(opt_key, sys_page, modified_page); + } } if (sys_page) m_treectrl->SetItemTextColour(cur_item, get_sys_label_clr()); @@ -500,6 +514,14 @@ void Tab::on_back_to_initial_value() if (find(m_dirty_options.begin(), m_dirty_options.end(), "bed_shape") != m_dirty_options.end()) group->back_to_initial_value("bed_shape"); } + if (group->title == _("Profile dependencies")){ + if (find(m_dirty_options.begin(), m_dirty_options.end(), "compatible_printers") != m_dirty_options.end()) + group->back_to_initial_value("compatible_printers"); + + bool is_empty = m_config->option("compatible_printers")->values.empty(); + m_compatible_printers_checkbox->SetValue(is_empty); + is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable(); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_dirty_options.begin(), m_dirty_options.end(), opt_key) != m_dirty_options.end()) @@ -527,6 +549,14 @@ void Tab::on_back_to_sys_value() if (find(m_sys_options.begin(), m_sys_options.end(), "bed_shape") == m_sys_options.end()) group->back_to_sys_value("bed_shape"); } + if (group->title == _("Profile dependencies")){ + if (find(m_sys_options.begin(), m_sys_options.end(), "compatible_printers") == m_sys_options.end()) + group->back_to_sys_value("compatible_printers"); + + bool is_empty = m_config->option("compatible_printers")->values.empty(); + m_compatible_printers_checkbox->SetValue(is_empty); + is_empty ? m_compatible_printers_btn->Disable() : m_compatible_printers_btn->Enable(); + } for (t_opt_map::iterator it = group->m_opt_map.begin(); it != group->m_opt_map.end(); ++it) { const std::string& opt_key = it->first; if (find(m_sys_options.begin(), m_sys_options.end(), opt_key) == m_sys_options.end()) @@ -905,7 +935,7 @@ void TabPrint::build() line.widget = [this](wxWindow* parent){ return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn); }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); option = optgroup->get_option("compatible_printers_condition"); option.opt.full_width = true; @@ -1279,7 +1309,7 @@ void TabFilament::build() line.widget = [this](wxWindow* parent){ return compatible_printers_widget(parent, &m_compatible_printers_checkbox, &m_compatible_printers_btn); }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); option = optgroup->get_option("compatible_printers_condition"); option.opt.full_width = true; @@ -1376,7 +1406,7 @@ void TabPrinter::build() return sizer; }; - optgroup->append_line(line); + optgroup->append_line(line, &m_colored_Label); optgroup->append_single_option_line("max_print_height"); optgroup->append_single_option_line("z_offset"); @@ -2114,6 +2144,7 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox if ((*checkbox)->GetValue()) load_key_value("compatible_printers", std::vector {}); get_field("compatible_printers_condition")->toggle((*checkbox)->GetValue()); + update_changed_ui(); }) ); (*btn)->Bind(wxEVT_BUTTON, ([this, parent, checkbox, btn](wxCommandEvent e) @@ -2156,6 +2187,7 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox } // All printers have been made compatible with this preset. load_key_value("compatible_printers", value); + update_changed_ui(); } })); return sizer; diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index 9465f86b4..c69f4285d 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -126,6 +126,7 @@ public: DynamicPrintConfig* m_config; std::string m_nonsys_btn_icon; ogStaticText* m_parent_preset_description_line; + wxStaticText* m_colored_Label = nullptr; public: Tab() {} @@ -166,6 +167,7 @@ public: void update_changed_ui(); void update_full_options_list(); void update_sys_ui_after_sel_preset(); + void get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page); void update_changed_tree_ui(); void update_undo_buttons();