diff --git a/xs/src/libslic3r/GCode/SpiralVase.cpp b/xs/src/libslic3r/GCode/SpiralVase.cpp index 892d3b4ccd..8e8ae3075c 100644 --- a/xs/src/libslic3r/GCode/SpiralVase.cpp +++ b/xs/src/libslic3r/GCode/SpiralVase.cpp @@ -17,7 +17,7 @@ std::string SpiralVase::process_layer(const std::string &gcode) // If we're not going to modify G-code, just feed it to the reader // in order to update positions. if (!this->enable) { - this->_reader.parse(gcode, {}); + this->_reader.parse_buffer(gcode); return gcode; } @@ -30,7 +30,7 @@ std::string SpiralVase::process_layer(const std::string &gcode) { //FIXME Performance warning: This copies the GCodeConfig of the reader. GCodeReader r = this->_reader; // clone - r.parse(gcode, [&total_layer_length, &layer_height, &z, &set_z] + r.parse_buffer(gcode, [&total_layer_length, &layer_height, &z, &set_z] (GCodeReader &reader, const GCodeReader::GCodeLine &line) { if (line.cmd_is("G1")) { if (line.extruding(reader)) { @@ -50,7 +50,7 @@ std::string SpiralVase::process_layer(const std::string &gcode) z -= layer_height; std::string new_gcode; - this->_reader.parse(gcode, [&new_gcode, &z, &layer_height, &total_layer_length] + this->_reader.parse_buffer(gcode, [&new_gcode, &z, &layer_height, &total_layer_length] (GCodeReader &reader, GCodeReader::GCodeLine line) { if (line.cmd_is("G1")) { if (line.has_z()) { diff --git a/xs/src/libslic3r/GCodeReader.cpp b/xs/src/libslic3r/GCodeReader.cpp index d1f56d9158..965b7ef8ec 100644 --- a/xs/src/libslic3r/GCodeReader.cpp +++ b/xs/src/libslic3r/GCodeReader.cpp @@ -20,14 +20,6 @@ void GCodeReader::apply_config(const DynamicPrintConfig &config) m_extrusion_axis = m_config.get_extrusion_axis()[0]; } -void GCodeReader::parse(const std::string &gcode, callback_t callback) -{ - std::istringstream ss(gcode); - std::string line; - while (std::getline(ss, line)) - this->parse_line(line, callback); -} - const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair &command) { PROFILE_FUNC(); diff --git a/xs/src/libslic3r/GCodeReader.hpp b/xs/src/libslic3r/GCodeReader.hpp index e546abe0b7..102cbd27ad 100644 --- a/xs/src/libslic3r/GCodeReader.hpp +++ b/xs/src/libslic3r/GCodeReader.hpp @@ -73,7 +73,21 @@ public: GCodeReader() : m_verbose(false), m_extrusion_axis('E') { memset(m_position, 0, sizeof(m_position)); } void apply_config(const GCodeConfig &config); void apply_config(const DynamicPrintConfig &config); - void parse(const std::string &gcode, callback_t callback); + + template + void parse_buffer(const std::string &buffer, Callback callback) + { + const char *ptr = buffer.c_str(); + GCodeLine gline; + while (*ptr != 0) { + gline.reset(); + ptr = this->parse_line(ptr, gline, callback); + } + } + + void parse_buffer(const std::string &buffer) + { this->parse_buffer(buffer, [](GCodeReader&, const GCodeReader::GCodeLine&){}); } + template const char* parse_line(const char *ptr, GCodeLine &gline, Callback &callback) { @@ -83,9 +97,11 @@ public: update_coordinates(gline, cmd); return end; } + template void parse_line(const std::string &line, Callback callback) { GCodeLine gline; this->parse_line(line.c_str(), gline, callback); } + void parse_file(const std::string &file, callback_t callback); float& x() { return m_position[X]; } diff --git a/xs/src/libslic3r/GCodeTimeEstimator.cpp b/xs/src/libslic3r/GCodeTimeEstimator.cpp index 8478eb77de..ef0d65d7cf 100644 --- a/xs/src/libslic3r/GCodeTimeEstimator.cpp +++ b/xs/src/libslic3r/GCodeTimeEstimator.cpp @@ -142,7 +142,9 @@ namespace Slic3r { void GCodeTimeEstimator::calculate_time_from_text(const std::string& gcode) { - _parser.parse(gcode, boost::bind(&GCodeTimeEstimator::_process_gcode_line, this, _1, _2)); + _parser.parse_buffer(gcode, + [this](GCodeReader &reader, const GCodeReader::GCodeLine &line) + { this->_process_gcode_line(reader, line); }); _calculate_time(); reset(); } @@ -921,7 +923,9 @@ namespace Slic3r { void GCodeTimeEstimator::_planner_forward_pass_kernel(Block* prev, Block* curr) { - if (prev == nullptr) + if (prev == nullptr || curr == nullptr) +//FIXME something is fishy here. Review and compare with the firmware. +// if (prev == nullptr) return; // If the previous block is an acceleration block, but it is not long enough to complete the