mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-29 19:52:02 +08:00
New gcode visualization: layers times refactoring
This commit is contained in:
parent
39c39798a8
commit
a3322bdd45
@ -1426,7 +1426,7 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#if ENABLE_NEW_GCODE_VIEWER
|
||||
for (size_t i = 0; i < static_cast<size_t>(libvgcode::ETimeMode::COUNT); ++i) {
|
||||
const std::vector<float> layers_times = m_new_viewer.get_layers_times(static_cast<libvgcode::ETimeMode>(i));
|
||||
const std::vector<float> layers_times = get_layers_times(static_cast<libvgcode::ETimeMode>(i));
|
||||
for (size_t j = 0; j < layers_times.size(); ++j) {
|
||||
m_extrusions.ranges.layer_time[i].update_from(layers_times[j]);
|
||||
}
|
||||
@ -3088,7 +3088,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
||||
case libvgcode::EViewType::Temperature: { color = m_extrusions.ranges.temperature.get_color_at(path.temperature); break; }
|
||||
case libvgcode::EViewType::LayerTimeLinear:
|
||||
case libvgcode::EViewType::LayerTimeLogarithmic: {
|
||||
const std::vector<float> layers_times = m_new_viewer.get_layers_times();
|
||||
const std::vector<float> layers_times = get_layers_times();
|
||||
if (!layers_times.empty() && m_layers.size() == layers_times.size()) {
|
||||
const Path::Sub_Path& sub_path = path.sub_paths.front();
|
||||
double z = static_cast<double>(sub_path.first.position.z());
|
||||
@ -4584,7 +4584,7 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
std::vector<int> view_options_id;
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#if ENABLE_NEW_GCODE_VIEWER
|
||||
const std::vector<float> layers_times = m_new_viewer.get_layers_times();
|
||||
const std::vector<float> layers_times = get_layers_times();
|
||||
if (!layers_times.empty() && m_layers.size() == layers_times.size()) {
|
||||
#else
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@ -5246,9 +5246,9 @@ void GCodeViewer::render_legend(float& legend_height)
|
||||
imgui.title(time_title + ":");
|
||||
|
||||
if (ImGui::BeginTable("Times", 2)) {
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
#if ENABLE_NEW_GCODE_VIEWER
|
||||
const std::vector<float> layers_times = m_new_viewer.get_layers_times();
|
||||
const std::vector<float> layers_times = get_layers_times();
|
||||
if (!layers_times.empty())
|
||||
add_strings_row_to_table(_u8L("First layer") + ":", ImGuiWrapper::COL_ORANGE_LIGHT,
|
||||
short_time_ui(get_time_dhms(layers_times.front())), ImGuiWrapper::to_ImVec4(ColorRGBA::WHITE()));
|
||||
|
@ -25,7 +25,7 @@ static bool is_colorprint_option(const PathVertex& v)
|
||||
return v.type == EMoveType::PausePrint || v.type == EMoveType::CustomGCode;
|
||||
}
|
||||
|
||||
void Layers::update(const PathVertex& vertex, uint32_t vertex_id)
|
||||
void Layers::update(const PathVertex& vertex, const std::array<float, static_cast<size_t>(ETimeMode::COUNT)>& times, uint32_t vertex_id)
|
||||
{
|
||||
|
||||
if (m_items.empty() || vertex.layer_id == m_items.size()) {
|
||||
@ -33,11 +33,15 @@ void Layers::update(const PathVertex& vertex, uint32_t vertex_id)
|
||||
assert(vertex.layer_id == static_cast<uint32_t>(m_items.size()));
|
||||
Item& item = m_items.emplace_back(Item());
|
||||
item.range.set(vertex_id, vertex_id);
|
||||
item.times = times;
|
||||
item.contains_colorprint_options |= is_colorprint_option(vertex);
|
||||
}
|
||||
else {
|
||||
Item& item = m_items.back();
|
||||
item.range.set(item.range.get()[0], vertex_id);
|
||||
for (size_t i = 0; i < static_cast<size_t>(ETimeMode::COUNT); ++i) {
|
||||
item.times[i] += times[i];
|
||||
}
|
||||
item.contains_colorprint_options |= is_colorprint_option(vertex);
|
||||
}
|
||||
}
|
||||
@ -52,11 +56,29 @@ bool Layers::empty() const
|
||||
return m_items.empty();
|
||||
}
|
||||
|
||||
size_t Layers::get_layers_count() const
|
||||
size_t Layers::count() const
|
||||
{
|
||||
return m_items.size();
|
||||
}
|
||||
|
||||
float Layers::get_time(ETimeMode mode, uint32_t layer_id) const
|
||||
{
|
||||
return (mode < ETimeMode::COUNT&& layer_id < static_cast<uint32_t>(m_items.size())) ?
|
||||
m_items[layer_id].times[static_cast<size_t>(mode)] : 0.0f;
|
||||
}
|
||||
|
||||
std::vector<float> Layers::get_times(ETimeMode mode) const
|
||||
{
|
||||
std::vector<float> ret;
|
||||
if (mode < ETimeMode::COUNT) {
|
||||
const size_t mode_id = static_cast<size_t>(mode);
|
||||
for (const Item& item : m_items) {
|
||||
ret.emplace_back(item.times[mode_id]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Layers::layer_contains_colorprint_options(uint32_t layer_id) const
|
||||
{
|
||||
return (layer_id < static_cast<uint32_t>(m_items.size())) ? m_items[layer_id].contains_colorprint_options : false;
|
||||
|
@ -10,10 +10,9 @@
|
||||
#if ENABLE_NEW_GCODE_VIEWER
|
||||
//################################################################################################################################
|
||||
|
||||
#include "Types.hpp"
|
||||
#include "Range.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
struct PathVertex;
|
||||
@ -21,11 +20,14 @@ struct PathVertex;
|
||||
class Layers
|
||||
{
|
||||
public:
|
||||
void update(const PathVertex& vertex, uint32_t vertex_id);
|
||||
void update(const PathVertex& vertex, const std::array<float, static_cast<size_t>(ETimeMode::COUNT)>& times, uint32_t vertex_id);
|
||||
void reset();
|
||||
|
||||
bool empty() const;
|
||||
size_t get_layers_count() const;
|
||||
size_t count() const;
|
||||
|
||||
float get_time(ETimeMode mode, uint32_t layer_id) const;
|
||||
std::vector<float> get_times(ETimeMode mode) const;
|
||||
|
||||
bool layer_contains_colorprint_options(uint32_t layer_id) const;
|
||||
|
||||
@ -33,9 +35,8 @@ private:
|
||||
struct Item
|
||||
{
|
||||
Range range;
|
||||
std::array<float, static_cast<size_t>(ETimeMode::COUNT)> times{ 0.0f, 0.0f };
|
||||
bool contains_colorprint_options{ false };
|
||||
|
||||
Item() = default;
|
||||
};
|
||||
|
||||
std::vector<Item> m_items;
|
||||
|
@ -16,44 +16,44 @@
|
||||
|
||||
namespace libvgcode {
|
||||
|
||||
const std::array<uint32_t, 2>& ViewRange::get_current_range() const
|
||||
const std::array<uint32_t, 2>& ViewRange::get_current() const
|
||||
{
|
||||
return m_current.get();
|
||||
}
|
||||
|
||||
void ViewRange::set_current_range(const Range& other)
|
||||
void ViewRange::set_current(const Range& other)
|
||||
{
|
||||
set_current_range(other.get());
|
||||
set_current(other.get());
|
||||
}
|
||||
|
||||
void ViewRange::set_current_range(const std::array<uint32_t, 2>& range)
|
||||
void ViewRange::set_current(const std::array<uint32_t, 2>& range)
|
||||
{
|
||||
set_current_range(range[0], range[1]);
|
||||
set_current(range[0], range[1]);
|
||||
}
|
||||
|
||||
void ViewRange::set_current_range(uint32_t min, uint32_t max)
|
||||
void ViewRange::set_current(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);
|
||||
}
|
||||
|
||||
const std::array<uint32_t, 2>& ViewRange::get_global_range() const
|
||||
const std::array<uint32_t, 2>& ViewRange::get_global() const
|
||||
{
|
||||
return m_global.get();
|
||||
}
|
||||
|
||||
void ViewRange::set_global_range(const Range& other)
|
||||
void ViewRange::set_global(const Range& other)
|
||||
{
|
||||
set_global_range(other.get());
|
||||
set_global(other.get());
|
||||
}
|
||||
|
||||
void ViewRange::set_global_range(const std::array<uint32_t, 2>& range)
|
||||
void ViewRange::set_global(const std::array<uint32_t, 2>& range)
|
||||
{
|
||||
set_global_range(range[0], range[1]);
|
||||
set_global(range[0], range[1]);
|
||||
}
|
||||
|
||||
void ViewRange::set_global_range(uint32_t min, uint32_t max)
|
||||
void ViewRange::set_global(uint32_t min, uint32_t max)
|
||||
{
|
||||
// is the global range being extended ?
|
||||
const bool new_max = max > m_global.get()[1];
|
||||
|
@ -17,15 +17,15 @@ namespace libvgcode {
|
||||
class ViewRange
|
||||
{
|
||||
public:
|
||||
const std::array<uint32_t, 2>& get_current_range() const;
|
||||
void set_current_range(const Range& other);
|
||||
void set_current_range(const std::array<uint32_t, 2>& range);
|
||||
void set_current_range(uint32_t min, uint32_t max);
|
||||
const std::array<uint32_t, 2>& get_current() const;
|
||||
void set_current(const Range& other);
|
||||
void set_current(const std::array<uint32_t, 2>& range);
|
||||
void set_current(uint32_t min, uint32_t max);
|
||||
|
||||
const std::array<uint32_t, 2>& get_global_range() const;
|
||||
void set_global_range(const Range& other);
|
||||
void set_global_range(const std::array<uint32_t, 2>& range);
|
||||
void set_global_range(uint32_t min, uint32_t max);
|
||||
const std::array<uint32_t, 2>& get_global() const;
|
||||
void set_global(const Range& other);
|
||||
void set_global(const std::array<uint32_t, 2>& range);
|
||||
void set_global(uint32_t min, uint32_t max);
|
||||
|
||||
void reset();
|
||||
|
||||
|
@ -520,13 +520,11 @@ void ViewerImpl::reset()
|
||||
m_layers.reset();
|
||||
m_layers_range.reset();
|
||||
m_view_range.reset();
|
||||
m_old_current_range.reset();
|
||||
m_extrusion_roles.reset();
|
||||
m_travels_time = { 0.0f, 0.0f };
|
||||
m_vertices.clear();
|
||||
m_vertices_map.clear();
|
||||
m_valid_lines_bitset.clear();
|
||||
m_layers_times = std::array<std::vector<float>, static_cast<size_t>(ETimeMode::COUNT)>();
|
||||
#if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
m_cog_marker.reset();
|
||||
#endif // !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
@ -607,7 +605,7 @@ void ViewerImpl::load(const Slic3r::GCodeProcessorResult& gcode_result, const GC
|
||||
static_cast<uint32_t>(curr.layer_id) };
|
||||
m_vertices_map.emplace_back(static_cast<uint32_t>(i) - seams_count);
|
||||
m_vertices.emplace_back(vertex);
|
||||
m_layers.update(vertex, static_cast<uint32_t>(m_vertices.size()));
|
||||
m_layers.update(vertex, { 0.0f, 0.0f }, static_cast<uint32_t>(m_vertices.size()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -616,7 +614,7 @@ void ViewerImpl::load(const Slic3r::GCodeProcessorResult& gcode_result, const GC
|
||||
static_cast<uint8_t>(curr.cp_color_id), static_cast<uint32_t>(curr.layer_id) };
|
||||
m_vertices_map.emplace_back(static_cast<uint32_t>(i) - seams_count);
|
||||
m_vertices.emplace_back(vertex);
|
||||
m_layers.update(vertex, static_cast<uint32_t>(m_vertices.size()));
|
||||
m_layers.update(vertex, curr.time, static_cast<uint32_t>(m_vertices.size()));
|
||||
|
||||
#if !ENABLE_NEW_GCODE_NO_COG_AND_TOOL_MARKERS
|
||||
// updates calculation for center of gravity
|
||||
@ -639,19 +637,6 @@ void ViewerImpl::load(const Slic3r::GCodeProcessorResult& gcode_result, const GC
|
||||
}
|
||||
else
|
||||
m_extrusion_roles.add(curr_role, curr.time);
|
||||
|
||||
if (curr.layer_id >= m_layers_times[0].size()) {
|
||||
const size_t curr_size = m_layers_times[0].size();
|
||||
for (size_t i = 0; i < static_cast<size_t>(ETimeMode::COUNT); ++i) {
|
||||
m_layers_times[i].resize(curr.layer_id + 1);
|
||||
for (size_t j = curr_size; j < m_layers_times[i].size(); ++j) {
|
||||
m_layers_times[i][j] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < static_cast<size_t>(ETimeMode::COUNT); ++i) {
|
||||
m_layers_times[i].back() += curr.time[i];
|
||||
}
|
||||
}
|
||||
m_vertices_map.shrink_to_fit();
|
||||
m_vertices.shrink_to_fit();
|
||||
@ -738,7 +723,7 @@ void ViewerImpl::load(const Slic3r::GCodeProcessorResult& gcode_result, const GC
|
||||
}
|
||||
|
||||
if (!m_layers.empty())
|
||||
set_layers_range(0, static_cast<uint32_t>(m_layers.get_layers_count() - 1));
|
||||
set_layers_range(0, static_cast<uint32_t>(m_layers.count() - 1));
|
||||
update_view_global_range();
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
@ -747,13 +732,13 @@ void ViewerImpl::update_enabled_entities()
|
||||
{
|
||||
std::vector<uint32_t> enabled_segments;
|
||||
std::vector<uint32_t> enabled_options;
|
||||
std::array<uint32_t, 2> range = m_view_range.get_current_range();
|
||||
std::array<uint32_t, 2> range = m_view_range.get_current();
|
||||
|
||||
// when top layer only visualization is enabled, we need to render
|
||||
// all the toolpaths in the other layers as grayed, so extend the range
|
||||
// to contain them
|
||||
if (m_settings.top_layer_only_view_range)
|
||||
range[0] = m_view_range.get_global_range()[0];
|
||||
range[0] = m_view_range.get_global()[0];
|
||||
|
||||
// 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)
|
||||
@ -831,7 +816,7 @@ void ViewerImpl::update_colors()
|
||||
update_color_ranges();
|
||||
|
||||
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];
|
||||
const bool color_top_layer_only = m_view_range.get_global()[1] != m_view_range.get_current()[1];
|
||||
std::vector<float> colors(m_vertices.size());
|
||||
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]));
|
||||
@ -987,12 +972,12 @@ void ViewerImpl::toggle_extrusion_role_visibility(EGCodeExtrusionRole role)
|
||||
|
||||
const std::array<uint32_t, 2>& ViewerImpl::get_view_current_range() const
|
||||
{
|
||||
return m_view_range.get_current_range();
|
||||
return m_view_range.get_current();
|
||||
}
|
||||
|
||||
const std::array<uint32_t, 2>& ViewerImpl::get_view_global_range() const
|
||||
{
|
||||
return m_view_range.get_global_range();
|
||||
return m_view_range.get_global();
|
||||
}
|
||||
|
||||
void ViewerImpl::set_view_current_range(uint32_t min, uint32_t max)
|
||||
@ -1030,15 +1015,14 @@ void ViewerImpl::set_view_current_range(uint32_t min, uint32_t max)
|
||||
Range new_range;
|
||||
new_range.set(min_id, max_id);
|
||||
|
||||
if (m_old_current_range != new_range) {
|
||||
if (m_view_range.get_current() != new_range.get()) {
|
||||
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_old_current_range = new_range;
|
||||
m_view_range.set_current(new_range);
|
||||
m_settings.update_enabled_entities = true;
|
||||
m_settings.update_colors = true;
|
||||
}
|
||||
@ -1051,7 +1035,7 @@ size_t ViewerImpl::get_vertices_count() const
|
||||
|
||||
PathVertex ViewerImpl::get_current_vertex() const
|
||||
{
|
||||
return m_vertices[m_view_range.get_current_range()[1]];
|
||||
return m_vertices[m_view_range.get_current()[1]];
|
||||
}
|
||||
|
||||
PathVertex ViewerImpl::get_vertex_at(size_t id) const
|
||||
@ -1096,7 +1080,7 @@ std::vector<float> ViewerImpl::get_layers_times() const
|
||||
|
||||
std::vector<float> ViewerImpl::get_layers_times(ETimeMode mode) const
|
||||
{
|
||||
return (mode < ETimeMode::COUNT) ? m_layers_times[static_cast<size_t>(mode)] : std::vector<float>();
|
||||
return m_layers.get_times(mode);
|
||||
}
|
||||
|
||||
size_t ViewerImpl::get_tool_colors_count() const
|
||||
@ -1226,7 +1210,7 @@ void ViewerImpl::update_view_global_range()
|
||||
}
|
||||
|
||||
if (first_it == m_vertices.end())
|
||||
m_view_range.set_global_range(0, 0);
|
||||
m_view_range.set_global(0, 0);
|
||||
else {
|
||||
if (travels_visible) {
|
||||
// if the global range starts with a travel move, extend it to the travel start
|
||||
@ -1266,7 +1250,7 @@ void ViewerImpl::update_view_global_range()
|
||||
}
|
||||
}
|
||||
|
||||
m_view_range.set_global_range(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it));
|
||||
m_view_range.set_global(std::distance(m_vertices.begin(), first_it), std::distance(m_vertices.begin(), last_it));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1296,9 +1280,10 @@ void ViewerImpl::update_color_ranges()
|
||||
m_speed_range.update(v.feedrate);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_layers_times.size(); ++i) {
|
||||
for (const float time : m_layers_times[static_cast<uint8_t>(m_settings.time_mode)]) {
|
||||
m_layer_time_range[i].update(time);
|
||||
const std::vector<float> times = m_layers.get_times(m_settings.time_mode);
|
||||
for (size_t i = 0; i < m_layer_time_range.size(); ++i) {
|
||||
for (float t : times) {
|
||||
m_layer_time_range[i].update(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1354,12 +1339,12 @@ Color ViewerImpl::select_color(const PathVertex& v) const
|
||||
case EViewType::LayerTimeLinear:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[0].get_color_at(m_layers_times[static_cast<size_t>(m_settings.time_mode)][v.layer_id]);
|
||||
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[0].get_color_at(m_layers.get_time(m_settings.time_mode, v.layer_id));
|
||||
}
|
||||
case EViewType::LayerTimeLogarithmic:
|
||||
{
|
||||
assert(!v.is_travel() || role < Travels_Colors.size());
|
||||
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[1].get_color_at(m_layers_times[static_cast<size_t>(m_settings.time_mode)][v.layer_id]);
|
||||
return v.is_travel() ? Travels_Colors[role] : m_layer_time_range[1].get_color_at(m_layers.get_time(m_settings.time_mode, v.layer_id));
|
||||
}
|
||||
case EViewType::Tool:
|
||||
{
|
||||
|
@ -154,10 +154,8 @@ private:
|
||||
Layers m_layers;
|
||||
Range m_layers_range;
|
||||
ViewRange m_view_range;
|
||||
Range m_old_current_range;
|
||||
ExtrusionRoles m_extrusion_roles;
|
||||
std::array<float, static_cast<size_t>(ETimeMode::COUNT)> m_travels_time{ 0.0f, 0.0f };
|
||||
std::array<std::vector<float>, static_cast<size_t>(ETimeMode::COUNT)> m_layers_times;
|
||||
|
||||
//
|
||||
// The OpenGL element used to represent all toolpath segments
|
||||
|
Loading…
x
Reference in New Issue
Block a user