From 5783cc62fb02c7433b119026ffcbd574d853fd6d Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Mon, 26 Apr 2021 09:21:16 +0200 Subject: [PATCH] Wipe tower priming lines are placed at origin with custom bed shapes Custom shapes were previously detected as circular and the lines were placed off the bed --- src/libslic3r/GCode/WipeTower.cpp | 20 +++++++++++++++++--- src/libslic3r/GCode/WipeTower.hpp | 3 ++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/GCode/WipeTower.cpp b/src/libslic3r/GCode/WipeTower.cpp index 10c68d076..86a6616ee 100644 --- a/src/libslic3r/GCode/WipeTower.cpp +++ b/src/libslic3r/GCode/WipeTower.cpp @@ -546,10 +546,24 @@ WipeTower::WipeTower(const PrintConfig& config, const std::vector& bed_points = config.bed_shape.values; + BoundingBoxf bb(bed_points); + m_bed_width = float(bb.size().x()); m_bed_shape = (bed_points.size() == 4 ? RectangularBed : CircularBed); - m_bed_width = float(BoundingBoxf(bed_points).size().x()); + + if (m_bed_shape == CircularBed) { + // this may still be a custom bed, check that the points are roughly on a circle + double r2 = std::pow(m_bed_width/2., 2.); + double lim2 = std::pow(m_bed_width/10., 2.); + Vec2d center = bb.center(); + for (const Vec2d& pt : bed_points) + if (std::abs(std::pow(pt.x()-center.x(), 2.) + std::pow(pt.y()-center.y(), 2.) - r2) > lim2) { + m_bed_shape = CustomBed; + break; + } + } + m_bed_bottom_left = m_bed_shape == RectangularBed ? Vec2f(bed_points.front().x(), bed_points.front().y()) : Vec2f::Zero(); @@ -628,7 +642,7 @@ std::vector WipeTower::prime( // In case of a circular bed, place it so it goes across the diameter and hope it will fit if (m_bed_shape == CircularBed) cleaning_box.translate(-m_bed_width/2 + m_bed_width * 0.03f, -m_bed_width * 0.12f); - if (m_bed_shape == RectangularBed) + else cleaning_box.translate(m_bed_bottom_left); std::vector results; diff --git a/src/libslic3r/GCode/WipeTower.hpp b/src/libslic3r/GCode/WipeTower.hpp index c3b2770b7..6fd7a8e21 100644 --- a/src/libslic3r/GCode/WipeTower.hpp +++ b/src/libslic3r/GCode/WipeTower.hpp @@ -277,7 +277,8 @@ private: // Bed properties enum { RectangularBed, - CircularBed + CircularBed, + CustomBed } m_bed_shape; float m_bed_width; // width of the bed bounding box Vec2f m_bed_bottom_left; // bottom-left corner coordinates (for rectangular beds)