WIP still with arrange return value.

This commit is contained in:
tamasmeszaros 2019-07-03 19:24:41 +02:00
parent b5215dae1b
commit e81f8a5fd9
8 changed files with 78 additions and 79 deletions

View File

@ -192,7 +192,7 @@ public:
return Unit(width())*height();
}
static inline _Box infinite(const P &center);
static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)});
};
template<class S> struct PointType<_Box<S>> {

View File

@ -908,7 +908,8 @@ private:
item.removeOffset();
});
if(stopfn_ && !stopfn_()) { // Ignore results if nesting was stopped.
if(!stopfn_ || (stopfn_ && !stopfn_())) {
// Ignore results if nesting was stopped.
const PackGroup& bins = lastResult();
unsigned binidx = 0;
for(auto& bin : bins) {

View File

@ -573,7 +573,7 @@ inline SLIC3R_CONSTEXPR coord_t stride_padding(coord_t w)
// a stop predicate can be also be passed to control the process.
bool arrange(ArrangeablePtrs & arrangables,
const ArrangeablePtrs & excludes,
coord_t min_obj_distance,
coord_t min_obj_dist,
const BedShapeHint & bedhint,
std::function<void(unsigned)> progressind,
std::function<bool()> stopcondition)
@ -615,13 +615,14 @@ bool arrange(ArrangeablePtrs & arrangables,
arrangeable,
items,
// callback called by arrange to apply the result on the arrangeable
[arrangeable, &binwidth](const Item &itm, unsigned binidx) {
[arrangeable, &binwidth, &ret](const Item &itm, unsigned binidx) {
ret = !binidx; // Return value false more bed is required
clppr::cInt stride = binidx * stride_padding(binwidth);
clppr::IntPoint offs = itm.translation();
arrangeable->apply_arrange_result({unscaled(offs.X + stride),
unscaled(offs.Y)},
itm.rotation());
itm.rotation(), binidx);
});
}
@ -629,60 +630,55 @@ bool arrange(ArrangeablePtrs & arrangables,
process_arrangeable(fixed, fixeditems, nullptr);
// Integer ceiling the min distance from the bed perimeters
coord_t md = min_obj_distance - SCALED_EPSILON;
coord_t md = min_obj_dist - SCALED_EPSILON;
md = (md % 2) ? md / 2 + 1 : md / 2;
auto &cfn = stopcondition;
auto &pri = progressind;
switch (bedhint.type) {
// case BedShapeType::BOX: {
// // Create the arranger for the box shaped bed
// BoundingBox bbb = bedhint.shape.box;
// bbb.min -= Point{md, md}, bbb.max += Point{md, md};
// Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}};
// binwidth = coord_t(binbb.width());
case BedShapeType::BOX: {
// Create the arranger for the box shaped bed
BoundingBox bbb = bedhint.shape.box;
bbb.min -= Point{md, md}, bbb.max += Point{md, md};
Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}};
binwidth = coord_t(binbb.width());
// _arrange(items, fixeditems, binbb, min_obj_distance, progressind, cfn);
// break;
// }
// case BedShapeType::CIRCLE: {
// auto c = bedhint.shape.circ;
// auto cc = to_lnCircle(c);
// binwidth = scaled(c.radius());
_arrange(items, fixeditems, binbb, min_obj_dist, pri, cfn);
break;
}
case BedShapeType::CIRCLE: {
auto c = bedhint.shape.circ;
auto cc = to_lnCircle(c);
binwidth = scaled(c.radius());
// _arrange(items, fixeditems, cc, min_obj_distance, progressind, cfn);
// break;
// }
// case BedShapeType::IRREGULAR: {
// auto ctour = Slic3rMultiPoint_to_ClipperPath(bedhint.shape.polygon);
// auto irrbed = sl::create<clppr::Polygon>(std::move(ctour));
// BoundingBox polybb(bedhint.shape.polygon);
// binwidth = (polybb.max(X) - polybb.min(X));
_arrange(items, fixeditems, cc, min_obj_dist, pri, cfn);
break;
}
case BedShapeType::IRREGULAR: {
auto ctour = Slic3rMultiPoint_to_ClipperPath(bedhint.shape.polygon);
auto irrbed = sl::create<clppr::Polygon>(std::move(ctour));
BoundingBox polybb(bedhint.shape.polygon);
binwidth = (polybb.max(X) - polybb.min(X));
// _arrange(items, fixeditems, irrbed, min_obj_distance, progressind, cfn);
// break;
// }
// case BedShapeType::INFINITE: {
// const InfiniteBed& nobin = bedhint.shape.infinite;
// Box infbb{{nobin.center.x(), nobin.center.y()}};
_arrange(items, fixeditems, irrbed, min_obj_dist, pri, cfn);
break;
}
case BedShapeType::INFINITE: {
const InfiniteBed& nobin = bedhint.shape.infinite;
auto infbb = Box::infinite({nobin.center.x(), nobin.center.y()});
// _arrange(items, fixeditems, infbb, min_obj_distance, progressind, cfn);
// break;
// }
// case BedShapeType::UNKNOWN: {
// // We know nothing about the bed, let it be infinite and zero centered
// _arrange(items, fixeditems, Box{}, min_obj_distance, progressind, cfn);
// break;
// }
default: {
Box infbb = Box::infinite({bedhint.shape.box.center().x(), bedhint.shape.box.center().y()});
_arrange(items, fixeditems, infbb, min_obj_distance, progressind, cfn);
_arrange(items, fixeditems, infbb, min_obj_dist, pri, cfn);
break;
}
case BedShapeType::UNKNOWN: {
// We know nothing about the bed, let it be infinite and zero centered
_arrange(items, fixeditems, Box::infinite(), min_obj_dist, pri, cfn);
break;
}
};
if(stopcondition()) return false;
if(stopcondition && stopcondition()) return false;
return ret;
}

View File

@ -58,7 +58,7 @@ public:
virtual ~Arrangeable() = default;
/// Apply the result transformation calculated by the arrangement.
virtual void apply_arrange_result(Vec2d offset, double rotation_rads) = 0;
virtual void apply_arrange_result(Vec2d offset, double rotation_rads, unsigned bed_num) = 0;
/// Get the 2D silhouette to arrange and an initial offset and rotation
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const = 0;

View File

@ -559,10 +559,10 @@ public:
// /////////////////////////////////////////////////////////////////////////
// Getting the input polygon for arrange
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const final;
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const override;
// Apply the arrange result on the ModelInstance
virtual void apply_arrange_result(Vec2d offs, double rot_rads) final
virtual void apply_arrange_result(Vec2d offs, double rot_rads, unsigned /*bed_num*/) override
{
// write the transformation data into the model instance
set_rotation(Z, rot_rads);

View File

@ -5739,7 +5739,7 @@ const SLAPrint* GLCanvas3D::sla_print() const
return (m_process == nullptr) ? nullptr : m_process->sla_print();
}
void GLCanvas3D::WipeTowerInfo::apply_arrange_result(Vec2d offset, double rotation_rads)
void GLCanvas3D::WipeTowerInfo::apply_arrange_result(Vec2d offset, double rotation_rads, unsigned /*bed_num*/)
{
m_pos = offset;
m_rotation = rotation_rads;

View File

@ -624,9 +624,9 @@ public:
return !std::isnan(m_pos.x()) && !std::isnan(m_pos.y());
}
virtual void apply_arrange_result(Vec2d offset, double rotation_rads) final;
virtual void apply_arrange_result(Vec2d offset, double rotation_rads, unsigned /*bed_num*/) override;
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const final
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const override
{
Polygon p({
{coord_t(0), coord_t(0)},

View File

@ -2483,32 +2483,34 @@ arrangement::BedShapeHint Plater::priv::get_bed_shape_hint() const {
}
void Plater::priv::ExclusiveJobGroup::ArrangeJob::process() {
static const auto arrangestr = _(L("Arranging"));
// FIXME: I don't know how to obtain the minimum distance, it depends
// on printer technology. I guess the following should work but it crashes.
double dist = 6; // PrintConfig::min_object_distance(config);
if (plater().printer_technology == ptFFF) {
dist = PrintConfig::min_object_distance(plater().config);
}
coord_t min_obj_distance = scaled(dist);
auto count = unsigned(m_selected.size());
arrangement::BedShapeHint bedshape = plater().get_bed_shape_hint();
plater().model.arrange_objects(6.f, nullptr);
// static const auto arrangestr = _(L("Arranging"));
try {
arrangement::arrange(m_selected, m_unselected, min_obj_distance,
bedshape,
[this, count](unsigned st) {
if (st > 0) // will not finalize after last one
update_status(count - st, arrangestr);
},
[this]() { return was_canceled(); });
} catch (std::exception & /*e*/) {
GUI::show_error(plater().q,
_(L("Could not arrange model objects! "
"Some geometries may be invalid.")));
}
// // FIXME: I don't know how to obtain the minimum distance, it depends
// // on printer technology. I guess the following should work but it crashes.
// double dist = 6; // PrintConfig::min_object_distance(config);
// if (plater().printer_technology == ptFFF) {
// dist = PrintConfig::min_object_distance(plater().config);
// }
// coord_t min_obj_distance = scaled(dist);
// auto count = unsigned(m_selected.size());
// arrangement::BedShapeHint bedshape = plater().get_bed_shape_hint();
// try {
// arrangement::arrange(m_selected, m_unselected, min_obj_distance,
// bedshape,
// [this, count](unsigned st) {
// if (st > 0) // will not finalize after last one
// update_status(count - st, arrangestr);
// },
// [this]() { return was_canceled(); });
// } catch (std::exception & /*e*/) {
// GUI::show_error(plater().q,
// _(L("Could not arrange model objects! "
// "Some geometries may be invalid.")));
// }
// finalize just here.
update_status(int(count),