diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 9cd0ffa3dd..1c45ce7db4 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -809,7 +809,7 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex key_values.emplace(BBL_JSON_KEY_VERSION, it.value()); } else if (boost::iequals(it.key(), BBL_JSON_KEY_IS_CUSTOM)) { - key_values.emplace(BBL_JSON_KEY_IS_CUSTOM, it.value()); + //skip it } else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { key_values.emplace(BBL_JSON_KEY_NAME, it.value()); @@ -1388,15 +1388,13 @@ ConfigSubstitutions ConfigBase::load_from_gcode_file(const std::string &file, Fo } //BBS: add json support -void ConfigBase::save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version, const std::string is_custom) const +void ConfigBase::save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const { json j; //record the headers j[BBL_JSON_KEY_VERSION] = version; j[BBL_JSON_KEY_NAME] = name; j[BBL_JSON_KEY_FROM] = from; - if (!is_custom.empty()) - j[BBL_JSON_KEY_IS_CUSTOM] = is_custom; //record all the key-values for (const std::string &opt_key : this->keys()) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index fb58ca4a14..95325cc5ab 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -2222,7 +2222,7 @@ public: void save(const std::string &file) const; //BBS: add json support - void save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version, const std::string is_custom = "") const; + void save_to_json(const std::string &file, const std::string &name, const std::string &from, const std::string &version) const; // Set all the nullable values to nils. void null_nullables(); diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index c239479a56..c3bb3196f9 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -536,13 +536,13 @@ void Preset::save(DynamicPrintConfig* parent_config) ConfigOption *opt_dst = temp_config.option(option, true); opt_dst->set(opt_src); } - temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined); + temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string()); } else if (!filament_id.empty() && inherits().empty()) { DynamicPrintConfig temp_config = config; temp_config.set_key_value(BBL_JSON_KEY_FILAMENT_ID, new ConfigOptionString(filament_id)); - temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined); + temp_config.save_to_json(this->file, this->name, from_str, this->version.to_string()); } else { - this->config.save_to_json(this->file, this->name, from_str, this->version.to_string(), this->custom_defined); + this->config.save_to_json(this->file, this->name, from_str, this->version.to_string()); } BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " save config for: " << this->name << " and filament_id: " << filament_id << " and base_id: " << this->base_id; @@ -744,13 +744,6 @@ bool Preset::has_lidar(PresetBundle *preset_bundle) return has_lidar; } -bool Preset::is_custom_defined() -{ - if (custom_defined == "1") - return true; - return false; -} - BedType Preset::get_default_bed_type(PresetBundle* preset_bundle) { if (config.has("default_bed_type") && !config.opt_string("default_bed_type").empty()) { @@ -1171,8 +1164,6 @@ void PresetCollection::load_presets( if (key_values.find(BBL_JSON_KEY_FILAMENT_ID) != key_values.end()) preset.filament_id = key_values[BBL_JSON_KEY_FILAMENT_ID]; - if (key_values.find(BBL_JSON_KEY_IS_CUSTOM) != key_values.end()) - preset.custom_defined = key_values[BBL_JSON_KEY_IS_CUSTOM]; if (key_values.find(BBL_JSON_KEY_DESCRIPTION) != key_values.end()) preset.description = key_values[BBL_JSON_KEY_DESCRIPTION]; if (key_values.find("instantiation") != key_values.end()) @@ -1198,13 +1189,13 @@ void PresetCollection::load_presets( preset.filament_id = inherit_preset->filament_id; } else { - // We support custom root preset now auto inherits_config2 = dynamic_cast(inherits_config); - if ((inherits_config2 && !inherits_config2->value.empty()) && !preset.is_custom_defined()) { - BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset.file; + if ((inherits_config2 && !inherits_config2->value.empty())) { + BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent %1% for config %2%!")%inherits_config2->value %preset.file; ++m_errors; continue; } + // We support custom root preset now // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field. preset.config = default_preset.config; } @@ -1274,9 +1265,7 @@ Preset* PresetCollection::get_preset_differed_for_save(Preset& preset) if (preset.is_system || preset.is_default) return nullptr; - Preset* new_preset = new Preset(); - *new_preset = preset; - + Preset* new_preset = nullptr; //BBS: only save difference for user preset std::string& inherits = preset.inherits(); Preset* parent_preset = nullptr; @@ -1284,15 +1273,46 @@ Preset* PresetCollection::get_preset_differed_for_save(Preset& preset) parent_preset = this->find_preset(inherits, false, true); } if (parent_preset) { + new_preset = new Preset(); + *new_preset = preset; + DynamicPrintConfig temp_config; std::vector dirty_options = preset.config.diff(parent_preset->config); + std::string extruder_id_name, extruder_variant_name; + std::set *key_set1 = nullptr, *key_set2 = nullptr; + Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2); + + if (!extruder_id_name.empty()) { + dirty_options.emplace_back(extruder_id_name); + } + if (!extruder_variant_name.empty()) { + dirty_options.emplace_back(extruder_variant_name); + } + for (auto option: dirty_options) { ConfigOption *opt_src = preset.config.option(option); ConfigOption *opt_dst = temp_config.option(option, true); - opt_dst->set(opt_src); + if (opt_dst->is_scalar() || !(opt_dst->nullable())) + opt_dst->set(opt_src); + else { + ConfigOptionVectorBase* opt_vec_src = static_cast(opt_src); + ConfigOptionVectorBase* opt_vec_dst = static_cast(opt_dst); + ConfigOptionVectorBase* opt_vec_inherit = static_cast(parent_preset->config.option(option)); + if (opt_vec_src->size() == 1) + opt_dst->set(opt_src); + else if (key_set1->find(option) != key_set1->end()) { + opt_vec_dst->set_with_nil(opt_vec_src, opt_vec_inherit, 1); + } + else if (key_set2->find(option) != key_set2->end()) { + opt_vec_dst->set_with_nil(opt_vec_src, opt_vec_inherit, 2); + } + else + opt_dst->set(opt_src); + } } + new_preset->config = temp_config; } @@ -1359,6 +1379,10 @@ void PresetCollection::load_project_embedded_presets(std::vector& proje std::vector::iterator it; BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size(); + std::string extruder_id_name, extruder_variant_name; + std::set *key_set1 = nullptr, *key_set2 = nullptr; + Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2); + lock(); for (it = project_presets.begin(); it != project_presets.end(); it++) { Preset* preset = *it; @@ -1396,11 +1420,13 @@ void PresetCollection::load_project_embedded_presets(std::vector& proje } else { // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field. - preset->config = default_preset.config; - BOOST_LOG_TRIVIAL(warning) << boost::format("can not find parent for config %1%!")%preset->file; - //continue; + //BBS 202407: don't load project embedded preset when can not find inherit + //preset->config = default_preset.config; + BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset->file; + continue; } - preset->config.apply(std::move(config)); + preset->config.update_diff_values_to_child_config(config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2); + //preset->config.apply(std::move(config)); Preset::normalize(preset->config); // Report configuration fields, which are misplaced into a wrong group. std::string incorrect_keys = Preset::remove_invalid_keys(preset->config, default_preset.config); @@ -1441,7 +1467,8 @@ std::vector PresetCollection::get_project_embedded_presets() Preset* new_preset = get_preset_differed_for_save(preset); - project_presets.push_back(new_preset); + if (new_preset) + project_presets.push_back(new_preset); } unlock(); BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size(); @@ -1571,33 +1598,29 @@ void PresetCollection::save_user_presets(const std::string& dir_path, const std: preset->sync_info.clear(); preset->file = path_for_preset(*preset); - if (preset->is_custom_defined()) { + //BBS: only save difference for user preset + std::string inherits = Preset::inherits(preset->config); + if (inherits.empty()) { + // We support custom root preset now + //BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name; + //// BBS add sync info + //preset->sync_info = "delete"; + //need_to_delete_list.push_back(preset->setting_id); + //delete_name_list.push_back(preset->name); preset->save(nullptr); - } else { - //BBS: only save difference for user preset - std::string inherits = Preset::inherits(preset->config); - if (inherits.empty()) { - // We support custom root preset now - //BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name; - //// BBS add sync info - //preset->sync_info = "delete"; - //need_to_delete_list.push_back(preset->setting_id); - //delete_name_list.push_back(preset->name); - preset->save(nullptr); - continue; - } - Preset* parent_preset = this->find_preset(inherits, false, true); - if (!parent_preset) { - ++m_errors; - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits; - continue; - } - - if (preset->base_id.empty()) - preset->base_id = parent_preset->setting_id; - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << preset->name << " filament_id: " << preset->filament_id << " base_id: " << preset->base_id; - preset->save(&(parent_preset->config)); + continue; } + Preset* parent_preset = this->find_preset(inherits, false, true); + if (!parent_preset) { + ++m_errors; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits; + continue; + } + + if (preset->base_id.empty()) + preset->base_id = parent_preset->setting_id; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << preset->name << " filament_id: " << preset->filament_id << " base_id: " << preset->base_id; + preset->save(&(parent_preset->config)); } for (auto delete_name: delete_name_list) @@ -1844,11 +1867,11 @@ bool PresetCollection::validate_preset(const std::string &preset_name, std::stri // Load a preset from an already parsed config file, insert it into the sorted sequence of presets // and select it, losing previous modifications. -Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select, Semver file_version, bool is_custom_defined) +Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select, Semver file_version) { DynamicPrintConfig cfg(this->default_preset().config); cfg.apply_only(config, cfg.keys(), true); - return this->load_preset(path, name, std::move(cfg), select, file_version, is_custom_defined); + return this->load_preset(path, name, std::move(cfg), select, file_version); } static bool profile_print_params_same(const DynamicPrintConfig &cfg_old, const DynamicPrintConfig &cfg_new) @@ -2123,7 +2146,7 @@ std::pair PresetCollection::load_external_preset( return std::make_pair(&preset, false); } -Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select, Semver file_version, bool is_custom_defined) +Preset& PresetCollection::load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select, Semver file_version) { lock(); auto it = this->find_preset_internal(name); @@ -2138,7 +2161,7 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string preset.config = std::move(config); preset.loaded = true; preset.is_dirty = false; - preset.custom_defined = is_custom_defined ? "1": "0"; + //BBS if (file_version.valid()) preset.version = file_version; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index c1095c4e87..e4edb5996b 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -250,7 +250,6 @@ public: std::string user_id; // preset user_id std::string base_id; // base id of preset std::string sync_info; // enum: "delete", "create", "update", "" - std::string custom_defined; // enum: "1", "0", "" std::string description; // long long updated_time{0}; //last updated time std::map key_values; @@ -475,8 +474,8 @@ public: // Load a preset from an already parsed config file, insert it into the sorted sequence of presets // and select it, losing previous modifications. - Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false); - Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true, Semver file_version = Semver(), bool is_custom_defined = false); + Preset& load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select = true, Semver file_version = Semver()); + Preset& load_preset(const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select = true, Semver file_version = Semver()); bool clone_presets(std::vector const &presets, std::vector &failures, std::function modifier, bool force_rewritten = false); bool clone_presets_for_printer( diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 0ab7c02c0b..7a4e802b06 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -2499,7 +2499,7 @@ ConfigSubstitutions PresetBundle::load_config_file(const std::string &path, Forw // Load a config file from a boost property_tree. This is a private method called from load_config_file. // is_external == false on if called from ConfigWizard -void PresetBundle::load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version, bool selected, bool is_custom_defined) +void PresetBundle::load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version, bool selected) { PrinterTechnology printer_technology = Preset::printer_technology(config); @@ -2604,7 +2604,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool [&config, &inherits, &inherits_values, &compatible_printers_condition, &compatible_printers_condition_values, &compatible_prints_condition, &compatible_prints_condition_values, - is_external, &name, &name_or_path, file_version, selected, is_custom_defined] + is_external, &name, &name_or_path, file_version, selected] (PresetCollection &presets, size_t idx, const std::string &key, const std::set &different_keys, std::string filament_id) { // Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles. inherits = inherits_values[idx]; @@ -2616,7 +2616,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool if (is_external) presets.load_external_preset(name_or_path, name, config.opt_string(key, true), config, different_keys, PresetCollection::LoadAndSelect::Always, file_version, filament_id); else - presets.load_preset(presets.path_from_name(name, inherits.empty()), name, config, selected, file_version, is_custom_defined).save(nullptr); + presets.load_preset(presets.path_from_name(name, inherits.empty()), name, config, selected, file_version).save(nullptr); }; switch (Preset::printer_technology(config)) { @@ -2685,7 +2685,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool loaded = this->filaments.load_external_preset(name_or_path, name, old_filament_profile_names->values.front(), config, filament_different_keys_set, PresetCollection::LoadAndSelect::Always, file_version, filament_id).first; else { // called from Config Wizard. - loaded= &this->filaments.load_preset(this->filaments.path_from_name(name, inherits.empty()), name, config, true, file_version, is_custom_defined); + loaded= &this->filaments.load_preset(this->filaments.path_from_name(name, inherits.empty()), name, config, true, file_version); loaded->save(nullptr); } this->filament_presets.clear(); diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 1fe3b576e1..a52fe2c83e 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -192,8 +192,8 @@ public: // Load user configuration and store it into the user profiles. // This method is called by the configuration wizard. - void load_config_from_wizard(const std::string &name, DynamicPrintConfig config, Semver file_version, bool is_custom_defined = false) - { this->load_config_file_config(name, false, std::move(config), file_version, true, is_custom_defined); } + void load_config_from_wizard(const std::string &name, DynamicPrintConfig config, Semver file_version) + { this->load_config_file_config(name, false, std::move(config), file_version, true); } // Load configuration that comes from a model file containing configuration, such as 3MF et al. // This method is called by the Plater. @@ -309,7 +309,7 @@ private: // Load print, filament & printer presets from a config. If it is an external config, then the name is extracted from the external path. // and the external config is just referenced, not stored into user profile directory. // If it is not an external config, then the config will be stored into the user profile directory. - void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version = Semver(), bool selected = false, bool is_custom_defined = false); + void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config, Semver file_version = Semver(), bool selected = false); /*ConfigSubstitutions load_config_file_config_bundle( const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule);*/ diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 4065c4e317..faeeea16b7 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -7990,15 +7990,6 @@ void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filamen } -bool DynamicPrintConfig::is_custom_defined() -{ - auto* is_custom_defined = dynamic_cast(this->option("is_custom_defined")); - if (!is_custom_defined || is_custom_defined->empty()) - return false; - if (is_custom_defined->get_at(0) == "1") - return true; - return false; -} //BBS: pass map to recording all invalid valies //FIXME localize this function. diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 129a94041f..d03b60d307 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -608,7 +608,6 @@ public: void update_values_to_printer_extruders(DynamicPrintConfig& printer_config, std::set& key_set, std::string id_name, std::string variant_name, unsigned int stride = 1, unsigned int extruder_id = 0); void update_values_to_printer_extruders_for_multiple_filaments(DynamicPrintConfig& printer_config, std::set& key_set, std::string id_name, std::string variant_name); - bool is_custom_defined(); }; extern std::set printer_extruder_options; extern std::set print_options_with_variant; diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index aeed5e47eb..063f7c088a 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -2599,7 +2599,7 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese custom_config->set_key_value("filament_colour", wxGetApp().preset_bundle->project_config.option("filament_colour")); const std::string profile_name = page_custom->profile_name(); Semver semver(SLIC3R_VERSION); - preset_bundle->load_config_from_wizard(profile_name, *custom_config, semver, true); + preset_bundle->load_config_from_wizard(profile_name, *custom_config, semver); wxGetApp().plater()->sidebar().update_presets(Slic3r::Preset::Type::TYPE_PRINTER); wxGetApp().plater()->sidebar().update_presets(Slic3r::Preset::Type::TYPE_FILAMENT); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 83533fcc9c..085d8b5636 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4721,7 +4721,6 @@ void GUI_App::sync_preset(Preset* preset) long long update_time = 0; // only sync user's preset if (!preset->is_user()) return; - if (preset->is_custom_defined()) return; auto setting_id = preset->setting_id; std::map values_map; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index ff030e111b..2672f74376 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -1460,8 +1460,7 @@ bool MainFrame::can_export_all_gcode() const bool MainFrame::can_print_3mf() const { if (m_plater && !m_plater->model().objects.empty()) { - if (wxGetApp().preset_bundle->printers.get_edited_preset().is_custom_defined()) - return false; + // } return true; }