Refactoring of GCodeViewer initialization

This commit is contained in:
enricoturri1966 2021-01-07 09:57:37 +01:00
parent 193e73177c
commit 91fdb67cd7
2 changed files with 42 additions and 54 deletions

View File

@ -306,10 +306,47 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Range_Colors {{
{ 0.581f, 0.149f, 0.087f } // reddish
}};
GCodeViewer::GCodeViewer()
{
// initializes non opengl data of TBuffers
for (size_t i = 0; i < m_buffers.size(); ++i) {
TBuffer& buffer = m_buffers[i];
switch (buffer_type(i))
{
default: { break; }
case EMoveType::Tool_change:
case EMoveType::Color_change:
case EMoveType::Pause_Print:
case EMoveType::Custom_GCode:
case EMoveType::Retract:
case EMoveType::Unretract:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point;
buffer.vertices.format = VBuffer::EFormat::Position;
break;
}
case EMoveType::Wipe:
case EMoveType::Extrude:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
break;
}
case EMoveType::Travel:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line;
buffer.vertices.format = VBuffer::EFormat::PositionNormal1;
break;
}
}
}
set_toolpath_move_type_visible(EMoveType::Extrude, true);
// m_sequential_view.skip_invisible_moves = true;
}
void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized)
{
init();
// avoid processing if called with the same gcode_result
if (m_last_result_id == gcode_result.id)
return;
@ -460,9 +497,6 @@ void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* conf
void GCodeViewer::reset()
{
m_initialized = false;
m_gl_data_initialized = false;
m_moves_count = 0;
for (TBuffer& buffer : m_buffers) {
buffer.reset();
@ -955,50 +989,6 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
fclose(fp);
}
void GCodeViewer::init()
{
if (m_initialized)
return;
// initializes non opengl data of TBuffers
for (size_t i = 0; i < m_buffers.size(); ++i) {
TBuffer& buffer = m_buffers[i];
switch (buffer_type(i))
{
default: { break; }
case EMoveType::Tool_change:
case EMoveType::Color_change:
case EMoveType::Pause_Print:
case EMoveType::Custom_GCode:
case EMoveType::Retract:
case EMoveType::Unretract:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Point;
buffer.vertices.format = VBuffer::EFormat::Position;
break;
}
case EMoveType::Wipe:
case EMoveType::Extrude:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Triangle;
buffer.vertices.format = VBuffer::EFormat::PositionNormal3;
break;
}
case EMoveType::Travel:
{
buffer.render_primitive_type = TBuffer::ERenderPrimitiveType::Line;
buffer.vertices.format = VBuffer::EFormat::PositionNormal1;
break;
}
}
}
set_toolpath_move_type_visible(EMoveType::Extrude, true);
// m_sequential_view.skip_invisible_moves = true;
m_initialized = true;
}
void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
{
#if ENABLE_GCODE_VIEWER_STATISTICS

View File

@ -195,7 +195,7 @@ class GCodeViewer
std::string shader;
std::vector<Path> paths;
// std::set seems to perform singificantly better, at least on Windows.
// std::set seems to perform significantly better, at least on Windows.
// std::unordered_set<RenderPath, RenderPathPropertyHash, RenderPathPropertyEqual> render_paths;
std::set<RenderPath, RenderPathPropertyLower> render_paths;
bool visible{ false };
@ -228,7 +228,7 @@ class GCodeViewer
{
case ERenderPrimitiveType::Point: { return 0; }
case ERenderPrimitiveType::Line: { return 1; }
case ERenderPrimitiveType::Triangle: { return 36; } // 1 vertex of 13th triangle
case ERenderPrimitiveType::Triangle: { return 36; } // 1st vertex of 13th triangle
default: { return 0; }
}
}
@ -461,7 +461,6 @@ public:
};
private:
bool m_initialized{ false };
mutable bool m_gl_data_initialized{ false };
unsigned int m_last_result_id{ 0 };
size_t m_moves_count{ 0 };
@ -490,7 +489,7 @@ private:
GCodeProcessor::Result::SettingsIds m_settings_ids;
public:
GCodeViewer() = default;
GCodeViewer();
~GCodeViewer() { reset(); }
// extract rendering data from the given parameters
@ -536,7 +535,6 @@ public:
void export_toolpaths_to_obj(const char* filename) const;
private:
void init();
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
void load_shells(const Print& print, bool initialized);
void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;