2012-06-06 16:05:03 +00:00
|
|
|
package Slic3r::Flow;
|
|
|
|
use Moo;
|
|
|
|
|
2012-09-23 01:03:08 +00:00
|
|
|
use Slic3r::Geometry qw(PI scale);
|
2012-06-06 16:05:03 +00:00
|
|
|
|
2012-07-03 16:05:31 +00:00
|
|
|
has 'nozzle_diameter' => (is => 'ro', required => 1);
|
2012-07-27 19:13:03 +00:00
|
|
|
has 'layer_height' => (is => 'ro', default => sub { $Slic3r::Config->layer_height });
|
2013-03-16 23:21:17 +00:00
|
|
|
has 'role' => (is => 'ro', default => sub { '' });
|
2012-06-23 19:45:18 +00:00
|
|
|
|
2012-07-03 16:05:31 +00:00
|
|
|
has 'width' => (is => 'rwp', builder => 1);
|
|
|
|
has 'spacing' => (is => 'lazy');
|
2012-09-23 01:03:08 +00:00
|
|
|
has 'scaled_width' => (is => 'lazy');
|
|
|
|
has 'scaled_spacing' => (is => 'lazy');
|
2012-06-06 16:05:03 +00:00
|
|
|
|
2012-06-28 12:44:54 +00:00
|
|
|
sub BUILD {
|
2012-06-06 16:05:03 +00:00
|
|
|
my $self = shift;
|
|
|
|
|
2012-07-03 16:05:31 +00:00
|
|
|
if ($self->width =~ /^(\d+(?:\.\d+)?)%$/) {
|
|
|
|
$self->_set_width($self->layer_height * $1 / 100);
|
|
|
|
}
|
|
|
|
$self->_set_width($self->_build_width) if $self->width == 0; # auto
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _build_width {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
# here we calculate a sane default by matching the flow speed (at the nozzle) and the feed rate
|
|
|
|
my $volume = ($self->nozzle_diameter**2) * PI/4;
|
|
|
|
my $shape_threshold = $self->nozzle_diameter * $self->layer_height + ($self->layer_height**2) * PI/4;
|
|
|
|
my $width;
|
|
|
|
if ($volume >= $shape_threshold) {
|
|
|
|
# rectangle with semicircles at the ends
|
|
|
|
$width = (($self->nozzle_diameter**2) * PI + ($self->layer_height**2) * (4 - PI)) / (4 * $self->layer_height);
|
2012-06-06 16:05:03 +00:00
|
|
|
} else {
|
2012-07-03 16:05:31 +00:00
|
|
|
# rectangle with squished semicircles at the ends
|
|
|
|
$width = $self->nozzle_diameter * ($self->nozzle_diameter/$self->layer_height - 4/PI + 1);
|
2012-06-06 16:05:03 +00:00
|
|
|
}
|
|
|
|
|
2013-03-16 23:21:17 +00:00
|
|
|
my $min = $self->nozzle_diameter * 1.05;
|
|
|
|
my $max;
|
|
|
|
if ($self->role ne 'infill') {
|
|
|
|
# do not limit width for sparse infill so that we use full native flow for it
|
|
|
|
$max = $self->nozzle_diameter * 1.7;
|
|
|
|
}
|
|
|
|
$width = $max if defined($max) && $width > $max;
|
2012-07-03 16:05:31 +00:00
|
|
|
$width = $min if $width < $min;
|
|
|
|
|
|
|
|
return $width;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub _build_spacing {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
my $min_flow_spacing;
|
|
|
|
if ($self->width >= ($self->nozzle_diameter + $self->layer_height)) {
|
2012-06-06 16:05:03 +00:00
|
|
|
# rectangle with semicircles at the ends
|
2012-07-03 16:05:31 +00:00
|
|
|
$min_flow_spacing = $self->width - $self->layer_height * (1 - PI/4);
|
2012-06-06 16:05:03 +00:00
|
|
|
} else {
|
|
|
|
# rectangle with shrunk semicircles at the ends
|
2012-07-03 16:05:31 +00:00
|
|
|
$min_flow_spacing = $self->nozzle_diameter * (1 - PI/4) + $self->width * PI/4;
|
2012-06-06 16:05:03 +00:00
|
|
|
}
|
2012-07-27 19:13:03 +00:00
|
|
|
return $self->width - &Slic3r::OVERLAP_FACTOR * ($self->width - $min_flow_spacing);
|
2012-06-06 16:05:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-25 12:23:46 +00:00
|
|
|
sub clone {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return (ref $self)->new(
|
|
|
|
nozzle_diameter => $self->nozzle_diameter,
|
|
|
|
layer_height => $self->layer_height,
|
|
|
|
@_,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2013-02-27 09:43:50 +00:00
|
|
|
sub _build_scaled_width {
|
2012-11-18 14:42:59 +00:00
|
|
|
my $self = shift;
|
2013-02-27 09:43:50 +00:00
|
|
|
return scale $self->width;
|
2012-11-18 14:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 09:43:50 +00:00
|
|
|
sub _build_scaled_spacing {
|
2012-11-18 14:42:59 +00:00
|
|
|
my $self = shift;
|
2013-02-27 09:43:50 +00:00
|
|
|
return scale $self->spacing;
|
2012-11-18 14:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 09:43:50 +00:00
|
|
|
|
|
|
|
package Slic3r::Flow::Bridge;
|
|
|
|
use Moo;
|
|
|
|
extends 'Slic3r::Flow';
|
|
|
|
|
|
|
|
use Slic3r::Geometry qw(PI);
|
|
|
|
|
|
|
|
sub _build_width {
|
2012-09-23 01:03:08 +00:00
|
|
|
my $self = shift;
|
2013-02-27 09:43:50 +00:00
|
|
|
return sqrt($Slic3r::Config->bridge_flow_ratio * ($self->nozzle_diameter**2));
|
2012-09-23 01:03:08 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 09:43:50 +00:00
|
|
|
sub _build_spacing {
|
2012-09-23 01:03:08 +00:00
|
|
|
my $self = shift;
|
2013-02-27 09:43:50 +00:00
|
|
|
my $width = $self->width;
|
|
|
|
return $width + &Slic3r::OVERLAP_FACTOR * ($width * PI / 4 - $width);
|
2012-09-23 01:03:08 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 16:05:03 +00:00
|
|
|
1;
|