From 2bc7601563ef5c35fb52d52943a57b7d0a8f7fa5 Mon Sep 17 00:00:00 2001 From: Erwan MATHIEU Date: Wed, 18 Dec 2024 16:01:16 +0100 Subject: [PATCH 1/2] 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. --- src/LayerPlan.cpp | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index 39f3e1b510..f57cba07a4 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -57,14 +57,15 @@ GCodePath* LayerPlan::getLatestPathWithConfig( { return &paths.back(); } - paths.emplace_back(GCodePath{ .z_offset = z_offset, - .config = config, - .mesh = current_mesh_, - .space_fill_type = space_fill_type, - .flow = flow, - .width_factor = width_factor, - .spiralize = spiralize, - .speed_factor = speed_factor }); + paths.emplace_back( + GCodePath{ .z_offset = z_offset, + .config = config, + .mesh = current_mesh_, + .space_fill_type = space_fill_type, + .flow = flow, + .width_factor = width_factor, + .spiralize = spiralize, + .speed_factor = speed_factor }); GCodePath* ret = &paths.back(); ret->skip_agressive_merge_hint = mode_skip_agressive_merge_; @@ -1322,7 +1323,7 @@ std::vector for (const auto& reversed_chunk : paths | ranges::views::enumerate | ranges::views::reverse | ranges::views::chunk_by( - [](const auto&path_a, const auto&path_b) + [](const auto& path_a, const auto& path_b) { return (! std::get<1>(path_a).isTravelPath()) || std::get<1>(path_b).isTravelPath(); })) @@ -2512,8 +2513,24 @@ void LayerPlan::writeGCode(GCodeExport& gcode) { ExtruderPlan& extruder_plan = extruder_plans_[extruder_plan_idx]; - const RetractionAndWipeConfig* retraction_config - = current_mesh ? ¤t_mesh->retraction_wipe_config : &storage_.retraction_wipe_config_per_extruder[extruder_plan.extruder_nr_]; + auto get_retraction_config = [&extruder_nr, this](std::shared_ptr& mesh) -> std::optional + { + if (mesh) + { + if (extruder_nr == mesh->settings.get("extruder_nr")) [[likely]] + { + return &mesh->retraction_wipe_config; + } + + // We are printing a part of a mesh with a different extruder, use this extruder settings instead (mesh-specific settings will be ignored) + return &storage_.retraction_wipe_config_per_extruder[extruder_nr]; + } + + // We have no mesh yet, a more global config should be used + return std::nullopt; + }; + + const RetractionAndWipeConfig* retraction_config = get_retraction_config(current_mesh).value_or(&storage_.retraction_wipe_config_per_extruder[extruder_plan.extruder_nr_]); coord_t z_hop_height = retraction_config->retraction_config.zHop; if (extruder_nr != extruder_plan.extruder_nr_) @@ -2697,7 +2714,7 @@ void LayerPlan::writeGCode(GCodeExport& gcode) if (path.retract) { - retraction_config = path.mesh ? &path.mesh->retraction_wipe_config : retraction_config; + retraction_config = get_retraction_config(path.mesh).value_or(retraction_config); gcode.writeRetraction(retraction_config->retraction_config); if (path.retract_for_nozzle_switch) { From 6bd4aa379a8e0564b00cf915c627cf338751948f Mon Sep 17 00:00:00 2001 From: wawanbreton Date: Wed, 18 Dec 2024 15:02:09 +0000 Subject: [PATCH 2/2] Apply clang-format --- src/LayerPlan.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/LayerPlan.cpp b/src/LayerPlan.cpp index f57cba07a4..5cfdd1d9c2 100644 --- a/src/LayerPlan.cpp +++ b/src/LayerPlan.cpp @@ -57,15 +57,14 @@ GCodePath* LayerPlan::getLatestPathWithConfig( { return &paths.back(); } - paths.emplace_back( - GCodePath{ .z_offset = z_offset, - .config = config, - .mesh = current_mesh_, - .space_fill_type = space_fill_type, - .flow = flow, - .width_factor = width_factor, - .spiralize = spiralize, - .speed_factor = speed_factor }); + paths.emplace_back(GCodePath{ .z_offset = z_offset, + .config = config, + .mesh = current_mesh_, + .space_fill_type = space_fill_type, + .flow = flow, + .width_factor = width_factor, + .spiralize = spiralize, + .speed_factor = speed_factor }); GCodePath* ret = &paths.back(); ret->skip_agressive_merge_hint = mode_skip_agressive_merge_; @@ -1323,7 +1322,7 @@ std::vector for (const auto& reversed_chunk : paths | ranges::views::enumerate | ranges::views::reverse | ranges::views::chunk_by( - [](const auto& path_a, const auto& path_b) + [](const auto&path_a, const auto&path_b) { return (! std::get<1>(path_a).isTravelPath()) || std::get<1>(path_b).isTravelPath(); }))