mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 10:17:55 -06:00
Refactoring of GCodeViewer initialization
This commit is contained in:
parent
27bd79e409
commit
ebed29708d
2 changed files with 42 additions and 54 deletions
|
@ -306,10 +306,47 @@ const std::vector<GCodeViewer::Color> GCodeViewer::Range_Colors {{
|
||||||
{ 0.581f, 0.149f, 0.087f } // reddish
|
{ 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)
|
void GCodeViewer::load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized)
|
||||||
{
|
{
|
||||||
init();
|
|
||||||
|
|
||||||
// avoid processing if called with the same gcode_result
|
// avoid processing if called with the same gcode_result
|
||||||
if (m_last_result_id == gcode_result.id)
|
if (m_last_result_id == gcode_result.id)
|
||||||
return;
|
return;
|
||||||
|
@ -460,9 +497,6 @@ void GCodeViewer::update_shells_color_by_extruder(const DynamicPrintConfig* conf
|
||||||
|
|
||||||
void GCodeViewer::reset()
|
void GCodeViewer::reset()
|
||||||
{
|
{
|
||||||
m_initialized = false;
|
|
||||||
m_gl_data_initialized = false;
|
|
||||||
|
|
||||||
m_moves_count = 0;
|
m_moves_count = 0;
|
||||||
for (TBuffer& buffer : m_buffers) {
|
for (TBuffer& buffer : m_buffers) {
|
||||||
buffer.reset();
|
buffer.reset();
|
||||||
|
@ -955,50 +989,6 @@ void GCodeViewer::export_toolpaths_to_obj(const char* filename) const
|
||||||
fclose(fp);
|
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)
|
void GCodeViewer::load_toolpaths(const GCodeProcessor::Result& gcode_result)
|
||||||
{
|
{
|
||||||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
|
|
|
@ -195,7 +195,7 @@ class GCodeViewer
|
||||||
|
|
||||||
std::string shader;
|
std::string shader;
|
||||||
std::vector<Path> paths;
|
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::unordered_set<RenderPath, RenderPathPropertyHash, RenderPathPropertyEqual> render_paths;
|
||||||
std::set<RenderPath, RenderPathPropertyLower> render_paths;
|
std::set<RenderPath, RenderPathPropertyLower> render_paths;
|
||||||
bool visible{ false };
|
bool visible{ false };
|
||||||
|
@ -228,7 +228,7 @@ class GCodeViewer
|
||||||
{
|
{
|
||||||
case ERenderPrimitiveType::Point: { return 0; }
|
case ERenderPrimitiveType::Point: { return 0; }
|
||||||
case ERenderPrimitiveType::Line: { return 1; }
|
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; }
|
default: { return 0; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -461,7 +461,6 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_initialized{ false };
|
|
||||||
mutable bool m_gl_data_initialized{ false };
|
mutable bool m_gl_data_initialized{ false };
|
||||||
unsigned int m_last_result_id{ 0 };
|
unsigned int m_last_result_id{ 0 };
|
||||||
size_t m_moves_count{ 0 };
|
size_t m_moves_count{ 0 };
|
||||||
|
@ -490,7 +489,7 @@ private:
|
||||||
GCodeProcessor::Result::SettingsIds m_settings_ids;
|
GCodeProcessor::Result::SettingsIds m_settings_ids;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GCodeViewer() = default;
|
GCodeViewer();
|
||||||
~GCodeViewer() { reset(); }
|
~GCodeViewer() { reset(); }
|
||||||
|
|
||||||
// extract rendering data from the given parameters
|
// extract rendering data from the given parameters
|
||||||
|
@ -536,7 +535,6 @@ public:
|
||||||
void export_toolpaths_to_obj(const char* filename) const;
|
void export_toolpaths_to_obj(const char* filename) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
|
||||||
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
|
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
|
||||||
void load_shells(const Print& print, bool initialized);
|
void load_shells(const Print& print, bool initialized);
|
||||||
void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;
|
void refresh_render_paths(bool keep_sequential_current_first, bool keep_sequential_current_last) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue