FIX: filament variant index & override nil value

Change-Id: I828fff09df39a60d59af516c969466d9b09e503f
Jira: none
This commit is contained in:
chunmao.guo 2024-07-18 17:04:14 +08:00 committed by lane.wei
parent e746035f31
commit 1745657e22
4 changed files with 54 additions and 27 deletions

View File

@ -2745,17 +2745,27 @@ void add_correct_opts_to_diff(const std::string &opt_key, t_config_option_keys&
for (int i = 0; i < int(opt_cur->values.size()); i++)
{
int init_id = i <= opt_init_max_id ? i : 0;
if (opt_cur->values[i] != opt_init->values[init_id]
&& (strict || !(opt_cur->is_nil(i) || opt_init->is_nil(init_id))))
vec.emplace_back(opt_key + "#" + std::to_string(i));
if (opt_cur->values[i] != opt_init->values[init_id]) {
if (opt_cur->nullable()) {
if (opt_cur->is_nil(i)) {
if (strict && !opt_init->is_nil(init_id))
vec.emplace_back(opt_key + "#" + std::to_string(i));
} else {
if (strict || !opt_init->is_nil(init_id))
vec.emplace_back(opt_key + "#" + std::to_string(i));
}
} else {
vec.emplace_back(opt_key + "#" + std::to_string(i));
}
}
}
}
// Use deep_diff to correct return of changed options, considering individual options for each extruder.
inline t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict = false)
inline t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict = true)
{
t_config_option_keys diff;
t_config_option_keys keys = config_this.keys();
t_config_option_keys keys;
if (strict) {
t_config_option_keys keys_this = config_this.keys();
t_config_option_keys keys_other = config_other.keys();

View File

@ -1000,7 +1000,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
{
case coPercents:
case coFloats: {
if (config.option(opt_key)->is_nil())
if (opt_index < 0 ? config.option(opt_key)->is_nil() : dynamic_cast<ConfigOptionVectorBase const*>(config.option(opt_key))->is_nil(opt_index))
ret = _(L("N/A"));
else {
double val = opt->type == coFloats ?
@ -1010,7 +1010,7 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
}
break;
case coFloatsOrPercents: {
if (config.option(opt_key)->is_nil())
if (opt_index < 0 ? config.option(opt_key)->is_nil() : dynamic_cast<ConfigOptionVectorBase const*>(config.option(opt_key))->is_nil(opt_index))
ret = _(L("N/A"));
else {
const auto& value = config.option<ConfigOptionFloatsOrPercentsNullable>(opt_key)->get_at(idx);

View File

@ -698,15 +698,20 @@ public:
void Sidebar::priv::sync_extruder_list()
{
auto printer_tab = dynamic_cast<TabPrinter *>(wxGetApp().get_tab(Preset::TYPE_PRINTER));
printer_tab->set_extruder_volume_type(0, NozzleVolumeType::nvtBigTraffic);
printer_tab->set_extruder_volume_type(1, NozzleVolumeType::nvtNormal);
MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine();
if (obj == nullptr) {
MessageDialog dlg(this->plater, _L("Please select a printer in 'Device' page first."), _L("Sync extruder infomation"), wxOK);
MessageDialog dlg(this->plater, _L("Please select a printer in 'Device' page first."), _L("Sync extruder infomation"), wxOK | wxICON_WARNING);
dlg.ShowModal();
return;
}
if (obj->m_nozzle_data.nozzles.size() != 2) {
MessageDialog dlg(this->plater, _L("The currently connected printer does not have two extruders."), _L("Sync extruder infomation"), wxOK | wxICON_WARNING);
dlg.ShowModal();
return;
}
auto printer_tab = dynamic_cast<TabPrinter *>(wxGetApp().get_tab(Preset::TYPE_PRINTER));
printer_tab->set_extruder_volume_type(0, NozzleVolumeType(obj->m_nozzle_data.nozzles[1].flow_type));
printer_tab->set_extruder_volume_type(1, NozzleVolumeType(obj->m_nozzle_data.nozzles[0].flow_type));
int left = 0, right = 0;
for (auto ams : obj->amsList) {
// Main (first) extruder at right
@ -1520,6 +1525,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
// Update dual extrudes
auto extruder_variants = printer_preset.config.option<ConfigOptionStrings>("extruder_variant_list");
p->m_dual_extruder_sizer->Show(extruder_variants->size() == 2);
p->m_extruder_sync->Show(extruder_variants->size() == 2);
if (extruder_variants->size() == 2) {
auto extruders_def = printer_preset.config.def()->get("extruder_type");
auto extruders = printer_preset.config.option<ConfigOptionEnumsGeneric>("extruder_type");
@ -1956,7 +1962,8 @@ std::map<int, DynamicPrintConfig> Sidebar::build_filament_ams_list(MachineObject
if (!obj) return filament_ams_list;
auto build_tray_config = [](AmsTray const & tray, std::string const & name) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": name %1% setting_id %2% color %3%") % name % tray.setting_id % tray.color;
BOOST_LOG_TRIVIAL(info) << boost::format("build_filament_ams_list: name %1% setting_id %2% type %3% color %4%")
% name % tray.setting_id % tray.type % tray.color;
DynamicPrintConfig tray_config;
tray_config.set_key_value("filament_id", new ConfigOptionStrings{tray.setting_id});
tray_config.set_key_value("tag_uid", new ConfigOptionStrings{tray.tag_uid});

View File

@ -50,7 +50,7 @@
namespace Slic3r {
t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict = false);
t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict = true);
namespace GUI {
@ -887,10 +887,14 @@ void Tab::update_changed_ui()
it.second = m_opt_status_value;
for (auto opt_key : dirty_options) {
m_options_list[opt_key] &= ~osInitValue;
auto iter = m_options_list.find(opt_key);
if (iter != m_options_list.end())
iter->second &= ~osInitValue;
}
for (auto opt_key : nonsys_options) {
m_options_list[opt_key] &= ~osSystemValue;
auto iter = m_options_list.find(opt_key);
if (iter != m_options_list.end())
iter->second &= ~osSystemValue;
}
decorate();
@ -962,8 +966,12 @@ void TabFilament::init_options_list()
if (!m_options_list.empty())
m_options_list.clear();
for (const std::string& opt_key : m_config->keys())
m_options_list.emplace(opt_key, m_opt_status_value);
for (const std::string &opt_key : m_config->keys()) {
if (filament_options_with_variant.find(opt_key) == filament_options_with_variant.end())
m_options_list.emplace(opt_key, m_opt_status_value);
else
m_options_list.emplace(opt_key + "#0", m_opt_status_value);
}
}
void Tab::get_sys_and_mod_flags(const std::string& opt_key, bool& sys_page, bool& modified_page)
@ -2473,11 +2481,11 @@ void TabPrintModel::update_model_config()
std::vector<std::string> global_diffs; // all diff keys to global config
for (auto & config : m_object_configs) {
all_keys = concat(all_keys, variant_keys(config.second->get()));
auto diffs = deep_diff(config.second->get(), global_config);
auto diffs = deep_diff(config.second->get(), global_config, false);
global_diffs = concat(global_diffs, diffs);
diff_config.apply_only(config.second->get(), diffs);
if (&config.second->get() == &local_config) continue;
local_diffs = concat(local_diffs, deep_diff(local_config, config.second->get(), true));
local_diffs = concat(local_diffs, deep_diff(local_config, config.second->get()));
}
m_null_keys = intersect(global_diffs, local_diffs);
m_config->apply(diff_config);
@ -3007,7 +3015,7 @@ void TabFilament::add_filament_overrides_page()
{
Line line {"",""};
//BBS
line = optgroup->create_single_option_line(optgroup->get_option(opt_key, 0));
line = optgroup->create_single_option_line(optgroup->get_option(opt_key, opt_index));
line.near_label_widget = [this, optgroup, opt_key, opt_index](wxWindow* parent) {
wxCheckBox* check_box = new wxCheckBox(parent, wxID_ANY, "");
@ -3083,9 +3091,9 @@ void TabFilament::update_filament_overrides_page()
"filament_retraction_distances_when_cut"
};
const int extruder_idx = 0; // #ys_FIXME
const int extruder_idx = m_variant_combo->GetSelection(); // #ys_FIXME
const bool have_retract_length = m_config->option("filament_retraction_length")->is_nil() ||
const bool have_retract_length = dynamic_cast<ConfigOptionVectorBase *>(m_config->option("filament_retraction_length"))->is_nil(extruder_idx) ||
m_config->opt_float("filament_retraction_length", extruder_idx) > 0;
for (const std::string& opt_key : opt_keys)
@ -3093,22 +3101,22 @@ void TabFilament::update_filament_overrides_page()
bool is_checked = opt_key=="filament_retraction_length" ? true : have_retract_length;
m_overrides_options[opt_key]->Enable(is_checked);
is_checked &= !m_config->option(opt_key)->is_nil();
is_checked &= !dynamic_cast<ConfigOptionVectorBase*>(m_config->option(opt_key))->is_nil(extruder_idx);
m_overrides_options[opt_key]->SetValue(is_checked);
Field* field = optgroup->get_fieldc(opt_key, extruder_idx);
Field* field = optgroup->get_fieldc(opt_key, 0);
if (field != nullptr) {
if (opt_key == "filament_long_retractions_when_cut") {
int machine_enabled_level = wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionInt>("enable_long_retraction_when_cut")->value;
bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament;
toggle_line(opt_key, machine_enabled);
toggle_line(opt_key, machine_enabled, extruder_idx + 256);
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<ConfigOptionInt>("enable_long_retraction_when_cut")->value;
bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament;
bool filament_enabled = m_config->option<ConfigOptionBools>("filament_long_retractions_when_cut")->values[extruder_idx] == 1;
toggle_line(opt_key, filament_enabled && machine_enabled);
toggle_line(opt_key, filament_enabled && machine_enabled, extruder_idx + 256);
field->toggle(is_checked && filament_enabled && machine_enabled);
}
else
@ -5856,7 +5864,9 @@ void Tab::switch_excluder(int extruder_id, bool reload)
{}, {"printer_extruder_id", "printer_extruder_variant"}, // Preset::TYPE_PRINTER
};
if (m_extruder_switch) {
int current_extruder = m_extruder_switch->IsEnabled() && m_extruder_switch->GetValue() ? 1 : 0;
int current_extruder = m_extruder_switch->IsThisEnabled() && m_extruder_switch->GetValue() ? 1 : 0;
m_variant_sizer->Show(2, m_extruder_switch->IsThisEnabled() && extruders->values[0] == extruders->values[1] &&
nozzle_volumes->values[0] == extruders->values[1]);
if (extruder_id == -1)
extruder_id = current_extruder;
else if (extruder_id != current_extruder)