ENH:add "forward" function in MsgDialog

jira: STUDIO-9971
Change-Id: I699912b4d18cb52aec2badf64a4655d20559ed7c
This commit is contained in:
zhou.xu 2025-01-23 12:15:17 +08:00 committed by lane.wei
parent 12fe1ac740
commit f608327a10
6 changed files with 66 additions and 31 deletions

View File

@ -22,15 +22,16 @@
#include "GUI_App.hpp" #include "GUI_App.hpp"
#define DESIGN_INPUT_SIZE wxSize(FromDIP(100), -1) #define DESIGN_INPUT_SIZE wxSize(FromDIP(100), -1)
#define MSG_DLG_MAX_SIZE wxSize(FromDIP(700), -1)
namespace Slic3r { namespace Slic3r {
namespace GUI { namespace GUI {
MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style, wxBitmap bitmap) MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style, wxBitmap bitmap, const wxString &forward_str)
: DPIDialog(parent ? parent : dynamic_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, title, wxDefaultPosition, wxSize(360, -1),wxDEFAULT_DIALOG_STYLE) : DPIDialog(parent ? parent : dynamic_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, title, wxDefaultPosition, wxSize(360, -1),wxDEFAULT_DIALOG_STYLE)
, boldfont(wxGetApp().normal_font()) , boldfont(wxGetApp().normal_font())
, content_sizer(new wxBoxSizer(wxVERTICAL)) , content_sizer(new wxBoxSizer(wxVERTICAL))
, btn_sizer(new wxBoxSizer(wxHORIZONTAL)) , btn_sizer(new wxBoxSizer(wxHORIZONTAL))
, m_forward_str(forward_str)
{ {
boldfont.SetWeight(wxFONTWEIGHT_BOLD); boldfont.SetWeight(wxFONTWEIGHT_BOLD);
SetBackgroundColour(0xFFFFFF); SetBackgroundColour(0xFFFFFF);
@ -212,7 +213,14 @@ Button* MsgDialog::get_button(wxWindowID btn_id){
void MsgDialog::apply_style(long style) void MsgDialog::apply_style(long style)
{ {
bool focus = (style & wxNO_DEFAULT) == 0; bool focus = (style & wxNO_DEFAULT) == 0;
if (style & wxOK) add_button(wxID_OK, focus, _L("OK")); if (style & wxFORWARD)
add_button(wxFORWARD, true, _L("Go to") + " " + m_forward_str);
if (style & wxOK) {
if (style & wxFORWARD) { add_button(wxID_OK, false, _L("Later")); }
else {
add_button(wxID_OK, focus, _L("OK"));
}
}
if (style & wxYES) add_button(wxID_YES, focus, _L("Yes")); if (style & wxYES) add_button(wxID_YES, focus, _L("Yes"));
if (style & wxNO) add_button(wxID_NO, false,_L("No")); if (style & wxNO) add_button(wxID_NO, false,_L("No"));
if (style & wxCANCEL) add_button(wxID_CANCEL, false, _L("Cancel")); if (style & wxCANCEL) add_button(wxID_CANCEL, false, _L("Cancel"));
@ -225,9 +233,10 @@ void MsgDialog::apply_style(long style)
void MsgDialog::finalize() void MsgDialog::finalize()
{ {
wxGetApp().UpdateDlgDarkUI(this); Layout();
Fit(); Fit();
CenterOnParent(); CenterOnParent();
wxGetApp().UpdateDlgDarkUI(this);
} }
@ -357,12 +366,13 @@ WarningDialog::WarningDialog(wxWindow *parent,
MessageDialog::MessageDialog(wxWindow* parent, MessageDialog::MessageDialog(wxWindow* parent,
const wxString& message, const wxString& message,
const wxString& caption/* = wxEmptyString*/, const wxString& caption/* = wxEmptyString*/,
long style/* = wxOK*/) long style /* = wxOK*/,
: MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_FULL_NAME) : caption, wxEmptyString, style) const wxString &forward_str /* = wxEmptyString*/)
: MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_FULL_NAME) : caption, wxEmptyString, style, wxBitmap(),forward_str)
{ {
add_msg_content(this, content_sizer, message); add_msg_content(this, content_sizer, message);
SetMaxSize(MSG_DLG_MAX_SIZE);
finalize(); finalize();
wxGetApp().UpdateDlgDarkUI(this);
} }

View File

@ -77,7 +77,7 @@ protected:
VERT_SPACING = 15,//TO VERT_SPACING = 15,//TO
}; };
MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style = wxOK, wxBitmap bitmap = wxNullBitmap); MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style = wxOK, wxBitmap bitmap = wxNullBitmap, const wxString &forward_str = "");
// returns pointer to created button // returns pointer to created button
Button* add_button(wxWindowID btn_id, bool set_focus = false, const wxString& label = wxString()); Button* add_button(wxWindowID btn_id, bool set_focus = false, const wxString& label = wxString());
// returns pointer to found button or NULL // returns pointer to found button or NULL
@ -92,6 +92,7 @@ protected:
wxStaticBitmap *logo; wxStaticBitmap *logo;
MsgButtonsHash m_buttons; MsgButtonsHash m_buttons;
CheckBox* m_checkbox_dsa{nullptr}; CheckBox* m_checkbox_dsa{nullptr};
wxString m_forward_str;
}; };
@ -151,10 +152,7 @@ class MessageDialog : public MsgDialog
{ {
public: public:
// NOTE! Don't change a signature of contsrucor. It have to be tha same as for wxMessageDialog // NOTE! Don't change a signature of contsrucor. It have to be tha same as for wxMessageDialog
MessageDialog( wxWindow *parent, MessageDialog(wxWindow *parent,const wxString& message, const wxString &caption = wxEmptyString, long style = wxOK,const wxString& forward_str = "");
const wxString& message,
const wxString& caption = wxEmptyString,
long style = wxOK);
MessageDialog(MessageDialog&&) = delete; MessageDialog(MessageDialog&&) = delete;
MessageDialog(const MessageDialog&) = delete; MessageDialog(const MessageDialog&) = delete;
MessageDialog &operator=(MessageDialog&&) = delete; MessageDialog &operator=(MessageDialog&&) = delete;

View File

@ -1131,18 +1131,17 @@ bool Sidebar::priv::switch_diameter(bool single)
bool Sidebar::priv::sync_extruder_list(bool &only_external_material) bool Sidebar::priv::sync_extruder_list(bool &only_external_material)
{ {
MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine(); MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine();
auto printer_name = plater->get_selected_printer_name_in_combox();
if (obj == nullptr) { if (obj == nullptr) {
MessageDialog dlg(this->plater, _L("Please select a printer in 'Device' page first."), _L("Sync printer information"), wxOK | wxICON_WARNING); plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
dlg.ShowModal();
return false; return false;
} }
if (obj->m_extder_data.extders.size() != 2) { if (obj->m_extder_data.extders.size() != 2) {//wxString(obj->get_preset_printer_model_name(machine_print_name))
MessageDialog dlg(this->plater, _L("The currently connected printer does not have two extruders."), _L("Sync printer information"), wxOK | wxICON_WARNING); plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::INCONSISTENT, _L("Sync printer information"));
dlg.ShowModal();
return false; return false;
} }
if (!check_printer_initialized(obj)) if (!plater->check_printer_initialized(obj))
return false; return false;
std::string machine_print_name = obj->printer_type; std::string machine_print_name = obj->printer_type;
@ -2887,9 +2886,8 @@ void Sidebar::sync_ams_list(bool is_from_big_sync_btn)
auto & list = wxGetApp().preset_bundle->filament_ams_list; auto & list = wxGetApp().preset_bundle->filament_ams_list;
if (list.empty()) { if (list.empty()) {
SyncAmsInfoDialog::SyncInfo temp_info; auto printer_name = p->plater->get_selected_printer_name_in_combox();
SyncAmsInfoDialog sync_dlg(this, temp_info); p->plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
sync_dlg.ShowModal();//printer is not connected
return; return;
} }
if (!wxGetApp().plater()->is_same_printer_for_connected_and_selected()) { if (!wxGetApp().plater()->is_same_printer_for_connected_and_selected()) {
@ -13322,7 +13320,7 @@ Preset *get_printer_preset(MachineObject *obj)
return printer_preset; return printer_preset;
} }
bool check_printer_initialized(MachineObject *obj,bool only_warning) bool Plater::check_printer_initialized(MachineObject *obj, bool only_warning)
{ {
if (!obj) if (!obj)
return false; return false;
@ -13350,8 +13348,8 @@ bool check_printer_initialized(MachineObject *obj,bool only_warning)
print_parts_dlg->update_machine_obj(obj); print_parts_dlg->update_machine_obj(obj);
print_parts_dlg->ShowModal(); print_parts_dlg->ShowModal();
} else { } else {
MessageDialog dlg(wxGetApp().plater(), _L("Printer not connected. Please connect or choose a printer on the Device page and try again."), _L("Warning"), wxOK | wxICON_WARNING); auto printer_name = get_selected_printer_name_in_combox(); // wxString(obj->get_preset_printer_model_name(machine_print_name))
dlg.ShowModal(); pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
} }
return false; return false;
} }
@ -15324,6 +15322,30 @@ void Plater::split_object() { p->split_object(); }
void Plater::split_volume() { p->split_volume(); } void Plater::split_volume() { p->split_volume(); }
void Plater::optimize_rotation() { if (!p->m_ui_jobs.is_any_running()) p->m_ui_jobs.optimize_rotation(); } void Plater::optimize_rotation() { if (!p->m_ui_jobs.is_any_running()) p->m_ui_jobs.optimize_rotation(); }
void Plater::update_menus() { p->menus.update(); } void Plater::update_menus() { p->menus.update(); }
wxString Plater::get_selected_printer_name_in_combox() {
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::string printer_model = preset_bundle->printers.get_selected_preset().config.option<ConfigOptionString>("printer_model")->value;
return printer_model;
}
void Plater::pop_warning_and_go_to_device_page(wxString printer_name, PrinterWarningType type, const wxString &title)
{
printer_name.Replace("Bambu Lab", "", false);
wxString content;
if (type == PrinterWarningType::NOT_CONNECTED) {
content = wxString::Format(_L("Printer not connected. Please go to the device page to connect an %s printer before syncing."), printer_name);
} else if (type == PrinterWarningType::INCONSISTENT) {
content = wxString::Format(_L("The currently connected printer on the device page is not an %s. Please switch to an %s before syncing."), printer_name, printer_name);
}
MessageDialog dlg(this, content, title, wxOK | wxFORWARD | wxICON_WARNING, _L("Device Page"));
auto result = dlg.ShowModal();
if (result == wxFORWARD) {
wxGetApp().mainframe->select_tab(size_t(MainFrame::tpMonitor));
}
}
bool Plater::is_same_printer_for_connected_and_selected() bool Plater::is_same_printer_for_connected_and_selected()
{ {
MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine(); MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine();
@ -15340,9 +15362,8 @@ bool Plater::is_same_printer_for_connected_and_selected()
return false; return false;
if (machine_print_name != target_model_id) { if (machine_print_name != target_model_id) {
MessageDialog dlg(this,_L("The currently selected machine preset is inconsistent with the connected printer type.Please change device or currently selected machine.\n"), auto printer_name = get_selected_printer_name_in_combox(); // wxString(obj->get_preset_printer_model_name(machine_print_name))
_L("Synchronize AMS Filament Information"), wxICON_WARNING | wxOK); pop_warning_and_go_to_device_page(printer_name, PrinterWarningType::INCONSISTENT, _L("Synchronize AMS Filament Information"));
dlg.ShowModal();
return false; return false;
} }
return true; return true;

View File

@ -492,6 +492,13 @@ public:
FilamentMapMode get_global_filament_map_mode() const; FilamentMapMode get_global_filament_map_mode() const;
void update_menus(); void update_menus();
wxString get_selected_printer_name_in_combox();
enum class PrinterWarningType {
NOT_CONNECTED,
INCONSISTENT,
};
void pop_warning_and_go_to_device_page(wxString printer_name, PrinterWarningType type, const wxString &title);
bool check_printer_initialized(MachineObject *obj, bool only_warning = false);
bool is_same_printer_for_connected_and_selected(); bool is_same_printer_for_connected_and_selected();
bool is_printer_configed_by_BBL(); bool is_printer_configed_by_BBL();
// BBS // BBS
@ -862,7 +869,7 @@ std::string check_boolean_possible(const std::vector<const ModelVolume *> &
Preset *get_printer_preset(MachineObject *obj); Preset *get_printer_preset(MachineObject *obj);
wxArrayString get_all_camera_view_type(); wxArrayString get_all_camera_view_type();
bool check_printer_initialized(MachineObject *obj, bool only_warning = false);
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View File

@ -80,7 +80,6 @@ void DropDown::Invalidate(bool clear)
void DropDown::SetSelection(int n) void DropDown::SetSelection(int n)
{ {
assert(n < (int) items.size());
if (n >= (int) items.size()) if (n >= (int) items.size())
n = -1; n = -1;
if (selection == n) return; if (selection == n) return;

View File

@ -214,7 +214,7 @@ static bool check_nozzle_diameter_and_type(const DynamicPrintConfig &full_config
return false; return false;
} }
if (!check_printer_initialized(obj)) if (!Slic3r::GUI::wxGetApp().plater()->check_printer_initialized(obj))
return false; return false;
// P1P/S // P1P/S