PRUSA 2.7.0

This commit is contained in:
sunsets
2023-12-27 18:02:35 +08:00
parent b33112327f
commit 0a3c63dcb1
488 changed files with 92371 additions and 29443 deletions

View File

@@ -441,7 +441,7 @@ ArrItem AdvancedItemConverter<ArrItem>::get_arritem(const Arrangeable &arrbl,
auto simpl_tol = static_cast<double>(this->simplification_tolerance());
if (simpl_tol > 0)
if (simpl_tol > 0.)
{
outline = expolygons_simplify(outline, simpl_tol);
if (!envelope.empty())

View File

@@ -4,6 +4,11 @@
namespace Slic3r {
ArrangeSettingsDb_AppCfg::ArrangeSettingsDb_AppCfg(AppConfig *appcfg) : m_appcfg{appcfg}
{
sync();
}
void ArrangeSettingsDb_AppCfg::sync()
{
m_settings_fff.postfix = "_fff";
m_settings_fff_seq.postfix = "_fff_seq_print";
@@ -57,27 +62,41 @@ ArrangeSettingsDb_AppCfg::ArrangeSettingsDb_AppCfg(AppConfig *appcfg) : m_appcfg
if (!dist_fff_str.empty())
m_settings_fff.vals.d_obj = string_to_float_decimal_point(dist_fff_str);
else
m_settings_fff.vals.d_obj = m_settings_fff.defaults.d_obj;
if (!dist_bed_fff_str.empty())
m_settings_fff.vals.d_bed = string_to_float_decimal_point(dist_bed_fff_str);
else
m_settings_fff.vals.d_bed = m_settings_fff.defaults.d_bed;
if (!dist_fff_seq_print_str.empty())
m_settings_fff_seq.vals.d_obj = string_to_float_decimal_point(dist_fff_seq_print_str);
else
m_settings_fff_seq.vals.d_obj = m_settings_fff_seq.defaults.d_obj;
if (!dist_bed_fff_seq_print_str.empty())
m_settings_fff_seq.vals.d_bed = string_to_float_decimal_point(dist_bed_fff_seq_print_str);
else
m_settings_fff_seq.vals.d_bed = m_settings_fff_seq.defaults.d_bed;
if (!dist_sla_str.empty())
m_settings_sla.vals.d_obj = string_to_float_decimal_point(dist_sla_str);
else
m_settings_sla.vals.d_obj = m_settings_sla.defaults.d_obj;
if (!dist_bed_sla_str.empty())
m_settings_sla.vals.d_bed = string_to_float_decimal_point(dist_bed_sla_str);
else
m_settings_sla.vals.d_bed = m_settings_sla.defaults.d_bed;
if (!en_rot_fff_str.empty())
m_settings_fff.vals.rotations = (en_rot_fff_str == "1" || en_rot_fff_str == "yes");
if (!en_rot_fff_seqp_str.empty())
m_settings_fff_seq.vals.rotations = (en_rot_fff_seqp_str == "1" || en_rot_fff_seqp_str == "yes");
else
m_settings_fff_seq.vals.rotations = m_settings_fff_seq.defaults.rotations;
if (!en_rot_sla_str.empty())
m_settings_sla.vals.rotations = (en_rot_sla_str == "1" || en_rot_sla_str == "yes");
@@ -90,38 +109,26 @@ ArrangeSettingsDb_AppCfg::ArrangeSettingsDb_AppCfg(AppConfig *appcfg) : m_appcfg
// if (!alignment_fff_seqp_str.empty())
// m_arrange_settings_fff_seq_print.alignment = std::stoi(alignment_fff_seqp_str);
else
m_settings_sla.vals.rotations = m_settings_sla.defaults.rotations;
// Override default alignment and save save/load it to a temporary slot "alignment_xl"
ArrangeSettingsView::XLPivots arr_alignment = ArrangeSettingsView::xlpFrontLeft;
if (!alignment_xl_str.empty()) {
int align_val = std::stoi(alignment_xl_str);
if (align_val >= 0 && align_val < ArrangeSettingsView::xlpCount)
arr_alignment =
static_cast<ArrangeSettingsView::XLPivots>(align_val);
}
auto arr_alignment = ArrangeSettingsView::to_xl_pivots(alignment_xl_str)
.value_or(m_settings_fff.defaults.xl_align);
m_settings_sla.vals.xl_align = arr_alignment ;
m_settings_fff.vals.xl_align = arr_alignment ;
m_settings_fff_seq.vals.xl_align = arr_alignment ;
ArrangeSettingsView::GeometryHandling geom_handl = arr2::ArrangeSettingsView::ghConvex;
if (!geom_handling_str.empty()) {
int gh = std::stoi(geom_handling_str);
if(gh >= 0 && gh < ArrangeSettingsView::GeometryHandling::ghCount)
geom_handl = static_cast<ArrangeSettingsView::GeometryHandling>(gh);
}
auto geom_handl = ArrangeSettingsView::to_geometry_handling(geom_handling_str)
.value_or(m_settings_fff.defaults.geom_handling);
m_settings_sla.vals.geom_handling = geom_handl;
m_settings_fff.vals.geom_handling = geom_handl;
m_settings_fff_seq.vals.geom_handling = geom_handl;
ArrangeSettingsView::ArrangeStrategy arr_strategy = arr2::ArrangeSettingsView::asAuto;
if (!strategy_str.empty()) {
int strateg = std::stoi(strategy_str);
if(strateg >= 0 && strateg < ArrangeSettingsView::ArrangeStrategy::asCount)
arr_strategy = static_cast<ArrangeSettingsView::ArrangeStrategy>(strateg);
}
auto arr_strategy = ArrangeSettingsView::to_arrange_strategy(strategy_str)
.value_or(m_settings_fff.defaults.arr_strategy);
m_settings_sla.vals.arr_strategy = arr_strategy;
m_settings_fff.vals.arr_strategy = arr_strategy;
@@ -174,7 +181,7 @@ arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_rotation_enabled(bool v)
arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_xl_alignment(XLPivots v)
{
m_settings_fff.vals.xl_align = v;
m_appcfg->set("arrange", "alignment_xl", std::to_string(v));
m_appcfg->set("arrange", "alignment_xl", std::string{get_label(v)});
return *this;
}
@@ -182,7 +189,7 @@ arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_xl_alignment(XLPivots v)
arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_geometry_handling(GeometryHandling v)
{
m_settings_fff.vals.geom_handling = v;
m_appcfg->set("arrange", "geometry_handling", std::to_string(v));
m_appcfg->set("arrange", "geometry_handling", std::string{get_label(v)});
return *this;
}
@@ -190,7 +197,7 @@ arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_geometry_handling(Geometr
arr2::ArrangeSettingsDb& ArrangeSettingsDb_AppCfg::set_arrange_strategy(ArrangeStrategy v)
{
m_settings_fff.vals.arr_strategy = v;
m_appcfg->set("arrange", "arrange_strategy", std::to_string(v));
m_appcfg->set("arrange", "arrange_strategy", std::string{get_label(v)});
return *this;
}

View File

@@ -52,6 +52,7 @@ private:
public:
explicit ArrangeSettingsDb_AppCfg(AppConfig *appcfg);
void sync();
float get_distance_from_objects() const override { return get_ref(this).d_obj; }
float get_distance_from_bed() const override { return get_ref(this).d_bed; }
bool is_rotation_enabled() const override { return get_ref(this).rotations; }

View File

@@ -2,8 +2,13 @@
#ifndef ARRANGESETTINGSVIEW_HPP
#define ARRANGESETTINGSVIEW_HPP
#include <string_view>
#include <array>
#include "libslic3r/StaticMap.hpp"
namespace Slic3r { namespace arr2 {
using namespace std::string_view_literals;
class ArrangeSettingsView
{
public:
@@ -28,6 +33,114 @@ public:
virtual XLPivots get_xl_alignment() const = 0;
virtual GeometryHandling get_geometry_handling() const = 0;
virtual ArrangeStrategy get_arrange_strategy() const = 0;
static constexpr std::string_view get_label(GeometryHandling v)
{
constexpr auto STR = std::array{
"0"sv, // convex
"1"sv, // balanced
"2"sv, // advanced
"-1"sv, // undefined
};
return STR[v];
}
static constexpr std::string_view get_label(ArrangeStrategy v)
{
constexpr auto STR = std::array{
"0"sv, // auto
"1"sv, // pulltocenter
"-1"sv, // undefined
};
return STR[v];
}
static constexpr std::string_view get_label(XLPivots v)
{
constexpr auto STR = std::array{
"0"sv, // center
"1"sv, // rearleft
"2"sv, // frontleft
"3"sv, // frontright
"4"sv, // rearright
"5"sv, // random
"-1"sv, // undefined
};
return STR[v];
}
private:
template<class EnumType, size_t N>
using EnumMap = StaticMap<std::string_view, EnumType, N>;
template<class EnumType, size_t N>
static constexpr std::optional<EnumType> get_enumval(std::string_view str,
const EnumMap<EnumType, N> &emap)
{
std::optional<EnumType> ret;
if (auto v = query(emap, str); v.has_value()) {
ret = *v;
}
return ret;
}
public:
static constexpr std::optional<GeometryHandling> to_geometry_handling(std::string_view str)
{
return get_enumval(str, GeometryHandlingLabels);
}
static constexpr std::optional<ArrangeStrategy> to_arrange_strategy(std::string_view str)
{
return get_enumval(str, ArrangeStrategyLabels);
}
static constexpr std::optional<XLPivots> to_xl_pivots(std::string_view str)
{
return get_enumval(str, XLPivotsLabels);
}
private:
static constexpr const auto GeometryHandlingLabels = make_staticmap<std::string_view, GeometryHandling>({
{"convex"sv, ghConvex},
{"balanced"sv, ghBalanced},
{"advanced"sv, ghAdvanced},
{"0"sv, ghConvex},
{"1"sv, ghBalanced},
{"2"sv, ghAdvanced},
});
static constexpr const auto ArrangeStrategyLabels = make_staticmap<std::string_view, ArrangeStrategy>({
{"auto"sv, asAuto},
{"pulltocenter"sv, asPullToCenter},
{"0"sv, asAuto},
{"1"sv, asPullToCenter}
});
static constexpr const auto XLPivotsLabels = make_staticmap<std::string_view, XLPivots>({
{"center"sv, xlpCenter },
{"rearleft"sv, xlpRearLeft },
{"frontleft"sv, xlpFrontLeft },
{"frontright"sv, xlpFrontRight },
{"rearright"sv, xlpRearRight },
{"random"sv, xlpRandom },
{"0"sv, xlpCenter },
{"1"sv, xlpRearLeft },
{"2"sv, xlpFrontLeft },
{"3"sv, xlpFrontRight },
{"4"sv, xlpRearRight },
{"5"sv, xlpRandom }
});
};
class ArrangeSettingsDb: public ArrangeSettingsView

View File

@@ -91,7 +91,7 @@ void fill_distances(const Polygon &poly, std::vector<double> &distances)
double dist = 0.;
auto lrange = line_range(poly);
for (const Line &l : lrange) {
for (const Line l : lrange) {
dist += l.length();
distances.emplace_back(dist);
}

View File

@@ -14,7 +14,9 @@ struct GravityKernel {
std::optional<Vec2crd> item_sink;
Vec2d active_sink;
GravityKernel(Vec2crd gravity_center) : sink{gravity_center} {}
GravityKernel(Vec2crd gravity_center) :
sink{gravity_center}, active_sink{unscaled(gravity_center)} {}
GravityKernel() = default;
template<class ArrItem>

View File

@@ -24,6 +24,7 @@ bool find_initial_position(Itm &itm,
{
if (all_items_range(packing_context).empty()) {
auto rotations = allowed_rotations(itm);
set_rotation(itm, 0.);
auto chull = envelope_convex_hull(itm);
for (double rot : rotations) {

View File

@@ -129,7 +129,7 @@ Polygon ifp_convex_convex(const Polygon &fixed, const Polygon &movable)
// the zero area polygon formed by the edge. The union of all these sub-nfps
// will contain a hole that is the actual ifp.
auto lrange = line_range(fixed);
for (const Line &l : lrange) { // Older mac compilers generate warnging if line_range is called in-place
for (const Line l : lrange) { // Older mac compilers generate warnging if line_range is called in-place
Polygon fixed = {l.a, l.b};
subnfps.emplace_back(nfp_convex_convex_legacy(fixed, movable));
}

View File

@@ -17,6 +17,7 @@ struct FillBedTask: public ArrangeTaskBase
std::vector<ArrItem> selected, unselected;
std::vector<ArrItem> selected_fillers;
ArrangeSettings settings;
ExtendedBed bed;
size_t selected_existing_count = 0;

View File

@@ -102,8 +102,6 @@ void extract(FillBedTask<ArrItem> &task,
};
// Set the lowest priority to the shrinked prototype (hole filler) item
set_priority(prototype_item_shrinked,
lowest_priority(range(task.selected)) - 1);
scene.model().for_each_arrangeable(collect_task_items);
@@ -119,7 +117,7 @@ void extract(FillBedTask<ArrItem> &task,
// Add as many filler items as there are needed items. Most of them will
// be discarded anyways.
std::fill_n(std::back_inserter(task.selected), needed_items,
std::fill_n(std::back_inserter(task.selected_fillers), needed_items,
prototype_item_shrinked);
}
@@ -172,7 +170,7 @@ std::unique_ptr<FillBedTaskResult> FillBedTask<ArrItem>::process_native(
void on_packed(ArrItem &itm) override
{
// Stop at the first filler that is not on the physical bed
do_stop = get_bed_index(itm) > PhysicalBedId && get_priority(itm) < 0;
do_stop = get_bed_index(itm) > PhysicalBedId && get_priority(itm) == 0;
}
} subctl(ctl, *this);
@@ -181,6 +179,12 @@ std::unique_ptr<FillBedTaskResult> FillBedTask<ArrItem>::process_native(
arranger->arrange(selected, unselected, bed, subctl);
auto unsel_cpy = unselected;
for (const auto &itm : selected) {
unsel_cpy.emplace_back(itm);
}
arranger->arrange(selected_fillers, unsel_cpy, bed, FillBedCtl{ctl, *this});
auto arranged_range = Range{selected.begin(),
selected.begin() + selected_existing_count};
@@ -193,6 +197,9 @@ std::unique_ptr<FillBedTaskResult> FillBedTask<ArrItem>::process_native(
if (get_bed_index(itm) == PhysicalBedId)
result->add_new_item(itm);
for (auto &itm : selected_fillers)
if (get_bed_index(itm) == PhysicalBedId)
result->add_new_item(itm);
return result;
}