2020-04-14 08:02:08 +00:00
|
|
|
#ifndef slic3r_GCodeViewer_hpp_
|
|
|
|
#define slic3r_GCodeViewer_hpp_
|
|
|
|
|
|
|
|
#if ENABLE_GCODE_VIEWER
|
2020-04-15 12:31:39 +00:00
|
|
|
#include "3DScene.hpp"
|
2020-04-14 08:02:08 +00:00
|
|
|
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
2020-05-11 14:26:35 +00:00
|
|
|
#include "GLModel.hpp"
|
2020-04-14 08:02:08 +00:00
|
|
|
|
2020-04-20 08:52:16 +00:00
|
|
|
#include <float.h>
|
|
|
|
|
2020-04-14 08:02:08 +00:00
|
|
|
namespace Slic3r {
|
2020-05-11 11:09:26 +00:00
|
|
|
|
2020-04-15 12:31:39 +00:00
|
|
|
class Print;
|
2020-05-11 11:09:26 +00:00
|
|
|
class TriangleMesh;
|
|
|
|
|
2020-04-14 08:02:08 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
class GCodeViewer
|
|
|
|
{
|
2020-05-05 10:09:11 +00:00
|
|
|
using Color = std::array<float, 3>;
|
2020-09-16 13:45:53 +00:00
|
|
|
using IndexBuffer = std::vector<unsigned int>;
|
|
|
|
using MultiIndexBuffer = std::vector<IndexBuffer>;
|
|
|
|
|
2020-05-05 10:09:11 +00:00
|
|
|
static const std::vector<Color> Extrusion_Role_Colors;
|
2020-05-22 09:52:07 +00:00
|
|
|
static const std::vector<Color> Options_Colors;
|
2020-05-05 10:09:11 +00:00
|
|
|
static const std::vector<Color> Travel_Colors;
|
|
|
|
static const std::vector<Color> Range_Colors;
|
2020-04-16 13:09:04 +00:00
|
|
|
|
2020-05-22 09:52:07 +00:00
|
|
|
enum class EOptionsColors : unsigned char
|
|
|
|
{
|
|
|
|
Retractions,
|
|
|
|
Unretractions,
|
|
|
|
ToolChanges,
|
|
|
|
ColorChanges,
|
|
|
|
PausePrints,
|
|
|
|
CustomGCodes
|
|
|
|
};
|
|
|
|
|
2020-08-19 09:25:12 +00:00
|
|
|
// vbo buffer containing vertices data used to rendder a specific toolpath type
|
2020-04-15 14:29:11 +00:00
|
|
|
struct VBuffer
|
2020-04-14 08:02:08 +00:00
|
|
|
{
|
2020-06-29 12:00:08 +00:00
|
|
|
enum class EFormat : unsigned char
|
|
|
|
{
|
2020-08-26 13:29:33 +00:00
|
|
|
// vertex format: 3 floats -> position.x|position.y|position.z
|
2020-06-29 12:00:08 +00:00
|
|
|
Position,
|
2020-08-26 13:29:33 +00:00
|
|
|
// vertex format: 4 floats -> position.x|position.y|position.z|normal.x
|
|
|
|
PositionNormal1,
|
|
|
|
// vertex format: 6 floats -> position.x|position.y|position.z|normal.x|normal.y|normal.z
|
|
|
|
PositionNormal3
|
2020-06-29 12:00:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EFormat format{ EFormat::Position };
|
|
|
|
// vbo id
|
|
|
|
unsigned int id{ 0 };
|
|
|
|
// count of vertices, updated after data are sent to gpu
|
|
|
|
size_t count{ 0 };
|
2020-04-15 14:29:11 +00:00
|
|
|
|
2020-06-29 12:00:08 +00:00
|
|
|
size_t data_size_bytes() const { return count * vertex_size_bytes(); }
|
2020-08-26 13:29:33 +00:00
|
|
|
|
|
|
|
size_t vertex_size_floats() const { return position_size_floats() + normal_size_floats(); }
|
|
|
|
size_t vertex_size_bytes() const { return vertex_size_floats() * sizeof(float); }
|
|
|
|
|
|
|
|
size_t position_offset_floats() const { return 0; }
|
|
|
|
size_t position_offset_size() const { return position_offset_floats() * sizeof(float); }
|
|
|
|
size_t position_size_floats() const
|
2020-06-29 12:00:08 +00:00
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
2020-08-26 13:29:33 +00:00
|
|
|
case EFormat::Position:
|
|
|
|
case EFormat::PositionNormal3: { return 3; }
|
|
|
|
case EFormat::PositionNormal1: { return 4; }
|
|
|
|
default: { return 0; }
|
2020-06-29 12:00:08 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-26 13:29:33 +00:00
|
|
|
size_t position_size_bytes() const { return position_size_floats() * sizeof(float); }
|
|
|
|
|
|
|
|
size_t normal_offset_floats() const
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case EFormat::Position:
|
|
|
|
case EFormat::PositionNormal1: { return 0; }
|
|
|
|
case EFormat::PositionNormal3: { return 3; }
|
|
|
|
default: { return 0; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size_t normal_offset_size() const { return normal_offset_floats() * sizeof(float); }
|
|
|
|
size_t normal_size_floats() const {
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case EFormat::Position:
|
|
|
|
case EFormat::PositionNormal1: { return 0; }
|
|
|
|
case EFormat::PositionNormal3: { return 3; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size_t normal_size_bytes() const { return normal_size_floats() * sizeof(float); }
|
2020-04-14 08:02:08 +00:00
|
|
|
|
2020-04-14 14:40:08 +00:00
|
|
|
void reset();
|
2020-06-29 12:00:08 +00:00
|
|
|
};
|
|
|
|
|
2020-08-25 06:12:28 +00:00
|
|
|
// ibo buffer containing indices data (lines/triangles) used to render a specific toolpath type
|
2020-06-29 12:00:08 +00:00
|
|
|
struct IBuffer
|
|
|
|
{
|
|
|
|
// ibo id
|
|
|
|
unsigned int id{ 0 };
|
|
|
|
// count of indices, updated after data are sent to gpu
|
|
|
|
size_t count{ 0 };
|
2020-04-14 14:40:08 +00:00
|
|
|
|
2020-06-29 12:00:08 +00:00
|
|
|
void reset();
|
2020-04-14 08:02:08 +00:00
|
|
|
};
|
|
|
|
|
2020-04-20 08:52:16 +00:00
|
|
|
// Used to identify different toolpath sub-types inside a IBuffer
|
2020-04-16 13:09:04 +00:00
|
|
|
struct Path
|
|
|
|
{
|
2020-04-28 10:24:03 +00:00
|
|
|
struct Endpoint
|
|
|
|
{
|
2020-09-16 13:45:53 +00:00
|
|
|
// index of the index buffer
|
|
|
|
unsigned int b_id{ 0 };
|
|
|
|
// index into the index buffer
|
|
|
|
size_t i_id{ 0 };
|
|
|
|
// sequential id (index into the vertex buffer)
|
|
|
|
size_t s_id{ 0 };
|
2020-05-04 07:37:06 +00:00
|
|
|
Vec3f position{ Vec3f::Zero() };
|
2020-04-28 10:24:03 +00:00
|
|
|
};
|
|
|
|
|
2020-08-03 11:57:10 +00:00
|
|
|
EMoveType type{ EMoveType::Noop };
|
2020-04-16 13:09:04 +00:00
|
|
|
ExtrusionRole role{ erNone };
|
2020-04-28 10:24:03 +00:00
|
|
|
Endpoint first;
|
|
|
|
Endpoint last;
|
2020-04-24 06:46:31 +00:00
|
|
|
float delta_extruder{ 0.0f };
|
2020-04-20 08:52:16 +00:00
|
|
|
float height{ 0.0f };
|
2020-04-20 11:24:25 +00:00
|
|
|
float width{ 0.0f };
|
2020-04-20 14:04:59 +00:00
|
|
|
float feedrate{ 0.0f };
|
2020-04-21 07:06:43 +00:00
|
|
|
float fan_speed{ 0.0f };
|
2020-04-21 09:38:42 +00:00
|
|
|
float volumetric_rate{ 0.0f };
|
2020-04-21 13:55:26 +00:00
|
|
|
unsigned char extruder_id{ 0 };
|
2020-04-22 14:29:07 +00:00
|
|
|
unsigned char cp_color_id{ 0 };
|
2020-04-16 13:09:04 +00:00
|
|
|
|
2020-05-04 07:37:06 +00:00
|
|
|
bool matches(const GCodeProcessor::MoveVertex& move) const;
|
2020-08-28 10:28:21 +00:00
|
|
|
size_t vertices_count() const { return last.s_id - first.s_id + 1; }
|
2020-09-16 13:45:53 +00:00
|
|
|
bool contains(size_t id) const { return first.s_id <= id && id <= last.s_id; }
|
2020-04-16 13:09:04 +00:00
|
|
|
};
|
|
|
|
|
2020-04-28 13:08:36 +00:00
|
|
|
// Used to batch the indices needed to render paths
|
|
|
|
struct RenderPath
|
|
|
|
{
|
2020-05-05 10:09:11 +00:00
|
|
|
Color color;
|
2020-09-16 13:45:53 +00:00
|
|
|
unsigned int path_id;
|
|
|
|
unsigned int index_buffer_id;
|
2020-04-28 13:08:36 +00:00
|
|
|
std::vector<unsigned int> sizes;
|
2020-09-15 06:18:54 +00:00
|
|
|
std::vector<size_t> offsets; // use size_t because we need an unsigned int whose size matches pointer's size (used in the call glMultiDrawElements())
|
2020-04-28 13:08:36 +00:00
|
|
|
};
|
|
|
|
|
2020-06-29 12:00:08 +00:00
|
|
|
// buffer containing data for rendering a specific toolpath type
|
|
|
|
struct TBuffer
|
2020-04-15 14:29:11 +00:00
|
|
|
{
|
2020-09-01 06:29:06 +00:00
|
|
|
enum class ERenderPrimitiveType : unsigned char
|
2020-08-26 13:29:33 +00:00
|
|
|
{
|
|
|
|
Point,
|
|
|
|
Line,
|
|
|
|
Triangle
|
|
|
|
};
|
|
|
|
|
2020-09-01 06:29:06 +00:00
|
|
|
ERenderPrimitiveType render_primitive_type;
|
2020-06-29 12:00:08 +00:00
|
|
|
VBuffer vertices;
|
2020-09-16 13:45:53 +00:00
|
|
|
std::vector<IBuffer> indices;
|
2020-06-29 12:00:08 +00:00
|
|
|
|
2020-05-20 12:11:22 +00:00
|
|
|
std::string shader;
|
2020-04-16 13:09:04 +00:00
|
|
|
std::vector<Path> paths;
|
2020-04-28 13:08:36 +00:00
|
|
|
std::vector<RenderPath> render_paths;
|
2020-04-15 14:29:11 +00:00
|
|
|
bool visible{ false };
|
|
|
|
|
|
|
|
void reset();
|
2020-09-16 13:45:53 +00:00
|
|
|
// b_id index of buffer contained in this->indices
|
|
|
|
// i_id index of first index contained in this->indices[b_id]
|
|
|
|
// s_id index of first vertex contained in this->vertices
|
|
|
|
void add_path(const GCodeProcessor::MoveVertex& move, unsigned int b_id, size_t i_id, size_t s_id);
|
2020-09-01 06:29:06 +00:00
|
|
|
unsigned int indices_per_segment() const {
|
|
|
|
switch (render_primitive_type)
|
|
|
|
{
|
|
|
|
case ERenderPrimitiveType::Point: { return 1; }
|
|
|
|
case ERenderPrimitiveType::Line: { return 2; }
|
|
|
|
case ERenderPrimitiveType::Triangle: { return 42; } // 3 indices x 14 triangles
|
|
|
|
default: { return 0; }
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 12:35:42 +00:00
|
|
|
unsigned int start_segment_vertex_offset() const {
|
|
|
|
switch (render_primitive_type)
|
|
|
|
{
|
|
|
|
case ERenderPrimitiveType::Point:
|
|
|
|
case ERenderPrimitiveType::Line:
|
|
|
|
case ERenderPrimitiveType::Triangle:
|
|
|
|
default: { return 0; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned int end_segment_vertex_offset() const {
|
|
|
|
switch (render_primitive_type)
|
|
|
|
{
|
|
|
|
case ERenderPrimitiveType::Point: { return 0; }
|
|
|
|
case ERenderPrimitiveType::Line: { return 1; }
|
|
|
|
case ERenderPrimitiveType::Triangle: { return 36; } // 1 vertex of 13th triangle
|
|
|
|
default: { return 0; }
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 13:45:53 +00:00
|
|
|
|
|
|
|
bool has_data() const { return vertices.id != 0 && !indices.empty() && indices.front().id != 0; }
|
2020-04-15 14:29:11 +00:00
|
|
|
};
|
|
|
|
|
2020-05-06 09:18:37 +00:00
|
|
|
// helper to render shells
|
2020-04-15 12:31:39 +00:00
|
|
|
struct Shells
|
|
|
|
{
|
|
|
|
GLVolumeCollection volumes;
|
|
|
|
bool visible{ false };
|
|
|
|
};
|
|
|
|
|
2020-04-20 08:52:16 +00:00
|
|
|
// helper to render extrusion paths
|
2020-04-17 08:43:29 +00:00
|
|
|
struct Extrusions
|
|
|
|
{
|
2020-04-20 08:52:16 +00:00
|
|
|
struct Range
|
|
|
|
{
|
|
|
|
float min;
|
|
|
|
float max;
|
2020-08-13 10:51:50 +00:00
|
|
|
unsigned int count;
|
2020-04-20 08:52:16 +00:00
|
|
|
|
|
|
|
Range() { reset(); }
|
|
|
|
|
2020-08-13 10:51:50 +00:00
|
|
|
void update_from(const float value) {
|
|
|
|
if (value != max && value != min)
|
|
|
|
++count;
|
|
|
|
min = std::min(min, value);
|
|
|
|
max = std::max(max, value);
|
|
|
|
}
|
|
|
|
void reset() { min = FLT_MAX; max = -FLT_MAX; count = 0; }
|
2020-04-20 08:52:16 +00:00
|
|
|
|
2020-04-22 14:29:07 +00:00
|
|
|
float step_size() const { return (max - min) / (static_cast<float>(Range_Colors.size()) - 1.0f); }
|
2020-05-05 10:09:11 +00:00
|
|
|
Color get_color_at(float value) const;
|
2020-04-20 08:52:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Ranges
|
|
|
|
{
|
|
|
|
// Color mapping by layer height.
|
|
|
|
Range height;
|
2020-04-20 11:24:25 +00:00
|
|
|
// Color mapping by extrusion width.
|
|
|
|
Range width;
|
2020-04-20 14:04:59 +00:00
|
|
|
// Color mapping by feedrate.
|
|
|
|
Range feedrate;
|
2020-04-21 07:06:43 +00:00
|
|
|
// Color mapping by fan speed.
|
|
|
|
Range fan_speed;
|
2020-04-21 09:38:42 +00:00
|
|
|
// Color mapping by volumetric extrusion rate.
|
|
|
|
Range volumetric_rate;
|
2020-04-20 08:52:16 +00:00
|
|
|
|
|
|
|
void reset() {
|
|
|
|
height.reset();
|
2020-04-20 11:24:25 +00:00
|
|
|
width.reset();
|
2020-04-20 14:04:59 +00:00
|
|
|
feedrate.reset();
|
2020-04-21 07:06:43 +00:00
|
|
|
fan_speed.reset();
|
2020-04-21 09:38:42 +00:00
|
|
|
volumetric_rate.reset();
|
2020-04-20 08:52:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-17 08:43:29 +00:00
|
|
|
unsigned int role_visibility_flags{ 0 };
|
2020-04-20 08:52:16 +00:00
|
|
|
Ranges ranges;
|
2020-04-17 08:43:29 +00:00
|
|
|
|
|
|
|
void reset_role_visibility_flags() {
|
|
|
|
role_visibility_flags = 0;
|
2020-08-26 13:29:33 +00:00
|
|
|
for (unsigned int i = 0; i < erCount; ++i) {
|
2020-04-17 08:43:29 +00:00
|
|
|
role_visibility_flags |= 1 << i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-20 08:52:16 +00:00
|
|
|
void reset_ranges() { ranges.reset(); }
|
2020-04-17 08:43:29 +00:00
|
|
|
};
|
|
|
|
|
2020-04-27 12:10:18 +00:00
|
|
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
|
|
|
struct Statistics
|
|
|
|
{
|
2020-09-11 13:19:23 +00:00
|
|
|
// time
|
2020-06-29 12:00:08 +00:00
|
|
|
long long results_time{ 0 };
|
2020-04-27 12:10:18 +00:00
|
|
|
long long load_time{ 0 };
|
|
|
|
long long refresh_time{ 0 };
|
2020-05-05 11:57:51 +00:00
|
|
|
long long refresh_paths_time{ 0 };
|
2020-06-24 14:57:09 +00:00
|
|
|
// opengl calls
|
2020-04-28 13:08:36 +00:00
|
|
|
long long gl_multi_points_calls_count{ 0 };
|
2020-08-26 13:29:33 +00:00
|
|
|
long long gl_multi_lines_calls_count{ 0 };
|
|
|
|
long long gl_multi_triangles_calls_count{ 0 };
|
2020-06-24 14:57:09 +00:00
|
|
|
// memory
|
2020-04-28 08:29:25 +00:00
|
|
|
long long results_size{ 0 };
|
2020-04-28 13:08:36 +00:00
|
|
|
long long vertices_gpu_size{ 0 };
|
|
|
|
long long indices_gpu_size{ 0 };
|
2020-05-04 07:37:06 +00:00
|
|
|
long long paths_size{ 0 };
|
2020-05-05 10:09:11 +00:00
|
|
|
long long render_paths_size{ 0 };
|
2020-09-11 13:19:23 +00:00
|
|
|
// other
|
2020-06-29 12:00:08 +00:00
|
|
|
long long travel_segments_count{ 0 };
|
|
|
|
long long extrude_segments_count{ 0 };
|
2020-09-11 13:19:23 +00:00
|
|
|
long long max_vertices_in_vertex_buffer{ 0 };
|
|
|
|
long long max_indices_in_index_buffer{ 0 };
|
2020-04-27 12:10:18 +00:00
|
|
|
|
|
|
|
void reset_all() {
|
|
|
|
reset_times();
|
|
|
|
reset_opengl();
|
|
|
|
reset_sizes();
|
2020-09-11 13:19:23 +00:00
|
|
|
reset_others();
|
2020-04-27 12:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_times() {
|
2020-06-29 12:00:08 +00:00
|
|
|
results_time = 0;
|
2020-04-27 12:10:18 +00:00
|
|
|
load_time = 0;
|
|
|
|
refresh_time = 0;
|
2020-05-05 11:57:51 +00:00
|
|
|
refresh_paths_time = 0;
|
2020-04-27 12:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_opengl() {
|
2020-04-28 13:08:36 +00:00
|
|
|
gl_multi_points_calls_count = 0;
|
2020-08-26 13:29:33 +00:00
|
|
|
gl_multi_lines_calls_count = 0;
|
|
|
|
gl_multi_triangles_calls_count = 0;
|
2020-04-27 12:10:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void reset_sizes() {
|
2020-04-28 08:29:25 +00:00
|
|
|
results_size = 0;
|
2020-04-28 13:08:36 +00:00
|
|
|
vertices_gpu_size = 0;
|
|
|
|
indices_gpu_size = 0;
|
2020-06-29 12:00:08 +00:00
|
|
|
paths_size = 0;
|
2020-05-05 10:09:11 +00:00
|
|
|
render_paths_size = 0;
|
2020-04-27 12:10:18 +00:00
|
|
|
}
|
2020-06-29 12:00:08 +00:00
|
|
|
|
2020-09-11 13:19:23 +00:00
|
|
|
void reset_others() {
|
2020-06-29 12:00:08 +00:00
|
|
|
travel_segments_count = 0;
|
|
|
|
extrude_segments_count = 0;
|
2020-09-11 13:19:23 +00:00
|
|
|
max_vertices_in_vertex_buffer = 0;
|
|
|
|
max_indices_in_index_buffer = 0;
|
2020-06-29 12:00:08 +00:00
|
|
|
}
|
2020-04-27 12:10:18 +00:00
|
|
|
};
|
|
|
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
|
|
|
|
2020-04-16 13:59:36 +00:00
|
|
|
public:
|
2020-05-15 07:22:51 +00:00
|
|
|
struct SequentialView
|
|
|
|
{
|
|
|
|
class Marker
|
|
|
|
{
|
2020-05-27 06:06:02 +00:00
|
|
|
GLModel m_model;
|
2020-06-09 06:12:51 +00:00
|
|
|
Vec3f m_world_position;
|
2020-05-15 07:22:51 +00:00
|
|
|
Transform3f m_world_transform;
|
2020-06-09 06:12:51 +00:00
|
|
|
float m_z_offset{ 0.5f };
|
2020-05-15 07:22:51 +00:00
|
|
|
std::array<float, 4> m_color{ 1.0f, 1.0f, 1.0f, 1.0f };
|
|
|
|
bool m_visible{ false };
|
|
|
|
|
|
|
|
public:
|
|
|
|
void init();
|
|
|
|
|
2020-06-24 14:57:09 +00:00
|
|
|
const BoundingBoxf3& get_bounding_box() const { return m_model.get_bounding_box(); }
|
2020-05-15 07:22:51 +00:00
|
|
|
|
2020-05-22 08:43:59 +00:00
|
|
|
void set_world_position(const Vec3f& position);
|
2020-05-15 07:22:51 +00:00
|
|
|
void set_color(const std::array<float, 4>& color) { m_color = color; }
|
|
|
|
|
|
|
|
bool is_visible() const { return m_visible; }
|
|
|
|
void set_visible(bool visible) { m_visible = visible; }
|
|
|
|
|
|
|
|
void render() const;
|
|
|
|
};
|
|
|
|
|
2020-05-18 11:24:07 +00:00
|
|
|
struct Endpoints
|
|
|
|
{
|
2020-09-16 13:45:53 +00:00
|
|
|
size_t first{ 0 };
|
|
|
|
size_t last{ 0 };
|
2020-05-18 11:24:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Endpoints endpoints;
|
|
|
|
Endpoints current;
|
2020-10-07 11:19:44 +00:00
|
|
|
Endpoints last_current;
|
2020-05-15 07:22:51 +00:00
|
|
|
Vec3f current_position{ Vec3f::Zero() };
|
|
|
|
Marker marker;
|
|
|
|
};
|
|
|
|
|
2020-04-16 13:59:36 +00:00
|
|
|
enum class EViewType : unsigned char
|
|
|
|
{
|
|
|
|
FeatureType,
|
|
|
|
Height,
|
|
|
|
Width,
|
|
|
|
Feedrate,
|
|
|
|
FanSpeed,
|
|
|
|
VolumetricRate,
|
|
|
|
Tool,
|
|
|
|
ColorPrint,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2020-04-21 13:55:26 +00:00
|
|
|
unsigned int m_last_result_id{ 0 };
|
2020-09-14 07:18:20 +00:00
|
|
|
size_t m_moves_count{ 0 };
|
2020-08-03 11:57:10 +00:00
|
|
|
mutable std::vector<TBuffer> m_buffers{ static_cast<size_t>(EMoveType::Extrude) };
|
2020-06-24 14:57:09 +00:00
|
|
|
// bounding box of toolpaths
|
|
|
|
BoundingBoxf3 m_paths_bounding_box;
|
|
|
|
// bounding box of toolpaths + marker tools
|
|
|
|
BoundingBoxf3 m_max_bounding_box;
|
2020-05-05 10:09:11 +00:00
|
|
|
std::vector<Color> m_tool_colors;
|
2020-04-14 14:40:08 +00:00
|
|
|
std::vector<double> m_layers_zs;
|
2020-04-27 09:44:29 +00:00
|
|
|
std::array<double, 2> m_layers_z_range;
|
2020-04-18 08:41:37 +00:00
|
|
|
std::vector<ExtrusionRole> m_roles;
|
2020-04-22 14:29:07 +00:00
|
|
|
std::vector<unsigned char> m_extruder_ids;
|
2020-04-28 06:50:52 +00:00
|
|
|
mutable Extrusions m_extrusions;
|
2020-05-05 10:09:11 +00:00
|
|
|
mutable SequentialView m_sequential_view;
|
2020-04-15 12:31:39 +00:00
|
|
|
Shells m_shells;
|
2020-04-24 08:59:03 +00:00
|
|
|
EViewType m_view_type{ EViewType::FeatureType };
|
2020-04-18 08:41:37 +00:00
|
|
|
bool m_legend_enabled{ true };
|
2020-08-03 11:57:10 +00:00
|
|
|
PrintEstimatedTimeStatistics m_time_statistics;
|
2020-08-06 08:15:34 +00:00
|
|
|
mutable PrintEstimatedTimeStatistics::ETimeMode m_time_estimate_mode{ PrintEstimatedTimeStatistics::ETimeMode::Normal };
|
2020-04-27 12:10:18 +00:00
|
|
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
|
|
|
mutable Statistics m_statistics;
|
|
|
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
2020-05-26 06:16:08 +00:00
|
|
|
std::array<float, 2> m_detected_point_sizes = { 0.0f, 0.0f };
|
2020-04-16 13:59:36 +00:00
|
|
|
|
2020-04-14 08:02:08 +00:00
|
|
|
public:
|
|
|
|
GCodeViewer() = default;
|
2020-04-14 14:40:08 +00:00
|
|
|
~GCodeViewer() { reset(); }
|
2020-04-14 08:02:08 +00:00
|
|
|
|
2020-05-26 06:16:08 +00:00
|
|
|
bool init();
|
2020-04-20 14:04:59 +00:00
|
|
|
|
2020-04-21 13:55:26 +00:00
|
|
|
// extract rendering data from the given parameters
|
2020-04-22 14:29:07 +00:00
|
|
|
void load(const GCodeProcessor::Result& gcode_result, const Print& print, bool initialized);
|
|
|
|
// recalculate ranges in dependence of what is visible and sets tool/print colors
|
|
|
|
void refresh(const GCodeProcessor::Result& gcode_result, const std::vector<std::string>& str_tool_colors);
|
2020-04-20 14:04:59 +00:00
|
|
|
|
2020-04-14 14:40:08 +00:00
|
|
|
void reset();
|
2020-04-14 08:02:08 +00:00
|
|
|
void render() const;
|
|
|
|
|
2020-05-05 10:09:11 +00:00
|
|
|
bool has_data() const { return !m_roles.empty(); }
|
|
|
|
|
2020-06-24 14:57:09 +00:00
|
|
|
const BoundingBoxf3& get_paths_bounding_box() const { return m_paths_bounding_box; }
|
|
|
|
const BoundingBoxf3& get_max_bounding_box() const { return m_max_bounding_box; }
|
2020-04-14 14:40:08 +00:00
|
|
|
const std::vector<double>& get_layers_zs() const { return m_layers_zs; };
|
|
|
|
|
2020-05-15 07:22:51 +00:00
|
|
|
const SequentialView& get_sequential_view() const { return m_sequential_view; }
|
2020-10-07 11:19:44 +00:00
|
|
|
void update_sequential_view_current(unsigned int first, unsigned int last);
|
2020-05-15 07:22:51 +00:00
|
|
|
|
2020-04-16 13:59:36 +00:00
|
|
|
EViewType get_view_type() const { return m_view_type; }
|
|
|
|
void set_view_type(EViewType type) {
|
|
|
|
if (type == EViewType::Count)
|
|
|
|
type = EViewType::FeatureType;
|
|
|
|
|
|
|
|
m_view_type = type;
|
|
|
|
}
|
|
|
|
|
2020-08-03 11:57:10 +00:00
|
|
|
bool is_toolpath_move_type_visible(EMoveType type) const;
|
|
|
|
void set_toolpath_move_type_visible(EMoveType type, bool visible);
|
2020-04-28 06:50:52 +00:00
|
|
|
unsigned int get_toolpath_role_visibility_flags() const { return m_extrusions.role_visibility_flags; }
|
2020-04-17 08:43:29 +00:00
|
|
|
void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; }
|
2020-04-28 06:50:52 +00:00
|
|
|
unsigned int get_options_visibility_flags() const;
|
2020-04-24 14:12:38 +00:00
|
|
|
void set_options_visibility_from_flags(unsigned int flags);
|
2020-05-15 07:22:51 +00:00
|
|
|
void set_layers_z_range(const std::array<double, 2>& layers_z_range);
|
2020-04-15 12:31:39 +00:00
|
|
|
|
2020-04-18 08:41:37 +00:00
|
|
|
bool is_legend_enabled() const { return m_legend_enabled; }
|
|
|
|
void enable_legend(bool enable) { m_legend_enabled = enable; }
|
|
|
|
|
2020-07-03 10:17:12 +00:00
|
|
|
void export_toolpaths_to_obj(const char* filename) const;
|
|
|
|
|
2020-04-14 08:02:08 +00:00
|
|
|
private:
|
2020-04-15 12:31:39 +00:00
|
|
|
void load_toolpaths(const GCodeProcessor::Result& gcode_result);
|
|
|
|
void load_shells(const Print& print, bool initialized);
|
2020-10-09 06:45:48 +00:00
|
|
|
void refresh_render_paths(/*bool keep_sequential_current_first,*/ bool keep_sequential_current_last) const;
|
2020-04-15 12:31:39 +00:00
|
|
|
void render_toolpaths() const;
|
|
|
|
void render_shells() const;
|
2020-04-27 12:10:18 +00:00
|
|
|
void render_legend() const;
|
|
|
|
#if ENABLE_GCODE_VIEWER_STATISTICS
|
|
|
|
void render_statistics() const;
|
|
|
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
2020-04-27 10:43:51 +00:00
|
|
|
bool is_visible(ExtrusionRole role) const {
|
|
|
|
return role < erCount && (m_extrusions.role_visibility_flags & (1 << role)) != 0;
|
|
|
|
}
|
|
|
|
bool is_visible(const Path& path) const { return is_visible(path.role); }
|
2020-09-15 06:18:54 +00:00
|
|
|
void log_memory_used(const std::string& label, long long additional = 0) const;
|
2020-04-14 08:02:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace GUI
|
|
|
|
} // namespace Slic3r
|
|
|
|
|
|
|
|
#endif // ENABLE_GCODE_VIEWER
|
|
|
|
|
|
|
|
#endif // slic3r_GCodeViewer_hpp_
|
|
|
|
|