@@ -2846,7 +2846,6 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
2846
2846
const ExtruderTrain& extruder = Application::getInstance ().current_slice_ ->scene .extruders [extruder_nr];
2847
2847
2848
2848
bool update_extrusion_offset = true ;
2849
- bool spiralize_finisher = false ;
2850
2849
2851
2850
double cumulative_path_time = 0 .; // Time in seconds.
2852
2851
const std::function<void (const double , const int64_t )> insertTempOnTime = [&](const double to_add, const int64_t path_idx)
@@ -3009,7 +3008,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
3009
3008
gcode.writeComment (ss.str ());
3010
3009
}
3011
3010
3012
- if (! ( path.spiralize || spiralize_finisher) && path.travel_to_z && (! path.retract || ! path.perform_z_hop )
3011
+ if (! path.spiralize && path.travel_to_z && (! path.retract || ! path.perform_z_hop )
3013
3012
&& (z_ + path.z_offset + path.points .front ().z_ != gcode.getPositionZ ()) && (path_idx > 0 || layer_nr_ > 0 ))
3014
3013
{
3015
3014
// First move to desired height to then make a plain horizontal move
@@ -3055,22 +3054,17 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
3055
3054
}
3056
3055
if (! coasting) // not same as 'else', cause we might have changed [coasting] in the line above...
3057
3056
{ // normal path to gcode algorithm
3058
- const coord_t extra_z_offset = spiralize_finisher ? layer_thickness_ : 0 ;
3059
-
3060
3057
Point3LL prev_point = gcode.getPosition ();
3061
- for (unsigned int point_idx = 0 ; point_idx < path.points . size (); point_idx++ )
3058
+ for (const auto & pt : path.points )
3062
3059
{
3063
- Point3LL& pt = path.points [point_idx];
3064
- pt.z_ += extra_z_offset;
3065
-
3066
3060
const auto [_, time ] = extruder_plan.getPointToPointTime (prev_point, pt, path);
3067
3061
insertTempOnTime (time , path_idx);
3068
3062
3069
3063
const double extrude_speed = speed * path.speed_back_pressure_factor ;
3070
3064
writeExtrusionRelativeZ (gcode, pt, extrude_speed, path.z_offset , path.getExtrusionMM3perMM (), path.config .type , update_extrusion_offset);
3071
3065
sendLineTo (path, pt, extrude_speed);
3072
3066
3073
- prev_point = path. points [point_idx] ;
3067
+ prev_point = pt ;
3074
3068
}
3075
3069
}
3076
3070
}
@@ -3092,32 +3086,45 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
3092
3086
3093
3087
double length = 0.0 ;
3094
3088
p0 = gcode.getPositionXY ();
3095
- for (; path_idx < paths.size () && paths[path_idx].spiralize ; path_idx++)
3096
- { // handle all consecutive spiralized paths > CHANGES path_idx!
3097
- GCodePath& spiral_path = paths[path_idx];
3098
-
3099
- for (unsigned int point_idx = 0 ; point_idx < spiral_path.points .size (); point_idx++)
3089
+ const auto writeSpiralPath =
3090
+ [&](const GCodePath& spiral_path, const bool end_layer) -> void
3091
+ {
3092
+ for (const auto & p1 : spiral_path.points )
3100
3093
{
3101
- const Point3LL p1 = spiral_path.points [point_idx];
3102
-
3103
3094
const Point2LL p1_2d = p1.toPoint2LL ();
3104
3095
length += vSizeMM (p0 - p1_2d);
3105
3096
p0 = p1_2d;
3106
3097
3107
- const coord_t z_offset = std::round (layer_thickness_ * length / totalLength);
3098
+ const coord_t z_offset = end_layer ? layer_thickness_ / 2 : std::round (layer_thickness_ * length / totalLength);
3108
3099
const double extrude_speed = speed * spiral_path.speed_back_pressure_factor ;
3109
3100
writeExtrusionRelativeZ (
3110
3101
gcode,
3111
- spiral_path. points [point_idx] ,
3102
+ p1 ,
3112
3103
extrude_speed,
3113
3104
path.z_offset + z_offset,
3114
3105
spiral_path.getExtrusionMM3perMM (),
3115
3106
spiral_path.config .type ,
3116
3107
update_extrusion_offset);
3117
3108
sendLineTo (spiral_path, Point3LL (p1.x_ , p1.y_ , z_offset), extrude_speed, layer_thickness_);
3118
3109
}
3110
+ };
3111
+
3112
+ for (; path_idx < paths.size () && paths[path_idx].spiralize ; path_idx++)
3113
+ { // handle all consecutive spiralized paths > CHANGES path_idx!
3114
+ constexpr bool not_end_layer = false ;
3115
+ writeSpiralPath (paths[path_idx], not_end_layer);
3116
+ }
3117
+
3118
+ if (path_idx < paths.size ())
3119
+ {
3120
+ // Handle last path & exit.
3121
+ constexpr bool end_layer = true ;
3122
+ for (; path_idx < paths.size (); path_idx++)
3123
+ {
3124
+ writeSpiralPath (paths[path_idx], end_layer);
3125
+ }
3126
+ break ;
3119
3127
}
3120
- spiralize_finisher = true ;
3121
3128
path_idx--; // the last path_idx didnt spiralize, so it's not part of the current spiralize path
3122
3129
}
3123
3130
} // paths for this extruder /\ .
0 commit comments