Merge branch 'main' into feat/printer-agent-infra

This commit is contained in:
Ian Chua
2026-09-15 16:47:15 +08:00
committed by GitHub
31 changed files with 944 additions and 303 deletions
+38 -26
View File
@@ -485,7 +485,7 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ
else if (compatibility_rule == ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem)
compatibility_rule = ForwardCompatibilitySubstitutionRule::Disable;
auto collection_for_type = [](PresetBundle &bundle, Preset::Type preset_type) -> PresetCollection * {
auto collection_for_type = [](const PresetBundle &bundle, Preset::Type preset_type) -> const PresetCollection * {
switch (preset_type) {
case Preset::TYPE_PRINT: return &bundle.prints;
case Preset::TYPE_FILAMENT: return &bundle.filaments;
@@ -494,15 +494,15 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ
}
};
PresetCollection *collection = collection_for_type(*this, type);
const PresetCollection *collection = collection_for_type(*this, type);
if (collection == nullptr) {
error = "Unsupported preset type";
return false;
}
const boost::filesystem::path source_path = boost::filesystem::absolute(source_file).lexically_normal();
auto find_loaded = [&](PresetBundle &bundle) -> const Preset * {
PresetCollection *loaded_collection = collection_for_type(bundle, type);
auto find_loaded = [&](const PresetBundle &bundle) -> const Preset * {
const PresetCollection *loaded_collection = collection_for_type(bundle, type);
const Preset *resolved = nullptr;
for (const Preset &preset : loaded_collection->get_presets()) {
if (preset.file.empty())
@@ -550,30 +550,11 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ
continue;
try {
PresetBundle library_bundle;
const PresetBundle *base_bundle = nullptr;
if (vendor_id != ORCA_FILAMENT_LIBRARY &&
boost::filesystem::is_regular_file(root_dir / (std::string(ORCA_FILAMENT_LIBRARY) + ".json"))) {
library_bundle.m_preserve_vendor_source_paths = true;
library_bundle.load_vendor_configs_from_json(root_dir.string(), ORCA_FILAMENT_LIBRARY, LoadSystem,
compatibility_rule, nullptr, false);
if (library_bundle.error_count() != 0) {
error = "OrcaFilamentLibrary contains invalid presets";
return false;
}
base_bundle = &library_bundle;
}
PresetBundle source_bundle;
source_bundle.m_preserve_vendor_source_paths = true;
source_bundle.load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem,
compatibility_rule, base_bundle, false);
if (source_bundle.error_count() != 0) {
error = "Vendor bundle contains invalid presets";
const PresetBundle *loaded = load_source_vendor(root_dir, vendor_id, compatibility_rule, error);
if (loaded == nullptr)
return false;
}
const Preset *resolved = find_loaded(source_bundle);
const Preset *resolved = find_loaded(*loaded);
if (resolved == nullptr) {
if (error.empty())
error = "Source file is not an instantiated preset in its vendor manifest";
@@ -592,6 +573,37 @@ bool PresetBundle::resolve_preset_config(DynamicPrintConfig &config, Preset::Typ
return false;
}
const PresetBundle *PresetBundle::load_source_vendor(const boost::filesystem::path &root_dir,
const std::string &vendor_id,
ForwardCompatibilitySubstitutionRule compatibility_rule,
std::string &error)
{
auto key = std::make_tuple(root_dir.string(), vendor_id, compatibility_rule);
if (auto it = m_source_vendor_bundles.find(key); it != m_source_vendor_bundles.end())
return it->second.get();
// The library loads with no base of its own, so the tree a vendor inherits from
// is the same one that resolves the library's own presets.
const PresetBundle *library = nullptr;
if (vendor_id != ORCA_FILAMENT_LIBRARY &&
boost::filesystem::is_regular_file(root_dir / (std::string(ORCA_FILAMENT_LIBRARY) + ".json"))) {
library = load_source_vendor(root_dir, ORCA_FILAMENT_LIBRARY, compatibility_rule, error);
if (library == nullptr) {
error = "OrcaFilamentLibrary contains invalid presets";
return nullptr;
}
}
auto bundle = std::make_unique<PresetBundle>();
bundle->m_preserve_vendor_source_paths = true;
bundle->load_vendor_configs_from_json(root_dir.string(), vendor_id, LoadSystem, compatibility_rule, library, false);
if (bundle->error_count() != 0) {
error = "Vendor bundle contains invalid presets";
return nullptr;
}
return m_source_vendor_bundles.emplace(std::move(key), std::move(bundle)).first->second.get();
}
bool PresetBundle::resolve_preset_config_type(DynamicPrintConfig &config, Preset::Type &type,
const std::string &source_file,
ForwardCompatibilitySubstitutionRule compatibility_rule,