From 738e3f004daa9082709800e4e3d0d9bbe1b7ed7e Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Fri, 27 Sep 2024 10:39:59 +0800 Subject: [PATCH] ENH:add "reset real zeros" button in rotate gizmo jira: STUDIO-8291 Change-Id: Ia10e4d8a2a3a073c22a1306aeab9ffa3e7b77c2b --- resources/images/toolbar_reset_zero.svg | 5 ++ resources/images/toolbar_reset_zero_hover.svg | 4 ++ src/slic3r/GUI/Gizmos/GLGizmosManager.cpp | 10 +++ src/slic3r/GUI/Gizmos/GLGizmosManager.hpp | 2 + .../GUI/Gizmos/GizmoObjectManipulation.cpp | 65 +++++++++++++++---- .../GUI/Gizmos/GizmoObjectManipulation.hpp | 4 +- 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 resources/images/toolbar_reset_zero.svg create mode 100644 resources/images/toolbar_reset_zero_hover.svg diff --git a/resources/images/toolbar_reset_zero.svg b/resources/images/toolbar_reset_zero.svg new file mode 100644 index 000000000..35c7469ab --- /dev/null +++ b/resources/images/toolbar_reset_zero.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/resources/images/toolbar_reset_zero_hover.svg b/resources/images/toolbar_reset_zero_hover.svg new file mode 100644 index 000000000..b2b03a214 --- /dev/null +++ b/resources/images/toolbar_reset_zero_hover.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp index fb516fb61..6f5184c8f 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.cpp @@ -268,6 +268,16 @@ bool GLGizmosManager::init_icon_textures() else return false; + if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/toolbar_reset_zero.svg", 14, 14, texture_id)) + icon_list.insert(std::make_pair((int) IC_TOOLBAR_RESET_ZERO, texture_id)); + else + return false; + + if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/toolbar_reset_zero_hover.svg", 14, 14, texture_id)) + icon_list.insert(std::make_pair((int) IC_TOOLBAR_RESET_ZERO_HOVER, texture_id)); + else + return false; + if (IMTexture::load_from_svg_file(Slic3r::resources_dir() + "/images/toolbar_tooltip.svg", 30, 22, texture_id)) icon_list.insert(std::make_pair((int)IC_TOOLBAR_TOOLTIP, texture_id)); else diff --git a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp index f95b30f59..6df7ad3d5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosManager.hpp @@ -163,6 +163,8 @@ public: enum MENU_ICON_NAME { IC_TOOLBAR_RESET = 0, IC_TOOLBAR_RESET_HOVER, + IC_TOOLBAR_RESET_ZERO, + IC_TOOLBAR_RESET_ZERO_HOVER, IC_TOOLBAR_TOOLTIP, IC_TOOLBAR_TOOLTIP_HOVER, IC_TEXT_B, diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp index 64cb30c15..b20ff6e31 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.cpp @@ -263,6 +263,7 @@ void GizmoObjectManipulation::update_reset_buttons_visibility() min_z = get_volume_min_z(volume); } m_show_clear_rotation = !rotation.isApprox(m_init_rotation); + m_show_reset_0_rotation = !rotation.isApprox(Vec3d::Zero()); m_show_clear_scale = (m_cache.scale / 100.0f - Vec3d::Ones()).norm() > 0.001; m_show_drop_to_bed = (std::abs(min_z) > EPSILON); } @@ -500,28 +501,36 @@ void GizmoObjectManipulation::reset_position_value() UpdateAndShow(true); } -void GizmoObjectManipulation::reset_rotation_value() +void GizmoObjectManipulation::reset_rotation_value(bool reset_relative) { Selection &selection = m_glcanvas.get_selection(); selection.setup_cache(); if (selection.is_single_volume_or_modifier()) { - GLVolume * vol = const_cast(selection.get_first_volume()); - Geometry::Transformation trafo = vol->get_volume_transformation(); - auto offset = trafo.get_offset(); - trafo.set_from_transform(m_init_rotation_scale_tran); - trafo.set_offset(offset); + GLVolume * vol = const_cast(selection.get_first_volume()); + Geometry::Transformation trafo = vol->get_volume_transformation(); + if (reset_relative) { + auto offset = trafo.get_offset(); + trafo.set_from_transform(m_init_rotation_scale_tran); + trafo.set_offset(offset); + } + else { + trafo.reset_rotation(); + } vol->set_volume_transformation(trafo); } else if (selection.is_single_full_instance()) { - Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); - auto offset = trafo.get_offset(); - trafo.set_from_transform(m_init_rotation_scale_tran); - trafo.set_offset(offset); + Geometry::Transformation trafo = selection.get_first_volume()->get_instance_transformation(); + if (reset_relative) { + auto offset = trafo.get_offset(); + trafo.set_from_transform(m_init_rotation_scale_tran); + trafo.set_offset(offset); + } else { + trafo.reset_rotation(); + } for (unsigned int idx : selection.get_volume_idxs()) { const_cast(selection.get_volume(idx))->set_instance_transformation(trafo); } } else return; - // Synchronize instances/volumes. selection.synchronize_unselected_instances(Selection::SyncRotationType::RESET); @@ -596,6 +605,23 @@ bool GizmoObjectManipulation::reset_button(ImGuiWrapper *imgui_wrapper, float ca return pressed; } +bool GizmoObjectManipulation::reset_zero_button(ImGuiWrapper *imgui_wrapper, float caption_max, float unit_size, float space_size, float end_text_size) +{ + bool pressed = false; + ImTextureID normal_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_RESET_ZERO); + ImTextureID hover_id = m_glcanvas.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_RESET_ZERO_HOVER); + + float font_size = ImGui::GetFontSize() * 1.1; + ImVec2 button_size = ImVec2(font_size, font_size); + + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); + + pressed = ImGui::ImageButton3(normal_id, hover_id, button_size); + + ImGui::PopStyleVar(1); + return pressed; +} + float GizmoObjectManipulation::max_unit_size(int number, Vec3d &vec1, Vec3d &vec2,std::string str) { if (number <= 1) return -1; @@ -941,7 +967,14 @@ void GizmoObjectManipulation::do_render_rotate_window(ImGuiWrapper *imgui_wrappe ImGui::SameLine(caption_max + (++index_unit) * unit_size + (++index) * space_size); ImGui::PushItemWidth(unit_size); ImGui::TextAlignCenter("Z"); - + if (m_show_reset_0_rotation) { + ImGui::SameLine(caption_max + 3 * unit_size + 4 * space_size + end_text_size); + if (reset_zero_button(imgui_wrapper, caption_max, unit_size, space_size, end_text_size)) { reset_rotation_value(false); } + if (ImGui::IsItemHovered()) { + float tooltip_size = imgui_wrapper->calc_text_size(_L("Reset current rotation to real zeros.")).x + 3 * space_size; + imgui_wrapper->tooltip(_u8L("Reset current rotation to real zeros."), tooltip_size); + } + } index = 1; index_unit = 1; @@ -964,7 +997,13 @@ void GizmoObjectManipulation::do_render_rotate_window(ImGuiWrapper *imgui_wrappe if (m_show_clear_rotation) { ImGui::SameLine(caption_max + 3 * unit_size + 4 * space_size + end_text_size); - if (reset_button(imgui_wrapper, caption_max, unit_size, space_size, end_text_size)) { reset_rotation_value(); } + if (reset_button(imgui_wrapper, caption_max, unit_size, space_size, end_text_size)) { + reset_rotation_value(true); + } + if (ImGui::IsItemHovered()) { + float tooltip_size = imgui_wrapper->calc_text_size(_L("Reset current rotation to the value when open the rotation tool.")).x + 3 * space_size; + imgui_wrapper->tooltip(_u8L("Reset current rotation to the value when open the rotation tool."), tooltip_size); + } } else { ImGui::SameLine(caption_max + 3 * unit_size + 5 * space_size + end_text_size); ImGui::InvisibleButton("", ImVec2(ImGui::GetFontSize(), ImGui::GetFontSize())); diff --git a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp index 5249c1bf3..a0ed0a64b 100644 --- a/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp +++ b/src/slic3r/GUI/Gizmos/GizmoObjectManipulation.hpp @@ -85,6 +85,7 @@ public: // Does the object manipulation panel work in World or Local coordinates? ECoordinatesType m_coordinates_type{ECoordinatesType::World}; + bool m_show_reset_0_rotation{false}; bool m_show_clear_rotation { false }; bool m_show_clear_scale { false }; bool m_show_drop_to_bed { false }; @@ -128,6 +129,7 @@ public: void do_render_scale_input_window(ImGuiWrapper* imgui_wrapper, std::string window_name, float x, float y, float bottom_limit); float max_unit_size(int number, Vec3d &vec1, Vec3d &vec2,std::string str); bool reset_button(ImGuiWrapper *imgui_wrapper, float caption_max, float unit_size, float space_size, float end_text_size); + bool reset_zero_button(ImGuiWrapper *imgui_wrapper, float caption_max, float unit_size, float space_size, float end_text_size); bool bbl_checkbox(const wxString &label, bool &value); void show_move_tooltip_information(ImGuiWrapper *imgui_wrapper, float caption_max, float x, float y); @@ -152,7 +154,7 @@ private: void change_size_value(int axis, double value); void do_scale(int axis, const Vec3d &scale) const; void reset_position_value(); - void reset_rotation_value(); + void reset_rotation_value(bool reset_relative); void reset_scale_value(); GLCanvas3D& m_glcanvas;