Add unique filament_id for inherited user presets
When a user creates a new filament preset by inheriting from an existing one (e.g., "Brand ABS @BBL H2D" inheriting from "Generic ABS @BBL H2D"), the resulting preset previously had no filament_id of its own. This caused two problems: 1. The AMS sync pipeline could not distinguish the user preset from its parent, so syncing filaments from the printer always resolved to the generic base preset instead of the user's custom one. 2. External tools that rely on filament_id for preset identification (e.g., Bambuddy, see maziggy/bambuddy#1053) could not assign or recognize user-created inherited presets in AMS slots. The root cause was twofold: - No filament_id was generated during save_current_preset() for inherited filament presets. Only base (non-inheriting) presets received one via the CreatePresetsDialog flow. - The AMS matching logic in sync_ams_list(), get_ams_cobox_infos(), and get_filament_presets() filtered candidates with `get_preset_base(f) == &f`, which by definition excludes any preset with a non-empty inherits() field. This commit: - Generates a unique filament_id (MD5 hash of preset name, prefixed with "P", truncated to 8 chars) when creating a new filament preset in PresetCollection::save_current_preset(). This matches the existing ID generation scheme used for base filaments in CreatePresetsDialog::get_filament_id(). - Persists filament_id into the JSON when saving inherited presets via Preset::save() and get_differed_values_to_update(). - Broadens the AMS filament matching predicates to also consider user presets that carry their own filament_id, rather than requiring them to be base presets. Files changed: src/libslic3r/Preset.cpp - ID generation, save, lookup src/libslic3r/PresetBundle.cpp - AMS sync matching predicates
This commit is contained in:
@@ -2307,7 +2307,7 @@ void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info)
|
||||
continue;
|
||||
}
|
||||
auto iter = std::find_if(filaments.begin(), filaments.end(),
|
||||
[this, &filament_id](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
|
||||
[this, &filament_id](auto &f) { return f.is_compatible && (filaments.get_preset_base(f) == &f || (f.is_user() && !f.filament_id.empty())) && f.filament_id == filament_id; });
|
||||
if (iter == filaments.end()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
|
||||
auto filament_type = ams.opt_string("filament_type", 0u);
|
||||
@@ -2409,7 +2409,7 @@ unsigned int PresetBundle::sync_ams_list(std::vector<std::pair<DynamicPrintConfi
|
||||
auto filament_type = ams.opt_string("filament_type", 0u);
|
||||
auto iter = std::find_if(filaments.begin(), filaments.end(), [this, &filament_id, &has_type, filament_type](auto &f) {
|
||||
has_type |= f.config.opt_string("filament_type", 0u) == filament_type;
|
||||
return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
|
||||
return f.is_compatible && (filaments.get_preset_base(f) == &f || (f.is_user() && !f.filament_id.empty())) && f.filament_id == filament_id; });
|
||||
if (iter == filaments.end()) {
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
|
||||
if (!filament_type.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user