mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 12:41:20 -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
				
			
		|  | @ -440,7 +440,7 @@ sub quick_slice { | |||
|         if ($params{reslice}) { | ||||
|             $output_file = $qs_last_output_file if defined $qs_last_output_file; | ||||
|         } elsif ($params{save_as}) { | ||||
|             $output_file = $sprint->expanded_output_filepath; | ||||
|             $output_file = $sprint->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)), | ||||
|  |  | |||
|  | @ -1298,9 +1298,9 @@ sub export_gcode { | |||
|      | ||||
|     # select output file | ||||
|     if ($output_file) { | ||||
|         $self->{export_gcode_output_file} = $self->{print}->expanded_output_filepath($output_file); | ||||
|         $self->{export_gcode_output_file} = $self->{print}->output_filepath($output_file); | ||||
|     } else { | ||||
|         my $default_output_file = $self->{print}->expanded_output_filepath($main::opt{output}); | ||||
|         my $default_output_file = $self->{print}->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 | wxFD_OVERWRITE_PROMPT); | ||||
|         if ($dlg->ShowModal != wxID_OK) { | ||||
|  | @ -1571,7 +1571,7 @@ sub _get_export_file { | |||
|      | ||||
|     my $output_file = $main::opt{output}; | ||||
|     { | ||||
|         $output_file = $self->{print}->expanded_output_filepath($output_file); | ||||
|         $output_file = $self->{print}->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::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ use Slic3r::Geometry qw(X Y); | |||
| has '_print' => ( | ||||
|     is      => 'ro', | ||||
|     default => sub { Slic3r::Print->new }, | ||||
|     handles => [qw(apply_config extruders expanded_output_filepath | ||||
|     handles => [qw(apply_config extruders output_filepath | ||||
|                     total_used_filament total_extruded_volume | ||||
|                     placeholder_parser process)], | ||||
| ); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci