From 2d3427fc4b11a3a00a4a7a194bd3ca0ec58912e8 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Sat, 20 Jan 2024 23:13:39 +0800 Subject: [PATCH] Add plate name edit btn --- src/slic3r/GUI/PartPlate.cpp | 71 +++++++++++++++++++++++++++++++++++- src/slic3r/GUI/PartPlate.hpp | 2 + 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index b2e393f5282..6b0d8c64060 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -51,6 +51,7 @@ static unsigned int GLOBAL_PLATE_INDEX = 0; static const double LOGICAL_PART_PLATE_GAP = 1. / 5.; static const int PARTPLATE_ICON_SIZE = 16; +static const int PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE = 12; static const int PARTPLATE_ICON_GAP_TOP = 3; static const int PARTPLATE_ICON_GAP_LEFT = 3; static const int PARTPLATE_ICON_GAP_Y = 5; @@ -571,6 +572,42 @@ void PartPlate::calc_vertex_for_number(int index, bool one_number, GLModel &buff BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; } +void PartPlate::calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, PickingModel &model) { + model.reset(); + + 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; + h = PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE; + p += Vec2d(0, PARTPLATE_TEXT_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 + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1) - h)}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + w), scale_(p(1) )}); + + if (!init_model_from_poly(model.model, poly, 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 + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1) - h)}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x + PARTPLATE_EDIT_PLATE_NAME_ICON_SIZE), scale_(p(1))}); + poly.contour.append({scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) )}); + + if (!init_model_from_poly(model.model, poly, GROUND_Z)) + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + } + + init_raycaster_from_model(model); +} + void PartPlate::calc_vertex_for_icons(int index, PickingModel &model) { model.reset(); @@ -975,6 +1012,13 @@ void PartPlate::render_icons(bool bottom, bool only_name, int hover_id) render_icon_texture(m_lock_icon.model, m_partplate_list->m_lockopen_texture); } + if (hover_id == 6) { + render_icon_texture(m_plate_name_edit_icon.model, m_partplate_list->m_plate_name_edit_hovered_texture); + show_tooltip(_u8L("Edit current plate name")); + } + else + render_icon_texture(m_plate_name_edit_icon.model, m_partplate_list->m_plate_name_edit_texture); + if (m_partplate_list->render_plate_settings) { if (hover_id == 5) { if (get_bed_type() == BedType::btDefault && get_print_seq() == PrintSequence::ByDefault && get_first_layer_print_sequence().empty()) @@ -1272,6 +1316,9 @@ void PartPlate::register_raycasters_for_picking(GLCanvas3D &canvas) register_model_for_picking(canvas, m_lock_icon, picking_id_component(4)); if (m_partplate_list->render_plate_settings) register_model_for_picking(canvas, m_plate_settings_icon, picking_id_component(5)); + + canvas.remove_raycasters_for_picking(SceneRaycaster::EType::Bed, picking_id_component(6)); + register_model_for_picking(canvas, m_plate_name_edit_icon, picking_id_component(6)); } int PartPlate::picking_id_component(int idx) const @@ -1781,7 +1828,12 @@ void PartPlate::generate_plate_name_texture() poly.contour.append({ scale_(p(0) + PARTPLATE_ICON_GAP_LEFT + offset_x), scale_(p(1) - PARTPLATE_TEXT_OFFSET_Y) }); if (!init_model_from_poly(m_plate_name_icon, poly, GROUND_Z)) - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "Unable to generate geometry buffers for icons\n"; + + auto canvas = this->m_partplate_list->m_plater->get_view3D_canvas3D(); + canvas->remove_raycasters_for_picking(SceneRaycaster::EType::Bed, picking_id_component(6)); + calc_vertex_for_plate_name_edit_icon(&m_name_texture, 0, m_plate_name_edit_icon); + register_model_for_picking(*canvas, m_plate_name_edit_icon, picking_id_component(6)); } void PartPlate::set_plate_name(const std::string& name) { @@ -3124,6 +3176,20 @@ 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; + } + } std::string text_str = "01"; wxFont* font = find_font(text_str,32); @@ -3161,7 +3227,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 4bf62680fe9..b6c5d430ff7 100644 --- a/src/slic3r/GUI/PartPlate.hpp +++ b/src/slic3r/GUI/PartPlate.hpp @@ -138,6 +138,7 @@ class PartPlate : public ObjectBase PickingModel m_orient_icon; PickingModel m_lock_icon; PickingModel m_plate_settings_icon; + PickingModel m_plate_name_edit_icon; GLModel m_plate_idx_icon; GLTexture m_texture; @@ -169,6 +170,7 @@ class PartPlate : public ObjectBase void calc_gridlines(const ExPolygon& poly, const BoundingBox& pp_bbox); void calc_height_limit(); void calc_vertex_for_number(int index, bool one_number, GLModel &buffer); + void calc_vertex_for_plate_name_edit_icon(GLTexture *texture, int index, PickingModel &model); void calc_vertex_for_icons(int index, PickingModel &model); // void calc_vertex_for_icons_background(int icon_count, GLModel &buffer); void render_background(bool force_default_color = false);