Fix filament syncing by fixing nozzle diameter guards (#13330)

* Remove unused `get_printer_preset` calls.

* `Plater::check_printer_initialized` should skip nozzle flow type checks if nozzle is unknown.

Also remove unnecessary `is_multi_extruders` check.

* Remove unused `CalibUtils::is_same_nozzle_diameters()` fn.

* Simplify `CalibUtils::check_printable_status_before_cali`.

The single-arity can delegate to the vectorized arity.

* Add `DevExtruderSystem::NozzleDiameterMatchesOrUnknown` to simply checks.

* Update `CalibrationPresetPage::update_sync_button_status()` to use `NozzleDiameterMatchesOrUnknown`.

Simplify logic by iterating over each extruder and checking for diameter and volume type match.

The previous code had several mistakes (from what I could tell):

- `curr_obj->is_multi_extruders()` doesn't imply exactly 2 extruders
- the single/multi branch served no purpose
- the single branch failed to check the volume type

* Specify `std::fabs` and add explicit import.

Ref: https://github.com/OrcaSlicer/OrcaSlicer/pull/13330#discussion_r3133613736

Not sure how idiomatic this is in C++ / OrcaSlicer codebase, but CoPilot suggested it and it seems reasonable.

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
Kevin J. Lynagh
2026-05-16 13:13:40 +02:00
committed by GitHub
parent 427d0f7a9f
commit 8dd1dd8921
5 changed files with 50 additions and 157 deletions

View File

@@ -169,52 +169,6 @@ static wxString to_wstring_name(std::string name)
return wxEmptyString;
}
static bool is_same_nozzle_diameters(const DynamicPrintConfig &full_config, const MachineObject *obj, wxString& error_msg)
{
if (obj == nullptr)
return true;
try {
std::string nozzle_type;
const ConfigOptionEnumsGenericNullable * config_nozzle_type = full_config.option<ConfigOptionEnumsGenericNullable>("nozzle_type");
std::vector<std::string> config_nozzle_types_str(config_nozzle_type->size());
for (size_t idx = 0; idx < config_nozzle_type->size(); ++idx)
config_nozzle_types_str[idx] = NozzleTypeEumnToStr[NozzleType(config_nozzle_type->values[idx])];
auto opt_nozzle_diameters = full_config.option<ConfigOptionFloats>("nozzle_diameter");
std::vector<float> config_nozzle_diameters(opt_nozzle_diameters->size());
for (size_t idx = 0; idx < opt_nozzle_diameters->size(); ++idx)
config_nozzle_diameters[idx] = opt_nozzle_diameters->values[idx];
std::vector<float> machine_nozzle_diameters(obj->GetExtderSystem()->GetTotalExtderCount());
for (size_t idx = 0; idx < obj->GetExtderSystem()->GetTotalExtderCount(); ++idx)
machine_nozzle_diameters[idx] = obj->GetExtderSystem()->GetNozzleDiameter(idx);
if (config_nozzle_diameters.size() != machine_nozzle_diameters.size()) {
wxString nozzle_in_preset = wxString::Format(_L("nozzle size in preset: %d"), config_nozzle_diameters.size());
wxString nozzle_in_printer = wxString::Format(_L("nozzle size memorized: %d"), machine_nozzle_diameters.size());
error_msg = _L("The size of nozzle type in preset is not consistent with memorized nozzle. Did you change your nozzle lately?") + "\n " + nozzle_in_preset +
"\n " + nozzle_in_printer + "\n";
return false;
}
for (size_t idx = 0; idx < config_nozzle_diameters.size(); ++idx) {
if (config_nozzle_diameters[idx] != machine_nozzle_diameters[idx]) {
wxString nozzle_in_preset = wxString::Format(_L("nozzle[%d] in preset: %.1f"), idx, config_nozzle_diameters[idx]);
wxString nozzle_in_printer = wxString::Format(_L("nozzle[%d] memorized: %.1f"), idx, machine_nozzle_diameters[idx]);
error_msg = _L("Your nozzle type in preset is not consistent with memorized nozzle. Did you change your nozzle lately?") + "\n " + nozzle_in_preset +
"\n " + nozzle_in_printer + "\n";
return false;
}
}
} catch (...) {}
return true;
}
static bool is_same_nozzle_type(const DynamicPrintConfig &full_config, const MachineObject *obj, wxString& error_msg)
{
if (obj == nullptr)
@@ -267,9 +221,6 @@ static bool check_nozzle_diameter_and_type(const DynamicPrintConfig &full_config
if (obj->GetExtderSystem()->GetNozzleType(0) == NozzleType::ntUndefine)
return true;
// if (!is_same_nozzle_diameters(full_config, obj, error_msg))
// return false;
if (!is_same_nozzle_type(full_config, obj, error_msg))
return false;
@@ -1374,7 +1325,6 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
}
bool is_multi_extruder = obj->is_multi_extruders();
Preset *printer_preset = get_printer_preset(obj);
for (const auto &cali_info : cali_infos.calib_datas) {
wxString name = "";
@@ -1393,9 +1343,9 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
return false;
}
float diameter = obj->GetExtderSystem()->GetNozzleDiameter(extruder_id);
NozzleFlowType nozzle_volume_type = obj->GetExtderSystem()->GetNozzleFlowType(extruder_id);
if (!is_approx(cali_info.nozzle_diameter, diameter)) {
if (!obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(extruder_id, cali_info.nozzle_diameter)) {
if (is_multi_extruder)
error_message = wxString::Format(_L("The currently selected nozzle diameter of %s extruder does not match the actual nozzle diameter.\n"
"Please click the Sync button above and restart the calibration."), name);
@@ -1436,7 +1386,6 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
return true;
bool is_multi_extruder = obj->is_multi_extruders();
Preset *printer_preset = get_printer_preset(obj);
for (const auto &cali_info : cali_infos) {
wxString name = "";
@@ -1460,10 +1409,7 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
return false;
}
float diameter = obj->GetExtderSystem()->GetNozzleDiameter(extruder_id);
NozzleFlowType nozzle_volume_type = obj->GetExtderSystem()->GetNozzleFlowType(cali_info.extruder_id);
if (!is_approx(cali_info.nozzle_diameter, diameter)) {
if (!obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(extruder_id, cali_info.nozzle_diameter)) {
if (is_multi_extruder)
error_message = wxString::Format(_L("The currently selected nozzle diameter of %s extruder does not match the actual nozzle diameter.\n"
"Please click the Sync button above and restart the calibration."), name);
@@ -1473,6 +1419,9 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
return false;
}
NozzleFlowType nozzle_volume_type = obj->GetExtderSystem()->GetNozzleFlowType(extruder_id);
if (nozzle_volume_type == NozzleFlowType::NONE_FLOWTYPE) {
if (is_multi_extruder)
error_message = wxString::Format(_L("Printer %s nozzle information has not been set. Please configure it before proceeding with the calibration."), name);
@@ -1496,52 +1445,7 @@ bool CalibUtils::check_printable_status_before_cali(const MachineObject *obj, co
bool CalibUtils::check_printable_status_before_cali(const MachineObject* obj, const CalibInfo& cali_info, wxString& error_message)
{
if (!obj) {
error_message = _L("Need select printer");
return false;
}
const ConfigOptionFloats *nozzle_diameter_config = cali_info.printer_prest->config.option<ConfigOptionFloats>("nozzle_diameter");
float nozzle_diameter = nozzle_diameter_config->values[0];
bool is_multi_extruder = obj->is_multi_extruders();
wxString name = _L("left");
if (cali_info.extruder_id == 0) {
name = _L("right");
}
float diameter = obj->GetExtderSystem()->GetNozzleDiameter(cali_info.extruder_id);
NozzleFlowType nozzle_volume_type = obj->GetExtderSystem()->GetNozzleFlowType(cali_info.extruder_id);
if (!is_approx(nozzle_diameter, diameter)) {
if (is_multi_extruder)
error_message = wxString::Format(_L("The currently selected nozzle diameter of %s extruder does not match the actual nozzle diameter.\n"
"Please click the Sync button above and restart the calibration."), name);
else
error_message = _L("The nozzle diameter does not match the actual printer nozzle diameter.\n"
"Please click the Sync button above and restart the calibration.");
return false;
}
if (nozzle_volume_type == NozzleFlowType::NONE_FLOWTYPE) {
if (is_multi_extruder)
error_message = wxString::Format(_L("Printer %s nozzle information has not been set. Please configure it before proceeding with the calibration."), name);
else
error_message = nozzle_not_set_text;
return false;
}
if (NozzleVolumeType(nozzle_volume_type - 1) != cali_info.nozzle_volume_type) {
if (is_multi_extruder)
error_message = wxString::Format(_L("The currently selected nozzle type of %s extruder does not match the actual printer nozzle type.\n"
"Please click the Sync button above and restart the calibration."), name);
else
error_message = nozzle_volume_type_not_match_text;
return false;
}
return true;
return check_printable_status_before_cali(obj, std::vector<CalibInfo>{cali_info}, error_message);
}
bool CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &full_config, const Calib_Params &params, wxString &error_message)