diff --git a/docs/HLSD/prime-tower-sparse-layers.md b/docs/HLSD/prime-tower-sparse-layers.md index 1b20cc7af8..ae4ba3bab5 100644 --- a/docs/HLSD/prime-tower-sparse-layers.md +++ b/docs/HLSD/prime-tower-sparse-layers.md @@ -119,6 +119,12 @@ draws while an object is dragged, measure the rise from the plate and apply only the nozzle cone and the head body. An object away from the toolhead, which only the rod or the lid can reach, is left to the precise check. The ring the user sees touches the object's outline exactly when the pre-slice check trips. +Arrange and Fill bed follow the rule too: they keep objects the toolhead radius +away from the tower, or only the nozzle cone when none of the objects they place +is taller than the nozzle height, and keep those taller than the rod clearance +out of its Y span. They measure the height from the plate. For the rod that is +stricter than the precise check, which only refuses an object that rises past +the rod clearance above the compacted tower. ## Merging sparse layers @@ -209,6 +215,11 @@ read as off rather than compacting or merging in one place and not another. - [GLCanvas3D.cpp](../../src/slic3r/GUI/GLCanvas3D.cpp) and [PartPlate.cpp](../../src/slic3r/GUI/PartPlate.cpp) draw the compacted tower's keep-out outlines live while the user drags. +- [ArrangeJob.cpp](../../src/slic3r/GUI/Jobs/ArrangeJob.cpp) grows the tower's + arrange polygon by the clearance that + [Arrange.cpp](../../src/libslic3r/Arrange.cpp) picks for the objects being + placed, and Arrange.cpp keeps objects taller than the rod clearance out of its + Y span. - [Rule tests](../../tests/libslic3r/test_wipe_tower.cpp) cover the gating of both settings, the per-layer predicates, the compacted z, the merge rule's run flushing, height conservation, the nozzle cap and the first-layer exemption, diff --git a/src/libslic3r/Arrange.cpp b/src/libslic3r/Arrange.cpp index bf18e7ab38..cdd418f7ff 100644 --- a/src/libslic3r/Arrange.cpp +++ b/src/libslic3r/Arrange.cpp @@ -334,6 +334,19 @@ void update_unselected_items_inflation(ArrangePolygons& unselected, const Dynami : (ap.is_extrusion_cali_object ? 0 : scale_(exclusion_gap)); }); } +double compacted_tower_arrange_clearance(const ArrangePolygons& placed, const ArrangeParams& params, double toolhead_radius) +{ + // The head body sits above the nozzle cone, so an object that rises no higher than nozzle_height + // only has to clear the cone, as compacted_wipe_tower_clearance() decides. Arrange measures the + // height from the plate, which is never less than the rise above the tower that check measures. + // The tower is one polygon for every object placed, so a single taller one gives them all the + // toolhead radius, and so does an empty list, whose objects are unknown. + const bool all_short = !placed.empty() && std::all_of(placed.begin(), placed.end(), [¶ms](const ArrangePolygon& ap) { + return ap.height <= params.nozzle_height + EPSILON; + }); + return all_short ? double(MAX_OUTER_NOZZLE_DIAMETER) : toolhead_radius; +} + void update_selected_items_axis_align(ArrangePolygons& selected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params) { // now only need to consider "Align to x axis" @@ -900,6 +913,22 @@ protected: score += height_score / valid_items_cnt; } + // Orca: the nozzle keeps coming down to a prime tower compacted by "No sparse layers", and + // the rod then sweeps the tower's Y span over the whole bed, so nothing taller than the rod + // clearance may share that span. Same test as compacted_wipe_tower_clearance(). + if (params.compacted_tower_growth >= 0 && item.height > params.clearance_height_to_rod) { + const auto item_bb = item.boundingBox(); + const auto iy1 = item_bb.minCorner().y() + item.inflation(); + const auto iy2 = item_bb.maxCorner().y() - item.inflation(); + for (const Item& p : m_items) { + if (!p.is_wipe_tower) continue; + const auto tower_bb = p.boundingBox(); + const auto grown = p.inflation() + params.compacted_tower_growth; + if (std::max(iy1, tower_bb.minCorner().y() + grown) - std::min(iy2, tower_bb.maxCorner().y() - grown) < scaled(params.clearance_dist_to_rod)) + score += LARGE_COST_TO_REJECT * 1.2; + } + } + std::set extruder_ids; for (int i = 0; i < m_items.size(); i++) { Item& p = m_items[i]; @@ -1247,6 +1276,15 @@ void _arrange( //sl::offset(corrected_bin, md); ArrangeParams mod_params = params; mod_params.min_obj_distance = 0; // items are already inflated + // Orca: aligning the finished pile would carry objects taller than the rod clearance back into + // the Y span of a compacted prime tower, which objfunc() has just kept them out of. A + // best_object_pos away from the bed centre makes the AutoArranger align the pile to it whatever + // do_final_align says, so that point goes back to the centre as well. + if (params.compacted_tower_growth >= 0 && + std::any_of(shapes.begin(), shapes.end(), [¶ms](const Item &itm) { return itm.height > params.clearance_height_to_rod; })) { + mod_params.do_final_align = false; + mod_params.align_center = Vec2d(0.5, 0.5); + } AutoArranger arranger{corrected_bin, mod_params, progressfn, stopfn}; diff --git a/src/libslic3r/Arrange.hpp b/src/libslic3r/Arrange.hpp index 2de7504089..bdf0ec6c14 100644 --- a/src/libslic3r/Arrange.hpp +++ b/src/libslic3r/Arrange.hpp @@ -156,6 +156,13 @@ struct ArrangeParams { float object_skirt_offset = 0; float nozzle_height = 0; float printable_height = 256.0; + // Orca: whether the prime tower stays low because "No sparse layers" drops its sparse layers, on a + // plate printed by layer: the condition the slicer's clearance check applies. + bool compacted_tower = false; + // Orca: how far (scaled) the polygon of such a tower was grown past the tower itself, or negative + // when no tower was grown. + coord_t compacted_tower_growth = -1; + float clearance_dist_to_rod = 0; Vec2d align_center{ 0.5,0.5 }; // Belt printer: items print in the order they lie along the belt axis, from // its low end unless belt_reversed, and a part's top prints @@ -198,6 +205,7 @@ struct ArrangeParams { ret += "\"clearance_height_to_rod\":" + std::to_string(clearance_height_to_rod) + ","; ret += "\"clearance_height_to_lid\":" + std::to_string(clearance_height_to_lid) + ","; ret += "\"clearance_radius\":" + std::to_string(clearance_radius) + ","; + ret += "\"compacted_tower_growth\":" + std::to_string(compacted_tower_growth) + ","; ret += "\"printable_height\":" + std::to_string(printable_height) + ","; return ret; } @@ -214,6 +222,11 @@ void update_selected_items_inflation(ArrangePolygons& selected, const DynamicPri void update_unselected_items_inflation(ArrangePolygons& unselected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params); +// Orca: how far in mm the objects in placed have to stay from a prime tower compacted by "No sparse +// layers": MAX_OUTER_NOZZLE_DIAMETER when none of them is taller than params.nozzle_height, +// toolhead_radius otherwise or when placed is empty. +double compacted_tower_arrange_clearance(const ArrangePolygons& placed, const ArrangeParams& params, double toolhead_radius); + void update_selected_items_axis_align(ArrangePolygons& selected, const DynamicPrintConfig* print_cfg, const ArrangeParams& params); bool has_bed_exclusion_regions(const ArrangePolygons& polygons); diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index 08d9e4acc2..b78ca6f859 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -6,6 +6,9 @@ #include "libslic3r/PresetBundle.hpp" #include "libslic3r/ModelArrange.hpp" #include "libslic3r/IMEXArrange.hpp" +#include "libslic3r/ClipperUtils.hpp" +#include "libslic3r/Print.hpp" +#include "libslic3r/GCode/WipeTower.hpp" #include "slic3r/GUI/PartPlate.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" @@ -158,11 +161,58 @@ static WipeTower get_wipe_tower(const Plater &plater, int plate_idx) return WipeTower{plater.canvas3D()->get_wipe_tower_info(plate_idx)}; } -arrangement::ArrangePolygon get_wipetower_arrange_poly(WipeTower* tower) +// Orca: the gap in mm the arranger will leave around each of the objects it is about to place, which +// is the smallest inflation update_selected_items_inflation() gives them. It is worked out on copies, +// since the arrange jobs only inflate the objects after the tower is in place. +static double arranged_object_gap(const arrangement::ArrangeParams& params, const ArrangePolygons& selected, const DynamicPrintConfig* print_cfg) +{ + if (selected.empty()) + return 0.; + arrangement::ArrangeParams params_copy = params; + ArrangePolygons selected_copy = selected; + update_selected_items_inflation(selected_copy, print_cfg, params_copy); + const auto by_inflation = [](const ArrangePolygon& lhs, const ArrangePolygon& rhs) { return lhs.inflation < rhs.inflation; }; + return unscale(std::min_element(selected_copy.begin(), selected_copy.end(), by_inflation)->inflation); +} + +// Orca: a prime tower compacted by "No sparse layers" stays low, so the toolhead comes down beside it +// at every tool change. The objects in placed have to keep from it the clearance +// compacted_tower_arrange_clearance() gives, as they do from one another when printing by object, so +// the arranger is given the tower grown by that much, less the gap it keeps around those objects +// anyway. params.compacted_tower says whether the tower is compacted at all; once grown, +// params.compacted_tower_growth holds by how much (scaled) the polygon now reaches past the tower's +// own zone, which the arranger needs to find the tower's Y span again. +static void grow_compacted_wipe_tower(arrangement::ArrangePolygon& ap, arrangement::ArrangeParams& params, const ArrangePolygons& placed) +{ + if (!params.compacted_tower || ap.poly.contour.points.empty()) + return; + + // The config init_arrange_params() read params from. + Plater* plater = wxGetApp().plater(); + const PrintConfig& config = plater->get_partplate_list().get_current_fff_print().config(); + // The tower's polygon holds its brim already, both the one of a tower already there and the + // estimated one, so only the margin for the line width is left to add. + const Polygons footprint = offset(ap.poly.contour, float(scale_(compacted_tower_footprint_padding(config, 0.)))); + if (footprint.empty()) + return; + const CompactedTowerZone zone = compacted_wipe_tower_zone(config, footprint.front()); + if (zone.empty()) + return; + const double clearance = compacted_tower_arrange_clearance(placed, params, zone.body_radius); + const coord_t growth = scaled(std::max(0., clearance - arranged_object_gap(params, placed, plater->config()))); + const Polygons grown = offset(zone.hull, float(growth), jtRound, scale_(0.1)); + if (grown.empty()) + return; + ap.poly.contour = grown.front(); + params.compacted_tower_growth = growth; +} + +arrangement::ArrangePolygon get_wipetower_arrange_poly(WipeTower* tower, arrangement::ArrangeParams& params, const ArrangePolygons& placed) { ArrangePolygon ap = tower->get_arrange_polygon(); ap.bed_idx = 0; ap.setter = NULL; // do not move wipe tower + grow_compacted_wipe_tower(ap, params, placed); return ap; } @@ -509,7 +559,7 @@ void ArrangeJob::prepare_wipe_tower() continue; if (auto wti = get_wipe_tower(*m_plater, bedid)) { // wipe tower is already there - wipe_tower_ap = get_wipetower_arrange_poly(&wti); + wipe_tower_ap = get_wipetower_arrange_poly(&wti, params, m_selected); wipe_tower_ap.bed_idx = bedid_unlocked; m_unselected.emplace_back(wipe_tower_ap); } @@ -520,6 +570,7 @@ void ArrangeJob::prepare_wipe_tower() extruder_ids.insert(plate_extruders.begin(), plate_extruders.end()); } wipe_tower_ap = estimate_wipe_tower_info(bedid, extruder_ids); + grow_compacted_wipe_tower(wipe_tower_ap, params, m_selected); wipe_tower_ap.bed_idx = bedid_unlocked; m_unselected.emplace_back(wipe_tower_ap); } @@ -585,7 +636,7 @@ void ArrangeJob::prepare_partplate() { // BBS if (auto wti = get_wipe_tower(*m_plater, current_plate_index)) { - ArrangePolygon&& ap = get_wipetower_arrange_poly(&wti); + ArrangePolygon&& ap = get_wipetower_arrange_poly(&wti, params, m_selected); m_unselected.emplace_back(std::move(ap)); } @@ -962,11 +1013,11 @@ void ArrangeJob::finalize(bool canceled, std::exception_ptr &eptr) { } std::optional -get_wipe_tower_arrangepoly(const Plater &plater) +get_wipe_tower_arrangepoly(const Plater &plater, arrangement::ArrangeParams ¶ms, const arrangement::ArrangePolygons &placed) { int id = plater.canvas3D()->fff_print()->get_plate_index(); if (auto wti = get_wipe_tower(plater, id)) - return get_wipetower_arrange_poly(&wti); + return get_wipetower_arrange_poly(&wti, params, placed); return {}; } @@ -994,6 +1045,7 @@ arrangement::ArrangeParams init_arrange_params(Plater *p) params.clearance_height_to_rod = print_config.extruder_clearance_height_to_rod.value; params.clearance_height_to_lid = print_config.extruder_clearance_height_to_lid.value; + params.clearance_dist_to_rod = print_config.extruder_clearance_dist_to_rod.value; params.clearance_radius = print_config.extruder_clearance_radius.value + object_skirt_offset * 2; params.object_skirt_offset = object_skirt_offset; params.printable_height = print_config.printable_height.value; @@ -1034,6 +1086,11 @@ arrangement::ArrangeParams init_arrange_params(Plater *p) params.bed_shrink_x = BED_SHRINK_SEQ_PRINT; params.bed_shrink_y = BED_SHRINK_SEQ_PRINT; } + + // Orca: the same condition as the slicer's clearance check for a compacted prime tower. Smooth + // timelapse and wrapping detection keep the tower at full height, and printing by object has a + // clearance check of its own. + params.compacted_tower = !params.is_seq_print && wipe_tower_sparse_layers_skipped(print_config); return params; } diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.hpp b/src/slic3r/GUI/Jobs/ArrangeJob.hpp index 4383174f56..f0b35645c7 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.hpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.hpp @@ -101,7 +101,12 @@ public: void finalize(bool canceled, std::exception_ptr &e) override; }; -std::optional get_wipe_tower_arrangepoly(const Plater &); +// The prime tower of the plate being sliced, to arrange around. A tower compacted by "No sparse +// layers" comes grown by the clearance the objects in placed need from it, which is then recorded in +// params; the inflation they will get counts towards it, so leave placed empty when they get none, +// and the tower keeps the whole toolhead radius. +std::optional get_wipe_tower_arrangepoly(const Plater &, arrangement::ArrangeParams ¶ms, + const arrangement::ArrangePolygons &placed = {}); // The gap between logical beds in the x axis expressed in ratio of // the current bed width. diff --git a/src/slic3r/GUI/Jobs/FillBedJob.cpp b/src/slic3r/GUI/Jobs/FillBedJob.cpp index e30d3df9c4..3f4017e279 100644 --- a/src/slic3r/GUI/Jobs/FillBedJob.cpp +++ b/src/slic3r/GUI/Jobs/FillBedJob.cpp @@ -166,7 +166,7 @@ void FillBedJob::prepare() m_unselected.emplace_back(ap); }*/ - if (auto wt = get_wipe_tower_arrangepoly(*m_plater)) + if (auto wt = get_wipe_tower_arrangepoly(*m_plater, params, m_selected)) m_unselected.emplace_back(std::move(*wt)); double sc = scaled(1.) * scaled(1.); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 03c2bd36ef..fecac3a46f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -11281,7 +11281,9 @@ void Plater::find_new_position(const ModelInstancePtrs &instances) } } - if (auto wt = get_wipe_tower_arrangepoly(*this)) + // The objects placed here are not inflated, so none are passed and the tower keeps the whole + // toolhead radius. + if (auto wt = get_wipe_tower_arrangepoly(*this, arr_params)) fixed.emplace_back(*wt); arrangement::arrange(movable, fixed, this->build_volume().polygon(), arr_params); diff --git a/tests/libslic3r/test_arrange.cpp b/tests/libslic3r/test_arrange.cpp index 5e335aecd8..565a4d5f30 100644 --- a/tests/libslic3r/test_arrange.cpp +++ b/tests/libslic3r/test_arrange.cpp @@ -1109,3 +1109,67 @@ TEST_CASE("Arrange keeps relevant objects outside conditional exclusion obstacle } require_no_overlap(items); } + +TEST_CASE("Objects taller than the rod clearance stay out of the Y span of a compacted prime tower", "[Arrange]") +{ + // A tower spanning Y 180..240 at the right edge of the bed, with no extra growth on its polygon. + ArrangePolygon tower; + Polygon outline; + outline.points = {Point(scaled(180.), scaled(180.)), Point(scaled(240.), scaled(180.)), Point(scaled(240.), scaled(240.)), Point(scaled(180.), scaled(240.))}; + tower.poly = ExPolygon(outline); + tower.bed_idx = 0; + tower.is_virt_object = true; + tower.is_wipe_tower = true; + + ArrangeParams params = quiet_params(scaled(2.)); + params.clearance_height_to_rod = 24.f; + params.clearance_dist_to_rod = 40.f; + params.compacted_tower_growth = 0; + + // The pile gathers around the tower, so without the rule the objects end up beside it. A + // best_object_pos away from the bed centre, as some printer profiles set, must not carry the + // pile back into the span either. + for (const Vec2d &align_center : {Vec2d(0.5, 0.5), Vec2d(0.3, 0.5), Vec2d(0.7, 0.5), Vec2d(0.5, 0.7)}) { + INFO("best_object_pos " << align_center.x() << "x" << align_center.y()); + params.align_center = align_center; + ArrangePolygons items = squares(4, 40., 50.); + arrange(items, {tower}, bed(250, 250), params); + + for (const ArrangePolygon &ap : items) { + REQUIRE(ap.bed_idx == 0); + CHECK(ap.transformed_poly().contour.bounding_box().max.y() <= scaled(180. - 40.)); + } + } + + // Objects that stay under the rod may share the span. + params.align_center = Vec2d(0.5, 0.5); + ArrangePolygons low = squares(4, 40., 10.); + arrange(low, {tower}, bed(250, 250), params); + CHECK(std::any_of(low.begin(), low.end(), [](const ArrangePolygon &ap) { + return ap.transformed_poly().contour.bounding_box().max.y() > scaled(180. - 40.); + })); +} + +TEST_CASE("Objects no taller than the nozzle height only keep the nozzle cone from a compacted prime tower", "[Arrange]") +{ + // A K2: toolhead radius 64 mm, nozzle height 4 mm. + const double toolhead_radius = 64.; + ArrangeParams params; + params.nozzle_height = 4.f; + + ArrangePolygon keychain; + keychain.height = 3.; + ArrangePolygon at_nozzle_height; + at_nozzle_height.height = 4.; + ArrangePolygon tall; + tall.height = 30.; + + using Catch::Matchers::WithinAbs; + CHECK_THAT(compacted_tower_arrange_clearance({keychain, at_nozzle_height}, params, toolhead_radius), WithinAbs(MAX_OUTER_NOZZLE_DIAMETER, EPSILON)); + // The tower is one polygon for all the objects placed, so one taller object gives every one of + // them the toolhead radius. + CHECK_THAT(compacted_tower_arrange_clearance({keychain, tall}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON)); + CHECK_THAT(compacted_tower_arrange_clearance({tall}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON)); + // find_new_position() passes no objects. + CHECK_THAT(compacted_tower_arrange_clearance({}, params, toolhead_radius), WithinAbs(toolhead_radius, EPSILON)); +}