From 3c862836f284a09b283404680094abb45f3a7464 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 16 Dec 2015 12:33:19 +0100 Subject: [PATCH] Refactored the Config XS bindings --- lib/Slic3r.pm | 1 + lib/Slic3r/Config.pm | 18 ++-- lib/Slic3r/GCode/Reader.pm | 2 +- lib/Slic3r/Print.pm | 2 +- lib/Slic3r/Print/GCode.pm | 6 +- xs/lib/Slic3r/XS.pm | 1 + xs/src/libslic3r/Config.cpp | 23 +++-- xs/src/libslic3r/Config.hpp | 14 +-- xs/src/libslic3r/PrintConfig.hpp | 42 ++++----- xs/src/perlglue.cpp | 1 + xs/xsp/Config.xsp | 145 +++++-------------------------- xs/xsp/Extruder.xsp | 3 +- xs/xsp/GCode.xsp | 12 ++- xs/xsp/GCodeWriter.xsp | 2 +- xs/xsp/PerimeterGenerator.xsp | 11 ++- xs/xsp/Print.xsp | 10 +-- xs/xsp/my.map | 3 + xs/xsp/typemap.xspt | 2 + 18 files changed, 104 insertions(+), 194 deletions(-) diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index be2979121..d093c609f 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -186,6 +186,7 @@ sub thread_cleanup { *Slic3r::Config::Print::DESTROY = sub {}; *Slic3r::Config::PrintObject::DESTROY = sub {}; *Slic3r::Config::PrintRegion::DESTROY = sub {}; + *Slic3r::Config::Static::DESTROY = sub {}; *Slic3r::ExPolygon::DESTROY = sub {}; *Slic3r::ExPolygon::Collection::DESTROY = sub {}; *Slic3r::Extruder::DESTROY = sub {}; diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index db7ff9691..a98565b83 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -389,19 +389,13 @@ sub read_ini { return $ini; } -package Slic3r::Config::GCode; +package Slic3r::Config::Static; use parent 'Slic3r::Config'; -package Slic3r::Config::Print; -use parent 'Slic3r::Config'; - -package Slic3r::Config::PrintObject; -use parent 'Slic3r::Config'; - -package Slic3r::Config::PrintRegion; -use parent 'Slic3r::Config'; - -package Slic3r::Config::Full; -use parent 'Slic3r::Config'; +sub Slic3r::Config::GCode::new { Slic3r::Config::Static::new_GCodeConfig } +sub Slic3r::Config::Print::new { Slic3r::Config::Static::new_PrintConfig } +sub Slic3r::Config::PrintObject::new { Slic3r::Config::Static::new_PrintObjectConfig } +sub Slic3r::Config::PrintRegion::new { Slic3r::Config::Static::new_PrintRegionConfig } +sub Slic3r::Config::Full::new { Slic3r::Config::Static::new_FullPrintConfig } 1; diff --git a/lib/Slic3r/GCode/Reader.pm b/lib/Slic3r/GCode/Reader.pm index bd82fc5b1..6743e6f83 100644 --- a/lib/Slic3r/GCode/Reader.pm +++ b/lib/Slic3r/GCode/Reader.pm @@ -15,7 +15,7 @@ my @AXES = qw(X Y Z E); sub apply_print_config { my ($self, $print_config) = @_; - $self->config->apply_print_config($print_config); + $self->config->apply_static($print_config); $self->_extrusion_axis($self->config->get_extrusion_axis); } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 6f1ff062f..95ae87377 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -287,7 +287,7 @@ sub make_skirt { $extruded_length[$extruder_idx] ||= 0; if (!$extruders_e_per_mm[$extruder_idx]) { my $config = Slic3r::Config::GCode->new; - $config->apply_print_config($self->config); + $config->apply_static($self->config); my $extruder = Slic3r::Extruder->new($extruder_idx, $config); $extruders_e_per_mm[$extruder_idx] = $extruder->e_per_mm($mm3_per_mm); } diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index 5b55fc148..0c458979d 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -353,7 +353,7 @@ sub process_layer { my $gcode = ""; my $object = $layer->object; - $self->_gcodegen->config->apply_object_config($object->config); + $self->_gcodegen->config->apply_static($object->config); # check whether we're going to apply spiralvase logic if (defined $self->_spiral_vase) { @@ -594,7 +594,7 @@ sub _extrude_perimeters { my $gcode = ""; foreach my $region_id (sort keys %$entities_by_region) { - $self->_gcodegen->config->apply_region_config($self->print->get_region($region_id)->config); + $self->_gcodegen->config->apply_static($self->print->get_region($region_id)->config); $gcode .= $self->_gcodegen->extrude($_, 'perimeter', -1) for @{ $entities_by_region->{$region_id} }; } @@ -606,7 +606,7 @@ sub _extrude_infill { my $gcode = ""; foreach my $region_id (sort keys %$entities_by_region) { - $self->_gcodegen->config->apply_region_config($self->print->get_region($region_id)->config); + $self->_gcodegen->config->apply_static($self->print->get_region($region_id)->config); my $collection = Slic3r::ExtrusionPath::Collection->new(@{ $entities_by_region->{$region_id} }); for my $fill (@{$collection->chained_path_from($self->_gcodegen->last_pos, 0)}) { diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index c27154a20..4f53966de 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -208,6 +208,7 @@ for my $class (qw( Slic3r::Config::Print Slic3r::Config::PrintObject Slic3r::Config::PrintRegion + Slic3r::Config::Static Slic3r::ExPolygon Slic3r::ExPolygon::Collection Slic3r::Extruder diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 3fa3b5db5..fe5c7beb5 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -150,6 +150,16 @@ ConfigBase::setenv_() #endif } +const ConfigOption* +ConfigBase::option(const t_config_option_key &opt_key) const { + return const_cast(this)->option(opt_key, false); +} + +ConfigOption* +ConfigBase::option(const t_config_option_key &opt_key, bool create) { + return this->optptr(opt_key, create); +} + DynamicConfig& DynamicConfig::operator= (DynamicConfig other) { this->swap(other); @@ -175,7 +185,7 @@ DynamicConfig::DynamicConfig (const DynamicConfig& other) { } ConfigOption* -DynamicConfig::option(const t_config_option_key &opt_key, bool create) { +DynamicConfig::optptr(const t_config_option_key &opt_key, bool create) { if (this->options.count(opt_key) == 0) { if (create) { const ConfigOptionDef* optdef = this->def->get(opt_key); @@ -231,11 +241,6 @@ template ConfigOptionBool* DynamicConfig::opt(const t_config_o template ConfigOptionBools* DynamicConfig::opt(const t_config_option_key &opt_key, bool create); template ConfigOptionPercent* DynamicConfig::opt(const t_config_option_key &opt_key, bool create); -const ConfigOption* -DynamicConfig::option(const t_config_option_key &opt_key) const { - return const_cast(this)->option(opt_key, false); -} - t_config_option_keys DynamicConfig::keys() const { t_config_option_keys keys; @@ -273,10 +278,4 @@ StaticConfig::keys() const { return keys; } -const ConfigOption* -StaticConfig::option(const t_config_option_key &opt_key) const -{ - return const_cast(this)->option(opt_key, false); -} - } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 8f94ceda6..1bd48e173 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -546,9 +546,11 @@ class ConfigBase const ConfigDef* def; ConfigBase() : def(NULL) {}; + virtual ~ConfigBase() {}; bool has(const t_config_option_key &opt_key); - virtual ConfigOption* option(const t_config_option_key &opt_key, bool create = false) = 0; - virtual const ConfigOption* option(const t_config_option_key &opt_key) const = 0; + const ConfigOption* option(const t_config_option_key &opt_key) const; + ConfigOption* option(const t_config_option_key &opt_key, bool create = false); + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) = 0; virtual t_config_option_keys keys() const = 0; void apply(const ConfigBase &other, bool ignore_nonexistent = false); bool equals(ConfigBase &other); @@ -567,10 +569,9 @@ class DynamicConfig : public virtual ConfigBase DynamicConfig(const DynamicConfig& other); DynamicConfig& operator= (DynamicConfig other); void swap(DynamicConfig &other); - ~DynamicConfig(); + virtual ~DynamicConfig(); template T* opt(const t_config_option_key &opt_key, bool create = false); - ConfigOption* option(const t_config_option_key &opt_key, bool create = false); - const ConfigOption* option(const t_config_option_key &opt_key) const; + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false); t_config_option_keys keys() const; void erase(const t_config_option_key &opt_key); @@ -584,8 +585,7 @@ class StaticConfig : public virtual ConfigBase public: StaticConfig() : ConfigBase() {}; t_config_option_keys keys() const; - virtual ConfigOption* option(const t_config_option_key &opt_key, bool create = false) = 0; - const ConfigOption* option(const t_config_option_key &opt_key) const; + //virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) = 0; void set_defaults(); }; diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index b14e669c6..cfcb75d60 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -93,13 +93,13 @@ class DynamicPrintConfig : public PrintConfigBase, public DynamicConfig void normalize(); }; -class StaticPrintConfigBase : public PrintConfigBase, public StaticConfig +class StaticPrintConfig : public PrintConfigBase, public StaticConfig { public: - StaticPrintConfigBase() : PrintConfigBase(), StaticConfig() {}; + StaticPrintConfig() : PrintConfigBase(), StaticConfig() {}; }; -class PrintObjectConfig : public virtual StaticPrintConfigBase +class PrintObjectConfig : public virtual StaticPrintConfig { public: ConfigOptionBool dont_support_bridges; @@ -126,11 +126,11 @@ class PrintObjectConfig : public virtual StaticPrintConfigBase ConfigOptionInt support_material_threshold; ConfigOptionFloat xy_size_compensation; - PrintObjectConfig() : StaticPrintConfigBase() { + PrintObjectConfig() : StaticPrintConfig() { this->set_defaults(); }; - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(dont_support_bridges); OPT_PTR(extrusion_width); OPT_PTR(first_layer_height); @@ -159,7 +159,7 @@ class PrintObjectConfig : public virtual StaticPrintConfigBase }; }; -class PrintRegionConfig : public virtual StaticPrintConfigBase +class PrintRegionConfig : public virtual StaticPrintConfig { public: ConfigOptionInt bottom_solid_layers; @@ -195,11 +195,11 @@ class PrintRegionConfig : public virtual StaticPrintConfigBase ConfigOptionInt top_solid_layers; ConfigOptionFloatOrPercent top_solid_infill_speed; - PrintRegionConfig() : StaticPrintConfigBase() { + PrintRegionConfig() : StaticPrintConfig() { this->set_defaults(); }; - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(bottom_solid_layers); OPT_PTR(bridge_flow_ratio); OPT_PTR(bridge_speed); @@ -237,7 +237,7 @@ class PrintRegionConfig : public virtual StaticPrintConfigBase }; }; -class GCodeConfig : public virtual StaticPrintConfigBase +class GCodeConfig : public virtual StaticPrintConfig { public: ConfigOptionString before_layer_gcode; @@ -264,11 +264,11 @@ class GCodeConfig : public virtual StaticPrintConfigBase ConfigOptionBool use_relative_e_distances; ConfigOptionBool use_volumetric_e; - GCodeConfig() : StaticPrintConfigBase() { + GCodeConfig() : StaticPrintConfig() { this->set_defaults(); }; - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(before_layer_gcode); OPT_PTR(end_gcode); OPT_PTR(extrusion_axis); @@ -366,7 +366,7 @@ class PrintConfig : public GCodeConfig this->set_defaults(); }; - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(avoid_crossing_perimeters); OPT_PTR(bed_shape); OPT_PTR(bed_temperature); @@ -420,13 +420,13 @@ class PrintConfig : public GCodeConfig // look in parent class ConfigOption* opt; - if ((opt = GCodeConfig::option(opt_key, create)) != NULL) return opt; + if ((opt = GCodeConfig::optptr(opt_key, create)) != NULL) return opt; return NULL; }; }; -class HostConfig : public virtual StaticPrintConfigBase +class HostConfig : public virtual StaticPrintConfig { public: ConfigOptionString octoprint_host; @@ -434,11 +434,11 @@ class HostConfig : public virtual StaticPrintConfigBase ConfigOptionString serial_port; ConfigOptionInt serial_speed; - HostConfig() : StaticPrintConfigBase() { + HostConfig() : StaticPrintConfig() { this->set_defaults(); }; - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { OPT_PTR(octoprint_host); OPT_PTR(octoprint_apikey); OPT_PTR(serial_port); @@ -452,12 +452,12 @@ class FullPrintConfig : public PrintObjectConfig, public PrintRegionConfig, public PrintConfig, public HostConfig { public: - ConfigOption* option(const t_config_option_key &opt_key, bool create = false) { + virtual ConfigOption* optptr(const t_config_option_key &opt_key, bool create = false) { ConfigOption* opt; - if ((opt = PrintObjectConfig::option(opt_key, create)) != NULL) return opt; - if ((opt = PrintRegionConfig::option(opt_key, create)) != NULL) return opt; - if ((opt = PrintConfig::option(opt_key, create)) != NULL) return opt; - if ((opt = HostConfig::option(opt_key, create)) != NULL) return opt; + if ((opt = PrintObjectConfig::optptr(opt_key, create)) != NULL) return opt; + if ((opt = PrintRegionConfig::optptr(opt_key, create)) != NULL) return opt; + if ((opt = PrintConfig::optptr(opt_key, create)) != NULL) return opt; + if ((opt = HostConfig::optptr(opt_key, create)) != NULL) return opt; return NULL; }; }; diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp index 22769e774..0eda2ebbf 100644 --- a/xs/src/perlglue.cpp +++ b/xs/src/perlglue.cpp @@ -45,6 +45,7 @@ REGISTER_CLASS(Point3, "Point3"); REGISTER_CLASS(Pointf, "Pointf"); REGISTER_CLASS(Pointf3, "Pointf3"); REGISTER_CLASS(DynamicPrintConfig, "Config"); +REGISTER_CLASS(StaticPrintConfig, "Config::Static"); REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject"); REGISTER_CLASS(PrintRegionConfig, "Config::PrintRegion"); REGISTER_CLASS(GCodeConfig, "Config::GCode"); diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index a9de4f49f..b37a49954 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -31,7 +31,7 @@ %code{% RETVAL = THIS->diff(*other); %}; bool equals(DynamicPrintConfig* other) %code{% RETVAL = THIS->equals(*other); %}; - void apply_static(FullPrintConfig* other) + void apply_static(StaticPrintConfig* other) %code{% THIS->apply(*other, true); %}; %name{get_keys} std::vector keys(); void erase(t_config_option_key opt_key); @@ -40,9 +40,18 @@ double min_object_distance(); }; -%name{Slic3r::Config::GCode} class GCodeConfig { - GCodeConfig(); - ~GCodeConfig(); +%name{Slic3r::Config::Static} class StaticPrintConfig { + static StaticPrintConfig* new_GCodeConfig() + %code{% RETVAL = new GCodeConfig (); %}; + static StaticPrintConfig* new_PrintConfig() + %code{% RETVAL = new PrintConfig (); %}; + static StaticPrintConfig* new_PrintObjectConfig() + %code{% RETVAL = new PrintObjectConfig (); %}; + static StaticPrintConfig* new_PrintRegionConfig() + %code{% RETVAL = new PrintRegionConfig (); %}; + static StaticPrintConfig* new_FullPrintConfig() + %code{% RETVAL = new FullPrintConfig (); %}; + ~StaticPrintConfig(); bool has(t_config_option_key opt_key); SV* as_hash() %code{% RETVAL = ConfigBase__as_hash(THIS); %}; @@ -60,129 +69,19 @@ double get_abs_value(t_config_option_key opt_key); %name{get_abs_value_over} double get_abs_value(t_config_option_key opt_key, double ratio_over); - void apply_print_config(PrintConfig* other) + void apply_static(StaticPrintConfig* other) %code{% THIS->apply(*other, true); %}; void apply_dynamic(DynamicPrintConfig* other) %code{% THIS->apply(*other, true); %}; %name{get_keys} std::vector keys(); - std::string get_extrusion_axis(); - %name{setenv} void setenv_(); -}; - -%name{Slic3r::Config::Print} class PrintConfig { - PrintConfig(); - ~PrintConfig(); - bool has(t_config_option_key opt_key); - SV* as_hash() - %code{% RETVAL = ConfigBase__as_hash(THIS); %}; - SV* get(t_config_option_key opt_key) - %code{% RETVAL = ConfigBase__get(THIS, opt_key); %}; - SV* get_at(t_config_option_key opt_key, int i) - %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %}; - bool set(t_config_option_key opt_key, SV* value) - %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %}; - bool set_deserialize(t_config_option_key opt_key, SV* str) - %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %}; - void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false) - %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %}; - std::string serialize(t_config_option_key opt_key); - double get_abs_value(t_config_option_key opt_key); - %name{get_abs_value_over} - double get_abs_value(t_config_option_key opt_key, double ratio_over); - void apply_dynamic(DynamicPrintConfig* other) - %code{% THIS->apply(*other, true); %}; - %name{get_keys} std::vector keys(); - std::string get_extrusion_axis(); - %name{setenv} void setenv_(); - double min_object_distance(); -}; - -%name{Slic3r::Config::PrintRegion} class PrintRegionConfig { - PrintRegionConfig(); - ~PrintRegionConfig(); - bool has(t_config_option_key opt_key); - SV* as_hash() - %code{% RETVAL = ConfigBase__as_hash(THIS); %}; - SV* get(t_config_option_key opt_key) - %code{% RETVAL = ConfigBase__get(THIS, opt_key); %}; - SV* get_at(t_config_option_key opt_key, int i) - %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %}; - bool set(t_config_option_key opt_key, SV* value) - %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %}; - bool set_deserialize(t_config_option_key opt_key, SV* str) - %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %}; - void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false) - %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %}; - std::string serialize(t_config_option_key opt_key); - double get_abs_value(t_config_option_key opt_key); - %name{get_abs_value_over} - double get_abs_value(t_config_option_key opt_key, double ratio_over); - void apply(PrintRegionConfig* other) - %code{% THIS->apply(*other, true); %}; - void apply_dynamic(DynamicPrintConfig* other) - %code{% THIS->apply(*other, true); %}; - %name{get_keys} std::vector keys(); - %name{setenv} void setenv_(); -}; - -%name{Slic3r::Config::PrintObject} class PrintObjectConfig { - PrintObjectConfig(); - ~PrintObjectConfig(); - bool has(t_config_option_key opt_key); - SV* as_hash() - %code{% RETVAL = ConfigBase__as_hash(THIS); %}; - SV* get(t_config_option_key opt_key) - %code{% RETVAL = ConfigBase__get(THIS, opt_key); %}; - SV* get_at(t_config_option_key opt_key, int i) - %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %}; - bool set(t_config_option_key opt_key, SV* value) - %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %}; - bool set_deserialize(t_config_option_key opt_key, SV* str) - %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %}; - void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false) - %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %}; - std::string serialize(t_config_option_key opt_key); - double get_abs_value(t_config_option_key opt_key); - %name{get_abs_value_over} - double get_abs_value(t_config_option_key opt_key, double ratio_over); - void apply(PrintObjectConfig* other) - %code{% THIS->apply(*other, true); %}; - void apply_dynamic(DynamicPrintConfig* other) - %code{% THIS->apply(*other, true); %}; - %name{get_keys} std::vector keys(); - %name{setenv} void setenv_(); -}; - -%name{Slic3r::Config::Full} class FullPrintConfig { - FullPrintConfig(); - ~FullPrintConfig(); - bool has(t_config_option_key opt_key); - SV* as_hash() - %code{% RETVAL = ConfigBase__as_hash(THIS); %}; - SV* get(t_config_option_key opt_key) - %code{% RETVAL = ConfigBase__get(THIS, opt_key); %}; - SV* get_at(t_config_option_key opt_key, int i) - %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %}; - bool set(t_config_option_key opt_key, SV* value) - %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %}; - bool set_deserialize(t_config_option_key opt_key, SV* str) - %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %}; - void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false) - %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %}; - std::string serialize(t_config_option_key opt_key); - double get_abs_value(t_config_option_key opt_key); - %name{get_abs_value_over} - double get_abs_value(t_config_option_key opt_key, double ratio_over); - void apply_print_config(PrintConfig* other) - %code{% THIS->apply(*other, true); %}; - void apply_object_config(PrintObjectConfig* other) - %code{% THIS->apply(*other, true); %}; - void apply_region_config(PrintRegionConfig* other) - %code{% THIS->apply(*other, true); %}; - void apply_dynamic(DynamicPrintConfig* other) - %code{% THIS->apply(*other, true); %}; - %name{get_keys} std::vector keys(); - std::string get_extrusion_axis(); + std::string get_extrusion_axis() + %code{% + if (GCodeConfig* config = dynamic_cast(THIS)) { + RETVAL = config->get_extrusion_axis(); + } else { + CONFESS("This StaticConfig object does not provide get_extrusion_axis()"); + } + %}; %name{setenv} void setenv_(); double min_object_distance(); }; diff --git a/xs/xsp/Extruder.xsp b/xs/xsp/Extruder.xsp index 57c64d94c..2a315858e 100644 --- a/xs/xsp/Extruder.xsp +++ b/xs/xsp/Extruder.xsp @@ -6,7 +6,8 @@ %} %name{Slic3r::Extruder} class Extruder { - Extruder(unsigned int id, GCodeConfig *config); + Extruder(unsigned int id, StaticPrintConfig* config) + %code%{ RETVAL = new Extruder (id, dynamic_cast(config)); %}; ~Extruder(); void reset(); double extrude(double dE); diff --git a/xs/xsp/GCode.xsp b/xs/xsp/GCode.xsp index 8197bb1ac..5bc1bf84f 100644 --- a/xs/xsp/GCode.xsp +++ b/xs/xsp/GCode.xsp @@ -77,7 +77,7 @@ Ref origin() %code{% RETVAL = &(THIS->origin); %}; - Ref config() + Ref config() %code{% RETVAL = &(THIS->config); %}; Ref writer() @@ -145,8 +145,14 @@ void set_volumetric_speed(double value) %code{% THIS->volumetric_speed = value; %}; - void apply_print_config(PrintConfig* print_config) - %code{% THIS->apply_print_config(*print_config); %}; + void apply_print_config(StaticPrintConfig* print_config) + %code{% + if (const PrintConfig* config = dynamic_cast(print_config)) { + THIS->apply_print_config(*config); + } else { + CONFESS("A PrintConfig object was not supplied to apply_print_config()"); + } + %}; void set_extruders(std::vector extruder_ids); void set_origin(Pointf* pointf) %code{% THIS->set_origin(*pointf); %}; diff --git a/xs/xsp/GCodeWriter.xsp b/xs/xsp/GCodeWriter.xsp index 15a919da8..a51e3a44b 100644 --- a/xs/xsp/GCodeWriter.xsp +++ b/xs/xsp/GCodeWriter.xsp @@ -9,7 +9,7 @@ GCodeWriter(); ~GCodeWriter(); - Ref config() + Ref config() %code%{ RETVAL = &THIS->config; %}; bool multiple_extruders() %code{% RETVAL = THIS->multiple_extruders; %}; diff --git a/xs/xsp/PerimeterGenerator.xsp b/xs/xsp/PerimeterGenerator.xsp index b5da8156c..b4d1d94ec 100644 --- a/xs/xsp/PerimeterGenerator.xsp +++ b/xs/xsp/PerimeterGenerator.xsp @@ -7,11 +7,14 @@ %name{Slic3r::Layer::PerimeterGenerator} class PerimeterGenerator { PerimeterGenerator(SurfaceCollection* slices, double layer_height, Flow* flow, - PrintRegionConfig* config, PrintObjectConfig* object_config, - PrintConfig* print_config, ExtrusionEntityCollection* loops, + StaticPrintConfig* region_config, StaticPrintConfig* object_config, + StaticPrintConfig* print_config, ExtrusionEntityCollection* loops, ExtrusionEntityCollection* gap_fill, SurfaceCollection* fill_surfaces) %code{% RETVAL = new PerimeterGenerator(slices, layer_height, *flow, - config, object_config, print_config, loops, gap_fill, fill_surfaces); %}; + dynamic_cast(region_config), + dynamic_cast(object_config), + dynamic_cast(print_config), + loops, gap_fill, fill_surfaces); %}; ~PerimeterGenerator(); void set_lower_slices(ExPolygonCollection* lower_slices) @@ -27,7 +30,7 @@ void set_solid_infill_flow(Flow* flow) %code{% THIS->solid_infill_flow = *flow; %}; - Ref config() + Ref config() %code{% RETVAL = THIS->config; %}; void process(); diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 9e2a19ae7..27d970a5b 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -30,7 +30,7 @@ _constant() %name{Slic3r::Print::Region} class PrintRegion { // owned by Print, no constructor/destructor - Ref config() + Ref config() %code%{ RETVAL = &THIS->config; %}; Ref print(); @@ -53,7 +53,7 @@ _constant() Ref print(); Ref model_object(); - Ref config() + Ref config() %code%{ RETVAL = &THIS->config; %}; Points copies(); t_layer_height_ranges layer_height_ranges() @@ -119,11 +119,11 @@ _constant() Print(); ~Print(); - Ref config() + Ref config() %code%{ RETVAL = &THIS->config; %}; - Ref default_object_config() + Ref default_object_config() %code%{ RETVAL = &THIS->default_object_config; %}; - Ref default_region_config() + Ref default_region_config() %code%{ RETVAL = &THIS->default_region_config; %}; Ref placeholder_parser() %code%{ RETVAL = &THIS->placeholder_parser; %}; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 609c97fcd..5f87f51c2 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -32,6 +32,9 @@ Clone O_OBJECT_SLIC3R_T DynamicPrintConfig* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T +StaticPrintConfig* O_OBJECT_SLIC3R +Ref O_OBJECT_SLIC3R_T + PrintObjectConfig* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 109c3a301..37d7a9620 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -39,6 +39,8 @@ %typemap{Clone}{simple}; %typemap{DynamicPrintConfig*}; %typemap{Ref}{simple}; +%typemap{StaticPrintConfig*}; +%typemap{Ref}{simple}; %typemap{PrintObjectConfig*}; %typemap{Ref}{simple}; %typemap{PrintRegionConfig*};