Skip to content

Commit

Permalink
#449 fix for Autoarrange in MSLA Mode
Browse files Browse the repository at this point in the history
Forgot to make it printer-type independent when fixing arrange.
  • Loading branch information
supermerill committed Sep 6, 2020
1 parent 31dfe94 commit 3d0a58a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ int CLI::run(int argc, char **argv)
PrintBase *print = (printer_technology == ptFFF) ? static_cast<PrintBase*>(&fff_print) : static_cast<PrintBase*>(&sla_print);
if (! m_config.opt_bool("dont_arrange")) {
//FIXME make the min_object_distance configurable.
model.arrange_objects(fff_print);
model.arrange_objects(print);
model.center_instances_around_point((! user_center_specified && m_print_config.has("bed_shape")) ?
BoundingBoxf(m_print_config.opt<ConfigOptionPoints>("bed_shape")->values).center() :
m_config.option<ConfigOptionPoint>("center")->value);
Expand Down
22 changes: 13 additions & 9 deletions src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ static bool _arrange(const Pointfs &sizes, coordf_t dist, const BoundingBoxf* bb

/* arrange objects preserving their instance count
but altering their instance positions */
bool Model::arrange_objects(const Print &print, const BoundingBoxf* bb)
bool Model::arrange_objects(const PrintBase *print, const BoundingBoxf* bb)
{
size_t count = 0;
for (auto obj : objects) count += obj->instances.size();
Expand Down Expand Up @@ -1823,7 +1823,7 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
polygon->scale(get_scaling_factor(X), get_scaling_factor(Y)); // scale around polygon origin
}

arrangement::ArrangePolygon ModelInstance::get_arrange_polygon(const Print& print) const
arrangement::ArrangePolygon ModelInstance::get_arrange_polygon(const PrintBase *print_base) const
{
static const double SIMPLIFY_TOLERANCE_MM = 0.1;

Expand All @@ -1841,13 +1841,17 @@ arrangement::ArrangePolygon ModelInstance::get_arrange_polygon(const Print& prin
// https://github.com/prusa3d/PrusaSlicer/issues/2209
if (!p.points.empty()) {
Polygons pp{p};
//grow
double dist = print.config().min_object_distance(&print.full_print_config());
std::cout << "min_object_distance = " << dist << "\n";
pp = offset(pp, scale_(dist));
//simplify
if (!pp.empty())
pp = pp.front().simplify(scaled<double>(SIMPLIFY_TOLERANCE_MM));
if (const Print* print = dynamic_cast<const Print*>(print_base))
{
//grow
double dist = print->config().min_object_distance(&print->full_print_config());
std::cout << "min_object_distance = " << dist << "\n";
pp = offset(pp, scale_(dist));
//simplify
if (!pp.empty())
pp = pp.front().simplify(scaled<double>(SIMPLIFY_TOLERANCE_MM));
}else
pp = p.simplify(scaled<double>(SIMPLIFY_TOLERANCE_MM));
if (!pp.empty()) p = pp.front();
}

Expand Down
5 changes: 3 additions & 2 deletions src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ModelMaterial;
class ModelObject;
class ModelVolume;
class ModelWipeTower;
class PrintBase;
class Print;
class SLAPrint;

Expand Down Expand Up @@ -667,7 +668,7 @@ class ModelInstance final : public ObjectBase
bool is_printable() const { return object->printable && printable && (print_volume_state == PVS_Inside); }

// Getting the input polygon for arrange
arrangement::ArrangePolygon get_arrange_polygon(const Print& print) const;
arrangement::ArrangePolygon get_arrange_polygon(const PrintBase* print) const;

// Apply the arrange result on the ModelInstance
void apply_arrange_result(const Vec2crd& offs, double rotation)
Expand Down Expand Up @@ -804,7 +805,7 @@ class Model final : public ObjectBase
bool center_instances_around_point(const Vec2d &point);
void translate(coordf_t x, coordf_t y, coordf_t z) { for (ModelObject *o : this->objects) o->translate(x, y, z); }
TriangleMesh mesh() const;
bool arrange_objects(const Print& print, const BoundingBoxf* bb = NULL);
bool arrange_objects(const PrintBase* print, const BoundingBoxf* bb = NULL);
// Croaks if the duplicated objects do not fit the print bed.
void duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL);
void duplicate_objects(size_t copies_num, coordf_t dist, const BoundingBoxf* bb = NULL);
Expand Down
14 changes: 10 additions & 4 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ struct Plater::priv
apply_wipe_tower();
}

ArrangePolygon get_arrange_polygon(const Print &print) const
ArrangePolygon get_arrange_polygon(const PrintBase *print) const
{
Polygon p({
{coord_t(0), coord_t(0)},
Expand Down Expand Up @@ -1627,7 +1627,8 @@ struct Plater::priv

// Set up arrange polygon for a ModelInstance and Wipe tower
template<class T> ArrangePolygon get_arrange_poly(T *obj) const {
ArrangePolygon ap = obj->get_arrange_polygon(this->plater().fff_print);
ArrangePolygon ap = obj->get_arrange_polygon(
this->plater().printer_technology == ptFFF ? (PrintBase*)&this->plater().fff_print : (PrintBase*)&this->plater().sla_print);
ap.priority = 0;
ap.bed_idx = ap.translation.x() / bed_stride();
ap.setter = [obj, this](const ArrangePolygon &p) {
Expand Down Expand Up @@ -2888,7 +2889,8 @@ void Plater::priv::find_new_position(const ModelInstancePtrs &instances,
for (const ModelObject *mo : model.objects)
for (const ModelInstance *inst : mo->instances) {
auto it = std::find(instances.begin(), instances.end(), inst);
auto arrpoly = inst->get_arrange_polygon(this->fff_print);
arrangement::ArrangePolygon arrpoly = inst->get_arrange_polygon(
this->printer_technology == ptFFF ? (PrintBase*)&this->fff_print : (PrintBase*)&this->sla_print);

if (it == instances.end())
fixed.emplace_back(std::move(arrpoly));
Expand All @@ -2897,7 +2899,8 @@ void Plater::priv::find_new_position(const ModelInstancePtrs &instances,
}

if (updated_wipe_tower())
fixed.emplace_back(wipetower.get_arrange_polygon(this->fff_print));
fixed.emplace_back(wipetower.get_arrange_polygon(
this->printer_technology == ptFFF ? (PrintBase*)&this->fff_print : (PrintBase*)&this->sla_print));

arrangement::arrange(movable, fixed, min_d, get_bed_shape_hint());

Expand Down Expand Up @@ -4660,6 +4663,9 @@ const Print& Plater::fff_print() const { return p->fff_print; }
Print& Plater::fff_print() { return p->fff_print; }
const SLAPrint& Plater::sla_print() const { return p->sla_print; }
SLAPrint& Plater::sla_print() { return p->sla_print; }
const PrintBase* Plater::current_print() const {
return printer_technology() == ptFFF ? (PrintBase*)&p->fff_print : (PrintBase*)&p->sla_print;
}

void Plater::new_project()
{
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/Plater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Slic3r {

class Model;
class ModelObject;
class PrintBase;
class Print;
class SLAPrint;
enum SLAPrintObjectStep : unsigned int;
Expand Down Expand Up @@ -150,6 +151,7 @@ class Plater: public wxPanel
Print& fff_print();
const SLAPrint& sla_print() const;
SLAPrint& sla_print();
const PrintBase* current_print() const;

void new_project();
void load_project();
Expand Down

0 comments on commit 3d0a58a

Please sign in to comment.