Fixed z layers indices under 3D preview sliders

This commit is contained in:
Enrico Turri 2018-05-18 10:14:47 +02:00
parent 5224acad59
commit 0584990b65
5 changed files with 23 additions and 15 deletions

View file

@ -2192,10 +2192,8 @@ sub reset_legend_texture {
}
sub get_current_print_zs {
my ($self) = @_;
my $count = $self->volumes->get_current_print_zs();
return $count;
my ($self, $active_only) = @_;
return $self->volumes->get_current_print_zs($active_only);
}
1;

View file

@ -380,7 +380,7 @@ sub load_print {
$self->show_hide_ui_elements('full');
# recalculates zs and update sliders accordingly
$self->{layers_z} = $self->canvas->get_current_print_zs();
$self->{layers_z} = $self->canvas->get_current_print_zs(1);
$n_layers = scalar(@{$self->{layers_z}});
if ($n_layers == 0) {
# all layers filtered out
@ -465,10 +465,21 @@ sub set_z_range
$self->{z_high} = $z_high;
$self->{z_label_low}->SetLabel(sprintf '%.2f', $z_low);
$self->{z_label_high}->SetLabel(sprintf '%.2f', $z_high);
my $z_idx_low = 1 + $self->slider_low->GetValue;
my $z_idx_high = 1 + $self->slider_high->GetValue;
$self->{z_label_low_idx}->SetLabel(sprintf '%d', $z_idx_low);
$self->{z_label_high_idx}->SetLabel(sprintf '%d', $z_idx_high);
my $layers_z = $self->canvas->get_current_print_zs(0);
for (my $i = 0; $i < scalar(@{$layers_z}); $i += 1) {
if (($z_low - 1e-6 < @{$layers_z}[$i]) && (@{$layers_z}[$i] < $z_low + 1e-6)) {
$self->{z_label_low_idx}->SetLabel(sprintf '%d', $i + 1);
last;
}
}
for (my $i = 0; $i < scalar(@{$layers_z}); $i += 1) {
if (($z_high - 1e-6 < @{$layers_z}[$i]) && (@{$layers_z}[$i] < $z_high + 1e-6)) {
$self->{z_label_high_idx}->SetLabel(sprintf '%d', $i + 1);
last;
}
}
$self->canvas->set_toolpaths_range($z_low - 1e-6, $z_high + 1e-6);
$self->canvas->Refresh if $self->IsShown;
}

View file

@ -760,13 +760,13 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con
}
}
std::vector<double> GLVolumeCollection::get_current_print_zs() const
std::vector<double> GLVolumeCollection::get_current_print_zs(bool active_only) const
{
// Collect layer top positions of all volumes.
std::vector<double> print_zs;
for (GLVolume *vol : this->volumes)
{
if (vol->is_active)
if (!active_only || vol->is_active)
append(print_zs, vol->print_zs);
}
std::sort(print_zs.begin(), print_zs.end());

View file

@ -428,7 +428,7 @@ public:
void update_colors_by_extruder(const DynamicPrintConfig* config);
// Returns a vector containing the sorted list of all the print_zs of the volumes contained in this collection
std::vector<double> get_current_print_zs() const;
std::vector<double> get_current_print_zs(bool active_only) const;
private:
GLVolumeCollection(const GLVolumeCollection &other);

View file

@ -92,10 +92,9 @@
int count()
%code{% RETVAL = THIS->volumes.size(); %};
std::vector<double> get_current_print_zs()
%code{% RETVAL = THIS->get_current_print_zs(); %};
std::vector<double> get_current_print_zs(bool active_only)
%code{% RETVAL = THIS->get_current_print_zs(active_only); %};
void set_range(double low, double high);
void render_VBOs() const;