NEW:added check nozzle diameter and nozzle type

jira:[new]

Change-Id: Icc6951b861258f367d4f9c1784842965896555e4
This commit is contained in:
tao wang 2023-07-19 16:47:25 +08:00 committed by Lane.Wei
parent aecb5a3a67
commit ca02ea749e
6 changed files with 216 additions and 6 deletions

View File

@ -1864,6 +1864,20 @@ int MachineObject::command_set_chamber_light(LIGHT_EFFECT effect, int on_time, i
return this->publish_json(j.dump());
}
int MachineObject::command_set_printer_nozzle(std::string nozzle_type, float diameter)
{
BOOST_LOG_TRIVIAL(info) << "command_set_printer_nozzle, nozzle_type = " << nozzle_type << " diameter = " << diameter;
json j;
j["system"]["command"] = "set_accessories";
j["system"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["system"]["accessory_type"] = "nozzle";
j["system"]["nozzle_type"] = nozzle_type;
j["system"]["nozzle_diameter"] = diameter;
return this->publish_json(j.dump());
}
int MachineObject::command_set_work_light(LIGHT_EFFECT effect, int on_time, int off_time, int loops, int interval)
{
json j;
@ -3299,6 +3313,17 @@ int MachineObject::parse_json(std::string payload)
;
}
try {
if (jj.contains("nozzle_type")) {
if (jj["nozzle_type"].is_string()) {
nozzle_type = jj["nozzle_type"].get<std::string>();
}
}
}
catch (...) {
;
}
#pragma region upgrade
try {
if (jj.contains("upgrade_state")) {

View File

@ -394,6 +394,7 @@ public:
bool local_use_ssl_for_mqtt { true };
bool local_use_ssl_for_ftp { true };
float nozzle_diameter { 0.0f };
std::string nozzle_type;
std::string dev_connection_type; /* lan | cloud */
std::string connection_type() { return dev_connection_type; }
std::string dev_connection_name; /* lan | eth */
@ -770,6 +771,7 @@ public:
int command_request_push_all(bool request_now = false);
int command_pushing(std::string cmd);
int command_clean_print_error(std::string task_id, int print_error);
int command_set_printer_nozzle(std::string nozzle_type, float diameter);
/* command upgrade */
int command_upgrade_confirm();

View File

@ -32,6 +32,7 @@ wxDEFINE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent);
wxDEFINE_EVENT(EVT_CLOSE_IPADDRESS_DLG, wxCommandEvent);
wxDEFINE_EVENT(EVT_CHECK_IP_ADDRESS_FAILED, wxCommandEvent);
wxDEFINE_EVENT(EVT_SECONDARY_CHECK_RETRY, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent);
ReleaseNoteDialog::ReleaseNoteDialog(Plater *plater /*= nullptr*/)
: DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe), wxID_ANY, _L("Release Note"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
@ -899,9 +900,27 @@ ConfirmBeforeSendDialog::ConfirmBeforeSendDialog(wxWindow* parent, wxWindowID id
m_button_cancel->Hide();
else
m_button_cancel->Show();
m_button_update_nozzle = new Button(this, _L("Confirm and Update Nozzle"));
m_button_update_nozzle->SetBackgroundColor(btn_bg_white);
m_button_update_nozzle->SetBorderColor(wxColour(38, 46, 48));
m_button_update_nozzle->SetFont(Label::Body_12);
m_button_update_nozzle->SetSize(wxSize(-1, FromDIP(24)));
m_button_update_nozzle->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_update_nozzle->SetCornerRadius(FromDIP(12));
m_button_update_nozzle->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
wxCommandEvent evt(EVT_UPDATE_NOZZLE);
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
this->on_hide();
});
m_button_update_nozzle->Hide();
sizer_button->AddStretchSpacer();
sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5));
sizer_button->Add(m_button_update_nozzle, 0, wxALL, FromDIP(5));
sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
sizer_button->Add(FromDIP(5),0, 0, 0);
bottom_sizer->Add(sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, 0);
@ -1007,6 +1026,12 @@ void ConfirmBeforeSendDialog::on_dpi_changed(const wxRect& suggested_rect)
rescale();
}
void ConfirmBeforeSendDialog::show_update_nozzle_button()
{
m_button_update_nozzle->Show(true);
Layout();
}
void ConfirmBeforeSendDialog::rescale()
{
m_button_ok->Rescale();

View File

@ -42,8 +42,9 @@ namespace Slic3r { namespace GUI {
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_CONFIRM, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_CANCEL, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_DONE, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_RETRY, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_DONE, wxCommandEvent);
wxDECLARE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent);
class ReleaseNoteDialog : public DPIDialog
{
@ -175,16 +176,19 @@ public:
void on_show();
void on_hide();
void update_btn_label(wxString ok_btn_text, wxString cancel_btn_text);
wxString format_text(wxString str, int warp);
void rescale();
~ConfirmBeforeSendDialog();
void on_dpi_changed(const wxRect& suggested_rect);
void show_update_nozzle_button();
wxString format_text(wxString str, int warp);
~ConfirmBeforeSendDialog();
wxBoxSizer* m_sizer_main;
wxScrolledWindow* m_vebview_release_note{ nullptr };
Label* m_staticText_release_note{ nullptr };
Button* m_button_ok;
Button* m_button_cancel;
Button* m_button_update_nozzle;
wxCheckBox* m_show_again_checkbox;
bool not_show_again = false;
std::string show_again_config_text = "";

View File

@ -1421,13 +1421,13 @@ void SelectMachineDialog::init_bind()
on_send_print();
}
else if (e.GetInt() == -2 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusSendingCanceled);
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
MessageDialog msg_wingow(nullptr, _L("Printer local connection failed, please try again."), "", wxAPPLY | wxOK);
msg_wingow.ShowModal();
}
else if (e.GetInt() == 5 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusSendingCanceled);
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
@ -2208,6 +2208,100 @@ bool SelectMachineDialog::is_blocking_printing()
return false;
}
bool SelectMachineDialog::is_same_nozzle_diameters(std::string& nozzle_type, std::string& nozzle_diameter)
{
bool is_same_nozzle_diameters = true;
float preset_nozzle_diameters;
std::string preset_nozzle_type;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return true;
MachineObject* obj_ = dev->get_selected_machine();
if (obj_ == nullptr) return true;
try
{
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
auto opt_nozzle_diameters = preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter");
const ConfigOptionEnum<NozzleType>* nozzle_type = preset_bundle->printers.get_edited_preset().config.option<ConfigOptionEnum<NozzleType>>("nozzle_type");
if (nozzle_type->value == NozzleType::ntHardenedSteel) {
preset_nozzle_type = "hardened_steel";
}
else if (nozzle_type->value == NozzleType::ntStainlessSteel) {
preset_nozzle_type = "stainless_steel";
}
if (obj_->nozzle_type != preset_nozzle_type) {
is_same_nozzle_diameters = false;
}
auto extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_used_extruders();
if (opt_nozzle_diameters != nullptr) {
for (auto i = 0; i < extruders.size(); i++) {
auto extruder = extruders[i] - 1;
preset_nozzle_diameters = float(opt_nozzle_diameters->get_at(extruder));
if (preset_nozzle_diameters != obj_->nozzle_diameter) {
is_same_nozzle_diameters = false;
}
}
}
}
catch (...)
{
}
nozzle_type = preset_nozzle_type;
nozzle_diameter = wxString::Format("%.1f",preset_nozzle_diameters).ToStdString();
return is_same_nozzle_diameters;
}
bool SelectMachineDialog::is_same_nozzle_type(std::string& filament_type)
{
bool is_same_nozzle_type = true;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return true;
MachineObject* obj_ = dev->get_selected_machine();
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;
}
auto printer_nozzle_hrc = Print::get_hrc_by_nozzle_type(nozzle_type);
auto preset_bundle = wxGetApp().preset_bundle;
for (auto filament_name : preset_bundle->filament_presets) {
for (auto iter = preset_bundle->filaments.lbegin(); iter != preset_bundle->filaments.end(); iter++) {
if (filament_name.compare(iter->name) == 0) {
std::string display_filament_type;
filament_type = iter->config.get_filament_type(display_filament_type);
auto filament_nozzle_hrc = preset_bundle->get_required_hrc_by_filament_type(filament_type);
if (abs(filament_nozzle_hrc) > abs(printer_nozzle_hrc)) {
BOOST_LOG_TRIVIAL(info) << "filaments hardness mismatch: filament = " << filament_type << " printer_nozzle_hrc = " << printer_nozzle_hrc;
is_same_nozzle_type = false;
}
}
}
}
return is_same_nozzle_type;
}
bool SelectMachineDialog::is_same_printer_model()
{
bool result = true;
@ -2242,6 +2336,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
{
bool has_slice_warnings = false;
bool has_update_nozzle = false;
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
@ -2342,9 +2437,41 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
confirm_text.push_back(_L("There are some unknown filaments in the AMS mappings. Please check whether they are the required filaments. If they are okay, press \"Confirm\" to start printing.") + "\n");
}
std::string nozzle_type;
std::string nozzle_diameter;
std::string filament_type;
if (!obj_->nozzle_type.empty()) {
if (!is_same_nozzle_diameters(nozzle_type, nozzle_diameter)) {
has_slice_warnings = true;
has_update_nozzle = true;
wxString nozzle_in_preset = wxString::Format(_L("nozzle in preset: %s %s"),nozzle_diameter, format_steel_name(nozzle_type));
wxString nozzle_in_printer = wxString::Format(_L("nozzle memorized: %.1f %s"), obj_->nozzle_diameter, format_steel_name(obj_->nozzle_type));
confirm_text.push_back(_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");
}
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));
confirm_text.push_back(nozzle_in_preset + "\n");
}
}
if (has_slice_warnings) {
wxString confirm_title = _L("Warning");
ConfirmBeforeSendDialog confirm_dlg(this, wxID_ANY, confirm_title);
if(has_update_nozzle){confirm_dlg.show_update_nozzle_button();}
confirm_dlg.Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, &confirm_dlg](wxCommandEvent& e) {
confirm_dlg.on_hide();
if (m_print_type == PrintFromType::FROM_SDCARD_VIEW) {
@ -2353,7 +2480,18 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
else {
this->on_send_print();
}
});
confirm_dlg.Bind(EVT_UPDATE_NOZZLE, [this, obj_, nozzle_type, nozzle_diameter, &confirm_dlg](wxCommandEvent& e) {
if (obj_ && !nozzle_type.empty() && !nozzle_diameter.empty()) {
try
{
float diameter = std::stof(nozzle_diameter);
diameter = round(diameter * 10) / 10;
obj_->command_set_printer_nozzle(nozzle_type, diameter);
}
catch (...) {}
}
});
confirm_text.push_back(_L("Please click the confirm button if you still want to proceed with printing.") + "\n");
@ -2384,6 +2522,18 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event)
}
}
wxString SelectMachineDialog::format_steel_name(std::string name)
{
if (name == "hardened_steel") {
return _L("Hardened Steel");
}
else if (name == "stainless_steel") {
return _L("Stainless Steel");
}
return wxEmptyString;
}
void SelectMachineDialog::Enable_Auto_Refill(bool enable)
{
if (enable) {
@ -2686,7 +2836,7 @@ void SelectMachineDialog::on_set_finish_mapping(wxCommandEvent &evt)
void SelectMachineDialog::on_print_job_cancel(wxCommandEvent &evt)
{
BOOST_LOG_TRIVIAL(info) << "print_job: canceled";
show_status(PrintDialogStatus::PrintStatusSendingCanceled);
show_status(PrintDialogStatus::PrintStatusInit);
// enter prepare mode
prepare_mode();
}
@ -3211,6 +3361,7 @@ void SelectMachineDialog::update_show_status()
}
}
// do ams mapping if no ams result
if (m_ams_mapping_result.empty()) {
do_ams_mapping(obj_);

View File

@ -445,6 +445,8 @@ public:
bool is_show_timelapse();
bool is_same_printer_model();
bool is_blocking_printing();
bool is_same_nozzle_diameters(std::string& nozzle_type, std::string& nozzle_diameter);
bool is_same_nozzle_type(std::string& filament_type);
bool has_tips(MachineObject* obj);
bool is_timeout();
int update_print_required_data(Slic3r::DynamicPrintConfig config, Slic3r::Model model, Slic3r::PlateDataPtrs plate_data_list, std::string file_name, std::string file_path);
@ -454,6 +456,7 @@ public:
bool get_ams_mapping_result(std::string& mapping_array_str, std::string& ams_mapping_info);
PrintFromType get_print_type() {return m_print_type;};
wxString format_steel_name(std::string name);
wxString format_text(wxString &m_msg);
wxWindow* create_ams_checkbox(wxString title, wxWindow* parent, wxString tooltip);
wxWindow* create_item_checkbox(wxString title, wxWindow* parent, wxString tooltip, std::string param);