From 1d08d427acac0443fc60a70f20a476b44cef0f76 Mon Sep 17 00:00:00 2001 From: "maosheng.wei" Date: Mon, 23 Oct 2023 15:55:50 +0800 Subject: [PATCH] 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 --- src/libslic3r/Preset.cpp | 22 +++-- src/libslic3r/PresetBundle.cpp | 4 +- src/slic3r/GUI/CreatePresetsDialog.cpp | 129 +++++++++++++++---------- 3 files changed, 97 insertions(+), 58 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 644930ec6..4a98a9b87 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2104,15 +2104,14 @@ bool PresetCollection::clone_presets(std::vector const &presets, modifier(preset, m_type); if (find_preset(preset.name)) { failures.push_back(preset.name); - continue; } preset.file = this->path_for_preset(preset); if (m_type == Preset::TYPE_PRINT) - preset.config.option("print_settings_id", true)->value = preset.name; + preset.config.option("print_settings_id", true)->value.clear(); else if (m_type == Preset::TYPE_FILAMENT) - preset.config.option("filament_settings_id", true)->values[0] = preset.name; + preset.config.option("filament_settings_id", true)->values[0].clear(); else if (m_type == Preset::TYPE_PRINTER) - preset.config.option("printer_settings_id", true)->value = preset.name; + preset.config.option("printer_settings_id", true)->value.clear(); preset.updated_time = (long long) Slic3r::Utils::get_current_time_utc(); } if (!failures.empty() && !force_rewritten) @@ -2137,7 +2136,7 @@ bool PresetCollection::clone_presets(std::vector const &presets, bool PresetCollection::clone_presets_for_printer(std::vector const &presets, std::vector &failures, std::string const &printer, bool force_rewritten) { 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 = ""; auto *compatible_printers = dynamic_cast(preset.config.option("compatible_printers")); compatible_printers->values = std::vector{ 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; } //BBS: add lock logic for sync preset in background + + if (m_type == Preset::TYPE_PRINT) + preset.config.option("print_settings_id", true)->value.clear(); + else if (m_type == Preset::TYPE_FILAMENT) + preset.config.option("filament_settings_id", true)->values[0].clear(); + else if (m_type == Preset::TYPE_PRINTER) + preset.config.option("printer_settings_id", true)->value.clear(); final_inherits = preset.inherits(); unlock(); // 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 preset.is_project_embedded = false; if (m_type == Preset::TYPE_PRINT) - preset.config.option("print_settings_id", true)->value = preset.name; + preset.config.option("print_settings_id", true)->value.clear(); else if (m_type == Preset::TYPE_FILAMENT) - preset.config.option("filament_settings_id", true)->values[0] = preset.name; + preset.config.option("filament_settings_id", true)->values[0].clear(); else if (m_type == Preset::TYPE_PRINTER) - preset.config.option("printer_settings_id", true)->value = preset.name; + preset.config.option("printer_settings_id", true)->value.clear(); //BBS: add lock logic for sync preset in background final_inherits = inherits; unlock(); diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 454971f5c..6cbfba69b 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1341,6 +1341,8 @@ VendorProfile PresetBundle::get_custom_vendor_models() const iter_model->id = model; iter_model->name = model; iter_model->variants = {VendorProfile::PrinterVariant(variant)}; + } else { + iter_model->variants.push_back(VendorProfile::PrinterVariant(variant)); } } return vendor; @@ -3011,7 +3013,7 @@ std::pair PresetBundle::load_vendor_configs_ PresetsConfigSubstitutions substitutions; //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)) // Reset this bundle, delete user profile files if SaveImported. this->reset(flags.has(LoadConfigBundleAttribute::SaveImported)); diff --git a/src/slic3r/GUI/CreatePresetsDialog.cpp b/src/slic3r/GUI/CreatePresetsDialog.cpp index d5081072f..8250727e2 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.cpp +++ b/src/slic3r/GUI/CreatePresetsDialog.cpp @@ -95,7 +95,8 @@ static const std::unordered_map> printer_m "Zero 120mm3", "Switchwire"}}, {"Zonestar", {"Z5", "Z6", "Z5x", "Z8", "Z9"}}}; -static const std::vector 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 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 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() { @@ -1254,7 +1255,7 @@ wxBoxSizer *CreatePrinterPresetDialog::create_printer_item(wxWindow *parent) 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); m_select_printer->SetValue(_L("Select printer")); 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); m_nozzle_diameter = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY); wxArrayString nozzle_diameters; - for (const std::string& nozzle : nozzle_diameter) { + for (const std::string nozzle : nozzle_diameter_vec) { nozzle_diameters.Add(nozzle + " nozzle"); } m_nozzle_diameter->Set(nozzle_diameters); m_nozzle_diameter->SetSelection(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(0, 0, 0, wxEXPAND | wxLEFT, FromDIP(200)); 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"), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), wxYES | wxYES_DEFAULT | wxCENTRE); dlg.ShowModal(); - return; 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 @@ -2051,13 +2061,12 @@ wxBoxSizer *CreatePrinterPresetDialog::create_page2_btns_item(wxWindow *parent) } printer_preset_name = custom_vendor + " " + custom_model + " " + nozzle_diameter; printer_model_name = custom_vendor + " " + custom_model; - printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find("nozzle") - 1); } else { std::string vender_name = into_u8(m_select_vendor->GetStringSelection()); std::string model_name = into_u8(m_select_model->GetStringSelection()); printer_preset_name = vender_name + " " + model_name + " " + nozzle_diameter; 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) { 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 printer_preset = itor->second; try{ 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; - } catch (...) { 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; } } + printer_nozzle_name = nozzle_diameter.substr(0, nozzle_diameter.find("nozzle") - 1); // Confirm if the printer preset has a duplicate 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 ********************************/ BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":creater printer "; - save_printable_area_config(m_printer_preset); - m_printer_preset->config.opt_string("printer_model", true) = printer_model_name; - m_printer_preset->config.opt_string("printer_variant") = printer_nozzle_name; + try { + auto printer_model = dynamic_cast(m_printer_preset->config.option("printer_model", true)); + if (printer_model) + printer_model->value = printer_model_name; + + auto printer_variant = dynamic_cast(m_printer_preset->config.option("printer_variant", true)); + if (printer_variant) + printer_variant->value = printer_nozzle_name; + + auto nozzle_diameter = dynamic_cast(m_printer_preset->config.option("nozzle_diameter", true)); + if (nozzle_diameter) { + std::unordered_map::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->update_compatible(PresetSelectCompatibleType::Always); EndModal(wxID_OK); @@ -2320,6 +2345,7 @@ void CreatePrinterPresetDialog::set_current_visible_printer() m_printer_name_to_preset.clear(); for (const Preset &printer_preset : printer_presets) { 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)); m_printer_name_to_preset[printer_preset.name] = std::make_shared(printer_preset); } @@ -2454,46 +2480,51 @@ void CreatePrinterPresetDialog::clear_preset_combobox() 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; - m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x); - double y = 0; - m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y); - double dx = 0; - m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx); - double dy = 0; - m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy); - //range check begin - if (x == 0 || y == 0) { - return false; - } - double x0 = 0.0; - double y0 = 0.0; - double x1 = x; - double y1 = y; - if (dx >= x || dy >= y) { - return false; - } - x0 -= dx; - x1 -= dx; - y0 -= dy; - y1 -= dy; - // range check end - std::vector points = {Vec2d(x0, y0), - Vec2d(x1, y0), - Vec2d(x1, y1), - Vec2d(x0, y1)}; - config.set_key_value("printable_area", new ConfigOptionPoints(points)); + if (curr_selected_printer_type == m_create_type.create_printer) { + double x = 0; + m_bed_size_x_input->GetTextCtrl()->GetValue().ToDouble(&x); + double y = 0; + m_bed_size_y_input->GetTextCtrl()->GetValue().ToDouble(&y); + double dx = 0; + m_bed_origin_x_input->GetTextCtrl()->GetValue().ToDouble(&dx); + double dy = 0; + m_bed_origin_y_input->GetTextCtrl()->GetValue().ToDouble(&dy); + // range check begin + if (x == 0 || y == 0) { return false; } + double x0 = 0.0; + double y0 = 0.0; + double x1 = x; + double y1 = y; + if (dx >= x || dy >= y) { return false; } + x0 -= dx; + x1 -= dx; + y0 -= dy; + y1 -= dy; + // range check end + std::vector 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; - m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height); - config.set("printable_height", max_print_height); - std::regex regex("\\\\"); - m_custom_model = std::regex_replace(m_custom_model, regex, "/"); - m_custom_texture = std::regex_replace(m_custom_texture, regex, "/"); - config.set("bed_custom_model", m_custom_model); - config.set("bed_custom_texture", m_custom_texture); + double max_print_height = 0; + m_print_height_input->GetTextCtrl()->GetValue().ToDouble(&max_print_height); + config.set("printable_height", max_print_height); + std::regex regex("\\\\"); + m_custom_model = std::regex_replace(m_custom_model, regex, "/"); + m_custom_texture = std::regex_replace(m_custom_texture, regex, "/"); + config.set("bed_custom_model", m_custom_model); + 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>::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 printer_preset = itor->second; + std::vector keys = {"printable_area", "printable_height", "bed_custom_model", "bed_custom_texture"}; + config.apply_only(printer_preset->config, keys, true); + } + } return true; }