1 #ifndef MODELARRANGE_HPP
2 #define MODELARRANGE_HPP
3
4 #include <libslic3r/Arrange.hpp>
5
6 namespace Slic3r {
7
8 class Model;
9 class ModelInstance;
10 using ModelInstancePtrs = std::vector<ModelInstance*>;
11
12 using arrangement::ArrangePolygon;
13 using arrangement::ArrangePolygons;
14 using arrangement::ArrangeParams;
15 using arrangement::InfiniteBed;
16 using arrangement::CircleBed;
17
18 // Do something with ArrangePolygons in virtual beds
19 using VirtualBedFn = std::function<void(arrangement::ArrangePolygon&)>;
20
throw_if_out_of_bed(arrangement::ArrangePolygon &)21 [[noreturn]] inline void throw_if_out_of_bed(arrangement::ArrangePolygon&)
22 {
23 throw Slic3r::RuntimeError("Objects could not fit on the bed");
24 }
25
26 ArrangePolygons get_arrange_polys(const Model &model, ModelInstancePtrs &instances);
27 ArrangePolygon get_arrange_poly(const Model &model);
28 bool apply_arrange_polys(ArrangePolygons &polys, ModelInstancePtrs &instances, VirtualBedFn);
29
30 void duplicate(Model &model, ArrangePolygons &copies, VirtualBedFn);
31 void duplicate_objects(Model &model, size_t copies_num);
32
33 template<class TBed>
arrange_objects(Model & model,const TBed & bed,const ArrangeParams & params,VirtualBedFn vfn=throw_if_out_of_bed)34 bool arrange_objects(Model & model,
35 const TBed & bed,
36 const ArrangeParams ¶ms,
37 VirtualBedFn vfn = throw_if_out_of_bed)
38 {
39 ModelInstancePtrs instances;
40 auto&& input = get_arrange_polys(model, instances);
41 arrangement::arrange(input, bed, params);
42
43 return apply_arrange_polys(input, instances, vfn);
44 }
45
46 template<class TBed>
duplicate(Model & model,size_t copies_num,const TBed & bed,const ArrangeParams & params,VirtualBedFn vfn=throw_if_out_of_bed)47 void duplicate(Model & model,
48 size_t copies_num,
49 const TBed & bed,
50 const ArrangeParams ¶ms,
51 VirtualBedFn vfn = throw_if_out_of_bed)
52 {
53 ArrangePolygons copies(copies_num, get_arrange_poly(model));
54 arrangement::arrange(copies, bed, params);
55 duplicate(model, copies, vfn);
56 }
57
58 template<class TBed>
duplicate_objects(Model & model,size_t copies_num,const TBed & bed,const ArrangeParams & params,VirtualBedFn vfn=throw_if_out_of_bed)59 void duplicate_objects(Model & model,
60 size_t copies_num,
61 const TBed & bed,
62 const ArrangeParams ¶ms,
63 VirtualBedFn vfn = throw_if_out_of_bed)
64 {
65 duplicate_objects(model, copies_num);
66 arrange_objects(model, bed, params, vfn);
67 }
68
69 }
70
71 #endif // MODELARRANGE_HPP
72