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
|
/*
* GNU AFFERO GENERAL PUBLIC LICENSE
* Version 3, 19 November 2007
* Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Xml.Serialization;
using Avalonia.Media;
using JetBrains.Annotations;
using UVtools.Core;
using UVtools.Core.Objects;
using Color=UVtools.WPF.Structures.Color;
namespace UVtools.WPF
{
[Serializable]
public sealed class UserSettings : BindableBase
{
#region Constants
public const ushort SETTINGS_VERSION = 2;
#endregion
#region Sub classes
#region General
[Serializable]
public sealed class GeneralUserSettings : BindableBase
{
private bool _startMaximized = true;
private bool _checkForUpdatesOnStartup = true;
private bool _loadDemoFileOnStartup = true;
private bool _windowsTakeIntoAccountScreenScaling = true;
private ushort _windowsHorizontalMargin = 200;
private ushort _windowsVerticalMargin = 400;
private byte _defaultOpenFileExtensionIndex;
private string _defaultDirectoryOpenFile;
private string _defaultDirectorySaveFile;
private string _defaultDirectoryExtractFile;
private string _defaultDirectoryConvertFile;
private bool _promptOverwriteFileSave = true;
private string _fileSaveNamePrefix;
private string _fileSaveNameSuffix = "_copy";
private int _maxDegreeOfParallelism;
public bool StartMaximized
{
get => _startMaximized;
set => RaiseAndSetIfChanged(ref _startMaximized, value);
}
public bool CheckForUpdatesOnStartup
{
get => _checkForUpdatesOnStartup;
set => RaiseAndSetIfChanged(ref _checkForUpdatesOnStartup, value);
}
public bool LoadDemoFileOnStartup
{
get => _loadDemoFileOnStartup;
set => RaiseAndSetIfChanged(ref _loadDemoFileOnStartup, value);
}
public bool WindowsTakeIntoAccountScreenScaling
{
get => _windowsTakeIntoAccountScreenScaling;
set => RaiseAndSetIfChanged(ref _windowsTakeIntoAccountScreenScaling, value);
}
public ushort WindowsHorizontalMargin
{
get => _windowsHorizontalMargin;
set => RaiseAndSetIfChanged(ref _windowsHorizontalMargin, value);
}
public ushort WindowsVerticalMargin
{
get => _windowsVerticalMargin;
set => RaiseAndSetIfChanged(ref _windowsVerticalMargin, value);
}
public byte DefaultOpenFileExtensionIndex
{
get => _defaultOpenFileExtensionIndex;
set => RaiseAndSetIfChanged(ref _defaultOpenFileExtensionIndex, value);
}
public string DefaultDirectoryOpenFile
{
get => _defaultDirectoryOpenFile;
set => RaiseAndSetIfChanged(ref _defaultDirectoryOpenFile, value);
}
public string DefaultDirectorySaveFile
{
get => _defaultDirectorySaveFile;
set => RaiseAndSetIfChanged(ref _defaultDirectorySaveFile, value);
}
public string DefaultDirectoryExtractFile
{
get => _defaultDirectoryExtractFile;
set => RaiseAndSetIfChanged(ref _defaultDirectoryExtractFile, value);
}
public string DefaultDirectoryConvertFile
{
get => _defaultDirectoryConvertFile;
set => RaiseAndSetIfChanged(ref _defaultDirectoryConvertFile, value);
}
public bool PromptOverwriteFileSave
{
get => _promptOverwriteFileSave;
set => RaiseAndSetIfChanged(ref _promptOverwriteFileSave, value);
}
public string FileSaveNamePrefix
{
get => _fileSaveNamePrefix;
set => RaiseAndSetIfChanged(ref _fileSaveNamePrefix, value);
}
public string FileSaveNameSuffix
{
get => _fileSaveNameSuffix;
set => RaiseAndSetIfChanged(ref _fileSaveNameSuffix, value);
}
/// <summary>
/// Gets or sets the maximum number of concurrent tasks enabled by a ParallelOptions instance.
/// </summary>
public int MaxDegreeOfParallelism
{
get => _maxDegreeOfParallelism;
set => RaiseAndSetIfChanged(ref _maxDegreeOfParallelism, value);
}
public GeneralUserSettings()
{
MaxDegreeOfParallelism = Environment.ProcessorCount;
}
public GeneralUserSettings Clone()
{
return MemberwiseClone() as GeneralUserSettings;
}
}
#endregion
#region Layer Preview
[Serializable]
public sealed class LayerPreviewUserSettings : BindableBase
{
private Color _tooltipOverlayBackgroundColor = new Color(210, 255, 255, 192);
private bool _tooltipOverlay = true;
private Color _volumeBoundsOutlineColor = new Color(210, 0, 255, 0);
private byte _volumeBoundsOutlineThickness = 3;
private bool _volumeBoundsOutline = true;
private Color _layerBoundsOutlineColor = new Color(210, 0, 255, 0);
private byte _layerBoundsOutlineThickness = 3;
private bool _layerBoundsOutline = false;
private Color _hollowOutlineColor = new Color(210, 255, 165, 0);
private byte _hollowOutlineLineThickness = 3;
private bool _hollowOutline = false;
private Color _previousLayerDifferenceColor = new Color(255, 255, 0, 255);
private Color _nextLayerDifferenceColor = new Color(255, 0, 255, 255);
private Color _bothLayerDifferenceColor = new Color(255, 255, 0, 0);
private bool _showLayerDifference = false;
private Color _islandColor = new Color(255, 255, 255, 0);
private Color _islandHighlightColor = new Color(255, 255, 215, 0);
private Color _overhangColor = new Color(255, 255, 105, 180);
private Color _overhangHighlightColor = new Color(255, 255, 20, 147);
private Color _resinTrapColor = new Color(255, 255, 165, 0);
private Color _resinTrapHighlightColor = new Color(255, 244, 164, 96);
private Color _touchingBoundsColor = new Color(255, 255, 0, 0);
private Color _crosshairColor = new Color(255, 255, 0, 0);
private bool _zoomToFitPrintVolumeBounds = true;
private byte _zoomLockLevelIndex = 7;
private bool _zoomIssues = true;
private bool _crosshairShowOnlyOnSelectedIssues = false;
private byte _crosshairFadeLevelIndex = 5;
private uint _crosshairLength = 20;
private byte _crosshairMargin = 5;
private bool _autoRotateLayerBestView = true;
private bool _layerZoomToFitOnLoad = true;
private bool _showBackgroudGrid;
public Color TooltipOverlayBackgroundColor
{
get => _tooltipOverlayBackgroundColor;
set
{
RaiseAndSetIfChanged(ref _tooltipOverlayBackgroundColor, value);
RaisePropertyChanged(nameof(TooltipOverlayBackgroundBrush));
}
}
[XmlIgnore]
public SolidColorBrush TooltipOverlayBackgroundBrush
{
get => new SolidColorBrush(_tooltipOverlayBackgroundColor.ToAvalonia());
set => TooltipOverlayBackgroundColor = new Color(value);
}
public bool TooltipOverlay
{
get => _tooltipOverlay;
set => RaiseAndSetIfChanged(ref _tooltipOverlay, value);
}
public Color VolumeBoundsOutlineColor
{
get => _volumeBoundsOutlineColor;
set
{
RaiseAndSetIfChanged(ref _volumeBoundsOutlineColor, value);
RaisePropertyChanged(nameof(VolumeBoundsOutlineBrush));
}
}
[XmlIgnore]
public SolidColorBrush VolumeBoundsOutlineBrush
{
get => new SolidColorBrush(_volumeBoundsOutlineColor.ToAvalonia());
set => VolumeBoundsOutlineColor = new Color(value);
}
public byte VolumeBoundsOutlineThickness
{
get => _volumeBoundsOutlineThickness;
set => RaiseAndSetIfChanged(ref _volumeBoundsOutlineThickness, value);
}
public bool VolumeBoundsOutline
{
get => _volumeBoundsOutline;
set => RaiseAndSetIfChanged(ref _volumeBoundsOutline, value);
}
public Color LayerBoundsOutlineColor
{
get => _layerBoundsOutlineColor;
set
{
RaiseAndSetIfChanged(ref _layerBoundsOutlineColor, value);
RaisePropertyChanged(nameof(LayerBoundsOutlineBrush));
}
}
[XmlIgnore]
public SolidColorBrush LayerBoundsOutlineBrush
{
get => new SolidColorBrush(_layerBoundsOutlineColor.ToAvalonia());
set => LayerBoundsOutlineColor = new Color(value);
}
public byte LayerBoundsOutlineThickness
{
get => _layerBoundsOutlineThickness;
set => RaiseAndSetIfChanged(ref _layerBoundsOutlineThickness, value);
}
public bool LayerBoundsOutline
{
get => _layerBoundsOutline;
set => RaiseAndSetIfChanged(ref _layerBoundsOutline, value);
}
public Color HollowOutlineColor
{
get => _hollowOutlineColor;
set
{
RaiseAndSetIfChanged(ref _hollowOutlineColor, value);
RaisePropertyChanged(nameof(HollowOutlineBrush));
}
}
[XmlIgnore]
public SolidColorBrush HollowOutlineBrush
{
get => new SolidColorBrush(_hollowOutlineColor.ToAvalonia());
set => HollowOutlineColor = new Color(value);
}
public byte HollowOutlineLineThickness
{
get => _hollowOutlineLineThickness;
set => RaiseAndSetIfChanged(ref _hollowOutlineLineThickness, value);
}
public bool HollowOutline
{
get => _hollowOutline;
set => RaiseAndSetIfChanged(ref _hollowOutline, value);
}
public Color PreviousLayerDifferenceColor
{
get => _previousLayerDifferenceColor;
set
{
RaiseAndSetIfChanged(ref _previousLayerDifferenceColor, value);
RaisePropertyChanged(nameof(PreviousLayerDifferenceBrush));
}
}
[XmlIgnore]
public SolidColorBrush PreviousLayerDifferenceBrush
{
get => new SolidColorBrush(_previousLayerDifferenceColor.ToAvalonia());
set => PreviousLayerDifferenceColor = new Color(value);
}
public Color NextLayerDifferenceColor
{
get => _nextLayerDifferenceColor;
set
{
RaiseAndSetIfChanged(ref _nextLayerDifferenceColor, value);
RaisePropertyChanged(nameof(NextLayerDifferenceBrush));
}
}
[XmlIgnore]
public SolidColorBrush NextLayerDifferenceBrush
{
get => new SolidColorBrush(_nextLayerDifferenceColor.ToAvalonia());
set => NextLayerDifferenceColor = new Color(value);
}
public Color BothLayerDifferenceColor
{
get => _bothLayerDifferenceColor;
set
{
RaiseAndSetIfChanged(ref _bothLayerDifferenceColor, value);
RaisePropertyChanged(nameof(BothLayerDifferenceBrush));
}
}
[XmlIgnore]
public SolidColorBrush BothLayerDifferenceBrush
{
get => new SolidColorBrush(_bothLayerDifferenceColor.ToAvalonia());
set => BothLayerDifferenceColor = new Color(value);
}
public bool ShowLayerDifference
{
get => _showLayerDifference;
set => RaiseAndSetIfChanged(ref _showLayerDifference, value);
}
public Color IslandColor
{
get => _islandColor;
set
{
RaiseAndSetIfChanged(ref _islandColor, value);
RaisePropertyChanged(nameof(IslandBrush));
}
}
[XmlIgnore]
public SolidColorBrush IslandBrush
{
get => new SolidColorBrush(_islandColor.ToAvalonia());
set => IslandColor = new Color(value);
}
public Color IslandHighlightColor
{
get => _islandHighlightColor;
set
{
RaiseAndSetIfChanged(ref _islandHighlightColor, value);
RaisePropertyChanged(nameof(IslandHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush IslandHighlightBrush
{
get => new SolidColorBrush(_islandHighlightColor.ToAvalonia());
set => IslandHighlightColor = new Color(value);
}
public Color OverhangColor
{
get => _overhangColor;
set
{
RaiseAndSetIfChanged(ref _overhangColor, value);
RaisePropertyChanged(nameof(OverhangBrush));
}
}
[XmlIgnore]
public SolidColorBrush OverhangBrush
{
get => new SolidColorBrush(_overhangColor.ToAvalonia());
set => OverhangColor = new Color(value);
}
public Color OverhangHighlightColor
{
get => _overhangHighlightColor;
set
{
RaiseAndSetIfChanged(ref _overhangHighlightColor, value);
RaisePropertyChanged(nameof(OverhangHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush OverhangHighlightBrush
{
get => new SolidColorBrush(_overhangHighlightColor.ToAvalonia());
set => OverhangHighlightColor = new Color(value);
}
public Color ResinTrapColor
{
get => _resinTrapColor;
set
{
RaiseAndSetIfChanged(ref _resinTrapColor, value);
RaisePropertyChanged(nameof(ResinTrapBrush));
}
}
[XmlIgnore]
public SolidColorBrush ResinTrapBrush
{
get => new SolidColorBrush(_resinTrapColor.ToAvalonia());
set => ResinTrapColor = new Color(value);
}
public Color ResinTrapHighlightColor
{
get => _resinTrapHighlightColor;
set
{
RaiseAndSetIfChanged(ref _resinTrapHighlightColor, value);
RaisePropertyChanged(nameof(ResinTrapHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush ResinTrapHighlightBrush
{
get => new SolidColorBrush(_resinTrapHighlightColor.ToAvalonia());
set => ResinTrapHighlightColor = new Color(value);
}
public Color TouchingBoundsColor
{
get => _touchingBoundsColor;
set
{
RaiseAndSetIfChanged(ref _touchingBoundsColor, value);
RaisePropertyChanged(nameof(TouchingBoundsBrush));
}
}
[XmlIgnore]
public SolidColorBrush TouchingBoundsBrush
{
get => new SolidColorBrush(_touchingBoundsColor.ToAvalonia());
set => TouchingBoundsColor = new Color(value);
}
public Color CrosshairColor
{
get => _crosshairColor;
set
{
RaiseAndSetIfChanged(ref _crosshairColor, value);
RaisePropertyChanged(nameof(CrosshairBrush));
}
}
[XmlIgnore]
public SolidColorBrush CrosshairBrush
{
get => new SolidColorBrush(_crosshairColor.ToAvalonia());
set => CrosshairColor = new Color(value);
}
public bool ZoomToFitPrintVolumeBounds
{
get => _zoomToFitPrintVolumeBounds;
set => RaiseAndSetIfChanged(ref _zoomToFitPrintVolumeBounds, value);
}
public byte ZoomLockLevelIndex
{
get => _zoomLockLevelIndex;
set => RaiseAndSetIfChanged(ref _zoomLockLevelIndex, value);
}
public bool ZoomIssues
{
get => _zoomIssues;
set => RaiseAndSetIfChanged(ref _zoomIssues, value);
}
public bool CrosshairShowOnlyOnSelectedIssues
{
get => _crosshairShowOnlyOnSelectedIssues;
set => RaiseAndSetIfChanged(ref _crosshairShowOnlyOnSelectedIssues, value);
}
public byte CrosshairFadeLevelIndex
{
get => _crosshairFadeLevelIndex;
set => RaiseAndSetIfChanged(ref _crosshairFadeLevelIndex, value);
}
public uint CrosshairLength
{
get => _crosshairLength;
set => RaiseAndSetIfChanged(ref _crosshairLength, value);
}
public byte CrosshairMargin
{
get => _crosshairMargin;
set => RaiseAndSetIfChanged(ref _crosshairMargin, value);
}
public bool AutoRotateLayerBestView
{
get => _autoRotateLayerBestView;
set => RaiseAndSetIfChanged(ref _autoRotateLayerBestView, value);
}
public bool LayerZoomToFitOnLoad
{
get => _layerZoomToFitOnLoad;
set => RaiseAndSetIfChanged(ref _layerZoomToFitOnLoad, value);
}
public bool ShowBackgroudGrid
{
get => _showBackgroudGrid;
set => RaiseAndSetIfChanged(ref _showBackgroudGrid, value);
}
public LayerPreviewUserSettings Clone()
{
return MemberwiseClone() as LayerPreviewUserSettings;
}
}
#endregion
#region Issues
[Serializable]
public sealed class IssuesUserSettings : BindableBase
{
private bool _computeIssuesOnLoad = false;
private bool _computeIssuesOnClickTab = true;
private bool _computeIslands = true;
private bool _computeOverhangs = true;
private bool _computeResinTraps = true;
private bool _computeTouchingBounds = true;
private bool _computeEmptyLayers = true;
private bool _islandEnhancedDetection = true;
private bool _islandAllowDiagonalBonds = false;
private byte _islandBinaryThreshold = 0;
private byte _islandRequiredAreaToProcessCheck = 1;
private byte _islandRequiredPixelBrightnessToProcessCheck = 1;
private byte _islandRequiredPixelsToSupport = 10;
private decimal _islandRequiredPixelsToSupportMultiplier = 0.25m;
private byte _islandRequiredPixelBrightnessToSupport = 150;
private bool _overhangIndependentFromIslands = true;
private byte _overhangErodeIterations = 49;
private byte _resinTrapBinaryThreshold = 127;
private byte _resinTrapRequiredAreaToProcessCheck = 17;
private byte _resinTrapRequiredBlackPixelsToDrain = 10;
private byte _resinTrapMaximumPixelBrightnessToDrain = 30;
private byte _touchingBoundMinimumPixelBrightness = 127;
private byte _touchingBoundMarginLeft = 5;
private byte _touchingBoundMarginTop = 5;
private byte _touchingBoundMarginRight = 5;
private byte _touchingBoundMarginBottom = 5;
private bool _touchingBoundSyncMargins = true;
public bool ComputeIssuesOnLoad
{
get => _computeIssuesOnLoad;
set => RaiseAndSetIfChanged(ref _computeIssuesOnLoad, value);
}
public bool ComputeIssuesOnClickTab
{
get => _computeIssuesOnClickTab;
set => RaiseAndSetIfChanged(ref _computeIssuesOnClickTab, value);
}
public bool ComputeIslands
{
get => _computeIslands;
set => RaiseAndSetIfChanged(ref _computeIslands, value);
}
public bool ComputeOverhangs
{
get => _computeOverhangs;
set => RaiseAndSetIfChanged(ref _computeOverhangs, value);
}
public bool ComputeResinTraps
{
get => _computeResinTraps;
set => RaiseAndSetIfChanged(ref _computeResinTraps, value);
}
public bool ComputeTouchingBounds
{
get => _computeTouchingBounds;
set => RaiseAndSetIfChanged(ref _computeTouchingBounds, value);
}
public bool ComputeEmptyLayers
{
get => _computeEmptyLayers;
set => RaiseAndSetIfChanged(ref _computeEmptyLayers, value);
}
public bool IslandEnhancedDetection
{
get => _islandEnhancedDetection;
set => RaiseAndSetIfChanged(ref _islandEnhancedDetection, value);
}
public bool IslandAllowDiagonalBonds
{
get => _islandAllowDiagonalBonds;
set => RaiseAndSetIfChanged(ref _islandAllowDiagonalBonds, value);
}
public byte IslandBinaryThreshold
{
get => _islandBinaryThreshold;
set => RaiseAndSetIfChanged(ref _islandBinaryThreshold, value);
}
public byte IslandRequiredAreaToProcessCheck
{
get => _islandRequiredAreaToProcessCheck;
set => RaiseAndSetIfChanged(ref _islandRequiredAreaToProcessCheck, value);
}
public decimal IslandRequiredPixelsToSupportMultiplier
{
get => _islandRequiredPixelsToSupportMultiplier;
set => RaiseAndSetIfChanged(ref _islandRequiredPixelsToSupportMultiplier, value);
}
public byte IslandRequiredPixelsToSupport
{
get => _islandRequiredPixelsToSupport;
set => RaiseAndSetIfChanged(ref _islandRequiredPixelsToSupport, value);
}
public byte IslandRequiredPixelBrightnessToProcessCheck
{
get => _islandRequiredPixelBrightnessToProcessCheck;
set => RaiseAndSetIfChanged(ref _islandRequiredPixelBrightnessToProcessCheck, value);
}
public byte IslandRequiredPixelBrightnessToSupport
{
get => _islandRequiredPixelBrightnessToSupport;
set => RaiseAndSetIfChanged(ref _islandRequiredPixelBrightnessToSupport, value);
}
public bool OverhangIndependentFromIslands
{
get => _overhangIndependentFromIslands;
set => RaiseAndSetIfChanged(ref _overhangIndependentFromIslands, value);
}
public byte OverhangErodeIterations
{
get => _overhangErodeIterations;
set => RaiseAndSetIfChanged(ref _overhangErodeIterations, value);
}
public byte ResinTrapBinaryThreshold
{
get => _resinTrapBinaryThreshold;
set => RaiseAndSetIfChanged(ref _resinTrapBinaryThreshold, value);
}
public byte ResinTrapRequiredAreaToProcessCheck
{
get => _resinTrapRequiredAreaToProcessCheck;
set => RaiseAndSetIfChanged(ref _resinTrapRequiredAreaToProcessCheck, value);
}
public byte ResinTrapRequiredBlackPixelsToDrain
{
get => _resinTrapRequiredBlackPixelsToDrain;
set => RaiseAndSetIfChanged(ref _resinTrapRequiredBlackPixelsToDrain, value);
}
public byte ResinTrapMaximumPixelBrightnessToDrain
{
get => _resinTrapMaximumPixelBrightnessToDrain;
set => RaiseAndSetIfChanged(ref _resinTrapMaximumPixelBrightnessToDrain, value);
}
public byte TouchingBoundMinimumPixelBrightness
{
get => _touchingBoundMinimumPixelBrightness;
set => RaiseAndSetIfChanged(ref _touchingBoundMinimumPixelBrightness, value);
}
public byte TouchingBoundMarginLeft
{
get => _touchingBoundMarginLeft;
set
{
if(!RaiseAndSetIfChanged(ref _touchingBoundMarginLeft, value)) return;
if (_touchingBoundSyncMargins)
{
TouchingBoundMarginRight = value;
}
}
}
public byte TouchingBoundMarginTop
{
get => _touchingBoundMarginTop;
set
{
if (!RaiseAndSetIfChanged(ref _touchingBoundMarginTop, value)) return;
if (_touchingBoundSyncMargins)
{
TouchingBoundMarginBottom = value;
}
}
}
public byte TouchingBoundMarginRight
{
get => _touchingBoundMarginRight;
set
{
if(!RaiseAndSetIfChanged(ref _touchingBoundMarginRight, value)) return;
if (_touchingBoundSyncMargins)
{
TouchingBoundMarginLeft = value;
}
}
}
public byte TouchingBoundMarginBottom
{
get => _touchingBoundMarginBottom;
set
{
if(!RaiseAndSetIfChanged(ref _touchingBoundMarginBottom, value)) return;
if (_touchingBoundSyncMargins)
{
TouchingBoundMarginTop = value;
}
}
}
public bool TouchingBoundSyncMargins
{
get => _touchingBoundSyncMargins;
set => RaiseAndSetIfChanged(ref _touchingBoundSyncMargins, value);
}
public IssuesUserSettings Clone()
{
return MemberwiseClone() as IssuesUserSettings;
}
}
#endregion
#region Pixel Editor
[Serializable]
public sealed class PixelEditorUserSettings : BindableBase
{
private Color _addPixelColor = new Color(255, 144, 238, 144);
private Color _addPixelHighlightColor = new Color(255, 0, 255, 0);
private Color _removePixelColor = new Color(255, 219, 112, 147);
private Color _removePixelHighlightColor = new Color(255, 139, 0, 0);
private Color _supportsColor = new Color(255, 0, 255, 255);
private Color _supportsHighlightColor = new Color(255, 0, 139, 139);
private Color _drainHoleColor = new Color(255, 142, 69, 133);
private Color _drainHoleHighlightColor = new Color(255, 159, 0, 197);
private Color _cursorColor = new Color(150, 52, 152, 219);
private bool _partialUpdateIslandsOnEditing = true;
private bool _closeEditorOnApply;
public Color AddPixelColor
{
get => _addPixelColor;
set
{
RaiseAndSetIfChanged(ref _addPixelColor, value);
RaisePropertyChanged(nameof(AddPixelBrush));
}
}
[XmlIgnore]
public SolidColorBrush AddPixelBrush
{
get => new SolidColorBrush(_addPixelColor.ToAvalonia());
set => AddPixelColor = new Color(value);
}
public Color AddPixelHighlightColor
{
get => _addPixelHighlightColor;
set
{
RaiseAndSetIfChanged(ref _addPixelHighlightColor, value);
RaisePropertyChanged(nameof(AddPixelHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush AddPixelHighlightBrush
{
get => new SolidColorBrush(_addPixelHighlightColor.ToAvalonia());
set => AddPixelHighlightColor = new Color(value);
}
public Color RemovePixelColor
{
get => _removePixelColor;
set
{
RaiseAndSetIfChanged(ref _removePixelColor, value);
RaisePropertyChanged(nameof(RemovePixelBrush));
}
}
[XmlIgnore]
public SolidColorBrush RemovePixelBrush
{
get => new SolidColorBrush(_removePixelColor.ToAvalonia());
set => RemovePixelColor = new Color(value);
}
public Color RemovePixelHighlightColor
{
get => _removePixelHighlightColor;
set
{
RaiseAndSetIfChanged(ref _removePixelHighlightColor, value);
RaisePropertyChanged(nameof(RemovePixelHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush RemovePixelHighlightBrush
{
get => new SolidColorBrush(_removePixelHighlightColor.ToAvalonia());
set => RemovePixelHighlightColor = new Color(value);
}
public Color SupportsColor
{
get => _supportsColor;
set
{
RaiseAndSetIfChanged(ref _supportsColor, value);
RaisePropertyChanged(nameof(SupportsBrush));
}
}
[XmlIgnore]
public SolidColorBrush SupportsBrush
{
get => new SolidColorBrush(_supportsColor.ToAvalonia());
set => SupportsColor = new Color(value);
}
public Color SupportsHighlightColor
{
get => _supportsHighlightColor;
set
{
RaiseAndSetIfChanged(ref _supportsHighlightColor, value);
RaisePropertyChanged(nameof(SupportsHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush SupportsHighlightBrush
{
get => new SolidColorBrush(_supportsHighlightColor.ToAvalonia());
set => SupportsHighlightColor = new Color(value);
}
public Color DrainHoleColor
{
get => _drainHoleColor;
set
{
RaiseAndSetIfChanged(ref _drainHoleColor, value);
RaisePropertyChanged(nameof(DrainHoleBrush));
}
}
[XmlIgnore]
public SolidColorBrush DrainHoleBrush
{
get => new SolidColorBrush(_drainHoleColor.ToAvalonia());
set => DrainHoleColor = new Color(value);
}
public Color DrainHoleHighlightColor
{
get => _drainHoleHighlightColor;
set
{
RaiseAndSetIfChanged(ref _drainHoleHighlightColor, value);
RaisePropertyChanged(nameof(DrainHoleHighlightBrush));
}
}
[XmlIgnore]
public SolidColorBrush DrainHoleHighlightBrush
{
get => new SolidColorBrush(_drainHoleHighlightColor.ToAvalonia());
set => DrainHoleHighlightColor = new Color(value);
}
public Color CursorColor
{
get => _cursorColor;
set
{
RaiseAndSetIfChanged(ref _cursorColor, value);
RaisePropertyChanged(nameof(CursorBrush));
}
}
[XmlIgnore]
public SolidColorBrush CursorBrush
{
get => new SolidColorBrush(_cursorColor.ToAvalonia());
set => CursorColor = new Color(value);
}
public bool PartialUpdateIslandsOnEditing
{
get => _partialUpdateIslandsOnEditing;
set => RaiseAndSetIfChanged(ref _partialUpdateIslandsOnEditing, value);
}
public bool CloseEditorOnApply
{
get => _closeEditorOnApply;
set => RaiseAndSetIfChanged(ref _closeEditorOnApply, value);
}
public PixelEditorUserSettings Clone()
{
return MemberwiseClone() as PixelEditorUserSettings;
}
}
#endregion
#region Layer Repair
[Serializable]
public sealed class LayerRepairUserSettings : BindableBase
{
private bool _repairIslands = true;
private bool _repairResinTraps = true;
private bool _removeEmptyLayers = true;
private ushort _removeIslandsBelowEqualPixels = 5;
private ushort _removeIslandsRecursiveIterations = 4;
private byte _closingIterations = 2;
private byte _openingIterations = 0;
public bool RepairIslands
{
get => _repairIslands;
set => RaiseAndSetIfChanged(ref _repairIslands, value);
}
public bool RepairResinTraps
{
get => _repairResinTraps;
set => RaiseAndSetIfChanged(ref _repairResinTraps, value);
}
public bool RemoveEmptyLayers
{
get => _removeEmptyLayers;
set => RaiseAndSetIfChanged(ref _removeEmptyLayers, value);
}
public ushort RemoveIslandsBelowEqualPixels
{
get => _removeIslandsBelowEqualPixels;
set => RaiseAndSetIfChanged(ref _removeIslandsBelowEqualPixels, value);
}
public ushort RemoveIslandsRecursiveIterations
{
get => _removeIslandsRecursiveIterations;
set => RaiseAndSetIfChanged(ref _removeIslandsRecursiveIterations, value);
}
public byte ClosingIterations
{
get => _closingIterations;
set => RaiseAndSetIfChanged(ref _closingIterations, value);
}
public byte OpeningIterations
{
get => _openingIterations;
set => RaiseAndSetIfChanged(ref _openingIterations, value);
}
public LayerRepairUserSettings Clone()
{
return MemberwiseClone() as LayerRepairUserSettings;
}
}
#endregion
#region Automations
[Serializable]
public sealed class AutomationsUserSettings : BindableBase
{
private bool _saveFileAfterModifications = true;
private bool _autoConvertSl1Files = true;
private bool _changeOnlyLightOffDelayIfZero = true;
private decimal _lightOffDelay = 2.5m;
private decimal _bottomLightOffDelay = 3m;
public bool SaveFileAfterModifications
{
get => _saveFileAfterModifications;
set => RaiseAndSetIfChanged(ref _saveFileAfterModifications, value);
}
public bool AutoConvertSL1Files
{
get => _autoConvertSl1Files;
set => RaiseAndSetIfChanged(ref _autoConvertSl1Files, value);
}
public bool ChangeOnlyLightOffDelayIfZero
{
get => _changeOnlyLightOffDelayIfZero;
set => RaiseAndSetIfChanged(ref _changeOnlyLightOffDelayIfZero, value);
}
public decimal LightOffDelay
{
get => _lightOffDelay;
set => RaiseAndSetIfChanged(ref _lightOffDelay, value);
}
public decimal BottomLightOffDelay
{
get => _bottomLightOffDelay;
set => RaiseAndSetIfChanged(ref _bottomLightOffDelay, value);
}
}
#endregion
#endregion
#region Singleton
public static string SettingsFolder
{
get
{
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), About.Software);
try
{
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return path;
}
}
/// <summary>
/// Default filepath for store <see cref="UserSettings"/>
/// </summary>
private static string FilePath => Path.Combine(SettingsFolder, "usersettings.xml");
private static UserSettings _instance;
/// <summary>
/// Instance of <see cref="UserSettings"/> (singleton)
/// </summary>
public static UserSettings Instance
{
get => _instance ??= new UserSettings();
internal set => _instance = value;
}
#endregion
#region Properties
private GeneralUserSettings _general;
private LayerPreviewUserSettings _layerPreview;
private IssuesUserSettings _issues;
private PixelEditorUserSettings _pixelEditor;
private LayerRepairUserSettings _layerRepair;
private AutomationsUserSettings _automations;
private ushort _settingsVersion = SETTINGS_VERSION;
private string _appVersion;
private uint _savesCount;
private DateTime _modifiedDateTime;
public GeneralUserSettings General
{
get => _general ??= new GeneralUserSettings();
set => _general = value;
}
public LayerPreviewUserSettings LayerPreview
{
get => _layerPreview ??= new LayerPreviewUserSettings();
set => _layerPreview = value;
}
public IssuesUserSettings Issues
{
get => _issues ??= new IssuesUserSettings();
set => _issues = value;
}
public PixelEditorUserSettings PixelEditor
{
get => _pixelEditor ??= new PixelEditorUserSettings();
set => _pixelEditor = value;
}
public LayerRepairUserSettings LayerRepair
{
get => _layerRepair ??= new LayerRepairUserSettings();
set => _layerRepair = value;
}
public AutomationsUserSettings Automations
{
get => _automations ??= new AutomationsUserSettings();
set => _automations = value;
}
/*
/// <summary>
/// Gets or sets the number of times this file has been reset to defaults
/// </summary>
public uint ResetCount { get; set; }
*/
public ushort SettingsVersion
{
get => _settingsVersion;
set => RaiseAndSetIfChanged(ref _settingsVersion, value);
}
/// <summary>
/// Gets or sets the last running version of UVtools with these settings
/// </summary>
[NotNull]
public string AppVersion
{
get => _appVersion ??= App.Version.ToString();
set => RaiseAndSetIfChanged(ref _appVersion, value);
}
/// <summary>
/// Gets or sets the number of times this file has been saved
/// </summary>
public uint SavesCount
{
get => _savesCount;
set => RaiseAndSetIfChanged(ref _savesCount, value);
}
/// <summary>
/// Gets or sets the last time this file has been modified
/// </summary>
public DateTime ModifiedDateTime
{
get => _modifiedDateTime;
set => RaiseAndSetIfChanged(ref _modifiedDateTime, value);
}
#endregion
#region Constructor
private UserSettings()
{ }
#endregion
#region Static Methods
/// <summary>
/// Reset settings to defaults
/// </summary>
/// <param name="save">True to save settings on file, otherwise false</param>
public static void Reset(bool save = false)
{
_instance = new UserSettings();
if (save) Save();
}
/// <summary>
/// Load settings from file
/// </summary>
public static void Load()
{
if (!File.Exists(FilePath))
{
return;
}
var serializer = new XmlSerializer(typeof(UserSettings));
try
{
using var myXmlReader = new StreamReader(FilePath);
_instance = (UserSettings)serializer.Deserialize(myXmlReader);
if (_instance.General.MaxDegreeOfParallelism <= 0)
_instance.General.MaxDegreeOfParallelism = Environment.ProcessorCount;
if (_instance.SettingsVersion < SETTINGS_VERSION)
{
// Upgrade
_instance.SettingsVersion = SETTINGS_VERSION;
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Reset();
}
}
/// <summary>
/// Save settings to file
/// </summary>
public static void Save()
{
Instance.SavesCount++;
_instance.ModifiedDateTime = DateTime.Now;
var serializer = new XmlSerializer(_instance.GetType());
try
{
using var myXmlWriter = new StreamWriter(FilePath);
serializer.Serialize(myXmlWriter, _instance);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
public static void SetVersion()
{
Instance.AppVersion = App.Version.ToString();
}
public static object[] PackObjects =>
new object[]
{
Instance.General,
Instance.LayerPreview,
Instance.Issues,
Instance.PixelEditor,
Instance.LayerRepair
};
#endregion
#region Methods
public UserSettings Clone()
{
var clone = MemberwiseClone() as UserSettings;
clone.General = clone.General.Clone();
clone.LayerPreview = clone.LayerPreview.Clone();
clone.Issues = clone.Issues.Clone();
clone.PixelEditor = clone.PixelEditor.Clone();
clone.LayerRepair = clone.LayerRepair.Clone();
return clone;
}
#endregion
}
}
|