sublayers and more

This commit is contained in:
Ian Bassi
2026-08-23 22:11:48 +08:00
committed by SoftFever
parent 76f23396ea
commit ccd34ab03a
11 changed files with 355 additions and 7 deletions
+85
View File
@@ -3575,6 +3575,63 @@ unsigned int PresetBundle::sync_ams_list(std::vector<std::pair<DynamicPrintConfi
ConfigOptionStrings *filament_color_type = project_config.option<ConfigOptionStrings>("filament_colour_type");
ConfigOptionInts * filament_map = project_config.option<ConfigOptionInts>("filament_map");
ConfigOptionInts * filament_volume_map = project_config.option<ConfigOptionInts>("filament_volume_map");
// Snapshot and temporarily strip mixed filament slots so AMS sync operates on physical
// filaments only. A mixed slot is virtual and has no tray to sync against; leaving it in
// would let AMS mapping overwrite it and would break the physical-first slot ordering the
// rest of the feature relies on. The slots are re-appended verbatim after the sync.
struct MixedSlotSnapshot {
std::string preset;
std::string color;
std::string color_type;
std::string mixed_components;
std::string mixed_sublayer_ratios;
bool mixed_gradient = false;
std::string mixed_gradient_range;
std::string mixed_gradient_curve;
bool mixed_gradient_per_part = false;
};
std::vector<MixedSlotSnapshot> mixed_snapshots;
auto* is_mixed_opt = project_config.option<ConfigOptionBools>("filament_is_mixed");
auto* mixed_comp_opt = project_config.option<ConfigOptionStrings>("filament_mixed_components");
auto* mixed_ratios_opt = project_config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios");
auto* mixed_gradient_opt = project_config.option<ConfigOptionBools>("filament_mixed_gradient");
auto* mixed_grad_range_opt = project_config.option<ConfigOptionStrings>("filament_mixed_gradient_range");
auto* mixed_grad_curve_opt = project_config.option<ConfigOptionStrings>("filament_mixed_gradient_curve");
auto* mixed_per_part_opt = project_config.option<ConfigOptionBools>("filament_mixed_gradient_per_part");
if (is_mixed_opt) {
for (size_t i = 0; i < is_mixed_opt->values.size() && i < this->filament_presets.size(); ++i) {
if (!is_mixed_opt->values[i])
continue;
MixedSlotSnapshot snap;
snap.preset = this->filament_presets[i];
snap.color = (i < filament_color->values.size()) ? filament_color->values[i] : "";
snap.color_type = (i < filament_color_type->values.size()) ? filament_color_type->values[i] : "";
if (mixed_comp_opt && i < mixed_comp_opt->values.size()) snap.mixed_components = mixed_comp_opt->values[i];
if (mixed_ratios_opt && i < mixed_ratios_opt->values.size()) snap.mixed_sublayer_ratios = mixed_ratios_opt->values[i];
if (mixed_gradient_opt && i < mixed_gradient_opt->values.size()) snap.mixed_gradient = mixed_gradient_opt->values[i];
if (mixed_grad_range_opt && i < mixed_grad_range_opt->values.size()) snap.mixed_gradient_range = mixed_grad_range_opt->values[i];
if (mixed_grad_curve_opt && i < mixed_grad_curve_opt->values.size()) snap.mixed_gradient_curve = mixed_grad_curve_opt->values[i];
if (mixed_per_part_opt && i < mixed_per_part_opt->values.size()) snap.mixed_gradient_per_part = mixed_per_part_opt->values[i];
mixed_snapshots.push_back(snap);
}
if (!mixed_snapshots.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": stripping " << mixed_snapshots.size() << " mixed filament slot(s) before AMS sync";
size_t phys_count = this->filament_presets.size() - mixed_snapshots.size();
this->filament_presets.resize(phys_count);
filament_color->values.resize(phys_count);
filament_color_type->values.resize(phys_count);
filament_map->values.resize(phys_count, 1);
is_mixed_opt->values.resize(phys_count);
if (mixed_comp_opt) mixed_comp_opt->values.resize(phys_count);
if (mixed_ratios_opt) mixed_ratios_opt->values.resize(phys_count);
if (mixed_gradient_opt) mixed_gradient_opt->values.resize(phys_count);
if (mixed_grad_range_opt) mixed_grad_range_opt->values.resize(phys_count);
if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.resize(phys_count);
if (mixed_per_part_opt) mixed_per_part_opt->values.resize(phys_count);
}
}
if (color_only) {
auto get_map_index = [&ams_infos](const std::vector<AMSMapInfo> &infos, const AMSMapInfo &temp) {
for (int i = 0; i < infos.size(); i++) {
@@ -3830,6 +3887,34 @@ unsigned int PresetBundle::sync_ams_list(std::vector<std::pair<DynamicPrintConfi
if (support_interface_filament_opt->value > filament_color_type->values.size())
support_interface_filament_opt->value = 0;
}
// Re-append mixed filament slots that were stripped before AMS sync
if (!mixed_snapshots.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": re-appending " << mixed_snapshots.size() << " mixed filament slot(s) after AMS sync";
size_t new_phys_count = this->filament_presets.size();
if (is_mixed_opt) is_mixed_opt->values.resize(new_phys_count, (unsigned char)false);
if (mixed_comp_opt) mixed_comp_opt->values.resize(new_phys_count);
if (mixed_ratios_opt) mixed_ratios_opt->values.resize(new_phys_count);
if (mixed_gradient_opt) mixed_gradient_opt->values.resize(new_phys_count, (unsigned char)false);
if (mixed_grad_range_opt) mixed_grad_range_opt->values.resize(new_phys_count);
if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.resize(new_phys_count);
if (mixed_per_part_opt) mixed_per_part_opt->values.resize(new_phys_count, (unsigned char)false);
for (auto& snap : mixed_snapshots) {
this->filament_presets.push_back(snap.preset);
filament_color->values.push_back(snap.color);
filament_color_type->values.push_back(snap.color_type);
ams_multi_color_filment.push_back({snap.color});
filament_map->values.push_back(1);
if (is_mixed_opt) is_mixed_opt->values.push_back((unsigned char)true);
if (mixed_comp_opt) mixed_comp_opt->values.push_back(snap.mixed_components);
if (mixed_ratios_opt) mixed_ratios_opt->values.push_back(snap.mixed_sublayer_ratios);
if (mixed_gradient_opt) mixed_gradient_opt->values.push_back((unsigned char)snap.mixed_gradient);
if (mixed_grad_range_opt) mixed_grad_range_opt->values.push_back(snap.mixed_gradient_range);
if (mixed_grad_curve_opt) mixed_grad_curve_opt->values.push_back(snap.mixed_gradient_curve);
if (mixed_per_part_opt) mixed_per_part_opt->values.push_back((unsigned char)snap.mixed_gradient_per_part);
}
}
// Update ams_multi_color_filment
update_filament_multi_color();
update_multi_material_filament_presets();