mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-08 08:11:14 +00:00
Size a Project's Mixed-Colour Metadata to the Filaments in the CLI (#16247)
The mixed-colour metadata options are parallel per-slot arrays in the project config. A project saved before they were sized per slot stores a single value for the gradient ones, and one saved before they existed stores none. The GUI sizes all seven to the filament count when it opens a project; the CLI kept the stored arrays and exported one-element defaults for absent ones, so a project it exported carried one-element arrays where the GUI writes one entry per filament. Slicing is unaffected, every reader treats a missing entry as not mixed / no gradient, but the GUI-vs-CLI comparison reported the four gradient keys on every mixed-filament project. The resize helper moves from PresetBundle.cpp, where it was file-local, to PrintConfig.cpp next to set_filament_dev_options(). It creates an option the config lacks before sizing it, a no-op for the bundle's project config where all seven always exist. The CLI calls it with its filament count once the project and loaded filaments are merged, after the check that every mixed slot has a filament of its own.
This commit is contained in:
@@ -4094,6 +4094,8 @@ int CLI::run(int argc, char **argv)
|
||||
flush_and_exit(CLI_MIXED_FILAMENT_INVALID);
|
||||
}
|
||||
}
|
||||
if (filament_count > 0)
|
||||
resize_mixed_filament_metadata(m_print_config, size_t(filament_count), size_t(filament_count));
|
||||
|
||||
m_print_config.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology", true)->value = printer_technology;
|
||||
|
||||
|
||||
@@ -3593,24 +3593,6 @@ void PresetBundle::export_selections(AppConfig &config)
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": printer %1%, print %2%, filaments[0] %3% ")%printers.get_selected_preset_name() % prints.get_selected_preset_name() %filament_presets[0];
|
||||
}
|
||||
|
||||
// Preserve metadata only for existing colour slots; new slots get false/empty defaults.
|
||||
static void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count)
|
||||
{
|
||||
auto resize = [old_slot_count, new_slot_count](auto *opt) {
|
||||
if (opt) {
|
||||
opt->values.resize(std::min(old_slot_count, opt->values.size()));
|
||||
opt->values.resize(new_slot_count);
|
||||
}
|
||||
};
|
||||
resize(config.option<ConfigOptionBools>("filament_is_mixed"));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_components"));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios"));
|
||||
resize(config.option<ConfigOptionBools>("filament_mixed_gradient"));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_range"));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve"));
|
||||
resize(config.option<ConfigOptionBools>("filament_mixed_gradient_per_part"));
|
||||
}
|
||||
|
||||
void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
|
||||
{
|
||||
unsigned old_filament_count = this->filament_presets.size();
|
||||
|
||||
@@ -10845,6 +10845,21 @@ void set_filament_dev_options(DynamicPrintConfig &config, const std::vector<cons
|
||||
}
|
||||
}
|
||||
|
||||
void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count)
|
||||
{
|
||||
auto resize = [old_slot_count, new_slot_count](auto *opt) {
|
||||
opt->values.resize(std::min(old_slot_count, opt->values.size()));
|
||||
opt->values.resize(new_slot_count);
|
||||
};
|
||||
resize(config.option<ConfigOptionBools>("filament_is_mixed", true));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_components", true));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_sublayer_ratios", true));
|
||||
resize(config.option<ConfigOptionBools>("filament_mixed_gradient", true));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_range", true));
|
||||
resize(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve", true));
|
||||
resize(config.option<ConfigOptionBools>("filament_mixed_gradient_per_part", true));
|
||||
}
|
||||
|
||||
|
||||
//used for object/region config
|
||||
//use the smallest of multiple to single
|
||||
|
||||
@@ -933,6 +933,10 @@ extern std::set<std::string> filament_dev_options;
|
||||
// filament_configs, one config per filament in slot order, as the filaments' values one after another.
|
||||
void set_filament_dev_options(DynamicPrintConfig &config, const std::vector<const DynamicPrintConfig *> &filament_configs);
|
||||
|
||||
// Orca: sizes the per-slot mixed-colour metadata options to new_slot_count, keeping the first
|
||||
// old_slot_count values; an option the config lacks is created.
|
||||
void resize_mixed_filament_metadata(DynamicPrintConfig &config, size_t old_slot_count, size_t new_slot_count);
|
||||
|
||||
extern void update_static_print_config_from_dynamic(ConfigBase& config, const DynamicPrintConfig& dest_config, std::vector<int> variant_index, std::set<std::string>& key_set1, int stride = 1);
|
||||
extern void compute_filament_override_value(const std::string& opt_key, const ConfigOption *opt_old_machine, const ConfigOption *opt_new_machine, const ConfigOption *opt_new_filament, const DynamicPrintConfig& new_full_config,
|
||||
t_config_option_keys& diff_keys, DynamicPrintConfig& filament_overrides, std::vector<int>& f_map_indices);
|
||||
|
||||
@@ -863,3 +863,23 @@ TEST_CASE("The device drying options are rebuilt as each filament's values in sl
|
||||
set_filament_dev_options(config, {&two_values, &no_value});
|
||||
REQUIRE(config.option<ConfigOptionStrings>("filament_dev_ams_drying_ams_limitations")->values == std::vector<std::string>({"1", "0", ""}));
|
||||
}
|
||||
|
||||
TEST_CASE("The mixed filament metadata is sized to the filament count", "[Config]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.option<ConfigOptionBools>("filament_is_mixed", true)->values = {false, false, true};
|
||||
config.option<ConfigOptionStrings>("filament_mixed_components", true)->values = {"", "", "1,2"};
|
||||
config.option<ConfigOptionBools>("filament_mixed_gradient", true)->values = {false};
|
||||
config.option<ConfigOptionStrings>("filament_mixed_gradient_range", true)->values = {""};
|
||||
|
||||
resize_mixed_filament_metadata(config, 3, 3);
|
||||
REQUIRE(config.option<ConfigOptionBools>("filament_is_mixed")->values == std::vector<unsigned char>({false, false, true}));
|
||||
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_components")->values == std::vector<std::string>({"", "", "1,2"}));
|
||||
REQUIRE(config.option<ConfigOptionBools>("filament_mixed_gradient")->values == std::vector<unsigned char>({false, false, false}));
|
||||
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_gradient_range")->values == std::vector<std::string>({"", "", ""}));
|
||||
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_gradient_curve")->values == std::vector<std::string>({"", "", ""}));
|
||||
|
||||
resize_mixed_filament_metadata(config, 2, 4);
|
||||
REQUIRE(config.option<ConfigOptionBools>("filament_is_mixed")->values == std::vector<unsigned char>({false, false, false, false}));
|
||||
REQUIRE(config.option<ConfigOptionStrings>("filament_mixed_components")->values == std::vector<std::string>({"", "", "", ""}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user