2011-10-03 09:55:32 +00:00
|
|
|
package Slic3r::Config;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2011-10-09 20:29:13 +00:00
|
|
|
use utf8;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2014-01-11 13:30:34 +00:00
|
|
|
use List::Util qw(first max);
|
2012-09-28 12:13:06 +00:00
|
|
|
|
2012-04-11 13:58:09 +00:00
|
|
|
# cemetery of old config settings
|
2013-07-06 09:35:40 +00:00
|
|
|
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
|
2014-01-11 22:46:20 +00:00
|
|
|
adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
|
|
|
|
rotate scale duplicate_grid);
|
2012-04-11 13:58:09 +00:00
|
|
|
|
2013-12-21 23:39:03 +00:00
|
|
|
our $Options = print_config_def();
|
2013-12-21 20:06:45 +00:00
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
# generate accessors
|
2013-12-21 20:06:45 +00:00
|
|
|
{
|
2011-10-05 16:13:47 +00:00
|
|
|
no strict 'refs';
|
2012-07-27 19:13:03 +00:00
|
|
|
for my $opt_key (keys %$Options) {
|
2014-01-02 16:24:23 +00:00
|
|
|
*{$opt_key} = sub { $_[0]->get($opt_key) };
|
2012-07-27 19:13:03 +00:00
|
|
|
}
|
2011-10-05 16:13:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub new_from_defaults {
|
|
|
|
my $class = shift;
|
2013-12-22 00:27:09 +00:00
|
|
|
my (@opt_keys) = @_;
|
2013-08-25 12:37:50 +00:00
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
my $self = $class->new;
|
2014-01-02 09:44:54 +00:00
|
|
|
my $defaults = Slic3r::Config::Full->new;
|
2013-12-22 00:27:09 +00:00
|
|
|
if (@opt_keys) {
|
|
|
|
$self->set($_, $defaults->get($_)) for @opt_keys;
|
|
|
|
} else {
|
|
|
|
$self->apply_static($defaults);
|
|
|
|
}
|
2013-12-21 20:06:45 +00:00
|
|
|
return $self;
|
2012-02-20 11:50:05 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub new_from_cli {
|
2011-10-05 16:13:47 +00:00
|
|
|
my $class = shift;
|
2012-07-27 19:13:03 +00:00
|
|
|
my %args = @_;
|
2011-10-05 16:13:47 +00:00
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
delete $args{$_} for grep !defined $args{$_}, keys %args;
|
|
|
|
|
2012-12-23 15:29:08 +00:00
|
|
|
for (qw(start end layer toolchange)) {
|
2012-07-27 19:13:03 +00:00
|
|
|
my $opt_key = "${_}_gcode";
|
|
|
|
if ($args{$opt_key}) {
|
2013-06-23 17:25:02 +00:00
|
|
|
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;
|
|
|
|
}
|
2012-06-19 16:11:51 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 19:13:03 +00:00
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
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});
|
|
|
|
}
|
|
|
|
}
|
2013-12-21 23:39:03 +00:00
|
|
|
|
|
|
|
return $self;
|
2012-06-19 16:11:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub merge {
|
2012-06-19 16:11:51 +00:00
|
|
|
my $class = shift;
|
2012-08-08 17:36:34 +00:00
|
|
|
my $config = $class->new;
|
|
|
|
$config->apply($_) for @_;
|
|
|
|
return $config;
|
2012-06-19 16:11:51 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub load {
|
2012-06-19 16:11:51 +00:00
|
|
|
my $class = shift;
|
|
|
|
my ($file) = @_;
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
my $ini = __PACKAGE__->read_ini($file);
|
2014-01-02 21:06:58 +00:00
|
|
|
my $config = $class->new;
|
2013-12-22 00:27:09 +00:00
|
|
|
foreach my $opt_key (keys %{$ini->{_}}) {
|
2013-12-23 23:30:51 +00:00
|
|
|
($opt_key, my $value) = _handle_legacy($opt_key, $ini->{_}{$opt_key});
|
2013-12-22 00:27:09 +00:00
|
|
|
next if !defined $opt_key;
|
|
|
|
$config->set_deserialize($opt_key, $value);
|
|
|
|
}
|
2012-07-27 19:13:03 +00:00
|
|
|
return $config;
|
2011-10-05 16:13:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub clone {
|
|
|
|
my $self = shift;
|
2013-12-21 20:06:45 +00:00
|
|
|
|
2014-01-02 21:06:58 +00:00
|
|
|
my $new = (ref $self)->new;
|
2013-12-21 20:06:45 +00:00
|
|
|
$new->apply($self);
|
2012-07-27 19:13:03 +00:00
|
|
|
return $new;
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub get_value {
|
|
|
|
my $self = shift;
|
|
|
|
my ($opt_key) = @_;
|
2011-10-05 16:13:47 +00:00
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
return $Options->{$opt_key}{ratio_over}
|
|
|
|
? $self->get_abs_value($opt_key)
|
|
|
|
: $self->get($opt_key);
|
2012-07-27 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-23 23:30:51 +00:00
|
|
|
sub _handle_legacy {
|
2013-12-21 20:06:45 +00:00
|
|
|
my ($opt_key, $value) = @_;
|
2012-07-27 19:13:03 +00:00
|
|
|
|
|
|
|
# handle legacy options
|
2014-01-11 22:46:20 +00:00
|
|
|
return () if first { $_ eq $opt_key } @Ignore;
|
2012-07-27 19:13:03 +00:00
|
|
|
if ($opt_key =~ /^(extrusion_width|bottom_layer_speed|first_layer_height)_ratio$/) {
|
|
|
|
$opt_key = $1;
|
|
|
|
$opt_key =~ s/^bottom_layer_speed$/first_layer_speed/;
|
|
|
|
$value = $value =~ /^\d+(?:\.\d+)?$/ && $value != 0 ? ($value*100) . "%" : 0;
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
2012-09-21 14:42:40 +00:00
|
|
|
if ($opt_key eq 'threads' && !$Slic3r::have_threads) {
|
|
|
|
$value = 1;
|
|
|
|
}
|
2013-06-07 21:24:53 +00:00
|
|
|
if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') {
|
|
|
|
$value = 'makerware';
|
|
|
|
}
|
2012-06-18 20:27:57 +00:00
|
|
|
|
2013-01-15 11:50:15 +00:00
|
|
|
# For historical reasons, the world's full of configs having these very low values;
|
|
|
|
# to avoid unexpected behavior we need to ignore them. Banning these two hard-coded
|
|
|
|
# values is a dirty hack and will need to be removed sometime in the future, but it
|
|
|
|
# will avoid lots of complaints for now.
|
|
|
|
if ($opt_key eq 'perimeter_acceleration' && $value == '25') {
|
|
|
|
$value = 0;
|
|
|
|
}
|
|
|
|
if ($opt_key eq 'infill_acceleration' && $value == '50') {
|
|
|
|
$value = 0;
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
if (!exists $Options->{$opt_key}) {
|
2012-11-18 16:42:52 +00:00
|
|
|
my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options;
|
|
|
|
if (!@keys) {
|
|
|
|
warn "Unknown option $opt_key\n";
|
2013-12-22 00:27:09 +00:00
|
|
|
return ();
|
2012-11-18 16:42:52 +00:00
|
|
|
}
|
|
|
|
$opt_key = $keys[0];
|
2012-07-27 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
return ($opt_key, $value);
|
2012-06-18 20:27:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub set_ifndef {
|
|
|
|
my $self = shift;
|
|
|
|
my ($opt_key, $value, $deserialize) = @_;
|
2012-06-18 20:27:57 +00:00
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
if (!$self->has($opt_key)) {
|
|
|
|
if ($deserialize) {
|
|
|
|
$self->set_deserialize($opt_key, $value);
|
|
|
|
} else {
|
|
|
|
$self->set($opt_key, $value);
|
|
|
|
}
|
|
|
|
}
|
2012-07-27 19:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub save {
|
|
|
|
my $self = shift;
|
2012-06-18 20:27:57 +00:00
|
|
|
my ($file) = @_;
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
my $ini = { _ => {} };
|
2013-12-21 20:06:45 +00:00
|
|
|
foreach my $opt_key (sort @{$self->get_keys}) {
|
2012-10-25 10:21:04 +00:00
|
|
|
next if $Options->{$opt_key}{shortcut};
|
2012-07-27 19:13:03 +00:00
|
|
|
$ini->{_}{$opt_key} = $self->serialize($opt_key);
|
|
|
|
}
|
|
|
|
__PACKAGE__->write_ini($file, $ini);
|
2011-10-05 16:13:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
sub setenv {
|
|
|
|
my $self = shift;
|
2011-10-14 14:24:55 +00:00
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
foreach my $opt_key (sort keys %$Options) {
|
|
|
|
$ENV{"SLIC3R_" . uc $opt_key} = $self->serialize($opt_key);
|
2011-10-14 14:24:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 17:28:41 +00:00
|
|
|
sub equals {
|
|
|
|
my ($self, $other) = @_;
|
|
|
|
return @{ $self->diff($other) } == 0;
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:06:58 +00:00
|
|
|
# this will *ignore* options not present in both configs
|
2013-12-30 17:28:41 +00:00
|
|
|
sub diff {
|
|
|
|
my ($self, $other) = @_;
|
|
|
|
|
|
|
|
my @diff = ();
|
|
|
|
foreach my $opt_key (sort @{$self->get_keys}) {
|
|
|
|
push @diff, $opt_key
|
2014-01-02 21:06:58 +00:00
|
|
|
if $other->has($opt_key) && $other->serialize($opt_key) ne $self->serialize($opt_key);
|
2013-12-30 17:28:41 +00:00
|
|
|
}
|
|
|
|
return [@diff];
|
|
|
|
}
|
|
|
|
|
2014-01-02 16:24:23 +00:00
|
|
|
# this method is idempotent by design and only applies to ::DynamicConfig or ::Full
|
|
|
|
# objects because it performs cross checks
|
2011-10-03 09:55:32 +00:00
|
|
|
sub validate {
|
2012-07-27 19:13:03 +00:00
|
|
|
my $self = shift;
|
2012-04-10 14:26:56 +00:00
|
|
|
|
|
|
|
# -j, --threads
|
|
|
|
die "Invalid value for --threads\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->threads < 1;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
|
|
|
# --layer-height
|
|
|
|
die "Invalid value for --layer-height\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->layer_height <= 0;
|
2011-10-03 09:55:32 +00:00
|
|
|
die "--layer-height must be a multiple of print resolution\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->layer_height / &Slic3r::SCALING_FACTOR % 1 != 0;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2012-06-06 14:11:38 +00:00
|
|
|
# --first-layer-height
|
|
|
|
die "Invalid value for --first-layer-height\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->first_layer_height !~ /^(?:\d*(?:\.\d+)?)%?$/;
|
2011-11-13 18:08:19 +00:00
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
# --filament-diameter
|
|
|
|
die "Invalid value for --filament-diameter\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if grep $_ < 1, @{$self->filament_diameter};
|
2011-10-03 09:55:32 +00:00
|
|
|
|
|
|
|
# --nozzle-diameter
|
|
|
|
die "Invalid value for --nozzle-diameter\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if grep $_ < 0, @{$self->nozzle_diameter};
|
2011-10-03 09:55:32 +00:00
|
|
|
die "--layer-height can't be greater than --nozzle-diameter\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if grep $self->layer_height > $_, @{$self->nozzle_diameter};
|
2011-11-13 18:08:19 +00:00
|
|
|
die "First layer height can't be greater than --nozzle-diameter\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if grep $self->get_value('first_layer_height') > $_, @{$self->nozzle_diameter};
|
2012-06-06 15:29:12 +00:00
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
# --perimeters
|
|
|
|
die "Invalid value for --perimeters\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->perimeters < 0;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
|
|
|
# --solid-layers
|
2012-10-25 10:21:04 +00:00
|
|
|
die "Invalid value for --solid-layers\n" if defined $self->solid_layers && $self->solid_layers < 0;
|
|
|
|
die "Invalid value for --top-solid-layers\n" if $self->top_solid_layers < 0;
|
|
|
|
die "Invalid value for --bottom-solid-layers\n" if $self->bottom_solid_layers < 0;
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2013-06-07 21:24:53 +00:00
|
|
|
# --gcode-flavor
|
|
|
|
die "Invalid value for --gcode-flavor\n"
|
|
|
|
if !first { $_ eq $self->gcode_flavor } @{$Options->{gcode_flavor}{values}};
|
|
|
|
|
2013-10-27 15:59:18 +00:00
|
|
|
die "--use-firmware-retraction is only supported by Marlin firmware\n"
|
|
|
|
if $self->use_firmware_retraction && $self->gcode_flavor ne 'reprap';
|
|
|
|
|
|
|
|
die "--use-firmware-retraction is not compatible with --wipe\n"
|
|
|
|
if $self->use_firmware_retraction && first {$_} @{$self->wipe};
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
# --print-center
|
|
|
|
die "Invalid value for --print-center\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if !ref $self->print_center
|
|
|
|
&& (!$self->print_center || $self->print_center !~ /^\d+,\d+$/);
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2011-11-13 17:14:02 +00:00
|
|
|
# --fill-pattern
|
|
|
|
die "Invalid value for --fill-pattern\n"
|
2012-09-28 12:13:06 +00:00
|
|
|
if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}};
|
2011-11-13 17:14:02 +00:00
|
|
|
|
|
|
|
# --solid-fill-pattern
|
|
|
|
die "Invalid value for --solid-fill-pattern\n"
|
2012-09-28 12:13:06 +00:00
|
|
|
if !first { $_ eq $self->solid_fill_pattern } @{$Options->{solid_fill_pattern}{values}};
|
2011-10-06 13:24:21 +00:00
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
# --fill-density
|
|
|
|
die "Invalid value for --fill-density\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->fill_density < 0 || $self->fill_density > 1;
|
2012-09-28 12:13:06 +00:00
|
|
|
die "The selected fill pattern is not supposed to work at 100% density\n"
|
|
|
|
if $self->fill_density == 1
|
|
|
|
&& !first { $_ eq $self->fill_pattern } @{$Options->{solid_fill_pattern}{values}};
|
2011-10-03 09:55:32 +00:00
|
|
|
|
2011-10-18 13:57:53 +00:00
|
|
|
# --infill-every-layers
|
|
|
|
die "Invalid value for --infill-every-layers\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->infill_every_layers !~ /^\d+$/ || $self->infill_every_layers < 1;
|
2011-10-18 13:57:53 +00:00
|
|
|
|
2012-04-11 15:52:06 +00:00
|
|
|
# --bed-size
|
|
|
|
die "Invalid value for --bed-size\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if !ref $self->bed_size
|
|
|
|
&& (!$self->bed_size || $self->bed_size !~ /^\d+,\d+$/);
|
2012-04-11 15:52:06 +00:00
|
|
|
|
2011-11-13 17:41:12 +00:00
|
|
|
# --skirt-height
|
|
|
|
die "Invalid value for --skirt-height\n"
|
2013-12-24 14:15:53 +00:00
|
|
|
if $self->skirt_height < -1; # -1 means as tall as the object
|
2011-11-28 17:37:53 +00:00
|
|
|
|
2012-02-19 08:32:16 +00:00
|
|
|
# --bridge-flow-ratio
|
|
|
|
die "Invalid value for --bridge-flow-ratio\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->bridge_flow_ratio <= 0;
|
2012-05-23 09:47:52 +00:00
|
|
|
|
|
|
|
# extruder clearance
|
|
|
|
die "Invalid value for --extruder-clearance-radius\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->extruder_clearance_radius <= 0;
|
2012-05-23 09:47:52 +00:00
|
|
|
die "Invalid value for --extruder-clearance-height\n"
|
2012-07-27 19:13:03 +00:00
|
|
|
if $self->extruder_clearance_height <= 0;
|
2013-05-31 10:45:18 +00:00
|
|
|
|
|
|
|
# --extrusion-multiplier
|
|
|
|
die "Invalid value for --extrusion-multiplier\n"
|
|
|
|
if defined first { $_ <= 0 } @{$self->extrusion_multiplier};
|
2013-06-30 13:39:03 +00:00
|
|
|
|
2013-08-09 12:33:20 +00:00
|
|
|
# --default-acceleration
|
|
|
|
die "Invalid zero value for --default-acceleration when using other acceleration settings\n"
|
|
|
|
if ($self->perimeter_acceleration || $self->infill_acceleration || $self->bridge_acceleration || $self->first_layer_acceleration)
|
|
|
|
&& !$self->default_acceleration;
|
|
|
|
|
2014-01-02 16:24:23 +00:00
|
|
|
# --spiral-vase
|
|
|
|
if ($self->spiral_vase) {
|
|
|
|
# Note that we might want to have more than one perimeter on the bottom
|
|
|
|
# solid layers.
|
|
|
|
die "Can't make more than one perimeter when spiral vase mode is enabled\n"
|
|
|
|
if $self->perimeters > 1;
|
|
|
|
|
|
|
|
die "Can't make less than one perimeter when spiral vase mode is enabled\n"
|
|
|
|
if $self->perimeters < 1;
|
|
|
|
|
|
|
|
die "Spiral vase mode is not compatible with non-zero fill density\n"
|
|
|
|
if $self->fill_density > 0;
|
|
|
|
|
|
|
|
die "Spiral vase mode is not compatible with top solid layers\n"
|
|
|
|
if $self->top_solid_layers > 0;
|
|
|
|
|
|
|
|
die "Spiral vase mode is not compatible with support material\n"
|
|
|
|
if $self->support_material || $self->support_material_enforce_layers > 0;
|
|
|
|
|
|
|
|
# This should be enforce automatically only on spiral layers and
|
|
|
|
# done on the others
|
|
|
|
die "Spiral vase mode is not compatible with retraction on layer change\n"
|
|
|
|
if defined first { $_ } @{ $self->retract_layer_change };
|
|
|
|
}
|
|
|
|
|
2014-01-11 13:30:34 +00:00
|
|
|
# extrusion widths
|
|
|
|
{
|
|
|
|
my $max_nozzle_diameter = max(@{ $self->nozzle_diameter });
|
|
|
|
die "Invalid extrusion width (too large)\n"
|
|
|
|
if defined first { $_ > 10 * $max_nozzle_diameter }
|
2014-01-11 13:48:13 +00:00
|
|
|
map $self->get_value("${_}_extrusion_width"),
|
2014-01-11 13:30:34 +00:00
|
|
|
qw(perimeter infill solid_infill top_infill support_material first_layer);
|
|
|
|
}
|
|
|
|
|
2013-06-30 13:39:03 +00:00
|
|
|
# general validation, quick and dirty
|
2014-01-02 09:44:54 +00:00
|
|
|
foreach my $opt_key (@{$self->get_keys}) {
|
2013-06-30 13:39:03 +00:00
|
|
|
my $opt = $Options->{$opt_key};
|
|
|
|
next unless defined $self->$opt_key;
|
|
|
|
next unless defined $opt->{cli} && $opt->{cli} =~ /=(.+)$/;
|
|
|
|
my $type = $1;
|
|
|
|
my @values = ();
|
|
|
|
if ($type =~ s/\@$//) {
|
|
|
|
die "Invalid value for $opt_key\n" if ref($self->$opt_key) ne 'ARRAY';
|
|
|
|
@values = @{ $self->$opt_key };
|
|
|
|
} else {
|
|
|
|
@values = ($self->$opt_key);
|
|
|
|
}
|
|
|
|
foreach my $value (@values) {
|
|
|
|
if ($type eq 'i' || $type eq 'f') {
|
|
|
|
die "Invalid value for $opt_key\n"
|
2013-07-03 08:51:44 +00:00
|
|
|
if ($type eq 'i' && $value !~ /^-?\d+$/)
|
|
|
|
|| ($type eq 'f' && $value !~ /^-?(?:\d+|\d*\.\d+)$/)
|
2013-06-30 13:39:03 +00:00
|
|
|
|| (defined $opt->{min} && $value < $opt->{min})
|
|
|
|
|| (defined $opt->{max} && $value > $opt->{max});
|
|
|
|
} elsif ($type eq 's' && $opt->{type} eq 'select') {
|
|
|
|
die "Invalid value for $opt_key\n"
|
|
|
|
unless first { $_ eq $value } @{ $opt->{values} };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-03 09:55:32 +00:00
|
|
|
}
|
|
|
|
|
2012-03-03 22:29:08 +00:00
|
|
|
sub replace_options {
|
2012-07-27 19:13:03 +00:00
|
|
|
my $self = shift;
|
2012-03-03 22:29:08 +00:00
|
|
|
my ($string, $more_variables) = @_;
|
|
|
|
|
2012-11-16 09:07:30 +00:00
|
|
|
$more_variables ||= {};
|
|
|
|
$more_variables->{$_} = $ENV{$_} for grep /^SLIC3R_/, keys %ENV;
|
|
|
|
{
|
|
|
|
my $variables_regex = join '|', keys %$more_variables;
|
|
|
|
$string =~ s/\[($variables_regex)\]/$more_variables->{$1}/eg;
|
2012-03-03 22:29:08 +00:00
|
|
|
}
|
|
|
|
|
2012-05-01 13:01:56 +00:00
|
|
|
my @lt = localtime; $lt[5] += 1900; $lt[4] += 1;
|
|
|
|
$string =~ s/\[timestamp\]/sprintf '%04d%02d%02d-%02d%02d%02d', @lt[5,4,3,2,1,0]/egx;
|
|
|
|
$string =~ s/\[year\]/$lt[5]/eg;
|
|
|
|
$string =~ s/\[month\]/$lt[4]/eg;
|
|
|
|
$string =~ s/\[day\]/$lt[3]/eg;
|
|
|
|
$string =~ s/\[hour\]/$lt[2]/eg;
|
|
|
|
$string =~ s/\[minute\]/$lt[1]/eg;
|
|
|
|
$string =~ s/\[second\]/$lt[0]/eg;
|
|
|
|
$string =~ s/\[version\]/$Slic3r::VERSION/eg;
|
|
|
|
|
2012-03-03 22:29:08 +00:00
|
|
|
# build a regexp to match the available options
|
2012-10-28 16:23:35 +00:00
|
|
|
my @options = grep !$Slic3r::Config::Options->{$_}{multiline},
|
2012-08-08 22:41:03 +00:00
|
|
|
grep $self->has($_),
|
2012-07-27 19:13:03 +00:00
|
|
|
keys %{$Slic3r::Config::Options};
|
2012-10-28 16:23:35 +00:00
|
|
|
my $options_regex = join '|', @options;
|
2012-03-03 22:29:08 +00:00
|
|
|
|
|
|
|
# use that regexp to search and replace option names with option values
|
2012-10-28 16:23:35 +00:00
|
|
|
$string =~ s/\[($options_regex)\]/$self->serialize($1)/eg;
|
|
|
|
foreach my $opt_key (grep ref $self->$_ eq 'ARRAY', @options) {
|
|
|
|
my $value = $self->$opt_key;
|
|
|
|
$string =~ s/\[${opt_key}_${_}\]/$value->[$_]/eg for 0 .. $#$value;
|
|
|
|
if ($Options->{$opt_key}{type} eq 'point') {
|
|
|
|
$string =~ s/\[${opt_key}_X\]/$value->[0]/eg;
|
|
|
|
$string =~ s/\[${opt_key}_Y\]/$value->[1]/eg;
|
|
|
|
}
|
|
|
|
}
|
2012-03-03 22:29:08 +00:00
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2012-08-29 17:37:27 +00:00
|
|
|
# min object distance is max(duplicate_distance, clearance_radius)
|
|
|
|
sub min_object_distance {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
return ($self->complete_objects && $self->extruder_clearance_radius > $self->duplicate_distance)
|
|
|
|
? $self->extruder_clearance_radius
|
|
|
|
: $self->duplicate_distance;
|
|
|
|
}
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
# CLASS METHODS:
|
|
|
|
|
|
|
|
sub write_ini {
|
|
|
|
my $class = shift;
|
|
|
|
my ($file, $ini) = @_;
|
|
|
|
|
2013-01-13 09:18:34 +00:00
|
|
|
Slic3r::open(\my $fh, '>', $file);
|
2012-07-27 19:13:03 +00:00
|
|
|
binmode $fh, ':utf8';
|
|
|
|
my $localtime = localtime;
|
|
|
|
printf $fh "# generated by Slic3r $Slic3r::VERSION on %s\n", "$localtime";
|
|
|
|
foreach my $category (sort keys %$ini) {
|
|
|
|
printf $fh "\n[%s]\n", $category if $category ne '_';
|
|
|
|
foreach my $key (sort keys %{$ini->{$category}}) {
|
|
|
|
printf $fh "%s = %s\n", $key, $ini->{$category}{$key};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub read_ini {
|
|
|
|
my $class = shift;
|
|
|
|
my ($file) = @_;
|
|
|
|
|
|
|
|
local $/ = "\n";
|
2013-01-13 09:18:34 +00:00
|
|
|
Slic3r::open(\my $fh, '<', $file);
|
2012-07-27 19:13:03 +00:00
|
|
|
binmode $fh, ':utf8';
|
|
|
|
|
|
|
|
my $ini = { _ => {} };
|
|
|
|
my $category = '_';
|
2013-06-06 08:46:58 +00:00
|
|
|
while (<$fh>) {
|
2012-07-27 19:13:03 +00:00
|
|
|
s/\R+$//;
|
|
|
|
next if /^\s+/;
|
|
|
|
next if /^$/;
|
|
|
|
next if /^\s*#/;
|
|
|
|
if (/^\[(\w+)\]$/) {
|
|
|
|
$category = $1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
/^(\w+) = (.*)/ or die "Unreadable configuration file (invalid data at line $.)\n";
|
|
|
|
$ini->{$category}{$1} = $2;
|
|
|
|
}
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
return $ini;
|
|
|
|
}
|
|
|
|
|
2014-01-02 09:44:54 +00:00
|
|
|
package Slic3r::Config::Print;
|
|
|
|
use parent 'Slic3r::Config';
|
|
|
|
|
|
|
|
package Slic3r::Config::PrintObject;
|
|
|
|
use parent 'Slic3r::Config';
|
|
|
|
|
|
|
|
package Slic3r::Config::PrintRegion;
|
|
|
|
use parent 'Slic3r::Config';
|
|
|
|
|
|
|
|
package Slic3r::Config::Full;
|
|
|
|
use parent 'Slic3r::Config';
|
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
1;
|