Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2018-01-03 23:55:32 +0300
committerbubnikv <bubnikv@gmail.com>2018-01-03 23:55:32 +0300
commit011281df86212cb2adf84f9229a78d31617d250d (patch)
tree3e1a3b9be839835edf34536f5e24ae066a77aaa0 /xs/src/libslic3r
parent998157fc9b6827f52052e7f5c1187f4bec867fe2 (diff)
Fix of the Spiral Vase after the GCodeReader rework.
A patch of the GCodeTimeEstimator to avoid crashes. This is not a final fix though.
Diffstat (limited to 'xs/src/libslic3r')
-rw-r--r--xs/src/libslic3r/GCode/SpiralVase.cpp6
-rw-r--r--xs/src/libslic3r/GCodeReader.cpp8
-rw-r--r--xs/src/libslic3r/GCodeReader.hpp18
-rw-r--r--xs/src/libslic3r/GCodeTimeEstimator.cpp8
4 files changed, 26 insertions, 14 deletions
diff --git a/xs/src/libslic3r/GCode/SpiralVase.cpp b/xs/src/libslic3r/GCode/SpiralVase.cpp
index 892d3b4cc..8e8ae3075 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 d1f56d915..965b7ef8e 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<const char*, const char*> &command)
{
PROFILE_FUNC();
diff --git a/xs/src/libslic3r/GCodeReader.hpp b/xs/src/libslic3r/GCodeReader.hpp
index e546abe0b..102cbd27a 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<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]; }
diff --git a/xs/src/libslic3r/GCodeTimeEstimator.cpp b/xs/src/libslic3r/GCodeTimeEstimator.cpp
index 8478eb77d..ef0d65d7c 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