Skip to content

Commit 45c91f1

Browse files
committed
Handle the last tapered end of spiralize on our own instead of with 'non-spiralize' code.
Eventually, we should probably refactor this to use the scarf-seam code. part of CURA-12369
1 parent caef8b8 commit 45c91f1

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

src/LayerPlan.cpp

+26-19
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,6 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
28462846
const ExtruderTrain& extruder = Application::getInstance().current_slice_->scene.extruders[extruder_nr];
28472847

28482848
bool update_extrusion_offset = true;
2849-
bool spiralize_finisher = false;
28502849

28512850
double cumulative_path_time = 0.; // Time in seconds.
28522851
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)
30093008
gcode.writeComment(ss.str());
30103009
}
30113010

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)
30133012
&& (z_ + path.z_offset + path.points.front().z_ != gcode.getPositionZ()) && (path_idx > 0 || layer_nr_ > 0))
30143013
{
30153014
// First move to desired height to then make a plain horizontal move
@@ -3055,22 +3054,17 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
30553054
}
30563055
if (! coasting) // not same as 'else', cause we might have changed [coasting] in the line above...
30573056
{ // normal path to gcode algorithm
3058-
const coord_t extra_z_offset = spiralize_finisher ? layer_thickness_ : 0;
3059-
30603057
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)
30623059
{
3063-
Point3LL& pt = path.points[point_idx];
3064-
pt.z_ += extra_z_offset;
3065-
30663060
const auto [_, time] = extruder_plan.getPointToPointTime(prev_point, pt, path);
30673061
insertTempOnTime(time, path_idx);
30683062

30693063
const double extrude_speed = speed * path.speed_back_pressure_factor;
30703064
writeExtrusionRelativeZ(gcode, pt, extrude_speed, path.z_offset, path.getExtrusionMM3perMM(), path.config.type, update_extrusion_offset);
30713065
sendLineTo(path, pt, extrude_speed);
30723066

3073-
prev_point = path.points[point_idx];
3067+
prev_point = pt;
30743068
}
30753069
}
30763070
}
@@ -3092,32 +3086,45 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
30923086

30933087
double length = 0.0;
30943088
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)
31003093
{
3101-
const Point3LL p1 = spiral_path.points[point_idx];
3102-
31033094
const Point2LL p1_2d = p1.toPoint2LL();
31043095
length += vSizeMM(p0 - p1_2d);
31053096
p0 = p1_2d;
31063097

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);
31083099
const double extrude_speed = speed * spiral_path.speed_back_pressure_factor;
31093100
writeExtrusionRelativeZ(
31103101
gcode,
3111-
spiral_path.points[point_idx],
3102+
p1,
31123103
extrude_speed,
31133104
path.z_offset + z_offset,
31143105
spiral_path.getExtrusionMM3perMM(),
31153106
spiral_path.config.type,
31163107
update_extrusion_offset);
31173108
sendLineTo(spiral_path, Point3LL(p1.x_, p1.y_, z_offset), extrude_speed, layer_thickness_);
31183109
}
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;
31193127
}
3120-
spiralize_finisher = true;
31213128
path_idx--; // the last path_idx didnt spiralize, so it's not part of the current spiralize path
31223129
}
31233130
} // paths for this extruder /\ .

0 commit comments

Comments
 (0)