Browse Source

Further reduction of Perl Config.pm methods.

bubnikv 7 years ago
parent
commit
2455aee97c

+ 0 - 44
lib/Slic3r/Config.pm

@@ -8,12 +8,6 @@ use utf8;
 
 use List::Util qw(first max);
 
-# cemetery of old config settings
-our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
-    adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
-    rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
-    randomize_start seal_position bed_size print_center g0 vibration_limit gcode_arcs pressure_advance);
-
 # C++ Slic3r::PrintConfigDef exported as a Perl hash of hashes.
 # The C++ counterpart is a constant singleton.
 our $Options = print_config_def();
@@ -29,23 +23,6 @@ $Options->{threads}{readonly} = !$Slic3r::have_threads;
     }
 }
 
-# Fill in the underlying C++ Slic3r::DynamicPrintConfig with the content of the defaults
-# provided by the C++ class Slic3r::FullPrintConfig.
-# Used by the UI.
-sub new_from_defaults {
-    my ($class, @opt_keys) = @_;
-    my $self = $class->new;
-    # Instantiating the C++ class Slic3r::FullPrintConfig.
-    my $defaults = Slic3r::Config::Full->new;
-    if (@opt_keys) {
-        $self->set($_, $defaults->get($_))
-            for grep $defaults->has($_), @opt_keys;
-    } else {
-        $self->apply_static($defaults);
-    }
-    return $self;
-}
-
 # From command line parameters, used by slic3r.pl
 sub new_from_cli {
     my $class = shift;
@@ -87,27 +64,6 @@ sub new_from_cli {
     return $self;
 }
 
-sub merge {
-    my $class = shift;
-    my $config = $class->new;
-    $config->apply($_) for @_;
-    return $config;
-}
-
-sub clone {
-    my $self = shift;
-    my $new = (ref $self)->new;
-    $new->apply($self);
-    return $new;
-}
-
-sub get_value {
-    my ($self, $opt_key) = @_;
-    return $Options->{$opt_key}{ratio_over}
-        ? $self->get_abs_value($opt_key)
-        : $self->get($opt_key);
-}
-
 # CLASS METHODS:
 
 # Write a "Windows" style ini file with categories enclosed in squre brackets.

+ 2 - 2
lib/Slic3r/GUI/ConfigWizard.pm

@@ -202,7 +202,7 @@ sub append_option {
     
     # populate repository with the factory default
     my ($opt_key, $opt_index) = split /#/, $full_key, 2;
-    $self->config->apply(Slic3r::Config->new_from_defaults($opt_key));
+    $self->config->apply(Slic3r::Config::new_from_defaults_keys($opt_key));
     
     # draw the control
     my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
@@ -300,7 +300,7 @@ sub new {
 
     $self->append_text('Set the shape of your printer\'s bed, then click Next.');
     
-    $self->config->apply(Slic3r::Config->new_from_defaults('bed_shape'));
+    $self->config->apply(Slic3r::Config::new_from_defaults_keys('bed_shape'));
     $self->{bed_shape_panel} = my $panel = Slic3r::GUI::BedShapePanel->new($self, $self->config->bed_shape);
     $self->{bed_shape_panel}->on_change(sub {
         $self->config->set('bed_shape', $self->{bed_shape_panel}->GetValue);

+ 1 - 1
lib/Slic3r/GUI/Plater.pm

@@ -49,7 +49,7 @@ sub new {
     my $class = shift;
     my ($parent) = @_;
     my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
-    $self->{config} = Slic3r::Config->new_from_defaults(qw(
+    $self->{config} = Slic3r::Config::new_from_defaults_keys(qw(
         bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width variable_layer_height
         serial_port serial_speed octoprint_host octoprint_apikey
         nozzle_diameter single_extruder_multi_material 

+ 4 - 4
lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm

@@ -312,7 +312,7 @@ sub selection_changed {
             $config = $self->{model_object}->config;
         }
         # get default values
-        my $default_config = Slic3r::Config->new_from_defaults(@opt_keys);
+        my $default_config = Slic3r::Config::new_from_defaults_keys(@opt_keys);
         
         # append default extruder
         push @opt_keys, 'extruder';
@@ -490,12 +490,12 @@ sub CanClose {
     # validate options before allowing user to dismiss the dialog
     # the validate method only works on full configs so we have
     # to merge our settings with the default ones
-    my $config = Slic3r::Config->merge($self->GetParent->GetParent->GetParent->GetParent->GetParent->config, $self->model_object->config);
+    my $config = $self->GetParent->GetParent->GetParent->GetParent->GetParent->config->clone;
     eval {
+        $config->apply($self->model_object->config);
         $config->validate;
     };
-    return 0 if Slic3r::GUI::catch_error($self);    
-    return 1;
+    return ! Slic3r::GUI::catch_error($self);
 }
 
 sub PartsChanged {

+ 3 - 3
slic3r.pl

@@ -92,12 +92,12 @@ if ($opt{save}) {
     if (@{$cli_config->get_keys} > 0) {
         $cli_config->save($opt{save});
     } else {
-        Slic3r::Config->new_from_defaults->save($opt{save});
+        Slic3r::Config::new_from_defaults->save($opt{save});
     }
 }
 
 # apply command line config on top of default config
-my $config = Slic3r::Config->new_from_defaults;
+my $config = Slic3r::Config::new_from_defaults;
 $config->apply($cli_config);
 
 # locate or create data directory
@@ -242,7 +242,7 @@ if (@ARGV) {  # slicing from command line
 sub usage {
     my ($exit_code) = @_;
     
-    my $config = Slic3r::Config->new_from_defaults->as_hash;
+    my $config = Slic3r::Config::new_from_defaults->as_hash;
     
     my $j = '';
     if ($Slic3r::have_threads) {

+ 1 - 1
t/avoid_crossing_perimeters.t

@@ -13,7 +13,7 @@ use Slic3r;
 use Slic3r::Test;
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('avoid_crossing_perimeters', 2);
     my $print = Slic3r::Test::init_print('20mm_cube', config => $config, duplicate => 2);
     ok my $gcode = Slic3r::Test::gcode($print), "no crash with avoid_crossing_perimeters and multiple objects";

+ 1 - 1
t/bridges.t

@@ -109,7 +109,7 @@ sub check_angle {
 }
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('top_solid_layers', 0);            # to prevent bridging on sparse infill
     $config->set('bridge_speed', 99);
     

+ 3 - 3
t/combineinfill.t

@@ -54,7 +54,7 @@ plan tests => 8;
             'infill is only present in correct number of layers';
     };
     
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('layer_height', 0.2);
     $config->set('first_layer_height', 0.2);
     $config->set('nozzle_diameter', [0.5]);
@@ -73,7 +73,7 @@ plan tests => 8;
 }
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('layer_height', 0.2);
     $config->set('first_layer_height', 0.2);
     $config->set('nozzle_diameter', [0.5]);
@@ -98,7 +98,7 @@ plan tests => 8;
 
 # the following needs to be adapted to the new API
 if (0) {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('skirts', 0);
     $config->set('solid_layers', 0);
     $config->set('bottom_solid_layers', 0);

+ 1 - 1
t/config.t

@@ -12,7 +12,7 @@ use Slic3r;
 use Slic3r::Test;
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('perimeter_extrusion_width', '250%');
     ok $config->validate, 'percent extrusion width is validated';
 }

+ 3 - 3
t/cooling.t

@@ -42,7 +42,7 @@ my $print_time1 = 100 / (3000 / 60); # 2 sec
 my $gcode2      = $gcode1 . "G1 X0 E1 F3000\n";
 my $print_time2 = 2 * $print_time1; # 4 sec
 
-my $config = Slic3r::Config->new_from_defaults;
+my $config = Slic3r::Config::new_from_defaults;
 # Default cooling settings.
 $config->set('bridge_fan_speed',            [ 100 ]);
 $config->set('cooling',                     [ 1 ]);
@@ -138,7 +138,7 @@ $config->set('disable_fan_first_layers',    [ 0 ]);
 }
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('cooling', [ 1 ]);
     $config->set('bridge_fan_speed', [ 100 ]);
     $config->set('fan_below_layer_time', [ 0 ]);
@@ -172,7 +172,7 @@ $config->set('disable_fan_first_layers',    [ 0 ]);
 }
 
 {
-    my $config = Slic3r::Config->new_from_defaults;
+    my $config = Slic3r::Config::new_from_defaults;
     $config->set('cooling', [ 1 ]);
     $config->set('fan_below_layer_time', [ 0 ]);
     $config->set('slowdown_below_layer_time', [ 10 ]);

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