From 44ca0a6c3d8857428d0b59c5c35859442724928d Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 27 Mar 2020 09:58:08 +0100 Subject: [PATCH] Add universal method to get bed shape from Config objects --- src/libslic3r/PrintConfig.cpp | 31 +++++++++++++++++++++++++++++++ src/libslic3r/PrintConfig.hpp | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index cba027d66..229e37527 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3575,8 +3575,39 @@ void DynamicPrintAndCLIConfig::handle_legacy(t_config_option_key &opt_key, std:: } } +static Points to_points(const std::vector &dpts) +{ + Points pts; pts.reserve(dpts.size()); + for (auto &v : dpts) + pts.emplace_back( coord_t(scale_(v.x())), coord_t(scale_(v.y())) ); + return pts; } +Points get_bed_shape(const DynamicPrintConfig &config) +{ + const auto *bed_shape_opt = config.opt("bed_shape"); + if (!bed_shape_opt) { + + // Here, it is certain that the bed shape is missing, so an infinite one + // has to be used, but still, the center of bed can be queried + if (auto center_opt = config.opt("center")) + return { scaled(center_opt->value) }; + + return {}; + } + + return to_points(bed_shape_opt->values); +} + +Points get_bed_shape(const PrintConfig &cfg) +{ + return to_points(cfg.bed_shape.values); +} + +Points get_bed_shape(const SLAPrinterConfig &cfg) { return to_points(cfg.bed_shape.values); } + +} // namespace Slic3r + #include CEREAL_REGISTER_TYPE(Slic3r::DynamicPrintConfig) CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::DynamicConfig, Slic3r::DynamicPrintConfig) diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 695629416..c2ecc461e 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1306,6 +1306,10 @@ private: static PrintAndCLIConfigDef s_def; }; +Points get_bed_shape(const DynamicPrintConfig &cfg); +Points get_bed_shape(const PrintConfig &cfg); +Points get_bed_shape(const SLAPrinterConfig &cfg); + } // namespace Slic3r // Serialization through the Cereal library