GCodeViewer -> Refactoring

This commit is contained in:
enricoturri1966 2020-04-28 12:24:03 +02:00
parent a00c391f0f
commit d265c84b76
3 changed files with 24 additions and 29 deletions

View File

@ -92,9 +92,8 @@ bool GCodeViewer::IBuffer::init_shader(const std::string& vertex_shader_src, con
void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move) void GCodeViewer::IBuffer::add_path(const GCodeProcessor::MoveVertex& move)
{ {
unsigned int id = static_cast<unsigned int>(data.size()); Path::Endpoint endpoint = { static_cast<unsigned int>(data.size()), static_cast<double>(move.position[2]) };
double z = static_cast<double>(move.position[2]); paths.push_back({ move.type, move.extrusion_role, endpoint, endpoint, move.delta_extruder, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
paths.push_back({ move.type, move.extrusion_role, id, id, z, z, move.delta_extruder, move.height, move.width, move.feedrate, move.fan_speed, move.volumetric_rate(), move.extruder_id, move.cp_color_id });
} }
std::array<float, 3> GCodeViewer::Extrusions::Range::get_color_at(float value) const std::array<float, 3> GCodeViewer::Extrusions::Range::get_color_at(float value) const
@ -409,13 +408,13 @@ void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
buffer.data.push_back(static_cast<unsigned int>(i - 1)); buffer.data.push_back(static_cast<unsigned int>(i - 1));
} }
buffer.paths.back().last = static_cast<unsigned int>(buffer.data.size()); buffer.paths.back().last.id = static_cast<unsigned int>(buffer.data.size());
buffer.data.push_back(static_cast<unsigned int>(i)); buffer.data.push_back(static_cast<unsigned int>(i));
break; break;
} }
default: default:
{ {
continue; break;
} }
} }
} }
@ -602,7 +601,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -620,7 +619,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -638,7 +637,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -656,7 +655,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -674,7 +673,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -692,7 +691,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
glsafe(::glEnable(GL_PROGRAM_POINT_SIZE)); glsafe(::glEnable(GL_PROGRAM_POINT_SIZE));
glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_POINTS, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
glsafe(::glDisable(GL_PROGRAM_POINT_SIZE)); glsafe(::glDisable(GL_PROGRAM_POINT_SIZE));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
@ -708,7 +707,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
set_color(current_program_id, extrusion_color(path)); set_color(current_program_id, extrusion_color(path));
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_line_strip_calls_count; ++m_statistics.gl_line_strip_calls_count;
@ -723,7 +722,7 @@ void GCodeViewer::render_toolpaths() const
continue; continue;
set_color(current_program_id, (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path)); set_color(current_program_id, (m_view_type == EViewType::Feedrate || m_view_type == EViewType::Tool || m_view_type == EViewType::ColorPrint) ? extrusion_color(path) : travel_color(path));
glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last - path.first + 1), GL_UNSIGNED_INT, (const void*)(path.first * sizeof(GLuint)))); glsafe(::glDrawElements(GL_LINE_STRIP, GLsizei(path.last.id - path.first.id + 1), GL_UNSIGNED_INT, (const void*)(path.first.id * sizeof(GLuint))));
#if ENABLE_GCODE_VIEWER_STATISTICS #if ENABLE_GCODE_VIEWER_STATISTICS
++m_statistics.gl_line_strip_calls_count; ++m_statistics.gl_line_strip_calls_count;

View File

@ -35,12 +35,16 @@ class GCodeViewer
// Used to identify different toolpath sub-types inside a IBuffer // Used to identify different toolpath sub-types inside a IBuffer
struct Path struct Path
{ {
struct Endpoint
{
unsigned int id{ 0u };
double z{ 0.0 };
};
GCodeProcessor::EMoveType type{ GCodeProcessor::EMoveType::Noop }; GCodeProcessor::EMoveType type{ GCodeProcessor::EMoveType::Noop };
ExtrusionRole role{ erNone }; ExtrusionRole role{ erNone };
unsigned int first{ 0 }; Endpoint first;
unsigned int last{ 0 }; Endpoint last;
double first_z{ 0.0f };
double last_z{ 0.0f };
float delta_extruder{ 0.0f }; float delta_extruder{ 0.0f };
float height{ 0.0f }; float height{ 0.0f };
float width{ 0.0f }; float width{ 0.0f };
@ -257,7 +261,7 @@ private:
return z > m_layers_z_range[0] - EPSILON && z < m_layers_z_range[1] + EPSILON; return z > m_layers_z_range[0] - EPSILON && z < m_layers_z_range[1] + EPSILON;
}; };
return in_z_range(path.first_z) || in_z_range(path.last_z); return in_z_range(path.first.z) || in_z_range(path.last.z);
} }
}; };

View File

@ -314,7 +314,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
m_label_show = new wxStaticText(this, wxID_ANY, _(L("Show"))); m_label_show = new wxStaticText(this, wxID_ANY, _(L("Show")));
m_combochecklist_features = new wxComboCtrl(); m_combochecklist_features = new wxComboCtrl();
m_combochecklist_features->Create(this, wxID_ANY, _(L("Feature types")), wxDefaultPosition, wxSize(15 * wxGetApp().em_unit(), -1), wxCB_READONLY); m_combochecklist_features->Create(this, wxID_ANY, _(L("Feature types")), wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
std::string feature_items = GUI::into_u8( std::string feature_items = GUI::into_u8(
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
_L("Unknown") + "|1|" + _L("Unknown") + "|1|" +
@ -337,7 +337,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
#if ENABLE_GCODE_VIEWER #if ENABLE_GCODE_VIEWER
m_combochecklist_options = new wxComboCtrl(); m_combochecklist_options = new wxComboCtrl();
m_combochecklist_options->Create(this, wxID_ANY, _(L("Others")), wxDefaultPosition, wxSize(15 * wxGetApp().em_unit(), -1), wxCB_READONLY); m_combochecklist_options->Create(this, wxID_ANY, _(L("Options")), wxDefaultPosition, wxDefaultSize, wxCB_READONLY);
std::string options_items = GUI::into_u8( std::string options_items = GUI::into_u8(
_(L("Travel")) + "|0|" + _(L("Travel")) + "|0|" +
_(L("Retractions")) + "|0|" + _(L("Retractions")) + "|0|" +
@ -349,7 +349,7 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view
_(L("Shells")) + "|0|" + _(L("Shells")) + "|0|" +
_(L("Legend")) + "|1" _(L("Legend")) + "|1"
); );
Slic3r::GUI::create_combochecklist(m_combochecklist_options, GUI::into_u8(_(L("Others"))), options_items); Slic3r::GUI::create_combochecklist(m_combochecklist_options, GUI::into_u8(_(L("Options"))), options_items);
#else #else
m_checkbox_travel = new wxCheckBox(this, wxID_ANY, _(L("Travel"))); m_checkbox_travel = new wxCheckBox(this, wxID_ANY, _(L("Travel")));
m_checkbox_retractions = new wxCheckBox(this, wxID_ANY, _(L("Retractions"))); m_checkbox_retractions = new wxCheckBox(this, wxID_ANY, _(L("Retractions")));
@ -605,15 +605,11 @@ void Preview::show_hide_ui_elements(const std::string& what)
bool enable = (what == "full"); bool enable = (what == "full");
m_label_show->Enable(enable); m_label_show->Enable(enable);
m_combochecklist_features->Enable(enable); m_combochecklist_features->Enable(enable);
#if ENABLE_GCODE_VIEWER
m_combochecklist_options->Enable(enable);
#else
m_checkbox_travel->Enable(enable); m_checkbox_travel->Enable(enable);
m_checkbox_retractions->Enable(enable); m_checkbox_retractions->Enable(enable);
m_checkbox_unretractions->Enable(enable); m_checkbox_unretractions->Enable(enable);
m_checkbox_shells->Enable(enable); m_checkbox_shells->Enable(enable);
m_checkbox_legend->Enable(enable); m_checkbox_legend->Enable(enable);
#endif // ENABLE_GCODE_VIEWER
enable = (what != "none"); enable = (what != "none");
m_label_view_type->Enable(enable); m_label_view_type->Enable(enable);
@ -622,15 +618,11 @@ void Preview::show_hide_ui_elements(const std::string& what)
bool visible = (what != "none"); bool visible = (what != "none");
m_label_show->Show(visible); m_label_show->Show(visible);
m_combochecklist_features->Show(visible); m_combochecklist_features->Show(visible);
#if ENABLE_GCODE_VIEWER
m_combochecklist_options->Show(visible);
#else
m_checkbox_travel->Show(visible); m_checkbox_travel->Show(visible);
m_checkbox_retractions->Show(visible); m_checkbox_retractions->Show(visible);
m_checkbox_unretractions->Show(visible); m_checkbox_unretractions->Show(visible);
m_checkbox_shells->Show(visible); m_checkbox_shells->Show(visible);
m_checkbox_legend->Show(visible); m_checkbox_legend->Show(visible);
#endif // ENABLE_GCODE_VIEWER
m_label_view_type->Show(visible); m_label_view_type->Show(visible);
m_choice_view_type->Show(visible); m_choice_view_type->Show(visible);
} }