diff --git a/src/libvgcode/include/PathVertex.hpp b/src/libvgcode/include/PathVertex.hpp index f48384e1f6..36cdd24b69 100644 --- a/src/libvgcode/include/PathVertex.hpp +++ b/src/libvgcode/include/PathVertex.hpp @@ -77,7 +77,7 @@ struct PathVertex // // Segment estimated times // - std::array times{ 0.0f, 0.0f }; + std::array times{ 0.0f, 0.0f }; // // Return true if the segment is an extrusion move @@ -102,7 +102,7 @@ struct PathVertex bool is_custom_gcode() const; }; -static const PathVertex Dummy_Path_Vertex = PathVertex(); +static const PathVertex DUMMY_PATH_VERTEX = PathVertex(); } // namespace libvgcode diff --git a/src/libvgcode/include/Types.hpp b/src/libvgcode/include/Types.hpp index 319811bd75..20f35150ee 100644 --- a/src/libvgcode/include/Types.hpp +++ b/src/libvgcode/include/Types.hpp @@ -15,8 +15,8 @@ namespace libvgcode { static constexpr float PI = 3.141592f; -static constexpr float Default_Travels_Radius = 0.1f; -static constexpr float Default_Wipes_Radius = 0.1f; +static constexpr float DEFAULT_TRAVELS_RADIUS = 0.1f; +static constexpr float DEFAULT_WIPES_RADIUS = 0.1f; // // Vector in 3 dimensions @@ -77,7 +77,7 @@ enum class EViewType : uint8_t COUNT }; -static constexpr size_t View_Types_Count = static_cast(EViewType::COUNT); +static constexpr size_t VIEW_TYPES_COUNT = static_cast(EViewType::COUNT); // // Move types @@ -98,20 +98,7 @@ enum class EMoveType : uint8_t COUNT }; -static constexpr size_t Move_Types_Count = static_cast(EMoveType::COUNT); - -// -// Travel move types -// -enum class ETravelMoveType : uint8_t -{ - Move, - Extrude, - Retract, - COUNT -}; - -static constexpr size_t Travel_Move_Types_Count = static_cast(ETravelMoveType::COUNT); +static constexpr size_t MOVE_TYPES_COUNT = static_cast(EMoveType::COUNT); // // Extrusion roles @@ -136,7 +123,7 @@ enum class EGCodeExtrusionRole : uint8_t COUNT }; -static constexpr size_t GCode_Extrusion_Roles_Count = static_cast(EGCodeExtrusionRole::COUNT); +static constexpr size_t GCODE_EXTRUSION_ROLES_COUNT = static_cast(EGCodeExtrusionRole::COUNT); // // Option types @@ -159,7 +146,7 @@ enum class EOptionType : uint8_t COUNT }; -static constexpr size_t Option_Types_Count = static_cast(EOptionType::COUNT); +static constexpr size_t OPTION_TYPES_COUNT = static_cast(EOptionType::COUNT); // // Time modes @@ -171,7 +158,7 @@ enum class ETimeMode : uint8_t COUNT }; -static constexpr size_t Time_Modes_Count = static_cast(ETimeMode::COUNT); +static constexpr size_t TIME_MODES_COUNT = static_cast(ETimeMode::COUNT); // // Color range types @@ -183,7 +170,7 @@ enum class EColorRangeType : uint8_t COUNT }; -static constexpr size_t Color_Range_Types_Count = static_cast(EColorRangeType::COUNT); +static constexpr size_t COLOR_RANGE_TYPES_COUNT = static_cast(EColorRangeType::COUNT); // // Bounding box types @@ -196,20 +183,19 @@ enum class EBBoxType : uint8_t COUNT }; -static constexpr size_t BBox_Types_Count = static_cast(EBBoxType::COUNT); +static constexpr size_t BBOX_TYPES_COUNT = static_cast(EBBoxType::COUNT); // // Predefined colors // -static const Color Dummy_Color{ 64, 64, 64 }; -static const Color Wipe_Color { 255, 255, 0 }; +static const Color DUMMY_COLOR{ 64, 64, 64 }; // // Palette used to render moves by ranges // EViewType: Height, Width, Speed, FanSpeed, Temperature, VolumetricFlowRate, // LayerTimeLinear, LayerTimeLogarithmic // -static const std::vector Ranges_Colors{ { +static const std::vector RANGES_COLORS{ { { 11, 44, 122 }, // bluish { 19, 89, 133 }, { 28, 136, 145 }, @@ -226,7 +212,7 @@ static const std::vector Ranges_Colors{ { // // Mapping from EMoveType to EOptionType // -extern EOptionType type_to_option(EMoveType type); +extern EOptionType move_type_to_option(EMoveType type); // // Returns the linear interpolation between the two given colors diff --git a/src/libvgcode/include/Viewer.hpp b/src/libvgcode/include/Viewer.hpp index 1856c943cd..a5aebe5640 100644 --- a/src/libvgcode/include/Viewer.hpp +++ b/src/libvgcode/include/Viewer.hpp @@ -112,6 +112,16 @@ public: // std::vector get_extrusion_roles() const; + // + // Return the count of detected options + // + size_t get_options_count() const; + + // + // Return the list of detected options + // + const std::vector& get_options() const; + // // Return the estimated time for the given role and the current time mode // @@ -154,10 +164,6 @@ public: void set_option_color(EOptionType type, const Color& color); void reset_default_options_colors(); - const Color& get_travel_move_color(ETravelMoveType type) const; - void set_travel_move_color(ETravelMoveType type, const Color& color); - void reset_default_travel_moves_colors(); - const ColorRange& get_height_range() const; const ColorRange& get_width_range() const; const ColorRange& get_speed_range() const; diff --git a/src/libvgcode/src/ColorRange.cpp b/src/libvgcode/src/ColorRange.cpp index 530a2e5e2b..c13592c690 100644 --- a/src/libvgcode/src/ColorRange.cpp +++ b/src/libvgcode/src/ColorRange.cpp @@ -52,14 +52,14 @@ Color ColorRange::get_color_at(float value) const global_t = (value - m_range[0]) / step; } - const size_t color_max_idx = Ranges_Colors.size() - 1; + const size_t color_max_idx = RANGES_COLORS.size() - 1; // Compute the two colors just below (low) and above (high) the input value const size_t color_low_idx = std::clamp(static_cast(global_t), 0, color_max_idx); const size_t color_high_idx = std::clamp(color_low_idx + 1, 0, color_max_idx); // Interpolate between the low and high colors to find exactly which color the input value should get - return lerp(Ranges_Colors[color_low_idx], Ranges_Colors[color_high_idx], global_t - static_cast(color_low_idx)); + return lerp(RANGES_COLORS[color_low_idx], RANGES_COLORS[color_high_idx], global_t - static_cast(color_low_idx)); } const std::array& ColorRange::get_range() const @@ -74,11 +74,11 @@ float ColorRange::get_step_size() const default: case EColorRangeType::Linear: { - return (m_range[1] - m_range[0]) / (static_cast(Ranges_Colors.size()) - 1.0f); + return (m_range[1] - m_range[0]) / (static_cast(RANGES_COLORS.size()) - 1.0f); } case EColorRangeType::Logarithmic: { - return (m_range[0] != 0.0f) ? std::log(m_range[1] / m_range[0]) / (static_cast(Ranges_Colors.size()) - 1.0f) : 0.0f; + return (m_range[0] != 0.0f) ? std::log(m_range[1] / m_range[0]) / (static_cast(RANGES_COLORS.size()) - 1.0f) : 0.0f; } } } @@ -98,7 +98,7 @@ std::vector ColorRange::get_values() const } else { const float step_size = get_step_size(); - for (size_t i = 0; i < Ranges_Colors.size(); ++i) { + for (size_t i = 0; i < RANGES_COLORS.size(); ++i) { float value = 0.0f; switch (m_type) { diff --git a/src/libvgcode/src/ExtrusionRoles.cpp b/src/libvgcode/src/ExtrusionRoles.cpp index 79dd811937..29995ed248 100644 --- a/src/libvgcode/src/ExtrusionRoles.cpp +++ b/src/libvgcode/src/ExtrusionRoles.cpp @@ -6,13 +6,13 @@ namespace libvgcode { -void ExtrusionRoles::add(EGCodeExtrusionRole role, const std::array& times) +void ExtrusionRoles::add(EGCodeExtrusionRole role, const std::array& times) { auto role_it = m_items.find(role); if (role_it == m_items.end()) role_it = m_items.insert(std::make_pair(role, Item())).first; - for (size_t i = 0; i < Time_Modes_Count; ++i) { + for (size_t i = 0; i < TIME_MODES_COUNT; ++i) { role_it->second.times[i] += times[i]; } } diff --git a/src/libvgcode/src/ExtrusionRoles.hpp b/src/libvgcode/src/ExtrusionRoles.hpp index 59fb84f8d5..e140b48420 100644 --- a/src/libvgcode/src/ExtrusionRoles.hpp +++ b/src/libvgcode/src/ExtrusionRoles.hpp @@ -16,10 +16,10 @@ class ExtrusionRoles public: struct Item { - std::array times; + std::array times; }; - void add(EGCodeExtrusionRole role, const std::array& times); + void add(EGCodeExtrusionRole role, const std::array& times); size_t get_roles_count() const { return m_items.size(); } std::vector get_roles() const; diff --git a/src/libvgcode/src/Layers.cpp b/src/libvgcode/src/Layers.cpp index c084b77f0b..642c00c589 100644 --- a/src/libvgcode/src/Layers.cpp +++ b/src/libvgcode/src/Layers.cpp @@ -33,7 +33,7 @@ void Layers::update(const PathVertex& vertex, uint32_t vertex_id) if (vertex.type == EMoveType::Extrude && vertex.role != EGCodeExtrusionRole::Custom && item.z != vertex.position[2]) item.z = vertex.position[2]; item.range.set_max(vertex_id); - for (size_t i = 0; i < Time_Modes_Count; ++i) { + for (size_t i = 0; i < TIME_MODES_COUNT; ++i) { item.times[i] += vertex.times[i]; } item.contains_colorprint_options |= is_colorprint_option(vertex); diff --git a/src/libvgcode/src/Layers.hpp b/src/libvgcode/src/Layers.hpp index 28a53a1626..2faf8cd81f 100644 --- a/src/libvgcode/src/Layers.hpp +++ b/src/libvgcode/src/Layers.hpp @@ -45,7 +45,7 @@ private: { float z{ 0.0f }; Range range; - std::array times{ 0.0f, 0.0f }; + std::array times{ 0.0f, 0.0f }; bool contains_colorprint_options{ false }; }; diff --git a/src/libvgcode/src/Types.cpp b/src/libvgcode/src/Types.cpp index fa986a4a3c..2aa8a40e9d 100644 --- a/src/libvgcode/src/Types.cpp +++ b/src/libvgcode/src/Types.cpp @@ -9,10 +9,12 @@ namespace libvgcode { // mapping from EMoveType to EOptionType -EOptionType type_to_option(EMoveType type) +EOptionType move_type_to_option(EMoveType type) { switch (type) { + case EMoveType::Travel: { return EOptionType::Travels; } + case EMoveType::Wipe: { return EOptionType::Wipes; } case EMoveType::Retract: { return EOptionType::Retractions; } case EMoveType::Unretract: { return EOptionType::Unretractions; } case EMoveType::Seam: { return EOptionType::Seams; } diff --git a/src/libvgcode/src/ViewRange.cpp b/src/libvgcode/src/ViewRange.cpp index 1ab33ed83d..ea2f1e916e 100644 --- a/src/libvgcode/src/ViewRange.cpp +++ b/src/libvgcode/src/ViewRange.cpp @@ -8,28 +8,18 @@ namespace libvgcode { void ViewRange::set_full(Interval::value_type min, Interval::value_type max) { - // is the full range being extended ? - const bool new_max = max > m_full.get_max(); m_full.set(min, max); // force the enabled range to stay inside the modified full range m_full.clamp(m_enabled); // force the visible range to stay inside the modified enabled range m_enabled.clamp(m_visible); - if (new_max) - // force the enabled range to fill the extended full range - m_enabled.set_max(max); } void ViewRange::set_enabled(Interval::value_type min, Interval::value_type max) { - // is the enabled range being extended ? - const bool new_max = max > m_enabled.get_max(); m_enabled.set(min, max); // force the visible range to stay inside the modified enabled range m_enabled.clamp(m_visible); - if (new_max) - // force the visible range to fill the extended enabled range - m_visible.set_max(max); } void ViewRange::set_visible(Interval::value_type min, Interval::value_type max) diff --git a/src/libvgcode/src/Viewer.cpp b/src/libvgcode/src/Viewer.cpp index 7c18848379..4b66beeebd 100644 --- a/src/libvgcode/src/Viewer.cpp +++ b/src/libvgcode/src/Viewer.cpp @@ -212,6 +212,16 @@ std::vector Viewer::get_extrusion_roles() const return m_impl->get_extrusion_roles(); } +size_t Viewer::get_options_count() const +{ + return m_impl->get_options_count(); +} + +const std::vector& Viewer::get_options() const +{ + return m_impl->get_options(); +} + float Viewer::get_extrusion_role_time(EGCodeExtrusionRole role) const { return m_impl->get_extrusion_role_time(role); @@ -287,21 +297,6 @@ void Viewer::reset_default_options_colors() m_impl->reset_default_options_colors(); } -const Color& Viewer::get_travel_move_color(ETravelMoveType type) const -{ - return m_impl->get_travel_move_color(type); -} - -void Viewer::set_travel_move_color(ETravelMoveType type, const Color& color) -{ - m_impl->set_travel_move_color(type, color); -} - -void Viewer::reset_default_travel_moves_colors() -{ - m_impl->reset_default_travel_moves_colors(); -} - const ColorRange& Viewer::get_height_range() const { return m_impl->get_height_range(); diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index bbf030906c..2cce460042 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -282,7 +282,7 @@ static void delete_buffers(unsigned int& id) // Palette used to render extrusion moves by extrusion roles // EViewType: FeatureType // -const std::map ViewerImpl::Default_Extrusion_Roles_Colors{ { +const std::map ViewerImpl::DEFAULT_EXTRUSION_ROLES_COLORS{ { { EGCodeExtrusionRole::None, { 230, 179, 179 } }, { EGCodeExtrusionRole::Perimeter, { 255, 230, 77 } }, { EGCodeExtrusionRole::ExternalPerimeter, { 255, 125, 56 } }, @@ -304,7 +304,9 @@ const std::map ViewerImpl::Default_Extrusion_Roles_C // Palette used to render options // EViewType: FeatureType // -const std::map ViewerImpl::Default_Options_Colors{ { +const std::map ViewerImpl::DEFAULT_OPTIONS_COLORS{ { + { EOptionType::Travels, { 56, 72, 155 } }, + { EOptionType::Wipes, { 255, 255, 0 } }, { EOptionType::Retractions, { 205, 34, 214 } }, { EOptionType::Unretractions, { 73, 173, 207 } }, { EOptionType::Seams, { 230, 230, 230 } }, @@ -314,17 +316,6 @@ const std::map ViewerImpl::Default_Options_Colors{ { { EOptionType::CustomGCodes, { 226, 210, 67 } } } }; -// -// Palette used to render travel moves -// EViewType: FeatureType, Height, Width, FanSpeed, Temperature, VolumetricFlowRate, -// LayerTimeLinear, LayerTimeLogarithmic -// -const std::map ViewerImpl::Default_Travel_Moves_Colors{ { - { ETravelMoveType::Move, { 56, 72, 155 } }, - { ETravelMoveType::Extrude, { 29, 108, 26 } }, - { ETravelMoveType::Retract, { 129, 16, 7 } } -} }; - ViewerImpl::~ViewerImpl() { reset(); @@ -428,6 +419,7 @@ void ViewerImpl::reset() m_layers.reset(); m_view_range.reset(); m_extrusion_roles.reset(); + m_options.clear(); m_travels_time = { 0.0f, 0.0f }; m_used_extruders_ids.clear(); m_vertices.clear(); @@ -471,13 +463,17 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) const PathVertex& v = m_vertices[i]; m_layers.update(v, static_cast(i)); if (v.type == EMoveType::Travel) { - for (size_t j = 0; j < Time_Modes_Count; ++j) { + for (size_t j = 0; j < TIME_MODES_COUNT; ++j) { m_travels_time[j] += v.times[j]; } } else m_extrusion_roles.add(v.role, v.times); + const EOptionType option_type = move_type_to_option(v.type); + if (option_type != EOptionType::COUNT) + m_options.emplace_back(option_type); + if (v.type == EMoveType::Extrude) m_used_extruders_ids.emplace_back(v.extruder_id); @@ -499,6 +495,10 @@ void ViewerImpl::load(GCodeInputData&& gcode_data) if (!m_layers.empty()) m_layers.set_view_range(0, static_cast(m_layers.count()) - 1); + std::sort(m_options.begin(), m_options.end()); + m_options.erase(std::unique(m_options.begin(), m_options.end()), m_options.end()); + m_options.shrink_to_fit(); + std::sort(m_used_extruders_ids.begin(), m_used_extruders_ids.end()); m_used_extruders_ids.erase(std::unique(m_used_extruders_ids.begin(), m_used_extruders_ids.end()), m_used_extruders_ids.end()); m_used_extruders_ids.shrink_to_fit(); @@ -628,7 +628,7 @@ void ViewerImpl::update_enabled_entities() continue; } else if (v.is_option()) { - if (!m_settings.options_visibility.at(type_to_option(v.type))) + if (!m_settings.options_visibility.at(move_type_to_option(v.type))) continue; } else if (v.is_extrusion()) { @@ -695,7 +695,7 @@ void ViewerImpl::update_colors() for (size_t i = 0; i < m_vertices.size(); ++i) { colors[i] = (color_top_layer_only && m_vertices[i].layer_id < top_layer_id && (!m_settings.spiral_vase_mode || i != m_view_range.get_enabled()[0])) ? - encode_color(Dummy_Color) : encode_color(get_vertex_color(m_vertices[i])); + encode_color(DUMMY_COLOR) : encode_color(get_vertex_color(m_vertices[i])); } // update gpu buffer for colors @@ -793,7 +793,16 @@ void ViewerImpl::toggle_option_visibility(EOptionType type) auto it = m_settings.options_visibility.find(type); if (it != m_settings.options_visibility.end()) { it->second = !it->second; + const Interval old_enabled_range = m_view_range.get_enabled(); update_view_full_range(); + const Interval& new_enabled_range = m_view_range.get_enabled(); + if (old_enabled_range != new_enabled_range) { + const Interval& visible_range = m_view_range.get_visible(); + if (old_enabled_range == visible_range) + m_view_range.set_visible(new_enabled_range); + else if (m_settings.top_layer_only_view_range && new_enabled_range[0] < visible_range[0]) + m_view_range.set_visible(new_enabled_range[0], visible_range[1]); + } m_settings.update_enabled_entities = true; m_settings.update_colors = true; } @@ -829,27 +838,24 @@ void ViewerImpl::set_view_visible_range(uint32_t min, uint32_t max) Color ViewerImpl::get_vertex_color(const PathVertex& v) const { if (v.type == EMoveType::Noop) - return Dummy_Color; + return DUMMY_COLOR; - if (v.is_wipe()) - return Wipe_Color; - - if (v.is_option()) - return get_option_color(type_to_option(v.type)); + if (v.is_wipe() || v.is_option()) + return get_option_color(move_type_to_option(v.type)); switch (m_settings.view_type) { case EViewType::FeatureType: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : get_extrusion_role_color(v.role); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : get_extrusion_role_color(v.role); } case EViewType::Height: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : m_height_range.get_color_at(v.height); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_height_range.get_color_at(v.height); } case EViewType::Width: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : m_width_range.get_color_at(v.width); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_width_range.get_color_at(v.width); } case EViewType::Speed: { @@ -857,24 +863,24 @@ Color ViewerImpl::get_vertex_color(const PathVertex& v) const } case EViewType::FanSpeed: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : m_fan_speed_range.get_color_at(v.fan_speed); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_fan_speed_range.get_color_at(v.fan_speed); } case EViewType::Temperature: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : m_temperature_range.get_color_at(v.temperature); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_temperature_range.get_color_at(v.temperature); } case EViewType::VolumetricFlowRate: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : m_volumetric_rate_range.get_color_at(v.volumetric_rate); + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_volumetric_rate_range.get_color_at(v.volumetric_rate); } case EViewType::LayerTimeLinear: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_layer_time_range[0].get_color_at(m_layers.get_layer_time(m_settings.time_mode, static_cast(v.layer_id))); } case EViewType::LayerTimeLogarithmic: { - return v.is_travel() ? get_travel_move_color(static_cast(v.role)) : + return v.is_travel() ? get_option_color(move_type_to_option(v.type)) : m_layer_time_range[1].get_color_at(m_layers.get_layer_time(m_settings.time_mode, static_cast(v.layer_id))); } case EViewType::Tool: @@ -884,13 +890,13 @@ Color ViewerImpl::get_vertex_color(const PathVertex& v) const } case EViewType::ColorPrint: { - return m_layers.layer_contains_colorprint_options(static_cast(v.layer_id)) ? Dummy_Color : + return m_layers.layer_contains_colorprint_options(static_cast(v.layer_id)) ? DUMMY_COLOR : m_tool_colors[static_cast(v.color_id) % m_tool_colors.size()]; } default: { break; } } - return Dummy_Color; + return DUMMY_COLOR; } void ViewerImpl::set_tool_colors(const std::vector& colors) @@ -902,7 +908,7 @@ void ViewerImpl::set_tool_colors(const std::vector& colors) const Color& ViewerImpl::get_extrusion_role_color(EGCodeExtrusionRole role) const { const auto it = m_extrusion_roles_colors.find(role); - return (it == m_extrusion_roles_colors.end()) ? Dummy_Color : it->second; + return (it == m_extrusion_roles_colors.end()) ? DUMMY_COLOR : it->second; } void ViewerImpl::set_extrusion_role_color(EGCodeExtrusionRole role, const Color& color) @@ -915,7 +921,7 @@ void ViewerImpl::set_extrusion_role_color(EGCodeExtrusionRole role, const Color& const Color& ViewerImpl::get_option_color(EOptionType type) const { const auto it = m_options_colors.find(type); - return (it == m_options_colors.end()) ? Dummy_Color : it->second; + return (it == m_options_colors.end()) ? DUMMY_COLOR : it->second; } void ViewerImpl::set_option_color(EOptionType type, const Color& color) @@ -925,19 +931,6 @@ void ViewerImpl::set_option_color(EOptionType type, const Color& color) it->second = color; } -const Color& ViewerImpl::get_travel_move_color(ETravelMoveType type) const -{ - const auto it = m_travel_moves_colors.find(type); - return (it == m_travel_moves_colors.end()) ? Dummy_Color : it->second; -} - -void ViewerImpl::set_travel_move_color(ETravelMoveType type, const Color& color) -{ - auto it = m_travel_moves_colors.find(type); - if (it != m_travel_moves_colors.end()) - it->second = color; -} - void ViewerImpl::set_travels_radius(float radius) { m_travels_radius = std::clamp(radius, 0.05f, 0.5f); @@ -952,19 +945,15 @@ void ViewerImpl::set_wipes_radius(float radius) static bool is_visible(const PathVertex& v, const Settings& settings) { - try { - return ((v.type == EMoveType::Travel && !settings.options_visibility.at(EOptionType::Travels)) || - (v.type == EMoveType::Wipe && !settings.options_visibility.at(EOptionType::Wipes)) || - (v.type == EMoveType::Retract && !settings.options_visibility.at(EOptionType::Retractions)) || - (v.type == EMoveType::Unretract && !settings.options_visibility.at(EOptionType::Unretractions)) || - (v.type == EMoveType::Seam && !settings.options_visibility.at(EOptionType::Seams)) || - (v.type == EMoveType::ToolChange && !settings.options_visibility.at(EOptionType::ToolChanges)) || - (v.type == EMoveType::ColorChange && !settings.options_visibility.at(EOptionType::ColorChanges)) || - (v.type == EMoveType::PausePrint && !settings.options_visibility.at(EOptionType::PausePrints)) || - (v.type == EMoveType::CustomGCode && !settings.options_visibility.at(EOptionType::CustomGCodes)) || - (v.type == EMoveType::Extrude && !settings.extrusion_roles_visibility.at(v.role))) ? false : true; + const EOptionType option_type = move_type_to_option(v.type); + try + { + return (option_type == EOptionType::COUNT) ? + (v.type == EMoveType::Extrude) ? settings.extrusion_roles_visibility.at(v.role) : false : + settings.options_visibility.at(option_type); } - catch (...) { + catch (...) + { return false; } } diff --git a/src/libvgcode/src/ViewerImpl.hpp b/src/libvgcode/src/ViewerImpl.hpp index a7c38b5f68..def9a0272e 100644 --- a/src/libvgcode/src/ViewerImpl.hpp +++ b/src/libvgcode/src/ViewerImpl.hpp @@ -106,7 +106,7 @@ public: size_t get_vertices_count() const { return m_vertices.size(); } const PathVertex& get_current_vertex() const { return get_vertex_at(m_view_range.get_visible()[1]); } const PathVertex& get_vertex_at(size_t id) const { - return (id < m_vertices.size()) ? m_vertices[id] : Dummy_Path_Vertex; + return (id < m_vertices.size()) ? m_vertices[id] : DUMMY_PATH_VERTEX; } Color get_vertex_color(const PathVertex& vertex) const; @@ -121,6 +121,9 @@ public: size_t get_extrusion_roles_count() const { return m_extrusion_roles.get_roles_count(); } float get_extrusion_role_time(EGCodeExtrusionRole role, ETimeMode mode) const { return m_extrusion_roles.get_time(role, mode); } + size_t get_options_count() const { return m_options.size(); } + const std::vector& get_options() const { return m_options; } + float get_travels_time() const { return get_travels_time(m_settings.time_mode); } float get_travels_time(ETimeMode mode) const { return (mode < ETimeMode::COUNT) ? m_travels_time[static_cast(mode)] : 0.0f; @@ -134,15 +137,11 @@ public: const Color& get_extrusion_role_color(EGCodeExtrusionRole role) const; void set_extrusion_role_color(EGCodeExtrusionRole role, const Color& color); - void reset_default_extrusion_roles_colors() { m_extrusion_roles_colors = Default_Extrusion_Roles_Colors; } + void reset_default_extrusion_roles_colors() { m_extrusion_roles_colors = DEFAULT_EXTRUSION_ROLES_COLORS; } const Color& get_option_color(EOptionType type) const; void set_option_color(EOptionType type, const Color& color); - void reset_default_options_colors() { m_options_colors = Default_Options_Colors; } - - const Color& get_travel_move_color(ETravelMoveType type) const; - void set_travel_move_color(ETravelMoveType type, const Color& color); - void reset_default_travel_moves_colors() { m_travel_moves_colors = Default_Travel_Moves_Colors; } + void reset_default_options_colors() { m_options_colors = DEFAULT_OPTIONS_COLORS; } const ColorRange& get_height_range() const { return m_height_range; } const ColorRange& get_width_range() const { return m_width_range; } @@ -190,17 +189,17 @@ private: Layers m_layers; ViewRange m_view_range; ExtrusionRoles m_extrusion_roles; - std::array m_travels_time{ 0.0f, 0.0f }; + std::vector m_options; + std::array m_travels_time{ 0.0f, 0.0f }; std::vector m_used_extruders_ids; - float m_travels_radius{ Default_Travels_Radius }; - float m_wipes_radius{ Default_Wipes_Radius }; + float m_travels_radius{ DEFAULT_TRAVELS_RADIUS }; + float m_wipes_radius{ DEFAULT_WIPES_RADIUS }; bool m_initialized{ false }; bool m_loading{ false }; - std::map m_extrusion_roles_colors{ Default_Extrusion_Roles_Colors }; - std::map m_options_colors{ Default_Options_Colors }; - std::map m_travel_moves_colors{ Default_Travel_Moves_Colors }; + std::map m_extrusion_roles_colors{ DEFAULT_EXTRUSION_ROLES_COLORS }; + std::map m_options_colors{ DEFAULT_OPTIONS_COLORS }; // // The OpenGL element used to represent all toolpath segments @@ -249,7 +248,7 @@ private: ColorRange m_fan_speed_range; ColorRange m_temperature_range; ColorRange m_volumetric_rate_range; - std::array m_layer_time_range{ + std::array m_layer_time_range{ ColorRange(EColorRangeType::Linear), ColorRange(EColorRangeType::Logarithmic) }; std::vector m_tool_colors; @@ -344,18 +343,12 @@ private: // Palette used to render extrusion moves by extrusion roles // EViewType: FeatureType // - static const std::map Default_Extrusion_Roles_Colors; + static const std::map DEFAULT_EXTRUSION_ROLES_COLORS; // // Palette used to render options // EViewType: FeatureType // - static const std::map Default_Options_Colors; - // - // Palette used to render travel moves - // EViewType: FeatureType, Height, Width, FanSpeed, Temperature, VolumetricFlowRate, - // LayerTimeLinear, LayerTimeLogarithmic - // - static const std::map Default_Travel_Moves_Colors; + static const std::map DEFAULT_OPTIONS_COLORS; }; } // namespace libvgcode diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 24a7bd6d5f..5b33eb40ec 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -1956,7 +1956,7 @@ private: const bool color_top_layer_only = m_viewer.get_view_full_range()[1] != m_viewer.get_view_visible_range()[1]; const libvgcode::Color color = (color_top_layer_only && v.layer_id < top_layer_id && (!m_viewer.is_spiral_vase_mode() || vertex_id != m_viewer.get_view_enabled_range()[0])) ? - libvgcode::Dummy_Color : m_viewer.get_vertex_color(v); + libvgcode::DUMMY_COLOR : m_viewer.get_vertex_color(v); auto color_it = std::find_if(m_colors.begin(), m_colors.end(), [&color](const libvgcode::Color& m) { return m == color; }); if (color_it == m_colors.end()) { m_colors.emplace_back(color); @@ -4547,7 +4547,7 @@ void GCodeViewer::render_legend(float& legend_height) char buf[1024]; ::sprintf(buf, "%.*f", decimals, value); #if ENABLE_NEW_GCODE_VIEWER - append_item(EItemType::Rect, libvgcode::convert(libvgcode::Ranges_Colors[i]), buf); + append_item(EItemType::Rect, libvgcode::convert(libvgcode::RANGES_COLORS[i]), buf); #else append_item(EItemType::Rect, Range_Colors[i], buf); #endif // ENABLE_NEW_GCODE_VIEWER @@ -4560,11 +4560,11 @@ void GCodeViewer::render_legend(float& legend_height) append_range_item(0, values.front(), decimals); else if (values.size() == 2) { // two items use case - append_range_item(static_cast(libvgcode::Ranges_Colors.size()) - 1, values.back(), decimals); + append_range_item(static_cast(libvgcode::RANGES_COLORS.size()) - 1, values.back(), decimals); append_range_item(0, values.front(), decimals); } else { - for (int i = static_cast(libvgcode::Ranges_Colors.size()) - 1; i >= 0; --i) { + for (int i = static_cast(libvgcode::RANGES_COLORS.size()) - 1; i >= 0; --i) { append_range_item(i, values[i], decimals); } } @@ -4596,7 +4596,7 @@ void GCodeViewer::render_legend(float& legend_height) if (str_value == "0s") str_value = "< 1s"; #if ENABLE_NEW_GCODE_VIEWER - append_item(EItemType::Rect, libvgcode::convert(libvgcode::Ranges_Colors[i]), str_value); + append_item(EItemType::Rect, libvgcode::convert(libvgcode::RANGES_COLORS[i]), str_value); #else append_item(EItemType::Rect, Range_Colors[i], str_value); #endif // ENABLE_NEW_GCODE_VIEWER @@ -4609,11 +4609,11 @@ void GCodeViewer::render_legend(float& legend_height) append_range_item(0, values.front()); else if (values.size() == 2) { // two items use case - append_range_item(static_cast(libvgcode::Ranges_Colors.size()) - 1, values.back()); + append_range_item(static_cast(libvgcode::RANGES_COLORS.size()) - 1, values.back()); append_range_item(0, values.front()); } else { - for (int i = static_cast(libvgcode::Ranges_Colors.size()) - 1; i >= 0; --i) { + for (int i = static_cast(libvgcode::RANGES_COLORS.size()) - 1; i >= 0; --i) { append_range_item(i, values[i]); } } @@ -4777,8 +4777,8 @@ void GCodeViewer::render_legend(float& legend_height) // calculate offsets to align time/percentage data const std::vector& roles = m_viewer.get_extrusion_roles(); for (libvgcode::EGCodeExtrusionRole role : roles) { - assert(static_cast(role) < libvgcode::GCode_Extrusion_Roles_Count); - if (static_cast(role) < libvgcode::GCode_Extrusion_Roles_Count) { + assert(static_cast(role) < libvgcode::GCODE_EXTRUSION_ROLES_COUNT); + if (static_cast(role) < libvgcode::GCODE_EXTRUSION_ROLES_COUNT) { labels.push_back(_u8L(gcode_extrusion_role_to_string(convert(role)))); auto [time, percent] = role_time_and_percent(role); #else @@ -4972,7 +4972,7 @@ void GCodeViewer::render_legend(float& legend_height) const std::vector& roles = m_viewer.get_extrusion_roles(); for (size_t i = 0; i < roles.size(); ++i) { libvgcode::EGCodeExtrusionRole role = roles[i]; - if (static_cast(role) >= libvgcode::GCode_Extrusion_Roles_Count) + if (static_cast(role) >= libvgcode::GCODE_EXTRUSION_ROLES_COUNT) continue; const bool visible = m_viewer.is_extrusion_role_visible(role); @@ -5005,7 +5005,7 @@ void GCodeViewer::render_legend(float& legend_height) #if ENABLE_NEW_GCODE_VIEWER if (m_viewer.is_option_visible(libvgcode::EOptionType::Travels)) - append_item(EItemType::Line, libvgcode::convert(m_viewer.get_travel_move_color(libvgcode::ETravelMoveType::Move)), _u8L("Travel"), true, short_time_ui(get_time_dhms(travels_time)), + append_item(EItemType::Line, libvgcode::convert(m_viewer.get_option_color(libvgcode::EOptionType::Travels)), _u8L("Travel"), true, short_time_ui(get_time_dhms(travels_time)), travels_time / time_mode.time, max_time_percent, offsets, 0.0f, 0.0f); #else if (m_buffers[buffer_id(EMoveType::Travel)].visible) diff --git a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp index b002296957..006f5e2dc1 100644 --- a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp +++ b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.cpp @@ -157,17 +157,6 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels const Slic3r::GCodeProcessorResult::MoveVertex& prev = moves[i - 1]; const EMoveType curr_type = convert(curr.type); - EGCodeExtrusionRole extrusion_role; - if (curr_type == EMoveType::Travel) { - // for travel moves set the extrusion role - // which will be used later to select the proper color - extrusion_role = (curr.delta_extruder == 0.0f) ? static_cast(ETravelMoveType::Move) : - (curr.delta_extruder > 0.0f) ? static_cast(ETravelMoveType::Extrude) : - static_cast(ETravelMoveType::Retract); - } - else - extrusion_role = convert(curr.extrusion_role); - float width; float height; switch (curr_type) @@ -192,19 +181,20 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels } } - if (type_to_option(curr_type) == libvgcode::EOptionType::COUNT) { + const EOptionType option_type = move_type_to_option(curr_type); + if (option_type == EOptionType::COUNT || option_type == EOptionType::Travels || option_type == EOptionType::Wipes) { if (ret.vertices.empty() || prev.type != curr.type || prev.extrusion_role != curr.extrusion_role) { // to allow libvgcode to properly detect the start/end of a path we need to add a 'phantom' vertex // equal to the current one with the exception of the position, which should match the previous move position, // and the times, which are set to zero #if ENABLE_COG_AND_TOOL_MARKERS const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, - curr.temperature, curr.volumetric_rate(), 0.0f, extrusion_role, curr_type, + curr.temperature, curr.volumetric_rate(), 0.0f, convert(curr.extrusion_role), curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; #else const libvgcode::PathVertex vertex = { convert(prev.position), height, width, curr.feedrate, curr.fan_speed, - curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, + curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), { 0.0f, 0.0f } }; #endif // ENABLE_COG_AND_TOOL_MARKERS @@ -215,11 +205,11 @@ GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels #if ENABLE_COG_AND_TOOL_MARKERS const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, curr.temperature, curr.volumetric_rate(), curr.mm3_per_mm * (curr.position - prev.position).norm(), - extrusion_role, curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), + convert(curr.extrusion_role), curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; #else const libvgcode::PathVertex vertex = { convert(curr.position), height, width, curr.feedrate, curr.fan_speed, - curr.temperature, curr.volumetric_rate(), extrusion_role, curr_type, static_cast(curr.gcode_id), + curr.temperature, curr.volumetric_rate(), convert(curr.extrusion_role), curr_type, static_cast(curr.gcode_id), static_cast(curr.layer_id), static_cast(curr.extruder_id), static_cast(curr.cp_color_id), curr.time }; #endif // ENABLE_COG_AND_TOOL_MARKERS ret.vertices.emplace_back(vertex); diff --git a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.hpp b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.hpp index d643068eb2..7ce2fa0333 100644 --- a/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.hpp +++ b/src/slic3r/GUI/LibVGCode/LibVGCodeWrapper.hpp @@ -55,8 +55,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, float travels_radius = Default_Travels_Radius, - float wipes_radius = Default_Wipes_Radius); +extern GCodeInputData convert(const Slic3r::GCodeProcessorResult& result, float travels_radius = DEFAULT_TRAVELS_RADIUS, + float wipes_radius = DEFAULT_WIPES_RADIUS); // mapping from Slic3r::Print to libvgcode::GCodeInputData extern GCodeInputData convert(const Slic3r::Print& print, const std::vector& str_tool_colors,