From 2ffa56633cac928df788aa7b270a11cdd1c2976c Mon Sep 17 00:00:00 2001 From: "tao.jin" Date: Sat, 26 Nov 2022 10:49:42 +0800 Subject: [PATCH] ENH: rebuild warning dialog with frame Change-Id: Id4a8ab80ecec30b668de59556823dad6838276fe --- src/slic3r/GUI/ReleaseNote.cpp | 46 ++++++++++++++---- src/slic3r/GUI/ReleaseNote.hpp | 6 ++- src/slic3r/GUI/SelectMachine.cpp | 18 ++++--- src/slic3r/GUI/SelectMachine.hpp | 3 ++ src/slic3r/GUI/StatusPanel.cpp | 36 ++++++++------ src/slic3r/GUI/StatusPanel.hpp | 3 +- src/slic3r/GUI/UpgradePanel.cpp | 80 +++++++++++++++++++------------- src/slic3r/GUI/UpgradePanel.hpp | 5 ++ 8 files changed, 133 insertions(+), 64 deletions(-) diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index a9b7ba3e9..8751aa7a4 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -343,7 +343,7 @@ void UpdateVersionDialog::update_version_info(wxString release_note, wxString ve } SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, const wxString& title, enum ButtonStyle btn_style, const wxPoint& pos, const wxSize& size, long style) - :DPIDialog(parent, id, title, pos, size, style) + :DPIFrame(parent, id, title, pos, size, style) { std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str(); SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); @@ -385,10 +385,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId()); e.SetEventObject(this); GetEventHandler()->ProcessEvent(evt); - if (this->IsModal()) - EndModal(wxID_YES); - else - this->Close(); + this->Hide(); }); m_button_cancel = new Button(this, _L("Cancel")); @@ -400,10 +397,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons m_button_cancel->SetCornerRadius(FromDIP(12)); m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { - if (this->IsModal()) - EndModal(wxID_NO); - else - this->Close(); + this->Hide(); }); if (btn_style != CONFIRM_AND_CANCEL) @@ -420,6 +414,7 @@ SecondaryCheckDialog::SecondaryCheckDialog(wxWindow* parent, wxWindowID id, cons m_sizer_right->Add(sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(35)); m_sizer_right->Add(0, 0, 0, wxTOP,FromDIP(18)); + Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {this->Hide();}); SetSizer(m_sizer_right); Layout(); @@ -457,6 +452,39 @@ void SecondaryCheckDialog::update_text(wxString text) m_sizer_main->Fit(this); } +void SecondaryCheckDialog::on_show() +{ + // recover button color + wxMouseEvent evt_ok(wxEVT_LEFT_UP); + m_button_ok->GetEventHandler()->ProcessEvent(evt_ok); + wxMouseEvent evt_cancel(wxEVT_LEFT_UP); + m_button_cancel->GetEventHandler()->ProcessEvent(evt_cancel); + + this->Show(); + this->SetFocus(); +} + +bool SecondaryCheckDialog::is_english_text(wxString str) +{ + std::regex reg("^[0-9a-zA-Z]+$"); + std::smatch matchResult; + + std::string pattern_Special = "{}[]<>~!@#$%^&*(),.?/ :"; + for (auto i = 0; i < str.Length(); i++) { + std::string regex_str = wxString(str[i]).ToStdString(); + if(std::regex_match(regex_str, matchResult, reg)){ + continue; + } + else { + int result = pattern_Special.find(regex_str.c_str()); + if (result < 0 || result > pattern_Special.length()) { + return false; + } + } + } + return true; +} + wxString SecondaryCheckDialog::format_text(wxStaticText* st, wxString str, int warp) { if (wxGetApp().app_config->get("language") != "zh_CN") { return str; } diff --git a/src/slic3r/GUI/ReleaseNote.hpp b/src/slic3r/GUI/ReleaseNote.hpp index 5cbc83ec9..57bff1139 100644 --- a/src/slic3r/GUI/ReleaseNote.hpp +++ b/src/slic3r/GUI/ReleaseNote.hpp @@ -80,7 +80,7 @@ public: Button* m_button_cancel; }; -class SecondaryCheckDialog : public DPIDialog +class SecondaryCheckDialog : public DPIFrame { public: enum ButtonStyle { @@ -98,9 +98,11 @@ public: long style = wxCLOSE_BOX | wxCAPTION ); void update_text(wxString text); + void on_show(); + bool is_english_text(wxString str); wxString format_text(wxStaticText* st, wxString str, int warp); ~SecondaryCheckDialog(); - void on_dpi_changed(const wxRect& suggested_rect) override; + void on_dpi_changed(const wxRect& suggested_rect); wxBoxSizer* m_sizer_main; wxScrolledWindow *m_vebview_release_note {nullptr}; diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 89be32ba1..c63e66f77 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -21,7 +21,6 @@ #include "Plater.hpp" #include "BitmapCache.hpp" #include "BindDialog.hpp" -#include "ReleaseNote.hpp" namespace Slic3r { namespace GUI { @@ -1935,7 +1934,12 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) if (!is_same_printer_type || has_slice_warnings) { wxString confirm_title = _L("Warning"); - SecondaryCheckDialog confirm_dlg(this, wxID_ANY, confirm_title); + if (confirm_dlg == nullptr) { + confirm_dlg = new SecondaryCheckDialog(this, wxID_ANY, confirm_title); + confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) { + this->on_ok(); + }); + } wxString info_msg = wxEmptyString; for (auto i = 0; i < confirm_text.size(); i++) { @@ -1947,10 +1951,9 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) } } - confirm_dlg.update_text(info_msg); - if (confirm_dlg.ShowModal() == wxID_YES) { - this->on_ok(); - } + confirm_dlg->update_text(info_msg); + confirm_dlg->on_show(); + } else { this->on_ok(); } @@ -2938,6 +2941,9 @@ bool SelectMachineDialog::Show(bool show) SelectMachineDialog::~SelectMachineDialog() { delete m_refresh_timer; + + if (confirm_dlg != nullptr) + delete confirm_dlg; } EditDevNameDialog::EditDevNameDialog(Plater *plater /*= nullptr*/) diff --git a/src/slic3r/GUI/SelectMachine.hpp b/src/slic3r/GUI/SelectMachine.hpp index 773105d06..6b4a6d10c 100644 --- a/src/slic3r/GUI/SelectMachine.hpp +++ b/src/slic3r/GUI/SelectMachine.hpp @@ -25,6 +25,7 @@ #include #include "AmsMappingPopup.hpp" +#include "ReleaseNote.hpp" #include "GUI_Utils.hpp" #include "wxExtensions.hpp" #include "DeviceManager.hpp" @@ -279,6 +280,8 @@ private: wxColour m_colour_def_color{wxColour(255, 255, 255)}; wxColour m_colour_bold_color{wxColour(38, 46, 48)}; + SecondaryCheckDialog* confirm_dlg = nullptr; + protected: MaterialHash m_materialList; std::vector m_filaments; diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index 3ed682289..cf4ceeb84 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -12,7 +12,6 @@ #include "libslic3r/Thread.hpp" #include "RecenterDialog.hpp" -#include "ReleaseNote.hpp" namespace Slic3r { namespace GUI { @@ -1175,6 +1174,13 @@ StatusPanel::~StatusPanel() m_calibration_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_calibration), NULL, this); m_options_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_show_print_options), NULL, this); m_button_unload->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_unload), NULL, this); + + // remove warning dialogs + if (m_print_error_dlg != nullptr) + delete m_print_error_dlg; + + if (abort_dlg != nullptr) + delete abort_dlg; } void StatusPanel::init_scaled_buttons() @@ -1262,12 +1268,14 @@ void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event) void StatusPanel::on_subtask_abort(wxCommandEvent &event) { - SecondaryCheckDialog abort_dlg(this->GetParent(), wxID_ANY, _L("Cancel print")); - abort_dlg.update_text(_L("Are you sure you want to cancel this print?")); - abort_dlg.Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) { - if (obj) obj->command_task_abort(); - }); - abort_dlg.ShowModal(); + if (abort_dlg == nullptr) { + abort_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Cancel print")); + abort_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) { + if (obj) obj->command_task_abort(); + }); + } + abort_dlg->update_text(_L("Are you sure you want to cancel this print?")); + abort_dlg->on_show(); } void StatusPanel::error_info_reset() @@ -1425,9 +1433,9 @@ void StatusPanel::show_error_message(wxString msg) if (m_panel_error_txt->IsShown()) { error_info_reset(); } - if (m_print_error_dlg.get() != nullptr) { - if (m_print_error_dlg.get()->IsShown()) { - m_print_error_dlg.get()->EndModal(wxID_OK); + if (m_print_error_dlg != nullptr) { + if (m_print_error_dlg->IsShown()) { + m_print_error_dlg->Hide(); } } } else { @@ -1436,9 +1444,11 @@ void StatusPanel::show_error_message(wxString msg) m_panel_error_txt->Show(); BOOST_LOG_TRIVIAL(info) << "show print error! error_msg = " << msg; - m_print_error_dlg = std::make_shared(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM); - m_print_error_dlg.get()->update_text(msg); - m_print_error_dlg.get()->ShowModal(); + if (m_print_error_dlg == nullptr) { + m_print_error_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM); + } + m_print_error_dlg->update_text(msg); + m_print_error_dlg->on_show(); } } diff --git a/src/slic3r/GUI/StatusPanel.hpp b/src/slic3r/GUI/StatusPanel.hpp index 87f4e2685..1488ffd6a 100644 --- a/src/slic3r/GUI/StatusPanel.hpp +++ b/src/slic3r/GUI/StatusPanel.hpp @@ -257,7 +257,8 @@ protected: PrintOptionsDialog* print_options_dlg { nullptr }; CalibrationDialog* calibration_dlg {nullptr}; AMSMaterialsSetting *m_filament_setting_dlg{nullptr}; - std::shared_ptr m_print_error_dlg = nullptr; + SecondaryCheckDialog* m_print_error_dlg = nullptr; + SecondaryCheckDialog* abort_dlg = nullptr; wxString m_request_url; bool m_start_loading_thumbnail = false; diff --git a/src/slic3r/GUI/UpgradePanel.cpp b/src/slic3r/GUI/UpgradePanel.cpp index d125ffc5b..f809571e8 100644 --- a/src/slic3r/GUI/UpgradePanel.cpp +++ b/src/slic3r/GUI/UpgradePanel.cpp @@ -4,7 +4,6 @@ #include "GUI.hpp" #include "GUI_App.hpp" #include "libslic3r/Thread.hpp" -#include "ReleaseNote.hpp" namespace Slic3r { namespace GUI { @@ -268,6 +267,9 @@ MachineInfoPanel::~MachineInfoPanel() { // Disconnect Events m_button_upgrade_firmware->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(MachineInfoPanel::on_upgrade_firmware), NULL, this); + + if (confirm_dlg != nullptr) + delete confirm_dlg; } void MachineInfoPanel::update(MachineObject* obj) @@ -661,30 +663,30 @@ void MachineInfoPanel::upgrade_firmware_internal() { void MachineInfoPanel::on_upgrade_firmware(wxCommandEvent &event) { - SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware")); - confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating.")); - confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) { - if (m_obj) { - m_obj->command_upgrade_confirm(); - } - }); - if (confirm_dlg->ShowModal()) { - delete confirm_dlg; + if (confirm_dlg == nullptr) { + confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware")); + confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_upgrade_confirm(); + } + }); } + confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating.")); + confirm_dlg->on_show(); } void MachineInfoPanel::on_consisitency_upgrade_firmware(wxCommandEvent &event) { - SecondaryCheckDialog* confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware")); - confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating.")); - confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent &e) { - if (m_obj) { - m_obj->command_consistency_upgrade_confirm(); - } - }); - if (confirm_dlg->ShowModal()) { - delete confirm_dlg; + if (confirm_dlg == nullptr) { + confirm_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware")); + confirm_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_consistency_upgrade_confirm(); + } + }); } + confirm_dlg->update_text(_L("Are you sure you want to update? This will take about 10 minutes. Do not turn off the power while the printer is updating.")); + confirm_dlg->on_show(); } void MachineInfoPanel::on_show_release_note(wxMouseEvent &event) @@ -746,7 +748,11 @@ UpgradePanel::UpgradePanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, UpgradePanel::~UpgradePanel() { + if (force_dlg != nullptr) + delete force_dlg ; + if (consistency_dlg != nullptr) + delete consistency_dlg ; } void UpgradePanel::msw_rescale() @@ -799,14 +805,18 @@ void UpgradePanel::update(MachineObject *obj) if (m_obj && m_show_forced_hint) { if (m_obj->upgrade_force_upgrade) { m_show_forced_hint = false; //lock hint - SecondaryCheckDialog force_dlg(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL | wxCLOSE_BOX | wxCAPTION); - force_dlg.update_text(_L( - "An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'." - )); - force_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_upgrade_firmware, m_push_upgrade_panel); - if (force_dlg->ShowModal()) { - delete force_dlg; + if (force_dlg == nullptr) { + force_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize); + force_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_upgrade_confirm(); + } + }); } + force_dlg->update_text(_L( + "An important update was detected and needs to be run before printing can continue. Do you want to update now? You can also update later from 'Upgrade firmware'." + )); + force_dlg->on_show(); } } @@ -818,14 +828,18 @@ void UpgradePanel::update(MachineObject *obj) if (m_obj && m_show_consistency_hint) { if (m_obj->upgrade_consistency_request) { m_show_consistency_hint = false; - SecondaryCheckDialog consistency_dlg(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize, wxPD_APP_MODAL | wxCLOSE_BOX | wxCAPTION); - consistency_dlg.update_text(_L( - "The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio." - )); - consistency_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, &MachineInfoPanel::on_consisitency_upgrade_firmware, m_push_upgrade_panel); - if (consistency_dlg->ShowModal()) { - delete consistency_dlg; + if (consistency_dlg == nullptr) { + consistency_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Update firmware"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_CANCEL, wxDefaultPosition, wxDefaultSize); + consistency_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this](wxCommandEvent& e) { + if (m_obj) { + m_obj->command_consistency_upgrade_confirm(); + } + }); } + consistency_dlg->update_text(_L( + "The firmware version is abnormal. Repairing and updating are required before printing. Do you want to update now? You can also update later on printer or update next time starting the studio." + )); + consistency_dlg->on_show(); } } diff --git a/src/slic3r/GUI/UpgradePanel.hpp b/src/slic3r/GUI/UpgradePanel.hpp index 378c48e42..392ecff1a 100644 --- a/src/slic3r/GUI/UpgradePanel.hpp +++ b/src/slic3r/GUI/UpgradePanel.hpp @@ -6,6 +6,7 @@ #include "Widgets/ProgressBar.hpp" #include #include +#include "ReleaseNote.hpp" namespace Slic3r { @@ -77,6 +78,8 @@ protected: int last_status = -1; std::string last_status_str = ""; + SecondaryCheckDialog* confirm_dlg = nullptr; + void upgrade_firmware_internal(); void on_show_release_note(wxMouseEvent &event); @@ -136,6 +139,8 @@ protected: int last_consistency_hint_status = -1; bool m_show_forced_hint = true; bool m_show_consistency_hint = true; + SecondaryCheckDialog* force_dlg{ nullptr }; + SecondaryCheckDialog* consistency_dlg{ nullptr }; public: UpgradePanel(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTAB_TRAVERSAL);