PrusaSlicer-NonPlainar/lib/Slic3r/Extruder.pm

96 lines
2.9 KiB
Perl
Raw Normal View History

package Slic3r::Extruder;
use Moo;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(EXTRUDER_ROLE_PERIMETER EXTRUDER_ROLE_INFILL EXTRUDER_ROLE_SUPPORT_MATERIAL
EXTRUDER_ROLE_SUPPORT_MATERIAL_INTERFACE);
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
2013-03-17 01:22:50 +00:00
use Slic3r::Geometry qw(PI scale);
2012-08-07 18:50:54 +00:00
use constant OPTIONS => [qw(
2012-08-07 19:39:45 +00:00
extruder_offset
2012-08-07 18:50:54 +00:00
nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature
retract_length retract_lift retract_speed retract_restart_extra retract_before_travel
2013-03-17 01:22:50 +00:00
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange wipe
2012-08-07 18:50:54 +00:00
)];
has 'id' => (is => 'rw', required => 1);
has $_ => (is => 'ro', required => 1) for @{&OPTIONS};
2014-01-02 16:24:23 +00:00
has 'use_relative_e_distances' => (is => 'ro', default => sub {0});
has 'E' => (is => 'rw', default => sub {0} );
has 'absolute_E' => (is => 'rw', default => sub {0} );
has 'retracted' => (is => 'rw', default => sub {0} );
has 'restart_extra' => (is => 'rw', default => sub {0} );
2012-07-03 16:05:31 +00:00
has 'e_per_mm3' => (is => 'lazy');
has 'retract_speed_mm_min' => (is => 'lazy');
use constant EXTRUDER_ROLE_PERIMETER => 1;
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}) {
2014-01-04 23:36:33 +00:00
$conf{$opt_key} = $config->get_at($opt_key, $extruder_id);
}
return $class->new(%conf);
}
2012-07-03 16:05:31 +00:00
sub _build_e_per_mm3 {
my $self = shift;
2012-07-03 16:05:31 +00:00
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));
}
sub _build_retract_speed_mm_min {
my $self = shift;
return $self->retract_speed * 60;
}
sub reset {
my ($self) = @_;
$self->E(0);
$self->absolute_E(0);
$self->retracted(0);
$self->restart_extra(0);
}
sub scaled_wipe_distance {
2013-12-24 11:03:30 +00:00
my ($self, $travel_speed) = @_;
# how far do we move in XY at travel_speed for the time needed to consume
# retract_length at retract_speed?
2013-06-03 20:49:47 +00:00
# reduce feedrate a bit; travel speed is often too high to move on existing material
# too fast = ripping of existing material; too slow = short wipe path, thus more blob
return scale($self->retract_length / $self->retract_speed * $travel_speed * 0.8);
2013-03-17 01:22:50 +00:00
}
sub extrude {
my ($self, $E) = @_;
2014-01-02 16:24:23 +00:00
$self->E(0) if $self->use_relative_e_distances;
$self->absolute_E($self->absolute_E + $E);
return $self->E($self->E + $E);
}
sub extruded_volume {
my ($self) = @_;
return $self->absolute_E * ($self->filament_diameter**2) * PI/4;
}
2012-10-29 10:17:57 +00:00
sub e_per_mm {
my ($self, $mm3_per_mm) = @_;
return $mm3_per_mm * $self->e_per_mm3;
2012-10-29 10:17:57 +00:00
}
1;