ENH: config: add the extruder variant apply logic in Print::Apply()

we need to keep the original values and update after pre-slice
jira: no-jira

Change-Id: I232d3c43340b4a23bc42121bd05380746e736f20
This commit is contained in:
lane.wei 2024-07-08 16:20:38 +08:00
parent 3321277f86
commit 7b7ebf1b95
8 changed files with 190 additions and 18 deletions

View File

@ -1998,10 +1998,10 @@ bool PresetBundle::support_different_extruders()
return supported;
}
DynamicPrintConfig PresetBundle::full_config(std::vector<int> filament_maps) const
DynamicPrintConfig PresetBundle::full_config(bool apply_extruder, std::vector<int> filament_maps) const
{
return (this->printers.get_edited_preset().printer_technology() == ptFFF) ?
this->full_fff_config(true, filament_maps) :
this->full_fff_config(apply_extruder, filament_maps) :
this->full_sla_config();
}

View File

@ -153,7 +153,7 @@ public:
bool has_defauls_only() const
{ return prints.has_defaults_only() && filaments.has_defaults_only() && printers.has_defaults_only(); }
DynamicPrintConfig full_config(std::vector<int> filament_maps = std::vector<int>()) const;
DynamicPrintConfig full_config(bool apply_extruder = true, std::vector<int> filament_maps = std::vector<int>()) const;
// full_config() with the some "useless" config removed.
DynamicPrintConfig full_config_secure(std::vector<int> filament_maps = std::vector<int>()) const;

View File

@ -2326,10 +2326,18 @@ void Print::finalize_first_layer_convex_hull()
void Print::update_filament_maps_to_config(std::vector<int> f_maps)
{
std::vector<int>& filament_maps = m_full_print_config.option<ConfigOptionInts>("filament_map", true)->values;
if (m_config.filament_map.values != f_maps)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": filament maps changed after pre-slicing.");
m_ori_full_print_config.option<ConfigOptionInts>("filament_map", true)->values = f_maps;
m_config.filament_map.values = f_maps;
filament_maps = f_maps;
m_config.filament_map.values = f_maps;
m_full_print_config = m_ori_full_print_config;
m_full_print_config.update_values_to_printer_extruders_for_multiple_filaments(m_full_print_config, filament_options_with_variant, "filament_self_index", "filament_extruder_variant");
t_config_option_keys keys(filament_options_with_variant.begin(), filament_options_with_variant.end());
m_config.apply_only(m_full_print_config, keys, true);
}
}
std::vector<int> Print::get_filament_maps() const

View File

@ -1107,6 +1107,15 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
}
}
//apply extruder related values
new_full_config.update_values_to_printer_extruders(new_full_config, printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant");
new_full_config.update_values_to_printer_extruders(new_full_config, printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2);
//update print config related with variants
new_full_config.update_values_to_printer_extruders(new_full_config, print_options_with_variant, "print_extruder_id", "print_extruder_variant");
m_ori_full_print_config = new_full_config;
new_full_config.update_values_to_printer_extruders_for_multiple_filaments(new_full_config, filament_options_with_variant, "filament_self_index", "filament_extruder_variant");
// Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles.
DynamicPrintConfig filament_overrides;
//BBS: add plate index
@ -1122,7 +1131,14 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
{
FilamentMapMode map_mode = new_full_config.option<ConfigOptionEnum<FilamentMapMode>>("filament_map_mode", true)->value;
if (map_mode == fmmAuto) {
print_diff_set.erase("filament_map");
if (print_diff_set.find("filament_map") != print_diff_set.end()) {
print_diff_set.erase("filament_map");
//full_config_diff.erase("filament_map");
ConfigOptionInts* old_opt = m_full_print_config.option<ConfigOptionInts>("filament_map", true);
ConfigOptionInts* new_opt = new_full_config.option<ConfigOptionInts>("filament_map", true);
old_opt->set(new_opt);
m_config.filament_map = *new_opt;
}
}
else {
print_diff_set.erase("extruder_filament_count");

View File

@ -550,6 +550,7 @@ protected:
Model m_model;
DynamicPrintConfig m_full_print_config;
DynamicPrintConfig m_ori_full_print_config; //original full print config without extruder applied
PlaceholderParser m_placeholder_parser;
//BBS: add plate id into print base

View File

@ -5553,7 +5553,7 @@ bool DynamicPrintConfig::support_different_extruders(int& extruder_count)
return (variant_set.size() > 1);
}
int DynamicPrintConfig::get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name, unsigned int stride) const
int DynamicPrintConfig::get_index_for_extruder(int extruder_or_filament_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name, unsigned int stride) const
{
int ret = -1;
@ -5569,7 +5569,7 @@ int DynamicPrintConfig::get_index_for_extruder(int extruder_id, std::string id_n
if (extruder_variant == variant) {
if (id_opt) {
const int id = id_opt->get_at(index);
if (id == extruder_id) {
if (id == extruder_or_filament_id) {
ret = index * stride;
break;
}
@ -5752,6 +5752,152 @@ void DynamicPrintConfig::update_values_to_printer_extruders(DynamicPrintConfig&
}
}
void DynamicPrintConfig::update_values_to_printer_extruders_for_multiple_filaments(DynamicPrintConfig& printer_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name)
{
int extruder_count, filament_count;
bool different_extruder = printer_config.support_different_extruders(extruder_count);
if ((extruder_count > 1) || different_extruder)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: extruder_count=%2%, different_extruder=%3%")%__LINE__ %extruder_count %different_extruder;
std::vector<int> filament_maps = printer_config.option<ConfigOptionInts>("filament_map")->values;
size_t filament_count = filament_maps.size();
//apply process settings
//auto opt_nozzle_diameters = this->option<ConfigOptionFloats>("nozzle_diameter");
//int extruder_count = opt_nozzle_diameters->size();
auto opt_extruder_type = dynamic_cast<const ConfigOptionEnumsGeneric*>(printer_config.option("extruder_type"));
auto opt_nozzle_volume_type = dynamic_cast<const ConfigOptionEnumsGeneric*>(printer_config.option("nozzle_volume_type"));
std::vector<int> variant_index;
variant_index.resize(filament_count, -1);
for (int f_index = 0; f_index < filament_count; f_index++)
{
ExtruderType extruder_type = (ExtruderType)(opt_extruder_type->get_at(filament_maps[f_index] - 1));
NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(opt_nozzle_volume_type->get_at(filament_maps[f_index] - 1));
//variant index
variant_index[f_index] = get_index_for_extruder(f_index+1, id_name, extruder_type, nozzle_volume_type, variant_name);
if (variant_index[f_index] < 0) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", Line %1%: could not found extruder_type %2%, nozzle_volume_type %3%, filament_index %4%, extruder index %5%")
%__LINE__ %s_keys_names_ExtruderType[extruder_type] % s_keys_names_NozzleVolumeType[nozzle_volume_type] % (f_index+1) %filament_maps[f_index];
assert(false);
}
}
const ConfigDef *config_def = this->def();
if (!config_def) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", Line %1%: can not find config define")%__LINE__;
return;
}
for (auto& key: key_set)
{
const ConfigOptionDef *optdef = config_def->get(key);
if (!optdef) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: can not find opt define for %2%")%__LINE__%key;
continue;
}
switch (optdef->type) {
case coStrings:
{
ConfigOptionStrings * opt = this->option<ConfigOptionStrings>(key);
std::vector<std::string> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coInts:
{
ConfigOptionInts * opt = this->option<ConfigOptionInts>(key);
std::vector<int> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coFloats:
{
ConfigOptionFloats * opt = this->option<ConfigOptionFloats>(key);
std::vector<double> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coPercents:
{
ConfigOptionPercents * opt = this->option<ConfigOptionPercents>(key);
std::vector<double> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coFloatsOrPercents:
{
ConfigOptionFloatsOrPercents * opt = this->option<ConfigOptionFloatsOrPercents>(key);
std::vector<FloatOrPercent> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coBools:
{
ConfigOptionBools * opt = this->option<ConfigOptionBools>(key);
std::vector<unsigned char> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
case coEnums:
{
ConfigOptionEnumsGeneric * opt = this->option<ConfigOptionEnumsGeneric>(key);
std::vector<int> new_values;
new_values.resize(filament_count);
for (int f_index = 0; f_index < filament_count; f_index++)
{
new_values[f_index] = opt->get_at(variant_index[f_index]);
}
opt->values = new_values;
break;
}
default:
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", Line %1%: unsupported option type for %2%")%__LINE__%key;
break;
}
}
}
}
void DynamicPrintConfig::update_non_diff_values_to_base_config(DynamicPrintConfig& new_config, const t_config_option_keys& keys, const std::set<std::string>& different_keys,
std::string extruder_id_name, std::string extruder_variant_name, std::set<std::string>& key_set1, std::set<std::string>& key_set2)
{

View File

@ -497,8 +497,9 @@ public:
//BBS
bool is_using_different_extruders();
bool support_different_extruders(int& extruder_count);
int get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name, unsigned int stride = 1) const;
int get_index_for_extruder(int extruder_or_filament_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name, unsigned int stride = 1) const;
void update_values_to_printer_extruders(DynamicPrintConfig& printer_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name, unsigned int stride = 1, unsigned int extruder_id = 0);
void update_values_to_printer_extruders_for_multiple_filaments(DynamicPrintConfig& printer_config, std::set<std::string>& key_set, std::string id_name, std::string variant_name);
void update_non_diff_values_to_base_config(DynamicPrintConfig& new_config, const t_config_option_keys& keys, const std::set<std::string>& different_keys, std::string extruder_id_name, std::string extruder_variant_name,
std::set<std::string>& key_set1, std::set<std::string>& key_set2 = std::set<std::string>());

View File

@ -5457,10 +5457,10 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
PartPlate* cur_plate = background_process.get_current_plate();
std::vector<int> f_maps = cur_plate->get_filament_maps();
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(f_maps));
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(false, f_maps));
}
else
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config());
invalidated = background_process.apply(this->model, wxGetApp().preset_bundle->full_config(false));
if ((invalidated == Print::APPLY_STATUS_CHANGED) || (invalidated == Print::APPLY_STATUS_INVALIDATED))
// BBS: add only gcode mode
@ -14005,10 +14005,10 @@ void Plater::apply_background_progress()
Print::ApplyStatus invalidated;
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ") % __LINE__ % plate_index % invalidated % result_valid;
if (invalidated & PrintBase::APPLY_STATUS_INVALIDATED)
@ -14049,10 +14049,10 @@ int Plater::select_plate(int plate_index, bool need_slice)
//always apply the current plate's print
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false));
bool model_fits, validate_err;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" %1%: plate %2%, after apply, invalidated= %3%, previous result_valid %4% ")%__LINE__ %plate_index %invalidated %result_valid;
@ -14357,10 +14357,10 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
//always apply the current plate's print
if (wxGetApp().preset_bundle->get_printer_extruder_count() > 1) {
std::vector<int> f_maps = part_plate->get_filament_maps();
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(f_maps));
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false, f_maps));
}
else
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config());
invalidated = p->background_process.apply(this->model(), wxGetApp().preset_bundle->full_config(false));
bool model_fits, validate_err;
validate_current_plate(model_fits, validate_err);