Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Arrange.hpp « libslic3r « src - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bc23108cd7d6e1d2af515cbd4d25f8e1051c71f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef MODELARRANGE_HPP
#define MODELARRANGE_HPP

#include "ExPolygon.hpp"
#include "BoundingBox.hpp"

namespace Slic3r {

namespace arrangement {

/// A geometry abstraction for a circular print bed. Similarly to BoundingBox.
class CircleBed {
    Point center_;
    double radius_;
public:

    inline CircleBed(): center_(0, 0), radius_(std::nan("")) {}
    inline CircleBed(const Point& c, double r): center_(c), radius_(r) {}

    inline double radius() const { return radius_; }
    inline const Point& center() const { return center_; }
    inline operator bool() { return !std::isnan(radius_); }
};

/// Representing an unbounded bin
struct InfiniteBed { Point center; };

/// Types of print bed shapes.
enum class BedShapeType {
    BOX,
    CIRCLE,
    IRREGULAR,
    INFINITE,
    UNKNOWN
};

/// Info about the print bed for the arrange() function.
struct BedShapeHint {
    BedShapeType type = BedShapeType::INFINITE;
    union BedShape_u {  // I know but who cares... TODO: use variant from cpp17?
        CircleBed   circ;
        BoundingBox box;
        Polyline    polygon;
        InfiniteBed infinite{};
        ~BedShape_u() {}
        BedShape_u() {};
    } shape;
    
    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;
    }
};

/// Get a bed shape hint for arrange() from a naked Polyline.
BedShapeHint bedShape(const Polyline& bed);

static const constexpr long UNARRANGED = -1;

struct ArrangePolygon {
    const ExPolygon poly;
    Vec2crd   translation{0, 0};
    double    rotation{0.0};
    long      bed_idx{UNARRANGED};
    
    ArrangePolygon(const ExPolygon &p, const Vec2crd &tr = {}, double rot = 0.0)
        : poly{p}, translation{tr}, rotation{rot}
    {}
};

using ArrangePolygons = std::vector<ArrangePolygon>;

/**
 * \brief Arranges the model objects on the screen.
 *
 * 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.
 *
 * \param stopcondition A predicate returning true if abort is needed.
 */
void arrange(ArrangePolygons &             items,
             coord_t                       min_obj_distance,
             const BedShapeHint &          bedhint,
             std::function<void(unsigned)> progressind   = nullptr,
             std::function<bool(void)>     stopcondition = nullptr);

/// Same as the previous, only that it takes unmovable items as an
/// additional argument.
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);

}   // arr
}   // Slic3r
#endif // MODELARRANGE_HPP