@@ -307,49 +307,64 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
307307
308308 // Declare & initialize retraction lengths
309309 double retraction_length_remaining = 0 ,
310- retractionBeforeWipe = 0 ,
311- retractionDuringWipe = 0 ;
310+ retraction_length_before_wipe = 0 ,
311+ retraction_length_during_wipe = 0 ,
312+ retraction_length_after_wipe = 0 ;
312313
313- // initialise the remaining retraction amount with the full retraction amount.
314- retraction_length_remaining = toolchange ? extruder->retract_length_toolchange () : extruder->retraction_length ();
314+ // Initialise the remaining retraction amount with the full retraction amount.
315+ retraction_length_remaining = toolchange ?
316+ extruder->retract_length_toolchange () : extruder->retraction_length ();
315317
316- // nothing to retract - return early
317- if (retraction_length_remaining <=EPSILON) return {0 .f ,0 .f };
318+ // Nothing to retract - return early
319+ if (retraction_length_remaining <= EPSILON)
320+ return { 0 .f , 0 .f , 0 .f };
318321
319- // calculate retraction before wipe distance from the user setting. Keep adding to this variable any excess retraction needed
320- // to be performed before the wipe.
321- retractionBeforeWipe = retraction_length_remaining * extruder->retract_before_wipe ();
322- retraction_length_remaining -= retractionBeforeWipe; // subtract it from the remaining retraction length
323-
324- // all of the retraction is to be done before the wipe
325- if (retraction_length_remaining <=EPSILON) return {retractionBeforeWipe,0 .f };
322+ // Calculate retraction before and after wipe distances from the user setting.
323+ // Keep adding to the for retraction before wipe variable any excess retraction
324+ // needed to be performed before the wipe.
325+ retraction_length_before_wipe = retraction_length_remaining * extruder->retract_before_wipe ();
326+ retraction_length_after_wipe = retraction_length_remaining * extruder->retract_after_wipe ();
327+
328+ // Subtract it from the remaining retraction length
329+ retraction_length_remaining -= retraction_length_before_wipe + retraction_length_after_wipe;
330+
331+ // All of the retraction is to be done before the wipe
332+ if (retraction_length_remaining <= EPSILON)
333+ return { retraction_length_before_wipe, 0 ., retraction_length_after_wipe };
326334
327335 // Calculate wipe speed
328- double wipe_speed = config.role_based_wipe_speed ? writer.get_current_speed () / 60.0 : config.get_abs_value (" wipe_speed" );
336+ double wipe_speed = config.role_based_wipe_speed ?
337+ writer.get_current_speed () / 60.0 : config.get_abs_value (" wipe_speed" );
329338 wipe_speed = std::max (wipe_speed, 10.0 );
330339
331340 // Process wipe path & calculate wipe path length
332341 double wipe_dist = scale_ (config.wipe_distance .get_at (extruder_id));
333- Polyline wipe_path = {last_pos};
342+ Polyline wipe_path = { last_pos };
334343 wipe_path.append (this ->path .points .begin () + 1 , this ->path .points .end ());
335344 double wipe_path_length = std::min (wipe_path.length (), wipe_dist);
336345
337346 // Calculate the maximum retraction amount during wipe
338- retractionDuringWipe = config.retraction_speed .get_at (extruder_id) * unscale_ (wipe_path_length) / wipe_speed;
339- // If the maximum retraction amount during wipe is too small, return 0 and retract everything prior to the wipe.
340- if (retractionDuringWipe <= EPSILON) return {retractionBeforeWipe,0 .f };
347+ retraction_length_during_wipe = config.retraction_speed .get_at (extruder_id) *
348+ unscale_ (wipe_path_length) / wipe_speed;
349+
350+ // If the maximum retraction amount during wipe is too small,
351+ // return 0 and retract everything prior to the wipe.
352+ if (retraction_length_during_wipe <= EPSILON)
353+ return { retraction_length_before_wipe, 0 ., retraction_length_after_wipe };
341354
342355 // If the maximum retraction amount during wipe is greater than any remaining retraction length
343356 // return the remaining retraction length to be retracted during the wipe
344- if (retractionDuringWipe - retraction_length_remaining > EPSILON) return {retractionBeforeWipe,retraction_length_remaining};
357+ if (retraction_length_during_wipe - retraction_length_remaining > EPSILON)
358+ return { retraction_length_before_wipe, retraction_length_remaining, retraction_length_after_wipe };
345359
346360 // We will always proceed with incrementing the retraction amount before wiping with the difference
347361 // and return the maximum allowed wipe amount to be retracted during the wipe move
348- retractionBeforeWipe += retraction_length_remaining - retractionDuringWipe;
349- return {retractionBeforeWipe, retractionDuringWipe};
362+ retraction_length_before_wipe += retraction_length_remaining - retraction_length_during_wipe;
363+
364+ return { retraction_length_before_wipe, retraction_length_during_wipe, retraction_length_after_wipe };
350365 }
351366
352- std::string Wipe::wipe (GCode& gcodegen,double length, bool toolchange, bool is_last)
367+ std::string Wipe::wipe (GCode& gcodegen, double length, bool toolchange, bool is_last)
353368 {
354369 std::string gcode;
355370
@@ -6369,8 +6384,9 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
63696384 // wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
63706385 if (EXTRUDER_CONFIG (wipe) && m_wipe.has_path () && scale_ (EXTRUDER_CONFIG (wipe_distance)) > SCALED_EPSILON) {
63716386 Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths (*this , toolchange);
6372- gcode += toolchange ? m_writer.retract_for_toolchange (true ,wipeRetractions.retractLengthBeforeWipe ) : m_writer.retract (true , wipeRetractions.retractLengthBeforeWipe );
6373- gcode += m_wipe.wipe (*this ,wipeRetractions.retractLengthDuringWipe , toolchange, is_last_retraction);
6387+ gcode += toolchange ? m_writer.retract_for_toolchange (true , wipeRetractions.retraction_length_before_wipe ) :
6388+ m_writer.retract (true , wipeRetractions.retraction_length_before_wipe );
6389+ gcode += m_wipe.wipe (*this , wipeRetractions.retraction_length_during_wipe , toolchange, is_last_retraction);
63746390 }
63756391
63766392 /* The parent class will decide whether we need to perform an actual retraction
0 commit comments