From d91f59379b3468f3cced6cd9fccf63e06dacaf67 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 6 Mar 2018 12:12:00 +0100 Subject: [PATCH 1/6] GCode Preview - Fixed values in range labels of legend texture --- xs/src/libslic3r/GCode/Analyzer.cpp | 12 +++++++ xs/src/libslic3r/GCode/PreviewData.cpp | 47 +++++++++++++++++++++----- xs/src/libslic3r/GCode/PreviewData.hpp | 16 +++++---- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 6530806c4..d4041ac19 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -717,6 +717,10 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) float feedrate = FLT_MAX; unsigned int extruder_id = -1; + GCodePreviewData::Range height_range; + GCodePreviewData::Range width_range; + GCodePreviewData::Range feedrate_range; + // constructs the polylines while traversing the moves for (const GCodeMove& move : travel_moves->second) { @@ -745,11 +749,19 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) type = move_type; feedrate = move.data.feedrate; extruder_id = move.data.extruder_id; + height_range.update_from(move.data.height); + width_range.update_from(move.data.width); + feedrate_range.update_from(move.data.feedrate); } // store last polyline polyline.remove_duplicate_points(); Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data); + + // updates preview ranges data + preview_data.travel.ranges.height.set_from(height_range); + preview_data.travel.ranges.width.set_from(width_range); + preview_data.travel.ranges.feedrate.set_from(feedrate_range); } void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data) diff --git a/xs/src/libslic3r/GCode/PreviewData.cpp b/xs/src/libslic3r/GCode/PreviewData.cpp index 1923505e4..73ec30eef 100644 --- a/xs/src/libslic3r/GCode/PreviewData.cpp +++ b/xs/src/libslic3r/GCode/PreviewData.cpp @@ -85,6 +85,12 @@ void GCodePreviewData::Range::update_from(float value) max = std::max(max, value); } +void GCodePreviewData::Range::update_from(const Range& other) +{ + min = std::min(min, other.min); + max = std::max(max, other.max); +} + void GCodePreviewData::Range::set_from(const Range& other) { min = other.min; @@ -198,6 +204,11 @@ void GCodePreviewData::Travel::set_default() width = Default_Width; height = Default_Height; ::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * 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)); + is_visible = false; } @@ -345,15 +356,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: { struct Helper { - static void FillListFromRange(LegendItemsList& list, const Range& range, unsigned int decimals, float scale_factor) + static void FillListFromRange(LegendItemsList& list, const std::vector& ranges, unsigned int decimals, float scale_factor) { + if (ranges.empty()) + return; + list.reserve(Range::Colors_Count); - float step = range.step_size(); + + Range total_range; + for (const Range* range : ranges) + { + if (range != nullptr) + total_range.update_from(*range); + } + + float step = total_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]); + char buf[1024]; + sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (total_range.min + (float)i * step), decimals, scale_factor * (total_range.min + (float)(i + 1) * step)); + list.emplace_back(buf, ranges[0]->colors[i]); } } }; @@ -377,17 +399,26 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: } case Extrusion::Height: { - Helper::FillListFromRange(items, extrusion.ranges.height, 3, 1.0f); + std::vector ranges; + ranges.push_back(&extrusion.ranges.height); + ranges.push_back(&travel.ranges.height); + Helper::FillListFromRange(items, ranges, 3, 1.0f); break; } case Extrusion::Width: { - Helper::FillListFromRange(items, extrusion.ranges.width, 3, 1.0f); + std::vector ranges; + ranges.push_back(&extrusion.ranges.width); + ranges.push_back(&travel.ranges.width); + Helper::FillListFromRange(items, ranges, 3, 1.0f); break; } case Extrusion::Feedrate: { - Helper::FillListFromRange(items, extrusion.ranges.feedrate, 0, 1.0f); + std::vector ranges; + ranges.push_back(&extrusion.ranges.feedrate); + ranges.push_back(&travel.ranges.feedrate); + Helper::FillListFromRange(items, ranges, 0, 1.0f); break; } case Extrusion::Tool: diff --git a/xs/src/libslic3r/GCode/PreviewData.hpp b/xs/src/libslic3r/GCode/PreviewData.hpp index 9fb2dc464..9579bf900 100644 --- a/xs/src/libslic3r/GCode/PreviewData.hpp +++ b/xs/src/libslic3r/GCode/PreviewData.hpp @@ -37,6 +37,7 @@ public: void reset(); bool empty() const; void update_from(float value); + void update_from(const Range& other); void set_from(const Range& other); float step_size() const; @@ -44,6 +45,13 @@ public: const Color& get_color_at_max() const; }; + struct Ranges + { + Range height; + Range width; + Range feedrate; + }; + struct LegendItem { std::string text; @@ -71,13 +79,6 @@ public: 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; @@ -140,6 +141,7 @@ public: float height; Color type_colors[Num_Types]; bool is_visible; + Ranges ranges; void set_default(); }; From fe59958ea84539c2252bc1a009247f997f4686b6 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 7 Mar 2018 09:17:59 +0100 Subject: [PATCH 2/6] GCode Preview - Unified preview data ranges to ensure proper paths colors --- xs/src/libslic3r/GCode/Analyzer.cpp | 12 +++--- xs/src/libslic3r/GCode/PreviewData.cpp | 59 +++++++++----------------- xs/src/libslic3r/GCode/PreviewData.hpp | 9 ++-- xs/src/slic3r/GUI/3DScene.cpp | 8 ++-- 4 files changed, 34 insertions(+), 54 deletions(-) diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index d4041ac19..ee1e55beb 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -688,9 +688,9 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ Helper::store_polyline(polyline, data, z, preview_data); // updates preview ranges data - preview_data.extrusion.ranges.height.set_from(height_range); - preview_data.extrusion.ranges.width.set_from(width_range); - preview_data.extrusion.ranges.feedrate.set_from(feedrate_range); + preview_data.ranges.height.set_from(height_range); + preview_data.ranges.width.set_from(width_range); + preview_data.ranges.feedrate.set_from(feedrate_range); } void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) @@ -759,9 +759,9 @@ void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) Helper::store_polyline(polyline, type, direction, feedrate, extruder_id, preview_data); // updates preview ranges data - preview_data.travel.ranges.height.set_from(height_range); - preview_data.travel.ranges.width.set_from(width_range); - preview_data.travel.ranges.feedrate.set_from(feedrate_range); + preview_data.ranges.height.set_from(height_range); + preview_data.ranges.width.set_from(width_range); + preview_data.ranges.feedrate.set_from(feedrate_range); } void GCodeAnalyzer::_calc_gcode_preview_retractions(GCodePreviewData& preview_data) diff --git a/xs/src/libslic3r/GCode/PreviewData.cpp b/xs/src/libslic3r/GCode/PreviewData.cpp index 73ec30eef..b9be6643b 100644 --- a/xs/src/libslic3r/GCode/PreviewData.cpp +++ b/xs/src/libslic3r/GCode/PreviewData.cpp @@ -164,9 +164,6 @@ void GCodePreviewData::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) { @@ -205,10 +202,6 @@ void GCodePreviewData::Travel::set_default() height = Default_Height; ::memcpy((void*)type_colors, (const void*)Default_Type_Colors, Num_Types * 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)); - is_visible = false; } @@ -239,6 +232,10 @@ GCodePreviewData::GCodePreviewData() void GCodePreviewData::set_default() { + ::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)); + extrusion.set_default(); travel.set_default(); retraction.set_default(); @@ -248,6 +245,9 @@ void GCodePreviewData::set_default() void GCodePreviewData::reset() { + ranges.width.reset(); + ranges.height.reset(); + ranges.feedrate.reset(); extrusion.layers.clear(); travel.polylines.clear(); retraction.positions.clear(); @@ -264,19 +264,19 @@ const GCodePreviewData::Color& GCodePreviewData::get_extrusion_role_color(Extrus return extrusion.role_colors[role]; } -const GCodePreviewData::Color& GCodePreviewData::get_extrusion_height_color(float height) const +const GCodePreviewData::Color& GCodePreviewData::get_height_color(float height) const { - return extrusion.ranges.height.get_color_at(height); + return ranges.height.get_color_at(height); } -const GCodePreviewData::Color& GCodePreviewData::get_extrusion_width_color(float width) const +const GCodePreviewData::Color& GCodePreviewData::get_width_color(float width) const { - return extrusion.ranges.width.get_color_at(width); + return ranges.width.get_color_at(width); } -const GCodePreviewData::Color& GCodePreviewData::get_extrusion_feedrate_color(float feedrate) const +const GCodePreviewData::Color& GCodePreviewData::get_feedrate_color(float feedrate) const { - return extrusion.ranges.feedrate.get_color_at(feedrate); + return ranges.feedrate.get_color_at(feedrate); } void GCodePreviewData::set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha) @@ -356,26 +356,16 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: { struct Helper { - static void FillListFromRange(LegendItemsList& list, const std::vector& ranges, unsigned int decimals, float scale_factor) + static void FillListFromRange(LegendItemsList& list, const Range& range, unsigned int decimals, float scale_factor) { - if (ranges.empty()) - return; - list.reserve(Range::Colors_Count); - Range total_range; - for (const Range* range : ranges) - { - if (range != nullptr) - total_range.update_from(*range); - } - - float step = total_range.step_size(); + float step = range.step_size(); for (unsigned int i = 0; i < Range::Colors_Count; ++i) { char buf[1024]; - sprintf(buf, "%.*f/%.*f", decimals, scale_factor * (total_range.min + (float)i * step), decimals, scale_factor * (total_range.min + (float)(i + 1) * step)); - list.emplace_back(buf, ranges[0]->colors[i]); + 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]); } } }; @@ -399,26 +389,17 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: } case Extrusion::Height: { - std::vector ranges; - ranges.push_back(&extrusion.ranges.height); - ranges.push_back(&travel.ranges.height); - Helper::FillListFromRange(items, ranges, 3, 1.0f); + Helper::FillListFromRange(items, ranges.height, 3, 1.0f); break; } case Extrusion::Width: { - std::vector ranges; - ranges.push_back(&extrusion.ranges.width); - ranges.push_back(&travel.ranges.width); - Helper::FillListFromRange(items, ranges, 3, 1.0f); + Helper::FillListFromRange(items, ranges.width, 3, 1.0f); break; } case Extrusion::Feedrate: { - std::vector ranges; - ranges.push_back(&extrusion.ranges.feedrate); - ranges.push_back(&travel.ranges.feedrate); - Helper::FillListFromRange(items, ranges, 0, 1.0f); + Helper::FillListFromRange(items, ranges.feedrate, 0, 1.0f); break; } case Extrusion::Tool: diff --git a/xs/src/libslic3r/GCode/PreviewData.hpp b/xs/src/libslic3r/GCode/PreviewData.hpp index 9579bf900..6375af5f0 100644 --- a/xs/src/libslic3r/GCode/PreviewData.hpp +++ b/xs/src/libslic3r/GCode/PreviewData.hpp @@ -92,7 +92,6 @@ public: EViewType view_type; Color role_colors[Num_Extrusion_Roles]; std::string role_names[Num_Extrusion_Roles]; - Ranges ranges; LayersList layers; unsigned int role_flags; @@ -141,7 +140,6 @@ public: float height; Color type_colors[Num_Types]; bool is_visible; - Ranges ranges; void set_default(); }; @@ -180,6 +178,7 @@ public: Retraction retraction; Retraction unretraction; Shell shell; + Ranges ranges; GCodePreviewData(); @@ -188,9 +187,9 @@ public: bool empty() const; 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; + const Color& get_height_color(float height) const; + const Color& get_width_color(float width) const; + const Color& get_feedrate_color(float feedrate) const; void set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha); void set_extrusion_paths_colors(const std::vector& colors); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 04e7f7dc6..8a1b19c51 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1777,11 +1777,11 @@ void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, case GCodePreviewData::Extrusion::FeatureType: return data.get_extrusion_role_color((ExtrusionRole)(int)value); case GCodePreviewData::Extrusion::Height: - return data.get_extrusion_height_color(value); + return data.get_height_color(value); case GCodePreviewData::Extrusion::Width: - return data.get_extrusion_width_color(value); + return data.get_width_color(value); case GCodePreviewData::Extrusion::Feedrate: - return data.get_extrusion_feedrate_color(value); + return data.get_feedrate_color(value); case GCodePreviewData::Extrusion::Tool: { static GCodePreviewData::Color color; @@ -2061,7 +2061,7 @@ bool _3DScene::_travel_paths_by_feedrate(const GCodePreviewData& preview_data, G // creates a new volume for each feedrate for (Feedrate& feedrate : feedrates) { - GLVolume* volume = new GLVolume(preview_data.get_extrusion_feedrate_color(feedrate.value).rgba); + GLVolume* volume = new GLVolume(preview_data.get_feedrate_color(feedrate.value).rgba); if (volume == nullptr) return false; else From d68804772aaa20e7b4e37c3a880896ed3782d238 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 9 Mar 2018 15:27:38 +0100 Subject: [PATCH 3/6] GCode Preview - Added handling of G10 and G11 commands --- xs/src/libslic3r/GCode/Analyzer.cpp | 22 ++++++++++++++++++++++ xs/src/libslic3r/GCode/Analyzer.hpp | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index ee1e55beb..15b99b2fb 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -177,6 +177,16 @@ void GCodeAnalyzer::_process_gcode_line(GCodeReader&, const GCodeReader::GCodeLi _processG1(line); break; } + case 10: // Retract + { + _processG10(line); + break; + } + case 11: // Unretract + { + _processG11(line); + break; + } case 22: // Firmware controlled Retract { _processG22(line); @@ -305,6 +315,18 @@ void GCodeAnalyzer::_processG1(const GCodeReader::GCodeLine& line) _store_move(type); } +void GCodeAnalyzer::_processG10(const GCodeReader::GCodeLine& line) +{ + // stores retract move + _store_move(GCodeMove::Retract); +} + +void GCodeAnalyzer::_processG11(const GCodeReader::GCodeLine& line) +{ + // stores unretract move + _store_move(GCodeMove::Unretract); +} + void GCodeAnalyzer::_processG22(const GCodeReader::GCodeLine& line) { // stores retract move diff --git a/xs/src/libslic3r/GCode/Analyzer.hpp b/xs/src/libslic3r/GCode/Analyzer.hpp index 7939d432d..e2f38292e 100644 --- a/xs/src/libslic3r/GCode/Analyzer.hpp +++ b/xs/src/libslic3r/GCode/Analyzer.hpp @@ -127,6 +127,12 @@ private: // Move void _processG1(const GCodeReader::GCodeLine& line); + // Retract + void _processG10(const GCodeReader::GCodeLine& line); + + // Unretract + void _processG11(const GCodeReader::GCodeLine& line); + // Firmware controlled Retract void _processG22(const GCodeReader::GCodeLine& line); From 4a179c81d29eaad4dc3b4a107a31809b68615076 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Wed, 21 Mar 2018 10:03:10 +0100 Subject: [PATCH 4/6] GCode Preview - Added visualization of volumetric flow rate --- lib/Slic3r/GUI/Plater/3DPreview.pm | 1 + xs/src/libslic3r/GCode/Analyzer.cpp | 7 ++++++- xs/src/libslic3r/GCode/PreviewData.cpp | 14 ++++++++++++++ xs/src/libslic3r/GCode/PreviewData.hpp | 3 +++ xs/src/slic3r/GUI/3DScene.cpp | 4 ++++ 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index 8f3fa49f5..537cb0c8f 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -69,6 +69,7 @@ sub new { $choice_view_type->Append(L("Height")); $choice_view_type->Append(L("Width")); $choice_view_type->Append(L("Speed")); + $choice_view_type->Append(L("Volumetric flow rate")); $choice_view_type->Append(L("Tool")); $choice_view_type->SetSelection(0); diff --git a/xs/src/libslic3r/GCode/Analyzer.cpp b/xs/src/libslic3r/GCode/Analyzer.cpp index 15b99b2fb..e20f6589f 100644 --- a/xs/src/libslic3r/GCode/Analyzer.cpp +++ b/xs/src/libslic3r/GCode/Analyzer.cpp @@ -670,14 +670,16 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ float z = FLT_MAX; Polyline polyline; Pointf3 position(FLT_MAX, FLT_MAX, FLT_MAX); + float volumetric_rate = FLT_MAX; GCodePreviewData::Range height_range; GCodePreviewData::Range width_range; GCodePreviewData::Range feedrate_range; + GCodePreviewData::Range volumetric_rate_range; // constructs the polylines while traversing the moves for (const GCodeMove& move : extrude_moves->second) { - if ((data != move.data) || (data.feedrate != move.data.feedrate) || (z != move.start_position.z) || (position != move.start_position)) + if ((data != move.data) || (z != move.start_position.z) || (position != move.start_position) || (volumetric_rate != move.data.feedrate * (float)move.data.mm3_per_mm)) { // store current polyline polyline.remove_duplicate_points(); @@ -693,9 +695,11 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ // update current values data = move.data; z = move.start_position.z; + volumetric_rate = move.data.feedrate * (float)move.data.mm3_per_mm; height_range.update_from(move.data.height); width_range.update_from(move.data.width); feedrate_range.update_from(move.data.feedrate); + volumetric_rate_range.update_from(volumetric_rate); } else // append end vertex of the move to current polyline @@ -713,6 +717,7 @@ void GCodeAnalyzer::_calc_gcode_preview_extrusion_layers(GCodePreviewData& previ preview_data.ranges.height.set_from(height_range); preview_data.ranges.width.set_from(width_range); preview_data.ranges.feedrate.set_from(feedrate_range); + preview_data.ranges.volumetric_rate.set_from(volumetric_rate_range); } void GCodeAnalyzer::_calc_gcode_preview_travel(GCodePreviewData& preview_data) diff --git a/xs/src/libslic3r/GCode/PreviewData.cpp b/xs/src/libslic3r/GCode/PreviewData.cpp index b9be6643b..69fd3524d 100644 --- a/xs/src/libslic3r/GCode/PreviewData.cpp +++ b/xs/src/libslic3r/GCode/PreviewData.cpp @@ -235,6 +235,7 @@ void GCodePreviewData::set_default() ::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)); + ::memcpy((void*)ranges.volumetric_rate.colors, (const void*)Range::Default_Colors, Range::Colors_Count * sizeof(Color)); extrusion.set_default(); travel.set_default(); @@ -248,6 +249,7 @@ void GCodePreviewData::reset() ranges.width.reset(); ranges.height.reset(); ranges.feedrate.reset(); + ranges.volumetric_rate.reset(); extrusion.layers.clear(); travel.polylines.clear(); retraction.positions.clear(); @@ -279,6 +281,11 @@ const GCodePreviewData::Color& GCodePreviewData::get_feedrate_color(float feedra return ranges.feedrate.get_color_at(feedrate); } +const GCodePreviewData::Color& GCodePreviewData::get_volumetric_rate_color(float rate) const +{ + return ranges.volumetric_rate.get_color_at(rate); +} + void GCodePreviewData::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) @@ -345,6 +352,8 @@ std::string GCodePreviewData::get_legend_title() const return L("Width (mm)"); case Extrusion::Feedrate: return L("Speed (mm/s)"); + case Extrusion::VolumetricRate: + return L("Volumetric flow rate (mm3/s)"); case Extrusion::Tool: return L("Tool"); } @@ -402,6 +411,11 @@ GCodePreviewData::LegendItemsList GCodePreviewData::get_legend_items(const std:: Helper::FillListFromRange(items, ranges.feedrate, 0, 1.0f); break; } + case Extrusion::VolumetricRate: + { + Helper::FillListFromRange(items, ranges.volumetric_rate, 3, 1.0f); + break; + } case Extrusion::Tool: { unsigned int tools_colors_count = tool_colors.size() / 4; diff --git a/xs/src/libslic3r/GCode/PreviewData.hpp b/xs/src/libslic3r/GCode/PreviewData.hpp index 6375af5f0..e9c5f7515 100644 --- a/xs/src/libslic3r/GCode/PreviewData.hpp +++ b/xs/src/libslic3r/GCode/PreviewData.hpp @@ -50,6 +50,7 @@ public: Range height; Range width; Range feedrate; + Range volumetric_rate; }; struct LegendItem @@ -70,6 +71,7 @@ public: Height, Width, Feedrate, + VolumetricRate, Tool, Num_View_Types }; @@ -190,6 +192,7 @@ public: const Color& get_height_color(float height) const; const Color& get_width_color(float width) const; const Color& get_feedrate_color(float feedrate) const; + const Color& get_volumetric_rate_color(float rate) const; void set_extrusion_role_color(const std::string& role_name, float red, float green, float blue, float alpha); void set_extrusion_paths_colors(const std::vector& colors); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 4762fa54c..eafca6cd1 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -2039,6 +2039,8 @@ void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, return path.width; case GCodePreviewData::Extrusion::Feedrate: return path.feedrate; + case GCodePreviewData::Extrusion::VolumetricRate: + return path.feedrate * (float)path.mm3_per_mm; case GCodePreviewData::Extrusion::Tool: return (float)path.extruder_id; } @@ -2058,6 +2060,8 @@ void _3DScene::_load_gcode_extrusion_paths(const GCodePreviewData& preview_data, return data.get_width_color(value); case GCodePreviewData::Extrusion::Feedrate: return data.get_feedrate_color(value); + case GCodePreviewData::Extrusion::VolumetricRate: + return data.get_volumetric_rate_color(value); case GCodePreviewData::Extrusion::Tool: { static GCodePreviewData::Color color; From c166af5ccec2c46ff7c030aa7bbbf7173d5e7e0f Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Tue, 27 Mar 2018 11:35:48 +0200 Subject: [PATCH 5/6] GCode Preview - Fixed z values set on sliders --- xs/src/slic3r/GUI/3DScene.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index eafca6cd1..95a739353 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -643,14 +643,18 @@ void GLVolumeCollection::update_outside_state(const DynamicPrintConfig* config, std::vector GLVolumeCollection::get_current_print_zs() const { std::vector print_zs; + std::vector rounded_print_zs; for (GLVolume *vol : this->volumes) { for (coordf_t z : vol->print_zs) { - double round_z = (double)round(z * 100000.0f) / 100000.0f; - if (std::find(print_zs.begin(), print_zs.end(), round_z) == print_zs.end()) - print_zs.push_back(round_z); + double round_z = ::round(z * 100000.0 + 0.5) / 100000.0; + if (std::find(rounded_print_zs.begin(), rounded_print_zs.end(), round_z) == rounded_print_zs.end()) + { + print_zs.push_back(z); + rounded_print_zs.push_back(round_z); + } } } From 2f6fbfb3381edcca6f81794c1fd2c76439c89a44 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 4 Apr 2018 11:00:25 +0200 Subject: [PATCH 6/6] Fix of SPE-183: Incorrect z values set into GCode Preview sliders. Rework to replace layer top heights with averages of EPSILON intervals. --- xs/src/slic3r/GUI/3DScene.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 95a739353..0db81d99b 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -642,24 +642,25 @@ void GLVolumeCollection::update_outside_state(const DynamicPrintConfig* config, std::vector GLVolumeCollection::get_current_print_zs() const { + // Collect layer top positions of all volumes. std::vector print_zs; - std::vector rounded_print_zs; - for (GLVolume *vol : this->volumes) - { - for (coordf_t z : vol->print_zs) - { - double round_z = ::round(z * 100000.0 + 0.5) / 100000.0; - if (std::find(rounded_print_zs.begin(), rounded_print_zs.end(), round_z) == rounded_print_zs.end()) - { - print_zs.push_back(z); - rounded_print_zs.push_back(round_z); - } - } - } - + append(print_zs, vol->print_zs); std::sort(print_zs.begin(), print_zs.end()); + // Replace intervals of layers with similar top positions with their average value. + int n = int(print_zs.size()); + int k = 0; + for (int i = 0; i < n;) { + int j = i + 1; + coordf_t zmax = print_zs[i] + EPSILON; + for (; j < n && print_zs[j] <= zmax; ++ j) ; + print_zs[k ++] = (j > i + 1) ? (0.5 * (print_zs[i] + print_zs[j - 1])) : print_zs[i]; + i = j; + } + if (k < n) + print_zs.erase(print_zs.begin() + k, print_zs.end()); + return print_zs; }