From d1cfdcb49e144f98dc3400d3e1bf05ea992ad7e4 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 26 Apr 2021 18:37:10 +0200 Subject: [PATCH] Refactoring of StaticPrintConfig & derived classes: 1) Using boost::preprocessor to reduce code duplicities when defining new configuration values. 2) Implemented static hash() and operator== on StaticPrintConfig derived classes to support hash tables of instances thereof. --- src/libslic3r/Config.hpp | 124 ++- src/libslic3r/GCode/CoolingBuffer.cpp | 2 +- src/libslic3r/GCodeReader.cpp | 4 +- src/libslic3r/GCodeWriter.cpp | 2 +- src/libslic3r/PrintConfig.cpp | 88 +- src/libslic3r/PrintConfig.hpp | 1285 ++++++++++--------------- xs/xsp/Config.xsp | 2 +- 7 files changed, 619 insertions(+), 888 deletions(-) diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index 9aab435ed..c49c492a3 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -18,11 +18,53 @@ #include #include +#include #include #include #include +namespace Slic3r { + struct FloatOrPercent + { + double value; + bool percent; + + private: + friend class cereal::access; + template void serialize(Archive& ar) { ar(this->value); ar(this->percent); } + }; + + inline bool operator==(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return l.value == r.value && l.percent == r.percent; } + inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) throw() { return !(l == r); } +} + +namespace std { + template<> struct hash { + std::size_t operator()(const Slic3r::FloatOrPercent& v) const noexcept { + std::size_t seed = std::hash{}(v.value); + return v.percent ? seed ^ 0x9e3779b9 : seed; + } + }; + + template<> struct hash { + std::size_t operator()(const Slic3r::Vec2d& v) const noexcept { + std::size_t seed = std::hash{}(v.x()); + boost::hash_combine(seed, std::hash{}(v.y())); + return seed; + } + }; + + template<> struct hash { + std::size_t operator()(const Slic3r::Vec3d& v) const noexcept { + std::size_t seed = std::hash{}(v.x()); + boost::hash_combine(seed, std::hash{}(v.y())); + boost::hash_combine(seed, std::hash{}(v.z())); + return seed; + } + }; +} + namespace Slic3r { // Name of the configuration option. @@ -137,6 +179,7 @@ public: virtual void setInt(int /* val */) { throw BadOptionTypeException("Calling ConfigOption::setInt on a non-int ConfigOption"); } virtual bool operator==(const ConfigOption &rhs) const = 0; bool operator!=(const ConfigOption &rhs) const { return ! (*this == rhs); } + virtual size_t hash() const throw() = 0; bool is_scalar() const { return (int(this->type()) & int(coVectorType)) == 0; } bool is_vector() const { return ! this->is_scalar(); } // If this option is nullable, then it may have its value or values set to nil. @@ -185,8 +228,10 @@ public: return this->value == static_cast*>(&rhs)->value; } - bool operator==(const T &rhs) const { return this->value == rhs; } - bool operator!=(const T &rhs) const { return this->value != rhs; } + bool operator==(const T &rhs) const throw() { return this->value == rhs; } + bool operator!=(const T &rhs) const throw() { return this->value != rhs; } + + size_t hash() const throw() override { return std::hash{}(this->value); } private: friend class cereal::access; @@ -339,8 +384,16 @@ public: return this->values == static_cast*>(&rhs)->values; } - bool operator==(const std::vector &rhs) const { return this->values == rhs; } - bool operator!=(const std::vector &rhs) const { return this->values != rhs; } + bool operator==(const std::vector &rhs) const throw() { return this->values == rhs; } + bool operator!=(const std::vector &rhs) const throw() { return this->values != rhs; } + + size_t hash() const throw() override { + std::hash hasher; + size_t seed = 0; + for (const auto &v : this->values) + boost::hash_combine(seed, hasher(v)); + return seed; + } // Is this option overridden by another option? // An option overrides another option if it is not nil and not equal. @@ -413,7 +466,7 @@ public: ConfigOptionType type() const override { return static_type(); } double getFloat() const override { return this->value; } ConfigOption* clone() const override { return new ConfigOptionFloat(*this); } - bool operator==(const ConfigOptionFloat &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionFloat &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -454,7 +507,7 @@ public: static ConfigOptionType static_type() { return coFloats; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionFloatsTempl(*this); } - bool operator==(const ConfigOptionFloatsTempl &rhs) const { return vectors_equal(this->values, rhs.values); } + bool operator==(const ConfigOptionFloatsTempl &rhs) const throw() { return vectors_equal(this->values, rhs.values); } bool operator==(const ConfigOption &rhs) const override { if (rhs.type() != this->type()) throw Slic3r::RuntimeError("ConfigOptionFloatsTempl: Comparing incompatible types"); @@ -566,7 +619,7 @@ public: int getInt() const override { return this->value; } void setInt(int val) override { this->value = val; } ConfigOption* clone() const override { return new ConfigOptionInt(*this); } - bool operator==(const ConfigOptionInt &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionInt &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -606,7 +659,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionIntsTempl(*this); } ConfigOptionIntsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionIntsTempl &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionIntsTempl &rhs) const throw() { return this->values == rhs.values; } // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -689,7 +742,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionString(*this); } ConfigOptionString& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionString &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionString &rhs) const throw() { return this->value == rhs.value; } bool empty() const { return this->value.empty(); } std::string serialize() const override @@ -722,7 +775,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionStrings(*this); } ConfigOptionStrings& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionStrings &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionStrings &rhs) const throw() { return this->values == rhs.values; } bool is_nil(size_t) const override { return false; } std::string serialize() const override @@ -757,7 +810,8 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPercent(*this); } ConfigOptionPercent& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPercent &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPercent &rhs) const throw() { return this->value == rhs.value; } + double get_abs_value(double ratio_over) const { return ratio_over * this->value / 100; } std::string serialize() const override @@ -796,8 +850,8 @@ public: static ConfigOptionType static_type() { return coPercents; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPercentsTempl(*this); } - ConfigOptionPercentsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPercentsTempl &rhs) const { return this->values == rhs.values; } + ConfigOptionPercentsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } + bool operator==(const ConfigOptionPercentsTempl &rhs) const throw() { return this->values == rhs.values; } std::string serialize() const override { @@ -856,8 +910,12 @@ public: assert(dynamic_cast(&rhs)); return *this == *static_cast(&rhs); } - bool operator==(const ConfigOptionFloatOrPercent &rhs) const + bool operator==(const ConfigOptionFloatOrPercent &rhs) const throw() { return this->value == rhs.value && this->percent == rhs.percent; } + size_t hash() const throw() override { + size_t seed = std::hash{}(this->value); + return this->percent ? seed ^ 0x9e3779b9 : seed; + } double get_abs_value(double ratio_over) const { return this->percent ? (ratio_over * this->value / 100) : this->value; } @@ -891,27 +949,6 @@ private: template void serialize(Archive &ar) { ar(cereal::base_class(this), percent); } }; - -struct FloatOrPercent -{ - double value; - bool percent; - -private: - friend class cereal::access; - template void serialize(Archive & ar) { ar(this->value); ar(this->percent); } -}; - -inline bool operator==(const FloatOrPercent &l, const FloatOrPercent &r) -{ - return l.value == r.value && l.percent == r.percent; -} - -inline bool operator!=(const FloatOrPercent& l, const FloatOrPercent& r) -{ - return !(l == r); -} - template class ConfigOptionFloatsOrPercentsTempl : public ConfigOptionVector { @@ -925,13 +962,14 @@ public: static ConfigOptionType static_type() { return coFloatsOrPercents; } ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionFloatsOrPercentsTempl(*this); } - bool operator==(const ConfigOptionFloatsOrPercentsTempl &rhs) const { return vectors_equal(this->values, rhs.values); } + bool operator==(const ConfigOptionFloatsOrPercentsTempl &rhs) const throw() { return vectors_equal(this->values, rhs.values); } bool operator==(const ConfigOption &rhs) const override { if (rhs.type() != this->type()) throw Slic3r::RuntimeError("ConfigOptionFloatsOrPercentsTempl: Comparing incompatible types"); assert(dynamic_cast*>(&rhs)); return vectors_equal(this->values, static_cast*>(&rhs)->values); } + // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -1038,7 +1076,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoint(*this); } ConfigOptionPoint& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoint &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPoint &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1074,7 +1112,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoints(*this); } ConfigOptionPoints& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoints &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionPoints &rhs) const throw() { return this->values == rhs.values; } bool is_nil(size_t) const override { return false; } std::string serialize() const override @@ -1146,7 +1184,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionPoint3(*this); } ConfigOptionPoint3& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionPoint3 &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionPoint3 &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1183,7 +1221,7 @@ public: bool getBool() const override { return this->value; } ConfigOption* clone() const override { return new ConfigOptionBool(*this); } ConfigOptionBool& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionBool &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionBool &rhs) const throw() { return this->value == rhs.value; } std::string serialize() const override { @@ -1217,7 +1255,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionBoolsTempl(*this); } ConfigOptionBoolsTempl& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionBoolsTempl &rhs) const { return this->values == rhs.values; } + bool operator==(const ConfigOptionBoolsTempl &rhs) const throw() { return this->values == rhs.values; } // Could a special "nil" value be stored inside the vector, indicating undefined value? bool nullable() const override { return NULLABLE; } // Special "nil" value to be stored into the vector if this->supports_nil(). @@ -1311,7 +1349,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionEnum(*this); } ConfigOptionEnum& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionEnum &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionEnum &rhs) const throw() { return this->value == rhs.value; } int getInt() const override { return (int)this->value; } void setInt(int val) override { this->value = T(val); } @@ -1397,7 +1435,7 @@ public: ConfigOptionType type() const override { return static_type(); } ConfigOption* clone() const override { return new ConfigOptionEnumGeneric(*this); } ConfigOptionEnumGeneric& operator=(const ConfigOption *opt) { this->set(opt); return *this; } - bool operator==(const ConfigOptionEnumGeneric &rhs) const { return this->value == rhs.value; } + bool operator==(const ConfigOptionEnumGeneric &rhs) const throw() { return this->value == rhs.value; } bool operator==(const ConfigOption &rhs) const override { diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index 7f48aae80..07b9b07bb 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -326,7 +326,7 @@ std::vector CoolingBuffer::parse_layer_gcode(const std:: PerExtruderAdjustments *adjustment = &per_extruder_adjustments[map_extruder_to_per_extruder_adjustment[current_extruder]]; const char *line_start = gcode.c_str(); const char *line_end = line_start; - const char extrusion_axis = config.get_extrusion_axis()[0]; + const char extrusion_axis = get_extrusion_axis(config)[0]; // Index of an existing CoolingLine of the current adjustment, which holds the feedrate setting command // for a sequence of extrusion moves. size_t active_speed_modifier = size_t(-1); diff --git a/src/libslic3r/GCodeReader.cpp b/src/libslic3r/GCodeReader.cpp index fb493fcb7..9753e4820 100644 --- a/src/libslic3r/GCodeReader.cpp +++ b/src/libslic3r/GCodeReader.cpp @@ -13,13 +13,13 @@ namespace Slic3r { void GCodeReader::apply_config(const GCodeConfig &config) { m_config = config; - m_extrusion_axis = m_config.get_extrusion_axis()[0]; + m_extrusion_axis = get_extrusion_axis(m_config)[0]; } void GCodeReader::apply_config(const DynamicPrintConfig &config) { m_config.apply(config, true); - m_extrusion_axis = m_config.get_extrusion_axis()[0]; + m_extrusion_axis = get_extrusion_axis(m_config)[0]; } const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, std::pair &command) diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index bc8533113..c84c7b09e 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -18,7 +18,7 @@ namespace Slic3r { void GCodeWriter::apply_print_config(const PrintConfig &print_config) { this->config.apply(print_config, true); - m_extrusion_axis = this->config.get_extrusion_axis(); + m_extrusion_axis = get_extrusion_axis(this->config); m_single_extruder_multi_material = print_config.single_extruder_multi_material.value; bool is_marlin = print_config.gcode_flavor.value == gcfMarlinLegacy || print_config.gcode_flavor.value == gcfMarlinFirmware; m_max_acceleration = std::lrint((is_marlin && print_config.machine_limits_usage.value == MachineLimitsUsage::EmitToGCode) ? diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 9f09bc9f3..f2c5f70a9 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -3608,7 +3608,7 @@ std::string DynamicPrintConfig::validate() FullPrintConfig fpc; fpc.apply(*this, true); // Verify this print options through the FullPrintConfig. - return fpc.validate(); + return Slic3r::validate(fpc); } default: //FIXME no validation on SLA data? @@ -3617,135 +3617,135 @@ std::string DynamicPrintConfig::validate() } //FIXME localize this function. -std::string FullPrintConfig::validate() +std::string validate(const FullPrintConfig &cfg) { // --layer-height - if (this->get_abs_value("layer_height") <= 0) + if (cfg.get_abs_value("layer_height") <= 0) return "Invalid value for --layer-height"; - if (fabs(fmod(this->get_abs_value("layer_height"), SCALING_FACTOR)) > 1e-4) + if (fabs(fmod(cfg.get_abs_value("layer_height"), SCALING_FACTOR)) > 1e-4) return "--layer-height must be a multiple of print resolution"; // --first-layer-height - if (first_layer_height.value <= 0) + if (cfg.first_layer_height.value <= 0) return "Invalid value for --first-layer-height"; // --filament-diameter - for (double fd : this->filament_diameter.values) + for (double fd : cfg.filament_diameter.values) if (fd < 1) return "Invalid value for --filament-diameter"; // --nozzle-diameter - for (double nd : this->nozzle_diameter.values) + for (double nd : cfg.nozzle_diameter.values) if (nd < 0.005) return "Invalid value for --nozzle-diameter"; // --perimeters - if (this->perimeters.value < 0) + if (cfg.perimeters.value < 0) return "Invalid value for --perimeters"; // --solid-layers - if (this->top_solid_layers < 0) + if (cfg.top_solid_layers < 0) return "Invalid value for --top-solid-layers"; - if (this->bottom_solid_layers < 0) + if (cfg.bottom_solid_layers < 0) return "Invalid value for --bottom-solid-layers"; - if (this->use_firmware_retraction.value && - this->gcode_flavor.value != gcfSmoothie && - this->gcode_flavor.value != gcfRepRapSprinter && - this->gcode_flavor.value != gcfRepRapFirmware && - this->gcode_flavor.value != gcfMarlinLegacy && - this->gcode_flavor.value != gcfMarlinFirmware && - this->gcode_flavor.value != gcfMachinekit && - this->gcode_flavor.value != gcfRepetier) + if (cfg.use_firmware_retraction.value && + cfg.gcode_flavor.value != gcfSmoothie && + cfg.gcode_flavor.value != gcfRepRapSprinter && + cfg.gcode_flavor.value != gcfRepRapFirmware && + cfg.gcode_flavor.value != gcfMarlinLegacy && + cfg.gcode_flavor.value != gcfMarlinFirmware && + cfg.gcode_flavor.value != gcfMachinekit && + cfg.gcode_flavor.value != gcfRepetier) return "--use-firmware-retraction is only supported by Marlin, Smoothie, RepRapFirmware, Repetier and Machinekit firmware"; - if (this->use_firmware_retraction.value) - for (unsigned char wipe : this->wipe.values) + if (cfg.use_firmware_retraction.value) + for (unsigned char wipe : cfg.wipe.values) if (wipe) return "--use-firmware-retraction is not compatible with --wipe"; // --gcode-flavor - if (! print_config_def.get("gcode_flavor")->has_enum_value(this->gcode_flavor.serialize())) + if (! print_config_def.get("gcode_flavor")->has_enum_value(cfg.gcode_flavor.serialize())) return "Invalid value for --gcode-flavor"; // --fill-pattern - if (! print_config_def.get("fill_pattern")->has_enum_value(this->fill_pattern.serialize())) + if (! print_config_def.get("fill_pattern")->has_enum_value(cfg.fill_pattern.serialize())) return "Invalid value for --fill-pattern"; // --top-fill-pattern - if (! print_config_def.get("top_fill_pattern")->has_enum_value(this->top_fill_pattern.serialize())) + if (! print_config_def.get("top_fill_pattern")->has_enum_value(cfg.top_fill_pattern.serialize())) return "Invalid value for --top-fill-pattern"; // --bottom-fill-pattern - if (! print_config_def.get("bottom_fill_pattern")->has_enum_value(this->bottom_fill_pattern.serialize())) + if (! print_config_def.get("bottom_fill_pattern")->has_enum_value(cfg.bottom_fill_pattern.serialize())) return "Invalid value for --bottom-fill-pattern"; // --fill-density - if (fabs(this->fill_density.value - 100.) < EPSILON && - ! print_config_def.get("top_fill_pattern")->has_enum_value(this->fill_pattern.serialize())) + if (fabs(cfg.fill_density.value - 100.) < EPSILON && + ! print_config_def.get("top_fill_pattern")->has_enum_value(cfg.fill_pattern.serialize())) return "The selected fill pattern is not supposed to work at 100% density"; // --infill-every-layers - if (this->infill_every_layers < 1) + if (cfg.infill_every_layers < 1) return "Invalid value for --infill-every-layers"; // --skirt-height - if (this->skirt_height < 0) + if (cfg.skirt_height < 0) return "Invalid value for --skirt-height"; // --bridge-flow-ratio - if (this->bridge_flow_ratio <= 0) + if (cfg.bridge_flow_ratio <= 0) return "Invalid value for --bridge-flow-ratio"; // extruder clearance - if (this->extruder_clearance_radius <= 0) + if (cfg.extruder_clearance_radius <= 0) return "Invalid value for --extruder-clearance-radius"; - if (this->extruder_clearance_height <= 0) + if (cfg.extruder_clearance_height <= 0) return "Invalid value for --extruder-clearance-height"; // --extrusion-multiplier - for (double em : this->extrusion_multiplier.values) + for (double em : cfg.extrusion_multiplier.values) if (em <= 0) return "Invalid value for --extrusion-multiplier"; // --default-acceleration - if ((this->perimeter_acceleration != 0. || this->infill_acceleration != 0. || this->bridge_acceleration != 0. || this->first_layer_acceleration != 0.) && - this->default_acceleration == 0.) + if ((cfg.perimeter_acceleration != 0. || cfg.infill_acceleration != 0. || cfg.bridge_acceleration != 0. || cfg.first_layer_acceleration != 0.) && + cfg.default_acceleration == 0.) return "Invalid zero value for --default-acceleration when using other acceleration settings"; // --spiral-vase - if (this->spiral_vase) { + if (cfg.spiral_vase) { // Note that we might want to have more than one perimeter on the bottom // solid layers. - if (this->perimeters > 1) + if (cfg.perimeters > 1) return "Can't make more than one perimeter when spiral vase mode is enabled"; - else if (this->perimeters < 1) + else if (cfg.perimeters < 1) return "Can't make less than one perimeter when spiral vase mode is enabled"; - if (this->fill_density > 0) + if (cfg.fill_density > 0) return "Spiral vase mode can only print hollow objects, so you need to set Fill density to 0"; - if (this->top_solid_layers > 0) + if (cfg.top_solid_layers > 0) return "Spiral vase mode is not compatible with top solid layers"; - if (this->support_material || this->support_material_enforce_layers > 0) + if (cfg.support_material || cfg.support_material_enforce_layers > 0) return "Spiral vase mode is not compatible with support material"; } // extrusion widths { double max_nozzle_diameter = 0.; - for (double dmr : this->nozzle_diameter.values) + for (double dmr : cfg.nozzle_diameter.values) max_nozzle_diameter = std::max(max_nozzle_diameter, dmr); const char *widths[] = { "external_perimeter", "perimeter", "infill", "solid_infill", "top_infill", "support_material", "first_layer" }; for (size_t i = 0; i < sizeof(widths) / sizeof(widths[i]); ++ i) { std::string key(widths[i]); key += "_extrusion_width"; - if (this->get_abs_value(key, max_nozzle_diameter) > 10. * max_nozzle_diameter) + if (cfg.get_abs_value(key, max_nozzle_diameter) > 10. * max_nozzle_diameter) return std::string("Invalid extrusion width (too large): ") + key; } } // Out of range validation of numeric values. - for (const std::string &opt_key : this->keys()) { - const ConfigOption *opt = this->optptr(opt_key); + for (const std::string &opt_key : cfg.keys()) { + const ConfigOption *opt = cfg.optptr(opt_key); assert(opt != nullptr); const ConfigOptionDef *optdef = print_config_def.get(opt_key); assert(optdef != nullptr); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 74cb5c774..7209bea89 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -19,6 +19,14 @@ #include "libslic3r.h" #include "Config.hpp" +#include +#include +#include +#include +#include +#include +#include + // #define HAS_PRESSURE_EQUALIZER namespace Slic3r { @@ -29,10 +37,10 @@ enum GCodeFlavor : unsigned char { }; enum class MachineLimitsUsage { - EmitToGCode, - TimeEstimateOnly, - Ignore, - Count, + EmitToGCode, + TimeEstimateOnly, + Ignore, + Count, }; enum PrintHostType { @@ -55,10 +63,10 @@ enum InfillPattern : int { }; enum class IroningType { - TopSurfaces, - TopmostOnly, - AllSolid, - Count, + TopSurfaces, + TopmostOnly, + AllSolid, + Count, }; enum SupportMaterialPattern { @@ -136,7 +144,7 @@ template<> inline const t_config_enum_values& ConfigOptionEnum m_extruder_option_keys; - std::vector m_extruder_retract_keys; + std::vector m_extruder_option_keys; + std::vector m_extruder_retract_keys; }; // The one and only global definition of SLic3r configuration options. @@ -337,7 +345,7 @@ public: void normalize_fdm(); - void set_num_extruders(unsigned int num_extruders); + void set_num_extruders(unsigned int num_extruders); // Validate the PrintConfig. Returns an empty string on success, otherwise an error message is returned. std::string validate(); @@ -358,7 +366,7 @@ public: // Overrides ConfigBase::def(). Static configuration definition. Any value stored into this ConfigBase shall have its definition here. const ConfigDef* def() const override { return &print_config_def; } // Reference to the cached list of keys. - virtual const t_config_option_keys& keys_ref() const = 0; + virtual const t_config_option_keys& keys_ref() const = 0; protected: // Verify whether the opt_key has not been obsoleted or renamed. @@ -482,729 +490,498 @@ public: \ void handle_legacy(t_config_option_key &opt_key, std::string &value) const override \ { PrintConfigDef::handle_legacy(opt_key, value); } -#define OPT_PTR(KEY) cache.opt_add(#KEY, base_ptr, this->KEY) +#define PRINT_CONFIG_CLASS_ELEMENT_DEFINITION(r, data, elem) BOOST_PP_TUPLE_ELEM(0, elem) BOOST_PP_TUPLE_ELEM(1, elem); +#define PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2(KEY) cache.opt_add(BOOST_PP_STRINGIZE(KEY), base_ptr, this->KEY); +#define PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION(r, data, elem) PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2(BOOST_PP_TUPLE_ELEM(1, elem)) +#define PRINT_CONFIG_CLASS_ELEMENT_HASH(r, data, elem) boost::hash_combine(seed, BOOST_PP_TUPLE_ELEM(1, elem).hash()); +#define PRINT_CONFIG_CLASS_ELEMENT_EQUAL(r, data, elem) if (! (BOOST_PP_TUPLE_ELEM(1, elem) == rhs.BOOST_PP_TUPLE_ELEM(1, elem))) return false; + +#define PRINT_CONFIG_CLASS_DEFINE(CLASS_NAME, PARAMETER_DEFINITION_SEQ) \ +class CLASS_NAME : public StaticPrintConfig { \ + STATIC_PRINT_CONFIG_CACHE(CLASS_NAME) \ +public: \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_DEFINITION, _, PARAMETER_DEFINITION_SEQ) \ + size_t hash() const throw() \ + { \ + size_t seed = 0; \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_HASH, _, PARAMETER_DEFINITION_SEQ) \ + return seed; \ + } \ + bool operator==(const CLASS_NAME &rhs) const throw() \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_EQUAL, _, PARAMETER_DEFINITION_SEQ) \ + return true; \ + } \ + bool operator!=(const CLASS_NAME &rhs) const throw() { return ! (*this == rhs); } \ +protected: \ + void initialize(StaticCacheBase &cache, const char *base_ptr) \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION, _, PARAMETER_DEFINITION_SEQ) \ + } \ +}; + +#define PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM(r, data, i, elem) BOOST_PP_COMMA_IF(i) public elem +#define PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST(CLASSES_PARENTS_TUPLE) BOOST_PP_SEQ_FOR_EACH_I(PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM(r, VALUE, i, elem) BOOST_PP_COMMA_IF(i) elem(VALUE) +#define PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, VALUE) BOOST_PP_SEQ_FOR_EACH_I(PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM, VALUE, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM(r, data, elem) this->elem::initialize(cache, base_ptr); +#define PRINT_CONFIG_CLASS_DERIVED_INITCACHE(CLASSES_PARENTS_TUPLE) BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) +#define PRINT_CONFIG_CLASS_DERIVED_HASH(r, data, elem) boost::hash_combine(seed, static_cast(this)->hash()); +#define PRINT_CONFIG_CLASS_DERIVED_EQUAL(r, data, elem) \ + if (! (*static_cast(this) == static_cast(rhs))) return false; + +// Generic version, with or without new parameters. Don't use this directly. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, PARAMETER_DEFINITION, PARAMETER_REGISTRATION, PARAMETER_HASHES, PARAMETER_EQUALS) \ +class CLASS_NAME : PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST(CLASSES_PARENTS_TUPLE) { \ + STATIC_PRINT_CONFIG_CACHE_DERIVED(CLASS_NAME) \ + CLASS_NAME() : PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, 0) { initialize_cache(); *this = s_cache_##CLASS_NAME.defaults(); } \ +public: \ + PARAMETER_DEFINITION \ + size_t hash() const throw() \ + { \ + size_t seed = 0; \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_HASH, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) \ + PARAMETER_HASHES \ + return seed; \ + } \ + bool operator==(const CLASS_NAME &rhs) const throw() \ + { \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_DERIVED_EQUAL, _, BOOST_PP_TUPLE_TO_SEQ(CLASSES_PARENTS_TUPLE)) \ + PARAMETER_EQUALS \ + return true; \ + } \ + bool operator!=(const CLASS_NAME &rhs) const throw() { return ! (*this == rhs); } \ +protected: \ + CLASS_NAME(int) : PRINT_CONFIG_CLASS_DERIVED_INITIALIZER(CLASSES_PARENTS_TUPLE, 1) {} \ + void initialize(StaticCacheBase &cache, const char* base_ptr) { \ + PRINT_CONFIG_CLASS_DERIVED_INITCACHE(CLASSES_PARENTS_TUPLE) \ + PARAMETER_REGISTRATION \ + } \ +}; +// Variant without adding new parameters. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE0(CLASS_NAME, CLASSES_PARENTS_TUPLE) \ + PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, BOOST_PP_EMPTY(), BOOST_PP_EMPTY(), BOOST_PP_EMPTY(), BOOST_PP_EMPTY()) +// Variant with adding new parameters. +#define PRINT_CONFIG_CLASS_DERIVED_DEFINE(CLASS_NAME, CLASSES_PARENTS_TUPLE, PARAMETER_DEFINITION_SEQ) \ + PRINT_CONFIG_CLASS_DERIVED_DEFINE1(CLASS_NAME, CLASSES_PARENTS_TUPLE, \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_DEFINITION, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_HASH, _, PARAMETER_DEFINITION_SEQ), \ + BOOST_PP_SEQ_FOR_EACH(PRINT_CONFIG_CLASS_ELEMENT_EQUAL, _, PARAMETER_DEFINITION_SEQ)) // This object is mapped to Perl as Slic3r::Config::PrintObject. -class PrintObjectConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(PrintObjectConfig) -public: - ConfigOptionFloat brim_offset; - ConfigOptionEnum brim_type; - ConfigOptionFloat brim_width; - ConfigOptionBool clip_multipart_objects; - ConfigOptionBool dont_support_bridges; - ConfigOptionFloat elefant_foot_compensation; - ConfigOptionFloatOrPercent extrusion_width; - ConfigOptionBool infill_only_where_needed; - // Force the generation of solid shells between adjacent materials/volumes. - ConfigOptionBool interface_shells; - ConfigOptionFloat layer_height; - ConfigOptionFloat raft_contact_distance; - ConfigOptionFloat raft_expansion; - ConfigOptionPercent raft_first_layer_density; - ConfigOptionFloat raft_first_layer_expansion; - ConfigOptionInt raft_layers; - ConfigOptionEnum seam_position; -// ConfigOptionFloat seam_preferred_direction; -// ConfigOptionFloat seam_preferred_direction_jitter; - ConfigOptionFloat slice_closing_radius; - ConfigOptionBool support_material; - // Automatic supports (generated based on support_material_threshold). - ConfigOptionBool support_material_auto; - // Direction of the support pattern (in XY plane). - ConfigOptionFloat support_material_angle; - ConfigOptionBool support_material_buildplate_only; - ConfigOptionFloat support_material_contact_distance; - ConfigOptionFloat support_material_bottom_contact_distance; - ConfigOptionInt support_material_enforce_layers; - ConfigOptionInt support_material_extruder; - ConfigOptionFloatOrPercent support_material_extrusion_width; - ConfigOptionBool support_material_interface_contact_loops; - ConfigOptionInt support_material_interface_extruder; - ConfigOptionInt support_material_interface_layers; - ConfigOptionInt support_material_bottom_interface_layers; - // Spacing between interface lines (the hatching distance). Set zero to get a solid interface. - ConfigOptionFloat support_material_interface_spacing; - ConfigOptionFloatOrPercent support_material_interface_speed; - ConfigOptionEnum support_material_pattern; - ConfigOptionEnum support_material_interface_pattern; - // Morphological closing of support areas. Only used for "sung" supports. - ConfigOptionFloat support_material_closing_radius; - // Spacing between support material lines (the hatching distance). - ConfigOptionFloat support_material_spacing; - ConfigOptionFloat support_material_speed; - ConfigOptionEnum support_material_style; - ConfigOptionBool support_material_synchronize_layers; - // Overhang angle threshold. - ConfigOptionInt support_material_threshold; - ConfigOptionBool support_material_with_sheath; - ConfigOptionFloatOrPercent support_material_xy_spacing; - ConfigOptionBool thick_bridges; - ConfigOptionFloat xy_size_compensation; - ConfigOptionBool wipe_into_objects; +PRINT_CONFIG_CLASS_DEFINE( + PrintObjectConfig, -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(brim_offset); - OPT_PTR(brim_type); - OPT_PTR(brim_width); - OPT_PTR(clip_multipart_objects); - OPT_PTR(dont_support_bridges); - OPT_PTR(elefant_foot_compensation); - OPT_PTR(extrusion_width); - OPT_PTR(infill_only_where_needed); - OPT_PTR(interface_shells); - OPT_PTR(layer_height); - OPT_PTR(raft_contact_distance); - OPT_PTR(raft_expansion); - OPT_PTR(raft_first_layer_density); - OPT_PTR(raft_first_layer_expansion); - OPT_PTR(raft_layers); - OPT_PTR(seam_position); - OPT_PTR(slice_closing_radius); -// OPT_PTR(seam_preferred_direction); -// OPT_PTR(seam_preferred_direction_jitter); - OPT_PTR(support_material); - OPT_PTR(support_material_auto); - OPT_PTR(support_material_angle); - OPT_PTR(support_material_buildplate_only); - OPT_PTR(support_material_contact_distance); - OPT_PTR(support_material_bottom_contact_distance); - OPT_PTR(support_material_enforce_layers); - OPT_PTR(support_material_interface_contact_loops); - OPT_PTR(support_material_extruder); - OPT_PTR(support_material_extrusion_width); - OPT_PTR(support_material_interface_extruder); - OPT_PTR(support_material_interface_layers); - OPT_PTR(support_material_bottom_interface_layers); - OPT_PTR(support_material_closing_radius); - OPT_PTR(support_material_interface_spacing); - OPT_PTR(support_material_interface_speed); - OPT_PTR(support_material_pattern); - OPT_PTR(support_material_interface_pattern); - OPT_PTR(support_material_spacing); - OPT_PTR(support_material_speed); - OPT_PTR(support_material_style); - OPT_PTR(support_material_synchronize_layers); - OPT_PTR(support_material_xy_spacing); - OPT_PTR(support_material_threshold); - OPT_PTR(support_material_with_sheath); - OPT_PTR(thick_bridges); - OPT_PTR(xy_size_compensation); - OPT_PTR(wipe_into_objects); - } -}; + ((ConfigOptionFloat, brim_offset)) + ((ConfigOptionEnum, brim_type)) + ((ConfigOptionFloat, brim_width)) + ((ConfigOptionBool, clip_multipart_objects)) + ((ConfigOptionBool, dont_support_bridges)) + ((ConfigOptionFloat, elefant_foot_compensation)) + ((ConfigOptionFloatOrPercent, extrusion_width)) + ((ConfigOptionBool, infill_only_where_needed)) + // Force the generation of solid shells between adjacent materials/volumes. + ((ConfigOptionBool, interface_shells)) + ((ConfigOptionFloat, layer_height)) + ((ConfigOptionFloat, raft_contact_distance)) + ((ConfigOptionFloat, raft_expansion)) + ((ConfigOptionPercent, raft_first_layer_density)) + ((ConfigOptionFloat, raft_first_layer_expansion)) + ((ConfigOptionInt, raft_layers)) + ((ConfigOptionEnum, seam_position)) +// ((ConfigOptionFloat, seam_preferred_direction)) +// ((ConfigOptionFloat, seam_preferred_direction_jitter)) + ((ConfigOptionFloat, slice_closing_radius)) + ((ConfigOptionBool, support_material)) + // Automatic supports (generated based on support_material_threshold). + ((ConfigOptionBool, support_material_auto)) + // Direction of the support pattern (in XY plane).` + ((ConfigOptionFloat, support_material_angle)) + ((ConfigOptionBool, support_material_buildplate_only)) + ((ConfigOptionFloat, support_material_contact_distance)) + ((ConfigOptionFloat, support_material_bottom_contact_distance)) + ((ConfigOptionInt, support_material_enforce_layers)) + ((ConfigOptionInt, support_material_extruder)) + ((ConfigOptionFloatOrPercent, support_material_extrusion_width)) + ((ConfigOptionBool, support_material_interface_contact_loops)) + ((ConfigOptionInt, support_material_interface_extruder)) + ((ConfigOptionInt, support_material_interface_layers)) + ((ConfigOptionInt, support_material_bottom_interface_layers)) + // Spacing between interface lines (the hatching distance). Set zero to get a solid interface. + ((ConfigOptionFloat, support_material_interface_spacing)) + ((ConfigOptionFloatOrPercent, support_material_interface_speed)) + ((ConfigOptionEnum, support_material_pattern)) + ((ConfigOptionEnum, support_material_interface_pattern)) + // Morphological closing of support areas. Only used for "sung" supports. + ((ConfigOptionFloat, support_material_closing_radius)) + // Spacing between support material lines (the hatching distance). + ((ConfigOptionFloat, support_material_spacing)) + ((ConfigOptionFloat, support_material_speed)) + ((ConfigOptionEnum, support_material_style)) + ((ConfigOptionBool, support_material_synchronize_layers)) + // Overhang angle threshold. + ((ConfigOptionInt, support_material_threshold)) + ((ConfigOptionBool, support_material_with_sheath)) + ((ConfigOptionFloatOrPercent, support_material_xy_spacing)) + ((ConfigOptionBool, thick_bridges)) + ((ConfigOptionFloat, xy_size_compensation)) + ((ConfigOptionBool, wipe_into_objects)) +) // This object is mapped to Perl as Slic3r::Config::PrintRegion. -class PrintRegionConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(PrintRegionConfig) -public: - ConfigOptionFloat bridge_angle; - ConfigOptionInt bottom_solid_layers; - ConfigOptionFloat bottom_solid_min_thickness; - ConfigOptionFloat bridge_flow_ratio; - ConfigOptionFloat bridge_speed; - ConfigOptionBool ensure_vertical_shell_thickness; - ConfigOptionEnum top_fill_pattern; - ConfigOptionEnum bottom_fill_pattern; - ConfigOptionFloatOrPercent external_perimeter_extrusion_width; - ConfigOptionFloatOrPercent external_perimeter_speed; - ConfigOptionBool external_perimeters_first; - ConfigOptionBool extra_perimeters; - ConfigOptionFloat fill_angle; - ConfigOptionPercent fill_density; - ConfigOptionEnum fill_pattern; - ConfigOptionEnum fuzzy_skin; - ConfigOptionFloat fuzzy_skin_thickness; - ConfigOptionFloat fuzzy_skin_point_dist; - ConfigOptionBool gap_fill_enabled; - ConfigOptionFloat gap_fill_speed; - ConfigOptionFloatOrPercent infill_anchor; - ConfigOptionFloatOrPercent infill_anchor_max; - ConfigOptionInt infill_extruder; - ConfigOptionFloatOrPercent infill_extrusion_width; - ConfigOptionInt infill_every_layers; - ConfigOptionFloatOrPercent infill_overlap; - ConfigOptionFloat infill_speed; +PRINT_CONFIG_CLASS_DEFINE( + PrintRegionConfig, + + ((ConfigOptionFloat, bridge_angle)) + ((ConfigOptionInt, bottom_solid_layers)) + ((ConfigOptionFloat, bottom_solid_min_thickness)) + ((ConfigOptionFloat, bridge_flow_ratio)) + ((ConfigOptionFloat, bridge_speed)) + ((ConfigOptionBool, ensure_vertical_shell_thickness)) + ((ConfigOptionEnum, top_fill_pattern)) + ((ConfigOptionEnum, bottom_fill_pattern)) + ((ConfigOptionFloatOrPercent, external_perimeter_extrusion_width)) + ((ConfigOptionFloatOrPercent, external_perimeter_speed)) + ((ConfigOptionBool, external_perimeters_first)) + ((ConfigOptionBool, extra_perimeters)) + ((ConfigOptionFloat, fill_angle)) + ((ConfigOptionPercent, fill_density)) + ((ConfigOptionEnum, fill_pattern)) + ((ConfigOptionEnum, fuzzy_skin)) + ((ConfigOptionFloat, fuzzy_skin_thickness)) + ((ConfigOptionFloat, fuzzy_skin_point_dist)) + ((ConfigOptionBool, gap_fill_enabled)) + ((ConfigOptionFloat, gap_fill_speed)) + ((ConfigOptionFloatOrPercent, infill_anchor)) + ((ConfigOptionFloatOrPercent, infill_anchor_max)) + ((ConfigOptionInt, infill_extruder)) + ((ConfigOptionFloatOrPercent, infill_extrusion_width)) + ((ConfigOptionInt, infill_every_layers)) + ((ConfigOptionFloatOrPercent, infill_overlap)) + ((ConfigOptionFloat, infill_speed)) // Ironing options - ConfigOptionBool ironing; - ConfigOptionEnum ironing_type; - ConfigOptionPercent ironing_flowrate; - ConfigOptionFloat ironing_spacing; - ConfigOptionFloat ironing_speed; + ((ConfigOptionBool, ironing)) + ((ConfigOptionEnum, ironing_type)) + ((ConfigOptionPercent, ironing_flowrate)) + ((ConfigOptionFloat, ironing_spacing)) + ((ConfigOptionFloat, ironing_speed)) // Detect bridging perimeters - ConfigOptionBool overhangs; - ConfigOptionInt perimeter_extruder; - ConfigOptionFloatOrPercent perimeter_extrusion_width; - ConfigOptionFloat perimeter_speed; + ((ConfigOptionBool, overhangs)) + ((ConfigOptionInt, perimeter_extruder)) + ((ConfigOptionFloatOrPercent, perimeter_extrusion_width)) + ((ConfigOptionFloat, perimeter_speed)) // Total number of perimeters. - ConfigOptionInt perimeters; - ConfigOptionFloatOrPercent small_perimeter_speed; - ConfigOptionFloat solid_infill_below_area; - ConfigOptionInt solid_infill_extruder; - ConfigOptionFloatOrPercent solid_infill_extrusion_width; - ConfigOptionInt solid_infill_every_layers; - ConfigOptionFloatOrPercent solid_infill_speed; + ((ConfigOptionInt, perimeters)) + ((ConfigOptionFloatOrPercent, small_perimeter_speed)) + ((ConfigOptionFloat, solid_infill_below_area)) + ((ConfigOptionInt, solid_infill_extruder)) + ((ConfigOptionFloatOrPercent, solid_infill_extrusion_width)) + ((ConfigOptionInt, solid_infill_every_layers)) + ((ConfigOptionFloatOrPercent, solid_infill_speed)) // Detect thin walls. - ConfigOptionBool thin_walls; - ConfigOptionFloatOrPercent top_infill_extrusion_width; - ConfigOptionInt top_solid_layers; - ConfigOptionFloat top_solid_min_thickness; - ConfigOptionFloatOrPercent top_solid_infill_speed; - ConfigOptionBool wipe_into_infill; + ((ConfigOptionBool, thin_walls)) + ((ConfigOptionFloatOrPercent, top_infill_extrusion_width)) + ((ConfigOptionInt, top_solid_layers)) + ((ConfigOptionFloat, top_solid_min_thickness)) + ((ConfigOptionFloatOrPercent, top_solid_infill_speed)) + ((ConfigOptionBool, wipe_into_infill)) +) -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(bridge_angle); - OPT_PTR(bottom_solid_layers); - OPT_PTR(bottom_solid_min_thickness); - OPT_PTR(bridge_flow_ratio); - OPT_PTR(bridge_speed); - OPT_PTR(ensure_vertical_shell_thickness); - OPT_PTR(top_fill_pattern); - OPT_PTR(bottom_fill_pattern); - OPT_PTR(external_perimeter_extrusion_width); - OPT_PTR(external_perimeter_speed); - OPT_PTR(external_perimeters_first); - OPT_PTR(extra_perimeters); - OPT_PTR(fill_angle); - OPT_PTR(fill_density); - OPT_PTR(fill_pattern); - OPT_PTR(fuzzy_skin); - OPT_PTR(fuzzy_skin_thickness); - OPT_PTR(fuzzy_skin_point_dist); - OPT_PTR(gap_fill_enabled); - OPT_PTR(gap_fill_speed); - OPT_PTR(infill_anchor); - OPT_PTR(infill_anchor_max); - OPT_PTR(infill_extruder); - OPT_PTR(infill_extrusion_width); - OPT_PTR(infill_every_layers); - OPT_PTR(infill_overlap); - OPT_PTR(infill_speed); - OPT_PTR(ironing); - OPT_PTR(ironing_type); - OPT_PTR(ironing_flowrate); - OPT_PTR(ironing_spacing); - OPT_PTR(ironing_speed); - OPT_PTR(overhangs); - OPT_PTR(perimeter_extruder); - OPT_PTR(perimeter_extrusion_width); - OPT_PTR(perimeter_speed); - OPT_PTR(perimeters); - OPT_PTR(small_perimeter_speed); - OPT_PTR(solid_infill_below_area); - OPT_PTR(solid_infill_extruder); - OPT_PTR(solid_infill_extrusion_width); - OPT_PTR(solid_infill_every_layers); - OPT_PTR(solid_infill_speed); - OPT_PTR(thin_walls); - OPT_PTR(top_infill_extrusion_width); - OPT_PTR(top_solid_infill_speed); - OPT_PTR(top_solid_layers); - OPT_PTR(top_solid_min_thickness); - OPT_PTR(wipe_into_infill); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + MachineEnvelopeConfig, -class MachineEnvelopeConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(MachineEnvelopeConfig) -public: - // Allowing the machine limits to be completely ignored or used just for time estimator. - ConfigOptionEnum machine_limits_usage; + // Allowing the machine limits to be completely ignored or used just for time estimator. + ((ConfigOptionEnum, machine_limits_usage)) // M201 X... Y... Z... E... [mm/sec^2] - ConfigOptionFloats machine_max_acceleration_x; - ConfigOptionFloats machine_max_acceleration_y; - ConfigOptionFloats machine_max_acceleration_z; - ConfigOptionFloats machine_max_acceleration_e; + ((ConfigOptionFloats, machine_max_acceleration_x)) + ((ConfigOptionFloats, machine_max_acceleration_y)) + ((ConfigOptionFloats, machine_max_acceleration_z)) + ((ConfigOptionFloats, machine_max_acceleration_e)) // M203 X... Y... Z... E... [mm/sec] - ConfigOptionFloats machine_max_feedrate_x; - ConfigOptionFloats machine_max_feedrate_y; - ConfigOptionFloats machine_max_feedrate_z; - ConfigOptionFloats machine_max_feedrate_e; + ((ConfigOptionFloats, machine_max_feedrate_x)) + ((ConfigOptionFloats, machine_max_feedrate_y)) + ((ConfigOptionFloats, machine_max_feedrate_z)) + ((ConfigOptionFloats, machine_max_feedrate_e)) // M204 P... R... T...[mm/sec^2] - ConfigOptionFloats machine_max_acceleration_extruding; - ConfigOptionFloats machine_max_acceleration_retracting; - ConfigOptionFloats machine_max_acceleration_travel; + ((ConfigOptionFloats, machine_max_acceleration_extruding)) + ((ConfigOptionFloats, machine_max_acceleration_retracting)) + ((ConfigOptionFloats, machine_max_acceleration_travel)) // M205 X... Y... Z... E... [mm/sec] - ConfigOptionFloats machine_max_jerk_x; - ConfigOptionFloats machine_max_jerk_y; - ConfigOptionFloats machine_max_jerk_z; - ConfigOptionFloats machine_max_jerk_e; + ((ConfigOptionFloats, machine_max_jerk_x)) + ((ConfigOptionFloats, machine_max_jerk_y)) + ((ConfigOptionFloats, machine_max_jerk_z)) + ((ConfigOptionFloats, machine_max_jerk_e)) // M205 T... [mm/sec] - ConfigOptionFloats machine_min_travel_rate; + ((ConfigOptionFloats, machine_min_travel_rate)) // M205 S... [mm/sec] - ConfigOptionFloats machine_min_extruding_rate; - -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(machine_limits_usage); - OPT_PTR(machine_max_acceleration_x); - OPT_PTR(machine_max_acceleration_y); - OPT_PTR(machine_max_acceleration_z); - OPT_PTR(machine_max_acceleration_e); - OPT_PTR(machine_max_feedrate_x); - OPT_PTR(machine_max_feedrate_y); - OPT_PTR(machine_max_feedrate_z); - OPT_PTR(machine_max_feedrate_e); - OPT_PTR(machine_max_acceleration_extruding); - OPT_PTR(machine_max_acceleration_retracting); - OPT_PTR(machine_max_acceleration_travel); - OPT_PTR(machine_max_jerk_x); - OPT_PTR(machine_max_jerk_y); - OPT_PTR(machine_max_jerk_z); - OPT_PTR(machine_max_jerk_e); - OPT_PTR(machine_min_travel_rate); - OPT_PTR(machine_min_extruding_rate); - } -}; + ((ConfigOptionFloats, machine_min_extruding_rate)) +) // This object is mapped to Perl as Slic3r::Config::GCode. -class GCodeConfig : public StaticPrintConfig +PRINT_CONFIG_CLASS_DEFINE( + GCodeConfig, + + ((ConfigOptionString, before_layer_gcode)) + ((ConfigOptionString, between_objects_gcode)) + ((ConfigOptionFloats, deretract_speed)) + ((ConfigOptionString, end_gcode)) + ((ConfigOptionStrings, end_filament_gcode)) + ((ConfigOptionString, extrusion_axis)) + ((ConfigOptionFloats, extrusion_multiplier)) + ((ConfigOptionFloats, filament_diameter)) + ((ConfigOptionFloats, filament_density)) + ((ConfigOptionStrings, filament_type)) + ((ConfigOptionBools, filament_soluble)) + ((ConfigOptionFloats, filament_cost)) + ((ConfigOptionFloats, filament_spool_weight)) + ((ConfigOptionFloats, filament_max_volumetric_speed)) + ((ConfigOptionFloats, filament_loading_speed)) + ((ConfigOptionFloats, filament_loading_speed_start)) + ((ConfigOptionFloats, filament_load_time)) + ((ConfigOptionFloats, filament_unloading_speed)) + ((ConfigOptionFloats, filament_unloading_speed_start)) + ((ConfigOptionFloats, filament_toolchange_delay)) + ((ConfigOptionFloats, filament_unload_time)) + ((ConfigOptionInts, filament_cooling_moves)) + ((ConfigOptionFloats, filament_cooling_initial_speed)) + ((ConfigOptionFloats, filament_minimal_purge_on_wipe_tower)) + ((ConfigOptionFloats, filament_cooling_final_speed)) + ((ConfigOptionStrings, filament_ramming_parameters)) + ((ConfigOptionBool, gcode_comments)) + ((ConfigOptionEnum, gcode_flavor)) + ((ConfigOptionBool, gcode_label_objects)) + ((ConfigOptionString, layer_gcode)) + ((ConfigOptionFloat, max_print_speed)) + ((ConfigOptionFloat, max_volumetric_speed)) +//#ifdef HAS_PRESSURE_EQUALIZER +// ((ConfigOptionFloat, max_volumetric_extrusion_rate_slope_positive)) +// ((ConfigOptionFloat, max_volumetric_extrusion_rate_slope_negative)) +//#endif + ((ConfigOptionPercents, retract_before_wipe)) + ((ConfigOptionFloats, retract_length)) + ((ConfigOptionFloats, retract_length_toolchange)) + ((ConfigOptionFloats, retract_lift)) + ((ConfigOptionFloats, retract_lift_above)) + ((ConfigOptionFloats, retract_lift_below)) + ((ConfigOptionFloats, retract_restart_extra)) + ((ConfigOptionFloats, retract_restart_extra_toolchange)) + ((ConfigOptionFloats, retract_speed)) + ((ConfigOptionString, start_gcode)) + ((ConfigOptionStrings, start_filament_gcode)) + ((ConfigOptionBool, single_extruder_multi_material)) + ((ConfigOptionBool, single_extruder_multi_material_priming)) + ((ConfigOptionBool, wipe_tower_no_sparse_layers)) + ((ConfigOptionString, toolchange_gcode)) + ((ConfigOptionFloat, travel_speed)) + ((ConfigOptionBool, use_firmware_retraction)) + ((ConfigOptionBool, use_relative_e_distances)) + ((ConfigOptionBool, use_volumetric_e)) + ((ConfigOptionBool, variable_layer_height)) + ((ConfigOptionFloat, cooling_tube_retraction)) + ((ConfigOptionFloat, cooling_tube_length)) + ((ConfigOptionBool, high_current_on_filament_swap)) + ((ConfigOptionFloat, parking_pos_retraction)) + ((ConfigOptionBool, remaining_times)) + ((ConfigOptionBool, silent_mode)) + ((ConfigOptionFloat, extra_loading_move)) + ((ConfigOptionString, color_change_gcode)) + ((ConfigOptionString, pause_print_gcode)) + ((ConfigOptionString, template_custom_gcode)) +) + +static inline std::string get_extrusion_axis(const GCodeConfig &cfg) { - STATIC_PRINT_CONFIG_CACHE(GCodeConfig) -public: - ConfigOptionString before_layer_gcode; - ConfigOptionString between_objects_gcode; - ConfigOptionFloats deretract_speed; - ConfigOptionString end_gcode; - ConfigOptionStrings end_filament_gcode; - ConfigOptionString extrusion_axis; - ConfigOptionFloats extrusion_multiplier; - ConfigOptionFloats filament_diameter; - ConfigOptionFloats filament_density; - ConfigOptionStrings filament_type; - ConfigOptionBools filament_soluble; - ConfigOptionFloats filament_cost; - ConfigOptionFloats filament_spool_weight; - ConfigOptionFloats filament_max_volumetric_speed; - ConfigOptionFloats filament_loading_speed; - ConfigOptionFloats filament_loading_speed_start; - ConfigOptionFloats filament_load_time; - ConfigOptionFloats filament_unloading_speed; - ConfigOptionFloats filament_unloading_speed_start; - ConfigOptionFloats filament_toolchange_delay; - ConfigOptionFloats filament_unload_time; - ConfigOptionInts filament_cooling_moves; - ConfigOptionFloats filament_cooling_initial_speed; - ConfigOptionFloats filament_minimal_purge_on_wipe_tower; - ConfigOptionFloats filament_cooling_final_speed; - ConfigOptionStrings filament_ramming_parameters; - ConfigOptionBool gcode_comments; - ConfigOptionEnum gcode_flavor; - ConfigOptionBool gcode_label_objects; - ConfigOptionString layer_gcode; - ConfigOptionFloat max_print_speed; - ConfigOptionFloat max_volumetric_speed; -#ifdef HAS_PRESSURE_EQUALIZER - ConfigOptionFloat max_volumetric_extrusion_rate_slope_positive; - ConfigOptionFloat max_volumetric_extrusion_rate_slope_negative; -#endif - ConfigOptionPercents retract_before_wipe; - ConfigOptionFloats retract_length; - ConfigOptionFloats retract_length_toolchange; - ConfigOptionFloats retract_lift; - ConfigOptionFloats retract_lift_above; - ConfigOptionFloats retract_lift_below; - ConfigOptionFloats retract_restart_extra; - ConfigOptionFloats retract_restart_extra_toolchange; - ConfigOptionFloats retract_speed; - ConfigOptionString start_gcode; - ConfigOptionStrings start_filament_gcode; - ConfigOptionBool single_extruder_multi_material; - ConfigOptionBool single_extruder_multi_material_priming; - ConfigOptionBool wipe_tower_no_sparse_layers; - ConfigOptionString toolchange_gcode; - ConfigOptionFloat travel_speed; - ConfigOptionBool use_firmware_retraction; - ConfigOptionBool use_relative_e_distances; - ConfigOptionBool use_volumetric_e; - ConfigOptionBool variable_layer_height; - ConfigOptionFloat cooling_tube_retraction; - ConfigOptionFloat cooling_tube_length; - ConfigOptionBool high_current_on_filament_swap; - ConfigOptionFloat parking_pos_retraction; - ConfigOptionBool remaining_times; - ConfigOptionBool silent_mode; - ConfigOptionFloat extra_loading_move; - ConfigOptionString color_change_gcode; - ConfigOptionString pause_print_gcode; - ConfigOptionString template_custom_gcode; - - std::string get_extrusion_axis() const - { - return - ((this->gcode_flavor.value == gcfMach3) || (this->gcode_flavor.value == gcfMachinekit)) ? "A" : - (this->gcode_flavor.value == gcfNoExtrusion) ? "" : this->extrusion_axis.value; - } - -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(before_layer_gcode); - OPT_PTR(between_objects_gcode); - OPT_PTR(deretract_speed); - OPT_PTR(end_gcode); - OPT_PTR(end_filament_gcode); - OPT_PTR(extrusion_axis); - OPT_PTR(extrusion_multiplier); - OPT_PTR(filament_diameter); - OPT_PTR(filament_density); - OPT_PTR(filament_type); - OPT_PTR(filament_soluble); - OPT_PTR(filament_cost); - OPT_PTR(filament_spool_weight); - OPT_PTR(filament_max_volumetric_speed); - OPT_PTR(filament_loading_speed); - OPT_PTR(filament_loading_speed_start); - OPT_PTR(filament_load_time); - OPT_PTR(filament_unloading_speed); - OPT_PTR(filament_unloading_speed_start); - OPT_PTR(filament_unload_time); - OPT_PTR(filament_toolchange_delay); - OPT_PTR(filament_cooling_moves); - OPT_PTR(filament_cooling_initial_speed); - OPT_PTR(filament_minimal_purge_on_wipe_tower); - OPT_PTR(filament_cooling_final_speed); - OPT_PTR(filament_ramming_parameters); - OPT_PTR(gcode_comments); - OPT_PTR(gcode_flavor); - OPT_PTR(gcode_label_objects); - OPT_PTR(layer_gcode); - OPT_PTR(max_print_speed); - OPT_PTR(max_volumetric_speed); -#ifdef HAS_PRESSURE_EQUALIZER - OPT_PTR(max_volumetric_extrusion_rate_slope_positive); - OPT_PTR(max_volumetric_extrusion_rate_slope_negative); -#endif /* HAS_PRESSURE_EQUALIZER */ - OPT_PTR(retract_before_wipe); - OPT_PTR(retract_length); - OPT_PTR(retract_length_toolchange); - OPT_PTR(retract_lift); - OPT_PTR(retract_lift_above); - OPT_PTR(retract_lift_below); - OPT_PTR(retract_restart_extra); - OPT_PTR(retract_restart_extra_toolchange); - OPT_PTR(retract_speed); - OPT_PTR(single_extruder_multi_material); - OPT_PTR(single_extruder_multi_material_priming); - OPT_PTR(wipe_tower_no_sparse_layers); - OPT_PTR(start_gcode); - OPT_PTR(start_filament_gcode); - OPT_PTR(toolchange_gcode); - OPT_PTR(travel_speed); - OPT_PTR(use_firmware_retraction); - OPT_PTR(use_relative_e_distances); - OPT_PTR(use_volumetric_e); - OPT_PTR(variable_layer_height); - OPT_PTR(cooling_tube_retraction); - OPT_PTR(cooling_tube_length); - OPT_PTR(high_current_on_filament_swap); - OPT_PTR(parking_pos_retraction); - OPT_PTR(remaining_times); - OPT_PTR(silent_mode); - OPT_PTR(extra_loading_move); - OPT_PTR(color_change_gcode); - OPT_PTR(pause_print_gcode); - OPT_PTR(template_custom_gcode); - } -}; + return + ((cfg.gcode_flavor.value == gcfMach3) || (cfg.gcode_flavor.value == gcfMachinekit)) ? "A" : + (cfg.gcode_flavor.value == gcfNoExtrusion) ? "" : cfg.extrusion_axis.value; +} // This object is mapped to Perl as Slic3r::Config::Print. -class PrintConfig : public MachineEnvelopeConfig, public GCodeConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(PrintConfig) - PrintConfig() : MachineEnvelopeConfig(0), GCodeConfig(0) { initialize_cache(); *this = s_cache_PrintConfig.defaults(); } -public: +PRINT_CONFIG_CLASS_DERIVED_DEFINE( + PrintConfig, + (MachineEnvelopeConfig, GCodeConfig), - ConfigOptionBool avoid_crossing_perimeters; - ConfigOptionFloatOrPercent avoid_crossing_perimeters_max_detour; - ConfigOptionPoints bed_shape; - ConfigOptionInts bed_temperature; - ConfigOptionFloat bridge_acceleration; - ConfigOptionInts bridge_fan_speed; - ConfigOptionBool complete_objects; - ConfigOptionFloats colorprint_heights; - ConfigOptionBools cooling; - ConfigOptionFloat default_acceleration; - ConfigOptionInts disable_fan_first_layers; - ConfigOptionFloat duplicate_distance; - ConfigOptionFloat extruder_clearance_height; - ConfigOptionFloat extruder_clearance_radius; - ConfigOptionStrings extruder_colour; - ConfigOptionPoints extruder_offset; - ConfigOptionBools fan_always_on; - ConfigOptionInts fan_below_layer_time; - ConfigOptionStrings filament_colour; - ConfigOptionStrings filament_notes; - ConfigOptionFloat first_layer_acceleration; - ConfigOptionInts first_layer_bed_temperature; - ConfigOptionFloatOrPercent first_layer_extrusion_width; - ConfigOptionFloatOrPercent first_layer_height; - ConfigOptionFloatOrPercent first_layer_speed; - ConfigOptionInts first_layer_temperature; - ConfigOptionInts full_fan_speed_layer; - ConfigOptionFloat infill_acceleration; - ConfigOptionBool infill_first; - ConfigOptionInts max_fan_speed; - ConfigOptionFloats max_layer_height; - ConfigOptionInts min_fan_speed; - ConfigOptionFloats min_layer_height; - ConfigOptionFloat max_print_height; - ConfigOptionFloats min_print_speed; - ConfigOptionFloat min_skirt_length; - ConfigOptionString notes; - ConfigOptionFloats nozzle_diameter; - ConfigOptionBool only_retract_when_crossing_perimeters; - ConfigOptionBool ooze_prevention; - ConfigOptionString output_filename_format; - ConfigOptionFloat perimeter_acceleration; - ConfigOptionStrings post_process; - ConfigOptionString printer_model; - ConfigOptionString printer_notes; - ConfigOptionFloat resolution; - ConfigOptionFloats retract_before_travel; - ConfigOptionBools retract_layer_change; - ConfigOptionFloat skirt_distance; - ConfigOptionInt skirt_height; - ConfigOptionBool draft_shield; - ConfigOptionInt skirts; - ConfigOptionInts slowdown_below_layer_time; - ConfigOptionBool spiral_vase; - ConfigOptionInt standby_temperature_delta; - ConfigOptionInts temperature; - ConfigOptionInt threads; - ConfigOptionBools wipe; - ConfigOptionBool wipe_tower; - ConfigOptionFloat wipe_tower_x; - ConfigOptionFloat wipe_tower_y; - ConfigOptionFloat wipe_tower_width; - ConfigOptionFloat wipe_tower_per_color_wipe; - ConfigOptionFloat wipe_tower_rotation_angle; - ConfigOptionFloat wipe_tower_brim_width; - ConfigOptionFloat wipe_tower_bridging; - ConfigOptionFloats wiping_volumes_matrix; - ConfigOptionFloats wiping_volumes_extruders; - ConfigOptionFloat z_offset; - -protected: - PrintConfig(int) : MachineEnvelopeConfig(1), GCodeConfig(1) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->MachineEnvelopeConfig::initialize(cache, base_ptr); - this->GCodeConfig::initialize(cache, base_ptr); - OPT_PTR(avoid_crossing_perimeters); - OPT_PTR(avoid_crossing_perimeters_max_detour); - OPT_PTR(bed_shape); - OPT_PTR(bed_temperature); - OPT_PTR(bridge_acceleration); - OPT_PTR(bridge_fan_speed); - OPT_PTR(complete_objects); - OPT_PTR(colorprint_heights); - OPT_PTR(cooling); - OPT_PTR(default_acceleration); - OPT_PTR(disable_fan_first_layers); - OPT_PTR(duplicate_distance); - OPT_PTR(extruder_clearance_height); - OPT_PTR(extruder_clearance_radius); - OPT_PTR(extruder_colour); - OPT_PTR(extruder_offset); - OPT_PTR(fan_always_on); - OPT_PTR(fan_below_layer_time); - OPT_PTR(filament_colour); - OPT_PTR(filament_notes); - OPT_PTR(first_layer_acceleration); - OPT_PTR(first_layer_bed_temperature); - OPT_PTR(first_layer_extrusion_width); - OPT_PTR(first_layer_height); - OPT_PTR(first_layer_speed); - OPT_PTR(first_layer_temperature); - OPT_PTR(full_fan_speed_layer); - OPT_PTR(infill_acceleration); - OPT_PTR(infill_first); - OPT_PTR(max_fan_speed); - OPT_PTR(max_layer_height); - OPT_PTR(min_fan_speed); - OPT_PTR(min_layer_height); - OPT_PTR(max_print_height); - OPT_PTR(min_print_speed); - OPT_PTR(min_skirt_length); - OPT_PTR(notes); - OPT_PTR(nozzle_diameter); - OPT_PTR(only_retract_when_crossing_perimeters); - OPT_PTR(ooze_prevention); - OPT_PTR(output_filename_format); - OPT_PTR(perimeter_acceleration); - OPT_PTR(post_process); - OPT_PTR(printer_model); - OPT_PTR(printer_notes); - OPT_PTR(resolution); - OPT_PTR(retract_before_travel); - OPT_PTR(retract_layer_change); - OPT_PTR(skirt_distance); - OPT_PTR(skirt_height); - OPT_PTR(draft_shield); - OPT_PTR(skirts); - OPT_PTR(slowdown_below_layer_time); - OPT_PTR(spiral_vase); - OPT_PTR(standby_temperature_delta); - OPT_PTR(temperature); - OPT_PTR(threads); - OPT_PTR(wipe); - OPT_PTR(wipe_tower); - OPT_PTR(wipe_tower_x); - OPT_PTR(wipe_tower_y); - OPT_PTR(wipe_tower_width); - OPT_PTR(wipe_tower_per_color_wipe); - OPT_PTR(wipe_tower_rotation_angle); - OPT_PTR(wipe_tower_brim_width); - OPT_PTR(wipe_tower_bridging); - OPT_PTR(wiping_volumes_matrix); - OPT_PTR(wiping_volumes_extruders); - OPT_PTR(z_offset); - } -}; + ((ConfigOptionBool, avoid_crossing_perimeters)) + ((ConfigOptionFloatOrPercent, avoid_crossing_perimeters_max_detour)) + ((ConfigOptionPoints, bed_shape)) + ((ConfigOptionInts, bed_temperature)) + ((ConfigOptionFloat, bridge_acceleration)) + ((ConfigOptionInts, bridge_fan_speed)) + ((ConfigOptionBool, complete_objects)) + ((ConfigOptionFloats, colorprint_heights)) + ((ConfigOptionBools, cooling)) + ((ConfigOptionFloat, default_acceleration)) + ((ConfigOptionInts, disable_fan_first_layers)) + ((ConfigOptionFloat, duplicate_distance)) + ((ConfigOptionFloat, extruder_clearance_height)) + ((ConfigOptionFloat, extruder_clearance_radius)) + ((ConfigOptionStrings, extruder_colour)) + ((ConfigOptionPoints, extruder_offset)) + ((ConfigOptionBools, fan_always_on)) + ((ConfigOptionInts, fan_below_layer_time)) + ((ConfigOptionStrings, filament_colour)) + ((ConfigOptionStrings, filament_notes)) + ((ConfigOptionFloat, first_layer_acceleration)) + ((ConfigOptionInts, first_layer_bed_temperature)) + ((ConfigOptionFloatOrPercent, first_layer_extrusion_width)) + ((ConfigOptionFloatOrPercent, first_layer_height)) + ((ConfigOptionFloatOrPercent, first_layer_speed)) + ((ConfigOptionInts, first_layer_temperature)) + ((ConfigOptionInts, full_fan_speed_layer)) + ((ConfigOptionFloat, infill_acceleration)) + ((ConfigOptionBool, infill_first)) + ((ConfigOptionInts, max_fan_speed)) + ((ConfigOptionFloats, max_layer_height)) + ((ConfigOptionInts, min_fan_speed)) + ((ConfigOptionFloats, min_layer_height)) + ((ConfigOptionFloat, max_print_height)) + ((ConfigOptionFloats, min_print_speed)) + ((ConfigOptionFloat, min_skirt_length)) + ((ConfigOptionString, notes)) + ((ConfigOptionFloats, nozzle_diameter)) + ((ConfigOptionBool, only_retract_when_crossing_perimeters)) + ((ConfigOptionBool, ooze_prevention)) + ((ConfigOptionString, output_filename_format)) + ((ConfigOptionFloat, perimeter_acceleration)) + ((ConfigOptionStrings, post_process)) + ((ConfigOptionString, printer_model)) + ((ConfigOptionString, printer_notes)) + ((ConfigOptionFloat, resolution)) + ((ConfigOptionFloats, retract_before_travel)) + ((ConfigOptionBools, retract_layer_change)) + ((ConfigOptionFloat, skirt_distance)) + ((ConfigOptionInt, skirt_height)) + ((ConfigOptionBool, draft_shield)) + ((ConfigOptionInt, skirts)) + ((ConfigOptionInts, slowdown_below_layer_time)) + ((ConfigOptionBool, spiral_vase)) + ((ConfigOptionInt, standby_temperature_delta)) + ((ConfigOptionInts, temperature)) + ((ConfigOptionInt, threads)) + ((ConfigOptionBools, wipe)) + ((ConfigOptionBool, wipe_tower)) + ((ConfigOptionFloat, wipe_tower_x)) + ((ConfigOptionFloat, wipe_tower_y)) + ((ConfigOptionFloat, wipe_tower_width)) + ((ConfigOptionFloat, wipe_tower_per_color_wipe)) + ((ConfigOptionFloat, wipe_tower_rotation_angle)) + ((ConfigOptionFloat, wipe_tower_brim_width)) + ((ConfigOptionFloat, wipe_tower_bridging)) + ((ConfigOptionFloats, wiping_volumes_matrix)) + ((ConfigOptionFloats, wiping_volumes_extruders)) + ((ConfigOptionFloat, z_offset)) +) // This object is mapped to Perl as Slic3r::Config::Full. -class FullPrintConfig : - public PrintObjectConfig, - public PrintRegionConfig, - public PrintConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(FullPrintConfig) - FullPrintConfig() : PrintObjectConfig(0), PrintRegionConfig(0), PrintConfig(0) { initialize_cache(); *this = s_cache_FullPrintConfig.defaults(); } +PRINT_CONFIG_CLASS_DERIVED_DEFINE0( + FullPrintConfig, + (PrintObjectConfig, PrintRegionConfig, PrintConfig) +) -public: - // Validate the FullPrintConfig. Returns an empty string on success, otherwise an error message is returned. - std::string validate(); +// Validate the FullPrintConfig. Returns an empty string on success, otherwise an error message is returned. +std::string validate(const FullPrintConfig &config); -protected: - // Protected constructor to be called to initialize ConfigCache::m_default. - FullPrintConfig(int) : PrintObjectConfig(0), PrintRegionConfig(0), PrintConfig(0) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->PrintObjectConfig::initialize(cache, base_ptr); - this->PrintRegionConfig::initialize(cache, base_ptr); - this->PrintConfig ::initialize(cache, base_ptr); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrintConfig, + ((ConfigOptionString, output_filename_format)) +) -// This object is mapped to Perl as Slic3r::Config::PrintRegion. -class SLAPrintConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrintConfig) -public: - ConfigOptionString output_filename_format; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrintObjectConfig, -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(output_filename_format); - } -}; - -class SLAPrintObjectConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrintObjectConfig) -public: - ConfigOptionFloat layer_height; + ((ConfigOptionFloat, layer_height)) //Number of the layers needed for the exposure time fade [3;20] - ConfigOptionInt faded_layers /*= 10*/; + ((ConfigOptionInt, faded_layers))/*= 10*/ - ConfigOptionFloat slice_closing_radius; + ((ConfigOptionFloat, slice_closing_radius)) // Enabling or disabling support creation - ConfigOptionBool supports_enable; + ((ConfigOptionBool, supports_enable)) // Diameter in mm of the pointing side of the head. - ConfigOptionFloat support_head_front_diameter /*= 0.2*/; + ((ConfigOptionFloat, support_head_front_diameter))/*= 0.2*/ // How much the pinhead has to penetrate the model surface - ConfigOptionFloat support_head_penetration /*= 0.2*/; + ((ConfigOptionFloat, support_head_penetration))/*= 0.2*/ // Width in mm from the back sphere center to the front sphere center. - ConfigOptionFloat support_head_width /*= 1.0*/; + ((ConfigOptionFloat, support_head_width))/*= 1.0*/ // Radius in mm of the support pillars. - ConfigOptionFloat support_pillar_diameter /*= 0.8*/; + ((ConfigOptionFloat, support_pillar_diameter))/*= 0.8*/ // The percentage of smaller pillars compared to the normal pillar diameter // which are used in problematic areas where a normal pilla cannot fit. - ConfigOptionPercent support_small_pillar_diameter_percent; + ((ConfigOptionPercent, support_small_pillar_diameter_percent)) // How much bridge (supporting another pinhead) can be placed on a pillar. - ConfigOptionInt support_max_bridges_on_pillar; + ((ConfigOptionInt, support_max_bridges_on_pillar)) // How the pillars are bridged together - ConfigOptionEnum support_pillar_connection_mode; + ((ConfigOptionEnum, support_pillar_connection_mode)) // Generate only ground facing supports - ConfigOptionBool support_buildplate_only; + ((ConfigOptionBool, support_buildplate_only)) // TODO: unimplemented at the moment. This coefficient will have an impact // when bridges and pillars are merged. The resulting pillar should be a bit // thicker than the ones merging into it. How much thicker? I don't know // but it will be derived from this value. - ConfigOptionFloat support_pillar_widening_factor; + ((ConfigOptionFloat, support_pillar_widening_factor)) // Radius in mm of the pillar base. - ConfigOptionFloat support_base_diameter /*= 2.0*/; + ((ConfigOptionFloat, support_base_diameter))/*= 2.0*/ // The height of the pillar base cone in mm. - ConfigOptionFloat support_base_height /*= 1.0*/; + ((ConfigOptionFloat, support_base_height))/*= 1.0*/ // The minimum distance of the pillar base from the model in mm. - ConfigOptionFloat support_base_safety_distance; /*= 1.0*/ + ((ConfigOptionFloat, support_base_safety_distance)) /*= 1.0*/ // The default angle for connecting support sticks and junctions. - ConfigOptionFloat support_critical_angle /*= 45*/; + ((ConfigOptionFloat, support_critical_angle))/*= 45*/ // The max length of a bridge in mm - ConfigOptionFloat support_max_bridge_length /*= 15.0*/; + ((ConfigOptionFloat, support_max_bridge_length))/*= 15.0*/ // The max distance of two pillars to get cross linked. - ConfigOptionFloat support_max_pillar_link_distance; + ((ConfigOptionFloat, support_max_pillar_link_distance)) // The elevation in Z direction upwards. This is the space between the pad // and the model object's bounding box bottom. Units in mm. - ConfigOptionFloat support_object_elevation /*= 5.0*/; + ((ConfigOptionFloat, support_object_elevation))/*= 5.0*/ /////// Following options influence automatic support points placement: - ConfigOptionInt support_points_density_relative; - ConfigOptionFloat support_points_minimal_distance; + ((ConfigOptionInt, support_points_density_relative)) + ((ConfigOptionFloat, support_points_minimal_distance)) // Now for the base pool (pad) ///////////////////////////////////////////// // Enabling or disabling support creation - ConfigOptionBool pad_enable; + ((ConfigOptionBool, pad_enable)) // The thickness of the pad walls - ConfigOptionFloat pad_wall_thickness /*= 2*/; + ((ConfigOptionFloat, pad_wall_thickness))/*= 2*/ // The height of the pad from the bottom to the top not considering the pit - ConfigOptionFloat pad_wall_height /*= 5*/; + ((ConfigOptionFloat, pad_wall_height))/*= 5*/ // How far should the pad extend around the contained geometry - ConfigOptionFloat pad_brim_size; + ((ConfigOptionFloat, pad_brim_size)) // The greatest distance where two individual pads are merged into one. The // distance is measured roughly from the centroids of the pads. - ConfigOptionFloat pad_max_merge_distance /*= 50*/; + ((ConfigOptionFloat, pad_max_merge_distance))/*= 50*/ // The smoothing radius of the pad edges - // ConfigOptionFloat pad_edge_radius /*= 1*/; + // ((ConfigOptionFloat, pad_edge_radius))/*= 1*/; // The slope of the pad wall... - ConfigOptionFloat pad_wall_slope; + ((ConfigOptionFloat, pad_wall_slope)) // ///////////////////////////////////////////////////////////////////////// // Zero elevation mode parameters: @@ -1215,21 +992,21 @@ public: // ///////////////////////////////////////////////////////////////////////// // Disable the elevation (ignore its value) and use the zero elevation mode - ConfigOptionBool pad_around_object; + ((ConfigOptionBool, pad_around_object)) - ConfigOptionBool pad_around_object_everywhere; + ((ConfigOptionBool, pad_around_object_everywhere)) // This is the gap between the object bottom and the generated pad - ConfigOptionFloat pad_object_gap; + ((ConfigOptionFloat, pad_object_gap)) // How far to place the connector sticks on the object pad perimeter - ConfigOptionFloat pad_object_connector_stride; + ((ConfigOptionFloat, pad_object_connector_stride)) // The width of the connectors sticks - ConfigOptionFloat pad_object_connector_width; + ((ConfigOptionFloat, pad_object_connector_width)) // How much should the tiny connectors penetrate into the model body - ConfigOptionFloat pad_object_connector_penetration; + ((ConfigOptionFloat, pad_object_connector_penetration)) // ///////////////////////////////////////////////////////////////////////// // Model hollowing parameters: @@ -1240,169 +1017,85 @@ public: // - resin removal. // ///////////////////////////////////////////////////////////////////////// - ConfigOptionBool hollowing_enable; + ((ConfigOptionBool, hollowing_enable)) // The minimum thickness of the model walls to maintain. Note that the // resulting walls may be thicker due to smoothing out fine cavities where // resin could stuck. - ConfigOptionFloat hollowing_min_thickness; + ((ConfigOptionFloat, hollowing_min_thickness)) // Indirectly controls the voxel size (resolution) used by openvdb - ConfigOptionFloat hollowing_quality; + ((ConfigOptionFloat, hollowing_quality)) // Indirectly controls the minimum size of created cavities. - ConfigOptionFloat hollowing_closing_distance; + ((ConfigOptionFloat, hollowing_closing_distance)) +) -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(layer_height); - OPT_PTR(faded_layers); - OPT_PTR(slice_closing_radius); - OPT_PTR(supports_enable); - OPT_PTR(support_head_front_diameter); - OPT_PTR(support_head_penetration); - OPT_PTR(support_head_width); - OPT_PTR(support_pillar_diameter); - OPT_PTR(support_small_pillar_diameter_percent); - OPT_PTR(support_max_bridges_on_pillar); - OPT_PTR(support_pillar_connection_mode); - OPT_PTR(support_buildplate_only); - OPT_PTR(support_pillar_widening_factor); - OPT_PTR(support_base_diameter); - OPT_PTR(support_base_height); - OPT_PTR(support_base_safety_distance); - OPT_PTR(support_critical_angle); - OPT_PTR(support_max_bridge_length); - OPT_PTR(support_max_pillar_link_distance); - OPT_PTR(support_points_density_relative); - OPT_PTR(support_points_minimal_distance); - OPT_PTR(support_object_elevation); - OPT_PTR(pad_enable); - OPT_PTR(pad_wall_thickness); - OPT_PTR(pad_wall_height); - OPT_PTR(pad_brim_size); - OPT_PTR(pad_max_merge_distance); - // OPT_PTR(pad_edge_radius); - OPT_PTR(pad_wall_slope); - OPT_PTR(pad_around_object); - OPT_PTR(pad_around_object_everywhere); - OPT_PTR(pad_object_gap); - OPT_PTR(pad_object_connector_stride); - OPT_PTR(pad_object_connector_width); - OPT_PTR(pad_object_connector_penetration); - OPT_PTR(hollowing_enable); - OPT_PTR(hollowing_min_thickness); - OPT_PTR(hollowing_quality); - OPT_PTR(hollowing_closing_distance); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAMaterialConfig, -class SLAMaterialConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAMaterialConfig) -public: - ConfigOptionFloat initial_layer_height; - ConfigOptionFloat bottle_cost; - ConfigOptionFloat bottle_volume; - ConfigOptionFloat bottle_weight; - ConfigOptionFloat material_density; - ConfigOptionFloat exposure_time; - ConfigOptionFloat initial_exposure_time; - ConfigOptionFloats material_correction; -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(initial_layer_height); - OPT_PTR(bottle_cost); - OPT_PTR(bottle_volume); - OPT_PTR(bottle_weight); - OPT_PTR(material_density); - OPT_PTR(exposure_time); - OPT_PTR(initial_exposure_time); - OPT_PTR(material_correction); - } -}; + ((ConfigOptionFloat, initial_layer_height)) + ((ConfigOptionFloat, bottle_cost)) + ((ConfigOptionFloat, bottle_volume)) + ((ConfigOptionFloat, bottle_weight)) + ((ConfigOptionFloat, material_density)) + ((ConfigOptionFloat, exposure_time)) + ((ConfigOptionFloat, initial_exposure_time)) + ((ConfigOptionFloats, material_correction)) +) -class SLAPrinterConfig : public StaticPrintConfig -{ - STATIC_PRINT_CONFIG_CACHE(SLAPrinterConfig) -public: - ConfigOptionEnum printer_technology; - ConfigOptionPoints bed_shape; - ConfigOptionFloat max_print_height; - ConfigOptionFloat display_width; - ConfigOptionFloat display_height; - ConfigOptionInt display_pixels_x; - ConfigOptionInt display_pixels_y; - ConfigOptionEnum display_orientation; - ConfigOptionBool display_mirror_x; - ConfigOptionBool display_mirror_y; - ConfigOptionFloats relative_correction; - ConfigOptionFloat absolute_correction; - ConfigOptionFloat elefant_foot_compensation; - ConfigOptionFloat elefant_foot_min_width; - ConfigOptionFloat gamma_correction; - ConfigOptionFloat fast_tilt_time; - ConfigOptionFloat slow_tilt_time; - ConfigOptionFloat area_fill; - ConfigOptionFloat min_exposure_time; - ConfigOptionFloat max_exposure_time; - ConfigOptionFloat min_initial_exposure_time; - ConfigOptionFloat max_initial_exposure_time; -protected: - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - OPT_PTR(printer_technology); - OPT_PTR(bed_shape); - OPT_PTR(max_print_height); - OPT_PTR(display_width); - OPT_PTR(display_height); - OPT_PTR(display_pixels_x); - OPT_PTR(display_pixels_y); - OPT_PTR(display_mirror_x); - OPT_PTR(display_mirror_y); - OPT_PTR(display_orientation); - OPT_PTR(relative_correction); - OPT_PTR(absolute_correction); - OPT_PTR(elefant_foot_compensation); - OPT_PTR(elefant_foot_min_width); - OPT_PTR(gamma_correction); - OPT_PTR(fast_tilt_time); - OPT_PTR(slow_tilt_time); - OPT_PTR(area_fill); - OPT_PTR(min_exposure_time); - OPT_PTR(max_exposure_time); - OPT_PTR(min_initial_exposure_time); - OPT_PTR(max_initial_exposure_time); - } -}; +PRINT_CONFIG_CLASS_DEFINE( + SLAPrinterConfig, -class SLAFullPrintConfig : public SLAPrinterConfig, public SLAPrintConfig, public SLAPrintObjectConfig, public SLAMaterialConfig -{ - STATIC_PRINT_CONFIG_CACHE_DERIVED(SLAFullPrintConfig) - SLAFullPrintConfig() : SLAPrinterConfig(0), SLAPrintConfig(0), SLAPrintObjectConfig(0), SLAMaterialConfig(0) { initialize_cache(); *this = s_cache_SLAFullPrintConfig.defaults(); } + ((ConfigOptionEnum, printer_technology)) + ((ConfigOptionPoints, bed_shape)) + ((ConfigOptionFloat, max_print_height)) + ((ConfigOptionFloat, display_width)) + ((ConfigOptionFloat, display_height)) + ((ConfigOptionInt, display_pixels_x)) + ((ConfigOptionInt, display_pixels_y)) + ((ConfigOptionEnum,display_orientation)) + ((ConfigOptionBool, display_mirror_x)) + ((ConfigOptionBool, display_mirror_y)) + ((ConfigOptionFloats, relative_correction)) + ((ConfigOptionFloat, absolute_correction)) + ((ConfigOptionFloat, elefant_foot_compensation)) + ((ConfigOptionFloat, elefant_foot_min_width)) + ((ConfigOptionFloat, gamma_correction)) + ((ConfigOptionFloat, fast_tilt_time)) + ((ConfigOptionFloat, slow_tilt_time)) + ((ConfigOptionFloat, area_fill)) + ((ConfigOptionFloat, min_exposure_time)) + ((ConfigOptionFloat, max_exposure_time)) + ((ConfigOptionFloat, min_initial_exposure_time)) + ((ConfigOptionFloat, max_initial_exposure_time)) +) -public: - // Validate the SLAFullPrintConfig. Returns an empty string on success, otherwise an error message is returned. -// std::string validate(); - -protected: - // Protected constructor to be called to initialize ConfigCache::m_default. - SLAFullPrintConfig(int) : SLAPrinterConfig(0), SLAPrintConfig(0), SLAPrintObjectConfig(0), SLAMaterialConfig(0) {} - void initialize(StaticCacheBase &cache, const char *base_ptr) - { - this->SLAPrinterConfig ::initialize(cache, base_ptr); - this->SLAPrintConfig ::initialize(cache, base_ptr); - this->SLAPrintObjectConfig::initialize(cache, base_ptr); - this->SLAMaterialConfig ::initialize(cache, base_ptr); - } -}; +PRINT_CONFIG_CLASS_DERIVED_DEFINE0( + SLAFullPrintConfig, + (SLAPrinterConfig, SLAPrintConfig, SLAPrintObjectConfig, SLAMaterialConfig) +) #undef STATIC_PRINT_CONFIG_CACHE #undef STATIC_PRINT_CONFIG_CACHE_BASE #undef STATIC_PRINT_CONFIG_CACHE_DERIVED -#undef OPT_PTR +#undef PRINT_CONFIG_CLASS_ELEMENT_DEFINITION +#undef PRINT_CONFIG_CLASS_ELEMENT_EQUAL +#undef PRINT_CONFIG_CLASS_ELEMENT_HASH +#undef PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION +#undef PRINT_CONFIG_CLASS_ELEMENT_INITIALIZATION2 +#undef PRINT_CONFIG_CLASS_DEFINE +#undef PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST +#undef PRINT_CONFIG_CLASS_DERIVED_CLASS_LIST_ITEM +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE0 +#undef PRINT_CONFIG_CLASS_DERIVED_DEFINE1 +#undef PRINT_CONFIG_CLASS_DERIVED_HASH +#undef PRINT_CONFIG_CLASS_DERIVED_EQUAL +#undef PRINT_CONFIG_CLASS_DERIVED_INITCACHE_ITEM +#undef PRINT_CONFIG_CLASS_DERIVED_INITCACHE +#undef PRINT_CONFIG_CLASS_DERIVED_INITIALIZER +#undef PRINT_CONFIG_CLASS_DERIVED_INITIALIZER_ITEM class CLIActionsConfigDef : public ConfigDef { diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index d8b60bc84..52a5e7d83 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -108,7 +108,7 @@ std::string get_extrusion_axis() %code{% if (GCodeConfig* config = dynamic_cast(THIS)) { - RETVAL = config->get_extrusion_axis(); + RETVAL = get_extrusion_axis(*config); } else { CONFESS("This StaticConfig object does not provide get_extrusion_axis()"); }