Fix of the Spiral Vase after the GCodeReader rework.

A patch of the GCodeTimeEstimator to avoid crashes. This is not a final fix though.
This commit is contained in:
bubnikv 2018-01-03 21:55:32 +01:00
parent 998157fc9b
commit 011281df86
4 changed files with 26 additions and 14 deletions

View file

@ -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()) {

View file

@ -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<const char*, const char*> &command)
{
PROFILE_FUNC();

View file

@ -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<typename Callback>
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<typename Callback>
const char* parse_line(const char *ptr, GCodeLine &gline, Callback &callback)
{
@ -83,9 +97,11 @@ public:
update_coordinates(gline, cmd);
return end;
}
template<typename Callback>
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]; }

View file

@ -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