mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-10 10:47:16 +00:00
Dead code removal and comment cleanup
This commit is contained in:
@@ -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
|
||||
// the full resolved filament config (no inheritance, no vendor/alias links), parentless and
|
||||
// universally compatible. 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 full resolved filament config (no inheritance, no vendor/alias links), parentless.
|
||||
// Note: universal printer compatibility is not enforced here - callers apply
|
||||
// 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
|
||||
// material grouping (get_filament_presets() groups user bases by filament_id).
|
||||
// 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();
|
||||
const auto it = this->find_preset_internal(final_name);
|
||||
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.vendor = nullptr;
|
||||
preset.alias.clear();
|
||||
@@ -3103,7 +3103,7 @@ std::string PresetCollection::add_detached_preset(const std::string &name_base,
|
||||
preset.m_excluded_from.clear();
|
||||
preset.setting_id.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_system = false;
|
||||
preset.is_external = false;
|
||||
|
||||
@@ -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
|
||||
// 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:
|
||||
// - colour: always applied to the slot, independent of the type gate;
|
||||
// - type match: the full dump still applies wholesale (every setting, as if the slot's
|
||||
// filament had been loaded from a normal save); a partial entry's keys are applied
|
||||
// as usual;
|
||||
// - type mismatch: the slot is replaced with the best visible candidate, scored by the
|
||||
// published identity (exact preset name resolved through the collection's name
|
||||
// machinery, then exact setting_id, exact filament_id, then vendor+type, then type
|
||||
// only); a preset no other slot references wins on equal scores, and a shared
|
||||
// exact-material preset is taken even though mutating it also affects the other
|
||||
// slot; the author's values are applied on top of it (full) or the published keys
|
||||
// are applied (partial);
|
||||
// - no replacement available: a full entry falls back to the first available visible
|
||||
// preset, applying the author's values on top of it; a partial entry keeps the
|
||||
// receiver's material and reports its keys as skipped.
|
||||
// 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.
|
||||
// - full: the slot always lands on a freshly created standalone detached copy
|
||||
// ("Detach from parent", project-embedded, universally compatible, within-load
|
||||
// deduped) - handled up front in the entry loop below; no library preset is ever
|
||||
// reused or mutated;
|
||||
// - partial: a type requirement gates the application - on type match (or no
|
||||
// requirement) the keys are applied onto the slot's effective preset; on mismatch
|
||||
// the slot is replaced with the best visible candidate, scored by the published
|
||||
// identity (exact preset name resolved through the collection's name machinery,
|
||||
// then exact setting_id, exact filament_id, then vendor+type, then type only); a
|
||||
// preset no other slot references wins on equal scores; with no replacement
|
||||
// available the receiver's material is kept and the keys are reported as skipped;
|
||||
// - colour: applied to the slot regardless of the type gate.
|
||||
// Applied partial values land on the collection's edited layer when the slot references
|
||||
// it and that layer survives the load (visible as a modification, revertible, the user's
|
||||
// unsaved edits preserved), otherwise on the stored preset in place.
|
||||
// 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
|
||||
// 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()))
|
||||
replacement_line += " (substitute: no exact material match)";
|
||||
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 {
|
||||
// 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)
|
||||
skipped_keys.emplace_back("material:" + material_label + " (" + key + ")");
|
||||
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 will survive the load (visible as a modification and revertible,
|
||||
// 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)
|
||||
? this->filaments.get_edited_preset().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)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,9 +175,10 @@ struct PublishedConfig
|
||||
{
|
||||
bool published = false;
|
||||
std::vector<std::string> published_keys;
|
||||
// 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
|
||||
// in place (see PublishedMaterialEntry in PublishSettings.hpp).
|
||||
// Per-slot published material keys, applied positionally (author slot N -> receiver slot N).
|
||||
// Partial entries are gated by the author's optional type requirement and written onto the
|
||||
// slot's stored preset in place; full entries instead detach (see PublishedMaterialEntry in
|
||||
// PublishSettings.hpp).
|
||||
std::vector<PublishedMaterialEntry> material_keys;
|
||||
// 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.
|
||||
|
||||
@@ -35,19 +35,20 @@ const std::set<std::string>& publishable_printer_keys();
|
||||
std::vector<std::string> collect_dirty_settings_keys(const PresetBundle& bundle);
|
||||
|
||||
// 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
|
||||
// (publish_type) is the author's explicit opt-in for requiring a material type.
|
||||
// The identity fields drive the created copy's naming and grouping on Full entries, the
|
||||
// notification labels, and the partial type gate (publish_type) is the author's explicit
|
||||
// opt-in for requiring a material type.
|
||||
struct PublishedMaterialEntry {
|
||||
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_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");
|
||||
// used on load to match the exact published variant, which filament_id alone cannot
|
||||
// distinguish ("Generic PLA" and "Generic PLA Matte" share their inherited id).
|
||||
// Unique preset id of the author's slot preset (e.g. Orca Filament Library "setting_id").
|
||||
// Not matched against the receiver's library; carried so identical Full entries within one
|
||||
// load share one created instance (within-load dedup key).
|
||||
std::string setting_id;
|
||||
// Canonical name of the author's slot preset (e.g. "Generic PLA @System"). The receiver
|
||||
// prefers an exact name/alias match over id matching: ids can be shared across variants
|
||||
// or missing from older files, the name is what the author actually selected.
|
||||
// Canonical name of the author's slot preset (e.g. "Generic PLA @System"). On Full import
|
||||
// it names the created copy after its "@variant" tail is stripped; never matched against
|
||||
// the receiver's library.
|
||||
std::string preset_name;
|
||||
// 0-based author filament slot; -1 (hand-crafted files) is skipped.
|
||||
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
|
||||
// config, masked to the author's slot index.
|
||||
std::vector<std::string> full_keys;
|
||||
// Vendor-agnostic (MaterialType) filament type the author requires for this slot; on
|
||||
// mismatch the slot is replaced with a same-type filament from the receiver's library.
|
||||
// For Full entries the baked filament_type on the created copy satisfies the type gate.
|
||||
// Vendor-agnostic (MaterialType) filament type the author requires for this slot; on a
|
||||
// partial entry's mismatch the slot is replaced with a same-type filament from the
|
||||
// receiver's library. Full entries consult no gate: they detach unconditionally, and the
|
||||
// copy carries whatever values the payload bakes.
|
||||
bool publish_type{false};
|
||||
std::string publish_type_value;
|
||||
// Required filament colour, applied on load regardless of the type match.
|
||||
|
||||
Reference in New Issue
Block a user