Skip to content

Commit 2bc7601

Browse files
committed
Fix wrong retraction settings being
CURA-12065 In the case where a mesh was printed with multiple extruders, the used retraction settings were always the one of the main extruder. Now we take the settings of the mesh only if using the main extruder. Mesh-specific settings will then be ignored for other extruders.
1 parent d4853d4 commit 2bc7601

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

src/LayerPlan.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ GCodePath* LayerPlan::getLatestPathWithConfig(
5757
{
5858
return &paths.back();
5959
}
60-
paths.emplace_back(GCodePath{ .z_offset = z_offset,
61-
.config = config,
62-
.mesh = current_mesh_,
63-
.space_fill_type = space_fill_type,
64-
.flow = flow,
65-
.width_factor = width_factor,
66-
.spiralize = spiralize,
67-
.speed_factor = speed_factor });
60+
paths.emplace_back(
61+
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 });
6869

6970
GCodePath* ret = &paths.back();
7071
ret->skip_agressive_merge_hint = mode_skip_agressive_merge_;
@@ -1322,7 +1323,7 @@ std::vector<LayerPlan::PathCoasting>
13221323

13231324
for (const auto& reversed_chunk : paths | ranges::views::enumerate | ranges::views::reverse
13241325
| ranges::views::chunk_by(
1325-
[](const auto&path_a, const auto&path_b)
1326+
[](const auto& path_a, const auto& path_b)
13261327
{
13271328
return (! std::get<1>(path_a).isTravelPath()) || std::get<1>(path_b).isTravelPath();
13281329
}))
@@ -2512,8 +2513,24 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
25122513
{
25132514
ExtruderPlan& extruder_plan = extruder_plans_[extruder_plan_idx];
25142515

2515-
const RetractionAndWipeConfig* retraction_config
2516-
= current_mesh ? &current_mesh->retraction_wipe_config : &storage_.retraction_wipe_config_per_extruder[extruder_plan.extruder_nr_];
2516+
auto get_retraction_config = [&extruder_nr, this](std::shared_ptr<const SliceMeshStorage>& mesh) -> std::optional<const RetractionAndWipeConfig*>
2517+
{
2518+
if (mesh)
2519+
{
2520+
if (extruder_nr == mesh->settings.get<size_t>("extruder_nr")) [[likely]]
2521+
{
2522+
return &mesh->retraction_wipe_config;
2523+
}
2524+
2525+
// We are printing a part of a mesh with a different extruder, use this extruder settings instead (mesh-specific settings will be ignored)
2526+
return &storage_.retraction_wipe_config_per_extruder[extruder_nr];
2527+
}
2528+
2529+
// We have no mesh yet, a more global config should be used
2530+
return std::nullopt;
2531+
};
2532+
2533+
const RetractionAndWipeConfig* retraction_config = get_retraction_config(current_mesh).value_or(&storage_.retraction_wipe_config_per_extruder[extruder_plan.extruder_nr_]);
25172534
coord_t z_hop_height = retraction_config->retraction_config.zHop;
25182535

25192536
if (extruder_nr != extruder_plan.extruder_nr_)
@@ -2697,7 +2714,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode)
26972714

26982715
if (path.retract)
26992716
{
2700-
retraction_config = path.mesh ? &path.mesh->retraction_wipe_config : retraction_config;
2717+
retraction_config = get_retraction_config(path.mesh).value_or(retraction_config);
27012718
gcode.writeRetraction(retraction_config->retraction_config);
27022719
if (path.retract_for_nozzle_switch)
27032720
{

0 commit comments

Comments
 (0)