From 3a6436f6f0369e57708c2174d7974eb6e4047b94 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 14 Feb 2018 18:42:09 +0100 Subject: [PATCH] Split the GCodePreviewData from the GCodeAnalyzer, as in the next step the GCodePreviewData will be exported to Perl. --- xs/CMakeLists.txt | 2 + xs/src/libslic3r/GCode/Analyzer.cpp | 387 ++-------------------------- xs/src/libslic3r/GCode/Analyzer.hpp | 190 -------------- xs/src/libslic3r/Print.cpp | 4 +- xs/src/libslic3r/Print.hpp | 6 +- xs/src/slic3r/GUI/3DScene.cpp | 110 ++++---- xs/src/slic3r/GUI/3DScene.hpp | 9 +- 7 files changed, 76 insertions(+), 632 deletions(-) diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index de475eaa0..a1848a67a 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -90,6 +90,8 @@ add_library(libslic3r STATIC ${LIBDIR}/libslic3r/GCode/CoolingBuffer.hpp ${LIBDIR}/libslic3r/GCode/PressureEqualizer.cpp ${LIBDIR}/libslic3r/GCode/PressureEqualizer.hpp + ${LIBDIR}/libslic3r/GCode/PreviewData.cpp + ${LIBDIR}/libslic3r/GCode/PreviewData.hpp ${LIBDIR}/libslic3r/GCode/PrintExtents.cpp ${LIBDIR}/libslic3r/GCode/PrintExtents.hpp ${LIBDIR}/libslic3r/GCode/SpiralVase.cpp diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 02e999bb4..938f0371d 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -7,6 +7,7 @@ #include "Print.hpp" #include "Analyzer.hpp" +#include "PreviewData.hpp" static const std::string AXIS_STR = "XYZE"; static const float MMMIN_TO_MMSEC = 1.0f / 60.0f; @@ -88,364 +89,6 @@ GCodeAnalyzer::GCodeMove::GCodeMove(GCodeMove::EType type, const GCodeAnalyzer:: { } -const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Color::Dummy(0.0f, 0.0f, 0.0f, 0.0f); - -GCodeAnalyzer::PreviewData::Color::Color() -{ - rgba[0] = 1.0f; - rgba[1] = 1.0f; - rgba[2] = 1.0f; - rgba[3] = 1.0f; -} - -GCodeAnalyzer::PreviewData::Color::Color(float r, float g, float b, float a) -{ - rgba[0] = r; - rgba[1] = g; - rgba[2] = b; - rgba[3] = a; -} - -std::vector GCodeAnalyzer::PreviewData::Color::as_bytes() const -{ - std::vector ret; - for (unsigned int i = 0; i < 4; ++i) - { - ret.push_back((unsigned char)(255.0f * rgba[i])); - } - return ret; -} - -GCodeAnalyzer::PreviewData::Extrusion::Layer::Layer(float z, const ExtrusionPaths& paths) - : z(z) - , paths(paths) -{ -} - -GCodeAnalyzer::PreviewData::Travel::Polyline::Polyline(EType type, EDirection direction, float feedrate, unsigned int extruder_id, const Polyline3& polyline) - : type(type) - , direction(direction) - , feedrate(feedrate) - , extruder_id(extruder_id) - , polyline(polyline) -{ -} - -const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Range::Default_Colors[Colors_Count] = -{ - Color(0.043f, 0.173f, 0.478f, 1.0f), - Color(0.075f, 0.349f, 0.522f, 1.0f), - Color(0.110f, 0.533f, 0.569f, 1.0f), - Color(0.016f, 0.839f, 0.059f, 1.0f), - Color(0.667f, 0.949f, 0.000f, 1.0f), - Color(0.988f, 0.975f, 0.012f, 1.0f), - Color(0.961f, 0.808f, 0.039f, 1.0f), - Color(0.890f, 0.533f, 0.125f, 1.0f), - Color(0.820f, 0.408f, 0.188f, 1.0f), - Color(0.761f, 0.322f, 0.235f, 1.0f) -}; - -GCodeAnalyzer::PreviewData::Range::Range() -{ - reset(); -} - -void GCodeAnalyzer::PreviewData::Range::reset() -{ - min = FLT_MAX; - max = -FLT_MAX; -} - -bool GCodeAnalyzer::PreviewData::Range::empty() const -{ - return min == max; -} - -void GCodeAnalyzer::PreviewData::Range::update_from(float value) -{ - min = std::min(min, value); - max = std::max(max, value); -} - -void GCodeAnalyzer::PreviewData::Range::set_from(const Range& other) -{ - min = other.min; - max = other.max; -} - -float GCodeAnalyzer::PreviewData::Range::step_size() const -{ - return (max - min) / (float)Colors_Count; -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::Range::get_color_at_max() const -{ - return colors[Colors_Count - 1]; -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::Range::get_color_at(float value) const -{ - return empty() ? get_color_at_max() : colors[clamp((unsigned int)0, Colors_Count - 1, (unsigned int)((value - min) / step_size()))]; -} - -GCodeAnalyzer::PreviewData::LegendItem::LegendItem(const std::string& text, const GCodeAnalyzer::PreviewData::Color& color) - : text(text) - , color(color) -{ -} - -const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Extrusion::Default_Extrusion_Role_Colors[Num_Extrusion_Roles] = -{ - Color(0.0f, 0.0f, 0.0f, 1.0f), // erNone - Color(1.0f, 0.0f, 0.0f, 1.0f), // erPerimeter - Color(0.0f, 1.0f, 0.0f, 1.0f), // erExternalPerimeter - Color(0.0f, 0.0f, 1.0f, 1.0f), // erOverhangPerimeter - Color(1.0f, 1.0f, 0.0f, 1.0f), // erInternalInfill - Color(1.0f, 0.0f, 1.0f, 1.0f), // erSolidInfill - Color(0.0f, 1.0f, 1.0f, 1.0f), // erTopSolidInfill - Color(0.5f, 0.5f, 0.5f, 1.0f), // erBridgeInfill - Color(1.0f, 1.0f, 1.0f, 1.0f), // erGapFill - Color(0.5f, 0.0f, 0.0f, 1.0f), // erSkirt - Color(0.0f, 0.5f, 0.0f, 1.0f), // erSupportMaterial - Color(0.0f, 0.0f, 0.5f, 1.0f), // erSupportMaterialInterface - Color(0.7f, 0.89f, 0.67f, 1.0f), // erWipeTower - Color(0.0f, 0.0f, 0.0f, 1.0f) // erMixed -}; - -// todo: merge with Slic3r::ExtrusionRole2String() from GCode.cpp -const std::string GCodeAnalyzer::PreviewData::Extrusion::Default_Extrusion_Role_Names[Num_Extrusion_Roles] -{ - "None", - "Perimeter", - "External perimeter", - "Overhang perimeter", - "Internal infill", - "Solid infill", - "Top solid infill", - "Bridge infill", - "Gap fill", - "Skirt", - "Support material", - "Support material interface", - "Wipe tower", - "Mixed" -}; - -const GCodeAnalyzer::PreviewData::Extrusion::EViewType GCodeAnalyzer::PreviewData::Extrusion::Default_View_Type = GCodeAnalyzer::PreviewData::Extrusion::FeatureType; - -void GCodeAnalyzer::PreviewData::Extrusion::set_default() -{ - view_type = Default_View_Type; - - ::memcpy((void*)role_colors, (const void*)Default_Extrusion_Role_Colors, Num_Extrusion_Roles * sizeof(Color)); - ::memcpy((void*)ranges.height.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); - ::memcpy((void*)ranges.width.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); - ::memcpy((void*)ranges.feedrate.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); - - for (unsigned int i = 0; i < Num_Extrusion_Roles; ++i) - { - role_names[i] = Default_Extrusion_Role_Names[i]; - } - - role_flags = 0; - for (unsigned int i = 0; i < Num_Extrusion_Roles; ++i) - { - role_flags += (unsigned int)::exp2((double)i); - } -} - -bool GCodeAnalyzer::PreviewData::Extrusion::is_role_flag_set(ExtrusionRole role) const -{ - return is_role_flag_set(role_flags, role); -} - -bool GCodeAnalyzer::PreviewData::Extrusion::is_role_flag_set(unsigned int flags, ExtrusionRole role) -{ - if (!is_valid_extrusion_role(role)) - return false; - - unsigned int flag = (unsigned int)::exp2((double)(role - erPerimeter)); - return (flags & flag) == flag; -} - -const float GCodeAnalyzer::PreviewData::Travel::Default_Width = 0.075f; -const float GCodeAnalyzer::PreviewData::Travel::Default_Height = 0.075f; -const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Travel::Default_Type_Colors[Num_Types] = -{ - Color(0.0f, 0.0f, 0.75f, 1.0f), // Move - Color(0.0f, 0.75f, 0.0f, 1.0f), // Extrude - Color(0.75f, 0.0f, 0.0f, 1.0f), // Retract -}; - -void GCodeAnalyzer::PreviewData::Travel::set_default() -{ - width = Default_Width; - height = Default_Height; - ::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * sizeof(Color)); - is_visible = false; -} - -const GCodeAnalyzer::PreviewData::Color GCodeAnalyzer::PreviewData::Retraction::Default_Color = GCodeAnalyzer::PreviewData::Color(1.0f, 1.0f, 1.0f, 1.0f); - -GCodeAnalyzer::PreviewData::Retraction::Position::Position(const Point3& position, float width, float height) - : position(position) - , width(width) - , height(height) -{ -} - -void GCodeAnalyzer::PreviewData::Retraction::set_default() -{ - color = Default_Color; - is_visible = false; -} - -void GCodeAnalyzer::PreviewData::Shell::set_default() -{ - is_visible = false; -} - -GCodeAnalyzer::PreviewData::PreviewData() -{ - set_default(); -} - -void GCodeAnalyzer::PreviewData::set_default() -{ - extrusion.set_default(); - travel.set_default(); - retraction.set_default(); - unretraction.set_default(); - shell.set_default(); -} - -void GCodeAnalyzer::PreviewData::reset() -{ - extrusion.layers.clear(); - travel.polylines.clear(); - retraction.positions.clear(); - unretraction.positions.clear(); -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::get_extrusion_role_color(ExtrusionRole role) const -{ - return extrusion.role_colors[role]; -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::get_extrusion_height_color(float height) const -{ - return extrusion.ranges.height.get_color_at(height); -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::get_extrusion_width_color(float width) const -{ - return extrusion.ranges.width.get_color_at(width); -} - -const GCodeAnalyzer::PreviewData::Color& GCodeAnalyzer::PreviewData::get_extrusion_feedrate_color(float feedrate) const -{ - return extrusion.ranges.feedrate.get_color_at(feedrate); -} - -void GCodeAnalyzer::PreviewData::set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha) -{ - for (unsigned int i = 0; i < Extrusion::Num_Extrusion_Roles; ++i) - { - if (role_name == extrusion.role_names[i]) - { - extrusion.role_colors[i] = Color(red, green, blue, alpha); - break; - } - } -} - -std::string GCodeAnalyzer::PreviewData::get_legend_title() const -{ - switch (extrusion.view_type) - { - case Extrusion::FeatureType: - return "Feature type"; - case Extrusion::Height: - return "Height (mm)"; - case Extrusion::Width: - return "Width (mm)"; - case Extrusion::Feedrate: - return "Speed (mm/s)"; - case Extrusion::Tool: - return "Tool"; - } - - return ""; -} - -GCodeAnalyzer::PreviewData::LegendItemsList GCodeAnalyzer::PreviewData::get_legend_items(const std::vector& tool_colors) const -{ - struct Helper - { - static void FillListFromRange(LegendItemsList& list, const Range& range, unsigned int decimals, float scale_factor) - { - list.reserve(Range::Colors_Count); - float step = range.step_size(); - for (unsigned int i = 0; i < Range::Colors_Count; ++i) - { - char buf[32]; - sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (range.min + (float)i * step), decimals, scale_factor * (range.min + (float)(i + 1) * step)); - list.emplace_back(buf, range.colors[i]); - } - } - }; - - LegendItemsList items; - - switch (extrusion.view_type) - { - case Extrusion::FeatureType: - { - items.reserve(erMixed - erPerimeter + 1); - for (unsigned int i = (unsigned int)erPerimeter; i < (unsigned int)erMixed; ++i) - { - items.emplace_back(extrusion.role_names[i], extrusion.role_colors[i]); - } - - break; - } - case Extrusion::Height: - { - Helper::FillListFromRange(items, extrusion.ranges.height, 3, 1.0f); - break; - } - case Extrusion::Width: - { - Helper::FillListFromRange(items, extrusion.ranges.width, 3, 1.0f); - break; - } - case Extrusion::Feedrate: - { - Helper::FillListFromRange(items, extrusion.ranges.feedrate, 0, 1.0f); - break; - } - case Extrusion::Tool: - { - unsigned int tools_colors_count = tool_colors.size() / 4; - items.reserve(tools_colors_count); - for (unsigned int i = 0; i < tools_colors_count; ++i) - { - char buf[32]; - sprintf(buf, "Extruder %d", i + 1); - - GCodeAnalyzer::PreviewData::Color color; - ::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + i * 4), 4 * sizeof(float)); - - items.emplace_back(buf, color); - } - - break; - } - } - - return items; -} - GCodeAnalyzer::GCodeAnalyzer() { reset(); @@ -962,9 +605,9 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) { struct Helper { - static PreviewData::Extrusion::Layer& get_layer_at_z(PreviewData::Extrusion::LayersList& layers, float z) + static GCodePreviewData::Extrusion::Layer& get_layer_at_z(GCodePreviewData::Extrusion::LayersList& layers, float z) { - for (PreviewData::Extrusion::Layer& layer : layers) + for (GCodePreviewData::Extrusion::Layer& layer : layers) { // if layer found, return it if (layer.z == z) @@ -999,9 +642,9 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(Print& print) float z = FLT_MAX; Polyline polyline; Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); - PreviewData::Range height_range; - PreviewData::Range width_range; - PreviewData::Range feedrate_range; + GCodePreviewData::Range height_range; + GCodePreviewData::Range width_range; + GCodePreviewData::Range feedrate_range; // constructs the polylines while traversing the moves for (const GCodeMove& move : extrude_moves->second) @@ -1048,7 +691,7 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print) { struct Helper { - static void store_polyline(const Polyline3& polyline, PreviewData::Travel::EType type, PreviewData::Travel::Polyline::EDirection direction, float feedrate, unsigned int extruder_id, Print& print) + static void store_polyline(const Polyline3& polyline, GCodePreviewData::Travel::EType type, GCodePreviewData::Travel::Polyline::EDirection direction, float feedrate, unsigned int extruder_id, Print& print) { // if the polyline is valid, store it if (polyline.is_valid()) @@ -1062,16 +705,16 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(Print& print) Polyline3 polyline; Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); - PreviewData::Travel::EType type = PreviewData::Travel::Num_Types; - PreviewData::Travel::Polyline::EDirection direction = PreviewData::Travel::Polyline::Num_Directions; + GCodePreviewData::Travel::EType type = GCodePreviewData::Travel::Num_Types; + GCodePreviewData::Travel::Polyline::EDirection direction = GCodePreviewData::Travel::Polyline::Num_Directions; float feedrate = FLT_MAX; unsigned int extruder_id = -1; // constructs the polylines while traversing the moves for (const GCodeMove& move : travel_moves->second) { - PreviewData::Travel::EType move_type = (move.delta_extruder < 0.0f) ? PreviewData::Travel::Retract : ((move.delta_extruder > 0.0f) ? PreviewData::Travel::Extrude : PreviewData::Travel::Move); - PreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x != move.end_position.x) || (move.start_position.y != move.end_position.y)) ? PreviewData::Travel::Polyline::Generic : PreviewData::Travel::Polyline::Vertical; + GCodePreviewData::Travel::EType move_type = (move.delta_extruder < 0.0f) ? GCodePreviewData::Travel::Retract : ((move.delta_extruder > 0.0f) ? GCodePreviewData::Travel::Extrude : GCodePreviewData::Travel::Move); + GCodePreviewData::Travel::Polyline::EDirection move_direction = ((move.start_position.x != move.end_position.x) || (move.start_position.y != move.end_position.y)) ? GCodePreviewData::Travel::Polyline::Generic : GCodePreviewData::Travel::Polyline::Vertical; if ((type != move_type) || (direction != move_direction) || (feedrate != move.data.feedrate) || (position != move.start_position) || (extruder_id != move.data.extruder_id)) { @@ -1130,17 +773,17 @@ void GCodeAnalyzer::_calc_gcode_preview_unretractions(Print& print) } } -GCodeAnalyzer::PreviewData::Color operator + (const GCodeAnalyzer::PreviewData::Color& c1, const GCodeAnalyzer::PreviewData::Color& c2) +GCodePreviewData::Color operator + (const GCodePreviewData::Color& c1, const GCodePreviewData::Color& c2) { - return GCodeAnalyzer::PreviewData::Color(clamp(0.0f, 1.0f, c1.rgba[0] + c2.rgba[0]), + return GCodePreviewData::Color(clamp(0.0f, 1.0f, c1.rgba[0] + c2.rgba[0]), clamp(0.0f, 1.0f, c1.rgba[1] + c2.rgba[1]), clamp(0.0f, 1.0f, c1.rgba[2] + c2.rgba[2]), clamp(0.0f, 1.0f, c1.rgba[3] + c2.rgba[3])); } -GCodeAnalyzer::PreviewData::Color operator * (float f, const GCodeAnalyzer::PreviewData::Color& color) +GCodePreviewData::Color operator * (float f, const GCodePreviewData::Color& color) { - return GCodeAnalyzer::PreviewData::Color(clamp(0.0f, 1.0f, f * color.rgba[0]), + return GCodePreviewData::Color(clamp(0.0f, 1.0f, f * color.rgba[0]), clamp(0.0f, 1.0f, f * color.rgba[1]), clamp(0.0f, 1.0f, f * color.rgba[2]), clamp(0.0f, 1.0f, f * color.rgba[3])); diff --git a/xs/src/libslic3r/GCode/Analyzer.hpp b/xs/src/libslic3r/GCode/Analyzer.hpp index 121360dbc..bfb2d668c 100644 --- a/xs/src/libslic3r/GCode/Analyzer.hpp +++ b/xs/src/libslic3r/GCode/Analyzer.hpp @@ -98,193 +98,6 @@ private: float position[Num_Axis]; }; -public: - struct PreviewData - { - struct Color - { - float rgba[4]; - - Color(); - Color(float r, float g, float b, float a); - - std::vector as_bytes() const; - - static const Color Dummy; - }; - - struct Range - { - static const unsigned int Colors_Count = 10; - static const Color Default_Colors[Colors_Count]; - - Color colors[Colors_Count]; - float min; - float max; - - Range(); - - void reset(); - bool empty() const; - void update_from(float value); - void set_from(const Range& other); - float step_size() const; - - const Color& get_color_at(float value) const; - const Color& get_color_at_max() const; - }; - - struct LegendItem - { - std::string text; - Color color; - - LegendItem(const std::string& text, const Color& color); - }; - - typedef std::vector LegendItemsList; - - struct Extrusion - { - enum EViewType : unsigned char - { - FeatureType, - Height, - Width, - Feedrate, - Tool, - Num_View_Types - }; - - static const unsigned int Num_Extrusion_Roles = (unsigned int)erMixed + 1; - static const Color Default_Extrusion_Role_Colors[Num_Extrusion_Roles]; - static const std::string Default_Extrusion_Role_Names[Num_Extrusion_Roles]; - static const EViewType Default_View_Type; - - struct Ranges - { - Range height; - Range width; - Range feedrate; - }; - - struct Layer - { - float z; - ExtrusionPaths paths; - - Layer(float z, const ExtrusionPaths& paths); - }; - - typedef std::vector LayersList; - - EViewType view_type; - Color role_colors[Num_Extrusion_Roles]; - std::string role_names[Num_Extrusion_Roles]; - Ranges ranges; - LayersList layers; - unsigned int role_flags; - - void set_default(); - bool is_role_flag_set(ExtrusionRole role) const; - - static bool is_role_flag_set(unsigned int flags, ExtrusionRole role); - }; - - struct Travel - { - enum EType : unsigned char - { - Move, - Extrude, - Retract, - Num_Types - }; - - static const float Default_Width; - static const float Default_Height; - static const Color Default_Type_Colors[Num_Types]; - - struct Polyline - { - enum EDirection - { - Vertical, - Generic, - Num_Directions - }; - - EType type; - EDirection direction; - float feedrate; - unsigned int extruder_id; - Polyline3 polyline; - - Polyline(EType type, EDirection direction, float feedrate, unsigned int extruder_id, const Polyline3& polyline); - }; - - typedef std::vector PolylinesList; - - PolylinesList polylines; - float width; - float height; - Color type_colors[Num_Types]; - bool is_visible; - - void set_default(); - }; - - struct Retraction - { - static const Color Default_Color; - - struct Position - { - Point3 position; - float width; - float height; - - Position(const Point3& position, float width, float height); - }; - - typedef std::vector PositionsList; - - PositionsList positions; - Color color; - bool is_visible; - - void set_default(); - }; - - struct Shell - { - bool is_visible; - - void set_default(); - }; - - Extrusion extrusion; - Travel travel; - Retraction retraction; - Retraction unretraction; - Shell shell; - - PreviewData(); - - void set_default(); - void reset(); - - const Color& get_extrusion_role_color(ExtrusionRole role) const; - const Color& get_extrusion_height_color(float height) const; - const Color& get_extrusion_width_color(float width) const; - const Color& get_extrusion_feedrate_color(float feedrate) const; - - void set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha); - - std::string get_legend_title() const; - LegendItemsList get_legend_items(const std::vector& tool_colors) const; - }; - private: State m_state; GCodeReader m_parser; @@ -409,9 +222,6 @@ private: void _calc_gcode_preview_unretractions(Print& print); }; -GCodeAnalyzer::PreviewData::Color operator + (const GCodeAnalyzer::PreviewData::Color& c1, const GCodeAnalyzer::PreviewData::Color& c2); -GCodeAnalyzer::PreviewData::Color operator * (float f, const GCodeAnalyzer::PreviewData::Color& color); - } // namespace Slic3r #endif /* slic3r_GCode_Analyzer_hpp_ */ diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index fd0964e57..5fb81124c 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -73,8 +73,8 @@ void Print::clear_gcode_preview_data() void Print::set_gcode_preview_type(unsigned char type) { - if ((0 <= type) && (type < GCodeAnalyzer::PreviewData::Extrusion::Num_View_Types)) - gcode_preview.extrusion.view_type = (GCodeAnalyzer::PreviewData::Extrusion::EViewType)type; + if ((0 <= type) && (type < GCodePreviewData::Extrusion::Num_View_Types)) + gcode_preview.extrusion.view_type = (GCodePreviewData::Extrusion::EViewType)type; } void Print::set_gcode_preview_extrusion_flags(unsigned int flags) diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index da94917fc..f08b4ec15 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -15,7 +15,7 @@ #include "Slicing.hpp" #include "GCode/ToolOrdering.hpp" #include "GCode/WipeTower.hpp" -#include "GCode/Analyzer.hpp" +#include "GCode/PreviewData.hpp" #include "tbb/atomic.h" @@ -241,7 +241,7 @@ public: // ordered collections of extrusion paths to build skirt loops and brim ExtrusionEntityCollection skirt, brim; - GCodeAnalyzer::PreviewData gcode_preview; + GCodePreviewData gcode_preview; Print() : total_used_filament(0), total_extruded_volume(0) { restart(); } ~Print() { clear_objects(); } @@ -272,7 +272,7 @@ public: // , , // ... // , }; - // where should be a string from GCodeAnalyzer::PreviewData::Extrusion::Default_Extrusion_Role_Names[] + // where should be a string from GCodePreviewData::Extrusion::Default_Extrusion_Role_Names[] // and an RGB color in hex format (i.e. red = FF0000) void set_gcode_extrusion_paths_colors(const std::vector& colors); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 553239a6f..b5fc9245e 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1109,19 +1109,7 @@ static void point3_to_verts(const Point3& point, double width, double height, GL thick_point_to_verts(point, width, height, volume); } -_3DScene::GCodePreviewData::FirstVolume::FirstVolume(_3DScene::GCodePreviewData::EType type, unsigned int flag, unsigned int id) - : type(type) - , flag(flag) - , id(id) -{ -} - -void _3DScene::GCodePreviewData::reset() -{ - first_volumes.clear(); -} - -_3DScene::GCodePreviewData _3DScene::s_gcode_preview_data; +_3DScene::GCodePreviewVolumeIndex _3DScene::s_gcode_preview_volume_index; _3DScene::LegendTexture _3DScene::s_legend_texture; const unsigned char _3DScene::LegendTexture::Squares_Border_Color[3] = { 64, 64, 64 }; @@ -1146,7 +1134,7 @@ bool _3DScene::LegendTexture::generate_texture(const Print& print, const std::ve // collects items to render const std::string& title = print.gcode_preview.get_legend_title(); - const GCodeAnalyzer::PreviewData::LegendItemsList& items = print.gcode_preview.get_legend_items(tool_colors); + const GCodePreviewData::LegendItemsList& items = print.gcode_preview.get_legend_items(tool_colors); unsigned int items_count = (unsigned int)items.size(); if (items_count == 0) @@ -1165,7 +1153,7 @@ bool _3DScene::LegendTexture::generate_texture(const Print& print, const std::ve unsigned int max_text_width = 0; unsigned int max_text_height = 0; - for (const GCodeAnalyzer::PreviewData::LegendItem& item : items) + for (const GCodePreviewData::LegendItem& item : items) { memDC.GetTextExtent(item.text, &w, &h); max_text_width = std::max(max_text_width, (unsigned int)w); @@ -1221,7 +1209,7 @@ bool _3DScene::LegendTexture::generate_texture(const Print& print, const std::ve unsigned int px_inner_square = Px_Square - 2; - for (const GCodeAnalyzer::PreviewData::LegendItem& item : items) + for (const GCodePreviewData::LegendItem& item : items) { // draw darker icon perimeter const std::vector& item_color_bytes = item.color.as_bytes(); @@ -1362,7 +1350,7 @@ void _3DScene::load_gcode_preview(const Print* print, GLVolumeCollection* volume { std::vector tool_colors = parse_colors(str_tool_colors); - s_gcode_preview_data.reset(); + s_gcode_preview_volume_index.reset(); _load_gcode_extrusion_paths(*print, *volumes, tool_colors, use_VBOs); _load_gcode_travel_paths(*print, *volumes, tool_colors, use_VBOs); @@ -1768,46 +1756,46 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio // helper functions to select data in dependence of the extrusion view type struct Helper { - static float path_filter(GCodeAnalyzer::PreviewData::Extrusion::EViewType type, const ExtrusionPath& path) + static float path_filter(GCodePreviewData::Extrusion::EViewType type, const ExtrusionPath& path) { switch (type) { - case GCodeAnalyzer::PreviewData::Extrusion::FeatureType: + case GCodePreviewData::Extrusion::FeatureType: return (float)path.role(); - case GCodeAnalyzer::PreviewData::Extrusion::Height: + case GCodePreviewData::Extrusion::Height: return path.height; - case GCodeAnalyzer::PreviewData::Extrusion::Width: + case GCodePreviewData::Extrusion::Width: return path.width; - case GCodeAnalyzer::PreviewData::Extrusion::Feedrate: + case GCodePreviewData::Extrusion::Feedrate: return path.feedrate; - case GCodeAnalyzer::PreviewData::Extrusion::Tool: + case GCodePreviewData::Extrusion::Tool: return (float)path.extruder_id; } return 0.0f; } - static const GCodeAnalyzer::PreviewData::Color& path_color(const GCodeAnalyzer::PreviewData& data, const std::vector& tool_colors, float value) + static const GCodePreviewData::Color& path_color(const GCodePreviewData& data, const std::vector& tool_colors, float value) { switch (data.extrusion.view_type) { - case GCodeAnalyzer::PreviewData::Extrusion::FeatureType: + case GCodePreviewData::Extrusion::FeatureType: return data.get_extrusion_role_color((ExtrusionRole)(int)value); - case GCodeAnalyzer::PreviewData::Extrusion::Height: + case GCodePreviewData::Extrusion::Height: return data.get_extrusion_height_color(value); - case GCodeAnalyzer::PreviewData::Extrusion::Width: + case GCodePreviewData::Extrusion::Width: return data.get_extrusion_width_color(value); - case GCodeAnalyzer::PreviewData::Extrusion::Feedrate: + case GCodePreviewData::Extrusion::Feedrate: return data.get_extrusion_feedrate_color(value); - case GCodeAnalyzer::PreviewData::Extrusion::Tool: + case GCodePreviewData::Extrusion::Tool: { - static GCodeAnalyzer::PreviewData::Color color; + static GCodePreviewData::Color color; ::memcpy((void*)color.rgba, (const void*)(tool_colors.data() + (unsigned int)value * 4), 4 * sizeof(float)); return color; } } - return GCodeAnalyzer::PreviewData::Color::Dummy; + return GCodePreviewData::Color::Dummy; } }; @@ -1843,7 +1831,7 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio // detects filters FiltersList filters; - for (const GCodeAnalyzer::PreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) + for (const GCodePreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) { for (const ExtrusionPath& path : layer.paths) { @@ -1861,7 +1849,7 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio // creates a new volume for each filter for (Filter& filter : filters) { - s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Extrusion, (unsigned int)filter.role, (unsigned int)volumes.volumes.size()); + s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Extrusion, (unsigned int)filter.role, (unsigned int)volumes.volumes.size()); GLVolume* volume = new GLVolume(Helper::path_color(print.gcode_preview, tool_colors, filter.value).rgba); if (volume != nullptr) @@ -1872,7 +1860,7 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio else { // an error occourred - restore to previous state and return - s_gcode_preview_data.first_volumes.pop_back(); + s_gcode_preview_volume_index.first_volumes.pop_back(); if (initial_volumes_count != volumes.volumes.size()) { std::vector::iterator begin = volumes.volumes.begin() + initial_volumes_count; @@ -1889,7 +1877,7 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio } // populates volumes - for (const GCodeAnalyzer::PreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) + for (const GCodePreviewData::Extrusion::Layer& layer : print.gcode_preview.extrusion.layers) { for (const ExtrusionPath& path : layer.paths) { @@ -1921,17 +1909,17 @@ void _3DScene::_load_gcode_extrusion_paths(const Print& print, GLVolumeCollectio void _3DScene::_load_gcode_travel_paths(const Print& print, GLVolumeCollection& volumes, const std::vector& tool_colors, bool use_VBOs) { size_t initial_volumes_count = volumes.volumes.size(); - s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Travel, 0, (unsigned int)initial_volumes_count); + s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Travel, 0, (unsigned int)initial_volumes_count); bool res = true; switch (print.gcode_preview.extrusion.view_type) { - case GCodeAnalyzer::PreviewData::Extrusion::Feedrate: + case GCodePreviewData::Extrusion::Feedrate: { res = _travel_paths_by_feedrate(print, volumes); break; } - case GCodeAnalyzer::PreviewData::Extrusion::Tool: + case GCodePreviewData::Extrusion::Tool: { res = _travel_paths_by_tool(print, volumes, tool_colors); break; @@ -1978,10 +1966,10 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol // Helper structure for types struct Type { - GCodeAnalyzer::PreviewData::Travel::EType value; + GCodePreviewData::Travel::EType value; GLVolume* volume; - explicit Type(GCodeAnalyzer::PreviewData::Travel::EType value) + explicit Type(GCodePreviewData::Travel::EType value) : value(value) , volume(nullptr) { @@ -1999,7 +1987,7 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol // detects types TypesList types; - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { if (std::find(types.begin(), types.end(), Type(polyline.type)) == types.end()) types.emplace_back(polyline.type); @@ -2023,7 +2011,7 @@ bool _3DScene::_travel_paths_by_type(const Print& print, GLVolumeCollection& vol } // populates volumes - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { TypesList::iterator type = std::find(types.begin(), types.end(), Type(polyline.type)); if (type != types.end()) @@ -2065,7 +2053,7 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& // detects feedrates FeedratesList feedrates; - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { if (std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)) == feedrates.end()) feedrates.emplace_back(polyline.feedrate); @@ -2089,7 +2077,7 @@ bool _3DScene::_travel_paths_by_feedrate(const Print& print, GLVolumeCollection& } // populates volumes - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { FeedratesList::iterator feedrate = std::find(feedrates.begin(), feedrates.end(), Feedrate(polyline.feedrate)); if (feedrate != feedrates.end()) @@ -2131,7 +2119,7 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol // detects tools ToolsList tools; - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { if (std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)) == tools.end()) tools.emplace_back(polyline.extruder_id); @@ -2155,7 +2143,7 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol } // populates volumes - for (const GCodeAnalyzer::PreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) + for (const GCodePreviewData::Travel::Polyline& polyline : print.gcode_preview.travel.polylines) { ToolsList::iterator tool = std::find(tools.begin(), tools.end(), Tool(polyline.extruder_id)); if (tool != tools.end()) @@ -2173,7 +2161,7 @@ bool _3DScene::_travel_paths_by_tool(const Print& print, GLVolumeCollection& vol void _3DScene::_load_gcode_retractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) { - s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Retraction, 0, (unsigned int)volumes.volumes.size()); + s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Retraction, 0, (unsigned int)volumes.volumes.size()); // nothing to render, return if (print.gcode_preview.retraction.positions.empty()) @@ -2184,7 +2172,7 @@ void _3DScene::_load_gcode_retractions(const Print& print, GLVolumeCollection& v { volumes.volumes.emplace_back(volume); - for (const GCodeAnalyzer::PreviewData::Retraction::Position& position : print.gcode_preview.retraction.positions) + for (const GCodePreviewData::Retraction::Position& position : print.gcode_preview.retraction.positions) { volume->print_zs.push_back(unscale(position.position.z)); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); @@ -2201,7 +2189,7 @@ void _3DScene::_load_gcode_retractions(const Print& print, GLVolumeCollection& v void _3DScene::_load_gcode_unretractions(const Print& print, GLVolumeCollection& volumes, bool use_VBOs) { - s_gcode_preview_data.first_volumes.emplace_back(GCodePreviewData::Unretraction, 0, (unsigned int)volumes.volumes.size()); + s_gcode_preview_volume_index.first_volumes.emplace_back(GCodePreviewVolumeIndex::Unretraction, 0, (unsigned int)volumes.volumes.size()); // nothing to render, return if (print.gcode_preview.unretraction.positions.empty()) @@ -2212,7 +2200,7 @@ void _3DScene::_load_gcode_unretractions(const Print& print, GLVolumeCollection& { volumes.volumes.emplace_back(volume); - for (const GCodeAnalyzer::PreviewData::Retraction::Position& position : print.gcode_preview.unretraction.positions) + for (const GCodePreviewData::Retraction::Position& position : print.gcode_preview.unretraction.positions) { volume->print_zs.push_back(unscale(position.position.z)); volume->offsets.push_back(volume->indexed_vertex_array.quad_indices.size()); @@ -2229,39 +2217,39 @@ void _3DScene::_load_gcode_unretractions(const Print& print, GLVolumeCollection& void _3DScene::_update_gcode_volumes_visibility(const Print& print, GLVolumeCollection& volumes) { - unsigned int size = (unsigned int)s_gcode_preview_data.first_volumes.size(); + unsigned int size = (unsigned int)s_gcode_preview_volume_index.first_volumes.size(); for (unsigned int i = 0; i < size; ++i) { - std::vector::iterator begin = volumes.volumes.begin() + s_gcode_preview_data.first_volumes[i].id; - std::vector::iterator end = (i + 1 < size) ? volumes.volumes.begin() + s_gcode_preview_data.first_volumes[i + 1].id : volumes.volumes.end(); + std::vector::iterator begin = volumes.volumes.begin() + s_gcode_preview_volume_index.first_volumes[i].id; + std::vector::iterator end = (i + 1 < size) ? volumes.volumes.begin() + s_gcode_preview_volume_index.first_volumes[i + 1].id : volumes.volumes.end(); for (std::vector::iterator it = begin; it != end; ++it) { GLVolume* volume = *it; - switch (s_gcode_preview_data.first_volumes[i].type) + switch (s_gcode_preview_volume_index.first_volumes[i].type) { - case GCodePreviewData::Extrusion: + case GCodePreviewVolumeIndex::Extrusion: { - volume->is_active = print.gcode_preview.extrusion.is_role_flag_set((ExtrusionRole)s_gcode_preview_data.first_volumes[i].flag); + volume->is_active = print.gcode_preview.extrusion.is_role_flag_set((ExtrusionRole)s_gcode_preview_volume_index.first_volumes[i].flag); break; } - case GCodePreviewData::Travel: + case GCodePreviewVolumeIndex::Travel: { volume->is_active = print.gcode_preview.travel.is_visible; break; } - case GCodePreviewData::Retraction: + case GCodePreviewVolumeIndex::Retraction: { volume->is_active = print.gcode_preview.retraction.is_visible; break; } - case GCodePreviewData::Unretraction: + case GCodePreviewVolumeIndex::Unretraction: { volume->is_active = print.gcode_preview.unretraction.is_visible; break; } - case GCodePreviewData::Shell: + case GCodePreviewVolumeIndex::Shell: { volume->is_active = print.gcode_preview.shell.is_visible; break; @@ -2284,7 +2272,7 @@ void _3DScene::_generate_legend_texture(const Print& print, const std::vector first_volumes; - void reset(); + void reset() { first_volumes.clear(); } }; - static GCodePreviewData s_gcode_preview_data; + static GCodePreviewVolumeIndex s_gcode_preview_volume_index; class LegendTexture {