Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Config.pm « Slic3r « lib - github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: faa6fc06e50634c410fa035077ec40de1d7ca4b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
package Slic3r::Config;
use strict;
use warnings;
use utf8;

use List::Util qw(first);

# cemetery of old config settings
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
    adjust_overhang_flow);

my $serialize_comma     = sub { join ',', @{$_[0]} };
my $serialize_comma_bool = sub { join ',', map $_ // 0, @{$_[0]} };
my $deserialize_comma   = sub { [ split /,/, $_[0] ] };

our $Options = {

    # miscellaneous options
    'notes' => {
        label   => 'Configuration notes',
        tooltip => 'You can put here your personal notes. This text will be added to the G-code header comments.',
        cli     => 'notes=s',
        type    => 's',
        multiline => 1,
        full_width => 1,
        height  => 130,
        serialize   => sub { join '\n', split /\R/, $_[0] },
        deserialize => sub { join "\n", split /\\n/, $_[0] },
        default => '',
    },
    'threads' => {
        label   => 'Threads',
        tooltip => 'Threads are used to parallelize long-running tasks. Optimal threads number is slightly above the number of available cores/processors. Beware that more threads consume more memory.',
        sidetext => '(more speed but more memory usage)',
        cli     => 'threads|j=i',
        type    => 'i',
        min     => 1,
        max     => 16,
        default => $Slic3r::have_threads ? 2 : 1,
        readonly => !$Slic3r::have_threads,
    },
    'resolution' => {
        label   => 'Resolution',
        tooltip => 'Minimum detail resolution, used to simplify the input file for speeding up the slicing job and reducing memory usage. High-resolution models often carry more detail than printers can render. Set to zero to disable any simplification and use full resolution from input.',
        sidetext => 'mm',
        cli     => 'resolution=f',
        type    => 'f',
        min     => 0,
        default => 0,
    },

    # output options
    'output_filename_format' => {
        label   => 'Output filename format',
        tooltip => 'You can use all configuration options as variables inside this template. For example: [layer_height], [fill_density] etc. You can also use [timestamp], [year], [month], [day], [hour], [minute], [second], [version], [input_filename], [input_filename_base].',
        cli     => 'output-filename-format=s',
        type    => 's',
        full_width => 1,
        default => '[input_filename_base].gcode',
    },

    # printer options
    'print_center' => {
        label   => 'Print center',
        tooltip => 'Enter the G-code coordinates of the point you want to center your print around.',
        sidetext => 'mm',
        cli     => 'print-center=s',
        type    => 'point',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [100,100],
    },
    'gcode_flavor' => {
        label   => 'G-code flavor',
        tooltip => 'Some G/M-code commands, including temperature control and others, are not universal. Set this option to your printer\'s firmware to get a compatible output. The "No extrusion" flavor prevents Slic3r from exporting any extrusion value at all.',
        cli     => 'gcode-flavor=s',
        type    => 'select',
        values  => [qw(reprap teacup makerware sailfish mach3 no-extrusion)],
        labels  => ['RepRap (Marlin/Sprinter/Repetier)', 'Teacup', 'MakerWare (MakerBot)', 'Sailfish (MakerBot)', 'Mach3/EMC', 'No extrusion'],
        default => 'reprap',
    },
    'use_relative_e_distances' => {
        label   => 'Use relative E distances',
        tooltip => 'If your firmware requires relative E values, check this, otherwise leave it unchecked. Most firmwares use absolute values.',
        cli     => 'use-relative-e-distances!',
        type    => 'bool',
        default => 0,
    },
    'extrusion_axis' => {
        label   => 'Extrusion axis',
        tooltip => 'Use this option to set the axis letter associated to your printer\'s extruder (usually E but some printers use A).',
        cli     => 'extrusion-axis=s',
        type    => 's',
        default => 'E',
    },
    'z_offset' => {
        label   => 'Z offset',
        tooltip => 'This value will be added (or subtracted) from all the Z coordinates in the output G-code. It is used to compensate for bad Z endstop position: for example, if your endstop zero actually leaves the nozzle 0.3mm far from the print bed, set this to -0.3 (or fix your endstop).',
        sidetext => 'mm',
        cli     => 'z-offset=f',
        type    => 'f',
        default => 0,
    },
    'gcode_arcs' => {
        label   => 'Use native G-code arcs',
        tooltip => 'This experimental feature tries to detect arcs from segments and generates G2/G3 arc commands instead of multiple straight G1 commands.',
        cli     => 'gcode-arcs!',
        type    => 'bool',
        default => 0,
    },
    'g0' => {
        label   => 'Use G0 for travel moves',
        tooltip => 'Only enable this if your firmware supports G0 properly (thus decouples all axes using their maximum speeds instead of synchronizing them). Travel moves and retractions will be combined in single commands, speeding them print up.',
        cli     => 'g0!',
        type    => 'bool',
        default => 0,
    },
    'gcode_comments' => {
        label   => 'Verbose G-code',
        tooltip => 'Enable this to get a commented G-code file, with each line explained by a descriptive text. If you print from SD card, the additional weight of the file could make your firmware slow down.',
        cli     => 'gcode-comments!',
        type    => 'bool',
        default => 0,
    },
    
    # extruders options
    'extruder_offset' => {
        label   => 'Extruder offset',
        tooltip => 'If your firmware doesn\'t handle the extruder displacement you need the G-code to take it into account. This option lets you specify the displacement of each extruder with respect to the first one. It expects positive coordinates (they will be subtracted from the XY coordinate).',
        sidetext => 'mm',
        cli     => 'extruder-offset=s@',
        type    => 'point',
        serialize   => sub { join ',', map { join 'x', @$_ } @{$_[0]} },
        deserialize => sub { [ map [ split /x/, $_ ], (ref $_[0] eq 'ARRAY') ? @{$_[0]} : (split /,/, $_[0] || '0x0') ] },
        default => [[0,0]],
    },
    'nozzle_diameter' => {
        label   => 'Nozzle diameter',
        tooltip => 'This is the diameter of your extruder nozzle (for example: 0.5, 0.35 etc.)',
        cli     => 'nozzle-diameter=f@',
        type    => 'f',
        sidetext => 'mm',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [0.5],
    },
    'filament_diameter' => {
        label   => 'Diameter',
        tooltip => 'Enter your filament diameter here. Good precision is required, so use a caliper and do multiple measurements along the filament, then compute the average.',
        sidetext => 'mm',
        cli     => 'filament-diameter=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default     => [3],
    },
    'extrusion_multiplier' => {
        label   => 'Extrusion multiplier',
        tooltip => 'This factor changes the amount of flow proportionally. You may need to tweak this setting to get nice surface finish and correct single wall widths. Usual values are between 0.9 and 1.1. If you think you need to change this more, check filament diameter and your firmware E steps.',
        cli     => 'extrusion-multiplier=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [1],
    },
    'temperature' => {
        label   => 'Other layers',
        tooltip => 'Extruder temperature for layers after the first one. Set this to zero to disable temperature control commands in the output.',
        sidetext => '°C',
        cli     => 'temperature=i@',
        type    => 'i',
        max     => 400,
        serialize   => $serialize_comma,
        deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] },
        default => [200],
    },
    'first_layer_temperature' => {
        label   => 'First layer',
        tooltip => 'Extruder temperature for first layer. If you want to control temperature manually during print, set this to zero to disable temperature control commands in the output file.',
        sidetext => '°C',
        cli     => 'first-layer-temperature=i@',
        type    => 'i',
        serialize   => $serialize_comma,
        deserialize => sub { $_[0] ? [ split /,/, $_[0] ] : [0] },
        max     => 400,
        default => [200],
    },
    
    # extruder mapping
    'perimeter_extruder' => {
        label   => 'Perimeter extruder',
        tooltip => 'The extruder to use when printing perimeters.',
        cli     => 'perimeter-extruder=i',
        type    => 'i',
        aliases => [qw(perimeters_extruder)],
        default => 1,
    },
    'infill_extruder' => {
        label   => 'Infill extruder',
        tooltip => 'The extruder to use when printing infill.',
        cli     => 'infill-extruder=i',
        type    => 'i',
        default => 1,
    },
    'support_material_extruder' => {
        label   => 'Support material extruder',
        tooltip => 'The extruder to use when printing support material. This affects brim too.',
        cli     => 'support-material-extruder=i',
        type    => 'i',
        default => 1,
    },
    
    # filament options
    'first_layer_bed_temperature' => {
        label   => 'First layer',
        tooltip => 'Heated build plate temperature for the first layer. Set this to zero to disable bed temperature control commands in the output.',
        sidetext => '°C',
        cli     => 'first-layer-bed-temperature=i',
        type    => 'i',
        max     => 300,
        default => 0,
    },
    'bed_temperature' => {
        label   => 'Other layers',
        tooltip => 'Bed temperature for layers after the first one. Set this to zero to disable bed temperature control commands in the output.',
        sidetext => '°C',
        cli     => 'bed-temperature=i',
        type    => 'i',
        max     => 300,
        default => 0,
    },
    
    # speed options
    'travel_speed' => {
        label   => 'Travel',
        tooltip => 'Speed for travel moves (jumps between distant extrusion points).',
        sidetext => 'mm/s',
        cli     => 'travel-speed=f',
        type    => 'f',
        aliases => [qw(travel_feed_rate)],
        default => 130,
    },
    'perimeter_speed' => {
        label   => 'Perimeters',
        tooltip => 'Speed for perimeters (contours, aka vertical shells).',
        sidetext => 'mm/s',
        cli     => 'perimeter-speed=f',
        type    => 'f',
        aliases => [qw(perimeter_feed_rate)],
        default => 30,
    },
    'small_perimeter_speed' => {
        label   => 'Small perimeters',
        tooltip => 'This separate setting will affect the speed of perimeters having radius <= 6.5mm (usually holes). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above.',
        sidetext => 'mm/s or %',
        cli     => 'small-perimeter-speed=s',
        type    => 'f',
        ratio_over => 'perimeter_speed',
        default => 30,
    },
    'external_perimeter_speed' => {
        label   => 'External perimeters',
        tooltip => 'This separate setting will affect the speed of external perimeters (the visible ones). If expressed as percentage (for example: 80%) it will be calculated on the perimeters speed setting above.',
        sidetext => 'mm/s or %',
        cli     => 'external-perimeter-speed=s',
        type    => 'f',
        ratio_over => 'perimeter_speed',
        default => '70%',
    },
    'infill_speed' => {
        label   => 'Infill',
        tooltip => 'Speed for printing the internal fill.',
        sidetext => 'mm/s',
        cli     => 'infill-speed=f',
        type    => 'f',
        aliases => [qw(print_feed_rate infill_feed_rate)],
        default => 60,
    },
    'solid_infill_speed' => {
        label   => 'Solid infill',
        tooltip => 'Speed for printing solid regions (top/bottom/internal horizontal shells). This can be expressed as a percentage (for example: 80%) over the default infill speed above.',
        sidetext => 'mm/s or %',
        cli     => 'solid-infill-speed=s',
        type    => 'f',
        ratio_over => 'infill_speed',
        aliases => [qw(solid_infill_feed_rate)],
        default => 60,
    },
    'top_solid_infill_speed' => {
        label   => 'Top solid infill',
        tooltip => 'Speed for printing top solid regions. You may want to slow down this to get a nicer surface finish. This can be expressed as a percentage (for example: 80%) over the solid infill speed above.',
        sidetext => 'mm/s or %',
        cli     => 'top-solid-infill-speed=s',
        type    => 'f',
        ratio_over => 'solid_infill_speed',
        default => 50,
    },
    'support_material_speed' => {
        label   => 'Support material',
        tooltip => 'Speed for printing support material.',
        sidetext => 'mm/s',
        cli     => 'support-material-speed=f',
        type    => 'f',
        default => 60,
    },
    'bridge_speed' => {
        label   => 'Bridges',
        tooltip => 'Speed for printing bridges.',
        sidetext => 'mm/s',
        cli     => 'bridge-speed=f',
        type    => 'f',
        aliases => [qw(bridge_feed_rate)],
        default => 60,
    },
    'gap_fill_speed' => {
        label   => 'Gap fill',
        tooltip => 'Speed for filling small gaps using short zigzag moves. Keep this reasonably low to avoid too much shaking and resonance issues. Set zero to disable gaps filling.',
        sidetext => 'mm/s',
        cli     => 'gap-fill-speed=f',
        type    => 'f',
        default => 20,
    },
    'first_layer_speed' => {
        label   => 'First layer speed',
        tooltip => 'If expressed as absolute value in mm/s, this speed will be applied to all the print moves of the first layer, regardless of their type. If expressed as a percentage (for example: 40%) it will scale the default speeds.',
        sidetext => 'mm/s or %',
        cli     => 'first-layer-speed=s',
        type    => 'f',
        default => '30%',
    },
    
    # acceleration options
    'default_acceleration' => {
        label   => 'Default',
        tooltip => 'This is the acceleration your printer will be reset to after the role-specific acceleration values are used (perimeter/infill). Set zero to prevent resetting acceleration at all.',
        sidetext => 'mm/s²',
        cli     => 'default-acceleration=f',
        type    => 'f',
        default => 0,
    },
    'perimeter_acceleration' => {
        label   => 'Perimeters',
        tooltip => 'This is the acceleration your printer will use for perimeters. A high value like 9000 usually gives good results if your hardware is up to the job. Set zero to disable acceleration control for perimeters.',
        sidetext => 'mm/s²',
        cli     => 'perimeter-acceleration=f',
        type    => 'f',
        default => 0,
    },
    'infill_acceleration' => {
        label   => 'Infill',
        tooltip => 'This is the acceleration your printer will use for infill. Set zero to disable acceleration control for infill.',
        sidetext => 'mm/s²',
        cli     => 'infill-acceleration=f',
        type    => 'f',
        default => 0,
    },
    'bridge_acceleration' => {
        label   => 'Bridge',
        tooltip => 'This is the acceleration your printer will use for bridges. Set zero to disable acceleration control for bridges.',
        sidetext => 'mm/s²',
        cli     => 'bridge-acceleration=f',
        type    => 'f',
        default => 0,
    },
    
    # accuracy options
    'layer_height' => {
        label   => 'Layer height',
        tooltip => 'This setting controls the height (and thus the total number) of the slices/layers. Thinner layers give better accuracy but take more time to print.',
        sidetext => 'mm',
        cli     => 'layer-height=f',
        type    => 'f',
        default => 0.4,
    },
    'first_layer_height' => {
        label   => 'First layer height',
        tooltip => 'When printing with very low layer heights, you might still want to print a thicker bottom layer to improve adhesion and tolerance for non perfect build plates. This can be expressed as an absolute value or as a percentage (for example: 150%) over the default layer height.',
        sidetext => 'mm or %',
        cli     => 'first-layer-height=s',
        type    => 'f',
        ratio_over => 'layer_height',
        default => 0.35,
    },
    'infill_every_layers' => {
        label   => 'Infill every',
        tooltip => 'This feature allows to combine infill and speed up your print by extruding thicker infill layers while preserving thin perimeters, thus accuracy.',
        sidetext => 'layers',
        cli     => 'infill-every-layers=i',
        type    => 'i',
        min     => 1,
        default => 1,
    },
    'solid_infill_every_layers' => {
        label   => 'Solid infill every',
        tooltip => 'This feature allows to force a solid layer every given number of layers. Zero to disable.',
        sidetext => 'layers',
        cli     => 'solid-infill-every-layers=i',
        type    => 'i',
        min     => 0,
        default => 0,
    },
    'infill_only_where_needed' => {
        label   => 'Only infill where needed',
        tooltip => 'This option will limit infill to the areas actually needed for supporting ceilings (it will act as internal support material).',
        cli     => 'infill-only-where-needed!',
        type    => 'bool',
        default => 0,
    },
    'infill_first' => {
        label   => 'Infill before perimeters',
        tooltip => 'This option will switch the print order of perimeters and infill, making the latter first.',
        cli     => 'infill-first!',
        type    => 'bool',
        default => 0,
    },
    
    # flow options
    'extrusion_width' => {
        label   => 'Default extrusion width',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width. If left to zero, Slic3r calculates a width automatically. If expressed as percentage (for example: 230%) it will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for auto)',
        cli     => 'extrusion-width=s',
        type    => 'f',
        default => 0,
    },
    'first_layer_extrusion_width' => {
        label   => 'First layer',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for first layer. You can use this to force fatter extrudates for better adhesion. If expressed as percentage (for example 120%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'first-layer-extrusion-width=s',
        type    => 'f',
        default => '200%',
    },
    'perimeter_extrusion_width' => {
        label   => 'Perimeters',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for perimeters. You may want to use thinner extrudates to get more accurate surfaces. If expressed as percentage (for example 90%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'perimeter-extrusion-width=s',
        type    => 'f',
        aliases => [qw(perimeters_extrusion_width)],
        default => 0,
    },
    'infill_extrusion_width' => {
        label   => 'Infill',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill. You may want to use fatter extrudates to speed up the infill and make your parts stronger. If expressed as percentage (for example 90%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'infill-extrusion-width=s',
        type    => 'f',
        default => 0,
    },
    'solid_infill_extrusion_width' => {
        label   => 'Solid infill',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill for solid surfaces. If expressed as percentage (for example 90%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'solid-infill-extrusion-width=s',
        type    => 'f',
        default => 0,
    },
    'top_infill_extrusion_width' => {
        label   => 'Top solid infill',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for infill for top surfaces. You may want to use thinner extrudates to fill all narrow regions and get a smoother finish. If expressed as percentage (for example 90%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'top-infill-extrusion-width=s',
        type    => 'f',
        default => 0,
    },
    'support_material_extrusion_width' => {
        label   => 'Support material',
        tooltip => 'Set this to a non-zero value to set a manual extrusion width for support material. If expressed as percentage (for example 90%) if will be computed over layer height.',
        sidetext => 'mm or % (leave 0 for default)',
        cli     => 'support-material-extrusion-width=s',
        type    => 'f',
        default => 0,
    },
    'bridge_flow_ratio' => {
        label   => 'Bridge flow ratio',
        tooltip => 'This factor affects the amount of plastic for bridging. You can decrease it slightly to pull the extrudates and prevent sagging, although default settings are usually good and you should experiment with cooling (use a fan) before tweaking this.',
        cli     => 'bridge-flow-ratio=f',
        type    => 'f',
        default => 1,
    },
    'vibration_limit' => {
        label   => 'Vibration limit',
        tooltip => 'This experimental option will slow down those moves hitting the configured frequency limit. The purpose of limiting vibrations is to avoid mechanical resonance. Set zero to disable.',
        sidetext => 'Hz',
        cli     => 'vibration-limit=f',
        type    => 'f',
        default => 0,
    },
    
    # print options
    'perimeters' => {
        label   => 'Perimeters (minimum)',
        tooltip => 'This option sets the number of perimeters to generate for each layer. Note that Slic3r will increase this number automatically when it detects sloping surfaces which benefit from a higher number of perimeters.',
        cli     => 'perimeters=i',
        type    => 'i',
        aliases => [qw(perimeter_offsets)],
        default => 3,
    },
    'solid_layers' => {
        label   => 'Solid layers',
        tooltip => 'Number of solid layers to generate on top and bottom surfaces.',
        cli     => 'solid-layers=i',
        type    => 'i',
        shortcut => [qw(top_solid_layers bottom_solid_layers)],
    },
    'top_solid_layers' => {
        label   => 'Top',
        tooltip => 'Number of solid layers to generate on top surfaces.',
        cli     => 'top-solid-layers=i',
        type    => 'i',
        default => 3,
    },
    'bottom_solid_layers' => {
        label   => 'Bottom',
        tooltip => 'Number of solid layers to generate on bottom surfaces.',
        cli     => 'bottom-solid-layers=i',
        type    => 'i',
        default => 3,
    },
    'fill_pattern' => {
        label   => 'Fill pattern',
        tooltip => 'Fill pattern for general low-density infill.',
        cli     => 'fill-pattern=s',
        type    => 'select',
        values  => [qw(rectilinear line concentric honeycomb hilbertcurve archimedeanchords octagramspiral)],
        labels  => [qw(rectilinear line concentric honeycomb), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
        default => 'honeycomb',
    },
    'solid_fill_pattern' => {
        label   => 'Top/bottom fill pattern',
        tooltip => 'Fill pattern for top/bottom infill.',
        cli     => 'solid-fill-pattern=s',
        type    => 'select',
        values  => [qw(rectilinear concentric hilbertcurve archimedeanchords octagramspiral)],
        labels  => [qw(rectilinear concentric), 'hilbertcurve (slow)', 'archimedeanchords (slow)', 'octagramspiral (slow)'],
        default => 'rectilinear',
    },
    'fill_density' => {
        label   => 'Fill density',
        tooltip => 'Density of internal infill, expressed in the range 0 - 1.',
        cli     => 'fill-density=f',
        type    => 'f',
        default => 0.4,
    },
    'fill_angle' => {
        label   => 'Fill angle',
        tooltip => 'Default base angle for infill orientation. Cross-hatching will be applied to this. Bridges will be infilled using the best direction Slic3r can detect, so this setting does not affect them.',
        sidetext => '°',
        cli     => 'fill-angle=i',
        type    => 'i',
        max     => 359,
        default => 45,
    },
    'solid_infill_below_area' => {
        label   => 'Solid infill threshold area',
        tooltip => 'Force solid infill for regions having a smaller area than the specified threshold.',
        sidetext => 'mm²',
        cli     => 'solid-infill-below-area=f',
        type    => 'f',
        default => 70,
    },
    'extra_perimeters' => {
        label   => 'Extra perimeters if needed',
        tooltip => 'Add more perimeters when needed for avoiding gaps in sloping walls.',
        cli     => 'extra-perimeters!',
        type    => 'bool',
        default => 1,
    },
    'randomize_start' => {
        label   => 'Randomize starting points',
        tooltip => 'Start each layer from a different vertex to prevent plastic build-up on the same corner.',
        cli     => 'randomize-start!',
        type    => 'bool',
        default => 0,
    },
    'start_perimeters_at_concave_points' => {
        label   => 'Concave points',
        tooltip => 'Prefer to start perimeters at a concave point.',
        cli     => 'start-perimeters-at-concave-points!',
        type    => 'bool',
        default => 0,
    },
    'start_perimeters_at_non_overhang' => {
        label   => 'Non-overhang points',
        tooltip => 'Prefer to start perimeters at non-overhanging points.',
        cli     => 'start-perimeters-at-non-overhang!',
        type    => 'bool',
        default => 0,
    },
    'thin_walls' => {
        label   => 'Detect thin walls',
        tooltip => 'Detect single-width walls (parts where two extrusions don\'t fit and we need to collapse them into a single trace).',
        cli     => 'thin-walls!',
        type    => 'bool',
        default => 1,
    },
    'overhangs' => {
        label   => 'Detect overhangs',
        tooltip => 'Experimental option to adjust flow for overhangs (bridge flow will be used), to apply bridge speed to them and enable fan.',
        cli     => 'overhangs!',
        type    => 'bool',
        default => 1,
    },
    'avoid_crossing_perimeters' => {
        label   => 'Avoid crossing perimeters',
        tooltip => 'Optimize travel moves in order to minimize the crossing of perimeters. This is mostly useful with Bowden extruders which suffer from oozing. This feature slows down both the print and the G-code generation.',
        cli     => 'avoid-crossing-perimeters!',
        type    => 'bool',
        default => 0,
    },
    'external_perimeters_first' => {
        label   => 'External perimeters first',
        tooltip => 'Print contour perimeters from the outermost one to the innermost one instead of the default inverse order.',
        cli     => 'external-perimeters-first!',
        type    => 'bool',
        default => 0,
    },
    'spiral_vase' => {
        label   => 'Spiral vase',
        tooltip => 'This experimental feature will raise Z gradually while printing a single-walled object in order to remove any visible seam. By enabling this option other settings will be overridden to enforce a single perimeter, no infill, no top solid layers, no support material. You can still set any number of bottom solid layers as well as skirt/brim loops. It won\'t work when printing more than an object.',
        cli     => 'spiral-vase!',
        type    => 'bool',
        default => 0,
    },
    'only_retract_when_crossing_perimeters' => {
        label   => 'Only retract when crossing perimeters',
        tooltip => 'Disables retraction when the travel path does not exceed the upper layer\'s perimeters (and thus any ooze will be probably invisible).',
        cli     => 'only-retract-when-crossing-perimeters!',
        type    => 'bool',
        default => 1,
    },
    'support_material' => {
        label   => 'Generate support material',
        tooltip => 'Enable support material generation.',
        cli     => 'support-material!',
        type    => 'bool',
        default => 0,
    },
    'support_material_threshold' => {
        label   => 'Overhang threshold',
        tooltip => 'Support material will not generated for overhangs whose slope angle is above the given threshold. Set to zero for automatic detection.',
        sidetext => '°',
        cli     => 'support-material-threshold=i',
        type    => 'i',
        default => 0,
    },
    'support_material_pattern' => {
        label   => 'Pattern',
        tooltip => 'Pattern used to generate support material.',
        cli     => 'support-material-pattern=s',
        type    => 'select',
        values  => [qw(rectilinear rectilinear-grid honeycomb)],
        labels  => ['rectilinear', 'rectilinear grid', 'honeycomb'],
        default => 'rectilinear',
    },
    'support_material_spacing' => {
        label   => 'Pattern spacing',
        tooltip => 'Spacing between support material lines.',
        sidetext => 'mm',
        cli     => 'support-material-spacing=f',
        type    => 'f',
        default => 2.5,
    },
    'support_material_angle' => {
        label   => 'Pattern angle',
        tooltip => 'Use this setting to rotate the support material pattern on the horizontal plane.',
        sidetext => '°',
        cli     => 'support-material-angle=i',
        type    => 'i',
        default => 0,
    },
    'support_material_interface_layers' => {
        label   => 'Interface layers',
        tooltip => 'Number of interface layers to insert between the object(s) and support material.',
        sidetext => 'layers',
        cli     => 'support-material-interface-layers=i',
        type    => 'i',
        default => 0,
    },
    'support_material_interface_spacing' => {
        label   => 'Interface pattern spacing',
        tooltip => 'Spacing between interface lines. Set zero to get a solid interface.',
        sidetext => 'mm',
        cli     => 'support-material-interface-spacing=f',
        type    => 'f',
        default => 0,
    },
    'support_material_enforce_layers' => {
        label   => 'Enforce support for the first',
        tooltip => 'Generate support material for the specified number of layers counting from bottom, regardless of whether normal support material is enabled or not and regardless of any angle threshold. This is useful for getting more adhesion of objects having a very thin or poor footprint on the build plate.',
        sidetext => 'layers',
        cli     => 'support-material-enforce-layers=f',
        type    => 'i',
        default => 0,
    },
    'raft_layers' => {
        label   => 'Raft layers',
        tooltip => 'Number of total raft layers to insert below the object(s).',
        sidetext => 'layers',
        cli     => 'raft-layers=i',
        type    => 'i',
        default => 0,
    },
    'start_gcode' => {
        label   => 'Start G-code',
        tooltip => 'This start procedure is inserted at the beginning of the output file, right after the temperature control commands for extruder and bed. If Slic3r detects M104 or M190 in your custom codes, such commands will not be prepended automatically. Note that you can use placeholder variables for all Slic3r settings, so you can put a "M104 S[first_layer_temperature]" command wherever you want.',
        cli     => 'start-gcode=s',
        type    => 's',
        multiline => 1,
        full_width => 1,
        height  => 120,
        serialize   => sub { join '\n', split /\R+/, $_[0] },
        deserialize => sub { join "\n", split /\\n/, $_[0] },
        default => <<'END',
G28 ; home all axes
G1 Z5 F5000 ; lift nozzle
END
    },
    'end_gcode' => {
        label   => 'End G-code',
        tooltip => 'This end procedure is inserted at the end of the output file. Note that you can use placeholder variables for all Slic3r settings.',
        cli     => 'end-gcode=s',
        type    => 's',
        multiline => 1,
        full_width => 1,
        height  => 120,
        serialize   => sub { join '\n', split /\R+/, $_[0] },
        deserialize => sub { join "\n", split /\\n/, $_[0] },
        default => <<'END',
M104 S0 ; turn off temperature
G28 X0  ; home X axis
M84     ; disable motors
END
    },
    'layer_gcode' => {
        label   => 'Layer change G-code',
        tooltip => 'This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings.',
        cli     => 'layer-gcode=s',
        type    => 's',
        multiline => 1,
        full_width => 1,
        height  => 50,
        serialize   => sub { join '\n', split /\R+/, $_[0] },
        deserialize => sub { join "\n", split /\\n/, $_[0] },
        default => '',
    },
    'toolchange_gcode' => {
        label   => 'Tool change G-code',
        tooltip => 'This custom code is inserted at every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].',
        cli     => 'toolchange-gcode=s',
        type    => 's',
        multiline => 1,
        full_width => 1,
        height  => 50,
        serialize   => sub { join '\n', split /\R+/, $_[0] },
        deserialize => sub { join "\n", split /\\n/, $_[0] },
        default => '',
    },
    'post_process' => {
        label   => 'Post-processing scripts',
        tooltip => 'If you want to process the output G-code through custom scripts, just list their absolute paths here. Separate multiple scripts with a semicolon. Scripts will be passed the absolute path to the G-code file as the first argument, and they can access the Slic3r config settings by reading environment variables.',
        cli     => 'post-process=s@',
        type    => 's@',
        multiline => 1,
        full_width => 1,
        height  => 60,
        serialize   => sub { join '; ', @{$_[0]} },
        deserialize => sub { [ split /\s*(?:;|\R)\s*/s, $_[0] ] },
        default => [],
    },
    
    # retraction options
    'retract_length' => {
        label   => 'Length',
        tooltip => 'When retraction is triggered, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).',
        sidetext => 'mm (zero to disable)',
        cli     => 'retract-length=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [1],
    },
    'retract_speed' => {
        label   => 'Speed',
        tooltip => 'The speed for retractions (it only applies to the extruder motor).',
        sidetext => 'mm/s',
        cli     => 'retract-speed=f@',
        type    => 'i',
        max     => 1000,
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [30],
    },
    'retract_restart_extra' => {
        label   => 'Extra length on restart',
        tooltip => 'When the retraction is compensated after the travel move, the extruder will push this additional amount of filament. This setting is rarely needed.',
        sidetext => 'mm',
        cli     => 'retract-restart-extra=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [0],
    },
    'retract_before_travel' => {
        label   => 'Minimum travel after retraction',
        tooltip => 'Retraction is not triggered when travel moves are shorter than this length.',
        sidetext => 'mm',
        cli     => 'retract-before-travel=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [2],
    },
    'retract_lift' => {
        label   => 'Lift Z',
        tooltip => 'If you set this to a positive value, Z is quickly raised every time a retraction is triggered.',
        sidetext => 'mm',
        cli     => 'retract-lift=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [0],
    },
    'retract_layer_change' => {
        label   => 'Retract on layer change',
        tooltip => 'This flag enforces a retraction whenever a Z move is done.',
        cli     => 'retract-layer-change!',
        type    => 'bool',
        serialize   => $serialize_comma_bool,
        deserialize => $deserialize_comma,
        default => [1],
    },
    'wipe' => {
        label   => 'Wipe before retract',
        tooltip => 'This flag will move the nozzle while retracting to minimize the possible blob on leaky extruders.',
        cli     => 'wipe!',
        type    => 'bool',
        serialize   => $serialize_comma_bool,
        deserialize => $deserialize_comma,
        default => [0],
    },
    'retract_length_toolchange' => {
        label   => 'Length',
        tooltip => 'When retraction is triggered before changing tool, filament is pulled back by the specified amount (the length is measured on raw filament, before it enters the extruder).',
        sidetext => 'mm (zero to disable)',
        cli     => 'retract-length-toolchange=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [10],
    },
    'retract_restart_extra_toolchange' => {
        label   => 'Extra length on restart',
        tooltip => 'When the retraction is compensated after changing tool, the extruder will push this additional amount of filament.',
        sidetext => 'mm',
        cli     => 'retract-restart-extra-toolchange=f@',
        type    => 'f',
        serialize   => $serialize_comma,
        deserialize => $deserialize_comma,
        default => [0],
    },
    
    # cooling options
    'cooling' => {
        label   => 'Enable auto cooling',
        tooltip => 'This flag enables the automatic cooling logic that adjusts print speed and fan speed according to layer printing time.',
        cli     => 'cooling!',
        type    => 'bool',
        default => 1,
    },
    'min_fan_speed' => {
        label   => 'Min',
        tooltip => 'This setting represents the minimum PWM your fan needs to work.',
        sidetext => '%',
        cli     => 'min-fan-speed=i',
        type    => 'i',
        max     => 100,
        default => 35,
    },
    'max_fan_speed' => {
        label   => 'Max',
        tooltip => 'This setting represents the maximum speed of your fan.',
        sidetext => '%',
        cli     => 'max-fan-speed=i',
        type    => 'i',
        max     => 100,
        default => 100,
    },
    'bridge_fan_speed' => {
        label   => 'Bridges fan speed',
        tooltip => 'This fan speed is enforced during all bridges and overhangs.',
        sidetext => '%',
        cli     => 'bridge-fan-speed=i',
        type    => 'i',
        max     => 100,
        default => 100,
    },
    'fan_below_layer_time' => {
        label   => 'Enable fan if layer print time is below',
        tooltip => 'If layer print time is estimated below this number of seconds, fan will be enabled and its speed will be calculated by interpolating the minimum and maximum speeds.',
        sidetext => 'approximate seconds',
        cli     => 'fan-below-layer-time=i',
        type    => 'i',
        max     => 1000,
        width   => 60,
        default => 60,
    },
    'slowdown_below_layer_time' => {
        label   => 'Slow down if layer print time is below',
        tooltip => 'If layer print time is estimated below this number of seconds, print moves speed will be scaled down to extend duration to this value.',
        sidetext => 'approximate seconds',
        cli     => 'slowdown-below-layer-time=i',
        type    => 'i',
        max     => 1000,
        width   => 60,
        default => 30,
    },
    'min_print_speed' => {
        label   => 'Min print speed',
        tooltip => 'Slic3r will not scale speed down below this speed.',
        sidetext => 'mm/s',
        cli     => 'min-print-speed=f',
        type    => 'i',
        max     => 1000,
        default => 10,
    },
    'disable_fan_first_layers' => {
        label   => 'Disable fan for the first',
        tooltip => 'You can set this to a positive value to disable fan at all during the first layers, so that it does not make adhesion worse.',
        sidetext => 'layers',
        cli     => 'disable-fan-first-layers=i',
        type    => 'i',
        max     => 1000,
        default => 1,
    },
    'fan_always_on' => {
        label   => 'Keep fan always on',
        tooltip => 'If this is enabled, fan will never be disabled and will be kept running at least at its minimum speed. Useful for PLA, harmful for ABS.',
        cli     => 'fan-always-on!',
        type    => 'bool',
        default => 0,
    },
    
    # skirt/brim options
    'skirts' => {
        label   => 'Loops',
        tooltip => 'Number of loops for this skirt, in other words its thickness. Set this to zero to disable skirt.',
        cli     => 'skirts=i',
        type    => 'i',
        default => 1,
    },
    'min_skirt_length' => {
        label   => 'Minimum extrusion length',
        tooltip => 'Generate no less than the number of skirt loops required to consume the specified amount of filament on the bottom layer. For multi-extruder machines, this minimum applies to each extruder.',
        sidetext => 'mm',
        cli     => 'min-skirt-length=f',
        type    => 'f',
        default => 0,
        min     => 0,
    },
    'skirt_distance' => {
        label   => 'Distance from object',
        tooltip => 'Distance between skirt and object(s). Set this to zero to attach the skirt to the object(s) and get a brim for better adhesion.',
        sidetext => 'mm',
        cli     => 'skirt-distance=f',
        type    => 'f',
        default => 6,
    },
    'skirt_height' => {
        label   => 'Skirt height',
        tooltip => 'Height of skirt expressed in layers. Set this to a tall value to use skirt as a shield against drafts.',
        sidetext => 'layers',
        cli     => 'skirt-height=i',
        type    => 'i',
        default => 1,
    },
    'brim_width' => {
        label   => 'Brim width',
        tooltip => 'Horizontal width of the brim that will be printed around each object on the first layer.',
        sidetext => 'mm',
        cli     => 'brim-width=f',
        type    => 'f',
        default => 0,
    },
    
    # transform options
    'scale' => {
        label   => 'Scale',
        cli     => 'scale=f',
        type    => 'f',
        default => 1,
    },
    'rotate' => {
        label   => 'Rotate',
        sidetext => '°',
        cli     => 'rotate=i',
        type    => 'i',
        max     => 359,
        default => 0,
    },
    'duplicate' => {
        label   => 'Copies (autoarrange)',
        cli     => 'duplicate=i',
        type    => 'i',
        min     => 1,
        default => 1,
    },
    'bed_size' => {
        label   => 'Bed size',
        tooltip => 'Size of your bed. This is used to adjust the preview in the plater and for auto-arranging parts in it.',
        sidetext => 'mm',
        cli     => 'bed-size=s',
        type    => 'point',
        serialize   => $serialize_comma,
        deserialize => sub { [ split /[,x]/, $_[0] ] },
        default => [200,200],
    },
    'duplicate_grid' => {
        label   => 'Copies (grid)',
        cli     => 'duplicate-grid=s',
        type    => 'point',
        serialize   => $serialize_comma,
        deserialize => sub { [ split /[,x]/, $_[0] ] },
        default => [1,1],
    },
    'duplicate_distance' => {
        label   => 'Distance between copies',
        tooltip => 'Distance used for the auto-arrange feature of the plater.',
        sidetext => 'mm',
        cli     => 'duplicate-distance=f',
        type    => 'f',
        aliases => [qw(multiply_distance)],
        default => 6,
    },
    
    # sequential printing options
    'complete_objects' => {
        label   => 'Complete individual objects',
        tooltip => 'When printing multiple objects or copies, this feature will complete each object before moving onto next one (and starting it from its bottom layer). This feature is useful to avoid the risk of ruined prints. Slic3r should warn and prevent you from extruder collisions, but beware.',
        cli     => 'complete-objects!',
        type    => 'bool',
        default => 0,
    },
    'extruder_clearance_radius' => {
        label   => 'Radius',
        tooltip => 'Set this to the clearance radius around your extruder. If the extruder is not centered, choose the largest value for safety. This setting is used to check for collisions and to display the graphical preview in the plater.',
        sidetext => 'mm',
        cli     => 'extruder-clearance-radius=f',
        type    => 'f',
        default => 20,
    },
    'extruder_clearance_height' => {
        label   => 'Height',
        tooltip => 'Set this to the vertical distance between your nozzle tip and (usually) the X carriage rods. In other words, this is the height of the clearance cylinder around your extruder, and it represents the maximum depth the extruder can peek before colliding with other printed objects.',
        sidetext => 'mm',
        cli     => 'extruder-clearance-height=f',
        type    => 'f',
        default => 20,
    },
};

# generate accessors
if (eval "use Class::XSAccessor; 1") {
    Class::XSAccessor->import(
        getters => { map { $_ => $_ } keys %$Options },
    );
} else {
    no strict 'refs';
    for my $opt_key (keys %$Options) {
        *{$opt_key} = sub { $_[0]{$opt_key} };
    }
}

sub new {
    my $class = shift;
    my %args = @_;
    
    my $self = bless {}, $class;
    $self->apply(%args);
    return $self;
}

sub new_from_defaults {
    my $class = shift;
    my @opt_keys = 
    return $class->new(
        map { $_ => $Options->{$_}{default} }
            grep !$Options->{$_}{shortcut},
            (@_ ? @_ : keys %$Options)
    );
}

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;
            }
        }
    }
    
    $args{$_} = $Options->{$_}{deserialize}->($args{$_})
        for grep exists $args{$_}, qw(print_center bed_size duplicate_grid extruder_offset retract_layer_change wipe);
    
    return $class->new(%args);
}

sub merge {
    my $class = shift;
    my $config = $class->new;
    $config->apply($_) for @_;
    return $config;
}

sub load {
    my $class = shift;
    my ($file) = @_;
    
    my $ini = __PACKAGE__->read_ini($file);
    my $config = __PACKAGE__->new;
    $config->set($_, $ini->{_}{$_}, 1) for keys %{$ini->{_}};
    return $config;
}

sub apply {
    my $self = shift;
    my %args = @_ == 1 ? %{$_[0]} : @_; # accept a single Config object too
    
    $self->set($_, $args{$_}) for keys %args;
}

sub clone {
    my $self = shift;
    my $new = __PACKAGE__->new(%$self);
    $new->{$_} = [@{$new->{$_}}] for grep { ref $new->{$_} eq 'ARRAY' } keys %$new;
    return $new;
}

sub get_value {
    my $self = shift;
    my ($opt_key) = @_;
    
    no strict 'refs';
    my $value = $self->get($opt_key);
    $value = $self->get_value($Options->{$opt_key}{ratio_over}) * $1/100
        if $Options->{$opt_key}{ratio_over} && $value =~ /^(\d+(?:\.\d+)?)%$/;
    return $value;
}

sub get {
    my $self = shift;
    my ($opt_key) = @_;
    
    return $self->{$opt_key};
}

sub set {
    my $self = shift;
    my ($opt_key, $value, $deserialize) = @_;
    
    # handle legacy options
    return if first { $_ eq $opt_key } @Ignore;
    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;
    }
    if ($opt_key eq 'threads' && !$Slic3r::have_threads) {
        $value = 1;
    }
    if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') {
        $value = 'makerware';
    }
    
    # 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;
    }
    
    if (!exists $Options->{$opt_key}) {
        my @keys = grep { $Options->{$_}{aliases} && grep $_ eq $opt_key, @{$Options->{$_}{aliases}} } keys %$Options;
        if (!@keys) {
            warn "Unknown option $opt_key\n";
            return;
        }
        $opt_key = $keys[0];
    }
    
    # clone arrayrefs
    $value = [@$value] if ref $value eq 'ARRAY';
    
    # deserialize if requested
    $value = $Options->{$opt_key}{deserialize}->($value)
        if $deserialize && $Options->{$opt_key}{deserialize};
    
    $self->{$opt_key} = $value;
    
    if ($Options->{$opt_key}{shortcut}) {
        $self->set($_, $value, $deserialize) for @{$Options->{$opt_key}{shortcut}};
    }
}

sub set_ifndef {
    my $self = shift;
    my ($opt_key, $value, $deserialize) = @_;
    
    $self->set($opt_key, $value, $deserialize)
        if !defined $self->get($opt_key);
}

sub has {
    my $self = shift;
    my ($opt_key) = @_;
    return exists $self->{$opt_key};
}

sub serialize {
    my $self = shift;
    my ($opt_key) = @_;
    
    my $value = $self->get($opt_key);
    $value = $Options->{$opt_key}{serialize}->($value) if $Options->{$opt_key}{serialize};
    return $value;
}

sub save {
    my $self = shift;
    my ($file) = @_;
    
    my $ini = { _ => {} };
    foreach my $opt_key (sort keys %$self) {
        next if $Options->{$opt_key}{shortcut};
        next if $Options->{$opt_key}{gui_only};
        $ini->{_}{$opt_key} = $self->serialize($opt_key);
    }
    __PACKAGE__->write_ini($file, $ini);
}

sub setenv {
    my $self = shift;
    
    foreach my $opt_key (sort keys %$Options) {
        next if $Options->{$opt_key}{gui_only};
        $ENV{"SLIC3R_" . uc $opt_key} = $self->serialize($opt_key);
    }
}

# this method is idempotent by design
sub validate {
    my $self = shift;
    
    # -j, --threads
    die "Invalid value for --threads\n"
        if $self->threads < 1;
    die "Your perl wasn't built with multithread support\n"
        if $self->threads > 1 && !$Slic3r::have_threads;

    # --layer-height
    die "Invalid value for --layer-height\n"
        if $self->layer_height <= 0;
    die "--layer-height must be a multiple of print resolution\n"
        if $self->layer_height / &Slic3r::SCALING_FACTOR % 1 != 0;
    
    # --first-layer-height
    die "Invalid value for --first-layer-height\n"
        if $self->first_layer_height !~ /^(?:\d*(?:\.\d+)?)%?$/;
    
    # --filament-diameter
    die "Invalid value for --filament-diameter\n"
        if grep $_ < 1, @{$self->filament_diameter};
    
    # --nozzle-diameter
    die "Invalid value for --nozzle-diameter\n"
        if grep $_ < 0, @{$self->nozzle_diameter};
    die "--layer-height can't be greater than --nozzle-diameter\n"
        if grep $self->layer_height > $_, @{$self->nozzle_diameter};
    die "First layer height can't be greater than --nozzle-diameter\n"
        if grep $self->get_value('first_layer_height') > $_, @{$self->nozzle_diameter};
    
    # --perimeters
    die "Invalid value for --perimeters\n"
        if $self->perimeters < 0;
    
    # --solid-layers
    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;
    
    # --gcode-flavor
    die "Invalid value for --gcode-flavor\n"
        if !first { $_ eq $self->gcode_flavor } @{$Options->{gcode_flavor}{values}};
    
    # --print-center
    die "Invalid value for --print-center\n"
        if !ref $self->print_center 
            && (!$self->print_center || $self->print_center !~ /^\d+,\d+$/);
    
    # --fill-pattern
    die "Invalid value for --fill-pattern\n"
        if !first { $_ eq $self->fill_pattern } @{$Options->{fill_pattern}{values}};
    
    # --solid-fill-pattern
    die "Invalid value for --solid-fill-pattern\n"
        if !first { $_ eq $self->solid_fill_pattern } @{$Options->{solid_fill_pattern}{values}};
    
    # --fill-density
    die "Invalid value for --fill-density\n"
        if $self->fill_density < 0 || $self->fill_density > 1;
    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}};
    
    # --infill-every-layers
    die "Invalid value for --infill-every-layers\n"
        if $self->infill_every_layers !~ /^\d+$/ || $self->infill_every_layers < 1;
    
    # --scale
    die "Invalid value for --scale\n"
        if $self->scale <= 0;
    
    # --bed-size
    die "Invalid value for --bed-size\n"
        if !ref $self->bed_size 
            && (!$self->bed_size || $self->bed_size !~ /^\d+,\d+$/);
    
    # --duplicate-grid
    die "Invalid value for --duplicate-grid\n"
        if !ref $self->duplicate_grid 
            && (!$self->duplicate_grid || $self->duplicate_grid !~ /^\d+,\d+$/);
    
    # --duplicate
    die "Invalid value for --duplicate or --duplicate-grid\n"
        if !$self->duplicate || $self->duplicate < 1 || !$self->duplicate_grid
            || (grep !$_, @{$self->duplicate_grid});
    die "Use either --duplicate or --duplicate-grid (using both doesn't make sense)\n"
        if $self->duplicate > 1 && $self->duplicate_grid && (grep $_ && $_ > 1, @{$self->duplicate_grid});
    
    # --skirt-height
    die "Invalid value for --skirt-height\n"
        if $self->skirt_height < 0;
    
    # --bridge-flow-ratio
    die "Invalid value for --bridge-flow-ratio\n"
        if $self->bridge_flow_ratio <= 0;
    
    # extruder clearance
    die "Invalid value for --extruder-clearance-radius\n"
        if $self->extruder_clearance_radius <= 0;
    die "Invalid value for --extruder-clearance-height\n"
        if $self->extruder_clearance_height <= 0;
    
    # --extrusion-multiplier
    die "Invalid value for --extrusion-multiplier\n"
        if defined first { $_ <= 0 } @{$self->extrusion_multiplier};
    
    # general validation, quick and dirty
    foreach my $opt_key (keys %$Options) {
        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"
                    if ($type eq 'i' && $value !~ /^-?\d+$/)
                    || ($type eq 'f' && $value !~ /^-?(?:\d+|\d*\.\d+)$/)
                    || (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} };
            }
        }
    }
}

sub replace_options {
    my $self = shift;
    my ($string, $more_variables) = @_;
    
    $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;
    }
    
    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;
    
    # build a regexp to match the available options
    my @options = grep !$Slic3r::Config::Options->{$_}{multiline},
        grep $self->has($_),
        keys %{$Slic3r::Config::Options};
    my $options_regex = join '|', @options;
    
    # use that regexp to search and replace option names with option values
    $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;
        }
    }
    return $string;
}

# 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;
}

# CLASS METHODS:

sub write_ini {
    my $class = shift;
    my ($file, $ini) = @_;
    
    Slic3r::open(\my $fh, '>', $file);
    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";
    Slic3r::open(\my $fh, '<', $file);
    binmode $fh, ':utf8';
    
    my $ini = { _ => {} };
    my $category = '_';
    while (<$fh>) {
        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;
}

1;