From 534e8bb909a7533020256104b220e93842e8ad02 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Thu, 30 Jul 2020 13:49:57 +0200 Subject: [PATCH] ENABLE_GCODE_VIEWER -> Export to gcode layer z and layer height at each layer change --- src/libslic3r/GCode.cpp | 42 +++++++++++++++++--------- src/libslic3r/GCode.hpp | 12 +++----- src/libslic3r/GCode/GCodeProcessor.cpp | 2 +- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index ced52207d..2dea4fb22 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1180,6 +1180,7 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu #if ENABLE_GCODE_VIEWER m_last_width = 0.0f; m_last_height = 0.0f; + m_last_layer_z = 0.0f; #else m_last_mm3_per_mm = GCodeAnalyzer::Default_mm3_per_mm; m_last_width = GCodeAnalyzer::Default_Width; @@ -2067,6 +2068,20 @@ void GCode::process_layer( std::string gcode; +#if ENABLE_GCODE_VIEWER + // export layer z + char buf[64]; + sprintf(buf, ";Z%g\n", print_z); + gcode += buf; + // export layer height + float height = first_layer ? static_cast(print_z) : static_cast(print_z) - m_last_layer_z; + sprintf(buf, ";%s%g\n", GCodeProcessor::Height_Tag.c_str(), height); + gcode += buf; + // update caches + m_last_layer_z = static_cast(print_z); + m_last_height = height; +#endif // ENABLE_GCODE_VIEWER + // Set new layer - this will change Z and force a retraction if retract_layer_change is enabled. if (! print.config().before_layer_gcode.value.empty()) { DynamicConfig config; @@ -3207,7 +3222,7 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, } } - // adds analyzer tags and updates analyzer's tracking data + // adds processor tags and updates processor tracking data #if !ENABLE_GCODE_VIEWER if (m_enable_analyzer) { #endif // !ENABLE_GCODE_VIEWER @@ -3234,40 +3249,39 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, sprintf(buf, ";%s%d\n", GCodeAnalyzer::Extrusion_Role_Tag.c_str(), int(m_last_analyzer_extrusion_role)); gcode += buf; } -#endif // ENABLE_GCODE_VIEWER -#if !ENABLE_GCODE_VIEWER if (last_was_wipe_tower || (m_last_mm3_per_mm != path.mm3_per_mm)) { m_last_mm3_per_mm = path.mm3_per_mm; sprintf(buf, ";%s%f\n", GCodeAnalyzer::Mm3_Per_Mm_Tag.c_str(), m_last_mm3_per_mm); gcode += buf; } -#endif // !ENABLE_GCODE_VIEWER +#endif // ENABLE_GCODE_VIEWER - if (last_was_wipe_tower || (m_last_width != path.width)) { + if (last_was_wipe_tower || m_last_width != path.width) { m_last_width = path.width; #if ENABLE_GCODE_VIEWER - sprintf(buf, ";%s%f\n", GCodeProcessor::Width_Tag.c_str(), m_last_width); - gcode += buf; + sprintf(buf, ";%s%g\n", GCodeProcessor::Width_Tag.c_str(), m_last_width); #else sprintf(buf, ";%s%f\n", GCodeAnalyzer::Width_Tag.c_str(), m_last_width); - gcode += buf; #endif // ENABLE_GCODE_VIEWER + gcode += buf; } - if (last_was_wipe_tower || (m_last_height != path.height)) { - m_last_height = path.height; + #if ENABLE_GCODE_VIEWER - sprintf(buf, ";%s%f\n", GCodeProcessor::Height_Tag.c_str(), m_last_height); + if (last_was_wipe_tower || std::abs(m_last_height - path.height) > EPSILON) { + m_last_height = path.height; + sprintf(buf, ";%s%g\n", GCodeProcessor::Height_Tag.c_str(), m_last_height); gcode += buf; + } #else + if (last_was_wipe_tower || m_last_height != path.height) { + m_last_height = path.height; sprintf(buf, ";%s%f\n", GCodeAnalyzer::Height_Tag.c_str(), m_last_height); gcode += buf; -#endif // ENABLE_GCODE_VIEWER } -#if !ENABLE_GCODE_VIEWER } -#endif // !ENABLE_GCODE_VIEWER +#endif // ENABLE_GCODE_VIEWER std::string comment; if (m_enable_cooling_markers) { diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 443c25bb2..69f98bfa5 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -172,14 +172,11 @@ public: m_volumetric_speed(0), m_last_pos_defined(false), m_last_extrusion_role(erNone), -#if ENABLE_GCODE_VIEWER - m_last_width(0.0f), - m_last_height(0.0f), -#else +#if !ENABLE_GCODE_VIEWER m_last_mm3_per_mm(GCodeAnalyzer::Default_mm3_per_mm), m_last_width(GCodeAnalyzer::Default_Width), m_last_height(GCodeAnalyzer::Default_Height), -#endif // ENABLE_GCODE_VIEWER +#endif // !ENABLE_GCODE_VIEWER m_brim_done(false), m_second_layer_things_done(false), m_normal_time_estimator(GCodeTimeEstimator::Normal), @@ -379,8 +376,9 @@ private: ExtrusionRole m_last_extrusion_role; #if ENABLE_GCODE_VIEWER // Support for G-Code Processor - float m_last_width; - float m_last_height; + float m_last_width{ 0.0f }; + float m_last_height{ 0.0f }; + float m_last_layer_z{ 0.0f }; #else // Support for G-Code Analyzer double m_last_mm3_per_mm; diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 7a6b1ecb4..c10552482 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -23,7 +23,7 @@ namespace Slic3r { const std::string GCodeProcessor::Extrusion_Role_Tag = "ExtrType:"; const std::string GCodeProcessor::Width_Tag = "PrusaSlicer__WIDTH:"; -const std::string GCodeProcessor::Height_Tag = "PrusaSlicer__HEIGHT:"; +const std::string GCodeProcessor::Height_Tag = "Height:"; const std::string GCodeProcessor::Color_Change_Tag = "COLOR_CHANGE"; const std::string GCodeProcessor::Pause_Print_Tag = "PAUSE_PRINT"; const std::string GCodeProcessor::Custom_Code_Tag = "CUSTOM_CODE";