Replace multitude of Extruder fields with querying a PrintConfig object by id.
This commit is contained in:
parent
b319dc9361
commit
2565d80679
@ -25,19 +25,19 @@ use constant EXTRUDER_ROLE_INFILL => 2;
|
||||
use constant EXTRUDER_ROLE_SUPPORT_MATERIAL => 3;
|
||||
use constant EXTRUDER_ROLE_SUPPORT_MATERIAL_INTERFACE => 4;
|
||||
|
||||
sub new_from_config {
|
||||
my ($class, $config, $extruder_id) = @_;
|
||||
|
||||
my %conf = (
|
||||
id => $extruder_id,
|
||||
use_relative_e_distances => $config->use_relative_e_distances,
|
||||
);
|
||||
foreach my $opt_key (@{&OPTIONS}) {
|
||||
$conf{$opt_key} = $config->get_at($opt_key, $extruder_id);
|
||||
# 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);
|
||||
};
|
||||
}
|
||||
return $class->new(%conf);
|
||||
}
|
||||
|
||||
|
||||
sub e_per_mm3 {
|
||||
my $self = shift;
|
||||
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));
|
||||
|
@ -53,7 +53,7 @@ sub set_extruders {
|
||||
my ($self, $extruder_ids) = @_;
|
||||
|
||||
foreach my $i (@$extruder_ids) {
|
||||
$self->extruders->{$i} = my $e = Slic3r::Extruder->new_from_config($self->print_config, $i);
|
||||
$self->extruders->{$i} = my $e = Slic3r::Extruder->new($i, $self->print_config);
|
||||
$self->enable_wipe(1) if $e->wipe;
|
||||
}
|
||||
|
||||
|
@ -714,7 +714,7 @@ sub make_skirt {
|
||||
if ($self->config->min_skirt_length > 0) {
|
||||
$extruded_length[$extruder_idx] ||= 0;
|
||||
if (!$extruders_e_per_mm[$extruder_idx]) {
|
||||
my $extruder = Slic3r::Extruder->new_from_config($self->config, $extruder_idx);
|
||||
my $extruder = Slic3r::Extruder->new($extruder_idx, $self->config);
|
||||
$extruders_e_per_mm[$extruder_idx] = $extruder->e_per_mm($mm3_per_mm);
|
||||
}
|
||||
$extruded_length[$extruder_idx] += unscale $loop->length * $extruders_e_per_mm[$extruder_idx];
|
||||
|
@ -221,20 +221,9 @@ use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Extruder;
|
||||
package Slic3r::Config::Print::Ref;
|
||||
our @ISA = 'Slic3r::Config::Print';
|
||||
|
||||
sub new {
|
||||
my ($class, %args) = @_;
|
||||
|
||||
$args{extruder_offset} = Slic3r::Point->new(@{$args{extruder_offset}});
|
||||
|
||||
return $class->_new(@args{qw(
|
||||
id use_relative_e_distances
|
||||
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)});
|
||||
}
|
||||
sub DESTROY {}
|
||||
|
||||
1;
|
||||
|
@ -2,39 +2,9 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Extruder::Extruder(int id, bool use_relative_e_distances,
|
||||
const Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe)
|
||||
Extruder::Extruder(int id, PrintConfig *config)
|
||||
: id(id),
|
||||
use_relative_e_distances(use_relative_e_distances),
|
||||
extruder_offset(*extruder_offset),
|
||||
nozzle_diameter(nozzle_diameter),
|
||||
filament_diameter(filament_diameter),
|
||||
extrusion_multiplier(extrusion_multiplier),
|
||||
temperature(temperature),
|
||||
first_layer_temperature(first_layer_temperature),
|
||||
retract_length(retract_length),
|
||||
retract_lift(retract_lift),
|
||||
retract_speed(retract_speed),
|
||||
retract_restart_extra(retract_restart_extra),
|
||||
retract_before_travel(retract_before_travel),
|
||||
retract_layer_change(retract_layer_change),
|
||||
retract_length_toolchange(retract_length_toolchange),
|
||||
retract_restart_extra_toolchange(retract_restart_extra_toolchange),
|
||||
wipe(wipe)
|
||||
config(*config) // make a copy
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@ -51,7 +21,7 @@ Extruder::reset()
|
||||
double
|
||||
Extruder::extrude(double dE)
|
||||
{
|
||||
if (use_relative_e_distances) {
|
||||
if (this->use_relative_e_distances()) {
|
||||
this->E = 0;
|
||||
}
|
||||
|
||||
@ -60,4 +30,13 @@ Extruder::extrude(double dE)
|
||||
return this->E;
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::use_relative_e_distances() const
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,55 +3,28 @@
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Point.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Extruder
|
||||
{
|
||||
public:
|
||||
Extruder(int id, bool use_relative_e_distances,
|
||||
const Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe);
|
||||
Extruder(int id, PrintConfig *config);
|
||||
virtual ~Extruder() {}
|
||||
void reset();
|
||||
double extrude(double dE);
|
||||
|
||||
bool use_relative_e_distances() const;
|
||||
|
||||
int id;
|
||||
bool use_relative_e_distances;
|
||||
double E;
|
||||
double absolute_E;
|
||||
double retracted;
|
||||
double restart_extra;
|
||||
|
||||
// options:
|
||||
Point extruder_offset;
|
||||
double nozzle_diameter;
|
||||
double filament_diameter;
|
||||
double extrusion_multiplier;
|
||||
int temperature;
|
||||
int first_layer_temperature;
|
||||
double retract_length;
|
||||
double retract_lift;
|
||||
int retract_speed;
|
||||
double retract_restart_extra;
|
||||
double retract_before_travel;
|
||||
bool retract_layer_change;
|
||||
double retract_length_toolchange;
|
||||
double retract_restart_extra_toolchange;
|
||||
double wipe;
|
||||
// TODO: maybe better to keep a reference to an existing object than copy it
|
||||
PrintConfig config;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -6,22 +6,7 @@
|
||||
%}
|
||||
|
||||
%name{Slic3r::Extruder} class Extruder {
|
||||
%name{_new} Extruder(int id, bool use_relative_e_distances,
|
||||
Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe);
|
||||
Extruder(int id, PrintConfig *config);
|
||||
|
||||
~Extruder();
|
||||
void reset();
|
||||
@ -30,6 +15,7 @@
|
||||
int id() const
|
||||
%code%{ RETVAL = THIS->id; %};
|
||||
|
||||
|
||||
double E() const
|
||||
%code%{ RETVAL = THIS->E; %};
|
||||
double set_E(double val) const
|
||||
@ -47,38 +33,9 @@
|
||||
double set_restart_extra(double val) const
|
||||
%code%{ RETVAL = THIS->restart_extra = val; %};
|
||||
|
||||
Point *extruder_offset() const
|
||||
PrintConfig *config()
|
||||
%code%{
|
||||
const char *CLASS = "Slic3r::Point";
|
||||
RETVAL = new Point(THIS->extruder_offset);
|
||||
const char *CLASS = "Slic3r::Config::Print::Ref";
|
||||
RETVAL = &THIS->config;
|
||||
%};
|
||||
|
||||
double nozzle_diameter() const
|
||||
%code%{ RETVAL = THIS->nozzle_diameter; %};
|
||||
double filament_diameter() const
|
||||
%code%{ RETVAL = THIS->filament_diameter; %};
|
||||
double extrusion_multiplier() const
|
||||
%code%{ RETVAL = THIS->extrusion_multiplier; %};
|
||||
int temperature() const
|
||||
%code%{ RETVAL = THIS->temperature; %};
|
||||
int first_layer_temperature() const
|
||||
%code%{ RETVAL = THIS->first_layer_temperature; %};
|
||||
double retract_length() const
|
||||
%code%{ RETVAL = THIS->retract_length; %};
|
||||
double retract_lift() const
|
||||
%code%{ RETVAL = THIS->retract_lift; %};
|
||||
int retract_speed() const
|
||||
%code%{ RETVAL = THIS->retract_speed; %};
|
||||
double retract_restart_extra() const
|
||||
%code%{ RETVAL = THIS->retract_restart_extra; %};
|
||||
double retract_before_travel() const
|
||||
%code%{ RETVAL = THIS->retract_before_travel; %};
|
||||
bool retract_layer_change() const
|
||||
%code%{ RETVAL = THIS->retract_layer_change; %};
|
||||
double retract_length_toolchange() const
|
||||
%code%{ RETVAL = THIS->retract_length_toolchange; %};
|
||||
double retract_restart_extra_toolchange() const
|
||||
%code%{ RETVAL = THIS->retract_restart_extra_toolchange; %};
|
||||
double wipe() const
|
||||
%code%{ RETVAL = THIS->wipe; %};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user