From 98c5eed4a67f17f6bd78148191b5d242ef80b60e Mon Sep 17 00:00:00 2001 From: harrierpigeon Date: Mon, 5 Oct 2026 14:19:53 -0500 Subject: [PATCH] Preview: reuse a belt print's toolpaths until the view is toggled load_as_gcode() skips the conversion and GPU upload when it is handed the result it already shows, but belt printers were exempt from that cache, because the designed/raw view changes the toolpath geometry for the same result. So every preview reload of a belt print, switching back to the Preview tab for one, converted and uploaded every toolpath again. Remember the view the result was converted for and reuse it while both match. Toggling the view (B, the legend checkbox, the toolbar menu) still converts again. The print config the back-transform reads cannot change without a new G-code result, so the result id covers it as it does on any other printer. Suggested by raistlin7447 on #14394. --- src/slic3r/GUI/GCodeViewer.cpp | 11 ++++++----- src/slic3r/GUI/GCodeViewer.hpp | 2 ++ src/slic3r/GUI/GUI_Preview.cpp | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 03fcb8699d..c886b7d65a 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1390,11 +1390,11 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const m_viewer.set_dim_previous_layers_brightness(0.01f * std::stoi(get_app_config()->get("preview_dim_previous_layers_brightness"))); // avoid processing if called with the same gcode_result. - // Belt printers are exempt: the toolpath geometry fed to libvgcode depends on - // the current designed/raw view state (back-transform applied in convert), so - // re-running the conversion is required for the upright view and for toggling - // it (hotkey B) to take effect even when the G-code itself is unchanged. - if (m_last_result_id == gcode_result.id && wxGetApp().is_editor() && !print.config().belt_printer.value) { + // On a belt printer the toolpath geometry fed to libvgcode also depends on the + // designed/raw view state (the back-transform is applied in convert), so the + // same result is converted again only when that view has been toggled. + const bool same_belt_view = !print.config().belt_printer.value || m_last_belt_show_designed == m_belt_show_designed; + if (m_last_result_id == gcode_result.id && wxGetApp().is_editor() && same_belt_view) { //BBS: add logs BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": the same id %1%, return directly, result %2% ") % m_last_result_id % (&gcode_result); @@ -1688,6 +1688,7 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const //BBS: move the id to the end of reset m_last_result_id = gcode_result.id; + m_last_belt_show_designed = m_belt_show_designed; m_gcode_result = &gcode_result; m_move_type_counts.fill(0); for (auto& move_type_times : m_move_type_times) diff --git a/src/slic3r/GUI/GCodeViewer.hpp b/src/slic3r/GUI/GCodeViewer.hpp index 656d719130..06d275a187 100644 --- a/src/slic3r/GUI/GCodeViewer.hpp +++ b/src/slic3r/GUI/GCodeViewer.hpp @@ -199,6 +199,8 @@ private: std::vector m_plater_extruder; bool m_gl_data_initialized{ false }; unsigned int m_last_result_id{ 0 }; + // Belt printers: the view the loaded result was converted for (see load_as_gcode). + bool m_last_belt_show_designed{ true }; //BBS: save m_gcode_result as well const GCodeProcessorResult* m_gcode_result; std::array(EMoveType::Count)> m_move_type_counts{}; diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 3a174c2aac..f52bd20cc2 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -373,7 +373,7 @@ void Preview::refresh_belt_view() { // Re-run the G-code preview conversion so the belt "designed view" toggle takes effect // (the back-transform is baked into the toolpath geometry in GCodeViewer::load_as_gcode, - // and belt printers are exempt from the same-result-id load cache so the re-convert runs). + // whose same-result cache also keys on the view state, so the re-convert runs). // Reset m_loaded_print to bypass the "already loaded" guard the way reload_print does, but // keep the current layer (Z) range and only-gcode mode so the view doesn't jump on toggle. m_loaded_print = nullptr;