From 9a17efc48093d777ca983e3af59f983b8b0389bd Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Thu, 2 Jul 2015 19:14:55 +0200 Subject: [PATCH] Use GCodeWriter for path segments (refactoring) --- xs/src/libslic3r/ExtrusionEntity.cpp | 51 ---------------------------- xs/src/libslic3r/ExtrusionEntity.hpp | 3 -- xs/src/libslic3r/GCode.cpp | 29 ++++++++++------ xs/xsp/ExtrusionPath.xsp | 3 -- 4 files changed, 18 insertions(+), 68 deletions(-) diff --git a/xs/src/libslic3r/ExtrusionEntity.cpp b/xs/src/libslic3r/ExtrusionEntity.cpp index f6c3b80a8..846269185 100644 --- a/xs/src/libslic3r/ExtrusionEntity.cpp +++ b/xs/src/libslic3r/ExtrusionEntity.cpp @@ -114,57 +114,6 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo REGISTER_CLASS(ExtrusionPath, "ExtrusionPath"); #endif -std::string -ExtrusionPath::gcode(Extruder* extruder, double e, double F, - double xofs, double yofs, std::string extrusion_axis, - std::string gcode_line_suffix) const -{ - dSP; - - std::stringstream stream; - stream.setf(std::ios::fixed); - - double local_F = F; - - Lines lines = this->polyline.lines(); - for (Lines::const_iterator line_it = lines.begin(); - line_it != lines.end(); ++line_it) - { - const double line_length = line_it->length() * SCALING_FACTOR; - - // calculate extrusion length for this line - double E = 0; - if (e > 0) { - extruder->extrude(e * line_length); - E = extruder->E; - } - - // compose G-code line - - Point point = line_it->b; - const double x = point.x * SCALING_FACTOR + xofs; - const double y = point.y * SCALING_FACTOR + yofs; - stream.precision(3); - stream << "G1 X" << x << " Y" << y; - - if (E != 0) { - stream.precision(5); - stream << " " << extrusion_axis << E; - } - - if (local_F != 0) { - stream.precision(3); - stream << " F" << local_F; - local_F = 0; - } - - stream << gcode_line_suffix; - stream << "\n"; - } - - return stream.str(); -} - Polygons ExtrusionPath::grow() const { diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index 9be5b4125..bcb50155a 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -79,9 +79,6 @@ class ExtrusionPath : public ExtrusionEntity bool is_infill() const; bool is_solid_infill() const; bool is_bridge() const; - std::string gcode(Extruder* extruder, double e, double F, - double xofs, double yofs, std::string extrusion_axis, - std::string gcode_line_suffix) const; Polygons grow() const; double min_mm3_per_mm() const { return this->mm3_per_mm; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 5b5d26acd..60145a6ab 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -357,22 +357,29 @@ GCode::_extrude_path(ExtrusionPath path, std::string description, double speed) // extrude arc or line if (path.is_bridge() && this->enable_cooling_markers) gcode += ";_BRIDGE_FAN_START\n"; - double path_length = unscale(path.length()); + gcode += this->writer.set_speed(F); + double path_length = 0; { - Pointf extruder_offset = EXTRUDER_CONFIG(extruder_offset); - gcode += path.gcode(this->writer.extruder(), e_per_mm, F, - this->origin.x - extruder_offset.x, - this->origin.y - extruder_offset.y, - this->writer.extrusion_axis(), - this->config.gcode_comments ? (" ; " + description) : ""); - - if (this->wipe.enable) { - this->wipe.path = path.polyline; - this->wipe.path.reverse(); + std::string comment = this->config.gcode_comments ? (" ; " + description) : ""; + Lines lines = path.polyline.lines(); + for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) { + const double line_length = line->length() * SCALING_FACTOR; + path_length += line_length; + + gcode += this->writer.extrude_to_xy( + this->point_to_gcode(line->b), + e_per_mm * line_length, + comment + ); } } + if (this->wipe.enable) { + this->wipe.path = path.polyline; + this->wipe.path.reverse(); + } if (path.is_bridge() && this->enable_cooling_markers) gcode += ";_BRIDGE_FAN_END\n"; + this->set_last_pos(path.last_point()); if (this->config.cooling) diff --git a/xs/xsp/ExtrusionPath.xsp b/xs/xsp/ExtrusionPath.xsp index 491862840..ca1b465cb 100644 --- a/xs/xsp/ExtrusionPath.xsp +++ b/xs/xsp/ExtrusionPath.xsp @@ -26,9 +26,6 @@ bool is_infill(); bool is_solid_infill(); bool is_bridge(); - std::string gcode(Extruder* extruder, double e, double F, - double xofs, double yofs, std::string extrusion_axis, - std::string gcode_line_suffix); Polygons grow(); %{