diff --git a/include/ExtruderPlan.h b/include/ExtruderPlan.h index bb07715410..3443827793 100644 --- a/include/ExtruderPlan.h +++ b/include/ExtruderPlan.h @@ -78,9 +78,11 @@ class ExtruderPlan * * \param path_idx The index into ExtruderPlan::paths which is currently being consider for temperature command insertion * \param gcode The gcode exporter to which to write the temperature command. - * \param cumulative_path_time The time spend on this path up to this point. + * \param cumulative_path_time The time spent on this path up to this point. Inserts whose path_idx is strictly less + * than the current path_idx are considered overdue and will be fired unconditionally. Inserts whose path_idx + * equals the current path_idx are fired only once cumulative_path_time reaches their time_after_path_start. */ - void handleInserts(const size_t path_idx, GCodeExport& gcode, const double cumulative_path_time = std::numeric_limits::infinity()); + void handleInserts(const size_t path_idx, GCodeExport& gcode, const double cumulative_path_time); /*! * Insert all remaining temp inserts into gcode, to be called at the end of an extruder plan diff --git a/src/ExtruderPlan.cpp b/src/ExtruderPlan.cpp index 58a6bb3f86..bcdfa48a01 100644 --- a/src/ExtruderPlan.cpp +++ b/src/ExtruderPlan.cpp @@ -30,8 +30,21 @@ void ExtruderPlan::insertCommand(NozzleTempInsert&& insert) void ExtruderPlan::handleInserts(const size_t path_idx, GCodeExport& gcode, const double cumulative_path_time) { - while (! inserts_.empty() && path_idx >= inserts_.front().path_idx && inserts_.front().time_after_path_start < cumulative_path_time) - { // handle the Insert to be inserted before this path_idx (and all inserts not handled yet) + while (! inserts_.empty()) + { + const NozzleTempInsert& insert = inserts_.front(); + if (insert.path_idx > path_idx) + { + // Insert is scheduled for a future path; nothing more to do for now. + break; + } + if (insert.path_idx == path_idx && insert.time_after_path_start > cumulative_path_time) + { + // Insert is scheduled for this path, but the required time within the path has not been reached yet. + break; + } + // Either the insert is overdue (insert.path_idx < path_idx) and must be fired immediately, + // or it is exactly on time (insert.path_idx == path_idx and time threshold reached). inserts_.front().write(gcode); inserts_.pop_front(); } diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index bbb1e5de43..46655c12c8 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -3512,7 +3512,9 @@ void LayerPlan::writeGCode(GCodeExport& gcode) for (size_t path_idx = 0; path_idx < paths.size(); path_idx++) { - extruder_plan.handleInserts(path_idx, gcode); + // Fire any inserts that became overdue during the previous path, using the total + // accumulated time from that path. + extruder_plan.handleInserts(path_idx, gcode, cumulative_path_time); cumulative_path_time = 0.; // reset to 0 for current path. GCodePath& path = paths[path_idx];