Skip to content

Commit a24ed92

Browse files
committed
Make sure z-hop won't change retract when not supposed to
CURA-11978
1 parent 3284964 commit a24ed92

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

include/gcodeExport.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ class GCodeExport : public NoCopy
531531
* Start or end a z hop
532532
* \param speed The speed used for moving, or 0 to take the default speed
533533
* \param height The actual height to be reached, relative to the current layer height
534-
* \param retract_distance The absolute retraction distance to be reached while doing the z-hop move
534+
* \param retract_distance The absolute retraction distance to be reached while doing the z-hop move, or nullopt to leave it unchanged
535535
*/
536-
void writeZhop(Velocity speed = 0.0, const coord_t height = 0, const double retract_distance = 0.0);
536+
void writeZhop(Velocity speed = 0.0, const coord_t height = 0, const std::optional<double> retract_distance = std::nullopt);
537537

538538
public:
539539
/*!
@@ -560,21 +560,21 @@ class GCodeExport : public NoCopy
560560
*
561561
* \param hop_height The height to move above the current layer.
562562
* \param speed The speed used for moving.
563-
* \param retract_distance The absolute retract distance to be reached during the z-hop move
563+
* \param retract_distance The absolute retract distance to be reached during the z-hop move, or nullopt to leave it unchanged
564564
* \param retract_ratio This is the ratio of the complete z-hop move that should be used to process the retraction. If >0 and <1 then the z-hop move
565565
* will actually be split in two part, one with retraction and one without.
566566
*/
567-
void writeZhopStart(const coord_t hop_height, Velocity speed = 0.0, double retract_distance = 0.0, const Ratio& retract_ratio = 0.0_r);
567+
void writeZhopStart(const coord_t hop_height, Velocity speed = 0.0, std::optional<double> retract_distance = std::nullopt, const Ratio& retract_ratio = 0.0_r);
568568

569569
/*!
570570
* End a z hop: go back to the layer height
571571
*
572572
* \param speed The speed used for moving.
573-
* \param prime_distance The absolute prime distance to be reached during the z-hop move
573+
* \param prime_distance The absolute prime distance to be reached during the z-hop move, or nullopt to leave it unchanged
574574
* \param prime_ratio This is the ratio of the complete z-hop move that should be used to process the priming. If >0 and <1 then the z-hop move
575575
* will actually be split in two part, one without priming and one with.
576576
*/
577-
void writeZhopEnd(Velocity speed = 0.0, const coord_t height = 0, const double prime_distance = 0.0, const Ratio& prime_ratio = 0.0_r);
577+
void writeZhopEnd(Velocity speed = 0.0, const coord_t height = 0, const std::optional<double> prime_distance = std::nullopt, const Ratio& prime_ratio = 0.0_r);
578578

579579
/*!
580580
* Start the new_extruder:

src/gcodeExport.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,9 @@ void GCodeExport::writeRetraction(const RetractionConfig& config, bool force, bo
12981298
extr_attr.prime_volume_ += config.prime_volume;
12991299
}
13001300

1301-
void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*/, const double retract_distance, const Ratio& retract_ratio)
1301+
void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*/, const std::optional<double> retract_distance, const Ratio& retract_ratio)
13021302
{
1303-
if (retract_ratio > 0.0 && retract_ratio < 1.0)
1303+
if (retract_distance.has_value() && retract_ratio > 0.0 && retract_ratio < 1.0)
13041304
{
13051305
// We have to split the z-hop move in two sub-moves, one with retraction and one without
13061306
writeZhopStart(hop_height * retract_ratio, speed, retract_distance, 0.0);
@@ -1314,7 +1314,7 @@ void GCodeExport::writeZhopStart(const coord_t hop_height, Velocity speed /*= 0*
13141314
}
13151315
}
13161316

1317-
void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, const double prime_distance, const Ratio& prime_ratio)
1317+
void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, const std::optional<double> prime_distance, const Ratio& prime_ratio)
13181318
{
13191319
if (z_hop_prime_leftover_.has_value())
13201320
{
@@ -1325,7 +1325,7 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, con
13251325

13261326
if (is_z_hopped_)
13271327
{
1328-
if (prime_ratio > 0.0 && prime_ratio < 1.0)
1328+
if (prime_distance.has_value() && prime_ratio > 0.0 && prime_ratio < 1.0)
13291329
{
13301330
// We have to split the z-hop move in two sub-moves, one without prime and one with
13311331
writeZhopEnd(speed, is_z_hopped_ * prime_ratio, extruder_attr_[current_extruder_].retraction_e_amount_current_, 0.0);
@@ -1338,15 +1338,19 @@ void GCodeExport::writeZhopEnd(Velocity speed /*= 0*/, const coord_t height, con
13381338
}
13391339
}
13401340

1341-
void GCodeExport::writeZhop(Velocity speed /*= 0*/, const coord_t height, const double retract_distance)
1341+
void GCodeExport::writeZhop(Velocity speed /*= 0*/, const coord_t height, const std::optional<double> retract_distance)
13421342
{
13431343
if (speed == 0)
13441344
{
13451345
const ExtruderTrain& extruder = Application::getInstance().current_slice_->scene.extruders[current_extruder_];
13461346
speed = extruder.settings_.get<Velocity>("speed_z_hop");
13471347
}
13481348

1349-
RetractionAmounts retraction_amounts = computeRetractionAmounts(extruder_attr_[current_extruder_], retract_distance);
1349+
RetractionAmounts retraction_amounts;
1350+
if (retract_distance.has_value())
1351+
{
1352+
retraction_amounts = computeRetractionAmounts(extruder_attr_[current_extruder_], *retract_distance);
1353+
}
13501354

13511355
is_z_hopped_ = height;
13521356
const coord_t target_z = current_layer_z_ + is_z_hopped_;

0 commit comments

Comments
 (0)