ENH:optimize method of gcodeviewer marker get current move

Change-Id: I935d8da52212156b4158d727b49d8b0e51105fa3
(cherry picked from commit 4826570649608691184c05260edf4c074dccb780)
This commit is contained in:
liz.li 2023-01-10 17:30:57 +08:00 committed by Lane.Wei
parent 70a0f09ea2
commit fdba5967fa
3 changed files with 33 additions and 21 deletions

View File

@ -321,8 +321,12 @@ void GCodeViewer::SequentialView::Marker::set_world_position(const Vec3f& positi
m_world_transform = (Geometry::assemble_transform((position + m_z_offset * Vec3f::UnitZ()).cast<double>()) * Geometry::assemble_transform(m_model.get_bounding_box().size().z() * Vec3d::UnitZ(), { M_PI, 0.0, 0.0 })).cast<float>();
}
void GCodeViewer::SequentialView::Marker::update_curr_move(const GCodeProcessorResult::MoveVertex move) {
m_curr_move = move;
}
//BBS: GUI refactor: add canvas size from parameters
void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_height, const EViewType& view_type, const std::vector<GCodeProcessorResult::MoveVertex>& moves, uint64_t curr_line_id) const
void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_height, const EViewType& view_type) const
{
if (!m_visible)
return;
@ -353,13 +357,6 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he
const ImU32 text_name_clr = m_is_dark ? IM_COL32(255, 255, 255, 0.88 * 255) : IM_COL32(38, 46, 48, 255);
const ImU32 text_value_clr = m_is_dark ? IM_COL32(255, 255, 255, 0.4 * 255) : IM_COL32(144, 144, 144, 255);
auto it = std::find_if(moves.begin(), moves.end(), [&curr_line_id](auto move) {
return move.gcode_id == curr_line_id;
});
if (it == moves.end()) {
return;
}
ImGuiWrapper& imgui = *wxGetApp().imgui();
//BBS: GUI refactor: add canvas size from parameters
imgui.set_next_window_pos(0.5f * static_cast<float>(canvas_width), static_cast<float>(canvas_height), ImGuiCond_Always, 0.5f, 1.0f);
@ -415,56 +412,56 @@ void GCodeViewer::SequentialView::Marker::render(int canvas_width, int canvas_he
switch (view_type) {
case EViewType::Height: {
ImGui::SameLine(window_padding + item_size + item_spacing);
sprintf(buf, "%s%.2f", height.c_str(), it->height);
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);
sprintf(buf, "%s%.2f", width.c_str(), it->width);
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(), it->feedrate);
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);
sprintf(buf, "%s%.2f", flow.c_str(), it->volumetric_rate());
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);
sprintf(buf, "%s%.0f", fanspeed.c_str(), it->fan_speed);
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);
sprintf(buf, "%s%.0f", temperature.c_str(), it->temperature);
sprintf(buf, "%s%.0f", temperature.c_str(), m_curr_move.temperature);
ImGui::PushItemWidth(item_size);
imgui.text(buf);
break;
}
case EViewType::LayerTime:{
ImGui::SameLine(window_padding + item_size + item_spacing);
sprintf(buf, "%s%.1f", layer_time.c_str(), it->layer_duration);
sprintf(buf, "%s%.1f", layer_time.c_str(), m_curr_move.layer_duration);
ImGui::PushItemWidth(item_size);
imgui.text(buf);
break;
}
case EViewType::LayerTimeLog: {
ImGui::SameLine(window_padding + item_size + item_spacing);
sprintf(buf, "%s%.1f", layer_time_log.c_str(), std::log(it->layer_duration));
sprintf(buf, "%s%.1f", layer_time_log.c_str(), std::log(m_curr_move.layer_duration));
ImGui::PushItemWidth(item_size);
imgui.text(buf);
break;
@ -699,9 +696,10 @@ void GCodeViewer::SequentialView::GCodeWindow::stop_mapping_file()
}
}
//BBS: GUI refactor: move to the right
void GCodeViewer::SequentialView::render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type, const std::vector<GCodeProcessorResult::MoveVertex>& moves) const
void GCodeViewer::SequentialView::render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const
{
marker.render(canvas_width, canvas_height, view_type, moves, static_cast<uint64_t>(gcode_ids[current.last]));
marker.render(canvas_width, canvas_height, view_type);
//float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height();
// BBS
#if 0
@ -1284,7 +1282,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(legend_height, canvas_width - right_margin * m_scale, canvas_height - bottom_margin * m_scale, m_view_type, m_gcode_result->moves);
m_sequential_view.render(legend_height, canvas_width - right_margin * m_scale, canvas_height - bottom_margin * m_scale, m_view_type);
}
#if ENABLE_GCODE_VIEWER_STATISTICS
render_statistics();
@ -1790,6 +1788,14 @@ void GCodeViewer::update_layers_slider_mode()
// TODO m_layers_slider->SetModeAndOnlyExtruder(one_extruder_printed_model, only_extruder);
}
void GCodeViewer::update_marker_curr_move() {
auto it = std::find_if(m_gcode_result->moves.begin(), m_gcode_result->moves.end(), [this](auto move) {
return move.gcode_id == static_cast<uint64_t>(m_sequential_view.gcode_ids[m_sequential_view.current.last]);
});
m_sequential_view.marker.update_curr_move(*it);
}
bool GCodeViewer::is_toolpath_move_type_visible(EMoveType type) const
{
size_t id = static_cast<size_t>(buffer_id(type));

View File

@ -618,6 +618,7 @@ public:
// see implementation of render() method
Vec3f m_world_offset;
float m_z_offset{ 0.5f };
GCodeProcessorResult::MoveVertex m_curr_move;
bool m_visible{ true };
bool m_is_dark = false;
@ -635,8 +636,10 @@ public:
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 std::vector<GCodeProcessorResult::MoveVertex>& moves, uint64_t curr_line_id) const;
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; }
void update_curr_move(const GCodeProcessorResult::MoveVertex move);
};
class GCodeWindow
@ -696,7 +699,7 @@ public:
float m_scale = 1.0;
//BBS: GUI refactor: add canvas size
void render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type, const std::vector<GCodeProcessorResult::MoveVertex>& moves) const;
void render(float legend_height, int canvas_width, int canvas_height, const EViewType& view_type) const;
};
struct ETools
@ -830,6 +833,7 @@ public:
void enable_moves_slider(bool enable) const;
void update_moves_slider(bool set_to_max = false);
void update_layers_slider_mode();
void update_marker_curr_move();
bool is_contained_in_bed() const { return m_contained_in_bed; }
//BBS: add only gcode mode

View File

@ -6638,12 +6638,14 @@ void GLCanvas3D::_render_gcode(int canvas_width, int canvas_height)
}
layers_slider->set_as_dirty(false);
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE));
m_gcode_viewer.update_marker_curr_move();
}
if (moves_slider->is_dirty()) {
moves_slider->set_as_dirty(false);
m_gcode_viewer.update_sequential_view_current((moves_slider->GetLowerValueD() - 1.0), static_cast<unsigned int>(moves_slider->GetHigherValueD() - 1.0));
post_event(SimpleEvent(EVT_GLCANVAS_UPDATE));
m_gcode_viewer.update_marker_curr_move();
}
}