Skip to content

Commit c833194

Browse files
committed
Properly apply retraction limitations during travel
CURA-11978
1 parent 4426c45 commit c833194

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

include/gcodeExport.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,9 @@ class GCodeExport : public NoCopy
552552
* @param force Indicates whether we should force the retraction to happen regardless of the maximum allowed retraction count
553553
* @param extruder_switch Indicates whether we retract for an extruder switch
554554
* @param retract_distance A specific absolute retraction distance to be used, or nullopt to use the one in the config
555+
* @return True if the retraction has been processed normally, false if it was skipped because of limitations
555556
*/
556-
void writeRetraction(const RetractionConfig& config, bool force = false, bool extruder_switch = false, const std::optional<double> retract_distance = std::nullopt);
557+
bool writeRetraction(const RetractionConfig& config, bool force = false, bool extruder_switch = false, const std::optional<double> retract_distance = std::nullopt);
557558

558559
/*!
559560
* Start a z hop with the given \p hop_height.

src/LayerPlan.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3160,11 +3160,17 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
31603160
computeAntiOozeAmounts(gcode, extruder, path, z_hop_height, retraction_config, retraction_amounts, priming_amounts);
31613161
}
31623162

3163-
gcode.writeRetraction(
3164-
retraction_config->retraction_config,
3165-
false,
3166-
false,
3167-
retraction_amounts.has_value() ? std::optional{ retraction_amounts->amount_while_still } : std::nullopt);
3163+
if (! gcode.writeRetraction(
3164+
retraction_config->retraction_config,
3165+
false,
3166+
false,
3167+
retraction_amounts.has_value() ? std::make_optional(retraction_amounts->amount_while_still) : std::nullopt))
3168+
{
3169+
// Retraction was cancelled because of limitations, so also cancel retraction/priming during travel
3170+
retraction_amounts.reset();
3171+
priming_amounts.reset();
3172+
}
3173+
31683174
if (path.retract_for_nozzle_switch)
31693175
{
31703176
constexpr bool force = true;
@@ -3177,7 +3183,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
31773183
gcode.writeZhopStart(
31783184
z_hop_height,
31793185
0.0,
3180-
retraction_amounts.has_value() ? retraction_amounts->z_hop.amount : 0.0,
3186+
retraction_amounts.has_value() ? std::make_optional(retraction_amounts->z_hop.amount) : std::nullopt,
31813187
retraction_amounts.has_value() ? retraction_amounts->z_hop.ratio : 0.0_r);
31823188
z_hop_height = retraction_config->retraction_config.zHop; // back to normal z hop
31833189
}

src/gcodeExport.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ void GCodeExport::writeUnretractionAndPrime()
12141214
}
12151215
}
12161216

1217-
void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bool extruder_switch, const std::optional<double> retract_distance)
1217+
bool GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bool extruder_switch, const std::optional<double> retract_distance)
12181218
{
12191219
ExtruderTrainAttributes& extr_attr = extruder_attr_[current_extruder_];
12201220

@@ -1228,13 +1228,7 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
12281228
}
12291229
extr_attr.retraction_e_amount_current_ = 1.0; // 1.0 is a stub; BFB doesn't use the actual retracted amount; retraction is performed by firmware
12301230
}
1231-
return;
1232-
}
1233-
1234-
RetractionAmounts retraction_amounts = computeRetractionAmounts(extr_attr, retract_distance.value_or(config.distance));
1235-
if (! retraction_amounts.has_retraction())
1236-
{
1237-
return;
1231+
return true;
12381232
}
12391233

12401234
{ // handle retraction limitation
@@ -1248,12 +1242,12 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
12481242
}
12491243
if (! force && config.retraction_count_max <= 0)
12501244
{
1251-
return;
1245+
return false;
12521246
}
12531247
if (! force && extruded_volume_at_previous_n_retractions.size() == config.retraction_count_max
12541248
&& current_extruded_volume < extruded_volume_at_previous_n_retractions.back() + config.retraction_extrusion_window * extr_attr.filament_area_)
12551249
{
1256-
return;
1250+
return false;
12571251
}
12581252
extruded_volume_at_previous_n_retractions.push_front(current_extruded_volume);
12591253
if (extruded_volume_at_previous_n_retractions.size() == config.retraction_count_max + 1)
@@ -1262,11 +1256,17 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
12621256
}
12631257
}
12641258

1259+
RetractionAmounts retraction_amounts = computeRetractionAmounts(extr_attr, retract_distance.value_or(config.distance));
1260+
if (! retraction_amounts.has_retraction())
1261+
{
1262+
return true;
1263+
}
1264+
12651265
if (extr_attr.machine_firmware_retract_)
12661266
{
12671267
if (extruder_switch && extr_attr.retraction_e_amount_current_)
12681268
{
1269-
return;
1269+
return true;
12701270
}
12711271
*output_stream_ << "G10";
12721272
if (extruder_switch && flavor_ == EGCodeFlavor::REPETIER)
@@ -1301,6 +1301,8 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
13011301
}
13021302

13031303
extr_attr.prime_volume_ += config.prime_volume;
1304+
1305+
return true;
13041306
}
13051307

13061308
void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*/, const std::optional<double> retract_distance, const Ratio& retract_ratio)

0 commit comments

Comments
 (0)