mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-30 22:32:07 +00:00
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:
@@ -1648,6 +1648,29 @@ bool CalibrationPresetPage::is_blocking_printing()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CalibrationPresetPage::is_nozzle_info_synced() const
|
||||
{
|
||||
if (!curr_obj || !curr_obj->is_info_ready())
|
||||
return false;
|
||||
|
||||
|
||||
for (const DevExtder& extruder : curr_obj->GetExtderSystem()->GetExtruders()) {
|
||||
const int extruder_id = extruder.GetExtId();
|
||||
|
||||
if (!curr_obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(extruder_id, get_nozzle_diameter(extruder_id)))
|
||||
return false;
|
||||
|
||||
if (curr_obj->is_nozzle_flow_type_supported()) {
|
||||
if (extruder.GetNozzleFlowType() == NozzleFlowType::NONE_FLOWTYPE)
|
||||
return false;
|
||||
if (int(extruder.GetNozzleFlowType()) - 1 != int(get_nozzle_volume_type(extruder_id)))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CalibrationPresetPage::update_sync_button_status()
|
||||
{
|
||||
auto set_status = [this](bool synced) {
|
||||
@@ -1664,53 +1687,7 @@ void CalibrationPresetPage::update_sync_button_status()
|
||||
}
|
||||
};
|
||||
|
||||
if (!curr_obj || !curr_obj->is_info_ready()) {
|
||||
set_status(false);
|
||||
return;
|
||||
}
|
||||
|
||||
struct CaliNozzleInfo
|
||||
{
|
||||
float nozzle_diameter{0.4f};
|
||||
int nozzle_volume_type{0};
|
||||
|
||||
bool operator==(const CaliNozzleInfo &other) const
|
||||
{
|
||||
return abs(nozzle_diameter - other.nozzle_diameter) < EPSILON
|
||||
&& nozzle_volume_type == other.nozzle_volume_type;
|
||||
}
|
||||
};
|
||||
|
||||
if (curr_obj->is_multi_extruders()) {
|
||||
std::vector<CaliNozzleInfo> machine_obj_nozzle_infos;
|
||||
machine_obj_nozzle_infos.resize(2);
|
||||
for (const DevExtder& extruder : curr_obj->GetExtderSystem()->GetExtruders()) {
|
||||
machine_obj_nozzle_infos[extruder.GetExtId()].nozzle_diameter = extruder.GetNozzleDiameter();
|
||||
machine_obj_nozzle_infos[extruder.GetExtId()].nozzle_volume_type = int(extruder.GetNozzleFlowType()) - 1;
|
||||
}
|
||||
|
||||
std::vector<CaliNozzleInfo> cali_nozzle_infos;
|
||||
cali_nozzle_infos.resize(2);
|
||||
for (size_t extruder_id = 0; extruder_id < 2; ++extruder_id) {
|
||||
cali_nozzle_infos[extruder_id].nozzle_diameter = get_nozzle_diameter(extruder_id);
|
||||
cali_nozzle_infos[extruder_id].nozzle_volume_type = int(get_nozzle_volume_type(extruder_id));
|
||||
}
|
||||
|
||||
if (machine_obj_nozzle_infos == cali_nozzle_infos) {
|
||||
set_status(true);
|
||||
}
|
||||
else {
|
||||
set_status(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (abs(curr_obj->GetExtderSystem()->GetNozzleDiameter(0) - get_nozzle_diameter(0)) < EPSILON) {
|
||||
set_status(true);
|
||||
}
|
||||
else {
|
||||
set_status(false);
|
||||
}
|
||||
}
|
||||
set_status(is_nozzle_info_synced());
|
||||
}
|
||||
|
||||
void CalibrationPresetPage::update_show_status()
|
||||
|
||||
@@ -265,6 +265,7 @@ protected:
|
||||
void update_combobox_filaments(MachineObject* obj);
|
||||
void update_show_status();
|
||||
void update_sync_button_status();
|
||||
bool is_nozzle_info_synced() const;
|
||||
void show_status(CaliPresetPageStatus status);
|
||||
void Enable_Send_Button(bool enable);
|
||||
bool is_blocking_printing();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <wx/string.h>
|
||||
|
||||
#include "DevDefs.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace Slic3r
|
||||
{
|
||||
@@ -145,6 +146,15 @@ public:
|
||||
float GetNozzleDiameter(int extder_id) const { return GetExtderById(extder_id) ? GetExtderById(extder_id)->GetNozzleDiameter() : 0.0; }
|
||||
int GetNozzleTempCurrent(int extder_id) const { return GetExtderById(extder_id) ? GetExtderById(extder_id)->GetCurrentTemp() : 0; }
|
||||
int GetNozzleTempTarget(int extder_id) const { return GetExtderById(extder_id) ? GetExtderById(extder_id)->GetTargetTemp() : 0; }
|
||||
bool NozzleDiameterMatchesOrUnknown(int extder_id, float target_diameter) const
|
||||
{
|
||||
float diameter = GetNozzleDiameter(extder_id);
|
||||
if (diameter == 0.0f) {
|
||||
return true;
|
||||
} else {
|
||||
return std::fabs(diameter - target_diameter) < 1e-3;
|
||||
}
|
||||
}
|
||||
|
||||
// get slot info which is connected to the extruder
|
||||
std::string GetCurrentAmsId() const;
|
||||
|
||||
@@ -14992,7 +14992,7 @@ Preset *get_printer_preset(const MachineObject *obj)
|
||||
return nullptr;
|
||||
|
||||
Preset *printer_preset = nullptr;
|
||||
float machine_nozzle_diameter = obj->GetExtderSystem()->GetNozzleDiameter(0);
|
||||
|
||||
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
||||
for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) {
|
||||
// only use system printer preset
|
||||
@@ -15005,7 +15005,8 @@ Preset *get_printer_preset(const MachineObject *obj)
|
||||
std::string model_id = printer_it->get_current_printer_type(preset_bundle);
|
||||
|
||||
std::string printer_type = obj->get_show_printer_type();
|
||||
if (model_id.compare(printer_type) == 0 && printer_nozzle_vals && abs(printer_nozzle_vals->get_at(0) - machine_nozzle_diameter) < 1e-3) {
|
||||
bool nozzle_diameter_matches_or_unknown = printer_nozzle_vals && obj->GetExtderSystem()->NozzleDiameterMatchesOrUnknown(0, printer_nozzle_vals->get_at(0));
|
||||
if (model_id.compare(printer_type) == 0 && nozzle_diameter_matches_or_unknown) {
|
||||
printer_preset = &(*printer_it);
|
||||
}
|
||||
}
|
||||
@@ -15021,12 +15022,12 @@ bool Plater::check_printer_initialized(MachineObject *obj, bool only_warning, bo
|
||||
|
||||
const auto& extruders = obj->GetExtderSystem()->GetExtruders();
|
||||
for (const DevExtder& extruder : extruders) {
|
||||
if (obj->is_multi_extruders()) {
|
||||
if (extruder.GetNozzleFlowType() == NozzleFlowType::NONE_FLOWTYPE) {
|
||||
has_been_initialized = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Skip check if nozzle type is unknown
|
||||
if (extruder.GetNozzleType() == NozzleType::ntUndefine) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (extruder.GetNozzleFlowType() == NozzleFlowType::NONE_FLOWTYPE) {
|
||||
has_been_initialized = false;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user