2015-01-18 18:36:47 +00:00
|
|
|
|
package Slic3r::GUI::Plater::3DPreview;
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
|
|
use Slic3r::Print::State ':steps';
|
2018-02-02 11:38:35 +00:00
|
|
|
|
use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE wxCB_READONLY);
|
2018-01-08 12:44:10 +00:00
|
|
|
|
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX EVT_CHOICE EVT_CHECKLISTBOX);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
use base qw(Wx::Panel Class::Accessor);
|
|
|
|
|
|
2018-02-26 15:23:44 +00:00
|
|
|
|
use Wx::Locale gettext => 'L';
|
|
|
|
|
|
2018-04-23 06:44:24 +00:00
|
|
|
|
__PACKAGE__->mk_accessors(qw(print gcode_preview_data enabled _loaded canvas slider_low slider_high single_layer));
|
2015-01-18 18:36:47 +00:00
|
|
|
|
|
|
|
|
|
sub new {
|
|
|
|
|
my $class = shift;
|
2018-02-14 19:35:59 +00:00
|
|
|
|
my ($parent, $print, $gcode_preview_data, $config) = @_;
|
2015-01-18 18:36:47 +00:00
|
|
|
|
|
|
|
|
|
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
|
2017-05-24 13:20:20 +00:00
|
|
|
|
$self->{config} = $config;
|
2017-05-30 15:24:50 +00:00
|
|
|
|
$self->{number_extruders} = 1;
|
2018-02-14 20:59:33 +00:00
|
|
|
|
# Show by feature type by default.
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->{preferred_color_mode} = 'feature';
|
2017-05-24 13:20:20 +00:00
|
|
|
|
|
2015-01-18 18:36:47 +00:00
|
|
|
|
# init GUI elements
|
|
|
|
|
my $canvas = Slic3r::GUI::3DScene->new($self);
|
2017-03-28 12:18:13 +00:00
|
|
|
|
$canvas->use_plain_shader(1);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
$self->canvas($canvas);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
my $slider_low = Wx::Slider->new(
|
2015-01-18 18:36:47 +00:00
|
|
|
|
$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,
|
|
|
|
|
);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
$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);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
|
2016-10-03 15:01:29 +00:00
|
|
|
|
my $z_label_low = $self->{z_label_low} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
|
|
|
|
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
|
|
|
|
$z_label_low->SetFont($Slic3r::GUI::small_font);
|
|
|
|
|
my $z_label_high = $self->{z_label_high} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
2015-01-18 18:36:47 +00:00
|
|
|
|
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
$z_label_high->SetFont($Slic3r::GUI::small_font);
|
2016-11-08 16:13:16 +00:00
|
|
|
|
|
2018-05-14 07:54:38 +00:00
|
|
|
|
my $z_label_low_idx = $self->{z_label_low_idx} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
|
|
|
|
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
|
|
|
|
$z_label_low_idx->SetFont($Slic3r::GUI::small_font);
|
|
|
|
|
my $z_label_high_idx = $self->{z_label_high_idx} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
|
|
|
|
|
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
|
|
|
|
|
$z_label_high_idx->SetFont($Slic3r::GUI::small_font);
|
|
|
|
|
|
2016-11-08 16:13:16 +00:00
|
|
|
|
$self->single_layer(0);
|
2018-02-26 15:23:44 +00:00
|
|
|
|
my $checkbox_singlelayer = $self->{checkbox_singlelayer} = Wx::CheckBox->new($self, -1, L("1 Layer"));
|
2015-01-18 18:36:47 +00:00
|
|
|
|
|
2018-02-26 15:23:44 +00:00
|
|
|
|
my $label_view_type = $self->{label_view_type} = Wx::StaticText->new($self, -1, L("View"));
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
2018-02-14 20:59:33 +00:00
|
|
|
|
my $choice_view_type = $self->{choice_view_type} = Wx::Choice->new($self, -1);
|
2018-02-26 15:23:44 +00:00
|
|
|
|
$choice_view_type->Append(L("Feature type"));
|
|
|
|
|
$choice_view_type->Append(L("Height"));
|
|
|
|
|
$choice_view_type->Append(L("Width"));
|
|
|
|
|
$choice_view_type->Append(L("Speed"));
|
2018-03-21 09:03:10 +00:00
|
|
|
|
$choice_view_type->Append(L("Volumetric flow rate"));
|
2018-02-26 15:23:44 +00:00
|
|
|
|
$choice_view_type->Append(L("Tool"));
|
2018-01-08 12:44:10 +00:00
|
|
|
|
$choice_view_type->SetSelection(0);
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
2018-04-24 12:21:31 +00:00
|
|
|
|
# the following value needs to be changed if new items are added into $choice_view_type before "Tool"
|
|
|
|
|
$self->{tool_idx} = 5;
|
|
|
|
|
|
2018-02-26 15:23:44 +00:00
|
|
|
|
my $label_show_features = $self->{label_show_features} = Wx::StaticText->new($self, -1, L("Show"));
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
2018-02-15 15:30:35 +00:00
|
|
|
|
my $combochecklist_features = $self->{combochecklist_features} = Wx::ComboCtrl->new();
|
2018-02-26 15:23:44 +00:00
|
|
|
|
$combochecklist_features->Create($self, -1, L("Feature types"), wxDefaultPosition, [200, -1], wxCB_READONLY);
|
|
|
|
|
my $feature_text = L("Feature types");
|
|
|
|
|
my $feature_items = L("Perimeter")."|"
|
|
|
|
|
.L("External perimeter")."|"
|
|
|
|
|
.L("Overhang perimeter")."|"
|
|
|
|
|
.L("Internal infill")."|"
|
|
|
|
|
.L("Solid infill")."|"
|
|
|
|
|
.L("Top solid infill")."|"
|
|
|
|
|
.L("Bridge infill")."|"
|
|
|
|
|
.L("Gap fill")."|"
|
|
|
|
|
.L("Skirt")."|"
|
|
|
|
|
.L("Support material")."|"
|
|
|
|
|
.L("Support material interface")."|"
|
|
|
|
|
.L("Wipe tower")."|"
|
|
|
|
|
.L("Custom");
|
2018-02-02 11:38:35 +00:00
|
|
|
|
Slic3r::GUI::create_combochecklist($combochecklist_features, $feature_text, $feature_items, 1);
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
2018-02-26 15:23:44 +00:00
|
|
|
|
my $checkbox_travel = $self->{checkbox_travel} = Wx::CheckBox->new($self, -1, L("Travel"));
|
|
|
|
|
my $checkbox_retractions = $self->{checkbox_retractions} = Wx::CheckBox->new($self, -1, L("Retractions"));
|
|
|
|
|
my $checkbox_unretractions = $self->{checkbox_unretractions} = Wx::CheckBox->new($self, -1, L("Unretractions"));
|
|
|
|
|
my $checkbox_shells = $self->{checkbox_shells} = Wx::CheckBox->new($self, -1, L("Shells"));
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
2016-10-03 15:01:29 +00:00
|
|
|
|
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
|
2016-11-08 16:13:16 +00:00
|
|
|
|
my $vsizer_outer = Wx::BoxSizer->new(wxVERTICAL);
|
2018-05-14 07:54:38 +00:00
|
|
|
|
$vsizer->Add($slider_low, 3, wxALIGN_CENTER_HORIZONTAL, 0);
|
|
|
|
|
$vsizer->Add($z_label_low_idx, 0, wxALIGN_CENTER_HORIZONTAL, 0);
|
|
|
|
|
$vsizer->Add($z_label_low, 0, wxALIGN_CENTER_HORIZONTAL, 0);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
$hsizer->Add($vsizer, 0, wxEXPAND, 0);
|
|
|
|
|
$vsizer = Wx::BoxSizer->new(wxVERTICAL);
|
2018-05-14 07:54:38 +00:00
|
|
|
|
$vsizer->Add($slider_high, 3, wxALIGN_CENTER_HORIZONTAL, 0);
|
|
|
|
|
$vsizer->Add($z_label_high_idx, 0, wxALIGN_CENTER_HORIZONTAL, 0);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
$vsizer->Add($z_label_high, 0, 0, 0);
|
|
|
|
|
$hsizer->Add($vsizer, 0, wxEXPAND, 0);
|
2016-11-08 16:13:16 +00:00
|
|
|
|
$vsizer_outer->Add($hsizer, 3, wxALIGN_CENTER_HORIZONTAL, 0);
|
|
|
|
|
$vsizer_outer->Add($checkbox_singlelayer, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5);
|
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
|
my $bottom_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
|
|
|
|
$bottom_sizer->Add($label_view_type, 0, wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->Add($choice_view_type, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->AddSpacer(10);
|
|
|
|
|
$bottom_sizer->Add($label_show_features, 0, wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->Add($combochecklist_features, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->AddSpacer(20);
|
|
|
|
|
$bottom_sizer->Add($checkbox_travel, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->AddSpacer(10);
|
|
|
|
|
$bottom_sizer->Add($checkbox_retractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
|
|
|
|
$bottom_sizer->AddSpacer(10);
|
|
|
|
|
$bottom_sizer->Add($checkbox_unretractions, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
2018-02-12 08:04:05 +00:00
|
|
|
|
$bottom_sizer->AddSpacer(10);
|
|
|
|
|
$bottom_sizer->Add($checkbox_shells, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
2015-01-18 18:36:47 +00:00
|
|
|
|
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
|
|
|
|
$sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
|
2016-11-08 16:13:16 +00:00
|
|
|
|
$sizer->Add($vsizer_outer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
|
2018-02-02 11:38:35 +00:00
|
|
|
|
|
|
|
|
|
my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
|
|
|
|
$main_sizer->Add($sizer, 1, wxALL | wxEXPAND, 0);
|
|
|
|
|
$main_sizer->Add($bottom_sizer, 0, wxALL | wxEXPAND, 0);
|
2016-10-03 15:01:29 +00:00
|
|
|
|
|
2016-11-08 16:13:16 +00:00
|
|
|
|
EVT_SLIDER($self, $slider_low, sub {
|
|
|
|
|
$slider_high->SetValue($slider_low->GetValue) if $self->single_layer;
|
|
|
|
|
$self->set_z_idx_low ($slider_low ->GetValue)
|
2016-10-03 15:01:29 +00:00
|
|
|
|
});
|
2016-11-08 16:13:16 +00:00
|
|
|
|
EVT_SLIDER($self, $slider_high, sub {
|
|
|
|
|
$slider_low->SetValue($slider_high->GetValue) if $self->single_layer;
|
|
|
|
|
$self->set_z_idx_high($slider_high->GetValue)
|
2015-01-18 18:36:47 +00:00
|
|
|
|
});
|
2015-01-18 19:55:44 +00:00
|
|
|
|
EVT_KEY_DOWN($canvas, sub {
|
|
|
|
|
my ($s, $event) = @_;
|
|
|
|
|
my $key = $event->GetKeyCode;
|
2017-06-06 17:14:52 +00:00
|
|
|
|
if ($event->HasModifiers) {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
} else {
|
2017-07-11 16:21:25 +00:00
|
|
|
|
if ($key == ord('U')) {
|
2017-06-06 17:14:52 +00:00
|
|
|
|
$slider_high->SetValue($slider_high->GetValue + 1);
|
|
|
|
|
$slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
|
|
|
|
|
$self->set_z_idx_high($slider_high->GetValue);
|
2017-07-11 16:21:25 +00:00
|
|
|
|
} elsif ($key == ord('D')) {
|
2017-06-06 17:14:52 +00:00
|
|
|
|
$slider_high->SetValue($slider_high->GetValue - 1);
|
|
|
|
|
$slider_low->SetValue($slider_high->GetValue) if ($event->ShiftDown());
|
2016-11-08 16:13:16 +00:00
|
|
|
|
$self->set_z_idx_high($slider_high->GetValue);
|
2017-06-06 17:14:52 +00:00
|
|
|
|
} elsif ($key == ord('S')) {
|
|
|
|
|
$checkbox_singlelayer->SetValue(! $checkbox_singlelayer->GetValue());
|
|
|
|
|
$self->single_layer($checkbox_singlelayer->GetValue());
|
|
|
|
|
if ($self->single_layer) {
|
|
|
|
|
$slider_low->SetValue($slider_high->GetValue);
|
|
|
|
|
$self->set_z_idx_high($slider_high->GetValue);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$event->Skip;
|
2016-11-08 16:13:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-07-11 16:21:25 +00:00
|
|
|
|
EVT_KEY_DOWN($slider_low, sub {
|
|
|
|
|
my ($s, $event) = @_;
|
|
|
|
|
my $key = $event->GetKeyCode;
|
|
|
|
|
if ($event->HasModifiers) {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
} else {
|
|
|
|
|
if ($key == WXK_LEFT) {
|
|
|
|
|
} elsif ($key == WXK_RIGHT) {
|
|
|
|
|
$slider_high->SetFocus;
|
|
|
|
|
} else {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
EVT_KEY_DOWN($slider_high, sub {
|
|
|
|
|
my ($s, $event) = @_;
|
|
|
|
|
my $key = $event->GetKeyCode;
|
|
|
|
|
if ($event->HasModifiers) {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
} else {
|
|
|
|
|
if ($key == WXK_LEFT) {
|
|
|
|
|
$slider_low->SetFocus;
|
|
|
|
|
} elsif ($key == WXK_RIGHT) {
|
|
|
|
|
} else {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-11-08 16:13:16 +00:00
|
|
|
|
EVT_CHECKBOX($self, $checkbox_singlelayer, sub {
|
|
|
|
|
$self->single_layer($checkbox_singlelayer->GetValue());
|
|
|
|
|
if ($self->single_layer) {
|
|
|
|
|
$slider_low->SetValue($slider_high->GetValue);
|
|
|
|
|
$self->set_z_idx_high($slider_high->GetValue);
|
2015-01-18 19:55:44 +00:00
|
|
|
|
}
|
|
|
|
|
});
|
2018-01-08 12:44:10 +00:00
|
|
|
|
EVT_CHOICE($self, $choice_view_type, sub {
|
|
|
|
|
my $selection = $choice_view_type->GetCurrentSelection();
|
2018-04-24 12:21:31 +00:00
|
|
|
|
$self->{preferred_color_mode} = ($selection == $self->{tool_idx}) ? 'tool' : 'feature';
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_type($selection);
|
2018-01-08 12:44:10 +00:00
|
|
|
|
$self->reload_print;
|
|
|
|
|
});
|
2018-02-02 11:38:35 +00:00
|
|
|
|
EVT_CHECKLISTBOX($self, $combochecklist_features, sub {
|
|
|
|
|
my $flags = Slic3r::GUI::combochecklist_get_flags($combochecklist_features);
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_extrusion_flags($flags);
|
2018-01-11 13:09:54 +00:00
|
|
|
|
$self->refresh_print;
|
2018-01-08 12:44:10 +00:00
|
|
|
|
});
|
|
|
|
|
EVT_CHECKBOX($self, $checkbox_travel, sub {
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_travel_visible($checkbox_travel->IsChecked());
|
2018-01-11 13:09:54 +00:00
|
|
|
|
$self->refresh_print;
|
2018-01-08 12:44:10 +00:00
|
|
|
|
});
|
|
|
|
|
EVT_CHECKBOX($self, $checkbox_retractions, sub {
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_retractions_visible($checkbox_retractions->IsChecked());
|
2018-01-11 13:09:54 +00:00
|
|
|
|
$self->refresh_print;
|
2018-01-08 12:44:10 +00:00
|
|
|
|
});
|
2018-01-08 15:05:01 +00:00
|
|
|
|
EVT_CHECKBOX($self, $checkbox_unretractions, sub {
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_unretractions_visible($checkbox_unretractions->IsChecked());
|
2018-01-11 13:09:54 +00:00
|
|
|
|
$self->refresh_print;
|
2018-01-08 15:05:01 +00:00
|
|
|
|
});
|
2018-02-12 08:04:05 +00:00
|
|
|
|
EVT_CHECKBOX($self, $checkbox_shells, sub {
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_shells_visible($checkbox_shells->IsChecked());
|
2018-02-12 08:04:05 +00:00
|
|
|
|
$self->refresh_print;
|
|
|
|
|
});
|
2018-01-08 12:44:10 +00:00
|
|
|
|
|
2018-02-02 11:38:35 +00:00
|
|
|
|
$self->SetSizer($main_sizer);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
$self->SetMinSize($self->GetSize);
|
|
|
|
|
$sizer->SetSizeHints($self);
|
|
|
|
|
|
|
|
|
|
# init canvas
|
|
|
|
|
$self->print($print);
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data($gcode_preview_data);
|
2018-02-13 12:16:23 +00:00
|
|
|
|
|
|
|
|
|
# sets colors for gcode preview extrusion roles
|
|
|
|
|
my @extrusion_roles_colors = (
|
2018-03-14 14:00:12 +00:00
|
|
|
|
'Perimeter' => 'FFFF66',
|
|
|
|
|
'External perimeter' => 'FFA500',
|
2018-02-13 12:16:23 +00:00
|
|
|
|
'Overhang perimeter' => '0000FF',
|
2018-03-14 14:00:12 +00:00
|
|
|
|
'Internal infill' => 'B1302A',
|
|
|
|
|
'Solid infill' => 'D732D7',
|
|
|
|
|
'Top solid infill' => 'FF1A1A',
|
2018-02-14 20:59:33 +00:00
|
|
|
|
'Bridge infill' => '9999FF',
|
2018-02-13 12:16:23 +00:00
|
|
|
|
'Gap fill' => 'FFFFFF',
|
2018-03-14 14:00:12 +00:00
|
|
|
|
'Skirt' => '845321',
|
2018-02-14 20:59:33 +00:00
|
|
|
|
'Support material' => '00FF00',
|
|
|
|
|
'Support material interface' => '008000',
|
2018-02-13 12:16:23 +00:00
|
|
|
|
'Wipe tower' => 'B3E3AB',
|
2018-03-14 14:00:12 +00:00
|
|
|
|
'Custom' => '28CC94',
|
2018-02-13 12:16:23 +00:00
|
|
|
|
);
|
2018-02-14 19:35:59 +00:00
|
|
|
|
$self->gcode_preview_data->set_extrusion_paths_colors(\@extrusion_roles_colors);
|
2018-02-13 12:16:23 +00:00
|
|
|
|
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->show_hide_ui_elements('none');
|
2015-01-18 18:36:47 +00:00
|
|
|
|
$self->reload_print;
|
|
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub reload_print {
|
2017-05-31 15:05:11 +00:00
|
|
|
|
my ($self, $force) = @_;
|
2018-05-18 12:08:59 +00:00
|
|
|
|
|
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::reset_volumes($self->canvas);
|
|
|
|
|
# $self->canvas->reset_objects;
|
|
|
|
|
#==============================================================================================================================
|
2015-01-25 09:59:39 +00:00
|
|
|
|
$self->_loaded(0);
|
2017-05-31 15:05:11 +00:00
|
|
|
|
|
|
|
|
|
if (! $self->IsShown && ! $force) {
|
2018-01-11 13:09:54 +00:00
|
|
|
|
# $self->{reload_delayed} = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->load_print;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub refresh_print {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
$self->_loaded(0);
|
|
|
|
|
|
|
|
|
|
if (! $self->IsShown) {
|
2017-05-31 15:05:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 09:59:39 +00:00
|
|
|
|
$self->load_print;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-23 13:30:41 +00:00
|
|
|
|
sub reset_gcode_preview_data {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
$self->gcode_preview_data->reset;
|
|
|
|
|
$self->canvas->reset_legend_texture();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-25 09:59:39 +00:00
|
|
|
|
sub load_print {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
return if $self->_loaded;
|
2015-01-18 18:36:47 +00:00
|
|
|
|
|
|
|
|
|
# we require that there's at least one object and the posSlice step
|
|
|
|
|
# is performed on all of them (this ensures that _shifted_copies was
|
|
|
|
|
# populated and we know the number of layers)
|
2016-11-11 11:00:40 +00:00
|
|
|
|
my $n_layers = 0;
|
|
|
|
|
if ($self->print->object_step_done(STEP_SLICE)) {
|
2015-01-18 18:36:47 +00:00
|
|
|
|
my %z = (); # z => 1
|
|
|
|
|
foreach my $object (@{$self->{print}->objects}) {
|
|
|
|
|
foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
|
|
|
|
|
$z{$layer->print_z} = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$self->{layers_z} = [ sort { $a <=> $b } keys %z ];
|
2016-11-11 11:00:40 +00:00
|
|
|
|
$n_layers = scalar(@{$self->{layers_z}});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($n_layers == 0) {
|
2018-05-17 14:02:31 +00:00
|
|
|
|
$self->reset_sliders;
|
2018-02-06 11:43:25 +00:00
|
|
|
|
$self->canvas->reset_legend_texture();
|
2016-11-11 11:00:40 +00:00
|
|
|
|
$self->canvas->Refresh; # clears canvas
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 15:30:35 +00:00
|
|
|
|
if ($self->{preferred_color_mode} eq 'tool_or_feature') {
|
|
|
|
|
# It is left to Slic3r to decide whether the print shall be colored by the tool or by the feature.
|
|
|
|
|
# Color by feature if it is a single extruder print.
|
|
|
|
|
my $extruders = $self->{print}->extruders;
|
2018-04-24 12:21:31 +00:00
|
|
|
|
my $type = (scalar(@{$extruders}) > 1) ? $self->{tool_idx} : 0;
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->gcode_preview_data->set_type($type);
|
|
|
|
|
$self->{choice_view_type}->SetSelection($type);
|
|
|
|
|
# If the ->SetSelection changed the following line, revert it to "decide yourself".
|
|
|
|
|
$self->{preferred_color_mode} = 'tool_or_feature';
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 13:20:20 +00:00
|
|
|
|
# Collect colors per extruder.
|
|
|
|
|
my @colors = ();
|
2018-04-24 12:21:31 +00:00
|
|
|
|
if (! $self->gcode_preview_data->empty() || $self->gcode_preview_data->type == $self->{tool_idx}) {
|
2018-02-14 20:59:33 +00:00
|
|
|
|
my @extruder_colors = @{$self->{config}->extruder_colour};
|
|
|
|
|
my @filament_colors = @{$self->{config}->filament_colour};
|
|
|
|
|
for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
|
|
|
|
|
my $color = $extruder_colors[$i];
|
|
|
|
|
$color = $filament_colors[$i] if (! defined($color) || $color !~ m/^#[[:xdigit:]]{6}/);
|
|
|
|
|
$color = '#FFFFFF' if (! defined($color) || $color !~ m/^#[[:xdigit:]]{6}/);
|
|
|
|
|
push @colors, $color;
|
|
|
|
|
}
|
2017-05-24 13:20:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 18:36:47 +00:00
|
|
|
|
if ($self->IsShown) {
|
2018-05-17 14:02:31 +00:00
|
|
|
|
# used to set the sliders to the extremes of the current zs range
|
|
|
|
|
$self->{force_sliders_full_range} = 0;
|
|
|
|
|
|
2018-02-14 20:59:33 +00:00
|
|
|
|
if ($self->gcode_preview_data->empty) {
|
|
|
|
|
# load skirt and brim
|
|
|
|
|
$self->canvas->load_print_toolpaths($self->print, \@colors);
|
|
|
|
|
$self->canvas->load_wipe_tower_toolpaths($self->print, \@colors);
|
|
|
|
|
foreach my $object (@{$self->print->objects}) {
|
|
|
|
|
$self->canvas->load_print_object_toolpaths($object, \@colors);
|
|
|
|
|
# Show the objects in very transparent color.
|
|
|
|
|
#my @volume_ids = $self->canvas->load_object($object->model_object);
|
|
|
|
|
#$self->canvas->volumes->[$_]->color->[3] = 0.2 for @volume_ids;
|
|
|
|
|
}
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->show_hide_ui_elements('simple');
|
2018-05-17 13:18:52 +00:00
|
|
|
|
$self->canvas->reset_legend_texture();
|
2018-02-14 20:59:33 +00:00
|
|
|
|
} else {
|
2018-04-23 06:44:24 +00:00
|
|
|
|
$self->{force_sliders_full_range} = (scalar(@{$self->canvas->volumes}) == 0);
|
2018-02-14 20:59:33 +00:00
|
|
|
|
$self->canvas->load_gcode_preview($self->print, $self->gcode_preview_data, \@colors);
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->show_hide_ui_elements('full');
|
2018-02-22 07:59:47 +00:00
|
|
|
|
|
|
|
|
|
# recalculates zs and update sliders accordingly
|
2018-05-18 08:14:47 +00:00
|
|
|
|
$self->{layers_z} = $self->canvas->get_current_print_zs(1);
|
2018-02-22 07:59:47 +00:00
|
|
|
|
$n_layers = scalar(@{$self->{layers_z}});
|
2018-05-17 14:02:31 +00:00
|
|
|
|
if ($n_layers == 0) {
|
|
|
|
|
# all layers filtered out
|
|
|
|
|
$self->reset_sliders;
|
|
|
|
|
$self->canvas->Refresh; # clears canvas
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-22 07:59:47 +00:00
|
|
|
|
|
2018-05-17 14:02:31 +00:00
|
|
|
|
$self->update_sliders($n_layers) if ($n_layers > 0);
|
2015-01-25 09:59:39 +00:00
|
|
|
|
$self->_loaded(1);
|
2015-01-18 18:36:47 +00:00
|
|
|
|
}
|
2018-02-22 07:59:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-17 14:02:31 +00:00
|
|
|
|
sub reset_sliders {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
$self->enabled(0);
|
|
|
|
|
$self->set_z_range(0,0);
|
|
|
|
|
$self->slider_low->Hide;
|
|
|
|
|
$self->slider_high->Hide;
|
|
|
|
|
$self->{z_label_low}->SetLabel("");
|
|
|
|
|
$self->{z_label_high}->SetLabel("");
|
|
|
|
|
$self->{z_label_low_idx}->SetLabel("");
|
|
|
|
|
$self->{z_label_high_idx}->SetLabel("");
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 07:59:47 +00:00
|
|
|
|
sub update_sliders
|
|
|
|
|
{
|
|
|
|
|
my ($self, $n_layers) = @_;
|
|
|
|
|
|
|
|
|
|
my $z_idx_low = $self->slider_low->GetValue;
|
|
|
|
|
my $z_idx_high = $self->slider_high->GetValue;
|
|
|
|
|
$self->enabled(1);
|
|
|
|
|
$self->slider_low->SetRange(0, $n_layers - 1);
|
|
|
|
|
$self->slider_high->SetRange(0, $n_layers - 1);
|
2015-12-05 22:21:50 +00:00
|
|
|
|
|
2018-02-22 07:59:47 +00:00
|
|
|
|
if ($self->{force_sliders_full_range}) {
|
|
|
|
|
$z_idx_low = 0;
|
|
|
|
|
$z_idx_high = $n_layers - 1;
|
|
|
|
|
} elsif ($z_idx_high < $n_layers && ($self->single_layer || $z_idx_high != 0)) {
|
2018-05-17 14:02:31 +00:00
|
|
|
|
# search new indices for nearest z (size of $self->{layers_z} may change in dependence of what is shown)
|
|
|
|
|
if (defined($self->{z_low})) {
|
|
|
|
|
for (my $i = scalar(@{$self->{layers_z}}) - 1; $i >= 0; $i -= 1) {
|
|
|
|
|
if ($self->{layers_z}[$i] <= $self->{z_low}) {
|
|
|
|
|
$z_idx_low = $i;
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (defined($self->{z_high})) {
|
|
|
|
|
for (my $i = scalar(@{$self->{layers_z}}) - 1; $i >= 0; $i -= 1) {
|
|
|
|
|
if ($self->{layers_z}[$i] <= $self->{z_high}) {
|
|
|
|
|
$z_idx_high = $i;
|
|
|
|
|
last;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} elsif ($z_idx_high >= $n_layers) {
|
2018-02-22 07:59:47 +00:00
|
|
|
|
# Out of range. Disable 'single layer' view.
|
|
|
|
|
$self->single_layer(0);
|
|
|
|
|
$self->{checkbox_singlelayer}->SetValue(0);
|
|
|
|
|
$z_idx_low = 0;
|
|
|
|
|
$z_idx_high = $n_layers - 1;
|
2018-05-17 14:02:31 +00:00
|
|
|
|
} else {
|
2018-02-22 07:59:47 +00:00
|
|
|
|
$z_idx_low = 0;
|
2018-05-17 14:02:31 +00:00
|
|
|
|
$z_idx_high = $n_layers - 1;
|
2018-02-22 07:59:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->slider_low->SetValue($z_idx_low);
|
|
|
|
|
$self->slider_high->SetValue($z_idx_high);
|
|
|
|
|
$self->slider_low->Show;
|
|
|
|
|
$self->slider_high->Show;
|
2016-11-11 11:00:40 +00:00
|
|
|
|
$self->set_z_range($self->{layers_z}[$z_idx_low], $self->{layers_z}[$z_idx_high]);
|
2018-02-22 07:59:47 +00:00
|
|
|
|
$self->Layout;
|
2015-01-18 18:36:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 15:01:29 +00:00
|
|
|
|
sub set_z_range
|
|
|
|
|
{
|
|
|
|
|
my ($self, $z_low, $z_high) = @_;
|
2015-01-18 19:48:54 +00:00
|
|
|
|
|
|
|
|
|
return if !$self->enabled;
|
2018-05-17 14:02:31 +00:00
|
|
|
|
$self->{z_low} = $z_low;
|
|
|
|
|
$self->{z_high} = $z_high;
|
2016-10-03 15:01:29 +00:00
|
|
|
|
$self->{z_label_low}->SetLabel(sprintf '%.2f', $z_low);
|
|
|
|
|
$self->{z_label_high}->SetLabel(sprintf '%.2f', $z_high);
|
2018-05-18 08:14:47 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 16:13:16 +00:00
|
|
|
|
$self->canvas->set_toolpaths_range($z_low - 1e-6, $z_high + 1e-6);
|
2015-01-18 19:48:54 +00:00
|
|
|
|
$self->canvas->Refresh if $self->IsShown;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 16:13:16 +00:00
|
|
|
|
sub set_z_idx_low
|
|
|
|
|
{
|
|
|
|
|
my ($self, $idx_low) = @_;
|
|
|
|
|
if ($self->enabled) {
|
|
|
|
|
my $idx_high = $self->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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_z_idx_high
|
|
|
|
|
{
|
|
|
|
|
my ($self, $idx_high) = @_;
|
|
|
|
|
if ($self->enabled) {
|
|
|
|
|
my $idx_low = $self->slider_low->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]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 18:36:47 +00:00
|
|
|
|
sub set_bed_shape {
|
|
|
|
|
my ($self, $bed_shape) = @_;
|
2018-05-15 13:38:25 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::set_bed_shape($self->canvas, $bed_shape);
|
|
|
|
|
# $self->canvas->set_bed_shape($bed_shape);
|
|
|
|
|
#==============================================================================================================================
|
2015-01-18 18:36:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 15:24:50 +00:00
|
|
|
|
sub set_number_extruders {
|
|
|
|
|
my ($self, $number_extruders) = @_;
|
|
|
|
|
if ($self->{number_extruders} != $number_extruders) {
|
|
|
|
|
$self->{number_extruders} = $number_extruders;
|
2018-02-15 15:30:35 +00:00
|
|
|
|
my $type = ($number_extruders > 1) ?
|
2018-04-24 12:21:31 +00:00
|
|
|
|
$self->{tool_idx} # color by a tool number
|
2018-02-14 20:59:33 +00:00
|
|
|
|
: 0; # color by a feature type
|
2018-02-15 15:30:35 +00:00
|
|
|
|
$self->{choice_view_type}->SetSelection($type);
|
|
|
|
|
$self->gcode_preview_data->set_type($type);
|
2018-04-24 12:21:31 +00:00
|
|
|
|
$self->{preferred_color_mode} = ($type == $self->{tool_idx}) ? 'tool_or_feature' : 'feature';
|
2017-05-30 15:24:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-15 15:30:35 +00:00
|
|
|
|
sub show_hide_ui_elements {
|
|
|
|
|
my ($self, $what) = @_;
|
|
|
|
|
my $method = ($what eq 'full') ? 'Enable' : 'Disable';
|
|
|
|
|
$self->{$_}->$method for qw(label_show_features combochecklist_features checkbox_travel checkbox_retractions checkbox_unretractions checkbox_shells);
|
|
|
|
|
$method = ($what eq 'none') ? 'Disable' : 'Enable';
|
|
|
|
|
$self->{$_}->$method for qw(label_view_type choice_view_type);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:05:11 +00:00
|
|
|
|
# Called by the Platter wxNotebook when this page is activated.
|
|
|
|
|
sub OnActivate {
|
2018-01-11 13:09:54 +00:00
|
|
|
|
# my ($self) = @_;
|
|
|
|
|
# $self->reload_print(1) if ($self->{reload_delayed});
|
2017-05-31 15:05:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 18:36:47 +00:00
|
|
|
|
1;
|