From e65e27ee5715d1bace2127f94d62d2f9c2f36ccb Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Mon, 5 Dec 2022 18:21:15 +0800 Subject: [PATCH] ENH:add reset direction function Change-Id: I3d89a738434f92ee34e9713d734347e3ea542497 --- src/slic3r/GUI/GLCanvas3D.cpp | 14 ++++++++++++-- src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 17 ++++++++++++++--- src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp | 16 +++++++++++++--- src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp | 12 ++++++------ src/slic3r/GUI/ImGuiWrapper.cpp | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 14c2d6e39..2c26ab449 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -7440,11 +7440,21 @@ void GLCanvas3D::_render_assemble_control() const ImGui::AlignTextToFramePadding(); { - imgui->text(_L("Section View")); + if (m_gizmos.m_assemble_view_data->model_objects_clipper()->get_position() == 0.f) { + ImGui::AlignTextToFramePadding(); + imgui->text(_L("Section View")); + } + else { + if (imgui->button(_L("Reset direction"))) { + wxGetApp().CallAfter([this]() { + m_gizmos.m_assemble_view_data->model_objects_clipper()->set_position(-1., false); + }); + } + } ImGui::SameLine(window_padding.x + text_size_x + item_spacing); ImGui::PushItemWidth(slider_width); - static float clp_dist = 0.f; + auto clp_dist = float(m_gizmos.m_assemble_view_data->model_objects_clipper()->get_position()); bool view_slider_changed = imgui->bbl_slider_float_style("##clp_dist", &clp_dist, 0.f, 1.f, "%.2f", 1.0f, true); ImGui::SameLine(window_padding.x + text_size_x + slider_width + item_spacing * 2); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index e090ba9de..951669ff9 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -81,6 +81,7 @@ bool GLGizmoFdmSupports::on_init() m_desc["clipping_of_view_caption"] = _L("Alt + Mouse wheel"); m_desc["clipping_of_view"] = _L("Section view"); + m_desc["reset_direction"] = _L("Reset direction"); m_desc["cursor_size_caption"] = _L("Ctrl + Mouse wheel"); m_desc["cursor_size"] = _L("Pen size"); m_desc["enforce_caption"] = _L("Left mouse button"); @@ -217,6 +218,7 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l const float cursor_slider_left = m_imgui->calc_text_size(m_desc.at("cursor_size")).x + m_imgui->scaled(1.5f); const float gap_fill_slider_left = m_imgui->calc_text_size(m_desc.at("gap_fill")).x + m_imgui->scaled(1.5f); const float highlight_slider_left = m_imgui->calc_text_size(m_desc.at("highlight_by_angle")).x + m_imgui->scaled(1.5f); + const float reset_button_slider_left = m_imgui->calc_text_size(m_desc.at("reset_direction")).x + m_imgui->scaled(1.5f) + ImGui::GetStyle().FramePadding.x * 2; const float on_overhangs_only_width = m_imgui->calc_text_size(m_desc["on_overhangs_only"]).x + m_imgui->scaled(1.5f); const float remove_btn_width = m_imgui->calc_text_size(m_desc.at("remove_all")).x + m_imgui->scaled(1.5f); const float filter_btn_width = m_imgui->calc_text_size(m_desc.at("perform")).x + m_imgui->scaled(1.5f); @@ -235,7 +237,7 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l total_text_max += caption_max + m_imgui->scaled(1.f); caption_max += m_imgui->scaled(1.f); - const float sliders_left_width = std::max(std::max(cursor_slider_left, clipping_slider_left), std::max(highlight_slider_left, gap_fill_slider_left)); + const float sliders_left_width = std::max(reset_button_slider_left, std::max(std::max(cursor_slider_left, clipping_slider_left), std::max(highlight_slider_left, gap_fill_slider_left))); const float slider_icon_width = m_imgui->get_slider_icon_size().x; const float max_tooltip_width = ImGui::GetFontSize() * 20.0f; @@ -394,8 +396,17 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l if (m_current_tool != ImGui::GapFillIcon) { ImGui::Separator(); - ImGui::AlignTextToFramePadding(); - m_imgui->text(m_desc.at("clipping_of_view")); + if (m_c->object_clipper()->get_position() == 0.f) { + ImGui::AlignTextToFramePadding(); + m_imgui->text(m_desc.at("clipping_of_view")); + } + else { + if (m_imgui->button(m_desc.at("reset_direction"))) { + wxGetApp().CallAfter([this]() { + m_c->object_clipper()->set_position(-1., false); + }); + } + } auto clp_dist = float(m_c->object_clipper()->get_position()); ImGui::SameLine(sliders_left_width); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp index 03e327b1b..07bb861a2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp @@ -185,7 +185,7 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit) // First calculate width of all the texts that are could possibly be shown. We will decide set the dialog width based on that: const float space_size = m_imgui->get_style_scaling() * 8; const float clipping_slider_left = std::max(m_imgui->calc_text_size(m_desc.at("clipping_of_view")).x, - m_imgui->calc_text_size(m_desc.at("reset_direction")).x) + m_imgui->calc_text_size(m_desc.at("reset_direction")).x + ImGui::GetStyle().FramePadding.x * 2) + m_imgui->scaled(1.5f); const float cursor_size_slider_left = m_imgui->calc_text_size(m_desc.at("cursor_size")).x + m_imgui->scaled(1.f); const float empty_button_width = m_imgui->calc_button_size("").x; @@ -271,8 +271,18 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit) ImGui::PushItemWidth(1.5 * slider_icon_width); ImGui::BBLDragFloat("##cursor_radius_input", &m_cursor_radius, 0.05f, 0.0f, 0.0f, "%.2f"); - ImGui::AlignTextToFramePadding(); - m_imgui->text(m_desc.at("clipping_of_view")); + ImGui::Separator(); + if (m_c->object_clipper()->get_position() == 0.f) { + ImGui::AlignTextToFramePadding(); + m_imgui->text(m_desc.at("clipping_of_view")); + } + else { + if (m_imgui->button(m_desc.at("reset_direction"))) { + wxGetApp().CallAfter([this]() { + m_c->object_clipper()->set_position(-1., false); + }); + } + } auto clp_dist = float(m_c->object_clipper()->get_position()); ImGui::SameLine(sliders_left_width); diff --git a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp index a8ef43c85..d52969ba5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmosCommon.cpp @@ -433,11 +433,11 @@ void ObjectClipper::set_position(double pos, bool keep_normal) int active_inst = get_pool()->selection_info()->get_active_instance(); double z_shift = get_pool()->selection_info()->get_sla_shift(); - Vec3d camera_dir = wxGetApp().plater()->get_camera().get_dir_forward(); - if (abs(camera_dir(0)) > EPSILON || abs(camera_dir(1)) > EPSILON) - camera_dir(2) = 0; + //Vec3d camera_dir = wxGetApp().plater()->get_camera().get_dir_forward(); + //if (abs(camera_dir(0)) > EPSILON || abs(camera_dir(1)) > EPSILON) + // camera_dir(2) = 0; - Vec3d normal = (keep_normal && m_clp) ? m_clp->get_normal() : -camera_dir; + Vec3d normal = (keep_normal && m_clp) ? m_clp->get_normal() : /*-camera_dir;*/ -wxGetApp().plater()->get_camera().get_dir_forward(); const Vec3d& center = mo->instances[active_inst]->get_offset() + Vec3d(0., 0., z_shift); float dist = normal.dot(center); @@ -697,8 +697,7 @@ void ModelObjectsClipper::render_cut() const void ModelObjectsClipper::set_position(double pos, bool keep_normal) { - Vec3d camera_dir = wxGetApp().plater()->get_camera().get_dir_forward(); - Vec3d normal = -camera_dir; + Vec3d normal = (keep_normal && m_clp) ? m_clp->get_normal() : -wxGetApp().plater()->get_camera().get_dir_forward(); const Vec3d& center = get_pool()->get_canvas()->volumes_bounding_box().center(); float dist = normal.dot(center); @@ -708,6 +707,7 @@ void ModelObjectsClipper::set_position(double pos, bool keep_normal) m_clp_ratio = pos; m_clp.reset(new ClippingPlane(normal, (dist - (-m_active_inst_bb_radius * GLVolume::explosion_ratio) - m_clp_ratio * 2 * m_active_inst_bb_radius * GLVolume::explosion_ratio))); get_pool()->get_canvas()->set_as_dirty(); + } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 7f0a53607..31d8e4dbc 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1712,7 +1712,7 @@ void ImGuiWrapper::push_toolbar_style(const float scale) ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 6 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGuiWrapper::COL_HOVER); // 7 ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 8 - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 9 + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(172 / 255.0f, 172 / 255.0f, 172 / 255.0f, 1.00f)); // 9 ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 1.00f)); // 10 ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(238 / 255.0f, 238 / 255.0f, 238 / 255.0f, 0.00f)); // 11 ImGui::PushStyleColor(ImGuiCol_TextSelectedBg, COL_GREEN_LIGHT); // 12