Skip invisible moves when moving horizontal slider thumb in preview

This commit is contained in:
enricoturri1966 2020-10-07 13:19:44 +02:00
parent e9d6e6ac8f
commit 9e0e597284
3 changed files with 71 additions and 35 deletions

View file

@ -1021,8 +1021,7 @@ void Control::OnLeftDown(wxMouseEvent& event)
m_mouse = maOneLayerIconClick; m_mouse = maOneLayerIconClick;
else if (is_point_in_rect(pos, m_rect_cog_icon)) else if (is_point_in_rect(pos, m_rect_cog_icon))
m_mouse = maCogIconClick; m_mouse = maCogIconClick;
else if (m_draw_mode == dmRegular) else if (m_draw_mode == dmRegular) {
{
if (is_point_in_rect(pos, m_rect_tick_action)) { if (is_point_in_rect(pos, m_rect_tick_action)) {
auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value }); auto it = m_ticks.ticks.find(TickCode{ m_selection == ssLower ? m_lower_value : m_higher_value });
m_mouse = it == m_ticks.ticks.end() ? maAddTick : maDeleteTick; m_mouse = it == m_ticks.ticks.end() ? maAddTick : maDeleteTick;
@ -1267,8 +1266,8 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
for (int i = 1; i <= extruders_cnt; i++) for (int i = 1; i <= extruders_cnt; i++)
{ {
const bool is_active_extruder = i == active_extruders[0] || i == active_extruders[1]; const bool is_active_extruder = i == active_extruders[0] || i == active_extruders[1];
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) + const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
(is_active_extruder ? " (" + _(L("active")) + ")" : ""); (is_active_extruder ? " (" + _L("active") + ")" : "");
if (m_mode == MultiAsSingle) if (m_mode == MultiAsSingle)
append_menu_item(change_extruder_menu, wxID_ANY, item_name, "", append_menu_item(change_extruder_menu, wxID_ANY, item_name, "",
@ -1280,7 +1279,7 @@ void Control::append_change_extruder_menu_item(wxMenu* menu, bool switch_current
(switch_current_code ? _L("Switch code to Change extruder") : _L("Change extruder") ) : (switch_current_code ? _L("Switch code to Change extruder") : _L("Change extruder") ) :
_L("Change extruder (N/A)"); _L("Change extruder (N/A)");
wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _(L("Use another extruder"))); wxMenuItem* change_extruder_menu_item = menu->AppendSubMenu(change_extruder_menu, change_extruder_menu_name, _L("Use another extruder"));
change_extruder_menu_item->SetBitmap(create_scaled_bitmap(active_extruders[1] > 0 ? "edit_uni" : "change_extruder")); change_extruder_menu_item->SetBitmap(create_scaled_bitmap(active_extruders[1] > 0 ? "edit_uni" : "change_extruder"));
GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) { GUI::wxGetApp().plater()->Bind(wxEVT_UPDATE_UI, [this, change_extruder_menu_item](wxUpdateUIEvent& evt) {
@ -1303,8 +1302,8 @@ void Control::append_add_color_change_menu_item(wxMenu* menu, bool switch_curren
{ {
const bool is_used_extruder = used_extruders_for_tick.empty() ? true : // #ys_FIXME till used_extruders_for_tick doesn't filled correct for mmMultiExtruder const bool is_used_extruder = used_extruders_for_tick.empty() ? true : // #ys_FIXME till used_extruders_for_tick doesn't filled correct for mmMultiExtruder
used_extruders_for_tick.find(i) != used_extruders_for_tick.end(); used_extruders_for_tick.find(i) != used_extruders_for_tick.end();
const wxString item_name = wxString::Format(_(L("Extruder %d")), i) + const wxString item_name = wxString::Format(_L("Extruder %d"), i) +
(is_used_extruder ? " (" + _(L("used")) + ")" : ""); (is_used_extruder ? " (" + _L("used") + ")" : "");
append_menu_item(add_color_change_menu, wxID_ANY, item_name, "", append_menu_item(add_color_change_menu, wxID_ANY, item_name, "",
[this, i](wxCommandEvent&) { add_code_as_tick(ColorChange, i); }, "", menu, [this, i](wxCommandEvent&) { add_code_as_tick(ColorChange, i); }, "", menu,
@ -1466,11 +1465,9 @@ void Control::OnKeyDown(wxKeyEvent &event)
else if (event.GetKeyCode() == WXK_SHIFT) else if (event.GetKeyCode() == WXK_SHIFT)
UseDefaultColors(false); UseDefaultColors(false);
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
else if (is_horizontal()) else if (is_horizontal()) {
{
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
if (m_is_focused) if (m_is_focused) {
{
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
if (key == WXK_LEFT || key == WXK_RIGHT) if (key == WXK_LEFT || key == WXK_RIGHT)
move_current_thumb(key == WXK_LEFT); move_current_thumb(key == WXK_LEFT);
@ -1481,11 +1478,10 @@ void Control::OnKeyDown(wxKeyEvent &event)
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
} }
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
} }
else { else {
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
if (m_is_focused) if (m_is_focused) {
{
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
if (key == WXK_LEFT || key == WXK_RIGHT) { if (key == WXK_LEFT || key == WXK_RIGHT) {
m_selection = key == WXK_LEFT ? ssHigher : ssLower; m_selection = key == WXK_LEFT ? ssHigher : ssLower;
@ -1704,18 +1700,18 @@ void Control::show_edit_context_menu()
append_add_color_change_menu_item(&menu, true); append_add_color_change_menu_item(&menu, true);
} }
else else
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Edit color")) : append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Edit color") :
it->type == PausePrint ? _(L("Edit pause print message")) : it->type == PausePrint ? _L("Edit pause print message") :
_(L("Edit custom G-code")), "", _L("Edit custom G-code"), "",
[this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu); [this](wxCommandEvent&) { edit_tick(); }, "edit_uni", &menu);
if (it->type == ColorChange && m_mode == MultiAsSingle) if (it->type == ColorChange && m_mode == MultiAsSingle)
append_change_extruder_menu_item(&menu, true); append_change_extruder_menu_item(&menu, true);
append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _(L("Delete color change")) : append_menu_item(&menu, wxID_ANY, it->type == ColorChange ? _L("Delete color change") :
it->type == ToolChange ? _(L("Delete tool change")) : it->type == ToolChange ? _L("Delete tool change") :
it->type == PausePrint ? _(L("Delete pause print")) : it->type == PausePrint ? _L("Delete pause print") :
_(L("Delete custom G-code")), "", _L("Delete custom G-code"), "",
[this](wxCommandEvent&) { delete_current_tick();}, "colorchange_del_f", &menu); [this](wxCommandEvent&) { delete_current_tick();}, "colorchange_del_f", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu); GUI::wxGetApp().plater()->PopupMenu(&menu);
@ -1725,14 +1721,14 @@ void Control::show_cog_icon_context_menu()
{ {
wxMenu menu; wxMenu menu;
append_menu_item(&menu, wxID_ANY, _(L("Jump to height")) + " (Shift+G)", "", append_menu_item(&menu, wxID_ANY, _L("Jump to height") + " (Shift+G)", "",
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
[this](wxCommandEvent&) { jump_to_value(); }, "", & menu); [this](wxCommandEvent&) { jump_to_value(); }, "", & menu);
#else #else
[this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu); [this](wxCommandEvent&) { jump_to_print_z(); }, "", &menu);
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER
append_menu_item(&menu, wxID_ANY, _(L("Set extruder sequence for the entire print")), "", append_menu_item(&menu, wxID_ANY, _L("Set extruder sequence for the entire print"), "",
[this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu); [this](wxCommandEvent&) { edit_extruder_sequence(); }, "", &menu);
GUI::wxGetApp().plater()->PopupMenu(&menu); GUI::wxGetApp().plater()->PopupMenu(&menu);
@ -1861,8 +1857,8 @@ static double get_print_z_to_jump(double active_print_z, double min_z, double ma
wxString msg_header = (mode == dmSequentialGCodeView) ? _L("Jump to move") : _L("Jump to height"); wxString msg_header = (mode == dmSequentialGCodeView) ? _L("Jump to move") : _L("Jump to height");
wxString msg_in = GUI::double_to_string(active_value); wxString msg_in = GUI::double_to_string(active_value);
#else #else
wxString msg_text = _(L("Enter the height you want to jump to")) + ":"; wxString msg_text = _L("Enter the height you want to jump to") + ":";
wxString msg_header = _(L("Jump to height")); wxString msg_header = _L("Jump to height");
wxString msg_in = GUI::double_to_string(active_print_z); wxString msg_in = GUI::double_to_string(active_print_z);
#endif // ENABLE_GCODE_VIEWER #endif // ENABLE_GCODE_VIEWER

View file

@ -495,6 +495,50 @@ void GCodeViewer::render() const
#endif // ENABLE_GCODE_VIEWER_STATISTICS #endif // ENABLE_GCODE_VIEWER_STATISTICS
} }
void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned int last)
{
auto is_visible = [this](unsigned int id) {
for (const TBuffer& buffer : m_buffers) {
if (buffer.visible) {
for (const Path& path : buffer.paths) {
if (path.first.s_id <= id && id <= path.last.s_id)
return true;
}
}
}
return false;
};
int first_diff = static_cast<int>(first) - static_cast<int>(m_sequential_view.last_current.first);
int last_diff = static_cast<int>(last) - static_cast<int>(m_sequential_view.last_current.last);
unsigned int new_first = first;
unsigned int new_last = last;
while (!is_visible(new_first)) {
if (first_diff > 0)
++new_first;
else
--new_first;
}
while (!is_visible(new_last)) {
if (last_diff > 0)
++new_last;
else
--new_last;
}
m_sequential_view.current.first = new_first;
m_sequential_view.current.last = new_last;
m_sequential_view.last_current = m_sequential_view.current;
refresh_render_paths(true, true);
if (new_first != first || new_last != last)
wxGetApp().plater()->update_preview_moves_slider();
}
bool GCodeViewer::is_toolpath_move_type_visible(EMoveType type) const bool GCodeViewer::is_toolpath_move_type_visible(EMoveType type) const
{ {
size_t id = static_cast<size_t>(buffer_id(type)); size_t id = static_cast<size_t>(buffer_id(type));
@ -2138,10 +2182,10 @@ void GCodeViewer::render_legend() const
} }
break; break;
} }
case EViewType::Height: { append_range(m_extrusions.ranges.height, 3); break; } case EViewType::Height: { append_range(m_extrusions.ranges.height, 3); break; }
case EViewType::Width: { append_range(m_extrusions.ranges.width, 3); break; } case EViewType::Width: { append_range(m_extrusions.ranges.width, 3); break; }
case EViewType::Feedrate: { append_range(m_extrusions.ranges.feedrate, 1); break; } case EViewType::Feedrate: { append_range(m_extrusions.ranges.feedrate, 1); break; }
case EViewType::FanSpeed: { append_range(m_extrusions.ranges.fan_speed, 0); break; } case EViewType::FanSpeed: { append_range(m_extrusions.ranges.fan_speed, 0); break; }
case EViewType::VolumetricRate: { append_range(m_extrusions.ranges.volumetric_rate, 3); break; } case EViewType::VolumetricRate: { append_range(m_extrusions.ranges.volumetric_rate, 3); break; }
case EViewType::Tool: case EViewType::Tool:
{ {

View file

@ -367,6 +367,7 @@ public:
Endpoints endpoints; Endpoints endpoints;
Endpoints current; Endpoints current;
Endpoints last_current;
Vec3f current_position{ Vec3f::Zero() }; Vec3f current_position{ Vec3f::Zero() };
Marker marker; Marker marker;
}; };
@ -430,12 +431,7 @@ public:
const std::vector<double>& get_layers_zs() const { return m_layers_zs; }; const std::vector<double>& get_layers_zs() const { return m_layers_zs; };
const SequentialView& get_sequential_view() const { return m_sequential_view; } const SequentialView& get_sequential_view() const { return m_sequential_view; }
void update_sequential_view_current(unsigned int first, unsigned int last) void update_sequential_view_current(unsigned int first, unsigned int last);
{
m_sequential_view.current.first = first;
m_sequential_view.current.last = last;
refresh_render_paths(true, true);
}
EViewType get_view_type() const { return m_view_type; } EViewType get_view_type() const { return m_view_type; }
void set_view_type(EViewType type) { void set_view_type(EViewType type) {