WIP still with arrange return value.
This commit is contained in:
parent
b5215dae1b
commit
e81f8a5fd9
@ -192,7 +192,7 @@ public:
|
|||||||
return Unit(width())*height();
|
return Unit(width())*height();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline _Box infinite(const P ¢er);
|
static inline _Box infinite(const P ¢er = {TCoord<P>(0), TCoord<P>(0)});
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class S> struct PointType<_Box<S>> {
|
template<class S> struct PointType<_Box<S>> {
|
||||||
|
@ -908,7 +908,8 @@ private:
|
|||||||
item.removeOffset();
|
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();
|
const PackGroup& bins = lastResult();
|
||||||
unsigned binidx = 0;
|
unsigned binidx = 0;
|
||||||
for(auto& bin : bins) {
|
for(auto& bin : bins) {
|
||||||
|
@ -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.
|
// a stop predicate can be also be passed to control the process.
|
||||||
bool arrange(ArrangeablePtrs & arrangables,
|
bool arrange(ArrangeablePtrs & arrangables,
|
||||||
const ArrangeablePtrs & excludes,
|
const ArrangeablePtrs & excludes,
|
||||||
coord_t min_obj_distance,
|
coord_t min_obj_dist,
|
||||||
const BedShapeHint & bedhint,
|
const BedShapeHint & bedhint,
|
||||||
std::function<void(unsigned)> progressind,
|
std::function<void(unsigned)> progressind,
|
||||||
std::function<bool()> stopcondition)
|
std::function<bool()> stopcondition)
|
||||||
@ -615,13 +615,14 @@ bool arrange(ArrangeablePtrs & arrangables,
|
|||||||
arrangeable,
|
arrangeable,
|
||||||
items,
|
items,
|
||||||
// callback called by arrange to apply the result on the arrangeable
|
// 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::cInt stride = binidx * stride_padding(binwidth);
|
||||||
|
|
||||||
clppr::IntPoint offs = itm.translation();
|
clppr::IntPoint offs = itm.translation();
|
||||||
arrangeable->apply_arrange_result({unscaled(offs.X + stride),
|
arrangeable->apply_arrange_result({unscaled(offs.X + stride),
|
||||||
unscaled(offs.Y)},
|
unscaled(offs.Y)},
|
||||||
itm.rotation());
|
itm.rotation(), binidx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,60 +630,55 @@ bool arrange(ArrangeablePtrs & arrangables,
|
|||||||
process_arrangeable(fixed, fixeditems, nullptr);
|
process_arrangeable(fixed, fixeditems, nullptr);
|
||||||
|
|
||||||
// Integer ceiling the min distance from the bed perimeters
|
// 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;
|
md = (md % 2) ? md / 2 + 1 : md / 2;
|
||||||
|
|
||||||
auto &cfn = stopcondition;
|
auto &cfn = stopcondition;
|
||||||
|
auto &pri = progressind;
|
||||||
|
|
||||||
switch (bedhint.type) {
|
switch (bedhint.type) {
|
||||||
// case BedShapeType::BOX: {
|
case BedShapeType::BOX: {
|
||||||
// // Create the arranger for the box shaped bed
|
// Create the arranger for the box shaped bed
|
||||||
// BoundingBox bbb = bedhint.shape.box;
|
BoundingBox bbb = bedhint.shape.box;
|
||||||
// bbb.min -= Point{md, md}, bbb.max += Point{md, md};
|
bbb.min -= Point{md, md}, bbb.max += Point{md, md};
|
||||||
// Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}};
|
Box binbb{{bbb.min(X), bbb.min(Y)}, {bbb.max(X), bbb.max(Y)}};
|
||||||
// binwidth = coord_t(binbb.width());
|
binwidth = coord_t(binbb.width());
|
||||||
|
|
||||||
// _arrange(items, fixeditems, binbb, min_obj_distance, progressind, cfn);
|
_arrange(items, fixeditems, binbb, min_obj_dist, pri, cfn);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case BedShapeType::CIRCLE: {
|
case BedShapeType::CIRCLE: {
|
||||||
// auto c = bedhint.shape.circ;
|
auto c = bedhint.shape.circ;
|
||||||
// auto cc = to_lnCircle(c);
|
auto cc = to_lnCircle(c);
|
||||||
// binwidth = scaled(c.radius());
|
binwidth = scaled(c.radius());
|
||||||
|
|
||||||
// _arrange(items, fixeditems, cc, min_obj_distance, progressind, cfn);
|
_arrange(items, fixeditems, cc, min_obj_dist, pri, cfn);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case BedShapeType::IRREGULAR: {
|
case BedShapeType::IRREGULAR: {
|
||||||
// auto ctour = Slic3rMultiPoint_to_ClipperPath(bedhint.shape.polygon);
|
auto ctour = Slic3rMultiPoint_to_ClipperPath(bedhint.shape.polygon);
|
||||||
// auto irrbed = sl::create<clppr::Polygon>(std::move(ctour));
|
auto irrbed = sl::create<clppr::Polygon>(std::move(ctour));
|
||||||
// BoundingBox polybb(bedhint.shape.polygon);
|
BoundingBox polybb(bedhint.shape.polygon);
|
||||||
// binwidth = (polybb.max(X) - polybb.min(X));
|
binwidth = (polybb.max(X) - polybb.min(X));
|
||||||
|
|
||||||
// _arrange(items, fixeditems, irrbed, min_obj_distance, progressind, cfn);
|
_arrange(items, fixeditems, irrbed, min_obj_dist, pri, cfn);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case BedShapeType::INFINITE: {
|
case BedShapeType::INFINITE: {
|
||||||
// const InfiniteBed& nobin = bedhint.shape.infinite;
|
const InfiniteBed& nobin = bedhint.shape.infinite;
|
||||||
// Box infbb{{nobin.center.x(), nobin.center.y()}};
|
auto infbb = Box::infinite({nobin.center.x(), nobin.center.y()});
|
||||||
|
|
||||||
// _arrange(items, fixeditems, infbb, min_obj_distance, progressind, cfn);
|
_arrange(items, fixeditems, infbb, min_obj_dist, pri, cfn);
|
||||||
// break;
|
break;
|
||||||
// }
|
}
|
||||||
// case BedShapeType::UNKNOWN: {
|
case BedShapeType::UNKNOWN: {
|
||||||
// // We know nothing about the bed, let it be infinite and zero centered
|
// We know nothing about the bed, let it be infinite and zero centered
|
||||||
// _arrange(items, fixeditems, Box{}, min_obj_distance, progressind, cfn);
|
_arrange(items, fixeditems, Box::infinite(), min_obj_dist, pri, 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);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if(stopcondition()) return false;
|
if(stopcondition && stopcondition()) return false;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
virtual ~Arrangeable() = default;
|
virtual ~Arrangeable() = default;
|
||||||
|
|
||||||
/// Apply the result transformation calculated by the arrangement.
|
/// 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
|
/// Get the 2D silhouette to arrange and an initial offset and rotation
|
||||||
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const = 0;
|
virtual std::tuple<Polygon, Vec2crd, double> get_arrange_polygon() const = 0;
|
||||||
|
@ -559,10 +559,10 @@ public:
|
|||||||
// /////////////////////////////////////////////////////////////////////////
|
// /////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Getting the input polygon for arrange
|
// 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
|
// 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
|
// write the transformation data into the model instance
|
||||||
set_rotation(Z, rot_rads);
|
set_rotation(Z, rot_rads);
|
||||||
|
@ -5739,7 +5739,7 @@ const SLAPrint* GLCanvas3D::sla_print() const
|
|||||||
return (m_process == nullptr) ? nullptr : m_process->sla_print();
|
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_pos = offset;
|
||||||
m_rotation = rotation_rads;
|
m_rotation = rotation_rads;
|
||||||
|
@ -624,9 +624,9 @@ public:
|
|||||||
return !std::isnan(m_pos.x()) && !std::isnan(m_pos.y());
|
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({
|
Polygon p({
|
||||||
{coord_t(0), coord_t(0)},
|
{coord_t(0), coord_t(0)},
|
||||||
|
@ -2483,32 +2483,34 @@ arrangement::BedShapeHint Plater::priv::get_bed_shape_hint() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Plater::priv::ExclusiveJobGroup::ArrangeJob::process() {
|
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());
|
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 {
|
// // FIXME: I don't know how to obtain the minimum distance, it depends
|
||||||
arrangement::arrange(m_selected, m_unselected, min_obj_distance,
|
// // on printer technology. I guess the following should work but it crashes.
|
||||||
bedshape,
|
// double dist = 6; // PrintConfig::min_object_distance(config);
|
||||||
[this, count](unsigned st) {
|
// if (plater().printer_technology == ptFFF) {
|
||||||
if (st > 0) // will not finalize after last one
|
// dist = PrintConfig::min_object_distance(plater().config);
|
||||||
update_status(count - st, arrangestr);
|
// }
|
||||||
},
|
|
||||||
[this]() { return was_canceled(); });
|
// coord_t min_obj_distance = scaled(dist);
|
||||||
} catch (std::exception & /*e*/) {
|
// auto count = unsigned(m_selected.size());
|
||||||
GUI::show_error(plater().q,
|
// arrangement::BedShapeHint bedshape = plater().get_bed_shape_hint();
|
||||||
_(L("Could not arrange model objects! "
|
|
||||||
"Some geometries may be invalid.")));
|
// 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.
|
// finalize just here.
|
||||||
update_status(int(count),
|
update_status(int(count),
|
||||||
|
Loading…
Reference in New Issue
Block a user