From 2e26c5812a98e47a25d97e7f574e8a4d8e8f7f9e Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Sun, 19 Jan 2025 18:20:02 +0800 Subject: [PATCH] ENH: refine logic in filament group in gcodeviewer jira: NONE Signed-off-by: xun.zhang Change-Id: Id89daec05f2d4017d326c6473bd62008dd9f0b11 --- src/slic3r/GUI/FilamentMapPanel.cpp | 3 +- src/slic3r/GUI/GCodeViewer.cpp | 105 ++++++++++++++-------------- 2 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/slic3r/GUI/FilamentMapPanel.cpp b/src/slic3r/GUI/FilamentMapPanel.cpp index e85cc1e2f..3546403cd 100644 --- a/src/slic3r/GUI/FilamentMapPanel.cpp +++ b/src/slic3r/GUI/FilamentMapPanel.cpp @@ -55,8 +55,7 @@ FilamentMapManualPanel::FilamentMapManualPanel(wxWindow *p top_sizer->Add(drag_sizer, 0, wxALIGN_CENTER | wxEXPAND); - m_tips = new Label(this, _L("Tips: You can drag the filaments to reassign them to different nozzles.\n" - "But your filament grouping may not be the most efficient for filament usage.")); + m_tips = new Label(this, _L("Tips: You can drag the filaments to reassign them to different nozzles.")); m_tips->SetFont(Label::Body_14); m_tips->SetForegroundColour(TextNormalGreyColor); top_sizer->AddSpacer(FromDIP(8)); diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 495f7104e..353234053 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4667,13 +4667,6 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) ImGui::PushStyleColor(ImGuiCol_Text, HyperColor.Value); imgui.text(label.c_str()); ImGui::PopStyleColor(); - - // underline - ImVec2 lineEnd = ImGui::GetItemRectMax(); - lineEnd.y -= 2.0f; - ImVec2 lineStart = lineEnd; - lineStart.x = ImGui::GetItemRectMin().x; - ImGui::GetWindowDrawList()->AddLine(lineStart, lineEnd, HyperColor); // click behavior if (ImGui::IsMouseHoveringRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), true)) { if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { @@ -4683,24 +4676,42 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) } }; + auto draw_dash_line = [&](ImDrawList* draw_list, int dash_length = 5, int gap_length = 3) { + ImVec2 p1 = ImGui::GetCursorScreenPos(); + ImVec2 p2 = ImVec2(p1.x + ImGui::GetContentRegionAvail().x, p1.y); + for (float i = p1.x; i < p2.x; i += (dash_length + gap_length)) { + draw_list->AddLine(ImVec2(i, p1.y), ImVec2(i + dash_length, p1.y), IM_COL32(206, 206, 206, 255)); + } + }; + ////BBS Color Arrangement Recommendation auto config = wxGetApp().plater()->get_partplate_list().get_current_fff_print().config(); auto stats_by_extruder = wxGetApp().plater()->get_partplate_list().get_current_fff_print().statistics_by_extruder(); - auto filament_map_mode = config.filament_map_mode.value; - auto is_auto = filament_map_mode < FilamentMapMode::fmmManual; - bool has_tips = true; - if (is_auto) { - float saved_flush_weight = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_curr.filament_flush_weight; - int saved_filament_changed_time = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count; - if (!(saved_flush_weight > EPSILON || saved_filament_changed_time > 0)) has_tips = false; - } + + float delta_weight_to_single_ext = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_curr.filament_flush_weight; + float delta_weight_to_best = stats_by_extruder.stats_by_multi_extruder_curr.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_best.filament_flush_weight; + int delta_change_to_single_ext = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count; + int delta_change_to_best = stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count - stats_by_extruder.stats_by_multi_extruder_best.filament_change_count; + + bool less_to_single_ext = delta_weight_to_single_ext > EPSILON || delta_change_to_single_ext > 0; + bool more_to_best = delta_weight_to_best > EPSILON || delta_change_to_best > 0; + // BBS AMS containers float line_height = ImGui::GetFrameHeight(); int AMS_filament_max_num = std::max(m_left_extruder_filament.size(), m_right_extruder_filament.size()); float three_words_width = imgui.calc_text_size("ABC").x; float ams_item_height = std::ceil(AMS_filament_max_num / 4.0f) * (three_words_width * 1.6f + line_height) + line_height * 2; - float AMS_container_height = ams_item_height + line_height * (has_tips ? 7 : 5); + + int tips_count = 8; + if (more_to_best) + tips_count = 8; + else if (less_to_single_ext) + tips_count = 6; + else + tips_count = 5; + + float AMS_container_height = ams_item_height + line_height * tips_count + line_height / 2; ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(1.f, 1.f, 1.f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(.15f, .18f, .19f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 3, 0)); @@ -4714,15 +4725,18 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) ImGui::Dummy({window_padding, window_padding}); ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(.8f, .8f, .8f, 1.0f)); - if (is_auto) - imgui.title(_u8L("Filament Grouping Recommendation")); - else - imgui.title(_u8L("Filament Grouping")); + imgui.bold_text(_u8L("Filament Grouping")); + ImGui::SameLine(); + std::string tip_str = _u8L("Why this grouping"); + ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() - window_padding - ImGui::CalcTextSize(tip_str.c_str()).x); + link_filament_group_wiki(tip_str); + ImGui::Separator(); ImGui::PopStyleColor(); ImGui::Dummy({window_padding, window_padding}); ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.1f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 2, window_padding)); + ImDrawList *child_begin_draw_list = ImGui::GetWindowDrawList(); ImVec2 cursor_pos = ImGui::GetCursorScreenPos(); child_begin_draw_list->AddRectFilled(cursor_pos, ImVec2(cursor_pos.x + half_width, cursor_pos.y + line_height), IM_COL32(0, 0, 0, 20)); @@ -4755,6 +4769,15 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) } ImGui::PopStyleColor(1); ImGui::PopStyleVar(1); + + ImGui::Dummy({window_padding, window_padding}); + imgui.text_wrapped(from_u8(_u8L("Please place filaments on the printer based on grouping result.")), ImGui::GetContentRegionAvail().x); + ImGui::Dummy({window_padding, window_padding}); + + { + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + draw_dash_line(draw_list); + } ImGui::Dummy({window_padding, window_padding}); bool is_optimal_group = true; @@ -4767,35 +4790,19 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) } return static_cast(num); }; - if (filament_map_mode == fmmAutoForFlush) { - float saved_flush_weight = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_best.filament_flush_weight; - int saved_filament_changed_time = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_best.filament_change_count; - if (saved_flush_weight > EPSILON || saved_filament_changed_time > 0) { - imgui.text(_u8L("Current grouping of slice result is optimal.")); - imgui.text_wrapped(from_u8((boost::format(_u8L("Save %1%g filament and %2% changes than one-nozzle printer.")) % number_format(saved_flush_weight) % saved_filament_changed_time).str()), parent_width); - } - } else if (filament_map_mode != fmmAutoForFlush) { - float more_cost = stats_by_extruder.stats_by_multi_extruder_curr.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_best.filament_flush_weight; - int more_time = stats_by_extruder.stats_by_multi_extruder_curr.filament_change_count - stats_by_extruder.stats_by_multi_extruder_best.filament_change_count; - if (more_cost > EPSILON || more_time > 0) { - is_optimal_group = false; - ImVec4 orangeColor = ImVec4(1.0f, 0.5f, 0.0f, 1.0f); - ImGui::PushStyleColor(ImGuiCol_Text, orangeColor); - imgui.text(_u8L("Current grouping of slice result is not optimal.")); - imgui.text_wrapped(from_u8((boost::format(_u8L("Cost %1%g filament and %2% changes more than optimal grouping.")) % number_format(more_cost) % more_time).str()), parent_width); - ImGui::PopStyleColor(1); - } else { - float saved_flush_weight = stats_by_extruder.stats_by_single_extruder.filament_flush_weight - stats_by_extruder.stats_by_multi_extruder_best.filament_flush_weight; - int saved_filament_changed_time = stats_by_extruder.stats_by_single_extruder.filament_change_count - stats_by_extruder.stats_by_multi_extruder_best.filament_change_count; - if (saved_flush_weight > EPSILON || saved_filament_changed_time > 0) { - imgui.text(_u8L("Current grouping of slice result is optimal.")); - imgui.text_wrapped(from_u8((boost::format(_u8L("Save %1%g filament and %2% changes than one-nozzle printer.")) % number_format(saved_flush_weight) % saved_filament_changed_time).str()), parent_width); - } - } + if (more_to_best) { + is_optimal_group = false; + ImVec4 orangeColor = ImVec4(1.0f, 0.5f, 0.0f, 1.0f); + ImGui::PushStyleColor(ImGuiCol_Text, orangeColor); + imgui.text(_u8L("Tips:")); + imgui.text(_u8L("Current grouping of slice result is not optimal.")); + imgui.text_wrapped(from_u8((boost::format(_u8L("Cost %1%g filament and %2% changes more than optimal grouping.")) % number_format(delta_weight_to_best) % delta_change_to_best).str()), parent_width); + ImGui::PopStyleColor(1); + } + else if (less_to_single_ext) { + imgui.text_wrapped(from_u8((boost::format(_u8L("Save %1%g filament and %2% changes than one-nozzle printer.")) % number_format(delta_weight_to_single_ext) % delta_change_to_single_ext).str()), parent_width); } - - imgui.text_wrapped(from_u8(_u8L("Please place the filaments on the printer as recommended.")), parent_width); ImGui::Dummy({window_padding, window_padding}); if (!is_optimal_group) { @@ -4806,10 +4813,6 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) } link_text(_u8L("Regroup filament")); - ImGui::SameLine(); - ImGui::SetCursorPosX(ImGui::GetWindowContentRegionWidth() - window_padding - ImGui::CalcTextSize("Tips").x); - link_filament_group_wiki(_u8L("Tips")); - ImGui::EndChild(); } ImGui::PopStyleColor(2);