blob: f854c6586932cb9b31d4cfc8a7e53d5de764e572 (
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
|
using System.Timers;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
using UVtools.Core.Operations;
using UVtools.WPF.Controls.Tools;
using UVtools.WPF.Extensions;
using UVtools.WPF.Windows;
namespace UVtools.WPF.Controls.Calibrators
{
public class CalibrateElephantFootControl : ToolControl
{
public OperationCalibrateElephantFoot Operation => BaseOperation as OperationCalibrateElephantFoot;
private readonly Timer _timer;
private Bitmap _previewImage;
public Bitmap PreviewImage
{
get => _previewImage;
set => RaiseAndSetIfChanged(ref _previewImage, value);
}
private KernelControl _kernelCtrl;
public CalibrateElephantFootControl()
{
this.InitializeComponent();
BaseOperation = new OperationCalibrateElephantFoot();
if(App.SlicerFile is not null)
{
Operation.LayerHeight = (decimal) App.SlicerFile.LayerHeight;
Operation.BottomExposure = (decimal) App.SlicerFile.BottomExposureTime;
Operation.NormalExposure = (decimal) App.SlicerFile.ExposureTime;
}
_kernelCtrl = this.Find<KernelControl>("KernelCtrl");
_timer = new Timer(20)
{
AutoReset = false
};
_timer.Elapsed += (sender, e) => Dispatcher.UIThread.InvokeAsync(UpdatePreview);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public override void Callback(ToolWindow.Callbacks callback)
{
if (App.SlicerFile is null) return;
switch (callback)
{
case ToolWindow.Callbacks.Init:
case ToolWindow.Callbacks.ProfileLoaded:
Operation.Resolution = App.SlicerFile.Resolution;
Operation.PropertyChanged += (sender, e) =>
{
_timer.Stop();
_timer.Start();
if (e.PropertyName == nameof(Operation.ObjectCount))
{
ParentWindow.ButtonOkEnabled = Operation.ObjectCount > 0;
return;
}
};
ParentWindow.ButtonOkEnabled = Operation.ObjectCount > 0;
_timer.Stop();
_timer.Start();
break;
}
}
public override bool UpdateOperation()
{
Operation.ErodeKernel.Matrix = _kernelCtrl.GetMatrix();
Operation.ErodeKernel.Anchor = _kernelCtrl.Anchor;
return !(Operation.ErodeKernel.Matrix is null);
}
public void UpdatePreview()
{
var layers = Operation.GetLayers();
_previewImage?.Dispose();
PreviewImage = layers[0].ToBitmap();
foreach (var layer in layers)
{
layer.Dispose();
}
}
}
}
|