Sync the AMS recommended temperature range with the tray's nozzle variant

This commit is contained in:
SoftFever
2026-10-01 02:54:18 +08:00
parent e1da47a72b
commit 35a4d941b8
7 changed files with 82 additions and 25 deletions
+14 -3
View File
@@ -4452,8 +4452,17 @@ std::vector<Preset *> PresetBundle::get_filament_presets_for_machine(const std::
return compatible; return compatible;
} }
int PresetBundle::get_filament_variant_index(const DynamicPrintConfig &filament_config, const DynamicPrintConfig &printer_config,
int extruder_id, NozzleVolumeType nozzle_volume_type)
{
const auto *extruder_types = printer_config.option<ConfigOptionEnumsGeneric>("extruder_type");
const ExtruderType extruder_type = extruder_types && !extruder_types->empty() ? ExtruderType(extruder_types->get_at(extruder_id)) : etDirectDrive;
return std::max(0, filament_config.get_index_for_extruder(1, "", extruder_type, nozzle_volume_type, "filament_extruder_variant"));
}
bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray( bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(
const std::string &printer_type, std::string& nozzle_diameter_str, std::string &setting_id, std::string &tag_uid, std::string &nozzle_temp_min, std::string &nozzle_temp_max, std::string& preset_setting_id) const std::string &printer_type, std::string& nozzle_diameter_str, std::string &setting_id, std::string &tag_uid, std::string &nozzle_temp_min, std::string &nozzle_temp_max, std::string& preset_setting_id,
int extruder_id, NozzleVolumeType nozzle_volume_type)
{ {
bool is_equation = true; bool is_equation = true;
@@ -4476,13 +4485,15 @@ bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_m
// Compare only once // Compare only once
if (!compared) { if (!compared) {
compared = true; compared = true;
const Preset *printer = printers.find_preset(printer_str);
const int variant_index = printer ? get_filament_variant_index(preset->config, printer->config, extruder_id, nozzle_volume_type) : 0;
bool min_temp_equation = false, max_temp_equation = false; bool min_temp_equation = false, max_temp_equation = false;
int min_nozzle_temp = std::stoi(nozzle_temp_min); int min_nozzle_temp = std::stoi(nozzle_temp_min);
int max_nozzle_temp = std::stoi(nozzle_temp_max); int max_nozzle_temp = std::stoi(nozzle_temp_max);
ConfigOption *opt_min = const_cast<Preset *>(preset)->config.option("nozzle_temperature_range_low"); ConfigOption *opt_min = const_cast<Preset *>(preset)->config.option("nozzle_temperature_range_low");
if (opt_min) { if (opt_min) {
ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min); ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min);
min_nozzle_temp = opt_min_ints->get_at(0); min_nozzle_temp = opt_min_ints->get_at(variant_index);
if (std::to_string(min_nozzle_temp) == nozzle_temp_min) if (std::to_string(min_nozzle_temp) == nozzle_temp_min)
min_temp_equation = true; min_temp_equation = true;
else { else {
@@ -4493,7 +4504,7 @@ bool PresetBundle::check_filament_temp_equation_by_printer_type_and_nozzle_for_m
ConfigOption *opt_max = const_cast<Preset *>(preset)->config.option("nozzle_temperature_range_high"); ConfigOption *opt_max = const_cast<Preset *>(preset)->config.option("nozzle_temperature_range_high");
if (opt_max) { if (opt_max) {
ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max); ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max);
max_nozzle_temp = opt_max_ints->get_at(0); max_nozzle_temp = opt_max_ints->get_at(variant_index);
if (std::to_string(max_nozzle_temp) == nozzle_temp_max) if (std::to_string(max_nozzle_temp) == nozzle_temp_max)
max_temp_equation = true; max_temp_equation = true;
else { else {
+10 -1
View File
@@ -407,13 +407,22 @@ public:
std::vector<Preset *> get_filament_presets_for_machine(const std::string &printer_type, std::vector<Preset *> get_filament_presets_for_machine(const std::string &printer_type,
const std::string &nozzle_diameter_str, const std::string &nozzle_diameter_str,
bool include_user_presets); bool include_user_presets);
// Orca: the variant index of a filament preset's per-variant options on extruder extruder_id of a printer
// preset, with the nozzle volume type the machine reports; 0 when the filament has no such variant.
static int get_filament_variant_index(const DynamicPrintConfig &filament_config,
const DynamicPrintConfig &printer_config,
int extruder_id,
NozzleVolumeType nozzle_volume_type);
// extruder_id and nozzle_volume_type identify the tray's nozzle, whose variant the temperature range is compared for.
bool check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(const std::string &printer_type, bool check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(const std::string &printer_type,
std::string & nozzle_diameter_str, std::string & nozzle_diameter_str,
std::string & setting_id, std::string & setting_id,
std::string & tag_uid, std::string & tag_uid,
std::string & nozzle_temp_min, std::string & nozzle_temp_min,
std::string & nozzle_temp_max, std::string & nozzle_temp_max,
std::string & preset_setting_id); std::string & preset_setting_id,
int extruder_id,
NozzleVolumeType nozzle_volume_type);
Preset * get_similar_printer_preset(std::string printer_model, std::string printer_variant); Preset * get_similar_printer_preset(std::string printer_model, std::string printer_variant);
PresetCollection prints; PresetCollection prints;
+21 -4
View File
@@ -1000,11 +1000,12 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
// update if nozzle_temperature_range is found // update if nozzle_temperature_range is found
const int variant_index = get_filament_variant_index(*filament_it, nozzle_diameter_str);
ConfigOption *opt_min = filament_it->config.option("nozzle_temperature_range_low"); ConfigOption *opt_min = filament_it->config.option("nozzle_temperature_range_low");
if (opt_min) { if (opt_min) {
ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min); ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min);
if (opt_min_ints) { if (opt_min_ints) {
wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(0)); wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(variant_index));
m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min); m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min);
} }
} }
@@ -1012,7 +1013,7 @@ void AMSMaterialsSetting::Popup(wxString filament, wxString sn, wxString temp_mi
if (opt_max) { if (opt_max) {
ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max); ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max);
if (opt_max_ints) { if (opt_max_ints) {
wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(0)); wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(variant_index));
m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max); m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max);
} }
} }
@@ -1218,6 +1219,21 @@ void AMSMaterialsSetting::on_select_cali_result(wxCommandEvent &evt)
} }
} }
int AMSMaterialsSetting::get_filament_variant_index(const Preset &filament, const std::string &nozzle_diameter_str)
{
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
if (!obj || !preset_bundle)
return 0;
const std::set<std::string> printer_names =
preset_bundle->get_printer_names_by_printer_type_and_nozzle(DevPrinterConfigUtil::get_printer_display_name(obj->printer_type), nozzle_diameter_str);
const Preset *printer = printer_names.empty() ? nullptr : preset_bundle->printers.find_preset(*printer_names.begin());
if (!printer)
return 0;
const int extruder_id = obj->get_extruder_id_by_ams_id(std::to_string(ams_id));
return PresetBundle::get_filament_variant_index(filament.config, printer->config, obj->get_preset_extruder_index(extruder_id),
DevNozzle::ToNozzleVolumeType(obj->GetExtderSystem()->GetNozzleFlowType(extruder_id)));
}
void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt) void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)
{ {
// Get the flag whether to open the filament setting dialog from the device page // Get the flag whether to open the filament setting dialog from the device page
@@ -1249,11 +1265,12 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)
if (it->filament_id != filament_id) if (it->filament_id != filament_id)
continue; continue;
// ) if nozzle_temperature_range is found // ) if nozzle_temperature_range is found
const int variant_index = get_filament_variant_index(*it, nozzle_diameter_str);
ConfigOption* opt_min = it->config.option("nozzle_temperature_range_low"); ConfigOption* opt_min = it->config.option("nozzle_temperature_range_low");
if (opt_min) { if (opt_min) {
ConfigOptionInts* opt_min_ints = dynamic_cast<ConfigOptionInts*>(opt_min); ConfigOptionInts* opt_min_ints = dynamic_cast<ConfigOptionInts*>(opt_min);
if (opt_min_ints) { if (opt_min_ints) {
wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(0)); wxString text_nozzle_temp_min = wxString::Format("%d", opt_min_ints->get_at(variant_index));
m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min); m_input_nozzle_min->GetTextCtrl()->SetValue(text_nozzle_temp_min);
} }
} }
@@ -1261,7 +1278,7 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt)
if (opt_max) { if (opt_max) {
ConfigOptionInts* opt_max_ints = dynamic_cast<ConfigOptionInts*>(opt_max); ConfigOptionInts* opt_max_ints = dynamic_cast<ConfigOptionInts*>(opt_max);
if (opt_max_ints) { if (opt_max_ints) {
wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(0)); wxString text_nozzle_temp_max = wxString::Format("%d", opt_max_ints->get_at(variant_index));
m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max); m_input_nozzle_max->GetTextCtrl()->SetValue(text_nozzle_temp_max);
} }
} }
+2
View File
@@ -150,6 +150,8 @@ protected:
void update_widgets(); void update_widgets();
void update_filament_editing(bool is_printing); void update_filament_editing(bool is_printing);
// Orca: the variant index of the filament's per-variant options on the nozzle this tray feeds
int get_filament_variant_index(const Preset &filament, const std::string &nozzle_diameter_str);
protected: protected:
StateColor m_btn_bg_green; StateColor m_btn_bg_green;
+15 -16
View File
@@ -5696,7 +5696,7 @@ void MachineObject::update_filament_list()
PresetBundle *preset_bundle = Slic3r::GUI::wxGetApp().preset_bundle; PresetBundle *preset_bundle = Slic3r::GUI::wxGetApp().preset_bundle;
// custom filament // custom filament
typedef std::map<std::string, std::pair<int, int>> map_pair; typedef std::map<std::string, std::pair<std::vector<int>, std::vector<int>>> map_pair;
std::map<std::string, map_pair> map_list; std::map<std::string, map_pair> map_list;
for (auto &pair : m_nozzle_filament_data) { for (auto &pair : m_nozzle_filament_data) {
map_list[pair.second.printer_preset_name] = map_pair{}; map_list[pair.second.printer_preset_name] = map_pair{};
@@ -5708,19 +5708,13 @@ void MachineObject::update_filament_list()
for (const std::string &printer_str : printer_strs->values) { for (const std::string &printer_str : printer_strs->values) {
if (map_list.find(printer_str) != map_list.end()) { if (map_list.find(printer_str) != map_list.end()) {
auto & filament_list = map_list[printer_str]; auto & filament_list = map_list[printer_str];
ConfigOption *opt_min = const_cast<Preset &>(preset).config.option("nozzle_temperature_range_low"); // Every variant's range, so a change to any of them rechecks the trays
int min_temp = -1; std::vector<int> min_temps{-1}, max_temps{-1};
if (opt_min) { if (auto *opt_min = preset.config.option<ConfigOptionInts>("nozzle_temperature_range_low"))
ConfigOptionInts *opt_min_ints = dynamic_cast<ConfigOptionInts *>(opt_min); min_temps = opt_min->values;
min_temp = opt_min_ints->get_at(0); if (auto *opt_max = preset.config.option<ConfigOptionInts>("nozzle_temperature_range_high"))
} max_temps = opt_max->values;
ConfigOption *opt_max = const_cast<Preset &>(preset).config.option("nozzle_temperature_range_high"); filament_list[preset.filament_id] = std::make_pair(min_temps, max_temps);
int max_temp = -1;
if (opt_max) {
ConfigOptionInts *opt_max_ints = dynamic_cast<ConfigOptionInts *>(opt_max);
max_temp = opt_max_ints->get_at(0);
}
filament_list[preset.filament_id] = std::make_pair(min_temp, max_temp);
break; break;
} }
} }
@@ -5856,10 +5850,13 @@ void MachineObject::check_ams_filament_valid()
need_checked_filament_id[nozzle_diameter_str].insert(curr_tray->setting_id); need_checked_filament_id[nozzle_diameter_str].insert(curr_tray->setting_id);
try { try {
std::string preset_setting_id; std::string preset_setting_id;
const int extruder_id = ams->GetExtruderId();
bool is_equation = preset_bundle->check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(printer_model, nozzle_diameter_str, bool is_equation = preset_bundle->check_filament_temp_equation_by_printer_type_and_nozzle_for_mas_tray(printer_model, nozzle_diameter_str,
curr_tray->setting_id, curr_tray->tag_uid, curr_tray->setting_id, curr_tray->tag_uid,
curr_tray->nozzle_temp_min, curr_tray->nozzle_temp_min,
curr_tray->nozzle_temp_max, preset_setting_id); curr_tray->nozzle_temp_max, preset_setting_id,
get_preset_extruder_index(extruder_id),
DevNozzle::ToNozzleVolumeType(m_extder_system->GetNozzleFlowType(extruder_id)));
if (!is_equation) { if (!is_equation) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << " ams filament is not match min max temp and reset, ams_id: " << ams_id << " tray_id" BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << " ams filament is not match min max temp and reset, ams_id: " << ams_id << " tray_id"
<< slot_id << "filament_id: " << curr_tray->setting_id; << slot_id << "filament_id: " << curr_tray->setting_id;
@@ -5924,7 +5921,9 @@ void MachineObject::check_ams_filament_valid()
this->printer_type), this->printer_type),
nozzle_diameter_str, vt_tray.setting_id, nozzle_diameter_str, vt_tray.setting_id,
vt_tray.tag_uid, vt_tray.nozzle_temp_min, vt_tray.tag_uid, vt_tray.nozzle_temp_min,
vt_tray.nozzle_temp_max, preset_setting_id); vt_tray.nozzle_temp_max, preset_setting_id,
get_preset_extruder_index(index),
DevNozzle::ToNozzleVolumeType(m_extder_system->GetNozzleFlowType(index)));
if (!is_equation) { if (!is_equation) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__
<< " vt_tray filament is not match min max temp and reset, filament_id: " << vt_tray.setting_id; << " vt_tray filament is not match min max temp and reset, filament_id: " << vt_tray.setting_id;
+4 -1
View File
@@ -341,6 +341,8 @@ public:
bool is_main_extruder_on_left() const { return false; } // only means the extruder is on the left hand when extruder id is 0 bool is_main_extruder_on_left() const { return false; } // only means the extruder is on the left hand when extruder id is 0
bool is_multi_extruders() const; bool is_multi_extruders() const;
int get_extruder_id_by_ams_id(const std::string& ams_id); int get_extruder_id_by_ams_id(const std::string& ams_id);
// Orca: the printer preset's extruder index of device extruder extder_id
int get_preset_extruder_index(int extder_id) const { return is_multi_extruders() ? (is_main_extruder_on_left() ? extder_id : 1 - extder_id) : 0; }
/* E3D has extra nozzle flow type info */ /* E3D has extra nozzle flow type info */
bool has_extra_flow_type{false}; bool has_extra_flow_type{false};
@@ -957,7 +959,8 @@ public:
{ {
std::set<std::string> checked_filament; std::set<std::string> checked_filament;
std::string printer_preset_name; std::string printer_preset_name;
std::map<std::string, std::pair<int, int>> filament_list; // filament_id, pair<min temp, max temp> // filament_id, pair<min temps, max temps>, one per filament variant
std::map<std::string, std::pair<std::vector<int>, std::vector<int>>> filament_list;
}; };
std::map<std::string, FilamentData> m_nozzle_filament_data; std::map<std::string, FilamentData> m_nozzle_filament_data;
void update_filament_list(); void update_filament_list();
@@ -5940,3 +5940,19 @@ TEST_CASE("A project's different settings always keep the preset bookkeeping key
CHECK(keys.count(key) == 1); CHECK(keys.count(key) == 1);
CHECK(PresetBundle::project_different_keys(std::string()).count("inherits") == 1); CHECK(PresetBundle::project_different_keys(std::string()).count("inherits") == 1);
} }
// A connected machine's tray is checked against the filament variant of the nozzle it feeds.
TEST_CASE("A filament's variant index follows the extruder type and nozzle volume type", "[Preset]")
{
DynamicPrintConfig filament;
filament.option<ConfigOptionStrings>("filament_extruder_variant", true)->values = {"Direct Drive Standard", "Direct Drive High Flow",
"Bowden Standard"};
DynamicPrintConfig printer;
printer.option<ConfigOptionEnumsGeneric>("extruder_type", true)->values = {etDirectDrive, etBowden};
CHECK(PresetBundle::get_filament_variant_index(filament, printer, 0, nvtStandard) == 0);
CHECK(PresetBundle::get_filament_variant_index(filament, printer, 0, nvtHighFlow) == 1);
CHECK(PresetBundle::get_filament_variant_index(filament, printer, 1, nvtStandard) == 2);
// the filament defines no Bowden High Flow variant
CHECK(PresetBundle::get_filament_variant_index(filament, printer, 1, nvtHighFlow) == 0);
}