mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-16 21:42:43 +00:00
Bug fixes and test cases for import filament of published 3MF. Update translations
This commit is contained in:
+216
-346
@@ -4752,9 +4752,8 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
}
|
||||
} // !is_published
|
||||
|
||||
// 4) Load the project config values (the per extruder wipe matrix etc).
|
||||
// In published mode the receiver must not inherit the author's filament/purge data,
|
||||
// so only the plate/bed geometry project keys are applied.
|
||||
// Load the project config values. In published mode only the plate/bed geometry keys
|
||||
// cross over (the receiver must not inherit the author's filament/purge data).
|
||||
this->project_config.apply_only(config, is_published ? s_project_options_published : s_project_options);
|
||||
|
||||
break;
|
||||
@@ -4774,29 +4773,23 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
this->update_compatible(PresetSelectCompatibleType::Never);
|
||||
this->update_multi_material_filament_presets();
|
||||
|
||||
// A "published" 3MF project overlays only the author-selected published keys onto the
|
||||
// user's currently-selected (edited) process preset. Scalar keys are applied directly;
|
||||
// vector (multi-extruder) keys are applied only when the edited preset has a matching
|
||||
// vector size. Keys that cannot be applied are collected for notification; legacy
|
||||
// filament/printer keys in a published file fall through into skipped_keys.
|
||||
// A "published" 3MF project overlays the author-selected published keys onto the user's
|
||||
// currently-selected (edited) process preset. Keys that cannot be applied are collected for
|
||||
// notification; filament-class keys in published_keys (which only the material pass knows
|
||||
// how to apply) fall through into skipped_keys.
|
||||
if (is_published) {
|
||||
std::vector<std::string> skipped_keys;
|
||||
std::set<std::string> applied_keys;
|
||||
// Set whenever the material overlay actually modifies a receiver filament preset
|
||||
// (applied key, colour or slot replacement). Only then must the edited preset be
|
||||
// re-snapshotted: re-selecting unconditionally would discard the user's unsaved
|
||||
// in-memory filament edits when the published file touches nothing.
|
||||
// Only re-select the edited filament preset when the material overlay changed
|
||||
// something: re-selecting unconditionally would discard the user's unsaved in-memory
|
||||
// filament edits when the published file touches nothing.
|
||||
bool material_applied = false;
|
||||
// Structural keys must never be applied to the user's presets: doing so would
|
||||
// rewrite their preset inheritance/structure. This is the single source of truth
|
||||
// shared with PublishSettingsDialog.cpp (publish_structural_keys in
|
||||
// PublishSettings.hpp). Defense-in-depth: a hand-crafted 3MF could set
|
||||
// published_keys to these regardless of the dialog, so skip them here too.
|
||||
// Structural keys are never applied (they would rewrite the user's preset
|
||||
// inheritance/structure). Defense-in-depth: a hand-crafted 3MF could list them despite
|
||||
// the dialog, so skip them here too.
|
||||
const std::set<std::string> &structural_keys = publish_structural_keys();
|
||||
// The printer overlay is restricted to the publishable retraction/z-hop allowlist.
|
||||
// Printer-class keys outside it are contract-excluded: never applied and never
|
||||
// reported as skipped (a hand-crafted 3MF listing machine_start_gcode or
|
||||
// nozzle_diameter must not apply them and must not spam the warning).
|
||||
// The printer overlay is restricted to the publishable retraction/z-hop allowlist;
|
||||
// printer-class keys outside it are contract-excluded (never applied, never reported).
|
||||
const std::set<std::string> &printer_allowlist = publishable_printer_keys();
|
||||
const std::vector<std::string> &printer_options = Preset::printer_options();
|
||||
const std::set<std::string> printer_option_set(printer_options.begin(), printer_options.end());
|
||||
@@ -4805,10 +4798,10 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
for (const std::string &key : published_config->published_keys) {
|
||||
if (applied_keys.count(key) != 0)
|
||||
continue; // already applied
|
||||
// A '#' suffix denotes a variant (per-extruder/per-filament) key; resolve the base key.
|
||||
// A '#' suffix denotes a variant key; resolve the base key.
|
||||
const std::string base_key = key.substr(0, key.find('#'));
|
||||
// Structural keys are intentionally never applied (not "skipped due to
|
||||
// mismatch"), so bail out before the applied/skipped bookkeeping.
|
||||
// Structural keys are never applied (not "skipped due to mismatch"), so bail
|
||||
// out before the applied/skipped bookkeeping.
|
||||
if (structural_keys.count(base_key) != 0)
|
||||
continue;
|
||||
if (allowlist != nullptr &&
|
||||
@@ -4822,23 +4815,29 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
if (src_opt == nullptr)
|
||||
continue; // key not present in the loaded config; record later
|
||||
if (src_opt->is_vector()) {
|
||||
// Vector key: apply only when the edited preset has a matching vector size.
|
||||
const ConfigOption *dst_opt = target.option(base_key);
|
||||
if (dst_opt == nullptr || !dst_opt->is_vector() ||
|
||||
static_cast<const ConfigOptionVectorBase*>(src_opt)->size() != static_cast<const ConfigOptionVectorBase*>(dst_opt)->size())
|
||||
if (dst_opt == nullptr || !dst_opt->is_vector())
|
||||
continue; // cannot apply; will be reported as skipped
|
||||
// A '#' variant index must be in range: ConfigOptionVector::set_at would
|
||||
// otherwise resize the destination vector, corrupting the receiver's preset.
|
||||
// A '#N' variant key (e.g. per-extruder retraction_length#2) applies one
|
||||
// element, so the index only needs to be in range on both sides - the
|
||||
// receiver may have a different extruder count than the author. Out-of-range
|
||||
// indices are skipped (set_at would otherwise resize the receiver's vector).
|
||||
if (key.size() > base_key.size()) {
|
||||
const size_t idx = static_cast<size_t>(std::atoi(key.c_str() + base_key.size() + 1));
|
||||
if (idx >= static_cast<const ConfigOptionVectorBase*>(src_opt)->size())
|
||||
if (idx >= static_cast<const ConfigOptionVectorBase*>(src_opt)->size() ||
|
||||
idx >= static_cast<const ConfigOptionVectorBase*>(dst_opt)->size())
|
||||
continue; // out-of-range variant: cannot apply; reported as skipped
|
||||
} else if (static_cast<const ConfigOptionVectorBase*>(src_opt)->size() !=
|
||||
static_cast<const ConfigOptionVectorBase*>(dst_opt)->size()) {
|
||||
// Whole-vector base key: the receiver must have a matching vector size,
|
||||
// otherwise applying would overwrite a different number of elements.
|
||||
continue; // cannot apply; will be reported as skipped
|
||||
}
|
||||
target.apply_only(config, {key}, true);
|
||||
applied_keys.insert(key);
|
||||
} else {
|
||||
// A scalar key cannot carry a '#N' variant suffix; a hand-crafted file
|
||||
// listing one is reported as skipped instead of being silently marked applied.
|
||||
// A scalar key cannot carry a '#N' suffix; a hand-crafted file listing one
|
||||
// is reported as skipped instead of being silently marked applied.
|
||||
if (key.find('#') != std::string::npos)
|
||||
continue;
|
||||
// Scalar key: apply only if present on the user's machine.
|
||||
@@ -4852,229 +4851,87 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
apply_published(this->prints.get_edited_preset().config, nullptr);
|
||||
apply_published(this->printers.get_edited_preset().config, &printer_allowlist);
|
||||
|
||||
// Material pass: apply the author's material-qualified keys onto the receiver's
|
||||
// matching filament presets. The file config carries the author's per-slot identity
|
||||
// (filament_type / filament_vendor remain in config; filament_ids was moved into a
|
||||
// local earlier) and the per-slot material retraction values.
|
||||
if (!published_config->material_keys.empty()) {
|
||||
const ConfigOptionStrings *file_types = config.option<ConfigOptionStrings>("filament_type");
|
||||
const ConfigOptionStrings *file_vendors = config.option<ConfigOptionStrings>("filament_vendor");
|
||||
auto identity_matches = [](const std::string &id, const std::string &type, const std::string &vendor,
|
||||
const std::string &slot_id, const std::string &slot_type, const std::string &slot_vendor) {
|
||||
// When both sides carry a filament_id, equality is required; otherwise fall
|
||||
// back to filament_type, with filament_vendor as an additional qualifier only
|
||||
// when both sides have a non-empty vendor.
|
||||
if (!id.empty() && !slot_id.empty())
|
||||
return id == slot_id;
|
||||
if (type.empty() || type != slot_type)
|
||||
return false;
|
||||
if (!vendor.empty() && !slot_vendor.empty())
|
||||
return vendor == slot_vendor;
|
||||
return true;
|
||||
};
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys) {
|
||||
// Entries using the filament-publishing-v2 features (full dump, published type or
|
||||
// colour) are handled by the positional per-slot pass below; the legacy identity
|
||||
// matching here applies only to files that predate those features.
|
||||
if (entry.full || entry.publish_type || entry.publish_color)
|
||||
continue;
|
||||
// Resolve the author's source slot and its ordinal among the author slots
|
||||
// carrying this entry's identity. A slotted entry (slot >= 0) names the exact
|
||||
// author slot and targets the receiver's Nth matching preset (N = ordinal);
|
||||
// a legacy entry (slot -1) uses the first matching author slot and applies to
|
||||
// every matching receiver preset.
|
||||
auto slot_identity = [&filament_ids, file_types, file_vendors](size_t slot, std::string &id, std::string &type, std::string &vendor) {
|
||||
id = (slot < filament_ids.size()) ? filament_ids[slot] : std::string();
|
||||
type = (file_types && slot < file_types->size()) ? file_types->get_at(slot) : std::string();
|
||||
vendor = (file_vendors && slot < file_vendors->size()) ? file_vendors->get_at(slot) : std::string();
|
||||
};
|
||||
bool author_found = false;
|
||||
size_t author_slot = 0;
|
||||
size_t author_ordinal = 0;
|
||||
if (entry.slot >= 0) {
|
||||
// Collect every author slot carrying this identity, in slot order; the
|
||||
// entry's slot must be among them, and its position is the ordinal used
|
||||
// to pick the receiver's matching preset.
|
||||
std::vector<size_t> matching_author_slots;
|
||||
for (size_t slot = 0; slot < filament_ids.size(); ++slot) {
|
||||
std::string slot_id, slot_type, slot_vendor;
|
||||
slot_identity(slot, slot_id, slot_type, slot_vendor);
|
||||
if (identity_matches(entry.filament_id, entry.filament_type, entry.filament_vendor,
|
||||
slot_id, slot_type, slot_vendor))
|
||||
matching_author_slots.emplace_back(slot);
|
||||
}
|
||||
const auto ordinal_it = std::find(matching_author_slots.begin(), matching_author_slots.end(), size_t(entry.slot));
|
||||
if (ordinal_it != matching_author_slots.end()) {
|
||||
author_slot = size_t(entry.slot);
|
||||
author_ordinal = size_t(ordinal_it - matching_author_slots.begin());
|
||||
author_found = true;
|
||||
}
|
||||
// Out of range, or the slot does not carry this identity: silent skip below.
|
||||
} else {
|
||||
// Legacy: the first author slot whose identity matches.
|
||||
for (size_t slot = 0; slot < filament_ids.size(); ++slot) {
|
||||
std::string slot_id, slot_type, slot_vendor;
|
||||
slot_identity(slot, slot_id, slot_type, slot_vendor);
|
||||
if (identity_matches(entry.filament_id, entry.filament_type, entry.filament_vendor,
|
||||
slot_id, slot_type, slot_vendor)) {
|
||||
author_slot = slot;
|
||||
author_found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!author_found)
|
||||
// No author slot carries this material: nothing to apply, nothing to report.
|
||||
continue;
|
||||
|
||||
const std::string material_label = entry.filament_id.empty() ? entry.filament_type : entry.filament_id;
|
||||
auto report_skipped = [&skipped_keys, &material_label](const std::string &key, const std::string &slot_qualifier = std::string()) {
|
||||
skipped_keys.emplace_back("material:" + material_label +
|
||||
(slot_qualifier.empty() ? std::string() : " " + slot_qualifier) +
|
||||
" (" + key + ")");
|
||||
};
|
||||
|
||||
// Collect the receiver's matching filament presets (distinct by preset name).
|
||||
std::vector<std::string> matched_preset_names;
|
||||
std::set<std::string> fallback_matched_names;
|
||||
for (const std::string &preset_name : this->filament_presets) {
|
||||
Preset *preset = this->filaments.find_preset(preset_name);
|
||||
if (preset == nullptr)
|
||||
continue;
|
||||
const std::string slot_id = preset->filament_id;
|
||||
// Null-guard the identity reads: a malformed user preset may lack
|
||||
// filament_type / filament_vendor entirely (hand-edited preset file).
|
||||
const ConfigOptionStrings *slot_types = preset->config.option<ConfigOptionStrings>("filament_type");
|
||||
const ConfigOptionStrings *slot_vendors = preset->config.option<ConfigOptionStrings>("filament_vendor");
|
||||
const std::string slot_type = (slot_types && !slot_types->values.empty()) ? slot_types->get_at(0) : std::string();
|
||||
const std::string slot_vendor = (slot_vendors && !slot_vendors->values.empty()) ? slot_vendors->get_at(0) : std::string();
|
||||
if (!identity_matches(entry.filament_id, entry.filament_type, entry.filament_vendor,
|
||||
slot_id, slot_type, slot_vendor))
|
||||
continue;
|
||||
if (std::find(matched_preset_names.begin(), matched_preset_names.end(), preset_name) == matched_preset_names.end())
|
||||
matched_preset_names.emplace_back(preset_name);
|
||||
if (entry.filament_id.empty() || slot_id.empty())
|
||||
fallback_matched_names.insert(preset_name);
|
||||
}
|
||||
if (matched_preset_names.empty()) {
|
||||
// No receiver material matches this entry: report each key as skipped.
|
||||
for (const std::string &key : entry.keys)
|
||||
report_skipped(key);
|
||||
continue;
|
||||
}
|
||||
if (fallback_matched_names.size() > 1) {
|
||||
// The type fallback matched more than one distinct receiver preset: never
|
||||
// guess which one the author meant.
|
||||
for (const std::string &key : entry.keys)
|
||||
report_skipped(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Slotted entries target the receiver's matching preset at the author's
|
||||
// ordinal; legacy entries apply to every matching receiver preset.
|
||||
std::vector<std::string> apply_to_preset_names;
|
||||
if (entry.slot >= 0) {
|
||||
if (author_ordinal >= matched_preset_names.size()) {
|
||||
// The receiver has fewer matching presets than the author's ordinal:
|
||||
// this slot's values cannot be placed, report each key.
|
||||
const std::string slot_qualifier = "slot " + std::to_string(entry.slot);
|
||||
for (const std::string &key : entry.keys)
|
||||
report_skipped(key, slot_qualifier);
|
||||
continue;
|
||||
}
|
||||
apply_to_preset_names.emplace_back(matched_preset_names[author_ordinal]);
|
||||
} else {
|
||||
apply_to_preset_names = matched_preset_names;
|
||||
}
|
||||
|
||||
for (const std::string &key : entry.keys) {
|
||||
const std::string base_key = key.substr(0, key.find('#'));
|
||||
if (structural_keys.count(base_key) != 0)
|
||||
continue; // structural: silent
|
||||
const ConfigOption *src_opt = config.option(base_key);
|
||||
if (src_opt == nullptr || !src_opt->is_vector() ||
|
||||
author_slot >= static_cast<const ConfigOptionVectorBase*>(src_opt)->size()) {
|
||||
report_skipped(key);
|
||||
continue;
|
||||
}
|
||||
for (const std::string &preset_name : apply_to_preset_names) {
|
||||
Preset *preset = this->filaments.find_preset(preset_name);
|
||||
if (preset == nullptr)
|
||||
continue;
|
||||
ConfigOption *dst_opt = preset->config.option(base_key);
|
||||
// Per-slot scalar copy: the receiver's filament preset holds a single
|
||||
// value per key (vector of size 1), the file holds the per-slot vector.
|
||||
if (dst_opt == nullptr || !dst_opt->is_vector() ||
|
||||
static_cast<const ConfigOptionVectorBase*>(dst_opt)->empty() ||
|
||||
dst_opt->type() != src_opt->type()) {
|
||||
report_skipped(key);
|
||||
continue;
|
||||
}
|
||||
static_cast<ConfigOptionVectorBase*>(dst_opt)->set_at(src_opt, 0, author_slot);
|
||||
material_applied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filament-publishing-v2: 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:
|
||||
// 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: a full dump is intentionally ignored (the receiver keeps its material),
|
||||
// a partial entry's keys are applied as usual;
|
||||
// - type mismatch: the slot is replaced with the first visible same-type filament from
|
||||
// the receiver's library; 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 applying the author's values
|
||||
// in-memory onto the receiver's current preset (no library import); a partial entry
|
||||
// keeps the receiver's material and reports its keys as skipped.
|
||||
// - 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 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 stored preset
|
||||
// directly (mutate 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 slot's values into another, published slots sharing a preset with another
|
||||
// slot are re-pointed at distinct presets before the values are applied.
|
||||
{
|
||||
// Slot growth is tied to the author slots that carry published content (full,
|
||||
// type or colour): the file's total filament count is irrelevant, and a slot the
|
||||
// author left unpublished must not pull a filler material into the receiver's
|
||||
// setup. Grow only as far as the highest published slot (never shrink, never
|
||||
// remove the receiver's existing materials).
|
||||
bool has_new_semantics = false;
|
||||
size_t target_slots = this->filament_presets.size();
|
||||
// Grow the receiver's slots only as far as the highest published slot (never
|
||||
// shrink, never pull filler materials for unpublished slots).
|
||||
bool has_published_entries = false;
|
||||
size_t target_slots = this->filament_presets.size();
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys) {
|
||||
if (!entry.full && !entry.publish_type && !entry.publish_color)
|
||||
continue; // legacy entry, handled above
|
||||
has_new_semantics = true;
|
||||
has_published_entries = true;
|
||||
if (entry.slot >= 0)
|
||||
target_slots = std::max(target_slots, size_t(entry.slot) + 1);
|
||||
}
|
||||
if (has_new_semantics) {
|
||||
if (has_published_entries) {
|
||||
// Defensive cap: never exceed the file's own filament count.
|
||||
target_slots = std::min(target_slots, num_filaments);
|
||||
// Slots that carry published content (full/type/colour) must reference a stored
|
||||
// preset that no other slot shares: the overlay mutates stored presets in place
|
||||
// (colour and keys), so a shared preset would leak one slot's published values
|
||||
// into every slot that references it.
|
||||
// Slots carrying published content, steering the initial preset selection of
|
||||
// newly grown slots.
|
||||
std::set<int> published_slots;
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys)
|
||||
if ((entry.full || entry.publish_type || entry.publish_color) && entry.slot >= 0)
|
||||
if (entry.slot >= 0)
|
||||
published_slots.insert(entry.slot);
|
||||
std::set<std::string> used_preset_names(this->filament_presets.begin(), this->filament_presets.end());
|
||||
// Mirror first_visible_idx()'s start index so suppressed default presets are
|
||||
// never picked as a slot material.
|
||||
const size_t first_candidate = this->filaments.is_default_suppressed() ? this->filaments.num_default_presets() : 0;
|
||||
// Candidate preference for a published entry: exact setting_id (variant-level,
|
||||
// since "Generic PLA" and "Generic PLA Matte" share filament_id), then exact
|
||||
// filament_id, then vendor+type, then type only (a type-only pick may surface an
|
||||
// unrelated preset, e.g. a different vendor's PLA).
|
||||
auto candidate_score = [](const Preset &candidate, const PublishedMaterialEntry &entry) -> int {
|
||||
if (!entry.setting_id.empty() && candidate.setting_id == entry.setting_id)
|
||||
return 3;
|
||||
const ConfigOptionStrings *types = candidate.config.opt<ConfigOptionStrings>("filament_type");
|
||||
const ConfigOptionStrings *vendors = candidate.config.opt<ConfigOptionStrings>("filament_vendor");
|
||||
const std::string type = (types != nullptr && !types->values.empty()) ? types->get_at(0) : std::string();
|
||||
const std::string vendor = (vendors != nullptr && !vendors->values.empty()) ? vendors->get_at(0) : std::string();
|
||||
if (!entry.filament_id.empty() && candidate.filament_id == entry.filament_id)
|
||||
return 2;
|
||||
if (normalize_filament_type(type) == entry.publish_type_value) {
|
||||
if (!entry.filament_vendor.empty() && vendor == entry.filament_vendor)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
while (this->filament_presets.size() < target_slots) {
|
||||
const size_t new_slot_idx = this->filament_presets.size();
|
||||
std::string initial_preset;
|
||||
if (published_slots.count(static_cast<int>(new_slot_idx)) != 0) {
|
||||
// Proactively assign a distinct matching candidate preset if this slot
|
||||
// carries a published type...
|
||||
// Prefer the best distinct candidate for the slot's published material
|
||||
// (exact id, then vendor+type, then type only)...
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys) {
|
||||
if (entry.slot != static_cast<int>(new_slot_idx) || !entry.publish_type || entry.publish_type_value.empty())
|
||||
continue;
|
||||
for (size_t i = 0; i < this->filaments.size(); ++i) {
|
||||
int best_score = -1;
|
||||
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible || used_preset_names.count(candidate.name) != 0)
|
||||
continue;
|
||||
if (normalize_filament_type(candidate.config.opt_string("filament_type", 0u)) == entry.publish_type_value) {
|
||||
const int score = candidate_score(candidate, entry);
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
initial_preset = candidate.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -5091,62 +4948,65 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
}
|
||||
}
|
||||
if (initial_preset.empty())
|
||||
// Unpublished filler slot, or every visible preset is already used: repeat
|
||||
// the receiver's last preset, mirroring the "Add one filament" behaviour
|
||||
// (PresetBundle::set_num_filaments).
|
||||
// Unpublished filler slot, or every visible preset is already used:
|
||||
// repeat the receiver's last preset ("Add one filament" behaviour).
|
||||
initial_preset = this->filament_presets.empty() ? this->filaments.first_visible().name
|
||||
: this->filament_presets.back();
|
||||
this->filament_presets.emplace_back(initial_preset);
|
||||
used_preset_names.insert(initial_preset);
|
||||
}
|
||||
// Slots that were grown before this block (e.g. by update_multi_material_filament_presets
|
||||
// matching the extruder count) may still alias another slot; re-point them at a
|
||||
// distinct preset. Slot 0, the receiver's own material, is never re-assigned.
|
||||
// Published slots that alias another slot (multi-extruder with one filament)
|
||||
// get re-pointed at distinct presets: the overlay mutates stored presets in
|
||||
// place, so a shared preset would leak one slot's published values into every
|
||||
// aliased slot. Slot 0 (the receiver's own material) is never re-assigned;
|
||||
// when no unused candidate exists the aliasing stays (unavoidable).
|
||||
auto referenced_elsewhere = [&](const std::string &preset_name, size_t except_slot) {
|
||||
for (size_t s = 0; s < this->filament_presets.size(); ++s)
|
||||
if (s != except_slot && this->filament_presets[s] == preset_name)
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
for (size_t slot = 1; slot < this->filament_presets.size(); ++slot) {
|
||||
if (published_slots.count(static_cast<int>(slot)) == 0)
|
||||
continue;
|
||||
bool shared = false;
|
||||
for (size_t other = 0; other < this->filament_presets.size(); ++other)
|
||||
if (other != slot && this->filament_presets[other] == this->filament_presets[slot]) {
|
||||
shared = true;
|
||||
break;
|
||||
}
|
||||
if (!shared)
|
||||
if (published_slots.count(static_cast<int>(slot)) == 0 ||
|
||||
!referenced_elsewhere(this->filament_presets[slot], slot))
|
||||
continue;
|
||||
// Prefer the best distinct candidate for the slot's published material
|
||||
// (exact id, then vendor+type, then type only)...
|
||||
std::string replacement;
|
||||
int best_score = -1;
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys) {
|
||||
if (entry.slot != static_cast<int>(slot) || !entry.publish_type || entry.publish_type_value.empty())
|
||||
continue;
|
||||
for (size_t i = 0; i < this->filaments.size(); ++i) {
|
||||
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible || used_preset_names.count(candidate.name) != 0)
|
||||
if (!candidate.is_visible || referenced_elsewhere(candidate.name, size_t(-1)))
|
||||
continue;
|
||||
if (normalize_filament_type(candidate.config.opt_string("filament_type", 0u)) == entry.publish_type_value) {
|
||||
const int score = candidate_score(candidate, entry);
|
||||
if (score > best_score) {
|
||||
best_score = score;
|
||||
replacement = candidate.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// ...otherwise any distinct visible preset not referenced by another slot.
|
||||
if (replacement.empty()) {
|
||||
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible || used_preset_names.count(candidate.name) != 0)
|
||||
continue;
|
||||
replacement = candidate.name;
|
||||
break;
|
||||
if (candidate.is_visible && !referenced_elsewhere(candidate.name, size_t(-1))) {
|
||||
replacement = candidate.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (replacement.empty())
|
||||
continue; // every visible preset is used: aliasing is unavoidable
|
||||
used_preset_names.erase(this->filament_presets[slot]);
|
||||
continue; // every visible preset is referenced: aliasing is unavoidable
|
||||
this->filament_presets[slot] = replacement;
|
||||
used_preset_names.insert(replacement);
|
||||
material_applied = true;
|
||||
}
|
||||
// Mirror set_num_filaments' project_config vector handling ("Add one filament"):
|
||||
// resize the per-slot colour/type/map vectors to the grown slot count and seed the
|
||||
// new entries so the slots render with colours instead of blank chips. Only the
|
||||
// new entries are seeded; the receiver's existing values are left untouched.
|
||||
// Grow the per-slot colour/type/map project vectors to the new slot count and
|
||||
// seed the new entries so the slots render with colours instead of blank chips
|
||||
// (mirrors set_num_filaments; existing values are left untouched).
|
||||
ConfigOptionStrings *proj_colour = this->project_config.opt<ConfigOptionStrings>("filament_colour");
|
||||
ConfigOptionStrings *proj_multi_colour = this->project_config.opt<ConfigOptionStrings>("filament_multi_colour");
|
||||
ConfigOptionStrings *proj_colour_type = this->project_config.opt<ConfigOptionStrings>("filament_colour_type");
|
||||
@@ -5184,8 +5044,7 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
if (proj_colour_type && slot < proj_colour_type->values.size())
|
||||
proj_colour_type->values[slot] = "1"; // default colour type
|
||||
}
|
||||
// Rebuild the flush volumes for the grown slot count (set_num_filaments does the
|
||||
// same; without it the matrix would stay at the receiver's old size).
|
||||
// Rebuild the flush volumes for the grown slot count (as set_num_filaments does).
|
||||
this->update_multi_material_filament_presets();
|
||||
|
||||
auto apply_slot_keys = [&](Preset &preset, const std::vector<std::string> &slot_keys, int author_slot,
|
||||
@@ -5207,23 +5066,22 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
skipped_keys.emplace_back("material:" + material_label + " (" + key + ")");
|
||||
continue;
|
||||
}
|
||||
// Per-slot scalar copy: the receiver's filament preset holds a single
|
||||
// value per key (vector of size 1), the file holds the per-slot vector.
|
||||
// Per-slot scalar copy: the receiver preset holds one value per key
|
||||
// (vector of size 1), the file holds the per-slot vector.
|
||||
static_cast<ConfigOptionVectorBase*>(dst_opt)->set_at(src_opt, 0, author_slot);
|
||||
material_applied = true;
|
||||
}
|
||||
};
|
||||
|
||||
// The slot's values are applied directly onto the slot's stored preset (mutate
|
||||
// in place); the per-entry type gate below may re-point the slot first.
|
||||
for (const PublishedMaterialEntry &entry : published_config->material_keys) {
|
||||
if (!entry.full && !entry.publish_type && !entry.publish_color)
|
||||
continue; // legacy entry, handled above
|
||||
if (entry.slot < 0 || size_t(entry.slot) >= this->filament_presets.size())
|
||||
continue; // out of range: nothing to do for this slot
|
||||
const size_t slot = size_t(entry.slot);
|
||||
// Modify the stored preset itself (real=true), never the edited snapshot:
|
||||
// find_preset would return &m_edited_preset for the currently selected slot,
|
||||
// and the re-select at the end of this block re-snapshots from the stored
|
||||
// preset, silently discarding any values applied to the snapshot.
|
||||
// Resolve the stored preset itself (real=true), never the edited snapshot:
|
||||
// find_preset would return &m_edited_preset for the selected slot, and the
|
||||
// re-select at the end re-snapshots from the stored preset.
|
||||
Preset *recv = this->filaments.find_preset(this->filament_presets[slot], false, true);
|
||||
if (recv == nullptr)
|
||||
continue;
|
||||
@@ -5234,83 +5092,96 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
|
||||
bool apply_slot = true;
|
||||
if (entry.publish_type && !entry.publish_type_value.empty()) {
|
||||
const std::string recv_type = normalize_filament_type(recv->config.opt_string("filament_type", 0u));
|
||||
if (recv_type == entry.publish_type_value) {
|
||||
// Type match: the receiver keeps its material. A full dump is
|
||||
// intentionally ignored for this slot; partial keys still apply.
|
||||
if (entry.full)
|
||||
apply_slot = false;
|
||||
} else {
|
||||
// Type mismatch: replace the slot with the first visible same-type
|
||||
// filament from the receiver's library, preferring one that no other
|
||||
// slot references (a shared stored preset would leak this slot's
|
||||
// published values into that slot).
|
||||
std::string replacement, first_same_type;
|
||||
for (size_t i = 0; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible)
|
||||
continue;
|
||||
if (normalize_filament_type(candidate.config.opt_string("filament_type", 0u)) != entry.publish_type_value)
|
||||
continue;
|
||||
if (first_same_type.empty())
|
||||
first_same_type = candidate.name;
|
||||
bool used_elsewhere = false;
|
||||
for (size_t s = 0; s < this->filament_presets.size(); ++s)
|
||||
if (s != slot && this->filament_presets[s] == candidate.name) {
|
||||
used_elsewhere = true;
|
||||
break;
|
||||
// Null-guard: a malformed receiver preset may lack filament_type.
|
||||
const ConfigOptionStrings *recv_types = recv->config.opt<ConfigOptionStrings>("filament_type");
|
||||
const std::string recv_type = (recv_types != nullptr && !recv_types->values.empty()) ? recv_types->get_at(0) : std::string();
|
||||
if (normalize_filament_type(recv_type) != entry.publish_type_value) {
|
||||
// Type mismatch: replace the slot with the best matching preset,
|
||||
// scored by the published identity (exact filament_id, then
|
||||
// vendor+type, then type only). A preset no other slot references
|
||||
// wins on equal scores; a shared exact-material preset is taken even
|
||||
// though mutating it also affects the other slot.
|
||||
auto find_best = [&](bool unreferenced_only) -> std::pair<int, std::string> {
|
||||
int best_score = -1;
|
||||
std::string best_name;
|
||||
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible)
|
||||
continue;
|
||||
const int score = candidate_score(candidate, entry);
|
||||
if (score <= best_score)
|
||||
continue;
|
||||
if (unreferenced_only) {
|
||||
bool used = false;
|
||||
for (size_t s = 0; s < this->filament_presets.size(); ++s)
|
||||
if (s != slot && this->filament_presets[s] == candidate.name) {
|
||||
used = true;
|
||||
break;
|
||||
}
|
||||
if (used)
|
||||
continue;
|
||||
}
|
||||
if (!used_elsewhere) {
|
||||
replacement = candidate.name;
|
||||
break;
|
||||
best_score = score;
|
||||
best_name = candidate.name;
|
||||
}
|
||||
return { best_score, best_name };
|
||||
};
|
||||
const auto [strict_score, strict_name] = find_best(true);
|
||||
const auto [relaxed_score, relaxed_name] = find_best(false);
|
||||
int score = strict_score;
|
||||
std::string replacement = strict_name;
|
||||
if (relaxed_score > strict_score) {
|
||||
score = relaxed_score;
|
||||
replacement = relaxed_name;
|
||||
}
|
||||
if (replacement.empty())
|
||||
replacement = first_same_type;
|
||||
if (!replacement.empty()) {
|
||||
const std::string old_name = recv->name;
|
||||
this->filament_presets[slot] = replacement;
|
||||
recv = this->filaments.find_preset(replacement, false, true);
|
||||
material_applied = true;
|
||||
published_config->material_replacements.emplace_back(
|
||||
"slot " + std::to_string(slot) + ": " + old_name + " -> " + replacement);
|
||||
std::string replacement_line = "slot " + std::to_string(slot) + ": " + old_name + " -> " + replacement;
|
||||
// A pick that is not the exact published material is a substitute;
|
||||
// an entry without identity fields cannot be judged, so it stays plain.
|
||||
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 library match: create a temporary project-embedded custom preset
|
||||
// populated with default settings and overlaid with the author's values.
|
||||
std::string custom_name = entry.publish_type_value + " (Published)";
|
||||
for (size_t idx = 1; this->filaments.find_preset(custom_name, false) != nullptr; ++idx)
|
||||
custom_name = entry.publish_type_value + " (Published " + std::to_string(idx) + ")";
|
||||
|
||||
// Capture the slot's current name BEFORE load_preset: the custom
|
||||
// name sorts ahead of the slot's material, so the deque insertion
|
||||
// relocates it and recv would dangle after the call.
|
||||
const std::string old_name = recv->name;
|
||||
|
||||
DynamicPrintConfig custom_cfg = this->filaments.default_preset_for(config).config;
|
||||
// filament_type is a per-slot vector option: set it via the strings
|
||||
// accessor. opt_string(key, bool) would ask for the scalar
|
||||
// ConfigOptionString, fail the cast and dereference nullptr.
|
||||
if (ConfigOptionStrings *type_opt = custom_cfg.opt<ConfigOptionStrings>("filament_type", true)) {
|
||||
if (type_opt->values.empty())
|
||||
type_opt->values.emplace_back();
|
||||
type_opt->values[0] = entry.publish_type_value;
|
||||
// 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).
|
||||
std::string fallback;
|
||||
for (size_t i = first_candidate; i < this->filaments.size(); ++i) {
|
||||
const Preset &candidate = this->filaments.preset(i);
|
||||
if (!candidate.is_visible)
|
||||
continue;
|
||||
if (fallback.empty())
|
||||
fallback = candidate.name;
|
||||
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) {
|
||||
fallback = candidate.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ConfigOptionStrings *id_opt = custom_cfg.opt<ConfigOptionStrings>("filament_settings_id", true))
|
||||
if (!id_opt->values.empty())
|
||||
id_opt->values[0] = custom_name;
|
||||
|
||||
Preset &created = this->filaments.load_preset("", custom_name, std::move(custom_cfg), false, file_version);
|
||||
created.is_project_embedded = true;
|
||||
created.is_visible = true;
|
||||
|
||||
this->filament_presets[slot] = custom_name;
|
||||
recv = &created;
|
||||
material_applied = true;
|
||||
published_config->material_replacements.emplace_back(
|
||||
"slot " + std::to_string(slot) + ": " + old_name + " -> " + custom_name);
|
||||
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;
|
||||
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 available: keep the
|
||||
// receiver's material and report this slot's keys as skipped.
|
||||
// Partial publish with no replacement: keep the receiver's
|
||||
// material and report the slot's keys as skipped.
|
||||
for (const std::string &key : entry.keys)
|
||||
skipped_keys.emplace_back("material:" + material_label + " (" + key + ")");
|
||||
apply_slot = false;
|
||||
@@ -5318,14 +5189,15 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
}
|
||||
}
|
||||
|
||||
// Colour is slot-scoped and independent of the type gate: it is applied to
|
||||
// whichever material ends up in the slot (original, replacement or the
|
||||
// in-memory fallback), and synced into project_config for GUI rendering.
|
||||
// The values below are applied onto whatever stored preset the slot ended up
|
||||
// on (original, type replacement or the full-publish fallback), in place.
|
||||
|
||||
// Colour is slot-scoped and independent of the type gate; it is also synced
|
||||
// into project_config for GUI rendering.
|
||||
if (entry.publish_color && !entry.color.empty()) {
|
||||
if (recv != nullptr) {
|
||||
// Create the key when the target preset lacks it (e.g. a replacement
|
||||
// built from the static defaults): the colour is a requirement, not
|
||||
// an optional override.
|
||||
// Create the key when the target preset lacks it: the colour is a
|
||||
// requirement, not an override.
|
||||
if (ConfigOptionStrings *colour = recv->config.opt<ConfigOptionStrings>("filament_colour", true)) {
|
||||
if (colour->values.empty())
|
||||
colour->values.emplace_back();
|
||||
@@ -5364,11 +5236,9 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||
}
|
||||
published_config->skipped_keys = std::move(skipped_keys);
|
||||
|
||||
// The material overlay above modified the filament collection presets in place, but
|
||||
// the edited preset (what the GUI displays) is a snapshot taken when the preset was
|
||||
// last selected. Re-select the first slot's filament (mirroring a normal project load)
|
||||
// so the applied values (colour, type, keys and slot replacements) surface in the GUI;
|
||||
// selecting any other slot's filament afterwards snapshots its modified preset too.
|
||||
// The material overlay mutates the collection presets in place, but the edited preset
|
||||
// (what the GUI displays) is a snapshot taken when the preset was last selected.
|
||||
// Re-select the first slot's filament so the applied values surface in the GUI.
|
||||
if (material_applied && !this->filament_presets.empty())
|
||||
this->filaments.select_preset_by_name(this->filament_presets.front(), true);
|
||||
}
|
||||
|
||||
@@ -167,22 +167,21 @@ struct PresetBundleMetadata
|
||||
}
|
||||
};
|
||||
|
||||
// Configuration describing a "published" 3MF project: the file carries a flag plus a list of
|
||||
// author-selected setting keys. When loading such a project the user's currently-selected
|
||||
// presets are kept and only the published keys are overlaid onto the edited presets.
|
||||
// A "published" 3MF project: keeps the user's currently-selected presets and overlays only the
|
||||
// author-selected published keys onto the edited presets.
|
||||
struct PublishedConfig
|
||||
{
|
||||
bool published = false;
|
||||
std::vector<std::string> published_keys;
|
||||
// Material-qualified published keys chosen by the author for the materials used in the
|
||||
// project; applied on load only to the receiver's filament presets whose material
|
||||
// identity matches (see PublishedMaterialEntry in PublishSettings.hpp).
|
||||
// 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).
|
||||
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.
|
||||
std::vector<std::string> skipped_keys;
|
||||
// Human-readable notices of the slot material replacements performed while loading a
|
||||
// published project (e.g. "Slot 2: replaced PETG with PLA"), for the load notification.
|
||||
// published project, for the load notification.
|
||||
std::vector<std::string> material_replacements;
|
||||
};
|
||||
|
||||
|
||||
@@ -30,11 +30,9 @@ std::string normalize_filament_type(const std::string& type)
|
||||
|
||||
const std::set<std::string>& publish_structural_keys()
|
||||
{
|
||||
// Structural / non-publishable keys. The *_settings_id keys are also part of
|
||||
// PresetCollection::skipped_in_dirty (Preset.cpp) and are excluded there too.
|
||||
// This mirrors the structural keys stripped from configs in Preset.cpp
|
||||
// (profile_print_params_same) plus other keys that must never be published
|
||||
// because they would rewrite the user's preset inheritance/structure.
|
||||
// Non-publishable keys: the *_settings_id keys are also in PresetCollection::skipped_in_dirty
|
||||
// (Preset.cpp) / stripped from configs (profile_print_params_same); publishing them would
|
||||
// rewrite the user's preset inheritance/structure.
|
||||
static const std::set<std::string> structural_keys = {
|
||||
"printer_settings_id", "filament_settings_id", "print_settings_id",
|
||||
"sla_print_settings_id", "sla_material_settings_id",
|
||||
@@ -88,9 +86,8 @@ const std::vector<PublishablePrinterOption>& publishable_printer_z_hop_options()
|
||||
|
||||
const std::set<std::string>& publishable_printer_keys()
|
||||
{
|
||||
// The union of the printer tab's "Retraction" and "Z-Hop" optgroups. The "Retraction when
|
||||
// switching material" keys are intentionally excluded: toolchange retraction is
|
||||
// device/profile territory, not a publishable behavior tweak.
|
||||
// Union of the two optgroups; "Retraction when switching material" keys are excluded
|
||||
// (toolchange retraction is device/profile territory, not a publishable behavior tweak).
|
||||
static const std::set<std::string> printer_keys = [] {
|
||||
std::set<std::string> keys;
|
||||
for (const PublishablePrinterOption &opt : publishable_printer_retraction_options())
|
||||
@@ -113,9 +110,8 @@ std::vector<std::string> collect_dirty_settings_keys(const PresetBundle& bundle)
|
||||
}
|
||||
};
|
||||
|
||||
// Print and printer presets each track a single edited preset; filaments may span
|
||||
// multiple slots (multi-material). Union the dirty keys of each collection's edited
|
||||
// preset; this feeds only the Publish dialog's pre-check.
|
||||
// Union the dirty keys of each collection's edited preset (filaments may span multiple
|
||||
// slots); feeds only the Publish dialog's pre-check.
|
||||
append_dirty(bundle.prints.current_dirty_options(true));
|
||||
append_dirty(bundle.printers.current_dirty_options(true));
|
||||
append_dirty(bundle.filaments.current_dirty_options(true));
|
||||
@@ -131,12 +127,11 @@ DynamicPrintConfig filter_published_config(
|
||||
DynamicPrintConfig filtered;
|
||||
|
||||
std::set<std::string> base_keys_to_include;
|
||||
// Base keys that must never be masked: identity, plate geometry, process/printer keys and
|
||||
// partially-published material keys keep today's whole-vector serialization (all slots).
|
||||
// Never masked (whole-vector serialization): identity, plate geometry, process/printer
|
||||
// keys and partially-published material keys.
|
||||
std::set<std::string> mask_exempt_keys;
|
||||
// For keys carried only by "full" entries: base key -> author slots whose values must
|
||||
// survive; the other slots are masked to their defaults so a full publish does not leak
|
||||
// the author's unrelated slot data.
|
||||
// "Full" entries only: base key -> author slots whose values must survive; other slots are
|
||||
// masked to their defaults so a full publish does not leak unrelated slot data.
|
||||
std::map<std::string, std::set<int>> full_slot_map;
|
||||
|
||||
// 1. Mandatory material identity & slot count keys for 3MF validation/normalization
|
||||
@@ -183,8 +178,7 @@ DynamicPrintConfig filter_published_config(
|
||||
mask_exempt_keys.insert(base_key);
|
||||
}
|
||||
}
|
||||
// 4b. "Full publish" entries carry the entire slot; the values of the covered keys are
|
||||
// masked to the author's slot on export (see the copy loop below).
|
||||
// Full-publish keys: mask to the author's slot on export (see the copy loop below).
|
||||
for (const std::string &key : entry.full_keys) {
|
||||
const std::string base_key = key.substr(0, key.find('#'));
|
||||
if (base_key.empty())
|
||||
@@ -195,9 +189,8 @@ DynamicPrintConfig filter_published_config(
|
||||
}
|
||||
}
|
||||
|
||||
// Mask a vector option's slots that are not author-published: copy the option default over
|
||||
// each non-published index. Keys without an option default are left unmasked (the file then
|
||||
// carries the whole vector, matching the partial-publish behavior).
|
||||
// Mask non-published vector slots with the option default; keys without a default stay
|
||||
// unmasked (whole vector, matching partial-publish behavior).
|
||||
auto mask_slots = [](ConfigOption &opt, const ConfigOptionDef *def, const std::set<int> &keep_slots) {
|
||||
auto *vec = dynamic_cast<ConfigOptionVectorBase*>(&opt);
|
||||
if (vec == nullptr || vec->size() == 0 || def == nullptr || !def->default_value)
|
||||
@@ -212,7 +205,7 @@ DynamicPrintConfig filter_published_config(
|
||||
vec->set_at(def->default_value.get(), idx, 0);
|
||||
};
|
||||
|
||||
// Copy selected options from full_config into filtered config
|
||||
// Copy the selected options from full_config into the filtered config.
|
||||
for (const std::string &key : base_keys_to_include) {
|
||||
if (const ConfigOption *opt = full_config.option(key)) {
|
||||
ConfigOption *cloned = opt->clone();
|
||||
|
||||
@@ -6,78 +6,63 @@
|
||||
namespace Slic3r {
|
||||
class PresetBundle;
|
||||
|
||||
// Structural / non-publishable setting keys, shared by the Publish dialog and the published-3MF
|
||||
// overlay path in PresetBundle::load_config_file_config. These keys must never be published
|
||||
// because they would rewrite the user's preset inheritance/structure. This is the single
|
||||
// source of truth for the denylist.
|
||||
// Structural keys that must never be published (single source of truth for the denylist):
|
||||
// publishing them would rewrite the user's preset inheritance/structure.
|
||||
const std::set<std::string>& publish_structural_keys();
|
||||
|
||||
// One option row of the printer tab's "Retraction" / "Z-Hop" optgroups (TabPrinter::build_fff,
|
||||
// Tab.cpp). Key and icon id are kept together so the tab can later be migrated onto these
|
||||
// lists; publishable_printer_keys() is their union, and the published-3MF loader/dialog must
|
||||
// never accept printer keys outside it.
|
||||
// One row of the printer tab's "Retraction" / "Z-Hop" optgroups (key + tab icon id), kept
|
||||
// together so the tab can later be migrated onto these lists.
|
||||
struct PublishablePrinterOption {
|
||||
const char *key; // config key, e.g. "retraction_length"
|
||||
const char *icon; // tab icon id, e.g. "printer_extruder_retraction#length"
|
||||
};
|
||||
|
||||
// The printer tab's "Retraction" optgroup options, in tab order.
|
||||
// The printer tab's "Retraction" / "Z-Hop" optgroup options, in tab order.
|
||||
const std::vector<PublishablePrinterOption>& publishable_printer_retraction_options();
|
||||
// The printer tab's "Z-Hop" optgroup options, in tab order.
|
||||
const std::vector<PublishablePrinterOption>& publishable_printer_z_hop_options();
|
||||
|
||||
// Printer-class retraction / z-hop keys that are publishable: the union of
|
||||
// publishable_printer_retraction_options() and publishable_printer_z_hop_options(). The
|
||||
// published-3MF overlay applies printer keys only when their base key is in this allowlist;
|
||||
// any other printer-class key in a published file is contract-excluded (never applied, never
|
||||
// reported as skipped).
|
||||
// Union of the two optgroup option lists; the published-3MF overlay applies printer keys only
|
||||
// when their base key is in this allowlist (anything else is contract-excluded).
|
||||
const std::set<std::string>& publishable_printer_keys();
|
||||
|
||||
// Returns the union of setting keys that differ from the base/system preset across the current
|
||||
// print, printer and filament presets (feeds the Publish dialog's pre-check).
|
||||
// Union of setting keys differing from the base/system preset across the current print,
|
||||
// printer and filament presets (feeds the Publish dialog's pre-check).
|
||||
std::vector<std::string> collect_dirty_settings_keys(const PresetBundle& bundle);
|
||||
|
||||
// A material-qualified set of published setting keys, chosen by the author for one of the
|
||||
// materials used in the project. The identity fields let the receiver apply the keys only
|
||||
// when a matching material is selected: filament_id is the most precise (stable across
|
||||
// machines/vendors when present, empty for user presets); filament_type + filament_vendor
|
||||
// are the fallback. Keys are base keys (no "#N" variant suffix).
|
||||
// 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.
|
||||
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)
|
||||
// 0-based author filament slot this entry's values came from; -1 = legacy/unspecified
|
||||
// (files written before the slot field). Slotted entries apply to the receiver's Nth
|
||||
// matching preset (N = the slot's ordinal among the author's matching slots); legacy
|
||||
// entries apply to every matching receiver preset.
|
||||
// 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).
|
||||
std::string setting_id;
|
||||
// 0-based author filament slot; -1 (hand-crafted files) is skipped.
|
||||
int slot{-1};
|
||||
std::vector<std::string> keys;
|
||||
// "Full Publish": the entire filament preset of this slot is serialized (see full_keys),
|
||||
// not just the individually selected keys. On load the type gate (publish_type_value)
|
||||
// decides whether the receiver keeps its material (type match) or is replaced; a full
|
||||
// entry carries no partial keys.
|
||||
// "Full Publish": serialize the whole filament preset (full_keys); the type gate then
|
||||
// decides whether the receiver keeps its material (type match) or is replaced.
|
||||
bool full{false};
|
||||
// All non-structural filament keys of the author's slot preset, present when full is true.
|
||||
// Values travel in the file config, masked to the author's slot index.
|
||||
// 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, curated (MaterialType) filament type the author requires for this slot.
|
||||
// On load the receiver's slot material is matched against it; on mismatch the slot is
|
||||
// replaced with a same-type filament from the receiver's library.
|
||||
// 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.
|
||||
bool publish_type{false};
|
||||
std::string publish_type_value;
|
||||
// Required filament colour for this slot, applied on load regardless of the type match.
|
||||
// Required filament colour, applied on load regardless of the type match.
|
||||
bool publish_color{false};
|
||||
std::string color;
|
||||
};
|
||||
|
||||
// Normalizes a filament type string against the curated MaterialType list: an exact match
|
||||
// wins, then the value is stripped after its first space ("PLA High Speed" -> "PLA"); a
|
||||
// value still not recognized is returned unchanged. Shared by the Publish dialog's type row
|
||||
// default and by the published-3MF loader's type matching.
|
||||
// "PLA High Speed" -> "PLA" (strip a space modifier); dash types like "PA-CF" are kept intact.
|
||||
std::string normalize_filament_type(const std::string& type);
|
||||
|
||||
// Constructs a minimal DynamicPrintConfig for a published 3MF export containing only the
|
||||
// author-selected published keys, material keys, material identity fields, and plate geometry keys.
|
||||
// Minimal DynamicPrintConfig for a published 3MF export: only the selected published keys,
|
||||
// material keys, identity fields and plate geometry keys.
|
||||
class DynamicPrintConfig;
|
||||
DynamicPrintConfig filter_published_config(
|
||||
const DynamicPrintConfig &full_config,
|
||||
|
||||
@@ -11,18 +11,16 @@ class DynamicPrintConfig;
|
||||
|
||||
namespace GUI {
|
||||
|
||||
// Return the value of the given option (identified by opt_key, which may contain
|
||||
// a "#<index>" suffix) formatted as a human readable string.
|
||||
// Human-readable value of opt_key (may carry a "#<index>" suffix) in config.
|
||||
wxString get_string_value(const std::string& opt_key, const DynamicPrintConfig& config);
|
||||
|
||||
// Return the full label of the given option (identified by opt_key, which may contain
|
||||
// a "#<index>" suffix). Returns "N/A" when the option is not set.
|
||||
// Full label of opt_key; "N/A" when the option is not set.
|
||||
wxString get_full_label(const std::string& opt_key, const DynamicPrintConfig& config);
|
||||
|
||||
// Strip the "#<index>" suffix (if any) from the given option key.
|
||||
// Strip the "#<index>" suffix (if any) from the option key.
|
||||
std::string get_pure_opt_key(const std::string& opt_key);
|
||||
|
||||
// Return the localized label of the currently selected value of an enum option.
|
||||
// Localized label of the currently selected value of an enum option.
|
||||
wxString get_string_from_enum(const std::string& opt_key, const DynamicPrintConfig& config, bool is_infill = false, int idx = -1);
|
||||
|
||||
} // namespace GUI
|
||||
|
||||
@@ -2837,11 +2837,11 @@ void MainFrame::init_menubar_as_editor()
|
||||
auto publish_handler = [this](wxCommandEvent&) { publish_project(); };
|
||||
|
||||
#ifndef __APPLE__
|
||||
append_menu_item(fileMenu, wxID_ANY, _L("Publish") + dots + "\t" + ctrl + shift + "E", _L("Export a 3MF file with the selected settings embedded"),
|
||||
append_menu_item(fileMenu, wxID_ANY, _L("Publish 3MF") + dots + "\t" + ctrl + shift + "E", _L("Export a 3MF file with the selected settings embedded"),
|
||||
publish_handler, "menu_publish", nullptr,
|
||||
[this](){return can_export_model(); }, this);
|
||||
#else
|
||||
append_menu_item(fileMenu, wxID_ANY, _L("Publish") + dots + "\t" + ctrl + shift + "E", _L("Export a 3MF file with the selected settings embedded"),
|
||||
append_menu_item(fileMenu, wxID_ANY, _L("Publish 3MF") + dots + "\t" + ctrl + shift + "E", _L("Export a 3MF file with the selected settings embedded"),
|
||||
publish_handler, "", nullptr,
|
||||
[this](){return can_export_model(); }, this);
|
||||
#endif
|
||||
|
||||
+23
-25
@@ -7208,9 +7208,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
}
|
||||
}
|
||||
|
||||
// BBS: a "published" 3MF project carries a flag plus a list of author-selected
|
||||
// setting keys. When present, keep the user's currently-selected presets and
|
||||
// overlay only the published keys onto the edited presets on load.
|
||||
// BBS: a "published" 3MF carries a flag plus the author-selected setting keys;
|
||||
// on load keep the user's current presets and overlay only those keys.
|
||||
PublishedConfig published_config;
|
||||
if (model.model_info != nullptr) {
|
||||
auto published_it = model.model_info->metadata_items.find("published");
|
||||
@@ -7249,6 +7248,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
entry.filament_vendor = mat["filament_vendor"].get<std::string>();
|
||||
if (mat.contains("filament_id") && mat["filament_id"].is_string())
|
||||
entry.filament_id = mat["filament_id"].get<std::string>();
|
||||
if (mat.contains("setting_id") && mat["setting_id"].is_string())
|
||||
entry.setting_id = mat["setting_id"].get<std::string>();
|
||||
}
|
||||
if (m.contains("slot") && m["slot"].is_number_integer())
|
||||
entry.slot = m["slot"].get<int>();
|
||||
@@ -7257,7 +7258,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
for (const auto &k : *entry_keys_it)
|
||||
if (k.is_string())
|
||||
entry.keys.emplace_back(k.get<std::string>());
|
||||
// Filament-publishing-v2 fields; absent in legacy files.
|
||||
// Fields always written by the current exporter.
|
||||
if (m.contains("full") && m["full"].is_boolean())
|
||||
entry.full = m["full"].get<bool>();
|
||||
const auto entry_full_keys_it = m.find("full_keys");
|
||||
@@ -7282,10 +7283,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
||||
}
|
||||
}
|
||||
|
||||
// BBS: a "published" 3MF behaves like a new project once loaded: the file's path
|
||||
// must not become the project filename (Save/Ctrl-S would otherwise overwrite the
|
||||
// shared file), and the published metadata is consumed by the overlay above and
|
||||
// stripped so a later save produces a normal, unpublished 3MF.
|
||||
// BBS: a "published" 3MF loads as a new project: its path must not become the
|
||||
// project filename (Save/Ctrl-S would overwrite the shared file), and the
|
||||
// published metadata is consumed above and stripped so a later save is a normal
|
||||
// unpublished 3MF.
|
||||
if (published_out != nullptr && published_config.published)
|
||||
*published_out = true;
|
||||
if (published_config.published && load_config && this->model.model_info != nullptr) {
|
||||
@@ -13309,10 +13310,10 @@ void Plater::load_project(wxString const& filename2,
|
||||
p->set_project_filename(filename);
|
||||
}
|
||||
else if (loaded_published) {
|
||||
// A "published" 3MF loads as a new project: the shared file's path must not become
|
||||
// the project filename, so Save/Ctrl-S prompts for a destination instead of
|
||||
// overwriting the published file. reset() above already cleared the project name
|
||||
// and folder; restore the default new-project title and keep the file in recents.
|
||||
// A "published" 3MF loads as a new project: its path must not become the project
|
||||
// filename (Save/Ctrl-S prompts for a destination instead of overwriting it);
|
||||
// reset() already cleared the project name, so restore the default title and keep
|
||||
// the file in recents.
|
||||
p->set_project_name(_L("Untitled"));
|
||||
if (!filename.IsEmpty())
|
||||
wxGetApp().mainframe->add_to_recent_projects(filename);
|
||||
@@ -16225,10 +16226,9 @@ void Plater::export_core_3mf()
|
||||
export_3mf(path_u8, SaveStrategy::Silence);
|
||||
}
|
||||
|
||||
// Export the current project as a "published" 3MF. This is a pure export: unlike save_project(),
|
||||
// it never touches the project's file name, dirty state, backup path or title, and the
|
||||
// published metadata is attached to the model only for the duration of the export so the
|
||||
// in-memory project stays exactly as it was (a later Save Project produces a normal 3MF).
|
||||
// Export the current project as a "published" 3MF: a pure export that never touches the
|
||||
// project's file name, dirty state, backup path or title, and attaches the published metadata
|
||||
// to the model only for the duration of the export (a later Save Project is a normal 3MF).
|
||||
int Plater::export_published_3mf(const std::vector<std::string>& published_keys, const std::vector<Slic3r::PublishedMaterialEntry>& material_keys)
|
||||
{
|
||||
wxString path = p->get_export_file(FT_3MF, _L("Publish 3MF file as:"));
|
||||
@@ -16240,14 +16240,14 @@ int Plater::export_published_3mf(const std::vector<std::string>& published_keys,
|
||||
j.push_back(key);
|
||||
nlohmann::json jm = nlohmann::json::array();
|
||||
for (const Slic3r::PublishedMaterialEntry& e : material_keys)
|
||||
jm.push_back({ {"material", {{"filament_type", e.filament_type}, {"filament_vendor", e.filament_vendor}, {"filament_id", e.filament_id}}}, {"slot", e.slot}, {"keys", e.keys},
|
||||
jm.push_back({ {"material", {{"filament_type", e.filament_type}, {"filament_vendor", e.filament_vendor}, {"filament_id", e.filament_id}, {"setting_id", e.setting_id}}}, {"slot", e.slot}, {"keys", e.keys},
|
||||
{"full", e.full}, {"full_keys", e.full_keys},
|
||||
{"publish_type", e.publish_type}, {"type", e.publish_type_value},
|
||||
{"publish_color", e.publish_color}, {"color", e.color} });
|
||||
|
||||
Model& model = this->model();
|
||||
// Remember the previous metadata state so it can be restored after the export, keeping the
|
||||
// in-memory project pristine (the published flag lives only in the exported file).
|
||||
// Save the previous metadata so it can be restored after the export, keeping the in-memory
|
||||
// project pristine (the published flag lives only in the exported file).
|
||||
const bool had_model_info = (model.model_info != nullptr);
|
||||
const bool had_published = had_model_info && (model.model_info->metadata_items.find("published") != model.model_info->metadata_items.end());
|
||||
const bool had_published_keys = had_model_info && (model.model_info->metadata_items.find("published_keys") != model.model_info->metadata_items.end());
|
||||
@@ -16261,15 +16261,13 @@ int Plater::export_published_3mf(const std::vector<std::string>& published_keys,
|
||||
model.model_info->metadata_items["published_keys"] = j.dump();
|
||||
model.model_info->metadata_items["published_material_keys"] = jm.dump();
|
||||
|
||||
// Minimal published export: filter full_config to only the published keys, material keys,
|
||||
// identity fields, and plate geometry keys, and omit project-embedded preset dumps.
|
||||
// Minimal published export: filter full_config to the published keys, material keys,
|
||||
// identity fields and plate geometry keys, and omit project-embedded preset dumps.
|
||||
DynamicPrintConfig full_cfg = wxGetApp().preset_bundle->full_config_secure();
|
||||
DynamicPrintConfig filtered_cfg = filter_published_config(full_cfg, published_keys, material_keys);
|
||||
|
||||
// Same file layout save_project() uses for its project files, plus SaveStrategy::Silence and SaveStrategy::MinimalPublished:
|
||||
// without it export_3mf() calls set_project_filename() on success, which would make this
|
||||
// pure export the current project file. Silence keeps the project state untouched, exactly
|
||||
// like export_core_3mf().
|
||||
// Same file layout as save_project(), plus Silence (so export_3mf does not set the project
|
||||
// filename on success, keeping this a pure export like export_core_3mf()) and MinimalPublished.
|
||||
auto save_strategy = SaveStrategy::SplitModel | SaveStrategy::ShareMesh | SaveStrategy::Silence | SaveStrategy::MinimalPublished;
|
||||
bool full_pathnames = wxGetApp().app_config->get_bool("export_sources_full_pathnames");
|
||||
if (full_pathnames)
|
||||
|
||||
@@ -495,9 +495,8 @@ public:
|
||||
void export_gcode_3mf(bool export_all = false);
|
||||
void send_gcode_finish(wxString name);
|
||||
void export_core_3mf();
|
||||
// Export the current project as a "published" 3MF: embeds the author-selected settings
|
||||
// (published_keys / published_material_keys) into the file's metadata. A pure export: the
|
||||
// in-memory project (filename, dirty state, model_info metadata) is left untouched.
|
||||
// Export a "published" 3MF embedding the author-selected settings in the file metadata; a
|
||||
// pure export that leaves the in-memory project untouched.
|
||||
int export_published_3mf(const std::vector<std::string>& published_keys, const std::vector<Slic3r::PublishedMaterialEntry>& material_keys);
|
||||
static TriangleMesh combine_mesh_fff(const ModelObject& mo, int instance_id, std::function<void(const std::string&)> notify_func = {});
|
||||
void export_stl(bool extended = false, bool selection_only = false, bool multi_stls = false, FileType file_type = FT_STL);
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
namespace Slic3r { namespace GUI {
|
||||
namespace {
|
||||
|
||||
// Menu ids for show_menu(). Dedicated range above the standard ids so the popup cannot
|
||||
// collide with application-level bindings (e.g. MainFrame's recent-files wxID_FILE1.. range).
|
||||
// Menu ids for show_menu(): dedicated range so the popup cannot collide with application-level
|
||||
// bindings (e.g. MainFrame's recent-files wxID_FILE1.. range).
|
||||
enum {
|
||||
kPublishSelectAll = wxID_HIGHEST + 1,
|
||||
kPublishDeselectAll,
|
||||
@@ -49,9 +49,7 @@ PublishMaterialIdentity material_identity(size_t slot, const DynamicPrintConfig&
|
||||
return identity;
|
||||
}
|
||||
|
||||
// "Generic PLA @System" -> "Generic PLA"; mirrors the alias derivation in
|
||||
// PresetBundle::load_vendor_configs_from_json (PresetBundle.cpp) and
|
||||
// PresetCollection::set_custom_preset_alias (Preset.cpp).
|
||||
// "Generic PLA @System" -> "Generic PLA"; mirrors the alias derivation in PresetBundle.cpp.
|
||||
std::string material_display_name(const std::string& preset_name)
|
||||
{
|
||||
const size_t at = preset_name.find_first_of('@');
|
||||
@@ -62,8 +60,8 @@ std::string material_display_name(const std::string& preset_name)
|
||||
return bare.empty() ? preset_name : bare;
|
||||
}
|
||||
|
||||
// Human-readable section title for a filament slot: the resolved preset name,
|
||||
// falling back to the filament type, then to the generic "Material".
|
||||
// Section title for a filament slot: the resolved preset name, then the filament type, then
|
||||
// the generic "Material".
|
||||
wxString material_title(size_t slot, const PresetBundle* bundle, const DynamicPrintConfig& full)
|
||||
{
|
||||
if (slot < bundle->filament_presets.size()) {
|
||||
@@ -165,8 +163,7 @@ PublishSettingsDialog::PublishSettingsDialog(wxWindow* parent)
|
||||
auto dlg_btns = new DialogButtons(this, {"OK", "Cancel"});
|
||||
|
||||
dlg_btns->GetOK()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
// Publish is always allowed: no settings selected means a publish with
|
||||
// no settings override.
|
||||
// Publish is always allowed: no settings selected means no settings override.
|
||||
EndModal(wxID_OK);
|
||||
});
|
||||
dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { EndModal(wxID_CANCEL); });
|
||||
@@ -183,12 +180,11 @@ PublishSettingsDialog::~PublishSettingsDialog() {}
|
||||
|
||||
void PublishSettingsDialog::build_option_model()
|
||||
{
|
||||
// Structural / non-publishable keys, shared with the published-3MF overlay
|
||||
// path (see libslic3r/PublishSettings.hpp).
|
||||
// Structural / non-publishable keys, shared with the published-3MF overlay path.
|
||||
const std::set<std::string>& denylist = publish_structural_keys();
|
||||
// Base keys already added in the print/printer sections. Printer rows share
|
||||
// this set: a base key appears once (per-extruder "#N" variants collapse to
|
||||
// the first occurrence - acceptable MVP; the per-extruder context is lost).
|
||||
// Base keys already added in the print/printer sections. Printer rows share this set:
|
||||
// per-extruder "#N" variants collapse to the first occurrence (acceptable MVP; the
|
||||
// per-extruder context is lost in the UI).
|
||||
std::set<std::string> added;
|
||||
|
||||
PresetBundle* bundle = wxGetApp().preset_bundle;
|
||||
@@ -198,17 +194,17 @@ void PublishSettingsDialog::build_option_model()
|
||||
m_info_allsel = _L("All items selected...");
|
||||
m_info_empty = _L("No matching items...");
|
||||
|
||||
// Keep the tab order explicit: Section's enum order is Print, Printer,
|
||||
// Material, while the dialog presents Printer, Filament, Process.
|
||||
// Tab order differs from Section's enum order (Print, Printer, Material): the dialog
|
||||
// presents Printer, Filament, Process.
|
||||
m_sections.reserve(3);
|
||||
const Section tab_order[] = {Section::Printer, Section::Material, Section::Print};
|
||||
for (Section kind : tab_order)
|
||||
section_group_for(kind);
|
||||
bind_tab_events();
|
||||
|
||||
// Shared per-option label/value computation; returns false when the option
|
||||
// must be skipped (denylisted / unknown / empty label). value is the pure
|
||||
// stringified value; unit is the translated sidetext (may be empty).
|
||||
// Shared per-option label/value computation; returns false when the option must be skipped
|
||||
// (denylisted / unknown / empty label). value is the stringified value; unit the translated
|
||||
// sidetext (may be empty).
|
||||
auto option_text = [&denylist, &full](const std::string& opt_id, const std::string& pure_key, wxString& label, wxString& value,
|
||||
wxString& unit) -> bool {
|
||||
if (denylist.count(pure_key) > 0)
|
||||
@@ -224,9 +220,8 @@ void PublishSettingsDialog::build_option_model()
|
||||
return true;
|
||||
};
|
||||
|
||||
// --- Phase 1: printer per-extruder retraction settings (displayed first,
|
||||
// mirroring the sidebar's Printer group). The printer tab's
|
||||
// "Extruder"/"Extruder N" pages carry the per-extruder retraction options.
|
||||
// --- Phase 1: printer per-extruder retraction settings (first, mirroring the sidebar's
|
||||
// Printer group), from the printer tab's "Extruder"/"Extruder N" pages.
|
||||
{
|
||||
size_t g = section_group_for(Section::Printer);
|
||||
category_index_for(_L("Extruder"), Section::Printer, "custom-gcode_extruder", g, 0);
|
||||
@@ -238,18 +233,17 @@ void PublishSettingsDialog::build_option_model()
|
||||
continue;
|
||||
const wxString page_title = Tab::translate_category(page->title(), tab->m_type);
|
||||
for (const ConfigOptionsGroupShp& optgroup : page->m_optgroups) {
|
||||
// Allowlist on the untranslated optgroup title; the "Retraction
|
||||
// when switching material" group is intentionally skipped.
|
||||
// Allowlist on the untranslated optgroup title; the "Retraction when
|
||||
// switching material" group is intentionally skipped.
|
||||
if (optgroup->title != "Retraction" && optgroup->title != "Z-Hop")
|
||||
continue;
|
||||
const wxString subcategory = _(optgroup->title);
|
||||
for (const auto& opt : optgroup->opt_map()) {
|
||||
const std::string& opt_id = opt.first;
|
||||
const std::string& pure_key = opt.second.first;
|
||||
// Per-extruder "#N" variants collapse to the first base key. The row stores
|
||||
// the BASE key (whole-vector semantics on load: the size-guarded apply
|
||||
// copies the author's full vector), while the "#0" opt_id is only used to
|
||||
// display the first extruder's value.
|
||||
// Per-extruder "#N" variants collapse to the first base key. The row
|
||||
// stores the base key; GetPublishedKeys() later expands it back to one
|
||||
// "#N" entry per extruder so the load side can apply per-extruder values.
|
||||
if (!added.insert(pure_key).second)
|
||||
continue;
|
||||
wxString label, value, unit;
|
||||
@@ -264,8 +258,8 @@ void PublishSettingsDialog::build_option_model()
|
||||
}
|
||||
}
|
||||
|
||||
// --- Phase 2: per-material sections synthesized from the filament tab's
|
||||
// "Setting Overrides" page, under the Filament group.
|
||||
// --- Phase 2: per-material sections synthesized from the filament tab's "Setting
|
||||
// Overrides" page, under the Filament group.
|
||||
{
|
||||
size_t g = section_group_for(Section::Material);
|
||||
Tab* filament_tab = nullptr;
|
||||
@@ -283,17 +277,16 @@ void PublishSettingsDialog::build_option_model()
|
||||
}
|
||||
|
||||
if (overrides_page != nullptr) {
|
||||
// One section per filament slot: a 4-slot printer (e.g. 1 PLA +
|
||||
// 3 PETG) shows 4 separate pages, each disambiguated internally by
|
||||
// its colour chip and slot identity while displaying the bare name.
|
||||
// One section per filament slot (a 4-slot printer shows 4 pages), each
|
||||
// disambiguated by its colour chip and slot identity while showing the bare name.
|
||||
for (size_t slot = 0; slot < bundle->filament_presets.size(); ++slot) {
|
||||
const PublishMaterialIdentity identity = material_identity(slot, full);
|
||||
const wxString title = material_title(slot, bundle, full);
|
||||
const size_t category_index = category_index_for(title, Section::Material, "custom-gcode_filament", g, slot, identity);
|
||||
|
||||
// Filament-publishing-v2 rows: the author may require a filament colour and/or
|
||||
// a vendor-agnostic material type for this slot. They live in their own
|
||||
// optgroup so they stay visually separated from the setting rows.
|
||||
// Material requirement rows: an optional filament colour and/or a
|
||||
// vendor-agnostic material type for this slot, in their own optgroup so they
|
||||
// stay visually separated from the setting rows.
|
||||
{
|
||||
const size_t req_sub = subcategory_index_for(category_index, _L("Material"), "custom-gcode_filament");
|
||||
std::string hex;
|
||||
@@ -309,18 +302,16 @@ void PublishSettingsDialog::build_option_model()
|
||||
RowKind::Type);
|
||||
}
|
||||
|
||||
// A material section must not repeat a key; the same key may
|
||||
// appear in other material sections - that is intended.
|
||||
// A material section must not repeat a key; the same key may appear in other
|
||||
// material sections - that is intended.
|
||||
std::set<std::string> material_added;
|
||||
|
||||
for (const ConfigOptionsGroupShp& optgroup : overrides_page->m_optgroups) {
|
||||
// Allowlist on the untranslated optgroup title; the
|
||||
// "Ironing" group is intentionally skipped.
|
||||
// Allowlist on the untranslated optgroup title; "Ironing" is skipped.
|
||||
if (optgroup->title != "Retraction" && optgroup->title != "Retraction when switching material")
|
||||
continue;
|
||||
for (const auto& opt : optgroup->opt_map()) {
|
||||
// Row keys are base keys (no "#N"): the load side
|
||||
// matches the material and uses the author's slot.
|
||||
// Row keys are base keys; the load side applies them positionally.
|
||||
const std::string& opt_id = opt.first;
|
||||
std::string base = opt_id.substr(0, opt_id.find('#'));
|
||||
if (!material_added.insert(base).second)
|
||||
@@ -381,17 +372,15 @@ void PublishSettingsDialog::build_option_model()
|
||||
}
|
||||
}
|
||||
|
||||
// Pre-check the dirty (modified) settings and mark them bold. The base-key
|
||||
// match covers all sections; collect_dirty_settings_keys already unions the
|
||||
// prints, printers and filaments of the bundle.
|
||||
// Pre-check the dirty (modified) settings and mark them bold (base-key match, across all
|
||||
// sections; collect_dirty_settings_keys unions the prints, printers and filaments).
|
||||
std::set<std::string> dirty_base;
|
||||
for (const std::string& key : collect_dirty_settings_keys(*wxGetApp().preset_bundle)) {
|
||||
auto n = key.find('#');
|
||||
dirty_base.insert(n == std::string::npos ? key : key.substr(0, n));
|
||||
}
|
||||
for (Row& row : m_rows) {
|
||||
// The Color/Type requirement rows are not "dirty overrides": they are never
|
||||
// auto-checked by the dirty pre-check.
|
||||
// The Color/Type requirement rows are not "dirty overrides": never auto-checked.
|
||||
if (row.kind != RowKind::Setting)
|
||||
continue;
|
||||
std::string base = row.key.substr(0, row.key.find('#'));
|
||||
@@ -402,8 +391,8 @@ void PublishSettingsDialog::build_option_model()
|
||||
}
|
||||
}
|
||||
|
||||
// Wire the "Full Publish" checkboxes: toggling one disables/enables the material's
|
||||
// rows. Bind by index so the lambda stays valid even if the vector is reallocated later.
|
||||
// Wire the "Full Publish" checkboxes: toggling one disables/enables the material's rows.
|
||||
// Bind by index so the lambda stays valid even if the vector is reallocated later.
|
||||
for (size_t c = 0; c < m_categories.size(); ++c)
|
||||
if (m_categories[c].full_check != nullptr)
|
||||
m_categories[c].full_check->Bind(wxEVT_CHECKBOX, [this, c](wxCommandEvent&) { on_full_toggle(c); });
|
||||
@@ -449,6 +438,7 @@ size_t PublishSettingsDialog::section_group_for(Section kind)
|
||||
section.icon_name = "process";
|
||||
break;
|
||||
}
|
||||
section.icon_bmp = ScalableBitmap(this, section.icon_name, 16);
|
||||
|
||||
constexpr long tab_style = wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_NONE | wxWANTS_CHARS |
|
||||
wxTR_FULL_ROW_HIGHLIGHT;
|
||||
@@ -466,7 +456,10 @@ size_t PublishSettingsDialog::section_group_for(Section kind)
|
||||
page_sizer->Add(section.page_host, 1, wxEXPAND | wxTOP, FromDIP(4));
|
||||
section.page->SetSizer(page_sizer);
|
||||
|
||||
m_outer_tabs->AppendItem(section.title);
|
||||
if (section.icon_bmp.bmp().IsOk())
|
||||
m_outer_tabs->AppendItem(section.title, section.icon_bmp.bmp());
|
||||
else
|
||||
m_outer_tabs->AppendItem(section.title);
|
||||
m_outer_host_sizer->Add(section.page, 1, wxEXPAND);
|
||||
section.page->Hide();
|
||||
m_sections.push_back(std::move(section));
|
||||
@@ -610,7 +603,7 @@ void PublishSettingsDialog::add_row_ui(const std::string& key,
|
||||
auto* row_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
row_sizer->Add(current.check, 0, wxALIGN_CENTER_VERTICAL);
|
||||
// The value is read-only text (incl. the Type row: the published type is the slot's
|
||||
// normalized type, the author cannot pick a different one here).
|
||||
// normalized type, not author-editable).
|
||||
current.value_label = new wxStaticText(category.scroll, wxID_ANY, value, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
|
||||
current.value_label->SetFont(Label::Body_13);
|
||||
current.value_label->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#262E30")));
|
||||
@@ -643,8 +636,7 @@ void PublishSettingsDialog::on_full_toggle(size_t category_index)
|
||||
|
||||
void PublishSettingsDialog::set_row_bold(Row& row, bool bold)
|
||||
{
|
||||
// Real set/clear: rebase on the dialog's body font so that clearing bold
|
||||
// restores the exact original font (the old CheckList::SetBold was one-way).
|
||||
// Rebase on the dialog's body font so clearing bold restores the exact original font.
|
||||
row.check->SetFont(bold ? Label::Body_13.Bold() : Label::Body_13);
|
||||
}
|
||||
|
||||
@@ -718,12 +710,11 @@ void PublishSettingsDialog::apply_filter(const wxString& filter_text)
|
||||
Freeze();
|
||||
wxString filter = filter_text.Lower();
|
||||
|
||||
// Pseudo filters (menu only): show only checked ("::sel") or only
|
||||
// unchecked ("::nonsel") rows.
|
||||
// Pseudo filters (menu only): show only checked ("::sel") or only unchecked ("::nonsel").
|
||||
const bool pseudo = (filter == "::sel" || filter == "::nonsel");
|
||||
m_fb_sizer->Show(!pseudo);
|
||||
|
||||
// Update row matches first; page and optgroup visibility is applied below.
|
||||
// Row matches are computed first; page and optgroup visibility is applied below.
|
||||
if (pseudo) {
|
||||
if (m_filter_ctrl->GetValue().Lower() != filter) {
|
||||
m_filter_ctrl->ChangeValue(filter);
|
||||
@@ -808,8 +799,7 @@ void PublishSettingsDialog::apply_visibility()
|
||||
|
||||
void PublishSettingsDialog::select_all(bool value)
|
||||
{
|
||||
// "All" does not auto-enable gated material sections; "None" leaves a gated
|
||||
// row's preserved value untouched.
|
||||
// "All" skips disabled (gated) rows; "None" leaves a gated row's preserved value.
|
||||
for (Row& row : m_rows)
|
||||
if (row.check->IsEnabled())
|
||||
row.check->SetValue(value);
|
||||
@@ -829,19 +819,18 @@ bool PublishSettingsDialog::row_is_visible(const Row& row) const
|
||||
void PublishSettingsDialog::select_visible(bool value)
|
||||
{
|
||||
wxString filter = m_filter_ctrl->GetValue().Lower();
|
||||
// In a pseudo-filter view the rows being toggled would all disappear;
|
||||
// drop the filter afterwards so the result stays visible.
|
||||
// In a pseudo-filter view the rows being toggled would all disappear; drop the filter
|
||||
// afterwards so the result stays visible.
|
||||
bool clear_pseudo = (!value && filter == "::nonsel") || (value && filter == "::sel");
|
||||
|
||||
// Toggle the rows that are visible under the *current* filter.
|
||||
// Toggle the rows visible under the *current* filter.
|
||||
for (Row& row : m_rows)
|
||||
if (row_is_visible(row))
|
||||
row.check->SetValue(value);
|
||||
|
||||
if (clear_pseudo) {
|
||||
// Note: SetValue() may fire wxEVT_TEXT on some platforms, which
|
||||
// re-enters apply_filter() - that is fine, the rows above were already
|
||||
// toggled and the trailing call below is idempotent.
|
||||
// Note: SetValue() may fire wxEVT_TEXT on some platforms, re-entering apply_filter() -
|
||||
// that is fine; the rows above were already toggled and the trailing call is idempotent.
|
||||
m_filter_ctrl->ChangeValue("");
|
||||
apply_filter(""); // resync visibility and the All/None bar
|
||||
}
|
||||
@@ -895,12 +884,31 @@ void PublishSettingsDialog::show_menu(wxMouseEvent& evt)
|
||||
std::vector<std::string> PublishSettingsDialog::GetPublishedKeys() const
|
||||
{
|
||||
std::vector<std::string> out;
|
||||
// Process and printer sections both travel through published_keys (the load-side
|
||||
// overlay applies process keys to the prints edited preset and the allowlisted
|
||||
// printer keys to the printers edited preset). Material keys use a separate API.
|
||||
for (const Row& row : m_rows)
|
||||
if ((row.section == Section::Print || row.section == Section::Printer) && row.check->GetValue())
|
||||
// Process and printer sections both travel through published_keys (the load-side overlay
|
||||
// applies process keys to the prints edited preset and the allowlisted printer keys to the
|
||||
// printers edited preset); material keys use a separate API.
|
||||
const DynamicPrintConfig full = wxGetApp().preset_bundle->full_config();
|
||||
for (const Row& row : m_rows) {
|
||||
if ((row.section != Section::Print && row.section != Section::Printer) || !row.check->GetValue())
|
||||
continue;
|
||||
if (row.section == Section::Printer) {
|
||||
// Printer rows store the base key (per-extruder "#N" variants collapsed during
|
||||
// build). Publish every extruder element so the load side can apply per-extruder
|
||||
// values even when the receiver has a different extruder count; a scalar printer
|
||||
// key is published as-is.
|
||||
const std::string base_key = row.key.substr(0, row.key.find('#'));
|
||||
if (const ConfigOption* opt = full.option(base_key)) {
|
||||
if (const auto* vec = dynamic_cast<const ConfigOptionVectorBase*>(opt)) {
|
||||
for (size_t i = 0; i < vec->size(); ++i)
|
||||
out.push_back(base_key + "#" + std::to_string(i));
|
||||
} else {
|
||||
out.push_back(base_key);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out.push_back(row.key);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -915,8 +923,15 @@ std::vector<Slic3r::PublishedMaterialEntry> PublishSettingsDialog::GetPublishedM
|
||||
entry.filament_vendor = cat.filament_vendor;
|
||||
entry.filament_id = cat.filament_id;
|
||||
entry.slot = static_cast<int>(cat.filament_slot);
|
||||
// "Full Publish": the entire filament preset of the slot is embedded; type and color
|
||||
// are implicitly published, and the per-key rows are disabled and their state is ignored.
|
||||
// The author's preset id distinguishes exact variants that share filament_id
|
||||
// ("Generic PLA" vs "Generic PLA Matte"), so the receiver can match precisely.
|
||||
PresetBundle *bundle = wxGetApp().preset_bundle;
|
||||
if (bundle != nullptr && cat.filament_slot < bundle->filament_presets.size()) {
|
||||
if (const Preset *preset = bundle->filaments.find_preset(bundle->filament_presets[cat.filament_slot], false, true))
|
||||
entry.setting_id = preset->setting_id;
|
||||
}
|
||||
// "Full Publish": the whole filament preset is embedded; type and colour are implicitly
|
||||
// published, and the per-key rows are disabled / their state ignored.
|
||||
if (cat.full_check != nullptr && cat.full_check->GetValue()) {
|
||||
entry.full = true;
|
||||
entry.full_keys = full_keys_for_slot();
|
||||
@@ -946,8 +961,7 @@ std::vector<Slic3r::PublishedMaterialEntry> PublishSettingsDialog::GetPublishedM
|
||||
entry.keys.push_back(row.key);
|
||||
}
|
||||
}
|
||||
// A material with only setting keys but none checked, or with nothing selected at all,
|
||||
// carries no information for the writer.
|
||||
// Nothing checked at all -> nothing to write.
|
||||
if (!entry.keys.empty() || entry.publish_type || entry.publish_color)
|
||||
out.push_back(std::move(entry));
|
||||
}
|
||||
@@ -956,9 +970,9 @@ std::vector<Slic3r::PublishedMaterialEntry> PublishSettingsDialog::GetPublishedM
|
||||
|
||||
std::vector<std::string> PublishSettingsDialog::full_keys_for_slot() const
|
||||
{
|
||||
// The canonical filament preset keys, minus the structural keys the published overlay must
|
||||
// The canonical filament preset keys minus the structural keys the published overlay must
|
||||
// never touch (inherits, compatibility, *_settings_id, ...), plus filament_colour (not a
|
||||
// member of Preset::filament_options). The values travel in the exported config, masked to
|
||||
// member of Preset::filament_options). Values travel in the exported config, masked to
|
||||
// this slot, and are applied on load onto the receiver's slot.
|
||||
const std::set<std::string>& denylist = publish_structural_keys();
|
||||
std::vector<std::string> keys;
|
||||
@@ -971,7 +985,7 @@ std::vector<std::string> PublishSettingsDialog::full_keys_for_slot() const
|
||||
|
||||
void PublishSettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
{
|
||||
// Rescale toolbar bitmaps and icons; collapse chevrons are vector-drawn and repaint themselves.
|
||||
// Rescale toolbar bitmaps and icons; collapse chevrons are vector-drawn and repaint.
|
||||
m_search.msw_rescale();
|
||||
m_menu.msw_rescale();
|
||||
m_filter_box->SetIcon(m_search.bmp());
|
||||
@@ -1000,8 +1014,13 @@ void PublishSettingsDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
cat.list_sizer->Layout();
|
||||
}
|
||||
|
||||
for (SectionGroup& section : m_sections)
|
||||
for (size_t s = 0; s < m_sections.size(); ++s) {
|
||||
SectionGroup& section = m_sections[s];
|
||||
section.icon_bmp.msw_rescale();
|
||||
if (section.icon_bmp.bmp().IsOk())
|
||||
m_outer_tabs->SetItemBitmap(s, section.icon_bmp.bmp());
|
||||
section.tabs->Rescale();
|
||||
}
|
||||
|
||||
// Refresh the per-row Color chips at the new DPI.
|
||||
for (Row& row : m_rows) {
|
||||
|
||||
@@ -28,25 +28,21 @@ struct PublishMaterialIdentity
|
||||
std::string id;
|
||||
};
|
||||
|
||||
// Dialog that lets a model author select which settings get embedded in a 3MF.
|
||||
// Settings are grouped into the same nested custom tab layout used by the
|
||||
// Process settings: Printer, Filament, and Process outer tabs, with category or
|
||||
// material tabs inside each section. Optgroups are ordinary grouped headers.
|
||||
// Modified (dirty) settings are pre-checked and shown bold. On OK, the print
|
||||
// rows become the "published_keys" list and the material rows become the
|
||||
// per-material "published_material_keys".
|
||||
// Dialog letting a model author select which settings get embedded in a 3MF. Nested tab layout
|
||||
// mirroring the Process settings (Printer / Filament / Process outer tabs, category or material
|
||||
// tabs inside each). Dirty settings are pre-checked and shown bold; on OK the print rows become
|
||||
// "published_keys" and the material rows become "published_material_keys".
|
||||
class PublishSettingsDialog : public DPIDialog
|
||||
{
|
||||
public:
|
||||
PublishSettingsDialog(wxWindow* parent = nullptr);
|
||||
~PublishSettingsDialog();
|
||||
|
||||
// The selected print-section setting keys (in display order). Keys may
|
||||
// contain '#'.
|
||||
// The selected print/printer setting keys (in display order); printer keys carry a '#N'
|
||||
// per-extruder suffix.
|
||||
std::vector<std::string> GetPublishedKeys() const;
|
||||
|
||||
// The selected keys grouped per material: one entry per material section
|
||||
// with at least one checked key. Keys are base keys (no "#N" suffix).
|
||||
// The selected keys grouped per material section (base keys, no '#N' suffix).
|
||||
std::vector<Slic3r::PublishedMaterialEntry> GetPublishedMaterialKeys() const;
|
||||
|
||||
protected:
|
||||
@@ -56,9 +52,9 @@ private:
|
||||
// Which part of the settings the row/category came from.
|
||||
enum class Section { Print, Printer, Material };
|
||||
|
||||
// One selectable setting row: a checkbox (setting name) plus a value label
|
||||
// and a (optional) grey unit label. key is the full config key and may carry
|
||||
// a "#N" variant suffix (print/printer rows); material rows carry the base key.
|
||||
// One selectable setting row: a checkbox (setting name) plus a value label and an optional
|
||||
// grey unit label. key is the full config key, possibly with a "#N" variant suffix
|
||||
// (print/printer rows); material rows carry the base key.
|
||||
enum class RowKind {
|
||||
Setting, // a regular setting key
|
||||
Color, // material colour requirement (filament_colour)
|
||||
@@ -113,9 +109,9 @@ private:
|
||||
ScalableBitmap icon_bmp; // scalable bitmap for DPI changes
|
||||
wxStaticBitmap* icon{nullptr};
|
||||
wxStaticBitmap* filament_color_chip{nullptr};
|
||||
wxStaticText* title_label{nullptr}; // material title (static text, Full Publish carries the label elsewhere)
|
||||
// "Full Publish": serializing the entire filament preset of this slot. While checked,
|
||||
// the slot's rows (incl. Color/Type) are disabled.
|
||||
wxStaticText* title_label{nullptr}; // material title (static text; Full Publish carries the label elsewhere)
|
||||
// "Full Publish": while checked, the whole slot preset is serialized and its rows
|
||||
// (incl. Color/Type) are disabled.
|
||||
bool full{false};
|
||||
wxCheckBox* full_check{nullptr};
|
||||
// Material identity, only for Section::Material categories.
|
||||
@@ -134,6 +130,7 @@ private:
|
||||
wxString title; // _L("Printer") / _L("Filament") / _L("Process")
|
||||
Section kind{Section::Print}; // maps 1:1 to the display group
|
||||
std::string icon_name; // "printer" / "filament" / "process"
|
||||
ScalableBitmap icon_bmp; // tab icon next to the title; rescaled on DPI change
|
||||
wxPanel* page{nullptr};
|
||||
TabCtrl* tabs{nullptr};
|
||||
wxPanel* page_host{nullptr};
|
||||
|
||||
Reference in New Issue
Block a user