New gcode visualization integration - Fixed toolpaths reset

This commit is contained in:
enricoturri1966 2024-01-09 13:14:14 +01:00 committed by Lukas Matena
parent 728cf61928
commit 5c29f868c3
8 changed files with 32 additions and 13 deletions

View File

@ -12,7 +12,7 @@
namespace libvgcode {
//
// Helper class to interpolate between colors defined in Ranges_Colors palette.
// Helper class to interpolate between colors defined in RANGES_COLORS palette.
// Interpolation can be done linearly or logarithmically.
// Usage:
// 1) Define an instance of ColorRange of the desired interpolation type
@ -64,7 +64,7 @@ public:
float get_step_size() const;
std::vector<float> get_values() const;
static const ColorRange Dummy_Color_Range;
static const ColorRange DUMMY_COLOR_RANGE;
private:
EColorRangeType m_type{ EColorRangeType::Linear };

View File

@ -27,19 +27,26 @@ public:
//
// Initialize the viewer.
// This method must be called after a valid OpenGL context has been already created
// and before to call any other method of the viewer.
// and before calling any other method of the viewer.
//
void init();
//
// Release the resources used by the viewer.
// This method must be called before releasing the OpenGL context if the viewer
// destructor is called after releasing the OpenGL context.
// goes out of scope after releasing the OpenGL context.
//
void shutdown();
//
// Reset the contents of the viewer.
// Automatically called by load() method.
//
void reset();
//
// Setup the viewer content from the given data.
//
void load(GCodeInputData&& gcode_data);
//
// Render the toolpaths according to the current settings,
// Render the toolpaths according to the current settings and
// using the given camera matrices.
//
void render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix);
@ -92,7 +99,7 @@ public:
size_t get_vertices_count() const;
//
// Return the vertex pointed by the max value of the view current range
// Return the vertex pointed by the max value of the view visible range
//
const PathVertex& get_current_vertex() const;
@ -101,6 +108,9 @@ public:
//
const PathVertex& get_vertex_at(size_t id) const;
//
// Return the color used to render the given vertex with the current settings.
//
Color get_vertex_color(const PathVertex& vertex) const;
//
@ -108,6 +118,9 @@ public:
//
size_t get_enabled_segments_count() const;
//
// Return the Interval containing the enabled segments
//
const Interval& get_enabled_segments_range() const;
//
@ -115,6 +128,9 @@ public:
//
size_t get_enabled_options_count() const;
//
// Return the Interval containing the enabled options
//
const Interval& get_enabled_options_range() const;
//

View File

@ -10,7 +10,7 @@
namespace libvgcode {
const ColorRange ColorRange::Dummy_Color_Range = ColorRange();
const ColorRange ColorRange::DUMMY_COLOR_RANGE = ColorRange();
ColorRange::ColorRange(EColorRangeType type)
: m_type(type)

View File

@ -463,6 +463,8 @@ void ViewerImpl::load(GCodeInputData&& gcode_data)
if (gcode_data.vertices.empty())
return;
reset();
m_loading = true;
m_vertices = std::move(gcode_data.vertices);

View File

@ -155,7 +155,7 @@ public:
const ColorRange& get_volumetric_rate_range() const { return m_volumetric_rate_range; }
const ColorRange& get_layer_time_range(EColorRangeType type) const {
return (static_cast<size_t>(type) < m_layer_time_range.size()) ?
m_layer_time_range[static_cast<size_t>(type)] : ColorRange::Dummy_Color_Range;
m_layer_time_range[static_cast<size_t>(type)] : ColorRange::DUMMY_COLOR_RANGE;
}
float get_travels_radius() const { return m_travels_radius; }

View File

@ -1290,8 +1290,6 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print & p
#if ENABLE_NEW_GCODE_VIEWER
void GCodeViewer::load_as_preview(libvgcode::GCodeInputData&& data, const std::vector<std::string>& str_tool_colors)
{
m_viewer.reset();
if (!str_tool_colors.empty()) {
std::vector<ColorRGBA> tool_colors;
decode_colors(str_tool_colors, tool_colors);

View File

@ -2743,9 +2743,6 @@ void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, c
_set_current();
// Release OpenGL data before generating new data.
this->reset_volumes();
#if ENABLE_NEW_GCODE_VIEWER
libvgcode::GCodeInputData data = libvgcode::convert(*print, str_tool_colors, color_print_values, static_cast<size_t>(wxGetApp().extruders_edited_cnt()));
@ -2756,6 +2753,9 @@ void GLCanvas3D::load_preview(const std::vector<std::string>& str_tool_colors, c
m_gcode_viewer.set_view_type(libvgcode::EViewType::FeatureType);
m_gcode_viewer.load_as_preview(std::move(data), str_tool_colors);
#else
// Release OpenGL data before generating new data.
this->reset_volumes();
const BuildVolume& build_volume = m_bed.build_volume();
_load_print_toolpaths(build_volume);
_load_wipe_tower_toolpaths(build_volume, str_tool_colors);

View File

@ -6233,6 +6233,9 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
p->reset_gcode_toolpaths();
p->view3D->get_canvas3d()->reset_sequential_print_clearance();
p->view3D->get_canvas3d()->set_sla_view_type(GLCanvas3D::ESLAViewType::Original);
#if ENABLE_NEW_GCODE_VIEWER
p->preview->get_canvas3d()->reset_volumes();
#endif // ENABLE_NEW_GCODE_VIEWER
}
else if (opt_key == "bed_shape" || opt_key == "bed_custom_texture" || opt_key == "bed_custom_model") {
bed_shape_changed = true;