mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 07:11:59 +08:00
New gcode visualization - Customizable travels and wipes segment radius
This commit is contained in:
parent
c57d63f2f9
commit
f408bd627e
@ -535,6 +535,10 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode
|
||||
ImGui::SameLine();
|
||||
imgui.text(_u8L("N/A"));
|
||||
}
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, _u8L("Layer") + ":");
|
||||
sprintf(buf, "%d", vertex.layer_id + 1);
|
||||
ImGui::SameLine();
|
||||
imgui.text(std::string(buf));
|
||||
}
|
||||
|
||||
// force extra frame to automatically update window size
|
||||
@ -1165,7 +1169,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
|
||||
reset();
|
||||
|
||||
// convert data from PrusaSlicer format to libvgcode format
|
||||
libvgcode::GCodeInputData data = libvgcode::convert(gcode_result);
|
||||
libvgcode::GCodeInputData data = libvgcode::convert(gcode_result, m_new_viewer.get_travels_radius(), m_new_viewer.get_wipes_radius());
|
||||
|
||||
// send data to the viewer
|
||||
m_new_viewer.load(std::move(data));
|
||||
@ -3627,7 +3631,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
m_new_viewer.render(converted_view_matrix, converted_projetion_matrix);
|
||||
|
||||
#if ENABLE_NEW_GCODE_VIEWER_DEBUG
|
||||
Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui();
|
||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||
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);
|
||||
@ -3636,13 +3640,13 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
imgui.text(std::to_string(m_new_viewer.get_vertices_count()));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::array<uint32_t, 2>& enabled_segments_range = m_new_viewer.get_enabled_segments_range();
|
||||
imgui.text(std::to_string(m_new_viewer.get_enabled_segments_count()) + " [" + std::to_string(enabled_segments_range[0]) +
|
||||
@ -3650,7 +3654,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::array<uint32_t, 2>& enabled_options_range = m_new_viewer.get_enabled_options_range();
|
||||
imgui.text(std::to_string(m_new_viewer.get_enabled_options_count()) + " [" + std::to_string(enabled_options_range[0]) +
|
||||
@ -3660,14 +3664,14 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "layers range");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "layers range");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::array<uint32_t, 2>& layers_range = m_new_viewer.get_layers_view_range();
|
||||
imgui.text(std::to_string(layers_range[0]) + " - " + std::to_string(layers_range[1]));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (full)");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "view range (full)");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::array<uint32_t, 2>& full_view_range = m_new_viewer.get_view_full_range();
|
||||
imgui.text(std::to_string(full_view_range[0]) + " - " + std::to_string(full_view_range[1]) + " | " +
|
||||
@ -3676,7 +3680,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (enabled)");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "view range (enabled)");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const std::array<uint32_t, 2>& enabled_view_range = m_new_viewer.get_view_enabled_range();
|
||||
imgui.text(std::to_string(enabled_view_range[0]) + " - " + std::to_string(enabled_view_range[1]) + " | " +
|
||||
@ -3685,7 +3689,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "view range (visible)");
|
||||
imgui.text_colored(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]) + " | " +
|
||||
@ -3695,7 +3699,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
auto add_range_property_row = [&imgui](const std::string& label, const std::array<float, 2>& range) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, label);
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
char buf[128];
|
||||
sprintf(buf, "%.3f - %.3f", range[0], range[1]);
|
||||
@ -3719,7 +3723,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
if (ImGui::BeginTable("Cog", 2)) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
imgui.text(std::to_string(get_cog_marker_scale_factor()));
|
||||
|
||||
@ -3731,13 +3735,13 @@ void GCodeViewer::render_new_toolpaths()
|
||||
if (ImGui::BeginTable("Tool", 2)) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
imgui.text(std::to_string(m_new_viewer.get_tool_marker_scale_factor()));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker z offset");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker z offset");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
float tool_z_offset = m_new_viewer.get_tool_marker_offset_z();
|
||||
if (imgui.slider_float("##ToolZOffset", &tool_z_offset, 0.0f, 1.0f))
|
||||
@ -3745,7 +3749,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
const libvgcode::Color& color = m_new_viewer.get_tool_marker_color();
|
||||
std::array<float, 3> c = { static_cast<float>(color[0]) / 255.0f, static_cast<float>(color[1]) / 255.0f, static_cast<float>(color[2]) / 255.0f };
|
||||
@ -3757,7 +3761,7 @@ void GCodeViewer::render_new_toolpaths()
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha");
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
float tool_alpha = m_new_viewer.get_tool_marker_alpha();
|
||||
if (imgui.slider_float("##ToolAlpha", &tool_alpha, 0.25f, 0.75f))
|
||||
@ -3768,6 +3772,30 @@ void GCodeViewer::render_new_toolpaths()
|
||||
#endif // !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
if (ImGui::BeginTable("Radii", 2)) {
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Travels radius");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
float travels_radius = m_new_viewer.get_travels_radius();
|
||||
ImGui::SetNextItemWidth(200.0f);
|
||||
if (imgui.slider_float("##TravelRadius", &travels_radius, 0.05f, 0.5f))
|
||||
m_new_viewer.set_travels_radius(travels_radius);
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableSetColumnIndex(0);
|
||||
imgui.text_colored(ImGuiWrapper::COL_ORANGE_LIGHT, "Wipes radius");
|
||||
ImGui::TableSetColumnIndex(1);
|
||||
float wipes_radius = m_new_viewer.get_wipes_radius();
|
||||
ImGui::SetNextItemWidth(200.0f);
|
||||
if (imgui.slider_float("##WipesRadius", &wipes_radius, 0.05f, 0.5f))
|
||||
m_new_viewer.set_wipes_radius(wipes_radius);
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
imgui.end();
|
||||
#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ Slic3r::PrintEstimatedStatistics::ETimeMode convert(const ETimeMode& mode)
|
||||
}
|
||||
}
|
||||
|
||||
GCodeInputData convert(const Slic3r::GCodeProcessorResult& result)
|
||||
GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels_radius, float wipes_radius)
|
||||
{
|
||||
const std::vector<Slic3r::GCodeProcessorResult::MoveVertex>& moves = result.moves;
|
||||
GCodeInputData ret;
|
||||
@ -178,14 +178,14 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result)
|
||||
{
|
||||
case EMoveType::Travel:
|
||||
{
|
||||
width = Default_Travel_Radius;
|
||||
height = Default_Travel_Radius;
|
||||
width = travels_radius;
|
||||
height = travels_radius;
|
||||
break;
|
||||
}
|
||||
case EMoveType::Wipe:
|
||||
{
|
||||
width = Default_Wipe_Radius;
|
||||
height = Default_Wipe_Radius;
|
||||
width = wipes_radius;
|
||||
height = wipes_radius;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -52,7 +52,8 @@ extern ETimeMode convert(const Slic3r::PrintEstimatedStatistics::ETimeMode& mode
|
||||
extern Slic3r::PrintEstimatedStatistics::ETimeMode convert(const ETimeMode& mode);
|
||||
|
||||
// mapping from Slic3r::GCodeProcessorResult to libvgcode::GCodeInputData
|
||||
extern GCodeInputData convert(const Slic3r::GCodeProcessorResult& result);
|
||||
extern GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels_radius = Default_Travels_Radius,
|
||||
float wipes_radius = Default_Wipes_Radius);
|
||||
|
||||
} // namespace libvgcode
|
||||
|
||||
|
@ -18,8 +18,8 @@ namespace libvgcode {
|
||||
|
||||
static constexpr float PI = 3.141592f;
|
||||
|
||||
static constexpr float Default_Travel_Radius = 0.05f;
|
||||
static constexpr float Default_Wipe_Radius = 0.05f;
|
||||
static constexpr float Default_Travels_Radius = 0.1f;
|
||||
static constexpr float Default_Wipes_Radius = 0.1f;
|
||||
|
||||
//
|
||||
// Vector in 3 dimensions
|
||||
@ -177,7 +177,7 @@ enum class EBBoxType : uint8_t
|
||||
// Predefined colors
|
||||
//
|
||||
static const Color Dummy_Color{ 64, 64, 64 };
|
||||
static const Color Wipe_Color { 255, 255, 255 };
|
||||
static const Color Wipe_Color { 255, 255, 0 };
|
||||
|
||||
//
|
||||
// Palette used to render moves by ranges
|
||||
|
@ -155,6 +155,11 @@ public:
|
||||
const ColorRange& get_volumetric_rate_range() const;
|
||||
const ColorRange& get_layer_time_range(EColorRangeType type) const;
|
||||
|
||||
float get_travels_radius() const;
|
||||
void set_travels_radius(float radius);
|
||||
float get_wipes_radius() const;
|
||||
void set_wipes_radius(float radius);
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
//
|
||||
// Returns the position of the center of gravity of the toolpaths.
|
||||
|
@ -292,6 +292,26 @@ const ColorRange& Viewer::get_layer_time_range(EColorRangeType type) const
|
||||
return m_impl->get_layer_time_range(type);
|
||||
}
|
||||
|
||||
float Viewer::get_travels_radius() const
|
||||
{
|
||||
return m_impl->get_travels_radius();
|
||||
}
|
||||
|
||||
void Viewer::set_travels_radius(float radius)
|
||||
{
|
||||
m_impl->set_travels_radius(radius);
|
||||
}
|
||||
|
||||
float Viewer::get_wipes_radius() const
|
||||
{
|
||||
return m_impl->get_wipes_radius();
|
||||
}
|
||||
|
||||
void Viewer::set_wipes_radius(float radius)
|
||||
{
|
||||
m_impl->set_wipes_radius(radius);
|
||||
}
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
Vec3 Viewer::get_cog_position() const
|
||||
{
|
||||
|
@ -989,6 +989,28 @@ const ColorRange& ViewerImpl::get_layer_time_range(EColorRangeType type) const
|
||||
}
|
||||
}
|
||||
|
||||
float ViewerImpl::get_travels_radius() const
|
||||
{
|
||||
return m_travels_radius;
|
||||
}
|
||||
|
||||
void ViewerImpl::set_travels_radius(float radius)
|
||||
{
|
||||
m_travels_radius = std::clamp(radius, 0.05f, 0.5f);
|
||||
update_heights_widths();
|
||||
}
|
||||
|
||||
float ViewerImpl::get_wipes_radius() const
|
||||
{
|
||||
return m_wipes_radius;
|
||||
}
|
||||
|
||||
void ViewerImpl::set_wipes_radius(float radius)
|
||||
{
|
||||
m_wipes_radius = std::clamp(radius, 0.05f, 0.5f);
|
||||
update_heights_widths();
|
||||
}
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
Vec3 ViewerImpl::get_cog_marker_position() const
|
||||
{
|
||||
@ -1089,6 +1111,7 @@ void ViewerImpl::update_view_full_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 wipes_visible = m_settings.options_visibility.at(EOptionType::Wipes);
|
||||
|
||||
auto first_it = m_vertices.begin();
|
||||
while (first_it != m_vertices.end() &&
|
||||
@ -1099,9 +1122,11 @@ void ViewerImpl::update_view_full_range()
|
||||
if (first_it == m_vertices.end())
|
||||
m_view_range.set_full(Range());
|
||||
else {
|
||||
if (travels_visible) {
|
||||
// if the global range starts with a travel move, extend it to the travel start
|
||||
while (first_it != m_vertices.begin() && first_it->is_travel()) {
|
||||
if (travels_visible || wipes_visible) {
|
||||
// if the global range starts with a travel/wipe move, extend it to the travel/wipe start
|
||||
while (first_it != m_vertices.begin() &&
|
||||
((travels_visible && first_it->is_travel()) ||
|
||||
(wipes_visible && first_it->is_wipe()))) {
|
||||
--first_it;
|
||||
}
|
||||
}
|
||||
@ -1130,10 +1155,11 @@ void ViewerImpl::update_view_full_range()
|
||||
if (reduced && rev_last_it != m_vertices.rend())
|
||||
last_it = rev_last_it.base() - 1;
|
||||
|
||||
if (travels_visible) {
|
||||
// if the global range ends with a travel move, extend it to the travel end
|
||||
if (travels_visible || wipes_visible) {
|
||||
// if the global range ends with a travel/wipe move, extend it to the travel/wipe end
|
||||
while (last_it != m_vertices.end() && last_it + 1 != m_vertices.end() &&
|
||||
last_it->is_travel() && (last_it + 1)->is_travel()) {
|
||||
((travels_visible && last_it->is_travel() && (last_it + 1)->is_travel()) ||
|
||||
(wipes_visible && last_it->is_wipe() && (last_it + 1)->is_wipe()))) {
|
||||
++last_it;
|
||||
}
|
||||
}
|
||||
@ -1197,6 +1223,31 @@ void ViewerImpl::update_color_ranges()
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerImpl::update_heights_widths()
|
||||
{
|
||||
if (m_heights_widths_angles_buf_id == 0)
|
||||
return;
|
||||
|
||||
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, m_heights_widths_angles_buf_id));
|
||||
Vec3* buffer = static_cast<Vec3*>(glMapBuffer(GL_TEXTURE_BUFFER, GL_WRITE_ONLY));
|
||||
glcheck();
|
||||
|
||||
for (size_t i = 0; i < m_vertices.size(); ++i) {
|
||||
const PathVertex& v = m_vertices[i];
|
||||
if (v.is_travel()) {
|
||||
buffer[i][0] = m_travels_radius;
|
||||
buffer[i][1] = m_travels_radius;
|
||||
}
|
||||
else if (v.is_wipe()) {
|
||||
buffer[i][0] = m_wipes_radius;
|
||||
buffer[i][1] = m_wipes_radius;
|
||||
}
|
||||
}
|
||||
|
||||
glsafe(glUnmapBuffer(GL_TEXTURE_BUFFER));
|
||||
glsafe(glBindBuffer(GL_TEXTURE_BUFFER, 0));
|
||||
}
|
||||
|
||||
Color ViewerImpl::select_color(const PathVertex& v) const
|
||||
{
|
||||
if (v.type == EMoveType::Noop)
|
||||
|
@ -138,6 +138,11 @@ public:
|
||||
const ColorRange& get_volumetric_rate_range() const;
|
||||
const ColorRange& get_layer_time_range(EColorRangeType type) const;
|
||||
|
||||
float get_travels_radius() const;
|
||||
void set_travels_radius(float radius);
|
||||
float get_wipes_radius() const;
|
||||
void set_wipes_radius(float radius);
|
||||
|
||||
#if !ENABLE_NEW_GCODE_VIEWER_NO_COG_AND_TOOL_MARKERS
|
||||
Vec3 get_cog_marker_position() const;
|
||||
|
||||
@ -170,6 +175,8 @@ private:
|
||||
ExtrusionRoles m_extrusion_roles;
|
||||
std::array<float, Time_Modes_Count> m_travels_time{ 0.0f, 0.0f };
|
||||
std::vector<uint8_t> m_used_extruders_ids;
|
||||
float m_travels_radius{ Default_Travels_Radius };
|
||||
float m_wipes_radius{ Default_Wipes_Radius };
|
||||
|
||||
bool m_initialized{ false };
|
||||
bool m_loading{ false };
|
||||
@ -302,6 +309,7 @@ private:
|
||||
|
||||
void update_view_full_range();
|
||||
void update_color_ranges();
|
||||
void update_heights_widths();
|
||||
Color select_color(const PathVertex& v) const;
|
||||
void render_segments(const Mat4x4& view_matrix, const Mat4x4& projection_matrix, const Vec3& camera_position);
|
||||
void render_options(const Mat4x4& view_matrix, const Mat4x4& projection_matrix);
|
||||
|
Loading…
x
Reference in New Issue
Block a user