Top layer only coloring for neww gcode visualization

This commit is contained in:
enricoturri1966 2023-10-31 08:38:10 +01:00 committed by Lukas Matena
parent f0a25c8ee0
commit 717bc821e3
2 changed files with 18 additions and 7 deletions

View File

@ -14,8 +14,6 @@
#if ENABLE_NEW_GCODE_VIEWER
//################################################################################################################################
#include <algorithm>
namespace libvgcode {
const std::array<uint32_t, 2>& ViewRange::get_current_range() const
@ -36,6 +34,7 @@ void ViewRange::set_current_range(const std::array<uint32_t, 2>& range)
void ViewRange::set_current_range(uint32_t min, uint32_t max)
{
m_current.set(min, max);
// force the current range to stay inside the modified global range
m_global.clamp(m_current);
}
@ -56,14 +55,20 @@ void ViewRange::set_global_range(const std::array<uint32_t, 2>& range)
void ViewRange::set_global_range(uint32_t min, uint32_t max)
{
// is the global range being extended ?
const bool new_max = max > m_global.get()[1];
m_global.set(min, max);
// force the current range to stay inside the modified global range
m_global.clamp(m_current);
if (new_max)
// force the current range to fill the extended global range
m_current.set(m_current.get()[0], max);
}
void ViewRange::reset()
{
m_global.reset();
m_global.reset();
m_current.reset();
}
} // namespace libvgcode

View File

@ -745,8 +745,11 @@ void ViewerImpl::update_enabled_entities()
std::vector<uint32_t> enabled_segments;
std::vector<uint32_t> enabled_options;
const std::array<uint32_t, 2>& current_range = m_view_range.get_current_range();
for (uint32_t i = current_range[0]; i < current_range[1]; ++i) {
std::array<uint32_t, 2> range = m_view_range.get_current_range();
if (m_settings.top_layer_only_view)
range[0] = m_view_range.get_global_range()[0];
for (uint32_t i = range[0]; i < range[1]; ++i) {
const PathVertex& v = m_vertices[i];
if (!m_valid_lines_bitset[i] && !v.is_option())
@ -820,8 +823,8 @@ void ViewerImpl::update_colors()
const uint32_t top_layer_id = m_settings.top_layer_only_view ? m_layers_range.get()[1] : 0;
std::vector<float> colors(m_vertices.size());
for (size_t i = 0; i < m_vertices.size(); i++) {
colors[i] = (m_vertices[i].layer_id < top_layer_id) ?
encode_color(Dummy_Color) : encode_color(select_color(m_vertices[i]));
colors[i] = (m_vertices[i].layer_id < top_layer_id) ?
encode_color(Dummy_Color) : encode_color(select_color(m_vertices[i]));
}
// update gpu buffer for colors
@ -929,6 +932,7 @@ void ViewerImpl::set_layers_range(uint32_t min, uint32_t max)
m_layers_range.set(min, max);
m_settings.update_view_global_range = true;
m_settings.update_enabled_entities = true;
m_settings.update_colors = true;
}
void ViewerImpl::set_top_layer_only_view(bool top_layer_only_view)
@ -1584,6 +1588,7 @@ void ViewerImpl::render_debug_window()
imgui.end();
/*
auto to_string = [](EMoveType type) {
switch (type)
{
@ -1623,6 +1628,7 @@ void ViewerImpl::render_debug_window()
ImGui::EndTable();
}
imgui.end();
*/
}
#endif // ENABLE_NEW_GCODE_VIEWER_DEBUG