diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index c0fcd7f4b8..1d73cd1fe7 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -548,19 +548,11 @@ std::vector Print::layers_sorted_for_object(float start, float end, std: StringObjectException Print::sequential_print_clearance_valid(const Print &print, Polygons *polygons, std::vector>* height_polygons) { StringObjectException single_object_exception; - auto print_config = print.config(); - Pointfs excluse_area_points = print_config.bed_exclude_area.values; - Polygons exclude_polys; - Polygon exclude_poly; + const auto& print_config = print.config(); + Polygons exclude_polys = get_bed_excluded_area(print_config); const Vec3d print_origin = print.get_plate_origin(); - for (int i = 0; i < excluse_area_points.size(); i++) { - auto pt = excluse_area_points[i]; - exclude_poly.points.emplace_back(scale_(pt.x() + print_origin.x()), scale_(pt.y() + print_origin.y())); - if (i % 4 == 3) { // exclude areas are always rectangle - exclude_polys.push_back(exclude_poly); - exclude_poly.points.clear(); - } - } + std::for_each(exclude_polys.begin(), exclude_polys.end(), + [&print_origin](Polygon& p) { p.translate(scale_(print_origin.x()), scale_(print_origin.y())); }); std::map map_model_object_to_convex_hull; struct print_instance_info @@ -887,19 +879,11 @@ static StringObjectException layered_print_cleareance_valid(const Print &print, if (print_instances_ordered.size() < 1) return {}; - auto print_config = print.config(); - Pointfs excluse_area_points = print_config.bed_exclude_area.values; - Polygons exclude_polys; - Polygon exclude_poly; + const auto& print_config = print.config(); + Polygons exclude_polys = get_bed_excluded_area(print_config); const Vec3d print_origin = print.get_plate_origin(); - for (int i = 0; i < excluse_area_points.size(); i++) { - auto pt = excluse_area_points[i]; - exclude_poly.points.emplace_back(scale_(pt.x() + print_origin.x()), scale_(pt.y() + print_origin.y())); - if (i % 4 == 3) { // exclude areas are always rectangle - exclude_polys.push_back(exclude_poly); - exclude_poly.points.clear(); - } - } + std::for_each(exclude_polys.begin(), exclude_polys.end(), + [&print_origin](Polygon& p) { p.translate(scale_(print_origin.x()), scale_(print_origin.y())); }); std::map map_model_object_to_convex_hull; // sequential_print_horizontal_clearance_valid diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 19903d7a90..77f4d25b12 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -8154,22 +8154,27 @@ Points get_bed_shape(const PrintConfig &cfg) Points get_bed_shape(const SLAPrinterConfig &cfg) { return to_points(make_counter_clockwise(cfg.printable_area.values)); } +Polygons get_bed_excluded_area(const PrintConfig& cfg) +{ + const Pointfs exclude_area_points = cfg.bed_exclude_area.values; + + Polygon exclude_poly; + for (int i = 0; i < exclude_area_points.size(); i++) { + auto pt = exclude_area_points[i]; + exclude_poly.points.emplace_back(scale_(pt.x()), scale_(pt.y())); + } + + exclude_poly.make_counter_clockwise(); + + return {exclude_poly}; +} + Polygon get_bed_shape_with_excluded_area(const PrintConfig& cfg) { Polygon bed_poly; bed_poly.points = get_bed_shape(cfg); - Points excluse_area_points = to_points(cfg.bed_exclude_area.values); - Polygons exclude_polys; - Polygon exclude_poly; - for (int i = 0; i < excluse_area_points.size(); i++) { - auto pt = excluse_area_points[i]; - exclude_poly.points.emplace_back(pt); - if (i % 4 == 3) { // exclude areas are always rectangle - exclude_polys.push_back(exclude_poly); - exclude_poly.points.clear(); - } - } + Polygons exclude_polys = get_bed_excluded_area(cfg); auto tmp = diff({ bed_poly }, exclude_polys); if (!tmp.empty()) bed_poly = tmp[0]; return bed_poly; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index f99b560592..95540005b4 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1738,6 +1738,7 @@ bool is_XL_printer(const PrintConfig &cfg); Points get_bed_shape(const DynamicPrintConfig &cfg); Points get_bed_shape(const PrintConfig &cfg); Points get_bed_shape(const SLAPrinterConfig &cfg); +Slic3r::Polygons get_bed_excluded_area(const PrintConfig& cfg); Slic3r::Polygon get_bed_shape_with_excluded_area(const PrintConfig& cfg); bool has_skirt(const DynamicPrintConfig& cfg); float get_real_skirt_dist(const DynamicPrintConfig& cfg); diff --git a/src/slic3r/GUI/Jobs/ArrangeJob.cpp b/src/slic3r/GUI/Jobs/ArrangeJob.cpp index b83b5743ae..95ec5c448c 100644 --- a/src/slic3r/GUI/Jobs/ArrangeJob.cpp +++ b/src/slic3r/GUI/Jobs/ArrangeJob.cpp @@ -458,17 +458,7 @@ void ArrangeJob::prepare() auto& print = wxGetApp().plater()->get_partplate_list().get_current_fff_print(); auto print_config = print.config(); bed_poly.points = get_bed_shape(*m_plater->config()); - Pointfs excluse_area_points = print_config.bed_exclude_area.values; - Polygons exclude_polys; - Polygon exclude_poly; - for (int i = 0; i < excluse_area_points.size(); i++) { - auto pt = excluse_area_points[i]; - exclude_poly.points.emplace_back(scale_(pt.x()), scale_(pt.y())); - if (i % 4 == 3) { // exclude areas are always rectangle - exclude_polys.push_back(exclude_poly); - exclude_poly.points.clear(); - } - } + Polygons exclude_polys = get_bed_excluded_area(print_config); bed_poly = diff({ bed_poly }, exclude_polys)[0]; }