mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	second draft implementation of output_filename_format
This commit is contained in:
		
							parent
							
								
									342823fdf3
								
							
						
					
					
						commit
						1071b556cb
					
				
					 6 changed files with 72 additions and 31 deletions
				
			
		|  | @ -81,8 +81,14 @@ The author is Alessandro Ranellucci (me). | ||||||
|         --help              Output this usage screen and exit |         --help              Output this usage screen and exit | ||||||
|         --save <file>       Save configuration to the specified file |         --save <file>       Save configuration to the specified file | ||||||
|         --load <file>       Load configuration from the specified file |         --load <file>       Load configuration from the specified file | ||||||
|         -o, --output        File to output gcode to (default: <inputfile>.gcode) |         -o <filename>       File name to output gcode to (default: --output) | ||||||
|          |        | ||||||
|  |       Output options: | ||||||
|  |         --output            Output file name format (default: [input_filename_base].gcode) | ||||||
|  |                             examples: | ||||||
|  |                             [input_filename_base]_h[layer_height]_p[perimeters]_s[solid_layers].gcode | ||||||
|  |                             [input_filename]_center[print_center]_layer[layer_height].gcode | ||||||
|  |        | ||||||
|       Printer options: |       Printer options: | ||||||
|         --nozzle-diameter   Diameter of nozzle in mm (default: 0.5) |         --nozzle-diameter   Diameter of nozzle in mm (default: 0.5) | ||||||
|         --print-center      Coordinates of the point to center the print around  |         --print-center      Coordinates of the point to center the print around  | ||||||
|  |  | ||||||
|  | @ -33,6 +33,9 @@ use Slic3r::Surface; | ||||||
| use Slic3r::TriangleMesh; | use Slic3r::TriangleMesh; | ||||||
| use Slic3r::TriangleMesh::IntersectionLine; | use Slic3r::TriangleMesh::IntersectionLine; | ||||||
| 
 | 
 | ||||||
|  | # output options | ||||||
|  | our $output_filename_format = '[input_filename_base].gcode'; | ||||||
|  | 
 | ||||||
| # printer options | # printer options | ||||||
| our $nozzle_diameter    = 0.5; | our $nozzle_diameter    = 0.5; | ||||||
| our $print_center       = [100,100];  # object will be centered around this point | our $print_center       = [100,100];  # object will be centered around this point | ||||||
|  |  | ||||||
|  | @ -7,6 +7,13 @@ use constant PI => 4 * atan2(1, 1); | ||||||
| 
 | 
 | ||||||
| our $Options = { | our $Options = { | ||||||
| 
 | 
 | ||||||
|  |     # output options | ||||||
|  |     'output_filename_format' => { | ||||||
|  |         label   => 'Output filename format', | ||||||
|  |         cli     => 'output=s', | ||||||
|  |         type    => 's', | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|     # printer options |     # printer options | ||||||
|     'nozzle_diameter' => { |     'nozzle_diameter' => { | ||||||
|         label   => 'Nozzle diameter', |         label   => 'Nozzle diameter', | ||||||
|  |  | ||||||
|  | @ -61,6 +61,10 @@ sub new { | ||||||
|             title => 'Extrusion', |             title => 'Extrusion', | ||||||
|             options => [qw(extrusion_width_ratio bridge_flow_ratio)], |             options => [qw(extrusion_width_ratio bridge_flow_ratio)], | ||||||
|         }, |         }, | ||||||
|  |         output => { | ||||||
|  |             title => 'Output', | ||||||
|  |             options => [qw(output_filename_format)], | ||||||
|  |         }, | ||||||
|     ); |     ); | ||||||
|     $self->{panels} = \%panels; |     $self->{panels} = \%panels; | ||||||
|      |      | ||||||
|  | @ -87,7 +91,7 @@ sub new { | ||||||
|         $make_tab->([qw(transform accuracy skirt)], [qw(print retract)]), |         $make_tab->([qw(transform accuracy skirt)], [qw(print retract)]), | ||||||
|         $make_tab->([qw(printer filament)], [qw(print_speed speed)]), |         $make_tab->([qw(printer filament)], [qw(print_speed speed)]), | ||||||
|         $make_tab->([qw(gcode)]), |         $make_tab->([qw(gcode)]), | ||||||
|         $make_tab->([qw(extrusion)]), |         $make_tab->([qw(extrusion)], [qw(output)]), | ||||||
|     ); |     ); | ||||||
|      |      | ||||||
|     $tabpanel->AddPage($tabs[0], "Print Settings"); |     $tabpanel->AddPage($tabs[0], "Print Settings"); | ||||||
|  | @ -148,27 +152,8 @@ sub do_slice { | ||||||
|         my $input_file_basename = basename($input_file); |         my $input_file_basename = basename($input_file); | ||||||
|         $last_dir = dirname($input_file); |         $last_dir = dirname($input_file); | ||||||
|          |          | ||||||
|         # select output file |  | ||||||
|         my $output_file = $main::opt{output}; |  | ||||||
|         if ($params{save_as}) { |  | ||||||
|             if (!$output_file) { |  | ||||||
|                 $output_file = $input_file_basename; |  | ||||||
|                 $output_file =~ s/\.stl$/.gcode/i; |  | ||||||
|             } |  | ||||||
|             my $dlg = Wx::FileDialog->new($self, 'Save gcode file as:', dirname($output_file), |  | ||||||
|                 basename($output_file), $gcode_wildcard, wxFD_SAVE); |  | ||||||
|             return if $dlg->ShowModal != wxID_OK; |  | ||||||
|             $output_file = $dlg->GetPath; |  | ||||||
|         } |  | ||||||
|          |  | ||||||
|         # show processbar dialog |  | ||||||
|         $process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...",  |  | ||||||
|             100, $self, wxPD_APP_MODAL); |  | ||||||
|         $process_dialog->Pulse; |  | ||||||
|          |  | ||||||
|         my $skein = Slic3r::Skein->new( |         my $skein = Slic3r::Skein->new( | ||||||
|             input_file  => $input_file, |             input_file  => $input_file, | ||||||
|             output_file => $output_file, |  | ||||||
|             status_cb   => sub { |             status_cb   => sub { | ||||||
|                 my ($percent, $message) = @_; |                 my ($percent, $message) = @_; | ||||||
|                 if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) { |                 if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) { | ||||||
|  | @ -176,6 +161,24 @@ sub do_slice { | ||||||
|                 } |                 } | ||||||
|             }, |             }, | ||||||
|         ); |         ); | ||||||
|  | 
 | ||||||
|  |         # select output file | ||||||
|  |         my $output_file = $main::opt{output_filename}; | ||||||
|  |         if ($params{save_as}) { | ||||||
|  |             if (!$output_file) { | ||||||
|  |                 $output_file = $skein->get_output_filename($input_file); | ||||||
|  |             } | ||||||
|  |             my $dlg = Wx::FileDialog->new($self, 'Save gcode file as:', dirname($output_file), | ||||||
|  |                 basename($output_file), $gcode_wildcard, wxFD_SAVE); | ||||||
|  |             return if $dlg->ShowModal != wxID_OK; | ||||||
|  |             $skein->output_file($dlg->GetPath); | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         # show processbar dialog | ||||||
|  |         $process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...",  | ||||||
|  |             100, $self, wxPD_APP_MODAL); | ||||||
|  |         $process_dialog->Pulse; | ||||||
|  |          | ||||||
|         { |         { | ||||||
|             my @warnings = (); |             my @warnings = (); | ||||||
|             local $SIG{__WARN__} = sub { push @warnings, $_[0] }; |             local $SIG{__WARN__} = sub { push @warnings, $_[0] }; | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ use Time::HiRes qw(gettimeofday tv_interval); | ||||||
| use XXX; | use XXX; | ||||||
| 
 | 
 | ||||||
| has 'input_file'    => (is => 'ro', required => 1); | has 'input_file'    => (is => 'ro', required => 1); | ||||||
| has 'output_file'   => (is => 'rw', required => 0); | has 'output_file'    => (is => 'rw', required => 0); | ||||||
| has 'status_cb'     => (is => 'rw', required => 0, default => sub { sub {} }); | has 'status_cb'     => (is => 'rw', required => 0, default => sub { sub {} }); | ||||||
| has 'processing_time' => (is => 'rw', required => 0); | has 'processing_time' => (is => 'rw', required => 0); | ||||||
| 
 | 
 | ||||||
|  | @ -83,12 +83,11 @@ sub go { | ||||||
|      |      | ||||||
|     # output everything to a GCODE file |     # output everything to a GCODE file | ||||||
|     $self->status_cb->(90, "Exporting GCODE..."); |     $self->status_cb->(90, "Exporting GCODE..."); | ||||||
|     if (!$self->output_file) { |     if ($self->output_file) { | ||||||
|         my $output_file = $self->input_file; |         $print->export_gcode($self->output_file); | ||||||
|         $output_file =~ s/\.stl$/.gcode/i; |     } else { | ||||||
|         $self->output_file($output_file); |         $print->export_gcode($self->get_output_filename); | ||||||
|     } |     } | ||||||
|     $print->export_gcode($self->output_file); |  | ||||||
|      |      | ||||||
|     # output some statistics |     # output some statistics | ||||||
|     $self->processing_time(tv_interval($t0)); |     $self->processing_time(tv_interval($t0)); | ||||||
|  | @ -101,4 +100,20 @@ sub go { | ||||||
|         $print->total_extrusion_length, $print->total_extrusion_volume; |         $print->total_extrusion_length, $print->total_extrusion_volume; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | sub get_output_filename { | ||||||
|  |     my $self = shift; | ||||||
|  |     my $filename = Slic3r::Config->get('output_filename_format'); | ||||||
|  |     my %opts = %$Slic3r::Config::Options; | ||||||
|  |     my $input = $self->input_file; | ||||||
|  |     # these pseudo-options are the path and filename, without and with extension, of the input file | ||||||
|  |     $filename =~ s/\[input_filename\]/$input/g; | ||||||
|  |     $input =~ s/\.stl$//i; | ||||||
|  |     $filename =~ s/\[input_filename_base\]/$input/g; | ||||||
|  |     # make a list of options | ||||||
|  |     my $options = join '|', keys %$Slic3r::Config::Options; | ||||||
|  |     # use that list to search and replace option names with option values | ||||||
|  |     $filename =~ s/\[($options)\]/Slic3r::Config->get($1)/eg; | ||||||
|  |     return $filename; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 1; | 1; | ||||||
|  |  | ||||||
							
								
								
									
										13
									
								
								slic3r.pl
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								slic3r.pl
									
										
									
									
									
								
							|  | @ -20,7 +20,8 @@ my %cli_options = (); | ||||||
|         'help'                  => sub { usage() }, |         'help'                  => sub { usage() }, | ||||||
|          |          | ||||||
|         'debug'                 => \$Slic3r::debug, |         'debug'                 => \$Slic3r::debug, | ||||||
|         'o|output=s'            => \$opt{output}, |          | ||||||
|  |         'o=s'                   => \$opt{output_filename}, | ||||||
|          |          | ||||||
|         'save=s'                => \$opt{save}, |         'save=s'                => \$opt{save}, | ||||||
|         'load=s'                => \$opt{load}, |         'load=s'                => \$opt{load}, | ||||||
|  | @ -70,7 +71,7 @@ if ($ARGV[0]) { | ||||||
|      |      | ||||||
|     my $skein = Slic3r::Skein->new( |     my $skein = Slic3r::Skein->new( | ||||||
|         input_file  => $input_file, |         input_file  => $input_file, | ||||||
|         output_file => $opt{output}, |         output_file => $opt{output_filename}, | ||||||
|     ); |     ); | ||||||
|     $skein->go; |     $skein->go; | ||||||
|      |      | ||||||
|  | @ -90,8 +91,14 @@ Usage: slic3r.pl [ OPTIONS ] file.stl | ||||||
|     --help              Output this usage screen and exit |     --help              Output this usage screen and exit | ||||||
|     --save <file>       Save configuration to the specified file |     --save <file>       Save configuration to the specified file | ||||||
|     --load <file>       Load configuration from the specified file |     --load <file>       Load configuration from the specified file | ||||||
|     -o, --output        File to output gcode to (default: <inputfile>.gcode) |     -o <filename>       File name to output gcode to (default: --output) | ||||||
|      |      | ||||||
|  |   Output options: | ||||||
|  |     --output            Output file name format (default: [input_filename_base].gcode) | ||||||
|  |                         examples: | ||||||
|  |                         [input_filename_base]_h[layer_height]_p[perimeters]_s[solid_layers].gcode | ||||||
|  |                         [input_filename]_center[print_center]_layer[layer_height].gcode | ||||||
|  |    | ||||||
|   Printer options: |   Printer options: | ||||||
|     --nozzle-diameter   Diameter of nozzle in mm (default: $Slic3r::nozzle_diameter) |     --nozzle-diameter   Diameter of nozzle in mm (default: $Slic3r::nozzle_diameter) | ||||||
|     --print-center      Coordinates of the point to center the print around  |     --print-center      Coordinates of the point to center the print around  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Clarence Risher
						Clarence Risher