@@ -306,46 +306,61 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
306306
307307        //  Declare & initialize retraction lengths
308308        double  retraction_length_remaining = 0 ,
309-                 retractionBeforeWipe = 0 ,
310-                 retractionDuringWipe = 0 ;
309+             retraction_length_before_wipe = 0 ,
310+             retraction_length_during_wipe = 0 ,
311+             retraction_length_after_wipe = 0 ;
311312
312-         //  initialise the remaining retraction amount with the full retraction amount.
313-         retraction_length_remaining = toolchange ? extruder->retract_length_toolchange () : extruder->retraction_length ();
313+         //  Initialise the remaining retraction amount with the full retraction amount.
314+         retraction_length_remaining = toolchange ? 
315+             extruder->retract_length_toolchange () : extruder->retraction_length ();
314316
315-         //  nothing to retract - return early
316-         if (retraction_length_remaining <=EPSILON) return  {0 .f ,0 .f };
317+         //  Nothing to retract - return early
318+         if  (retraction_length_remaining <= EPSILON)
319+             return  { 0 .f , 0 .f , 0 .f  };
317320
318-         //  calculate retraction before wipe distance from the user setting. Keep adding to this variable any excess retraction needed
319-         //  to be performed before the wipe.
320-         retractionBeforeWipe = retraction_length_remaining * extruder->retract_before_wipe ();
321-         retraction_length_remaining -= retractionBeforeWipe; //  subtract it from the remaining retraction length
322-         
323-         //  all of the retraction is to be done before the wipe
324-         if (retraction_length_remaining <=EPSILON) return  {retractionBeforeWipe,0 .f };
321+         //  Calculate retraction before and after wipe distances from the user setting. 
322+         //  Keep adding to the for retraction before wipe variable any excess retraction 
323+         //  needed to be performed before the wipe.
324+         retraction_length_before_wipe = retraction_length_remaining * extruder->retract_before_wipe ();
325+         retraction_length_after_wipe = retraction_length_remaining * extruder->retract_after_wipe ();
326+ 
327+         //  Subtract it from the remaining retraction length
328+         retraction_length_remaining -= retraction_length_before_wipe + retraction_length_after_wipe;
329+ 
330+         //  All of the retraction is to be done before the wipe
331+         if  (retraction_length_remaining <= EPSILON) 
332+             return  { retraction_length_before_wipe, 0 ., retraction_length_after_wipe };
325333
326334        //  Calculate wipe speed
327-         double  wipe_speed = config.role_based_wipe_speed  ? writer.get_current_speed () / 60.0  : config.get_abs_value (" wipe_speed" 
335+         double  wipe_speed = config.role_based_wipe_speed  ? 
336+             writer.get_current_speed () / 60.0  : config.get_abs_value (" wipe_speed" 
328337        wipe_speed = std::max (wipe_speed, 10.0 );
329338
330339        //  Process wipe path & calculate wipe path length
331340        double  wipe_dist = scale_ (config.wipe_distance .get_at (extruder_id));
332-         Polyline wipe_path = {last_pos};
341+         Polyline wipe_path = {  last_pos  };
333342        wipe_path.append (this ->path .points .begin () + 1 , this ->path .points .end ());
334343        double  wipe_path_length = std::min (wipe_path.length (), wipe_dist);
335344
336345        //  Calculate the maximum retraction amount during wipe
337-         retractionDuringWipe = config.retraction_speed .get_at (extruder_id) * unscale_ (wipe_path_length) / wipe_speed;
338-         //  If the maximum retraction amount during wipe is too small, return 0 and retract everything prior to the wipe.
339-         if (retractionDuringWipe <= EPSILON) return  {retractionBeforeWipe,0 .f };
346+         retraction_length_during_wipe = config.retraction_speed .get_at (extruder_id) * 
347+             unscale_ (wipe_path_length) / wipe_speed;
348+ 
349+         //  If the maximum retraction amount during wipe is too small, 
350+         //  return 0 and retract everything prior to the wipe.
351+         if  (retraction_length_during_wipe <= EPSILON) 
352+             return  { retraction_length_before_wipe, 0 ., retraction_length_after_wipe };
340353
341354        //  If the maximum retraction amount during wipe is greater than any remaining retraction length
342355        //  return the remaining retraction length to be retracted during the wipe
343-         if  (retractionDuringWipe - retraction_length_remaining > EPSILON) return  {retractionBeforeWipe,retraction_length_remaining};
356+         if  (retraction_length_during_wipe - retraction_length_remaining > EPSILON) 
357+             return  { retraction_length_before_wipe, retraction_length_remaining, retraction_length_after_wipe };
344358
345359        //  We will always proceed with incrementing the retraction amount before wiping with the difference
346360        //  and return the maximum allowed wipe amount to be retracted during the wipe move
347-         retractionBeforeWipe += retraction_length_remaining - retractionDuringWipe;
348-         return  {retractionBeforeWipe, retractionDuringWipe};
361+         retraction_length_before_wipe += retraction_length_remaining - retraction_length_during_wipe;
362+ 
363+         return  { retraction_length_before_wipe, retraction_length_during_wipe, retraction_length_after_wipe };
349364    }
350365
351366    std::string transform_gcode (const  std::string &gcode, Vec2f pos, const  Vec2f &translation, float  angle)
@@ -6999,8 +7014,9 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li
69997014    //  wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance)
70007015    if  (FILAMENT_CONFIG (wipe) && m_wipe.has_path () && scale_ (FILAMENT_CONFIG (wipe_distance)) > SCALED_EPSILON) {
70017016        Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths (*this , toolchange);
7002-         gcode += toolchange ? m_writer.retract_for_toolchange (true ,wipeRetractions.retractLengthBeforeWipe ) : m_writer.retract (true , wipeRetractions.retractLengthBeforeWipe );
7003-         gcode += m_wipe.wipe (*this ,wipeRetractions.retractLengthDuringWipe , toolchange, is_last_retraction);
7017+         gcode += toolchange ? m_writer.retract_for_toolchange (true , wipeRetractions.retraction_length_before_wipe ) :
7018+                               m_writer.retract (true , wipeRetractions.retraction_length_before_wipe );
7019+         gcode += m_wipe.wipe (*this , wipeRetractions.retraction_length_during_wipe , toolchange, is_last_retraction);
70047020    }
70057021
70067022    /*   The parent class will decide whether we need to perform an actual retraction
0 commit comments