From 3934b1dbeda85413f930ab89d0b386f070f67170 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Wed, 9 Feb 2022 12:02:33 +0100 Subject: [PATCH] Remove repeated spaces from the wipe tower gcode (#7503) --- src/libslic3r/GCode.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 5148926288..3d0ca5069b 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -363,7 +363,7 @@ namespace Slic3r { // All G1 commands should be translated and rotated. X and Y coords are // only pushed to the output when they differ from last time. // WT generator can override this by appending the never_skip_tag - if (line.find("G1 ") == 0) { + if (boost::starts_with(line, "G1 ")) { bool never_skip = false; auto it = line.find(WipeTower::never_skip_tag()); if (it != std::string::npos) { @@ -375,6 +375,7 @@ namespace Slic3r { std::istringstream line_str(line); line_str >> std::noskipws; // don't skip whitespace char ch = 0; + line_str >> ch >> ch; // read the "G1" while (line_str >> ch) { if (ch == 'X' || ch == 'Y') line_str >> (ch == 'X' ? pos.x() : pos.y()); @@ -386,14 +387,16 @@ namespace Slic3r { if (transformed_pos != old_pos || never_skip) { line = line_out.str(); + boost::trim_left(line); // Remove leading spaces std::ostringstream oss; - oss << std::fixed << std::setprecision(3) << "G1 "; + oss << std::fixed << std::setprecision(3) << "G1"; if (transformed_pos.x() != old_pos.x() || never_skip) oss << " X" << transformed_pos.x() - extruder_offset.x(); if (transformed_pos.y() != old_pos.y() || never_skip) oss << " Y" << transformed_pos.y() - extruder_offset.y(); - oss << " "; - line.replace(line.find("G1 "), 3, oss.str()); + if (! line.empty()) + oss << " "; + line = oss.str() + line; old_pos = transformed_pos; } }