Rendering of debug imgui dialog moved from class libvgcode::Viewer to class libvgcode::Toolpaths + warnings fixing

This commit is contained in:
enricoturri1966 2023-10-26 13:28:46 +02:00 committed by Lukas Matena
parent 2710ab4005
commit 76419b7443
6 changed files with 122 additions and 209 deletions

View File

@ -1169,7 +1169,6 @@ void GCodeViewer::render()
const Camera& camera = wxGetApp().plater()->get_camera(); const Camera& camera = wxGetApp().plater()->get_camera();
const Matrix4f view_matrix = camera.get_view_matrix().matrix().cast<float>(); const Matrix4f view_matrix = camera.get_view_matrix().matrix().cast<float>();
const Matrix4f projection_matrix = camera.get_projection_matrix().matrix().cast<float>(); const Matrix4f projection_matrix = camera.get_projection_matrix().matrix().cast<float>();
const Vec3f camera_position = camera.get_position().cast<float>();
libvgcode::Mat4x4f converted_view_matrix; libvgcode::Mat4x4f converted_view_matrix;
std::memcpy(converted_view_matrix.data(), view_matrix.data(), 16 * sizeof(float)); std::memcpy(converted_view_matrix.data(), view_matrix.data(), 16 * sizeof(float));

View File

@ -20,11 +20,11 @@
namespace libvgcode { namespace libvgcode {
// /1-------6\ //| /1-------6\ |
// / | | \ //| / | | \ |
// 2--0-------5--7 //| 2--0-------5--7 |
// \ | | / //| \ | | / |
// 3-------4 //| 3-------4 |
static constexpr const std::array<uint8_t, 24> VERTEX_DATA = { static constexpr const std::array<uint8_t, 24> VERTEX_DATA = {
0, 1, 2, // front spike 0, 1, 2, // front spike
0, 2, 3, // front spike 0, 2, 3, // front spike

View File

@ -18,6 +18,8 @@
// PrusaSlicer development only -> !!!TO BE REMOVED!!! // PrusaSlicer development only -> !!!TO BE REMOVED!!!
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
#include "libslic3r/GCode/GCodeProcessor.hpp" #include "libslic3r/GCode/GCodeProcessor.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/ImGuiWrapper.hpp"
//################################################################################################################################ //################################################################################################################################
#include <map> #include <map>
@ -836,6 +838,11 @@ void Toolpaths::render(const Mat4x4f& view_matrix, const Mat4x4f& projection_mat
render_tool_marker(view_matrix, projection_matrix); render_tool_marker(view_matrix, projection_matrix);
if (m_settings.options_visibility.at(EOptionType::CenterOfGravity)) if (m_settings.options_visibility.at(EOptionType::CenterOfGravity))
render_cog_marker(view_matrix, projection_matrix); render_cog_marker(view_matrix, projection_matrix);
//################################################################################################################################
// Debug
render_debug_window();
//################################################################################################################################
} }
EViewType Toolpaths::get_view_type() const EViewType Toolpaths::get_view_type() const
@ -990,74 +997,6 @@ void Toolpaths::set_tool_marker_alpha(float alpha)
m_tool_marker.set_alpha(alpha); m_tool_marker.set_alpha(alpha);
} }
//################################################################################################################################
// Debug
size_t Toolpaths::get_vertices_count() const
{
return m_vertices.size();
}
size_t Toolpaths::get_enabled_segments_count() const
{
return m_enabled_segments_count;
}
size_t Toolpaths::get_enabled_options_count() const
{
return m_enabled_options_count;
}
const std::pair<uint32_t, uint32_t>& Toolpaths::get_enabled_segments_range() const
{
return m_enabled_segments_range;
}
const std::pair<uint32_t, uint32_t>& Toolpaths::get_enabled_options_range() const
{
return m_enabled_options_range;
}
const std::array<float, 2>& Toolpaths::get_height_range() const
{
return m_height_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_width_range() const
{
return m_width_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_speed_range() const
{
return m_speed_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_fan_speed_range() const
{
return m_fan_speed_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_temperature_range() const
{
return m_temperature_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_volumetric_rate_range() const
{
return m_volumetric_rate_range.get_range();
}
const std::array<float, 2>& Toolpaths::get_layer_time_linear_range() const
{
return m_layer_time_range[0].get_range();
}
const std::array<float, 2>& Toolpaths::get_layer_time_logarithmic_range() const
{
return m_layer_time_range[1].get_range();
}
//################################################################################################################################
static void delete_textures(unsigned int& id) static void delete_textures(unsigned int& id)
{ {
if (id != 0) { if (id != 0) {
@ -1197,6 +1136,7 @@ Color Toolpaths::select_color(const PathVertex& v) const
{ {
return m_tool_colors[v.color_id % m_tool_colors.size()]; return m_tool_colors[v.color_id % m_tool_colors.size()];
} }
default: { break; }
} }
return Dummy_Color; return Dummy_Color;
@ -1377,6 +1317,110 @@ void Toolpaths::render_tool_marker(const Mat4x4f& view_matrix, const Mat4x4f& pr
glsafe(glUseProgram(curr_shader)); glsafe(glUseProgram(curr_shader));
} }
//################################################################################################################################
// Debug
void Toolpaths::render_debug_window()
{
Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui();
imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
if (ImGui::BeginTable("Data", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(m_vertices.size()));
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(m_enabled_segments_count) + " [" + std::to_string(m_enabled_segments_range.first) + "-" + std::to_string(m_enabled_segments_range.second) + "]");
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(m_enabled_options_count) + " [" + std::to_string(m_enabled_options_range.first) + "-" + std::to_string(m_enabled_options_range.second) + "]");
ImGui::Separator();
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "sequential range");
ImGui::TableSetColumnIndex(1);
const std::array<size_t, 2>& current_view_range = get_view_current_range();
imgui.text(std::to_string(current_view_range[0]) + " - " + std::to_string(current_view_range[1]));
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::TableSetColumnIndex(1);
char buf[64];
sprintf(buf, "%.3f - %.3f", range[0], range[1]);
imgui.text(buf);
};
add_range_property_row("height range", m_height_range.get_range());
add_range_property_row("width range", m_width_range.get_range());
add_range_property_row("speed range", m_speed_range.get_range());
add_range_property_row("fan speed range", m_fan_speed_range.get_range());
add_range_property_row("temperature range", m_temperature_range.get_range());
add_range_property_row("volumetric rate range", m_volumetric_rate_range.get_range());
add_range_property_row("layer time linear range", m_layer_time_range[0].get_range());
add_range_property_row("layer time logarithmic range", m_layer_time_range[1].get_range());
ImGui::EndTable();
ImGui::Separator();
if (ImGui::BeginTable("Cog", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(get_cog_marker_scale_factor()));
ImGui::EndTable();
}
ImGui::Separator();
if (ImGui::BeginTable("Tool", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(get_tool_marker_scale_factor()));
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color");
ImGui::TableSetColumnIndex(1);
Color color = get_tool_marker_color();
if (ImGui::ColorPicker3("##ToolColor", color.data()))
set_tool_marker_color(color);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha");
ImGui::TableSetColumnIndex(1);
float tool_alpha = get_tool_marker_alpha();
if (imgui.slider_float("##ToolAlpha", &tool_alpha, 0.25f, 0.75f))
set_tool_marker_alpha(tool_alpha);
ImGui::EndTable();
}
}
imgui.end();
}
//################################################################################################################################
} // namespace libvgcode } // namespace libvgcode
//################################################################################################################################ //################################################################################################################################

View File

@ -115,23 +115,6 @@ public:
void set_tool_marker_color(const Color& color); void set_tool_marker_color(const Color& color);
void set_tool_marker_alpha(float size); void set_tool_marker_alpha(float size);
//################################################################################################################################
// Debug
size_t get_vertices_count() const;
size_t get_enabled_segments_count() const;
size_t get_enabled_options_count() const;
const std::pair<uint32_t, uint32_t>& get_enabled_segments_range() const;
const std::pair<uint32_t, uint32_t>& get_enabled_options_range() const;
const std::array<float, 2>& get_height_range() const;
const std::array<float, 2>& get_width_range() const;
const std::array<float, 2>& get_speed_range() const;
const std::array<float, 2>& get_fan_speed_range() const;
const std::array<float, 2>& get_temperature_range() const;
const std::array<float, 2>& get_volumetric_rate_range() const;
const std::array<float, 2>& get_layer_time_linear_range() const;
const std::array<float, 2>& get_layer_time_logarithmic_range() const;
//################################################################################################################################
private: private:
Settings m_settings; Settings m_settings;
ViewRange m_view_range; ViewRange m_view_range;
@ -269,6 +252,11 @@ private:
void render_options(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix); void render_options(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix);
void render_cog_marker(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix); void render_cog_marker(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix);
void render_tool_marker(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix); void render_tool_marker(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix);
//################################################################################################################################
// Debug
void render_debug_window();
//################################################################################################################################
}; };
} // namespace libvgcode } // namespace libvgcode

View File

@ -14,8 +14,6 @@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
#include "libslic3r/GCode/GCodeProcessor.hpp" #include "libslic3r/GCode/GCodeProcessor.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/ImGuiWrapper.hpp"
//################################################################################################################################ //################################################################################################################################
namespace libvgcode { namespace libvgcode {
@ -33,11 +31,6 @@ void Viewer::load(const Slic3r::GCodeProcessorResult& gcode_result, const std::v
void Viewer::render(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix) void Viewer::render(const Mat4x4f& view_matrix, const Mat4x4f& projection_matrix)
{ {
m_toolpaths.render(view_matrix, projection_matrix); m_toolpaths.render(view_matrix, projection_matrix);
//################################################################################################################################
// Debug
render_debug_window();
//################################################################################################################################
} }
EViewType Viewer::get_view_type() const EViewType Viewer::get_view_type() const
@ -155,112 +148,6 @@ void Viewer::set_tool_marker_alpha(float alpha)
m_toolpaths.set_tool_marker_alpha(alpha); m_toolpaths.set_tool_marker_alpha(alpha);
} }
//################################################################################################################################
// Debug
void Viewer::render_debug_window()
{
Slic3r::GUI::ImGuiWrapper& imgui = *Slic3r::GUI::wxGetApp().imgui();
imgui.begin(std::string("LibVGCode Viewer Debug"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
if (ImGui::BeginTable("Data", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# vertices");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(m_toolpaths.get_vertices_count()));
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled lines");
ImGui::TableSetColumnIndex(1);
const std::pair<uint32_t, uint32_t>& enabled_segments_range = m_toolpaths.get_enabled_segments_range();
imgui.text(std::to_string(m_toolpaths.get_enabled_segments_count()) + " [" + std::to_string(enabled_segments_range.first) + "-" + std::to_string(enabled_segments_range.second) + "]");
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "# enabled options");
ImGui::TableSetColumnIndex(1);
const std::pair<uint32_t, uint32_t>& enabled_options_range = m_toolpaths.get_enabled_options_range();
imgui.text(std::to_string(m_toolpaths.get_enabled_options_count()) + " [" + std::to_string(enabled_options_range.first) + "-" + std::to_string(enabled_options_range.second) + "]");
ImGui::Separator();
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "sequential range");
ImGui::TableSetColumnIndex(1);
const std::array<size_t, 2>& current_view_range = m_toolpaths.get_view_current_range();
imgui.text(std::to_string(current_view_range[0]) + " - " + std::to_string(current_view_range[1]));
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::TableSetColumnIndex(1);
char buf[64];
::sprintf(buf, "%.3f - %.3f", range[0], range[1]);
imgui.text(buf);
};
add_range_property_row("height range", m_toolpaths.get_height_range());
add_range_property_row("width range", m_toolpaths.get_width_range());
add_range_property_row("speed range", m_toolpaths.get_speed_range());
add_range_property_row("fan speed range", m_toolpaths.get_fan_speed_range());
add_range_property_row("temperature range", m_toolpaths.get_temperature_range());
add_range_property_row("volumetric rate range", m_toolpaths.get_volumetric_rate_range());
add_range_property_row("layer time linear range", m_toolpaths.get_layer_time_linear_range());
add_range_property_row("layer time logarithmic range", m_toolpaths.get_layer_time_logarithmic_range());
ImGui::EndTable();
ImGui::Separator();
if (ImGui::BeginTable("Cog", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Cog marker scale factor");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(get_cog_marker_scale_factor()));
ImGui::EndTable();
}
ImGui::Separator();
if (ImGui::BeginTable("Tool", 2)) {
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker scale factor");
ImGui::TableSetColumnIndex(1);
imgui.text(std::to_string(get_tool_marker_scale_factor()));
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker color");
ImGui::TableSetColumnIndex(1);
Color color = get_tool_marker_color();
if (ImGui::ColorPicker3("##ToolColor", color.data()))
set_tool_marker_color(color);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
imgui.text_colored(Slic3r::GUI::ImGuiWrapper::COL_ORANGE_LIGHT, "Tool marker alpha");
ImGui::TableSetColumnIndex(1);
float tool_alpha = get_tool_marker_alpha();
if (imgui.slider_float("##ToolAlpha", &tool_alpha, 0.25f, 0.75f))
set_tool_marker_alpha(tool_alpha);
ImGui::EndTable();
}
}
imgui.end();
}
//################################################################################################################################
} // namespace libvgcode } // namespace libvgcode
//################################################################################################################################ //################################################################################################################################

View File

@ -86,11 +86,6 @@ public:
private: private:
Toolpaths m_toolpaths; Toolpaths m_toolpaths;
//################################################################################################################################
// Debug
void render_debug_window();
//################################################################################################################################
}; };
} // namespace libvgcode } // namespace libvgcode