Added a low layer slider into the 3D preview window.
This is to limit the preview to a span of layers.
This commit is contained in:
parent
b7af7276c9
commit
ae2bae137a
@ -8,7 +8,8 @@
|
||||
# for efficient building of vertex arrays for OpenGL rendering.
|
||||
#
|
||||
# Slic3r::GUI::Plater::3D derives from Slic3r::GUI::3DScene,
|
||||
# Slic3r::GUI::Plater::3DPreview, Slic3r::GUI::Plater::ObjectCutDialog and Slic3r::GUI::Plater::ObjectPartsPanel
|
||||
# Slic3r::GUI::Plater::3DPreview, Slic3r::GUI::Plater::3DToolpaths,
|
||||
# Slic3r::GUI::Plater::ObjectCutDialog and Slic3r::GUI::Plater::ObjectPartsPanel
|
||||
# own $self->{canvas} of the Slic3r::GUI::3DScene type.
|
||||
#
|
||||
# Therefore the 3DScene supports renderng of STLs, extrusions and cutting planes,
|
||||
@ -944,9 +945,13 @@ sub draw_volumes {
|
||||
}
|
||||
# This shall not happen.
|
||||
next if ($i == @{$volume->offsets});
|
||||
# Remember start of the layer.
|
||||
if ($i >= 3) {
|
||||
# Get end of the preceding layer, which is the start of the current layer.
|
||||
$qverts_begin = $volume->offsets->[$i-2];
|
||||
$tverts_begin = $volume->offsets->[$i-1];
|
||||
}
|
||||
# Some layers are above $min_z. Which?
|
||||
$qverts_begin = $volume->offsets->[$i+1];
|
||||
$tverts_begin = $volume->offsets->[$i+2];
|
||||
while ($i < @{$volume->offsets} && $volume->offsets->[$i] <= $max_z) {
|
||||
$i += 3;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use Wx qw(:misc :sizer :slider :statictext wxWHITE);
|
||||
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN);
|
||||
use base qw(Wx::Panel Class::Accessor);
|
||||
|
||||
__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider));
|
||||
__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider_low slider_high));
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
@ -19,7 +19,7 @@ sub new {
|
||||
# init GUI elements
|
||||
my $canvas = Slic3r::GUI::3DScene->new($self);
|
||||
$self->canvas($canvas);
|
||||
my $slider = Wx::Slider->new(
|
||||
my $slider_low = Wx::Slider->new(
|
||||
$self, -1,
|
||||
0, # default
|
||||
0, # min
|
||||
@ -30,34 +30,73 @@ sub new {
|
||||
wxDefaultSize,
|
||||
wxVERTICAL | wxSL_INVERSE,
|
||||
);
|
||||
$self->slider($slider);
|
||||
$self->slider_low($slider_low);
|
||||
my $slider_high = Wx::Slider->new(
|
||||
$self, -1,
|
||||
0, # default
|
||||
0, # min
|
||||
# we set max to a bogus non-zero value because the MSW implementation of wxSlider
|
||||
# will skip drawing the slider if max <= min:
|
||||
1, # max
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
wxVERTICAL | wxSL_INVERSE,
|
||||
);
|
||||
$self->slider_high($slider_high);
|
||||
|
||||
my $z_label = $self->{z_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
||||
my $z_label_low = $self->{z_label_low} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
||||
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
||||
$z_label->SetFont($Slic3r::GUI::small_font);
|
||||
$z_label_low->SetFont($Slic3r::GUI::small_font);
|
||||
my $z_label_high = $self->{z_label_high} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
||||
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
||||
$z_label_high->SetFont($Slic3r::GUI::small_font);
|
||||
|
||||
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
$vsizer->Add($slider, 1, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
|
||||
$vsizer->Add($z_label, 0, wxALL | wxEXPAND | wxALIGN_CENTER, 3);
|
||||
$vsizer->Add($slider_low, 3, 0, 0);
|
||||
$vsizer->Add($z_label_low, 0, 0, 0);
|
||||
$hsizer->Add($vsizer, 0, wxEXPAND, 0);
|
||||
$vsizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
$vsizer->Add($slider_high, 3, 0, 0);
|
||||
$vsizer->Add($z_label_high, 0, 0, 0);
|
||||
$hsizer->Add($vsizer, 0, wxEXPAND, 0);
|
||||
|
||||
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
$sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
|
||||
$sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
|
||||
$sizer->Add($hsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
|
||||
|
||||
EVT_SLIDER($self, $slider, sub {
|
||||
$self->set_z($self->{layers_z}[$slider->GetValue])
|
||||
if $self->enabled;
|
||||
EVT_SLIDER($self, $slider_low, sub {
|
||||
if ($self->enabled) {
|
||||
my $idx_low = $slider_low->GetValue;
|
||||
my $idx_high = $slider_high->GetValue;
|
||||
if ($idx_low >= $idx_high) {
|
||||
$idx_high = $idx_low;
|
||||
$self->slider_high->SetValue($idx_high);
|
||||
}
|
||||
$self->set_z_range($self->{layers_z}[$idx_low], $self->{layers_z}[$idx_high]);
|
||||
}
|
||||
});
|
||||
EVT_SLIDER($self, $slider_high, sub {
|
||||
if ($self->enabled) {
|
||||
my $idx_low = $slider_low->GetValue;
|
||||
my $idx_high = $slider_high->GetValue;
|
||||
if ($idx_low > $idx_high) {
|
||||
$idx_low = $idx_high;
|
||||
$self->slider_low->SetValue($idx_low);
|
||||
}
|
||||
$self->set_z_range($self->{layers_z}[$idx_low], $self->{layers_z}[$idx_high]);
|
||||
}
|
||||
});
|
||||
EVT_KEY_DOWN($canvas, sub {
|
||||
my ($s, $event) = @_;
|
||||
|
||||
my $key = $event->GetKeyCode;
|
||||
if ($key == 85 || $key == 315) {
|
||||
$slider->SetValue($slider->GetValue + 1);
|
||||
$self->set_z($self->{layers_z}[$slider->GetValue]);
|
||||
$slider_high->SetValue($slider_high->GetValue + 1);
|
||||
$self->set_z_high($self->{layers_z}[$slider_high->GetValue]);
|
||||
} elsif ($key == 68 || $key == 317) {
|
||||
$slider->SetValue($slider->GetValue - 1);
|
||||
$self->set_z($self->{layers_z}[$slider->GetValue]);
|
||||
$slider_high->SetValue($slider_high->GetValue - 1);
|
||||
$self->set_z_high($self->{layers_z}[$slider_high->GetValue]);
|
||||
}
|
||||
});
|
||||
|
||||
@ -90,7 +129,8 @@ sub load_print {
|
||||
# populated and we know the number of layers)
|
||||
if (!$self->print->object_step_done(STEP_SLICE)) {
|
||||
$self->enabled(0);
|
||||
$self->slider->Hide;
|
||||
$self->slider_low->Hide;
|
||||
$self->slider_high->Hide;
|
||||
$self->canvas->Refresh; # clears canvas
|
||||
return;
|
||||
}
|
||||
@ -105,14 +145,17 @@ sub load_print {
|
||||
}
|
||||
$self->enabled(1);
|
||||
$self->{layers_z} = [ sort { $a <=> $b } keys %z ];
|
||||
$self->slider->SetRange(0, scalar(@{$self->{layers_z}})-1);
|
||||
if (($z_idx = $self->slider->GetValue) <= $#{$self->{layers_z}} && $self->slider->GetValue != 0) {
|
||||
$self->slider_low->SetRange(0, scalar(@{$self->{layers_z}})-1);
|
||||
$self->slider_high->SetRange(0, scalar(@{$self->{layers_z}})-1);
|
||||
$self->slider_low->SetValue(0);
|
||||
if (($z_idx = $self->slider_high->GetValue) <= $#{$self->{layers_z}} && $self->slider_high->GetValue != 0) {
|
||||
# use $z_idx
|
||||
} else {
|
||||
$self->slider->SetValue(scalar(@{$self->{layers_z}})-1);
|
||||
$self->slider_high->SetValue(scalar(@{$self->{layers_z}})-1);
|
||||
$z_idx = @{$self->{layers_z}} ? -1 : undef;
|
||||
}
|
||||
$self->slider->Show;
|
||||
$self->slider_low->Show;
|
||||
$self->slider_high->Show;
|
||||
$self->Layout;
|
||||
}
|
||||
|
||||
@ -131,15 +174,17 @@ sub load_print {
|
||||
$self->_loaded(1);
|
||||
}
|
||||
|
||||
$self->set_z($self->{layers_z}[$z_idx]);
|
||||
$self->set_z_range(0, $self->{layers_z}[$z_idx]);
|
||||
}
|
||||
|
||||
sub set_z {
|
||||
my ($self, $z) = @_;
|
||||
sub set_z_range
|
||||
{
|
||||
my ($self, $z_low, $z_high) = @_;
|
||||
|
||||
return if !$self->enabled;
|
||||
$self->{z_label}->SetLabel(sprintf '%.2f', $z);
|
||||
$self->canvas->set_toolpaths_range(0, $z);
|
||||
$self->{z_label_low}->SetLabel(sprintf '%.2f', $z_low);
|
||||
$self->{z_label_high}->SetLabel(sprintf '%.2f', $z_high);
|
||||
$self->canvas->set_toolpaths_range($z_low, $z_high);
|
||||
$self->canvas->Refresh if $self->IsShown;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user