Replace multitude of Extruder fields with querying a PrintConfig object by id.

This commit is contained in:
Y. Sapir 2014-04-27 00:28:32 +03:00
parent b319dc9361
commit 2565d80679
7 changed files with 38 additions and 140 deletions

View File

@ -25,19 +25,19 @@ use constant EXTRUDER_ROLE_INFILL => 2;
use constant EXTRUDER_ROLE_SUPPORT_MATERIAL => 3; use constant EXTRUDER_ROLE_SUPPORT_MATERIAL => 3;
use constant EXTRUDER_ROLE_SUPPORT_MATERIAL_INTERFACE => 4; use constant EXTRUDER_ROLE_SUPPORT_MATERIAL_INTERFACE => 4;
sub new_from_config {
my ($class, $config, $extruder_id) = @_; # generate accessors
{
my %conf = ( no strict 'refs';
id => $extruder_id, for my $opt_key (@{&Slic3r::Extruder::OPTIONS}) {
use_relative_e_distances => $config->use_relative_e_distances, *{$opt_key} = sub {
); my $self = shift;
foreach my $opt_key (@{&OPTIONS}) { $self->config->get_at($opt_key, $self->id);
$conf{$opt_key} = $config->get_at($opt_key, $extruder_id); };
} }
return $class->new(%conf);
} }
sub e_per_mm3 { sub e_per_mm3 {
my $self = shift; my $self = shift;
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI)); return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));

View File

@ -53,7 +53,7 @@ sub set_extruders {
my ($self, $extruder_ids) = @_; my ($self, $extruder_ids) = @_;
foreach my $i (@$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; $self->enable_wipe(1) if $e->wipe;
} }

View File

@ -714,7 +714,7 @@ sub make_skirt {
if ($self->config->min_skirt_length > 0) { if ($self->config->min_skirt_length > 0) {
$extruded_length[$extruder_idx] ||= 0; $extruded_length[$extruder_idx] ||= 0;
if (!$extruders_e_per_mm[$extruder_idx]) { 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); $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]; $extruded_length[$extruder_idx] += unscale $loop->length * $extruders_e_per_mm[$extruder_idx];

View File

@ -221,20 +221,9 @@ use overload
'@{}' => sub { $_[0]->arrayref }, '@{}' => sub { $_[0]->arrayref },
'fallback' => 1; 'fallback' => 1;
package Slic3r::Extruder; package Slic3r::Config::Print::Ref;
our @ISA = 'Slic3r::Config::Print';
sub new { sub DESTROY {}
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)});
}
1; 1;

View File

@ -2,39 +2,9 @@
namespace Slic3r { namespace Slic3r {
Extruder::Extruder(int id, bool use_relative_e_distances, Extruder::Extruder(int id, PrintConfig *config)
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)
: id(id), : id(id),
use_relative_e_distances(use_relative_e_distances), config(*config) // make a copy
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)
{ {
reset(); reset();
} }
@ -51,7 +21,7 @@ Extruder::reset()
double double
Extruder::extrude(double dE) Extruder::extrude(double dE)
{ {
if (use_relative_e_distances) { if (this->use_relative_e_distances()) {
this->E = 0; this->E = 0;
} }
@ -60,4 +30,13 @@ Extruder::extrude(double dE)
return this->E; 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);
}
} }

View File

@ -3,55 +3,28 @@
#include <myinit.h> #include <myinit.h>
#include "Point.hpp" #include "Point.hpp"
#include "PrintConfig.hpp"
namespace Slic3r { namespace Slic3r {
class Extruder class Extruder
{ {
public: public:
Extruder(int id, bool use_relative_e_distances, Extruder(int id, PrintConfig *config);
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);
virtual ~Extruder() {} virtual ~Extruder() {}
void reset(); void reset();
double extrude(double dE); double extrude(double dE);
bool use_relative_e_distances() const;
int id; int id;
bool use_relative_e_distances;
double E; double E;
double absolute_E; double absolute_E;
double retracted; double retracted;
double restart_extra; double restart_extra;
// options: // TODO: maybe better to keep a reference to an existing object than copy it
Point extruder_offset; PrintConfig config;
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;
}; };
} }

View File

@ -6,22 +6,7 @@
%} %}
%name{Slic3r::Extruder} class Extruder { %name{Slic3r::Extruder} class Extruder {
%name{_new} Extruder(int id, bool use_relative_e_distances, Extruder(int id, PrintConfig *config);
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();
void reset(); void reset();
@ -30,6 +15,7 @@
int id() const int id() const
%code%{ RETVAL = THIS->id; %}; %code%{ RETVAL = THIS->id; %};
double E() const double E() const
%code%{ RETVAL = THIS->E; %}; %code%{ RETVAL = THIS->E; %};
double set_E(double val) const double set_E(double val) const
@ -47,38 +33,9 @@
double set_restart_extra(double val) const double set_restart_extra(double val) const
%code%{ RETVAL = THIS->restart_extra = val; %}; %code%{ RETVAL = THIS->restart_extra = val; %};
Point *extruder_offset() const PrintConfig *config()
%code%{ %code%{
const char *CLASS = "Slic3r::Point"; const char *CLASS = "Slic3r::Config::Print::Ref";
RETVAL = new Point(THIS->extruder_offset); 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; %};
}; };