FIX: parameters modify of printer preset

Ensure correct behavior when modifying parameters of printer preset

Change-Id: Ic627a8e202bf4224b742336cc43ac611ddc5c997
This commit is contained in:
zhimin.zeng 2024-06-28 09:35:56 +08:00 committed by lane.wei
parent 8c8c9a967b
commit 366a14d8f7
8 changed files with 85 additions and 33 deletions

View File

@ -157,7 +157,7 @@ public:
ToolOrdering(const Print& print, unsigned int first_extruder, bool prime_multi_material = false);
void clear() {
m_layer_tools.clear(); m_tool_order_cache.clear();
m_layer_tools.clear(); m_tool_order_cache.clear();
}
// Only valid for non-sequential print:

View File

@ -5038,11 +5038,15 @@ std::set<std::string> filament_options_with_variant = {
"filament_extruder_variant"
};
std::set<std::string> printer_options_with_variant_1 = {
/*"extruder_type",
// Parameters that are the same as the number of extruders
std::set<std::string> printer_extruder_options = {
"extruder_type",
"nozzle_diameter",
"nozzle_volume_type".
"min_layer_height",
"nozzle_volume_type"
};
std::set<std::string> printer_options_with_variant_1 = {
/*"min_layer_height",
"max_layer_height",*/
//"retraction_length",
"z_hop",
@ -5315,6 +5319,33 @@ void handle_legacy_sla(DynamicPrintConfig &config)
}
}
size_t DynamicPrintConfig::get_parameter_size(const std::string& param_name, size_t extruder_nums)
{
if (extruder_nums > 1) {
size_t volume_type_size = 2;
auto nozzle_volume_type_opt = dynamic_cast<const ConfigOptionEnumsGeneric *>(this->option("nozzle_volume_type"));
if (nozzle_volume_type_opt) {
volume_type_size = nozzle_volume_type_opt->values.size();
}
if (printer_options_with_variant_1.count(param_name) > 0) {
return extruder_nums * volume_type_size;
}
else if (printer_options_with_variant_2.count(param_name) > 0) {
return extruder_nums * volume_type_size * 2;
}
else if (filament_options_with_variant.count(param_name) > 0) {
return extruder_nums * volume_type_size;
}
else if (print_options_with_variant.count(param_name) > 0) {
return extruder_nums * volume_type_size;
}
else {
return extruder_nums;
}
}
return extruder_nums;
}
void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders)
{
const auto &defaults = FullPrintConfig::defaults();
@ -5326,8 +5357,9 @@ void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders)
auto *opt = this->option(key, false);
assert(opt != nullptr);
assert(opt->is_vector());
if (opt != nullptr && opt->is_vector())
static_cast<ConfigOptionVectorBase*>(opt)->resize(num_extruders, defaults.option(key));
if (opt != nullptr && opt->is_vector()) {
static_cast<ConfigOptionVectorBase*>(opt)->resize(get_parameter_size(key, num_extruders), defaults.option(key));
}
}
}

View File

@ -476,6 +476,7 @@ public:
//return the changed param set
t_config_option_keys normalize_fdm_2(int num_objects, int used_filaments = 0);
size_t get_parameter_size(const std::string& param_name, size_t extruder_nums);
void set_num_extruders(unsigned int num_extruders);
// BBS
@ -503,6 +504,7 @@ public:
bool is_custom_defined();
};
extern std::set<std::string> printer_extruder_options;
extern std::set<std::string> print_options_with_variant;
extern std::set<std::string> filament_options_with_variant;
extern std::set<std::string> printer_options_with_variant_1;

View File

@ -20,17 +20,24 @@
namespace Slic3r { namespace GUI {
// BBS: new layout
constexpr int titleWidth = 20;
// BBS: new layout
constexpr int titleWidth = 20;
// get the param index of cur_exturder
int get_extruder_idx(const DynamicPrintConfig& config, const std::string &opt_key, int cur_extruder_id)
{
if (printer_extruder_options.find(opt_key) != printer_extruder_options.end()) {
return cur_extruder_id;
}
int extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count();
if (extruder_count == 1 || cur_extruder_id == -1)
return 0;
assert(cur_extruder_id < extruder_count);
auto opt_extruder_type = dynamic_cast<const ConfigOptionEnumsGeneric *>(config.option("extruder_type"));
auto opt_nozzle_volume_type = dynamic_cast<const ConfigOptionEnumsGeneric *>(config.option("nozzle_volume_type"));
const DynamicPrintConfig& cur_printer_config = wxGetApp().preset_bundle->printers.get_selected_preset().config;
auto opt_extruder_type = dynamic_cast<const ConfigOptionEnumsGeneric *>(cur_printer_config.option("extruder_type"));
auto opt_nozzle_volume_type = dynamic_cast<const ConfigOptionEnumsGeneric *>(cur_printer_config.option("nozzle_volume_type"));
if (!opt_extruder_type || !opt_nozzle_volume_type)
return 0;
@ -730,6 +737,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config,
auto opt_id = m_opt_map.find(opt_key)->first;
std::string opt_short_key = m_opt_map.at(opt_id).first;
int opt_index = m_opt_map.at(opt_id).second;
opt_index = get_extruder_idx(*m_config, opt_short_key, opt_index);
value = get_config_value(config, opt_short_key, opt_index);
}
@ -1295,17 +1303,11 @@ void ExtruderOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const
auto itOption = it->second;
const std::string& opt_key = itOption.first;
auto opt = m_config->option(opt_key);
const ConfigOptionVectorBase* opt_vec = dynamic_cast<const ConfigOptionVectorBase*>(opt);
if (opt_vec != nullptr) {
for (int opt_index = 0; opt_index < opt_vec->size(); opt_index++) {
this->change_opt_value(opt_key, value, opt_index);
}
}
else {
int opt_index = itOption.second;
this->change_opt_value(opt_key, value, opt_index == -1 ? 0 : opt_index);
int opt_index = itOption.second;
if (printer_extruder_options.find(opt_key) == printer_extruder_options.end()) {
opt_index = get_extruder_idx(*m_config, itOption.first, itOption.second);
}
this->change_opt_value(opt_key, value, opt_index == -1 ? 0 : opt_index);
}
OptionsGroup::on_change_OG(opt_id, value);

View File

@ -1521,7 +1521,7 @@ void Sidebar::update_presets(Preset::Type preset_type)
if (boost::algorithm::contains(extruder_variants->values[index], extruder + " " + nozzle_volumes_def->enum_labels[i])) {
if (nozzle_volumes->values[index] == i)
select = box.GetCount();
box.Append(_L(nozzle_volumes_def->enum_labels[i], {}, (void*)i));
box.Append(_L(nozzle_volumes_def->enum_labels[i]), {}, (void*)i);
}
}
box.SetSelection(select);

View File

@ -818,17 +818,28 @@ std::vector<std::string> Tab::filter_diff_option(const std::vector<std::string>
}
return std::make_pair(param_name, index);
}
return std::make_pair(value, 0);
return std::make_pair(value, -1);
};
std::vector<std::string> diff_options;
for (std::string option : options) {
auto name_to_index = get_name_and_index(option);
int active_index = get_extruder_idx(*m_config, name_to_index.first, m_active_page->m_extruder_idx);
if (active_index == name_to_index.second) {
std::string name_to_extruder_id = name_to_index.first + "#" + std::to_string(m_active_page->m_extruder_idx);
if (name_to_index.second == -1) {
diff_options.emplace_back(option);
continue;
}
size_t nozzle_nums = wxGetApp().preset_bundle->get_printer_extruder_count();
std::vector<int> support_indexes;
for (size_t i = 0; i < nozzle_nums; ++i) {
support_indexes.push_back(get_extruder_idx(*m_config, name_to_index.first, i));
}
auto iter = std::find(support_indexes.begin(), support_indexes.end(), name_to_index.second);
if (iter != support_indexes.end()) {
int extruder_id = std::distance(support_indexes.begin(), iter);
std::string name_to_extruder_id = name_to_index.first + "#" + std::to_string(extruder_id);
diff_options.emplace_back(name_to_extruder_id);
}
}
}
return diff_options;
@ -855,6 +866,7 @@ void Tab::update_changed_ui()
it.second = m_opt_status_value;
dirty_options = filter_diff_option(dirty_options);
nonsys_options = filter_diff_option(nonsys_options);
for (auto opt_key : dirty_options) {
m_options_list[opt_key] &= ~osInitValue;
@ -3896,7 +3908,7 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
// create a page, but pretend it's an extruder page, so we can add it to m_pages ourselves
auto page = add_options_page(L("Single extruder MM setup"), "printer", true);
auto optgroup = page->new_optgroup(L("Single extruder multimaterial parameters"));
if (from_initial_build)
page->clear();
else {
@ -3914,12 +3926,12 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
//# build page
//const wxString& page_name = wxString::Format("Extruder %d", int(extruder_idx + 1));
auto page = add_options_page(page_name, "empty", true);
page->m_extruder_idx = extruder_idx;
m_pages.insert(m_pages.begin() + n_before_extruders + extruder_idx, page);
auto optgroup = page->new_optgroup(L("Type"), L"param_type", -1, true);
optgroup->append_single_option_line("extruder_type", "", extruder_idx);
optgroup->append_single_option_line("nozzle_diameter", "", extruder_idx);
optgroup->append_single_option_line("nozzle_volume_type", "", extruder_idx);
optgroup->m_on_change = [this, extruder_idx](const t_config_option_key& opt_key, boost::any value)
{
@ -3952,9 +3964,8 @@ void TabPrinter::build_unregular_pages(bool from_initial_build/* = false*/)
// load_config(new_conf);
// }
//}
on_value_change(opt_key, value);
update_dirty();
on_value_change(opt_key, value);
update();
};
@ -5534,7 +5545,12 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep
return sizer;
}
void TabPrinter::set_extruder_volume_type(int extruder_id, NozzleVolumeType type) {}
void TabPrinter::set_extruder_volume_type(int extruder_id, NozzleVolumeType type)
{
auto nozzle_volumes = m_config->option<ConfigOptionEnumsGeneric>("nozzle_volume_type");
assert(nozzle_volumes->values.size() > (size_t)extruder_id);
nozzle_volumes->values[extruder_id] = type;
}
// Return a callback to create a TabPrinter widget to edit bed shape
wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent)

View File

@ -77,7 +77,6 @@ public:
// BBS
bool m_split_multi_line = false;
bool m_option_label_at_right = false;
int m_extruder_idx = 0; // if is multi extruder, recorde the page is belong to which extruder
public:
std::vector <ConfigOptionsGroupShp> m_optgroups;

View File

@ -164,6 +164,7 @@ int ComboBox::Append(const wxString &item,
icons.push_back(bitmap);
datas.push_back(clientData);
types.push_back(wxClientData_None);
SetClientDataType(wxClientData_Void);
drop.Invalidate();
return texts.size() - 1;
}