mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
Ported expanded_output_filepath() to C++/XS
This commit is contained in:
parent
66493ce821
commit
6a90fceaaf
8 changed files with 42 additions and 47 deletions
|
@ -77,7 +77,7 @@ sub export_gcode {
|
|||
$self->process;
|
||||
|
||||
# output everything to a G-code file
|
||||
my $output_file = $self->expanded_output_filepath($params{output_file});
|
||||
my $output_file = $self->output_filepath($params{output_file} // '');
|
||||
$self->status_cb->(90, "Exporting G-code" . ($output_file ? " to $output_file" : ""));
|
||||
$self->write_gcode($params{output_fh} || $output_file);
|
||||
|
||||
|
@ -105,7 +105,7 @@ sub export_svg {
|
|||
|
||||
my $fh = $params{output_fh};
|
||||
if (!$fh) {
|
||||
my $output_file = $self->expanded_output_filepath($params{output_file});
|
||||
my $output_file = $self->output_filepath($params{output_file});
|
||||
$output_file =~ s/\.gcode$/.svg/i;
|
||||
Slic3r::open(\$fh, ">", $output_file) or die "Failed to open $output_file for writing\n";
|
||||
print "Exporting to $output_file..." unless $params{quiet};
|
||||
|
@ -326,45 +326,6 @@ sub write_gcode {
|
|||
}
|
||||
}
|
||||
|
||||
# this method will return the supplied input file path after expanding its
|
||||
# format variables with their values
|
||||
sub expanded_output_filepath {
|
||||
my $self = shift;
|
||||
my ($path) = @_;
|
||||
|
||||
return undef if !@{$self->objects};
|
||||
my $input_file = first { defined $_ } map $_->model_object->input_file, @{$self->objects};
|
||||
return undef if !defined $input_file;
|
||||
|
||||
my $filename = my $filename_base = basename($input_file);
|
||||
$filename_base =~ s/\.[^.]+$//; # without suffix
|
||||
|
||||
# set filename in placeholder parser so that it's available also in custom G-code
|
||||
$self->placeholder_parser->set(input_filename => $filename);
|
||||
$self->placeholder_parser->set(input_filename_base => $filename_base);
|
||||
|
||||
# set other variables from model object
|
||||
$self->placeholder_parser->set_multiple(
|
||||
scale => [ map $_->model_object->instances->[0]->scaling_factor * 100 . "%", @{$self->objects} ],
|
||||
);
|
||||
|
||||
if ($path && -d $path) {
|
||||
# if output path is an existing directory, we take that and append
|
||||
# the specified filename format
|
||||
$path = File::Spec->join($path, $self->config->output_filename_format);
|
||||
} elsif (!$path) {
|
||||
# if no explicit output file was defined, we take the input
|
||||
# file directory and append the specified filename format
|
||||
$path = (fileparse($input_file))[1] . $self->config->output_filename_format;
|
||||
} else {
|
||||
# path is a full path to a file so we use it as it is
|
||||
}
|
||||
|
||||
# make sure we use an up-to-date timestamp
|
||||
$self->placeholder_parser->update_timestamp;
|
||||
return $self->placeholder_parser->process($path);
|
||||
}
|
||||
|
||||
# Wrapper around the C++ Slic3r::Print::validate()
|
||||
# to produce a Perl exception without a hang-up on some Strawberry perls.
|
||||
sub validate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue