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

ToolCalculatorControl.axaml.cs « Tools « Controls « UVtools.WPF - github.com/sn4k3/UVtools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56827471191da74506a2e3be68672abfd84a72be (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
using System;
using Avalonia.Markup.Xaml;
using UVtools.Core.FileFormats;
using UVtools.Core.Operations;
using UVtools.WPF.Windows;

namespace UVtools.WPF.Controls.Tools
{
    public class ToolCalculatorControl : ToolControl
    {
        private decimal _lightOffDelayPrintTimeHours;
        public OperationCalculator Operation => BaseOperation as OperationCalculator;

        public decimal LightOffDelayPrintTimeHours
        {
            get => _lightOffDelayPrintTimeHours;
            set => RaiseAndSetIfChanged(ref _lightOffDelayPrintTimeHours, value);
        }

        public ToolCalculatorControl()
        {
            BaseOperation = new OperationCalculator(SlicerFile);
            if (!ValidateSpawn()) return; 
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        public override void Callback(ToolWindow.Callbacks callback)
        {
            switch (callback)
            {
                case ToolWindow.Callbacks.Init:
                case ToolWindow.Callbacks.Loaded:
                    Operation.CalcLightOffDelay.PropertyChanged += (sender, e) =>
                    {
                        if (e.PropertyName != nameof(Operation.CalcLightOffDelay.LightOffDelay) &&
                            e.PropertyName != nameof(Operation.CalcLightOffDelay.BottomLightOffDelay)) return;
                        LightOffDelayPrintTimeHours = Math.Round(
                            (FileFormat.ExtraPrintTime +
                             SlicerFile.BottomLayerCount * (Operation.CalcLightOffDelay.BottomLightOffDelay + (decimal)SlicerFile.BottomExposureTime) +
                             SlicerFile.NormalLayerCount * (Operation.CalcLightOffDelay.LightOffDelay + (decimal)SlicerFile.ExposureTime))
                            / 3600, 2);
                    };

                    _lightOffDelayPrintTimeHours = (decimal)SlicerFile.PrintTimeHours;
                    break;
            }
        }

        public void LightOffDelaySetParameters(byte side)
        {
            if (side == 0) // Bottom layers
            {
                SlicerFile.BottomLiftHeight = (float)Operation.CalcLightOffDelay.BottomLiftHeight;
                SlicerFile.BottomLiftSpeed = (float)Operation.CalcLightOffDelay.BottomLiftSpeed;
                SlicerFile.RetractSpeed = (float)Operation.CalcLightOffDelay.RetractSpeed;
                SlicerFile.BottomLightOffDelay = (float)Operation.CalcLightOffDelay.BottomLightOffDelay;
            }
            else // Normal layers
            {
                SlicerFile.LiftHeight = (float)Operation.CalcLightOffDelay.LiftHeight;
                SlicerFile.LiftSpeed = (float)Operation.CalcLightOffDelay.LiftSpeed;
                SlicerFile.RetractSpeed = (float)Operation.CalcLightOffDelay.RetractSpeed;
                SlicerFile.LightOffDelay = (float)Operation.CalcLightOffDelay.LightOffDelay;
            }

            LightOffDelayPrintTimeHours = (decimal)SlicerFile.PrintTimeHours;

            App.MainWindow.CanSave = true;
        }
    }
}