From 249ee5b76642d52f785978618ae775b60de08d9d Mon Sep 17 00:00:00 2001 From: Arthur Date: Mon, 8 Jan 2024 10:24:41 +0800 Subject: [PATCH] ENH: improve auto arranging with multi colors Improve sortfunc: single color objects first, then objects with more colors jira: none Change-Id: I06945d85206331121a26efd3ea8fcc575a183005 --- src/libslic3r/Arrange.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index cf7203b0c..8221c6ea4 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -674,8 +674,7 @@ protected: bool first_object = extruder_ids.empty(); // the two objects (previously packed items and the current item) are considered having same color if either one's colors are a subset of the other std::set item_extruder_ids(item.extrude_ids.begin(), item.extrude_ids.end()); - bool same_color_with_previous_items = std::includes(item_extruder_ids.begin(), item_extruder_ids.end(), extruder_ids.begin(), extruder_ids.end()) - || std::includes(extruder_ids.begin(), extruder_ids.end(), item_extruder_ids.begin(), item_extruder_ids.end()); + bool same_color_with_previous_items = std::includes(extruder_ids.begin(), extruder_ids.end(), item_extruder_ids.begin(), item_extruder_ids.end()); if (!(first_object || same_color_with_previous_items)) score += LARGE_COST_TO_REJECT * 1.3; } // for layered printing, we want extruder change as few as possible @@ -811,7 +810,15 @@ public: (i1.height != i2.height ? (i1.height < i2.height) : (i1.area() > i2.area())); } else { - return i1.bed_temp != i2.bed_temp ? (i1.bed_temp > i2.bed_temp) : + // single color objects first, then objects with more colors + if (i1.extrude_ids.size() != i2.extrude_ids.size()){ + if (i1.extrude_ids.size() == 1 || i2.extrude_ids.size() == 1) + return i1.extrude_ids.size() == 1; + else + return i1.extrude_ids.size() > i2.extrude_ids.size(); + } + else + return i1.bed_temp != i2.bed_temp ? (i1.bed_temp > i2.bed_temp) : (i1.extrude_ids != i2.extrude_ids ? (i1.extrude_ids.front() < i2.extrude_ids.front()) : (i1.area() > i2.area())); } };