NEW: config: add logic in config system to support multiple extruder

1. add nozzle_volume_type
2. add extruder_variant_list
3. add printer_extruder_variant,print_extruder_variant, filament_extruder_variant
4. construct backend fullprintconfig

Change-Id: I50659634e2cde363112ff5ded6c199d7548c6f2f
This commit is contained in:
lane.wei 2024-06-01 16:42:54 +08:00
parent 26bf483bfe
commit 03058ba29d
5 changed files with 388 additions and 8 deletions

View File

@ -214,6 +214,7 @@ namespace Slic3r {
std::vector<float> filament_densities;
std::vector<float> filament_costs;
std::vector<int> filament_vitrification_temperature;
std::vector<int> filament_maps;
PrintEstimatedStatistics print_statistics;
std::vector<CustomGCode::Item> custom_gcode_per_print_z;
std::vector<std::pair<float, std::pair<size_t, size_t>>> spiral_vase_layers;

View File

@ -2017,8 +2017,17 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
}
different_settings.emplace_back(different_print_settings);
//BBS: update printer config related with variants
out.update_values_to_printer_extruders(printer_options_with_variant_1, "printer_extruder_id", "printer_extruder_variant");
out.update_values_to_printer_extruders(printer_options_with_variant_2, "printer_extruder_id", "printer_extruder_variant", 2);
//update print config related with variants
out.update_values_to_printer_extruders(print_options_with_variant, "print_extruder_id", "print_extruder_variant");
if (num_filaments <= 1) {
out.apply(this->filaments.get_edited_preset().config);
//BBS: update filament config related with variants
DynamicPrintConfig filament_config = this->filaments.get_edited_preset().config;
filament_config.update_values_to_printer_extruders(filament_options_with_variant, "filament_extruder_id", "filament_extruder_variant", 1, this->filament_maps[0]);
out.apply(filament_config);
compatible_printers_condition.emplace_back(this->filaments.get_edited_preset().compatible_printers_condition());
compatible_prints_condition .emplace_back(this->filaments.get_edited_preset().compatible_prints_condition());
//BBS: add logic for settings check between different system presets
@ -2102,6 +2111,13 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
different_settings.emplace_back(different_filament_settings);
}
std::vector<DynamicPrintConfig> filament_temp_configs;
filament_temp_configs.resize(num_filaments);
for (size_t i = 0; i < num_filaments; ++i) {
filament_temp_configs[i] = *(filament_configs[i]);
filament_temp_configs[i].update_values_to_printer_extruders(filament_options_with_variant, "filament_extruder_id", "filament_extruder_variant", 1, this->filament_maps[i]);
}
// loop through options and apply them to the resulting config.
for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
if (key == "compatible_prints" || key == "compatible_printers")
@ -2110,7 +2126,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
ConfigOption *opt_dst = out.option(key, false);
if (opt_dst->is_scalar()) {
// Get an option, do not create if it does not exist.
const ConfigOption *opt_src = filament_configs.front()->option(key);
const ConfigOption *opt_src = filament_temp_configs.front().option(key);
if (opt_src != nullptr)
opt_dst->set(opt_src);
} else {
@ -2120,7 +2136,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
std::vector<const ConfigOption*> filament_opts(num_filaments, nullptr);
// Setting a vector value from all filament_configs.
for (size_t i = 0; i < filament_opts.size(); ++i)
filament_opts[i] = filament_configs[i]->option(key);
filament_opts[i] = filament_temp_configs[i].option(key);
opt_vec_dst->set(filament_opts);
}
}
@ -2161,6 +2177,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
out.option<ConfigOptionStrings>("filament_settings_id", true)->values = this->filament_presets;
out.option<ConfigOptionString >("printer_settings_id", true)->value = this->printers.get_selected_preset_name();
out.option<ConfigOptionStrings>("filament_ids", true)->values = filament_ids;
out.option<ConfigOptionInts>("filament_map", true)->values = this->filament_maps;
// Serialize the collected "compatible_printers_condition" and "inherits" fields.
// There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
// The vector will not be stored if all fields are empty strings.

View File

@ -124,6 +124,8 @@ public:
// BBS: ams
std::map<int, DynamicPrintConfig> filament_ams_list;
std::vector<std::vector<std::string>> ams_multi_color_filment;
std::vector<int> filament_maps;
// Calibrate
Preset const * calibrate_printer = nullptr;
std::set<Preset const *> calibrate_filaments;

View File

@ -374,6 +374,32 @@ static const t_config_enum_values s_keys_map_ExtruderType = {
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(ExtruderType)
static const t_config_enum_values s_keys_map_NozzleVolumeType = {
{ "Normal", evtNormal },
{ "Big Traffic", evtBigTraffic }
};
CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(NozzleVolumeType)
//BBS
std::string get_extruder_variant_string(ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type)
{
std::string variant_string;
if (extruder_type > etMaxExtruderType) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", unsupported ExtruderType=%1%")%extruder_type;
//extruder_type = etDirectDrive;
return variant_string;
}
if (nozzle_volume_type > evtMaxNozzleVolumeType) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(", unsupported NozzleVolumeType=%1%")%nozzle_volume_type;
//extruder_type = etDirectDrive;
return variant_string;
}
variant_string = s_keys_names_ExtruderType[extruder_type];
variant_string+= " ";
variant_string+= s_keys_names_NozzleVolumeType[nozzle_volume_type];
}
static void assign_printer_technology_to_unknown(t_optiondef_map &options, PrinterTechnology printer_technology)
{
for (std::pair<const t_config_option_key, ConfigOptionDef> &kvp : options)
@ -1504,6 +1530,12 @@ void PrintConfigDef::init_fff_params()
def->mode = comDevelop;
def->set_default_value(new ConfigOptionInts{0});
def = this->add("filament_map", coInts);
def->label = L("Filament map to extruder");
def->tooltip = L("Filament map to extruder");
def->mode = comDevelop;
def->set_default_value(new ConfigOptionInts{1});
def = this->add("filament_max_volumetric_speed", coFloats);
def->label = L("Max volumetric speed");
def->tooltip = L("This setting stands for how much volume of filament can be melted and extruded per second. "
@ -2944,6 +2976,60 @@ void PrintConfigDef::init_fff_params()
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnumsGeneric{ ExtruderType::etDirectDrive });
//BBS
def = this->add("nozzle_volume_type", coEnums);
def->label = L("Nozzle Volume Type");
def->tooltip = ("Nozzle volume type");
def->enum_keys_map = &ConfigOptionEnum<NozzleVolumeType>::get_enum_values();
def->enum_values.push_back("Normal");
def->enum_values.push_back("BigTraffic");
def->enum_labels.push_back(L("Normal"));
def->enum_labels.push_back(L("Big Traffic"));
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionEnumsGeneric{ NozzleVolumeType::evtNormal });
def = this->add("extruder_variant_list", coStrings);
def->label = "Extruder variant list";
def->tooltip = "Extruder variant list";
def->set_default_value(new ConfigOptionStrings { "Direct drive Normal" });
def->cli = ConfigOptionDef::nocli;
def = this->add("printer_extruder_id", coInts);
def->label = "Printer extruder id";
def->tooltip = "Printer extruder id";
def->set_default_value(new ConfigOptionInts { 1 });
def->cli = ConfigOptionDef::nocli;
def = this->add("printer_extruder_variant", coStrings);
def->label = "Printer's extruder variant";
def->tooltip = "Printer's extruder variant";
def->set_default_value(new ConfigOptionStrings { "Direct drive Normal" });
def->cli = ConfigOptionDef::nocli;
def = this->add("print_extruder_id", coInts);
def->label = "Print extruder id";
def->tooltip = "Print extruder id";
def->set_default_value(new ConfigOptionInts { 1 });
def->cli = ConfigOptionDef::nocli;
def = this->add("print_extruder_variant", coStrings);
def->label = "Print's extruder variant";
def->tooltip = "Print's extruder variant";
def->set_default_value(new ConfigOptionStrings { "Direct drive Normal" });
def->cli = ConfigOptionDef::nocli;
def = this->add("filament_extruder_id", coInts);
def->label = "Filament extruder id";
def->tooltip = "Filament extruder id";
def->set_default_value(new ConfigOptionInts { 1 });
def->cli = ConfigOptionDef::nocli;
def = this->add("filament_extruder_variant", coStrings);
def->label = "Filament's extruder variant";
def->tooltip = "Filament's extruder variant";
def->set_default_value(new ConfigOptionStrings { "Direct drive Normal" });
def->cli = ConfigOptionDef::nocli;
def = this->add("retract_restart_extra", coFloats);
def->label = L("Extra length on restart");
//def->label = "Extra length on restart";
@ -4877,6 +4963,24 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
const PrintConfigDef print_config_def;
//todo
std::vector<std::string> print_options_with_variant = {
"outer_wall_speed"
};
std::vector<std::string> filament_options_with_variant = {
"filament_max_volumetric_speed"
};
std::vector<std::string> printer_options_with_variant_1 = {
"retraction_length"
};
//options with silient mode
std::vector<std::string> printer_options_with_variant_2 = {
"machine_max_acceleration_x"
};
DynamicPrintConfig DynamicPrintConfig::full_print_config()
{
return DynamicPrintConfig((const PrintRegionConfig&)FullPrintConfig::defaults());
@ -5236,6 +5340,236 @@ std::string DynamicPrintConfig::get_filament_type(std::string &displayed_filamen
return "PLA";
}
bool DynamicPrintConfig::is_using_different_extruders()
{
bool ret = false;
auto nozzle_diameters_opt = dynamic_cast<const ConfigOptionFloats*>(this->option("nozzle_diameter"));
if (nozzle_diameters_opt != nullptr) {
int size = nozzle_diameters_opt->size();
if (size > 1) {
auto extruder_type_opt = dynamic_cast<const ConfigOptionEnumsGeneric*>(this->option("extruder_type"));
auto nozzle_volume_type_opt = dynamic_cast<const ConfigOptionEnumsGeneric*>(this->option("nozzle_volume_type"));
if (extruder_type_opt && nozzle_volume_type_opt) {
ExtruderType extruder_type = (ExtruderType)(extruder_type_opt->get_at(0));
NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(nozzle_volume_type_opt->get_at(0));
for (int index = 1; index < size; index++)
{
ExtruderType extruder_type_1 = (ExtruderType)(extruder_type_opt->get_at(index));
NozzleVolumeType nozzle_volume_type_1 = (NozzleVolumeType)(nozzle_volume_type_opt->get_at(index));
if ((extruder_type_1 != extruder_type) || (nozzle_volume_type_1 != nozzle_volume_type)) {
ret = true;
break;
}
}
}
}
}
return ret;
}
bool DynamicPrintConfig::support_different_extruders(int& extruder_count)
{
std::set<std::string> variant_set;
auto nozzle_diameters_opt = dynamic_cast<const ConfigOptionFloats*>(this->option("nozzle_diameter"));
if (nozzle_diameters_opt != nullptr) {
int size = nozzle_diameters_opt->size();
extruder_count = size;
auto extruder_variant_opt = dynamic_cast<const ConfigOptionStrings*>(this->option("extruder_variant_list"));
for (int index = 0; index < size; index++)
{
std::string variant = extruder_variant_opt->get_at(index);
std::vector<std::string> variants_list;
boost::split(variants_list, variant, boost::is_any_of(","), boost::token_compress_on);
if (!variants_list.empty())
variant_set.insert(variants_list.begin(), variants_list.end());
}
}
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)
{
int ret = -1;
auto variant_opt = dynamic_cast<const ConfigOptionStrings*>(this->option(variant_name));
auto id_opt = dynamic_cast<const ConfigOptionInts*>(this->option(id_name));
if ((variant_opt != nullptr)&&(id_opt != nullptr)) {
int v_size = variant_opt->size();
int i_size = variant_opt->size();
std::string extruder_variant = get_extruder_variant_string(extruder_type, nozzle_volume_type);
for (int index = 0; index < v_size; index++)
{
const std::string variant = variant_opt->get_at(index);
const int id = id_opt->get_at(index);
if ((extruder_variant == variant)&&(id == extruder_id)) {
ret = index;
break;
}
}
}
return ret;
}
void DynamicPrintConfig::update_values_to_printer_extruders(std::vector<std::string>& key_list, std::string id_name, std::string variant_name, unsigned int stride, unsigned int extruder_id)
{
int extruder_count;
bool different_extruder = support_different_extruders(extruder_count);
if ((extruder_count > 1) || different_extruder)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", Line %1%: different extruders processing")%__LINE__;
//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*>(this->option("extruder_type"));
auto opt_nozzle_volume_type = dynamic_cast<const ConfigOptionEnumsGeneric*>(this->option("nozzle_volume_type"));
std::vector<int> variant_index;
if (extruder_id > 0 && extruder_id < extruder_count) {
variant_index.resize(1);
ExtruderType extruder_type = (ExtruderType)(opt_extruder_type->get_at(extruder_id - 1));
NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(opt_nozzle_volume_type->get_at(extruder_id - 1));
//variant index
variant_index[0] = get_index_for_extruder(extruder_id, id_name, extruder_type, nozzle_volume_type, variant_name);
extruder_count = 1;
}
else {
variant_index.resize(extruder_count);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
ExtruderType extruder_type = (ExtruderType)(opt_extruder_type->get_at(e_index));
NozzleVolumeType nozzle_volume_type = (NozzleVolumeType)(opt_nozzle_volume_type->get_at(e_index));
//variant index
variant_index[e_index] = get_index_for_extruder(e_index+1, id_name, extruder_type, nozzle_volume_type, variant_name);
}
}
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_list)
{
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(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coInts:
{
ConfigOptionInts * opt = this->option<ConfigOptionInts>(key);
std::vector<int> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coFloats:
{
ConfigOptionFloats * opt = this->option<ConfigOptionFloats>(key);
std::vector<double> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coPercents:
{
ConfigOptionPercents * opt = this->option<ConfigOptionPercents>(key);
std::vector<double> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coFloatsOrPercents:
{
ConfigOptionFloatsOrPercents * opt = this->option<ConfigOptionFloatsOrPercents>(key);
std::vector<FloatOrPercent> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coBools:
{
ConfigOptionBools * opt = this->option<ConfigOptionBools>(key);
std::vector<unsigned char> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
opt->values = new_values;
break;
}
case coEnums:
{
ConfigOptionEnumsGeneric * opt = this->option<ConfigOptionEnumsGeneric>(key);
std::vector<int> new_values;
new_values.resize(extruder_count * stride);
for (int e_index = 0; e_index < extruder_count; e_index++)
{
for (int i = 0; i < stride; i++)
new_values[e_index*stride + i] = opt->get_at(variant_index[e_index]*stride + i);
}
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"));

View File

@ -243,7 +243,7 @@ enum class ExtruderOnlyAreaType:unsigned char {
// BBS
enum LayerSeq {
flsAuto,
flsAuto,
flsCutomize
};
@ -284,9 +284,18 @@ enum ZHopType {
// BBS
enum ExtruderType {
etDirectDrive = 0,
etBowden
etBowden,
etMaxExtruderType = etBowden
};
enum NozzleVolumeType {
evtNormal = 0,
evtBigTraffic,
evtMaxNozzleVolumeType = evtBigTraffic
};
extern std::string get_extruder_variant_string(ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type);
static std::string bed_type_to_gcode_string(const BedType type)
{
std::string type_str;
@ -485,8 +494,18 @@ public:
//BBS special case Support G/ Support W
std::string get_filament_type(std::string &displayed_filament_type, int id = 0);
//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);
void update_values_to_printer_extruders(std::vector<std::string>& key_list, std::string id_name, std::string variant_name, unsigned int stride = 1, unsigned int extruder_id = 0);
bool is_custom_defined();
};
extern std::vector<std::string> print_options_with_variant;
extern std::vector<std::string> filament_options_with_variant;
extern std::vector<std::string> printer_options_with_variant_1;
extern std::vector<std::string> printer_options_with_variant_2;
void handle_legacy_sla(DynamicPrintConfig &config);
@ -808,6 +827,8 @@ PRINT_CONFIG_CLASS_DEFINE(
PRINT_CONFIG_CLASS_DEFINE(
PrintRegionConfig,
((ConfigOptionInts, print_extruder_id))
((ConfigOptionStrings, print_extruder_variant))
((ConfigOptionInt, bottom_shell_layers))
((ConfigOptionFloat, bottom_shell_thickness))
((ConfigOptionFloat, bridge_angle))
@ -922,8 +943,8 @@ PRINT_CONFIG_CLASS_DEFINE(
PRINT_CONFIG_CLASS_DEFINE(
GCodeConfig,
((ConfigOptionString, before_layer_change_gcode))
((ConfigOptionString, printing_by_object_gcode))
((ConfigOptionString, before_layer_change_gcode))
((ConfigOptionString, printing_by_object_gcode))
((ConfigOptionFloats, deretraction_speed))
//BBS
((ConfigOptionBool, enable_arc_fitting))
@ -947,6 +968,9 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionInts, temperature_vitrification)) //BBS
((ConfigOptionFloats, filament_max_volumetric_speed))
((ConfigOptionInts, required_nozzle_HRC))
((ConfigOptionInts, filament_map))
((ConfigOptionInts, filament_extruder_id))
((ConfigOptionStrings, filament_extruder_variant))
((ConfigOptionFloat, machine_load_filament_time))
((ConfigOptionFloat, machine_unload_filament_time))
((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower))
@ -998,6 +1022,9 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionBool, accel_to_decel_enable))
((ConfigOptionPercent, accel_to_decel_factor))
((ConfigOptionEnumsGeneric, extruder_type))
((ConfigOptionEnumsGeneric, nozzle_volume_type))
((ConfigOptionInts, printer_extruder_id))
((ConfigOptionStrings, printer_extruder_variant))
//Orca
((ConfigOptionBool, has_scarf_joint_seam))
)
@ -1524,7 +1551,6 @@ private:
static uint64_t s_last_timestamp;
};
} // namespace Slic3r
// Serialization through the Cereal library