mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-26 12:22:32 +00:00
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 (cherry picked from commit 7b7ebf1b959ba5c967baff30fb226c808a2e7d44)
This commit is contained in:
@@ -2126,10 +2126,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -183,7 +183,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;
|
||||
|
||||
|
||||
@@ -2607,10 +2607,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
|
||||
|
||||
@@ -1125,6 +1125,15 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", has_scarf_joint_seam:" << has_scarf_joint_seam;
|
||||
}
|
||||
|
||||
//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
|
||||
@@ -1140,7 +1149,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");
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7645,7 +7645,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;
|
||||
|
||||
@@ -7661,7 +7661,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;
|
||||
}
|
||||
@@ -7844,6 +7844,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool DynamicPrintConfig::is_custom_defined()
|
||||
{
|
||||
auto* is_custom_defined = dynamic_cast<const ConfigOptionStrings*>(this->option("is_custom_defined"));
|
||||
|
||||
@@ -604,8 +604,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);
|
||||
|
||||
bool is_custom_defined();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user