12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- package Slic3r::Config;
- use strict;
- use warnings;
- use utf8;
- use List::Util qw(first max);
- our $Options = print_config_def();
- {
- no strict 'refs';
- for my $opt_key (keys %$Options) {
- *{$opt_key} = sub {
-
- $_[0]->get($opt_key)
- };
- }
- }
- sub new_from_cli {
- my $class = shift;
- my %args = @_;
-
-
- delete $args{$_} for grep !defined $args{$_}, keys %args;
-
-
-
- for (qw(start end layer toolchange)) {
- my $opt_key = "${_}_gcode";
- if ($args{$opt_key}) {
- if (-e $args{$opt_key}) {
- Slic3r::open(\my $fh, "<", $args{$opt_key})
- or die "Failed to open $args{$opt_key}\n";
- binmode $fh, ':utf8';
- $args{$opt_key} = do { local $/; <$fh> };
- close $fh;
- }
- }
- }
- my $self = $class->new;
- foreach my $opt_key (keys %args) {
- my $opt_def = $Options->{$opt_key};
-
-
-
- if ($opt_key =~ /^(?:bed_shape|duplicate_grid|extruder_offset)$/ || $opt_def->{type} eq 'bool') {
- $self->set_deserialize($opt_key, $args{$opt_key});
- } elsif (my $shortcut = $opt_def->{shortcut}) {
- $self->set($_, $args{$opt_key}) for @$shortcut;
- } else {
- $self->set($opt_key, $args{$opt_key});
- }
- }
-
- return $self;
- }
- package Slic3r::Config::Static;
- use parent 'Slic3r::Config';
- sub Slic3r::Config::GCode::new { Slic3r::Config::Static::new_GCodeConfig }
- sub Slic3r::Config::Print::new { Slic3r::Config::Static::new_PrintConfig }
- sub Slic3r::Config::PrintObject::new { Slic3r::Config::Static::new_PrintObjectConfig }
- sub Slic3r::Config::PrintRegion::new { Slic3r::Config::Static::new_PrintRegionConfig }
- sub Slic3r::Config::Full::new { Slic3r::Config::Static::new_FullPrintConfig }
- 1;
|