Update filament overrides UI.

After introducing the new z-hop strategy the filament overrides
were in a state of disarray. This commit fixes it.
This commit is contained in:
Martin Šach 2023-11-08 18:42:09 +01:00 committed by SachCZ
parent 0c64950151
commit 9a68645106

View File

@ -1986,38 +1986,56 @@ void TabFilament::update_line_with_near_label_widget(ConfigOptionsGroupShp optgr
field->toggle(is_checked);
}
std::vector<std::pair<std::string, std::vector<std::string>>> 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<ConfigOptionsGroupShp> 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<std::string> 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<ConfigOptionsGroupShp> 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);