diff --git a/lib/Slic3r/GCode/CoolingBuffer.pm b/lib/Slic3r/GCode/CoolingBuffer.pm index 62ffb2c76..19fb8d7a8 100644 --- a/lib/Slic3r/GCode/CoolingBuffer.pm +++ b/lib/Slic3r/GCode/CoolingBuffer.pm @@ -56,7 +56,7 @@ sub flush { Slic3r::debugf " fan = %d%%, speed = %d%%\n", $fan_speed, $speed_factor * 100; if ($speed_factor < 1) { - $gcode =~ s/^(?=.*? [XY])(?=.*? E)(?!;_WIPE)(?min_print_speed ? $self->min_print_speed : $new_speed) /gexm; @@ -73,6 +73,7 @@ sub flush { $gcode =~ s/^;_BRIDGE_FAN_END\n/ $self->gcodegen->writer->set_fan($fan_speed, 1) /gmex; } $gcode =~ s/;_WIPE//g; + $gcode =~ s/;_EXTRUDE_SET_SPEED//g; return $gcode; } diff --git a/t/cooling.t b/t/cooling.t index 42d0414c1..9958037f1 100644 --- a/t/cooling.t +++ b/t/cooling.t @@ -34,14 +34,20 @@ $config->set('disable_fan_first_layers', 0); { my $buffer = buffer($config); $buffer->gcodegen->set_elapsed_time($buffer->config->slowdown_below_layer_time + 1); - my $gcode = $buffer->append('G1 X100 E1 F3000', 0, 0, 0.4) . $buffer->flush; + my $gcode = $buffer->append('G1 F3000;_EXTRUDE_SET_SPEED\nG1 X100 E1', 0, 0, 0.4) . $buffer->flush; like $gcode, qr/F3000/, 'speed is not altered when elapsed time is greater than slowdown threshold'; } { my $buffer = buffer($config); $buffer->gcodegen->set_elapsed_time($buffer->config->slowdown_below_layer_time - 1); - my $gcode = $buffer->append("G1 X50 F2500\nG1 X100 E1 F3000\nG1 E4 F400", 0, 0, 0.4) . $buffer->flush; + my $gcode = $buffer->append( + "G1 X50 F2500\n" . + "G1 F3000;_EXTRUDE_SET_SPEED\n" . + "G1 X100 E1\n" . + "G1 E4 F400", + 0, 0, 0.4 + ) . $buffer->flush; unlike $gcode, qr/F3000/, 'speed is altered when elapsed time is lower than slowdown threshold'; like $gcode, qr/F2500/, 'speed is not altered for travel moves'; like $gcode, qr/F400/, 'speed is not altered for extruder-only moves'; diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 69056652e..88020246b 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -177,11 +177,11 @@ Wipe::wipe(GCode &gcodegen, bool toolchange) /* Reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one due to rounding (TODO: test and/or better math for this) */ double dE = length * (segment_length / wipe_dist) * 0.95; - gcode += gcodegen.writer.set_speed(wipe_speed*60); + gcode += gcodegen.writer.set_speed(wipe_speed*60, gcodegen.enable_cooling_markers ? ";_WIPE" : ""); gcode += gcodegen.writer.extrude_to_xy( gcodegen.point_to_gcode(line->b), -dE, - (std::string)"wipe and retract" + (gcodegen.enable_cooling_markers ? ";_WIPE" : "") + "wipe and retract" ); retracted += dE; } @@ -198,7 +198,7 @@ Wipe::wipe(GCode &gcodegen, bool toolchange) GCode::GCode() : placeholder_parser(NULL), enable_loop_clipping(true), enable_cooling_markers(false), layer_count(0), - layer_index(-1), layer(NULL), first_layer(false), elapsed_time(0), volumetric_speed(0), + layer_index(-1), layer(NULL), first_layer(false), elapsed_time(0.0), volumetric_speed(0), _last_pos_defined(false) { } @@ -562,7 +562,7 @@ GCode::_extrude(ExtrusionPath path, std::string description, double speed) // extrude arc or line if (path.is_bridge() && this->enable_cooling_markers) gcode += ";_BRIDGE_FAN_START\n"; - gcode += this->writer.set_speed(F); + gcode += this->writer.set_speed(F, this->enable_cooling_markers ? ";_EXTRUDE_SET_SPEED" : ""); double path_length = 0; { std::string comment = this->config.gcode_comments ? description : ""; @@ -629,9 +629,17 @@ GCode::travel_to(const Point &point, ExtrusionRole role, std::string comment) // use G1 because we rely on paths being straight (G0 may make round paths) Lines lines = travel.lines(); - for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) - gcode += this->writer.travel_to_xy(this->point_to_gcode(line->b), comment); - + double path_length = 0; + 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.travel_to_xy(this->point_to_gcode(line->b), comment); + } + + if (this->config.cooling) + this->elapsed_time += path_length / this->config.get_abs_value("travel_speed"); + return gcode; } diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index 7aa0143a3..ebeb50e78 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -82,7 +82,7 @@ class GCode { const Layer* layer; std::map _seam_position; bool first_layer; // this flag triggers first layer speeds - unsigned int elapsed_time; // seconds + float elapsed_time; // seconds double volumetric_speed; GCode(); diff --git a/xs/xsp/GCode.xsp b/xs/xsp/GCode.xsp index 5bc1bf84f..7f17a3a12 100644 --- a/xs/xsp/GCode.xsp +++ b/xs/xsp/GCode.xsp @@ -129,9 +129,9 @@ void set_first_layer(bool value) %code{% THIS->first_layer = value; %}; - unsigned int elapsed_time() + float elapsed_time() %code{% RETVAL = THIS->elapsed_time; %}; - void set_elapsed_time(unsigned int value) + void set_elapsed_time(float value) %code{% THIS->elapsed_time = value; %}; bool last_pos_defined();