Replace Extruder::config accessor with Perl wrapper, with C++ option accessors.
This commit is contained in:
parent
71b0b211ec
commit
e005ff32c4
@ -10,13 +10,6 @@ our %EXPORT_TAGS = (roles => \@EXPORT_OK);
|
||||
|
||||
use Slic3r::Geometry qw(PI scale);
|
||||
|
||||
use constant OPTIONS => [qw(
|
||||
extruder_offset
|
||||
nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature
|
||||
retract_length retract_lift retract_speed retract_restart_extra retract_before_travel
|
||||
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange wipe
|
||||
)];
|
||||
|
||||
# has 'e_per_mm3' => (is => 'lazy');
|
||||
# has 'retract_speed_mm_min' => (is => 'lazy');
|
||||
|
||||
@ -26,18 +19,6 @@ use constant EXTRUDER_ROLE_SUPPORT_MATERIAL => 3;
|
||||
use constant EXTRUDER_ROLE_SUPPORT_MATERIAL_INTERFACE => 4;
|
||||
|
||||
|
||||
# generate accessors
|
||||
{
|
||||
no strict 'refs';
|
||||
for my $opt_key (@{&Slic3r::Extruder::OPTIONS}) {
|
||||
*{$opt_key} = sub {
|
||||
my $self = shift;
|
||||
$self->config->get_at($opt_key, $self->id);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub e_per_mm3 {
|
||||
my $self = shift;
|
||||
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));
|
||||
|
@ -33,15 +33,119 @@ Extruder::extrude(double dE)
|
||||
return this->E;
|
||||
}
|
||||
|
||||
template <typename Val, class OptType> Val
|
||||
Extruder::get_config(const char *name) const
|
||||
{
|
||||
// TODO: figure out way to avoid static_cast to access hidden const method
|
||||
const ConfigOption *opt = static_cast<const ConfigBase*>(this->config)
|
||||
->option(name);
|
||||
return dynamic_cast<const OptType *>(opt)->get_at(this->id);
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::use_relative_e_distances() const
|
||||
{
|
||||
// not using get_config because use_relative_e_distances is global
|
||||
// for all extruders
|
||||
|
||||
// TODO: figure out way to avoid static_cast to access hidden const method
|
||||
const ConfigOption *opt = static_cast<const ConfigBase*>(this->config)
|
||||
->option("use_relative_e_distances");
|
||||
return *static_cast<const ConfigOptionBool*>(opt);
|
||||
}
|
||||
|
||||
Pointf
|
||||
Extruder::extruder_offset() const
|
||||
{
|
||||
return get_config<Pointf, ConfigOptionPoints>("extruder_offset");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::nozzle_diameter() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("nozzle_diameter");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::filament_diameter() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("filament_diameter");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::extrusion_multiplier() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("extrusion_multiplier");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::temperature() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("temperature");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::first_layer_temperature() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("first_layer_temperature");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_length() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_length");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_lift() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_lift");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::retract_speed() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("retract_speed");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_restart_extra() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_restart_extra");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_before_travel() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_before_travel");
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::retract_layer_change() const
|
||||
{
|
||||
return get_config<bool, ConfigOptionBools>("retract_layer_change");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_length_toolchange() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_length_toolchange");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_restart_extra_toolchange() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>(
|
||||
"retract_restart_extra_toolchange");
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::wipe() const
|
||||
{
|
||||
return get_config<bool, ConfigOptionBools>("wipe");
|
||||
}
|
||||
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Extruder, "Extruder");
|
||||
#endif
|
||||
|
@ -15,7 +15,23 @@ class Extruder
|
||||
void reset();
|
||||
double extrude(double dE);
|
||||
|
||||
|
||||
bool use_relative_e_distances() const;
|
||||
Pointf extruder_offset() const;
|
||||
double nozzle_diameter() const;
|
||||
double filament_diameter() const;
|
||||
double extrusion_multiplier() const;
|
||||
int temperature() const;
|
||||
int first_layer_temperature() const;
|
||||
double retract_length() const;
|
||||
double retract_lift() const;
|
||||
int retract_speed() const;
|
||||
double retract_restart_extra() const;
|
||||
double retract_before_travel() const;
|
||||
bool retract_layer_change() const;
|
||||
double retract_length_toolchange() const;
|
||||
double retract_restart_extra_toolchange() const;
|
||||
bool wipe() const;
|
||||
|
||||
int id;
|
||||
double E;
|
||||
@ -24,6 +40,13 @@ class Extruder
|
||||
double restart_extra;
|
||||
|
||||
PrintConfig *config;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// get value from a ConfigOptionVector subtype, indexed by extruder id
|
||||
template <typename Val, class OptType>
|
||||
Val get_config(const char *name) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,19 @@
|
||||
double set_restart_extra(double val) const
|
||||
%code%{ RETVAL = THIS->restart_extra = val; %};
|
||||
|
||||
PrintConfig *config()
|
||||
%code%{
|
||||
const char *CLASS = "Slic3r::Config::Print::Ref";
|
||||
RETVAL = &THIS->config;
|
||||
%};
|
||||
Clone<Pointf> extruder_offset() const;
|
||||
double nozzle_diameter() const;
|
||||
double filament_diameter() const;
|
||||
double extrusion_multiplier() const;
|
||||
int temperature() const;
|
||||
int first_layer_temperature() const;
|
||||
double retract_length() const;
|
||||
double retract_lift() const;
|
||||
int retract_speed() const;
|
||||
double retract_restart_extra() const;
|
||||
double retract_before_travel() const;
|
||||
bool retract_layer_change() const;
|
||||
double retract_length_toolchange() const;
|
||||
double retract_restart_extra_toolchange() const;
|
||||
bool wipe() const;
|
||||
};
|
||||
|
@ -25,6 +25,10 @@ Point* O_OBJECT_SLIC3R
|
||||
Ref<Point> O_OBJECT_SLIC3R_T
|
||||
Clone<Point> O_OBJECT_SLIC3R_T
|
||||
|
||||
Pointf* O_OBJECT_SLIC3R
|
||||
Ref<Pointf> O_OBJECT_SLIC3R_T
|
||||
Clone<Pointf> O_OBJECT_SLIC3R_T
|
||||
|
||||
Pointf3* O_OBJECT_SLIC3R
|
||||
Ref<Pointf3> O_OBJECT_SLIC3R_T
|
||||
Clone<Pointf3> O_OBJECT_SLIC3R_T
|
||||
|
@ -12,6 +12,9 @@
|
||||
%typemap{Point*};
|
||||
%typemap{Ref<Point>}{simple};
|
||||
%typemap{Clone<Point>}{simple};
|
||||
%typemap{Pointf*};
|
||||
%typemap{Ref<Pointf>}{simple};
|
||||
%typemap{Clone<Pointf>}{simple};
|
||||
%typemap{Pointf3*};
|
||||
%typemap{Ref<Pointf3>}{simple};
|
||||
%typemap{Clone<Pointf3>}{simple};
|
||||
|
Loading…
Reference in New Issue
Block a user