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

CalibrateToleranceControl.axaml.cs « Calibrators « Controls « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b37ce709e48a8163fa3954b746cefa47fd401d77 (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
using System.Timers;
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 CalibrateToleranceControl : ToolControl
    {
        public OperationCalibrateTolerance Operation => BaseOperation as OperationCalibrateTolerance;

        private Timer _timer;

        /*public string ProfileName
        {
            get => _profileName;
            set => RaiseAndSetIfChanged(ref _profileName, value);
        }*/

        //public bool IsProfileAddEnabled => Operation.ScaleXFactor != 100 || Operation.ScaleYFactor != 100;

        private Bitmap _previewImage;
        /*private string _profileName;
        private bool _isProfileNameEnabled;*/

        public Bitmap PreviewImage
        {
            get => _previewImage;
            set => RaiseAndSetIfChanged(ref _previewImage, value);
        }

        public bool IsDisplaySizeVisible => App.SlicerFile.DisplayWidth <= 0 && App.SlicerFile.DisplayHeight <= 0;

        public CalibrateToleranceControl()
        {
            BaseOperation = new OperationCalibrateTolerance(SlicerFile);
            if (!ValidateSpawn()) return;
            InitializeComponent();
            

            _timer = new Timer(100)
            {
                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.Loaded:
                    Operation.PropertyChanged += (sender, e) =>
                    {
                        _timer.Stop();
                        _timer.Start();
                        /*if (e.PropertyName == nameof(Operation.ScaleXFactor) || e.PropertyName == nameof(Operation.ScaleYFactor))
                        {
                            RaisePropertyChanged(nameof(IsProfileAddEnabled));
                            return;
                        }*/
                    };
                    _timer.Stop();
                    _timer.Start();
                    break;
            }
        }

        public void UpdatePreview()
        {
            var layers = Operation.GetLayers();
            _previewImage?.Dispose();
            PreviewImage = layers[^1].ToBitmap();
            foreach (var layer in layers)
            {
                layer.Dispose();
            }
        }

        /*public async void AddProfile()
        {
            OperationResize resize = new OperationResize
            {
                ProfileName = ProfileName,
                X = Operation.ScaleXFactor,
                Y = Operation.ScaleYFactor
            };
            var find = OperationProfiles.FindByName(resize, ProfileName);
            if (find is not null)
            {
                if (await ParentWindow.MessageBoxQuestion(
                    $"A profile with same name and/or values already exists, do you want to overwrite:\n{find}\nwith:\n{resize}\n?") != ButtonResult.Yes) return;

                OperationProfiles.RemoveProfile(resize, false);
            }

            OperationProfiles.AddProfile(resize);
            await ParentWindow.MessageBoxInfo($"The resize profile has been added.\nGo to Tools - Resize and select the saved profile to load it in.\n{resize}");
        }

        public void AutoNameProfile()
        {
            var printerName = string.IsNullOrEmpty(App.SlicerFile.MachineName)
                ? "MyPrinterX"
                : App.SlicerFile.MachineName;
            ProfileName = $"{printerName}, MyResinX, {Operation.Microns}µm, {Operation.BottomExposure}s/{Operation.NormalExposure}s";
        }
        */
    }
}