From ee62ffcc7da8f569c06e1938922a3971ddf53f11 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Mon, 17 Oct 2022 14:58:22 +0800 Subject: [PATCH] NEW: add confirm dialog after check conditions confirm to check printer model and slice warnings Change-Id: I07a272fda1a5e2ebc0f4e106815fe07da5aaa4df Signed-off-by: Stone Li --- src/libslic3r/GCode/GCodeProcessor.hpp | 11 +++++ src/libslic3r/Preset.cpp | 18 +++++++ src/libslic3r/Preset.hpp | 3 +- src/slic3r/GUI/ConfirmHintDialog.cpp | 14 +++++- src/slic3r/GUI/ConfirmHintDialog.hpp | 2 + src/slic3r/GUI/PartPlate.hpp | 1 + src/slic3r/GUI/Plater.cpp | 10 ++++ src/slic3r/GUI/Plater.hpp | 1 + src/slic3r/GUI/SelectMachine.cpp | 65 +++++++++++++++++++++++++- src/slic3r/GUI/SelectMachine.hpp | 5 +- 10 files changed, 124 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 686c86160..108eef79b 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -16,6 +16,9 @@ namespace Slic3r { +// slice warnings enum strings +#define BED_TEMP_TOO_HIGH_THAN_FILAMENT "bed_temperature_too_high_than_filament" + enum class EMoveType : unsigned char { Noop, @@ -128,6 +131,14 @@ namespace Slic3r { } }; + struct SliceWarnings { + int level; // 0: normal tips, 1: warning; 2: error + std::string msg; // enum string + std::vector params; // extra msg info + }; + + std::vector warnings; + std::string filename; unsigned int id; std::vector moves; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 210680943..862f35ad2 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -644,6 +644,24 @@ std::string Preset::get_filament_type(std::string &display_filament_type) return config.get_filament_type(display_filament_type); } +std::string Preset::get_printer_type(PresetBundle *preset_bundle) +{ + if (preset_bundle) { + auto config = &preset_bundle->printers.get_edited_preset().config; + std::string vendor_name; + for (auto vendor_profile : preset_bundle->vendors) { + for (auto vendor_model : vendor_profile.second.models) + if (vendor_model.name == config->opt_string("printer_model")) + { + vendor_name = vendor_profile.first; + return vendor_model.model_id; + } + } + } + return ""; +} + + bool Preset::is_bbl_vendor_preset(PresetBundle *preset_bundle) { bool is_bbl_vendor_preset = true; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index 843a49417..7578bb239 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -296,8 +296,9 @@ public: // special for upport G and Support W std::string get_filament_type(std::string &display_filament_type); + std::string get_printer_type(PresetBundle *preset_bundle); - bool is_bbl_vendor_preset(PresetBundle *m_preset_bundle); + bool is_bbl_vendor_preset(PresetBundle *preset_bundle); static const std::vector& print_options(); static const std::vector& filament_options(); diff --git a/src/slic3r/GUI/ConfirmHintDialog.cpp b/src/slic3r/GUI/ConfirmHintDialog.cpp index 50e91d5c4..c64aea79f 100644 --- a/src/slic3r/GUI/ConfirmHintDialog.cpp +++ b/src/slic3r/GUI/ConfirmHintDialog.cpp @@ -104,8 +104,13 @@ void ConfirmHintDialog::render(wxDC& dc) { auto text_size = dc.GetTextExtent(count_txt); if (text_size.x + pos_firm_up_hint.x + FromDIP(25) < wxSize(FromDIP(475), FromDIP(100)).x) { - if (firm_up_hint[i] == ' ' || firm_up_hint[i] == '\n') + if (firm_up_hint[i] == ' ') { new_line_pos = i; + } else if (firm_up_hint[i] == '\n') { + fisrt_line = firm_up_hint.SubString(0, i); + remaining_line = firm_up_hint.SubString(i + 1, firm_up_hint.length()); + break; + } } else { if (!is_ch) { @@ -123,7 +128,6 @@ void ConfirmHintDialog::render(wxDC& dc) { } dc.DrawText(fisrt_line, pos_firm_up_hint); - count_txt = ""; new_line_pos = 0; for (int i = 0; i < remaining_line.length(); i++) { @@ -167,6 +171,12 @@ void ConfirmHintDialog::on_button_close(wxCommandEvent& event) { this->Close(); } +bool ConfirmHintDialog::Show(bool show) +{ + if (show) { CentreOnParent(); } + return DPIDialog::Show(show); +} + void ConfirmHintDialog::on_dpi_changed(const wxRect& suggested_rect) { m_button_confirm->SetMinSize(wxSize(-1, FromDIP(24))); m_button_confirm->SetCornerRadius(FromDIP(12)); diff --git a/src/slic3r/GUI/ConfirmHintDialog.hpp b/src/slic3r/GUI/ConfirmHintDialog.hpp index 76483f2c8..e265077e0 100644 --- a/src/slic3r/GUI/ConfirmHintDialog.hpp +++ b/src/slic3r/GUI/ConfirmHintDialog.hpp @@ -45,6 +45,8 @@ public: void SetHint(const wxString &hint); + bool Show(bool show) override; + ~ConfirmHintDialog(); }; }} // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index ab6324d20..b194a96ef 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -347,6 +347,7 @@ public: Print* fff_print() { return m_print; } //return the slice result GCodeProcessorResult* get_slice_result() { return m_gcode_result; } + std::string get_tmp_gcode_path(); std::string get_temp_config_3mf_path(); //this API should only be used for command line usage diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 2a7c784b8..ea271f1bd 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2540,6 +2540,16 @@ wxColour Plater::get_next_color_for_filament() return colors[curr_color_filamenet++ % 7]; } +wxString Plater::get_slice_warning_string(GCodeProcessorResult::SliceWarnings& warning) +{ + if (warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { + return _L("The bed temperature exceeds filament's vitrification temperature. Please open the front door of printer before printing to avoid nozzle clog."); + } + else { + return wxString(warning.msg); + } +} + void Plater::priv::apply_free_camera_correction(bool apply/* = true*/) { bool use_perspective_camera = get_config("use_perspective_camera").compare("true") == 0; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 11556056d..ae6d91dec 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -235,6 +235,7 @@ public: static void setPrintSpeedTable(Slic3r::GlobalSpeedMap& printSpeedMap); static void setExtruderParams(std::map& extParas); static wxColour get_next_color_for_filament(); + static wxString get_slice_warning_string(GCodeProcessorResult::SliceWarnings& warning); // BBS: restore std::vector load_files(const std::vector& input_files, LoadStrategy strategy = LoadStrategy::LoadModel | LoadStrategy::LoadConfig, bool ask_multi = false); diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 68d695614..d3f7c9e57 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -21,6 +21,7 @@ #include "Plater.hpp" #include "BitmapCache.hpp" #include "BindDialog.hpp" +#include "ConfirmHintDialog.hpp" namespace Slic3r { namespace GUI { @@ -1046,7 +1047,7 @@ SelectMachineDialog::SelectMachineDialog(Plater *plater) m_button_ensure->SetMinSize(SELECT_MACHINE_DIALOG_BUTTON_SIZE); m_button_ensure->SetCornerRadius(FromDIP(12)); - m_button_ensure->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_ok, this); + m_button_ensure->Bind(wxEVT_BUTTON, &SelectMachineDialog::on_ok_btn, this); m_sizer_pcont->Add(m_button_ensure, 0, wxEXPAND | wxBOTTOM, FromDIP(10)); m_sizer_prepare->Add(m_sizer_pcont, 0, wxEXPAND, 0); m_panel_prepare->SetSizer(m_sizer_prepare); @@ -1716,7 +1717,67 @@ void SelectMachineDialog::on_cancel(wxCloseEvent &event) this->EndModal(wxID_CANCEL); } -void SelectMachineDialog::on_ok(wxCommandEvent &event) +bool SelectMachineDialog::is_same_printer_model() +{ + bool result = true; + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return result; + + MachineObject* obj_ = dev->get_selected_machine(); + assert(obj_->dev_id == m_printer_last_select); + if (obj_ == nullptr) { + return result; + } + + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + if (preset_bundle && preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle) != obj_->printer_type) { + BOOST_LOG_TRIVIAL(info) << "printer_model: source = " << preset_bundle->printers.get_edited_preset().get_printer_type(preset_bundle); + BOOST_LOG_TRIVIAL(info) << "printer_model: target = " << obj_->printer_type; + return false; + } + + return true; +} + +void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) +{ + wxString confirm_text = _L("Please check the following infomation:\n"); + + //Check Printer Model Id + bool is_same_printer_type = is_same_printer_model(); + confirm_text += _L("The printer type used to generate G-code is not the same type as the currently selected physical printer. It is recommend to re-slice by selecting the same printer type.\n"); + + //Check slice warnings + bool has_slice_warnings = false; + PartPlate* plate = m_plater->get_partplate_list().get_curr_plate(); + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (dev) { + MachineObject* obj_ = dev->get_selected_machine(); + for (auto warning : plate->get_slice_result()->warnings) { + if ((obj_->printer_type == "BL-P001" || obj_->printer_type == "BL-P002") && warning.msg == BED_TEMP_TOO_HIGH_THAN_FILAMENT) { + confirm_text += Plater::get_slice_warning_string(warning) + "\n"; + } else { + has_slice_warnings = true; + } + } + } + + if (!is_same_printer_type + || has_slice_warnings + ) { + wxString confirm_title = _L("Confirm"); + ConfirmHintDialog confirm_dlg(this, wxID_ANY, confirm_title); + confirm_dlg.SetHint(confirm_text); + confirm_dlg.Bind(EVT_CONFIRM_HINT, [this](wxCommandEvent& e) { + this->on_ok(); + }); + confirm_dlg.ShowModal(); + } else { + this->on_ok(); + } +} + +void SelectMachineDialog::on_ok() { BOOST_LOG_TRIVIAL(info) << "print_job: on_ok to send"; m_is_canceled = false; diff --git a/src/slic3r/GUI/SelectMachine.hpp b/src/slic3r/GUI/SelectMachine.hpp index 853429213..08d6029ad 100644 --- a/src/slic3r/GUI/SelectMachine.hpp +++ b/src/slic3r/GUI/SelectMachine.hpp @@ -358,6 +358,8 @@ public: void show_status(PrintDialogStatus status, std::vector params = std::vector()); PrintDialogStatus get_status() { return m_print_status; } + bool is_same_printer_model(); + bool Show(bool show); /* model */ @@ -393,7 +395,8 @@ protected: // Virtual event handlers, overide them in your derived class void update_printer_combobox(wxCommandEvent &event); void on_cancel(wxCloseEvent &event); - void on_ok(wxCommandEvent &event); + void on_ok_btn(wxCommandEvent &event); + void on_ok(); void on_refresh(wxCommandEvent &event); void on_set_finish_mapping(wxCommandEvent &evt); void on_print_job_cancel(wxCommandEvent &evt);