diff --git a/src/slic3r/GUI/ParamsPanel.cpp b/src/slic3r/GUI/ParamsPanel.cpp index 3aa3d7c61..9cf9dfe05 100644 --- a/src/slic3r/GUI/ParamsPanel.cpp +++ b/src/slic3r/GUI/ParamsPanel.cpp @@ -23,7 +23,7 @@ namespace Slic3r { namespace GUI { -TipsDialog::TipsDialog(wxWindow *parent, const wxString &title, const wxString &description, std::string app_key) +TipsDialog::TipsDialog(wxWindow *parent, const wxString &title, const wxString &description, std::string app_key, long style) : DPIDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX), m_app_key(app_key) { @@ -60,18 +60,22 @@ TipsDialog::TipsDialog(wxWindow *parent, const wxString &title, const wxString & wxBoxSizer *m_sizer_right = new wxBoxSizer(wxHORIZONTAL); - m_confirm = new Button(this, _L("OK")); - StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), - std::pair(wxColour(0, 174, 66), StateColor::Normal)); - - m_confirm->SetBackgroundColor(btn_bg_green); - m_confirm->SetBorderColor(wxColour(0, 174, 66)); - m_confirm->SetTextColor(wxColour(255, 255, 255)); - m_confirm->SetSize(TIPS_DIALOG_BUTTON_SIZE); - m_confirm->SetMinSize(TIPS_DIALOG_BUTTON_SIZE); - m_confirm->SetCornerRadius(FromDIP(12)); - m_confirm->Bind(wxEVT_LEFT_DOWN, &TipsDialog::on_ok, this); - m_sizer_right->Add(m_confirm, 0, wxALL, FromDIP(5)); + if (style & wxOK) { + Button* btn = add_button(wxID_OK, _L("OK"), true); + m_sizer_right->Add(btn, 0, wxALL, FromDIP(5)); + } + if (style & wxYES) { + Button *btn = add_button(wxID_YES, _L("Yes"), true); + m_sizer_right->Add(btn, 0, wxALL, FromDIP(5)); + } + if (style & wxNO) { + Button *btn = add_button(wxID_NO, _L("No"), false); + m_sizer_right->Add(btn, 0, wxALL, FromDIP(5)); + } + if (style & wxCANCEL) { + Button *btn = add_button(wxID_CANCEL, _L("Cancel"), false); + m_sizer_right->Add(btn, 0, wxALL, FromDIP(5)); + } m_sizer_bottom->Add(m_sizer_right, 0, wxEXPAND, FromDIP(5)); m_sizer_main->Add(m_sizer_bottom, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(40)); @@ -101,7 +105,7 @@ wxBoxSizer *TipsDialog::create_item_checkbox(wxString title, wxWindow *parent, w checkbox_title->Wrap(-1); m_sizer_checkbox->Add(checkbox_title, 0, wxALIGN_CENTER | wxALL, 3); - m_show_again = wxGetApp().app_config->get(param) == "true" ? true : false; + m_show_again = wxGetApp().app_config->has(param); checkbox->SetValue(m_show_again); checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, checkbox, param](wxCommandEvent &e) { @@ -112,6 +116,62 @@ wxBoxSizer *TipsDialog::create_item_checkbox(wxString title, wxWindow *parent, w return m_sizer_checkbox; } +Button *TipsDialog::add_button(wxWindowID btn_id, const wxString &label, bool set_focus /*= false*/) +{ + Button* btn = new Button(this, label, "", 0, 0, btn_id); + StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), + std::pair(wxColour(61, 203, 115), StateColor::Hovered), + std::pair(wxColour(0, 174, 66), StateColor::Normal)); + + StateColor btn_bd_green(std::pair(wxColour(0, 174, 66), StateColor::Normal)); + + StateColor btn_text_green(std::pair(wxColour(255, 255, 254), StateColor::Normal)); + + StateColor btn_bg_white( + std::pair(wxColour(206, 206, 206), StateColor::Pressed), + std::pair(wxColour(238, 238, 238), StateColor::Hovered), + std::pair(wxColour(255, 255, 255), StateColor::Normal) + ); + + StateColor btn_bd_white(std::pair(wxColour(38, 46, 48), StateColor::Normal)); + + StateColor btn_text_white(std::pair(wxColour(38, 46, 48), StateColor::Normal)); + + if (btn_id == wxID_OK || btn_id == wxID_YES) { + btn->SetBackgroundColor(btn_bg_green); + btn->SetBorderColor(btn_bd_green); + btn->SetTextColor(btn_text_green); + } + + if (btn_id == wxID_CANCEL || btn_id == wxID_NO) { + btn->SetBackgroundColor(btn_bg_white); + btn->SetBorderColor(btn_bd_white); + btn->SetTextColor(btn_text_white); + } + + if (set_focus) + btn->SetFocus(); + + btn->SetSize(TIPS_DIALOG_BUTTON_SIZE); + btn->SetMinSize(TIPS_DIALOG_BUTTON_SIZE); + btn->SetCornerRadius(FromDIP(12)); + btn->Bind(wxEVT_BUTTON, [this, btn_id](wxCommandEvent &) { + if (m_show_again) { + if (!m_app_key.empty()) { + if (btn_id == wxID_OK || btn_id == wxID_YES) { + wxGetApp().app_config->set_bool(m_app_key, true); + } + + if (btn_id == wxID_NO) { + wxGetApp().app_config->set_bool(m_app_key, false); + } + } + } + EndModal(btn_id); + }); + return btn; +} + void TipsDialog::on_dpi_changed(const wxRect &suggested_rect) { if (m_confirm) m_confirm->SetMinSize(TIPS_DIALOG_BUTTON_SIZE); diff --git a/src/slic3r/GUI/ParamsPanel.hpp b/src/slic3r/GUI/ParamsPanel.hpp index bdc40f116..8bf08378f 100644 --- a/src/slic3r/GUI/ParamsPanel.hpp +++ b/src/slic3r/GUI/ParamsPanel.hpp @@ -48,7 +48,7 @@ private: std::string m_app_key; public: - TipsDialog(wxWindow *parent, const wxString &title, const wxString &description, std::string app_key = ""); + TipsDialog(wxWindow *parent, const wxString &title, const wxString &description, std::string app_key = "", long style = wxOK); Button *m_confirm{nullptr}; Button *m_cancel{nullptr}; wxPanel *m_top_line{nullptr}; @@ -58,6 +58,7 @@ protected: void on_dpi_changed(const wxRect &suggested_rect) override; void on_ok(wxMouseEvent &event); wxBoxSizer *create_item_checkbox(wxString title, wxWindow *parent, wxString tooltip, std::string param); + Button* add_button(wxWindowID btn_id, const wxString &label, bool set_focus = false); }; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0978afb57..43aceb1da 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4687,6 +4687,77 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (dev) { + MachineObject *obj = dev->get_selected_machine(); + if (obj) { + if (obj->m_extder_data.extders.size() > 0) { + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + Preset &printer_preset = preset_bundle->printers.get_selected_preset(); + + double preset_nozzle_diameter = 0.4; + const ConfigOption *opt = printer_preset.config.option("nozzle_diameter"); + if (opt) + preset_nozzle_diameter = static_cast(opt)->values[0]; + float machine_nozzle_diameter = obj->m_extder_data.extders[0].diameter; + + std::string machine_type = obj->printer_type; + if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit) + machine_type = "C12"; + + if (printer_preset.get_current_printer_type(preset_bundle) != machine_type || !is_approx((float) preset_nozzle_diameter, machine_nozzle_diameter)) { + auto get_printer_preset = [](MachineObject *obj, float nozzle_value) -> Preset * { + if (!obj) + return nullptr; + + Preset *printer_preset = nullptr; + PresetBundle *preset_bundle = wxGetApp().preset_bundle; + for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) { + // only use system printer preset + if (!printer_it->is_system) continue; + + ConfigOption *printer_nozzle_opt = printer_it->config.option("nozzle_diameter"); + ConfigOptionFloatsNullable *printer_nozzle_vals = nullptr; + if (printer_nozzle_opt) printer_nozzle_vals = dynamic_cast(printer_nozzle_opt); + std::string model_id = printer_it->get_current_printer_type(preset_bundle); + + std::string printer_type = obj->printer_type; + if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit) + printer_type = "C12"; + if (model_id.compare(printer_type) == 0 && printer_nozzle_vals && abs(printer_nozzle_vals->get_at(0) - nozzle_value) < 1e-3) { + printer_preset = &(*printer_it); + } + }; + + return printer_preset; + }; + + Preset *machine_preset = get_printer_preset(obj, machine_nozzle_diameter); + if (machine_preset != nullptr) { + bool sync_printer_info = false; + if (!wxGetApp().app_config->has("sync_after_load_file_show_flag")) { + wxString tips = from_u8((boost::format(L("The printer you are currently bound to is %s,\nThe printer preset for your current file is %s,\n")) %machine_preset->name % printer_preset.name).str()); + if (obj->is_multi_extruders()) + tips += L("Do you want to sync printer presets, ams and nozzle information immediately?"); + else + tips += L("Do you want to sync printer presets immediately?"); + + TipsDialog dlg(wxGetApp().mainframe, _L("Tips"), tips, "sync_after_load_file_show_flag", wxYES_NO); + if (dlg.ShowModal() == wxID_YES) { sync_printer_info = true; } + } else { + sync_printer_info = wxGetApp().app_config->get("sync_after_load_file_show_flag") == "true"; + } + if (sync_printer_info) { + Tab *printer_tab = GUI::wxGetApp().get_tab(Preset::Type::TYPE_PRINTER); + printer_tab->select_preset(machine_preset->name); + if (obj->is_multi_extruders()) GUI::wxGetApp().sidebar().sync_extruder_list(); + } + } + } + } + } + } + if (new_model) delete new_model; //BBS: translate old 3mf to correct positions