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"
#define DESIGN_INPUT_SIZE wxSize(FromDIP(100), -1)
#define MSG_DLG_MAX_SIZE wxSize(FromDIP(700), -1)
namespace Slic3r {
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)
, boldfont(wxGetApp().normal_font())
, content_sizer(new wxBoxSizer(wxVERTICAL))
, btn_sizer(new wxBoxSizer(wxHORIZONTAL))
, m_forward_str(forward_str)
{
boldfont.SetWeight(wxFONTWEIGHT_BOLD);
SetBackgroundColour(0xFFFFFF);
@ -212,7 +213,14 @@ Button* MsgDialog::get_button(wxWindowID btn_id){
void MsgDialog::apply_style(long style)
{
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 & wxNO) add_button(wxID_NO, false,_L("No"));
if (style & wxCANCEL) add_button(wxID_CANCEL, false, _L("Cancel"));
@ -225,9 +233,10 @@ void MsgDialog::apply_style(long style)
void MsgDialog::finalize()
{
wxGetApp().UpdateDlgDarkUI(this);
Layout();
Fit();
CenterOnParent();
wxGetApp().UpdateDlgDarkUI(this);
}
@ -357,12 +366,13 @@ WarningDialog::WarningDialog(wxWindow *parent,
MessageDialog::MessageDialog(wxWindow* parent,
const wxString& message,
const wxString& caption/* = wxEmptyString*/,
long style/* = wxOK*/)
: MsgDialog(parent, caption.IsEmpty() ? wxString::Format(_L("%s info"), SLIC3R_APP_FULL_NAME) : caption, wxEmptyString, style)
long style /* = wxOK*/,
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);
SetMaxSize(MSG_DLG_MAX_SIZE);
finalize();
wxGetApp().UpdateDlgDarkUI(this);
}

View File

@ -77,7 +77,7 @@ protected:
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
Button* add_button(wxWindowID btn_id, bool set_focus = false, const wxString& label = wxString());
// returns pointer to found button or NULL
@ -92,6 +92,7 @@ protected:
wxStaticBitmap *logo;
MsgButtonsHash m_buttons;
CheckBox* m_checkbox_dsa{nullptr};
wxString m_forward_str;
};
@ -151,10 +152,7 @@ class MessageDialog : public MsgDialog
{
public:
// NOTE! Don't change a signature of contsrucor. It have to be tha same as for wxMessageDialog
MessageDialog( wxWindow *parent,
const wxString& message,
const wxString& caption = wxEmptyString,
long style = wxOK);
MessageDialog(wxWindow *parent,const wxString& message, const wxString &caption = wxEmptyString, long style = wxOK,const wxString& forward_str = "");
MessageDialog(MessageDialog&&) = delete;
MessageDialog(const 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)
{
MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine();
auto printer_name = plater->get_selected_printer_name_in_combox();
if (obj == nullptr) {
MessageDialog dlg(this->plater, _L("Please select a printer in 'Device' page first."), _L("Sync printer information"), wxOK | wxICON_WARNING);
dlg.ShowModal();
plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
return false;
}
if (obj->m_extder_data.extders.size() != 2) {
MessageDialog dlg(this->plater, _L("The currently connected printer does not have two extruders."), _L("Sync printer information"), wxOK | wxICON_WARNING);
dlg.ShowModal();
if (obj->m_extder_data.extders.size() != 2) {//wxString(obj->get_preset_printer_model_name(machine_print_name))
plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::INCONSISTENT, _L("Sync printer information"));
return false;
}
if (!check_printer_initialized(obj))
if (!plater->check_printer_initialized(obj))
return false;
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;
if (list.empty()) {
SyncAmsInfoDialog::SyncInfo temp_info;
SyncAmsInfoDialog sync_dlg(this, temp_info);
sync_dlg.ShowModal();//printer is not connected
auto printer_name = p->plater->get_selected_printer_name_in_combox();
p->plater->pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
return;
}
if (!wxGetApp().plater()->is_same_printer_for_connected_and_selected()) {
@ -13322,7 +13320,7 @@ Preset *get_printer_preset(MachineObject *obj)
return printer_preset;
}
bool check_printer_initialized(MachineObject *obj,bool only_warning)
bool Plater::check_printer_initialized(MachineObject *obj, bool only_warning)
{
if (!obj)
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->ShowModal();
} 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);
dlg.ShowModal();
auto printer_name = get_selected_printer_name_in_combox(); // wxString(obj->get_preset_printer_model_name(machine_print_name))
pop_warning_and_go_to_device_page(printer_name, Plater::PrinterWarningType::NOT_CONNECTED, _L("Sync printer information"));
}
return false;
}
@ -15324,6 +15322,30 @@ void Plater::split_object() { p->split_object(); }
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::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()
{
MachineObject *obj = wxGetApp().getDeviceManager()->get_selected_machine();
@ -15340,9 +15362,8 @@ bool Plater::is_same_printer_for_connected_and_selected()
return false;
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"),
_L("Synchronize AMS Filament Information"), wxICON_WARNING | wxOK);
dlg.ShowModal();
auto printer_name = get_selected_printer_name_in_combox(); // wxString(obj->get_preset_printer_model_name(machine_print_name))
pop_warning_and_go_to_device_page(printer_name, PrinterWarningType::INCONSISTENT, _L("Synchronize AMS Filament Information"));
return false;
}
return true;

View File

@ -492,6 +492,13 @@ public:
FilamentMapMode get_global_filament_map_mode() const;
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_printer_configed_by_BBL();
// BBS
@ -862,7 +869,7 @@ std::string check_boolean_possible(const std::vector<const ModelVolume *> &
Preset *get_printer_preset(MachineObject *obj);
wxArrayString get_all_camera_view_type();
bool check_printer_initialized(MachineObject *obj, bool only_warning = false);
} // namespace GUI
} // namespace Slic3r

View File

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

View File

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