Allow custom ranges with layer_height = 0

This commit is contained in:
Alessandro Ranellucci 2013-03-24 15:26:55 +01:00
parent b7cd362820
commit 6bc5de0b5d
2 changed files with 48 additions and 26 deletions

View File

@ -98,7 +98,7 @@ sub new {
my $sizer = Wx::BoxSizer->new(wxVERTICAL); my $sizer = Wx::BoxSizer->new(wxVERTICAL);
{ {
my $label = Wx::StaticText->new($self, -1, "You can use this section to override the default layer height for parts of this object.", my $label = Wx::StaticText->new($self, -1, "You can use this section to override the default layer height for parts of this object. Set layer height to zero to skip portions of the input file.",
wxDefaultPosition, [-1, 25]); wxDefaultPosition, [-1, 25]);
$label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); $label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
$sizer->Add($label, 0, wxEXPAND | wxALL, 10); $sizer->Add($label, 0, wxEXPAND | wxALL, 10);
@ -162,7 +162,7 @@ sub CanClose {
Slic3r::GUI::show_error($self, "Invalid Z range $min-$max."); Slic3r::GUI::show_error($self, "Invalid Z range $min-$max.");
return 0; return 0;
} }
if ($height <= 0) { if ($height < 0) {
Slic3r::GUI::show_error($self, "Invalid layer height $height."); Slic3r::GUI::show_error($self, "Invalid layer height $height.");
return 0; return 0;
} }

View File

@ -18,26 +18,50 @@ has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_m
sub BUILD { sub BUILD {
my $self = shift; my $self = shift;
# make layers # make layers taking custom heights into account
my $print_z = my $slice_z = my $raft_z = 0; my $print_z = my $slice_z = my $height = 0;
while (!@{$self->layers} || $self->layers->[-1]->slice_z < $self->size->[Z]) {
my $id = $#{$self->layers} + 1; # add raft layers
my $height = $Slic3r::Config->layer_height; for my $id (0 .. $Slic3r::Config->raft_layers-1) {
$height = $Slic3r::Config->get_value('first_layer_height') if $id == 0; $height = ($id == 0)
if (my $range = first { $_->[0] <= ($print_z + $_->[2]) && $_->[1] >= ($print_z + $_->[2]) } @{$self->layer_height_ranges}) { ? $Slic3r::Config->get_value('first_layer_height')
$height = $range->[2]; : $Slic3r::Config->layer_height;
}
$print_z += $height; $print_z += $height;
if ($id < $Slic3r::Config->raft_layers) { push @{$self->layers}, Slic3r::Layer->new(
# this is a raft layer object => $self,
$raft_z += $height; id => $id,
$slice_z = -1; height => $height,
} else { print_z => scale $print_z,
$slice_z = $print_z - ($height/2) - $raft_z; slice_z => -1,
);
} }
# loop until we have at least one layer and the max slice_z reaches the object height
my $max_z = unscale $self->size->[Z];
while (!@{$self->layers} || ($slice_z - $height) <= $max_z) {
my $id = $#{$self->layers} + 1;
# assign the default height to the layer according to the general settings
$height = ($id == 0)
? $Slic3r::Config->get_value('first_layer_height')
: $Slic3r::Config->layer_height;
# look for an applicable custom range
if (my $range = first { $_->[0] <= $slice_z && $_->[1] > $slice_z } @{$self->layer_height_ranges}) {
$height = $range->[2];
# if user set custom height to zero we should just skip the range and resume slicing over it
if ($height == 0) {
$slice_z += $range->[1] - $range->[0];
next;
}
}
$print_z += $height;
$slice_z += $height/2;
### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z; ### Slic3r::debugf "Layer %d: height = %s; slice_z = %s; print_z = %s\n", $id, $height, $slice_z, $print_z;
push @{$self->layers}, Slic3r::Layer->new( push @{$self->layers}, Slic3r::Layer->new(
@ -47,6 +71,8 @@ sub BUILD {
print_z => scale $print_z, print_z => scale $print_z,
slice_z => scale $slice_z, slice_z => scale $slice_z,
); );
$slice_z += $height/2; # add the other half layer
} }
} }
@ -131,9 +157,8 @@ sub slice {
# free memory # free memory
$self->meshes(undef); $self->meshes(undef);
# remove last layer if empty # remove last layer(s) if empty
# (we might have created it because of the $max_layer = ... + 1 code in TriangleMesh) pop @{$self->layers} while !map @{$_->lines}, @{$self->layers->[-1]->regions};
pop @{$self->layers} if !map @{$_->lines}, @{$self->layers->[-1]->regions};
foreach my $layer (@{ $self->layers }) { foreach my $layer (@{ $self->layers }) {
# make sure all layers contain layer region objects for all regions # make sure all layers contain layer region objects for all regions
@ -806,7 +831,6 @@ sub generate_support_material {
[ map @$_, @current_layer_offsetted_slices ], [ map @$_, @current_layer_offsetted_slices ],
); );
$layers_contact_areas{$i} = [ $layers_contact_areas{$i} = [
map $_->simplify($flow->scaled_spacing),
@{collapse_ex([ map @$_, @{$layers_contact_areas{$i}} ], $flow->scaled_width)}, @{collapse_ex([ map @$_, @{$layers_contact_areas{$i}} ], $flow->scaled_width)},
]; ];
@ -820,7 +844,6 @@ sub generate_support_material {
], ],
); );
$layers_interfaces{$i} = [ $layers_interfaces{$i} = [
map $_->simplify($flow->scaled_spacing),
@{collapse_ex([ map @$_, @{$layers_interfaces{$i}} ], $flow->scaled_width)}, @{collapse_ex([ map @$_, @{$layers_interfaces{$i}} ], $flow->scaled_width)},
]; ];
@ -842,7 +865,6 @@ sub generate_support_material {
], ],
); );
$layers{$i} = [ $layers{$i} = [
map $_->simplify($flow->scaled_spacing),
@{collapse_ex([ map @$_, @{$layers{$i}} ], $flow->scaled_width)}, @{collapse_ex([ map @$_, @{$layers{$i}} ], $flow->scaled_width)},
]; ];