Fix renamed_from feature and others

This commit is contained in:
SoftFever
2025-01-19 23:04:35 +08:00
parent 8188963e20
commit 206c6228a5
6 changed files with 83 additions and 79 deletions

View File

@@ -2523,6 +2523,17 @@ Preset* PresetCollection::find_preset(const std::string &name, bool first_visibl
first_visible_if_not_found ? &this->first_visible() : nullptr;
}
const Preset* PresetCollection::find_preset2(const std::string& name) const
{
auto preset = const_cast<PresetCollection*>(this)->find_preset(name, false, true);
if (preset == nullptr) {
auto _name = get_preset_name_renamed(name);
if(_name != nullptr)
preset = const_cast<PresetCollection*>(this)->find_preset(*_name, false, true);
}
return preset;
}
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
size_t PresetCollection::first_visible_idx() const
{

View File

@@ -596,6 +596,8 @@ public:
Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false, bool real = false);
const Preset* find_preset(const std::string &name, bool first_visible_if_not_found = false) const
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
// Orca: find preset, if not found, keep searching in the renamed history
const Preset* find_preset2(const std::string &name) const;
size_t first_visible_idx() const;
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.

View File

@@ -1,6 +1,7 @@
#include <cassert>
#include "PresetBundle.hpp"
#include "PrintConfig.hpp"
#include "libslic3r.h"
#include "Utils.hpp"
#include "Model.hpp"
@@ -1281,7 +1282,7 @@ std::pair<PresetsConfigSubstitutions, std::string> PresetBundle::load_system_pre
// Load the other vendor configs, merge them with this PresetBundle.
// Report duplicate profiles.
PresetBundle other;
append(substitutions, other.load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem, compatibility_rule).first);
append(substitutions, other.load_vendor_configs_from_json(dir.string(), vendor_name, PresetBundle::LoadSystem, compatibility_rule, this).first);
std::vector<std::string> duplicates = this->merge_presets(std::move(other));
if (! duplicates.empty()) {
errors_cummulative += "Found duplicated settings in vendor " + vendor_name + "'s json file lists: ";
@@ -3300,7 +3301,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
//BBS: Load a config bundle file from json
std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_from_json(
const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule)
const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle* base_bundle)
{
// Enable substitutions for user config bundle, throw an exception when loading a system profile.
ConfigSubstitutionContext substitution_context { compatibility_rule };
@@ -3509,7 +3510,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
PresetCollection *presets = nullptr;
size_t presets_loaded = 0;
auto parse_subfile = [this, path, vendor_name, presets_loaded, current_vendor_profile](
auto parse_subfile = [this, path, vendor_name, presets_loaded, current_vendor_profile, base_bundle](
ConfigSubstitutionContext& substitution_context,
PresetsConfigSubstitutions& substitutions,
LoadConfigBundleAttributes& flags,
@@ -3554,19 +3555,32 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
if (it1 != key_values.end()) {
inherits = it1->second;
auto it2 = config_maps.find(inherits);
if (it2 != config_maps.end()) {
default_config = nullptr;
if (it2 != config_maps.end())
default_config = &(it2->second);
if(default_config == nullptr && base_bundle != nullptr) {
auto base_it2 = base_bundle->m_config_maps.find(inherits);
if (base_it2 != base_bundle->m_config_maps.end())
default_config = &(base_it2->second);
}
if (default_config != nullptr) {
if (filament_id.empty() && (presets_collection->type() == Preset::TYPE_FILAMENT)) {
auto filament_id_map_iter = filament_id_maps.find(inherits);
if (filament_id_map_iter != filament_id_maps.end()) {
filament_id = filament_id_map_iter->second;
}
if (filament_id.empty() && base_bundle != nullptr) {
auto filament_id_map_iter = base_bundle->m_filament_id_maps.find(inherits);
if (filament_id_map_iter != base_bundle->m_filament_id_maps.end()) {
filament_id = filament_id_map_iter->second;
}
}
}
}
else {
++m_errors;
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": can not find inherits "<<inherits<<" for " << preset_name;
//throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name));
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": can not find inherits " << inherits << " for " << preset_name;
// throw ConfigurationError(format("can not find inherits %1% for %2%", inherits, preset_name));
reason = "Can not find inherits: " + inherits;
return reason;
}
@@ -3748,6 +3762,10 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
throw ConfigurationError((boost::format("Failed loading configuration file %1%\nSuggest cleaning the directory %2% firstly") % subfile_path % path).str());
}
}
if (vendor_name == ORCA_FILAMENT_LIBRARY) {
m_config_maps = configs;
m_filament_id_maps = filament_id_maps;
}
//3.3) paste the printers
presets = &this->printers;

View File

@@ -160,7 +160,12 @@ public:
// and the system profiles will point to the VendorProfile instances owned by PresetBundle::vendors.
VendorMap vendors;
struct ObsoletePresets {
// Orca: for OrcaFilamentLibrary
std::map<std::string, DynamicPrintConfig> m_config_maps;
std::map<std::string, std::string> m_filament_id_maps;
struct ObsoletePresets
{
std::vector<std::string> prints;
std::vector<std::string> sla_prints;
std::vector<std::string> filaments;
@@ -212,9 +217,9 @@ public:
// Don't do any config substitutions when loading a system profile, perform and report substitutions otherwise.
/*std::pair<PresetsConfigSubstitutions, size_t> load_configbundle(
const std::string &path, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule);*/
//BBS: add json related logic
//Orca: load config bundle from json, pass the base bundle to support cross vendor inheritance
std::pair<PresetsConfigSubstitutions, size_t> load_vendor_configs_from_json(
const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule);
const std::string &path, const std::string &vendor_name, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule, const PresetBundle* base_bundle = nullptr);
// Export a config bundle file containing all the presets and the names of the active presets.
//void export_configbundle(const std::string &path, bool export_system_settings = false, bool export_physical_printers = false);