diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 6bcae6e08..3c2d209d3 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1011,17 +1011,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_last_result_id = gcode_result.id; m_gcode_result = &gcode_result; m_only_gcode_in_preview = only_gcode; - - std::vector filament_maps = print.get_filament_maps(); - std::vector color_opt = print.config().option("filament_colour")->values; - std::vector type_opt = print.config().option("filament_type")->values; - for (int i = 0; i < filament_maps.size(); ++i) { - if (filament_maps[i] == 1) { - m_left_extruder_filament.emplace_back(type_opt[i], color_opt[i]); - } else { - m_right_extruder_filament.emplace_back(type_opt[i], color_opt[i]); - } - } + m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends); //BBS: add only gcode mode @@ -1033,6 +1023,18 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr load_toolpaths(gcode_result, build_volume, exclude_bounding_box); + // BBS: data for rendering color arrangement recommendation + m_nozzle_nums = print.config().option("nozzle_diameter")->values.size(); + std::vector filament_maps = print.get_filament_maps(); + std::vector color_opt = print.config().option("filament_colour")->values; + std::vector type_opt = print.config().option("filament_type")->values; + for (auto extruder_id : m_extruder_ids) { + if (filament_maps[extruder_id] == 1) { + m_left_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id}); + } else { + m_right_extruder_filament.push_back({type_opt[extruder_id], color_opt[extruder_id], extruder_id}); + } + } //BBS: add mutex for protection of gcode result if (m_layers.empty()) { gcode_result.unlock(); @@ -1288,6 +1290,8 @@ void GCodeViewer::reset() m_print_statistics.reset(); m_custom_gcode_per_print_z = std::vector(); m_sequential_view.gcode_window.reset(); + m_left_extruder_filament.clear(); + m_right_extruder_filament.clear(); #if ENABLE_GCODE_VIEWER_STATISTICS m_statistics.reset_all(); #endif // ENABLE_GCODE_VIEWER_STATISTICS @@ -4617,8 +4621,10 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) ImGui::SameLine(); imgui.title(_u8L("Color Arrangement Recommendation")); //BBS AMS containers + int AMS_filament_max_num = std::max(m_left_extruder_filament.size(), m_right_extruder_filament.size()); + float AMS_container_height = (std::ceil(AMS_filament_max_num / 4.0f) * 80.0f + 70.0f ) * m_scale; ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 3, 0)); - ImGui::BeginChild("#AMS", ImVec2(0, 230.0f), false, ImGuiWindowFlags_AlwaysUseWindowPadding); + ImGui::BeginChild("#AMS", ImVec2(0, AMS_container_height), false, ImGuiWindowFlags_AlwaysUseWindowPadding); { // BBS save time; imgui.text(_u8L("Since you set 1 AMS")); @@ -4632,7 +4638,7 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) float available_width = ImGui::GetContentRegionAvail().x; float available_height = ImGui::GetContentRegionAvail().y; float half_width = available_width * 0.5f; - float spacing = 12.0f * m_scale; + float spacing = 18.0f * m_scale; ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.00f, 0.00f, 0.00f, 0.3f)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(window_padding * 2, window_padding)); ImDrawList *child_begin_draw_list = ImGui::GetWindowDrawList(); @@ -4644,8 +4650,9 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) ImGui::Dummy({window_padding, window_padding}); int index = 1; for (const auto &extruder_filament : m_left_extruder_filament) { - imgui.filament_group(extruder_filament.first, extruder_filament.second.c_str()); + imgui.filament_group(extruder_filament.type, extruder_filament.hex_color.c_str(), extruder_filament.filament_id); if (index % 4 != 0) { ImGui::SameLine(0, spacing); } + index++; } ImGui::EndChild(); } @@ -4658,8 +4665,9 @@ void GCodeViewer::render_legend_color_arr_recommen(float window_padding) ImGui::Dummy({window_padding, window_padding}); int index = 1; for (const auto &extruder_filament : m_right_extruder_filament) { - imgui.filament_group(extruder_filament.first, extruder_filament.second.c_str()); + imgui.filament_group(extruder_filament.type, extruder_filament.hex_color.c_str(), extruder_filament.filament_id); if (index % 4 != 0) { ImGui::SameLine(0, spacing); } + index++; } ImGui::EndChild(); } @@ -4996,10 +5004,12 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv return; } - render_legend_color_arr_recommen(window_padding); + if(m_nozzle_nums > 1) + render_legend_color_arr_recommen(window_padding); //BBS display Color Scheme ImGui::Dummy({ window_padding, window_padding }); + ImGui::Dummy({ window_padding, window_padding }); ImGui::SameLine(); imgui.bold_text(_u8L("Color Scheme")); push_combo_style(); diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 2887c4961..514a266d0 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -720,6 +720,13 @@ public: std::vector m_tool_visibles; }; + struct ExtruderFilament + { + std::string type; + std::string hex_color; + unsigned char filament_id; + }; + enum class EViewType : unsigned char { FeatureType = 0, @@ -752,9 +759,9 @@ private: std::vector m_ssid_to_moveid_map; //BBS: extruder dispensing filament - //std::pair - std::vector> m_left_extruder_filament; - std::vector> m_right_extruder_filament; + std::vector m_left_extruder_filament; + std::vector m_right_extruder_filament; + size_t m_nozzle_nums; std::vector m_buffers{ static_cast(EMoveType::Extrude) }; // bounding box of toolpaths diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 79a92cb16..51d708853 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -2841,13 +2841,17 @@ void ImGuiWrapper::clipboard_set(void* /* user_data */, const char* text) } } -void ImGuiWrapper::filament_group(const std::string &filament_type, const char *hex_color) +void ImGuiWrapper::filament_group(const std::string &filament_type, const char *hex_color, unsigned char filament_id) { //ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); + std::string id = std::to_string(static_cast (filament_id + 1)); ImDrawList *draw_list = ImGui::GetWindowDrawList(); static ImTextureID transparent; ImVec2 img_size = {30.0f, 45.0f}; ImVec2 text_size = ImGui::CalcTextSize(filament_type.c_str()); + ImVec2 id_text_size = this->calc_text_size(id); + unsigned char rgb[3]; + BitmapCache::load_from_svg_file_change_color(Slic3r::resources_dir() + "/images/filament_green.svg", img_size.x, img_size.y, transparent, hex_color); ImGui::BeginGroup(); { @@ -2856,6 +2860,11 @@ void ImGuiWrapper::filament_group(const std::string &filament_type, const char * // image border test // draw_list->AddRect(cursor_pos, {cursor_pos.x + img_size.x, cursor_pos.y + img_size.y}, IM_COL32(0, 0, 0, 255)); ImVec2 current_cursor = ImGui::GetCursorPos(); + ImGui::SetCursorPos({current_cursor.x + (img_size.x - id_text_size.x) * 0.5f + 2, current_cursor.y + (img_size.y - id_text_size.y) * 0.5f - 2}); + Slic3r::GUI::BitmapCache::parse_color(hex_color, rgb); + float gray = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]; + ImVec4 text_color = gray < 80 ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f) : ImVec4(0, 0, 0, 1.0f); + this->text_colored(text_color, id.c_str()); ImGui::SetCursorPos({current_cursor.x + (img_size.x - text_size.x) * 0.5f, current_cursor.y + 40}); this->text(filament_type); ImGui::EndGroup(); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index f5d89f8a7..346d1c664 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -153,8 +153,8 @@ public: void text_wrapped(const wxString &label, float wrap_width); void tooltip(const char *label, float wrap_width); void tooltip(const wxString &label, float wrap_width); - void filament_group(const std::string &filament_type, const char *hex_color); - void sub_title(const std::string &label); + void filament_group(const std::string &filament_type, const char *hex_color, unsigned char filament_id); + void sub_title(const std::string &label); // Float sliders: Manually inserted values aren't clamped by ImGui.Using this wrapper function does (when clamp==true).