Skip to content

Commit

Permalink
Validate the height values entered into the layer height table.
Browse files Browse the repository at this point in the history
Clamp these values between the minimum of min_layer_height per nozzle
and the maximum of max_layer_height per nozzle.
Don't allow entering zero layer height to trim an object,
the cut dialog should be used instead.

Fixes #235
  • Loading branch information
bubnikv committed Apr 5, 2017
1 parent 6f5700a commit b66bfb4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/Slic3r/GUI/Plater.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,7 @@ sub object_settings_dialog {
my $dlg = Slic3r::GUI::Plater::ObjectSettingsDialog->new($self,
object => $self->{objects}[$obj_idx],
model_object => $model_object,
config => $self->GetFrame->config,
);
$self->pause_background_process;
$dlg->ShowModal;
Expand Down
34 changes: 31 additions & 3 deletions lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ sub new {
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, "Settings for " . $params{object}->name, wxDefaultPosition, [700,500], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
$self->{$_} = $params{$_} for keys %params;

$self->{tabpanel} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
$self->{tabpanel}->AddPage($self->{parts} = Slic3r::GUI::Plater::ObjectPartsPanel->new($self->{tabpanel}, model_object => $params{model_object}), "Parts");
$self->{tabpanel}->AddPage($self->{layers} = Slic3r::GUI::Plater::ObjectDialog::LayersTab->new($self->{tabpanel}), "Layers");
Expand Down Expand Up @@ -80,7 +80,7 @@ sub new {
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. Set layer height to zero to skip portions of the input file.",
my $label = Wx::StaticText->new($self, -1, "You can use this section to override the default layer height for parts of this object.",
wxDefaultPosition, [-1, 40]);
$label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
$sizer->Add($label, 0, wxEXPAND | wxALL, 10);
Expand Down Expand Up @@ -112,7 +112,7 @@ sub new {
my $value = $grid->GetCellValue($event->GetRow, $event->GetCol);
$value =~ s/,/./g;
$value =~ s/[^0-9.]//g;
$grid->SetCellValue($event->GetRow, $event->GetCol, $value);
$grid->SetCellValue($event->GetRow, $event->GetCol, ($event->GetCol == 2) ? $self->_clamp_layer_height($value) : $value);

# if there's no empty row, let's append one
for my $i (0 .. $grid->GetNumberRows) {
Expand All @@ -136,6 +136,34 @@ sub new {
return $self;
}

sub _clamp_layer_height
{
my ($self, $value) = @_;
# $self->GetParent->GetParent is of type Slic3r::GUI::Plater::ObjectSettingsDialog
my $config = $self->GetParent->GetParent->{config};
if ($value =~ /^[0-9,.E]+$/) {
# Looks like a number. Validate the layer height.
my $nozzle_dmrs = $config->get('nozzle_diameter');
my $min_layer_heights = $config->get('min_layer_height');
my $max_layer_heights = $config->get('max_layer_height');
my $min_layer_height = 1000.;
my $max_layer_height = 0.;
my $max_nozzle_dmr = 0.;
for (my $i = 0; $i < int(@{$nozzle_dmrs}); $i += 1) {
$min_layer_height = $min_layer_heights->[$i] if ($min_layer_heights->[$i] < $min_layer_height);
$max_layer_height = $max_layer_heights->[$i] if ($max_layer_heights->[$i] > $max_layer_height);
$max_nozzle_dmr = $nozzle_dmrs ->[$i] if ($nozzle_dmrs ->[$i] > $max_nozzle_dmr );
}
$min_layer_height = 0.005 if ($min_layer_height < 0.005);
$max_layer_height = $max_nozzle_dmr if ($max_layer_height > $max_nozzle_dmr);
return ($value < $min_layer_height) ? $min_layer_height :
($value > $max_layer_height) ? $max_layer_height : $value;
} else {
# If an invalid numeric value has been entered, use the default layer height.
return $config->get('layer_height');
}
}

sub CanClose {
my $self = shift;

Expand Down

0 comments on commit b66bfb4

Please sign in to comment.