More incomplete work for Flow/Extruder refactoring

This commit is contained in:
Alessandro Ranellucci 2014-01-03 18:27:46 +01:00
parent 52ce6e4a7b
commit 8ed738d3f7
27 changed files with 250 additions and 233 deletions

View file

@ -9,8 +9,10 @@ our %EXPORT_TAGS = (roles => \@EXPORT_OK);
use Slic3r::Geometry qw(PI);
has 'width' => (is => 'ro');
has 'spacing' => (is => 'ro');
has 'width' => (is => 'ro', required => 1);
has 'spacing' => (is => 'ro', required => 1);
has 'nozzle_diameter' => (is => 'ro', required => 1);
has 'bridge' => (is => 'ro', default => sub {0});
has 'scaled_width' => (is => 'lazy');
has 'scaled_spacing' => (is => 'lazy');
@ -21,32 +23,67 @@ use constant FLOW_ROLE_TOP_SOLID_INFILL => 4;
use constant FLOW_ROLE_SUPPORT_MATERIAL => 5;
use constant FLOW_ROLE_SUPPORT_MATERIAL_INTERFACE => 6;
sub BUILDARGS {
my ($self, %args) = @_;
use constant BRIDGE_EXTRA_SPACING => 0.05;
use constant OVERLAP_FACTOR => 1;
sub new_from_width {
my ($class, %args) = @_;
# the constructor can take two sets of arguments:
# - width (only absolute value), spacing
# - width (abs/%/0), role, nozzle_diameter, layer_height, bridge_flow_ratio
# (if bridge_flow_ratio == 0, we return a non-bridge flow)
if (exists $args{role}) {
if ($args{width} eq '0') {
$args{width} = $self->_width(@args{qw(role nozzle_diameter layer_height bridge_flow_ratio)});
} elsif ($args{width} =~ /^(\d+(?:\.\d+)?)%$/) {
$args{width} = $args{layer_height} * $1 / 100;
}
$args{spacing} = $self->_spacing(@args{qw(width nozzle_diameter layer_height bridge_flow_ratio)});
%args = (
width => $args{width},
spacing => $args{spacing},
);
if ($args{width} eq '0') {
$args{width} = _width(@args{qw(role nozzle_diameter layer_height bridge_flow_ratio)});
} elsif ($args{width} =~ /^(\d+(?:\.\d+)?)%$/) {
$args{width} = $args{layer_height} * $1 / 100;
}
return {%args};
return $class->new(
width => $args{width},
spacing => _spacing(@args{qw(width nozzle_diameter layer_height bridge_flow_ratio)}),
nozzle_diameter => $args{nozzle_diameter},
bridge => ($args{bridge_flow_ratio} > 0) ? 1 : 0,
);
}
sub new_from_spacing {
my ($class, %args) = @_;
return $class->new(
width => _width_from_spacing(@args{qw(spacing nozzle_diameter layer_height bridge)}),
spacing => $args{spacing},
nozzle_diameter => $args{nozzle_diameter},
bridge => $args{bridge},
);
}
sub clone {
my $self = shift;
return (ref $self)->new(
width => $self->width,
spacing => $self->spacing,
nozzle_diameter => $self->nozzle_diameter,
bridge => $self->bridge,
);
}
sub mm3_per_mm {
my ($self, $h) = @_;
my $w = $self->width;
my $s = $self->spacing;
if ($self->bridge) {
return ($s**2) * PI/4;
} elsif ($w >= ($self->nozzle_diameter + $h)) {
# rectangle with semicircles at the ends
return $w * $h + ($h**2) / 4 * (PI - 4);
} else {
# rectangle with shrunk semicircles at the ends
return $self->nozzle_diameter * $h * (1 - PI/4) + $h * $w * PI/4;
}
}
sub _width {
my ($self, $role, $nozzle_diameter, $layer_height, $bridge_flow_ratio) = @_;
my ($role, $nozzle_diameter, $layer_height, $bridge_flow_ratio) = @_;
if ($bridge_flow_ratio > 0) {
return sqrt($bridge_flow_ratio * ($nozzle_diameter**2));
@ -78,11 +115,30 @@ sub _width {
return $width;
}
sub _width_from_spacing {
my ($s, $nozzle_diameter, $h, $bridge) = @_;
if ($bridge) {
return $s - BRIDGE_EXTRA_SPACING;
}
my $w_threshold = $h + $nozzle_diameter;
my $s_threshold = $w_threshold - OVERLAP_FACTOR * ($w_threshold - ($w_threshold - $h * (1 - PI/4)));
if ($s >= $s_threshold) {
# rectangle with semicircles at the ends
return $s + OVERLAP_FACTOR * $h * (1 - PI/4);
} else {
# rectangle with shrunk semicircles at the ends
return ($s + $nozzle_diameter * OVERLAP_FACTOR * (PI/4 - 1)) / (1 + OVERLAP_FACTOR * (PI/4 - 1));
}
}
sub _spacing {
my ($self, $width, $nozzle_diameter, $layer_height, $bridge_flow_ratio) = @_;
my ($width, $nozzle_diameter, $layer_height, $bridge_flow_ratio) = @_;
if ($bridge_flow_ratio > 0) {
return $width + 0.05;
return $width + BRIDGE_EXTRA_SPACING;
}
my $min_flow_spacing;
@ -93,16 +149,7 @@ sub _spacing {
# rectangle with shrunk semicircles at the ends
$min_flow_spacing = $nozzle_diameter * (1 - PI/4) + $width * PI/4;
}
return $width - &Slic3r::OVERLAP_FACTOR * ($width - $min_flow_spacing);
}
sub clone {
my $self = shift;
return (ref $self)->new(
width => $self->width,
spacing => $self->spacing,
);
return $width - OVERLAP_FACTOR * ($width - $min_flow_spacing);
}
sub _build_scaled_width {