diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 22b5060d3..a2a0dc9d3 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -679,7 +679,7 @@ std::string Preset::get_printer_type(PresetBundle *preset_bundle) vendor_name = vendor_profile.first; return vendor_model.model_id; } - } + } } return ""; } @@ -1748,28 +1748,33 @@ void PresetCollection::update_after_user_presets_loaded() return; } -//BBS: validate_printers -bool PresetCollection::validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit) +//BBS: validate_preset +bool PresetCollection::validate_preset(const std::string &preset_name, std::string &inherit_name) { - std::string& original_name = config.opt_string("printer_settings_id", true); - std::deque::iterator it = this->find_preset_internal(original_name); - bool found = it != m_presets.end() && it->name == original_name && (it->is_system || it->is_default); + std::deque::iterator it = this->find_preset_internal(preset_name); + bool found = (it != m_presets.end()) && (it->name == preset_name) && (it->is_system || it->is_default); if (!found) { - it = this->find_preset_renamed(original_name); + it = this->find_preset_renamed(preset_name); found = it != m_presets.end() && (it->is_system || it->is_default); } if (!found) { - if (!inherit.empty()) { - it = this->find_preset_internal(inherit); - found = it != m_presets.end() && it->name == inherit && (it->is_system || it->is_default); + if (!inherit_name.empty()) { + it = this->find_preset_internal(inherit_name); + found = it != m_presets.end() && it->name == inherit_name && (it->is_system || it->is_default); + if (found) + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, found inherit in list")%preset_name %inherit_name; + else + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, can not found preset and inherit in list")%preset_name %inherit_name; } else { //inherit is null , should not happen , just consider it as valid found = false; - BOOST_LOG_TRIVIAL(warning) << boost::format(": name %1%, printer_settings %2%, no inherit, set to not found")%name %original_name; + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, no inherit, set to not found")%preset_name; } } - BOOST_LOG_TRIVIAL(warning) << boost::format(": name %1%, printer_settings %2%, inherit %3%, found result %4%")%name %original_name % inherit % found; + else { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, found in list")%preset_name; + } return found; } @@ -2152,7 +2157,7 @@ bool PresetCollection::clone_presets_for_filament(std::vector co { return clone_presets(presets, failures, [filament_name, filament_id, vendor_name](Preset &preset, Preset::Type &type) { preset.name = filament_name + " " + preset.name.substr(preset.name.find_last_of('@')); - if (type == Preset::TYPE_FILAMENT) + if (type == Preset::TYPE_FILAMENT) preset.config.option("filament_vendor", true)->values[0] = vendor_name; preset.filament_id = filament_id; }, diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 7b7f0223d..cb791d528 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -391,8 +391,8 @@ public: typedef std::function SyncFunc; //BBS get m_presets begin Iterator lbegin() { return m_presets.begin(); } - //BBS: validate_printers - bool validate_printers(const std::string &name, DynamicPrintConfig& config, std::string &inherit); + //BBS: validate_preset + bool validate_preset(const std::string &name, std::string &inherit); Iterator begin() { return m_presets.begin() + m_num_default_presets; } ConstIterator begin() const { return m_presets.cbegin() + m_num_default_presets; } diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index c8d874dcb..6b4b218a2 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -707,7 +707,7 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector status = mz_zip_reader_extract_to_file(&zip_archive, i, target_file_path.c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); // target file is opened - if (MZ_FALSE == status) { + if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << "Failed to open target file: " << target_file_path; } else { import_json_presets(substitutions, target_file_path, override_confirm, rule, overwrite, result); @@ -937,26 +937,79 @@ void PresetBundle::update_system_preset_setting_ids(std::map gcodes_key_set = {"filament_end_gcode", "filament_start_gcode", "change_filament_gcode", "layer_change_gcode", "machine_end_gcode", "machine_pause_gcode", "machine_start_gcode", "template_custom_gcode"}; +int PresetBundle::validate_presets(const std::string &file_name, DynamicPrintConfig& config, std::set& different_gcodes) { - // BBS TODO: -#if 0 - std::vector inherits_values; - PrinterTechnology printer_technology = Preset::printer_technology(config); - size_t num_extruders = (printer_technology == ptFFF) ? - std::min(config.option("nozzle_diameter" )->values.size(), - config.option("filament_diameter")->values.size()) : 1; - inherits_values.resize(num_extruders + 2, std::string()); - inherits_values = config.option("inherits_group", true)->values; + bool validated = false; + std::vector inherits_values = config.option("inherits_group", true)->values; + std::vector filament_preset_name = config.option("filament_settings_id", true)->values; + std::string printer_preset = config.option("printer_settings_id", true)->value; + bool has_different_settings_to_system = config.option("different_settings_to_system")?true:false; + std::vector different_values; + int ret = VALIDATE_PRESETS_SUCCESS; - std::string inherits; - if (inherits_values.size() >= (num_extruders + 2)) - inherits = inherits_values[num_extruders + 1]; + if (has_different_settings_to_system) + different_values = config.option("different_settings_to_system", true)->values; - return this->printers.validate_printers(name, config, inherits); -#else - return true; -#endif + //PrinterTechnology printer_technology = Preset::printer_technology(config); + size_t filament_count = config.option("filament_diameter")->values.size(); + inherits_values.resize(filament_count + 2, std::string()); + different_values.resize(filament_count + 2, std::string()); + filament_preset_name.resize(filament_count, std::string()); + + std::string printer_inherits = inherits_values[filament_count + 1]; + + validated = this->printers.validate_preset(printer_preset, printer_inherits); + if (!validated) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the printer preset not inherit from system") % file_name; + different_gcodes.emplace(printer_preset); + ret = VALIDATE_PRESETS_PRINTER_NOT_FOUND; + } + for(unsigned int index = 0; index < filament_count; index ++) + { + std::string filament_preset = filament_preset_name[index]; + std::string filament_inherits = inherits_values[index+1]; + + validated = this->filaments.validate_preset(filament_preset, filament_inherits); + if (!validated) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found the filament %2% preset not inherit from system") % file_name %(index+1); + different_gcodes.emplace(filament_preset); + ret = VALIDATE_PRESETS_FILAMENTS_NOT_FOUND; + } + } + + //self defined presets, return directly + if (ret) + { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found self defined presets, count %2%") %file_name %different_gcodes.size(); + return ret; + } + + for(unsigned int index = 1; index < filament_count+2; index ++) + { + std::string different_settingss = different_values[index]; + + std::vector different_keys; + + Slic3r::unescape_strings_cstyle(different_settingss, different_keys); + + for (unsigned int j = 0; j < different_keys.size(); j++) { + if (gcodes_key_set.find(different_keys[j]) != gcodes_key_set.end()) { + different_gcodes.emplace(different_keys[j]); + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":preset index %1%, different key %2%") %index %different_keys[j]; + } + } + } + + if (!different_gcodes.empty()) + { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(":file_name %1%, found different gcodes count %2%") %file_name %different_gcodes.size(); + return VALIDATE_PRESETS_MODIFIED_GCODES; + } + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":file_name %1%, validate presets success!") % file_name; + + return VALIDATE_PRESETS_SUCCESS; } void PresetBundle::remove_users_preset(AppConfig &config, std::map> *my_presets) diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index fd821d420..4349bb61e 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -12,6 +12,12 @@ #define DEFAULT_USER_FOLDER_NAME "default" #define BUNDLE_STRUCTURE_JSON_NAME "bundle_structure.json" +#define VALIDATE_PRESETS_SUCCESS 0 +#define VALIDATE_PRESETS_PRINTER_NOT_FOUND 1 +#define VALIDATE_PRESETS_FILAMENTS_NOT_FOUND 2 +#define VALIDATE_PRESETS_MODIFIED_GCODES 3 + + namespace Slic3r { // Bundle of Print + Filament + Printer presets. @@ -64,7 +70,7 @@ public: void update_system_preset_setting_ids(std::map>& system_presets); //BBS: add API to get previous machine - bool validate_printers(const std::string &name, DynamicPrintConfig& config); + int validate_presets(const std::string &file_name, DynamicPrintConfig& config, std::set& different_gcodes); //BBS: add function to generate differed preset for save //the pointer should be freed by the caller @@ -183,7 +189,7 @@ public: //void export_current_configbundle(const std::string &path); //BBS: add a function to export system presets for cloud-slicer //void export_system_configs(const std::string &path); - std::vector export_current_configs(const std::string &path, std::function override_confirm, + std::vector export_current_configs(const std::string &path, std::function override_confirm, bool include_modify, bool export_system_settings = false); // Enable / disable the "- default -" preset. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index bd607ba22..554368b1b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3491,22 +3491,30 @@ std::vector Plater::priv::load_files(const std::vector& input_ Preset::normalize(config); PresetBundle *preset_bundle = wxGetApp().preset_bundle; // BBS: first validate the printer - // TODO: remove it after released"" - bool validated = preset_bundle->validate_printers(filename.string(), config); - if (!validated) { - load_config = false; - load_old_project = true; - // select view to 3D - q->select_view_3D("3D"); - // select plate 0 as default - q->select_plate(0); - show_info(q, _L("The 3mf is not compatible, load geometry data only!"), _L("Incompatible 3mf")); - for (ModelObject *model_object : model.objects) { - model_object->config.reset(); - // Is there any modifier or advanced config data? - for (ModelVolume *model_volume : model_object->volumes) model_volume->config.reset(); - } - } else { + // validate the system profiles + std::set modified_gcodes; + int validated = preset_bundle->validate_presets(filename.string(), config, modified_gcodes); + if (validated == VALIDATE_PRESETS_MODIFIED_GCODES) { + std::string warning_message = L("The 3mf has following modified G-codes in filament or printer presets:"); + warning_message += "\n"; + for (std::set::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it) + warning_message += "-" + *it + "\n"; + warning_message += "\n"; + warning_message += L("Please confirm that these modified G-codes are safe to prevent any damage to the machine!"); + show_info(q, warning_message, _L("Modified G-codes")); + } + else if ((validated == VALIDATE_PRESETS_PRINTER_NOT_FOUND) || (validated == VALIDATE_PRESETS_FILAMENTS_NOT_FOUND)) { + std::string warning_message = L("The 3mf has following customized filament or printer presets:"); + warning_message += "\n"; + for (std::set::iterator it=modified_gcodes.begin(); it!=modified_gcodes.end(); ++it) + warning_message += "-" + *it + "\n"; + warning_message += "\n"; + warning_message += L("Please confirm that the G-codes within these presets are safe to prevent any damage to the machine!"); + show_info(q, warning_message, _L("Customized Preset")); + } + + //always load config + { preset_bundle->load_config_model(filename.string(), std::move(config), file_version); ConfigOption* bed_type_opt = preset_bundle->project_config.option("curr_bed_type"); @@ -4182,9 +4190,9 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type) out_path += output_file.extension().string(); boost::system::error_code ec; if (boost::filesystem::exists(into_u8(out_path), ec)) { - auto result = MessageBox(q->GetHandle(), - wxString::Format(_L("The file %s already exists\nDo you want to replace it?"), out_path), - _L("Comfirm Save As"), + auto result = MessageBox(q->GetHandle(), + wxString::Format(_L("The file %s already exists\nDo you want to replace it?"), out_path), + _L("Comfirm Save As"), MB_YESNO | MB_ICONWARNING); if (result != IDYES) return wxEmptyString; @@ -8364,7 +8372,7 @@ void Plater::import_model_id(wxString download_info) body, http_status, error); - + if (retry_count == max_retries) { msg = _L("Importing to Bambu Studio failed. Please download the file and manually import it."); cont = false;