From 43e4569f55825788a8e88330142779a13d1785cc Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Thu, 12 Sep 2024 14:10:33 +0800 Subject: [PATCH] FIX: can't merge paths with different attributes jira:NONE Signed-off-by: xun.zhang Change-Id: I0c853de6b1938c7e2addbaab5a45b35daf5a32fa --- src/libslic3r/ExtrusionEntity.cpp | 13 ++++++++++ src/libslic3r/ExtrusionEntity.hpp | 2 ++ src/libslic3r/GCode.cpp | 40 ++++++++++++++----------------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/ExtrusionEntity.cpp b/src/libslic3r/ExtrusionEntity.cpp index 7cc2a35ad..a786577da 100644 --- a/src/libslic3r/ExtrusionEntity.cpp +++ b/src/libslic3r/ExtrusionEntity.cpp @@ -66,6 +66,19 @@ void ExtrusionPath::polygons_covered_by_spacing(Polygons &out, const float scale polygons_append(out, offset(this->polyline, 0.5f * float(flow.scaled_spacing()) + scaled_epsilon)); } +bool ExtrusionPath::can_merge(const ExtrusionPath& other) +{ + return overhang_degree == other.overhang_degree && + curve_degree==other.curve_degree && + mm3_per_mm == other.mm3_per_mm && + width == other.width && + height == other.height && + m_can_reverse == other.m_can_reverse && + m_role == other.m_role && + m_no_extrusion == other.m_no_extrusion && + smooth_speed == other.smooth_speed; +} + void ExtrusionMultiPath::reverse() { for (ExtrusionPath &path : this->paths) diff --git a/src/libslic3r/ExtrusionEntity.hpp b/src/libslic3r/ExtrusionEntity.hpp index 7799f32f4..00ed27886 100644 --- a/src/libslic3r/ExtrusionEntity.hpp +++ b/src/libslic3r/ExtrusionEntity.hpp @@ -285,6 +285,8 @@ public: void set_reverse() override { m_can_reverse = false; } bool can_reverse() const override { return m_can_reverse; } + bool can_merge(const ExtrusionPath& other); + private: void _inflate_collection(const Polylines &polylines, ExtrusionEntityCollection* collection) const; bool m_can_reverse = true; diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 0c9089554..44c0f2a5a 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -4677,41 +4677,37 @@ ExtrusionPaths GCode::split_and_mapping_speed(double &other_path_v, double &fina ExtrusionPaths GCode::merge_same_speed_paths(const ExtrusionPaths &paths) { ExtrusionPaths output_paths; + std::optional merged_path; - size_t path_idx = 0; - int merge_start = 0; - ExtrusionPath merge_path; - for (; path_idx < paths.size(); path_idx++) { + for(size_t path_idx=0;path_idxcan_merge(path)){ + merged_path->polyline.append(path.polyline); + } + else{ + output_paths.push_back(std::move(*merged_path)); + merged_path = path; } } - if (!merge_path.empty() && merge_start < paths.size()) - output_paths.push_back(std::move(merge_path)); + if(merged_path.has_value()) + output_paths.push_back(std::move(*merged_path)); return output_paths; }