A bunch of fixes for the new gcode visualization

This commit is contained in:
enricoturri1966 2023-11-10 11:52:27 +01:00 committed by Lukas Matena
parent 0764d9ffda
commit 39c39798a8
7 changed files with 98 additions and 30 deletions

View File

@ -742,6 +742,17 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s
break; break;
} }
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
size_t last_block_id = first_block_id;
for (size_t i = last_block_id; i < cumulative_lines_counts.size(); ++i) {
if (*m_cache_range.max <= cumulative_lines_counts[i]) {
last_block_id = i;
break;
}
}
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
size_t last_block_id = 0; size_t last_block_id = 0;
for (size_t i = 0; i < cumulative_lines_counts.size(); ++i) { for (size_t i = 0; i < cumulative_lines_counts.size(); ++i) {
if (*m_cache_range.max <= cumulative_lines_counts[i]) { if (*m_cache_range.max <= cumulative_lines_counts[i]) {
@ -749,6 +760,9 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s
break; break;
} }
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
assert(last_block_id >= first_block_id); assert(last_block_id >= first_block_id);
FilePtr file(boost::nowide::fopen(m_filename.c_str(), "rb")); FilePtr file(boost::nowide::fopen(m_filename.c_str(), "rb"));
@ -785,11 +799,23 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s
} }
const size_t ref_id = (i == 0) ? 0 : i - 1; const size_t ref_id = (i == 0) ? 0 : i - 1;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
const size_t first_line_id = (i == 0) ? *m_cache_range.min : const size_t first_line_id = (i == 0) ? *m_cache_range.min :
(*m_cache_range.min > cumulative_lines_counts[ref_id]) ? *m_cache_range.min - cumulative_lines_counts[ref_id] : 1; (*m_cache_range.min > cumulative_lines_counts[ref_id]) ? *m_cache_range.min - cumulative_lines_counts[ref_id] : 1;
const size_t last_line_id = (*m_cache_range.max <= cumulative_lines_counts[i]) ? const size_t last_line_id = (*m_cache_range.max <= cumulative_lines_counts[i]) ?
(i == 0) ? *m_cache_range.max : *m_cache_range.max - cumulative_lines_counts[ref_id] : m_lines_ends[i].size(); (i == 0) ? *m_cache_range.max : *m_cache_range.max - cumulative_lines_counts[ref_id] : m_lines_ends[i].size();
assert(last_line_id >= first_line_id); assert(last_line_id >= first_line_id);
#else
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
const size_t first_line_id = (i == 0) ? *m_cache_range.min :
(*m_cache_range.min > cumulative_lines_counts[ref_id]) ? *m_cache_range.min - cumulative_lines_counts[ref_id] : 1;
const size_t last_line_id = (*m_cache_range.max <= cumulative_lines_counts[i]) ?
(i == 0) ? *m_cache_range.max : *m_cache_range.max - cumulative_lines_counts[ref_id] : m_lines_ends[i].size();
assert(last_line_id >= first_line_id);
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
for (size_t j = first_line_id; j <= last_line_id; ++j) { for (size_t j = first_line_id; j <= last_line_id; ++j) {
const size_t begin = (j == 1) ? 0 : m_lines_ends[i][j - 2]; const size_t begin = (j == 1) ? 0 : m_lines_ends[i][j - 2];
@ -811,14 +837,19 @@ void GCodeViewer::SequentialView::GCodeWindow::render(float top, float bottom, s
} }
} }
} }
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER
assert(m_lines_cache.size() == m_cache_range.size());
#endif // ENABLE_NEW_GCODE_VIEWER
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}; };
static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT; static const ImVec4 LINE_NUMBER_COLOR = ImGuiWrapper::COL_ORANGE_LIGHT;
static const ImVec4 SELECTION_RECT_COLOR = ImGuiWrapper::COL_ORANGE_DARK; static const ImVec4 SELECTION_RECT_COLOR = ImGuiWrapper::COL_ORANGE_DARK;
static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f }; static const ImVec4 COMMAND_COLOR = { 0.8f, 0.8f, 0.0f, 1.0f };
static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f }; static const ImVec4 PARAMETERS_COLOR = { 1.0f, 1.0f, 1.0f, 1.0f };
static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f }; static const ImVec4 COMMENT_COLOR = { 0.7f, 0.7f, 0.7f, 1.0f };
static const ImVec4 ELLIPSIS_COLOR = { 0.0f, 0.7f, 0.0f, 1.0f }; static const ImVec4 ELLIPSIS_COLOR = { 0.0f, 0.7f, 0.0f, 1.0f };
if (!m_visible || m_filename.empty() || m_lines_ends.empty() || curr_line_id == 0) if (!m_visible || m_filename.empty() || m_lines_ends.empty() || curr_line_id == 0)
return; return;
@ -1178,7 +1209,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
{ {
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#if ENABLE_NEW_GCODE_VIEWER #if ENABLE_NEW_GCODE_VIEWER
m_new_viewer.set_top_layer_only_view(get_app_config()->get_bool("seq_top_layer_only")); m_new_viewer.set_top_layer_only_view_range(get_app_config()->get_bool("seq_top_layer_only"));
std::vector<ColorRGBA> tool_colors; std::vector<ColorRGBA> tool_colors;
if (m_new_viewer.get_view_type() == libvgcode::EViewType::Tool && !gcode_result.extruder_colors.empty()) if (m_new_viewer.get_view_type() == libvgcode::EViewType::Tool && !gcode_result.extruder_colors.empty())

View File

@ -23,7 +23,7 @@ struct Settings
bool update_colors{ true }; bool update_colors{ true };
EViewType view_type{ EViewType::FeatureType }; EViewType view_type{ EViewType::FeatureType };
ETimeMode time_mode{ ETimeMode::Normal }; ETimeMode time_mode{ ETimeMode::Normal };
bool top_layer_only_view{ false }; bool top_layer_only_view_range{ false };
std::map<EOptionType, bool> options_visibility{ { std::map<EOptionType, bool> options_visibility{ {
{ EOptionType::Travels, false }, { EOptionType::Travels, false },

View File

@ -67,8 +67,8 @@ void ViewRange::set_global_range(uint32_t min, uint32_t max)
void ViewRange::reset() void ViewRange::reset()
{ {
m_global.reset();
m_current.reset(); m_current.reset();
m_global.reset();
} }
} // namespace libvgcode } // namespace libvgcode

View File

@ -73,14 +73,14 @@ void Viewer::set_layers_range(uint32_t min, uint32_t max)
m_impl.set_layers_range(min, max); m_impl.set_layers_range(min, max);
} }
bool Viewer::is_top_layer_only_view() const bool Viewer::is_top_layer_only_view_range() const
{ {
return m_impl.is_top_layer_only_view(); return m_impl.is_top_layer_only_view_range();
} }
void Viewer::set_top_layer_only_view(bool top_layer_only_view) void Viewer::set_top_layer_only_view_range(bool top_layer_only_view_range)
{ {
m_impl.set_top_layer_only_view(top_layer_only_view); m_impl.set_top_layer_only_view_range(top_layer_only_view_range);
} }
bool Viewer::is_option_visible(EOptionType type) const bool Viewer::is_option_visible(EOptionType type) const

View File

@ -49,8 +49,8 @@ public:
void set_layers_range(const std::array<uint32_t, 2>& range); void set_layers_range(const std::array<uint32_t, 2>& range);
void set_layers_range(uint32_t min, uint32_t max); void set_layers_range(uint32_t min, uint32_t max);
bool is_top_layer_only_view() const; bool is_top_layer_only_view_range() const;
void set_top_layer_only_view(bool top_layer_only_view); void set_top_layer_only_view_range(bool top_layer_only_view_range);
bool is_option_visible(EOptionType type) const; bool is_option_visible(EOptionType type) const;
void toggle_option_visibility(EOptionType type); void toggle_option_visibility(EOptionType type);

View File

@ -752,11 +752,11 @@ void ViewerImpl::update_enabled_entities()
// 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) if (m_settings.top_layer_only_view_range)
range[0] = m_view_range.get_global_range()[0]; range[0] = m_view_range.get_global_range()[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()) if (m_vertices[range[1]].is_option() && range[1] < static_cast<uint32_t>(m_vertices.size()) - 1)
++range[1]; ++range[1];
for (uint32_t i = range[0]; i < range[1]; ++i) { for (uint32_t i = range[0]; i < range[1]; ++i) {
@ -830,10 +830,11 @@ void ViewerImpl::update_colors()
{ {
update_color_ranges(); update_color_ranges();
const uint32_t top_layer_id = m_settings.top_layer_only_view ? m_layers_range.get()[1] : 0; const uint32_t top_layer_id = m_settings.top_layer_only_view_range ? m_layers_range.get()[1] : 0;
const bool color_top_layer_only = m_view_range.get_global_range()[1] != m_view_range.get_current_range()[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] = (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]));
} }
// update gpu buffer for colors // update gpu buffer for colors
@ -892,9 +893,9 @@ const std::array<uint32_t, 2>& ViewerImpl::get_layers_range() const
return m_layers_range.get(); return m_layers_range.get();
} }
bool ViewerImpl::is_top_layer_only_view() const bool ViewerImpl::is_top_layer_only_view_range() const
{ {
return m_settings.top_layer_only_view; return m_settings.top_layer_only_view_range;
} }
bool ViewerImpl::is_option_visible(EOptionType type) const bool ViewerImpl::is_option_visible(EOptionType type) const
@ -946,9 +947,9 @@ void ViewerImpl::set_layers_range(uint32_t min, uint32_t max)
m_settings.update_colors = true; m_settings.update_colors = true;
} }
void ViewerImpl::set_top_layer_only_view(bool top_layer_only_view) void ViewerImpl::set_top_layer_only_view_range(bool top_layer_only_view_range)
{ {
m_settings.top_layer_only_view = top_layer_only_view; m_settings.top_layer_only_view_range = top_layer_only_view_range;
m_settings.update_colors = true; m_settings.update_colors = true;
} }
@ -1030,9 +1031,16 @@ void ViewerImpl::set_view_current_range(uint32_t min, uint32_t max)
new_range.set(min_id, max_id); new_range.set(min_id, max_id);
if (m_old_current_range != new_range) { if (m_old_current_range != new_range) {
if (m_settings.update_view_global_range) {
// 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_range(new_range); m_view_range.set_current_range(new_range);
m_old_current_range = new_range; m_old_current_range = new_range;
m_settings.update_enabled_entities = true; m_settings.update_enabled_entities = true;
m_settings.update_colors = true;
} }
} }
@ -1186,16 +1194,34 @@ void ViewerImpl::set_tool_marker_alpha(float alpha)
} }
#endif // !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS #endif // !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
static bool is_visible(EMoveType type, const Settings& settings)
{
try
{
return ((type == EMoveType::Travel && !settings.options_visibility.at(EOptionType::Travels)) ||
(type == EMoveType::Wipe && !settings.options_visibility.at(EOptionType::Wipes)) ||
(type == EMoveType::Retract && !settings.options_visibility.at(EOptionType::Retractions)) ||
(type == EMoveType::Unretract && !settings.options_visibility.at(EOptionType::Unretractions)) ||
(type == EMoveType::Seam && !settings.options_visibility.at(EOptionType::Seams)) ||
(type == EMoveType::ToolChange && !settings.options_visibility.at(EOptionType::ToolChanges)) ||
(type == EMoveType::ColorChange && !settings.options_visibility.at(EOptionType::ColorChanges)) ||
(type == EMoveType::PausePrint && !settings.options_visibility.at(EOptionType::PausePrints)) ||
(type == EMoveType::CustomGCode && !settings.options_visibility.at(EOptionType::CustomGCodes))) ? false : true;
}
catch (...)
{
return false;
}
}
void ViewerImpl::update_view_global_range() void ViewerImpl::update_view_global_range()
{ {
const std::array<uint32_t, 2>& layers_range = m_layers_range.get(); const std::array<uint32_t, 2>& layers_range = m_layers_range.get();
const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels); const bool travels_visible = m_settings.options_visibility.at(EOptionType::Travels);
auto first_it = m_vertices.begin(); auto first_it = m_vertices.begin();
while (first_it != m_vertices.end() && ( while (first_it != m_vertices.end() &&
first_it->layer_id < layers_range[0] || (first_it->layer_id < layers_range[0] || !is_visible(first_it->type, m_settings))) {
first_it->is_option() ||
(first_it->is_travel() && !travels_visible))) {
++first_it; ++first_it;
} }
@ -1213,18 +1239,29 @@ void ViewerImpl::update_view_global_range()
while (last_it != m_vertices.end() && last_it->layer_id <= layers_range[1]) { while (last_it != m_vertices.end() && last_it->layer_id <= layers_range[1]) {
++last_it; ++last_it;
} }
if (last_it != first_it)
--last_it;
// remove trailing options, if any // remove disabled trailing options, if any
auto rev_first_it = std::make_reverse_iterator(first_it); auto rev_first_it = std::make_reverse_iterator(first_it);
if (rev_first_it != m_vertices.rbegin())
--rev_first_it;
auto rev_last_it = std::make_reverse_iterator(last_it); auto rev_last_it = std::make_reverse_iterator(last_it);
while (rev_last_it != rev_first_it && rev_last_it->is_option()) { if (rev_last_it != m_vertices.rbegin())
--rev_last_it;
bool reduced = false;
while (rev_last_it != rev_first_it && !is_visible(rev_last_it->type, m_settings)) {
++rev_last_it; ++rev_last_it;
reduced = true;
} }
last_it = rev_last_it.base(); if (reduced && rev_last_it != m_vertices.rend())
last_it = rev_last_it.base() - 1;
if (travels_visible) { if (travels_visible) {
// if the global range ends with a travel move, extend it to the travel end // if the global range ends with a travel move, extend it to the travel end
while (last_it != m_vertices.end() && last_it->is_travel()) { while (last_it != m_vertices.end() && last_it + 1 != m_vertices.end() && last_it->is_travel()) {
++last_it; ++last_it;
} }
} }

View File

@ -82,7 +82,7 @@ public:
EViewType get_view_type() const; EViewType get_view_type() const;
ETimeMode get_time_mode() const; ETimeMode get_time_mode() const;
const std::array<uint32_t, 2>& get_layers_range() const; const std::array<uint32_t, 2>& get_layers_range() const;
bool is_top_layer_only_view() const; bool is_top_layer_only_view_range() const;
bool is_option_visible(EOptionType type) const; bool is_option_visible(EOptionType type) const;
bool is_extrusion_role_visible(EGCodeExtrusionRole role) const; bool is_extrusion_role_visible(EGCodeExtrusionRole role) const;
@ -93,7 +93,7 @@ public:
void set_time_mode(ETimeMode mode); void set_time_mode(ETimeMode mode);
void set_layers_range(const std::array<uint32_t, 2>& range); void set_layers_range(const std::array<uint32_t, 2>& range);
void set_layers_range(uint32_t min, uint32_t max); void set_layers_range(uint32_t min, uint32_t max);
void set_top_layer_only_view(bool top_layer_only_view); void set_top_layer_only_view_range(bool top_layer_only_view_range);
void toggle_option_visibility(EOptionType type); void toggle_option_visibility(EOptionType type);
void toggle_extrusion_role_visibility(EGCodeExtrusionRole role); void toggle_extrusion_role_visibility(EGCodeExtrusionRole role);