From 5b7fdd0d6d2036d58fb157e12c94f02cfdcbff54 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Mon, 16 Oct 2023 11:51:10 +0200 Subject: [PATCH 1/4] fixing arrange for sequential print SPE-1866 Fixing problem with incorrect arrange settings for sequential mode On first start of the app when the arrange dialog wasn't open yet, see also Remove leftover debug code Using a StaticMap in ArrangeSettingsView --- src/libslic3r/Arrange/ArrangeImpl.hpp | 2 +- .../Arrange/ArrangeSettingsDb_AppCfg.cpp | 74 ++++++------ .../Arrange/ArrangeSettingsDb_AppCfg.hpp | 2 + src/libslic3r/Arrange/ArrangeSettingsView.hpp | 105 ++++++++++++++++++ src/slic3r/GUI/GLCanvas3D.cpp | 30 +++-- 5 files changed, 157 insertions(+), 56 deletions(-) diff --git a/src/libslic3r/Arrange/ArrangeImpl.hpp b/src/libslic3r/Arrange/ArrangeImpl.hpp index 92786a41fb..d3cda35e3e 100644 --- a/src/libslic3r/Arrange/ArrangeImpl.hpp +++ b/src/libslic3r/Arrange/ArrangeImpl.hpp @@ -444,7 +444,7 @@ ArrItem AdvancedItemConverter::get_arritem(const Arrangeable &arrbl, auto simpl_tol = static_cast(this->simplification_tolerance()); - if (simpl_tol > 0) + if (simpl_tol > 0.) { outline = expolygons_simplify(outline, simpl_tol); if (!envelope.empty()) diff --git a/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.cpp b/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.cpp index 086ea957d7..fcd8e209c6 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.cpp +++ b/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.cpp @@ -7,6 +7,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"; @@ -39,16 +44,6 @@ ArrangeSettingsDb_AppCfg::ArrangeSettingsDb_AppCfg(AppConfig *appcfg) : m_appcfg std::string en_rot_sla_str = m_appcfg->get("arrange", "enable_rotation_sla"); - // std::string alignment_fff_str = - // m_appcfg->get("arrange", "alignment_fff"); - - // std::string alignment_fff_seqp_str = - // m_appcfg->get("arrange", "alignment_fff_seq_pring"); - - // std::string alignment_sla_str = - // m_appcfg->get("arrange", "alignment_sla"); - - // Override default alignment and save save/load it to a temporary slot "alignment_xl" std::string alignment_xl_str = m_appcfg->get("arrange", "alignment_xl"); @@ -60,71 +55,64 @@ 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"); + else + m_settings_sla.vals.rotations = m_settings_sla.defaults.rotations; - // if (!alignment_sla_str.empty()) - // m_arrange_settings_sla.alignment = std::stoi(alignment_sla_str); - - // if (!alignment_fff_str.empty()) - // m_arrange_settings_fff.alignment = std::stoi(alignment_fff_str); - - // if (!alignment_fff_seqp_str.empty()) - // m_arrange_settings_fff_seq_print.alignment = std::stoi(alignment_fff_seqp_str); - - // 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(align_val); - } + // Override default alignment and save/load it to a temporary slot "alignment_xl" + 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(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(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; @@ -177,7 +165,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; } @@ -185,7 +173,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; } @@ -193,7 +181,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; } diff --git a/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.hpp b/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.hpp index 741c079342..dec64fa0d5 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.hpp +++ b/src/libslic3r/Arrange/ArrangeSettingsDb_AppCfg.hpp @@ -55,6 +55,8 @@ 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; } diff --git a/src/libslic3r/Arrange/ArrangeSettingsView.hpp b/src/libslic3r/Arrange/ArrangeSettingsView.hpp index 2bdecfcfc9..e55b769415 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsView.hpp +++ b/src/libslic3r/Arrange/ArrangeSettingsView.hpp @@ -5,8 +5,15 @@ #ifndef ARRANGESETTINGSVIEW_HPP #define ARRANGESETTINGSVIEW_HPP +#include +#include + +#include "libslic3r/StaticMap.hpp" + namespace Slic3r { namespace arr2 { +using namespace std::string_view_literals; + class ArrangeSettingsView { public: @@ -31,6 +38,104 @@ 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{ + "convex"sv, "balanced"sv, "advanced"sv, "undefined"sv + }; + + return STR[v]; + } + + static constexpr std::string_view get_label(ArrangeStrategy v) + { + constexpr auto STR = std::array{ + "auto"sv, "pulltocenter"sv, "undefined"sv + }; + + return STR[v]; + } + + static constexpr std::string_view get_label(XLPivots v) + { + constexpr auto STR = std::array{"center"sv, + "rearleft"sv, + "frontleft"sv, + "frontright"sv, + "rearright"sv, + "random"sv, + "undefined"sv}; + + return STR[v]; + } + + static constexpr std::optional to_geometry_handling(std::string_view str) + { + return get_enumval(str, GeometryHandlingLabels); + } + + static constexpr std::optional to_arrange_strategy(std::string_view str) + { + return get_enumval(str, ArrangeStrategyLabels); + } + + static constexpr std::optional to_xl_pivots(std::string_view str) + { + return get_enumval(str, XLPivotsLabels); + } + +private: + + template + using EnumMap = StaticMap; + + template + static constexpr std::optional get_enumval(std::string_view str, + const EnumMap &emap) + { + std::optional ret; + + if (auto v = query(emap, str); v.has_value()) { + ret = v.value(); + } + + return ret; + } + + static constexpr const auto GeometryHandlingLabels = make_staticmap({ + {"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({ + {"auto"sv, asAuto}, + {"pulltocenter"sv, asPullToCenter}, + + {"0"sv, asAuto}, + {"1"sv, asPullToCenter} + }); + + static constexpr const auto XLPivotsLabels = make_staticmap({ + {"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 diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f29424b4cd..29eadf6657 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1,13 +1,13 @@ -///|/ Copyright (c) Prusa Research 2018 - 2023 Enrico Turri @enricoturri1966, Oleksandra Iushchenko @YuSanka, Tomáš Mészáros @tamasmeszaros, Lukáš Matěna @lukasmatena, Vojtěch Bubník @bubnikv, David Kocík @kocikdav, Filip Sykala @Jony01, Lukáš Hejl @hejllukas, Vojtěch Král @vojtechkral -///|/ Copyright (c) BambuStudio 2023 manch1n @manch1n -///|/ Copyright (c) SuperSlicer 2023 Remi Durand @supermerill -///|/ Copyright (c) 2020 Benjamin Greiner -///|/ Copyright (c) 2019 John Drake @foxox -///|/ Copyright (c) 2019 BeldrothTheGold @BeldrothTheGold -///|/ Copyright (c) 2019 Thomas Moore -///|/ -///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher -///|/ +///|/ Copyright (c) Prusa Research 2018 - 2023 Enrico Turri @enricoturri1966, Oleksandra Iushchenko @YuSanka, Tomáš Mészáros @tamasmeszaros, Lukáš Matěna @lukasmatena, Vojtěch Bubník @bubnikv, David Kocík @kocikdav, Filip Sykala @Jony01, Lukáš Hejl @hejllukas, Vojtěch Král @vojtechkral +///|/ Copyright (c) BambuStudio 2023 manch1n @manch1n +///|/ Copyright (c) SuperSlicer 2023 Remi Durand @supermerill +///|/ Copyright (c) 2020 Benjamin Greiner +///|/ Copyright (c) 2019 John Drake @foxox +///|/ Copyright (c) 2019 BeldrothTheGold @BeldrothTheGold +///|/ Copyright (c) 2019 Thomas Moore +///|/ +///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher +///|/ #include "libslic3r/libslic3r.h" #include "GLCanvas3D.hpp" @@ -1642,7 +1642,6 @@ void GLCanvas3D::set_config(const DynamicPrintConfig* config) m_config = config; m_layers_editing.set_config(config); - if (config) { PrinterTechnology ptech = current_printer_technology(); @@ -1663,7 +1662,14 @@ void GLCanvas3D::set_config(const DynamicPrintConfig* config) double objdst = min_object_distance(*config); double min_obj_dst = slot == ArrangeSettingsDb_AppCfg::slotFFFSeqPrint ? objdst : 0.; m_arrange_settings_db.set_distance_from_obj_range(slot, min_obj_dst, 100.); - m_arrange_settings_db.get_defaults(slot).d_obj = objdst; + + if (std::abs(m_arrange_settings_db.get_defaults(slot).d_obj - objdst) > EPSILON) { + m_arrange_settings_db.get_defaults(slot).d_obj = objdst; + + // Defaults have changed, so let's sync with the app config and fill + // in the missing values with the new defaults. + m_arrange_settings_db.sync(); + } } } From dc37d04e823fea1872f73679e910060e64fda7de Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 5 Oct 2023 14:38:18 +0200 Subject: [PATCH 2/4] Fix broken forward-compatibility for arrange settings with <=2.6.1 --- src/libslic3r/Arrange/ArrangeSettingsView.hpp | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/Arrange/ArrangeSettingsView.hpp b/src/libslic3r/Arrange/ArrangeSettingsView.hpp index e55b769415..b3d81e06c1 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsView.hpp +++ b/src/libslic3r/Arrange/ArrangeSettingsView.hpp @@ -42,7 +42,10 @@ public: static constexpr std::string_view get_label(GeometryHandling v) { constexpr auto STR = std::array{ - "convex"sv, "balanced"sv, "advanced"sv, "undefined"sv + "0"sv, // convex + "1"sv, // balanced + "2"sv, // advanced + "-1"sv, // undefined }; return STR[v]; @@ -51,7 +54,9 @@ public: static constexpr std::string_view get_label(ArrangeStrategy v) { constexpr auto STR = std::array{ - "auto"sv, "pulltocenter"sv, "undefined"sv + "0"sv, // auto + "1"sv, // pulltocenter + "-1"sv, // undefined }; return STR[v]; @@ -59,13 +64,15 @@ public: static constexpr std::string_view get_label(XLPivots v) { - constexpr auto STR = std::array{"center"sv, - "rearleft"sv, - "frontleft"sv, - "frontright"sv, - "rearright"sv, - "random"sv, - "undefined"sv}; + 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]; } From 9598a52aee3559612d01a8337ab8e7b631a21497 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 5 Oct 2023 16:00:16 +0200 Subject: [PATCH 3/4] Try to fix build on Mac --- src/libslic3r/Arrange/ArrangeSettingsView.hpp | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/libslic3r/Arrange/ArrangeSettingsView.hpp b/src/libslic3r/Arrange/ArrangeSettingsView.hpp index b3d81e06c1..59d171c110 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsView.hpp +++ b/src/libslic3r/Arrange/ArrangeSettingsView.hpp @@ -77,21 +77,6 @@ public: return STR[v]; } - static constexpr std::optional to_geometry_handling(std::string_view str) - { - return get_enumval(str, GeometryHandlingLabels); - } - - static constexpr std::optional to_arrange_strategy(std::string_view str) - { - return get_enumval(str, ArrangeStrategyLabels); - } - - static constexpr std::optional to_xl_pivots(std::string_view str) - { - return get_enumval(str, XLPivotsLabels); - } - private: template @@ -110,6 +95,25 @@ private: return ret; } +public: + + static constexpr std::optional to_geometry_handling(std::string_view str) + { + return get_enumval(str, GeometryHandlingLabels); + } + + static constexpr std::optional to_arrange_strategy(std::string_view str) + { + return get_enumval(str, ArrangeStrategyLabels); + } + + static constexpr std::optional to_xl_pivots(std::string_view str) + { + return get_enumval(str, XLPivotsLabels); + } + +private: + static constexpr const auto GeometryHandlingLabels = make_staticmap({ {"convex"sv, ghConvex}, {"balanced"sv, ghBalanced}, From 564a4c7c3b5829aa7d7ffaf7850a01d690b8ddf5 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Thu, 5 Oct 2023 16:38:23 +0200 Subject: [PATCH 4/4] Follow up: fix for std::optional not having method value() on Mac --- src/libslic3r/Arrange/ArrangeSettingsView.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libslic3r/Arrange/ArrangeSettingsView.hpp b/src/libslic3r/Arrange/ArrangeSettingsView.hpp index 59d171c110..d62e59d1cd 100644 --- a/src/libslic3r/Arrange/ArrangeSettingsView.hpp +++ b/src/libslic3r/Arrange/ArrangeSettingsView.hpp @@ -89,7 +89,7 @@ private: std::optional ret; if (auto v = query(emap, str); v.has_value()) { - ret = v.value(); + ret = *v; } return ret;