Fixing the "last item doesn't fit" problem.

This commit is contained in:
tamasmeszaros 2018-08-02 13:15:30 +02:00
parent 6cdec7ac9a
commit a7ba51bd11
5 changed files with 399 additions and 219 deletions

View file

@ -294,6 +294,8 @@ void AppController::arrange_model()
supports_asynch()? std::launch::async : std::launch::deferred,
[this]()
{
using Coord = libnest2d::TCoord<libnest2d::PointImpl>;
unsigned count = 0;
for(auto obj : model_->objects) count += obj->instances.size();
@ -311,14 +313,25 @@ void AppController::arrange_model()
auto dist = print_ctl()->config().min_object_distance();
// Create the arranger config
auto min_obj_distance = static_cast<Coord>(dist/SCALING_FACTOR);
BoundingBoxf bb(print_ctl()->config().bed_shape.values);
auto& bedpoints = print_ctl()->config().bed_shape.values;
Polyline bed; bed.points.reserve(bedpoints.size());
for(auto& v : bedpoints)
bed.append(Point::new_scale(v.x, v.y));
if(pind) pind->update(0, _(L("Arranging objects...")));
try {
arr::arrange(*model_, dist, &bb, false, [pind, count](unsigned rem){
if(pind) pind->update(count - rem, _(L("Arranging objects...")));
arr::arrange(*model_,
min_obj_distance,
bed,
arr::BOX,
false, // create many piles not just one pile
[pind, count](unsigned rem) {
if(pind)
pind->update(count - rem, _(L("Arranging objects...")));
});
} catch(std::exception& e) {
std::cerr << e.what() << std::endl;