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

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVojtech Bubnik <bubnikv@gmail.com>2021-09-13 13:51:50 +0300
committerVojtech Bubnik <bubnikv@gmail.com>2021-09-13 13:51:50 +0300
commite78d647cc239966fdbbd91b995b6f5bef3adc710 (patch)
tree4c46709c90c5fb027d9789a4fd0b933559ccc2b1 /src/libslic3r
parente7591e6aa60042c19a0aa20305af0f6e0d8439c0 (diff)
Follow-up to e7591e6aa60042c19a0aa20305af0f6e0d8439c0
GCodeFormatter default copy constructor / copy operators were not safe and they were used in debug mode.
Diffstat (limited to 'src/libslic3r')
-rw-r--r--src/libslic3r/GCodeWriter.cpp16
-rw-r--r--src/libslic3r/GCodeWriter.hpp45
2 files changed, 33 insertions, 28 deletions
diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp
index 83557fdbb..f57e25406 100644
--- a/src/libslic3r/GCodeWriter.cpp
+++ b/src/libslic3r/GCodeWriter.cpp
@@ -258,7 +258,7 @@ std::string GCodeWriter::set_speed(double F, const std::string &comment, const s
assert(F > 0.);
assert(F < 100000.);
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_f(F);
w.emit_comment(this->config.gcode_comments, comment);
w.emit_string(cooling_marker);
@@ -270,7 +270,7 @@ std::string GCodeWriter::travel_to_xy(const Vec2d &point, const std::string &com
m_pos(0) = point(0);
m_pos(1) = point(1);
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_xy(point);
w.emit_f(this->config.travel_speed.value * 60.0);
w.emit_comment(this->config.gcode_comments, comment);
@@ -303,7 +303,7 @@ std::string GCodeWriter::travel_to_xyz(const Vec3d &point, const std::string &co
m_lifted = 0;
m_pos = point;
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_xyz(point);
w.emit_f(this->config.travel_speed.value * 60.0);
w.emit_comment(this->config.gcode_comments, comment);
@@ -337,7 +337,7 @@ std::string GCodeWriter::_travel_to_z(double z, const std::string &comment)
if (speed == 0.)
speed = this->config.travel_speed.value;
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_z(z);
w.emit_f(speed * 60.0);
w.emit_comment(this->config.gcode_comments, comment);
@@ -362,7 +362,7 @@ std::string GCodeWriter::extrude_to_xy(const Vec2d &point, double dE, const std:
m_pos(1) = point(1);
m_extruder->extrude(dE);
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_xy(point);
w.emit_e(m_extrusion_axis, m_extruder->E());
w.emit_comment(this->config.gcode_comments, comment);
@@ -375,7 +375,7 @@ std::string GCodeWriter::extrude_to_xyz(const Vec3d &point, double dE, const std
m_lifted = 0;
m_extruder->extrude(dE);
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_xyz(point);
w.emit_e(m_extrusion_axis, m_extruder->E());
w.emit_comment(this->config.gcode_comments, comment);
@@ -426,7 +426,7 @@ std::string GCodeWriter::_retract(double length, double restart_extra, const std
if (this->config.use_firmware_retraction) {
gcode = FLAVOR_IS(gcfMachinekit) ? "G22 ; retract\n" : "G10 ; retract\n";
} else if (! m_extrusion_axis.empty()) {
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_e(m_extrusion_axis, m_extruder->E());
w.emit_f(m_extruder->retract_speed() * 60.);
w.emit_comment(this->config.gcode_comments, comment);
@@ -453,7 +453,7 @@ std::string GCodeWriter::unretract()
gcode += this->reset_e();
} else if (! m_extrusion_axis.empty()) {
// use G1 instead of G0 because G0 will blend the restart with the previous travel move
- auto w = GCodeFormatter::G1();
+ GCodeG1Formatter w;
w.emit_e(m_extrusion_axis, m_extruder->E());
w.emit_f(m_extruder->deretract_speed() * 60.);
w.emit_comment(this->config.gcode_comments, " ; unretract");
diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp
index 12a2b5a88..6e2c08d3b 100644
--- a/src/libslic3r/GCodeWriter.hpp
+++ b/src/libslic3r/GCodeWriter.hpp
@@ -95,32 +95,18 @@ private:
};
class GCodeFormatter {
-private:
- static constexpr const size_t buflen = 256;
- char buf[buflen];
- char *buf_end;
- std::to_chars_result ptr_err;
-
- GCodeFormatter() {
- this->buf_end = buf + buflen;
+public:
+ GCodeFormatter() {
+ this->buf_end = buf + buflen;
this->ptr_err.ptr = this->buf;
}
-public:
+ GCodeFormatter(const GCodeFormatter&) = delete;
+ GCodeFormatter& operator=(const GCodeFormatter&) = delete;
+
static constexpr const int XYZF_EXPORT_DIGITS = 3;
static constexpr const int E_EXPORT_DIGITS = 5;
- static GCodeFormatter empty() {
- return {};
- }
- static GCodeFormatter G1() {
- GCodeFormatter out;
- out.buf[0] = 'G';
- out.buf[1] = '1';
- out.ptr_err.ptr += 2;
- return out;
- }
-
void emit_axis(const char axis, const double v, size_t digits);
void emit_xy(const Vec2d &point) {
@@ -165,6 +151,25 @@ public:
*ptr_err.ptr ++ = '\n';
return std::string(this->buf, ptr_err.ptr - buf);
}
+
+protected:
+ static constexpr const size_t buflen = 256;
+ char buf[buflen];
+ char* buf_end;
+ std::to_chars_result ptr_err;
+};
+
+class GCodeG1Formatter : public GCodeFormatter {
+public:
+ GCodeG1Formatter() {
+ this->buf[0] = 'G';
+ this->buf[1] = '1';
+ this->buf_end = buf + buflen;
+ this->ptr_err.ptr = this->buf + 2;
+ }
+
+ GCodeG1Formatter(const GCodeG1Formatter&) = delete;
+ GCodeG1Formatter& operator=(const GCodeG1Formatter&) = delete;
};
} /* namespace Slic3r */