ENH:add "reset real zeros" button in rotate gizmo

jira: STUDIO-8291
Change-Id: Ia10e4d8a2a3a073c22a1306aeab9ffa3e7b77c2b
This commit is contained in:
zhou.xu 2024-09-27 10:39:59 +08:00 committed by Lane.Wei
parent 2f716f4b40
commit 738e3f004d
6 changed files with 76 additions and 14 deletions

View File

@ -0,0 +1,5 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.6457 7C10.5448 7 10.4602 6.9247 10.4433 6.82524C10.1226 4.93741 8.47917 3.5 6.5 3.5C4.29086 3.5 2.5 5.29086 2.5 7.5C2.5 9.47929 3.93759 11.1228 5.82559 11.4434C5.92506 11.4603 6.00037 11.5448 6.00037 11.6457V12.7588C6.00037 12.8763 5.89925 12.9688 5.7827 12.9536C3.08405 12.6022 1 10.2945 1 7.5C1 4.46243 3.46243 2 6.5 2C9.29433 2 11.6019 4.08386 11.9536 6.78232C11.9688 6.89888 11.8763 7 11.7587 7H10.6457Z" fill="#FF6F00"/>
<path d="M11.1649 9.76271C11.0854 9.87751 10.9156 9.87751 10.8361 9.76271L8.61993 6.5639C8.52803 6.43126 8.62296 6.25 8.78433 6.25H13.2167C13.3781 6.25 13.473 6.43126 13.3811 6.5639L11.1649 9.76271Z" fill="#FF6F00"/>
<path d="M8.38678 7.61146C8.38678 8.48963 8.22064 9.15893 7.88836 9.61938C7.56082 10.0798 7.09326 10.31 6.48566 10.31C5.87807 10.31 5.40576 10.0822 5.06873 9.6265C4.73645 9.16605 4.57031 8.49438 4.57031 7.61146C4.57031 6.72855 4.73645 6.05687 5.06873 5.59643C5.40576 5.13598 5.87807 4.90576 6.48566 4.90576C7.09326 4.90576 7.56082 5.13598 7.88836 5.59643C8.22064 6.05687 8.38678 6.72855 8.38678 7.61146ZM5.85908 7.61146C5.85908 8.14786 5.90892 8.54659 6.00861 8.80767C6.11304 9.06874 6.27206 9.19928 6.48566 9.19928C6.69453 9.19928 6.8488 9.06874 6.94848 8.80767C7.04817 8.54184 7.09801 8.14311 7.09801 7.61146C7.09801 7.07982 7.04817 6.68346 6.94848 6.42238C6.8488 6.15656 6.69453 6.02364 6.48566 6.02364C6.27206 6.02364 6.11304 6.15181 6.00861 6.40814C5.90892 6.66447 5.85908 7.06558 5.85908 7.61146Z" fill="#FF6F00"/>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,4 @@
<svg width="14" height="15" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.2937 5.6687C9.71589 3.84914 8.01293 2.53076 6.00204 2.53076C3.51563 2.53076 1.5 4.54639 1.5 7.0328C1.5 9.27369 3.13722 11.1322 5.28073 11.4774C5.38062 11.4935 5.4564 11.5783 5.4564 11.6794V12.7916C5.4564 12.9091 5.35522 13.0016 5.23861 12.9868C2.28425 12.6118 0 10.0891 0 7.0328C0 3.71797 2.68721 1.03076 6.00204 1.03076C8.84765 1.03076 11.2307 3.01105 11.8484 5.6687H13.3662C13.5275 5.6687 13.6225 5.84996 13.5306 5.9826L11.0772 9.52371C10.9977 9.63851 10.8279 9.63851 10.7484 9.52371L8.29505 5.9826C8.20315 5.84996 8.29808 5.6687 8.45945 5.6687H10.2937Z" fill="#FF6F00"/>
<path d="M7.99414 7.03451C7.99414 7.96884 7.81738 8.68095 7.46384 9.17084C7.11537 9.66073 6.6179 9.90568 5.97144 9.90568C5.32499 9.90568 4.82247 9.66326 4.46389 9.17842C4.11036 8.68852 3.93359 7.97389 3.93359 7.03451C3.93359 6.09513 4.11036 5.38049 4.46389 4.8906C4.82247 4.40071 5.32499 4.15576 5.97144 4.15576C6.6179 4.15576 7.11537 4.40071 7.46384 4.8906C7.81738 5.38049 7.99414 6.09513 7.99414 7.03451ZM5.30479 7.03451C5.30479 7.60521 5.35782 8.02944 5.46387 8.30722C5.57498 8.58499 5.74417 8.72388 5.97144 8.72388C6.19366 8.72388 6.3578 8.58499 6.46386 8.30722C6.56992 8.02439 6.62295 7.60016 6.62295 7.03451C6.62295 6.46886 6.56992 6.04715 6.46386 5.76937C6.3578 5.48655 6.19366 5.34514 5.97144 5.34514C5.74417 5.34514 5.57498 5.4815 5.46387 5.75422C5.35782 6.02695 5.30479 6.45371 5.30479 7.03451Z" fill="#FF6F00"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -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

View File

@ -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,

View File

@ -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<GLVolume *>(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<GLVolume *>(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<GLVolume *>(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()));

View File

@ -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;