From e55aa34da00d739edacf8c37c4ef713ad43db383 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 29 Jun 2023 16:26:43 +0800 Subject: [PATCH] NEW: add plate name edit function Change-Id: Ic2aacd8617856efd2f528bddab74e5881df28e01 (cherry picked from commit b0bd89928ed974aa77a0b2f4138c53899ae8ba93) --- resources/images/plate_name_edit.svg | 3 + resources/images/plate_name_edit_dark.svg | 3 + resources/images/plate_name_edit_hover.svg | 4 + .../images/plate_name_edit_hover_dark.svg | 4 + src/slic3r/GUI/GLTexture.hpp | 1 + src/slic3r/GUI/GUI_Factories.cpp | 2 +- src/slic3r/GUI/PartPlate.cpp | 95 ++++++++++++++-- src/slic3r/GUI/PartPlate.hpp | 8 +- src/slic3r/GUI/PlateSettingsDialog.cpp | 103 ++++++++++++++++-- src/slic3r/GUI/PlateSettingsDialog.hpp | 26 ++++- src/slic3r/GUI/Plater.cpp | 26 ++++- 11 files changed, 247 insertions(+), 28 deletions(-) create mode 100644 resources/images/plate_name_edit.svg create mode 100644 resources/images/plate_name_edit_dark.svg create mode 100644 resources/images/plate_name_edit_hover.svg create mode 100644 resources/images/plate_name_edit_hover_dark.svg diff --git a/resources/images/plate_name_edit.svg b/resources/images/plate_name_edit.svg new file mode 100644 index 000000000..c9266a127 --- /dev/null +++ b/resources/images/plate_name_edit.svg @@ -0,0 +1,3 @@ + + + diff --git a/resources/images/plate_name_edit_dark.svg b/resources/images/plate_name_edit_dark.svg new file mode 100644 index 000000000..c9266a127 --- /dev/null +++ b/resources/images/plate_name_edit_dark.svg @@ -0,0 +1,3 @@ + + + diff --git a/resources/images/plate_name_edit_hover.svg b/resources/images/plate_name_edit_hover.svg new file mode 100644 index 000000000..9359cd74b --- /dev/null +++ b/resources/images/plate_name_edit_hover.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/plate_name_edit_hover_dark.svg b/resources/images/plate_name_edit_hover_dark.svg new file mode 100644 index 000000000..a9840d5ca --- /dev/null +++ b/resources/images/plate_name_edit_hover_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/slic3r/GUI/GLTexture.hpp b/src/slic3r/GUI/GLTexture.hpp index 53fbe1a6a..d898a10bd 100644 --- a/src/slic3r/GUI/GLTexture.hpp +++ b/src/slic3r/GUI/GLTexture.hpp @@ -112,6 +112,7 @@ namespace GUI { bool generate_from_text_string(const std::string& text_str, wxFont& font, wxColor background = *wxBLACK, wxColor foreground = *wxWHITE); unsigned int get_id() const { return m_id; } + int get_original_width() const { return m_original_width; } int get_width() const { return m_width; } int get_height() const { return m_height; } diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index b82d0c704..d545bf0d0 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -1657,7 +1657,7 @@ void MenuFactory::append_menu_item_fill_bed(wxMenu *menu) } void MenuFactory::append_menu_item_plate_name(wxMenu *menu) { - wxString name= _L("Edit plate settings"); + wxString name= _L("Edit Plate Name"); // Delete old menu item const int item_id = menu->FindItem(name); if (item_id != wxNOT_FOUND) menu->Destroy(item_id); diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 9fec20eba..eb8def534 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -55,6 +55,7 @@ static const int PARTPLATE_ICON_GAP_Y = 5; static const int PARTPLATE_TEXT_OFFSET_X1 = 3; static const int PARTPLATE_TEXT_OFFSET_X2 = 1; static const int PARTPLATE_TEXT_OFFSET_Y = 1; +static const int PARTPLATE_PLATENAME_OFFSET_Y = 10; std::array PlateTextureForeground = {0x0, 0xae, 0x42, 0xff}; namespace Slic3r { @@ -423,11 +424,11 @@ void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &b float offset_x = 1; w = int(factor * (texture.get_width() * 16) / texture.get_height()); h = int(factor * 16); - Vec2d p = bed_ext[3] + Vec2d(0, 1 + h * texture.m_original_height / texture.get_height()); - poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) - h + PARTPLATE_TEXT_OFFSET_Y)}); - poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w - offset_x), scale_(p(1) - h + PARTPLATE_TEXT_OFFSET_Y)}); - poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w - offset_x), scale_(p(1) - PARTPLATE_TEXT_OFFSET_Y)}); - poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) - PARTPLATE_TEXT_OFFSET_Y)}); + Vec2d p = bed_ext[3] + Vec2d(0, PARTPLATE_PLATENAME_OFFSET_Y + h * texture.m_original_height / texture.get_height()); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w - offset_x), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w - offset_x), scale_(p(1) )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )}); auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); if (!buffer.set_from_triangles(triangles, GROUND_Z)) BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; @@ -439,6 +440,46 @@ void PartPlate::calc_vertex_for_plate_name(GLTexture &texture, GeometryBuffer &b } } +void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer) { + auto bed_ext = get_extents(m_shape); + auto factor = bed_ext.size()(1) / 200.0; + wxCoord w, h; + h = int(factor * 16); + ExPolygon poly; + Vec2d p = bed_ext[3]; + float offset_x = 1; + const int plate_name_edit_icon_height = 12; + const int plate_name_edit_icon_width = 12; + h = plate_name_edit_icon_height; + p += Vec2d(0, PARTPLATE_PLATENAME_OFFSET_Y + h); + if (texture && texture->get_width() > 0 && texture->get_height()) { + w = int(factor * (texture->get_original_width() * 16) / texture->get_height()) + 1; + + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + plate_name_edit_icon_width), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + plate_name_edit_icon_width), scale_(p(1) )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) )}); + + auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); + if (!buffer.set_from_triangles(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + } else { + + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x ), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x+ plate_name_edit_icon_width), scale_(p(1) - h )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x+ plate_name_edit_icon_width), scale_(p(1) )}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )}); + + auto triangles = triangulate_expolygon_2f(poly, NORMALS_UP); + if (!buffer.set_from_triangles(triangles, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + } + if (m_plate_name_edit_vbo_id > 0) { + glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id)); + m_plate_name_edit_vbo_id = 0; + } +} + void PartPlate::calc_vertex_for_icons(int index, GeometryBuffer &buffer) { ExPolygon poly; @@ -795,12 +836,18 @@ void PartPlate::render_icon_texture(int position_id, int tex_coords_id, const Ge void PartPlate::render_plate_name_texture(int position_id, int tex_coords_id) { if (m_name.length() == 0) { + if (m_name_change) { + m_name_change = false; + calc_vertex_for_plate_name_edit_icon(nullptr, 0, m_plate_name_edit_icon); + } return; } if (m_name_texture.get_id() == 0 || m_name_change) { m_name_change = false; generate_plate_name_texture(); calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon); + + calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon); } if (m_plate_name_vbo_id == 0 && m_plate_name_icon.get_vertices_data_size() > 0) { @@ -871,7 +918,12 @@ void PartPlate::render_icons(bool bottom, bool only_body, int hover_id) render_icon_texture(position_id, tex_coords_id, m_lock_icon, m_partplate_list->m_lockopen_texture, m_lock_vbo_id); } - if (m_partplate_list->render_plate_settings) { + if (hover_id == 6) + render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_hovered_texture, m_plate_name_edit_vbo_id); + else + render_icon_texture(position_id, tex_coords_id, m_plate_name_edit_icon, m_partplate_list->m_plate_name_edit_texture, m_plate_name_edit_vbo_id); + + if (m_partplate_list->render_plate_settings) { if (hover_id == 5) { if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault) render_icon_texture(position_id, tex_coords_id, m_plate_settings_icon, m_partplate_list->m_plate_settings_hovered_texture, m_plate_settings_vbo_id); @@ -1223,6 +1275,14 @@ void PartPlate::on_render_for_picking() const { m_grabber_color[3] = color[3]; if (m_partplate_list->render_plate_settings) render_rectangle_for_picking(m_plate_settings_icon, m_grabber_color); + hover_id = 6; + color = picking_color_component(hover_id); + m_grabber_color[0] = color[0]; + m_grabber_color[1] = color[1]; + m_grabber_color[2] = color[2]; + m_grabber_color[3] = color[3]; + // render_left_arrow(m_grabber_color, false); + render_rectangle_for_picking(m_plate_name_edit_icon, m_grabber_color); } std::array PartPlate::picking_color_component(int idx) const @@ -1271,6 +1331,10 @@ void PartPlate::release_opengl_resource() glsafe(::glDeleteBuffers(1, &m_plate_name_vbo_id)); m_plate_name_vbo_id = 0; } + if (m_plate_name_edit_vbo_id > 0) { + glsafe(::glDeleteBuffers(1, &m_plate_name_edit_vbo_id)); + m_plate_name_edit_vbo_id = 0; + } } std::vector PartPlate::get_extruders(bool conside_custom_gcode) const @@ -2273,6 +2337,7 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve //calc_vertex_for_number(0, (m_plate_index < 9), m_plate_idx_icon); calc_vertex_for_number(0, false, m_plate_idx_icon); calc_vertex_for_plate_name(m_name_texture, m_plate_name_icon);//if (generate_plate_name_texture()) + calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon); } calc_height_limit(); @@ -2819,6 +2884,21 @@ void PartPlateList::generate_icon_textures() } } + // if (m_plate_name_edit_texture.get_id() == 0) + { + file_name = path + (m_is_dark ? "plate_name_edit_dark.svg" : "plate_name_edit.svg"); + if (!m_plate_name_edit_texture.load_from_svg_file(file_name, true, false, false, icon_size)) { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(":load file %1% failed") % file_name; + } + } + // if (m_plate_name_edit_hovered_texture.get_id() == 0) + { + file_name = path + (m_is_dark ? "plate_name_edit_hover_dark.svg" : "plate_name_edit_hover.svg"); + if (!m_plate_name_edit_hovered_texture.load_from_svg_file(file_name, true, false, false, icon_size)) { + 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; @@ -2878,7 +2958,8 @@ void PartPlateList::release_icon_textures() m_plate_settings_texture.reset(); m_plate_settings_texture.reset(); m_plate_settings_hovered_texture.reset(); - + m_plate_name_edit_texture.reset(); + m_plate_name_edit_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 9ef3b41f8..1d095eb52 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -125,6 +125,7 @@ private: GeometryBuffer m_height_limit_bottom; GeometryBuffer m_height_limit_top; GeometryBuffer m_del_icon; + GeometryBuffer m_plate_name_edit_icon; //GeometryBuffer m_del_and_background_icon; mutable unsigned int m_del_vbo_id{ 0 }; GeometryBuffer m_arrange_icon; @@ -137,6 +138,7 @@ private: mutable unsigned int m_plate_settings_vbo_id{ 0 }; GeometryBuffer m_plate_idx_icon; mutable unsigned int m_plate_idx_vbo_id{ 0 }; + mutable unsigned int m_plate_name_edit_vbo_id{0}; GLTexture m_texture; mutable float m_grabber_color[4]; @@ -167,6 +169,7 @@ private: void calc_height_limit(); void calc_vertex_for_number(int index, bool one_number, GeometryBuffer &buffer); void calc_vertex_for_plate_name(GLTexture& texture, GeometryBuffer &buffer); + void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, GeometryBuffer &buffer); void calc_vertex_for_icons(int index, GeometryBuffer &buffer); void calc_vertex_for_icons_background(int icon_count, GeometryBuffer &buffer); void render_background(bool force_default_color = false) const; @@ -193,7 +196,8 @@ private: public: static const unsigned int PLATE_BASE_ID = 255 * 255 * 253; - static const unsigned int GRABBER_COUNT = 6; + static const unsigned int PLATE_NAME_HOVER_ID = 6; + static const unsigned int GRABBER_COUNT = 7; static std::array SELECT_COLOR; static std::array UNSELECT_COLOR; @@ -518,6 +522,8 @@ class PartPlateList : public ObjectBase GLTexture m_plate_settings_changed_texture; GLTexture m_plate_settings_hovered_texture; GLTexture m_plate_settings_changed_hovered_texture; + GLTexture m_plate_name_edit_texture; + GLTexture m_plate_name_edit_hovered_texture; GLTexture m_idx_textures[MAX_PLATE_COUNT]; // set render option bool render_bedtype_logo = true; diff --git a/src/slic3r/GUI/PlateSettingsDialog.cpp b/src/slic3r/GUI/PlateSettingsDialog.cpp index 6b3ef0c83..09f304f4c 100644 --- a/src/slic3r/GUI/PlateSettingsDialog.cpp +++ b/src/slic3r/GUI/PlateSettingsDialog.cpp @@ -43,13 +43,6 @@ PlateSettingsDialog::PlateSettingsDialog(wxWindow* parent, wxWindowID id, const top_sizer->Add(m_print_seq_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT |wxALL, FromDIP(5)); top_sizer->Add(m_print_seq_choice, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT |wxALL, FromDIP(5)); - auto plate_name_txt = new wxStaticText(this, wxID_ANY, _L("Plate name")); - plate_name_txt->SetFont(Label::Body_14); - m_ti_plate_name = new TextInput(this, wxString::FromDouble(0.0), "", "", wxDefaultPosition, wxSize(FromDIP(240), -1), wxTE_PROCESS_ENTER); - top_sizer->Add(plate_name_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); - top_sizer->Add(m_ti_plate_name, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, FromDIP(5)); - m_ti_plate_name->GetTextCtrl()->SetMaxLength(40); - m_sizer_main->Add(top_sizer, 0, wxEXPAND | wxALL, FromDIP(30)); auto sizer_button = new wxBoxSizer(wxHORIZONTAL); @@ -156,11 +149,101 @@ void PlateSettingsDialog::on_dpi_changed(const wxRect& suggested_rect) m_button_cancel->Rescale(); } -wxString PlateSettingsDialog::get_plate_name() const { return m_ti_plate_name->GetTextCtrl()->GetValue(); + +//PlateNameEditDialog +PlateNameEditDialog::PlateNameEditDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) + : DPIDialog(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)); + + SetBackgroundColour(*wxWHITE); + wxBoxSizer *m_sizer_main = new wxBoxSizer(wxVERTICAL); + auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(400), -1)); + m_line_top->SetBackgroundColour(wxColour(166, 169, 170)); + m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0); + m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); + + wxFlexGridSizer *top_sizer = new wxFlexGridSizer(0, 2, FromDIP(5), 0); + top_sizer->AddGrowableCol(0, 1); + top_sizer->SetFlexibleDirection(wxBOTH); + top_sizer->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED); + + auto plate_name_txt = new wxStaticText(this, wxID_ANY, _L("Plate name")); + plate_name_txt->SetFont(Label::Body_14); + m_ti_plate_name = new TextInput(this, wxString::FromDouble(0.0), "", "", wxDefaultPosition, wxSize(FromDIP(240), -1), wxTE_PROCESS_ENTER); + top_sizer->Add(plate_name_txt, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_LEFT | wxALL, FromDIP(5)); + top_sizer->Add(m_ti_plate_name, 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, FromDIP(5)); + m_ti_plate_name->GetTextCtrl()->SetMaxLength(40); + + m_sizer_main->Add(top_sizer, 0, wxEXPAND | wxALL, FromDIP(30)); + + auto sizer_button = new wxBoxSizer(wxHORIZONTAL); + 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_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), + std::pair(*wxWHITE, StateColor::Normal)); + + m_button_ok = new Button(this, _L("OK")); + m_button_ok->SetBackgroundColor(btn_bg_green); + m_button_ok->SetBorderColor(*wxWHITE); + m_button_ok->SetTextColor(wxColour("#FFFFFE")); + m_button_ok->SetFont(Label::Body_12); + m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_ok->SetCornerRadius(FromDIP(12)); + m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { + wxCommandEvent evt(EVT_SET_BED_TYPE_CONFIRM, GetId()); + e.SetEventObject(this); + GetEventHandler()->ProcessEvent(evt); + if (this->IsModal()) + EndModal(wxID_YES); + else + this->Close(); + }); + + m_button_cancel = new Button(this, _L("Cancel")); + m_button_cancel->SetBackgroundColor(btn_bg_white); + m_button_cancel->SetBorderColor(wxColour(38, 46, 48)); + m_button_cancel->SetFont(Label::Body_12); + m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24))); + m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24))); + 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(); + }); + + sizer_button->AddStretchSpacer(); + sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5)); + sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5)); + sizer_button->Add(FromDIP(30), 0, 0, 0); + + m_sizer_main->Add(sizer_button, 0, wxEXPAND, FromDIP(20)); + + SetSizer(m_sizer_main); + Layout(); + m_sizer_main->Fit(this); + + CenterOnParent(); + + wxGetApp().UpdateDlgDarkUI(this); } -void PlateSettingsDialog::set_plate_name(const wxString &name) { - m_ti_plate_name->GetTextCtrl()->SetValue(name); } +PlateNameEditDialog::~PlateNameEditDialog() {} +void PlateNameEditDialog::on_dpi_changed(const wxRect &suggested_rect) +{ + m_button_ok->Rescale(); + m_button_cancel->Rescale(); +} + + +wxString PlateNameEditDialog::get_plate_name() const { return m_ti_plate_name->GetTextCtrl()->GetValue(); } + +void PlateNameEditDialog::set_plate_name(const wxString &name) { m_ti_plate_name->GetTextCtrl()->SetValue(name); } }} // namespace Slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/PlateSettingsDialog.hpp b/src/slic3r/GUI/PlateSettingsDialog.hpp index 2ba0721d3..83310d7e6 100644 --- a/src/slic3r/GUI/PlateSettingsDialog.hpp +++ b/src/slic3r/GUI/PlateSettingsDialog.hpp @@ -49,17 +49,35 @@ public: return choice; }; - wxString get_plate_name() const; - void set_plate_name(const wxString &name); - protected: ComboBox* m_print_seq_choice { nullptr }; ComboBox* m_bed_type_choice { nullptr }; Button* m_button_ok; Button* m_button_cancel; - TextInput *m_ti_plate_name; }; +class PlateNameEditDialog : public DPIDialog +{ +public: + enum ButtonStyle { ONLY_CONFIRM = 0, CONFIRM_AND_CANCEL = 1, MAX_STYLE_NUM = 2 }; + PlateNameEditDialog(wxWindow * parent, + wxWindowID id = wxID_ANY, + const wxString &title = wxEmptyString, + const wxPoint & pos = wxDefaultPosition, + const wxSize & size = wxDefaultSize, + long style = wxCLOSE_BOX | wxCAPTION); + + ~PlateNameEditDialog(); + void on_dpi_changed(const wxRect &suggested_rect) override; + + wxString get_plate_name() const; + void set_plate_name(const wxString &name); + +protected: + Button * m_button_ok; + Button * m_button_cancel; + TextInput *m_ti_plate_name; +}; }} // namespace Slic3r::GUI #endif \ No newline at end of file diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c5fa1ad42..68a710984 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -11808,7 +11808,7 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi int action, plate_index; plate_index = hover_id / PartPlate::GRABBER_COUNT; - action = isModidyPlateName?5:hover_id % PartPlate::GRABBER_COUNT; + action = isModidyPlateName ? PartPlate::PLATE_NAME_HOVER_ID : hover_id % PartPlate::GRABBER_COUNT; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": enter, hover_id %1%, plate_index %2%, action %3%")%hover_id % plate_index %action; if (action == 0) @@ -11952,8 +11952,6 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi else dlg.sync_print_seq(0); - wxString curr_plate_name = from_u8(curr_plate->get_plate_name()); - dlg.set_plate_name(curr_plate_name); dlg.Bind(EVT_SET_BED_TYPE_CONFIRM, [this, plate_index, &dlg](wxCommandEvent& e) { PartPlate *curr_plate = p->partplate_list.get_curr_plate(); @@ -11980,12 +11978,30 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi }); dlg.ShowModal(); + this->schedule_background_process(); + } + else { + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; + ret = -1; + } + } + else if ((action == 6) && (!right_click)) { + // set the plate type + ret = select_plate(plate_index); + if (!ret) { + PlateNameEditDialog dlg(this, wxID_ANY, _L("Edit Plate Name")); + PartPlate * curr_plate = p->partplate_list.get_curr_plate(); + + wxString curr_plate_name = from_u8(curr_plate->get_plate_name()); + dlg.set_plate_name(curr_plate_name); + + dlg.ShowModal(); + wxString dlg_plate_name = dlg.get_plate_name(); curr_plate->set_plate_name(dlg_plate_name.ToUTF8().data()); this->schedule_background_process(); - } - else { + } else { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "can not select plate %1%" << plate_index; ret = -1; }