Dead code removal and comment cleanup

This commit is contained in:
Lam Wei Lun
2026-08-25 14:17:56 +08:00
parent 0ba7bae794
commit d4cb739b8b
4 changed files with 43 additions and 97 deletions

View File

@@ -3056,9 +3056,11 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det
} }
// A detached standalone preset for the Full Publish receiver: create a user preset holding // A detached standalone preset for the Full Publish receiver: create a user preset holding
// the full resolved filament config (no inheritance, no vendor/alias links), parentless and // the full resolved filament config (no inheritance, no vendor/alias links), parentless.
// universally compatible. Mirrors save_current_preset(detach=true)'s creation branch but // Note: universal printer compatibility is not enforced here - callers apply
// does not force-select or diff against a parent; the caller decides whether to select it. // make_publish_universal() to the config before handing it over when they need it.
// Mirrors save_current_preset(detach=true)'s creation branch but does not force-select or
// diff against a parent; the caller decides whether to select it.
// The published entry's filament_id is forwarded so user bases keep their stable // The published entry's filament_id is forwarded so user bases keep their stable
// material grouping (get_filament_presets() groups user bases by filament_id). // material grouping (get_filament_presets() groups user bases by filament_id).
// save_to_project=true (the Full Publish default) creates a project-embedded preset: // save_to_project=true (the Full Publish default) creates a project-embedded preset:
@@ -3094,8 +3096,6 @@ std::string PresetCollection::add_detached_preset(const std::string &name_base,
lock(); lock();
const auto it = this->find_preset_internal(final_name); const auto it = this->find_preset_internal(final_name);
Preset &preset = *m_presets.insert(it, stored); Preset &preset = *m_presets.insert(it, stored);
stored.name.clear(); // avoid stale copied name being used below
stored.config.clear();
preset.name = final_name; preset.name = final_name;
preset.vendor = nullptr; preset.vendor = nullptr;
preset.alias.clear(); preset.alias.clear();
@@ -3103,7 +3103,7 @@ std::string PresetCollection::add_detached_preset(const std::string &name_base,
preset.m_excluded_from.clear(); preset.m_excluded_from.clear();
preset.setting_id.clear(); preset.setting_id.clear();
preset.inherits().clear(); preset.inherits().clear();
preset.version = Semver::parse(SoftFever_VERSION) ? *Semver::parse(SoftFever_VERSION) : Semver(); preset.version = Semver::parse(SoftFever_VERSION).value_or(Semver());
preset.is_default = false; preset.is_default = false;
preset.is_system = false; preset.is_system = false;
preset.is_external = false; preset.is_external = false;

View File

@@ -4921,25 +4921,21 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
// Material pass: positional per-slot entries. The author published, per slot, either the // Material pass: positional per-slot entries. The author published, per slot, either the
// entire filament (full) or specific keys plus optionally a curated type and/or colour. // entire filament (full) or specific keys plus optionally a curated type and/or colour.
// The receiver's slot is matched positionally against the published type: // - full: the slot always lands on a freshly created standalone detached copy
// - colour: always applied to the slot, independent of the type gate; // ("Detach from parent", project-embedded, universally compatible, within-load
// - type match: the full dump still applies wholesale (every setting, as if the slot's // deduped) - handled up front in the entry loop below; no library preset is ever
// filament had been loaded from a normal save); a partial entry's keys are applied // reused or mutated;
// as usual; // - partial: a type requirement gates the application - on type match (or no
// - type mismatch: the slot is replaced with the best visible candidate, scored by the // requirement) the keys are applied onto the slot's effective preset; on mismatch
// published identity (exact preset name resolved through the collection's name // the slot is replaced with the best visible candidate, scored by the published
// machinery, then exact setting_id, exact filament_id, then vendor+type, then type // identity (exact preset name resolved through the collection's name machinery,
// only); a preset no other slot references wins on equal scores, and a shared // then exact setting_id, exact filament_id, then vendor+type, then type only); a
// exact-material preset is taken even though mutating it also affects the other // preset no other slot references wins on equal scores; with no replacement
// slot; the author's values are applied on top of it (full) or the published keys // available the receiver's material is kept and the keys are reported as skipped;
// are applied (partial); // - colour: applied to the slot regardless of the type gate.
// - no replacement available: a full entry falls back to the first available visible // Applied partial values land on the collection's edited layer when the slot references
// preset, applying the author's values on top of it; a partial entry keeps the // it and that layer survives the load (visible as a modification, revertible, the user's
// receiver's material and reports its keys as skipped. // unsaved edits preserved), otherwise on the stored preset in place.
// All applied values (colour and keys) are written onto the slot's effective preset -
// the collection's edited layer when the slot references the edited preset (visible as
// a modification, revertible, the user's unsaved edits preserved), otherwise the stored
// preset in place: the receiver's material keeps its identity and is simply overridden.
// To keep slot-to-slot aliasing (several slots referencing one preset) from leaking one // To keep slot-to-slot aliasing (several slots referencing one preset) from leaking one
// slot's values into another, published slots sharing a preset with another slot are // slot's values into another, published slots sharing a preset with another slot are
// re-pointed at distinct presets before the values are applied. // re-pointed at distinct presets before the values are applied.
@@ -5521,64 +5517,10 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
if (score < 2 && (!entry.filament_id.empty() || !entry.filament_vendor.empty())) if (score < 2 && (!entry.filament_id.empty() || !entry.filament_vendor.empty()))
replacement_line += " (substitute: no exact material match)"; replacement_line += " (substitute: no exact material match)";
published_config->material_replacements.emplace_back(std::move(replacement_line)); published_config->material_replacements.emplace_back(std::move(replacement_line));
} else if (entry.full) {
// No same-type library preset: fall back to the first available
// visible preset, preferring one no other slot references, and
// apply the author's full values on top of it (the dump carries
// filament_type, so the preset takes the author's type). A preset
// of the published material's own family is preferred overall -
// except that a referenced preset must never win just on family,
// since the dump would mutate it for every sharing slot too.
std::string fallback;
const std::string wanted_family = !entry.publish_type_value.empty()
? entry.publish_type_value : normalize_filament_type(entry.filament_type);
auto pick_fallback = [&](bool want_family) -> std::string {
std::string first;
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
const Preset &candidate = this->filaments.preset(i);
if (!candidate.is_visible)
continue;
if (want_family) {
if (wanted_family.empty())
break;
const ConfigOptionStrings *cand_types = candidate.config.opt<ConfigOptionStrings>("filament_type");
if (normalize_filament_type(cand_types != nullptr && !cand_types->values.empty() ? cand_types->get_at(0) : std::string()) != wanted_family)
continue;
}
bool referenced = false;
for (size_t s = 0; s < this->filament_presets.size(); ++s)
if (this->filament_presets[s] == candidate.name) {
referenced = true;
break;
}
if (!referenced)
return candidate.name;
if (first.empty())
first = candidate.name;
}
return first;
};
if (!wanted_family.empty())
fallback = pick_fallback(true);
if (fallback.empty())
fallback = pick_fallback(false);
if (!fallback.empty() && fallback != recv->name) {
const std::string old_name = recv->name;
this->filament_presets[slot] = fallback;
recv = this->filaments.find_preset(fallback, false, true);
material_applied = true;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": published 3MF slot " << slot << " material " << old_name
<< " -> " << fallback << " (full-publish fallback, preset_name \""
<< entry.preset_name << "\", type \"" << entry.publish_type_value << "\")";
published_config->material_replacements.emplace_back(
"slot " + std::to_string(slot) + ": " + old_name + " -> " + fallback +
" (substitute: no " + entry.publish_type_value + " available)");
}
// No visible preset at all: keep the receiver's material and let
// the full dump mutate it below.
} else { } else {
// Partial publish with no replacement: keep the receiver's // Partial publish with no replacement: keep the receiver's
// material and report the slot's keys as skipped. // material and report the slot's keys as skipped. (Full entries
// never reach this gate: they detach above.)
for (const std::string &key : entry.keys) for (const std::string &key : entry.keys)
skipped_keys.emplace_back("material:" + material_label + " (" + key + ")"); skipped_keys.emplace_back("material:" + material_label + " (" + key + ")");
apply_slot = false; apply_slot = false;
@@ -5590,7 +5532,8 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
// layer when the slot references the collection's edited preset and that // layer when the slot references the collection's edited preset and that
// layer will survive the load (visible as a modification and revertible, // layer will survive the load (visible as a modification and revertible,
// preserving the user's unsaved edits), otherwise the stored preset it ended // preserving the user's unsaved edits), otherwise the stored preset it ended
// up on (original, type replacement or the full-publish fallback), in place. // up on (original or partial type replacement), in place. Full entries never
// get here - they detach above.
DynamicPrintConfig &write_config = (edited_survives_load && recv->name == this->filaments.get_edited_preset().name) DynamicPrintConfig &write_config = (edited_survives_load && recv->name == this->filaments.get_edited_preset().name)
? this->filaments.get_edited_preset().config ? this->filaments.get_edited_preset().config
: recv->config; : recv->config;
@@ -5619,7 +5562,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
} }
if (apply_slot && recv != nullptr) if (apply_slot && recv != nullptr)
apply_slot_keys(write_config, entry.full ? entry.full_keys : entry.keys, entry.slot, material_label); apply_slot_keys(write_config, entry.keys, entry.slot, material_label);
} }
} }
} }

View File

@@ -175,9 +175,10 @@ struct PublishedConfig
{ {
bool published = false; bool published = false;
std::vector<std::string> published_keys; std::vector<std::string> published_keys;
// Per-slot published material keys, applied positionally (author slot N -> receiver slot N), // Per-slot published material keys, applied positionally (author slot N -> receiver slot N).
// gated by the author's optional type requirement and written onto the slot's stored preset // Partial entries are gated by the author's optional type requirement and written onto the
// in place (see PublishedMaterialEntry in PublishSettings.hpp). // slot's stored preset in place; full entries instead detach (see PublishedMaterialEntry in
// PublishSettings.hpp).
std::vector<PublishedMaterialEntry> material_keys; std::vector<PublishedMaterialEntry> material_keys;
// Keys that could not be applied (missing on the user's machine or vector size mismatch), // Keys that could not be applied (missing on the user's machine or vector size mismatch),
// filled in by load_config_file_config for notification purposes. // filled in by load_config_file_config for notification purposes.

View File

@@ -35,19 +35,20 @@ const std::set<std::string>& publishable_printer_keys();
std::vector<std::string> collect_dirty_settings_keys(const PresetBundle& bundle); std::vector<std::string> collect_dirty_settings_keys(const PresetBundle& bundle);
// Per-slot published material keys, applied positionally (author slot N -> receiver slot N). // Per-slot published material keys, applied positionally (author slot N -> receiver slot N).
// The identity fields are carried for reference/notification labels only; the type gate // The identity fields drive the created copy's naming and grouping on Full entries, the
// (publish_type) is the author's explicit opt-in for requiring a material type. // notification labels, and the partial type gate (publish_type) is the author's explicit
// opt-in for requiring a material type.
struct PublishedMaterialEntry { struct PublishedMaterialEntry {
std::string filament_type; // material family, e.g. "PLA" (may be empty) std::string filament_type; // material family, e.g. "PLA" (may be empty)
std::string filament_vendor; // e.g. "Generic", "Bambu" (may be empty) std::string filament_vendor; // e.g. "Generic", "Bambu" (may be empty)
std::string filament_id; // stable material id, e.g. "GFL99" (may be empty) std::string filament_id; // stable material id, e.g. "GFL99" (may be empty)
// Unique preset id of the author's slot preset (e.g. Orca Filament Library "setting_id"); // Unique preset id of the author's slot preset (e.g. Orca Filament Library "setting_id").
// used on load to match the exact published variant, which filament_id alone cannot // Not matched against the receiver's library; carried so identical Full entries within one
// distinguish ("Generic PLA" and "Generic PLA Matte" share their inherited id). // load share one created instance (within-load dedup key).
std::string setting_id; std::string setting_id;
// Canonical name of the author's slot preset (e.g. "Generic PLA @System"). The receiver // Canonical name of the author's slot preset (e.g. "Generic PLA @System"). On Full import
// prefers an exact name/alias match over id matching: ids can be shared across variants // it names the created copy after its "@variant" tail is stripped; never matched against
// or missing from older files, the name is what the author actually selected. // the receiver's library.
std::string preset_name; std::string preset_name;
// 0-based author filament slot; -1 (hand-crafted files) is skipped. // 0-based author filament slot; -1 (hand-crafted files) is skipped.
int slot{-1}; int slot{-1};
@@ -63,9 +64,10 @@ struct PublishedMaterialEntry {
// All non-structural filament keys of the author's slot preset; values travel in the file // All non-structural filament keys of the author's slot preset; values travel in the file
// config, masked to the author's slot index. // config, masked to the author's slot index.
std::vector<std::string> full_keys; std::vector<std::string> full_keys;
// Vendor-agnostic (MaterialType) filament type the author requires for this slot; on // Vendor-agnostic (MaterialType) filament type the author requires for this slot; on a
// mismatch the slot is replaced with a same-type filament from the receiver's library. // partial entry's mismatch the slot is replaced with a same-type filament from the
// For Full entries the baked filament_type on the created copy satisfies the type gate. // receiver's library. Full entries consult no gate: they detach unconditionally, and the
// copy carries whatever values the payload bakes.
bool publish_type{false}; bool publish_type{false};
std::string publish_type_value; std::string publish_type_value;
// Required filament colour, applied on load regardless of the type match. // Required filament colour, applied on load regardless of the type match.