From dc943eddaf0da862fd213bcc0e0afbd5ca6aadca Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 24 Oct 2024 17:24:09 +0800 Subject: [PATCH 1/3] Exclude movements before first extrusion from layer time calculation when dealing with layer cooling (SoftFever/OrcaSlicer#7171) If layer starts with a color change, the full layer time will be much longer, which will trick the slicer to think this layer has enough cooling time. However the actual filament extrusion time (the real "printing" part) won't necessarily have enough time to cool down, so if we don't do extra slowing down before starting next layer, the filament could still be soft and lead to worse surface quality. --- src/libslic3r/GCode/CoolingBuffer.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index 2f4938bc7a..2197428bc0 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -346,6 +346,10 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: // for a sequence of extrusion moves. size_t active_speed_modifier = size_t(-1); + // Orca: Whether we had our first extrusion in this layer. + // Time of any other movements before the first extrusion will be excluded from the layer time. + bool layer_had_extrusion = false; + for (; *line_start != 0; line_start = line_end) { while (*line_end != '\n' && *line_end != 0) @@ -404,6 +408,10 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: line.type |= CoolingLine::TYPE_EXTERNAL_PERIMETER; if (wipe) line.type |= CoolingLine::TYPE_WIPE; + + // Orca: only slow down movements since the first extrusion + if (boost::contains(sline, ";_EXTRUDE_SET_SPEED")) + layer_had_extrusion = true; // ORCA: Dont slowdown external perimeters for layer time feature // use the adjustment pointer to ensure the value for the current extruder (filament) is used. @@ -514,6 +522,13 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: } else if (boost::starts_with(sline, ";_FORCE_RESUME_FAN_SPEED")) { line.type = CoolingLine::TYPE_FORCE_RESUME_FAN; } + + // Orca: For any movements before this layer's first ever extrusion, we exclude them from the layer time calculation. + if (!layer_had_extrusion) { + assert((line.type & CoolingLine::TYPE_ADJUSTABLE) == 0); + line.time = line.time_max = 0; + } + if (line.type != 0) adjustment->lines.emplace_back(std::move(line)); } From 4bb6525c4ffdbcc0446a96d67d608db6743bd6f2 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 24 Oct 2024 21:27:03 +0800 Subject: [PATCH 2/3] Fix issue that `total_time` is not updated after slowing down --- src/libslic3r/GCode/CoolingBuffer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index 2197428bc0..e88f3b38f1 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -151,6 +151,7 @@ struct PerExtruderAdjustments } time_total += line.time; } + this->time_total = time_total; return time_total; } // Slow down each adjustable G-code line proportionally by a factor. @@ -166,6 +167,7 @@ struct PerExtruderAdjustments } time_total += line.time; } + this->time_total = time_total; return time_total; } @@ -204,6 +206,7 @@ struct PerExtruderAdjustments // Used by non-proportional slow down. void slow_down_to_feedrate(float min_feedrate) { assert(this->slow_down_min_speed < min_feedrate + EPSILON); + float time_total = 0.f; for (size_t i = 0; i < n_lines_adjustable; ++ i) { CoolingLine &line = lines[i]; if (line.feedrate > min_feedrate) { @@ -211,7 +214,9 @@ struct PerExtruderAdjustments line.feedrate = min_feedrate; line.slowdown = true; } + time_total += line.time; } + this->time_total = time_total; } // Extruder, for which the G-code will be adjusted. From 6169b4fa2a4fc94cf81a2d44ca3d403f817edb98 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 24 Oct 2024 21:27:46 +0800 Subject: [PATCH 3/3] Fix issue when the extruder do not have any adjustable extrusion --- src/libslic3r/GCode/CoolingBuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index e88f3b38f1..c83d854ee4 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -555,8 +555,7 @@ static inline void extruder_range_slow_down_non_proportional( for (PerExtruderAdjustments *adj : by_min_print_speed) { adj->idx_line_begin = 0; adj->idx_line_end = 0; - assert(adj->idx_line_begin < adj->n_lines_adjustable); - if (adj->lines[adj->idx_line_begin].feedrate > feedrate) + if (adj->idx_line_begin < adj->n_lines_adjustable && adj->lines[adj->idx_line_begin].feedrate> feedrate) feedrate = adj->lines[adj->idx_line_begin].feedrate; } assert(feedrate > 0.f); @@ -643,6 +642,7 @@ float CoolingBuffer::calculate_layer_slowdown(std::vectorslow_down_layer_time < adj2->slow_down_layer_time; });