ENH: Check the nozzle diameter when sending calibration

Jira: 4977
Change-Id: Iabbba44583bbd9fbaaa889ca546ee0ccbb2aa77f
This commit is contained in:
zhimin.zeng 2023-11-06 17:50:40 +08:00 committed by Lane.Wei
parent 28b71cecbb
commit 84800a674f
2 changed files with 102 additions and 2 deletions

View File

@ -2518,10 +2518,9 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
else if (!is_same_nozzle_type(filament_type)){
has_slice_warnings = true;
has_update_nozzle = true;
nozzle_type = "hardened_steel";
nozzle_diameter = wxString::Format("%.1f", obj_->nozzle_diameter).ToStdString();
wxString nozzle_in_preset = wxString::Format(_L("*Printing %s material with %s may cause nozzle damage"), filament_type, format_steel_name(nozzle_type));
wxString nozzle_in_preset = wxString::Format(_L("*Printing %s material with %s may cause nozzle damage"), filament_type, format_steel_name(obj_->nozzle_type));
confirm_text.push_back(nozzle_in_preset + "\n");
}
}

View File

@ -54,6 +54,104 @@ std::string get_calib_mode_name(CalibMode cali_mode, int stage)
}
}
static wxString to_wstring_name(std::string name)
{
if (name == "hardened_steel") {
return _L("Hardened Steel");
} else if (name == "stainless_steel") {
return _L("Stainless Steel");
}
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 ConfigOptionEnum<NozzleType> * config_nozzle_type = full_config.option<ConfigOptionEnum<NozzleType>>("nozzle_type");
if (config_nozzle_type->value == NozzleType::ntHardenedSteel) {
nozzle_type = "hardened_steel";
} else if (config_nozzle_type->value == NozzleType::ntStainlessSteel) {
nozzle_type = "stainless_steel";
}
auto opt_nozzle_diameters = full_config.option<ConfigOptionFloats>("nozzle_diameter");
if (opt_nozzle_diameters != nullptr) {
float preset_nozzle_diameter = opt_nozzle_diameters->get_at(0);
if (preset_nozzle_diameter != obj->nozzle_diameter) {
wxString nozzle_in_preset = wxString::Format(_L("nozzle in preset: %s %s"), wxString::Format("%.1f", preset_nozzle_diameter).ToStdString(), to_wstring_name(nozzle_type));
wxString nozzle_in_printer = wxString::Format(_L("nozzle memorized: %.1f %s"), obj->nozzle_diameter, to_wstring_name(obj->nozzle_type));
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)
return true;
NozzleType nozzle_type = NozzleType::ntUndefine;
if (obj->nozzle_type == "stainless_steel") {
nozzle_type = NozzleType::ntStainlessSteel;
} else if (obj->nozzle_type == "hardened_steel") {
nozzle_type = NozzleType::ntHardenedSteel;
}
int printer_nozzle_hrc = Print::get_hrc_by_nozzle_type(nozzle_type);
if (full_config.has("required_nozzle_HRC")) {
int filament_nozzle_hrc = full_config.opt_int("required_nozzle_HRC", 0);
if (abs(filament_nozzle_hrc) > abs(printer_nozzle_hrc)) {
BOOST_LOG_TRIVIAL(info) << "filaments hardness mismatch: printer_nozzle_hrc = " << printer_nozzle_hrc << ", filament_nozzle_hrc = " << filament_nozzle_hrc;
std::string filament_type = full_config.opt_string("filament_type", 0);
error_msg = wxString::Format(_L("*Printing %s material with %s may cause nozzle damage"), filament_type, to_wstring_name(obj->nozzle_type));
error_msg += "\n";
return false;
}
}
return true;
}
static bool check_nozzle_diameter_and_type(const DynamicPrintConfig &full_config, wxString& error_msg)
{
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) {
error_msg = _L("Need select printer");
return false;
}
MachineObject *obj = dev->get_selected_machine();
if (obj == nullptr) {
error_msg = _L("Need select printer");
return false;
}
// P1P/S
if (obj->nozzle_type.empty())
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;
return true;
}
CalibMode CalibUtils::get_calib_mode_by_name(const std::string name, int& cali_stage)
{
if (name == "pa_line_calib_mode") {
@ -899,6 +997,9 @@ void CalibUtils::process_and_store_3mf(Model *model, const DynamicPrintConfig &f
// return;
//}
if (!check_nozzle_diameter_and_type(full_config, error_message))
return;
fff_print->process();
part_plate->update_slice_result_valid_state(true);