From 95d12c24f61ba848f752bd09124931017d9e3361 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 29 Aug 2023 21:25:47 +0800 Subject: [PATCH] QoL: show transparent shell in gcode preview and truncate long gcode line caused by native Klipper commands --- localization/i18n/OrcaSlicer.pot | 2 +- localization/i18n/cs/OrcaSlicer_cs.po | 2 +- localization/i18n/de/OrcaSlicer_de.po | 2 +- localization/i18n/en/OrcaSlicer_en.po | 4 +- localization/i18n/es/OrcaSlicer_es.po | 2 +- localization/i18n/fr/OrcaSlicer_fr.po | 2 +- localization/i18n/hu/OrcaSlicer_hu.po | 2 +- localization/i18n/it/OrcaSlicer_it.po | 2 +- localization/i18n/ja/OrcaSlicer_ja.po | 2 +- localization/i18n/ko/OrcaSlicer_ko.po | 2 +- localization/i18n/nl/OrcaSlicer_nl.po | 2 +- localization/i18n/ru/OrcaSlicer_ru.po | 2 +- localization/i18n/sv/OrcaSlicer_sv.po | 2 +- localization/i18n/uk/OrcaSlicer_uk.po | 2 +- localization/i18n/zh_TW/OrcaSlicer_zh_TW.po | 2 +- localization/i18n/zh_cn/OrcaSlicer_zh_CN.po | 2 +- src/slic3r/GUI/3DScene.cpp | 11 + src/slic3r/GUI/3DScene.hpp | 2 + src/slic3r/GUI/GCodeViewer.cpp | 215 ++++++++++---------- src/slic3r/GUI/GCodeViewer.hpp | 14 +- src/slic3r/GUI/GLCanvas3D.cpp | 6 +- src/slic3r/GUI/GLCanvas3D.hpp | 3 +- src/slic3r/GUI/GUI_Preview.cpp | 5 +- 23 files changed, 157 insertions(+), 133 deletions(-) diff --git a/localization/i18n/OrcaSlicer.pot b/localization/i18n/OrcaSlicer.pot index f55b313287..aa6e6b4b48 100644 --- a/localization/i18n/OrcaSlicer.pot +++ b/localization/i18n/OrcaSlicer.pot @@ -2561,7 +2561,7 @@ msgstr "" msgid "Layer Time: " msgstr "" -msgid "Fan Speed: " +msgid "Fan: " msgstr "" msgid "Temperature: " diff --git a/localization/i18n/cs/OrcaSlicer_cs.po b/localization/i18n/cs/OrcaSlicer_cs.po index db6c6fabd0..8a9b7213ad 100644 --- a/localization/i18n/cs/OrcaSlicer_cs.po +++ b/localization/i18n/cs/OrcaSlicer_cs.po @@ -2759,7 +2759,7 @@ msgstr "Průtok: " msgid "Layer Time: " msgstr "Čas vrstvy: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Rychlost ventilátoru: " msgid "Temperature: " diff --git a/localization/i18n/de/OrcaSlicer_de.po b/localization/i18n/de/OrcaSlicer_de.po index e58bc4763b..dfa1f7f735 100644 --- a/localization/i18n/de/OrcaSlicer_de.po +++ b/localization/i18n/de/OrcaSlicer_de.po @@ -2822,7 +2822,7 @@ msgstr "Durchfluss: " msgid "Layer Time: " msgstr "Schichtdauer:" -msgid "Fan Speed: " +msgid "Fan: " msgstr "Lüftergeschwindigkeit: " msgid "Temperature: " diff --git a/localization/i18n/en/OrcaSlicer_en.po b/localization/i18n/en/OrcaSlicer_en.po index 86e13d501a..1cab0f07a9 100644 --- a/localization/i18n/en/OrcaSlicer_en.po +++ b/localization/i18n/en/OrcaSlicer_en.po @@ -2725,8 +2725,8 @@ msgstr "Flow: " msgid "Layer Time: " msgstr "Layer Time: " -msgid "Fan Speed: " -msgstr "Fan Speed: " +msgid "Fan: " +msgstr "Fan: " msgid "Temperature: " msgstr "Temperature: " diff --git a/localization/i18n/es/OrcaSlicer_es.po b/localization/i18n/es/OrcaSlicer_es.po index 04f04fbe05..3c8d83234a 100644 --- a/localization/i18n/es/OrcaSlicer_es.po +++ b/localization/i18n/es/OrcaSlicer_es.po @@ -2799,7 +2799,7 @@ msgstr "Flujo: " msgid "Layer Time: " msgstr "Tiempo de Capa: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Velocidad del Ventilador: " msgid "Temperature: " diff --git a/localization/i18n/fr/OrcaSlicer_fr.po b/localization/i18n/fr/OrcaSlicer_fr.po index 9885e8c0b0..59aa3886cf 100644 --- a/localization/i18n/fr/OrcaSlicer_fr.po +++ b/localization/i18n/fr/OrcaSlicer_fr.po @@ -2806,7 +2806,7 @@ msgstr "Débit: " msgid "Layer Time: " msgstr "Durée de couche:" -msgid "Fan Speed: " +msgid "Fan: " msgstr "Vitesse du ventilateur: " msgid "Temperature: " diff --git a/localization/i18n/hu/OrcaSlicer_hu.po b/localization/i18n/hu/OrcaSlicer_hu.po index 6913ebde99..4e56be84ea 100644 --- a/localization/i18n/hu/OrcaSlicer_hu.po +++ b/localization/i18n/hu/OrcaSlicer_hu.po @@ -2749,7 +2749,7 @@ msgstr "Anyagáramlás:" msgid "Layer Time: " msgstr "Rétegidő: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Ventilátor-fordulatszám:" msgid "Temperature: " diff --git a/localization/i18n/it/OrcaSlicer_it.po b/localization/i18n/it/OrcaSlicer_it.po index 12d3e261b3..d1d903c6ae 100644 --- a/localization/i18n/it/OrcaSlicer_it.po +++ b/localization/i18n/it/OrcaSlicer_it.po @@ -2744,7 +2744,7 @@ msgstr "Flusso: " msgid "Layer Time: " msgstr "Tempo layer:" -msgid "Fan Speed: " +msgid "Fan: " msgstr "Velocità ventola:" msgid "Temperature: " diff --git a/localization/i18n/ja/OrcaSlicer_ja.po b/localization/i18n/ja/OrcaSlicer_ja.po index 6620b6e96f..fbd1445834 100644 --- a/localization/i18n/ja/OrcaSlicer_ja.po +++ b/localization/i18n/ja/OrcaSlicer_ja.po @@ -2665,7 +2665,7 @@ msgstr "フロー" msgid "Layer Time: " msgstr "積層時間" -msgid "Fan Speed: " +msgid "Fan: " msgstr "ファン回転速度" msgid "Temperature: " diff --git a/localization/i18n/ko/OrcaSlicer_ko.po b/localization/i18n/ko/OrcaSlicer_ko.po index f0b18c24ac..170c8ee7ac 100644 --- a/localization/i18n/ko/OrcaSlicer_ko.po +++ b/localization/i18n/ko/OrcaSlicer_ko.po @@ -2708,7 +2708,7 @@ msgstr "유량: " msgid "Layer Time: " msgstr "레이어 시간: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "팬 속도: " msgid "Temperature: " diff --git a/localization/i18n/nl/OrcaSlicer_nl.po b/localization/i18n/nl/OrcaSlicer_nl.po index 39201f0aae..3d35d7c4a0 100644 --- a/localization/i18n/nl/OrcaSlicer_nl.po +++ b/localization/i18n/nl/OrcaSlicer_nl.po @@ -2769,7 +2769,7 @@ msgstr "Flow: " msgid "Layer Time: " msgstr "Laagtijd:" -msgid "Fan Speed: " +msgid "Fan: " msgstr "Ventilatorsnelheid:" msgid "Temperature: " diff --git a/localization/i18n/ru/OrcaSlicer_ru.po b/localization/i18n/ru/OrcaSlicer_ru.po index e58ccd90e5..b8028f6a58 100644 --- a/localization/i18n/ru/OrcaSlicer_ru.po +++ b/localization/i18n/ru/OrcaSlicer_ru.po @@ -2783,7 +2783,7 @@ msgstr "Поток: " msgid "Layer Time: " msgstr "Время печати слоя: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Скорость вентилятора: " msgid "Temperature: " diff --git a/localization/i18n/sv/OrcaSlicer_sv.po b/localization/i18n/sv/OrcaSlicer_sv.po index b519e84814..c2ee461abe 100644 --- a/localization/i18n/sv/OrcaSlicer_sv.po +++ b/localization/i18n/sv/OrcaSlicer_sv.po @@ -2738,7 +2738,7 @@ msgstr "Flöde: " msgid "Layer Time: " msgstr "Lager Tid: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Fläkthastighet: " msgid "Temperature: " diff --git a/localization/i18n/uk/OrcaSlicer_uk.po b/localization/i18n/uk/OrcaSlicer_uk.po index a168bf53ca..c6483d4dee 100644 --- a/localization/i18n/uk/OrcaSlicer_uk.po +++ b/localization/i18n/uk/OrcaSlicer_uk.po @@ -2768,7 +2768,7 @@ msgstr "Потік: " msgid "Layer Time: " msgstr "Час шару: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "Швидкість вентилятора: " msgid "Temperature: " diff --git a/localization/i18n/zh_TW/OrcaSlicer_zh_TW.po b/localization/i18n/zh_TW/OrcaSlicer_zh_TW.po index 10378445f0..3e95090571 100644 --- a/localization/i18n/zh_TW/OrcaSlicer_zh_TW.po +++ b/localization/i18n/zh_TW/OrcaSlicer_zh_TW.po @@ -2641,7 +2641,7 @@ msgstr "擠出流量: " msgid "Layer Time: " msgstr "層時間: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "風扇速度: " msgid "Temperature: " diff --git a/localization/i18n/zh_cn/OrcaSlicer_zh_CN.po b/localization/i18n/zh_cn/OrcaSlicer_zh_CN.po index bbce30fe55..2a4fb0cc3d 100644 --- a/localization/i18n/zh_cn/OrcaSlicer_zh_CN.po +++ b/localization/i18n/zh_cn/OrcaSlicer_zh_CN.po @@ -2641,7 +2641,7 @@ msgstr "挤出流量: " msgid "Layer Time: " msgstr "层时间: " -msgid "Fan Speed: " +msgid "Fan: " msgstr "风扇速度: " msgid "Temperature: " diff --git a/src/slic3r/GUI/3DScene.cpp b/src/slic3r/GUI/3DScene.cpp index 06fec07eea..e4b9030aa6 100644 --- a/src/slic3r/GUI/3DScene.cpp +++ b/src/slic3r/GUI/3DScene.cpp @@ -1,3 +1,4 @@ +#include "slic3r/GUI/3DScene.hpp" #include #if ENABLE_SMOOTH_NORMALS @@ -1615,6 +1616,16 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig *con } } +void GLVolumeCollection::set_transparency(float alpha) +{ + for (GLVolume *volume : volumes) { + if (volume == nullptr || volume->is_modifier || volume->is_wipe_tower || (volume->volume_idx() < 0)) + continue; + + volume->color[3] = alpha; + } +} + std::vector GLVolumeCollection::get_current_print_zs(bool active_only) const { // Collect layer top positions of all volumes. diff --git a/src/slic3r/GUI/3DScene.hpp b/src/slic3r/GUI/3DScene.hpp index dcabb59946..c850884da8 100644 --- a/src/slic3r/GUI/3DScene.hpp +++ b/src/slic3r/GUI/3DScene.hpp @@ -714,6 +714,8 @@ public: size_t total_memory_used() const { return this->cpu_memory_used() + this->gpu_memory_used(); } // Return CPU, GPU and total memory log line. std::string log_memory_info() const; + + void set_transparency(float alpha); private: GLVolumeCollection(const GLVolumeCollection &other); diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index e67f27d30f..97c85990bf 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -77,7 +77,7 @@ static std::string get_view_type_string(GCodeViewer::EViewType view_type) return _u8L("Filament"); else if (view_type == GCodeViewer::EViewType::LayerTime) return _u8L("Layer Time"); - else if (view_type == GCodeViewer::EViewType::LayerTimeLog) +else if (view_type == GCodeViewer::EViewType::LayerTimeLog) return _u8L("Layer Time (log)"); return ""; } @@ -292,22 +292,22 @@ GCodeViewer::Color GCodeViewer::Extrusions::Range::get_color_at(float value) con } float GCodeViewer::Extrusions::Range::step_size() const { - if (log_scale) +if (log_scale) { float min_range = min; if (min_range == 0) min_range = 0.001f; return (std::log(max / min_range) / (static_cast(Range_Colors.size()) - 1.0f)); } else - return (max - min) / (static_cast(Range_Colors.size()) - 1.0f); + return (max - min) / (static_cast(Range_Colors.size()) - 1.0f); } float GCodeViewer::Extrusions::Range::get_value_at_step(int step) const { if (!log_scale) return min + static_cast(step) * step_size(); else - return std::exp(std::log(min) + static_cast(step) * step_size()); - + return std::exp(std::log(min) + static_cast(step) * step_size()); + } GCodeViewer::SequentialRangeCap::~SequentialRangeCap() { if (ibo > 0) @@ -327,7 +327,7 @@ void GCodeViewer::SequentialRangeCap::reset() { void GCodeViewer::SequentialView::Marker::init(std::string filename) { if (filename.empty()) { - //m_model.init_from(stilized_arrow(16, 1.5f, 3.0f, 0.8f, 3.0f)); + m_model.init_from(stilized_arrow(16, 1.5f, 3.0f, 0.8f, 3.0f)); } else { m_model.init_from_file(filename); } @@ -399,73 +399,73 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he std::string speed = ImGui::ColorMarkerStart + _u8L("Speed: ") + ImGui::ColorMarkerEnd; std::string flow = ImGui::ColorMarkerStart + _u8L("Flow: ") + ImGui::ColorMarkerEnd; std::string layer_time = ImGui::ColorMarkerStart + _u8L("Layer Time: ") + ImGui::ColorMarkerEnd; - std::string fanspeed = ImGui::ColorMarkerStart + _u8L("Fan Speed: ") + ImGui::ColorMarkerEnd; + std::string fanspeed = ImGui::ColorMarkerStart + _u8L("Fan: ") + ImGui::ColorMarkerEnd; std::string temperature = ImGui::ColorMarkerStart + _u8L("Temperature: ") + ImGui::ColorMarkerEnd; const float item_size = imgui.calc_text_size("X: 000.000 ").x; const float item_spacing = imgui.get_item_spacing().x; const float window_padding = ImGui::GetStyle().WindowPadding.x; char buf[1024]; - if (view_type == EViewType::Height || - view_type == EViewType::Width || - view_type == EViewType::Feedrate || - view_type == EViewType::VolumetricRate || - view_type == EViewType::LayerTime || - view_type == EViewType::LayerTimeLog || - view_type == EViewType::FanSpeed || - view_type == EViewType::Temperature) + if (true) { + float startx2 = window_padding + item_size + item_spacing; + float startx3 = window_padding + 2*(item_size + item_spacing); sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x()); ImGui::PushItemWidth(item_size); imgui.text(buf); - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y()); ImGui::PushItemWidth(item_size); imgui.text(buf); + ImGui::SameLine(startx3); sprintf(buf, "%s%.3f", z.c_str(), position.z()); ImGui::PushItemWidth(item_size); imgui.text(buf); + sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); + ImGui::PushItemWidth(item_size); + imgui.text(buf); + switch (view_type) { case EViewType::Height: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.2f", height.c_str(), m_curr_move.height); ImGui::PushItemWidth(item_size); imgui.text(buf); break; } case EViewType::Width: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.2f", width.c_str(), m_curr_move.width); ImGui::PushItemWidth(item_size); imgui.text(buf); break; } - case EViewType::Feedrate: { - ImGui::SameLine(window_padding + item_size + item_spacing); - sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); - ImGui::PushItemWidth(item_size); - imgui.text(buf); - break; - } + // case EViewType::Feedrate: { + // ImGui::SameLine(startx2); + // sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); + // ImGui::PushItemWidth(item_size); + // imgui.text(buf); + // break; + // } case EViewType::VolumetricRate: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.2f", flow.c_str(), m_curr_move.volumetric_rate()); ImGui::PushItemWidth(item_size); imgui.text(buf); break; } case EViewType::FanSpeed: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.0f", fanspeed.c_str(), m_curr_move.fan_speed); ImGui::PushItemWidth(item_size); imgui.text(buf); break; } case EViewType::Temperature: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.0f", temperature.c_str(), m_curr_move.temperature); ImGui::PushItemWidth(item_size); imgui.text(buf); @@ -473,7 +473,7 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he } case EViewType::LayerTime: case EViewType::LayerTimeLog: { - ImGui::SameLine(window_padding + item_size + item_spacing); + ImGui::SameLine(startx2); sprintf(buf, "%s%.1f", layer_time.c_str(), m_curr_move.layer_duration); ImGui::PushItemWidth(item_size); imgui.text(buf); @@ -484,27 +484,20 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he } text_line = 2; } - else { - sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x()); - ImGui::PushItemWidth(item_size); - imgui.text(buf); + // else { + // sprintf(buf, "%s%.3f", x.c_str(), position.x() - plate->get_origin().x()); + // imgui.text(buf); - ImGui::SameLine(window_padding + item_size + item_spacing); - sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y()); - ImGui::PushItemWidth(item_size); - imgui.text(buf); + // ImGui::SameLine(); + // sprintf(buf, "%s%.3f", y.c_str(), position.y() - plate->get_origin().y()); + // imgui.text(buf); - sprintf(buf, "%s%.3f", z.c_str(), position.z()); - ImGui::PushItemWidth(item_size); - imgui.text(buf); - - ImGui::SameLine(window_padding + item_size + item_spacing); - sprintf(buf, "%s%.0f", speed.c_str(), m_curr_move.feedrate); - ImGui::PushItemWidth(item_size); - imgui.text(buf); + // ImGui::SameLine(); + // sprintf(buf, "%s%.3f", z.c_str(), position.z()); + // imgui.text(buf); - text_line = 1; - } + // text_line = 1; + // } // force extra frame to automatically update window size float window_width = ImGui::GetWindowWidth(); @@ -553,19 +546,22 @@ void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& fil void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, float right, uint64_t curr_line_id) const //void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, uint64_t curr_line_id) const { + // Orca: truncate long lines(>55 characters), add "..." at the end auto update_lines = [this](uint64_t start_id, uint64_t end_id) { std::vector ret; ret.reserve(end_id - start_id + 1); for (uint64_t id = start_id; id <= end_id; ++id) { // read line from file - const size_t start = id == 1 ? 0 : m_lines_ends[id - 2]; - const size_t len = m_lines_ends[id - 1] - start; - std::string gline(m_file.data() + start, len); + const size_t start = id == 1 ? 0 : m_lines_ends[id - 2]; + const size_t original_len = m_lines_ends[id - 1] - start; + const size_t len = std::min(original_len, (size_t) 55); + std::string gline(m_file.data() + start, len); - std::string command; - std::string parameters; - std::string comment; + // If original line is longer than 55 characters, truncate and append "..." + if (original_len > 55) + gline = gline.substr(0, 52) + "..."; + std::string command, parameters, comment; // extract comment std::vector tokens; boost::split(tokens, gline, boost::is_any_of(";"), boost::token_compress_on); @@ -583,7 +579,7 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, f } } } - ret.push_back({ command, parameters, comment }); + ret.push_back({command, parameters, comment}); } return ret; }; @@ -717,11 +713,11 @@ void GCodeViewer::SequentialView::GCodeWindow::stop_mapping_file() BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": finished mapping file " << m_filename; } } -//BBS: GUI refactor: move to the right -void GCodeViewer::SequentialView::render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const +void GCodeViewer::SequentialView::render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const { - if (has_render_path) - marker.render(canvas_width, canvas_height, view_type); +if (has_render_path) + marker.render(canvas_width, canvas_height, view_type); + //float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); // BBS #if 0 @@ -729,8 +725,7 @@ void GCodeViewer::SequentialView::render(const bool has_render_path, float legen bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); #endif if (has_render_path) - gcode_window.render(legend_height + 2, std::max(10.f, (float)canvas_height - 40), (float)canvas_width, - static_cast(gcode_ids[current.last])); + gcode_window.render(legend_height + 2, std::max(10.f, (float)canvas_height - 40), (float)canvas_width - (float)right_margin, static_cast(gcode_ids[current.last])); } const std::vector GCodeViewer::Extrusion_Role_Colors {{ @@ -938,7 +933,7 @@ void GCodeViewer::update_by_mode(ConfigOptionMode mode) view_type_items.push_back(EViewType::Width); view_type_items.push_back(EViewType::VolumetricRate); view_type_items.push_back(EViewType::LayerTime); - view_type_items.push_back(EViewType::LayerTimeLog); +view_type_items.push_back(EViewType::LayerTimeLog); view_type_items.push_back(EViewType::FanSpeed); view_type_items.push_back(EViewType::Temperature); if (mode == ConfigOptionMode::comDevelop) { @@ -1000,10 +995,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_gcode_result = &gcode_result; m_only_gcode_in_preview = only_gcode; - m_sequential_view.gcode_window.load_gcode(gcode_result.filename, - // Stealing out lines_ends should be safe because this gcode_result is - // processed only once (see the 1st if in this function). - std::move(const_cast &>(gcode_result.lines_ends))); + m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends); //BBS: add only gcode mode //if (wxGetApp().is_gcode_viewer()) @@ -1023,7 +1015,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr m_settings_ids = gcode_result.settings_ids; m_filament_diameters = gcode_result.filament_diameters; m_filament_densities = gcode_result.filament_densities; - m_sequential_view.m_show_gcode_window = false; +m_sequential_view.m_show_gcode_window = false; //BBS: always load shell at preview /*if (wxGetApp().is_editor()) @@ -1161,6 +1153,9 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v for (auto item : m_tools.m_tool_visibles) item = true; } + for (int i = 0; i < m_tools.m_tool_colors.size(); i++) { + m_tools.m_tool_colors[i] = adjust_color_for_rendering(m_tools.m_tool_colors[i]); + } // ensure there are enough colors defined while (m_tools.m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) { m_tools.m_tool_colors.push_back(decode_color("#FF8000")); @@ -1186,10 +1181,10 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v m_extrusions.ranges.temperature.update_from(curr.temperature); if (curr.extrusion_role != erCustom || is_visible(erCustom)) m_extrusions.ranges.volumetric_rate.update_from(round_to_bin(curr.volumetric_rate())); - + if (curr.layer_duration > 0.f) { m_extrusions.ranges.layer_duration.update_from(curr.layer_duration); - m_extrusions.ranges.layer_duration_log.update_from(curr.layer_duration); +m_extrusions.ranges.layer_duration_log.update_from(curr.layer_duration); } [[fallthrough]]; } @@ -1221,12 +1216,14 @@ void GCodeViewer::refresh_render_paths() refresh_render_paths(false, false); } -void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* config) +void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig *config) { if (config != nullptr) - m_shells.volumes.update_colors_by_extruder(config); + m_shells.volumes.update_colors_by_extruder(config, false); } +void GCodeViewer::set_shell_transparency(float alpha) { m_shells.volumes.set_transparency(alpha); } + //BBS: always load shell at preview void GCodeViewer::reset_shell() { @@ -1281,15 +1278,15 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) m_statistics.total_instances_gpu_size = 0; #endif // ENABLE_GCODE_VIEWER_STATISTICS - //BBS: always render shells in preview window render_shells(); + // Orca: add shell overlay effect + glsafe(::glClear(GL_DEPTH_BUFFER_BIT)); if (m_roles.empty()) return; - glsafe(::glEnable(GL_DEPTH_TEST)); + render_toolpaths(); - //render_shells(); float legend_height = 0.0f; render_legend(legend_height, canvas_width, canvas_height, right_margin); @@ -1299,7 +1296,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) } //BBS fixed bottom_margin for space to render horiz slider - int bottom_margin = 64; + int bottom_margin = 39; m_sequential_view.m_show_gcode_window = m_sequential_view.m_show_gcode_window || (m_sequential_view.current.last != m_sequential_view.endpoints.last && !m_no_render_path); @@ -1307,7 +1304,7 @@ void GCodeViewer::render(int canvas_width, int canvas_height, int right_margin) m_sequential_view.marker.set_world_position(m_sequential_view.current_position); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); //BBS fixed buttom margin. m_moves_slider.pos_y - m_sequential_view.render(!m_no_render_path, legend_height, canvas_width - right_margin * m_scale, canvas_height - bottom_margin * m_scale, m_view_type); + m_sequential_view.render(!m_no_render_path, legend_height, canvas_width, canvas_height - bottom_margin * m_scale, right_margin * m_scale, m_view_type); } #if ENABLE_GCODE_VIEWER_STATISTICS render_statistics(); @@ -3099,10 +3096,10 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result, const m_extruder_ids.shrink_to_fit(); std::vector plater_extruder; - for (auto mid : m_extruder_ids){ + for (auto mid : m_extruder_ids){ int eid = mid; plater_extruder.push_back(++eid); - } + } m_plater_extruder = plater_extruder; // replace layers for spiral vase mode @@ -3426,10 +3423,10 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool // update current sequential position sequential_view->current.first = !top_layer_only && keep_sequential_current_first ? std::clamp(sequential_view->current.first, global_endpoints.first, global_endpoints.last) : global_endpoints.first; if (global_endpoints.last == 0) { - m_no_render_path = true; +m_no_render_path = true; sequential_view->current.last = global_endpoints.last; } else { - m_no_render_path = false; +m_no_render_path = false; sequential_view->current.last = keep_sequential_current_last ? std::clamp(sequential_view->current.last, global_endpoints.first, global_endpoints.last) : global_endpoints.last; } @@ -3840,7 +3837,7 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GCODE_VIEWER_STATISTICS this #endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { + ](std::vector::reverse_iterator it_path, std::vector::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) { glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_POINT_SPRITE)); @@ -3867,7 +3864,7 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GCODE_VIEWER_STATISTICS this #endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { + ](std::vector::reverse_iterator it_path, std::vector::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) { for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { const RenderPath& path = *it; // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. @@ -3885,7 +3882,7 @@ void GCodeViewer::render_toolpaths() #if ENABLE_GCODE_VIEWER_STATISTICS this #endif // ENABLE_GCODE_VIEWER_STATISTICS - ](std::vector::iterator it_path, std::vector::iterator it_end, GLShaderProgram& shader, int uniform_color) { + ](std::vector::reverse_iterator it_path, std::vector::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) { for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) { const RenderPath& path = *it; // Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415. @@ -4015,13 +4012,15 @@ void GCodeViewer::render_toolpaths() default: break; } int uniform_color = shader->get_uniform_location("uniform_color"); - auto it_path = buffer.render_paths.begin(); + auto it_path = buffer.render_paths.rbegin(); //BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(":buffer indices size %1%, render_path size %2% ")%buffer.indices.size() %buffer.render_paths.size(); - for (unsigned int ibuffer_id = 0; ibuffer_id < static_cast(buffer.indices.size()); ++ibuffer_id) { + unsigned int indices_count = static_cast(buffer.indices.size()); + for (unsigned int index = 0; index < indices_count; ++index) { + unsigned int ibuffer_id = indices_count - index - 1; const IBuffer& i_buffer = buffer.indices[ibuffer_id]; // Skip all paths with ibuffer_id < ibuffer_id. - for (; it_path != buffer.render_paths.end() && it_path->ibuffer_id < ibuffer_id; ++ it_path) ; - if (it_path == buffer.render_paths.end() || it_path->ibuffer_id > ibuffer_id) + for (; it_path != buffer.render_paths.rend() && it_path->ibuffer_id > ibuffer_id; ++ it_path) ; + if (it_path == buffer.render_paths.rend() || it_path->ibuffer_id < ibuffer_id) // Not found. This shall not happen. continue; @@ -4040,16 +4039,16 @@ void GCodeViewer::render_toolpaths() switch (buffer.render_primitive_type) { case TBuffer::ERenderPrimitiveType::Point: { - render_as_points(it_path, buffer.render_paths.end(), *shader, uniform_color); + render_as_points(it_path, buffer.render_paths.rend(), *shader, uniform_color); break; } case TBuffer::ERenderPrimitiveType::Line: { glsafe(::glLineWidth(static_cast(line_width(zoom)))); - render_as_lines(it_path, buffer.render_paths.end(), *shader, uniform_color); + render_as_lines(it_path, buffer.render_paths.rend(), *shader, uniform_color); break; } case TBuffer::ERenderPrimitiveType::Triangle: { - render_as_triangles(it_path, buffer.render_paths.end(), *shader, uniform_color); + render_as_triangles(it_path, buffer.render_paths.rend(), *shader, uniform_color); break; } default: { break; } @@ -4172,6 +4171,10 @@ void GCodeViewer::render_all_plates_stats(const std::vector filament_densities = gcode_result_list.front()->filament_densities; std::vector filament_colors = decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back())); + for (int i = 0; i < filament_colors.size(); i++) { + filament_colors[i] = adjust_color_for_rendering(filament_colors[i]); + } + bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; float window_padding = 4.0f * m_scale; const float icon_size = ImGui::GetTextLineHeight() * 0.7; @@ -4315,18 +4318,20 @@ void GCodeViewer::render_all_plates_stats(const std::vectorfirst + 1), offsets[0] }); char buf[64]; + double unit_conver = imperial_units ? GizmoObjectManipulation::oz_to_g : 1.0; if (show_detailed_statistics_page) { - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] / unit_conver); columns_offsets.push_back({ buf, offsets[1] }); - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m_all_plates[i], flushed_filaments_g_all_plates[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m_all_plates[i], flushed_filaments_g_all_plates[i] / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m_all_plates[i] + flushed_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] + flushed_filaments_g_all_plates[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (model_used_filaments_m_all_plates[i] + flushed_filaments_m_all_plates[i]), + (model_used_filaments_g_all_plates[i] + flushed_filaments_g_all_plates[i]) / unit_conver); columns_offsets.push_back({ buf, offsets[3] }); } else { - ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i]); + ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m_all_plates[i], model_used_filaments_g_all_plates[i] / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); } @@ -4420,7 +4425,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv default: case EItemType::Rect: { draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale }, - ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f })); + ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f })); break; } case EItemType::Circle: { @@ -4949,7 +4954,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv columns_offsets.push_back({ std::to_string(extruder_idx + 1), offsets[0] }); char buf[64]; - ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[0] , model_used_filaments_g[0]); + ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[0], model_used_filaments_g[0] / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); append_item(EItemType::Rect, m_tools.m_tool_colors[extruder_idx], columns_offsets, false); @@ -4983,19 +4988,20 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv char buf[64]; if (show_flushed_filaments) { - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i], model_used_filaments_g[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i], model_used_filaments_g[i] / unit_conver); columns_offsets.push_back({ buf, offsets[1] }); - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m[i], flushed_filaments_g[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", flushed_filaments_m[i], flushed_filaments_g[i] / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", model_used_filaments_m[i] + flushed_filaments_m[i], model_used_filaments_g[i] + flushed_filaments_g[i]); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (model_used_filaments_m[i] + flushed_filaments_m[i]), + (model_used_filaments_g[i] + flushed_filaments_g[i]) / unit_conver); columns_offsets.push_back({ buf, offsets[3] }); } else { char buf[64]; - ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[i], model_used_filaments_g[i]); - columns_offsets.push_back({ buf, offsets[2] }); + ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", model_used_filaments_m[i], model_used_filaments_g[i] / unit_conver); + columns_offsets.push_back({buf, offsets[2]}); } append_item(EItemType::Rect, m_tools.m_tool_colors[extruder_idx], columns_offsets, false, filament_visible, [this, extruder_idx]() { @@ -5044,20 +5050,20 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv std::vector> columns_offsets; columns_offsets.push_back({ _u8L("Total"), offsets[0] }); if (!show_flushed_filaments) { - ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", total_model_used_filament_m, total_model_used_filament_g); + ::sprintf(buf, imperial_units ? "%.2f in %.2f oz" : "%.2f m %.2f g", total_model_used_filament_m, total_model_used_filament_g / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets); } else { - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m, total_model_used_filament_g); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m, total_model_used_filament_g / unit_conver); columns_offsets.push_back({ buf, offsets[1] }); - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_flushed_filament_m, total_flushed_filament_g); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_flushed_filament_m, total_flushed_filament_g / unit_conver); columns_offsets.push_back({ buf, offsets[2] }); bool imperial_units = wxGetApp().app_config->get("use_inches") == "1"; - ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", (total_model_used_filament_m + total_flushed_filament_m) * 1000 / /*1000*/koef, (total_model_used_filament_g + total_flushed_filament_g) / unit_conver); + ::sprintf(buf, imperial_units ? "%.2f in\n%.2f oz" : "%.2f m\n%.2f g", total_model_used_filament_m + total_flushed_filament_m, (total_model_used_filament_g + total_flushed_filament_g) / unit_conver); columns_offsets.push_back({ buf, offsets[3] }); append_item(EItemType::None, m_tools.m_tool_colors[0], columns_offsets); @@ -5712,3 +5718,4 @@ GCodeViewer::Color GCodeViewer::option_color(EMoveType move_type) const } // namespace GUI } // namespace Slic3r + diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index d66c136c82..5b8cd0ebb8 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -408,7 +408,7 @@ class GCodeViewer min = std::min(min, value); max = std::max(max, value); } - void reset(bool log = false) { min = FLT_MAX; max = -FLT_MAX; count = 0; log_scale = false; log_scale = log; } + void reset(bool log = false) { min = FLT_MAX; max = -FLT_MAX; count = 0; log_scale = log; } float step_size() const; Color get_color_at(float value) const; @@ -432,7 +432,7 @@ class GCodeViewer Range temperature; // Color mapping by layer time. Range layer_duration; - Range layer_duration_log; +Range layer_duration_log; void reset() { height.reset(); width.reset(); @@ -492,7 +492,7 @@ class GCodeViewer std::vector& get_endpoints() { return m_endpoints; } double get_z_at(unsigned int id) const { return (id < m_zs.size()) ? m_zs[id] : 0.0; } Endpoints get_endpoints_at(unsigned int id) const { return (id < m_endpoints.size()) ? m_endpoints[id] : Endpoints(); } - int get_l_at(double z) const + int get_l_at(float z) const { auto iter = std::upper_bound(m_zs.begin(), m_zs.end(), z); return std::distance(m_zs.begin(), iter); @@ -640,7 +640,6 @@ public: bool is_visible() const { return m_visible; } void set_visible(bool visible) { m_visible = visible; } - //BBS: GUI refactor: add canvas size void render(int canvas_width, int canvas_height, const EViewType& view_type) const; void on_change_color_mode(bool is_dark) { m_is_dark = is_dark; } @@ -708,8 +707,7 @@ public: std::vector gcode_ids; float m_scale = 1.0; bool m_show_gcode_window = false; - //BBS: GUI refactor: add canvas size - void render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const; + void render(const bool has_render_path, float legend_height, int canvas_width, int canvas_height, int right_margin, const EViewType& view_type) const; }; struct ETools @@ -737,7 +735,6 @@ public: //BBS ConflictResultOpt m_conflict_result; - private: std::vector m_plater_extruder; bool m_gl_data_initialized{ false }; @@ -795,7 +792,7 @@ private: std::vector m_custom_gcode_per_print_z; bool m_contained_in_bed{ true }; - mutable bool m_no_render_path { false }; +mutable bool m_no_render_path { false }; bool m_is_dark = false; public: @@ -816,6 +813,7 @@ public: void refresh(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors); void refresh_render_paths(); void update_shells_color_by_extruder(const DynamicPrintConfig* config); + void set_shell_transparency(float alpha = 0.15f); void reset(); //BBS: always load shell at preview diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 29aeb064c6..2b16986016 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -17,6 +17,7 @@ #include "slic3r/GUI/3DBed.hpp" #include "slic3r/GUI/3DScene.hpp" #include "slic3r/GUI/BackgroundSlicingProcess.hpp" +#include "slic3r/GUI/GLCanvas3D.hpp" #include "slic3r/GUI/GLShader.hpp" #include "slic3r/GUI/GUI.hpp" #include "slic3r/GUI/Tab.hpp" @@ -2753,7 +2754,6 @@ static void reserve_new_volume_finalize_old_volume(GLVolume& vol_new, GLVolume& vol_old.finalize_geometry(gl_initialized); } -//BBS: always load shell at preview void GLCanvas3D::load_shells(const Print& print, bool force_previewing) { if (m_initialized) @@ -2763,6 +2763,10 @@ void GLCanvas3D::load_shells(const Print& print, bool force_previewing) } } +void GLCanvas3D::set_shell_transparence(float alpha){ + m_gcode_viewer.set_shell_transparency(alpha); + +} //BBS: add only gcode mode void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector& str_tool_colors, bool only_gcode) { diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 5f3983494c..fe99626e57 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -900,7 +900,8 @@ public: void mirror_selection(Axis axis); void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false); - //BBS: always load shell at preview + //Orca: shell preview improvement + void set_shell_transparence(float alpha = 0.2f); void load_shells(const Print& print, bool force_previewing = false); void reset_shells() { m_gcode_viewer.reset_shell(); } void set_shells_on_previewing(bool is_preview) { m_gcode_viewer.set_shells_on_preview(is_preview); } diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index d92d99dd72..7489640ef9 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -717,8 +717,9 @@ void Preview::load_print_as_fff(bool keep_z_range, bool only_gcode) //BBS show sliders show_moves_sliders(); - //BBS: turn off shells for preview - m_canvas->set_shells_on_previewing(false); + //Orca: keep shell preview on but make it more transparent + m_canvas->set_shells_on_previewing(true); + m_canvas->set_shell_transparence(); Refresh(); zs = m_canvas->get_gcode_layers_zs(); //BBS: add m_loaded_print logic