Merge branch 'tm_arrange_bounds_SPE-1247'

This commit is contained in:
tamasmeszaros 2022-09-20 10:59:49 +02:00
commit a3aeddfd13
5 changed files with 54 additions and 13 deletions

View File

@ -198,9 +198,11 @@ public:
inline P center() const BP2D_NOEXCEPT;
template<class Unit = TCompute<P>>
template<class Unit = TCompute<P>>
inline Unit area() const BP2D_NOEXCEPT {
return Unit(width())*height();
constexpr TCoord<P> Zero{0};
Unit s = width() < Zero || height() < Zero ? Unit(-1) : Unit(1);
return s * libnest2d::abs(Unit(width()) * height());
}
static inline _Box infinite(const P &center = {TCoord<P>(0), TCoord<P>(0)});

View File

@ -497,11 +497,11 @@ void _arrange(
mod_params.min_obj_distance = 0;
AutoArranger<BinT> arranger{corrected_bin, mod_params, progressfn, stopfn};
auto infl = coord_t(std::ceil(params.min_obj_distance / 2.0));
for (Item& itm : shapes) itm.inflate(infl);
for (Item& itm : excludes) itm.inflate(infl);
remove_large_items(excludes, corrected_bin);
// If there is something on the plate
@ -511,7 +511,7 @@ void _arrange(
inp.reserve(shapes.size() + excludes.size());
for (auto &itm : shapes ) inp.emplace_back(itm);
for (auto &itm : excludes) inp.emplace_back(itm);
// Use the minimum bounding box rotation as a starting point.
// TODO: This only works for convex hull. If we ever switch to concave
// polygon nesting, a convex hull needs to be calculated.
@ -528,7 +528,13 @@ void _arrange(
}
}
arranger(inp.begin(), inp.end());
if (sl::area(corrected_bin) > 0)
arranger(inp.begin(), inp.end());
else {
for (Item &itm : inp)
itm.binId(BIN_ID_UNSET);
}
for (Item &itm : inp) itm.inflate(-infl);
}

View File

@ -1111,12 +1111,21 @@ void GLCanvas3D::load_arrange_settings()
std::string dist_fff_str =
wxGetApp().app_config->get("arrange", "min_object_distance_fff");
std::string dist_bed_fff_str =
wxGetApp().app_config->get("arrange", "min_bed_distance_fff");
std::string dist_fff_seq_print_str =
wxGetApp().app_config->get("arrange", "min_object_distance_fff_seq_print");
std::string dist_bed_fff_seq_print_str =
wxGetApp().app_config->get("arrange", "min_bed_distance_fff_seq_print");
std::string dist_sla_str =
wxGetApp().app_config->get("arrange", "min_object_distance_sla");
std::string dist_bed_sla_str =
wxGetApp().app_config->get("arrange", "min_bed_distance_sla");
std::string en_rot_fff_str =
wxGetApp().app_config->get("arrange", "enable_rotation_fff");
@ -1129,12 +1138,21 @@ void GLCanvas3D::load_arrange_settings()
if (!dist_fff_str.empty())
m_arrange_settings_fff.distance = string_to_float_decimal_point(dist_fff_str);
if (!dist_bed_fff_str.empty())
m_arrange_settings_fff.distance_from_bed = string_to_float_decimal_point(dist_bed_fff_str);
if (!dist_fff_seq_print_str.empty())
m_arrange_settings_fff_seq_print.distance = string_to_float_decimal_point(dist_fff_seq_print_str);
if (!dist_bed_fff_seq_print_str.empty())
m_arrange_settings_fff_seq_print.distance_from_bed = string_to_float_decimal_point(dist_bed_fff_seq_print_str);
if (!dist_sla_str.empty())
m_arrange_settings_sla.distance = string_to_float_decimal_point(dist_sla_str);
if (!dist_bed_sla_str.empty())
m_arrange_settings_sla.distance_from_bed = string_to_float_decimal_point(dist_bed_sla_str);
if (!en_rot_fff_str.empty())
m_arrange_settings_fff.enable_rotation = (en_rot_fff_str == "1" || en_rot_fff_str == "yes");
@ -4525,11 +4543,13 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x)
bool settings_changed = false;
float dist_min = 0.f;
std::string dist_key = "min_object_distance", rot_key = "enable_rotation";
float dist_bed_min = 0.f;
std::string dist_key = "min_object_distance";
std::string dist_bed_key = "min_bed_distance";
std::string rot_key = "enable_rotation";
std::string postfix;
if (ptech == ptSLA) {
dist_min = 0.f;
postfix = "_sla";
} else if (ptech == ptFFF) {
auto co_opt = m_config->option<ConfigOptionBool>("complete_objects");
@ -4543,7 +4563,8 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x)
}
dist_key += postfix;
rot_key += postfix;
dist_bed_key += postfix;
rot_key += postfix;
imgui->text(GUI::format_wxstr(_L("Press %1%left mouse button to enter the exact value"), shortkey_ctrl_prefix()));
@ -4554,6 +4575,13 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x)
settings_changed = true;
}
if (imgui->slider_float(_L("Spacing from bed"), &settings.distance_from_bed, dist_bed_min, 100.0f, "%5.2f") || dist_bed_min > settings.distance_from_bed) {
settings.distance_from_bed = std::max(dist_bed_min, settings.distance_from_bed);
settings_out.distance_from_bed = settings.distance_from_bed;
appcfg->set("arrange", dist_bed_key.c_str(), float_to_string_decimal_point(settings_out.distance_from_bed));
settings_changed = true;
}
if (imgui->checkbox(_L("Enable rotations (slow)"), settings.enable_rotation)) {
settings_out.enable_rotation = settings.enable_rotation;
appcfg->set("arrange", rot_key.c_str(), settings_out.enable_rotation? "1" : "0");
@ -4566,6 +4594,7 @@ bool GLCanvas3D::_render_arrange_menu(float pos_x)
settings_out = ArrangeSettings{};
settings_out.distance = std::max(dist_min, settings_out.distance);
appcfg->set("arrange", dist_key.c_str(), float_to_string_decimal_point(settings_out.distance));
appcfg->set("arrange", dist_bed_key.c_str(), float_to_string_decimal_point(settings_out.distance_from_bed));
appcfg->set("arrange", rot_key.c_str(), settings_out.enable_rotation? "1" : "0");
settings_changed = true;
}

View File

@ -1,7 +1,6 @@
#include "ArrangeJob.hpp"
#include "libslic3r/BuildVolume.hpp"
#include "libslic3r/MTUtils.hpp"
#include "libslic3r/Model.hpp"
#include "slic3r/GUI/Plater.hpp"
@ -167,12 +166,16 @@ void ArrangeJob::process(Ctl &ctl)
static const auto arrangestr = _u8L("Arranging");
ctl.update_status(0, arrangestr);
ctl.call_on_main_thread([this]{ prepare(); }).wait();;
arrangement::ArrangeParams params = get_arrange_params(m_plater);
arrangement::ArrangeParams params;
Points bedpts;
ctl.call_on_main_thread([this, &params, &bedpts]{
prepare();
params = get_arrange_params(m_plater);
bedpts = get_bed_shape(*m_plater->config());
}).wait();
auto count = unsigned(m_selected.size() + m_unprintable.size());
Points bedpts = get_bed_shape(*m_plater->config());
params.stopcondition = [&ctl]() { return ctl.was_canceled(); };

View File

@ -117,6 +117,7 @@ void FillBedJob::process(Ctl &ctl)
arrangement::ArrangeParams params;
params.allow_rotations = settings.enable_rotation;
params.min_obj_distance = scaled(settings.distance);
params.min_bed_distance = scaled(settings.distance_from_bed);
bool do_stop = false;
params.stopcondition = [&ctl, &do_stop]() {