2013-12-20 19:54:11 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Slic3r::XS;
|
2021-04-21 13:47:28 +00:00
|
|
|
use Test::More tests => 143;
|
2013-12-20 19:54:11 +00:00
|
|
|
|
2015-12-16 11:58:06 +00:00
|
|
|
foreach my $config (Slic3r::Config->new, Slic3r::Config::Static::new_FullPrintConfig) {
|
2013-12-20 19:54:11 +00:00
|
|
|
$config->set('layer_height', 0.3);
|
|
|
|
ok abs($config->get('layer_height') - 0.3) < 1e-4, 'set/get float';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('layer_height'), '0.3', 'serialize float';
|
2013-12-20 19:54:11 +00:00
|
|
|
|
|
|
|
$config->set('perimeters', 2);
|
|
|
|
is $config->get('perimeters'), 2, 'set/get int';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('perimeters'), '2', 'serialize int';
|
2013-12-20 19:54:11 +00:00
|
|
|
|
|
|
|
$config->set('extrusion_axis', 'A');
|
|
|
|
is $config->get('extrusion_axis'), 'A', 'set/get string';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('extrusion_axis'), 'A', 'serialize string';
|
2013-12-20 19:54:11 +00:00
|
|
|
|
|
|
|
$config->set('notes', "foo\nbar");
|
|
|
|
is $config->get('notes'), "foo\nbar", 'set/get string with newline';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('notes'), 'foo\nbar', 'serialize string with newline';
|
2013-12-20 19:54:11 +00:00
|
|
|
$config->set_deserialize('notes', 'bar\nbaz');
|
|
|
|
is $config->get('notes'), "bar\nbaz", 'deserialize string with newline';
|
2016-11-01 12:41:24 +00:00
|
|
|
|
|
|
|
foreach my $test_data (
|
|
|
|
{
|
|
|
|
name => 'empty',
|
|
|
|
values => [],
|
|
|
|
serialized => ''
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name => 'single empty',
|
|
|
|
values => [''],
|
|
|
|
serialized => '""'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name => 'single noempty, simple',
|
|
|
|
values => ['RGB'],
|
|
|
|
serialized => 'RGB'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name => 'multiple noempty, simple',
|
|
|
|
values => ['ABC', 'DEF', '09182745@!#$*(&'],
|
|
|
|
serialized => 'ABC;DEF;09182745@!#$*(&'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name => 'multiple, simple, some empty',
|
|
|
|
values => ['ABC', 'DEF', '', '09182745@!#$*(&', ''],
|
|
|
|
serialized => 'ABC;DEF;;09182745@!#$*(&;'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name => 'complex',
|
|
|
|
values => ['some "quoted" notes', "yet\n some notes", "whatever \n notes", ''],
|
|
|
|
serialized => '"some \"quoted\" notes";"yet\n some notes";"whatever \n notes";'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
{
|
|
|
|
$config->set('filament_notes', $test_data->{values});
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('filament_notes'), $test_data->{serialized}, 'serialize multi-string value ' . $test_data->{name};
|
2016-11-01 12:41:24 +00:00
|
|
|
$config->set_deserialize('filament_notes', '');
|
|
|
|
is_deeply $config->get('filament_notes'), [], 'deserialize multi-string value - empty ' . $test_data->{name};
|
|
|
|
$config->set_deserialize('filament_notes', $test_data->{serialized});
|
|
|
|
is_deeply $config->get('filament_notes'), $test_data->{values}, 'deserialize complex multi-string value ' . $test_data->{name};
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:54:11 +00:00
|
|
|
$config->set('first_layer_height', 0.3);
|
|
|
|
ok abs($config->get('first_layer_height') - 0.3) < 1e-4, 'set/get absolute floatOrPercent';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('first_layer_height'), '0.3', 'serialize absolute floatOrPercent';
|
2013-12-20 19:54:11 +00:00
|
|
|
|
2021-04-21 13:46:47 +00:00
|
|
|
# This is no more supported after first_layer_height was moved from PrintObjectConfig to PrintConfig.
|
|
|
|
# $config->set('first_layer_height', $config->get('layer_height'));
|
|
|
|
# $config->get_abs_value('first_layer_height');
|
|
|
|
# ok abs($config->get_abs_value('first_layer_height') - 0.15) < 1e-4, 'set/get relative floatOrPercent';
|
2021-04-21 13:38:00 +00:00
|
|
|
# is $config->opt_serialize('first_layer_height'), '50%', 'serialize relative floatOrPercent';
|
2013-12-20 19:54:11 +00:00
|
|
|
|
2014-06-16 21:58:45 +00:00
|
|
|
# Uh-oh, we have no point option to test at the moment
|
|
|
|
#ok $config->set('print_center', [50,80]), 'valid point coordinates';
|
|
|
|
#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';
|
|
|
|
#ok !$config->set('print_center', ['t',80]), 'invalid point X';
|
|
|
|
#ok !$config->set('print_center', [50,'t']), 'invalid point Y';
|
2013-12-20 20:32:18 +00:00
|
|
|
|
|
|
|
$config->set('use_relative_e_distances', 1);
|
|
|
|
is $config->get('use_relative_e_distances'), 1, 'set/get bool';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('use_relative_e_distances'), '1', 'serialize bool';
|
2013-12-21 09:46:43 +00:00
|
|
|
$config->set('gcode_flavor', 'teacup');
|
|
|
|
is $config->get('gcode_flavor'), 'teacup', 'set/get enum';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('gcode_flavor'), 'teacup', 'serialize enum';
|
2013-12-21 15:15:41 +00:00
|
|
|
$config->set_deserialize('gcode_flavor', 'mach3');
|
2014-01-05 15:51:16 +00:00
|
|
|
is $config->get('gcode_flavor'), 'mach3', 'deserialize enum (gcode_flavor)';
|
2015-01-07 20:20:58 +00:00
|
|
|
$config->set_deserialize('gcode_flavor', 'machinekit');
|
|
|
|
is $config->get('gcode_flavor'), 'machinekit', 'deserialize enum (gcode_flavor)';
|
2013-12-21 13:27:58 +00:00
|
|
|
|
2014-01-03 17:27:46 +00:00
|
|
|
$config->set_deserialize('fill_pattern', 'line');
|
2014-01-05 15:51:16 +00:00
|
|
|
is $config->get('fill_pattern'), 'line', 'deserialize enum (fill_pattern)';
|
|
|
|
|
2018-03-14 19:08:34 +00:00
|
|
|
$config->set_deserialize('support_material_pattern', 'rectilinear');
|
|
|
|
is $config->get('support_material_pattern'), 'rectilinear', 'deserialize enum (support_material_pattern)';
|
2014-01-03 17:27:46 +00:00
|
|
|
|
2013-12-21 13:27:58 +00:00
|
|
|
$config->set('extruder_offset', [[10,20],[30,45]]);
|
2014-10-28 22:37:20 +00:00
|
|
|
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[10,20],[30,45]], 'set/get points';
|
2014-11-04 20:07:18 +00:00
|
|
|
$config->set('extruder_offset', [Slic3r::Pointf->new(10,20),Slic3r::Pointf->new(30,45)]);
|
|
|
|
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[10,20],[30,45]], 'set/get points';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('extruder_offset'), '10x20,30x45', 'serialize points';
|
2013-12-21 13:27:58 +00:00
|
|
|
$config->set_deserialize('extruder_offset', '20x10');
|
2014-10-28 22:37:20 +00:00
|
|
|
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[20,10]], 'deserialize points';
|
2014-08-04 09:34:53 +00:00
|
|
|
$config->set_deserialize('extruder_offset', '0x0');
|
2014-10-28 22:37:20 +00:00
|
|
|
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [[0,0]], 'deserialize points';
|
2014-04-19 14:38:28 +00:00
|
|
|
{
|
|
|
|
my @values = ([10,20]);
|
|
|
|
$values[2] = [10,20]; # implicitely extend array; this is not the same as explicitely assigning undef to second item
|
|
|
|
ok !$config->set('extruder_offset', \@values), 'reject undef points';
|
|
|
|
}
|
2013-12-21 13:27:58 +00:00
|
|
|
|
|
|
|
# truncate ->get() to first decimal digit
|
2013-12-23 23:30:51 +00:00
|
|
|
$config->set('nozzle_diameter', [0.2,3]);
|
|
|
|
is_deeply [ map int($_*10)/10, @{$config->get('nozzle_diameter')} ], [0.2,3], 'set/get floats';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('nozzle_diameter'), '0.2,3', 'serialize floats';
|
2013-12-21 13:27:58 +00:00
|
|
|
$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';
|
2013-12-23 23:30:51 +00:00
|
|
|
$config->set_deserialize('nozzle_diameter', '3');
|
|
|
|
is_deeply [ map int($_*10)/10, @{$config->get('nozzle_diameter')} ], [3], 'deserialize a single float';
|
2014-04-19 14:38:28 +00:00
|
|
|
{
|
|
|
|
my @values = (0.4);
|
|
|
|
$values[2] = 2; # implicitely extend array; this is not the same as explicitely assigning undef to second item
|
|
|
|
ok !$config->set('nozzle_diameter', \@values), 'reject undef floats';
|
|
|
|
}
|
2013-12-21 13:27:58 +00:00
|
|
|
|
|
|
|
$config->set('temperature', [180,210]);
|
|
|
|
is_deeply $config->get('temperature'), [180,210], 'set/get ints';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('temperature'), '180,210', 'serialize ints';
|
2013-12-21 13:27:58 +00:00
|
|
|
$config->set_deserialize('temperature', '195,220');
|
|
|
|
is_deeply $config->get('temperature'), [195,220], 'deserialize ints';
|
2014-04-19 14:38:28 +00:00
|
|
|
{
|
|
|
|
my @values = (180);
|
|
|
|
$values[2] = 200; # implicitely extend array; this is not the same as explicitely assigning undef to second item
|
|
|
|
ok !$config->set('temperature', \@values), 'reject undef ints';
|
|
|
|
}
|
2013-12-21 13:27:58 +00:00
|
|
|
|
|
|
|
$config->set('wipe', [1,0]);
|
|
|
|
is_deeply $config->get('wipe'), [1,0], 'set/get bools';
|
2014-01-04 23:36:33 +00:00
|
|
|
is $config->get_at('wipe', 0), 1, 'get_at bools';
|
|
|
|
is $config->get_at('wipe', 1), 0, 'get_at bools';
|
|
|
|
is $config->get_at('wipe', 9), 1, 'get_at bools';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('wipe'), '1,0', 'serialize bools';
|
2013-12-21 13:27:58 +00:00
|
|
|
$config->set_deserialize('wipe', '0,1,1');
|
|
|
|
is_deeply $config->get('wipe'), [0,1,1], 'deserialize bools';
|
2014-05-21 09:38:42 +00:00
|
|
|
$config->set_deserialize('wipe', '');
|
|
|
|
is_deeply $config->get('wipe'), [], 'deserialize bools from empty string';
|
2014-04-19 17:14:41 +00:00
|
|
|
$config->set_deserialize('retract_layer_change', 0);
|
|
|
|
is_deeply $config->get('retract_layer_change'), [0], 'deserialize bools from non-string value';
|
2014-04-19 14:38:28 +00:00
|
|
|
{
|
|
|
|
my @values = (1);
|
|
|
|
$values[2] = 1; # implicitely extend array; this is not the same as explicitely assigning undef to second item
|
|
|
|
ok !$config->set('wipe', \@values), 'reject undef bools';
|
|
|
|
}
|
2013-12-21 20:06:45 +00:00
|
|
|
|
2013-12-21 23:39:03 +00:00
|
|
|
$config->set('post_process', ['foo','bar']);
|
|
|
|
is_deeply $config->get('post_process'), ['foo','bar'], 'set/get strings';
|
2019-06-27 09:02:45 +00:00
|
|
|
is $config->opt_serialize('post_process'), 'foo;bar', 'serialize strings';
|
2013-12-21 23:39:03 +00:00
|
|
|
$config->set_deserialize('post_process', 'bar;baz');
|
|
|
|
is_deeply $config->get('post_process'), ['bar','baz'], 'deserialize strings';
|
2014-04-19 14:38:28 +00:00
|
|
|
{
|
|
|
|
my @values = ('foo');
|
|
|
|
$values[2] = 'bar'; # implicitely extend array; this is not the same as explicitely assigning undef to second item
|
|
|
|
ok !$config->set('post_process', \@values), 'reject undef strings';
|
|
|
|
}
|
2013-12-21 23:39:03 +00:00
|
|
|
|
2013-12-21 20:06:45 +00:00
|
|
|
is_deeply [ sort @{$config->get_keys} ], [ sort keys %{$config->as_hash} ], 'get_keys and as_hash';
|
2013-12-20 19:54:11 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 15:32:11 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
$config->set('perimeters', 2);
|
|
|
|
|
2013-12-23 23:30:51 +00:00
|
|
|
# test that no crash happens when using set_deserialize() with a key that hasn't been set() yet
|
|
|
|
$config->set_deserialize('filament_diameter', '3');
|
|
|
|
|
2015-12-16 11:58:06 +00:00
|
|
|
my $config2 = Slic3r::Config::Static::new_FullPrintConfig;
|
2013-12-21 15:32:11 +00:00
|
|
|
$config2->apply_dynamic($config);
|
2013-12-21 20:06:45 +00:00
|
|
|
is $config2->get('perimeters'), 2, 'apply_dynamic';
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-12-16 11:58:06 +00:00
|
|
|
my $config = Slic3r::Config::Static::new_FullPrintConfig;
|
2013-12-21 20:06:45 +00:00
|
|
|
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';
|
2014-01-05 12:16:13 +00:00
|
|
|
|
|
|
|
$config->set('top_solid_infill_speed', 70);
|
|
|
|
is $config->get_abs_value('top_solid_infill_speed'), 70, 'get_abs_value() works when ratio_over references a floatOrPercent option';
|
2013-12-21 15:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-01-03 17:27:46 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
$config->set('fill_pattern', 'line');
|
|
|
|
|
|
|
|
my $config2 = Slic3r::Config->new;
|
|
|
|
$config2->set('fill_pattern', 'hilbertcurve');
|
|
|
|
|
|
|
|
is $config->get('fill_pattern'), 'line', 'no interferences between DynamicConfig objects';
|
|
|
|
}
|
|
|
|
|
2014-03-24 13:16:37 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
# the pair [0,0] is part of the test, since it checks whether the 0x0 serialized value is correctly parsed
|
|
|
|
$config->set('extruder_offset', [ [0,0], [20,0], [0,20] ]);
|
|
|
|
my $config2 = Slic3r::Config->new;
|
|
|
|
$config2->apply($config);
|
2014-10-28 22:37:20 +00:00
|
|
|
is_deeply [ map $_->pp, @{$config->get('extruder_offset')} ], [ map $_->pp, @{$config2->get('extruder_offset')} ],
|
|
|
|
'apply dynamic over dynamic';
|
2014-03-24 13:16:37 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 23:01:33 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
$config->set('extruder', 2);
|
|
|
|
$config->set('perimeter_extruder', 3);
|
2020-09-24 18:32:52 +00:00
|
|
|
$config->normalize_fdm;
|
2014-03-26 23:01:33 +00:00
|
|
|
ok !$config->has('extruder'), 'extruder option is removed after normalize()';
|
|
|
|
is $config->get('infill_extruder'), 2, 'undefined extruder is populated with default extruder';
|
|
|
|
is $config->get('perimeter_extruder'), 3, 'defined extruder is not overwritten by default extruder';
|
|
|
|
}
|
|
|
|
|
2014-12-16 23:34:00 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
$config->set('infill_extruder', 2);
|
2020-09-24 18:32:52 +00:00
|
|
|
$config->normalize_fdm;
|
2014-12-16 23:34:00 +00:00
|
|
|
is $config->get('solid_infill_extruder'), 2, 'undefined solid infill extruder is populated with infill extruder';
|
|
|
|
}
|
|
|
|
|
2014-05-26 21:51:58 +00:00
|
|
|
{
|
|
|
|
my $config = Slic3r::Config->new;
|
|
|
|
$config->set('spiral_vase', 1);
|
|
|
|
$config->set('retract_layer_change', [1,0]);
|
2020-09-24 18:32:52 +00:00
|
|
|
$config->normalize_fdm;
|
2014-05-26 21:51:58 +00:00
|
|
|
is_deeply $config->get('retract_layer_change'), [0,0], 'retract_layer_change is disabled with spiral_vase';
|
|
|
|
}
|
|
|
|
|
2017-06-14 15:51:14 +00:00
|
|
|
{
|
|
|
|
use Cwd qw(abs_path);
|
|
|
|
use File::Basename qw(dirname);
|
|
|
|
my $path = abs_path($0);
|
2017-10-27 14:11:06 +00:00
|
|
|
my $config = Slic3r::Config::load(dirname($path)."/inc/22_config_bad_config_options.ini");
|
2017-06-14 15:51:14 +00:00
|
|
|
ok 1, 'did not crash on reading invalid items in config';
|
|
|
|
}
|
|
|
|
|
2013-12-20 19:54:11 +00:00
|
|
|
__END__
|