From 36d8d53427003c9ed3e5583e6f23dd0dd2e7ea76 Mon Sep 17 00:00:00 2001 From: "tao.jin" Date: Fri, 11 Nov 2022 12:30:00 +0800 Subject: [PATCH] ENH: refine set partplate bedtype dialog & button Change-Id: Icf1ec314f04c6156e92f2f5a8646b97cf4c2220c --- resources/images/plate_set_bedtype.svg | 18 ++++----- ...rned.svg => plate_set_bedtype_changed.svg} | 0 .../plate_set_bedtype_changed_hover.svg | 10 +++++ resources/images/plate_set_bedtype_hover.svg | 18 ++++----- src/slic3r/GUI/PartPlate.cpp | 39 ++++++++++++------- src/slic3r/GUI/PartPlate.hpp | 7 ++-- src/slic3r/GUI/Plater.cpp | 7 ++-- src/slic3r/GUI/SetBedTypeDialog.cpp | 26 ++++++------- src/slic3r/GUI/SetBedTypeDialog.hpp | 2 +- 9 files changed, 74 insertions(+), 53 deletions(-) rename resources/images/{plate_set_bedtype_warned.svg => plate_set_bedtype_changed.svg} (100%) create mode 100644 resources/images/plate_set_bedtype_changed_hover.svg diff --git a/resources/images/plate_set_bedtype.svg b/resources/images/plate_set_bedtype.svg index b4b616d56..f4735d007 100644 --- a/resources/images/plate_set_bedtype.svg +++ b/resources/images/plate_set_bedtype.svg @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + diff --git a/resources/images/plate_set_bedtype_warned.svg b/resources/images/plate_set_bedtype_changed.svg similarity index 100% rename from resources/images/plate_set_bedtype_warned.svg rename to resources/images/plate_set_bedtype_changed.svg diff --git a/resources/images/plate_set_bedtype_changed_hover.svg b/resources/images/plate_set_bedtype_changed_hover.svg new file mode 100644 index 000000000..303b4fbbe --- /dev/null +++ b/resources/images/plate_set_bedtype_changed_hover.svg @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/resources/images/plate_set_bedtype_hover.svg b/resources/images/plate_set_bedtype_hover.svg index cc95c312f..db07509cd 100644 --- a/resources/images/plate_set_bedtype_hover.svg +++ b/resources/images/plate_set_bedtype_hover.svg @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 766c07ebc..21d51861e 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -149,6 +149,7 @@ BedType PartPlate::get_bed_type() const void PartPlate::set_bed_type(BedType bed_type, bool& same_as_global) { + is_same_bedtype_with_global = true; // should be called in GUI context assert(m_plater != nullptr); @@ -162,11 +163,13 @@ void PartPlate::set_bed_type(BedType bed_type, bool& same_as_global) std::string bed_type_key = "curr_bed_type"; BedType global_bed_type = proj_cfg.opt_enum(bed_type_key); same_as_global = bed_type == global_bed_type; + is_same_bedtype_with_global = same_as_global; return; } } same_as_global = false; + is_same_bedtype_with_global = same_as_global; } void PartPlate::reset_bed_type() @@ -708,13 +711,17 @@ void PartPlate::render_icons(bool bottom, int hover_id) const } if (m_partplate_list->render_bedtype_setting) { - if (hover_id == 5) - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_hovered_texture, m_bedtype_vbo_id); - else { - if (render_bedtype_setting_warned) - render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_warned_texture, m_bedtype_vbo_id); + if (hover_id == 5) { + if (is_same_bedtype_with_global) + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_hovered_texture, m_bedtype_vbo_id); else + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_hovered_texture, m_bedtype_vbo_id); + } + else { + if (is_same_bedtype_with_global) render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_texture, m_bedtype_vbo_id); + else + render_icon_texture(position_id, tex_coords_id, m_bedtype_icon, m_partplate_list->m_bedtype_changed_texture, m_bedtype_vbo_id); } } @@ -2024,11 +2031,6 @@ void PartPlate::render(bool bottom, bool only_body, bool force_background_color, glsafe(::glDisable(GL_DEPTH_TEST)); } -void PartPlate::set_plate_render_option(bool bedtype_setting_warned) -{ - render_bedtype_setting_warned = bedtype_setting_warned; -} - void PartPlate::set_selected() { m_selected = true; } @@ -2437,10 +2439,10 @@ void PartPlateList::generate_icon_textures() } } - if (m_bedtype_warned_texture.get_id() == 0) + if (m_bedtype_changed_texture.get_id() == 0) { - file_name = path + "plate_set_bedtype_warned.svg"; - if (!m_bedtype_warned_texture.load_from_svg_file(file_name, true, false, false, max_tex_size / 8)) { + file_name = path + "plate_set_bedtype_changed.svg"; + if (!m_bedtype_changed_texture.load_from_svg_file(file_name, true, false, false, max_tex_size / 8)) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(":load file %1% failed") % file_name; } } @@ -2453,6 +2455,14 @@ void PartPlateList::generate_icon_textures() } } + if (m_bedtype_changed_hovered_texture.get_id() == 0) + { + file_name = path + "plate_set_bedtype_changed_hover.svg"; + if (!m_bedtype_changed_hovered_texture.load_from_svg_file(file_name, true, false, false, max_tex_size / 8)) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(":load file %1% failed") % file_name; + } + } + auto is_font_suitable = [](std::string text_str, wxFont& font, int max_size) { wxMemoryDC memDC; wxCoord w, h; @@ -2510,8 +2520,9 @@ void PartPlateList::release_icon_textures() m_lockopen_texture.reset(); m_lockopen_hovered_texture.reset(); m_bedtype_texture.reset(); - m_bedtype_warned_texture.reset(); + m_bedtype_changed_texture.reset(); m_bedtype_hovered_texture.reset(); + m_bedtype_changed_hovered_texture.reset(); for (int i = 0;i < MAX_PLATE_COUNT; i++) { m_idx_textures[i].reset(); diff --git a/src/slic3r/GUI/PartPlate.hpp b/src/slic3r/GUI/PartPlate.hpp index ba161ec99..bf5174baf 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -139,7 +139,7 @@ private: GLTexture m_texture; // plate render option - bool render_bedtype_setting_warned = false; + bool is_same_bedtype_with_global = true; mutable float m_grabber_color[4]; float m_scale_factor{ 1.0f }; @@ -210,7 +210,6 @@ public: void clear(bool clear_sliced_result = true); BedType get_bed_type() const; - bool is_bedtype_same_as_global = true; void set_bed_type(BedType, bool& same_as_global); void reset_bed_type(); DynamicPrintConfig* config() { return &m_config; } @@ -304,7 +303,6 @@ public: void render(bool bottom, bool only_body = false, bool force_background_color = false, HeightLimitMode mode = HEIGHT_LIMIT_NONE, int hover_id = -1); void render_for_picking() const { on_render_for_picking(); } - void set_plate_render_option(bool bedtype_setting_warned); void set_selected(); void set_unselected(); void set_hover_id(int id) { m_hover_id = id; } @@ -461,8 +459,9 @@ class PartPlateList : public ObjectBase GLTexture m_lockopen_texture; GLTexture m_lockopen_hovered_texture; GLTexture m_bedtype_texture; - GLTexture m_bedtype_warned_texture; + GLTexture m_bedtype_changed_texture; GLTexture m_bedtype_hovered_texture; + GLTexture m_bedtype_changed_hovered_texture; GLTexture m_idx_textures[MAX_PLATE_COUNT]; // set render option bool render_bedtype_logo = true; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index e20d5282c..77c3fcdfb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5222,7 +5222,9 @@ void Plater::priv::on_select_bed_type(wxCommandEvent &evt) // update render auto plate_list = partplate_list.get_plate_list(); for (auto plate : plate_list) { - plate->set_plate_render_option(false); + bool same_as_global = false; + auto type = plate->get_bed_type(); + plate->set_bed_type(type, same_as_global); } view3D->get_canvas3d()->render(); preview->msw_rescale(); @@ -10607,13 +10609,12 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click) //set the plate type ret = select_plate(plate_index); if (!ret) { - SetBedTypeDialog dlg(this, wxID_ANY, _L("Select bed type")); + SetBedTypeDialog dlg(this, wxID_ANY, _L("Select Bed Type")); dlg.sync_bed_type(p->partplate_list.get_curr_plate()->get_bed_type()); dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index](wxCommandEvent& e) { bool same_as_global = false; auto type = (BedType)(e.GetInt()); p->partplate_list.get_curr_plate()->set_bed_type(type, same_as_global); - p->partplate_list.get_curr_plate()->set_plate_render_option(same_as_global?false:true); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select bed type %1% for plate %2% at plate side")%type %plate_index; }); dlg.ShowModal(); diff --git a/src/slic3r/GUI/SetBedTypeDialog.cpp b/src/slic3r/GUI/SetBedTypeDialog.cpp index da90220b4..76c9ce735 100644 --- a/src/slic3r/GUI/SetBedTypeDialog.cpp +++ b/src/slic3r/GUI/SetBedTypeDialog.cpp @@ -101,40 +101,40 @@ wxWindow* SetBedTypeDialog::create_item_radiobox(wxString title, wxWindow* paren RadioBox *radiobox = new RadioBox(item); radiobox->SetPosition(wxPoint(padding_left, (item->GetSize().GetHeight() - radiobox->GetSize().GetHeight()) / 2)); - radiobox->Bind(wxEVT_LEFT_DOWN, &SetBedTypeDialog::select_curr_radiobox, this); radio_buttons.push_back(radiobox); + int btn_idx = radio_buttons.size() - 1; + radiobox->Bind(wxEVT_LEFT_DOWN, [this, btn_idx](wxMouseEvent &e) { + SetBedTypeDialog::select_curr_radiobox(btn_idx); + }); wxStaticText *text = new wxStaticText(item, wxID_ANY, title, wxDefaultPosition, wxDefaultSize); text->SetPosition(wxPoint(padding_left + radiobox->GetSize().GetWidth() + 10, (item->GetSize().GetHeight() - text->GetSize().GetHeight()) / 2)); text->SetFont(Label::Body_14); text->SetForegroundColour(0x686868); + text->Bind(wxEVT_LEFT_DOWN, [this, btn_idx](wxMouseEvent &e) { + SetBedTypeDialog::select_curr_radiobox(btn_idx); + }); radiobox->SetToolTip(tooltip); text->SetToolTip(tooltip); return item; } -void SetBedTypeDialog::select_curr_radiobox(wxMouseEvent &e) +void SetBedTypeDialog::select_curr_radiobox(int btn_idx) { int len = radio_buttons.size(); - for (auto rbtn:radio_buttons) { - if (rbtn->GetId() == e.GetId()) - rbtn->SetValue(true); + for (int i = 0; i < len; ++i) { + if (i == btn_idx) + radio_buttons[i]->SetValue(true); else - rbtn->SetValue(false); + radio_buttons[i]->SetValue(false); } } void SetBedTypeDialog::sync_bed_type(BedType type) { int select_type = (int)(type); - int len = radio_buttons.size(); - for (int i = 0; i < len; ++i) { - if (i == select_type) - radio_buttons[i]->SetValue(true); - else - radio_buttons[i]->SetValue(false); - } + select_curr_radiobox(select_type); } void SetBedTypeDialog::on_dpi_changed(const wxRect& suggested_rect) diff --git a/src/slic3r/GUI/SetBedTypeDialog.hpp b/src/slic3r/GUI/SetBedTypeDialog.hpp index f877431e4..1fc9f6029 100644 --- a/src/slic3r/GUI/SetBedTypeDialog.hpp +++ b/src/slic3r/GUI/SetBedTypeDialog.hpp @@ -41,7 +41,7 @@ protected: std::vector radio_buttons; wxWindow * create_item_radiobox(wxString title, wxWindow *parent, wxString tooltip, int padding_left, int groupid, std::string param); - void select_curr_radiobox(wxMouseEvent &e); + void select_curr_radiobox(int btn_idx); }; }} // namespace Slic3r::GUI