From 9a6864510603f6125d0a67da95af412c193d0f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C5=A0ach?= Date: Wed, 8 Nov 2023 18:42:09 +0100 Subject: [PATCH] Update filament overrides UI. After introducing the new z-hop strategy the filament overrides were in a state of disarray. This commit fixes it. --- src/slic3r/GUI/Tab.cpp | 178 +++++++++++++++++++++++++---------------- 1 file changed, 108 insertions(+), 70 deletions(-) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ce445a2fb0..69e2ff613c 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1986,38 +1986,56 @@ void TabFilament::update_line_with_near_label_widget(ConfigOptionsGroupShp optgr field->toggle(is_checked); } +std::vector>> option_keys { + {"Travel lift", { + "filament_retract_lift", + "filament_travel_ramping_lift", + "filament_travel_max_lift", + "filament_travel_slope", + "filament_travel_lift_before_obstacle", + "filament_retract_lift_above", + "filament_retract_lift_below" + }}, + {"Retraction", { + "filament_retract_length", + "filament_retract_speed", + "filament_deretract_speed", + "filament_retract_restart_extra", + "filament_retract_before_travel", + "filament_retract_layer_change", + "filament_wipe", + "filament_retract_before_wipe", + }}, + {"Retraction when tool is disabled", { + "filament_retract_length_toolchange", + "filament_retract_restart_extra_toolchange" + }} +}; + void TabFilament::add_filament_overrides_page() { PageShp page = add_options_page(L("Filament Overrides"), "wrench"); - ConfigOptionsGroupShp optgroup = page->new_optgroup(L("Travels")); const int extruder_idx = 0; // #ys_FIXME - for (const std::string opt_key : { - "filament_travel_ramping_lift", - "filament_travel_slope", - "filament_retract_lift", - "filament_travel_max_lift", - "filament_retract_length", - "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", - "filament_travel_lift_before_obstacle" - }) - create_line_with_near_label_widget(optgroup, opt_key, extruder_idx); - - optgroup = page->new_optgroup(L("Retraction when tool is disabled")); - for (const std::string opt_key : { "filament_retract_length_toolchange", - "filament_retract_restart_extra_toolchange" - }) - create_line_with_near_label_widget(optgroup, opt_key, extruder_idx); + for (const auto&[title, keys] : option_keys) { + ConfigOptionsGroupShp optgroup = page->new_optgroup(L(title)); + for (const std::string& opt_key : keys) { + create_line_with_near_label_widget(optgroup, opt_key, extruder_idx); + } + } +} +std::optional get_option_group(const Page* page, const std::string& title) { + auto og_it = std::find_if( + page->m_optgroups.begin(), page->m_optgroups.end(), + [&](const ConfigOptionsGroupShp& og) { + return og->title == title; + } + ); + if (og_it == page->m_optgroups.end()) + return {}; + return *og_it; } void TabFilament::update_filament_overrides_page() @@ -2026,57 +2044,77 @@ void TabFilament::update_filament_overrides_page() return; Page* page = m_active_page; - auto og_it = std::find_if(page->m_optgroups.begin(), page->m_optgroups.end(), [](const ConfigOptionsGroupShp og) { return og->title == "Travels"; }); - if (og_it == page->m_optgroups.end()) - return; - ConfigOptionsGroupShp optgroup = *og_it; - - std::vector opt_keys = { "filament_retract_length", - "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", - "filament_travel_slope", - "filament_travel_max_lift", - "filament_retract_lift", - "filament_travel_lift_before_obstacle" - }; const int extruder_idx = 0; // #ys_FIXME - const bool have_retract_length = m_config->option("filament_retract_length")->is_nil() || - m_config->opt_float("filament_retract_length", extruder_idx) > 0; + const bool have_retract_length = ( + m_config->option("filament_retract_length")->is_nil() + || m_config->opt_float("filament_retract_length", extruder_idx) > 0 + ); - for (const std::string& opt_key : opt_keys) - { - bool is_checked = opt_key=="filament_retract_length" ? true : have_retract_length; - update_line_with_near_label_widget(optgroup, opt_key, extruder_idx, is_checked); -/* - m_overrides_options[opt_key]->Enable(is_checked); + const bool uses_ramping_lift = ( + m_config->option("filament_travel_ramping_lift")->is_nil() + || m_config->opt_bool("filament_travel_ramping_lift", extruder_idx) + ); - is_checked &= !m_config->option(opt_key)->is_nil(); - CheckBox::SetValue(m_overrides_options[opt_key], is_checked); + const bool is_lifting = ( + m_config->option("filament_travel_max_lift")->is_nil() + || m_config->opt_float("filament_travel_max_lift", extruder_idx) > 0 + || m_config->option("filament_retract_lift")->is_nil() + || m_config->opt_float("filament_retract_lift", extruder_idx) > 0 + ); - Field* field = optgroup->get_fieldc(opt_key, extruder_idx); - if (field != nullptr) - field->toggle(is_checked); -*/ + for (const auto&[title, keys] : option_keys) { + std::optional optgroup{get_option_group(page, title)}; + if (!optgroup) { + continue; + } + + for (const std::string& opt_key : keys) { + bool is_checked{true}; + if ( + title == "Retraction" + && opt_key != "filament_retract_length" + && !have_retract_length + ) { + is_checked = false; + } + + if ( + title == "Travel lift" + && uses_ramping_lift + && opt_key == "filament_retract_lift" + && !m_config->option("filament_travel_ramping_lift")->is_nil() + && m_config->opt_bool("filament_travel_ramping_lift", extruder_idx) + ) { + is_checked = false; + } + + if ( + title == "Travel lift" + && !is_lifting + && ( + opt_key == "filament_retract_lift_above" + || opt_key == "filament_retract_lift_below" + ) + ) { + is_checked = false; + } + + if ( + title == "Travel lift" + && !uses_ramping_lift + && opt_key != "filament_travel_ramping_lift" + && opt_key != "filament_retract_lift" + && opt_key != "filament_retract_lift_above" + && opt_key != "filament_retract_lift_below" + ) { + is_checked = false; + } + + update_line_with_near_label_widget(*optgroup, opt_key, extruder_idx, is_checked); + } } - - og_it = std::find_if(page->m_optgroups.begin(), page->m_optgroups.end(), [](const ConfigOptionsGroupShp og) { return og->title == "Retraction when tool is disabled"; }); - if (og_it == page->m_optgroups.end()) - return; - optgroup = *og_it; - - for (const std::string& opt_key : {"filament_retract_length_toolchange", "filament_retract_restart_extra_toolchange"}) - update_line_with_near_label_widget(optgroup, opt_key, extruder_idx); - - } void TabFilament::create_extruder_combobox() @@ -3267,7 +3305,7 @@ void TabPrinter::build_extruder_pages(size_t n_before_extruders) optgroup = page->new_optgroup(L("Travel lift")); optgroup->append_single_option_line("retract_lift", "", extruder_idx); - optgroup->append_single_option_line("travel_ramping_lift"); + optgroup->append_single_option_line("travel_ramping_lift", "", extruder_idx); optgroup->append_single_option_line("travel_max_lift", "", extruder_idx); optgroup->append_single_option_line("travel_slope", "", extruder_idx); optgroup->append_single_option_line("travel_lift_before_obstacle", "", extruder_idx);