diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm
index 17acd0e48..bd6635b70 100644
--- a/lib/Slic3r.pm
+++ b/lib/Slic3r.pm
@@ -133,6 +133,8 @@ sub parallelize {
 sub thread_cleanup {
     # prevent destruction of shared objects
     no warnings 'redefine';
+    *Slic3r::Config::DESTROY                = sub {};
+    *Slic3r::Config::Print::DESTROY         = sub {};
     *Slic3r::ExPolygon::DESTROY             = sub {};
     *Slic3r::ExPolygon::Collection::DESTROY = sub {};
     *Slic3r::ExtrusionLoop::DESTROY         = sub {};
diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm
index 332ad5314..e722ff9f9 100644
--- a/lib/Slic3r/Config.pm
+++ b/lib/Slic3r/Config.pm
@@ -9,1177 +9,28 @@ use List::Util qw(first);
 our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
     adjust_overhang_flow standby_temperature);
 
-my $serialize_comma     = sub { join ',', @{$_[0]} };
-my $serialize_comma_bool = sub { join ',', map $_ // 0, @{$_[0]} };
-my $deserialize_comma   = sub { [ split /,/, $_[0] ] };
-
-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,
-        full_width => 1,
-        height  => 130,
-        serialize   => sub { join '\n', split /\R/, $_[0] },
-        deserialize => sub { join "\n", split /\\n/, $_[0] },
-        default => '',
-    },
-    'threads' => {
-        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,
-        default => $Slic3r::have_threads ? 2 : 1,
-        readonly => !$Slic3r::have_threads,
-    },
-    'resolution' => {
-        label   => 'Resolution',
-        tooltip => 'Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input.',
-        sidetext => 'mm',
-        cli     => 'resolution=f',
-        type    => 'f',
-        min     => 0,
-        default => 0,
-    },
-
-    # 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,
-        default => '[input_filename_base].gcode',
-    },
-
-    # printer options
-    'print_center' => {
-        label   => 'Print center',
-        tooltip => 'These G-code coordinates are used to center your plater viewport.',
-        sidetext => 'mm',
-        cli     => 'print-center=s',
-        type    => 'point',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [100,100],
-    },
-    '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 makerware sailfish mach3 no-extrusion)],
-        labels  => ['RepRap (Marlin/Sprinter/Repetier)', 'Teacup', 'MakerWare (MakerBot)', 'Sailfish (MakerBot)', 'Mach3/EMC', 'No extrusion'],
-        default => 'reprap',
-    },
-    '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',
-        default => 0,
-    },
-    'use_firmware_retraction' => {
-        label   => 'Use firmware retraction',
-        tooltip => 'This experimental setting uses G10 and G11 commands to have the firmware handle the retraction. This is only supported in recent Marlin.',
-        cli     => 'use-firmware-retraction!',
-        type    => 'bool',
-        default => 0,
-    },
-    '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',
-        default => 'E',
-    },
-    'z_offset' => {
-        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',
-        default => 0,
-    },
-    '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',
-        default => 0,
-    },
-    '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',
-        default => 0,
-    },
-    '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',
-        default => 0,
-    },
-    
-    # extruders options
-    'extruder_offset' => {
-        label   => 'Extruder offset',
-        tooltip => 'If your firmware doesn\'t handle the extruder displacement you need the G-code to take it into account. This option lets you specify the displacement of each extruder with respect to the first one. It expects positive coordinates (they will be subtracted from the XY coordinate).',
-        sidetext => 'mm',
-        cli     => 'extruder-offset=s@',
-        type    => 'point',
-        serialize   => sub { join ',', map { join 'x', @$_ } @{$_[0]} },
-        deserialize => sub { [ map [ split /x/, $_ ], (ref $_[0] eq 'ARRAY') ? @{$_[0]} : (split /,/, $_[0] || '0x0') ] },
-        default => [[0,0]],
-    },
-    'nozzle_diameter' => {
-        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',
-        sidetext => 'mm',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [0.5],
-    },
-    'filament_diameter' => {
-        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',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default     => [3],
-    },
-    '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',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [1],
-    },
-    'temperature' => {
-        label   => 'Other layers',
-        full_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',
-        max     => 400,
-        serialize   => $serialize_comma,
-        deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] },
-        default => [200],
-    },
-    'first_layer_temperature' => {
-        label   => 'First layer',
-        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   => $serialize_comma,
-        deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] },
-        max     => 400,
-        default => [200],
-    },
-    
-    # extruder mapping
-    'perimeter_extruder' => {
-        label   => 'Perimeter extruder',
-        tooltip => 'The extruder to use when printing perimeters.',
-        cli     => 'perimeter-extruder=i',
-        type    => 'i',
-        aliases => [qw(perimeters_extruder)],
-        default => 1,
-    },
-    'infill_extruder' => {
-        label   => 'Infill extruder',
-        tooltip => 'The extruder to use when printing infill.',
-        cli     => 'infill-extruder=i',
-        type    => 'i',
-        default => 1,
-    },
-    'support_material_extruder' => {
-        label   => 'Support material extruder',
-        tooltip => 'The extruder to use when printing support material. This affects brim and raft too.',
-        cli     => 'support-material-extruder=i',
-        type    => 'i',
-        default => 1,
-    },
-    'support_material_interface_extruder' => {
-        label   => 'Support material interface extruder',
-        tooltip => 'The extruder to use when printing support material interface. This affects raft too.',
-        cli     => 'support-material-interface-extruder=i',
-        type    => 'i',
-        default => 1,
-    },
-    
-    # multiple extruder options
-    'ooze_prevention' => {
-        label   => 'Enable',
-        tooltip => 'This option will drop the temperature of the inactive extruders to prevent oozing. It will enable a tall skirt automatically and move extruders outside such skirt when changing temperatures.',
-        cli     => 'ooze-prevention!',
-        type    => 'bool',
-        default => 0,
-    },
-    'standby_temperature_delta' => {
-        label   => 'Temperature variation',
-        tooltip => 'Temperature difference to be applied when an extruder is not active.',
-        sidetext => '∆°C',
-        cli     => 'standby-temperature-delta=i',
-        type    => 'i',
-        min     => -400,
-        max     => 400,
-        default => -5,
-    },
-    
-    # filament options
-    'first_layer_bed_temperature' => {
-        label   => 'First layer',
-        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,
-        default => 0,
-    },
-    'bed_temperature' => {
-        label   => 'Other layers',
-        full_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,
-        default => 0,
-    },
-    
-    # speed options
-    'travel_speed' => {
-        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)],
-        default => 130,
-    },
-    'perimeter_speed' => {
-        label   => 'Perimeters',
-        tooltip => 'Speed for perimeters (contours, aka vertical shells).',
-        sidetext => 'mm/s',
-        cli     => 'perimeter-speed=f',
-        type    => 'f',
-        aliases => [qw(perimeter_feed_rate)],
-        default => 30,
-    },
-    'small_perimeter_speed' => {
-        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',
-        default => 30,
-    },
-    'external_perimeter_speed' => {
-        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',
-        default => '70%',
-    },
-    'infill_speed' => {
-        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)],
-        default => 60,
-    },
-    'solid_infill_speed' => {
-        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)],
-        default => 60,
-    },
-    'top_solid_infill_speed' => {
-        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',
-        default => 50,
-    },
-    'support_material_speed' => {
-        label   => 'Support material',
-        tooltip => 'Speed for printing support material.',
-        sidetext => 'mm/s',
-        cli     => 'support-material-speed=f',
-        type    => 'f',
-        default => 60,
-    },
-    'bridge_speed' => {
-        label   => 'Bridges',
-        tooltip => 'Speed for printing bridges.',
-        sidetext => 'mm/s',
-        cli     => 'bridge-speed=f',
-        type    => 'f',
-        aliases => [qw(bridge_feed_rate)],
-        default => 60,
-    },
-    'gap_fill_speed' => {
-        label   => 'Gap fill',
-        tooltip => 'Speed for filling small gaps using short zigzag moves. Keep this reasonably low to avoid too much shaking and resonance issues. Set zero to disable gaps filling.',
-        sidetext => 'mm/s',
-        cli     => 'gap-fill-speed=f',
-        type    => 'f',
-        default => 20,
-    },
-    'first_layer_speed' => {
-        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',
-        default => '30%',
-    },
-    
-    # acceleration options
-    'default_acceleration' => {
-        label   => 'Default',
-        tooltip => 'This is the acceleration your printer will be reset to after the role-specific acceleration values are used (perimeter/infill). Set zero to prevent resetting acceleration at all.',
-        sidetext => 'mm/s²',
-        cli     => 'default-acceleration=f',
-        type    => 'f',
-        default => 0,
-    },
-    'perimeter_acceleration' => {
-        label   => 'Perimeters',
-        tooltip => 'This is the acceleration your printer will use for perimeters. A high value like 9000 usually gives good results if your hardware is up to the job. Set zero to disable acceleration control for perimeters.',
-        sidetext => 'mm/s²',
-        cli     => 'perimeter-acceleration=f',
-        type    => 'f',
-        default => 0,
-    },
-    'infill_acceleration' => {
-        label   => 'Infill',
-        tooltip => 'This is the acceleration your printer will use for infill. Set zero to disable acceleration control for infill.',
-        sidetext => 'mm/s²',
-        cli     => 'infill-acceleration=f',
-        type    => 'f',
-        default => 0,
-    },
-    'bridge_acceleration' => {
-        label   => 'Bridge',
-        tooltip => 'This is the acceleration your printer will use for bridges. Set zero to disable acceleration control for bridges.',
-        sidetext => 'mm/s²',
-        cli     => 'bridge-acceleration=f',
-        type    => 'f',
-        default => 0,
-    },
-    'first_layer_acceleration' => {
-        label   => 'First layer',
-        tooltip => 'This is the acceleration your printer will use for first layer. Set zero to disable acceleration control for first layer.',
-        sidetext => 'mm/s²',
-        cli     => 'first-layer-acceleration=f',
-        type    => 'f',
-        default => 0,
-    },
-    
-    # accuracy options
-    'layer_height' => {
-        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',
-        default => 0.4,
-    },
-    'first_layer_height' => {
-        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',
-        default => 0.35,
-    },
-    'infill_every_layers' => {
-        label   => 'Combine infill every',
-        full_label   => 'Combine infill every n layers',
-        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',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'infill-every-layers=i',
-        type    => 'i',
-        min     => 1,
-        default => 1,
-    },
-    'solid_infill_every_layers' => {
-        label   => 'Solid infill every',
-        tooltip => 'This feature allows to force a solid layer every given number of layers. Zero to disable.',
-        sidetext => 'layers',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'solid-infill-every-layers=i',
-        type    => 'i',
-        min     => 0,
-        default => 0,
-    },
-    'infill_only_where_needed' => {
-        label   => 'Only infill where needed',
-        tooltip => 'This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material).',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'infill-only-where-needed!',
-        type    => 'bool',
-        default => 0,
-    },
-    'infill_first' => {
-        label   => 'Infill before perimeters',
-        tooltip => 'This option will switch the print order of perimeters and infill, making the latter first.',
-        cli     => 'infill-first!',
-        type    => 'bool',
-        default => 0,
-    },
-    
-    # flow options
-    'extrusion_width' => {
-        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',
-        default => 0,
-    },
-    'first_layer_extrusion_width' => {
-        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 layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'first-layer-extrusion-width=s',
-        type    => 'f',
-        default => '200%',
-    },
-    'perimeter_extrusion_width' => {
-        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 layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'perimeter-extrusion-width=s',
-        type    => 'f',
-        aliases => [qw(perimeters_extrusion_width)],
-        default => 0,
-    },
-    'infill_extrusion_width' => {
-        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 layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'infill-extrusion-width=s',
-        type    => 'f',
-        default => 0,
-    },
-    'solid_infill_extrusion_width' => {
-        label   => 'Solid infill',
-        tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. If expressed as percentage (for example 90%) if will be computed over layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'solid-infill-extrusion-width=s',
-        type    => 'f',
-        default => 0,
-    },
-    'top_infill_extrusion_width' => {
-        label   => 'Top solid infill',
-        tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. If expressed as percentage (for example 90%) if will be computed over layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'top-infill-extrusion-width=s',
-        type    => 'f',
-        default => 0,
-    },
-    'support_material_extrusion_width' => {
-        label   => 'Support material',
-        tooltip => 'Set this to a non-zero value to set a manual extrusion width for support material. If expressed as percentage (for example 90%) if will be computed over layer height.',
-        sidetext => 'mm or % (leave 0 for default)',
-        cli     => 'support-material-extrusion-width=s',
-        type    => 'f',
-        default => 0,
-    },
-    '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',
-        default => 1,
-    },
-    'vibration_limit' => {
-        label   => 'Vibration limit',
-        tooltip => 'This experimental option will slow down those moves hitting the configured frequency limit. The purpose of limiting vibrations is to avoid mechanical resonance. Set zero to disable.',
-        sidetext => 'Hz',
-        cli     => 'vibration-limit=f',
-        type    => 'f',
-        default => 0,
-    },
-    
-    # print options
-    'perimeters' => {
-        label   => 'Perimeters (minimum)',
-        tooltip => 'This option sets the number of perimeters to generate for each layer. Note that Slic3r may increase this number automatically when it detects sloping surfaces which benefit from a higher number of perimeters if the Extra Perimeters option is enabled.',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'perimeters=i',
-        type    => 'i',
-        aliases => [qw(perimeter_offsets)],
-        default => 3,
-    },
-    'solid_layers' => {
-        label   => 'Solid layers',
-        tooltip => 'Number of solid layers to generate on top and bottom surfaces.',
-        cli     => 'solid-layers=i',
-        type    => 'i',
-        shortcut => [qw(top_solid_layers bottom_solid_layers)],
-    },
-    'top_solid_layers' => {
-        label   => 'Top',
-        full_label => 'Top solid layers',
-        tooltip => 'Number of solid layers to generate on top surfaces.',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'top-solid-layers=i',
-        type    => 'i',
-        default => 3,
-    },
-    'bottom_solid_layers' => {
-        label   => 'Bottom',
-        full_label => 'Bottom solid layers',
-        tooltip => 'Number of solid layers to generate on bottom surfaces.',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'bottom-solid-layers=i',
-        type    => 'i',
-        default => 3,
-    },
-    'fill_pattern' => {
-        label   => 'Fill pattern',
-        tooltip => 'Fill pattern for general low-density infill.',
-        scope   => 'object',
-        category => '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)'],
-        default => 'honeycomb',
-    },
-    'solid_fill_pattern' => {
-        label   => 'Top/bottom fill pattern',
-        tooltip => 'Fill pattern for top/bottom infill.',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'solid-fill-pattern=s',
-        type    => 'select',
-        values  => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)],
-        labels  => [qw(rectilinear concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
-        default => 'rectilinear',
-    },
-    'fill_density' => {
-        label   => 'Fill density',
-        tooltip => 'Density of internal infill, expressed in the range 0 - 1.',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'fill-density=f',
-        type    => 'f',
-        default => 0.4,
-    },
-    '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,
-        default => 45,
-    },
-    'solid_infill_below_area' => {
-        label   => 'Solid infill threshold area',
-        tooltip => 'Force solid infill for regions having a smaller area than the specified threshold.',
-        sidetext => 'mm²',
-        scope   => 'object',
-        category => 'Infill',
-        cli     => 'solid-infill-below-area=f',
-        type    => 'f',
-        default => 70,
-    },
-    'extra_perimeters' => {
-        label   => 'Extra perimeters if needed',
-        tooltip => 'Add more perimeters when needed for avoiding gaps in sloping walls.',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'extra-perimeters!',
-        type    => 'bool',
-        default => 1,
-    },
-    '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',
-        default => 0,
-    },
-    'start_perimeters_at_concave_points' => {
-        label   => 'Concave points',
-        tooltip => 'Prefer to start perimeters at a concave point.',
-        cli     => 'start-perimeters-at-concave-points!',
-        type    => 'bool',
-        default => 0,
-    },
-    'start_perimeters_at_non_overhang' => {
-        label   => 'Non-overhang points',
-        tooltip => 'Prefer to start perimeters at non-overhanging points.',
-        cli     => 'start-perimeters-at-non-overhang!',
-        type    => 'bool',
-        default => 0,
-    },
-    'thin_walls' => {
-        label   => 'Detect thin walls',
-        tooltip => 'Detect single-width walls (parts where two extrusions don\'t fit and we need to collapse them into a single trace).',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'thin-walls!',
-        type    => 'bool',
-        default => 1,
-    },
-    'overhangs' => {
-        label   => 'Detect bridging perimeters',
-        tooltip => 'Experimental option to adjust flow for overhangs (bridge flow will be used), to apply bridge speed to them and enable fan.',
-        scope   => 'object',
-        category => 'Layers and Perimeters',
-        cli     => 'overhangs!',
-        type    => 'bool',
-        default => 1,
-    },
-    'avoid_crossing_perimeters' => {
-        label   => 'Avoid crossing perimeters',
-        tooltip => 'Optimize travel moves in order to minimize the crossing of perimeters. This is mostly useful with Bowden extruders which suffer from oozing. This feature slows down both the print and the G-code generation.',
-        cli     => 'avoid-crossing-perimeters!',
-        type    => 'bool',
-        default => 0,
-    },
-    'external_perimeters_first' => {
-        label   => 'External perimeters first',
-        tooltip => 'Print contour perimeters from the outermost one to the innermost one instead of the default inverse order.',
-        cli     => 'external-perimeters-first!',
-        type    => 'bool',
-        default => 0,
-    },
-    'spiral_vase' => {
-        label   => 'Spiral vase',
-        tooltip => 'This experimental feature will raise Z gradually while printing a single-walled object in order to remove any visible seam. By enabling this option other settings will be overridden to enforce a single perimeter, no infill, no top solid layers, no support material. You can still set any number of bottom solid layers as well as skirt/brim loops. It won\'t work when printing more than an object.',
-        cli     => 'spiral-vase!',
-        type    => 'bool',
-        default => 0,
-    },
-    'only_retract_when_crossing_perimeters' => {
-        label   => 'Only retract when crossing perimeters',
-        tooltip => 'Disables retraction when the travel path does not exceed the upper layer\'s perimeters (and thus any ooze will be probably invisible).',
-        cli     => 'only-retract-when-crossing-perimeters!',
-        type    => 'bool',
-        default => 1,
-    },
-    'support_material' => {
-        label   => 'Generate support material',
-        scope   => 'object',
-        category => 'Support material',
-        tooltip => 'Enable support material generation.',
-        cli     => 'support-material!',
-        type    => 'bool',
-        default => 0,
-    },
-    'support_material_threshold' => {
-        label   => 'Overhang threshold',
-        tooltip => 'Support material will not be generated for overhangs whose slope angle (90° = vertical) is above the given threshold. In other words, this value represent the most horizontal slope (measured from the horizontal plane) that you can print without support material. Set to zero for automatic detection (recommended).',
-        sidetext => '°',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'support-material-threshold=i',
-        type    => 'i',
-        default => 0,
-    },
-    'support_material_pattern' => {
-        label   => 'Pattern',
-        tooltip => 'Pattern used to generate support material.',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'support-material-pattern=s',
-        type    => 'select',
-        values  => [qw(rectilinear rectilinear-grid honeycomb)],
-        labels  => ['rectilinear', 'rectilinear grid', 'honeycomb'],
-        default => 'honeycomb',
-    },
-    'support_material_spacing' => {
-        label   => 'Pattern spacing',
-        tooltip => 'Spacing between support material lines.',
-        sidetext => 'mm',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'support-material-spacing=f',
-        type    => 'f',
-        default => 2.5,
-    },
-    'support_material_angle' => {
-        label   => 'Pattern angle',
-        tooltip => 'Use this setting to rotate the support material pattern on the horizontal plane.',
-        scope   => 'object',
-        category => 'Support material',
-        sidetext => '°',
-        cli     => 'support-material-angle=i',
-        type    => 'i',
-        default => 0,
-    },
-    'support_material_interface_layers' => {
-        label   => 'Interface layers',
-        tooltip => 'Number of interface layers to insert between the object(s) and support material.',
-        sidetext => 'layers',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'support-material-interface-layers=i',
-        type    => 'i',
-        default => 3,
-    },
-    'support_material_interface_spacing' => {
-        label   => 'Interface pattern spacing',
-        tooltip => 'Spacing between interface lines. Set zero to get a solid interface.',
-        scope   => 'object',
-        category => 'Support material',
-        sidetext => 'mm',
-        cli     => 'support-material-interface-spacing=f',
-        type    => 'f',
-        default => 0,
-    },
-    'support_material_enforce_layers' => {
-        label   => 'Enforce support for the first',
-        full_label   => 'Enforce support for the first n layers',
-        tooltip => 'Generate support material for the specified number of layers counting from bottom, regardless of whether normal support material is enabled or not and regardless of any angle threshold. This is useful for getting more adhesion of objects having a very thin or poor footprint on the build plate.',
-        sidetext => 'layers',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'support-material-enforce-layers=f',
-        type    => 'i',
-        default => 0,
-    },
-    'raft_layers' => {
-        label   => 'Raft layers',
-        tooltip => 'The object will be raised by this number of layers, and support material will be generated under it.',
-        sidetext => 'layers',
-        scope   => 'object',
-        category => 'Support material',
-        cli     => 'raft-layers=i',
-        type    => 'i',
-        default => 0,
-    },
-    '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,
-        full_width => 1,
-        height  => 120,
-        serialize   => sub { join '\n', split /\R+/, $_[0] },
-        deserialize => sub { join "\n", split /\\n/, $_[0] },
-        default => <<'END',
-G28 ; home all axes
-G1 Z5 F5000 ; lift nozzle
-END
-    },
-    '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,
-        full_width => 1,
-        height  => 120,
-        serialize   => sub { join '\n', split /\R+/, $_[0] },
-        deserialize => sub { join "\n", split /\\n/, $_[0] },
-        default => <<'END',
-M104 S0 ; turn off temperature
-G28 X0  ; home X axis
-M84     ; disable motors
-END
-    },
-    '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,
-        full_width => 1,
-        height  => 50,
-        serialize   => sub { join '\n', split /\R+/, $_[0] },
-        deserialize => sub { join "\n", split /\\n/, $_[0] },
-        default => '',
-    },
-    'toolchange_gcode' => {
-        label   => 'Tool change G-code',
-        tooltip => 'This custom code is inserted at every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].',
-        cli     => 'toolchange-gcode=s',
-        type    => 's',
-        multiline => 1,
-        full_width => 1,
-        height  => 50,
-        serialize   => sub { join '\n', split /\R+/, $_[0] },
-        deserialize => sub { join "\n", split /\\n/, $_[0] },
-        default => '',
-    },
-    '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,
-        full_width => 1,
-        height  => 60,
-        serialize   => sub { join '; ', @{$_[0]} },
-        deserialize => sub { [ split /\s*(?:;|\R)\s*/s, $_[0] ] },
-        default => [],
-    },
-    
-    # retraction options
-    'retract_length' => {
-        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',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [1],
-    },
-    'retract_speed' => {
-        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,
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [30],
-    },
-    'retract_restart_extra' => {
-        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',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [0],
-    },
-    'retract_before_travel' => {
-        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',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [2],
-    },
-    'retract_lift' => {
-        label   => 'Lift Z',
-        tooltip => 'If you set this to a positive value, Z is quickly raised every time a retraction is triggered. When using multiple extruders, only the setting for the first extruder will be considered.',
-        sidetext => 'mm',
-        cli     => 'retract-lift=f@',
-        type    => 'f',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [0],
-    },
-    'retract_layer_change' => {
-        label   => 'Retract on layer change',
-        tooltip => 'This flag enforces a retraction whenever a Z move is done.',
-        cli     => 'retract-layer-change!',
-        type    => 'bool',
-        serialize   => $serialize_comma_bool,
-        deserialize => $deserialize_comma,
-        default => [1],
-    },
-    'wipe' => {
-        label   => 'Wipe while retracting',
-        tooltip => 'This flag will move the nozzle while retracting to minimize the possible blob on leaky extruders.',
-        cli     => 'wipe!',
-        type    => 'bool',
-        serialize   => $serialize_comma_bool,
-        deserialize => $deserialize_comma,
-        default => [0],
-    },
-    'retract_length_toolchange' => {
-        label   => 'Length',
-        tooltip => 'When retraction is triggered before changing tool, 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-toolchange=f@',
-        type    => 'f',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [10],
-    },
-    'retract_restart_extra_toolchange' => {
-        label   => 'Extra length on restart',
-        tooltip => 'When the retraction is compensated after changing tool, the extruder will push this additional amount of filament.',
-        sidetext => 'mm',
-        cli     => 'retract-restart-extra-toolchange=f@',
-        type    => 'f',
-        serialize   => $serialize_comma,
-        deserialize => $deserialize_comma,
-        default => [0],
-    },
-    
-    # cooling options
-    'cooling' => {
-        label   => 'Enable auto cooling',
-        tooltip => 'This flag enables the automatic cooling logic that adjusts print speed and fan speed according to layer printing time.',
-        cli     => 'cooling!',
-        type    => 'bool',
-        default => 1,
-    },
-    'min_fan_speed' => {
-        label   => 'Min',
-        tooltip => 'This setting represents the minimum PWM your fan needs to work.',
-        sidetext => '%',
-        cli     => 'min-fan-speed=i',
-        type    => 'i',
-        max     => 100,
-        default => 35,
-    },
-    'max_fan_speed' => {
-        label   => 'Max',
-        tooltip => 'This setting represents the maximum speed of your fan.',
-        sidetext => '%',
-        cli     => 'max-fan-speed=i',
-        type    => 'i',
-        max     => 100,
-        default => 100,
-    },
-    'bridge_fan_speed' => {
-        label   => 'Bridges fan speed',
-        tooltip => 'This fan speed is enforced during all bridges and overhangs.',
-        sidetext => '%',
-        cli     => 'bridge-fan-speed=i',
-        type    => 'i',
-        max     => 100,
-        default => 100,
-    },
-    'fan_below_layer_time' => {
-        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,
-        default => 60,
-    },
-    'slowdown_below_layer_time' => {
-        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,
-        default => 30,
-    },
-    'min_print_speed' => {
-        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,
-        default => 10,
-    },
-    'disable_fan_first_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,
-        default => 1,
-    },
-    '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',
-        default => 0,
-    },
-    
-    # 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',
-        default => 1,
-    },
-    'min_skirt_length' => {
-        label   => 'Minimum extrusion length',
-        tooltip => 'Generate no less than the number of skirt loops required to consume the specified amount of filament on the bottom layer. For multi-extruder machines, this minimum applies to each extruder.',
-        sidetext => 'mm',
-        cli     => 'min-skirt-length=f',
-        type    => 'f',
-        default => 0,
-        min     => 0,
-    },
-    'skirt_distance' => {
-        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',
-        default => 6,
-    },
-    'skirt_height' => {
-        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',
-        default => 1,
-    },
-    'brim_width' => {
-        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',
-        default => 0,
-    },
-    
-    # transform options
-    'scale' => {
-        label   => 'Scale',
-        cli     => 'scale=f',
-        type    => 'f',
-        default => 1,
-    },
-    'rotate' => {
-        label   => 'Rotate',
-        sidetext => '°',
-        cli     => 'rotate=i',
-        type    => 'i',
-        max     => 359,
-        default => 0,
-    },
-    'duplicate' => {
-        label   => 'Copies (autoarrange)',
-        cli     => 'duplicate=i',
-        type    => 'i',
-        min     => 1,
-        default => 1,
-    },
-    'bed_size' => {
-        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   => $serialize_comma,
-        deserialize => sub { [ split /[,x]/, $_[0] ] },
-        default => [200,200],
-    },
-    'duplicate_grid' => {
-        label   => 'Copies (grid)',
-        cli     => 'duplicate-grid=s',
-        type    => 'point',
-        serialize   => $serialize_comma,
-        deserialize => sub { [ split /[,x]/, $_[0] ] },
-        default => [1,1],
-    },
-    'duplicate_distance' => {
-        label   => 'Distance between copies',
-        tooltip => 'Distance used for the auto-arrange feature of the plater.',
-        sidetext => 'mm',
-        cli     => 'duplicate-distance=f',
-        type    => 'f',
-        aliases => [qw(multiply_distance)],
-        default => 6,
-    },
-    
-    # sequential printing options
-    'complete_objects' => {
-        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',
-        default => 0,
-    },
-    'extruder_clearance_radius' => {
-        label   => '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    => 'f',
-        default => 20,
-    },
-    'extruder_clearance_height' => {
-        label   => '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    => 'f',
-        default => 20,
-    },
-};
+our $Options = print_config_def();
 
 # generate accessors
-if (eval "use Class::XSAccessor; 1") {
-    Class::XSAccessor->import(
-        getters => { map { $_ => $_ } keys %$Options },
-    );
-} else {
+{
     no strict 'refs';
     for my $opt_key (keys %$Options) {
-        *{$opt_key} = sub { $_[0]{$opt_key} };
+        *{$opt_key} = sub { $_[0]->get($opt_key) };
     }
 }
 
-sub new {
-    my $class = shift;
-    my %args = @_;
-    
-    my $self = bless {}, $class;
-    $self->apply(%args);
-    return $self;
-}
-
 sub new_from_defaults {
     my $class = shift;
+    my (@opt_keys) = @_;
     
-    return $class->new(
-        map { $_ => $Options->{$_}{default} }
-            grep !$Options->{$_}{shortcut},
-            (@_ ? @_ : keys %$Options)
-    );
+    my $self = $class->new;
+    my $defaults = Slic3r::Config::Print->new;
+    if (@opt_keys) {
+        $self->set($_, $defaults->get($_)) for @opt_keys;
+    } else {
+        $self->apply_static($defaults);
+    }
+    return $self;
 }
 
 sub new_from_cli {
@@ -1201,10 +52,16 @@ sub new_from_cli {
         }
     }
     
-    $args{$_} = $Options->{$_}{deserialize}->($args{$_})
-        for grep exists $args{$_}, qw(print_center bed_size duplicate_grid extruder_offset retract_layer_change wipe);
+    my $self = $class->new;
+    foreach my $opt_key (keys %args) {
+        if ($opt_key =~ /^(?:print_center|bed_size|duplicate_grid|extruder_offset|retract_layer_change|wipe)$/) {
+            $self->set_deserialize($opt_key, $args{$opt_key});
+        } else {
+            $self->set($opt_key, $args{$opt_key});
+        }
+    }
     
-    return $class->new(%args);
+    return $self;
 }
 
 sub merge {
@@ -1220,21 +77,20 @@ sub load {
     
     my $ini = __PACKAGE__->read_ini($file);
     my $config = __PACKAGE__->new;
-    $config->set($_, $ini->{_}{$_}, 1) for keys %{$ini->{_}};
+    foreach my $opt_key (keys %{$ini->{_}}) {
+        print "key: $opt_key\n";
+        ($opt_key, my $value) = handle_legacy($opt_key, $ini->{_}{$opt_key});
+        next if !defined $opt_key;
+        $config->set_deserialize($opt_key, $value);
+    }
     return $config;
 }
 
-sub apply {
-    my $self = shift;
-    my %args = @_ == 1 ? %{$_[0]} : @_; # accept a single Config object too
-    
-    $self->set($_, $args{$_}) for keys %args;
-}
-
 sub clone {
     my $self = shift;
-    my $new = __PACKAGE__->new(%$self);
-    $new->{$_} = [@{$new->{$_}}] for grep { ref $new->{$_} eq 'ARRAY' } keys %$new;
+    
+    my $new = __PACKAGE__->new;
+    $new->apply($self);
     return $new;
 }
 
@@ -1242,26 +98,17 @@ sub get_value {
     my $self = shift;
     my ($opt_key) = @_;
     
-    no strict 'refs';
-    my $value = $self->get($opt_key);
-    $value = $self->get_value($Options->{$opt_key}{ratio_over}) * $1/100
-        if $Options->{$opt_key}{ratio_over} && $value =~ /^(\d+(?:\.\d+)?)%$/;
-    return $value;
+    return $Options->{$opt_key}{ratio_over}
+        ? $self->get_abs_value($opt_key)
+        : $self->get($opt_key);
 }
 
-sub get {
+sub handle_legacy {
     my $self = shift;
-    my ($opt_key) = @_;
-    
-    return $self->{$opt_key};
-}
-
-sub set {
-    my $self = shift;
-    my ($opt_key, $value, $deserialize) = @_;
+    my ($opt_key, $value) = @_;
     
     # handle legacy options
-    return if first { $_ eq $opt_key } @Ignore;
+    return ($opt_key, $value) if first { $_ eq $opt_key } @Ignore;
     if ($opt_key =~ /^(extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) {
         $opt_key = $1;
         $opt_key =~ s/^bottom_layer_speed$/first_layer_speed/;
@@ -1289,46 +136,25 @@ sub set {
         my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options;
         if (!@keys) {
             warn "Unknown option $opt_key\n";
-            return;
+            return ();
         }
         $opt_key = $keys[0];
     }
     
-    # clone arrayrefs
-    $value = [@$value] if ref $value eq 'ARRAY';
-    
-    # deserialize if requested
-    $value = $Options->{$opt_key}{deserialize}->($value)
-        if $deserialize && $Options->{$opt_key}{deserialize};
-    
-    $self->{$opt_key} = $value;
-    
-    if ($Options->{$opt_key}{shortcut}) {
-        $self->set($_, $value, $deserialize) for @{$Options->{$opt_key}{shortcut}};
-    }
+    return ($opt_key, $value);
 }
 
 sub set_ifndef {
     my $self = shift;
     my ($opt_key, $value, $deserialize) = @_;
     
-    $self->set($opt_key, $value, $deserialize)
-        if !defined $self->get($opt_key);
-}
-
-sub has {
-    my $self = shift;
-    my ($opt_key) = @_;
-    return exists $self->{$opt_key};
-}
-
-sub serialize {
-    my $self = shift;
-    my ($opt_key) = @_;
-    
-    my $value = $self->get($opt_key);
-    $value = $Options->{$opt_key}{serialize}->($value) if $Options->{$opt_key}{serialize};
-    return $value;
+    if (!$self->has($opt_key)) {
+        if ($deserialize) {
+            $self->set_deserialize($opt_key, $value);
+        } else {
+            $self->set($opt_key, $value);
+        }
+    }
 }
 
 sub save {
@@ -1336,9 +162,8 @@ sub save {
     my ($file) = @_;
     
     my $ini = { _ => {} };
-    foreach my $opt_key (sort keys %$self) {
+    foreach my $opt_key (sort @{$self->get_keys}) {
         next if $Options->{$opt_key}{shortcut};
-        next if $Options->{$opt_key}{gui_only};
         $ini->{_}{$opt_key} = $self->serialize($opt_key);
     }
     __PACKAGE__->write_ini($file, $ini);
@@ -1348,7 +173,6 @@ sub setenv {
     my $self = shift;
     
     foreach my $opt_key (sort keys %$Options) {
-        next if $Options->{$opt_key}{gui_only};
         $ENV{"SLIC3R_" . uc $opt_key} = $self->serialize($opt_key);
     }
 }
@@ -1360,8 +184,6 @@ sub validate {
     # -j, --threads
     die "Invalid value for --threads\n"
         if $self->threads < 1;
-    die "Your perl wasn't built with multithread support\n"
-        if $self->threads > 1 && !$Slic3r::have_threads;
 
     # --layer-height
     die "Invalid value for --layer-height\n"
diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm
index 61a3b7a54..d849405ba 100644
--- a/lib/Slic3r/GUI/OptionsGroup.pm
+++ b/lib/Slic3r/GUI/OptionsGroup.pm
@@ -381,9 +381,17 @@ sub _set_config {
     my ($opt_key, $index, $value) = @_;
     
     my ($get_m, $serialized) = $self->_config_methods($opt_key, $index);
-    defined $index
-        ? $self->config->$get_m($opt_key)->[$index] = $value
-        : $self->config->set($opt_key, $value, $serialized);
+    if (defined $index) {
+        my $values = $self->config->$get_m($opt_key);
+        $values->[$index] = $value;
+        $self->config->set($opt_key, $values);
+    } else {
+        if ($serialized) {
+            $self->config->set_deserialize($opt_key, $value);
+        } else {
+            $self->config->set($opt_key, $value);
+        }
+    }
 }
 
 sub _config_methods {
diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm
index a566c36c2..58647851f 100644
--- a/lib/Slic3r/GUI/Plater.pm
+++ b/lib/Slic3r/GUI/Plater.pm
@@ -733,6 +733,9 @@ sub export_gcode {
             catch_error => sub { Slic3r::GUI::catch_error($self, @_) && $self->on_export_failed },
         );
     }
+    
+    # this method gets executed in a separate thread by wxWidgets since it's a button handler
+    Slic3r::thread_cleanup() if $Slic3r::have_threads;
 }
 
 sub export_gcode2 {
@@ -802,6 +805,9 @@ sub export_stl {
     my $output_file = $self->_get_export_file('STL') or return;
     Slic3r::Format::STL->write_file($output_file, $self->{model}, binary => 1);
     $self->statusbar->SetStatusText("STL file exported to $output_file");
+    
+    # this method gets executed in a separate thread by wxWidgets since it's a button handler
+    Slic3r::thread_cleanup() if $Slic3r::have_threads;
 }
 
 sub export_amf {
@@ -810,6 +816,9 @@ sub export_amf {
     my $output_file = $self->_get_export_file('AMF') or return;
     Slic3r::Format::AMF->write_file($output_file, $self->{model});
     $self->statusbar->SetStatusText("AMF file exported to $output_file");
+    
+    # this method gets executed in a separate thread by wxWidgets since it's a menu handler
+    Slic3r::thread_cleanup() if $Slic3r::have_threads;
 }
 
 sub _get_export_file {
@@ -853,7 +862,9 @@ sub make_thumbnail {
     };
     
     @_ = ();
-    $Slic3r::have_threads ? threads->create($cb)->detach : $cb->();
+    $Slic3r::have_threads
+        ? threads->create(sub { $cb->(); Slic3r::thread_cleanup(); })->detach
+        : $cb->();
 }
 
 sub on_thumbnail_made {
diff --git a/lib/Slic3r/GUI/SkeinPanel.pm b/lib/Slic3r/GUI/SkeinPanel.pm
index d48818313..fd33a1b9a 100644
--- a/lib/Slic3r/GUI/SkeinPanel.pm
+++ b/lib/Slic3r/GUI/SkeinPanel.pm
@@ -312,7 +312,7 @@ sub load_config {
     my ($config) = @_;
     
     foreach my $tab (values %{$self->{options_tabs}}) {
-        $tab->set_value($_, $config->$_) for keys %$config;
+        $tab->set_value($_, $config->$_) for @{$config->get_keys};
     }
 }
 
diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm
index 02fcf6ad4..8a0426117 100644
--- a/lib/Slic3r/GUI/Tab.pm
+++ b/lib/Slic3r/GUI/Tab.pm
@@ -291,7 +291,8 @@ sub set_value {
 sub reload_values {
     my $self = shift;
     
-    $self->set_value($_, $self->{config}->get($_)) for keys %{$self->{config}};
+    $self->set_value($_, $self->{config}->get($_))
+        for @{$self->{config}->get_keys};
 }
 
 sub update_tree {
@@ -735,7 +736,9 @@ sub config {
     
     # remove all unused values
     foreach my $opt_key ($self->_extruder_options) {
-        splice @{ $config->{$opt_key} }, $self->{extruders_count};
+        my $values = $config->get($opt_key);
+        splice @$values, $self->{extruders_count};
+        $config->set($opt_key, $values);
     }
     
     return $config;
diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm
index 5c30f84a4..a0f7d1dab 100644
--- a/lib/Slic3r/Print.pm
+++ b/lib/Slic3r/Print.pm
@@ -925,13 +925,13 @@ sub write_gcode {
             $extruder->absolute_E, $extruder->extruded_volume/1000;
     }
     
-    if ($Slic3r::Config->gcode_comments) {
+    if ($self->config->gcode_comments) {
         # append full config
         print $fh "\n";
-        foreach my $opt_key (sort keys %{$Slic3r::Config}) {
+        foreach my $opt_key (sort @{$self->config->get_keys}) {
             next if $Slic3r::Config::Options->{$opt_key}{shortcut};
             next if $Slic3r::Config::Options->{$opt_key}{gui_only};
-            printf $fh "; %s = %s\n", $opt_key, $Slic3r::Config->serialize($opt_key);
+            printf $fh "; %s = %s\n", $opt_key, $self->config->serialize($opt_key);
         }
     }
     
diff --git a/slic3r.pl b/slic3r.pl
index 00d99409d..c9ea4c5ef 100755
--- a/slic3r.pl
+++ b/slic3r.pl
@@ -187,7 +187,7 @@ if (@ARGV) {  # slicing from command line
 sub usage {
     my ($exit_code) = @_;
     
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config->new_from_defaults->as_hash;
     
     my $j = '';
     if ($Slic3r::have_threads) {
diff --git a/xs/MANIFEST b/xs/MANIFEST
index 903b39deb..e37aaa62d 100644
--- a/xs/MANIFEST
+++ b/xs/MANIFEST
@@ -12,6 +12,8 @@ src/clipper.cpp
 src/clipper.hpp
 src/ClipperUtils.cpp
 src/ClipperUtils.hpp
+src/Config.cpp
+src/Config.hpp
 src/ExPolygon.cpp
 src/ExPolygon.hpp
 src/ExPolygonCollection.cpp
@@ -35,6 +37,8 @@ src/Polyline.cpp
 src/Polyline.hpp
 src/PolylineCollection.cpp
 src/PolylineCollection.hpp
+src/PrintConfig.cpp
+src/PrintConfig.hpp
 src/PrintState.cpp
 src/PrintState.hpp
 src/ppport.h
@@ -60,7 +64,9 @@ t/11_clipper.t
 t/12_extrusionpathcollection.t
 t/13_polylinecollection.t
 t/14_geometry.t
+t/15_config.t
 xsp/Clipper.xsp
+xsp/Config.xsp
 xsp/ExPolygon.xsp
 xsp/ExPolygonCollection.xsp
 xsp/ExtrusionEntityCollection.xsp
diff --git a/xs/src/Config.cpp b/xs/src/Config.cpp
new file mode 100644
index 000000000..c97eb51cd
--- /dev/null
+++ b/xs/src/Config.cpp
@@ -0,0 +1,257 @@
+#include "Config.hpp"
+
+namespace Slic3r {
+
+bool
+ConfigBase::has(const t_config_option_key opt_key) {
+    return (this->option(opt_key, false) != NULL);
+}
+
+void
+ConfigBase::apply(ConfigBase &other, bool ignore_nonexistent) {
+    // get list of option keys to apply
+    t_config_option_keys opt_keys;
+    other.keys(&opt_keys);
+    
+    // loop through options and apply them
+    for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
+        ConfigOption* my_opt = this->option(*it, true);
+        if (my_opt == NULL) {
+            if (ignore_nonexistent == false) throw "Attempt to apply non-existent option";
+            continue;
+        }
+        
+        // not the most efficient way, but easier than casting pointers to subclasses
+        my_opt->deserialize( other.option(*it)->serialize() );
+    }
+}
+
+std::string
+ConfigBase::serialize(const t_config_option_key opt_key) {
+    ConfigOption* opt = this->option(opt_key);
+    assert(opt != NULL);
+    return opt->serialize();
+}
+
+void
+ConfigBase::set_deserialize(const t_config_option_key opt_key, std::string str) {
+    ConfigOption* opt = this->option(opt_key);
+    assert(opt != NULL);
+    opt->deserialize(str);
+}
+
+double
+ConfigBase::get_abs_value(const t_config_option_key opt_key) {
+    // get option definition
+    assert(this->def->count(opt_key) != 0);
+    ConfigOptionDef* def = &(*this->def)[opt_key];
+    assert(def->type == coFloatOrPercent);
+    
+    // get stored option value
+    ConfigOptionFloatOrPercent* opt = dynamic_cast<ConfigOptionFloatOrPercent*>(this->option(opt_key));
+    assert(opt != NULL);
+    
+    // compute absolute value
+    if (opt->percent) {
+        ConfigOptionFloat* optbase = dynamic_cast<ConfigOptionFloat*>(this->option(def->ratio_over));
+        if (optbase == NULL) throw "ratio_over option not found";
+        return optbase->value * opt->value / 100;
+    } else {
+        return opt->value;
+    }
+}
+
+#ifdef SLIC3RXS
+SV*
+ConfigBase::as_hash() {
+    HV* hv = newHV();
+    
+    t_config_option_keys opt_keys;
+    this->keys(&opt_keys);
+    
+    for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it)
+        (void)hv_store( hv, it->c_str(), it->length(), this->get(*it), 0 );
+    
+    return newRV_noinc((SV*)hv);
+}
+
+SV*
+ConfigBase::get(t_config_option_key opt_key) {
+    ConfigOption* opt = this->option(opt_key);
+    if (opt == NULL) return &PL_sv_undef;
+    if (ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt)) {
+        return newSVnv(optv->value);
+    } else if (ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt)) {
+        AV* av = newAV();
+        av_fill(av, optv->values.size()-1);
+        for (std::vector<double>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
+            av_store(av, it - optv->values.begin(), newSVnv(*it));
+        return newRV_noinc((SV*)av);
+    } else if (ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt)) {
+        return newSViv(optv->value);
+    } else if (ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt)) {
+        AV* av = newAV();
+        av_fill(av, optv->values.size()-1);
+        for (std::vector<int>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
+            av_store(av, it - optv->values.begin(), newSViv(*it));
+        return newRV_noinc((SV*)av);
+    } else if (ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt)) {
+        // we don't serialize() because that would escape newlines
+        return newSVpvn(optv->value.c_str(), optv->value.length());
+    } else if (ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt)) {
+        AV* av = newAV();
+        av_fill(av, optv->values.size()-1);
+        for (std::vector<std::string>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
+            av_store(av, it - optv->values.begin(), newSVpvn(it->c_str(), it->length()));
+        return newRV_noinc((SV*)av);
+    } else if (ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt)) {
+        return optv->point.to_SV_pureperl();
+    } else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
+        AV* av = newAV();
+        av_fill(av, optv->points.size()-1);
+        for (Pointfs::iterator it = optv->points.begin(); it != optv->points.end(); ++it)
+            av_store(av, it - optv->points.begin(), it->to_SV_pureperl());
+        return newRV_noinc((SV*)av);
+    } else if (ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt)) {
+        return newSViv(optv->value ? 1 : 0);
+    } else if (ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt)) {
+        AV* av = newAV();
+        av_fill(av, optv->values.size()-1);
+        for (std::vector<bool>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
+            av_store(av, it - optv->values.begin(), newSViv(*it ? 1 : 0));
+        return newRV_noinc((SV*)av);
+    } else {
+        std::string serialized = opt->serialize();
+        return newSVpvn(serialized.c_str(), serialized.length());
+    }
+}
+
+void
+ConfigBase::set(t_config_option_key opt_key, SV* value) {
+    ConfigOption* opt = this->option(opt_key, true);
+    if (opt == NULL) CONFESS("Trying to set non-existing option");
+    
+    if (ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt)) {
+        optv->value = SvNV(value);
+    } else if (ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt)) {
+        optv->values.clear();
+        AV* av = (AV*)SvRV(value);
+        const size_t len = av_len(av)+1;
+        for (size_t i = 0; i < len; i++) {
+            SV** elem = av_fetch(av, i, 0);
+            optv->values.push_back(SvNV(*elem));
+        }
+    } else if (ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt)) {
+        optv->value = SvIV(value);
+    } else if (ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt)) {
+        optv->values.clear();
+        AV* av = (AV*)SvRV(value);
+        const size_t len = av_len(av)+1;
+        for (size_t i = 0; i < len; i++) {
+            SV** elem = av_fetch(av, i, 0);
+            optv->values.push_back(SvIV(*elem));
+        }
+    } else if (ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt)) {
+        optv->value = std::string(SvPV_nolen(value), SvCUR(value));
+    } else if (ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt)) {
+        optv->values.clear();
+        AV* av = (AV*)SvRV(value);
+        const size_t len = av_len(av)+1;
+        for (size_t i = 0; i < len; i++) {
+            SV** elem = av_fetch(av, i, 0);
+            optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem)));
+        }
+    } else if (ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt)) {
+        optv->point.from_SV(value);
+    } else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
+        optv->points.clear();
+        AV* av = (AV*)SvRV(value);
+        const size_t len = av_len(av)+1;
+        for (size_t i = 0; i < len; i++) {
+            SV** elem = av_fetch(av, i, 0);
+            Pointf point;
+            point.from_SV(*elem);
+            optv->points.push_back(point);
+        }
+    } else if (ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt)) {
+        optv->value = SvTRUE(value);
+    } else if (ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt)) {
+        optv->values.clear();
+        AV* av = (AV*)SvRV(value);
+        const size_t len = av_len(av)+1;
+        for (size_t i = 0; i < len; i++) {
+            SV** elem = av_fetch(av, i, 0);
+            optv->values.push_back(SvTRUE(*elem));
+        }
+    } else {
+        opt->deserialize( std::string(SvPV_nolen(value)) );
+    }
+}
+#endif
+
+DynamicConfig::~DynamicConfig () {
+    for (t_options_map::iterator it = this->options.begin(); it != this->options.end(); ++it) {
+        ConfigOption* opt = it->second;
+        if (opt != NULL) delete opt;
+    }
+}
+
+ConfigOption*
+DynamicConfig::option(const t_config_option_key opt_key, bool create) {
+    if (this->options.count(opt_key) == 0) {
+        if (create) {
+            ConfigOptionDef* optdef = &(*this->def)[opt_key];
+            ConfigOption* opt;
+            if (optdef->type == coFloat) {
+                opt = new ConfigOptionFloat ();
+            } else if (optdef->type == coFloats) {
+                opt = new ConfigOptionFloats ();
+            } else if (optdef->type == coInt) {
+                opt = new ConfigOptionInt ();
+            } else if (optdef->type == coInts) {
+                opt = new ConfigOptionInts ();
+            } else if (optdef->type == coString) {
+                opt = new ConfigOptionString ();
+            } else if (optdef->type == coStrings) {
+                opt = new ConfigOptionStrings ();
+            } else if (optdef->type == coFloatOrPercent) {
+                opt = new ConfigOptionFloatOrPercent ();
+            } else if (optdef->type == coPoint) {
+                opt = new ConfigOptionPoint ();
+            } else if (optdef->type == coPoints) {
+                opt = new ConfigOptionPoints ();
+            } else if (optdef->type == coBool) {
+                opt = new ConfigOptionBool ();
+            } else if (optdef->type == coBools) {
+                opt = new ConfigOptionBools ();
+            } else if (optdef->type == coEnum) {
+                ConfigOptionEnumGeneric* optv = new ConfigOptionEnumGeneric ();
+                optv->keys_map = &optdef->enum_keys_map;
+                opt = static_cast<ConfigOption*>(optv);
+            } else {
+                throw "Unknown option type";
+            }
+            this->options[opt_key] = opt;
+            return opt;
+        } else {
+            return NULL;
+        }
+    }
+    return this->options[opt_key];
+}
+
+void
+DynamicConfig::keys(t_config_option_keys *keys) {
+    for (t_options_map::const_iterator it = this->options.begin(); it != this->options.end(); ++it)
+        keys->push_back(it->first);
+}
+
+void
+StaticConfig::keys(t_config_option_keys *keys) {
+    for (t_optiondef_map::const_iterator it = this->def->begin(); it != this->def->end(); ++it) {
+        ConfigOption* opt = this->option(it->first);
+        if (opt != NULL) keys->push_back(it->first);
+    }
+}
+
+}
diff --git a/xs/src/Config.hpp b/xs/src/Config.hpp
new file mode 100644
index 000000000..e222651c8
--- /dev/null
+++ b/xs/src/Config.hpp
@@ -0,0 +1,427 @@
+#ifndef slic3r_Config_hpp_
+#define slic3r_Config_hpp_
+
+#include <myinit.h>
+#include <map>
+#include <sstream>
+#include <climits>
+#include <cstdio>
+#include <cstdlib>
+#include <iostream>
+#include <string>
+#include <vector>
+#include "Point.hpp"
+
+namespace Slic3r {
+
+typedef std::string t_config_option_key;
+typedef std::vector<std::string> t_config_option_keys;
+
+class ConfigOption {
+    public:
+    virtual ~ConfigOption() {};
+    virtual std::string serialize() = 0;
+    virtual void deserialize(std::string str) = 0;
+};
+
+class ConfigOptionFloat : public ConfigOption
+{
+    public:
+    double value;  // use double instead of float for preserving compatibility with values coming from Perl
+    ConfigOptionFloat() : value(0) {};
+    
+    operator double() const { return this->value; };
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        ss << this->value;
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->value = ::atof(str.c_str());
+    };
+};
+
+class ConfigOptionFloats : public ConfigOption
+{
+    public:
+    std::vector<double> values;
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        for (std::vector<double>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
+            if (it - this->values.begin() != 0) ss << ",";
+            ss << *it;
+        }
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->values.clear();
+        std::istringstream is(str);
+        std::string item_str;
+        while (std::getline(is, item_str, ',')) {
+            this->values.push_back(::atof(item_str.c_str()));
+        }
+    };
+};
+
+class ConfigOptionInt : public ConfigOption
+{
+    public:
+    int value;
+    ConfigOptionInt() : value(0) {};
+    
+    operator int() const { return this->value; };
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        ss << this->value;
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->value = ::atoi(str.c_str());
+    };
+};
+
+class ConfigOptionInts : public ConfigOption
+{
+    public:
+    std::vector<int> values;
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        for (std::vector<int>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
+            if (it - this->values.begin() != 0) ss << ",";
+            ss << *it;
+        }
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->values.clear();
+        std::istringstream is(str);
+        std::string item_str;
+        while (std::getline(is, item_str, ',')) {
+            this->values.push_back(::atoi(item_str.c_str()));
+        }
+    };
+};
+
+class ConfigOptionString : public ConfigOption
+{
+    public:
+    std::string value;
+    ConfigOptionString() : value("") {};
+    
+    operator std::string() const { return this->value; };
+    
+    std::string serialize() {
+        std::string str = this->value;
+        
+        // s/\R/\\n/g
+        size_t pos = 0;
+        while ((pos = str.find("\n", pos)) != std::string::npos || (pos = str.find("\r", pos)) != std::string::npos) {
+            str.replace(pos, 1, "\\n");
+            pos += 2; // length of "\\n"
+        }
+        
+        return str; 
+    };
+    
+    void deserialize(std::string str) {
+        // s/\\n/\n/g
+        size_t pos = 0;
+        while ((pos = str.find("\\n", pos)) != std::string::npos) {
+            str.replace(pos, 2, "\n");
+            pos += 1; // length of "\n"
+        }
+        
+        this->value = str;
+    };
+};
+
+// semicolon-separated strings
+class ConfigOptionStrings : public ConfigOption
+{
+    public:
+    std::vector<std::string> values;
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        for (std::vector<std::string>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
+            if (it - this->values.begin() != 0) ss << ";";
+            ss << *it;
+        }
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->values.clear();
+        std::istringstream is(str);
+        std::string item_str;
+        while (std::getline(is, item_str, ';')) {
+            this->values.push_back(item_str);
+        }
+    };
+};
+
+class ConfigOptionFloatOrPercent : public ConfigOption
+{
+    public:
+    double value;
+    bool percent;
+    ConfigOptionFloatOrPercent() : value(0), percent(false) {};
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        ss << this->value;
+        std::string s(ss.str());
+        if (this->percent) s += "%";
+        return s;
+    };
+    
+    void deserialize(std::string str) {
+        if (str.find_first_of("%") != std::string::npos) {
+            sscanf(str.c_str(), "%lf%%", &this->value);
+            this->percent = true;
+        } else {
+            this->value = ::atof(str.c_str());
+            this->percent = false;
+        }
+    };
+};
+
+class ConfigOptionPoint : public ConfigOption
+{
+    public:
+    Pointf point;
+    ConfigOptionPoint() : point(Pointf(0,0)) {};
+    
+    operator Pointf() const { return this->point; };
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        ss << this->point.x;
+        ss << ",";
+        ss << this->point.y;
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        sscanf(str.c_str(), "%lf%*1[,x]%lf", &this->point.x, &this->point.y);
+    };
+};
+
+class ConfigOptionPoints : public ConfigOption
+{
+    public:
+    Pointfs points;
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        for (Pointfs::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
+            if (it - this->points.begin() != 0) ss << ",";
+            ss << it->x;
+            ss << "x";
+            ss << it->y;
+        }
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->points.clear();
+        std::istringstream is(str);
+        std::string point_str;
+        while (std::getline(is, point_str, ',')) {
+            Pointf point;
+            sscanf(point_str.c_str(), "%lfx%lf", &point.x, &point.y);
+            this->points.push_back(point);
+        }
+    };
+};
+
+class ConfigOptionBool : public ConfigOption
+{
+    public:
+    bool value;
+    ConfigOptionBool() : value(false) {};
+    
+    operator bool() const { return this->value; };
+    
+    std::string serialize() {
+        return std::string(this->value ? "1" : "0");
+    };
+    
+    void deserialize(std::string str) {
+        this->value = (str.compare("1") == 0);
+    };
+};
+
+class ConfigOptionBools : public ConfigOption
+{
+    public:
+    std::vector<bool> values;
+    
+    std::string serialize() {
+        std::ostringstream ss;
+        for (std::vector<bool>::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
+            if (it - this->values.begin() != 0) ss << ",";
+            ss << (*it ? "1" : "0");
+        }
+        return ss.str();
+    };
+    
+    void deserialize(std::string str) {
+        this->values.clear();
+        std::istringstream is(str);
+        std::string item_str;
+        while (std::getline(is, item_str, ',')) {
+            this->values.push_back(item_str.compare("1") == 0);
+        }
+    };
+};
+
+typedef std::map<std::string,int> t_config_enum_values;
+
+template <class T>
+class ConfigOptionEnum : public ConfigOption
+{
+    public:
+    T value;
+    
+    operator T() const { return this->value; };
+    
+    std::string serialize() {
+        t_config_enum_values enum_keys_map = ConfigOptionEnum<T>::get_enum_values();
+        for (t_config_enum_values::iterator it = enum_keys_map.begin(); it != enum_keys_map.end(); ++it) {
+            if (it->second == static_cast<int>(this->value)) return it->first;
+        }
+        return "";
+    };
+
+    void deserialize(std::string str) {
+        t_config_enum_values enum_keys_map = ConfigOptionEnum<T>::get_enum_values();
+        assert(enum_keys_map.count(str) > 0);
+        this->value = static_cast<T>(enum_keys_map[str]);
+    };
+
+    static t_config_enum_values get_enum_values();
+};
+
+/* We use this one in DynamicConfig objects, otherwise it's better to use
+   the specialized ConfigOptionEnum<T> containers. */
+class ConfigOptionEnumGeneric : public ConfigOption
+{
+    public:
+    int value;
+    t_config_enum_values* keys_map;
+    
+    operator int() const { return this->value; };
+    
+    std::string serialize() {
+        for (t_config_enum_values::iterator it = this->keys_map->begin(); it != this->keys_map->end(); ++it) {
+            if (it->second == this->value) return it->first;
+        }
+        return "";
+    };
+
+    void deserialize(std::string str) {
+        assert(this->keys_map->count(str) != 0);
+        this->value = (*this->keys_map)[str];
+    };
+};
+
+enum ConfigOptionType {
+    coFloat,
+    coFloats,
+    coInt,
+    coInts,
+    coString,
+    coStrings,
+    coFloatOrPercent,
+    coPoint,
+    coPoints,
+    coBool,
+    coBools,
+    coEnum,
+};
+
+class ConfigOptionDef
+{
+    public:
+    ConfigOptionType type;
+    std::string label;
+    std::string category;
+    std::string tooltip;
+    std::string sidetext;
+    std::string cli;
+    std::string scope;
+    t_config_option_key ratio_over;
+    bool multiline;
+    bool full_label;
+    bool full_width;
+    bool readonly;
+    int height;
+    int width;
+    int min;
+    int max;
+    std::vector<t_config_option_key> aliases;
+    std::vector<t_config_option_key> shortcut;
+    std::vector<std::string> enum_values;
+    std::vector<std::string> enum_labels;
+    t_config_enum_values enum_keys_map;
+    
+    ConfigOptionDef() : multiline(false), full_label(false), full_width(false), readonly(false),
+                        height(-1), width(-1), min(INT_MIN), max(INT_MAX) {};
+};
+
+typedef std::map<t_config_option_key,ConfigOptionDef> t_optiondef_map;
+
+class ConfigBase
+{
+    public:
+    t_optiondef_map* def;
+    
+    ConfigBase() : def(NULL) {};
+    bool has(const t_config_option_key opt_key);
+    virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
+    virtual void keys(t_config_option_keys *keys) = 0;
+    void apply(ConfigBase &other, bool ignore_nonexistent = false);
+    std::string serialize(const t_config_option_key opt_key);
+    void set_deserialize(const t_config_option_key opt_key, std::string str);
+    double get_abs_value(const t_config_option_key opt_key);
+    
+    #ifdef SLIC3RXS
+    SV* as_hash();
+    SV* get(t_config_option_key opt_key);
+    void set(t_config_option_key opt_key, SV* value);
+    #endif
+};
+
+class DynamicConfig : public ConfigBase
+{
+    public:
+    DynamicConfig() {};
+    ~DynamicConfig();
+    ConfigOption* option(const t_config_option_key opt_key, bool create = false);
+    void keys(t_config_option_keys *keys);
+    
+    private:
+    DynamicConfig(const DynamicConfig& other);              // we disable this by making it private and unimplemented
+    DynamicConfig& operator= (const DynamicConfig& other);  // we disable this by making it private and unimplemented
+    typedef std::map<t_config_option_key,ConfigOption*> t_options_map;
+    t_options_map options;
+};
+
+class StaticConfig : public ConfigBase
+{
+    public:
+    void keys(t_config_option_keys *keys);
+};
+
+}
+
+#endif
diff --git a/xs/src/Point.cpp b/xs/src/Point.cpp
index db9c1417b..fbb3b06c6 100644
--- a/xs/src/Point.cpp
+++ b/xs/src/Point.cpp
@@ -174,6 +174,23 @@ Point::from_SV_check(SV* point_sv)
         this->from_SV(point_sv);
     }
 }
+
+SV*
+Pointf::to_SV_pureperl() const {
+    AV* av = newAV();
+    av_fill(av, 1);
+    av_store(av, 0, newSVnv(this->x));
+    av_store(av, 1, newSVnv(this->y));
+    return newRV_noinc((SV*)av);
+}
+
+void
+Pointf::from_SV(SV* point_sv)
+{
+    AV* point_av = (AV*)SvRV(point_sv);
+    this->x = SvNV(*av_fetch(point_av, 0, 0));
+    this->y = SvNV(*av_fetch(point_av, 1, 0));
+}
 #endif
 
 }
diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp
index d89a12cb8..507d082c9 100644
--- a/xs/src/Point.hpp
+++ b/xs/src/Point.hpp
@@ -9,8 +9,10 @@ namespace Slic3r {
 
 class Line;
 class Point;
+class Pointf;
 typedef std::vector<Point> Points;
 typedef std::vector<Point*> PointPtrs;
+typedef std::vector<Pointf> Pointfs;
 
 class Point
 {
@@ -42,6 +44,19 @@ class Point
     #endif
 };
 
+class Pointf
+{
+    public:
+    double x;
+    double y;
+    explicit Pointf(double _x = 0, double _y = 0): x(_x), y(_y) {};
+    
+    #ifdef SLIC3RXS
+    void from_SV(SV* point_sv);
+    SV* to_SV_pureperl() const;
+    #endif
+};
+
 }
 
 #endif
diff --git a/xs/src/PrintConfig.cpp b/xs/src/PrintConfig.cpp
new file mode 100644
index 000000000..76cc9ef49
--- /dev/null
+++ b/xs/src/PrintConfig.cpp
@@ -0,0 +1,7 @@
+#include "PrintConfig.hpp"
+
+namespace Slic3r {
+
+t_optiondef_map PrintConfig::PrintConfigDef = PrintConfig::build_def();
+
+}
diff --git a/xs/src/PrintConfig.hpp b/xs/src/PrintConfig.hpp
new file mode 100644
index 000000000..4dd732150
--- /dev/null
+++ b/xs/src/PrintConfig.hpp
@@ -0,0 +1,1307 @@
+#ifndef slic3r_PrintConfig_hpp_
+#define slic3r_PrintConfig_hpp_
+
+#include "Config.hpp"
+
+namespace Slic3r {
+
+enum GCodeFlavor {
+    gcfRepRap, gcfTeacup, gcfMakerWare, gcfSailfish, gcfMach3, gcfNoExtrusion,
+};
+
+enum InfillPattern {
+    ipRectilinear, ipLine, ipConcentric, ipHoneycomb,
+    ipHilbertCurve, ipArchimedeanChords, ipOctagramSpiral,
+};
+
+template<> inline t_config_enum_values ConfigOptionEnum<GCodeFlavor>::get_enum_values() {
+    t_config_enum_values keys_map;
+    keys_map["reprap"]          = gcfRepRap;
+    keys_map["teacup"]          = gcfTeacup;
+    keys_map["makerware"]       = gcfMakerWare;
+    keys_map["sailfish"]        = gcfSailfish;
+    keys_map["mach3"]           = gcfMach3;
+    keys_map["no-extrusion"]    = gcfNoExtrusion;
+    return keys_map;
+}
+
+template<> inline t_config_enum_values ConfigOptionEnum<InfillPattern>::get_enum_values() {
+    t_config_enum_values keys_map;
+    keys_map["rectilinear"]         = ipRectilinear;
+    keys_map["line"]                = ipLine;
+    keys_map["concentric"]          = ipConcentric;
+    keys_map["honeycomb"]           = ipHoneycomb;
+    keys_map["hilbertcurve"]        = ipHilbertCurve;
+    keys_map["archimedeanchords"]   = ipArchimedeanChords;
+    keys_map["octagramspiral"]      = ipOctagramSpiral;
+    return keys_map;
+}
+
+class PrintConfig : public StaticConfig
+{
+    public:
+    static t_optiondef_map PrintConfigDef;
+    
+    ConfigOptionBool                avoid_crossing_perimeters;
+    ConfigOptionPoint               bed_size;
+    ConfigOptionInt                 bed_temperature;
+    ConfigOptionInt                 bottom_solid_layers;
+    ConfigOptionFloat               bridge_acceleration;
+    ConfigOptionInt                 bridge_fan_speed;
+    ConfigOptionFloat               bridge_flow_ratio;
+    ConfigOptionFloat               bridge_speed;
+    ConfigOptionFloat               brim_width;
+    ConfigOptionBool                complete_objects;
+    ConfigOptionBool                cooling;
+    ConfigOptionFloat               default_acceleration;
+    ConfigOptionInt                 disable_fan_first_layers;
+    ConfigOptionInt                 duplicate;
+    ConfigOptionFloat               duplicate_distance;
+    ConfigOptionPoint               duplicate_grid;
+    ConfigOptionString              end_gcode;
+    ConfigOptionFloatOrPercent      external_perimeter_speed;
+    ConfigOptionBool                external_perimeters_first;
+    ConfigOptionBool                extra_perimeters;
+    ConfigOptionFloat               extruder_clearance_height;
+    ConfigOptionFloat               extruder_clearance_radius;
+    ConfigOptionPoints              extruder_offset;
+    ConfigOptionString              extrusion_axis;
+    ConfigOptionFloats              extrusion_multiplier;
+    ConfigOptionFloatOrPercent      extrusion_width;
+    ConfigOptionBool                fan_always_on;
+    ConfigOptionInt                 fan_below_layer_time;
+    ConfigOptionFloats              filament_diameter;
+    ConfigOptionInt                 fill_angle;
+    ConfigOptionFloat               fill_density;
+    ConfigOptionEnum<InfillPattern> fill_pattern;
+    ConfigOptionFloat               first_layer_acceleration;
+    ConfigOptionInt                 first_layer_bed_temperature;
+    ConfigOptionFloatOrPercent      first_layer_extrusion_width;
+    ConfigOptionFloatOrPercent      first_layer_height;
+    ConfigOptionFloatOrPercent      first_layer_speed;
+    ConfigOptionInts                first_layer_temperature;
+    ConfigOptionBool                g0;
+    ConfigOptionFloat               gap_fill_speed;
+    ConfigOptionBool                gcode_arcs;
+    ConfigOptionBool                gcode_comments;
+    ConfigOptionEnum<GCodeFlavor>   gcode_flavor;
+    ConfigOptionFloat               infill_acceleration;
+    ConfigOptionInt                 infill_every_layers;
+    ConfigOptionInt                 infill_extruder;
+    ConfigOptionFloatOrPercent      infill_extrusion_width;
+    ConfigOptionBool                infill_first;
+    ConfigOptionBool                infill_only_where_needed;
+    ConfigOptionFloat               infill_speed;
+    ConfigOptionString              layer_gcode;
+    ConfigOptionFloat               layer_height;
+    ConfigOptionInt                 max_fan_speed;
+    ConfigOptionInt                 min_fan_speed;
+    ConfigOptionInt                 min_print_speed;
+    ConfigOptionFloat               min_skirt_length;
+    ConfigOptionString              notes;
+    ConfigOptionFloats              nozzle_diameter;
+    ConfigOptionBool                only_retract_when_crossing_perimeters;
+    ConfigOptionBool                ooze_prevention;
+    ConfigOptionString              output_filename_format;
+    ConfigOptionBool                overhangs;
+    ConfigOptionFloat               perimeter_acceleration;
+    ConfigOptionInt                 perimeter_extruder;
+    ConfigOptionFloatOrPercent      perimeter_extrusion_width;
+    ConfigOptionFloat               perimeter_speed;
+    ConfigOptionInt                 perimeters;
+    ConfigOptionStrings             post_process;
+    ConfigOptionPoint               print_center;
+    ConfigOptionInt                 raft_layers;
+    ConfigOptionBool                randomize_start;
+    ConfigOptionFloat               resolution;
+    ConfigOptionFloats              retract_before_travel;
+    ConfigOptionBools               retract_layer_change;
+    ConfigOptionFloats              retract_length;
+    ConfigOptionFloats              retract_length_toolchange;
+    ConfigOptionFloats              retract_lift;
+    ConfigOptionFloats              retract_restart_extra;
+    ConfigOptionFloats              retract_restart_extra_toolchange;
+    ConfigOptionInts                retract_speed;
+    ConfigOptionInt                 rotate;
+    ConfigOptionFloat               scale;
+    ConfigOptionFloat               skirt_distance;
+    ConfigOptionInt                 skirt_height;
+    ConfigOptionInt                 skirts;
+    ConfigOptionInt                 slowdown_below_layer_time;
+    ConfigOptionFloatOrPercent      small_perimeter_speed;
+    ConfigOptionEnum<InfillPattern> solid_fill_pattern;
+    ConfigOptionFloat               solid_infill_below_area;
+    ConfigOptionInt                 solid_infill_every_layers;
+    ConfigOptionFloatOrPercent      solid_infill_extrusion_width;
+    ConfigOptionFloatOrPercent      solid_infill_speed;
+    ConfigOptionInt                 solid_layers;
+    ConfigOptionBool                spiral_vase;
+    ConfigOptionInt                 standby_temperature_delta;
+    ConfigOptionString              start_gcode;
+    ConfigOptionBool                start_perimeters_at_concave_points;
+    ConfigOptionBool                start_perimeters_at_non_overhang;
+    ConfigOptionBool                support_material;
+    ConfigOptionInt                 support_material_angle;
+    ConfigOptionInt                 support_material_enforce_layers;
+    ConfigOptionInt                 support_material_extruder;
+    ConfigOptionFloatOrPercent      support_material_extrusion_width;
+    ConfigOptionInt                 support_material_interface_extruder;
+    ConfigOptionInt                 support_material_interface_layers;
+    ConfigOptionFloat               support_material_interface_spacing;
+    ConfigOptionEnum<InfillPattern> support_material_pattern;
+    ConfigOptionFloat               support_material_spacing;
+    ConfigOptionFloat               support_material_speed;
+    ConfigOptionInt                 support_material_threshold;
+    ConfigOptionInts                temperature;
+    ConfigOptionBool                thin_walls;
+    ConfigOptionInt                 threads;
+    ConfigOptionString              toolchange_gcode;
+    ConfigOptionFloatOrPercent      top_infill_extrusion_width;
+    ConfigOptionFloatOrPercent      top_solid_infill_speed;
+    ConfigOptionInt                 top_solid_layers;
+    ConfigOptionFloat               travel_speed;
+    ConfigOptionBool                use_firmware_retraction;
+    ConfigOptionBool                use_relative_e_distances;
+    ConfigOptionFloat               vibration_limit;
+    ConfigOptionBools               wipe;
+    ConfigOptionFloat               z_offset;
+    
+    PrintConfig() {
+        this->def = &PrintConfig::PrintConfigDef;
+        
+        this->avoid_crossing_perimeters.value                    = false;
+        this->bed_size.point                                     = Pointf(200,200);
+        this->bed_temperature.value                              = 0;
+        this->bottom_solid_layers.value                          = 3;
+        this->bridge_acceleration.value                          = 0;
+        this->bridge_fan_speed.value                             = 100;
+        this->bridge_flow_ratio.value                            = 1;
+        this->bridge_speed.value                                 = 60;
+        this->brim_width.value                                   = 0;
+        this->complete_objects.value                             = false;
+        this->cooling.value                                      = true;
+        this->default_acceleration.value                         = 0;
+        this->disable_fan_first_layers.value                     = 1;
+        this->duplicate.value                                    = 1;
+        this->duplicate_distance.value                           = 6;
+        this->duplicate_grid.point                               = Pointf(1,1);
+        this->end_gcode.value                                    = "M104 S0 ; turn off temperature\nG28 X0  ; home X axis\nM84     ; disable motors\n";
+        this->external_perimeter_speed.value                     = 70;
+        this->external_perimeter_speed.percent                   = true;
+        this->external_perimeters_first.value                    = false;
+        this->extra_perimeters.value                             = true;
+        this->extruder_clearance_height.value                    = 20;
+        this->extruder_clearance_radius.value                    = 20;
+        this->extruder_offset.points.resize(1);
+        this->extruder_offset.points[0]                          = Pointf(0,0);
+        this->extrusion_axis.value                               = "E";
+        this->extrusion_multiplier.values.resize(1);
+        this->extrusion_multiplier.values[0]                     = 1;
+        this->extrusion_width.value                              = 0;
+        this->extrusion_width.percent                            = false;
+        this->fan_always_on.value                                = false;
+        this->fan_below_layer_time.value                         = 60;
+        this->filament_diameter.values.resize(1);
+        this->filament_diameter.values[0]                        = 3;
+        this->fill_angle.value                                   = 45;
+        this->fill_density.value                                 = 0.4;
+        this->fill_pattern.value                                 = ipHoneycomb;
+        this->first_layer_acceleration.value                     = 0;
+        this->first_layer_bed_temperature.value                  = 0;
+        this->first_layer_extrusion_width.value                  = 200;
+        this->first_layer_extrusion_width.percent                = true;
+        this->first_layer_height.value                           = 0.35;
+        this->first_layer_height.percent                         = false;
+        this->first_layer_speed.value                            = 30;
+        this->first_layer_speed.percent                          = true;
+        this->first_layer_temperature.values.resize(1);
+        this->first_layer_temperature.values[0]                  = 200;
+        this->g0.value                                           = false;
+        this->gap_fill_speed.value                               = 20;
+        this->gcode_arcs.value                                   = false;
+        this->gcode_comments.value                               = false;
+        this->gcode_flavor.value                                 = gcfRepRap;
+        this->infill_acceleration.value                          = 0;
+        this->infill_every_layers.value                          = 1;
+        this->infill_extruder.value                              = 1;
+        this->infill_extrusion_width.value                       = 0;
+        this->infill_extrusion_width.percent                     = false;
+        this->infill_first.value                                 = false;
+        this->infill_only_where_needed.value                     = false;
+        this->infill_speed.value                                 = 60;
+        this->layer_gcode.value                                  = "";
+        this->layer_height.value                                 = 0.4;
+        this->max_fan_speed.value                                = 100;
+        this->min_fan_speed.value                                = 35;
+        this->min_print_speed.value                              = 10;
+        this->min_skirt_length.value                             = 0;
+        this->notes.value                                        = "";
+        this->nozzle_diameter.values.resize(1);
+        this->nozzle_diameter.values[0]                          = 0.5;
+        this->only_retract_when_crossing_perimeters.value        = true;
+        this->ooze_prevention.value                              = false;
+        this->output_filename_format.value                       = "[input_filename_base].gcode";
+        this->overhangs.value                                    = true;
+        this->perimeter_acceleration.value                       = 0;
+        this->perimeter_extruder.value                           = 1;
+        this->perimeter_extrusion_width.value                    = 0;
+        this->perimeter_extrusion_width.percent                  = false;
+        this->perimeter_speed.value                              = 30;
+        this->perimeters.value                                   = 3;
+        this->print_center.point                                 = Pointf(100,100);
+        this->raft_layers.value                                  = 0;
+        this->randomize_start.value                              = false;
+        this->resolution.value                                   = 0;
+        this->retract_before_travel.values.resize(1);
+        this->retract_before_travel.values[0]                    = 2;
+        this->retract_layer_change.values.resize(1);
+        this->retract_layer_change.values[0]                     = true;
+        this->retract_length.values.resize(1);
+        this->retract_length.values[0]                           = 1;
+        this->retract_length_toolchange.values.resize(1);
+        this->retract_length_toolchange.values[0]                = 10;
+        this->retract_lift.values.resize(1);
+        this->retract_lift.values[0]                             = 0;
+        this->retract_restart_extra.values.resize(1);
+        this->retract_restart_extra.values[0]                    = 0;
+        this->retract_restart_extra_toolchange.values.resize(1);
+        this->retract_restart_extra_toolchange.values[0]         = 0;
+        this->retract_speed.values.resize(1);
+        this->retract_speed.values[0]                            = 30;
+        this->rotate.value                                       = 0;
+        this->scale.value                                        = 1;
+        this->skirt_distance.value                               = 6;
+        this->skirt_height.value                                 = 1;
+        this->skirts.value                                       = 1;
+        this->slowdown_below_layer_time.value                    = 30;
+        this->small_perimeter_speed.value                        = 30;
+        this->small_perimeter_speed.percent                      = false;
+        this->solid_fill_pattern.value                           = ipRectilinear;
+        this->solid_infill_below_area.value                      = 70;
+        this->solid_infill_every_layers.value                    = 0;
+        this->solid_infill_extrusion_width.value                 = 0;
+        this->solid_infill_extrusion_width.percent               = false;
+        this->solid_infill_speed.value                           = 60;
+        this->solid_infill_speed.percent                         = false;
+        this->spiral_vase.value                                  = false;
+        this->standby_temperature_delta.value                    = -5;
+        this->start_gcode.value                                  = "G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n";
+        this->start_perimeters_at_concave_points.value           = false;
+        this->start_perimeters_at_non_overhang.value             = false;
+        this->support_material.value                             = false;
+        this->support_material_angle.value                       = 0;
+        this->support_material_enforce_layers.value              = 0;
+        this->support_material_extruder.value                    = 1;
+        this->support_material_extrusion_width.value             = 0;
+        this->support_material_extrusion_width.percent           = false;
+        this->support_material_interface_extruder.value          = 1;
+        this->support_material_interface_layers.value            = 3;
+        this->support_material_interface_spacing.value           = 0;
+        this->support_material_pattern.value                     = ipHoneycomb;
+        this->support_material_spacing.value                     = 2.5;
+        this->support_material_speed.value                       = 60;
+        this->support_material_threshold.value                   = 0;
+        this->temperature.values.resize(1);
+        this->temperature.values[0]                              = 200;
+        this->thin_walls.value                                   = true;
+        this->threads.value                                      = 2;
+        this->toolchange_gcode.value                             = "";
+        this->top_infill_extrusion_width.value                   = 0;
+        this->top_infill_extrusion_width.percent                 = false;
+        this->top_solid_infill_speed.value                       = 50;
+        this->top_solid_infill_speed.percent                     = false;
+        this->top_solid_layers.value                             = 3;
+        this->travel_speed.value                                 = 130;
+        this->use_firmware_retraction.value                      = false;
+        this->use_relative_e_distances.value                     = false;
+        this->vibration_limit.value                              = 0;
+        this->wipe.values.resize(1);
+        this->wipe.values[0]                                     = false;
+        this->z_offset.value                                     = 0;
+    };
+    
+    ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
+        if (opt_key == "avoid_crossing_perimeters")                  return &this->avoid_crossing_perimeters;
+        if (opt_key == "bed_size")                                   return &this->bed_size;
+        if (opt_key == "bed_temperature")                            return &this->bed_temperature;
+        if (opt_key == "bottom_solid_layers")                        return &this->bottom_solid_layers;
+        if (opt_key == "bridge_acceleration")                        return &this->bridge_acceleration;
+        if (opt_key == "bridge_fan_speed")                           return &this->bridge_fan_speed;
+        if (opt_key == "bridge_flow_ratio")                          return &this->bridge_flow_ratio;
+        if (opt_key == "bridge_speed")                               return &this->bridge_speed;
+        if (opt_key == "brim_width")                                 return &this->brim_width;
+        if (opt_key == "complete_objects")                           return &this->complete_objects;
+        if (opt_key == "cooling")                                    return &this->cooling;
+        if (opt_key == "default_acceleration")                       return &this->default_acceleration;
+        if (opt_key == "disable_fan_first_layers")                   return &this->disable_fan_first_layers;
+        if (opt_key == "duplicate")                                  return &this->duplicate;
+        if (opt_key == "duplicate_distance")                         return &this->duplicate_distance;
+        if (opt_key == "duplicate_grid")                             return &this->duplicate_grid;
+        if (opt_key == "end_gcode")                                  return &this->end_gcode;
+        if (opt_key == "external_perimeter_speed")                   return &this->external_perimeter_speed;
+        if (opt_key == "external_perimeters_first")                  return &this->external_perimeters_first;
+        if (opt_key == "extra_perimeters")                           return &this->extra_perimeters;
+        if (opt_key == "extruder_clearance_height")                  return &this->extruder_clearance_height;
+        if (opt_key == "extruder_clearance_radius")                  return &this->extruder_clearance_radius;
+        if (opt_key == "extruder_offset")                            return &this->extruder_offset;
+        if (opt_key == "extrusion_axis")                             return &this->extrusion_axis;
+        if (opt_key == "extrusion_multiplier")                       return &this->extrusion_multiplier;
+        if (opt_key == "extrusion_width")                            return &this->extrusion_width;
+        if (opt_key == "fan_always_on")                              return &this->fan_always_on;
+        if (opt_key == "fan_below_layer_time")                       return &this->fan_below_layer_time;
+        if (opt_key == "filament_diameter")                          return &this->filament_diameter;
+        if (opt_key == "fill_angle")                                 return &this->fill_angle;
+        if (opt_key == "fill_density")                               return &this->fill_density;
+        if (opt_key == "fill_pattern")                               return &this->fill_pattern;
+        if (opt_key == "first_layer_acceleration")                   return &this->first_layer_acceleration;
+        if (opt_key == "first_layer_bed_temperature")                return &this->first_layer_bed_temperature;
+        if (opt_key == "first_layer_extrusion_width")                return &this->first_layer_extrusion_width;
+        if (opt_key == "first_layer_height")                         return &this->first_layer_height;
+        if (opt_key == "first_layer_speed")                          return &this->first_layer_speed;
+        if (opt_key == "first_layer_temperature")                    return &this->first_layer_temperature;
+        if (opt_key == "g0")                                         return &this->g0;
+        if (opt_key == "gap_fill_speed")                             return &this->gap_fill_speed;
+        if (opt_key == "gcode_arcs")                                 return &this->gcode_arcs;
+        if (opt_key == "gcode_comments")                             return &this->gcode_comments;
+        if (opt_key == "gcode_flavor")                               return &this->gcode_flavor;
+        if (opt_key == "infill_acceleration")                        return &this->infill_acceleration;
+        if (opt_key == "infill_every_layers")                        return &this->infill_every_layers;
+        if (opt_key == "infill_extruder")                            return &this->infill_extruder;
+        if (opt_key == "infill_extrusion_width")                     return &this->infill_extrusion_width;
+        if (opt_key == "infill_first")                               return &this->infill_first;
+        if (opt_key == "infill_only_where_needed")                   return &this->infill_only_where_needed;
+        if (opt_key == "infill_speed")                               return &this->infill_speed;
+        if (opt_key == "layer_gcode")                                return &this->layer_gcode;
+        if (opt_key == "layer_height")                               return &this->layer_height;
+        if (opt_key == "max_fan_speed")                              return &this->max_fan_speed;
+        if (opt_key == "min_fan_speed")                              return &this->min_fan_speed;
+        if (opt_key == "min_print_speed")                            return &this->min_print_speed;
+        if (opt_key == "min_skirt_length")                           return &this->min_skirt_length;
+        if (opt_key == "notes")                                      return &this->notes;
+        if (opt_key == "nozzle_diameter")                            return &this->nozzle_diameter;
+        if (opt_key == "only_retract_when_crossing_perimeters")      return &this->only_retract_when_crossing_perimeters;
+        if (opt_key == "ooze_prevention")                            return &this->ooze_prevention;
+        if (opt_key == "output_filename_format")                     return &this->output_filename_format;
+        if (opt_key == "overhangs")                                  return &this->overhangs;
+        if (opt_key == "perimeter_acceleration")                     return &this->perimeter_acceleration;
+        if (opt_key == "perimeter_extruder")                         return &this->perimeter_extruder;
+        if (opt_key == "perimeter_extrusion_width")                  return &this->perimeter_extrusion_width;
+        if (opt_key == "perimeter_speed")                            return &this->perimeter_speed;
+        if (opt_key == "perimeters")                                 return &this->perimeters;
+        if (opt_key == "post_process")                               return &this->post_process;
+        if (opt_key == "print_center")                               return &this->print_center;
+        if (opt_key == "raft_layers")                                return &this->raft_layers;
+        if (opt_key == "randomize_start")                            return &this->randomize_start;
+        if (opt_key == "resolution")                                 return &this->resolution;
+        if (opt_key == "retract_before_travel")                      return &this->retract_before_travel;
+        if (opt_key == "retract_layer_change")                       return &this->retract_layer_change;
+        if (opt_key == "retract_length")                             return &this->retract_length;
+        if (opt_key == "retract_length_toolchange")                  return &this->retract_length_toolchange;
+        if (opt_key == "retract_lift")                               return &this->retract_lift;
+        if (opt_key == "retract_restart_extra")                      return &this->retract_restart_extra;
+        if (opt_key == "retract_restart_extra_toolchange")           return &this->retract_restart_extra_toolchange;
+        if (opt_key == "retract_speed")                              return &this->retract_speed;
+        if (opt_key == "rotate")                                     return &this->rotate;
+        if (opt_key == "scale")                                      return &this->scale;
+        if (opt_key == "skirt_distance")                             return &this->skirt_distance;
+        if (opt_key == "skirt_height")                               return &this->skirt_height;
+        if (opt_key == "skirts")                                     return &this->skirts;
+        if (opt_key == "slowdown_below_layer_time")                  return &this->slowdown_below_layer_time;
+        if (opt_key == "small_perimeter_speed")                      return &this->small_perimeter_speed;
+        if (opt_key == "solid_fill_pattern")                         return &this->solid_fill_pattern;
+        if (opt_key == "solid_infill_below_area")                    return &this->solid_infill_below_area;
+        if (opt_key == "solid_infill_every_layers")                  return &this->solid_infill_every_layers;
+        if (opt_key == "solid_infill_extrusion_width")               return &this->solid_infill_extrusion_width;
+        if (opt_key == "solid_infill_speed")                         return &this->solid_infill_speed;
+        if (opt_key == "solid_layers")                               return &this->solid_layers;
+        if (opt_key == "spiral_vase")                                return &this->spiral_vase;
+        if (opt_key == "standby_temperature_delta")                  return &this->standby_temperature_delta;
+        if (opt_key == "start_gcode")                                return &this->start_gcode;
+        if (opt_key == "start_perimeters_at_concave_points")         return &this->start_perimeters_at_concave_points;
+        if (opt_key == "start_perimeters_at_non_overhang")           return &this->start_perimeters_at_non_overhang;
+        if (opt_key == "support_material")                           return &this->support_material;
+        if (opt_key == "support_material_angle")                     return &this->support_material_angle;
+        if (opt_key == "support_material_enforce_layers")            return &this->support_material_enforce_layers;
+        if (opt_key == "support_material_extruder")                  return &this->support_material_extruder;
+        if (opt_key == "support_material_extrusion_width")           return &this->support_material_extrusion_width;
+        if (opt_key == "support_material_interface_extruder")        return &this->support_material_interface_extruder;
+        if (opt_key == "support_material_interface_layers")          return &this->support_material_interface_layers;
+        if (opt_key == "support_material_interface_spacing")         return &this->support_material_interface_spacing;
+        if (opt_key == "support_material_pattern")                   return &this->support_material_pattern;
+        if (opt_key == "support_material_spacing")                   return &this->support_material_spacing;
+        if (opt_key == "support_material_speed")                     return &this->support_material_speed;
+        if (opt_key == "support_material_threshold")                 return &this->support_material_threshold;
+        if (opt_key == "temperature")                                return &this->temperature;
+        if (opt_key == "thin_walls")                                 return &this->thin_walls;
+        if (opt_key == "threads")                                    return &this->threads;
+        if (opt_key == "toolchange_gcode")                           return &this->toolchange_gcode;
+        if (opt_key == "top_infill_extrusion_width")                 return &this->top_infill_extrusion_width;
+        if (opt_key == "top_solid_infill_speed")                     return &this->top_solid_infill_speed;
+        if (opt_key == "top_solid_layers")                           return &this->top_solid_layers;
+        if (opt_key == "travel_speed")                               return &this->travel_speed;
+        if (opt_key == "use_firmware_retraction")                    return &this->use_firmware_retraction;
+        if (opt_key == "use_relative_e_distances")                   return &this->use_relative_e_distances;
+        if (opt_key == "vibration_limit")                            return &this->vibration_limit;
+        if (opt_key == "wipe")                                       return &this->wipe;
+        if (opt_key == "z_offset")                                   return &this->z_offset;
+        
+        if (create) throw "Attempt to create non-existing option in StaticConfig object";
+        return NULL;
+    };
+    
+    static t_optiondef_map build_def () {
+        t_optiondef_map Options;
+        
+        Options["avoid_crossing_perimeters"].type = coBool;
+        Options["avoid_crossing_perimeters"].label = "Avoid crossing perimeters";
+        Options["avoid_crossing_perimeters"].tooltip = "Optimize travel moves in order to minimize the crossing of perimeters. This is mostly useful with Bowden extruders which suffer from oozing. This feature slows down both the print and the G-code generation.";
+        Options["avoid_crossing_perimeters"].cli = "avoid-crossing-perimeters!";
+
+        Options["bed_size"].type = coPoint;
+        Options["bed_size"].label = "Bed size";
+        Options["bed_size"].tooltip = "Size of your bed. This is used to adjust the preview in the plater and for auto-arranging parts in it.";
+        Options["bed_size"].sidetext = "mm";
+        Options["bed_size"].cli = "bed-size=s";
+
+        Options["bed_temperature"].type = coInt;
+        Options["bed_temperature"].label = "Other layers";
+        Options["bed_temperature"].tooltip = "Bed temperature for layers after the first one. Set this to zero to disable bed temperature control commands in the output.";
+        Options["bed_temperature"].sidetext = "°C";
+        Options["bed_temperature"].cli = "bed-temperature=i";
+        Options["bed_temperature"].full_label = true;
+        Options["bed_temperature"].max = 300;
+
+        Options["bottom_solid_layers"].type = coInt;
+        Options["bottom_solid_layers"].label = "Bottom";
+        Options["bottom_solid_layers"].category = "Layers and Perimeters";
+        Options["bottom_solid_layers"].tooltip = "Number of solid layers to generate on bottom surfaces.";
+        Options["bottom_solid_layers"].cli = "bottom-solid-layers=i";
+        Options["bottom_solid_layers"].scope = "object";
+        Options["bottom_solid_layers"].full_label = true;
+
+        Options["bridge_acceleration"].type = coFloat;
+        Options["bridge_acceleration"].label = "Bridge";
+        Options["bridge_acceleration"].tooltip = "This is the acceleration your printer will use for bridges. Set zero to disable acceleration control for bridges.";
+        Options["bridge_acceleration"].sidetext = "mm/s²";
+        Options["bridge_acceleration"].cli = "bridge-acceleration=f";
+
+        Options["bridge_fan_speed"].type = coInt;
+        Options["bridge_fan_speed"].label = "Bridges fan speed";
+        Options["bridge_fan_speed"].tooltip = "This fan speed is enforced during all bridges and overhangs.";
+        Options["bridge_fan_speed"].sidetext = "%";
+        Options["bridge_fan_speed"].cli = "bridge-fan-speed=i";
+        Options["bridge_fan_speed"].max = 100;
+
+        Options["bridge_flow_ratio"].type = coFloat;
+        Options["bridge_flow_ratio"].label = "Bridge flow ratio";
+        Options["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.";
+        Options["bridge_flow_ratio"].cli = "bridge-flow-ratio=f";
+
+        Options["bridge_speed"].type = coFloat;
+        Options["bridge_speed"].label = "Bridges";
+        Options["bridge_speed"].tooltip = "Speed for printing bridges.";
+        Options["bridge_speed"].sidetext = "mm/s";
+        Options["bridge_speed"].cli = "bridge-speed=f";
+        Options["bridge_speed"].aliases.push_back("bridge_feed_rate");
+
+        Options["brim_width"].type = coFloat;
+        Options["brim_width"].label = "Brim width";
+        Options["brim_width"].tooltip = "Horizontal width of the brim that will be printed around each object on the first layer.";
+        Options["brim_width"].sidetext = "mm";
+        Options["brim_width"].cli = "brim-width=f";
+
+        Options["complete_objects"].type = coBool;
+        Options["complete_objects"].label = "Complete individual objects";
+        Options["complete_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.";
+        Options["complete_objects"].cli = "complete-objects!";
+
+        Options["cooling"].type = coBool;
+        Options["cooling"].label = "Enable auto cooling";
+        Options["cooling"].tooltip = "This flag enables the automatic cooling logic that adjusts print speed and fan speed according to layer printing time.";
+        Options["cooling"].cli = "cooling!";
+
+        Options["default_acceleration"].type = coFloat;
+        Options["default_acceleration"].label = "Default";
+        Options["default_acceleration"].tooltip = "This is the acceleration your printer will be reset to after the role-specific acceleration values are used (perimeter/infill). Set zero to prevent resetting acceleration at all.";
+        Options["default_acceleration"].sidetext = "mm/s²";
+        Options["default_acceleration"].cli = "default-acceleration=f";
+
+        Options["disable_fan_first_layers"].type = coInt;
+        Options["disable_fan_first_layers"].label = "Disable fan for the first";
+        Options["disable_fan_first_layers"].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.";
+        Options["disable_fan_first_layers"].sidetext = "layers";
+        Options["disable_fan_first_layers"].cli = "disable-fan-first-layers=i";
+        Options["disable_fan_first_layers"].max = 1000;
+
+        Options["duplicate"].type = coInt;
+        Options["duplicate"].label = "Copies (autoarrange)";
+        Options["duplicate"].cli = "duplicate=i";
+        Options["duplicate"].min = 1;
+
+        Options["duplicate_distance"].type = coFloat;
+        Options["duplicate_distance"].label = "Distance between copies";
+        Options["duplicate_distance"].tooltip = "Distance used for the auto-arrange feature of the plater.";
+        Options["duplicate_distance"].sidetext = "mm";
+        Options["duplicate_distance"].cli = "duplicate-distance=f";
+        Options["duplicate_distance"].aliases.push_back("multiply_distance");
+
+        Options["duplicate_grid"].type = coPoint;
+        Options["duplicate_grid"].label = "Copies (grid)";
+        Options["duplicate_grid"].cli = "duplicate-grid=s";
+
+        Options["end_gcode"].type = coString;
+        Options["end_gcode"].label = "End G-code";
+        Options["end_gcode"].tooltip = "This end procedure is inserted at the end of the output file. Note that you can use placeholder variables for all Slic3r settings.";
+        Options["end_gcode"].cli = "end-gcode=s";
+        Options["end_gcode"].multiline = true;
+        Options["end_gcode"].full_width = true;
+        Options["end_gcode"].height = 120;
+
+        Options["external_perimeter_speed"].type = coFloatOrPercent;
+        Options["external_perimeter_speed"].label = "External perimeters";
+        Options["external_perimeter_speed"].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.";
+        Options["external_perimeter_speed"].sidetext = "mm/s or %";
+        Options["external_perimeter_speed"].cli = "external-perimeter-speed=s";
+        Options["external_perimeter_speed"].ratio_over = "perimeter_speed";
+
+        Options["external_perimeters_first"].type = coBool;
+        Options["external_perimeters_first"].label = "External perimeters first";
+        Options["external_perimeters_first"].tooltip = "Print contour perimeters from the outermost one to the innermost one instead of the default inverse order.";
+        Options["external_perimeters_first"].cli = "external-perimeters-first!";
+
+        Options["extra_perimeters"].type = coBool;
+        Options["extra_perimeters"].label = "Extra perimeters if needed";
+        Options["extra_perimeters"].category = "Layers and Perimeters";
+        Options["extra_perimeters"].tooltip = "Add more perimeters when needed for avoiding gaps in sloping walls.";
+        Options["extra_perimeters"].cli = "extra-perimeters!";
+        Options["extra_perimeters"].scope = "object";
+
+        Options["extruder_clearance_height"].type = coFloat;
+        Options["extruder_clearance_height"].label = "Height";
+        Options["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.";
+        Options["extruder_clearance_height"].sidetext = "mm";
+        Options["extruder_clearance_height"].cli = "extruder-clearance-height=f";
+
+        Options["extruder_clearance_radius"].type = coFloat;
+        Options["extruder_clearance_radius"].label = "Radius";
+        Options["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.";
+        Options["extruder_clearance_radius"].sidetext = "mm";
+        Options["extruder_clearance_radius"].cli = "extruder-clearance-radius=f";
+
+        Options["extruder_offset"].type = coPoints;
+        Options["extruder_offset"].label = "Extruder offset";
+        Options["extruder_offset"].tooltip = "If your firmware doesn't handle the extruder displacement you need the G-code to take it into account. This option lets you specify the displacement of each extruder with respect to the first one. It expects positive coordinates (they will be subtracted from the XY coordinate).";
+        Options["extruder_offset"].sidetext = "mm";
+        Options["extruder_offset"].cli = "extruder-offset=s@";
+
+        Options["extrusion_axis"].type = coString;
+        Options["extrusion_axis"].label = "Extrusion axis";
+        Options["extrusion_axis"].tooltip = "Use this option to set the axis letter associated to your printer's extruder (usually E but some printers use A).";
+        Options["extrusion_axis"].cli = "extrusion-axis=s";
+
+        Options["extrusion_multiplier"].type = coFloats;
+        Options["extrusion_multiplier"].label = "Extrusion multiplier";
+        Options["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.";
+        Options["extrusion_multiplier"].cli = "extrusion-multiplier=f@";
+
+        Options["extrusion_width"].type = coFloatOrPercent;
+        Options["extrusion_width"].label = "Default extrusion width";
+        Options["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.";
+        Options["extrusion_width"].sidetext = "mm or % (leave 0 for auto)";
+        Options["extrusion_width"].cli = "extrusion-width=s";
+
+        Options["fan_always_on"].type = coBool;
+        Options["fan_always_on"].label = "Keep fan always on";
+        Options["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.";
+        Options["fan_always_on"].cli = "fan-always-on!";
+
+        Options["fan_below_layer_time"].type = coInt;
+        Options["fan_below_layer_time"].label = "Enable fan if layer print time is below";
+        Options["fan_below_layer_time"].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.";
+        Options["fan_below_layer_time"].sidetext = "approximate seconds";
+        Options["fan_below_layer_time"].cli = "fan-below-layer-time=i";
+        Options["fan_below_layer_time"].width = 60;
+        Options["fan_below_layer_time"].max = 1000;
+
+        Options["filament_diameter"].type = coFloats;
+        Options["filament_diameter"].label = "Diameter";
+        Options["filament_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.";
+        Options["filament_diameter"].sidetext = "mm";
+        Options["filament_diameter"].cli = "filament-diameter=f@";
+
+        Options["fill_angle"].type = coInt;
+        Options["fill_angle"].label = "Fill angle";
+        Options["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.";
+        Options["fill_angle"].sidetext = "°";
+        Options["fill_angle"].cli = "fill-angle=i";
+        Options["fill_angle"].max = 359;
+
+        Options["fill_density"].type = coFloat;
+        Options["fill_density"].label = "Fill density";
+        Options["fill_density"].category = "Infill";
+        Options["fill_density"].tooltip = "Density of internal infill, expressed in the range 0 - 1.";
+        Options["fill_density"].cli = "fill-density=f";
+        Options["fill_density"].scope = "object";
+
+        Options["fill_pattern"].type = coEnum;
+        Options["fill_pattern"].label = "Fill pattern";
+        Options["fill_pattern"].category = "Infill";
+        Options["fill_pattern"].tooltip = "Fill pattern for general low-density infill.";
+        Options["fill_pattern"].cli = "fill-pattern=s";
+        Options["fill_pattern"].scope = "object";
+        Options["fill_pattern"].enum_values.push_back("rectilinear");
+        Options["fill_pattern"].enum_values.push_back("line");
+        Options["fill_pattern"].enum_values.push_back("concentric");
+        Options["fill_pattern"].enum_values.push_back("honeycomb");
+        Options["fill_pattern"].enum_values.push_back("hilbertcurve");
+        Options["fill_pattern"].enum_values.push_back("archimedeanchords");
+        Options["fill_pattern"].enum_values.push_back("octagramspiral");
+        Options["fill_pattern"].enum_labels.push_back("rectilinear");
+        Options["fill_pattern"].enum_labels.push_back("line");
+        Options["fill_pattern"].enum_labels.push_back("concentric");
+        Options["fill_pattern"].enum_labels.push_back("honeycomb");
+        Options["fill_pattern"].enum_labels.push_back("hilbertcurve (slow)");
+        Options["fill_pattern"].enum_labels.push_back("archimedeanchords (slow)");
+        Options["fill_pattern"].enum_labels.push_back("octagramspiral (slow)");
+
+        Options["first_layer_acceleration"].type = coFloat;
+        Options["first_layer_acceleration"].label = "First layer";
+        Options["first_layer_acceleration"].tooltip = "This is the acceleration your printer will use for first layer. Set zero to disable acceleration control for first layer.";
+        Options["first_layer_acceleration"].sidetext = "mm/s²";
+        Options["first_layer_acceleration"].cli = "first-layer-acceleration=f";
+
+        Options["first_layer_bed_temperature"].type = coInt;
+        Options["first_layer_bed_temperature"].label = "First layer";
+        Options["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.";
+        Options["first_layer_bed_temperature"].sidetext = "°C";
+        Options["first_layer_bed_temperature"].cli = "first-layer-bed-temperature=i";
+        Options["first_layer_bed_temperature"].max = 300;
+
+        Options["first_layer_extrusion_width"].type = coFloatOrPercent;
+        Options["first_layer_extrusion_width"].label = "First layer";
+        Options["first_layer_extrusion_width"].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 layer height.";
+        Options["first_layer_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["first_layer_extrusion_width"].cli = "first-layer-extrusion-width=s";
+
+        Options["first_layer_height"].type = coFloatOrPercent;
+        Options["first_layer_height"].label = "First layer height";
+        Options["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.";
+        Options["first_layer_height"].sidetext = "mm or %";
+        Options["first_layer_height"].cli = "first-layer-height=s";
+        Options["first_layer_height"].ratio_over = "layer_height";
+
+        Options["first_layer_speed"].type = coFloatOrPercent;
+        Options["first_layer_speed"].label = "First layer speed";
+        Options["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.";
+        Options["first_layer_speed"].sidetext = "mm/s or %";
+        Options["first_layer_speed"].cli = "first-layer-speed=s";
+
+        Options["first_layer_temperature"].type = coInts;
+        Options["first_layer_temperature"].label = "First layer";
+        Options["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.";
+        Options["first_layer_temperature"].sidetext = "°C";
+        Options["first_layer_temperature"].cli = "first-layer-temperature=i@";
+        Options["first_layer_temperature"].max = 400;
+
+        Options["g0"].type = coBool;
+        Options["g0"].label = "Use G0 for travel moves";
+        Options["g0"].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.";
+        Options["g0"].cli = "g0!";
+
+        Options["gap_fill_speed"].type = coFloat;
+        Options["gap_fill_speed"].label = "Gap fill";
+        Options["gap_fill_speed"].tooltip = "Speed for filling small gaps using short zigzag moves. Keep this reasonably low to avoid too much shaking and resonance issues. Set zero to disable gaps filling.";
+        Options["gap_fill_speed"].sidetext = "mm/s";
+        Options["gap_fill_speed"].cli = "gap-fill-speed=f";
+
+        Options["gcode_arcs"].type = coBool;
+        Options["gcode_arcs"].label = "Use native G-code arcs";
+        Options["gcode_arcs"].tooltip = "This experimental feature tries to detect arcs from segments and generates G2/G3 arc commands instead of multiple straight G1 commands.";
+        Options["gcode_arcs"].cli = "gcode-arcs!";
+
+        Options["gcode_comments"].type = coBool;
+        Options["gcode_comments"].label = "Verbose G-code";
+        Options["gcode_comments"].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.";
+        Options["gcode_comments"].cli = "gcode-comments!";
+
+        Options["gcode_flavor"].type = coEnum;
+        Options["gcode_flavor"].label = "G-code flavor";
+        Options["gcode_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.";
+        Options["gcode_flavor"].cli = "gcode-flavor=s";
+        Options["gcode_flavor"].enum_values.push_back("reprap");
+        Options["gcode_flavor"].enum_values.push_back("teacup");
+        Options["gcode_flavor"].enum_values.push_back("makerware");
+        Options["gcode_flavor"].enum_values.push_back("sailfish");
+        Options["gcode_flavor"].enum_values.push_back("mach3");
+        Options["gcode_flavor"].enum_values.push_back("no-extrusion");
+        Options["gcode_flavor"].enum_labels.push_back("RepRap (Marlin/Sprinter/Repetier)");
+        Options["gcode_flavor"].enum_labels.push_back("Teacup");
+        Options["gcode_flavor"].enum_labels.push_back("MakerWare (MakerBot)");
+        Options["gcode_flavor"].enum_labels.push_back("Sailfish (MakerBot)");
+        Options["gcode_flavor"].enum_labels.push_back("Mach3/EMC");
+        Options["gcode_flavor"].enum_labels.push_back("No extrusion");
+
+        Options["infill_acceleration"].type = coFloat;
+        Options["infill_acceleration"].label = "Infill";
+        Options["infill_acceleration"].tooltip = "This is the acceleration your printer will use for infill. Set zero to disable acceleration control for infill.";
+        Options["infill_acceleration"].sidetext = "mm/s²";
+        Options["infill_acceleration"].cli = "infill-acceleration=f";
+
+        Options["infill_every_layers"].type = coInt;
+        Options["infill_every_layers"].label = "Combine infill every";
+        Options["infill_every_layers"].category = "Infill";
+        Options["infill_every_layers"].tooltip = "This feature allows to combine infill and speed up your print by extruding thicker infill layers while preserving thin perimeters, thus accuracy.";
+        Options["infill_every_layers"].sidetext = "layers";
+        Options["infill_every_layers"].cli = "infill-every-layers=i";
+        Options["infill_every_layers"].scope = "object";
+        Options["infill_every_layers"].full_label = true;
+        Options["infill_every_layers"].min = 1;
+
+        Options["infill_extruder"].type = coInt;
+        Options["infill_extruder"].label = "Infill extruder";
+        Options["infill_extruder"].tooltip = "The extruder to use when printing infill.";
+        Options["infill_extruder"].cli = "infill-extruder=i";
+
+        Options["infill_extrusion_width"].type = coFloatOrPercent;
+        Options["infill_extrusion_width"].label = "Infill";
+        Options["infill_extrusion_width"].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 layer height.";
+        Options["infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["infill_extrusion_width"].cli = "infill-extrusion-width=s";
+
+        Options["infill_first"].type = coBool;
+        Options["infill_first"].label = "Infill before perimeters";
+        Options["infill_first"].tooltip = "This option will switch the print order of perimeters and infill, making the latter first.";
+        Options["infill_first"].cli = "infill-first!";
+
+        Options["infill_only_where_needed"].type = coBool;
+        Options["infill_only_where_needed"].label = "Only infill where needed";
+        Options["infill_only_where_needed"].category = "Infill";
+        Options["infill_only_where_needed"].tooltip = "This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material).";
+        Options["infill_only_where_needed"].cli = "infill-only-where-needed!";
+        Options["infill_only_where_needed"].scope = "object";
+
+        Options["infill_speed"].type = coFloat;
+        Options["infill_speed"].label = "Infill";
+        Options["infill_speed"].tooltip = "Speed for printing the internal fill.";
+        Options["infill_speed"].sidetext = "mm/s";
+        Options["infill_speed"].cli = "infill-speed=f";
+        Options["infill_speed"].aliases.push_back("print_feed_rate");
+        Options["infill_speed"].aliases.push_back("infill_feed_rate");
+
+        Options["layer_gcode"].type = coString;
+        Options["layer_gcode"].label = "Layer change G-code";
+        Options["layer_gcode"].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.";
+        Options["layer_gcode"].cli = "layer-gcode=s";
+        Options["layer_gcode"].multiline = true;
+        Options["layer_gcode"].full_width = true;
+        Options["layer_gcode"].height = 50;
+
+        Options["layer_height"].type = coFloat;
+        Options["layer_height"].label = "Layer height";
+        Options["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.";
+        Options["layer_height"].sidetext = "mm";
+        Options["layer_height"].cli = "layer-height=f";
+
+        Options["max_fan_speed"].type = coInt;
+        Options["max_fan_speed"].label = "Max";
+        Options["max_fan_speed"].tooltip = "This setting represents the maximum speed of your fan.";
+        Options["max_fan_speed"].sidetext = "%";
+        Options["max_fan_speed"].cli = "max-fan-speed=i";
+        Options["max_fan_speed"].max = 100;
+
+        Options["min_fan_speed"].type = coInt;
+        Options["min_fan_speed"].label = "Min";
+        Options["min_fan_speed"].tooltip = "This setting represents the minimum PWM your fan needs to work.";
+        Options["min_fan_speed"].sidetext = "%";
+        Options["min_fan_speed"].cli = "min-fan-speed=i";
+        Options["min_fan_speed"].max = 100;
+
+        Options["min_print_speed"].type = coInt;
+        Options["min_print_speed"].label = "Min print speed";
+        Options["min_print_speed"].tooltip = "Slic3r will not scale speed down below this speed.";
+        Options["min_print_speed"].sidetext = "mm/s";
+        Options["min_print_speed"].cli = "min-print-speed=f";
+        Options["min_print_speed"].max = 1000;
+
+        Options["min_skirt_length"].type = coFloat;
+        Options["min_skirt_length"].label = "Minimum extrusion length";
+        Options["min_skirt_length"].tooltip = "Generate no less than the number of skirt loops required to consume the specified amount of filament on the bottom layer. For multi-extruder machines, this minimum applies to each extruder.";
+        Options["min_skirt_length"].sidetext = "mm";
+        Options["min_skirt_length"].cli = "min-skirt-length=f";
+        Options["min_skirt_length"].min = 0;
+
+        Options["notes"].type = coString;
+        Options["notes"].label = "Configuration notes";
+        Options["notes"].tooltip = "You can put here your personal notes. This text will be added to the G-code header comments.";
+        Options["notes"].cli = "notes=s";
+        Options["notes"].multiline = true;
+        Options["notes"].full_width = true;
+        Options["notes"].height = 130;
+
+        Options["nozzle_diameter"].type = coFloats;
+        Options["nozzle_diameter"].label = "Nozzle diameter";
+        Options["nozzle_diameter"].tooltip = "This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)";
+        Options["nozzle_diameter"].sidetext = "mm";
+        Options["nozzle_diameter"].cli = "nozzle-diameter=f@";
+
+        Options["only_retract_when_crossing_perimeters"].type = coBool;
+        Options["only_retract_when_crossing_perimeters"].label = "Only retract when crossing perimeters";
+        Options["only_retract_when_crossing_perimeters"].tooltip = "Disables retraction when the travel path does not exceed the upper layer's perimeters (and thus any ooze will be probably invisible).";
+        Options["only_retract_when_crossing_perimeters"].cli = "only-retract-when-crossing-perimeters!";
+
+        Options["ooze_prevention"].type = coBool;
+        Options["ooze_prevention"].label = "Enable";
+        Options["ooze_prevention"].tooltip = "This option will drop the temperature of the inactive extruders to prevent oozing. It will enable a tall skirt automatically and move extruders outside such skirt when changing temperatures.";
+        Options["ooze_prevention"].cli = "ooze-prevention!";
+
+        Options["output_filename_format"].type = coString;
+        Options["output_filename_format"].label = "Output filename format";
+        Options["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].";
+        Options["output_filename_format"].cli = "output-filename-format=s";
+        Options["output_filename_format"].full_width = true;
+
+        Options["overhangs"].type = coBool;
+        Options["overhangs"].label = "Detect bridging perimeters";
+        Options["overhangs"].category = "Layers and Perimeters";
+        Options["overhangs"].tooltip = "Experimental option to adjust flow for overhangs (bridge flow will be used), to apply bridge speed to them and enable fan.";
+        Options["overhangs"].cli = "overhangs!";
+        Options["overhangs"].scope = "object";
+
+        Options["perimeter_acceleration"].type = coFloat;
+        Options["perimeter_acceleration"].label = "Perimeters";
+        Options["perimeter_acceleration"].tooltip = "This is the acceleration your printer will use for perimeters. A high value like 9000 usually gives good results if your hardware is up to the job. Set zero to disable acceleration control for perimeters.";
+        Options["perimeter_acceleration"].sidetext = "mm/s²";
+        Options["perimeter_acceleration"].cli = "perimeter-acceleration=f";
+
+        Options["perimeter_extruder"].type = coInt;
+        Options["perimeter_extruder"].label = "Perimeter extruder";
+        Options["perimeter_extruder"].tooltip = "The extruder to use when printing perimeters.";
+        Options["perimeter_extruder"].cli = "perimeter-extruder=i";
+        Options["perimeter_extruder"].aliases.push_back("perimeters_extruder");
+
+        Options["perimeter_extrusion_width"].type = coFloatOrPercent;
+        Options["perimeter_extrusion_width"].label = "Perimeters";
+        Options["perimeter_extrusion_width"].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 layer height.";
+        Options["perimeter_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["perimeter_extrusion_width"].cli = "perimeter-extrusion-width=s";
+        Options["perimeter_extrusion_width"].aliases.push_back("perimeters_extrusion_width");
+
+        Options["perimeter_speed"].type = coFloat;
+        Options["perimeter_speed"].label = "Perimeters";
+        Options["perimeter_speed"].tooltip = "Speed for perimeters (contours, aka vertical shells).";
+        Options["perimeter_speed"].sidetext = "mm/s";
+        Options["perimeter_speed"].cli = "perimeter-speed=f";
+        Options["perimeter_speed"].aliases.push_back("perimeter_feed_rate");
+
+        Options["perimeters"].type = coInt;
+        Options["perimeters"].label = "Perimeters (minimum)";
+        Options["perimeters"].category = "Layers and Perimeters";
+        Options["perimeters"].tooltip = "This option sets the number of perimeters to generate for each layer. Note that Slic3r may increase this number automatically when it detects sloping surfaces which benefit from a higher number of perimeters if the Extra Perimeters option is enabled.";
+        Options["perimeters"].cli = "perimeters=i";
+        Options["perimeters"].scope = "object";
+        Options["perimeters"].aliases.push_back("perimeter_offsets");
+
+        Options["post_process"].type = coStrings;
+        Options["post_process"].label = "Post-processing scripts";
+        Options["post_process"].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.";
+        Options["post_process"].cli = "post-process=s@";
+        Options["post_process"].multiline = true;
+        Options["post_process"].full_width = true;
+        Options["post_process"].height = 60;
+
+        Options["print_center"].type = coPoint;
+        Options["print_center"].label = "Print center";
+        Options["print_center"].tooltip = "These G-code coordinates are used to center your plater viewport.";
+        Options["print_center"].sidetext = "mm";
+        Options["print_center"].cli = "print-center=s";
+
+        Options["raft_layers"].type = coInt;
+        Options["raft_layers"].label = "Raft layers";
+        Options["raft_layers"].category = "Support material";
+        Options["raft_layers"].tooltip = "The object will be raised by this number of layers, and support material will be generated under it.";
+        Options["raft_layers"].sidetext = "layers";
+        Options["raft_layers"].cli = "raft-layers=i";
+        Options["raft_layers"].scope = "object";
+
+        Options["randomize_start"].type = coBool;
+        Options["randomize_start"].label = "Randomize starting points";
+        Options["randomize_start"].tooltip = "Start each layer from a different vertex to prevent plastic build-up on the same corner.";
+        Options["randomize_start"].cli = "randomize-start!";
+
+        Options["resolution"].type = coFloat;
+        Options["resolution"].label = "Resolution";
+        Options["resolution"].tooltip = "Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input.";
+        Options["resolution"].sidetext = "mm";
+        Options["resolution"].cli = "resolution=f";
+        Options["resolution"].min = 0;
+
+        Options["retract_before_travel"].type = coFloats;
+        Options["retract_before_travel"].label = "Minimum travel after retraction";
+        Options["retract_before_travel"].tooltip = "Retraction is not triggered when travel moves are shorter than this length.";
+        Options["retract_before_travel"].sidetext = "mm";
+        Options["retract_before_travel"].cli = "retract-before-travel=f@";
+
+        Options["retract_layer_change"].type = coBools;
+        Options["retract_layer_change"].label = "Retract on layer change";
+        Options["retract_layer_change"].tooltip = "This flag enforces a retraction whenever a Z move is done.";
+        Options["retract_layer_change"].cli = "retract-layer-change!";
+
+        Options["retract_length"].type = coFloats;
+        Options["retract_length"].label = "Length";
+        Options["retract_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).";
+        Options["retract_length"].sidetext = "mm (zero to disable)";
+        Options["retract_length"].cli = "retract-length=f@";
+
+        Options["retract_length_toolchange"].type = coFloats;
+        Options["retract_length_toolchange"].label = "Length";
+        Options["retract_length_toolchange"].tooltip = "When retraction is triggered before changing tool, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).";
+        Options["retract_length_toolchange"].sidetext = "mm (zero to disable)";
+        Options["retract_length_toolchange"].cli = "retract-length-toolchange=f@";
+
+        Options["retract_lift"].type = coFloats;
+        Options["retract_lift"].label = "Lift Z";
+        Options["retract_lift"].tooltip = "If you set this to a positive value, Z is quickly raised every time a retraction is triggered. When using multiple extruders, only the setting for the first extruder will be considered.";
+        Options["retract_lift"].sidetext = "mm";
+        Options["retract_lift"].cli = "retract-lift=f@";
+
+        Options["retract_restart_extra"].type = coFloats;
+        Options["retract_restart_extra"].label = "Extra length on restart";
+        Options["retract_restart_extra"].tooltip = "When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed.";
+        Options["retract_restart_extra"].sidetext = "mm";
+        Options["retract_restart_extra"].cli = "retract-restart-extra=f@";
+
+        Options["retract_restart_extra_toolchange"].type = coFloats;
+        Options["retract_restart_extra_toolchange"].label = "Extra length on restart";
+        Options["retract_restart_extra_toolchange"].tooltip = "When the retraction is compensated after changing tool, the extruder will push this additional amount of filament.";
+        Options["retract_restart_extra_toolchange"].sidetext = "mm";
+        Options["retract_restart_extra_toolchange"].cli = "retract-restart-extra-toolchange=f@";
+
+        Options["retract_speed"].type = coInts;
+        Options["retract_speed"].label = "Speed";
+        Options["retract_speed"].tooltip = "The speed for retractions (it only applies to the extruder motor).";
+        Options["retract_speed"].sidetext = "mm/s";
+        Options["retract_speed"].cli = "retract-speed=f@";
+        Options["retract_speed"].max = 1000;
+
+        Options["rotate"].type = coInt;
+        Options["rotate"].label = "Rotate";
+        Options["rotate"].sidetext = "°";
+        Options["rotate"].cli = "rotate=i";
+        Options["rotate"].max = 359;
+
+        Options["scale"].type = coFloat;
+        Options["scale"].label = "Scale";
+        Options["scale"].cli = "scale=f";
+
+        Options["skirt_distance"].type = coFloat;
+        Options["skirt_distance"].label = "Distance from object";
+        Options["skirt_distance"].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.";
+        Options["skirt_distance"].sidetext = "mm";
+        Options["skirt_distance"].cli = "skirt-distance=f";
+
+        Options["skirt_height"].type = coInt;
+        Options["skirt_height"].label = "Skirt height";
+        Options["skirt_height"].tooltip = "Height of skirt expressed in layers. Set this to a tall value to use skirt as a shield against drafts.";
+        Options["skirt_height"].sidetext = "layers";
+        Options["skirt_height"].cli = "skirt-height=i";
+
+        Options["skirts"].type = coInt;
+        Options["skirts"].label = "Loops";
+        Options["skirts"].tooltip = "Number of loops for this skirt, in other words its thickness. Set this to zero to disable skirt.";
+        Options["skirts"].cli = "skirts=i";
+
+        Options["slowdown_below_layer_time"].type = coInt;
+        Options["slowdown_below_layer_time"].label = "Slow down if layer print time is below";
+        Options["slowdown_below_layer_time"].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.";
+        Options["slowdown_below_layer_time"].sidetext = "approximate seconds";
+        Options["slowdown_below_layer_time"].cli = "slowdown-below-layer-time=i";
+        Options["slowdown_below_layer_time"].width = 60;
+        Options["slowdown_below_layer_time"].max = 1000;
+
+        Options["small_perimeter_speed"].type = coFloatOrPercent;
+        Options["small_perimeter_speed"].label = "Small perimeters";
+        Options["small_perimeter_speed"].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.";
+        Options["small_perimeter_speed"].sidetext = "mm/s or %";
+        Options["small_perimeter_speed"].cli = "small-perimeter-speed=s";
+        Options["small_perimeter_speed"].ratio_over = "perimeter_speed";
+
+        Options["solid_fill_pattern"].type = coEnum;
+        Options["solid_fill_pattern"].label = "Top/bottom fill pattern";
+        Options["solid_fill_pattern"].category = "Infill";
+        Options["solid_fill_pattern"].tooltip = "Fill pattern for top/bottom infill.";
+        Options["solid_fill_pattern"].cli = "solid-fill-pattern=s";
+        Options["solid_fill_pattern"].scope = "object";
+        Options["solid_fill_pattern"].enum_values.push_back("rectilinear");
+        Options["solid_fill_pattern"].enum_values.push_back("concentric");
+        Options["solid_fill_pattern"].enum_values.push_back("hilbertcurve");
+        Options["solid_fill_pattern"].enum_values.push_back("archimedeanchords");
+        Options["solid_fill_pattern"].enum_values.push_back("octagramspiral");
+        Options["solid_fill_pattern"].enum_labels.push_back("rectilinear");
+        Options["solid_fill_pattern"].enum_labels.push_back("concentric");
+        Options["solid_fill_pattern"].enum_labels.push_back("hilbertcurve (slow)");
+        Options["solid_fill_pattern"].enum_labels.push_back("archimedeanchords (slow)");
+        Options["solid_fill_pattern"].enum_labels.push_back("octagramspiral (slow)");
+
+        Options["solid_infill_below_area"].type = coFloat;
+        Options["solid_infill_below_area"].label = "Solid infill threshold area";
+        Options["solid_infill_below_area"].category = "Infill";
+        Options["solid_infill_below_area"].tooltip = "Force solid infill for regions having a smaller area than the specified threshold.";
+        Options["solid_infill_below_area"].sidetext = "mm²";
+        Options["solid_infill_below_area"].cli = "solid-infill-below-area=f";
+        Options["solid_infill_below_area"].scope = "object";
+
+        Options["solid_infill_every_layers"].type = coInt;
+        Options["solid_infill_every_layers"].label = "Solid infill every";
+        Options["solid_infill_every_layers"].category = "Infill";
+        Options["solid_infill_every_layers"].tooltip = "This feature allows to force a solid layer every given number of layers. Zero to disable.";
+        Options["solid_infill_every_layers"].sidetext = "layers";
+        Options["solid_infill_every_layers"].cli = "solid-infill-every-layers=i";
+        Options["solid_infill_every_layers"].scope = "object";
+        Options["solid_infill_every_layers"].min = 0;
+
+        Options["solid_infill_extrusion_width"].type = coFloatOrPercent;
+        Options["solid_infill_extrusion_width"].label = "Solid infill";
+        Options["solid_infill_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. If expressed as percentage (for example 90%) if will be computed over layer height.";
+        Options["solid_infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["solid_infill_extrusion_width"].cli = "solid-infill-extrusion-width=s";
+
+        Options["solid_infill_speed"].type = coFloatOrPercent;
+        Options["solid_infill_speed"].label = "Solid infill";
+        Options["solid_infill_speed"].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.";
+        Options["solid_infill_speed"].sidetext = "mm/s or %";
+        Options["solid_infill_speed"].cli = "solid-infill-speed=s";
+        Options["solid_infill_speed"].ratio_over = "infill_speed";
+        Options["solid_infill_speed"].aliases.push_back("solid_infill_feed_rate");
+
+        Options["solid_layers"].type = coInt;
+        Options["solid_layers"].label = "Solid layers";
+        Options["solid_layers"].tooltip = "Number of solid layers to generate on top and bottom surfaces.";
+        Options["solid_layers"].cli = "solid-layers=i";
+        Options["solid_layers"].shortcut.push_back("top_solid_layers");
+        Options["solid_layers"].shortcut.push_back("bottom_solid_layers");
+
+        Options["spiral_vase"].type = coBool;
+        Options["spiral_vase"].label = "Spiral vase";
+        Options["spiral_vase"].tooltip = "This experimental feature will raise Z gradually while printing a single-walled object in order to remove any visible seam. By enabling this option other settings will be overridden to enforce a single perimeter, no infill, no top solid layers, no support material. You can still set any number of bottom solid layers as well as skirt/brim loops. It won't work when printing more than an object.";
+        Options["spiral_vase"].cli = "spiral-vase!";
+
+        Options["standby_temperature_delta"].type = coInt;
+        Options["standby_temperature_delta"].label = "Temperature variation";
+        Options["standby_temperature_delta"].tooltip = "Temperature difference to be applied when an extruder is not active.";
+        Options["standby_temperature_delta"].sidetext = "∆°C";
+        Options["standby_temperature_delta"].cli = "standby-temperature-delta=i";
+        Options["standby_temperature_delta"].min = -400;
+        Options["standby_temperature_delta"].max = 400;
+
+        Options["start_gcode"].type = coString;
+        Options["start_gcode"].label = "Start G-code";
+        Options["start_gcode"].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.";
+        Options["start_gcode"].cli = "start-gcode=s";
+        Options["start_gcode"].multiline = true;
+        Options["start_gcode"].full_width = true;
+        Options["start_gcode"].height = 120;
+
+        Options["start_perimeters_at_concave_points"].type = coBool;
+        Options["start_perimeters_at_concave_points"].label = "Concave points";
+        Options["start_perimeters_at_concave_points"].tooltip = "Prefer to start perimeters at a concave point.";
+        Options["start_perimeters_at_concave_points"].cli = "start-perimeters-at-concave-points!";
+
+        Options["start_perimeters_at_non_overhang"].type = coBool;
+        Options["start_perimeters_at_non_overhang"].label = "Non-overhang points";
+        Options["start_perimeters_at_non_overhang"].tooltip = "Prefer to start perimeters at non-overhanging points.";
+        Options["start_perimeters_at_non_overhang"].cli = "start-perimeters-at-non-overhang!";
+
+        Options["support_material"].type = coBool;
+        Options["support_material"].label = "Generate support material";
+        Options["support_material"].category = "Support material";
+        Options["support_material"].tooltip = "Enable support material generation.";
+        Options["support_material"].cli = "support-material!";
+        Options["support_material"].scope = "object";
+
+        Options["support_material_angle"].type = coInt;
+        Options["support_material_angle"].label = "Pattern angle";
+        Options["support_material_angle"].category = "Support material";
+        Options["support_material_angle"].tooltip = "Use this setting to rotate the support material pattern on the horizontal plane.";
+        Options["support_material_angle"].sidetext = "°";
+        Options["support_material_angle"].cli = "support-material-angle=i";
+        Options["support_material_angle"].scope = "object";
+
+        Options["support_material_enforce_layers"].type = coInt;
+        Options["support_material_enforce_layers"].label = "Enforce support for the first";
+        Options["support_material_enforce_layers"].category = "Support material";
+        Options["support_material_enforce_layers"].tooltip = "Generate support material for the specified number of layers counting from bottom, regardless of whether normal support material is enabled or not and regardless of any angle threshold. This is useful for getting more adhesion of objects having a very thin or poor footprint on the build plate.";
+        Options["support_material_enforce_layers"].sidetext = "layers";
+        Options["support_material_enforce_layers"].cli = "support-material-enforce-layers=f";
+        Options["support_material_enforce_layers"].scope = "object";
+        Options["support_material_enforce_layers"].full_label = true;
+
+        Options["support_material_extruder"].type = coInt;
+        Options["support_material_extruder"].label = "Support material extruder";
+        Options["support_material_extruder"].tooltip = "The extruder to use when printing support material. This affects brim and raft too.";
+        Options["support_material_extruder"].cli = "support-material-extruder=i";
+
+        Options["support_material_extrusion_width"].type = coFloatOrPercent;
+        Options["support_material_extrusion_width"].label = "Support material";
+        Options["support_material_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for support material. If expressed as percentage (for example 90%) if will be computed over layer height.";
+        Options["support_material_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["support_material_extrusion_width"].cli = "support-material-extrusion-width=s";
+
+        Options["support_material_interface_extruder"].type = coInt;
+        Options["support_material_interface_extruder"].label = "Support material interface extruder";
+        Options["support_material_interface_extruder"].tooltip = "The extruder to use when printing support material interface. This affects raft too.";
+        Options["support_material_interface_extruder"].cli = "support-material-interface-extruder=i";
+
+        Options["support_material_interface_layers"].type = coInt;
+        Options["support_material_interface_layers"].label = "Interface layers";
+        Options["support_material_interface_layers"].category = "Support material";
+        Options["support_material_interface_layers"].tooltip = "Number of interface layers to insert between the object(s) and support material.";
+        Options["support_material_interface_layers"].sidetext = "layers";
+        Options["support_material_interface_layers"].cli = "support-material-interface-layers=i";
+        Options["support_material_interface_layers"].scope = "object";
+
+        Options["support_material_interface_spacing"].type = coFloat;
+        Options["support_material_interface_spacing"].label = "Interface pattern spacing";
+        Options["support_material_interface_spacing"].category = "Support material";
+        Options["support_material_interface_spacing"].tooltip = "Spacing between interface lines. Set zero to get a solid interface.";
+        Options["support_material_interface_spacing"].sidetext = "mm";
+        Options["support_material_interface_spacing"].cli = "support-material-interface-spacing=f";
+        Options["support_material_interface_spacing"].scope = "object";
+
+        Options["support_material_pattern"].type = coEnum;
+        Options["support_material_pattern"].label = "Pattern";
+        Options["support_material_pattern"].category = "Support material";
+        Options["support_material_pattern"].tooltip = "Pattern used to generate support material.";
+        Options["support_material_pattern"].cli = "support-material-pattern=s";
+        Options["support_material_pattern"].scope = "object";
+        Options["support_material_pattern"].enum_values.push_back("rectilinear");
+        Options["support_material_pattern"].enum_values.push_back("rectilinear-grid");
+        Options["support_material_pattern"].enum_values.push_back("honeycomb");
+        Options["support_material_pattern"].enum_labels.push_back("rectilinear");
+        Options["support_material_pattern"].enum_labels.push_back("rectilinear grid");
+        Options["support_material_pattern"].enum_labels.push_back("honeycomb");
+
+        Options["support_material_spacing"].type = coFloat;
+        Options["support_material_spacing"].label = "Pattern spacing";
+        Options["support_material_spacing"].category = "Support material";
+        Options["support_material_spacing"].tooltip = "Spacing between support material lines.";
+        Options["support_material_spacing"].sidetext = "mm";
+        Options["support_material_spacing"].cli = "support-material-spacing=f";
+        Options["support_material_spacing"].scope = "object";
+
+        Options["support_material_speed"].type = coFloat;
+        Options["support_material_speed"].label = "Support material";
+        Options["support_material_speed"].tooltip = "Speed for printing support material.";
+        Options["support_material_speed"].sidetext = "mm/s";
+        Options["support_material_speed"].cli = "support-material-speed=f";
+
+        Options["support_material_threshold"].type = coInt;
+        Options["support_material_threshold"].label = "Overhang threshold";
+        Options["support_material_threshold"].category = "Support material";
+        Options["support_material_threshold"].tooltip = "Support material will not be generated for overhangs whose slope angle (90° = vertical) is above the given threshold. In other words, this value represent the most horizontal slope (measured from the horizontal plane) that you can print without support material. Set to zero for automatic detection (recommended).";
+        Options["support_material_threshold"].sidetext = "°";
+        Options["support_material_threshold"].cli = "support-material-threshold=i";
+        Options["support_material_threshold"].scope = "object";
+
+        Options["temperature"].type = coInts;
+        Options["temperature"].label = "Other layers";
+        Options["temperature"].tooltip = "Extruder temperature for layers after the first one. Set this to zero to disable temperature control commands in the output.";
+        Options["temperature"].sidetext = "°C";
+        Options["temperature"].cli = "temperature=i@";
+        Options["temperature"].full_label = true;
+        Options["temperature"].max = 400;
+
+        Options["thin_walls"].type = coBool;
+        Options["thin_walls"].label = "Detect thin walls";
+        Options["thin_walls"].category = "Layers and Perimeters";
+        Options["thin_walls"].tooltip = "Detect single-width walls (parts where two extrusions don't fit and we need to collapse them into a single trace).";
+        Options["thin_walls"].cli = "thin-walls!";
+        Options["thin_walls"].scope = "object";
+
+        Options["threads"].type = coInt;
+        Options["threads"].label = "Threads";
+        Options["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.";
+        Options["threads"].sidetext = "(more speed but more memory usage)";
+        Options["threads"].cli = "threads|j=i";
+        Options["threads"].readonly = true;
+        Options["threads"].min = 1;
+        Options["threads"].max = 16;
+
+        Options["toolchange_gcode"].type = coString;
+        Options["toolchange_gcode"].label = "Tool change G-code";
+        Options["toolchange_gcode"].tooltip = "This custom code is inserted at every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].";
+        Options["toolchange_gcode"].cli = "toolchange-gcode=s";
+        Options["toolchange_gcode"].multiline = true;
+        Options["toolchange_gcode"].full_width = true;
+        Options["toolchange_gcode"].height = 50;
+
+        Options["top_infill_extrusion_width"].type = coFloatOrPercent;
+        Options["top_infill_extrusion_width"].label = "Top solid infill";
+        Options["top_infill_extrusion_width"].tooltip = "Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. If expressed as percentage (for example 90%) if will be computed over layer height.";
+        Options["top_infill_extrusion_width"].sidetext = "mm or % (leave 0 for default)";
+        Options["top_infill_extrusion_width"].cli = "top-infill-extrusion-width=s";
+
+        Options["top_solid_infill_speed"].type = coFloatOrPercent;
+        Options["top_solid_infill_speed"].label = "Top solid infill";
+        Options["top_solid_infill_speed"].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.";
+        Options["top_solid_infill_speed"].sidetext = "mm/s or %";
+        Options["top_solid_infill_speed"].cli = "top-solid-infill-speed=s";
+        Options["top_solid_infill_speed"].ratio_over = "solid_infill_speed";
+
+        Options["top_solid_layers"].type = coInt;
+        Options["top_solid_layers"].label = "Top";
+        Options["top_solid_layers"].category = "Layers and Perimeters";
+        Options["top_solid_layers"].tooltip = "Number of solid layers to generate on top surfaces.";
+        Options["top_solid_layers"].cli = "top-solid-layers=i";
+        Options["top_solid_layers"].scope = "object";
+        Options["top_solid_layers"].full_label = true;
+
+        Options["travel_speed"].type = coFloat;
+        Options["travel_speed"].label = "Travel";
+        Options["travel_speed"].tooltip = "Speed for travel moves (jumps between distant extrusion points).";
+        Options["travel_speed"].sidetext = "mm/s";
+        Options["travel_speed"].cli = "travel-speed=f";
+        Options["travel_speed"].aliases.push_back("travel_feed_rate");
+
+        Options["use_firmware_retraction"].type = coBool;
+        Options["use_firmware_retraction"].label = "Use firmware retraction";
+        Options["use_firmware_retraction"].tooltip = "This experimental setting uses G10 and G11 commands to have the firmware handle the retraction. This is only supported in recent Marlin.";
+        Options["use_firmware_retraction"].cli = "use-firmware-retraction!";
+
+        Options["use_relative_e_distances"].type = coBool;
+        Options["use_relative_e_distances"].label = "Use relative E distances";
+        Options["use_relative_e_distances"].tooltip = "If your firmware requires relative E values, check this, otherwise leave it unchecked. Most firmwares use absolute values.";
+        Options["use_relative_e_distances"].cli = "use-relative-e-distances!";
+
+        Options["vibration_limit"].type = coFloat;
+        Options["vibration_limit"].label = "Vibration limit";
+        Options["vibration_limit"].tooltip = "This experimental option will slow down those moves hitting the configured frequency limit. The purpose of limiting vibrations is to avoid mechanical resonance. Set zero to disable.";
+        Options["vibration_limit"].sidetext = "Hz";
+        Options["vibration_limit"].cli = "vibration-limit=f";
+
+        Options["wipe"].type = coBools;
+        Options["wipe"].label = "Wipe while retracting";
+        Options["wipe"].tooltip = "This flag will move the nozzle while retracting to minimize the possible blob on leaky extruders.";
+        Options["wipe"].cli = "wipe!";
+
+        Options["z_offset"].type = coFloat;
+        Options["z_offset"].label = "Z offset";
+        Options["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).";
+        Options["z_offset"].sidetext = "mm";
+        Options["z_offset"].cli = "z-offset=f";
+        
+        return Options;
+    };
+};
+
+class DynamicPrintConfig : public DynamicConfig
+{
+    public:
+    DynamicPrintConfig() {
+        this->def = &PrintConfig::PrintConfigDef;
+    };
+
+};
+
+}
+
+#endif
diff --git a/xs/t/15_config.t b/xs/t/15_config.t
new file mode 100644
index 000000000..0ece6bd95
--- /dev/null
+++ b/xs/t/15_config.t
@@ -0,0 +1,102 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Slic3r::XS;
+use Test::More tests => 76;
+
+foreach my $config (Slic3r::Config->new, Slic3r::Config::Print->new) {
+    $config->set('layer_height', 0.3);
+    ok abs($config->get('layer_height') - 0.3) < 1e-4, 'set/get float';
+    is $config->serialize('layer_height'), '0.3', 'serialize float';
+    
+    $config->set('perimeters', 2);
+    is $config->get('perimeters'), 2, 'set/get int';
+    is $config->serialize('perimeters'), '2', 'serialize int';
+    
+    $config->set('extrusion_axis', 'A');
+    is $config->get('extrusion_axis'), 'A', 'set/get string';
+    is $config->serialize('extrusion_axis'), 'A', 'serialize string';
+    
+    $config->set('notes', "foo\nbar");
+    is $config->get('notes'), "foo\nbar", 'set/get string with newline';
+    is $config->serialize('notes'), 'foo\nbar', 'serialize string with newline';
+    $config->set_deserialize('notes', 'bar\nbaz');
+    is $config->get('notes'), "bar\nbaz", 'deserialize string with newline';
+    
+    $config->set('first_layer_height', 0.3);
+    ok abs($config->get('first_layer_height') - 0.3) < 1e-4, 'set/get absolute floatOrPercent';
+    is $config->serialize('first_layer_height'), '0.3', 'serialize absolute floatOrPercent';
+    
+    $config->set('first_layer_height', '50%');
+    ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent';
+    is $config->serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent';
+    
+    $config->set('print_center', [50,80]);
+    is_deeply $config->get('print_center'), [50,80], 'set/get point';
+    is $config->serialize('print_center'), '50,80', 'serialize point';
+    $config->set_deserialize('print_center', '20,10');
+    is_deeply $config->get('print_center'), [20,10], 'deserialize point';
+    
+    $config->set('use_relative_e_distances', 1);
+    is $config->get('use_relative_e_distances'), 1, 'set/get bool';
+    is $config->serialize('use_relative_e_distances'), '1', 'serialize bool';
+    
+    $config->set('gcode_flavor', 'teacup');
+    is $config->get('gcode_flavor'), 'teacup', 'set/get enum';
+    is $config->serialize('gcode_flavor'), 'teacup', 'serialize enum';
+    $config->set_deserialize('gcode_flavor', 'mach3');
+    is $config->get('gcode_flavor'), 'mach3', 'deserialize enum';
+    
+    $config->set('extruder_offset', [[10,20],[30,45]]);
+    is_deeply $config->get('extruder_offset'), [[10,20],[30,45]], 'set/get points';
+    is $config->serialize('extruder_offset'), '10x20,30x45', 'serialize points';
+    $config->set_deserialize('extruder_offset', '20x10');
+    is_deeply $config->get('extruder_offset'), [[20,10]], 'deserialize points';
+    
+    # truncate ->get() to first decimal digit
+    $config->set('nozzle_diameter', [0.2,0.3]);
+    is_deeply [ map int($_*10)/10, @{$config->get('nozzle_diameter')} ], [0.2,0.3], 'set/get floats';
+    is $config->serialize('nozzle_diameter'), '0.2,0.3', 'serialize floats';
+    $config->set_deserialize('nozzle_diameter', '0.1,0.4');
+    is_deeply [ map int($_*10)/10, @{$config->get('nozzle_diameter')} ], [0.1,0.4], 'deserialize floats';
+    
+    $config->set('temperature', [180,210]);
+    is_deeply $config->get('temperature'), [180,210], 'set/get ints';
+    is $config->serialize('temperature'), '180,210', 'serialize ints';
+    $config->set_deserialize('temperature', '195,220');
+    is_deeply $config->get('temperature'), [195,220], 'deserialize ints';
+    
+    $config->set('wipe', [1,0]);
+    is_deeply $config->get('wipe'), [1,0], 'set/get bools';
+    is $config->serialize('wipe'), '1,0', 'serialize bools';
+    $config->set_deserialize('wipe', '0,1,1');
+    is_deeply $config->get('wipe'), [0,1,1], 'deserialize bools';
+    
+    $config->set('post_process', ['foo','bar']);
+    is_deeply $config->get('post_process'), ['foo','bar'], 'set/get strings';
+    is $config->serialize('post_process'), 'foo;bar', 'serialize strings';
+    $config->set_deserialize('post_process', 'bar;baz');
+    is_deeply $config->get('post_process'), ['bar','baz'], 'deserialize strings';
+    
+    is_deeply [ sort @{$config->get_keys} ], [ sort keys %{$config->as_hash} ], 'get_keys and as_hash';
+}
+
+{
+    my $config = Slic3r::Config->new;
+    $config->set('perimeters', 2);
+    
+    my $config2 = Slic3r::Config::Print->new;
+    $config2->apply_dynamic($config);
+    is $config2->get('perimeters'), 2, 'apply_dynamic';
+}
+
+{
+    my $config = Slic3r::Config::Print->new;
+    my $config2 = Slic3r::Config->new;
+    $config2->apply_static($config);
+    is $config2->get('perimeters'), Slic3r::Config::print_config_def()->{perimeters}{default}, 'apply_static and print_config_def';
+}
+
+__END__
diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp
new file mode 100644
index 000000000..7373dbee9
--- /dev/null
+++ b/xs/xsp/Config.xsp
@@ -0,0 +1,144 @@
+%module{Slic3r::XS};
+
+%{
+#include <myinit.h>
+#include "PrintConfig.hpp"
+%}
+
+%name{Slic3r::Config} class DynamicPrintConfig {
+    DynamicPrintConfig();
+    ~DynamicPrintConfig();
+    bool has(t_config_option_key opt_key);
+    SV* as_hash();
+    SV* get(t_config_option_key opt_key);
+    void set(t_config_option_key opt_key, SV* value);
+    void set_deserialize(t_config_option_key opt_key, std::string str);
+    std::string serialize(t_config_option_key opt_key);
+    double get_abs_value(t_config_option_key opt_key);
+    void apply(DynamicPrintConfig* other)
+        %code{% THIS->apply(*other, true); %};
+    void apply_static(PrintConfig* other)
+        %code{% THIS->apply(*other, true); %};
+    std::vector<std::string> get_keys()
+        %code{% THIS->keys(&RETVAL); %};
+%{
+
+%}
+};
+
+%name{Slic3r::Config::Print} class PrintConfig {
+    PrintConfig();
+    ~PrintConfig();
+    bool has(t_config_option_key opt_key);
+    SV* as_hash();
+    SV* get(t_config_option_key opt_key);
+    void set(t_config_option_key opt_key, SV* value);
+    void set_deserialize(t_config_option_key opt_key, std::string str);
+    std::string serialize(t_config_option_key opt_key);
+    double get_abs_value(t_config_option_key opt_key);
+    void apply_dynamic(DynamicPrintConfig* other)
+        %code{% THIS->apply(*other, true); %};
+    std::vector<std::string> get_keys()
+        %code{% THIS->keys(&RETVAL); %};
+%{
+
+%}
+};
+
+%package{Slic3r::Config};
+
+%{
+PROTOTYPES: DISABLE
+
+SV*
+print_config_def()
+    CODE:
+        PrintConfig config;
+        t_optiondef_map* def = config.def;
+        
+        HV* options_hv = newHV();
+        for (t_optiondef_map::iterator oit = def->begin(); oit != def->end(); ++oit) {
+            HV* hv = newHV();
+            
+            t_config_option_key opt_key = oit->first;
+            ConfigOptionDef* optdef     = &oit->second;
+            
+            const char* opt_type;
+            if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent) {
+                opt_type = "f";
+            } else if (optdef->type == coInt || optdef->type == coInts) {
+                opt_type = "i";
+            } else if (optdef->type == coString) {
+                opt_type = "s";
+            } else if (optdef->type == coStrings) {
+                opt_type = "s@";
+            } else if (optdef->type == coPoint || optdef->type == coPoints) {
+                opt_type = "point";
+            } else if (optdef->type == coBool || optdef->type == coBools) {
+                opt_type = "bool";
+            } else if (optdef->type == coEnum) {
+                opt_type = "select";
+            } else {
+                throw "Unknown option type";
+            }
+            (void)hv_stores( hv, "type",        newSVpv(opt_type, 0) );
+            (void)hv_stores( hv, "label",       newSVpvn(optdef->label.c_str(), optdef->label.length()) );
+            (void)hv_stores( hv, "category",    newSVpvn(optdef->category.c_str(), optdef->category.length()) );
+            (void)hv_stores( hv, "tooltip",     newSVpvn(optdef->tooltip.c_str(), optdef->tooltip.length()) );
+            (void)hv_stores( hv, "sidetext",    newSVpvn(optdef->sidetext.c_str(), optdef->sidetext.length()) );
+            (void)hv_stores( hv, "cli",         newSVpvn(optdef->cli.c_str(), optdef->cli.length()) );
+            (void)hv_stores( hv, "scope",       newSVpvn(optdef->scope.c_str(), optdef->scope.length()) );
+            (void)hv_stores( hv, "ratio_over",  newSVpvn(optdef->ratio_over.c_str(), optdef->ratio_over.length()) );
+            (void)hv_stores( hv, "multiline",   newSViv(optdef->multiline ? 1 : 0) );
+            (void)hv_stores( hv, "full_label",  newSViv(optdef->full_label ? 1 : 0) );
+            (void)hv_stores( hv, "full_width",  newSViv(optdef->full_width ? 1 : 0) );
+            (void)hv_stores( hv, "readonly",    newSViv(optdef->readonly ? 1 : 0) );
+            (void)hv_stores( hv, "height",      newSViv(optdef->height) );
+            (void)hv_stores( hv, "width",       newSViv(optdef->width) );
+            (void)hv_stores( hv, "min",         newSViv(optdef->min) );
+            (void)hv_stores( hv, "max",         newSViv(optdef->max) );
+            
+            // aliases
+            {
+                AV* av = newAV();
+                av_fill(av, optdef->aliases.size()-1);
+                for (std::vector<t_config_option_key>::iterator it = optdef->aliases.begin(); it != optdef->aliases.end(); ++it)
+                    av_store(av, it - optdef->aliases.begin(), newSVpvn(it->c_str(), it->length()));
+                (void)hv_stores( hv, "aliases", newRV_noinc((SV*)av) );
+            }
+            
+            // shortcut
+            {
+                AV* av = newAV();
+                av_fill(av, optdef->shortcut.size()-1);
+                for (std::vector<t_config_option_key>::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it)
+                    av_store(av, it - optdef->shortcut.begin(), newSVpvn(it->c_str(), it->length()));
+                (void)hv_stores( hv, "shortcut", newRV_noinc((SV*)av) );
+            }
+            
+            // enum_values
+            {
+                AV* av = newAV();
+                av_fill(av, optdef->enum_values.size()-1);
+                for (std::vector<std::string>::iterator it = optdef->enum_values.begin(); it != optdef->enum_values.end(); ++it)
+                    av_store(av, it - optdef->enum_values.begin(), newSVpvn(it->c_str(), it->length()));
+                (void)hv_stores( hv, "values", newRV_noinc((SV*)av) );
+            }
+            
+            // enum_labels
+            {
+                AV* av = newAV();
+                av_fill(av, optdef->enum_labels.size()-1);
+                for (std::vector<std::string>::iterator it = optdef->enum_labels.begin(); it != optdef->enum_labels.end(); ++it)
+                    av_store(av, it - optdef->enum_labels.begin(), newSVpvn(it->c_str(), it->length()));
+                (void)hv_stores( hv, "labels", newRV_noinc((SV*)av) );
+            }
+            
+            (void)hv_stores( hv, "default", config.get(opt_key) );
+            (void)hv_store( options_hv, opt_key.c_str(), opt_key.length(), newRV_noinc((SV*)hv), 0 );
+        }
+        
+        RETVAL = newRV_noinc((SV*)options_hv);
+    OUTPUT:
+        RETVAL
+%}
diff --git a/xs/xsp/my.map b/xs/xsp/my.map
index 415b9a58c..7c370ac10 100644
--- a/xs/xsp/my.map
+++ b/xs/xsp/my.map
@@ -1,5 +1,8 @@
 std::vector<Points::size_type>  T_STD_VECTOR_INT
+t_config_option_key T_STD_STRING
 
+DynamicPrintConfig*  O_OBJECT
+PrintConfig*  O_OBJECT
 ZTable*         O_OBJECT
 TriangleMesh*         O_OBJECT
 Point*         O_OBJECT
diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt
index 6457717e3..eb6302e7d 100644
--- a/xs/xsp/typemap.xspt
+++ b/xs/xsp/typemap.xspt
@@ -1,11 +1,15 @@
 %typemap{bool}{simple};
 %typemap{std::string};
+%typemap{t_config_option_key};
 %typemap{std::vector<unsigned int>*};
 %typemap{std::vector<double>};
 %typemap{std::vector<double>*};
+%typemap{std::vector<std::string>};
 %typemap{SV*};
 %typemap{AV*};
 %typemap{Point*};
+%typemap{DynamicPrintConfig*};
+%typemap{PrintConfig*};
 %typemap{ExPolygon*};
 %typemap{ExPolygonCollection*};
 %typemap{Line*};