ENH: add extruder_ams_count behavior

1. save to appconfig and project setting
2. use it to group
jira: none

Change-Id: Id4048fc1b47f6904b2e9c0154aaa3a2b03590437
This commit is contained in:
zhimin.zeng 2024-07-17 17:19:27 +08:00 committed by lane.wei
parent 6c02c7bc8c
commit da32b878b3
8 changed files with 108 additions and 35 deletions

View File

@ -1134,10 +1134,24 @@ std::vector<int> ToolOrdering::get_recommended_filament_maps(const std::vector<s
// if mutli_extruder, calc group,otherwise set to 0
if (nozzle_nums == 2)
{
std::vector<std::string> extruder_ams_count_str = print_config->extruder_ams_count.values;
auto extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str);
std::vector<int> group_size = { 16, 16 };
if (extruder_ams_counts.size() > 0) {
assert(extruder_ams_counts.size() == 2);
for (int i = 0; i < extruder_ams_counts.size(); ++i) {
group_size[i] = 0;
const auto &ams_count = extruder_ams_counts[i];
for (auto iter = ams_count.begin(); iter != ams_count.end(); ++iter) {
group_size[i] += iter->first * iter->second;
}
}
}
FilamentGroup fg(
nozzle_flush_mtx,
used_filaments.size(),
{ 16,16 }
group_size
);
fg.get_custom_seq = get_custom_seq;
fg.calc_filament_group(layer_filaments,FGStrategy::BestFit);

View File

@ -1615,6 +1615,13 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p
}
filament_colors.resize(filament_presets.size(), "#00AE42");
project_config.option<ConfigOptionStrings>("filament_colour")->values = filament_colors;
std::vector<std::string> extruder_ams_count_str;
if (config.has("presets", "extruder_ams_count")) {
boost::algorithm::split(extruder_ams_count_str, config.get("presets", "extruder_ams_count"), boost::algorithm::is_any_of(","));
}
this->extruder_ams_counts = get_extruder_ams_count(extruder_ams_count_str);
std::vector<std::string> matrix;
if (config.has("presets", "flush_volumes_matrix")) {
boost::algorithm::split(matrix, config.get("presets", "flush_volumes_matrix"), boost::algorithm::is_any_of("|"));
@ -1695,6 +1702,7 @@ void PresetBundle::export_selections(AppConfig &config)
CNumericLocalesSetter locales_setter;
std::string filament_colors = boost::algorithm::join(project_config.option<ConfigOptionStrings>("filament_colour")->values, ",");
config.set("presets", "filament_colors", filament_colors);
std::string flush_volumes_matrix = boost::algorithm::join(project_config.option<ConfigOptionFloats>("flush_volumes_matrix")->values |
boost::adaptors::transformed(static_cast<std::string (*)(double)>(std::to_string)),
"|");
@ -2282,7 +2290,7 @@ DynamicPrintConfig PresetBundle::full_fff_config(bool apply_extruder, std::vecto
//BBS: add logic for settings check between different system presets
add_if_some_non_empty(std::move(different_settings), "different_settings_to_system");
add_if_some_non_empty(std::move(print_compatible_printers), "print_compatible_printers");
out.option<ConfigOptionInts>("extruder_filament_count", true)->values = this->extruder_filament_counts;
out.option<ConfigOptionStrings>("extruder_ams_count", true)->values = save_extruder_ams_count_to_string(this->extruder_ams_counts);
out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptFFF;
return out;
@ -2500,11 +2508,12 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
}
}
}
//no need to parse extruder_filament_count
std::vector<int> extruder_filament_count = std::move(config.option<ConfigOptionInts>("extruder_filament_count", true)->values);
config.erase("extruder_filament_count");
if (this->extruder_filament_counts.empty())
this->extruder_filament_counts = extruder_filament_count;
//no need to parse extruder_ams_count
std::vector<std::string> extruder_ams_count = std::move(config.option<ConfigOptionStrings>("extruder_ams_count", true)->values);
config.erase("extruder_ams_count");
if (this->extruder_ams_counts.empty())
this->extruder_ams_counts = get_extruder_ams_count(extruder_ams_count);
// 1) Create a name from the file name.
// Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles.

View File

@ -126,7 +126,8 @@ public:
std::map<int, DynamicPrintConfig> filament_ams_list;
std::vector<std::vector<std::string>> ams_multi_color_filment;
std::vector<int> extruder_filament_counts;
std::vector<std::map<int, int>> extruder_ams_counts;
// Calibrate
Preset const * calibrate_printer = nullptr;
std::set<Preset const *> calibrate_filaments;

View File

@ -244,7 +244,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n
|| opt_key == "first_layer_print_sequence"
|| opt_key == "other_layers_print_sequence"
|| opt_key == "other_layers_print_sequence_nums"
|| opt_key == "extruder_filament_count"
|| opt_key == "extruder_ams_count"
|| opt_key == "filament_map_mode"
|| opt_key == "filament_map"
//|| opt_key == "wipe_tower_bridging"

View File

@ -1144,7 +1144,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
}
}
else {
print_diff_set.erase("extruder_filament_count");
print_diff_set.erase("extruder_ams_count");
std::vector<int> old_filament_map = m_config.filament_map.values;
std::vector<int> new_filament_map = new_full_config.option<ConfigOptionInts>("filament_map", true)->values;

View File

@ -416,6 +416,41 @@ std::string get_extruder_variant_string(ExtruderType extruder_type, NozzleVolume
return variant_string;
}
std::vector<std::map<int, int>> get_extruder_ams_count(const std::vector<std::string>& strs)
{
std::vector<std::map<int, int>> extruder_ams_counts;
for (const std::string& str : strs) {
std::map<int, int> ams_count_info;
std::vector<std::string> ams_infos;
boost::algorithm::split(ams_infos, str, boost::algorithm::is_any_of("|"));
for (const std::string& ams_info : ams_infos) {
std::vector<std::string> numbers;
boost::algorithm::split(numbers, ams_info, boost::algorithm::is_any_of("#"));
assert(numbers.size() == 2);
ams_count_info.insert(std::make_pair(stoi(numbers[0]), stoi(numbers[1])));
}
extruder_ams_counts.emplace_back(ams_count_info);
}
return extruder_ams_counts;
}
std::vector<std::string> save_extruder_ams_count_to_string(const std::vector<std::map<int, int>> &extruder_ams_count)
{
std::vector<std::string> extruder_ams_count_str;
for (size_t i = 0; i < extruder_ams_count.size(); ++i) {
std::ostringstream oss;
const auto &item = extruder_ams_count[i];
for (auto it = item.begin(); it != item.end(); ++it) {
oss << it->first << "#" << it->second;
if (std::next(it) != item.end()) {
oss << "|";
}
}
extruder_ams_count_str.push_back(oss.str());
}
return extruder_ams_count_str;
}
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)
@ -3037,10 +3072,10 @@ void PrintConfigDef::init_fff_params()
def->set_default_value(new ConfigOptionStrings { "Direct Drive Normal" });
def->cli = ConfigOptionDef::nocli;
def = this->add("extruder_filament_count", coInts);
def->label = "Extruder filament count";
def->tooltip = "Filament counts per extruder";
def->set_default_value(new ConfigOptionInts { 1 });
def = this->add("extruder_ams_count", coStrings);
def->label = "Extruder ams count";
def->tooltip = "Ams counts of per extruder";
def->set_default_value(new ConfigOptionStrings { });
def->cli = ConfigOptionDef::nocli;
def = this->add("printer_extruder_id", coInts);

View File

@ -369,6 +369,10 @@ static std::string get_bed_temp_1st_layer_key(const BedType type)
return "";
}
// for parse extruder_ams_count
extern std::vector<std::map<int, int>> get_extruder_ams_count(const std::vector<std::string> &strs);
extern std::vector<std::string> save_extruder_ams_count_to_string(const std::vector<std::map<int, int>> &extruder_ams_count);
#define CONFIG_OPTION_ENUM_DECLARE_STATIC_MAPS(NAME) \
template<> const t_config_enum_names& ConfigOptionEnum<NAME>::get_enum_names(); \
template<> const t_config_enum_values& ConfigOptionEnum<NAME>::get_enum_values();
@ -1032,7 +1036,7 @@ PRINT_CONFIG_CLASS_DEFINE(
((ConfigOptionPercent, accel_to_decel_factor))
((ConfigOptionEnumsGeneric, extruder_type))
((ConfigOptionEnumsGeneric, nozzle_volume_type))
((ConfigOptionInts, extruder_filament_count))
((ConfigOptionStrings, extruder_ams_count))
((ConfigOptionInts, printer_extruder_id))
((ConfigOptionStrings, printer_extruder_variant))
//Orca

View File

@ -655,34 +655,44 @@ public:
static void SetAMSCount(int index, int ams4, int ams1)
{
auto count_str = wxGetApp().app_config->get("preset", "ams_count");
std::vector<std::string> counts;
boost::algorithm::split(counts, count_str, boost::algorithm::is_any_of("|"));
counts.resize(2);
counts[index] = (boost::format("%d/%d") % ams4 % ams1).str();
wxGetApp().app_config->set("preset", "ams_count", boost::algorithm::join(counts, "|"));
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
preset_bundle.extruder_ams_counts.resize(2);
auto &ams_map = preset_bundle.extruder_ams_counts[index];
ams_map[4] = ams4;
ams_map[1] = ams1;
std::vector<std::string> extruder_ams_count = save_extruder_ams_count_to_string(preset_bundle.extruder_ams_counts);
std::string extruder_ams_count_str = boost::algorithm::join(extruder_ams_count, ",");
wxGetApp().app_config->set("presets", "extruder_ams_count", extruder_ams_count_str);
}
static void GetAMSCount(int index, int & ams4, int & ams1)
{
auto count_str = wxGetApp().app_config->get("preset", "ams_count");
std::vector<std::string> counts;
boost::algorithm::split(counts, count_str, boost::algorithm::is_any_of("|"));
counts.resize(2);
std::vector<std::string> counts2;
boost::algorithm::split(counts2, counts[index], boost::algorithm::is_any_of("/"));
counts2.resize(2);
ams4 = std::atoi(counts2[0].c_str());
ams1 = std::atoi(counts2[1].c_str());
PresetBundle &preset_bundle = *wxGetApp().preset_bundle;
if (preset_bundle.extruder_ams_counts.empty()) {
ams4 = 0;
ams1 = 0;
}
else {
assert(preset_bundle.extruder_ams_counts.size() == 2);
ams4 = preset_bundle.extruder_ams_counts[index][4];
ams1 = preset_bundle.extruder_ams_counts[index][1];
}
}
static void UpdateAMSCount(int index, wxStaticText *text)
{
auto count_str = wxGetApp().app_config->get("preset", "ams_count");
std::vector<std::string> counts;
boost::algorithm::split(counts, count_str, boost::algorithm::is_any_of("|"));
counts.resize(2);
text->SetLabel(from_u8(counts[index]));
std::vector<std::map<int, int>> &ams_counts = wxGetApp().preset_bundle->extruder_ams_counts;
ams_counts.resize(2);
std::map<int, int>& ams_map = ams_counts[index];
if (ams_map.find(4) == ams_map.end()) {
ams_map[4] = 0;
}
if (ams_map.find(1) == ams_map.end()) {
ams_map[1] = 0;
}
std::string ams_info = std::to_string(ams_map[4]) + "/" + std::to_string(ams_map[1]);
text->SetLabel(from_u8(ams_info));
}
};