FIX: fix create nozzle for exist printer issue

Jira: XXXX
copy some new parameter for new preset

Change-Id: If17f329eea541d9da332185367b2ea1b7972d2dd
Signed-off-by: maosheng.wei <maosheng.wei@bambulab.com>
This commit is contained in:
maosheng.wei 2023-10-23 15:55:50 +08:00 committed by Lane.Wei
parent 8c0ff69474
commit 1d08d427ac
3 changed files with 97 additions and 58 deletions

View File

@ -2104,15 +2104,14 @@ bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets,
modifier(preset, m_type); modifier(preset, m_type);
if (find_preset(preset.name)) { if (find_preset(preset.name)) {
failures.push_back(preset.name); failures.push_back(preset.name);
continue;
} }
preset.file = this->path_for_preset(preset); preset.file = this->path_for_preset(preset);
if (m_type == Preset::TYPE_PRINT) if (m_type == Preset::TYPE_PRINT)
preset.config.option<ConfigOptionString>("print_settings_id", true)->value = preset.name; preset.config.option<ConfigOptionString>("print_settings_id", true)->value.clear();
else if (m_type == Preset::TYPE_FILAMENT) else if (m_type == Preset::TYPE_FILAMENT)
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = preset.name; preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0].clear();
else if (m_type == Preset::TYPE_PRINTER) else if (m_type == Preset::TYPE_PRINTER)
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = preset.name; preset.config.option<ConfigOptionString>("printer_settings_id", true)->value.clear();
preset.updated_time = (long long) Slic3r::Utils::get_current_time_utc(); preset.updated_time = (long long) Slic3r::Utils::get_current_time_utc();
} }
if (!failures.empty() && !force_rewritten) if (!failures.empty() && !force_rewritten)
@ -2137,7 +2136,7 @@ bool PresetCollection::clone_presets(std::vector<Preset const *> const &presets,
bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer, bool force_rewritten) bool PresetCollection::clone_presets_for_printer(std::vector<Preset const *> const &presets, std::vector<std::string> &failures, std::string const &printer, bool force_rewritten)
{ {
return clone_presets(presets, failures, [printer](Preset &preset, Preset::Type &type) { return clone_presets(presets, failures, [printer](Preset &preset, Preset::Type &type) {
preset.name = preset.name.substr(0, preset.name.find("@")) + " @" + printer; preset.name = preset.name.substr(0, preset.name.find(" @")) + " @" + printer;
//preset.alias = ""; //preset.alias = "";
auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers")); auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
compatible_printers->values = std::vector<std::string>{ printer }; compatible_printers->values = std::vector<std::string>{ printer };
@ -2233,6 +2232,13 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name; BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name;
} }
//BBS: add lock logic for sync preset in background //BBS: add lock logic for sync preset in background
if (m_type == Preset::TYPE_PRINT)
preset.config.option<ConfigOptionString>("print_settings_id", true)->value.clear();
else if (m_type == Preset::TYPE_FILAMENT)
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0].clear();
else if (m_type == Preset::TYPE_PRINTER)
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value.clear();
final_inherits = preset.inherits(); final_inherits = preset.inherits();
unlock(); unlock();
// TODO: apply change from custom root to devided presets. // TODO: apply change from custom root to devided presets.
@ -2276,11 +2282,11 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det
else else
preset.is_project_embedded = false; preset.is_project_embedded = false;
if (m_type == Preset::TYPE_PRINT) if (m_type == Preset::TYPE_PRINT)
preset.config.option<ConfigOptionString >("print_settings_id", true)->value = preset.name; preset.config.option<ConfigOptionString>("print_settings_id", true)->value.clear();
else if (m_type == Preset::TYPE_FILAMENT) else if (m_type == Preset::TYPE_FILAMENT)
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = preset.name; preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0].clear();
else if (m_type == Preset::TYPE_PRINTER) else if (m_type == Preset::TYPE_PRINTER)
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = preset.name; preset.config.option<ConfigOptionString>("printer_settings_id", true)->value.clear();
//BBS: add lock logic for sync preset in background //BBS: add lock logic for sync preset in background
final_inherits = inherits; final_inherits = inherits;
unlock(); unlock();

View File

@ -1341,6 +1341,8 @@ VendorProfile PresetBundle::get_custom_vendor_models() const
iter_model->id = model; iter_model->id = model;
iter_model->name = model; iter_model->name = model;
iter_model->variants = {VendorProfile::PrinterVariant(variant)}; iter_model->variants = {VendorProfile::PrinterVariant(variant)};
} else {
iter_model->variants.push_back(VendorProfile::PrinterVariant(variant));
} }
} }
return vendor; return vendor;
@ -3011,7 +3013,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
PresetsConfigSubstitutions substitutions; PresetsConfigSubstitutions substitutions;
//BBS: add config related logs //BBS: add config related logs
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, path %1%, compatibility_rule %2%")%path.c_str()%compatibility_rule; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, path %1%, compatibility_rule %2%")%path.c_str()%compatibility_rule;
if (flags.has(LoadConfigBundleAttribute::ResetUserProfile) || flags.has(LoadConfigBundleAttribute::LoadSystem)) if (flags.has(LoadConfigBundleAttribute::ResetUserProfile) || flags.has(LoadConfigBundleAttribute::LoadSystem))
// Reset this bundle, delete user profile files if SaveImported. // Reset this bundle, delete user profile files if SaveImported.
this->reset(flags.has(LoadConfigBundleAttribute::SaveImported)); this->reset(flags.has(LoadConfigBundleAttribute::SaveImported));

View File

@ -95,7 +95,8 @@ static const std::unordered_map<std::string, std::vector<std::string>> printer_m
"Zero 120mm3", "Switchwire"}}, "Zero 120mm3", "Switchwire"}},
{"Zonestar", {"Z5", "Z6", "Z5x", "Z8", "Z9"}}}; {"Zonestar", {"Z5", "Z6", "Z5x", "Z8", "Z9"}}};
static const std::vector<std::string> nozzle_diameter = {"0.2","0.25", "0.3","0.35", "0.4", "0.5", "0.6","0.75", "0.8", "1.0", "1.2"}; static const std::vector<std::string> nozzle_diameter_vec = {"0.2","0.25", "0.3","0.35", "0.4", "0.5", "0.6","0.75", "0.8", "1.0", "1.2"};
static const std::unordered_map<std::string, float> nozzle_diameter_map = {{"0.2 nozzle", 0.2}, {"0.25 nozzle", 0.25}, {"0.3 nozzle", 0.3}, {"0.35 nozzle", 0.35}, {"0.4 nozzle", 0.4}, {"0.5 nozzle", 0.5}, {"0.6 nozzle", 0.6}, {"0.75 nozzle", 0.75}, {"0.8 nozzle", 0.8}, {"1.0 nozzle", 1.0}, {"1.2 nozzle", 1.2}};
static std::string get_curr_time() static std::string get_curr_time()
{ {
@ -1254,7 +1255,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_printer_item(wxWindow *parent)
e.Skip(); e.Skip();
}); });
m_select_printer = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY); m_select_printer = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, PRINTER_PRESET_MODEL_SIZE, 0, nullptr, wxCB_READONLY);
comboBoxSizer->Add(m_select_printer, 0, wxEXPAND | wxALL, 0); comboBoxSizer->Add(m_select_printer, 0, wxEXPAND | wxALL, 0);
m_select_printer->SetValue(_L("Select printer")); m_select_printer->SetValue(_L("Select printer"));
m_select_printer->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR); m_select_printer->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
@ -1348,13 +1349,14 @@ wxBoxSizer *CreatePrinterPresetDialog::create_nozzle_diameter_item(wxWindow *par
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL); wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_nozzle_diameter = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY); m_nozzle_diameter = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
wxArrayString nozzle_diameters; wxArrayString nozzle_diameters;
for (const std::string& nozzle : nozzle_diameter) { for (const std::string nozzle : nozzle_diameter_vec) {
nozzle_diameters.Add(nozzle + " nozzle"); nozzle_diameters.Add(nozzle + " nozzle");
} }
m_nozzle_diameter->Set(nozzle_diameters); m_nozzle_diameter->Set(nozzle_diameters);
m_nozzle_diameter->SetSelection(0); m_nozzle_diameter->SetSelection(0);
comboBoxSizer->Add(m_nozzle_diameter, 0, wxEXPAND | wxALL, 0); comboBoxSizer->Add(m_nozzle_diameter, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10)); horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
horizontal_sizer->Add(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(200));
return horizontal_sizer; return horizontal_sizer;
} }
@ -2029,8 +2031,16 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
MessageDialog dlg(this, _L("You have not yet chosen which printer preset to create based on. Please choose the vendor and model of the printer"), MessageDialog dlg(this, _L("You have not yet chosen which printer preset to create based on. Please choose the vendor and model of the printer"),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE); wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal(); dlg.ShowModal();
return;
show_page1(); show_page1();
return;
}
if (!save_printable_area_config(m_printer_preset)) {
MessageDialog dlg(this, _L("You have entered an illegal input in the printable area section on the first page. Please check before creating it."),
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
show_page1();
return;
} }
// create preset name // create preset name
@ -2051,13 +2061,12 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
} }
printer_preset_name = custom_vendor + " " + custom_model + " " + nozzle_diameter; printer_preset_name = custom_vendor + " " + custom_model + " " + nozzle_diameter;
printer_model_name = custom_vendor + " " + custom_model; printer_model_name = custom_vendor + " " + custom_model;
printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find("nozzle") - 1);
} else { } else {
std::string vender_name = into_u8(m_select_vendor->GetStringSelection()); std::string vender_name = into_u8(m_select_vendor->GetStringSelection());
std::string model_name = into_u8(m_select_model->GetStringSelection()); std::string model_name = into_u8(m_select_model->GetStringSelection());
printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter; printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter;
printer_model_name = vender_name + " " + model_name; printer_model_name = vender_name + " " + model_name;
printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find("nozzle") - 1);
} }
} else if (curr_selected_printer_type == m_create_type.create_nozzle) { } else if (curr_selected_printer_type == m_create_type.create_nozzle) {
std::string selected_printer_preset_name = into_u8(m_select_printer->GetStringSelection()); std::string selected_printer_preset_name = into_u8(m_select_printer->GetStringSelection());
@ -2067,9 +2076,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
std::shared_ptr<Preset> printer_preset = itor->second; std::shared_ptr<Preset> printer_preset = itor->second;
try{ try{
printer_model_name = printer_preset->config.opt_string("printer_model", true); printer_model_name = printer_preset->config.opt_string("printer_model", true);
printer_nozzle_name = printer_preset->config.opt_string("printer_variant", true);
printer_preset_name = printer_model_name + " " + nozzle_diameter; printer_preset_name = printer_model_name + " " + nozzle_diameter;
} }
catch (...) { catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " get config printer_model or , and the name is: " << selected_printer_preset_name; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " get config printer_model or , and the name is: " << selected_printer_preset_name;
@ -2079,6 +2086,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " don't get printer preset, and the name is: " << selected_printer_preset_name; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " don't get printer preset, and the name is: " << selected_printer_preset_name;
} }
} }
printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find("nozzle") - 1);
// Confirm if the printer preset has a duplicate name // Confirm if the printer preset has a duplicate name
if (!rewritten && preset_bundle->printers.find_preset(printer_preset_name)) { if (!rewritten && preset_bundle->printers.find_preset(printer_preset_name)) {
@ -2221,9 +2229,26 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent)
/****************************** clone printer preset ********************************/ /****************************** clone printer preset ********************************/
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":creater printer "; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":creater printer ";
save_printable_area_config(m_printer_preset); try {
m_printer_preset->config.opt_string("printer_model", true) = printer_model_name; auto printer_model = dynamic_cast<ConfigOptionString *>(m_printer_preset->config.option("printer_model", true));
m_printer_preset->config.opt_string("printer_variant") = printer_nozzle_name; if (printer_model)
printer_model->value = printer_model_name;
auto printer_variant = dynamic_cast<ConfigOptionString *>(m_printer_preset->config.option("printer_variant", true));
if (printer_variant)
printer_variant->value = printer_nozzle_name;
auto nozzle_diameter = dynamic_cast<ConfigOptionFloats *>(m_printer_preset->config.option("nozzle_diameter", true));
if (nozzle_diameter) {
std::unordered_map<std::string, float>::const_iterator iter = nozzle_diameter_map.find(printer_nozzle_name + " nozzle");
if (nozzle_diameter_map.end() != iter) {
nozzle_diameter->values = {iter->second};
}
}
}
catch (...) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " bisic info is not rewritten, may be printer_model, printer_variant, or nozzle_diameter";
}
preset_bundle->printers.save_current_preset(printer_preset_name, true, false, m_printer_preset); preset_bundle->printers.save_current_preset(printer_preset_name, true, false, m_printer_preset);
preset_bundle->update_compatible(PresetSelectCompatibleType::Always); preset_bundle->update_compatible(PresetSelectCompatibleType::Always);
EndModal(wxID_OK); EndModal(wxID_OK);
@ -2320,6 +2345,7 @@ void CreatePrinterPresetDialog::set_current_visible_printer()
m_printer_name_to_preset.clear(); m_printer_name_to_preset.clear();
for (const Preset &printer_preset : printer_presets) { for (const Preset &printer_preset : printer_presets) {
if (printer_preset.is_system || !printer_preset.is_visible) continue; if (printer_preset.is_system || !printer_preset.is_visible) continue;
if (preset_bundle->printers.get_preset_base(printer_preset)->name != printer_preset.name) continue;
printer_choice.push_back(wxString::FromUTF8(printer_preset.name)); printer_choice.push_back(wxString::FromUTF8(printer_preset.name));
m_printer_name_to_preset[printer_preset.name] = std::make_shared<Preset>(printer_preset); m_printer_name_to_preset[printer_preset.name] = std::make_shared<Preset>(printer_preset);
} }
@ -2454,46 +2480,51 @@ void CreatePrinterPresetDialog::clear_preset_combobox()
bool CreatePrinterPresetDialog::save_printable_area_config(Preset *preset) bool CreatePrinterPresetDialog::save_printable_area_config(Preset *preset)
{ {
DynamicPrintConfig &config = preset->config; const wxString curr_selected_printer_type = curr_create_printer_type();
DynamicPrintConfig &config = preset->config;
double x = 0; if (curr_selected_printer_type == m_create_type.create_printer) {
m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x); double x = 0;
double y = 0; m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x);
m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y); double y = 0;
double dx = 0; m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y);
m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx); double dx = 0;
double dy = 0; m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx);
m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy); double dy = 0;
//range check begin m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy);
if (x == 0 || y == 0) { // range check begin
return false; if (x == 0 || y == 0) { return false; }
} double x0 = 0.0;
double x0 = 0.0; double y0 = 0.0;
double y0 = 0.0; double x1 = x;
double x1 = x; double y1 = y;
double y1 = y; if (dx >= x || dy >= y) { return false; }
if (dx >= x || dy >= y) { x0 -= dx;
return false; x1 -= dx;
} y0 -= dy;
x0 -= dx; y1 -= dy;
x1 -= dx; // range check end
y0 -= dy; std::vector<Vec2d> points = {Vec2d(x0, y0), Vec2d(x1, y0), Vec2d(x1, y1), Vec2d(x0, y1)};
y1 -= dy; config.set_key_value("printable_area", new ConfigOptionPoints(points));
// range check end
std::vector<Vec2d> points = {Vec2d(x0, y0),
Vec2d(x1, y0),
Vec2d(x1, y1),
Vec2d(x0, y1)};
config.set_key_value("printable_area", new ConfigOptionPoints(points));
double max_print_height = 0; double max_print_height = 0;
m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height); m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height);
config.set("printable_height", max_print_height); config.set("printable_height", max_print_height);
std::regex regex("\\\\"); std::regex regex("\\\\");
m_custom_model = std::regex_replace(m_custom_model, regex, "/"); m_custom_model = std::regex_replace(m_custom_model, regex, "/");
m_custom_texture = std::regex_replace(m_custom_texture, regex, "/"); m_custom_texture = std::regex_replace(m_custom_texture, regex, "/");
config.set("bed_custom_model", m_custom_model); config.set("bed_custom_model", m_custom_model);
config.set("bed_custom_texture", m_custom_texture); config.set("bed_custom_texture", m_custom_texture);
} else if(m_create_type.create_nozzle){
std::string selected_printer_preset_name = into_u8(m_select_printer->GetStringSelection());
std::unordered_map<std::string, std::shared_ptr<Preset>>::iterator itor = m_printer_name_to_preset.find(selected_printer_preset_name);
assert(m_printer_name_to_preset.end() != itor);
if (m_printer_name_to_preset.end() != itor) {
std::shared_ptr<Preset> printer_preset = itor->second;
std::vector<std::string> keys = {"printable_area", "printable_height", "bed_custom_model", "bed_custom_texture"};
config.apply_only(printer_preset->config, keys, true);
}
}
return true; return true;
} }