Better fix for non-global options not being replaced in filename placeholders. Includes refactoring and a new PlaceholderParser class. Also includes regression tests. #1831

This commit is contained in:
Alessandro Ranellucci 2014-03-17 00:39:07 +01:00
parent bc054e613c
commit 34f1511e0c
10 changed files with 146 additions and 128 deletions

View file

@ -670,16 +670,31 @@ sub export_gcode {
return;
}
# get config before spawning the thread because it needs GetParent and it's not available there
our $config = $self->skeinpanel->config;
our $extra_variables = $self->skeinpanel->extra_variables;
# It looks like declaring a local $SIG{__WARN__} prevents the ugly
# "Attempt to free unreferenced scalar" warning...
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
# apply config and validate print
my $config = $self->skeinpanel->config;
eval {
# this will throw errors if config is not valid
$config->validate;
$self->{print}->apply_config($config);
$self->{print}->validate;
};
# apply extra variables
{
my $extra = $self->skeinpanel->extra_variables;
$self->{print}->placeholder_parser->set($_, $extra->{$_}) for keys %$extra;
}
# select output file
$self->{output_file} = $main::opt{output};
{
$self->{output_file} = $self->skeinpanel->init_print->expanded_output_filepath($self->{output_file}, $self->{model}->objects->[0]->input_file);
my $dlg = Wx::FileDialog->new($self, 'Save G-code file as:', Slic3r::GUI->output_path(dirname($self->{output_file})),
basename($self->{output_file}), &Slic3r::GUI::SkeinPanel::FILE_WILDCARDS->{gcode}, wxFD_SAVE);
my $output_file = $self->{print}->expanded_output_filepath($self->{output_file});
my $dlg = Wx::FileDialog->new($self, 'Save G-code file as:', Slic3r::GUI->output_path(dirname($output_file)),
basename($output_file), &Slic3r::GUI::SkeinPanel::FILE_WILDCARDS->{gcode}, wxFD_SAVE);
if ($dlg->ShowModal != wxID_OK) {
$dlg->Destroy;
return;
@ -692,10 +707,6 @@ sub export_gcode {
$self->statusbar->StartBusy;
# It looks like declaring a local $SIG{__WARN__} prevents the ugly
# "Attempt to free unreferenced scalar" warning...
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
if ($Slic3r::have_threads) {
@_ = ();
@ -704,8 +715,6 @@ sub export_gcode {
$self->{export_thread} = threads->create(sub {
$_thread_self->export_gcode2(
$config,
$extra_variables,
$_thread_self->{output_file},
progressbar => sub { Wx::PostEvent($_thread_self, Wx::PlThreadEvent->new(-1, $PROGRESS_BAR_EVENT, shared_clone([@_]))) },
message_dialog => sub { Wx::PostEvent($_thread_self, Wx::PlThreadEvent->new(-1, $MESSAGE_DIALOG_EVENT, shared_clone([@_]))) },
@ -727,8 +736,6 @@ sub export_gcode {
});
} else {
$self->export_gcode2(
$config,
$extra_variables,
$self->{output_file},
progressbar => sub {
my ($percent, $message) = @_;
@ -747,7 +754,7 @@ sub export_gcode {
sub export_gcode2 {
my $self = shift;
my ($config, $extra_variables, $output_file, %params) = @_;
my ($output_file, %params) = @_;
local $SIG{'KILL'} = sub {
Slic3r::debugf "Exporting cancelled; exiting thread...\n";
Slic3r::thread_cleanup();
@ -756,16 +763,7 @@ sub export_gcode2 {
my $print = $self->{print};
eval {
# this will throw errors if config is not valid
$config->validate;
$print->apply_config($config);
$print->apply_extra_variables($extra_variables);
$print->validate;
{
my @warnings = ();
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
@ -840,7 +838,7 @@ sub _get_export_file {
my $output_file = $main::opt{output};
{
$output_file = $self->skeinpanel->init_print->expanded_output_filepath($output_file, $self->{model}->objects->[0]->input_file);
$output_file = $self->{print}->expanded_output_filepath($output_file);
$output_file =~ s/\.gcode$/$suffix/i;
my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file),
basename($output_file), &Slic3r::GUI::SkeinPanel::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);