Skip to content

Commit

Permalink
ENH: Check the nozzle diameter when sending calibration
Browse files Browse the repository at this point in the history
Jira: 4977
Change-Id: Iabbba44583bbd9fbaaa889ca546ee0ccbb2aa77f
  • Loading branch information
zhimin-zeng-bambulab authored and lanewei120 committed Nov 9, 2023
1 parent 28b71ce commit 84800a6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/slic3r/GUI/SelectMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
101 changes: 101 additions & 0 deletions src/slic3r/Utils/CalibUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 84800a6

Please sign in to comment.