Browse Source

Refactored configuration handling.
Slic3r::Config is now an object. Multiple partial config objects are used throughout the codebase as local repositories, then merged and serialized when necessary.

Alessandro Ranellucci 12 years ago
parent
commit
7e34244b05

+ 14 - 140
lib/Slic3r.pm

@@ -50,153 +50,27 @@ use Slic3r::Surface;
 use Slic3r::TriangleMesh;
 eval "use Slic3r::Build";
 
-our $threads            = $have_threads ? 2 : 1;
-
-# miscellaneous options
-our $notes              = '';
-
-# output options
-our $output_filename_format = '[input_filename_base].gcode';
-our $post_process       = [];
-
-# printer options
-our $print_center       = [100,100];  # object will be centered around this point
-our $z_offset           = 0;
-our $gcode_flavor       = 'reprap';
-our $use_relative_e_distances = 0;
-our $extrusion_axis     = 'E';
-our $gcode_arcs         = 0;
-our $g0                 = 0;
-our $gcode_comments     = 0;
-
-# filament options
-our $filament_diameter      = [3];    # mm
-our $extrusion_multiplier   = [1];
-our $temperature            = [200];
-our $first_layer_temperature= [@$temperature];
-our $bed_temperature        = 0;
-our $first_layer_bed_temperature = $bed_temperature;
-
-# extruders
-our $extruders              = [];
-our $nozzle_diameter        = [0.5];
-
-# extruder mapping (1-based indexes)
-our $perimeter_extruder         = 1;
-our $infill_extruder            = 1;
-our $support_material_extruder  = 1;
-
-# speed options
-our $travel_speed           = 130;      # mm/s
-our $perimeter_speed        = 30;       # mm/s
-our $small_perimeter_speed  = 30;       # mm/s or %
-our $external_perimeter_speed  = '100%';       # mm/s or %
-our $infill_speed           = 60;       # mm/s
-our $solid_infill_speed     = 60;       # mm/s or %
-our $top_solid_infill_speed = 50;       # mm/s or %
-our $bridge_speed           = 60;       # mm/s
-our $first_layer_speed      = '30%';    # mm/s or %  
-
-# acceleration options
-our $acceleration           = 0;
-our $perimeter_acceleration = 25;   # mm/s^2
-our $infill_acceleration    = 50;   # mm/s^2
-
-# accuracy options
-our $scaling_factor         = 0.000001;
-our $resolution             = 0.01;
-our $small_perimeter_length = (6.5 / $scaling_factor)*2*PI;
-our $layer_height           = 0.4;
-our $first_layer_height     = '100%';  # mm or %
-our $_first_layer_height    = undef;   # mm (computed)
-our $infill_every_layers    = 1;
-
-# flow options
-our $extrusion_width                = 0;
-our $first_layer_extrusion_width    = '200%';
-our $perimeter_extrusion_width      = 0;
-our $infill_extrusion_width         = 0;
-our $support_material_extrusion_width = 0;
-our $bridge_flow_ratio              = 1;
-our $overlap_factor                 = 0.5;
-our $flow;
-our $first_layer_flow;
-our $perimeters_flow;
-our $infill_flow;
-our $support_material_flow;
-
-# print options
-our $perimeters         = 3;
-our $solid_layers       = 3;
-our $fill_pattern       = 'rectilinear';
-our $solid_fill_pattern = 'rectilinear';
-our $fill_density       = 0.4;  # 1 = 100%
-our $fill_angle         = 45;
-our $extra_perimeters   = 1;
-our $randomize_start    = 1;
-our $support_material   = 0;
-our $support_material_threshold = 45;
-our $support_material_pattern = 'rectilinear';
-our $support_material_spacing = 2.5;
-our $support_material_angle = 0;
-our $start_gcode = "G28 ; home all axes";
-our $end_gcode = <<"END";
-M104 S0 ; turn off temperature
-G28 X0  ; home X axis
-M84     ; disable motors
-END
-our $layer_gcode        = '';
-
-# retraction options
-our $retract_length         = 1;    # mm
-our $retract_restart_extra  = 0;    # mm
-our $retract_speed          = 30;   # mm/s
-our $retract_before_travel  = 2;    # mm
-our $retract_lift           = 0;    # mm
-
-# cooling options
-our $cooling                = 0;
-our $min_fan_speed          = 35;
-our $max_fan_speed          = 100;
-our $bridge_fan_speed       = 100;
-our $fan_below_layer_time   = 60;
-our $slowdown_below_layer_time = 15;
-our $min_print_speed        = 10;
-our $disable_fan_first_layers = 1;
-our $fan_always_on          = 0;
-
-# skirt/brim options
-our $skirts             = 1;
-our $skirt_distance     = 6;    # mm
-our $skirt_height       = 1;    # layers
-our $brim_width         = 0;    # mm
-
-# transform options
-our $scale              = 1;
-our $rotate             = 0;
-our $duplicate_mode     = 'no';
-our $duplicate          = 1;
-our $bed_size           = [200,200];
-our $duplicate_grid     = [1,1];
-our $duplicate_distance = 6;    # mm
-
-# sequential printing
-our $complete_objects           = 0;
-our $extruder_clearance_radius  = 20;     # mm
-our $extruder_clearance_height  = 20;     # mm
-
-our $Defaults = Slic3r::Config->current;
-our $Settings = { presets => {} };  # application settings
+use constant SCALING_FACTOR         => 0.000001;
+use constant RESOLUTION             => 0.01;
+use constant OVERLAP_FACTOR         => 0.5;
+use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI;
+
+# The following variables hold the objects used throughout the slicing
+# process.  They should belong to the Print object, but we are keeping 
+# them here because it makes accessing them slightly faster.
+our $Config;
+our $extruders;
+our ($flow, $first_layer_flow, $perimeter_flow, $infill_flow, $support_material_flow);
 
 sub parallelize {
     my %params = @_;
     
-    if (!$params{disable} && $Slic3r::have_threads && $Slic3r::threads > 1) {
+    if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) {
         my $q = Thread::Queue->new;
-        $q->enqueue(@{ $params{items} }, (map undef, 1..$Slic3r::threads));
+        $q->enqueue(@{ $params{items} }, (map undef, 1..$Config->threads));
         
         my $thread_cb = sub { $params{thread_cb}->($q) };
-        foreach my $th (map threads->create($thread_cb), 1..$Slic3r::threads) {
+        foreach my $th (map threads->create($thread_cb), 1..$Config->threads) {
             $params{collect_cb}->($th->join);
         }
     } else {

File diff suppressed because it is too large
+ 247 - 227
lib/Slic3r/Config.pm


+ 1 - 1
lib/Slic3r/ExPolygon.pm

@@ -62,7 +62,7 @@ sub boost_polygon {
 sub offset {
     my $self = shift;
     my ($distance, $scale, $joinType, $miterLimit) = @_;
-    $scale      ||= $Slic3r::scaling_factor * 1000000;
+    $scale      ||= &Slic3r::SCALING_FACTOR * 1000000;
     $joinType   = JT_MITER if !defined $joinType;
     $miterLimit ||= 2;
     

+ 3 - 3
lib/Slic3r/Extruder.pm

@@ -29,15 +29,15 @@ sub mm3_per_mm {
     my $cache_key = "${s}_${h}";
     if (!exists $self->_mm3_per_mm_cache->{$cache_key}) {
         my $w_threshold = $h + $self->nozzle_diameter;
-        my $s_threshold = $w_threshold - $Slic3r::overlap_factor * ($w_threshold - ($w_threshold - $h * (1 - PI/4)));
+        my $s_threshold = $w_threshold - &Slic3r::OVERLAP_FACTOR * ($w_threshold - ($w_threshold - $h * (1 - PI/4)));
         
         if ($s >= $s_threshold) {
             # rectangle with semicircles at the ends
-            my $w = $s + $Slic3r::overlap_factor * $h * (1 - PI/4);
+            my $w = $s + &Slic3r::OVERLAP_FACTOR * $h * (1 - PI/4);
             $self->_mm3_per_mm_cache->{$cache_key} = $w * $h + ($h**2) / 4 * (PI - 4);
         } else {
             # rectangle with shrunk semicircles at the ends
-            my $w = ($s + $self->nozzle_diameter * $Slic3r::overlap_factor * (PI/4 - 1)) / (1 + $Slic3r::overlap_factor * (PI/4 - 1));
+            my $w = ($s + $self->nozzle_diameter * &Slic3r::OVERLAP_FACTOR * (PI/4 - 1)) / (1 + &Slic3r::OVERLAP_FACTOR * (PI/4 - 1));
             $self->_mm3_per_mm_cache->{$cache_key} = $self->nozzle_diameter * $h * (1 - PI/4) + $h * $w * PI/4;
         }
     }

+ 1 - 1
lib/Slic3r/ExtrusionPath.pm

@@ -159,7 +159,7 @@ sub detect_arcs {
     my ($max_angle, $len_epsilon) = @_;
     
     $max_angle = deg2rad($max_angle || 15);
-    $len_epsilon ||= 10 / $Slic3r::scaling_factor;
+    $len_epsilon ||= 10 / &Slic3r::SCALING_FACTOR;
     
     my @points = @{$self->points};
     my @paths = ();

+ 6 - 6
lib/Slic3r/Fill.pm

@@ -39,7 +39,7 @@ sub BUILD {
     my $max_print_dimension = ($print_size->[X] > $print_size->[Y] ? $print_size->[X] : $print_size->[Y]) * sqrt(2);
     $self->max_print_dimension($max_print_dimension);
     
-    $self->filler($_) for ('rectilinear', $Slic3r::fill_pattern, $Slic3r::solid_fill_pattern);
+    $self->filler($_) for ('rectilinear', $Slic3r::Config->fill_pattern, $Slic3r::Config->solid_fill_pattern);
 }
 
 sub filler {
@@ -131,8 +131,8 @@ sub make_fill {
     my @fills = ();
     my @fills_ordering_points =  ();
     SURFACE: foreach my $surface (@surfaces) {
-        my $filler          = $Slic3r::fill_pattern;
-        my $density         = $Slic3r::fill_density;
+        my $filler          = $Slic3r::Config->fill_pattern;
+        my $density         = $Slic3r::Config->fill_density;
         my $flow_spacing    = $layer->infill_flow->spacing;
         my $is_bridge       = $layer->id > 0 && $surface->surface_type == S_TYPE_BOTTOM;
         my $is_solid        = (grep { $surface->surface_type == $_ } S_TYPE_TOP, S_TYPE_BOTTOM, S_TYPE_INTERNALSOLID) ? 1 : 0;
@@ -140,10 +140,10 @@ sub make_fill {
         # force 100% density and rectilinear fill for external surfaces
         if ($surface->surface_type != S_TYPE_INTERNAL) {
             $density = 1;
-            $filler = $Slic3r::solid_fill_pattern;
+            $filler = $Slic3r::Config->solid_fill_pattern;
             if ($is_bridge) {
                 $filler = 'rectilinear';
-                $flow_spacing = sqrt($Slic3r::bridge_flow_ratio * ($layer->infill_flow->nozzle_diameter**2));
+                $flow_spacing = sqrt($Slic3r::Config->bridge_flow_ratio * ($layer->infill_flow->nozzle_diameter**2));
             } elsif ($surface->surface_type == S_TYPE_INTERNALSOLID) {
                 $filler = 'rectilinear';
             }
@@ -181,7 +181,7 @@ sub make_fill {
     {
         my %args = (
             role            => EXTR_ROLE_SOLIDFILL,
-            flow_spacing    => $layer->perimeters_flow->spacing,
+            flow_spacing    => $layer->perimeter_flow->spacing,
         );
         push @fills, map {
             $_->isa('Slic3r::Polygon')

+ 1 - 1
lib/Slic3r/Fill/Base.pm

@@ -5,7 +5,7 @@ use Moo;
 has 'print'               => (is => 'rw');
 has 'layer'               => (is => 'rw');
 has 'max_print_dimension' => (is => 'rw');
-has 'angle'               => (is => 'rw', default => sub { $Slic3r::fill_angle });
+has 'angle'               => (is => 'rw', default => sub { $Slic3r::Config->fill_angle });
 
 use constant PI => 4 * atan2(1, 1);
 

+ 2 - 2
lib/Slic3r/Flow.pm

@@ -4,7 +4,7 @@ use Moo;
 use Slic3r::Geometry qw(PI);
 
 has 'nozzle_diameter'   => (is => 'ro', required => 1);
-has 'layer_height'      => (is => 'ro', default => sub { $Slic3r::layer_height });
+has 'layer_height'      => (is => 'ro', default => sub { $Slic3r::Config->layer_height });
 
 has 'width'             => (is => 'rwp', builder => 1);
 has 'spacing'           => (is => 'lazy');
@@ -52,7 +52,7 @@ sub _build_spacing {
         # rectangle with shrunk semicircles at the ends
         $min_flow_spacing = $self->nozzle_diameter * (1 - PI/4) + $self->width * PI/4;
     }
-    return $self->width - $Slic3r::overlap_factor * ($self->width - $min_flow_spacing);
+    return $self->width - &Slic3r::OVERLAP_FACTOR * ($self->width - $min_flow_spacing);
 }
 
 1;

+ 60 - 60
lib/Slic3r/GCode.pm

@@ -25,15 +25,15 @@ has 'dec'                => (is => 'ro', default => sub { 3 } );
 has 'speeds' => (
     is      => 'ro',
     default => sub {{
-        travel              => 60 * Slic3r::Config->get('travel_speed'),
-        perimeter           => 60 * Slic3r::Config->get('perimeter_speed'),
-        small_perimeter     => 60 * Slic3r::Config->get('small_perimeter_speed'),
-        external_perimeter  => 60 * Slic3r::Config->get('external_perimeter_speed'),
-        infill              => 60 * Slic3r::Config->get('infill_speed'),
-        solid_infill        => 60 * Slic3r::Config->get('solid_infill_speed'),
-        top_solid_infill    => 60 * Slic3r::Config->get('top_solid_infill_speed'),
-        bridge              => 60 * Slic3r::Config->get('bridge_speed'),
-        retract             => 60 * Slic3r::Config->get('retract_speed'),
+        travel              => 60 * $Slic3r::Config->get_value('travel_speed'),
+        perimeter           => 60 * $Slic3r::Config->get_value('perimeter_speed'),
+        small_perimeter     => 60 * $Slic3r::Config->get_value('small_perimeter_speed'),
+        external_perimeter  => 60 * $Slic3r::Config->get_value('external_perimeter_speed'),
+        infill              => 60 * $Slic3r::Config->get_value('infill_speed'),
+        solid_infill        => 60 * $Slic3r::Config->get_value('solid_infill_speed'),
+        top_solid_infill    => 60 * $Slic3r::Config->get_value('top_solid_infill_speed'),
+        bridge              => 60 * $Slic3r::Config->get_value('bridge_speed'),
+        retract             => 60 * $Slic3r::Config->get_value('retract_speed'),
     }},
 );
 
@@ -62,7 +62,7 @@ sub change_layer {
     my ($layer) = @_;
     
     $self->layer($layer);
-    my $z = $Slic3r::z_offset + $layer->print_z * $Slic3r::scaling_factor;
+    my $z = $Slic3r::Config->z_offset + $layer->print_z * &Slic3r::SCALING_FACTOR;
     
     my $gcode = "";
     
@@ -70,8 +70,8 @@ sub change_layer {
     $gcode .= $self->G0(undef, $z, 0, 'move to next layer (' . $layer->id . ')')
         if $self->z != $z && !$self->lifted;
     
-    $gcode .= Slic3r::Config->replace_options($Slic3r::layer_gcode) . "\n"
-        if $Slic3r::layer_gcode;
+    $gcode .= $Slic3r::Config->replace_options($Slic3r::Config->layer_gcode) . "\n"
+        if $Slic3r::Config->layer_gcode;
     
     return $gcode;
 }
@@ -95,10 +95,10 @@ sub extrude_loop {
     # find the point of the loop that is closest to the current extruder position
     # or randomize if requested
     my $last_pos = $self->last_pos;
-    if ($Slic3r::randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) {
+    if ($Slic3r::Config->randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) {
         srand $self->layer->id * 10;
-        $last_pos = Slic3r::Point->new(scale $Slic3r::print_center->[X], scale $Slic3r::bed_size->[Y]);
-        $last_pos->rotate(rand(2*PI), $Slic3r::print_center);
+        $last_pos = Slic3r::Point->new(scale $Slic3r::Config->print_center->[X], scale $Slic3r::Config->bed_size->[Y]);
+        $last_pos->rotate(rand(2*PI), $Slic3r::Config->print_center);
     }
     my $start_index = $loop->nearest_point_index_to($last_pos);
     
@@ -123,7 +123,7 @@ sub extrude_path {
     $path->merge_continuous_lines;
     
     # detect arcs
-    if ($Slic3r::gcode_arcs && !$recursive) {
+    if ($Slic3r::Config->gcode_arcs && !$recursive) {
         my $gcode = "";
         foreach my $arc_path ($path->detect_arcs) {
             $gcode .= $self->extrude_path($arc_path, $description, 1);
@@ -136,10 +136,10 @@ sub extrude_path {
     # retract if distance from previous position is greater or equal to the one
     # specified by the user *and* to the maximum distance between infill lines
     {
-        my $distance_from_last_pos = $self->last_pos->distance_to($path->points->[0]) * $Slic3r::scaling_factor;
-        my $distance_threshold = $Slic3r::retract_before_travel;
-        $distance_threshold = 2 * ($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) / $Slic3r::fill_density * sqrt(2)
-            if 0 && $Slic3r::fill_density > 0 && $description =~ /fill/;
+        my $distance_from_last_pos = $self->last_pos->distance_to($path->points->[0]) * &Slic3r::SCALING_FACTOR;
+        my $distance_threshold = $Slic3r::Config->retract_before_travel;
+        $distance_threshold = 2 * ($self->layer ? $self->layer->flow->width : $Slic3r::flow->width) / $Slic3r::Config->fill_density * sqrt(2)
+            if 0 && $Slic3r::Config->fill_density > 0 && $description =~ /fill/;
     
         if ($distance_from_last_pos >= $distance_threshold) {
             $gcode .= $self->retract(travel_to => $path->points->[0]);
@@ -181,12 +181,12 @@ sub extrude_path {
         }
     }
     
-    if ($Slic3r::cooling) {
+    if ($Slic3r::Config->cooling) {
         my $path_time = unscale($path_length) / $self->speeds->{$self->last_speed} * 60;
         if ($self->layer->id == 0) {
-            $path_time = $Slic3r::first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
+            $path_time = $Slic3r::Config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
                 ? $path_time / ($1/100)
-                : unscale($path_length) / $Slic3r::first_layer_speed * 60;
+                : unscale($path_length) / $Slic3r::Config->first_layer_speed * 60;
         }
         $self->elapsed_time($self->elapsed_time + $path_time);
     }
@@ -198,18 +198,18 @@ sub retract {
     my $self = shift;
     my %params = @_;
     
-    return "" unless $Slic3r::retract_length > 0 
+    return "" unless $Slic3r::Config->retract_length > 0 
         && !$self->retracted;
     
     # prepare moves
     $self->speed('retract');
-    my $retract = [undef, undef, -$Slic3r::retract_length, "retract"];
-    my $lift    = ($Slic3r::retract_lift == 0 || defined $params{move_z})
+    my $retract = [undef, undef, -$Slic3r::Config->retract_length, "retract"];
+    my $lift    = ($Slic3r::Config->retract_lift == 0 || defined $params{move_z})
         ? undef
-        : [undef, $self->z + $Slic3r::retract_lift, 0, 'lift plate during retraction'];
+        : [undef, $self->z + $Slic3r::Config->retract_lift, 0, 'lift plate during retraction'];
     
     my $gcode = "";
-    if (($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3') && $params{travel_to}) {
+    if (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && $params{travel_to}) {
         if ($lift) {
             # combine lift and retract
             $lift->[2] = $retract->[2];
@@ -219,14 +219,14 @@ sub retract {
             my $travel = [$params{travel_to}, undef, $retract->[2], 'travel and retract'];
             $gcode .= $self->G0(@$travel);
         }
-    } elsif (($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3') && defined $params{move_z}) {
+    } elsif (($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3') && defined $params{move_z}) {
         # combine Z change and retraction
         my $travel = [undef, $params{move_z}, $retract->[2], 'change layer and retract'];
         $gcode .= $self->G0(@$travel);
     } else {
         $gcode .= $self->G1(@$retract);
-        if (defined $params{move_z} && $Slic3r::retract_lift > 0) {
-            my $travel = [undef, $params{move_z} + $Slic3r::retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
+        if (defined $params{move_z} && $Slic3r::Config->retract_lift > 0) {
+            my $travel = [undef, $params{move_z} + $Slic3r::Config->retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
             $gcode .= $self->G0(@$travel);
             $self->lifted(1);
         } elsif ($lift) {
@@ -238,7 +238,7 @@ sub retract {
     
     # reset extrusion distance during retracts
     # this makes sure we leave sufficient precision in the firmware
-    $gcode .= $self->reset_e if $Slic3r::gcode_flavor !~ /^(?:mach3|makerbot)$/;
+    $gcode .= $self->reset_e if $Slic3r::Config->gcode_flavor !~ /^(?:mach3|makerbot)$/;
     
     return $gcode;
 }
@@ -249,12 +249,12 @@ sub unretract {
     my $gcode = "";
     
     if ($self->lifted) {
-        $gcode .= $self->G0(undef, $self->z - $Slic3r::retract_lift, 0, 'restore layer Z');
+        $gcode .= $self->G0(undef, $self->z - $Slic3r::Config->retract_lift, 0, 'restore layer Z');
         $self->lifted(0);
     }
     
     $self->speed('retract');
-    $gcode .= $self->G0(undef, undef, ($Slic3r::retract_length + $Slic3r::retract_restart_extra), 
+    $gcode .= $self->G0(undef, undef, ($Slic3r::Config->retract_length + $Slic3r::Config->retract_restart_extra), 
         "compensate retraction");
     
     return $gcode;
@@ -264,22 +264,22 @@ sub reset_e {
     my $self = shift;
     
     $self->extrusion_distance(0);
-    return sprintf "G92 %s0%s\n", $Slic3r::extrusion_axis, ($Slic3r::gcode_comments ? ' ; reset extrusion distance' : '')
-        if $Slic3r::extrusion_axis && !$Slic3r::use_relative_e_distances;
+    return sprintf "G92 %s0%s\n", $Slic3r::Config->extrusion_axis, ($Slic3r::Config->gcode_comments ? ' ; reset extrusion distance' : '')
+        if $Slic3r::Config->extrusion_axis && !$Slic3r::Config->use_relative_e_distances;
 }
 
 sub set_acceleration {
     my $self = shift;
     my ($acceleration) = @_;
-    return "" unless $Slic3r::acceleration;
+    return "" unless $Slic3r::Config->acceleration;
     
     return sprintf "M201 E%s%s\n",
-        $acceleration, ($Slic3r::gcode_comments ? ' ; adjust acceleration' : '');
+        $acceleration, ($Slic3r::Config->gcode_comments ? ' ; adjust acceleration' : '');
 }
 
 sub G0 {
     my $self = shift;
-    return $self->G1(@_) if !($Slic3r::g0 || $Slic3r::gcode_flavor eq 'mach3');
+    return $self->G1(@_) if !($Slic3r::Config->g0 || $Slic3r::Config->gcode_flavor eq 'mach3');
     return $self->_G0_G1("G0", @_);
 }
 
@@ -295,8 +295,8 @@ sub _G0_G1 {
     
     if ($point) {
         $gcode .= sprintf " X%.${dec}f Y%.${dec}f", 
-            ($point->x * $Slic3r::scaling_factor) + $self->shift_x, 
-            ($point->y * $Slic3r::scaling_factor) + $self->shift_y; #**
+            ($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x, 
+            ($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y; #**
         $self->last_pos($point);
     }
     if (defined $z && $z != $self->z) {
@@ -315,13 +315,13 @@ sub G2_G3 {
     my $gcode = $orientation eq 'cw' ? "G2" : "G3";
     
     $gcode .= sprintf " X%.${dec}f Y%.${dec}f", 
-        ($point->x * $Slic3r::scaling_factor) + $self->shift_x, 
-        ($point->y * $Slic3r::scaling_factor) + $self->shift_y; #**
+        ($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x, 
+        ($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y; #**
     
     # XY distance of the center from the start position
     $gcode .= sprintf " I%.${dec}f J%.${dec}f",
-        ($center->[X] - $self->last_pos->[X]) * $Slic3r::scaling_factor,
-        ($center->[Y] - $self->last_pos->[Y]) * $Slic3r::scaling_factor;
+        ($center->[X] - $self->last_pos->[X]) * &Slic3r::SCALING_FACTOR,
+        ($center->[Y] - $self->last_pos->[Y]) * &Slic3r::SCALING_FACTOR;
     
     $self->last_pos($point);
     return $self->_Gx($gcode, $e, $comment);
@@ -348,23 +348,23 @@ sub _Gx {
         # apply the speed reduction for print moves on bottom layer
         my $speed_f = $self->speeds->{$speed};
         if ($e && $self->layer->id == 0 && $comment !~ /retract/) {
-            $speed_f = $Slic3r::first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
+            $speed_f = $Slic3r::Config->first_layer_speed =~ /^(\d+(?:\.\d+)?)%$/
                 ? ($speed_f * $1/100)
-                : $Slic3r::first_layer_speed * 60;
+                : $Slic3r::Config->first_layer_speed * 60;
         }
         $gcode .= sprintf " F%.${dec}f", $speed_f;
         $self->last_speed($speed);
     }
     
     # output extrusion distance
-    if ($e && $Slic3r::extrusion_axis) {
-        $self->extrusion_distance(0) if $Slic3r::use_relative_e_distances;
+    if ($e && $Slic3r::Config->extrusion_axis) {
+        $self->extrusion_distance(0) if $Slic3r::Config->use_relative_e_distances;
         $self->extrusion_distance($self->extrusion_distance + $e);
         $self->total_extrusion_length($self->total_extrusion_length + $e);
-        $gcode .= sprintf " %s%.5f", $Slic3r::extrusion_axis, $self->extrusion_distance;
+        $gcode .= sprintf " %s%.5f", $Slic3r::Config->extrusion_axis, $self->extrusion_distance;
     }
     
-    $gcode .= sprintf " ; %s", $comment if $comment && $Slic3r::gcode_comments;
+    $gcode .= sprintf " ; %s", $comment if $comment && $Slic3r::Config->gcode_comments;
     if ($append_bridge_off) {
         $gcode .= "\n;_BRIDGE_FAN_END";
     }
@@ -379,7 +379,7 @@ sub set_tool {
     
     $self->extruder_idx($tool);
     return $self->retract
-        . (sprintf "T%d%s\n", $tool, ($Slic3r::gcode_comments ? ' ; change tool' : ''))
+        . (sprintf "T%d%s\n", $tool, ($Slic3r::Config->gcode_comments ? ' ; change tool' : ''))
         . $self->reset_e
         . $self->unretract;
 }
@@ -391,10 +391,10 @@ sub set_fan {
     if ($self->last_fan_speed != $speed || $dont_save) {
         $self->last_fan_speed($speed) if !$dont_save;
         if ($speed == 0) {
-            return sprintf "M107%s\n", ($Slic3r::gcode_comments ? ' ; disable fan' : '');
+            return sprintf "M107%s\n", ($Slic3r::Config->gcode_comments ? ' ; disable fan' : '');
         } else {
-            return sprintf "M106 %s%d%s\n", ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'),
-                (255 * $speed / 100), ($Slic3r::gcode_comments ? ' ; enable fan' : '');
+            return sprintf "M106 %s%d%s\n", ($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
+                (255 * $speed / 100), ($Slic3r::Config->gcode_comments ? ' ; enable fan' : '');
         }
     }
     return "";
@@ -404,13 +404,13 @@ sub set_temperature {
     my $self = shift;
     my ($temperature, $wait, $tool) = @_;
     
-    return "" if $wait && $Slic3r::gcode_flavor eq 'makerbot';
+    return "" if $wait && $Slic3r::Config->gcode_flavor eq 'makerbot';
     
     my ($code, $comment) = $wait
         ? ('M109', 'wait for temperature to be reached')
         : ('M104', 'set temperature');
     return sprintf "$code %s%d %s; $comment\n",
-        ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
+        ($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
         (defined $tool && $tool != $self->extruder_idx) ? "T$tool " : "";
 }
 
@@ -419,12 +419,12 @@ sub set_bed_temperature {
     my ($temperature, $wait) = @_;
     
     my ($code, $comment) = $wait
-        ? (($Slic3r::gcode_flavor eq 'makerbot' ? 'M109'
-            : $Slic3r::gcode_flavor eq 'teacup' ? 'M109 P1'
+        ? (($Slic3r::Config->gcode_flavor eq 'makerbot' ? 'M109'
+            : $Slic3r::Config->gcode_flavor eq 'teacup' ? 'M109 P1'
             : 'M190'), 'wait for bed temperature to be reached')
         : ('M140', 'set bed temperature');
     return sprintf "$code %s%d ; $comment\n",
-        ($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
+        ($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
 }
 
 1;

+ 9 - 2
lib/Slic3r/GUI.pm

@@ -31,6 +31,7 @@ use constant MI_CONF_WIZARD   => 11;
 use constant MI_WEBSITE       => 12;
 
 our $datadir;
+our $Settings;
 
 our $small_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
 $small_font->SetPointSize(11) if !&Wx::wxMSW;
@@ -57,7 +58,7 @@ sub OnInit {
     # load settings
     if (-f "$datadir/slic3r.ini") {
         my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
-        $Slic3r::Settings = $ini if $ini;
+        $Settings = $ini if $ini;
     }
     
     # application frame
@@ -86,7 +87,7 @@ sub OnInit {
         $fileMenu->Append(MI_SLICE_SVG, "Slice to SV&G…\tCtrl+G", 'Slice file to SVG');
         $fileMenu->AppendSeparator();
         $fileMenu->Append(wxID_EXIT, "&Quit", 'Quit Slic3r');
-        EVT_MENU($frame, MI_LOAD_CONF, sub { $self->{skeinpanel}->load_config });
+        EVT_MENU($frame, MI_LOAD_CONF, sub { $self->{skeinpanel}->load_config_file });
         EVT_MENU($frame, MI_EXPORT_CONF, sub { $self->{skeinpanel}->save_config });
         EVT_MENU($frame, MI_QUICK_SLICE, sub { $self->{skeinpanel}->do_slice;
                                                $repeat->Enable(defined $Slic3r::GUI::SkeinPanel::last_input_file) });
@@ -205,6 +206,12 @@ sub notify {
     $self->{notifier}->notify($message);
 }
 
+sub save_settings {
+    my $self = shift;
+    
+    Slic3r::Config->write_ini("$datadir/slic3r.ini", $Settings);
+}
+
 package Slic3r::GUI::ProgressStatusBar;
 use Wx qw(:gauge :misc);
 use base 'Wx::StatusBar';

Some files were not shown because too many files changed in this diff