New gcode visualization integration - View ranges management moved to new visualizer

This commit is contained in:
enricoturri1966 2023-11-27 14:14:36 +01:00 committed by Lukas Matena
parent 9cec7dc3a2
commit 560263ea05
16 changed files with 417 additions and 236 deletions

View File

@ -59,6 +59,12 @@ static Vec3 convert(const Slic3r::Vec3f& v)
return { v.x(), v.y(), v.z() }; return { v.x(), v.y(), v.z() };
} }
// mapping from libvgcode::Vec3 to Slic3r::Vec3f
static Slic3r::Vec3f convert(const Vec3& v)
{
return { v[0], v[1], v[2] };
}
// mapping from Slic3r::Matrix4f to libvgcode::Mat4x4 // mapping from Slic3r::Matrix4f to libvgcode::Mat4x4
static Mat4x4 convert(const Slic3r::Matrix4f& m) static Mat4x4 convert(const Slic3r::Matrix4f& m)
{ {
@ -70,13 +76,14 @@ static Mat4x4 convert(const Slic3r::Matrix4f& m)
// mapping from libvgcode::Color to Slic3r::ColorRGBA // mapping from libvgcode::Color to Slic3r::ColorRGBA
static Slic3r::ColorRGBA convert(const Color& c) static Slic3r::ColorRGBA convert(const Color& c)
{ {
return { c[0], c[1], c[2], 1.0f }; static const float inv_255 = 1.0f / 255.0f;
return { c[0] * inv_255, c[1] * inv_255, c[2] * inv_255, 1.0f };
} }
// mapping from Slic3r::ColorRGBA to libvgcode::Color // mapping from Slic3r::ColorRGBA to libvgcode::Color
static Color convert(const Slic3r::ColorRGBA& c) static Color convert(const Slic3r::ColorRGBA& c)
{ {
return { c.r(), c.g(), c.b() }; return { static_cast<uint8_t>(c.r() * 255.0f), static_cast<uint8_t>(c.g() * 255.0f), static_cast<uint8_t>(c.b() * 255.0f) };
} }
// mapping from libvgcode::EGCodeExtrusionRole to Slic3r::GCodeExtrusionRole // mapping from libvgcode::EGCodeExtrusionRole to Slic3r::GCodeExtrusionRole
@ -180,21 +187,12 @@ static GCodeInputData convert(const Slic3r::GCodeProcessorResult& result)
const std::vector<Slic3r::GCodeProcessorResult::MoveVertex>& moves = result.moves; const std::vector<Slic3r::GCodeProcessorResult::MoveVertex>& moves = result.moves;
GCodeInputData ret; GCodeInputData ret;
ret.vertices.reserve(2 * moves.size()); ret.vertices.reserve(2 * moves.size());
// Seam moves have no correspondence in the gcode,
// there are no gcode lines associated to them,
// but are added at the end of a loop, by the gcode processor, to be able to visualize them.
// To properly associate the other moves to the gcode lines, we need to keep track
// of them and modify the vertices' move_id accordingly.
uint32_t seams_count = 0;
for (size_t i = 1; i < moves.size(); ++i) { for (size_t i = 1; i < moves.size(); ++i) {
const Slic3r::GCodeProcessorResult::MoveVertex& curr = moves[i]; const Slic3r::GCodeProcessorResult::MoveVertex& curr = moves[i];
const Slic3r::GCodeProcessorResult::MoveVertex& prev = moves[i - 1]; const Slic3r::GCodeProcessorResult::MoveVertex& prev = moves[i - 1];
const EMoveType curr_type = convert(curr.type); const EMoveType curr_type = convert(curr.type);
const EGCodeExtrusionRole curr_role = convert(curr.extrusion_role); const EGCodeExtrusionRole curr_role = convert(curr.extrusion_role);
if (curr_type == EMoveType::Seam)
++seams_count;
EGCodeExtrusionRole extrusion_role; EGCodeExtrusionRole extrusion_role;
if (curr_type == EMoveType::Travel) { if (curr_type == EMoveType::Travel) {
// for travel moves set the extrusion role // for travel moves set the extrusion role
@ -239,29 +237,28 @@ static GCodeInputData convert(const Slic3r::GCodeProcessorResult& result)
// equal to the current one with the exception of the position, which should match the previous move position, // equal to the current one with the exception of the position, which should match the previous move position,
// and the times, which are set to zero // and the times, which are set to zero
#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed,
curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type,
static_cast<uint32_t>(i) - seams_count, static_cast<uint32_t>(curr.layer_id), static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } }; static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
#else #else
const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed,
curr.temperature, curr.volumetric_rate(), 0.0f, curr.temperature, curr.volumetric_rate(), 0.0f, extrusion_role, curr_type,
extrusion_role, curr_type, static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
static_cast<uint32_t>(i) - seams_count, static_cast<uint32_t>(curr.layer_id), static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), { 0.0f, 0.0f } };
#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
ret.vertices.emplace_back(vertex); ret.vertices.emplace_back(vertex);
} }
} }
#if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #if ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature, const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed,
curr.volumetric_rate(), extrusion_role, curr_type, static_cast<uint32_t>(i) - seams_count, static_cast<uint32_t>(curr.layer_id), curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, static_cast<uint32_t>(curr.gcode_id),
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time }; static_cast<uint32_t>(curr.layer_id), static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
#else #else
const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature, const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed,
curr.volumetric_rate(), curr.mm3_per_mm * (curr.position - prev.position).norm(), extrusion_role, curr_type, curr.temperature, curr.volumetric_rate(), curr.mm3_per_mm * (curr.position - prev.position).norm(),
static_cast<uint32_t>(i) - seams_count, static_cast<uint32_t>(curr.layer_id), extrusion_role, curr_type, static_cast<uint32_t>(curr.gcode_id), static_cast<uint32_t>(curr.layer_id),
static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time }; static_cast<uint8_t>(curr.extruder_id), static_cast<uint8_t>(curr.cp_color_id), curr.time };
#endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #endif // ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
ret.vertices.emplace_back(vertex); ret.vertices.emplace_back(vertex);
@ -728,7 +725,7 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode
ImGui::SameLine(); ImGui::SameLine();
libvgcode::PathVertex vertex = viewer->get_current_vertex(); libvgcode::PathVertex vertex = viewer->get_current_vertex();
if (vertex.type == libvgcode::EMoveType::Seam) if (vertex.type == libvgcode::EMoveType::Seam)
vertex = viewer->get_vertex_at(viewer->get_view_current_range()[1] - 1); vertex = viewer->get_vertex_at(viewer->get_view_visible_range()[1] - 1);
char buf[1024]; char buf[1024];
sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", vertex.position[0], vertex.position[1], vertex.position[2]); sprintf(buf, "X: %.3f, Y: %.3f, Z: %.3f", vertex.position[0], vertex.position[1], vertex.position[2]);
@ -1141,33 +1138,41 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
void GCodeViewer::SequentialView::render(float legend_height, const libvgcode::Viewer* viewer) void GCodeViewer::SequentialView::render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id)
{ {
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
if (viewer == nullptr) if (viewer == nullptr)
#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void GCodeViewer::SequentialView::render(float legend_height) void GCodeViewer::SequentialView::render(float legend_height)
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER #endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
marker.render(); marker.render();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
marker.render_position_window(viewer); marker.render_position_window(viewer);
#endif // ENABLE_NEW_GCODE_VIEWER #endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height(); float bottom = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size().get_height();
if (wxGetApp().is_editor()) if (wxGetApp().is_editor())
bottom -= wxGetApp().plater()->get_view_toolbar().get_height(); bottom -= wxGetApp().plater()->get_view_toolbar().get_height();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
gcode_window.render(legend_height, bottom, gcode_id);
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
gcode_window.render(legend_height, bottom, static_cast<uint64_t>(gcode_ids[current.last])); gcode_window.render(legend_height, bottom, static_cast<uint64_t>(gcode_ids[current.last]));
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
const std::array<ColorRGBA, static_cast<size_t>(GCodeExtrusionRole::Count)> GCodeViewer::Extrusion_Role_Colors{ { const std::array<ColorRGBA, static_cast<size_t>(GCodeExtrusionRole::Count)> GCodeViewer::Extrusion_Role_Colors{ {
{ 0.90f, 0.70f, 0.70f, 1.0f }, // GCodeExtrusionRole::None { 0.90f, 0.70f, 0.70f, 1.0f }, // GCodeExtrusionRole::None
{ 1.00f, 0.90f, 0.30f, 1.0f }, // GCodeExtrusionRole::Perimeter { 1.00f, 0.90f, 0.30f, 1.0f }, // GCodeExtrusionRole::Perimeter
@ -1246,27 +1251,27 @@ const std::vector<ColorRGBA> GCodeViewer::Range_Colors{ {
const ColorRGBA GCodeViewer::Wipe_Color = ColorRGBA::YELLOW(); const ColorRGBA GCodeViewer::Wipe_Color = ColorRGBA::YELLOW();
const ColorRGBA GCodeViewer::Neutral_Color = ColorRGBA::DARK_GRAY(); const ColorRGBA GCodeViewer::Neutral_Color = ColorRGBA::DARK_GRAY();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
GCodeViewer::GCodeViewer() GCodeViewer::GCodeViewer()
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_extrusions.reset_role_visibility_flags(); m_extrusions.reset_role_visibility_flags();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_shells.volumes.set_use_raycasters(false); m_shells.volumes.set_use_raycasters(false);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// m_sequential_view.skip_invisible_moves = true; // m_sequential_view.skip_invisible_moves = true;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
} }
void GCodeViewer::init() void GCodeViewer::init()
@ -1719,13 +1724,22 @@ void GCodeViewer::render()
float legend_height = 0.0f; float legend_height = 0.0f;
if (!m_layers.empty()) { if (!m_layers.empty()) {
render_legend(legend_height); render_legend(legend_height);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
if (m_new_viewer.get_view_enabled_range()[1] != m_new_viewer.get_view_visible_range()[1]) {
m_sequential_view.marker.set_world_position(libvgcode::convert(m_new_viewer.get_current_vertex().position));
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
if (m_sequential_view.current.last != m_sequential_view.endpoints.last) { if (m_sequential_view.current.last != m_sequential_view.endpoints.last) {
m_sequential_view.marker.set_world_position(m_sequential_view.current_position); m_sequential_view.marker.set_world_position(m_sequential_view.current_position);
m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset); m_sequential_view.marker.set_world_offset(m_sequential_view.current_offset);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_sequential_view.marker.set_z_offset(m_z_offset); m_sequential_view.marker.set_z_offset(m_z_offset);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
m_sequential_view.render(legend_height, m_use_new_viewer ? &m_new_viewer : nullptr); m_sequential_view.render(legend_height, m_use_new_viewer ? &m_new_viewer : nullptr, m_new_viewer.get_current_vertex().gcode_id);
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_sequential_view.render(legend_height); m_sequential_view.render(legend_height);
@ -1743,7 +1757,9 @@ void GCodeViewer::render()
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
if (m_use_new_viewer) { if (m_use_new_viewer) {
ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui();
imgui.begin(std::string("LibVGCode Viewer Controller"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size();
imgui.set_next_window_pos(static_cast<float>(cnv_size.get_width()), static_cast<float>(cnv_size.get_height()), ImGuiCond_Always, 1.0f, 1.0f);
imgui.begin(std::string("LibVGCode Viewer Controller"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
imgui.checkbox("Cog marker fixed screen size", m_cog_marker_fixed_screen_size); imgui.checkbox("Cog marker fixed screen size", m_cog_marker_fixed_screen_size);
if (ImGui::BeginTable("Cog", 2)) { if (ImGui::BeginTable("Cog", 2)) {
@ -1785,10 +1801,7 @@ void GCodeViewer::update_sequential_view_current(unsigned int first, unsigned in
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
m_new_viewer.set_view_current_range(static_cast<uint32_t>(first), static_cast<uint32_t>(last)); m_new_viewer.set_view_visible_range(static_cast<uint32_t>(first), static_cast<uint32_t>(last));
m_sequential_view.current.first = first;
m_sequential_view.current.last = last;
m_sequential_view.last_current = m_sequential_view.current;
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
auto is_visible = [this](unsigned int id) { auto is_visible = [this](unsigned int id) {
@ -2426,22 +2439,28 @@ void GCodeViewer::load_toolpaths(const GCodeProcessorResult& gcode_result)
m_cog.reset(); m_cog.reset();
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
m_sequential_view.gcode_ids.clear(); m_sequential_view.gcode_ids.clear();
for (size_t i = 0; i < gcode_result.moves.size(); ++i) { for (size_t i = 0; i < gcode_result.moves.size(); ++i) {
const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i]; const GCodeProcessorResult::MoveVertex& move = gcode_result.moves[i];
if (move.type != EMoveType::Seam) if (move.type != EMoveType::Seam)
m_sequential_view.gcode_ids.push_back(move.gcode_id); m_sequential_view.gcode_ids.push_back(move.gcode_id);
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
bool account_for_volumetric_rate = m_new_viewer.get_view_type() == libvgcode::EViewType::VolumetricFlowRate; bool account_for_volumetric_rate = m_new_viewer.get_view_type() == libvgcode::EViewType::VolumetricFlowRate;
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bool account_for_volumetric_rate = m_view_type == EViewType::VolumetricRate; bool account_for_volumetric_rate = m_view_type == EViewType::VolumetricRate;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER #endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::vector<MultiVertexBuffer> vertices(m_buffers.size()); std::vector<MultiVertexBuffer> vertices(m_buffers.size());
std::vector<MultiIndexBuffer> indices(m_buffers.size()); std::vector<MultiIndexBuffer> indices(m_buffers.size());
@ -3913,7 +3932,9 @@ void GCodeViewer::render_new_toolpaths()
#if ENABLE_NEW_GCODE_VIEWER_DEBUG #if ENABLE_NEW_GCODE_VIEWER_DEBUG
Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui(); Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui();
imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse); const Size cnv_size = wxGetApp().plater()->get_current_canvas3D()->get_canvas_size();
imgui.set_next_window_pos(static_cast<float>(cnv_size.get_width()), 0.0f, ImGuiCond_Always, 1.0f, 0.0f);
imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize);
if (ImGui::BeginTable("Data", 2)) { if (ImGui::BeginTable("Data", 2)) {
@ -3950,17 +3971,30 @@ void GCodeViewer::render_new_toolpaths()
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (current)"); imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (full)");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
const std::array<uint32_t, 2>& current_view_range = m_new_viewer.get_view_current_range(); const std::array<uint32_t, 2>& full_view_range = m_new_viewer.get_view_full_range();
imgui.text(std::to_string(current_view_range[0]) + " - " + std::to_string(current_view_range[1])); imgui.text(std::to_string(full_view_range[0]) + " - " + std::to_string(full_view_range[1]) + " | " +
std::to_string(m_new_viewer.get_vertex_at(full_view_range[0]).gcode_id) + " - " +
std::to_string(m_new_viewer.get_vertex_at(full_view_range[1]).gcode_id));
ImGui::TableNextRow(); ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0); ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (global)"); imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (enabled)");
ImGui::TableSetColumnIndex(1); ImGui::TableSetColumnIndex(1);
const std::array<uint32_t, 2>& global_view_range = m_new_viewer.get_view_global_range(); const std::array<uint32_t, 2>& enabled_view_range = m_new_viewer.get_view_enabled_range();
imgui.text(std::to_string(global_view_range[0]) + " - " + std::to_string(global_view_range[1])); imgui.text(std::to_string(enabled_view_range[0]) + " - " + std::to_string(enabled_view_range[1]) + " | " +
std::to_string(m_new_viewer.get_vertex_at(enabled_view_range[0]).gcode_id) + " - " +
std::to_string(m_new_viewer.get_vertex_at(enabled_view_range[1]).gcode_id));
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (visible)");
ImGui::TableSetColumnIndex(1);
const std::array<uint32_t, 2>& visible_view_range = m_new_viewer.get_view_visible_range();
imgui.text(std::to_string(visible_view_range[0]) + " - " + std::to_string(visible_view_range[1]) + " | " +
std::to_string(m_new_viewer.get_vertex_at(visible_view_range[0]).gcode_id) + " - " +
std::to_string(m_new_viewer.get_vertex_at(visible_view_range[1]).gcode_id));
auto add_range_property_row = [&imgui](const std::string& label, const std::array<float, 2>& range) { auto add_range_property_row = [&imgui](const std::string& label, const std::array<float, 2>& range) {
ImGui::TableNextRow(); ImGui::TableNextRow();

View File

@ -835,11 +835,17 @@ public:
Vec3f current_offset{ Vec3f::Zero() }; Vec3f current_offset{ Vec3f::Zero() };
Marker marker; Marker marker;
GCodeWindow gcode_window; GCodeWindow gcode_window;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
std::vector<unsigned int> gcode_ids; std::vector<unsigned int> gcode_ids;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
void render(float legend_height, const libvgcode::Viewer* viewer); void render(float legend_height, const libvgcode::Viewer* viewer, uint32_t gcode_id);
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void render(float legend_height); void render(float legend_height);
@ -848,9 +854,9 @@ public:
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}; };
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
enum class EViewType : unsigned char enum class EViewType : unsigned char
{ {
FeatureType, FeatureType,
@ -866,20 +872,20 @@ public:
ColorPrint, ColorPrint,
Count Count
}; };
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
private: private:
bool m_gl_data_initialized{ false }; bool m_gl_data_initialized{ false };
unsigned int m_last_result_id{ 0 }; unsigned int m_last_result_id{ 0 };
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EViewType m_last_view_type{ EViewType::Count }; EViewType m_last_view_type{ EViewType::Count };
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
size_t m_moves_count{ 0 }; size_t m_moves_count{ 0 };
std::vector<TBuffer> m_buffers{ static_cast<size_t>(EMoveType::Extrude) }; std::vector<TBuffer> m_buffers{ static_cast<size_t>(EMoveType::Extrude) };
// bounding box of toolpaths // bounding box of toolpaths
@ -1055,14 +1061,23 @@ public:
const SequentialView& get_sequential_view() const { return m_sequential_view; } const SequentialView& get_sequential_view() const { return m_sequential_view; }
void update_sequential_view_current(unsigned int first, unsigned int last); void update_sequential_view_current(unsigned int first, unsigned int last);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
const std::array<uint32_t, 2>& get_gcode_view_full_range() const { return m_new_viewer.get_view_full_range(); }
const std::array<uint32_t, 2>& get_gcode_view_enabled_range() const { return m_new_viewer.get_view_enabled_range(); }
const std::array<uint32_t, 2>& get_gcode_view_visible_range() const { return m_new_viewer.get_view_visible_range(); }
libvgcode::PathVertex get_gcode_vertex_at(size_t id) const { return m_new_viewer.get_vertex_at(id); }
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bool is_contained_in_bed() const { return m_contained_in_bed; } bool is_contained_in_bed() const { return m_contained_in_bed; }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
void set_view_type(libvgcode::EViewType type) { m_new_viewer.set_view_type(type); } void set_view_type(libvgcode::EViewType type) { m_new_viewer.set_view_type(type); }
libvgcode::EViewType get_view_type() const { return m_new_viewer.get_view_type(); } libvgcode::EViewType get_view_type() const { return m_new_viewer.get_view_type(); }
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
EViewType get_view_type() const { return m_view_type; } EViewType get_view_type() const { return m_view_type; }
void set_view_type(EViewType type) { void set_view_type(EViewType type) {
if (type == EViewType::Count) if (type == EViewType::Count)
@ -1070,20 +1085,20 @@ public:
m_view_type = type; m_view_type = type;
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER #endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bool is_toolpath_move_type_visible(EMoveType type) const; bool is_toolpath_move_type_visible(EMoveType type) const;
void set_toolpath_move_type_visible(EMoveType type, bool visible); void set_toolpath_move_type_visible(EMoveType type, bool visible);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if !ENABLE_NEW_GCODE_VIEWER #if !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
unsigned int get_toolpath_role_visibility_flags() const { return m_extrusions.role_visibility_flags; } unsigned int get_toolpath_role_visibility_flags() const { return m_extrusions.role_visibility_flags; }
void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; } void set_toolpath_role_visibility_flags(unsigned int flags) { m_extrusions.role_visibility_flags = flags; }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // !ENABLE_NEW_GCODE_VIEWER #endif // !ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
unsigned int get_options_visibility_flags() const; unsigned int get_options_visibility_flags() const;
void set_options_visibility_from_flags(unsigned int flags); void set_options_visibility_from_flags(unsigned int flags);
void set_layers_z_range(const std::array<unsigned int, 2>& layers_z_range); void set_layers_z_range(const std::array<unsigned int, 2>& layers_z_range);

View File

@ -736,9 +736,11 @@ public:
const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); } const GCodeViewer::SequentialView& get_gcode_sequential_view() const { return m_gcode_viewer.get_sequential_view(); }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); }
m_gcode_viewer.update_sequential_view_current(first, last); const std::array<uint32_t, 2>& get_gcode_view_full_range() const { return m_gcode_viewer.get_gcode_view_full_range(); }
} const std::array<uint32_t, 2>& get_gcode_view_enabled_range() const { return m_gcode_viewer.get_gcode_view_enabled_range(); }
const std::array<uint32_t, 2>& get_gcode_view_visible_range() const { return m_gcode_viewer.get_gcode_view_visible_range(); }
libvgcode::PathVertex get_gcode_vertex_at(size_t id) const { return m_gcode_viewer.get_gcode_vertex_at(id); }
#else #else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); } void update_gcode_sequential_view_current(unsigned int first, unsigned int last) { m_gcode_viewer.update_sequential_view_current(first, last); }

View File

@ -713,6 +713,40 @@ void Preview::update_layers_slider_from_canvas(wxKeyEvent& event)
void Preview::update_moves_slider() void Preview::update_moves_slider()
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
const std::array<uint32_t, 2>& range = m_canvas->get_gcode_view_enabled_range();
uint32_t last_gcode_id = m_canvas->get_gcode_vertex_at(static_cast<size_t>(range[0])).gcode_id;
const size_t range_size = static_cast<size_t>(range[1] - range[0] + 1);
std::vector<double> values;
values.reserve(range_size);
std::vector<double> alternate_values;
alternate_values.reserve(range_size);
for (uint32_t i = range[0]; i <= range[1]; ++i) {
const uint32_t gcode_id = m_canvas->get_gcode_vertex_at(static_cast<size_t>(i)).gcode_id;
if (i > range[0]) {
// skip consecutive moves with same gcode id (resulting from processing G2 and G3 lines)
if (last_gcode_id == gcode_id) {
values.back() = static_cast<double>(i + 1);
alternate_values.back() = static_cast<double>(gcode_id);
continue;
}
else
last_gcode_id = gcode_id;
}
values.emplace_back(static_cast<double>(i + 1));
alternate_values.emplace_back(static_cast<double>(gcode_id));
}
m_moves_slider->SetSliderValues(values);
m_moves_slider->SetSliderAlternateValues(alternate_values);
m_moves_slider->SetMaxValue(int(values.size()) - 1);
m_moves_slider->SetSelectionSpan(values.front() - 1 - range[0], values.back() - 1 - range[0]);
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
const GCodeViewer::SequentialView& view = m_canvas->get_gcode_sequential_view(); const GCodeViewer::SequentialView& view = m_canvas->get_gcode_sequential_view();
// this should not be needed, but it is here to try to prevent rambling crashes on Mac Asan // this should not be needed, but it is here to try to prevent rambling crashes on Mac Asan
if (view.endpoints.last < view.endpoints.first) if (view.endpoints.last < view.endpoints.first)
@ -746,6 +780,9 @@ void Preview::update_moves_slider()
m_moves_slider->SetSliderAlternateValues(alternate_values); m_moves_slider->SetSliderAlternateValues(alternate_values);
m_moves_slider->SetMaxValue(int(values.size()) - 1); m_moves_slider->SetMaxValue(int(values.size()) - 1);
m_moves_slider->SetSelectionSpan(values.front() - 1 - view.endpoints.first, values.back() - 1 - view.endpoints.first); m_moves_slider->SetSelectionSpan(values.front() - 1 - view.endpoints.first, values.back() - 1 - view.endpoints.first);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
} }
void Preview::enable_moves_slider(bool enable) void Preview::enable_moves_slider(bool enable)

View File

@ -28,7 +28,7 @@ struct PathVertex
#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS #endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
EGCodeExtrusionRole role{ EGCodeExtrusionRole::None }; EGCodeExtrusionRole role{ EGCodeExtrusionRole::None };
EMoveType type{ EMoveType::Noop }; EMoveType type{ EMoveType::Noop };
uint32_t move_id{ 0 }; uint32_t gcode_id{ 0 };
uint32_t layer_id{ 0 }; uint32_t layer_id{ 0 };
uint8_t extruder_id{ 0 }; uint8_t extruder_id{ 0 };
uint8_t color_id{ 0 }; uint8_t color_id{ 0 };

View File

@ -23,6 +23,11 @@ const std::array<uint32_t, 2>& Range::get() const
return m_range; return m_range;
} }
void Range::set(const Range& other)
{
m_range = other.m_range;
}
void Range::set(const std::array<uint32_t, 2>& range) void Range::set(const std::array<uint32_t, 2>& range)
{ {
set(range[0], range[1]); set(range[0], range[1]);
@ -36,6 +41,26 @@ void Range::set(uint32_t min, uint32_t max)
m_range[1] = max; m_range[1] = max;
} }
uint32_t Range::get_min() const
{
return m_range[0];
}
void Range::set_min(uint32_t min)
{
set(min, m_range[1]);
}
uint32_t Range::get_max() const
{
return m_range[1];
}
void Range::set_max(uint32_t max)
{
set(m_range[0], max);
}
void Range::clamp(Range& other) void Range::clamp(Range& other)
{ {
other.m_range[0] = std::clamp(other.m_range[0], m_range[0], m_range[1]); other.m_range[0] = std::clamp(other.m_range[0], m_range[0], m_range[1]);

View File

@ -19,8 +19,16 @@ class Range
{ {
public: public:
const std::array<uint32_t, 2>& get() const; const std::array<uint32_t, 2>& get() const;
void set(const Range& other);
void set(const std::array<uint32_t, 2>& range); void set(const std::array<uint32_t, 2>& range);
void set(uint32_t min, uint32_t max); void set(uint32_t min, uint32_t max);
uint32_t get_min() const;
void set_min(uint32_t min);
uint32_t get_max() const;
void set_max(uint32_t max);
// clamp the given range to stay inside this range // clamp the given range to stay inside this range
void clamp(Range& other); void clamp(Range& other);
void reset(); void reset();

View File

@ -18,7 +18,7 @@ namespace libvgcode {
struct Settings struct Settings
{ {
bool update_view_global_range{ true }; bool update_view_full_range{ true };
bool update_enabled_entities{ true }; bool update_enabled_entities{ true };
bool update_colors{ true }; bool update_colors{ true };
EViewType view_type{ EViewType::FeatureType }; EViewType view_type{ EViewType::FeatureType };

View File

@ -34,12 +34,17 @@ EOptionType type_to_option(EMoveType type)
} }
} }
static uint8_t lerp(uint8_t f1, uint8_t f2, float t)
{
const float one_minus_t = 1.0f - t;
return static_cast<uint8_t>(one_minus_t * static_cast<float>(f1) + t * static_cast<float>(f2));
}
// It will be possible to replace this with std::lerp when using c++20
Color lerp(const Color& c1, const Color& c2, float t) Color lerp(const Color& c1, const Color& c2, float t)
{ {
// It will be possible to replace this with std::lerp when using c++20
t = std::clamp(t, 0.0f, 1.0f); t = std::clamp(t, 0.0f, 1.0f);
const float one_minus_t = 1.0f - t; return { lerp(c1[0], c2[0], t), lerp(c1[1], c2[1], t), lerp(c1[2], c2[2], t) };
return { one_minus_t * c1[0] + t * c2[0], one_minus_t * c1[1] + t * c2[1], one_minus_t * c1[2] + t * c2[2] };
} }
} // namespace libvgcode } // namespace libvgcode

View File

@ -23,6 +23,9 @@ static constexpr float Default_Wipe_Radius = 0.05f;
// //
// Vector in 3 dimensions // Vector in 3 dimensions
// [0] -> x
// [1] -> y
// [2] -> z
// Used for positions, displacements and so on. // Used for positions, displacements and so on.
// //
using Vec3 = std::array<float, 3>; using Vec3 = std::array<float, 3>;
@ -37,12 +40,12 @@ using Vec3 = std::array<float, 3>;
using Mat4x4 = std::array<float, 16>; using Mat4x4 = std::array<float, 16>;
// //
// RGB color
// [0] -> red // [0] -> red
// [1] -> green // [1] -> green
// [2] -> blue // [2] -> blue
// Values should belong to the range [0..1]
// //
using Color = std::array<float, 3>; using Color = std::array<uint8_t, 3>;
// //
// View types // View types
@ -142,8 +145,8 @@ static constexpr size_t Time_Modes_Count = static_cast<size_t>(ETimeMode::COUNT)
// //
// Predefined colors // Predefined colors
// //
static const Color Dummy_Color{ 0.25f, 0.25f, 0.25f }; static const Color Dummy_Color{ 64, 64, 64 };
static const Color Wipe_Color{ 1.0f, 1.0f, 0.0f }; static const Color Wipe_Color { 255, 255, 255 };
// //
// Palette used to render moves by ranges // Palette used to render moves by ranges
@ -151,17 +154,17 @@ static const Color Wipe_Color{ 1.0f, 1.0f, 0.0f };
// LayerTimeLinear, LayerTimeLogarithmic // LayerTimeLinear, LayerTimeLogarithmic
// //
static const std::vector<Color> Ranges_Colors{ { static const std::vector<Color> Ranges_Colors{ {
{ 0.043f, 0.173f, 0.478f }, // bluish { 11, 44, 122 }, // bluish
{ 0.075f, 0.349f, 0.522f }, { 19, 89, 133 },
{ 0.110f, 0.533f, 0.569f }, { 28, 136, 145 },
{ 0.016f, 0.839f, 0.059f }, { 4, 214, 15 },
{ 0.667f, 0.949f, 0.000f }, { 170, 242, 0 },
{ 0.988f, 0.975f, 0.012f }, { 252, 249, 3 },
{ 0.961f, 0.808f, 0.039f }, { 245, 206, 10 },
{ 0.890f, 0.533f, 0.125f }, { 227, 136, 32 },
{ 0.820f, 0.408f, 0.188f }, { 209, 104, 48 },
{ 0.761f, 0.322f, 0.235f }, { 194, 82, 60 },
{ 0.581f, 0.149f, 0.087f } // reddish { 148, 38, 22 } // reddish
} }; } };
// //
@ -169,21 +172,21 @@ static const std::vector<Color> Ranges_Colors{ {
// EViewType: FeatureType // EViewType: FeatureType
// //
static const std::vector<Color> Extrusion_Roles_Colors{ { static const std::vector<Color> Extrusion_Roles_Colors{ {
{ 0.90f, 0.70f, 0.70f }, // None { 230, 179, 179 }, // None
{ 1.00f, 0.90f, 0.30f }, // Perimeter { 255, 230, 77 }, // Perimeter
{ 1.00f, 0.49f, 0.22f }, // ExternalPerimeter { 255, 125, 56 }, // ExternalPerimeter
{ 0.12f, 0.12f, 1.00f }, // OverhangPerimeter { 31, 31, 255 }, // OverhangPerimeter
{ 0.69f, 0.19f, 0.16f }, // InternalInfill { 176, 48, 41 }, // InternalInfill
{ 0.59f, 0.33f, 0.80f }, // SolidInfill { 150, 84, 204 }, // SolidInfill
{ 0.94f, 0.25f, 0.25f }, // TopSolidInfill { 240, 64, 64 }, // TopSolidInfill
{ 1.00f, 0.55f, 0.41f }, // Ironing { 255, 140, 105 }, // Ironing
{ 0.30f, 0.50f, 0.73f }, // BridgeInfill { 77, 128, 186 }, // BridgeInfill
{ 1.00f, 1.00f, 1.00f }, // GapFill { 255, 255, 255 }, // GapFill
{ 0.00f, 0.53f, 0.43f }, // Skirt { 0, 135, 110 }, // Skirt
{ 0.00f, 1.00f, 0.00f }, // SupportMaterial { 0, 255, 0 }, // SupportMaterial
{ 0.00f, 0.50f, 0.00f }, // SupportMaterialInterface { 0, 128, 0 }, // SupportMaterialInterface
{ 0.70f, 0.89f, 0.67f }, // WipeTower { 179, 227, 171 }, // WipeTower
{ 0.37f, 0.82f, 0.58f }, // Custom { 94, 209, 148 } // Custom
} }; } };
// //
@ -192,22 +195,22 @@ static const std::vector<Color> Extrusion_Roles_Colors{ {
// LayerTimeLinear, LayerTimeLogarithmic // LayerTimeLinear, LayerTimeLogarithmic
// //
static const std::vector<Color> Travels_Colors{ { static const std::vector<Color> Travels_Colors{ {
{ 0.219f, 0.282f, 0.609f }, // Move { 56, 72, 155 }, // Move
{ 0.112f, 0.422f, 0.103f }, // Extrude { 29, 108, 26 }, // Extrude
{ 0.505f, 0.064f, 0.028f } // Retract { 129, 16, 7 } // Retract
} }; } };
// //
// Palette used to render options // Palette used to render options
// //
static const std::map<EMoveType, Color> Options_Colors{ { static const std::map<EMoveType, Color> Options_Colors{ {
{ EMoveType::Retract, { 0.803f, 0.135f, 0.839f } }, { EMoveType::Retract, { 205, 34, 214 } },
{ EMoveType::Unretract, { 0.287f, 0.679f, 0.810f } }, { EMoveType::Unretract, { 73, 173, 207 } },
{ EMoveType::Seam, { 0.900f, 0.900f, 0.900f } }, { EMoveType::Seam, { 230, 230, 230 } },
{ EMoveType::ToolChange, { 0.758f, 0.744f, 0.389f } }, { EMoveType::ToolChange, { 193, 190, 99 } },
{ EMoveType::ColorChange, { 0.856f, 0.582f, 0.546f } }, { EMoveType::ColorChange, { 218, 148, 139 } },
{ EMoveType::PausePrint, { 0.322f, 0.942f, 0.512f } }, { EMoveType::PausePrint, { 82, 240, 131 } },
{ EMoveType::CustomGCode, { 0.886f, 0.825f, 0.262f } } { EMoveType::CustomGCode, { 226, 210, 67 } }
} }; } };
// //

View File

@ -16,59 +16,92 @@
namespace libvgcode { namespace libvgcode {
const std::array<uint32_t, 2>& ViewRange::get_current() const const std::array<uint32_t, 2>& ViewRange::get_full() const
{ {
return m_current.get(); return m_full.get();
} }
void ViewRange::set_current(const Range& other) void ViewRange::set_full(const Range& other)
{ {
set_current(other.get()); set_full(other.get());
} }
void ViewRange::set_current(const std::array<uint32_t, 2>& range) void ViewRange::set_full(const std::array<uint32_t, 2>& range)
{ {
set_current(range[0], range[1]); set_full(range[0], range[1]);
} }
void ViewRange::set_current(uint32_t min, uint32_t max) void ViewRange::set_full(uint32_t min, uint32_t max)
{ {
m_current.set(min, max); // is the full range being extended ?
// force the current range to stay inside the modified global range const bool new_max = max > m_full.get_max();
m_global.clamp(m_current); m_full.set(min, max);
// force the enabled range to stay inside the modified full range
m_full.clamp(m_enabled);
// force the visible range to stay inside the modified enabled range
m_enabled.clamp(m_visible);
if (new_max) {
// force the enabled range to fill the extended full range
m_enabled.set_max(max);
// force the visible range to fill the extended enabled range
m_visible.set_max(max);
}
} }
const std::array<uint32_t, 2>& ViewRange::get_global() const const std::array<uint32_t, 2>& ViewRange::get_enabled() const
{ {
return m_global.get(); return m_enabled.get();
} }
void ViewRange::set_global(const Range& other) void ViewRange::set_enabled(const Range& other)
{ {
set_global(other.get()); set_enabled(other.get());
} }
void ViewRange::set_global(const std::array<uint32_t, 2>& range) void ViewRange::set_enabled(const std::array<uint32_t, 2>& range)
{ {
set_global(range[0], range[1]); set_enabled(range[0], range[1]);
} }
void ViewRange::set_global(uint32_t min, uint32_t max) void ViewRange::set_enabled(uint32_t min, uint32_t max)
{ {
// is the global range being extended ? // is the enabled range being extended ?
const bool new_max = max > m_global.get()[1]; const bool new_max = max > m_enabled.get_max();
m_global.set(min, max); m_enabled.set(min, max);
// force the current range to stay inside the modified global range // force the visible range to stay inside the modified enabled range
m_global.clamp(m_current); m_enabled.clamp(m_visible);
if (new_max) if (new_max)
// force the current range to fill the extended global range // force the visible range to fill the extended enabled range
m_current.set(m_current.get()[0], max); m_visible.set_max(max);
}
const std::array<uint32_t, 2>& ViewRange::get_visible() const
{
return m_visible.get();
}
void ViewRange::set_visible(const Range& other)
{
set_visible(other.get());
}
void ViewRange::set_visible(const std::array<uint32_t, 2>& range)
{
set_visible(range[0], range[1]);
}
void ViewRange::set_visible(uint32_t min, uint32_t max)
{
m_visible.set(min, max);
// force the visible range to stay inside the enabled range
m_enabled.clamp(m_visible);
} }
void ViewRange::reset() void ViewRange::reset()
{ {
m_current.reset(); m_full.reset();
m_global.reset(); m_enabled.reset();
m_visible.reset();
} }
} // namespace libvgcode } // namespace libvgcode

View File

@ -17,21 +17,43 @@ namespace libvgcode {
class ViewRange class ViewRange
{ {
public: public:
const std::array<uint32_t, 2>& get_current() const; const std::array<uint32_t, 2>& get_full() const;
void set_current(const Range& other); void set_full(const Range& other);
void set_current(const std::array<uint32_t, 2>& range); void set_full(const std::array<uint32_t, 2>& range);
void set_current(uint32_t min, uint32_t max); void set_full(uint32_t min, uint32_t max);
const std::array<uint32_t, 2>& get_global() const; const std::array<uint32_t, 2>& get_enabled() const;
void set_global(const Range& other); void set_enabled(const Range& other);
void set_global(const std::array<uint32_t, 2>& range); void set_enabled(const std::array<uint32_t, 2>& range);
void set_global(uint32_t min, uint32_t max); void set_enabled(uint32_t min, uint32_t max);
const std::array<uint32_t, 2>& get_visible() const;
void set_visible(const Range& other);
void set_visible(const std::array<uint32_t, 2>& range);
void set_visible(uint32_t min, uint32_t max);
void reset(); void reset();
private: private:
Range m_current; //
Range m_global; // Full range
// The range of moves that could potentially be visible.
// It is usually equal to the enabled range, unless Settings::top_layer_only_view_range is set to true.
//
Range m_full;
//
// Enabled range
// The range of moves that are enabled for visualization.
// It is usually equal to the full range, unless Settings::top_layer_only_view_range is set to true.
//
Range m_enabled;
//
// Visible range
// The range of moves that are currently rendered.
//
Range m_visible;
}; };
} // namespace libvgcode } // namespace libvgcode

View File

@ -101,19 +101,24 @@ void Viewer::toggle_extrusion_role_visibility(EGCodeExtrusionRole role)
m_impl.toggle_extrusion_role_visibility(role); m_impl.toggle_extrusion_role_visibility(role);
} }
const std::array<uint32_t, 2>& Viewer::get_view_current_range() const const std::array<uint32_t, 2>& Viewer::get_view_full_range() const
{ {
return m_impl.get_view_current_range(); return m_impl.get_view_full_range();
} }
const std::array<uint32_t, 2>& Viewer::get_view_global_range() const const std::array<uint32_t, 2>& Viewer::get_view_enabled_range() const
{ {
return m_impl.get_view_global_range(); return m_impl.get_view_enabled_range();
} }
void Viewer::set_view_current_range(uint32_t min, uint32_t max) const std::array<uint32_t, 2>& Viewer::get_view_visible_range() const
{ {
m_impl.set_view_current_range(min, max); return m_impl.get_view_visible_range();
}
void Viewer::set_view_visible_range(uint32_t min, uint32_t max)
{
m_impl.set_view_visible_range(min, max);
} }
uint32_t Viewer::get_vertices_count() const uint32_t Viewer::get_vertices_count() const

View File

@ -50,13 +50,15 @@ public:
bool is_extrusion_role_visible(EGCodeExtrusionRole role) const; bool is_extrusion_role_visible(EGCodeExtrusionRole role) const;
void toggle_extrusion_role_visibility(EGCodeExtrusionRole role); void toggle_extrusion_role_visibility(EGCodeExtrusionRole role);
const std::array<uint32_t, 2>& get_view_current_range() const; const std::array<uint32_t, 2>& get_view_full_range() const;
const std::array<uint32_t, 2>& get_view_global_range() const; const std::array<uint32_t, 2>& get_view_enabled_range() const;
const std::array<uint32_t, 2>& get_view_visible_range() const;
// //
// min must be smaller than max // min must be smaller than max
// values are clamped to the view global range // values are clamped to the current view global range
// //
void set_view_current_range(uint32_t min, uint32_t max); void set_view_visible_range(uint32_t min, uint32_t max);
// //
// Return the count of vertices used to render the toolpaths // Return the count of vertices used to render the toolpaths

View File

@ -583,7 +583,7 @@ void ViewerImpl::load(GCodeInputData&& gcode_data)
if (!m_layers.empty()) if (!m_layers.empty())
set_layers_range(0, static_cast<uint32_t>(m_layers.count() - 1)); set_layers_range(0, static_cast<uint32_t>(m_layers.count() - 1));
update_view_global_range();
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -591,13 +591,13 @@ void ViewerImpl::update_enabled_entities()
{ {
std::vector<uint32_t> enabled_segments; std::vector<uint32_t> enabled_segments;
std::vector<uint32_t> enabled_options; std::vector<uint32_t> enabled_options;
std::array<uint32_t, 2> range = m_view_range.get_current(); std::array<uint32_t, 2> range = m_view_range.get_visible();
// when top layer only visualization is enabled, we need to render // when top layer only visualization is enabled, we need to render
// all the toolpaths in the other layers as grayed, so extend the range // all the toolpaths in the other layers as grayed, so extend the range
// to contain them // to contain them
if (m_settings.top_layer_only_view_range) if (m_settings.top_layer_only_view_range)
range[0] = m_view_range.get_global()[0]; range[0] = m_view_range.get_full()[0];
// to show the options at the current tool marker position we need to extend the range by one extra step // to show the options at the current tool marker position we need to extend the range by one extra step
if (m_vertices[range[1]].is_option() && range[1] < static_cast<uint32_t>(m_vertices.size()) - 1) if (m_vertices[range[1]].is_option() && range[1] < static_cast<uint32_t>(m_vertices.size()) - 1)
@ -665,11 +665,11 @@ void ViewerImpl::update_enabled_entities()
} }
static float encode_color(const Color& color) { static float encode_color(const Color& color) {
const int r = (int)(255.0f * color[0]); const int r = static_cast<int>(color[0]);
const int g = (int)(255.0f * color[1]); const int g = static_cast<int>(color[1]);
const int b = (int)(255.0f * color[2]); const int b = static_cast<int>(color[2]);
const int i_color = r << 16 | g << 8 | b; const int i_color = r << 16 | g << 8 | b;
return float(i_color); return static_cast<float>(i_color);
} }
void ViewerImpl::update_colors() void ViewerImpl::update_colors()
@ -677,7 +677,7 @@ void ViewerImpl::update_colors()
update_color_ranges(); update_color_ranges();
const uint32_t top_layer_id = m_settings.top_layer_only_view_range ? m_layers.get_view_range()[1] : 0; const uint32_t top_layer_id = m_settings.top_layer_only_view_range ? m_layers.get_view_range()[1] : 0;
const bool color_top_layer_only = m_view_range.get_global()[1] != m_view_range.get_current()[1]; const bool color_top_layer_only = m_view_range.get_full()[1] != m_view_range.get_visible()[1];
std::vector<float> colors(m_vertices.size()); std::vector<float> colors(m_vertices.size());
for (size_t i = 0; i < m_vertices.size(); i++) { for (size_t i = 0; i < m_vertices.size(); i++) {
colors[i] = (color_top_layer_only && m_vertices[i].layer_id < top_layer_id) ? encode_color(Dummy_Color) : encode_color(select_color(m_vertices[i])); colors[i] = (color_top_layer_only && m_vertices[i].layer_id < top_layer_id) ? encode_color(Dummy_Color) : encode_color(select_color(m_vertices[i]));
@ -692,9 +692,9 @@ void ViewerImpl::update_colors()
void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix) void ViewerImpl::render(const Mat4x4& view_matrix, const Mat4x4& projection_matrix)
{ {
if (m_settings.update_view_global_range) { if (m_settings.update_view_full_range) {
update_view_global_range(); update_view_full_range();
m_settings.update_view_global_range = false; m_settings.update_view_full_range = false;
} }
if (m_settings.update_enabled_entities) { if (m_settings.update_enabled_entities) {
@ -755,7 +755,9 @@ void ViewerImpl::set_layers_range(const std::array<uint32_t, 2>& range)
void ViewerImpl::set_layers_range(uint32_t min, uint32_t max) void ViewerImpl::set_layers_range(uint32_t min, uint32_t max)
{ {
m_layers.set_view_range(min, max); m_layers.set_view_range(min, max);
m_settings.update_view_global_range = true; // force immediate update of the full range
update_view_full_range();
m_settings.update_view_full_range = false;
m_settings.update_enabled_entities = true; m_settings.update_enabled_entities = true;
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -786,7 +788,7 @@ void ViewerImpl::toggle_option_visibility(EOptionType type)
try { try {
bool& value = m_settings.options_visibility.at(type); bool& value = m_settings.options_visibility.at(type);
value = !value; value = !value;
m_settings.update_view_global_range = true; m_settings.update_view_full_range = true;
m_settings.update_enabled_entities = true; m_settings.update_enabled_entities = true;
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -810,7 +812,7 @@ void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role)
try { try {
bool& value = m_settings.extrusion_roles_visibility.at(role); bool& value = m_settings.extrusion_roles_visibility.at(role);
value = !value; value = !value;
m_settings.update_view_global_range = true; m_settings.update_view_full_range = true;
m_settings.update_enabled_entities = true; m_settings.update_enabled_entities = true;
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -819,57 +821,29 @@ void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role)
} }
} }
const std::array<uint32_t, 2>& ViewerImpl::get_view_current_range() const const std::array<uint32_t, 2>& ViewerImpl::get_view_full_range() const
{ {
return m_view_range.get_current(); return m_view_range.get_full();
} }
const std::array<uint32_t, 2>& ViewerImpl::get_view_global_range() const const std::array<uint32_t, 2>& ViewerImpl::get_view_enabled_range() const
{ {
return m_view_range.get_global(); return m_view_range.get_enabled();
} }
void ViewerImpl::set_view_current_range(uint32_t min, uint32_t max) const std::array<uint32_t, 2>& ViewerImpl::get_view_visible_range() const
{ {
uint32_t min_id = 0; return m_view_range.get_visible();
for (size_t i = 0; i < m_vertices.size(); ++i) { }
if (m_vertices[i].move_id < min)
min_id = static_cast<uint32_t>(i);
else
break;
}
++min_id;
uint32_t max_id = min_id; void ViewerImpl::set_view_visible_range(uint32_t min, uint32_t max)
if (max > min) { {
for (size_t i = static_cast<size_t>(min_id); i < m_vertices.size(); ++i) { // force update of the full range, to avoid clamping the visible range with full old values
if (m_vertices[i].move_id < max) // when calling m_view_range.set_visible()
max_id = static_cast<uint32_t>(i); update_view_full_range();
else m_settings.update_view_full_range = false;
break;
}
++max_id;
}
// adjust the max id to take in account the 'phantom' vertices m_view_range.set_visible(min, max);
if (max_id < static_cast<uint32_t>(m_vertices.size() - 1) &&
m_vertices[max_id + 1].type == m_vertices[max_id].type &&
m_vertices[max_id + 1].move_id == m_vertices[max_id].move_id)
++max_id;
// we show the seams when the endpoint of a closed path is reached, so we need to increase the max id by one
if (max_id < static_cast<uint32_t>(m_vertices.size() - 1) && m_vertices[max_id + 1].type == EMoveType::Seam)
++max_id;
Range new_range;
new_range.set(min_id, max_id);
// force update of global range, if required, to avoid clamping the current range with global old values
// when calling set_current_range()
update_view_global_range();
m_settings.update_view_global_range = false;
m_view_range.set_current(new_range);
m_settings.update_enabled_entities = true; m_settings.update_enabled_entities = true;
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -881,7 +855,7 @@ size_t ViewerImpl::get_vertices_count() const
PathVertex ViewerImpl::get_current_vertex() const PathVertex ViewerImpl::get_current_vertex() const
{ {
return m_vertices[m_view_range.get_current()[1]]; return m_vertices[m_view_range.get_visible()[1]];
} }
PathVertex ViewerImpl::get_vertex_at(size_t id) const PathVertex ViewerImpl::get_vertex_at(size_t id) const
@ -1101,7 +1075,7 @@ static bool is_visible(const PathVertex& v, const Settings& settings)
} }
} }
void ViewerImpl::update_view_global_range() void ViewerImpl::update_view_full_range()
{ {
const std::array<uint32_t, 2>& layers_range = m_layers.get_view_range(); const std::array<uint32_t, 2>& layers_range = m_layers.get_view_range();
const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels); const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels);
@ -1113,7 +1087,7 @@ void ViewerImpl::update_view_global_range()
} }
if (first_it == m_vertices.end()) if (first_it == m_vertices.end())
m_view_range.set_global(0, 0); m_view_range.set_full(Range());
else { else {
if (travels_visible) { if (travels_visible) {
// if the global range starts with a travel move, extend it to the travel start // if the global range starts with a travel move, extend it to the travel start
@ -1154,7 +1128,22 @@ void ViewerImpl::update_view_global_range()
} }
} }
m_view_range.set_global(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it)); m_view_range.set_full(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it));
if (m_settings.top_layer_only_view_range) {
const std::array<uint32_t, 2>& full_range = m_view_range.get_full();
auto top_first_it = m_vertices.begin() + full_range[0];
bool shortened = false;
while (top_first_it != m_vertices.end() && (top_first_it->layer_id < layers_range[1] || !is_visible(*top_first_it, m_settings))) {
++top_first_it;
shortened = true;
}
if (shortened)
--top_first_it;
m_view_range.set_enabled(std::distance(m_vertices.begin(), top_first_it), full_range[1]);
}
else
m_view_range.set_enabled(m_view_range.get_full());
} }
} }

View File

@ -90,9 +90,10 @@ public:
bool is_extrusion_role_visible(EGCodeExtrusionRole role) const; bool is_extrusion_role_visible(EGCodeExtrusionRole role) const;
void toggle_extrusion_role_visibility(EGCodeExtrusionRole role); void toggle_extrusion_role_visibility(EGCodeExtrusionRole role);
const std::array<uint32_t, 2>& get_view_current_range() const; const std::array<uint32_t, 2>& get_view_full_range() const;
const std::array<uint32_t, 2>& get_view_global_range() const; const std::array<uint32_t, 2>& get_view_enabled_range() const;
void set_view_current_range(uint32_t min, uint32_t max); const std::array<uint32_t, 2>& get_view_visible_range() const;
void set_view_visible_range(uint32_t min, uint32_t max);
size_t get_vertices_count() const; size_t get_vertices_count() const;
PathVertex get_current_vertex() const; PathVertex get_current_vertex() const;
@ -284,7 +285,7 @@ private:
unsigned int m_enabled_options_buf_id{ 0 }; unsigned int m_enabled_options_buf_id{ 0 };
unsigned int m_enabled_options_tex_id{ 0 }; unsigned int m_enabled_options_tex_id{ 0 };
void update_view_global_range(); void update_view_full_range();
void update_color_ranges(); void update_color_ranges();
Color select_color(const PathVertex& v) const; Color select_color(const PathVertex& v) const;
void render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position); void render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position);