Merge branch 'new-gui'

Conflicts:
	lib/Slic3r.pm
	lib/Slic3r/Config.pm
	lib/Slic3r/GUI/OptionsGroup.pm
	lib/Slic3r/GUI/SkeinPanel.pm
	lib/Slic3r/Print.pm
This commit is contained in:
Alessandro Ranellucci 2012-07-18 15:48:04 +02:00
commit f173096a6c
32 changed files with 1854 additions and 450 deletions

View file

@ -24,6 +24,7 @@ my $build = Module::Build->new(
},
recommends => {
'Growl::GNTP' => '0.15',
'Net::DBus' => '0',
'Wx' => '0.9901',
},
script_files => ['slic3r.pl'],

View file

@ -27,9 +27,11 @@ lib/Slic3r/GCode.pm
lib/Slic3r/Geometry.pm
lib/Slic3r/Geometry/Clipper.pm
lib/Slic3r/GUI.pm
lib/Slic3r/GUI/ConfigWizard.pm
lib/Slic3r/GUI/Plater.pm
lib/Slic3r/GUI/OptionsGroup.pm
lib/Slic3r/GUI/SkeinPanel.pm
lib/Slic3r/GUI/Tab.pm
lib/Slic3r/Layer.pm
lib/Slic3r/Line.pm
lib/Slic3r/Point.pm
@ -60,3 +62,30 @@ utils/stl-to-amf.pl
var/Slic3r.icns
var/Slic3r.ico
var/Slic3r.png
var/Slic3r_128px.png
var/add.png
var/arrow_out.png
var/arrow_rotate_anticlockwise.png
var/arrow_rotate_clockwise.png
var/arrow_up.png
var/box.png
var/brick_add.png
var/brick_delete.png
var/brick_go.png
var/bricks.png
var/building.png
var/cog.png
var/cog_go.png
var/cross.png
var/delete.png
var/funnel.png
var/hourglass.png
var/layers.png
var/note.png
var/page_white_go.png
var/printer_empty.png
var/shading.png
var/shape_ungroup.png
var/spool.png
var/time.png
var/wrench.png

View file

@ -6,8 +6,8 @@ A: Yes.
## What's it?
Slic3r is an STL-to-GCODE translator for RepRap 3D printers, aiming to
be a modern and fast alternative to Skeinforge.
Slic3r is a G-code generator for 3D printers. It's compatible with RepRaps,
Makerbots, Ultimakers and many more machines.
See the [project homepage](http://slic3r.org/) at slic3r.org
for more information.
@ -63,14 +63,21 @@ download and run, with no dependencies required.
## Can I help?
Sure! Send patches and/or drop me a line at aar@cpan.org. You can also
Sure! Drop me a line at aar@cpan.org. You can also
find me in #reprap and in #slic3r on FreeNode with the nickname _Sound_.
Before sending patches and pull requests contact me to discuss your proposed
changes: this way we'll ensure nobody wastes their time and no conflicts arise
in development.
## What's Slic3r license?
Slic3r is licensed under the _GNU Affero General Public License, version 3_.
The author is Alessandro Ranellucci.
The [Silk icon set](http://www.famfamfam.com/lab/icons/silk/) used in Slic3r is
licensed under the _Creative Commons Attribution 3.0 License_.
The author of the Silk icon set is Mark James.
## How can I invoke slic3r.pl using the command line?
Usage: slic3r.pl [ OPTIONS ] file.stl

View file

@ -70,16 +70,16 @@ our $g0 = 0;
our $gcode_comments = 0;
# filament options
our $bed_temperature = 0;
our $first_layer_bed_temperature;
our $filament_diameter = [3]; # mm
our $extrusion_multiplier = [1];
our $temperature = [200];
our $first_layer_temperature= [@$temperature];
our $bed_temperature = 0;
our $first_layer_bed_temperature = $bed_temperature;
# extruders
our $extruders = [];
our $nozzle_diameter = [0.5];
our $filament_diameter = [3]; # mm
our $extrusion_multiplier = [1];
our $temperature = [200];
our $first_layer_temperature= [];
# extruder mapping (1-based indexes)
our $perimeter_extruder = 1;
@ -185,6 +185,9 @@ our $complete_objects = 0;
our $extruder_clearance_radius = 20; # mm
our $extruder_clearance_height = 20; # mm
our $Defaults = Slic3r::Config->current;
our $Settings = { presets => {} }; # application settings
sub parallelize {
my %params = @_;

View file

@ -8,35 +8,50 @@ use constant PI => 4 * atan2(1, 1);
# cemetery of old config settings
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool);
our %Groups = (
print => [qw(layer_height first_layer_height perimeters randomize_start solid_layers fill_density fill_angle fill_pattern solid_fill_pattern infill_every_layers perimeter_speed small_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed bridge_speed travel_speed first_layer_speed skirts skirt_distance skirt_height support_material notes complete_objects extruder_clearance_radius extruder_clearance_height gcode_comments output_filename_format post_process extrusion_width first_layer_extrusion_width infill_extrusion_width bridge_flow_ratio duplicate_distance)],
filament => [qw(filament_diameter extrusion_multiplier temperature first_layer_temperature bed_temperature first_layer_bed_temperature cooling min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers fan_always_on fan_below_layer_time slowdown_below_layer_time min_print_speed)],
printer => [qw(bed_size print_center z_offset gcode_flavor use_relative_e_distances nozzle_diameter retract_length retract_lift retract_speed retract_restart_extra retract_before_travel start_gcode end_gcode layer_gcode)],
);
our $Options = {
# miscellaneous options
'notes' => {
label => 'Configuration notes',
tooltip => 'You can put here your personal notes. This text will be added to the G-code header comments.',
cli => 'notes=s',
type => 's',
multiline => 1,
width => 400,
height => 100,
full_width => 1,
height => 130,
serialize => sub { join '\n', split /\R/, $_[0] },
deserialize => sub { join "\n", split /\\n/, $_[0] },
},
'threads' => {
label => 'Threads (more speed, more memory usage)',
label => 'Threads',
tooltip => 'Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors. Beware that more threads consume more memory.',
sidetext => '(more speed but more memory usage)',
cli => 'threads|j=i',
type => 'i',
min => 1,
max => 16,
},
# output options
'output_filename_format' => {
label => 'Output filename format',
tooltip => 'You can use all configuration options as variables inside this template. For example: [layer_height], [fill_density] etc. You can also use [timestamp], [year], [month], [day], [hour], [minute], [second], [version], [input_filename], [input_filename_base].',
cli => 'output-filename-format=s',
type => 's',
full_width => 1,
},
# printer options
'print_center' => {
label => 'Print center (mm)',
label => 'Print center',
tooltip => 'Enter the G-code coordinates of the point you want to center your print around.',
sidetext => 'mm',
cli => 'print-center=s',
type => 'point',
serialize => sub { join ',', @{$_[0]} },
@ -44,6 +59,7 @@ our $Options = {
},
'gcode_flavor' => {
label => 'G-code flavor',
tooltip => 'Some G/M-code commands, including temperature control and others, are not universal. Set this option to your printer\'s firmware to get a compatible output. The "No extrusion" flavor prevents Slic3r from exporting any extrusion value at all.',
cli => 'gcode-flavor=s',
type => 'select',
values => [qw(reprap teacup makerbot mach3 no-extrusion)],
@ -51,74 +67,88 @@ our $Options = {
},
'use_relative_e_distances' => {
label => 'Use relative E distances',
tooltip => 'If your firmware requires relative E values, check this, otherwise leave it unchecked. Most firmwares use absolute values.',
cli => 'use-relative-e-distances!',
type => 'bool',
},
'extrusion_axis' => {
label => 'Extrusion axis',
tooltip => 'Use this option to set the axis letter associated to your printer\'s extruder (usually E but some printers use A).',
cli => 'extrusion-axis=s',
type => 's',
},
'z_offset' => {
label => 'Z offset (mm)',
label => 'Z offset',
tooltip => 'This value will be added (or subtracted) from all the Z coordinates in the output G-code. It is used to compensate for bad Z endstop position: for example, if your endstop zero actually leaves the nozzle 0.3mm far from the print bed, set this to -0.3 (or fix your endstop).',
sidetext => 'mm',
cli => 'z-offset=f',
type => 'f',
},
'gcode_arcs' => {
label => 'Use native G-code arcs',
tooltip => 'This experimental feature tries to detect arcs from segments and generates G2/G3 arc commands instead of multiple straight G1 commands.',
cli => 'gcode-arcs!',
type => 'bool',
},
'g0' => {
label => 'Use G0 for travel moves',
tooltip => 'Only enable this if your firmware supports G0 properly (thus decouples all axes using their maximum speeds instead of synchronizing them). Travel moves and retractions will be combined in single commands, speeding them print up.',
cli => 'g0!',
type => 'bool',
},
'gcode_comments' => {
label => 'Verbose G-code',
tooltip => 'Enable this to get a commented G-code file, with each line explained by a descriptive text. If you print from SD card, the additional weight of the file could make your firmware slow down.',
cli => 'gcode-comments!',
type => 'bool',
},
# extruders options
'nozzle_diameter' => {
label => 'Nozzle diameter (mm)',
label => 'Nozzle diameter',
tooltip => 'This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)',
cli => 'nozzle-diameter=f@',
type => 'f',
important => 1,
sidetext => 'mm',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
},
'filament_diameter' => {
label => 'Diameter (mm)',
label => 'Diameter',
tooltip => 'Enter your filament diameter here. Good precision is required, so use a caliper and do multiple measurements along the filament, then compute the average.',
sidetext => 'mm',
cli => 'filament-diameter=f@',
type => 'f',
important => 1,
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
},
'extrusion_multiplier' => {
label => 'Extrusion multiplier',
tooltip => 'This factor changes the amount of flow proportionally. You may need to tweak this setting to get nice surface finish and correct single wall widths. Usual values are between 0.9 and 1.1. If you think you need to change this more, check filament diameter and your firmware E steps.',
cli => 'extrusion-multiplier=f@',
type => 'f',
aliases => [qw(filament_packing_density)],
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
},
'temperature' => {
label => 'Temperature (°C)',
label => 'Temperature',
tooltip => 'Extruder temperature for layers after the first one. Set this to zero to disable temperature control commands in the output.',
sidetext => '°C',
cli => 'temperature=i@',
type => 'i',
important => 1,
max => 300,
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
},
'first_layer_temperature' => {
label => 'First layer temperature (°C)',
label => 'First layer temperature',
tooltip => 'Extruder temperature for first layer. If you want to control temperature manually during print, set this to zero to disable temperature control commands in the output file.',
sidetext => '°C',
cli => 'first-layer-temperature=i@',
type => 'i',
serialize => sub { join ',', @{$_[0]} },
deserialize => sub { [ split /,/, $_[0] ] },
max => 300,
},
# extruder mapping
@ -141,68 +171,92 @@ our $Options = {
# filament options
'first_layer_bed_temperature' => {
label => 'First layer bed temperature (°C)',
label => 'First layer bed temperature',
tooltip => 'Heated build plate temperature for the first layer. Set this to zero to disable bed temperature control commands in the output.',
sidetext => '°C',
cli => 'first-layer-bed-temperature=i',
type => 'i',
max => 300,
},
'bed_temperature' => {
label => 'Bed Temperature (°C)',
label => 'Bed Temperature',
tooltip => 'Bed temperature for layers after the first one. Set this to zero to disable bed temperature control commands in the output.',
sidetext => '°C',
cli => 'bed-temperature=i',
type => 'i',
max => 300,
},
# speed options
'travel_speed' => {
label => 'Travel (mm/s)',
label => 'Travel',
tooltip => 'Speed for travel moves (jumps between distant extrusion points).',
sidetext => 'mm/s',
cli => 'travel-speed=f',
type => 'f',
aliases => [qw(travel_feed_rate)],
},
'perimeter_speed' => {
label => 'Perimeters (mm/s)',
label => 'Perimeters',
tooltip => 'Speed for perimeters (contours, aka vertical shells).',
sidetext => 'mm/s',
cli => 'perimeter-speed=f',
type => 'f',
aliases => [qw(perimeter_feed_rate)],
},
'small_perimeter_speed' => {
label => 'Small perimeters (mm/s or %)',
label => 'Small perimeters',
tooltip => 'This separate setting will affect the speed of perimeters having radius <= 6.5mm (usually holes). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above.',
sidetext => 'mm/s or %',
cli => 'small-perimeter-speed=s',
type => 'f',
ratio_over => 'perimeter_speed',
},
'external_perimeter_speed' => {
label => 'External perimeters (mm/s or %)',
label => 'External perimeters',
tooltip => 'This separate setting will affect the speed of external perimeters (the visible ones). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above.',
sidetext => 'mm/s or %',
cli => 'external-perimeter-speed=s',
type => 'f',
ratio_over => 'perimeter_speed',
},
'infill_speed' => {
label => 'Infill (mm/s)',
label => 'Infill',
tooltip => 'Speed for printing the internal fill.',
sidetext => 'mm/s',
cli => 'infill-speed=f',
type => 'f',
aliases => [qw(print_feed_rate infill_feed_rate)],
},
'solid_infill_speed' => {
label => 'Solid infill (mm/s or %)',
label => 'Solid infill',
tooltip => 'Speed for printing solid regions (top/bottom/internal horizontal shells). This can be expressed as a percentage (for example: 80%) over the default infill speed above.',
sidetext => 'mm/s or %',
cli => 'solid-infill-speed=s',
type => 'f',
ratio_over => 'infill_speed',
aliases => [qw(solid_infill_feed_rate)],
},
'top_solid_infill_speed' => {
label => 'Top solid infill (mm/s or %)',
label => 'Top solid infill',
tooltip => 'Speed for printing top solid regions. You may want to slow down this to get a nicer surface finish. This can be expressed as a percentage (for example: 80%) over the solid infill speed above.',
sidetext => 'mm/s or %',
cli => 'top-solid-infill-speed=s',
type => 'f',
ratio_over => 'solid_infill_speed',
},
'bridge_speed' => {
label => 'Bridges (mm/s)',
label => 'Bridges',
tooltip => 'Speed for printing bridges.',
sidetext => 'mm/s',
cli => 'bridge-speed=f',
type => 'f',
aliases => [qw(bridge_feed_rate)],
},
'first_layer_speed' => {
label => 'First layer speed (mm/s or %)',
label => 'First layer speed',
tooltip => 'If expressed as absolute value in mm/s, this speed will be applied to all the print moves of the first layer, regardless of their type. If expressed as a percentage (for example: 40%) it will scale the default speeds.',
sidetext => 'mm/s or %',
cli => 'first-layer-speed=s',
type => 'f',
},
@ -214,53 +268,70 @@ our $Options = {
type => 'bool',
},
'perimeter_acceleration' => {
label => 'Perimeters (mm/s²)',
label => 'Perimeters',
sidetext => 'mm/s²',
cli => 'perimeter-acceleration',
type => 'f',
},
'infill_acceleration' => {
label => 'Infill (mm/s²)',
label => 'Infill',
sidetext => 'mm/s²',
cli => 'infill-acceleration',
type => 'f',
},
# accuracy options
'layer_height' => {
label => 'Layer height (mm)',
label => 'Layer height',
tooltip => 'This setting controls the height (and thus the total number) of the slices/layers. Thinner layers give better accuracy but take more time to print.',
sidetext => 'mm',
cli => 'layer-height=f',
type => 'f',
},
'first_layer_height' => {
label => 'First layer height (mm or %)',
label => 'First layer height',
tooltip => 'When printing with very low layer heights, you might still want to print a thicker bottom layer to improve adhesion and tolerance for non perfect build plates. This can be expressed as an absolute value or as a percentage (for example: 150%) over the default layer height.',
sidetext => 'mm or %',
cli => 'first-layer-height=s',
type => 'f',
ratio_over => 'layer_height',
},
'infill_every_layers' => {
label => 'Infill every N layers',
label => 'Infill every',
tooltip => 'This feature allows to combine infill and speed up your print by extruding thicker infill layers while preserving thin perimeters, thus accuracy.',
sidetext => 'layers',
cli => 'infill-every-layers=i',
type => 'i',
min => 1,
},
# flow options
'extrusion_width' => {
label => 'Extrusion width (mm or %; leave zero to calculate automatically)',
label => 'Default extrusion width',
tooltip => 'Set this to a non-zero value to set a manual extrusion width. If left to zero, Slic3r calculates a width automatically. If expressed as percentage (for example: 230%) it will be computed over layer height.',
sidetext => 'mm or % (leave 0 for auto)',
cli => 'extrusion-width=s',
type => 'f',
},
'first_layer_extrusion_width' => {
label => 'First layer extrusion width (mm or % or 0 for default)',
label => 'First layer',
tooltip => 'Set this to a non-zero value to set a manual extrusion width for first layer. You can use this to force fatter extrudates for better adhesion. If expressed as percentage (for example 120%) if will be computed over the default extrusion width (which could be calculated automatically or set manually using the option above).',
sidetext => 'mm or % (leave 0 for default)',
cli => 'first-layer-extrusion-width=s',
type => 'f',
},
'perimeter_extrusion_width' => {
label => 'Perimeter extrusion width (mm or % or 0 for default)',
label => 'Perimeters',
tooltip => 'Set this to a non-zero value to set a manual extrusion width for perimeters. You may want to use thinner extrudates to get more accurate surfaces. If expressed as percentage (for example 90%) if will be computed over the default extrusion width (which could be calculated automatically or set manually using the option above).',
sidetext => 'mm or % (leave 0 for default)',
cli => 'perimeter-extrusion-width=s',
type => 'f',
aliases => [qw(perimeters_extrusion_width)],
},
'infill_extrusion_width' => {
label => 'Infill extrusion width (mm or % or 0 for default)',
label => 'Infill',
tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill. You may want to use fatter extrudates to speed up the infill and make your parts stronger. If expressed as percentage (for example 90%) if will be computed over the default extrusion width (which could be calculated automatically or set manually using the option above).',
sidetext => 'mm or % (leave 0 for default)',
cli => 'infill-extrusion-width=s',
type => 'f',
},
@ -271,31 +342,36 @@ our $Options = {
},
'bridge_flow_ratio' => {
label => 'Bridge flow ratio',
tooltip => 'This factor affects the amount of plastic for bridging. You can decrease it slightly to pull the extrudates and prevent sagging, although default settings are usually good and you should experiment with cooling (use a fan) before tweaking this.',
cli => 'bridge-flow-ratio=f',
type => 'f',
},
# print options
'perimeters' => {
label => 'Perimeters',
label => 'Perimeters (minimum)',
tooltip => 'This option sets the number of perimeters to generate for each layer. Note that Slic3r will increase this number automatically when it detects sloping surfaces which benefit from a higher number of perimeters.',
cli => 'perimeters=i',
type => 'i',
aliases => [qw(perimeter_offsets)],
},
'solid_layers' => {
label => 'Solid layers',
tooltip => 'Number of solid layers to generate on top and bottom.',
cli => 'solid-layers=i',
type => 'i',
},
'fill_pattern' => {
label => 'Fill pattern',
tooltip => 'Fill pattern for general low-density infill.',
cli => 'fill-pattern=s',
type => 'select',
values => [qw(rectilinear line concentric honeycomb hilbertcurve archimedeanchords octagramspiral)],
labels => [qw(rectilinear line concentric honeycomb), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
},
'solid_fill_pattern' => {
label => 'Solid fill pattern',
label => 'Top/bottom fill pattern',
tooltip => 'Fill pattern for top/bottom infill.',
cli => 'solid-fill-pattern=s',
type => 'select',
values => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)],
@ -303,13 +379,17 @@ our $Options = {
},
'fill_density' => {
label => 'Fill density',
tooltip => 'Density of internal infill, expressed in the range 0 - 1.',
cli => 'fill-density=f',
type => 'f',
},
'fill_angle' => {
label => 'Fill angle (°)',
label => 'Fill angle',
tooltip => 'Default base angle for infill orientation. Cross-hatching will be applied to this. Bridges will be infilled using the best direction Slic3r can detect, so this setting does not affect them.',
sidetext => '°',
cli => 'fill-angle=i',
type => 'i',
max => 359,
},
'extra_perimeters' => {
label => 'Generate extra perimeters when needed',
@ -318,72 +398,85 @@ our $Options = {
},
'randomize_start' => {
label => 'Randomize starting points',
tooltip => 'Start each layer from a different vertex to prevent plastic build-up on the same corner.',
cli => 'randomize-start!',
type => 'bool',
},
'support_material' => {
label => 'Generate support material',
tooltip => 'Enable support material generation.',
cli => 'support-material!',
type => 'bool',
},
'support_material_threshold' => {
label => 'Overhang threshold (°)',
label => 'Overhang threshold',
tooltip => 'Support material will not generated for overhangs whose slope angle is above the given threshold.',
sidetext => '°',
cli => 'support-material-threshold=i',
type => 'i',
},
'support_material_pattern' => {
label => 'Pattern',
tooltip => 'Pattern used to generate support material.',
cli => 'support-material-pattern=s',
type => 'select',
values => [qw(rectilinear honeycomb)],
labels => [qw(rectilinear honeycomb)],
},
'support_material_spacing' => {
label => 'Pattern spacing (mm)',
label => 'Pattern spacing',
tooltip => 'Spacing between support material lines.',
sidetext => 'mm',
cli => 'support-material-spacing=f',
type => 'f',
},
'support_material_angle' => {
label => 'Pattern angle (°)',
label => 'Pattern angle',
tooltip => 'Use this setting to rotate the support material pattern on the horizontal plane.',
sidetext => '°',
cli => 'support-material-angle=i',
type => 'i',
},
'start_gcode' => {
label => 'Start G-code',
tooltip => 'This start procedure is inserted at the beginning of the output file, right after the temperature control commands for extruder and bed. If Slic3r detects M104 or M190 in your custom codes, such commands will not be prepended automatically. Note that you can use placeholder variables for all Slic3r settings, so you can put a "M104 S[first_layer_temperature]" command wherever you want.',
cli => 'start-gcode=s',
type => 's',
multiline => 1,
width => 350,
full_width => 1,
height => 120,
serialize => sub { join '\n', split /\R+/, $_[0] },
deserialize => sub { join "\n", split /\\n/, $_[0] },
},
'end_gcode' => {
label => 'End G-code',
tooltip => 'This end procedure is inserted at the end of the output file. Note that you can use placeholder variables for all Slic3r settings.',
cli => 'end-gcode=s',
type => 's',
multiline => 1,
width => 350,
full_width => 1,
height => 120,
serialize => sub { join '\n', split /\R+/, $_[0] },
deserialize => sub { join "\n", split /\\n/, $_[0] },
},
'layer_gcode' => {
label => 'Layer change G-code',
tooltip => 'This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings.',
cli => 'layer-gcode=s',
type => 's',
multiline => 1,
width => 350,
full_width => 1,
height => 50,
serialize => sub { join '\n', split /\R+/, $_[0] },
deserialize => sub { join "\n", split /\\n/, $_[0] },
},
'post_process' => {
label => 'Post-processing scripts',
tooltip => 'If you want to process the output G-code through custom scripts, just list their absolute paths here. Separate multiple scripts with a semicolon. Scripts will be passed the absolute path to the G-code file as the first argument, and they can access the Slic3r config settings by reading environment variables.',
cli => 'post-process=s@',
type => 's@',
multiline => 1,
width => 350,
full_width => 1,
height => 60,
serialize => sub { join '; ', @{$_[0]} },
deserialize => sub { [ split /\s*;\s*/, $_[0] ] },
@ -391,27 +484,38 @@ our $Options = {
# retraction options
'retract_length' => {
label => 'Length (mm)',
label => 'Length',
tooltip => 'When retraction is triggered, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).',
sidetext => 'mm (zero to disable)',
cli => 'retract-length=f',
type => 'f',
},
'retract_speed' => {
label => 'Speed (mm/s)',
label => 'Speed',
tooltip => 'The speed for retractions (it only applies to the extruder motor).',
sidetext => 'mm/s',
cli => 'retract-speed=f',
type => 'i',
max => 1000,
},
'retract_restart_extra' => {
label => 'Extra length on restart (mm)',
label => 'Extra length on restart',
tooltip => 'When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed.',
sidetext => 'mm',
cli => 'retract-restart-extra=f',
type => 'f',
},
'retract_before_travel' => {
label => 'Minimum travel after retraction (mm)',
label => 'Minimum travel after retraction',
tooltip => 'Retraction is not triggered when travel moves are shorter than this length.',
sidetext => 'mm',
cli => 'retract-before-travel=f',
type => 'f',
},
'retract_lift' => {
label => 'Lift Z (mm)',
label => 'Lift Z',
tooltip => 'If you set this to a positive value, Z is quickly raised every time a retraction is triggered.',
sidetext => 'mm',
cli => 'retract-lift=f',
type => 'f',
},
@ -419,46 +523,71 @@ our $Options = {
# cooling options
'cooling' => {
label => 'Enable cooling',
tooltip => 'This flag enables all the cooling features.',
cli => 'cooling!',
type => 'bool',
},
'min_fan_speed' => {
label => 'Min fan speed (%)',
label => 'Min fan speed',
tooltip => 'This setting represents the minimum PWM your fan needs to work.',
sidetext => '%',
cli => 'min-fan-speed=i',
type => 'i',
max => 1000,
},
'max_fan_speed' => {
label => 'Max fan speed (%)',
label => 'Max fan speed',
tooltip => 'This setting represents the maximum speed of your fan.',
sidetext => '%',
cli => 'max-fan-speed=i',
type => 'i',
max => 1000,
},
'bridge_fan_speed' => {
label => 'Bridge fan speed (%)',
label => 'Bridge fan speed',
tooltip => 'This fan speed is enforced during all bridges.',
sidetext => '%',
cli => 'bridge-fan-speed=i',
type => 'i',
max => 1000,
},
'fan_below_layer_time' => {
label => 'Enable fan if layer print time is below (approximate seconds)',
label => 'Enable fan if layer print time is below',
tooltip => 'If layer print time is estimated below this number of seconds, fan will be enabled and its speed will be calculated by interpolating the minimum and maximum speeds.',
sidetext => 'approximate seconds',
cli => 'fan-below-layer-time=i',
type => 'i',
max => 1000,
width => 60,
},
'slowdown_below_layer_time' => {
label => 'Slow down if layer print time is below (approximate seconds)',
label => 'Slow down if layer print time is below',
tooltip => 'If layer print time is estimated below this number of seconds, print moves speed will be scaled down to extend duration to this value.',
sidetext => 'approximate seconds',
cli => 'slowdown-below-layer-time=i',
type => 'i',
max => 1000,
width => 60,
},
'min_print_speed' => {
label => 'Min print speed (mm/s)',
label => 'Min print speed',
tooltip => 'Slic3r will not scale speed down below this speed.',
sidetext => 'mm/s',
cli => 'min-print-speed=f',
type => 'i',
max => 1000,
},
'disable_fan_first_layers' => {
label => 'Disable fan for the first N layers',
label => 'Disable fan for the first',
tooltip => 'You can set this to a positive value to disable fan at all during the first layers, so that it does not make adhesion worse.',
sidetext => 'layers',
cli => 'disable-fan-first-layers=i',
type => 'i',
max => 1000,
},
'fan_always_on' => {
label => 'Keep fan always on',
tooltip => 'If this is enabled, fan will never be disabled and will be kept running at least at its minimum speed. Useful for PLA, harmful for ABS.',
cli => 'fan-always-on!',
type => 'bool',
},
@ -466,21 +595,28 @@ our $Options = {
# skirt/brim options
'skirts' => {
label => 'Loops',
tooltip => 'Number of loops for this skirt, in other words its thickness. Set this to zero to disable skirt.',
cli => 'skirts=i',
type => 'i',
},
'skirt_distance' => {
label => 'Distance from object (mm)',
label => 'Distance from object',
tooltip => 'Distance between skirt and object(s). Set this to zero to attach the skirt to the object(s) and get a brim for better adhesion.',
sidetext => 'mm',
cli => 'skirt-distance=f',
type => 'f',
},
'skirt_height' => {
label => 'Skirt height (layers)',
label => 'Skirt height',
tooltip => 'Height of skirt expressed in layers. Set this to a tall value to use skirt as a shield against drafts.',
sidetext => 'layers',
cli => 'skirt-height=i',
type => 'i',
},
'brim_width' => {
label => 'Brim width (mm)',
label => 'Brim width',
tooltip => 'Horizontal width of the brim that will be printed around each object on the first layer.',
sidetext => 'mm',
cli => 'brim-width=f',
type => 'f',
},
@ -492,24 +628,22 @@ our $Options = {
type => 'f',
},
'rotate' => {
label => 'Rotate (°)',
label => 'Rotate',
sidetext => '°',
cli => 'rotate=i',
type => 'i',
},
'duplicate_mode' => {
label => 'Duplicate',
gui_only => 1,
type => 'select',
values => [qw(no autoarrange grid)],
labels => ['No', 'Autoarrange', 'Grid'],
max => 359,
},
'duplicate' => {
label => 'Copies (autoarrange)',
cli => 'duplicate=i',
type => 'i',
min => 1,
},
'bed_size' => {
label => 'Bed size (mm)',
label => 'Bed size',
tooltip => 'Size of your bed. This is used to adjust the preview in the plater and for auto-arranging parts in it.',
sidetext => 'mm',
cli => 'bed-size=s',
type => 'point',
serialize => sub { join ',', @{$_[0]} },
@ -524,26 +658,33 @@ our $Options = {
},
'duplicate_distance' => {
label => 'Distance between copies',
tooltip => 'Distance used for the auto-arrange feature of the plater.',
sidetext => 'mm',
cli => 'duplicate-distance=f',
type => 'i',
type => 'f',
aliases => [qw(multiply_distance)],
},
# sequential printing options
'complete_objects' => {
label => 'Complete individual objects (watch out for extruder collisions)',
label => 'Complete individual objects',
tooltip => 'When printing multiple objects or copies, this feature will complete each object before moving onto next one (and starting it from its bottom layer). This feature is useful to avoid the risk of ruined prints. Slic3r should warn and prevent you from extruder collisions, but beware.',
cli => 'complete-objects!',
type => 'bool',
},
'extruder_clearance_radius' => {
label => 'Extruder clearance radius (mm)',
label => 'Extruder clearance radius',
tooltip => 'Set this to the clearance radius around your extruder. If the extruder is not centered, choose the largest value for safety. This setting is used to check for collisions and to display the graphical preview in the plater.',
sidetext => 'mm',
cli => 'extruder-clearance-radius=f',
type => 'i',
type => 'f',
},
'extruder_clearance_height' => {
label => 'Extruder clearance height (mm)',
label => 'Extruder clearance height',
tooltip => 'Set this to the vertical distance between your nozzle tip and (usually) the X carriage rods. In other words, this is the height of the clearance cylinder around your extruder, and it represents the maximum depth the extruder can peek before colliding with other printed objects.',
sidetext => 'mm',
cli => 'extruder-clearance-height=f',
type => 'i',
type => 'f',
},
};
@ -588,20 +729,42 @@ sub deserialize {
: set($opt_key, $value);
}
sub save {
sub write_ini {
my $class = shift;
my ($file) = @_;
my ($file, $ini) = @_;
open my $fh, '>', $file;
binmode $fh, ':utf8';
printf $fh "# generated by Slic3r $Slic3r::VERSION\n";
foreach my $category (sort keys %$ini) {
printf $fh "\n[%s]\n", $category if $category ne '_';
foreach my $key (sort keys %{$ini->{$category}}) {
printf $fh "%s = %s\n", $key, $ini->{$category}{$key};
}
}
close $fh;
}
sub save {
my $class = shift;
my ($file, $group) = @_;
my $ini = { _ => {} };
foreach my $opt (sort keys %$Options) {
next if defined $group && not ($opt ~~ @{$Groups{$group}});
next if $Options->{$opt}{gui_only};
my $value = get_raw($opt);
$value = $Options->{$opt}{serialize}->($value) if $Options->{$opt}{serialize};
printf $fh "%s = %s\n", $opt, $value;
$ini->{_}{$opt} = $value;
}
close $fh;
$class->write_ini($file, $ini);
}
sub save_settings {
my $class = shift;
my ($file) = @_;
$class->write_ini($file, $Slic3r::Settings);
}
sub setenv {
@ -614,22 +777,46 @@ sub setenv {
}
}
sub load {
sub current {
my $class = shift;
return { map +($_ => get_raw($_)), sort keys %$Options };
}
sub read_ini {
my $class = shift;
my ($file) = @_;
my %ignore = map { $_ => 1 } @Ignore;
local $/ = "\n";
open my $fh, '<', $file;
binmode $fh, ':utf8';
while (<$fh>) {
my $ini = { _ => {} };
my $category = '_';
while (my $_ = <$fh>) {
s/\R+$//;
next if /^\s+/;
next if /^$/;
next if /^\s*#/;
if (/^\[(\w+)\]$/) {
$category = $1;
next;
}
/^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n";
my ($key, $val) = ($1, $2);
$ini->{$category}{$1} = $2;
}
close $fh;
return $ini;
}
sub load_hash {
my $class = shift;
my ($hash, $group, $deserialized) = @_;
my %ignore = map { $_ => 1 } @Ignore;
foreach my $key (sort keys %$hash) {
next if defined $group && not ($key ~~ @{$Groups{$group}});
my $val = $hash->{$key};
# handle legacy options
next if $ignore{$key};
@ -645,9 +832,16 @@ sub load {
}
next unless $key;
my $opt = $Options->{$key};
set($key, $opt->{deserialize} ? $opt->{deserialize}->($val) : $val);
set($key, ($opt->{deserialize} && !$deserialized) ? $opt->{deserialize}->($val) : $val);
}
close $fh;
}
sub load {
my $class = shift;
my ($file) = @_;
my $ini = __PACKAGE__->read_ini($file);
__PACKAGE__->load_hash($ini->{_});
}
sub validate_cli {

View file

@ -4,15 +4,32 @@ use warnings;
use utf8;
use FindBin;
use Slic3r::GUI::AboutDialog;
use Slic3r::GUI::ConfigWizard;
use Slic3r::GUI::Plater;
use Slic3r::GUI::OptionsGroup;
use Slic3r::GUI::SkeinPanel;
use Slic3r::GUI::Tab;
use Wx 0.9901 qw(:sizer :frame wxID_EXIT wxID_ABOUT);
use Wx::Event qw(EVT_MENU);
use Wx 0.9901 qw(:bitmap :dialog :frame :icon :id :misc :systemsettings);
use Wx::Event qw(EVT_CLOSE EVT_MENU);
use base 'Wx::App';
my $growler;
use constant MI_LOAD_CONF => 1;
use constant MI_EXPORT_CONF => 2;
use constant MI_QUICK_SLICE => 3;
use constant MI_REPEAT_QUICK => 4;
use constant MI_QUICK_SAVE_AS => 5;
use constant MI_SLICE_SVG => 6;
use constant MI_CONF_WIZARD => 7;
use constant MI_WEBSITE => 8;
our $datadir;
our $small_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$small_font->SetPointSize(11) if !&Wx::wxMSW;
our $medium_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$medium_font->SetPointSize(12);
sub OnInit {
my $self = shift;
@ -20,85 +37,113 @@ sub OnInit {
$self->SetAppName('Slic3r');
Slic3r::debugf "wxWidgets version %s\n", &Wx::wxVERSION_STRING;
my $frame = Wx::Frame->new( undef, -1, 'Slic3r', [-1, -1], Wx::wxDefaultSize,
wxDEFAULT_FRAME_STYLE ^ (wxRESIZE_BORDER | wxMAXIMIZE_BOX) );
Wx::Image::AddHandler(Wx::PNGHandler->new);
$frame->SetIcon(Wx::Icon->new("$Slic3r::var/Slic3r_128px.png", &Wx::wxBITMAP_TYPE_PNG) );
$self->{notifier} = Slic3r::GUI::Notifier->new;
my $panel = Slic3r::GUI::SkeinPanel->new($frame);
my $box = Wx::BoxSizer->new(wxVERTICAL);
$box->Add($panel, 0);
if (eval "use Growl::GNTP; 1") {
# register growl notifications
eval {
$growler = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => "$Slic3r::var/Slic3r.png");
$growler->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
};
# locate or create data directory
$datadir = Wx::StandardPaths::Get->GetUserDataDir;
Slic3r::debugf "Data directory: %s\n", $datadir;
my $run_wizard = (-d $datadir) ? 0 : 1;
for ($datadir, "$datadir/print", "$datadir/filament", "$datadir/printer") {
mkdir or $self->fatal_error("Slic3r was unable to create its data directory at $_ (errno: $!).")
unless -d $_;
}
# menubar
my $menubar = Wx::MenuBar->new;
# load settings
if (-f "$datadir/slic3r.ini") {
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
$Slic3r::Settings = $ini if $ini;
}
# application frame
Wx::Image::AddHandler(Wx::PNGHandler->new);
my $frame = Wx::Frame->new(undef, -1, 'Slic3r', wxDefaultPosition, [760, 470], wxDEFAULT_FRAME_STYLE);
$frame->SetIcon(Wx::Icon->new("$Slic3r::var/Slic3r_128px.png", wxBITMAP_TYPE_PNG) );
$self->{skeinpanel} = Slic3r::GUI::SkeinPanel->new($frame);
$self->SetTopWindow($frame);
# status bar
$frame->{statusbar} = Slic3r::GUI::ProgressStatusBar->new($frame, -1);
$frame->{statusbar}->SetStatusText("Version $Slic3r::VERSION - Remember to check for updates at http://slic3r.org/");
$frame->SetStatusBar($frame->{statusbar});
# File menu
my $fileMenu = Wx::Menu->new;
$fileMenu->Append(1, "Save Config…");
$fileMenu->Append(2, "Open Config…");
$fileMenu->AppendSeparator();
$fileMenu->Append(3, "Slice…");
$fileMenu->Append(4, "Reslice");
$fileMenu->Append(5, "Slice and Save As…");
$fileMenu->Append(6, "Export SVG…");
$fileMenu->AppendSeparator();
$fileMenu->Append(wxID_EXIT, "&Quit");
$menubar->Append($fileMenu, "&File");
EVT_MENU($frame, 1, sub { $panel->save_config });
EVT_MENU($frame, 2, sub { $panel->load_config });
EVT_MENU($frame, 3, sub { $panel->do_slice });
EVT_MENU($frame, 4, sub { $panel->do_slice(reslice => 1) });
EVT_MENU($frame, 5, sub { $panel->do_slice(save_as => 1) });
EVT_MENU($frame, 6, sub { $panel->do_slice(save_as => 1, export_svg => 1) });
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(1)});
{
$fileMenu->Append(MI_LOAD_CONF, "&Load Config…\tCtrl+L");
$fileMenu->Append(MI_EXPORT_CONF, "&Export Config…\tCtrl+E");
$fileMenu->AppendSeparator();
$fileMenu->Append(MI_QUICK_SLICE, "Q&uick Slice…\tCtrl+U");
$fileMenu->Append(MI_QUICK_SAVE_AS, "Quick Slice and Save &As…\tCtrl+Alt+U");
my $repeat = $fileMenu->Append(MI_REPEAT_QUICK, "&Repeat Last Quick Slice\tCtrl+Shift+U");
$repeat->Enable(0);
$fileMenu->AppendSeparator();
$fileMenu->Append(MI_SLICE_SVG, "Slice to SV&G…\tCtrl+G");
$fileMenu->AppendSeparator();
$fileMenu->Append(wxID_EXIT, "&Quit");
EVT_MENU($frame, MI_LOAD_CONF, sub { $self->{skeinpanel}->load_config });
EVT_MENU($frame, MI_EXPORT_CONF, sub { $self->{skeinpanel}->save_config });
EVT_MENU($frame, MI_QUICK_SLICE, sub { $self->{skeinpanel}->do_slice;
$repeat->Enable(defined $Slic3r::GUI::SkeinPanel::last_input_file) });
EVT_MENU($frame, MI_REPEAT_QUICK, sub { $self->{skeinpanel}->do_slice(reslice => 1) });
EVT_MENU($frame, MI_QUICK_SAVE_AS, sub { $self->{skeinpanel}->do_slice(save_as => 1);
$repeat->Enable(defined $Slic3r::GUI::SkeinPanel::last_input_file) });
EVT_MENU($frame, MI_SLICE_SVG, sub { $self->{skeinpanel}->do_slice(save_as => 1, export_svg => 1) });
EVT_MENU($frame, wxID_EXIT, sub {$_[0]->Close(0)});
}
# Help menu
my $helpMenu = Wx::Menu->new;
$helpMenu->Append(wxID_ABOUT, "&About");
$menubar->Append($helpMenu, "&Help");
EVT_MENU($frame, wxID_ABOUT, \&About);
# Set the menubar after appending items, otherwise special items
# will not be handled correctly
$frame->SetMenuBar($menubar);
{
$helpMenu->Append(MI_CONF_WIZARD, "&Configuration $Slic3r::GUI::ConfigWizard::wizard…");
$helpMenu->Append(MI_WEBSITE, "Slic3r &Website");
$helpMenu->Append(wxID_ABOUT, "&About Slic3r");
EVT_MENU($frame, MI_CONF_WIZARD, sub { $self->{skeinpanel}->config_wizard });
EVT_MENU($frame, MI_WEBSITE, sub { Wx::LaunchDefaultBrowser('http://slic3r.org/') });
EVT_MENU($frame, wxID_ABOUT, \&about);
}
$box->SetSizeHints($frame);
$frame->SetSizer($box);
# menubar
# assign menubar to frame after appending items, otherwise special items
# will not be handled correctly
{
my $menubar = Wx::MenuBar->new;
$menubar->Append($fileMenu, "&File");
$menubar->Append($helpMenu, "&Help");
$frame->SetMenuBar($menubar);
}
EVT_CLOSE($frame, sub {
my (undef, $event) = @_;
if ($event->CanVeto && !$self->{skeinpanel}->check_unsaved_changes) {
$event->Veto;
return;
}
$event->Skip;
});
$frame->Fit;
$frame->SetMinSize($frame->GetSize);
$frame->Show;
$frame->Layout;
$self->{skeinpanel}->config_wizard if $run_wizard;
return 1;
}
sub About {
sub about {
my $frame = shift;
my $info = Wx::AboutDialogInfo->new;
$info->SetName('Slic3r');
$info->AddDeveloper('Alessandro Ranellucci');
$info->SetVersion($Slic3r::VERSION);
$info->SetDescription('STL-to-GCODE translator for RepRap printers');
Wx::AboutBox($info);
my $about = Slic3r::GUI::AboutDialog->new($frame);
$about->ShowModal;
$about->Destroy;
}
sub catch_error {
my ($self, $cb, $message_dialog) = @_;
if (my $err = $@) {
$cb->() if $cb;
my @params = ($err, 'Error', &Wx::wxOK | &Wx::wxICON_ERROR);
my @params = ($err, 'Error', wxOK | wxICON_ERROR);
$message_dialog
? $message_dialog->(@params)
: Wx::MessageDialog->new($self, @params)->ShowModal;
@ -107,11 +152,23 @@ sub catch_error {
return 0;
}
sub show_error {
my $self = shift;
my ($message) = @_;
Wx::MessageDialog->new($self, $message, 'Error', wxOK | wxICON_ERROR)->ShowModal;
}
sub fatal_error {
my $self = shift;
$self->show_error(@_);
exit 1;
}
sub warning_catcher {
my ($self, $message_dialog) = @_;
return sub {
my $message = shift;
my @params = ($message, 'Warning', &Wx::wxOK | &Wx::wxICON_WARNING);
my @params = ($message, 'Warning', wxOK | wxICON_WARNING);
$message_dialog
? $message_dialog->(@params)
: Wx::MessageDialog->new($self, @params)->ShowModal;
@ -119,33 +176,33 @@ sub warning_catcher {
}
sub notify {
my $self = shift;
my ($message) = @_;
eval {
$growler->notify(Event => 'SKEIN_DONE', Title => 'Slicing Done!', Message => $message)
if $growler;
};
my $frame = $self->GetTopWindow;
$frame->RequestUserAttention unless ($frame->IsActive);
$self->{notifier}->notify($message);
}
package Slic3r::GUI::ProgressStatusBar;
use Wx qw(:gauge :misc);
use base 'Wx::StatusBar';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{_changed} = 0;
$self->{busy} = 0;
$self->{timer} = Wx::Timer->new($self);
$self->{prog} = Wx::Gauge->new($self, &Wx::wxGA_HORIZONTAL, 100, [-1,-1], [-1,-1]);
$self->{prog} = Wx::Gauge->new($self, wxGA_HORIZONTAL, 100, wxDefaultPosition, wxDefaultSize);
$self->{prog}->Hide;
$self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", [-1,-1], [-1,8]);
$self->{cancelbutton} = Wx::Button->new($self, -1, "Cancel", wxDefaultPosition, wxDefaultSize);
$self->{cancelbutton}->Hide;
$self->SetFieldsCount(3);
$self->SetStatusWidths(-1, 150, 155);
Wx::Event::EVT_IDLE($self, sub { $self->_Reposition });
Wx::Event::EVT_TIMER($self, \&OnTimer, $self->{timer});
Wx::Event::EVT_SIZE($self, \&OnSize);
Wx::Event::EVT_BUTTON($self, $self->{cancelbutton}, sub {
@ -161,30 +218,23 @@ sub DESTROY {
$self->{timer}->Stop if $self->{timer} && $self->{timer}->IsRunning;
}
sub _Reposition {
my $self = shift;
##if ($self->{_changed}) {
{
my $rect = $self->GetFieldRect($self->GetFieldsCount - 1);
my $prog_pos = [$rect->GetX + 2, $rect->GetY + 2];
$self->{prog}->Move($prog_pos);
$self->{prog}->SetSize($rect->GetWidth - 8, $rect->GetHeight - 4);
}
{
my $rect = $self->GetFieldRect($self->GetFieldsCount - 2);
my $pos = [$rect->GetX + 2, $rect->GetY + 2];
$self->{cancelbutton}->Move($pos);
$self->{cancelbutton}->SetSize($rect->GetWidth - 8, $rect->GetHeight - 4);
}
$self->{_changed} = 0;
}
sub OnSize {
my ($self, $event) = @_;
$self->{_changed} = 1;
$self->_Reposition;
my %fields = (
# 0 is reserved for status text
1 => $self->{cancelbutton},
2 => $self->{prog},
);
foreach (keys %fields) {
my $rect = $self->GetFieldRect($_);
my $offset = &Wx::wxGTK ? 1 : 0; # add a cosmetic 1 pixel offset on wxGTK
my $pos = [$rect->GetX + $offset, $rect->GetY + $offset];
$fields{$_}->Move($pos);
$fields{$_}->SetSize($rect->GetWidth - $offset, $rect->GetHeight);
}
$event->Skip;
}
@ -244,7 +294,6 @@ sub ShowProgress {
my $self = shift;
my ($show) = @_;
$self->_Reposition;
$self->{prog}->Show($show);
$self->{prog}->Pulse;
}
@ -254,7 +303,6 @@ sub StartBusy {
my $rate = shift || 100;
$self->{_busy} = 1;
$self->_Reposition;
$self->ShowProgress(1);
if (!$self->{timer}->IsRunning) {
$self->{timer}->Start($rate);
@ -275,4 +323,44 @@ sub IsBusy {
return $self->{_busy};
}
package Slic3r::GUI::Notifier;
sub new {
my $class = shift;
my $self;
$self->{icon} = "$Slic3r::var/Slic3r.png";
if (eval 'use Growl::GNTP; 1') {
# register with growl
eval {
$self->{growler} = Growl::GNTP->new(AppName => 'Slic3r', AppIcon => $self->{icon});
$self->{growler}->register([{Name => 'SKEIN_DONE', DisplayName => 'Slicing Done'}]);
};
}
bless $self, $class;
return $self;
}
sub notify {
my ($self, $message) = @_;
my $title = 'Slicing Done!';
eval {
$self->{growler}->notify(Event => 'SKEIN_DONE', Title => $title, Message => $message)
if $self->{growler};
};
if (eval 'use Net::DBus; 1') {
eval {
my $session = Net::DBus->session;
my $serv = $session->get_service('org.freedesktop.Notifications');
my $notifier = $serv->get_object('/org/freedesktop/Notifications',
'org.freedesktop.Notifications');
$notifier->Notify('Slic3r', 0, $self->{icon}, $title, $message, [], {}, -1);
}
};
}
1;

View file

@ -0,0 +1,109 @@
package Slic3r::GUI::AboutDialog;
use strict;
use warnings;
use utf8;
use Wx qw(:font :html :misc :sizer :systemsettings);
use Wx::Event qw(EVT_HTML_LINK_CLICKED);
use Wx::Print;
use Wx::Html;
use base 'Wx::Dialog';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, 'About Slic3r', wxDefaultPosition, [600, 270]);
$self->SetBackgroundColour(Wx::wxWHITE);
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
$self->SetSizer($hsizer);
# logo
my $logo = Slic3r::GUI::AboutDialog::Logo->new($self, -1, wxDefaultPosition, wxDefaultSize);
$logo->SetBackgroundColour(Wx::wxWHITE);
$hsizer->Add($logo, 0, wxEXPAND | wxLEFT | wxRIGHT, 30);
my $vsizer = Wx::BoxSizer->new(wxVERTICAL);
$hsizer->Add($vsizer, 1, wxEXPAND, 0);
# title
my $title = Wx::StaticText->new($self, -1, 'Slic3r', wxDefaultPosition, wxDefaultSize);
my $title_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$title_font->SetWeight(wxFONTWEIGHT_BOLD);
$title_font->SetFamily(wxFONTFAMILY_ROMAN);
$title_font->SetPointSize(24);
$title->SetFont($title_font);
$vsizer->Add($title, 0, wxALIGN_LEFT | wxTOP, 30);
# version
my $version = Wx::StaticText->new($self, -1, "Version $Slic3r::VERSION", wxDefaultPosition, wxDefaultSize);
my $version_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$version_font->SetPointSize(&Wx::wxMSW ? 9 : 11);
$version->SetFont($version_font);
$vsizer->Add($version, 0, wxALIGN_LEFT | wxBOTTOM, 10);
# text
my $text =
'<html>' .
'<body bgcolor="#ffffff" link="#808080">' .
'<font color="#808080">' .
'Copyright &copy; 2011-2012 Alessandro Ranellucci. All rights reserved. ' .
'<a href="http://slic3r.org/">Slic3r</a> is licensed under the ' .
'<a href="http://www.gnu.org/licenses/agpl-3.0.html">GNU Affero General Public License, version 3</a>.' .
'<br /><br /><br />' .
'Slic3r logo designed by Corey Daniels, <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon Set</a> designed by Mark James. ' .
'Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess and numerous others.' .
'</font>' .
'</body>' .
'</html>';
my $html = Wx::HtmlWindow->new($self, -1, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_NEVER);
my $font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
my $size = &Wx::wxMSW ? 8 : 10;
$html->SetFonts($font->GetFaceName, $font->GetFaceName, [$size, $size, $size, $size, $size, $size, $size]);
$html->SetBorders(2);
$html->SetPage($text);
$vsizer->Add($html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 20);
EVT_HTML_LINK_CLICKED($self, $html, \&link_clicked);
return $self;
}
sub link_clicked {
my ($self, $event) = @_;
Wx::LaunchDefaultBrowser($event->GetLinkInfo->GetHref);
$event->Skip(0);
}
package Slic3r::GUI::AboutDialog::Logo;
use Wx qw(:bitmap :dc);
use Wx::Event qw(EVT_PAINT);
use base 'Wx::Panel';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{logo} = Wx::Bitmap->new("$Slic3r::var/Slic3r_192px.png", wxBITMAP_TYPE_PNG);
$self->SetMinSize(Wx::Size->new($self->{logo}->GetWidth, $self->{logo}->GetHeight));
EVT_PAINT($self, \&repaint);
return $self;
}
sub repaint {
my ($self, $event) = @_;
my $dc = Wx::PaintDC->new($self);
$dc->SetBackgroundMode(wxTRANSPARENT);
my $size = $self->GetSize;
my $logo_w = $self->{logo}->GetWidth;
my $logo_h = $self->{logo}->GetHeight;
$dc->DrawBitmap($self->{logo}, ($size->GetWidth - $logo_w) / 2, ($size->GetHeight - $logo_h) / 2, 1);
$event->Skip;
}
1;

View file

@ -0,0 +1,469 @@
package Slic3r::GUI::ConfigWizard;
use strict;
use warnings;
use utf8;
use Wx;
use base 'Wx::Wizard';
# adhere to various human interface guidelines
our $wizard = 'Wizard';
$wizard = 'Assistant' if &Wx::wxMAC || &Wx::wxGTK;
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, "Configuration $wizard");
# Start from sane defaults
$self->{old} = Slic3r::Config->current;
Slic3r::Config->load_hash($Slic3r::Defaults, undef, 1);
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Welcome->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Firmware->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Bed->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Nozzle->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Filament->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Temperature->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::BedTemperature->new($self));
$self->add_page(Slic3r::GUI::ConfigWizard::Page::Finished->new($self));
$_->build_index for @{$self->{pages}};
return $self;
}
sub add_page {
my $self = shift;
my ($page) = @_;
my $n = push @{$self->{pages}}, $page;
# add first page to the page area sizer
$self->GetPageAreaSizer->Add($page) if $n == 1;
# link pages
$self->{pages}[$n-2]->set_next_page($page) if $n >= 2;
$page->set_previous_page($self->{pages}[$n-2]) if $n >= 2;
}
sub run {
my $self = shift;
my $modified;
if (Wx::Wizard::RunWizard($self, $self->{pages}[0])) {
$_->apply for @{$self->{pages}};
$modified = 1;
} else {
Slic3r::Config->load_hash($self->{old}, undef, 1);
$modified = 0;
}
$self->Destroy;
return $modified;
}
package Slic3r::GUI::ConfigWizard::Option;
use Wx qw(:combobox :misc :sizer :textctrl);
use Wx::Event qw(EVT_CHECKBOX EVT_COMBOBOX EVT_SPINCTRL EVT_TEXT);
use base 'Wx::StaticBoxSizer';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $box = Wx::StaticBox->new($parent, -1, '');
my $self = $class->SUPER::new($box, wxHORIZONTAL);
my $label_width = 200;
my $opt_key = $params{option};
my $opt = $Slic3r::Config::Options->{$opt_key};
my $callback = $params{callback} || sub {};
# label
my $label = Wx::StaticText->new($parent, -1, "$opt->{label}:", wxDefaultPosition, wxDefaultSize);
$label->Wrap($label_width);
$self->Add($label, 1, wxEXPAND);
# input field(s) and unit
my $field;
if ($opt->{type} =~ /^(i|f|s|s@)$/) {
my $style = $opt->{multiline} ? wxTE_MULTILINE : 0;
my $size = Wx::Size->new($opt->{width} || -1, $opt->{height} || -1);
my ($get, $set) = $opt->{type} eq 's@' ? qw(serialize deserialize) : qw(get_raw set);
if ($opt->{type} eq 'i') {
my $value = Slic3r::Config->$get($opt_key);
$field = Wx::SpinCtrl->new($parent, -1, $value, wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 100, $value);
EVT_SPINCTRL($parent, $field, sub { $callback->($opt_key, $field->GetValue) });
} else {
$field = Wx::TextCtrl->new($parent, -1, Slic3r::Config->$get($opt_key), wxDefaultPosition, $size, $style);
EVT_TEXT($parent, $field, sub { $callback->($opt_key, $field->GetValue) });
}
} elsif ($opt->{type} eq 'bool') {
$field = Wx::CheckBox->new($parent, -1, '');
$field->SetValue(Slic3r::Config->get_raw($opt_key));
EVT_CHECKBOX($parent, $field, sub { $callback->($opt_key, $field->GetValue) });
} elsif ($opt->{type} eq 'point') {
$field = Wx::BoxSizer->new(wxHORIZONTAL);
my $field_size = Wx::Size->new(40, -1);
my $value = Slic3r::Config->get_raw($opt_key);
my @items = (
Wx::StaticText->new($parent, -1, 'x:'),
my $x_field = Wx::TextCtrl->new($parent, -1, $value->[0], wxDefaultPosition, $field_size),
Wx::StaticText->new($parent, -1, ' y:'),
my $y_field = Wx::TextCtrl->new($parent, -1, $value->[1], wxDefaultPosition, $field_size),
);
$field->Add($_) for @items;
EVT_TEXT($parent, $x_field, sub { $callback->($opt_key, [$x_field->GetValue, $y_field->GetValue]) });
EVT_TEXT($parent, $y_field, sub { $callback->($opt_key, [$x_field->GetValue, $y_field->GetValue]) });
} elsif ($opt->{type} eq 'select') {
$field = Wx::ComboBox->new($parent, -1, '', wxDefaultPosition, wxDefaultSize, $opt->{labels} || $opt->{values}, wxCB_READONLY);
my $value = Slic3r::Config->get_raw($opt_key);
$field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}});
EVT_COMBOBOX($parent, $field, sub { $callback->($opt_key, $opt->{values}[$field->GetSelection]) });
} else {
die 'Unsupported option type: ' . $opt->{type};
}
if ($opt->{sidetext}) {
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($field);
my $sidetext = Wx::StaticText->new($parent, -1, $opt->{sidetext}, wxDefaultPosition, wxDefaultSize);
$sizer->Add($sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
$self->Add($sizer);
} else {
$self->Add($field, 0, $opt->{full_width} ? wxEXPAND : 0);
}
return $self;
}
package Slic3r::GUI::ConfigWizard::Index;
use Wx qw(:bitmap :dc :font :misc :sizer :systemsettings :window);
use Wx::Event qw(EVT_ERASE_BACKGROUND EVT_PAINT);
use base 'Wx::Panel';
sub new {
my $class = shift;
my ($parent, $title) = @_;
my $self = $class->SUPER::new($parent);
push @{$self->{titles}}, $title;
$self->{own_index} = 0;
$self->{bullets}->{before} = Wx::Bitmap->new("$Slic3r::var/bullet_black.png", wxBITMAP_TYPE_PNG);
$self->{bullets}->{own} = Wx::Bitmap->new("$Slic3r::var/bullet_blue.png", wxBITMAP_TYPE_PNG);
$self->{bullets}->{after} = Wx::Bitmap->new("$Slic3r::var/bullet_white.png", wxBITMAP_TYPE_PNG);
$self->{background} = Wx::Bitmap->new("$Slic3r::var/Slic3r_192px_transparent.png", wxBITMAP_TYPE_PNG);
$self->SetMinSize(Wx::Size->new($self->{background}->GetWidth, $self->{background}->GetHeight));
EVT_PAINT($self, \&repaint);
return $self;
}
sub repaint {
my ($self, $event) = @_;
my $size = $self->GetClientSize;
my $gab = 5;
my $dc = Wx::PaintDC->new($self);
$dc->SetBackgroundMode(wxTRANSPARENT);
$dc->SetFont($self->GetFont);
$dc->SetTextForeground($self->GetForegroundColour);
my $background_h = $self->{background}->GetHeight;
my $background_w = $self->{background}->GetWidth;
$dc->DrawBitmap($self->{background}, ($size->GetWidth - $background_w) / 2, ($size->GetHeight - $background_h) / 2, 1);
my $label_h = $self->{bullets}->{own}->GetHeight;
$label_h = $dc->GetCharHeight if $dc->GetCharHeight > $label_h;
my $label_w = $size->GetWidth;
my $i = 0;
foreach (@{$self->{titles}}) {
my $bullet = $self->{bullets}->{own};
$bullet = $self->{bullets}->{before} if $i < $self->{own_index};
$bullet = $self->{bullets}->{after} if $i > $self->{own_index};
$dc->SetTextForeground(Wx::Colour->new(128, 128, 128)) if $i > $self->{own_index};
$dc->DrawLabel($_, $bullet, Wx::Rect->new(0, $i * ($label_h + $gab), $label_w, $label_h));
$i++;
}
$event->Skip;
}
sub prepend_title {
my $self = shift;
my ($title) = @_;
unshift @{$self->{titles}}, $title;
$self->{own_index}++;
$self->Refresh;
}
sub append_title {
my $self = shift;
my ($title) = @_;
push @{$self->{titles}}, $title;
$self->Refresh;
}
package Slic3r::GUI::ConfigWizard::Page;
use Wx qw(:font :misc :sizer :staticline :systemsettings);
use base 'Wx::WizardPage';
sub new {
my $class = shift;
my ($parent, $title, $short_title) = @_;
my $self = $class->SUPER::new($parent);
my $sizer = Wx::FlexGridSizer->new(0, 2, 10, 10);
$sizer->AddGrowableCol(1, 1);
$sizer->AddGrowableRow(1, 1);
$sizer->AddStretchSpacer(0);
$self->SetSizer($sizer);
# title
my $text = Wx::StaticText->new($self, -1, $title, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
my $bold_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$bold_font->SetWeight(wxFONTWEIGHT_BOLD);
$bold_font->SetPointSize(14);
$text->SetFont($bold_font);
$sizer->Add($text, 0, wxALIGN_LEFT, 0);
# index
$self->{short_title} = $short_title ? $short_title : $title;
$self->{index} = Slic3r::GUI::ConfigWizard::Index->new($self, $self->{short_title});
$sizer->Add($self->{index}, 1, wxEXPAND | wxTOP | wxRIGHT, 10);
# contents
$self->{width} = 400;
$self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($self->{vsizer}, 1, wxEXPAND, 0);
return $self;
}
sub append_text {
my $self = shift;
my ($text) = @_;
my $para = Wx::StaticText->new($self, -1, $text, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
$para->Wrap($self->{width});
$para->SetMinSize([$self->{width}, -1]);
$self->{vsizer}->Add($para, 0, wxALIGN_LEFT | wxTOP | wxBOTTOM, 10);
}
sub append_option {
my $self = shift;
my ($opt_key) = @_;
my $option = Slic3r::GUI::ConfigWizard::Option->new($self, option => $opt_key,
callback => sub {
my ($opt_key, $value) = @_;
$self->{options}->{$opt_key} = $value;
});
$self->{vsizer}->Add($option, 0, wxEXPAND | wxTOP | wxBOTTOM, 10);
}
sub apply {
my $self = shift;
Slic3r::Config->set($_, $self->{options}->{$_}) foreach (keys %{$self->{options}});
}
sub set_previous_page {
my $self = shift;
my ($previous_page) = @_;
$self->{previous_page} = $previous_page;
}
sub GetPrev {
my $self = shift;
return $self->{previous_page};
}
sub set_next_page {
my $self = shift;
my ($next_page) = @_;
$self->{next_page} = $next_page;
}
sub GetNext {
my $self = shift;
return $self->{next_page};
}
sub get_short_title {
my $self = shift;
return $self->{short_title};
}
sub build_index {
my $self = shift;
my $page = $self;
$self->{index}->prepend_title($page->get_short_title) while ($page = $page->GetPrev);
$page = $self;
$self->{index}->append_title($page->get_short_title) while ($page = $page->GetNext);
}
package Slic3r::GUI::ConfigWizard::Page::Welcome;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, "Welcome to the Slic3r Configuration $wizard", 'Welcome');
$self->append_text('Hello, welcome to Slic3r! This '.lc($wizard).' helps you with the initial configuration; just a few settings and you will be ready to print.');
$self->append_text('To import an existing configuration instead, cancel this '.lc($wizard).' and use the Open Config menu item found in the File menu.');
$self->append_text('To continue, click Next.');
return $self;
}
package Slic3r::GUI::ConfigWizard::Page::Firmware;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Firmware Type');
$self->append_text('Choose the type of firmware used by your printer, then click Next.');
$self->append_option('gcode_flavor');
return $self;
}
package Slic3r::GUI::ConfigWizard::Page::Bed;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Bed Size');
$self->append_text('Enter the size of your printers bed, then click Next.');
$self->append_option('bed_size');
return $self;
}
sub apply {
my $self = shift;
$self->SUPER::apply;
# set print_center to centre of bed_size
my $bed_size = Slic3r::Config->get_raw('bed_size');
Slic3r::Config->set('print_center', [$bed_size->[0]/2, $bed_size->[1]/2]);
}
package Slic3r::GUI::ConfigWizard::Page::Nozzle;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Nozzle Diameter');
$self->append_text('Enter the diameter of your printers hot end nozzle, then click Next.');
$self->append_option('nozzle_diameter');
return $self;
}
sub apply {
my $self = shift;
$self->SUPER::apply;
# set first_layer_height + layer_height based on nozzle_diameter
my $nozzle = Slic3r::Config->get_raw('nozzle_diameter');
Slic3r::Config->set('first_layer_height', $nozzle);
Slic3r::Config->set('layer_height', $nozzle - 0.1);
}
package Slic3r::GUI::ConfigWizard::Page::Filament;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Filament Diameter');
$self->append_text('Enter the diameter of your filament, then click Next.');
$self->append_text('Good precision is required, so use a caliper and do multiple measurements along the filament, then compute the average.');
$self->append_option('filament_diameter');
return $self;
}
package Slic3r::GUI::ConfigWizard::Page::Temperature;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Extrusion Temperature');
$self->append_text('Enter the temperature needed for extruding your filament, then click Next.');
$self->append_text('A rule of thumb is 160 to 230 °C for PLA, and 215 to 250 °C for ABS.');
$self->append_option('temperature');
return $self;
}
sub apply {
my $self = shift;
$self->SUPER::apply;
# set first_layer_temperature to temperature + 5
my $temperature = Slic3r::Config->get_raw('temperature');
Slic3r::Config->set('first_layer_temperature', $temperature + 5);
}
package Slic3r::GUI::ConfigWizard::Page::BedTemperature;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Bed Temperature');
$self->append_text('Enter the bed temperature needed for getting your filament to stick to your heated bed, then click Next.');
$self->append_text('A rule of thumb is 60 °C for PLA and 110 °C for ABS.');
$self->append_option('bed_temperature');
return $self;
}
sub apply {
my $self = shift;
$self->SUPER::apply;
# set first_layer_bed_temperature to temperature + 5
my $temperature = Slic3r::Config->get_raw('bed_temperature');
Slic3r::Config->set('first_layer_bed_temperature', $temperature + 5);
}
package Slic3r::GUI::ConfigWizard::Page::Finished;
use base 'Slic3r::GUI::ConfigWizard::Page';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, 'Congratulations!', 'Finish');
$self->append_text("You have successfully completed the Slic3r Configuration $wizard. " .
'Slic3r is now configured for your printer and filament.');
$self->append_text('To close this '.lc($wizard).' and apply the newly created configuration, click Finish.');
return $self;
}
1;

View file

@ -2,14 +2,14 @@ package Slic3r::GUI::OptionsGroup;
use strict;
use warnings;
use Wx qw(:sizer wxSYS_DEFAULT_GUI_FONT);
use Wx::Event qw(EVT_TEXT EVT_CHECKBOX EVT_CHOICE);
use Wx qw(:combobox :font :misc :sizer :systemsettings :textctrl);
use Wx::Event qw(EVT_CHECKBOX EVT_COMBOBOX EVT_SPINCTRL EVT_TEXT);
use base 'Wx::StaticBoxSizer';
# not very elegant, but this solution is temporary waiting for a better GUI
our @reload_callbacks = ();
our %fields = (); # $key => [$control]
our %reload_callbacks = (); # key => $cb
our %fields = (); # $key => [$control]
sub new {
my $class = shift;
@ -18,34 +18,31 @@ sub new {
my $box = Wx::StaticBox->new($parent, -1, $p{title});
my $self = $class->SUPER::new($box, wxVERTICAL);
my $grid_sizer = Wx::FlexGridSizer->new(scalar(@{$p{options}}), 2, 2, 0);
#grab the default font, to fix Windows font issues/keep things consistent
my $bold_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
$bold_font->SetWeight(&Wx::wxFONTWEIGHT_BOLD);
my $grid_sizer = Wx::FlexGridSizer->new(scalar(@{$p{options}}), 2, ($p{no_labels} ? 1 : 2), 0);
$grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
$grid_sizer->AddGrowableCol($p{no_labels} ? 0 : 1);
my $sidetext_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
my $onChange = $p{on_change} || sub {};
foreach my $opt_key (@{$p{options}}) {
my $index;
$opt_key =~ s/#(\d+)$// and $index = $1;
my $opt = $Slic3r::Config::Options->{$opt_key};
my $label = Wx::StaticText->new($parent, -1, "$opt->{label}:", Wx::wxDefaultPosition,
[$p{label_width} || 180, -1]);
$label->Wrap($p{label_width} || 180); # needed to avoid Linux/GTK bug
my $label;
if (!$p{no_labels}) {print $opt_key, "\n" if !defined $opt->{label};
$label = Wx::StaticText->new($parent, -1, "$opt->{label}:", wxDefaultPosition, [$p{label_width} || 180, -1]);
$label->Wrap($p{label_width} || 180) ; # needed to avoid Linux/GTK bug
$grid_sizer->Add($label);
}
#set the bold font point size to the same size as all the other labels (for consistency)
$bold_font->SetPointSize($label->GetFont()->GetPointSize());
$label->SetFont($bold_font) if $opt->{important};
my $field;
if ($opt->{type} =~ /^(i|f|s|s@)$/) {
my $style = 0;
my $size = Wx::wxDefaultSize;
if ($opt->{multiline}) {
$style = &Wx::wxTE_MULTILINE;
$size = Wx::Size->new($opt->{width} || -1, $opt->{height} || -1);
}
$style = wxTE_MULTILINE if $opt->{multiline};
my $size = Wx::Size->new($opt->{width} || -1, $opt->{height} || -1);
# if it's an array type but no index was specified, use the serialized version
my ($get_m, $set_m) = $opt->{type} =~ /\@$/ && !defined $index
@ -57,8 +54,10 @@ sub new {
$val = $val->[$index] if defined $index;
return $val;
};
$field = Wx::TextCtrl->new($parent, -1, $get->(), Wx::wxDefaultPosition, $size, $style);
push @reload_callbacks, sub { $field->SetValue($get->()) };
$field = $opt->{type} eq 'i'
? Wx::SpinCtrl->new($parent, -1, $get->(), wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 100, $get->())
: Wx::TextCtrl->new($parent, -1, $get->(), wxDefaultPosition, $size, $style);
$reload_callbacks{$opt_key} = sub { $field->SetValue($get->()) };
my $set = sub {
my $val = $field->GetValue;
@ -67,51 +66,70 @@ sub new {
} else {
Slic3r::Config->$set_m($opt_key, $val);
}
$onChange->($opt_key);
};
EVT_TEXT($parent, $field, sub { $set->() });
$opt->{type} eq 'i'
? EVT_SPINCTRL($parent, $field, $set)
: EVT_TEXT($parent, $field, $set);
} elsif ($opt->{type} eq 'bool') {
$field = Wx::CheckBox->new($parent, -1, "");
$field->SetValue(Slic3r::Config->get_raw($opt_key));
EVT_CHECKBOX($parent, $field, sub { Slic3r::Config->set($opt_key, $field->GetValue) });
push @reload_callbacks, sub { $field->SetValue(Slic3r::Config->get_raw($opt_key)) };
EVT_CHECKBOX($parent, $field, sub { Slic3r::Config->set($opt_key, $field->GetValue); $onChange->($opt_key) });
$reload_callbacks{$opt_key} = sub { $field->SetValue(Slic3r::Config->get_raw($opt_key)) };
} elsif ($opt->{type} eq 'point') {
$field = Wx::BoxSizer->new(wxHORIZONTAL);
my $field_size = Wx::Size->new(40, -1);
my $value = Slic3r::Config->get_raw($opt_key);
$field->Add($_) for (
my @items = (
Wx::StaticText->new($parent, -1, "x:"),
my $x_field = Wx::TextCtrl->new($parent, -1, $value->[0], Wx::wxDefaultPosition, $field_size),
my $x_field = Wx::TextCtrl->new($parent, -1, $value->[0], wxDefaultPosition, $field_size),
Wx::StaticText->new($parent, -1, " y:"),
my $y_field = Wx::TextCtrl->new($parent, -1, $value->[1], Wx::wxDefaultPosition, $field_size),
my $y_field = Wx::TextCtrl->new($parent, -1, $value->[1], wxDefaultPosition, $field_size),
);
$field->Add($_) for @items;
if ($opt->{tooltip}) {
$_->SetToolTipString($opt->{tooltip}) for @items;
}
my $set_value = sub {
my ($i, $value) = @_;
my $val = Slic3r::Config->get_raw($opt_key);
$val->[$i] = $value;
Slic3r::Config->set($opt_key, $val);
};
EVT_TEXT($parent, $x_field, sub { $set_value->(0, $x_field->GetValue) });
EVT_TEXT($parent, $y_field, sub { $set_value->(1, $y_field->GetValue) });
push @reload_callbacks, sub {
EVT_TEXT($parent, $x_field, sub { $set_value->(0, $x_field->GetValue); $onChange->($opt_key) });
EVT_TEXT($parent, $y_field, sub { $set_value->(1, $y_field->GetValue); $onChange->($opt_key) });
$reload_callbacks{$opt_key} = sub {
my $value = Slic3r::Config->get_raw($opt_key);
$x_field->SetValue($value->[0]);
$y_field->SetValue($value->[1]);
};
$fields{$opt_key} = [$x_field, $y_field];
} elsif ($opt->{type} eq 'select') {
$field = Wx::Choice->new($parent, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, $opt->{labels} || $opt->{values});
EVT_CHOICE($parent, $field, sub {
$field = Wx::ComboBox->new($parent, -1, "", wxDefaultPosition, wxDefaultSize, $opt->{labels} || $opt->{values}, wxCB_READONLY);
EVT_COMBOBOX($parent, $field, sub {
Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]);
$onChange->($opt_key);
});
push @reload_callbacks, sub {
$reload_callbacks{$opt_key} = sub {
my $value = Slic3r::Config->get_raw($opt_key);
$field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}});
};
$reload_callbacks[-1]->();
$reload_callbacks{$opt_key}->();
} else {
die "Unsupported option type: " . $opt->{type};
}
$grid_sizer->Add($_) for $label, $field;
$label->SetToolTipString($opt->{tooltip}) if $label && $opt->{tooltip};
$field->SetToolTipString($opt->{tooltip}) if $opt->{tooltip} && $field->can('SetToolTipString');
if ($opt->{sidetext}) {
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($field);
my $sidetext = Wx::StaticText->new($parent, -1, $opt->{sidetext}, wxDefaultPosition, wxDefaultSize);
$sidetext->SetFont($sidetext_font);
$sizer->Add($sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL , 4);
$grid_sizer->Add($sizer);
} else {
$grid_sizer->Add($field, 0, $opt->{full_width} ? wxEXPAND : 0);
}
$fields{$opt_key} ||= [$field];
}

View file

@ -8,10 +8,8 @@ use Math::ConvexHull qw(convex_hull);
use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 scale unscale);
use Slic3r::Geometry::Clipper qw(JT_ROUND);
use threads::shared qw(shared_clone);
use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxICON_QUESTION
wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL);
use Wx::Event qw(EVT_BUTTON EVT_PAINT EVT_MOUSE_EVENTS EVT_LIST_ITEM_SELECTED EVT_LIST_ITEM_DESELECTED
EVT_COMMAND EVT_TOOL);
use Wx qw(:bitmap :brush :button :dialog :filedialog :font :icon :id :listctrl :misc :pen :sizer :toolbar :window);
use Wx::Event qw(EVT_BUTTON EVT_COMMAND EVT_LIST_ITEM_DESELECTED EVT_LIST_ITEM_SELECTED EVT_MOUSE_EVENTS EVT_PAINT EVT_TOOL);
use base 'Wx::Panel';
use constant TB_MORE => 1;
@ -33,58 +31,58 @@ sub new {
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
$self->{canvas} = Wx::Panel->new($self, -1, [-1, -1], [300, 300]);
$self->{canvas} = Wx::Panel->new($self, -1, wxDefaultPosition, [300, 300]);
$self->{canvas}->SetBackgroundColour(Wx::wxWHITE);
EVT_PAINT($self->{canvas}, \&repaint);
EVT_MOUSE_EVENTS($self->{canvas}, \&mouse_event);
$self->{objects_brush} = Wx::Brush->new(Wx::Colour->new(210,210,210), &Wx::wxSOLID);
$self->{selected_brush} = Wx::Brush->new(Wx::Colour->new(255,128,128), &Wx::wxSOLID);
$self->{transparent_brush} = Wx::Brush->new(Wx::Colour->new(0,0,0), &Wx::wxTRANSPARENT);
$self->{grid_pen} = Wx::Pen->new(Wx::Colour->new(230,230,230), 1, &Wx::wxSOLID);
$self->{print_center_pen} = Wx::Pen->new(Wx::Colour->new(200,200,200), 1, &Wx::wxSOLID);
$self->{clearance_pen} = Wx::Pen->new(Wx::Colour->new(0,0,200), 1, &Wx::wxSOLID);
$self->{skirt_pen} = Wx::Pen->new(Wx::Colour->new(150,150,150), 1, &Wx::wxSOLID);
$self->{objects_brush} = Wx::Brush->new(Wx::Colour->new(210,210,210), wxSOLID);
$self->{selected_brush} = Wx::Brush->new(Wx::Colour->new(255,128,128), wxSOLID);
$self->{transparent_brush} = Wx::Brush->new(Wx::Colour->new(0,0,0), wxTRANSPARENT);
$self->{grid_pen} = Wx::Pen->new(Wx::Colour->new(230,230,230), 1, wxSOLID);
$self->{print_center_pen} = Wx::Pen->new(Wx::Colour->new(200,200,200), 1, wxSOLID);
$self->{clearance_pen} = Wx::Pen->new(Wx::Colour->new(0,0,200), 1, wxSOLID);
$self->{skirt_pen} = Wx::Pen->new(Wx::Colour->new(150,150,150), 1, wxSOLID);
$self->{list} = Wx::ListView->new($self, -1, [-1, -1], [-1, 180], &Wx::wxLC_SINGLE_SEL | &Wx::wxLC_REPORT | &Wx::wxBORDER_DEFAULT);
$self->{list}->InsertColumn(0, "Name", &Wx::wxLIST_FORMAT_LEFT, 300);
$self->{list}->InsertColumn(1, "Copies", &Wx::wxLIST_FORMAT_CENTER, 50);
$self->{list}->InsertColumn(2, "Scale", &Wx::wxLIST_FORMAT_CENTER, 50);
$self->{list} = Wx::ListView->new($self, -1, wxDefaultPosition, [-1, 180], wxLC_SINGLE_SEL | wxLC_REPORT | wxBORDER_SUNKEN);
$self->{list}->InsertColumn(0, "Name", wxLIST_FORMAT_LEFT, 300);
$self->{list}->InsertColumn(1, "Copies", wxLIST_FORMAT_CENTER, 50);
$self->{list}->InsertColumn(2, "Scale", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE_USEHEADER);
EVT_LIST_ITEM_SELECTED($self, $self->{list}, \&list_item_selected);
EVT_LIST_ITEM_DESELECTED($self, $self->{list}, \&list_item_deselected);
# toolbar for object manipulation
if (!&Wx::wxMSW) {
Wx::ToolTip::Enable(1);
$self->{htoolbar} = Wx::ToolBar->new($self, -1, [-1, -1], [-1, -1], &Wx::wxTB_HORIZONTAL | &Wx::wxTB_HORZ_TEXT);
$self->{htoolbar}->AddTool(TB_MORE, "More", Wx::Bitmap->new("$Slic3r::var/add.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_LESS, "Less", Wx::Bitmap->new("$Slic3r::var/delete.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar} = Wx::ToolBar->new($self, -1, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL | wxTB_TEXT | wxBORDER_SIMPLE);
$self->{htoolbar}->AddTool(TB_MORE, "More", Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_LESS, "Less", Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddSeparator;
$self->{htoolbar}->AddTool(TB_45CCW, "45° ccw", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_anticlockwise.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_45CW, "45° cw", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_clockwise.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_ROTATE, "Rotate...", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_clockwise.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_45CCW, "45° ccw", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_anticlockwise.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_45CW, "45° cw", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_clockwise.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_ROTATE, "Rotate", Wx::Bitmap->new("$Slic3r::var/arrow_rotate_clockwise.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddSeparator;
$self->{htoolbar}->AddTool(TB_SCALE, "Scale...", Wx::Bitmap->new("$Slic3r::var/arrow_out.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_SCALE, "Scale", Wx::Bitmap->new("$Slic3r::var/arrow_out.png", wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddSeparator;
$self->{htoolbar}->AddTool(TB_SPLIT, "Split", Wx::Bitmap->new("$Slic3r::var/shape_ungroup.png", &Wx::wxBITMAP_TYPE_PNG), '');
$self->{htoolbar}->AddTool(TB_SPLIT, "Split", Wx::Bitmap->new("$Slic3r::var/shape_ungroup.png", wxBITMAP_TYPE_PNG), '');
} else {
my %tbar_buttons = (increase => "More", decrease => "Less", rotate45ccw => "45°", rotate45cw => "45°",
rotate => "Rotate…", changescale => "Scale…", split => "Split");
$self->{btoolbar} = Wx::BoxSizer->new(wxHORIZONTAL);
for (qw(increase decrease rotate45ccw rotate45cw rotate changescale split)) {
$self->{"btn_$_"} = Wx::Button->new($self, -1, $tbar_buttons{$_}, [-1,-1], [-1,-1], &Wx::wxBU_EXACTFIT);
$self->{"btn_$_"} = Wx::Button->new($self, -1, $tbar_buttons{$_}, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
$self->{btoolbar}->Add($self->{"btn_$_"});
}
}
# general buttons
$self->{btn_load} = Wx::Button->new($self, -1, "Add…", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_remove} = Wx::Button->new($self, -1, "Delete", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_reset} = Wx::Button->new($self, -1, "Delete All", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_arrange} = Wx::Button->new($self, -1, "Autoarrange", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_export_gcode} = Wx::Button->new($self, -1, "Export G-code…", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_load} = Wx::Button->new($self, -1, "Add…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
$self->{btn_remove} = Wx::Button->new($self, -1, "Delete", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
$self->{btn_reset} = Wx::Button->new($self, -1, "Delete All", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
$self->{btn_arrange} = Wx::Button->new($self, -1, "Autoarrange", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
$self->{btn_export_gcode} = Wx::Button->new($self, -1, "Export G-code…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
$self->{btn_export_gcode}->SetDefault;
$self->{btn_export_stl} = Wx::Button->new($self, -1, "Export STL…", [-1,-1], [-1,-1], &Wx::wxBU_LEFT);
$self->{btn_export_stl} = Wx::Button->new($self, -1, "Export STL…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
if (&Wx::wxVERSION_STRING =~ / 2\.9\.[1-9]/) {
my %icons = qw(
@ -104,7 +102,7 @@ sub new {
split shape_ungroup.png
);
for (grep $self->{"btn_$_"}, keys %icons) {
$self->{"btn_$_"}->SetBitmap(Wx::Bitmap->new("$Slic3r::var/$icons{$_}", &Wx::wxBITMAP_TYPE_PNG));
$self->{"btn_$_"}->SetBitmap(Wx::Bitmap->new("$Slic3r::var/$icons{$_}", wxBITMAP_TYPE_PNG));
}
}
$self->selection_changed(0);
@ -148,7 +146,7 @@ sub new {
my ($self, $event) = @_;
my ($percent, $message) = @{$event->GetData};
$self->statusbar->SetProgress($percent);
$self->statusbar->SetStatusText("$message...");
$self->statusbar->SetStatusText("$message");
});
EVT_COMMAND($self, -1, $MESSAGE_DIALOG_EVENT, sub {
@ -185,17 +183,35 @@ sub new {
my $list_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$list_sizer->Add($self->{list}, 1, wxEXPAND | wxALL, 0);
$list_sizer->Add($self->{vtoolbar}, 0, wxEXPAND, 0) if $self->{vtoolbar};
my $vertical_sizer = Wx::BoxSizer->new(wxVERTICAL);
$vertical_sizer->Add($self->{htoolbar}, 0, wxEXPAND, 0) if $self->{htoolbar};
$vertical_sizer->Add($self->{btoolbar}, 0, wxEXPAND, 0) if $self->{btoolbar};
$vertical_sizer->Add($list_sizer, 0, wxEXPAND | &Wx::wxBOTTOM, 10);
$vertical_sizer->Add($list_sizer, 0, wxEXPAND | wxBOTTOM, 10);
$vertical_sizer->Add($buttons, 0, wxEXPAND);
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($self->{canvas}, 0, wxALL, 10);
$sizer->Add($vertical_sizer, 1, wxEXPAND | wxALL, 10);
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
$hsizer->Add($self->{canvas}, 0, wxALL, 10);
$hsizer->Add($vertical_sizer, 1, wxEXPAND | wxALL, 10);
my $presets = Wx::BoxSizer->new(wxHORIZONTAL);
my %group_labels = (
print => 'Print settings',
filament => 'Filament',
printer => 'Printer',
);
$self->{preset_choosers} = {};
for my $group (qw(print filament printer)) {
my $text = Wx::StaticText->new($self, -1, "$group_labels{$group}:", wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
$self->{preset_choosers}{$group} = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], []);
$presets->Add($text, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxRIGHT, 4);
$presets->Add($self->{preset_choosers}{$group}, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 15);
}
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($hsizer, 0, wxEXPAND | wxBOTTOM, 10);
$sizer->Add($presets, 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
$sizer->SetSizeHints($self);
$self->SetSizer($sizer);
}
@ -206,7 +222,7 @@ sub load {
my $self = shift;
my $dir = $Slic3r::GUI::SkeinPanel::last_skein_dir || $Slic3r::GUI::SkeinPanel::last_config_dir || "";
my $dialog = Wx::FileDialog->new($self, 'Choose one or more files (STL/OBJ/AMF):', $dir, "", $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_OPEN | &Wx::wxFD_MULTIPLE | &Wx::wxFD_FILE_MUST_EXIST);
my $dialog = Wx::FileDialog->new($self, 'Choose one or more files (STL/OBJ/AMF):', $dir, "", $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
if ($dialog->ShowModal != wxID_OK) {
$dialog->Destroy;
return;
@ -222,7 +238,7 @@ sub load_file {
$Slic3r::GUI::SkeinPanel::last_skein_dir = dirname($input_file);
my $process_dialog = Wx::ProgressDialog->new('Loading...', "Processing input file...", 100, $self, 0);
my $process_dialog = Wx::ProgressDialog->new('Loading…', "Processing input file…", 100, $self, 0);
$process_dialog->Pulse;
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
$self->{print}->add_object_from_file($input_file);
@ -336,7 +352,7 @@ sub rotate {
return if !$angle || $angle == -1;
}
$self->statusbar->SetStatusText("Rotating object...");
$self->statusbar->SetStatusText("Rotating object");
$self->statusbar->StartBusy;
# rotate, realign to 0,0 and update size
@ -374,7 +390,7 @@ sub changescale {
$scale = Wx::GetNumberFromUser("", "Enter the scale % for the selected object:", "Scale", $scale*100, 0, 5000, $self);
return if !$scale || $scale == -1;
$self->statusbar->SetStatusText("Scaling object...");
$self->statusbar->SetStatusText("Scaling object");
$self->statusbar->StartBusy;
my $object = $self->{print}->objects->[$obj_idx];
@ -425,7 +441,7 @@ sub export_gcode {
my $self = shift;
if ($self->{export_thread}) {
Wx::MessageDialog->new($self, "Another slicing job is currently running.", 'Error', wxOK | &Wx::wxICON_ERROR)->ShowModal;
Wx::MessageDialog->new($self, "Another slicing job is currently running.", 'Error', wxOK | wxICON_ERROR)->ShowModal;
return;
}
@ -471,7 +487,7 @@ sub export_gcode {
progressbar => sub {
my ($percent, $message) = @_;
$self->statusbar->SetProgress($percent);
$self->statusbar->SetStatusText("$message...");
$self->statusbar->SetStatusText("$message");
},
message_dialog => sub { Wx::MessageDialog->new($self, @_)->ShowModal },
on_completed => sub { $self->on_export_completed(@_) },
@ -515,12 +531,13 @@ sub export_gcode2 {
}
my $message = "Your files were successfully sliced";
$message .= sprintf " in %d minutes and %.3f seconds",
int($print->processing_time/60),
$print->processing_time - int($print->processing_time/60)*60
if $print->processing_time;
if ($print->processing_time) {
$message .= ' in';
my $minutes = int($print->processing_time/60);
$message .= sprintf " %d minutes and", $minutes if $minutes;
$message .= sprintf " %.1f seconds", $print->processing_time - $minutes*60;
}
$message .= ".";
Slic3r::GUI::notify($message);
$params{on_completed}->($message);
$print->cleanup;
};
@ -536,12 +553,11 @@ sub on_export_completed {
$self->statusbar->SetCancelCallback(undef);
$self->statusbar->StopBusy;
$self->statusbar->SetStatusText("G-code file exported to $self->{output_file}");
Wx::MessageDialog->new($self, $message, 'Done!', wxOK | wxICON_INFORMATION)->ShowModal;
&Wx::wxTheApp->notify($message);
}
sub on_export_failed {
my $self = shift;
my ($message) = @_;
$self->{export_thread}->detach if $self->{export_thread};
$self->{export_thread} = undef;
@ -561,7 +577,7 @@ sub export_stl {
$output_file = $print->expanded_output_filepath($output_file);
$output_file =~ s/\.gcode$/.stl/i;
my $dlg = Wx::FileDialog->new($self, 'Save STL file as:', dirname($output_file),
basename($output_file), $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_SAVE | &Wx::wxFD_OVERWRITE_PROMPT);
basename($output_file), $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal != wxID_OK) {
$dlg->Destroy;
return;
@ -674,12 +690,12 @@ sub repaint {
$dc->DrawLine(0, $size[Y]/2, $size[X], $size[Y]/2);
$dc->SetTextForeground(Wx::Colour->new(0,0,0));
$dc->SetFont(Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL));
$dc->DrawLabel("X = " . $Slic3r::print_center->[X], Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), &Wx::wxALIGN_CENTER_HORIZONTAL | &Wx::wxALIGN_BOTTOM);
$dc->DrawLabel("X = " . $Slic3r::print_center->[X], Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
$dc->DrawRotatedText("Y = " . $Slic3r::print_center->[Y], 0, $size[Y]/2+15, 90);
}
# draw frame
$dc->SetPen(Wx::wxBLACK_PEN);
$dc->SetPen(wxBLACK_PEN);
$dc->SetBrush($parent->{transparent_brush});
$dc->DrawRectangle(0, 0, @size);
@ -687,11 +703,11 @@ sub repaint {
if (!@{$print->objects}) {
$dc->SetTextForeground(Wx::Colour->new(150,50,50));
$dc->SetFont(Wx::Font->new(14, wxDEFAULT, wxNORMAL, wxNORMAL));
$dc->DrawLabel("Drag your objects here", Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), &Wx::wxALIGN_CENTER_HORIZONTAL | &Wx::wxALIGN_CENTER_VERTICAL);
$dc->DrawLabel("Drag your objects here", Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
}
# draw thumbnails
$dc->SetPen(Wx::wxBLACK_PEN);
$dc->SetPen(wxBLACK_PEN);
@{$parent->{object_previews}} = ();
for my $obj_idx (0 .. $#{$print->objects}) {
next unless $parent->{thumbnails}[$obj_idx];
@ -834,7 +850,6 @@ sub _y {
}
package Slic3r::GUI::Plater::DropTarget;
use Wx::DND;
use base 'Wx::FileDropTarget';

View file

@ -5,8 +5,7 @@ use utf8;
use File::Basename qw(basename dirname);
use Slic3r::Geometry qw(X Y);
use Wx qw(:sizer :progressdialog wxOK wxICON_INFORMATION wxICON_WARNING wxICON_ERROR wxICON_QUESTION
wxOK wxCANCEL wxID_OK wxFD_OPEN wxFD_SAVE wxDEFAULT wxNORMAL);
use Wx qw(:dialog :filedialog :font :icon :id :misc :notebook :sizer);
use Wx::Event qw(EVT_BUTTON);
use base 'Wx::Panel';
@ -21,145 +20,24 @@ sub new {
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
no warnings 'qw';
my %panels = (
printer => {
title => 'Printer',
options => [qw(nozzle_diameter#0 bed_size print_center z_offset gcode_flavor use_relative_e_distances)],
},
filament => {
title => 'Filament',
options => [qw(filament_diameter#0 extrusion_multiplier#0 temperature#0 first_layer_temperature#0 bed_temperature first_layer_bed_temperature)],
},
print_speed => {
title => 'Print speed',
options => [qw(perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed bridge_speed)],
},
speed => {
title => 'Other speed settings',
options => [qw(travel_speed first_layer_speed)],
},
accuracy => {
title => 'Accuracy',
options => [qw(layer_height first_layer_height infill_every_layers)],
},
print => {
title => 'Print settings',
options => [qw(perimeters solid_layers fill_density fill_angle fill_pattern solid_fill_pattern randomize_start)],
},
retract => {
title => 'Retraction',
options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
},
cooling => {
title => 'Cooling',
options => [qw(cooling min_fan_speed max_fan_speed bridge_fan_speed fan_below_layer_time slowdown_below_layer_time min_print_speed disable_fan_first_layers fan_always_on)],
label_width => 450,
},
skirt => {
title => 'Skirt',
options => [qw(skirts skirt_distance skirt_height brim_width)],
},
gcode => {
title => 'G-code',
options => [qw(start_gcode end_gcode layer_gcode gcode_comments post_process)],
label_width => 260,
},
sequential_printing => {
title => 'Sequential printing',
options => [qw(complete_objects extruder_clearance_radius extruder_clearance_height)],
},
extrusion => {
title => 'Extrusion',
options => [qw(extrusion_width first_layer_extrusion_width perimeter_extrusion_width infill_extrusion_width support_material_extrusion_width bridge_flow_ratio)],
},
output => {
title => 'Output',
options => [qw(output_filename_format duplicate_distance)],
},
other => {
title => 'Other',
options => [ ($Slic3r::have_threads ? qw(threads) : ()), qw(extra_perimeters) ],
},
notes => {
title => 'Notes',
options => [qw(notes)],
},
support_material => {
title => 'Support material',
options => [qw(support_material support_material_threshold support_material_pattern support_material_spacing support_material_angle support_material_extruder)],
},
);
$self->{panels} = \%panels;
my $tabpanel = Wx::Notebook->new($self, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, &Wx::wxNB_TOP);
my $make_tab = sub {
my @cols = @_;
my $tab = Wx::Panel->new($tabpanel, -1);
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
foreach my $col (@cols) {
my $vertical_sizer = Wx::BoxSizer->new(wxVERTICAL);
for my $optgroup (@$col) {
next unless @{ $panels{$optgroup}{options} };
my $optpanel = Slic3r::GUI::OptionsGroup->new($tab, %{$panels{$optgroup}});
$vertical_sizer->Add($optpanel, 0, wxEXPAND | wxALL, 10);
}
$sizer->Add($vertical_sizer);
}
$tab->SetSizer($sizer);
return $tab;
my $tabpanel = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP);
$tabpanel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($tabpanel), "Plater");
$self->{options_tabs} = {
print => Slic3r::GUI::Tab::Print->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{print}),
filament => Slic3r::GUI::Tab::Filament->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{filament}),
printer => Slic3r::GUI::Tab::Printer->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{printer}),
};
my @tabs = (
$make_tab->([qw(accuracy skirt support_material)], [qw(print retract)]),
$make_tab->([qw(cooling notes)]),
$make_tab->([qw(printer filament)], [qw(print_speed speed)]),
$make_tab->([qw(gcode)]),
$make_tab->([qw(extrusion)], [qw(output other sequential_printing)]),
);
$tabpanel->AddPage(Slic3r::GUI::Plater->new($tabpanel), "Plater");
$tabpanel->AddPage($tabs[0], "Print Settings");
$tabpanel->AddPage($tabs[1], "Cooling");
$tabpanel->AddPage($tabs[2], "Printer and Filament");
$tabpanel->AddPage($tabs[3], "G-code");
$tabpanel->AddPage($tabs[4], "Advanced");
my $buttons_sizer;
{
$buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
my $slice_button = Wx::Button->new($self, -1, "Quick slice…");
$slice_button->SetDefault();
$buttons_sizer->Add($slice_button, 0, wxRIGHT, 20);
EVT_BUTTON($self, $slice_button, sub { $self->do_slice });
my $save_button = Wx::Button->new($self, -1, "Save config...");
$buttons_sizer->Add($save_button, 0, wxRIGHT, 5);
EVT_BUTTON($self, $save_button, sub { $self->save_config });
my $load_button = Wx::Button->new($self, -1, "Load config...");
$buttons_sizer->Add($load_button, 0, wxRIGHT, 5);
EVT_BUTTON($self, $load_button, sub { $self->load_config });
my $text = Wx::StaticText->new($self, -1, "Remember to check for updates at http://slic3r.org/\nVersion: $Slic3r::VERSION", Wx::wxDefaultPosition, Wx::wxDefaultSize, wxALIGN_RIGHT);
my $font = Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL);
$text->SetFont($font);
$buttons_sizer->Add($text, 1, wxEXPAND | wxALIGN_RIGHT);
}
$tabpanel->AddPage($self->{options_tabs}{print}, $self->{options_tabs}{print}->title);
$tabpanel->AddPage($self->{options_tabs}{filament}, $self->{options_tabs}{filament}->title);
$tabpanel->AddPage($self->{options_tabs}{printer}, $self->{options_tabs}{printer}->title);
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($buttons_sizer, 0, wxEXPAND | wxALL, 10);
$sizer->Add($tabpanel);
$sizer->Add($tabpanel, 1, wxEXPAND);
$sizer->SetSizeHints($self);
$self->SetSizer($sizer);
$self->Layout;
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks;
return $self;
}
@ -182,7 +60,7 @@ sub do_slice {
$copies = $Slic3r::duplicate if $Slic3r::duplicate > 1;
if ($copies > 1) {
my $confirmation = Wx::MessageDialog->new($self, "Are you sure you want to slice $copies copies?",
'Confirm', wxICON_QUESTION | wxOK | wxCANCEL);
'Multiple Copies', wxICON_QUESTION | wxOK | wxCANCEL);
return unless $confirmation->ShowModal == wxID_OK;
}
@ -191,23 +69,23 @@ sub do_slice {
my $input_file;
if (!$params{reslice}) {
my $dialog = Wx::FileDialog->new($self, 'Choose a file to slice (STL/OBJ/AMF):', $dir, "", $model_wildcard, wxFD_OPEN | &Wx::wxFD_FILE_MUST_EXIST);
my $dialog = Wx::FileDialog->new($self, 'Choose a file to slice (STL/OBJ/AMF):', $dir, "", $model_wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if ($dialog->ShowModal != wxID_OK) {
$dialog->Destroy;
return;
}
$input_file = $dialog->GetPaths;
$dialog->Destroy;
$last_input_file = $input_file;
$last_input_file = $input_file unless $params{export_svg};
} else {
if (!defined $last_input_file) {
Wx::MessageDialog->new($self, "No previously sliced file",
'Confirm', wxICON_ERROR | wxOK)->ShowModal();
Wx::MessageDialog->new($self, "No previously sliced file.",
'Error', wxICON_ERROR | wxOK)->ShowModal();
return;
}
if (! -e $last_input_file) {
Wx::MessageDialog->new($self, "Cannot find previously sliced file!",
'Confirm', wxICON_ERROR | wxOK)->ShowModal();
Wx::MessageDialog->new($self, "Previously sliced file ($last_input_file) not found.",
'File Not Found', wxICON_ERROR | wxOK)->ShowModal();
return;
}
$input_file = $last_input_file;
@ -232,12 +110,13 @@ sub do_slice {
$dlg->Destroy;
return;
}
$output_file = $last_output_file = $dlg->GetPath;
$output_file = $dlg->GetPath;
$last_output_file = $output_file unless $params{export_svg};
$dlg->Destroy;
}
# show processbar dialog
$process_dialog = Wx::ProgressDialog->new('Slicing...', "Processing $input_file_basename...",
$process_dialog = Wx::ProgressDialog->new('Slicing…', "Processing $input_file_basename…",
100, $self, 0);
$process_dialog->Pulse;
@ -249,7 +128,7 @@ sub do_slice {
status_cb => sub {
my ($percent, $message) = @_;
if (&Wx::wxVERSION_STRING =~ / 2\.(8\.|9\.[2-9])/) {
$process_dialog->Update($percent, "$message...");
$process_dialog->Update($percent, "$message");
}
},
);
@ -264,13 +143,15 @@ sub do_slice {
undef $process_dialog;
my $message = "$input_file_basename was successfully sliced";
$message .= sprintf " in %d minutes and %.3f seconds",
int($print->processing_time/60),
$print->processing_time - int($print->processing_time/60)*60
if $print->processing_time;
if ($print->processing_time) {
$message .= ' in';
my $minutes = int($print->processing_time/60);
$message .= sprintf " %d minutes and", $minutes if $minutes;
$message .= sprintf " %.1f seconds", $print->processing_time - $minutes*60;
}
$message .= ".";
Slic3r::GUI::notify($message);
Wx::MessageDialog->new($self, $message, 'Done!',
&Wx::wxTheApp->notify($message);
Wx::MessageDialog->new($self, $message, 'Slicing Done!',
wxOK | wxICON_INFORMATION)->ShowModal;
};
Slic3r::GUI::catch_error($self, sub { $process_dialog->Destroy if $process_dialog });
@ -289,7 +170,7 @@ sub save_config {
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
my $filename = $last_config ? basename($last_config) : "config.ini";
my $dlg = Wx::FileDialog->new($self, 'Save configuration as:', $dir, $filename,
$ini_wildcard, wxFD_SAVE | &Wx::wxFD_OVERWRITE_PROMPT);
$ini_wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal == wxID_OK) {
my $file = $dlg->GetPath;
$last_config_dir = dirname($file);
@ -301,22 +182,44 @@ sub save_config {
sub load_config {
my $self = shift;
my ($file) = @_;
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
$ini_wildcard, wxFD_OPEN | &Wx::wxFD_FILE_MUST_EXIST);
if ($dlg->ShowModal == wxID_OK) {
my ($file) = $dlg->GetPaths;
$last_config_dir = dirname($file);
$last_config = $file;
eval {
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
Slic3r::Config->load($file);
};
Slic3r::GUI::catch_error($self);
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks;
if (!$file) {
return unless $self->check_unsaved_changes;
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
$ini_wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
return unless $dlg->ShowModal == wxID_OK;
($file) = $dlg->GetPaths;
$dlg->Destroy;
}
$dlg->Destroy;
$last_config_dir = dirname($file);
$last_config = $file;
$_->external_config_loaded($file) for values %{$self->{options_tabs}};
}
sub config_wizard {
my $self = shift;
return unless $self->check_unsaved_changes;
if (Slic3r::GUI::ConfigWizard->new($self)->run) {
$_->() for values %Slic3r::GUI::OptionsGroup::reload_callbacks;
$_->set_dirty(1) for values %{$self->{options_tabs}};
}
}
sub check_unsaved_changes {
my $self = shift;
my @dirty = map $_->title, grep $_->is_dirty, values %{$self->{options_tabs}};
if (@dirty) {
my $titles = join ', ', @dirty;
my $confirm = Wx::MessageDialog->new($self, "You have unsaved changes ($titles). Discard changes and continue anyway?",
'Unsaved Presets', wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT);
return ($confirm->ShowModal == wxID_YES);
}
return 1;
}
1;

556
lib/Slic3r/GUI/Tab.pm Normal file
View file

@ -0,0 +1,556 @@
package Slic3r::GUI::Tab;
use strict;
use warnings;
use utf8;
use File::Basename qw(basename);
use List::Util qw(first);
use Wx qw(:bookctrl :dialog :icon :id :misc :sizer :treectrl :window);
use Wx::Event qw(EVT_BUTTON EVT_CHOICE EVT_TREE_SEL_CHANGED);
use base 'Wx::Panel';
sub new {
my $class = shift;
my ($parent, $title, %params) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT);
$self->{title} = $title;
$self->{sync_presets_with} = $params{sync_presets_with};
EVT_CHOICE($parent, $self->{sync_presets_with}, sub {
$self->{presets_choice}->SetSelection($self->{sync_presets_with}->GetSelection);
$self->on_select_preset;
});
# horizontal sizer
$self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
$self->{sizer}->SetSizeHints($self);
$self->SetSizer($self->{sizer});
# left vertical sizer
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
$self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
my $left_col_width = 150;
# preset chooser
{
# choice menu
$self->{presets_choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [$left_col_width, -1], []);
$self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
# buttons
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG));
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
$self->{btn_save_preset}->SetToolTipString("Save current " . lc($title));
$self->{btn_delete_preset}->SetToolTipString("Delete this preset");
$self->{btn_delete_preset}->Disable;
### These cause GTK warnings:
###my $box = Wx::StaticBox->new($self, -1, "Presets:", wxDefaultPosition, [$left_col_width, 50]);
###my $hsizer = Wx::StaticBoxSizer->new($box, wxHORIZONTAL);
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
$left_sizer->Add($hsizer, 0, wxEXPAND | wxBOTTOM, 5);
$hsizer->Add($self->{presets_choice}, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 3);
$hsizer->Add($self->{btn_save_preset}, 0, wxALIGN_CENTER_VERTICAL);
$hsizer->Add($self->{btn_delete_preset}, 0, wxALIGN_CENTER_VERTICAL);
}
# tree
$self->{treectrl} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [$left_col_width, -1], wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN);
$left_sizer->Add($self->{treectrl}, 1, wxEXPAND);
$self->{icons} = Wx::ImageList->new(16, 16, 1);
$self->{treectrl}->AssignImageList($self->{icons});
$self->{iconcount} = -1;
$self->{treectrl}->AddRoot("root");
$self->{pages} = {};
$self->{treectrl}->SetIndent(0);
EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
$_->Hide for values %{$self->{pages}};
$self->{sizer}->Remove(1);
my $page = $self->{pages}->{ $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) };
$page->Show;
$self->{sizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
$self->{sizer}->Layout;
});
EVT_CHOICE($parent, $self->{presets_choice}, sub {
$self->on_select_preset;
$self->sync_presets;
});
EVT_BUTTON($self, $self->{btn_save_preset}, sub {
my $preset = $self->current_preset;
my $default_name = $preset->{default} ? 'Untitled' : basename($preset->{name});
$default_name =~ s/\.ini$//i;
my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
title => lc($title),
default => $default_name,
values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ],
);
return unless $dlg->ShowModal == wxID_OK;
my $file = sprintf "$Slic3r::GUI::datadir/$self->{presets_group}/%s.ini", $dlg->get_name;
Slic3r::Config->save($file, $self->{presets_group});
$self->set_dirty(0);
$self->load_presets;
$self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $dlg->get_name . ".ini" } 1 .. $#{$self->{presets}});
$self->on_select_preset;
$self->sync_presets;
});
EVT_BUTTON($self, $self->{btn_delete_preset}, sub {
my $i = $self->{presets_choice}->GetSelection;
return if $i == 0; # this shouldn't happen but let's trap it anyway
my $res = Wx::MessageDialog->new($self, "Are you sure you want to delete the selected preset?", 'Delete Preset', wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION)->ShowModal;
return unless $res == wxID_YES;
if (-e $self->{presets}[$i-1]{file}) {
unlink $self->{presets}[$i-1]{file};
}
splice @{$self->{presets}}, $i-1, 1;
$self->{presets_choice}->Delete($i);
$self->{presets_choice}->SetSelection(0);
$self->on_select_preset;
$self->sync_presets;
});
return $self;
}
sub current_preset {
my $self = shift;
return $self->{presets}[ $self->{presets_choice}->GetSelection ];
}
sub on_select_preset {
my $self = shift;
if (defined $self->{dirty}) {
# TODO: prompt user?
$self->set_dirty(0);
}
my $preset = $self->current_preset;
if ($preset->{default}) {
# default settings: disable the delete button
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
$self->{btn_delete_preset}->Disable;
} else {
if (!-e $preset->{file}) {
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($preset->{file}).");
return;
}
eval {
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
Slic3r::Config->load($preset->{file}, $self->{presets_group});
};
Slic3r::GUI::catch_error($self);
$preset->{external}
? $self->{btn_delete_preset}->Disable
: $self->{btn_delete_preset}->Enable;
}
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
$self->set_dirty(0);
$Slic3r::Settings->{presets}{$self->{presets_group}} = $preset->{file} ? basename($preset->{file}) : '';
Slic3r::Config->save_settings("$Slic3r::GUI::datadir/slic3r.ini");
}
sub add_options_page {
my $self = shift;
my $title = shift;
my $icon = (ref $_[1]) ? undef : shift;
my $page = Slic3r::GUI::Tab::Page->new($self, @_, on_change => sub {
$self->set_dirty(1);
$self->sync_presets;
});
my $bitmap = $icon
? Wx::Bitmap->new("$Slic3r::var/$icon", wxBITMAP_TYPE_PNG)
: undef;
if ($bitmap) {
$self->{icons}->Add($bitmap);
$self->{iconcount}++;
}
$page->Hide;
my $itemId = $self->{treectrl}->AppendItem($self->{treectrl}->GetRootItem, $title, $self->{iconcount});
$self->{pages}{$title} = $page;
if (keys %{$self->{pages}} == 1) {
$self->{treectrl}->SelectItem($itemId);
}
}
sub set_dirty {
my $self = shift;
my ($dirty) = @_;
my $i = $self->{dirty} // $self->{presets_choice}->GetSelection; #/
my $text = $self->{presets_choice}->GetString($i);
if ($dirty) {
$self->{dirty} = $i;
if ($text !~ / \(modified\)$/) {
$self->{presets_choice}->SetString($i, "$text (modified)");
$self->{presets_choice}->SetSelection($i); # wxMSW needs this after every SetString()
}
} else {
$self->{dirty} = undef;
$text =~ s/ \(modified\)$//;
$self->{presets_choice}->SetString($i, $text);
$self->{presets_choice}->SetSelection($i); # wxMSW needs this after every SetString()
}
$self->sync_presets;
}
sub is_dirty {
my $self = shift;
return (defined $self->{dirty});
}
sub title {
my $self = shift;
return $self->{title};
}
sub load_presets {
my $self = shift;
my ($group) = @_;
$self->{presets_group} ||= $group;
$self->{presets} = [{
default => 1,
name => '- default -',
}];
opendir my $dh, "$Slic3r::GUI::datadir/$self->{presets_group}" or die "Failed to read directory $Slic3r::GUI::datadir/$self->{presets_group} (errno: $!)\n";
foreach my $file (sort grep /\.ini$/i, readdir $dh) {
my $name = basename($file);
$name =~ s/\.ini$//;
push @{$self->{presets}}, {
file => "$Slic3r::GUI::datadir/$self->{presets_group}/$file",
name => $name,
};
}
closedir $dh;
$self->{presets_choice}->Clear;
$self->{presets_choice}->Append($_->{name}) for @{$self->{presets}};
{
# load last used preset
my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::Settings->{presets}{$self->{presets_group}} || '') } 1 .. $#{$self->{presets}};
$self->{presets_choice}->SetSelection($i || 0);
$self->on_select_preset;
}
$self->sync_presets;
}
sub external_config_loaded {
my $self = shift;
my ($file) = @_;
# look for the loaded config among the existing menu items
my $i = first { $self->{presets}[$_]{file} eq $file && $self->{presets}[$_]{external} } 1..$#{$self->{presets}};
if (!$i) {
my $preset_name = basename($file); # keep the .ini suffix
push @{$self->{presets}}, {
file => $file,
name => $preset_name,
external => 1,
};
$self->{presets_choice}->Append($preset_name);
$i = $#{$self->{presets}};
}
$self->{presets_choice}->SetSelection($i);
$self->on_select_preset;
$self->sync_presets;
}
sub sync_presets {
my $self = shift;
return unless $self->{sync_presets_with};
$self->{sync_presets_with}->Clear;
foreach my $item ($self->{presets_choice}->GetStrings) {
$self->{sync_presets_with}->Append($item);
}
$self->{sync_presets_with}->SetSelection($self->{presets_choice}->GetSelection);
}
package Slic3r::GUI::Tab::Print;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Print Settings', %params);
$self->add_options_page('Layers and perimeters', 'layers.png', optgroups => [
{
title => 'Layer height',
options => [qw(layer_height first_layer_height)],
},
{
title => 'Vertical shells',
options => [qw(perimeters randomize_start extra_perimeters)],
},
{
title => 'Horizontal shells',
options => [qw(solid_layers)],
},
]);
$self->add_options_page('Infill', 'shading.png', optgroups => [
{
title => 'Infill',
options => [qw(fill_density fill_angle fill_pattern solid_fill_pattern infill_every_layers)],
},
]);
$self->add_options_page('Speed', 'time.png', optgroups => [
{
title => 'Speed for print moves',
options => [qw(perimeter_speed small_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed bridge_speed)],
},
{
title => 'Speed for non-print moves',
options => [qw(travel_speed)],
},
{
title => 'Modifiers',
options => [qw(first_layer_speed)],
},
]);
$self->add_options_page('Skirt and brim', 'box.png', optgroups => [
{
title => 'Skirt',
options => [qw(skirts skirt_distance skirt_height)],
},
{
title => 'Brim',
options => [qw(brim_width)],
},
]);
$self->add_options_page('Support material', 'building.png', optgroups => [
{
title => 'Support material',
options => [qw(support_material support_material_threshold support_material_pattern support_material_spacing support_material_angle)],
},
]);
$self->add_options_page('Notes', 'note.png', optgroups => [
{
title => 'Notes',
no_labels => 1,
options => [qw(notes)],
},
]);
$self->add_options_page('Output options', 'page_white_go.png', optgroups => [
{
title => 'Sequential printing',
options => [qw(complete_objects extruder_clearance_radius extruder_clearance_height)],
},
{
title => 'Output file',
options => [qw(gcode_comments output_filename_format)],
},
{
title => 'Post-processing scripts',
no_labels => 1,
options => [qw(post_process)],
},
]);
$self->add_options_page('Advanced', 'wrench.png', optgroups => [
{
title => 'Extrusion width',
label_width => 180,
options => [qw(extrusion_width first_layer_extrusion_width perimeter_extrusion_width infill_extrusion_width)],
},
{
title => 'Flow',
options => [qw(bridge_flow_ratio)],
},
{
title => 'Other',
options => [qw(duplicate_distance), ($Slic3r::have_threads ? qw(threads) : ())],
},
]);
$self->load_presets('print');
return $self;
}
package Slic3r::GUI::Tab::Filament;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Filament Settings', %params);
$self->add_options_page('Filament', 'spool.png', optgroups => [
{
title => 'Filament',
options => ['filament_diameter#0', 'extrusion_multiplier#0'],
},
{
title => 'Temperature',
options => ['temperature#0', 'first_layer_temperature#0', qw(bed_temperature first_layer_bed_temperature)],
},
]);
$self->add_options_page('Cooling', 'hourglass.png', optgroups => [
{
title => 'Enable',
options => [qw(cooling)],
},
{
title => 'Fan settings',
options => [qw(min_fan_speed max_fan_speed bridge_fan_speed disable_fan_first_layers fan_always_on)],
},
{
title => 'Cooling thresholds',
label_width => 250,
options => [qw(fan_below_layer_time slowdown_below_layer_time min_print_speed)],
},
]);
$self->load_presets('filament');
return $self;
}
package Slic3r::GUI::Tab::Printer;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Printer Settings', %params);
$self->add_options_page('General', 'printer_empty.png', optgroups => [
{
title => 'Size and coordinates',
options => [qw(bed_size print_center z_offset)],
},
{
title => 'Firmware',
options => [qw(gcode_flavor use_relative_e_distances)],
},
]);
$self->add_options_page('Extruder 1', 'funnel.png', optgroups => [
{
title => 'Size',
options => ['nozzle_diameter#0'],
},
{
title => 'Retraction',
options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
},
]);
$self->add_options_page('Custom G-code', 'cog.png', optgroups => [
{
title => 'Start G-code',
no_labels => 1,
options => [qw(start_gcode)],
},
{
title => 'End G-code',
no_labels => 1,
options => [qw(end_gcode)],
},
{
title => 'Layer change G-code',
no_labels => 1,
options => [qw(layer_gcode)],
},
]);
$self->load_presets('printer');
return $self;
}
package Slic3r::GUI::Tab::Page;
use Wx qw(:sizer);
use base 'Wx::ScrolledWindow';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1);
$self->SetScrollbars(1, 1, 1, 1);
$self->{vsizer} = Wx::BoxSizer->new(wxVERTICAL);
$self->SetSizer($self->{vsizer});
if ($params{optgroups}) {
$self->append_optgroup(%$_, on_change => $params{on_change}) for @{$params{optgroups}};
}
return $self;
}
sub append_optgroup {
my $self = shift;
my $optgroup = Slic3r::GUI::OptionsGroup->new($self, label_width => 200, @_);
$self->{vsizer}->Add($optgroup, 0, wxEXPAND | wxALL, 5);
}
package Slic3r::GUI::SavePresetWindow;
use Wx qw(:combobox :dialog :id :misc :sizer);
use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);
use base 'Wx::Dialog';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, "Save preset", wxDefaultPosition, wxDefaultSize);
my $text = Wx::StaticText->new($self, -1, "Save " . lc($params{title}) . " as:", wxDefaultPosition, wxDefaultSize);
$self->{combo} = Wx::ComboBox->new($self, -1, $params{default}, wxDefaultPosition, wxDefaultSize, $params{values},
wxTE_PROCESS_ENTER);
my $buttons = $self->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($text, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
$sizer->Add($self->{combo}, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
$sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
EVT_BUTTON($self, wxID_OK, \&accept);
EVT_TEXT_ENTER($self, $self->{combo}, \&accept);
$self->SetSizer($sizer);
$sizer->SetSizeHints($self);
return $self;
}
sub accept {
my ($self, $event) = @_;
if (($self->{chosen_name} = $self->{combo}->GetValue)) {
if ($self->{chosen_name} =~ /^[a-z0-9 _-]+$/i) {
$self->EndModal(wxID_OK);
} else {
Slic3r::GUI::show_error($self, "The supplied name is not valid.");
}
}
}
sub get_name {
my $self = shift;
return $self->{chosen_name};
}
1;

View file

@ -9,6 +9,7 @@ BEGIN {
}
use Getopt::Long qw(:config no_auto_abbrev);
use List::Util qw(first);
use Slic3r;
$|++;
@ -57,26 +58,37 @@ if ($opt{load}) {
}
# validate command line options
delete $cli_options{$_} for grep !defined $cli_options{$_}, keys %cli_options;
Slic3r::Config->validate_cli(\%cli_options);
# apply command line options
Slic3r::Config->set($_ => $cli_options{$_})
for grep defined $cli_options{$_}, keys %cli_options;
# initialize GUI
my $gui;
if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
$gui = Slic3r::GUI->new;
$gui->{skeinpanel}->load_config($opt{load}[0]) if $opt{load};
}
die $@ if $@ && $opt{gui};
# validate configuration
# apply command line options
Slic3r::Config->set($_ => $cli_options{$_}) for keys %cli_options;
# validate configuration, convert options like --print-center to arrayrefs, init extruders etc.
Slic3r::Config->validate;
# save configuration
Slic3r::Config->save($opt{save}) if $opt{save};
# start GUI
if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
no warnings 'once';
$Slic3r::GUI::SkeinPanel::last_config = $opt{load} ? $opt{load}[0] : undef;
Slic3r::GUI->new->MainLoop;
# apply command line options to GUI as well and start it
if ($gui) {
for my $opt_key (keys %cli_options) {
no warnings 'once';
( $Slic3r::GUI::OptionsGroup::reload_callbacks{$opt_key} || sub {} )->();
my $group = first { $opt_key ~~ @$_ } keys %Slic3r::Groups;
$gui->{skeinpanel}{options_tabs}{$group}->set_dirty(1) if $group;
}
$gui->MainLoop;
exit;
}
die $@ if $@ && $opt{gui};
if (@ARGV) {
while (my $input_file = shift @ARGV) {

BIN
var/Slic3r_192px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
var/arrow_up.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

BIN
var/box.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 555 B

BIN
var/building.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

BIN
var/bullet_black.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 211 B

BIN
var/bullet_blue.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

BIN
var/bullet_white.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

BIN
var/cog.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 512 B

BIN
var/disk.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 620 B

BIN
var/funnel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

BIN
var/hourglass.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

BIN
var/note.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

BIN
var/page_white_go.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

BIN
var/printer_empty.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

BIN
var/shading.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
var/spool.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
var/time.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

BIN
var/wrench.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B