Merge branch 'master' into sender

Conflicts:
	Build.PL
	lib/Slic3r.pm
	xs/MANIFEST
	xs/src/libslic3r/PrintConfig.hpp
This commit is contained in:
Alessandro Ranellucci 2015-11-01 19:12:13 +01:00
commit 9b21ac877a
93 changed files with 3339 additions and 2050 deletions

View file

@ -3,8 +3,8 @@ use strict;
use warnings;
use utf8;
use Wx qw(:font :html :misc :dialog :sizer :systemsettings);
use Wx::Event qw(EVT_HTML_LINK_CLICKED);
use Wx qw(:font :html :misc :dialog :sizer :systemsettings :frame :id);
use Wx::Event qw(EVT_HTML_LINK_CLICKED EVT_LEFT_DOWN EVT_BUTTON);
use Wx::Print;
use Wx::Html;
use base 'Wx::Dialog';
@ -12,7 +12,7 @@ use base 'Wx::Dialog';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, 'About Slic3r', wxDefaultPosition, [600, 300], &Wx::wxCLOSE_BOX);
my $self = $class->SUPER::new($parent, -1, 'About Slic3r', wxDefaultPosition, [600, 340], wxCAPTION);
$self->SetBackgroundColour(Wx::wxWHITE);
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
@ -65,7 +65,18 @@ sub new {
$html->SetPage($text);
$vsizer->Add($html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 20);
EVT_HTML_LINK_CLICKED($self, $html, \&link_clicked);
my $buttons = $self->CreateStdDialogButtonSizer(wxCLOSE);
$self->SetEscapeId(wxID_CLOSE);
EVT_BUTTON($self, wxID_CLOSE, sub {
$self->EndModal(wxID_CLOSE);
$self->Close;
});
$vsizer->Add($buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);
EVT_LEFT_DOWN($self, sub { $self->Close });
EVT_LEFT_DOWN($logo, sub { $self->Close });
return $self;
}

View file

@ -11,8 +11,8 @@ use Wx qw(:frame :bitmap :id :misc :notebook :panel :sizer :menu :dialog :filedi
use Wx::Event qw(EVT_CLOSE EVT_MENU);
use base 'Wx::Frame';
our $last_input_file;
our $last_output_file;
our $qs_last_input_file;
our $qs_last_output_file;
our $last_config;
sub new {
@ -197,7 +197,8 @@ sub _init_menubar {
$self->repair_stl;
}, undef, 'wrench.png');
$fileMenu->AppendSeparator();
$self->_append_menu_item($fileMenu, "Preferences…", 'Application preferences', sub {
# Cmd+, is standard on OS X - what about other operating systems?
$self->_append_menu_item($fileMenu, "Preferences…\tCtrl+,", 'Application preferences', sub {
Slic3r::GUI::Preferences->new($self)->ShowModal;
}, wxID_PREFERENCES);
$fileMenu->AppendSeparator();
@ -321,19 +322,19 @@ sub quick_slice {
}
$input_file = Slic3r::decode_path($dialog->GetPaths);
$dialog->Destroy;
$last_input_file = $input_file unless $params{export_svg};
$qs_last_input_file = $input_file unless $params{export_svg};
} else {
if (!defined $last_input_file) {
if (!defined $qs_last_input_file) {
Wx::MessageDialog->new($self, "No previously sliced file.",
'Error', wxICON_ERROR | wxOK)->ShowModal();
return;
}
if (! -e $last_input_file) {
Wx::MessageDialog->new($self, "Previously sliced file ($last_input_file) not found.",
if (! -e $qs_last_input_file) {
Wx::MessageDialog->new($self, "Previously sliced file ($qs_last_input_file) not found.",
'File Not Found', wxICON_ERROR | wxOK)->ShowModal();
return;
}
$input_file = $last_input_file;
$input_file = $qs_last_input_file;
}
my $input_file_basename = basename($input_file);
$Slic3r::GUI::Settings->{recent}{skein_directory} = dirname($input_file);
@ -368,19 +369,19 @@ sub quick_slice {
# select output file
my $output_file;
if ($params{reslice}) {
$output_file = $last_output_file if defined $last_output_file;
$output_file = $qs_last_output_file if defined $qs_last_output_file;
} elsif ($params{save_as}) {
$output_file = $sprint->expanded_output_filepath;
$output_file =~ s/\.gcode$/.svg/i if $params{export_svg};
my $dlg = Wx::FileDialog->new($self, 'Save ' . ($params{export_svg} ? 'SVG' : 'G-code') . ' file as:',
wxTheApp->output_path(dirname($output_file)),
basename($output_file), $params{export_svg} ? &Slic3r::GUI::FILE_WILDCARDS->{svg} : &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE);
basename($output_file), $params{export_svg} ? &Slic3r::GUI::FILE_WILDCARDS->{svg} : &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal != wxID_OK) {
$dlg->Destroy;
return;
}
$output_file = Slic3r::decode_path($dlg->GetPath);
$last_output_file = $output_file unless $params{export_svg};
$qs_last_output_file = $output_file unless $params{export_svg};
$Slic3r::GUI::Settings->{_}{last_output_path} = dirname($output_file);
wxTheApp->save_settings;
$dlg->Destroy;

View file

@ -137,6 +137,7 @@ sub BUILD {
$self->wxWindow($field);
EVT_SPINCTRL($self->parent, $field, sub {
$self->tmp_value(undef);
$self->_on_change($self->option->opt_id);
});
EVT_TEXT($self->parent, $field, sub {
@ -147,11 +148,14 @@ sub BUILD {
# gets the old one, and on_kill_focus resets the control to the old value.
# As a workaround, we get the new value from $event->GetString and store
# here temporarily so that we can return it from $self->get_value
$self->tmp_value($event->GetString);
$self->tmp_value($event->GetString) if $event->GetString =~ /^\d+$/;
$self->_on_change($self->option->opt_id);
$self->tmp_value(undef);
# We don't reset tmp_value here because _on_change might put callbacks
# in the CallAfter queue, and we want the tmp value to be available from
# them as well.
});
EVT_KILL_FOCUS($field, sub {
$self->tmp_value(undef);
$self->_on_kill_focus($self->option->opt_id, @_);
});
}

View file

@ -337,7 +337,13 @@ sub new {
$text->SetFont($Slic3r::GUI::small_font);
my $choice = Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [], wxCB_READONLY);
$self->{preset_choosers}{$group} = [$choice];
EVT_COMBOBOX($choice, $choice, sub { $self->_on_select_preset($group, @_) });
# setup the listener
EVT_COMBOBOX($choice, $choice, sub {
my ($choice) = @_;
wxTheApp->CallAfter(sub {
$self->_on_select_preset($group, $choice);
});
});
$presets->Add($text, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 4);
$presets->Add($choice, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND | wxBOTTOM, 0);
}
@ -431,7 +437,9 @@ sub _on_select_preset {
wxTheApp->save_settings;
return;
}
$self->{on_select_preset}->($group, $choice->GetSelection)
# call GetSelection() in scalar context as it's context-aware
$self->{on_select_preset}->($group, scalar $choice->GetSelection)
if $self->{on_select_preset};
# get new config and generate on_config_change() event for updating plater and other things
@ -445,10 +453,16 @@ sub GetFrame {
sub update_presets {
my $self = shift;
my ($group, $presets, $selected) = @_;
my ($group, $presets, $selected, $is_dirty) = @_;
foreach my $choice (@{ $self->{preset_choosers}{$group} }) {
my $sel = $choice->GetSelection;
my @choosers = @{ $self->{preset_choosers}{$group} };
foreach my $choice (@choosers) {
if ($group eq 'filament' && @choosers > 1) {
# if we have more than one filament chooser, keep our selection
# instead of importing the one from the tab
$selected = $choice->GetSelection;
$is_dirty = 0;
}
$choice->Clear;
foreach my $preset (@$presets) {
my $bitmap;
@ -471,15 +485,23 @@ sub update_presets {
}
$choice->AppendString($preset->name, $bitmap);
}
$choice->SetSelection($sel) if $sel <= $#$presets;
if ($selected <= $#$presets) {
if ($is_dirty) {
$choice->SetString($selected, $choice->GetString($selected) . " (modified)");
}
# call SetSelection() only after SetString() otherwise the new string
# won't be picked up as the visible string
$choice->SetSelection($selected);
}
}
$self->{preset_choosers}{$group}[0]->SetSelection($selected);
}
sub filament_presets {
my $self = shift;
return map $_->GetSelection, @{ $self->{preset_choosers}{filament} };
# force scalar context for GetSelection() as it's context-aware
return map scalar($_->GetSelection), @{ $self->{preset_choosers}{filament} };
}
sub add {
@ -1083,7 +1105,7 @@ sub export_gcode {
} else {
my $default_output_file = $self->{print}->expanded_output_filepath($main::opt{output});
my $dlg = Wx::FileDialog->new($self, 'Save G-code file as:', wxTheApp->output_path(dirname($default_output_file)),
basename($default_output_file), &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE);
basename($default_output_file), &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal != wxID_OK) {
$dlg->Destroy;
return;
@ -1091,7 +1113,7 @@ sub export_gcode {
my $path = Slic3r::decode_path($dlg->GetPath);
$Slic3r::GUI::Settings->{_}{last_output_path} = dirname($path);
wxTheApp->save_settings;
$self->{export_gcode_output_file} = $Slic3r::GUI::MainFrame::last_output_file = $path;
$self->{export_gcode_output_file} = $path;
$dlg->Destroy;
}
@ -1239,13 +1261,15 @@ sub send_gcode {
my $ua = LWP::UserAgent->new;
$ua->timeout(180);
my $path = Slic3r::encode_path($self->{send_gcode_file});
my $res = $ua->post(
"http://" . $self->{config}->octoprint_host . "/api/files/local",
Content_Type => 'form-data',
'X-Api-Key' => $self->{config}->octoprint_apikey,
Content => [
# OctoPrint doesn't like Windows paths
file => [ $self->{send_gcode_file}, basename($self->{send_gcode_file}) ],
# OctoPrint doesn't like Windows paths so we use basename()
# Also, since we need to read from filesystem we process it through encode_path()
file => [ $path, basename($path) ],
],
);
@ -1315,7 +1339,7 @@ sub _get_export_file {
$dlg->Destroy;
return undef;
}
$output_file = $Slic3r::GUI::MainFrame::last_output_file = Slic3r::decode_path($dlg->GetPath);
$output_file = Slic3r::decode_path($dlg->GetPath);
$dlg->Destroy;
}
return $output_file;
@ -1383,14 +1407,34 @@ sub on_extruders_change {
my $choices = $self->{preset_choosers}{filament};
while (@$choices < $num_extruders) {
# copy strings from first choice
my @presets = $choices->[0]->GetStrings;
push @$choices, Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [@presets], wxCB_READONLY);
# initialize new choice
my $choice = Wx::BitmapComboBox->new($self, -1, "", wxDefaultPosition, wxDefaultSize, [@presets], wxCB_READONLY);
push @$choices, $choice;
# copy icons from first choice
$choice->SetItemBitmap($_, $choices->[0]->GetItemBitmap($_)) for 0..$#presets;
# insert new choice into sizer
$self->{presets_sizer}->Insert(4 + ($#$choices-1)*2, 0, 0);
$self->{presets_sizer}->Insert(5 + ($#$choices-1)*2, $choices->[-1], 0, wxEXPAND | wxBOTTOM, FILAMENT_CHOOSERS_SPACING);
EVT_COMBOBOX($choices->[-1], $choices->[-1], sub { $self->_on_select_preset('filament', @_) });
my $i = first { $choices->[-1]->GetString($_) eq ($Slic3r::GUI::Settings->{presets}{"filament_" . $#$choices} || '') } 0 .. $#presets;
$choices->[-1]->SetSelection($i || 0);
$self->{presets_sizer}->Insert(5 + ($#$choices-1)*2, $choice, 0, wxEXPAND | wxBOTTOM, FILAMENT_CHOOSERS_SPACING);
# setup the listener
EVT_COMBOBOX($choice, $choice, sub {
my ($choice) = @_;
wxTheApp->CallAfter(sub {
$self->_on_select_preset('filament', $choice);
});
});
# initialize selection
my $i = first { $choice->GetString($_) eq ($Slic3r::GUI::Settings->{presets}{"filament_" . $#$choices} || '') } 0 .. $#presets;
$choice->SetSelection($i || 0);
}
# remove unused choices if any
while (@$choices > $num_extruders) {
$self->{presets_sizer}->Remove(4 + ($#$choices-1)*2); # label
$self->{presets_sizer}->Remove(4 + ($#$choices-1)*2); # wxChoice

View file

@ -164,6 +164,8 @@ sub new {
EVT_MOUSEWHEEL($self, sub {
my ($self, $e) = @_;
return if !$self->GetParent->enabled;
my $old_zoom = $self->_zoom;
# Calculate the zoom delta and apply it to the current zoom factor
@ -205,6 +207,8 @@ sub new {
sub mouse_event {
my ($self, $e) = @_;
return if !$self->GetParent->enabled;
my $pos = Slic3r::Pointf->new($e->GetPositionXY);
if ($e->Entering && &Wx::wxMSW) {
# wxMSW needs focus in order to catch mouse wheel events
@ -262,8 +266,9 @@ sub set_z {
}
}
# reverse layers so that we draw the lowermost (i.e. current) on top
$self->z($z);
$self->layers([ @layers ]);
$self->layers([ reverse @layers ]);
$self->Refresh;
}

View file

@ -107,12 +107,17 @@ sub new {
$grid->SetCellValue($event->GetRow, $event->GetCol, $value);
# if there's no empty row, let's append one
for my $i (0 .. $grid->GetNumberRows-1) {
for my $i (0 .. $grid->GetNumberRows) {
if ($i == $grid->GetNumberRows) {
# if we're here then we found no empty row
$grid->AppendRows(1);
last;
}
if (!grep $grid->GetCellValue($i, $_), 0..2) {
return;
# exit loop if this row is empty
last;
}
}
$grid->AppendRows(1);
$self->{layers_changed} = 1;
});

View file

@ -65,7 +65,9 @@ sub new {
$self->{treectrl}->AddRoot("root");
$self->{pages} = [];
$self->{treectrl}->SetIndent(0);
$self->{disable_tree_sel_changed_event} = 0;
EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
return if $self->{disable_tree_sel_changed_event};
my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
or return;
$_->Hide for @{$self->{pages}};
@ -106,6 +108,7 @@ sub new {
$self->{config} = Slic3r::Config->new;
$self->build;
$self->update_tree;
$self->_update;
if ($self->hidden_options) {
$self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
@ -177,8 +180,11 @@ sub _update {}
sub _on_presets_changed {
my $self = shift;
$self->{on_presets_changed}->($self->{presets}, $self->{presets_choice}->GetSelection)
if $self->{on_presets_changed};
$self->{on_presets_changed}->(
$self->{presets},
scalar($self->{presets_choice}->GetSelection),
$self->is_dirty,
) if $self->{on_presets_changed};
}
sub on_preset_loaded {}
@ -198,6 +204,8 @@ sub select_preset {
sub select_preset_by_name {
my ($self, $name) = @_;
$name = Unicode::Normalize::NFC($name);
$self->select_preset(first { $self->{presets}[$_]->name eq $name } 0 .. $#{$self->{presets}});
}
@ -223,6 +231,10 @@ sub on_select_preset {
'Unsaved Changes', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
if ($confirm->ShowModal == wxID_NO) {
$self->{presets_choice}->SetSelection($self->current_preset);
# trigger the on_presets_changed event so that we also restore the previous value
# in the plater selector
$self->_on_presets_changed;
return;
}
}
@ -282,7 +294,6 @@ sub add_options_page {
$page->Hide;
$self->{sizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
push @{$self->{pages}}, $page;
$self->update_tree;
return $page;
}
@ -303,12 +314,15 @@ sub update_tree {
foreach my $page (@{$self->{pages}}) {
my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID});
if ($page->{title} eq $selected) {
$self->{disable_tree_sel_changed_event} = 1;
$self->{treectrl}->SelectItem($itemId);
$self->{disable_tree_sel_changed_event} = 0;
$have_selection = 1;
}
}
if (!$have_selection) {
# this is triggered on first load, so we don't disable the sel change event
$self->{treectrl}->SelectItem($self->{treectrl}->GetFirstChild($rootItem));
}
}
@ -431,6 +445,7 @@ sub set_value {
package Slic3r::GUI::Tab::Print;
use base 'Slic3r::GUI::Tab';
use List::Util qw(first);
use Wx qw(:icon :dialog :id);
sub name { 'print' }
@ -449,6 +464,7 @@ sub build {
infill_every_layers infill_only_where_needed
solid_infill_every_layers fill_angle solid_infill_below_area
only_retract_when_crossing_perimeters infill_first
max_print_speed max_volumetric_speed
perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed
solid_infill_speed top_solid_infill_speed support_material_speed
support_material_interface_speed bridge_speed gap_fill_speed
@ -606,6 +622,11 @@ sub build {
$optgroup->append_single_option_line('first_layer_acceleration');
$optgroup->append_single_option_line('default_acceleration');
}
{
my $optgroup = $page->new_optgroup('Autospeed (advanced)');
$optgroup->append_single_option_line('max_print_speed');
$optgroup->append_single_option_line('max_volumetric_speed');
}
}
{
@ -738,6 +759,22 @@ sub _update {
}
}
if ($config->fill_density == 100
&& !first { $_ eq $config->fill_pattern } @{$Slic3r::Config::Options->{external_fill_pattern}{values}}) {
my $dialog = Wx::MessageDialog->new($self,
"The " . $config->fill_pattern . " infill pattern is not supposed to work at 100% density.\n"
. "\nShall I switch to rectilinear fill pattern?",
'Infill', wxICON_WARNING | wxYES | wxNO);
my $new_conf = Slic3r::Config->new;
if ($dialog->ShowModal() == wxID_YES) {
$new_conf->set("fill_pattern", 1);
} else {
$new_conf->set("fill_density", 40);
}
$self->load_config($new_conf);
}
my $have_perimeters = $config->perimeters > 0;
$self->get_field($_)->toggle($have_perimeters)
for qw(extra_perimeters thin_walls overhangs seam_position external_perimeters_first
@ -1016,8 +1053,10 @@ sub build {
$optgroup->on_change(sub {
my ($opt_id) = @_;
if ($opt_id eq 'extruders_count') {
wxTheApp->CallAfter(sub {
$self->_extruders_count_changed($optgroup->get_value('extruders_count'));
});
$self->update_dirty;
$self->_extruders_count_changed($optgroup->get_value('extruders_count'));
}
});
}
@ -1231,8 +1270,6 @@ sub _build_extruder_pages {
$optgroup->append_single_option_line($_, $extruder_idx)
for qw(retract_length_toolchange retract_restart_extra_toolchange);
}
$self->{extruder_pages}[$extruder_idx]{disabled} = 0;
}
# remove extra pages
@ -1325,7 +1362,7 @@ sub load_config_file {
}
package Slic3r::GUI::Tab::Page;
use Wx qw(:misc :panel :sizer);
use Wx qw(wxTheApp :misc :panel :sizer);
use base 'Wx::ScrolledWindow';
sub new {
@ -1353,8 +1390,11 @@ sub new_optgroup {
config => $self->GetParent->{config},
label_width => $params{label_width} // 200,
on_change => sub {
$self->GetParent->update_dirty;
$self->GetParent->_on_value_change(@_);
my ($opt_key, $value) = @_;
wxTheApp->CallAfter(sub {
$self->GetParent->update_dirty;
$self->GetParent->_on_value_change($opt_key, $value);
});
},
);
@ -1454,7 +1494,7 @@ sub config {
if ($self->default) {
return Slic3r::Config->new_from_defaults(@$keys);
} else {
if (!-e $self->file) {
if (!-e Slic3r::encode_path($self->file)) {
Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ").");
return undef;
}