Improved error reporting of the PlaceholderParser.
The PlaceholderParser is currently used by the GCode.cpp and by Printer.cpp to generate a new name for the exported G-code or SVG file. The PlaceholderParser::process() will throw a runtime_error with a comprehensive error message. The G-code export will include these error messages into the G-code text with !!!!!! separators, and the GUI will inform the user, that the G-code export failed.
This commit is contained in:
parent
1244fd09eb
commit
8746f84fa2
11 changed files with 190 additions and 141 deletions
|
@ -422,6 +422,7 @@ sub quick_slice {
|
|||
if ($params{reslice}) {
|
||||
$output_file = $qs_last_output_file if defined $qs_last_output_file;
|
||||
} elsif ($params{save_as}) {
|
||||
# The following line may die if the output_filename_format template substitution fails.
|
||||
$output_file = $sprint->output_filepath;
|
||||
$output_file =~ s/\.[gG][cC][oO][dD][eE]$/.svg/ if $params{export_svg};
|
||||
my $dlg = Wx::FileDialog->new($self, 'Save ' . ($params{export_svg} ? 'SVG' : 'G-code') . ' file as:',
|
||||
|
|
|
@ -1291,9 +1291,11 @@ sub export_gcode {
|
|||
|
||||
# select output file
|
||||
if ($output_file) {
|
||||
$self->{export_gcode_output_file} = $self->{print}->output_filepath($output_file);
|
||||
$self->{export_gcode_output_file} = eval { $self->{print}->output_filepath($output_file) };
|
||||
Slic3r::GUI::catch_error($self) and return;
|
||||
} else {
|
||||
my $default_output_file = $self->{print}->output_filepath($main::opt{output} // '');
|
||||
my $default_output_file = eval { $self->{print}->output_filepath($main::opt{output} // '') };
|
||||
Slic3r::GUI::catch_error($self) and return;
|
||||
my $dlg = Wx::FileDialog->new($self, 'Save G-code file as:',
|
||||
wxTheApp->{app_config}->get_last_output_dir(dirname($default_output_file)),
|
||||
basename($default_output_file), &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
|
@ -1544,7 +1546,8 @@ sub export_amf {
|
|||
sub _get_export_file {
|
||||
my ($self, $format) = @_;
|
||||
my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml';
|
||||
my $output_file = $self->{print}->output_filepath($main::opt{output} // '');
|
||||
my $output_file = eval { $self->{print}->output_filepath($main::opt{output} // '') };
|
||||
Slic3r::GUI::catch_error($self) and return undef;
|
||||
$output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/;
|
||||
my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file),
|
||||
basename($output_file), &Slic3r::GUI::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
|
||||
|
|
|
@ -65,6 +65,9 @@ sub process {
|
|||
}
|
||||
|
||||
# G-code export process, running at a background thread.
|
||||
# The export_gcode may die for various reasons (fails to process output_filename_format,
|
||||
# write error into the G-code, cannot execute post-processing scripts).
|
||||
# It is up to the caller to show an error message.
|
||||
sub export_gcode {
|
||||
my $self = shift;
|
||||
my %params = @_;
|
||||
|
@ -73,11 +76,12 @@ sub export_gcode {
|
|||
$self->process;
|
||||
|
||||
# output everything to a G-code file
|
||||
# The following call may die if the output_filename_format template substitution fails.
|
||||
my $output_file = $self->output_filepath($params{output_file} // '');
|
||||
$self->status_cb->(90, "Exporting G-code" . ($output_file ? " to $output_file" : ""));
|
||||
|
||||
die "G-code export to " . $output_file . " failed\n"
|
||||
if ! Slic3r::GCode->new->do_export($self, $output_file);
|
||||
# The following line may die for multiple reasons.
|
||||
Slic3r::GCode->new->do_export($self, $output_file);
|
||||
|
||||
# run post-processing scripts
|
||||
if (@{$self->config->post_process}) {
|
||||
|
@ -99,6 +103,7 @@ sub export_gcode {
|
|||
}
|
||||
|
||||
# Export SVG slices for the offline SLA printing.
|
||||
# The export_svg is expected to be executed inside an eval block.
|
||||
sub export_svg {
|
||||
my $self = shift;
|
||||
my %params = @_;
|
||||
|
@ -107,6 +112,7 @@ sub export_svg {
|
|||
|
||||
my $fh = $params{output_fh};
|
||||
if (!$fh) {
|
||||
# The following line may die if the output_filename_format template substitution fails.
|
||||
my $output_file = $self->output_filepath($params{output_file});
|
||||
$output_file =~ s/\.[gG][cC][oO][dD][eE]$/.svg/;
|
||||
Slic3r::open(\$fh, ">", $output_file) or die "Failed to open $output_file for writing\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue