2018-07-30 14:41:35 +00:00
|
|
|
#ifndef MODELARRANGE_HPP
|
|
|
|
#define MODELARRANGE_HPP
|
|
|
|
|
2019-07-12 19:03:49 +00:00
|
|
|
#include "ExPolygon.hpp"
|
2019-06-26 15:09:26 +00:00
|
|
|
#include "BoundingBox.hpp"
|
2018-08-03 10:37:27 +00:00
|
|
|
|
2018-07-30 14:41:35 +00:00
|
|
|
namespace Slic3r {
|
2018-08-02 11:15:30 +00:00
|
|
|
|
2019-07-01 16:22:07 +00:00
|
|
|
namespace arrangement {
|
2018-07-30 14:41:35 +00:00
|
|
|
|
2019-06-28 16:27:15 +00:00
|
|
|
/// A geometry abstraction for a circular print bed. Similarly to BoundingBox.
|
2019-06-28 15:03:50 +00:00
|
|
|
class CircleBed {
|
2018-08-03 12:49:26 +00:00
|
|
|
Point center_;
|
|
|
|
double radius_;
|
|
|
|
public:
|
|
|
|
|
2019-06-28 15:03:50 +00:00
|
|
|
inline CircleBed(): center_(0, 0), radius_(std::nan("")) {}
|
|
|
|
inline CircleBed(const Point& c, double r): center_(c), radius_(r) {}
|
2018-08-03 12:49:26 +00:00
|
|
|
|
|
|
|
inline double radius() const { return radius_; }
|
|
|
|
inline const Point& center() const { return center_; }
|
2018-08-06 09:30:10 +00:00
|
|
|
inline operator bool() { return !std::isnan(radius_); }
|
2018-08-03 12:49:26 +00:00
|
|
|
};
|
|
|
|
|
2019-07-01 16:22:07 +00:00
|
|
|
/// Representing an unbounded bin
|
|
|
|
struct InfiniteBed { Point center; };
|
|
|
|
|
2019-06-28 16:27:15 +00:00
|
|
|
/// Types of print bed shapes.
|
2018-08-03 12:49:26 +00:00
|
|
|
enum class BedShapeType {
|
2018-08-02 11:15:30 +00:00
|
|
|
BOX,
|
|
|
|
CIRCLE,
|
|
|
|
IRREGULAR,
|
2019-07-01 16:22:07 +00:00
|
|
|
INFINITE,
|
|
|
|
UNKNOWN
|
2018-08-02 11:15:30 +00:00
|
|
|
};
|
|
|
|
|
2019-06-28 16:27:15 +00:00
|
|
|
/// Info about the print bed for the arrange() function.
|
2018-08-03 12:49:26 +00:00
|
|
|
struct BedShapeHint {
|
2019-07-01 16:22:07 +00:00
|
|
|
BedShapeType type = BedShapeType::INFINITE;
|
2019-07-12 19:03:49 +00:00
|
|
|
union BedShape_u { // I know but who cares... TODO: use variant from cpp17?
|
2019-07-01 16:22:07 +00:00
|
|
|
CircleBed circ;
|
2018-08-03 12:49:26 +00:00
|
|
|
BoundingBox box;
|
2019-07-01 16:22:07 +00:00
|
|
|
Polyline polygon;
|
2019-07-12 19:03:49 +00:00
|
|
|
InfiniteBed infinite{};
|
|
|
|
~BedShape_u() {}
|
|
|
|
BedShape_u() {};
|
2018-08-03 12:49:26 +00:00
|
|
|
} shape;
|
2019-07-12 19:03:49 +00:00
|
|
|
|
|
|
|
BedShapeHint() {};
|
|
|
|
|
|
|
|
~BedShapeHint() {
|
|
|
|
if (type == BedShapeType::IRREGULAR)
|
|
|
|
shape.polygon.Slic3r::Polyline::~Polyline();
|
|
|
|
};
|
|
|
|
|
|
|
|
BedShapeHint(const BedShapeHint &cpy) {
|
|
|
|
*this = cpy;
|
|
|
|
}
|
|
|
|
|
|
|
|
BedShapeHint& operator=(const BedShapeHint &cpy) {
|
|
|
|
type = cpy.type;
|
|
|
|
switch(type) {
|
|
|
|
case BedShapeType::BOX: shape.box = cpy.shape.box; break;
|
|
|
|
case BedShapeType::CIRCLE: shape.circ = cpy.shape.circ; break;
|
|
|
|
case BedShapeType::IRREGULAR: shape.polygon = cpy.shape.polygon; break;
|
|
|
|
case BedShapeType::INFINITE: shape.infinite = cpy.shape.infinite; break;
|
|
|
|
case BedShapeType::UNKNOWN: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
2018-08-03 12:49:26 +00:00
|
|
|
};
|
|
|
|
|
2019-06-28 16:27:15 +00:00
|
|
|
/// Get a bed shape hint for arrange() from a naked Polyline.
|
2018-11-12 13:52:52 +00:00
|
|
|
BedShapeHint bedShape(const Polyline& bed);
|
2018-08-02 11:15:30 +00:00
|
|
|
|
2019-07-12 19:03:49 +00:00
|
|
|
static const constexpr long UNARRANGED = -1;
|
|
|
|
|
|
|
|
struct ArrangePolygon {
|
|
|
|
const ExPolygon poly;
|
|
|
|
Vec2crd translation{0, 0};
|
|
|
|
double rotation{0.0};
|
|
|
|
long bed_idx{UNARRANGED};
|
2019-06-26 15:09:26 +00:00
|
|
|
|
2019-07-12 19:03:49 +00:00
|
|
|
ArrangePolygon(const ExPolygon &p, const Vec2crd &tr = {}, double rot = 0.0)
|
|
|
|
: poly{p}, translation{tr}, rotation{rot}
|
|
|
|
{}
|
2019-04-29 12:32:02 +00:00
|
|
|
};
|
|
|
|
|
2019-07-12 19:03:49 +00:00
|
|
|
using ArrangePolygons = std::vector<ArrangePolygon>;
|
2019-06-26 15:09:26 +00:00
|
|
|
|
2018-07-30 14:41:35 +00:00
|
|
|
/**
|
|
|
|
* \brief Arranges the model objects on the screen.
|
|
|
|
*
|
2019-06-28 16:27:15 +00:00
|
|
|
* The arrangement considers multiple bins (aka. print beds) for placing
|
|
|
|
* all the items provided in the model argument. If the items don't fit on
|
|
|
|
* one print bed, the remaining will be placed onto newly created print
|
|
|
|
* beds. The first_bin_only parameter, if set to true, disables this
|
|
|
|
* behavior and makes sure that only one print bed is filled and the
|
|
|
|
* remaining items will be untouched. When set to false, the items which
|
|
|
|
* could not fit onto the print bed will be placed next to the print bed so
|
|
|
|
* the user should see a pile of items on the print bed and some other
|
|
|
|
* piles outside the print area that can be dragged later onto the print
|
|
|
|
* bed as a group.
|
|
|
|
*
|
|
|
|
* \param items Input which are object pointers implementing the
|
|
|
|
* Arrangeable interface.
|
|
|
|
*
|
|
|
|
* \param min_obj_distance The minimum distance which is allowed for any
|
|
|
|
* pair of items on the print bed in any direction.
|
|
|
|
*
|
|
|
|
* \param bedhint Info about the shape and type of the
|
|
|
|
* bed. remaining items which do not fit onto the print area next to the
|
|
|
|
* print bed or leave them untouched (let the user arrange them by hand or
|
|
|
|
* remove them).
|
|
|
|
*
|
|
|
|
* \param progressind Progress indicator callback called when
|
|
|
|
* an object gets packed. The unsigned argument is the number of items
|
|
|
|
* remaining to pack.
|
2018-07-30 14:41:35 +00:00
|
|
|
*
|
2018-09-17 13:12:13 +00:00
|
|
|
* \param stopcondition A predicate returning true if abort is needed.
|
2018-07-30 14:41:35 +00:00
|
|
|
*/
|
2019-07-12 19:03:49 +00:00
|
|
|
void arrange(ArrangePolygons & items,
|
|
|
|
coord_t min_obj_distance,
|
|
|
|
const BedShapeHint & bedhint,
|
|
|
|
std::function<void(unsigned)> progressind = nullptr,
|
|
|
|
std::function<bool(void)> stopcondition = nullptr);
|
2018-08-03 12:49:26 +00:00
|
|
|
|
2019-06-28 16:27:15 +00:00
|
|
|
/// Same as the previous, only that it takes unmovable items as an
|
|
|
|
/// additional argument.
|
2019-07-12 19:03:49 +00:00
|
|
|
void arrange(ArrangePolygons & items,
|
|
|
|
const ArrangePolygons & excludes,
|
|
|
|
coord_t min_obj_distance,
|
|
|
|
const BedShapeHint & bedhint,
|
|
|
|
std::function<void(unsigned)> progressind = nullptr,
|
|
|
|
std::function<bool(void)> stopcondition = nullptr);
|
2018-07-30 14:41:35 +00:00
|
|
|
|
2019-01-22 16:50:33 +00:00
|
|
|
} // arr
|
|
|
|
} // Slic3r
|
2018-07-30 14:41:35 +00:00
|
|
|
#endif // MODELARRANGE_HPP
|