diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 1fd87f3e2a..e18bd7b951 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -451,6 +451,23 @@ void Preset::set_visible_from_appconfig(const AppConfig &app_config) } } +std::string Preset::trim_vendor_repo_prefix(const std::string& id) const +{ + return Preset::trim_vendor_repo_prefix(id, this->vendor); +} +std::string Preset::trim_vendor_repo_prefix(const std::string& id, const VendorProfile* vendor_profile) const +{ + if (!vendor_profile) { + return id; + } + std::string res = id; + if (boost::algorithm::starts_with(res, vendor_profile->repo_prefix)) { + boost::algorithm::erase_head(res, vendor_profile->repo_prefix.size()); + boost::algorithm::trim_left(res); + } + return res; +} + static std::vector s_Preset_print_options { "layer_height", "first_layer_height", "perimeters", "spiral_vase", "slice_closing_radius", "slicing_mode", "top_solid_layers", "top_solid_min_thickness", "bottom_solid_layers", "bottom_solid_min_thickness", diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 5bdf954a92..c2f3c35ee2 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -224,6 +224,10 @@ public: // Sort lexicographically by a preset name. The preset name shall be unique across a single PresetCollection. bool operator<(const Preset &other) const { return this->name < other.name; } + // Returns id without trimmed prefix if present and vendor has any. + std::string trim_vendor_repo_prefix(const std::string& id) const; + std::string trim_vendor_repo_prefix(const std::string& id, const VendorProfile* vendor_profile) const; + static const std::vector& print_options(); static const std::vector& filament_options(); // Printer options contain the nozzle options. diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index c84d12a812..4213acd872 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3888,20 +3888,8 @@ const Preset* find_preset_by_nozzle_and_options( for (const Preset &preset : collection) { // trim repo prefix std::string printer_model = preset.config.opt_string("printer_model"); - std::string vendor_repo_prefix; - if (preset.vendor) { - vendor_repo_prefix = preset.vendor->repo_prefix; - } else if (std::string inherits = preset.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - if (printer_model.find(vendor_repo_prefix) == 0) { - printer_model = printer_model.substr(vendor_repo_prefix.size() - ); - boost::trim_left(printer_model); - } + const PresetWithVendorProfile& printer_with_vendor = collection.get_preset_with_vendor_profile(preset); + printer_model = preset.trim_vendor_repo_prefix(printer_model, printer_with_vendor.vendor); if (!preset.is_system || printer_model != model_id) continue; diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index 4fee64e03b..d47205a9f1 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -732,13 +732,7 @@ void PhysicalPrinterDialog::update_host_type(bool printer_change) if (Preset* preset = wxGetApp().preset_bundle->printers.find_preset(preset_name)) { std::string model_id = preset->config.opt_string("printer_model"); if (preset->vendor) { - std::string model_id_no_pref = model_id; - std::string vendor_repo_prefix; - vendor_repo_prefix = preset->vendor->repo_prefix; - if (model_id_no_pref.find(vendor_repo_prefix) == 0) { - model_id_no_pref = model_id_no_pref.substr(vendor_repo_prefix.size()); - boost::trim_left(model_id_no_pref); - } + std::string model_id_no_pref = preset->trim_vendor_repo_prefix(model_id); if (preset->vendor->name.find("Prusa Research") != std::string::npos) { const std::vector& models = preset->vendor->models; auto it = std::find_if(models.begin(), models.end(), @@ -763,15 +757,7 @@ void PhysicalPrinterDialog::update_host_type(bool printer_change) break; } std::string model_id = preset->config.opt_string("printer_model"); - // remove prefix from printer_model - if (preset->vendor) { - std::string vendor_repo_prefix; - vendor_repo_prefix = preset->vendor->repo_prefix; - if (model_id.find(vendor_repo_prefix) == 0) { - model_id = model_id.substr(vendor_repo_prefix.size()); - boost::trim_left(model_id); - } - } + model_id = preset->trim_vendor_repo_prefix(model_id); if (preset->vendor && preset->vendor->name.find("Prusa Research") == std::string::npos) { connect.supported = false; break; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f9ba7eb4dd..39060650b0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2157,33 +2157,19 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool if (full_config.has("binary_gcode")) // needed for SLA full_config.set("binary_gcode", bool(full_config.opt_bool("binary_gcode") & wxGetApp().app_config->get_bool("use_binary_gcode_when_supported"))); + // Set printer_model in full_config a model without repo prefix (including inherited profiles) const Preset &selected_printer = wxGetApp().preset_bundle->printers.get_selected_preset(); - std::string printer_model_serialized = full_config.option("printer_model")->serialize(); + std::string printer_model = selected_printer.config.opt_string("printer_model"); + const PresetWithVendorProfile& printer_with_vendor = wxGetApp().preset_bundle->printers.get_preset_with_vendor_profile(selected_printer); + printer_model = selected_printer.trim_vendor_repo_prefix(printer_model, printer_with_vendor.vendor); + full_config.set("printer_model", printer_model); - const VendorProfile* vendor = nullptr; - std::string vendor_repo_prefix; if (selected_printer.vendor) { - vendor = selected_printer.vendor; - - } else if (std::string inherits = selected_printer.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - - if (vendor) { - vendor_repo_prefix = vendor->repo_prefix; // Passing extra info about preset vendor and version, so these can be inserted as metadata to GCode - full_config.set("profile_vendor", vendor->name, true); - full_config.set("profile_version", vendor->config_version.to_string(), true); + full_config.set("profile_vendor", selected_printer.vendor->name, true); + full_config.set("profile_version", selected_printer.vendor->config_version.to_string(), true); } - if (printer_model_serialized.find(vendor_repo_prefix) == 0) { - printer_model_serialized = printer_model_serialized.substr(vendor_repo_prefix.size()); - boost::trim_left(printer_model_serialized); - full_config.set("printer_model", printer_model_serialized); - } // If the update_background_process() was not called by the timer, kill the timer, // so the update_restart_background_process() will not be called again in vain. background_process_timer.Stop(); diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 5759f9c768..7d41ae02d9 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -979,20 +979,9 @@ static std::string get_connect_state_suffix_for_printer(const Preset& printer_pr for (const auto& [printer_model_nozzle_pair, states] : printer_state_map) { std::string printer_model = printer_preset.config.opt_string("printer_model"); - std::string vendor_repo_prefix; - if (printer_preset.vendor) { - vendor_repo_prefix = printer_preset.vendor->repo_prefix; - } else if (std::string inherits = printer_preset.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - if (printer_model.find(vendor_repo_prefix) == 0) { - printer_model = printer_model.substr(vendor_repo_prefix.size()); - boost::trim_left(printer_model); - } - + const PresetWithVendorProfile& printer_with_vendor = wxGetApp().preset_bundle->printers.get_preset_with_vendor_profile(printer_preset); + printer_model = printer_preset.trim_vendor_repo_prefix(printer_model, printer_with_vendor.vendor); + if (printer_preset.config.has("nozzle_diameter")) { double nozzle_diameter = static_cast(printer_preset.config.option("nozzle_diameter"))->values[0]; wxString nozzle_diameter_serialized = double_to_string(nozzle_diameter); @@ -1043,19 +1032,8 @@ static bool fill_data_to_connect_info_line( const Preset& printer_preset, for (const auto& [printer_model_nozzle_pair, states] : printer_state_map) { // get printer_model without repo prefix std::string printer_model = printer_preset.config.opt_string("printer_model"); - std::string vendor_repo_prefix; - if (printer_preset.vendor) { - vendor_repo_prefix = printer_preset.vendor->repo_prefix; - } else if (std::string inherits = printer_preset.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - if (printer_model.find(vendor_repo_prefix) == 0) { - printer_model = printer_model.substr(vendor_repo_prefix.size()); - boost::trim_left(printer_model); - } + const PresetWithVendorProfile& printer_with_vendor = wxGetApp().preset_bundle->printers.get_preset_with_vendor_profile(printer_preset); + printer_model = printer_preset.trim_vendor_repo_prefix(printer_model, printer_with_vendor.vendor); if (printer_preset.config.has("nozzle_diameter")) { double nozzle_diameter = static_cast(printer_preset.config.option("nozzle_diameter"))->values[0]; diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 1a07032103..2f09930358 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -577,19 +577,8 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF() { filament_abrasive_serialized += "]"; std::string printer_model_serialized = full_config.option("printer_model")->serialize(); - std::string vendor_repo_prefix; - if (selected_printer.vendor) { - vendor_repo_prefix = selected_printer.vendor->repo_prefix; - } else if (std::string inherits = selected_printer.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - if (printer_model_serialized.find(vendor_repo_prefix) == 0) { - printer_model_serialized = printer_model_serialized.substr(vendor_repo_prefix.size()); - boost::trim_left(printer_model_serialized); - } + const PresetWithVendorProfile& printer_with_vendor = wxGetApp().preset_bundle->printers.get_preset_with_vendor_profile(selected_printer); + printer_model_serialized = selected_printer.trim_vendor_repo_prefix(printer_model_serialized, printer_with_vendor.vendor); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized); const std::string filename = wxGetApp().plater()->get_upload_filename(); @@ -615,18 +604,9 @@ void PrinterPickWebViewDialog::request_compatible_printers_SLA() std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize(); std::string vendor_repo_prefix; - if (selected_printer.vendor) { - vendor_repo_prefix = selected_printer.vendor->repo_prefix; - } else if (std::string inherits = selected_printer.inherits(); !inherits.empty()) { - const Preset *parent = wxGetApp().preset_bundle->printers.find_preset(inherits); - if (parent && parent->vendor) { - vendor_repo_prefix = parent->vendor->repo_prefix; - } - } - if (printer_model_serialized.find(vendor_repo_prefix) == 0) { - printer_model_serialized = printer_model_serialized.substr(vendor_repo_prefix.size()); - boost::trim_left(printer_model_serialized); - } + const PresetWithVendorProfile& printer_with_vendor = wxGetApp().preset_bundle->printers.get_preset_with_vendor_profile(selected_printer); + printer_model_serialized = selected_printer.trim_vendor_repo_prefix(printer_model_serialized, printer_with_vendor.vendor); + const Preset& selected_material = wxGetApp().preset_bundle->sla_materials.get_selected_preset(); const std::string material_type_serialized = selected_material.config.option("material_type")->serialize(); const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized);