From 8278be8d26419230a944de3cb06fb9c066b40790 Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Thu, 3 Nov 2022 16:56:17 +0800 Subject: [PATCH] NEW:support jump to specific layer in preview Change-Id: Ia2396c3512f521e31e440783e2ce12926f1ddeca --- src/slic3r/GUI/GLCanvas3D.cpp | 25 +++++-- src/slic3r/GUI/IMSlider.cpp | 117 ++++++++++++++++++++++++++++---- src/slic3r/GUI/IMSlider.hpp | 18 ++--- src/slic3r/GUI/ImGuiWrapper.cpp | 40 ++++++++++- src/slic3r/GUI/ImGuiWrapper.hpp | 6 ++ 5 files changed, 176 insertions(+), 30 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 3203d25537..cc869b385f 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2809,11 +2809,21 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) IMSlider *m_layers_slider = get_gcode_viewer().get_layers_slider(); IMSlider *m_moves_slider = get_gcode_viewer().get_moves_slider(); if (evt.CmdDown() || evt.ShiftDown()) { + if (evt.GetKeyCode() == 'G') { + m_layers_slider->show_go_to_layer(true); + } IMSlider *m_layers_slider = get_gcode_viewer().get_layers_slider(); IMSlider *m_moves_slider = get_gcode_viewer().get_moves_slider(); if (keyCode == WXK_UP || keyCode == WXK_DOWN) { - const int new_pos = keyCode == WXK_UP ? m_layers_slider->GetHigherValue() + 5 : m_layers_slider->GetHigherValue() - 5; - m_layers_slider->SetHigherValue(new_pos); + int new_pos; + if (m_layers_slider->GetSelection() == ssHigher) { + new_pos = keyCode == WXK_UP ? m_layers_slider->GetHigherValue() + 5 : m_layers_slider->GetHigherValue() - 5; + m_layers_slider->SetHigherValue(new_pos); + } + else if (m_layers_slider->GetSelection() == ssLower) { + new_pos = keyCode == WXK_UP ? m_layers_slider->GetLowerValue() + 5 : m_layers_slider->GetLowerValue() - 5; + m_layers_slider->SetLowerValue(new_pos); + } if (m_layers_slider->is_one_layer()) m_layers_slider->SetLowerValue(m_layers_slider->GetHigherValue()); // BBS set as dirty, update in render_gcode() m_layers_slider->set_as_dirty(); @@ -2825,8 +2835,15 @@ void GLCanvas3D::on_key(wxKeyEvent& evt) } } else if (keyCode == WXK_UP || keyCode == WXK_DOWN) { - const int new_pos = keyCode == WXK_UP ? m_layers_slider->GetHigherValue() + 1 : m_layers_slider->GetHigherValue() - 1; - m_layers_slider->SetHigherValue(new_pos); + int new_pos; + if (m_layers_slider->GetSelection() == ssHigher) { + new_pos = keyCode == WXK_UP ? m_layers_slider->GetHigherValue() + 1 : m_layers_slider->GetHigherValue() - 1; + m_layers_slider->SetHigherValue(new_pos); + } + else if (m_layers_slider->GetSelection() == ssLower) { + new_pos = keyCode == WXK_UP ? m_layers_slider->GetLowerValue() + 1 : m_layers_slider->GetLowerValue() - 1; + m_layers_slider->SetLowerValue(new_pos); + } if (m_layers_slider->is_one_layer()) m_layers_slider->SetLowerValue(m_layers_slider->GetHigherValue()); // BBS set as dirty, update in render_gcode() m_layers_slider->set_as_dirty(); diff --git a/src/slic3r/GUI/IMSlider.cpp b/src/slic3r/GUI/IMSlider.cpp index 12a1ee18d5..2a343bc953 100644 --- a/src/slic3r/GUI/IMSlider.cpp +++ b/src/slic3r/GUI/IMSlider.cpp @@ -1223,6 +1223,8 @@ bool IMSlider::render(int canvas_width, int canvas_height) render_input_custom_gcode(); + render_go_to_layer_dialog(); + if (is_horizontal()) { float pos_x = std::max(LEFT_MARGIN, 0.2f * canvas_width); float pos_y = (canvas_height - HORIZONTAL_SLIDER_SIZE.y * m_scale); @@ -1282,11 +1284,12 @@ void IMSlider::render_input_custom_gcode() return; ImGuiWrapper& imgui = *wxGetApp().imgui(); static bool move_to_center = true; + static bool set_focus_when_appearing = true; if (move_to_center) { - move_to_center = false; auto pos_x = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width() / 2; auto pos_y = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height() / 2; imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always, 0.5f, 0.5f); + move_to_center = false; } imgui.push_common_window_style(m_scale); @@ -1301,6 +1304,10 @@ void IMSlider::render_input_custom_gcode() | ImGuiWindowFlags_NoScrollWithMouse; imgui.begin(_u8L("Custom G-code"), windows_flag); imgui.text(_u8L("Enter Custom G-code used on current layer:")); + if (set_focus_when_appearing) { + ImGui::SetKeyboardFocusHere(0); + set_focus_when_appearing = false; + } int text_height = 6; ImGui::InputTextMultiline("##text", m_custom_gcode, sizeof(m_custom_gcode), ImVec2(-1, ImGui::GetTextLineHeight() * text_height)); //text_height = 5; @@ -1311,29 +1318,103 @@ void IMSlider::render_input_custom_gcode() ImGui::NewLine(); ImGui::SameLine(ImGui::GetStyle().WindowPadding.x * 14); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f / 255.f, 174.f / 255.f, 66.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(61.f / 255.f, 203.f / 255.f, 115.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(27.f / 255.f, 136.f / 255.f, 68.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.f, 1.f, 1.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); + imgui.push_confirm_button_style(); if (imgui.bbl_button(_L("OK"))) { m_show_custom_gcode_window = false; add_custom_gcode(m_custom_gcode); move_to_center = true; + set_focus_when_appearing = true; } - ImGui::PopStyleColor(5); + imgui.pop_confirm_button_style(); ImGui::SameLine(); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(255.f / 255.f, 255.f / 255.f, 255.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(238.f / 255.f, 238.f / 255.f, 238.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(206.f / 255.f, 206.f / 255.f, 206.f / 255.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(0.f, 0.f, 0.f, 1.f)); - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(38.f / 255.0f, 46.f / 255.0f, 48.f / 255.0f, 1.00f)); + imgui.push_cancel_button_style(); if (imgui.bbl_button(_L("Cancel"))) { m_show_custom_gcode_window = false; move_to_center = true; + set_focus_when_appearing = true; } - ImGui::PopStyleColor(5); + imgui.pop_cancel_button_style(); + + imgui.end(); + ImGui::PopStyleVar(3); + imgui.pop_common_window_style(); +} + +void IMSlider::do_go_to_layer(size_t layer_number) { + clamp((int)layer_number, m_min_value, m_max_value); + GetSelection() == ssLower ? SetLowerValue(layer_number) : SetHigherValue(layer_number); +} + +void IMSlider::render_go_to_layer_dialog(){ + if (!m_show_go_to_layer_dialog) + return; + ImGuiWrapper& imgui = *wxGetApp().imgui(); + static bool move_to_center = true; + static bool set_focus_when_appearing = true; + if (move_to_center) { + auto pos_x = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_width() / 2; + auto pos_y = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height() / 2; + imgui.set_next_window_pos(pos_x, pos_y, ImGuiCond_Always, 0.5f, 0.5f); + move_to_center = false; + } + + imgui.push_common_window_style(m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 12.f * m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 3) * m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(10, 7) * m_scale); + int windows_flag = + ImGuiWindowFlags_NoCollapse + | ImGuiWindowFlags_AlwaysAutoResize + | ImGuiWindowFlags_NoResize + | ImGuiWindowFlags_NoScrollbar + | ImGuiWindowFlags_NoScrollWithMouse; + imgui.begin(_u8L("Go to layer"), windows_flag); + imgui.text(_u8L("Layer number") + " (" + std::to_string(m_min_value) + " - " + std::to_string(m_max_value) + "):"); + ImGui::PushItemWidth(210 * m_scale); + if (set_focus_when_appearing) { + ImGui::SetKeyboardFocusHere(0); + set_focus_when_appearing = false; + } + ImGui::InputText("##input_layer_number", m_layer_number, sizeof(m_layer_number)); + + ImGui::NewLine(); + ImGui::SameLine(GImGui->Style.WindowPadding.x * 6); + imgui.push_confirm_button_style(); + bool disable_button = false; + if (strlen(m_layer_number) == 0) + disable_button = true; + else { + for (size_t i = 0; i< strlen(m_layer_number); i++) + if (!isdigit(m_layer_number[i])) + disable_button = true; + if (!disable_button && (m_min_value > atoi(m_layer_number) || atoi(m_layer_number) > m_max_value)) + disable_button = true; + } + if (disable_button) { + ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); + imgui.push_button_disable_style(); + } + if (imgui.bbl_button(_L("OK"))) { + do_go_to_layer(atoi(m_layer_number)); + m_show_go_to_layer_dialog = false; + move_to_center = true; + set_focus_when_appearing = true; + } + if (disable_button) { + ImGui::PopItemFlag(); + imgui.pop_button_disable_style(); + } + imgui.pop_confirm_button_style(); + + ImGui::SameLine(); + imgui.push_cancel_button_style(); + if (imgui.bbl_button(_L("Cancel"))) { + m_show_go_to_layer_dialog = false; + move_to_center = true; + set_focus_when_appearing = true; + } + imgui.pop_cancel_button_style(); imgui.end(); ImGui::PopStyleVar(3); @@ -1354,8 +1435,11 @@ void IMSlider::render_menu() if (ImGui::BeginPopup("slider_menu_popup")) { if ((m_selection == ssLower && GetLowerValueD() == m_zero_layer_height) || (m_selection == ssHigher && GetHigherValueD() == m_zero_layer_height)) { - menu_item_with_icon(_u8L("Add Pause").c_str(), "", ImVec2(0, 0), 0, false, false); - }else + if (menu_item_with_icon(_u8L("Jump to Layer").c_str(), "")) { + m_show_go_to_layer_dialog = true; + } + } + else { if (menu_item_with_icon(_u8L("Add Pause").c_str(), "")) { add_code_as_tick(PausePrint); @@ -1368,6 +1452,9 @@ void IMSlider::render_menu() add_code_as_tick(Template); } } + if (menu_item_with_icon(_u8L("Jump to Layer").c_str(), "")) { + m_show_go_to_layer_dialog = true; + } } //BBS render this menu item only when extruder_num > 1 diff --git a/src/slic3r/GUI/IMSlider.hpp b/src/slic3r/GUI/IMSlider.hpp index 5b6e7ce983..cb6a6ccc27 100644 --- a/src/slic3r/GUI/IMSlider.hpp +++ b/src/slic3r/GUI/IMSlider.hpp @@ -261,18 +261,13 @@ public: void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); } - void add_custom_gcode(std::string custom_gcode); - void add_code_as_tick(Type type, int selected_extruder = -1); void post_ticks_changed_event(Type type = Custom); bool check_ticks_changed_event(Type type); bool switch_one_layer_mode(); + void show_go_to_layer(bool show) { m_show_go_to_layer_dialog = show; } bool render(int canvas_width, int canvas_height); - void render_menu(); - - void render_input_custom_gcode(); - //BBS update scroll value changed bool is_dirty() { return m_dirty; } void set_as_dirty(bool dirty = true) { m_dirty = dirty; } @@ -286,10 +281,17 @@ public: ExtrudersSequence m_extruders_sequence; float m_scale = 1.0; void set_scale(float scale = 1.0); + protected: + void add_custom_gcode(std::string custom_gcode); + void add_code_as_tick(Type type, int selected_extruder = -1); + void do_go_to_layer(size_t layer_number); void correct_lower_value(); void correct_higher_value(); bool horizontal_slider(const char* str_id, int* v, int v_min, int v_max, const ImVec2& pos, const ImVec2& size, float scale = 1.0); + void render_go_to_layer_dialog(); + void render_input_custom_gcode(); + void render_menu(); void draw_background(const ImRect& groove); void draw_colored_band(const ImRect& groove, const ImRect& slideable_region); void draw_ticks(const ImRect& slideable_region); @@ -305,8 +307,6 @@ private: int get_tick_from_value(double value, bool force_lower_bound = false); float get_pos_from_value(int v_min, int v_max, int value, const ImRect& rect); - - std::string get_color_for_tool_change_tick(std::set::const_iterator it) const; // Get active extruders for tick. // Means one current extruder for not existing tick OR @@ -331,6 +331,7 @@ private: bool m_is_focused = false; bool m_show_menu = false; bool m_show_custom_gcode_window = false; + bool m_show_go_to_layer_dialog = false; bool m_force_mode_apply = true; bool m_enable_action_icon = true; bool m_enable_cog_icon = false; @@ -373,6 +374,7 @@ private: std::vector m_alternate_values; char m_custom_gcode[1024] = { 0 }; + char m_layer_number[64] = { 0 }; }; } diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 77503e14ed..5448aeabdf 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -1694,9 +1694,9 @@ void ImGuiWrapper::push_common_window_style(const float scale) { ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 3.0f * scale); ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(38 / 255.0f, 46 / 255.0f, 48 / 255.0f, 1.00f)); // 1 - ImGui::PushStyleColor(ImGuiCol_WindowBg, ImGuiWrapper::COL_WINDOW_BG); // 2 - ImGui::PushStyleColor(ImGuiCol_TitleBg, ImGuiWrapper::COL_TITLE_BG); // 3 - ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImGuiWrapper::COL_TITLE_BG); // 4 + ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 2 + ImGui::PushStyleColor(ImGuiCol_TitleBg, ImVec4(245 / 255.0f, 245 / 255.0f, 245 / 255.0f, 1.00f)); // 3 + ImGui::PushStyleColor(ImGuiCol_TitleBgActive, ImVec4(245 / 255.0f, 245 / 255.0f, 245 / 255.0f, 1.00f)); // 4 ImGui::PushStyleColor(ImGuiCol_Separator, ImGuiWrapper::COL_SEPARATOR); // 5 ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.00f, 1.00f, 1.00f, 1.00f)); // 6 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.00f, 0.68f, 0.26f, 1.00f)); // 7 @@ -1714,6 +1714,40 @@ void ImGuiWrapper::pop_common_window_style() { ImGui::PopStyleVar(5); } +void ImGuiWrapper::push_confirm_button_style() { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f / 255.f, 174.f / 255.f, 66.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(61.f / 255.f, 203.f / 255.f, 115.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(27.f / 255.f, 136.f / 255.f, 68.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(1.f, 1.f, 1.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); +} + +void ImGuiWrapper::pop_confirm_button_style() { + ImGui::PopStyleColor(5); +} + +void ImGuiWrapper::push_cancel_button_style() { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(255.f / 255.f, 255.f / 255.f, 255.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(238.f / 255.f, 238.f / 255.f, 238.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(206.f / 255.f, 206.f / 255.f, 206.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_CheckMark, ImVec4(0.f, 0.f, 0.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(38.f / 255.0f, 46.f / 255.0f, 48.f / 255.0f, 1.00f)); +} + +void ImGuiWrapper::pop_cancel_button_style() { + ImGui::PopStyleColor(5); +} + +void ImGuiWrapper::push_button_disable_style() { + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(206.f / 255.f, 206.f / 255.f, 206.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(206.f / 255.f, 206.f / 255.f, 206.f / 255.f, 1.f)); + ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); +} + +void ImGuiWrapper::pop_button_disable_style() { + ImGui::PopStyleColor(3); +} + void ImGuiWrapper::init_font(bool compress) { destroy_font(); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index e0efa6b06e..824271878c 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -194,6 +194,12 @@ public: static void pop_menu_style(); static void push_common_window_style(const float scale); static void pop_common_window_style(); + static void push_confirm_button_style(); + static void pop_confirm_button_style(); + static void push_cancel_button_style(); + static void pop_cancel_button_style(); + static void push_button_disable_style(); + static void pop_button_disable_style(); //BBS static int TOOLBAR_WINDOW_FLAGS;