Merge with master

This commit is contained in:
Lukas Matena 2018-02-21 13:22:51 +01:00
commit de92f45eaf
125 changed files with 38665 additions and 4069 deletions

View file

@ -4,20 +4,22 @@ use warnings;
use utf8;
use Slic3r::Print::State ':steps';
use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE);
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX);
use Wx qw(:misc :sizer :slider :statictext :keycode wxWHITE wxCB_READONLY);
use Wx::Event qw(EVT_SLIDER EVT_KEY_DOWN EVT_CHECKBOX EVT_CHOICE EVT_CHECKLISTBOX);
use base qw(Wx::Panel Class::Accessor);
__PACKAGE__->mk_accessors(qw(print enabled _loaded canvas slider_low slider_high single_layer));
__PACKAGE__->mk_accessors(qw(print gcode_preview_data enabled _loaded canvas slider_low slider_high single_layer auto_zoom));
sub new {
my $class = shift;
my ($parent, $print, $config) = @_;
my ($parent, $print, $gcode_preview_data, $config) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
$self->{config} = $config;
$self->{number_extruders} = 1;
# Show by feature type by default.
$self->{preferred_color_mode} = 'feature';
$self->auto_zoom(1);
# init GUI elements
my $canvas = Slic3r::GUI::3DScene->new($self);
@ -56,10 +58,35 @@ sub new {
$z_label_high->SetFont($Slic3r::GUI::small_font);
$self->single_layer(0);
$self->{color_by_extruder} = 0;
my $checkbox_singlelayer = $self->{checkbox_singlelayer} = Wx::CheckBox->new($self, -1, "1 Layer");
my $checkbox_color_by_extruder = $self->{checkbox_color_by_extruder} = Wx::CheckBox->new($self, -1, "Tool");
my $label_view_type = $self->{label_view_type} = Wx::StaticText->new($self, -1, "View");
my $choice_view_type = $self->{choice_view_type} = Wx::Choice->new($self, -1);
$choice_view_type->Append("Feature type");
$choice_view_type->Append("Height");
$choice_view_type->Append("Width");
$choice_view_type->Append("Speed");
$choice_view_type->Append("Tool");
$choice_view_type->SetSelection(0);
my $label_show_features = $self->{label_show_features} = Wx::StaticText->new($self, -1, "Show");
my $combochecklist_features = $self->{combochecklist_features} = Wx::ComboCtrl->new();
$combochecklist_features->Create($self, -1, "Feature types", wxDefaultPosition, [200, -1], wxCB_READONLY);
#FIXME If the following line is removed, the combo box popup list will not react to mouse clicks.
# On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10.
$combochecklist_features->UseAltPopupWindow();
$combochecklist_features->EnablePopupAnimation(0);
my $feature_text = "Feature types";
my $feature_items = "Perimeter|External perimeter|Overhang perimeter|Internal infill|Solid infill|Top solid infill|Bridge infill|Gap fill|Skirt|Support material|Support material interface|Wipe tower";
Slic3r::GUI::create_combochecklist($combochecklist_features, $feature_text, $feature_items, 1);
my $checkbox_travel = $self->{checkbox_travel} = Wx::CheckBox->new($self, -1, "Travel");
my $checkbox_retractions = $self->{checkbox_retractions} = Wx::CheckBox->new($self, -1, "Retractions");
my $checkbox_unretractions = $self->{checkbox_unretractions} = Wx::CheckBox->new($self, -1, "Unretractions");
my $checkbox_shells = $self->{checkbox_shells} = Wx::CheckBox->new($self, -1, "Shells");
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
my $vsizer_outer = Wx::BoxSizer->new(wxVERTICAL);
@ -72,11 +99,29 @@ sub new {
$hsizer->Add($vsizer, 0, wxEXPAND, 0);
$vsizer_outer->Add($hsizer, 3, wxALIGN_CENTER_HORIZONTAL, 0);
$vsizer_outer->Add($checkbox_singlelayer, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5);
$vsizer_outer->Add($checkbox_color_by_extruder, 0, wxTOP | wxALIGN_CENTER_HORIZONTAL, 5);
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);
$bottom_sizer->AddSpacer(10);
$bottom_sizer->Add($checkbox_shells, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, 5);
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
$sizer->Add($vsizer_outer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
my $main_sizer = Wx::BoxSizer->new(wxVERTICAL);
$main_sizer->Add($sizer, 1, wxALL | wxEXPAND, 0);
$main_sizer->Add($bottom_sizer, 0, wxALL | wxEXPAND, 0);
EVT_SLIDER($self, $slider_low, sub {
$slider_high->SetValue($slider_low->GetValue) if $self->single_layer;
@ -147,18 +192,73 @@ sub new {
$self->set_z_idx_high($slider_high->GetValue);
}
});
EVT_CHECKBOX($self, $checkbox_color_by_extruder, sub {
$self->{color_by_extruder} = $checkbox_color_by_extruder->GetValue();
$self->{preferred_color_mode} = $self->{color_by_extruder} ? 'tool' : 'feature';
EVT_CHOICE($self, $choice_view_type, sub {
my $selection = $choice_view_type->GetCurrentSelection();
$self->{preferred_color_mode} = ($selection == 4) ? 'tool' : 'feature';
$self->gcode_preview_data->set_type($selection);
$self->auto_zoom(0);
$self->reload_print;
$self->auto_zoom(1);
});
EVT_CHECKLISTBOX($self, $combochecklist_features, sub {
my $flags = Slic3r::GUI::combochecklist_get_flags($combochecklist_features);
$self->gcode_preview_data->set_extrusion_flags($flags);
$self->auto_zoom(0);
$self->refresh_print;
$self->auto_zoom(1);
});
EVT_CHECKBOX($self, $checkbox_travel, sub {
$self->gcode_preview_data->set_travel_visible($checkbox_travel->IsChecked());
$self->auto_zoom(0);
$self->refresh_print;
$self->auto_zoom(1);
});
EVT_CHECKBOX($self, $checkbox_retractions, sub {
$self->gcode_preview_data->set_retractions_visible($checkbox_retractions->IsChecked());
$self->auto_zoom(0);
$self->refresh_print;
$self->auto_zoom(1);
});
EVT_CHECKBOX($self, $checkbox_unretractions, sub {
$self->gcode_preview_data->set_unretractions_visible($checkbox_unretractions->IsChecked());
$self->auto_zoom(0);
$self->refresh_print;
$self->auto_zoom(1);
});
EVT_CHECKBOX($self, $checkbox_shells, sub {
$self->gcode_preview_data->set_shells_visible($checkbox_shells->IsChecked());
$self->auto_zoom(0);
$self->refresh_print;
$self->auto_zoom(1);
});
$self->SetSizer($sizer);
$self->SetSizer($main_sizer);
$self->SetMinSize($self->GetSize);
$sizer->SetSizeHints($self);
# init canvas
$self->print($print);
$self->gcode_preview_data($gcode_preview_data);
# sets colors for gcode preview extrusion roles
my @extrusion_roles_colors = (
'Perimeter' => 'FFA500',
'External perimeter' => 'FFFF66',
'Overhang perimeter' => '0000FF',
'Internal infill' => 'FF0000',
'Solid infill' => 'CD00CD',
'Top solid infill' => 'FF3333',
'Bridge infill' => '9999FF',
'Gap fill' => 'FFFFFF',
'Skirt' => '7F0000',
'Support material' => '00FF00',
'Support material interface' => '008000',
'Wipe tower' => 'B3E3AB',
);
$self->gcode_preview_data->set_extrusion_paths_colors(\@extrusion_roles_colors);
$self->show_hide_ui_elements('none');
$self->reload_print;
return $self;
@ -171,7 +271,19 @@ sub reload_print {
$self->_loaded(0);
if (! $self->IsShown && ! $force) {
$self->{reload_delayed} = 1;
# $self->{reload_delayed} = 1;
return;
}
$self->load_print;
}
sub refresh_print {
my ($self) = @_;
$self->_loaded(0);
if (! $self->IsShown) {
return;
}
@ -203,6 +315,9 @@ sub load_print {
$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->canvas->reset_legend_texture();
$self->canvas->Refresh; # clears canvas
return;
}
@ -232,21 +347,20 @@ sub load_print {
$self->slider_high->Show;
$self->Layout;
my $by_tool = $self->{color_by_extruder};
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;
$by_tool = scalar(@{$extruders}) > 1;
$self->{color_by_extruder} = $by_tool;
$self->{checkbox_color_by_extruder}->SetValue($by_tool);
my $type = (scalar(@{$extruders}) > 1) ? 4 : 0;
$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';
}
# Collect colors per extruder.
# Leave it empty, if the print should be colored by a feature.
my @colors = ();
if ($by_tool) {
if (! $self->gcode_preview_data->empty() || $self->gcode_preview_data->type == 4) {
my @extruder_colors = @{$self->{config}->extruder_colour};
my @filament_colors = @{$self->{config}->filament_colour};
for (my $i = 0; $i <= $#extruder_colors; $i += 1) {
@ -258,18 +372,24 @@ sub load_print {
}
if ($self->IsShown) {
# 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;
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;
}
$self->show_hide_ui_elements('simple');
} else {
$self->canvas->load_gcode_preview($self->print, $self->gcode_preview_data, \@colors);
$self->show_hide_ui_elements('full');
}
if ($self->auto_zoom) {
$self->canvas->zoom_to_volumes;
}
$self->canvas->zoom_to_volumes;
$self->_loaded(1);
}
@ -322,17 +442,27 @@ sub set_number_extruders {
my ($self, $number_extruders) = @_;
if ($self->{number_extruders} != $number_extruders) {
$self->{number_extruders} = $number_extruders;
my $by_tool = $number_extruders > 1;
$self->{color_by_extruder} = $by_tool;
$self->{checkbox_color_by_extruder}->SetValue($by_tool);
$self->{preferred_color_mode} = $by_tool ? 'tool_or_feature' : 'feature';
my $type = ($number_extruders > 1) ?
4 # color by a tool number
: 0; # color by a feature type
$self->{choice_view_type}->SetSelection($type);
$self->gcode_preview_data->set_type($type);
$self->{preferred_color_mode} = ($type == 4) ? 'tool_or_feature' : 'feature';
}
}
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);
}
# Called by the Platter wxNotebook when this page is activated.
sub OnActivate {
my ($self) = @_;
$self->reload_print(1) if ($self->{reload_delayed});
# my ($self) = @_;
# $self->reload_print(1) if ($self->{reload_delayed});
}
1;

View file

@ -1,156 +0,0 @@
package Slic3r::GUI::Plater::3DToolpaths;
use strict;
use warnings;
use utf8;
use Slic3r::Print::State ':steps';
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));
sub new {
my $class = shift;
my ($parent, $print) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition);
# init GUI elements
my $canvas = Slic3r::GUI::3DScene->new($self);
$self->canvas($canvas);
my $slider = 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($slider);
my $z_label = $self->{z_label} = Wx::StaticText->new($self, -1, "", wxDefaultPosition,
[40,-1], wxALIGN_CENTRE_HORIZONTAL);
$z_label->SetFont($Slic3r::GUI::small_font);
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);
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($canvas, 1, wxALL | wxEXPAND, 0);
$sizer->Add($vsizer, 0, wxTOP | wxBOTTOM | wxEXPAND, 5);
EVT_SLIDER($self, $slider, sub {
$self->set_z($self->{layers_z}[$slider->GetValue])
if $self->enabled;
});
EVT_KEY_DOWN($canvas, sub {
my ($s, $event) = @_;
if ($event->HasModifiers) {
$event->Skip;
} else {
my $key = $event->GetKeyCode;
if ($key == 85 || $key == 315) {
$slider->SetValue($slider->GetValue + 1);
$self->set_z($self->{layers_z}[$slider->GetValue]);
} elsif ($key == 68 || $key == 317) {
$slider->SetValue($slider->GetValue - 1);
$self->set_z($self->{layers_z}[$slider->GetValue]);
} else {
$event->Skip;
}
}
});
$self->SetSizer($sizer);
$self->SetMinSize($self->GetSize);
$sizer->SetSizeHints($self);
# init canvas
$self->print($print);
$self->reload_print;
return $self;
}
sub reload_print {
my ($self) = @_;
$self->canvas->reset_objects;
$self->_loaded(0);
$self->load_print;
}
sub load_print {
my ($self) = @_;
return if $self->_loaded;
# 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)
if (!$self->print->object_step_done(STEP_SLICE)) {
$self->enabled(0);
$self->slider->Hide;
$self->canvas->Refresh; # clears canvas
return;
}
my $z_idx;
{
my %z = (); # z => 1
foreach my $object (@{$self->{print}->objects}) {
foreach my $layer (@{$object->layers}, @{$object->support_layers}) {
$z{$layer->print_z} = 1;
}
}
$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) {
# use $z_idx
} else {
$self->slider->SetValue(scalar(@{$self->{layers_z}})-1);
$z_idx = @{$self->{layers_z}} ? -1 : undef;
}
$self->slider->Show;
$self->Layout;
}
if ($self->IsShown) {
# load skirt and brim
$self->canvas->load_print_toolpaths($self->print);
foreach my $object (@{$self->print->objects}) {
$self->canvas->load_print_object_toolpaths($object);
# 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;
}
$self->canvas->zoom_to_volumes;
$self->_loaded(1);
}
$self->set_z($self->{layers_z}[$z_idx]);
}
sub set_z {
my ($self, $z) = @_;
return if !$self->enabled;
$self->{z_label}->SetLabel(sprintf '%.2f', $z);
$self->canvas->set_toolpaths_range(0, $z);
$self->canvas->Refresh if $self->IsShown;
}
sub set_bed_shape {
my ($self, $bed_shape) = @_;
$self->canvas->set_bed_shape($bed_shape);
}
1;