Skip to content

Commit

Permalink
fix gcode viewer refresh when selecting travel moves
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jun 4, 2024
1 parent d7be50b commit 2af5a9e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2264,10 +2264,12 @@ bool GLCanvas3D::is_gcode_preview_dirty(const GCodeProcessorResult& gcode_result
return last_showned_gcode != gcode_result.computed_timestamp;
}

void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors)
void GLCanvas3D::load_gcode_preview(const GCodeProcessorResult &gcode_result,
const std::vector<std::string> &str_tool_colors,
bool force_gcode_color_recompute)
{
if (last_showned_gcode != gcode_result.computed_timestamp
|| !m_gcode_viewer.is_loaded(gcode_result)) {
if (last_showned_gcode != gcode_result.computed_timestamp || force_gcode_color_recompute ||
!m_gcode_viewer.is_loaded(gcode_result)) {
last_showned_gcode = gcode_result.computed_timestamp;
m_gcode_viewer.load(gcode_result, *this->fff_print(), m_initialized);

Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/GLCanvas3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class GLCanvas3D

void reload_scene(bool refresh_immediately, bool force_full_scene_refresh = false);

void load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors);
void load_gcode_preview(const GCodeProcessorResult& gcode_result, const std::vector<std::string>& str_tool_colors, bool force_gcode_color_recompute = false);
void refresh_gcode_preview_render_paths();
void set_gcode_view_preview_type(GCodeViewer::EViewType type) { return m_gcode_viewer.set_view_type(type); }
GCodeViewer::EViewType get_gcode_view_preview_type() const { return m_gcode_viewer.get_view_type(); }
Expand Down
20 changes: 13 additions & 7 deletions src/slic3r/GUI/GUI_Preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,12 @@ void Preview::on_combochecklist_options(wxCommandEvent& evt)
m_canvas->set_gcode_options_visibility_from_flags(new_flags);
if (m_canvas->get_gcode_view_type() == GCodeViewer::EViewType::Feedrate) {
const unsigned int diff_flags = curr_flags ^ new_flags;
if ((diff_flags & (1 << static_cast<unsigned int>(Preview::OptionType::Travel))) != 0)
if ((diff_flags & (1 << static_cast<unsigned int>(Preview::OptionType::Travel))) != 0) {
m_force_gcode_color_recompute = true;
refresh_print();
else
} else {
m_canvas->refresh_gcode_preview_render_paths();
}
}
else
m_canvas->refresh_gcode_preview_render_paths();
Expand Down Expand Up @@ -924,13 +926,16 @@ void Preview::update_moves_slider()
alternate_values[count] = static_cast<double>(view.gcode_ids[i]);
++count;
}

// should the end of the horizontal slider stay at the end?
bool max_is_max = m_moves_slider->GetMaxValue() == m_moves_slider->GetHigherValue();
// update values
m_moves_slider->SetSliderValues(values);
m_moves_slider->SetSliderAlternateValues(alternate_values);
m_moves_slider->SetMaxValue(view.endpoints.last - view.endpoints.first);
m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first, view.current.last - view.endpoints.first);
m_moves_slider->Refresh();
m_moves_slider->Update();
m_moves_slider->SetSelectionSpan(view.current.first - view.endpoints.first,
max_is_max ? m_moves_slider->GetMaxValue() :
(view.current.last - view.endpoints.first));
m_moves_slider->fire_update_if_needed();
}

void Preview::enable_moves_slider(bool enable)
Expand Down Expand Up @@ -1038,7 +1043,8 @@ void Preview::load_print_as_fff(bool keep_z_range)
// Load the real G-code preview.
if (current_force_state == ForceState::NoForce)
m_canvas->set_items_show(false, true);
m_canvas->load_gcode_preview(*m_gcode_result, colors);
m_canvas->load_gcode_preview(*m_gcode_result, colors, m_force_gcode_color_recompute);
m_force_gcode_color_recompute = false;
m_left_sizer->Show(m_bottom_toolbar_panel);
m_left_sizer->Layout();
Refresh();
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GUI_Preview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class Preview : public wxTitledPanel
//fields to see what color to display
bool m_has_switched_to_color = false;
bool m_has_switched_to_extruders = false;
bool m_force_gcode_color_recompute = false;

bool m_loaded { false };

Expand Down

0 comments on commit 2af5a9e

Please sign in to comment.