@@ -58,14 +58,15 @@ GCodePath* LayerPlan::getLatestPathWithConfig(
5858 {
5959 return &paths.back ();
6060 }
61- paths.emplace_back (GCodePath{ .z_offset = z_offset,
62- .config = config,
63- .mesh = current_mesh_,
64- .space_fill_type = space_fill_type,
65- .flow = flow,
66- .width_factor = width_factor,
67- .spiralize = spiralize,
68- .speed_factor = speed_factor });
61+ paths.emplace_back (
62+ GCodePath{ .z_offset = z_offset,
63+ .config = config,
64+ .mesh = current_mesh_,
65+ .space_fill_type = space_fill_type,
66+ .flow = flow,
67+ .width_factor = width_factor,
68+ .spiralize = spiralize,
69+ .speed_factor = speed_factor });
6970
7071 GCodePath* ret = &paths.back ();
7172 ret->skip_agressive_merge_hint = mode_skip_agressive_merge_;
@@ -2222,94 +2223,107 @@ void LayerPlan::computeAntiOozeAmounts(
22222223 extra_time_still_prime = prime_duration_during_travel - allowed_prime_duration_during_travel;
22232224 }
22242225
2225- const auto compute_anti_ooze_amounts
2226- = [&](const double distance, const Ratio& during_travel_ratio, const Velocity& speed, const Duration& extra_time_still, const bool reversed) -> TravelAntiOozing
2227- {
2228- TravelAntiOozing anti_oozing;
2226+ retraction_amounts = computeAntiOozeAmount (
2227+ travel_durations,
2228+ gcode,
2229+ path,
2230+ retract_distance,
2231+ retraction_config->retraction_config .retract_during_travel ,
2232+ retraction_config->retraction_config .speed ,
2233+ extra_time_still_retraction,
2234+ false );
22292235
2230- // First, assume we have enough time to perform retraction and priming during travel as required by the settings
2231- anti_oozing.amount_while_still = distance * (1.0 - during_travel_ratio);
2236+ priming_amounts = computeAntiOozeAmount (
2237+ travel_durations,
2238+ gcode,
2239+ path,
2240+ prime_distance,
2241+ retraction_config->retraction_config .prime_during_travel ,
2242+ retraction_config->retraction_config .primeSpeed ,
2243+ extra_time_still_prime,
2244+ true );
2245+ }
22322246
2233- const double max_amount_during_z_hop = anti_oozing.amount_while_still + speed * travel_durations.z_hop ;
2234- anti_oozing.z_hop .amount = std::min (distance, max_amount_during_z_hop);
2247+ TravelAntiOozing LayerPlan::computeAntiOozeAmount (
2248+ const TravelDurations& travel_durations,
2249+ const GCodeExport& gcode,
2250+ const GCodePath& path,
2251+ const double distance,
2252+ const Ratio& during_travel_ratio,
2253+ const Velocity& speed,
2254+ const Duration& extra_time_still,
2255+ const bool reversed)
2256+ {
2257+ TravelAntiOozing anti_oozing;
22352258
2236- anti_oozing.amount_while_travel = distance;
2259+ // First, assume we have enough time to perform retraction and priming during travel as required by the settings
2260+ anti_oozing.amount_while_still = distance * (1.0 - during_travel_ratio);
22372261
2238- if (extra_time_still > 0 )
2239- {
2240- // Now, if we need some extra time, adjust the stationary and z-hop amounts so that actual travel is not overloaded
2241- const double missing_amount = speed * extra_time_still;
2242- anti_oozing.amount_while_still += missing_amount;
2243- anti_oozing.z_hop .amount += missing_amount;
2244- }
2262+ const double max_amount_during_z_hop = anti_oozing.amount_while_still + speed * travel_durations.z_hop ;
2263+ anti_oozing.z_hop .amount = std::min (distance, max_amount_during_z_hop);
22452264
2246- if (travel_durations.z_hop > 0 )
2247- {
2248- // If the retraction/prime should stop/start during z-hop move, compute the ratio of the move which should contain the retraction/prime
2249- anti_oozing.z_hop .ratio = ((anti_oozing.z_hop .amount - anti_oozing.amount_while_still ) / speed) / travel_durations.z_hop ;
2250- }
2265+ anti_oozing.amount_while_travel = distance;
22512266
2252- // Now we are going to iterate over all the points of the travel move, including the start position, so create a temporary list and fill it appropriately
2253- const Point2LL start_position = gcode.getPosition ().toPoint2LL ();
2254- std::vector<Point3LL> points;
2255- if (reversed)
2256- {
2257- points.insert (points.end (), path.points .rbegin (), path.points .rend ());
2258- points.push_back (start_position);
2259- }
2260- else
2261- {
2262- points = path.points ;
2263- points.insert (points.begin (), start_position);
2264- }
2267+ if (extra_time_still > 0 )
2268+ {
2269+ // Now, if we need some extra time, adjust the stationary and z-hop amounts so that actual travel is not overloaded
2270+ const double missing_amount = speed * extra_time_still;
2271+ anti_oozing.amount_while_still += missing_amount;
2272+ anti_oozing.z_hop .amount += missing_amount;
2273+ }
22652274
2266- // Now loop over the segments of the travel move to find when and where the retraction/prime should stop/start
2267- const Duration duration_during_travel = (anti_oozing.amount_while_travel - anti_oozing.z_hop .amount ) / speed;
2268- Duration travel_duration;
2269- for (const auto & segment : points | ranges::views::sliding (2 ))
2270- {
2271- const Point2LL& segment_start = segment[0 ].toPoint2LL ();
2272- const Point2LL& segment_end = segment[1 ].toPoint2LL ();
2275+ if (travel_durations.z_hop > 0 )
2276+ {
2277+ // If the retraction/prime should stop/start during z-hop move, compute the ratio of the move which should contain the retraction/prime
2278+ anti_oozing.z_hop .ratio = ((anti_oozing.z_hop .amount - anti_oozing.amount_while_still ) / speed) / travel_durations.z_hop ;
2279+ }
22732280
2274- const Duration segment_duration = (vSize (segment_end - segment_start) / path.config .getSpeed ()) / 1000.0 ;
2275- if (travel_duration + segment_duration >= (duration_during_travel - 0 .001_s))
2281+ // Now we are going to iterate over all the points of the travel move, including the start position, so create a temporary list and fill it appropriately
2282+ const Point2LL start_position = gcode.getPosition ().toPoint2LL ();
2283+ std::vector<Point3LL> points;
2284+ if (reversed)
2285+ {
2286+ points.insert (points.end (), path.points .rbegin (), path.points .rend ());
2287+ points.push_back (start_position);
2288+ }
2289+ else
2290+ {
2291+ points = path.points ;
2292+ points.insert (points.begin (), start_position);
2293+ }
2294+
2295+ // Now loop over the segments of the travel move to find when and where the retraction/prime should stop/start
2296+ const Duration duration_during_travel = (anti_oozing.amount_while_travel - anti_oozing.z_hop .amount ) / speed;
2297+ Duration travel_duration;
2298+ for (const auto & segment : points | ranges::views::sliding (2 ))
2299+ {
2300+ const Point2LL& segment_start = segment[0 ].toPoint2LL ();
2301+ const Point2LL& segment_end = segment[1 ].toPoint2LL ();
2302+
2303+ const Duration segment_duration = (vSize (segment_end - segment_start) / path.config .getSpeed ()) / 1000.0 ;
2304+ if (travel_duration + segment_duration >= (duration_during_travel - 0 .001_s))
2305+ {
2306+ // Retraction/prime ends/starts on this segment, so calculate the intermediate position and final/start amount
2307+ const double segment_ratio = (duration_during_travel - travel_duration) / segment_duration;
2308+ anti_oozing.segment_split_position = cura::lerp (segment_start, segment_end, segment_ratio).toPoint2LL ();
2309+ if (reversed)
22762310 {
2277- // Retraction/prime ends/starts on this segment, so calculate the intermediate position and final/start amount
2278- const double segment_ratio = (duration_during_travel - travel_duration) / segment_duration;
2279- anti_oozing.segment_split_position = cura::lerp (segment_start, segment_end, segment_ratio).toPoint2LL ();
2280- if (reversed)
2281- {
2282- anti_oozing.amount_by_segment .insert (anti_oozing.amount_by_segment .begin (), anti_oozing.z_hop .amount );
2283- }
2284- else
2285- {
2286- anti_oozing.amount_by_segment .push_back (anti_oozing.amount_while_travel );
2287- }
2288- break ;
2311+ anti_oozing.amount_by_segment .insert (anti_oozing.amount_by_segment .begin (), anti_oozing.z_hop .amount );
22892312 }
2290-
2291- // This segment fully contains the retraction/prime, set the proper intermediate amount and keep looping
2292- anti_oozing.amount_by_segment .push_back (
2293- std::lerp (anti_oozing. z_hop . amount , anti_oozing. amount_while_travel , (travel_duration + segment_duration) / duration_during_travel));
2294- travel_duration += segment_duration ;
2313+ else
2314+ {
2315+ anti_oozing.amount_by_segment .push_back (anti_oozing. amount_while_travel );
2316+ }
2317+ break ;
22952318 }
22962319
2297- return anti_oozing;
2298- };
2299-
2300- retraction_amounts = compute_anti_ooze_amounts (
2301- retract_distance,
2302- retraction_config->retraction_config .retract_during_travel ,
2303- retraction_config->retraction_config .speed ,
2304- extra_time_still_retraction,
2305- false );
2320+ // This segment fully contains the retraction/prime, set the proper intermediate amount and keep looping
2321+ anti_oozing.amount_by_segment .push_back (
2322+ std::lerp (anti_oozing.z_hop .amount , anti_oozing.amount_while_travel , (travel_duration + segment_duration) / duration_during_travel));
2323+ travel_duration += segment_duration;
2324+ }
23062325
2307- priming_amounts = compute_anti_ooze_amounts (
2308- prime_distance,
2309- retraction_config->retraction_config .prime_during_travel ,
2310- retraction_config->retraction_config .primeSpeed ,
2311- extra_time_still_prime,
2312- true );
2326+ return anti_oozing;
23132327}
23142328
23152329void LayerPlan::writeTravelSegment (
0 commit comments