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
|
/*
* 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.Drawing;
using System.Globalization;
using UVtools.Core;
using UVtools.Core.FileFormats;
using UVtools.Core.Operations;
namespace UVtools.GUI.Controls.Tools
{
public partial class CtrlToolCalculator : CtrlToolWindowContent
{
public OperationCalculator Operation { get; }
public CtrlToolCalculator()
{
InitializeComponent();
Operation = new OperationCalculator
{
CalcMillimetersToPixels = new OperationCalculator.MillimetersToPixels(Program.SlicerFile.Resolution, Program.SlicerFile.Display),
CalcLightOffDelay = new OperationCalculator.LightOffDelayC(
(decimal) Program.SlicerFile.LiftHeight, (decimal) Program.SlicerFile.BottomLiftHeight,
(decimal) Program.SlicerFile.LiftSpeed, (decimal) Program.SlicerFile.BottomLiftSpeed,
(decimal) Program.SlicerFile.RetractSpeed, (decimal)Program.SlicerFile.RetractSpeed)
};
SetOperation(Operation);
tpMillimetersToPixels.Tag = Operation.CalcMillimetersToPixels;
tpLightOffDelay.Tag = Operation.CalcMillimetersToPixels;
lbMMtoPixelsDescription.Text = Operation.CalcMillimetersToPixels.Description;
lbMMtoPixelsDescription.Text += $"\n\nFormula: {Operation.CalcMillimetersToPixels.Formula}";
lbMMtoPixelsDescription.MaximumSize = new Size(Width - 20, 0);
lbLightOffDelayDescription.Text = Operation.CalcLightOffDelay.Description;
lbLightOffDelayDescription.Text += $"\n\nFormula: {Operation.CalcLightOffDelay.Formula}";
lbLightOffDelayDescription.MaximumSize = new Size(Width - 20, 0);
nmMMtoPXResolutionX.Value = Program.SlicerFile.ResolutionX;
nmMMtoPXResolutionY.Value = Program.SlicerFile.ResolutionY;
nmMMtoPXDisplayWidth.Value = (decimal) Program.SlicerFile.DisplayWidth;
nmMMtoPXDisplayHeight.Value = (decimal) Program.SlicerFile.DisplayHeight;
nmMMtoPXInputMillimeters.Value = Operation.CalcMillimetersToPixels.Millimeters;
Operation.CalcMillimetersToPixels.PropertyChanged += (sender, e) =>
{
if(e.PropertyName == nameof(Operation.CalcMillimetersToPixels.PixelsX)
|| e.PropertyName == nameof(Operation.CalcMillimetersToPixels.PixelsY))
CalculateMillimetersToPixels();
};
nmLightOffDelayLiftHeight.Value = (decimal) Program.SlicerFile.LiftHeight;
nmLightOffDelayBottomLiftHeight.Value = (decimal) Program.SlicerFile.BottomLiftHeight;
nmLightOffDelayLiftSpeed.Value = (decimal) Program.SlicerFile.LiftSpeed;
nmLightOffDelayBottomLiftSpeed.Value = (decimal) Program.SlicerFile.BottomLiftSpeed;
nmLightOffDelayBottomRetract.Value = nmLightOffDelayRetract.Value = (decimal) Program.SlicerFile.RetractSpeed;
nmLightOffDelayWaitTime.Value = Operation.CalcLightOffDelay.WaitTime;
nmLightOffDelayBottomWaitTime.Value = Operation.CalcLightOffDelay.BottomWaitTime;
lbLightOffDelayCurrentValue.Text = $"Current value: {Program.SlicerFile.LayerOffTime}";
lbLightOffDelayCurrentBottomValue.Text = $"Current value: {Program.SlicerFile.BottomLayerOffTime}";
Operation.CalcLightOffDelay.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(Operation.CalcLightOffDelay.LightOffDelay)
|| e.PropertyName == nameof(Operation.CalcLightOffDelay.BottomLightOffDelay))
CalculateLightOffDelay();
};
CalculateMillimetersToPixels();
CalculateLightOffDelay();
}
private void CalculateMillimetersToPixels()
{
tbMMtoPXResultPixelsPerMillimeterX.Text = Operation.CalcMillimetersToPixels.PixelsPerMillimeterX.ToString(CultureInfo.InvariantCulture);
tbMMtoPXResultPixelsPerMillimeterY.Text = Operation.CalcMillimetersToPixels.PixelsPerMillimeterY.ToString(CultureInfo.InvariantCulture);
tbMMtoPXResultPixelsX.Text = Operation.CalcMillimetersToPixels.PixelsX.ToString(CultureInfo.InvariantCulture);
tbMMtoPXResultPixelsY.Text = Operation.CalcMillimetersToPixels.PixelsY.ToString(CultureInfo.InvariantCulture);
}
private void CalculateLightOffDelay()
{
tbLightOffDelay.Text = Operation.CalcLightOffDelay.LightOffDelay.ToString(CultureInfo.InvariantCulture);
tbLightOffDelayBottom.Text = Operation.CalcLightOffDelay.BottomLightOffDelay.ToString(CultureInfo.InvariantCulture);
}
private void EventValueChanged(object sender, EventArgs e)
{
// Millimeters to pixels
if (ReferenceEquals(sender, nmMMtoPXResolutionX))
{
Operation.CalcMillimetersToPixels.ResolutionX = (uint) nmMMtoPXResolutionX.Value;
return;
}
if (ReferenceEquals(sender, nmMMtoPXResolutionY))
{
Operation.CalcMillimetersToPixels.ResolutionY = (uint)nmMMtoPXResolutionY.Value;
return;
}
if (ReferenceEquals(sender, nmMMtoPXDisplayWidth))
{
Operation.CalcMillimetersToPixels.DisplayWidth = nmMMtoPXDisplayWidth.Value;
return;
}
if (ReferenceEquals(sender, nmMMtoPXDisplayHeight))
{
Operation.CalcMillimetersToPixels.DisplayHeight = nmMMtoPXDisplayHeight.Value;
return;
}
if (ReferenceEquals(sender, nmMMtoPXInputMillimeters))
{
Operation.CalcMillimetersToPixels.Millimeters = nmMMtoPXInputMillimeters.Value;
return;
}
// Light-Off Delay
if (ReferenceEquals(sender, nmLightOffDelayLiftHeight))
{
Operation.CalcLightOffDelay.LiftHeight = nmLightOffDelayLiftHeight.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayBottomLiftHeight))
{
Operation.CalcLightOffDelay.BottomLiftHeight = nmLightOffDelayBottomLiftHeight.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayLiftSpeed))
{
Operation.CalcLightOffDelay.LiftSpeed = nmLightOffDelayLiftSpeed.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayBottomLiftSpeed))
{
Operation.CalcLightOffDelay.BottomLiftSpeed = nmLightOffDelayBottomLiftSpeed.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayRetract))
{
nmLightOffDelayBottomRetract.Value = Operation.CalcLightOffDelay.RetractSpeed = nmLightOffDelayRetract.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayBottomRetract))
{
Operation.CalcLightOffDelay.BottomRetractSpeed = nmLightOffDelayBottomRetract.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayWaitTime))
{
Operation.CalcLightOffDelay.WaitTime = nmLightOffDelayWaitTime.Value;
return;
}
if (ReferenceEquals(sender, nmLightOffDelayBottomWaitTime))
{
Operation.CalcLightOffDelay.BottomWaitTime = nmLightOffDelayBottomWaitTime.Value;
return;
}
}
private void EventClick(object sender, EventArgs e)
{
if (ReferenceEquals(sender, btnLightOffDelaySetParameter))
{
Program.SlicerFile.LiftHeight = (float) Operation.CalcLightOffDelay.LiftHeight;
Program.SlicerFile.LiftSpeed = (float) Operation.CalcLightOffDelay.LiftSpeed;
Program.SlicerFile.RetractSpeed = (float) Operation.CalcLightOffDelay.RetractSpeed;
Program.SlicerFile.LayerOffTime = (float) Operation.CalcLightOffDelay.LightOffDelay;
Program.FrmMain.CanSave = true;
lbLightOffDelayCurrentValue.Text = $"Current value: {Program.SlicerFile.LayerOffTime}";
return;
}
if (ReferenceEquals(sender, btnLightOffDelaySetBottomParameter))
{
Program.SlicerFile.BottomLiftHeight = (float)Operation.CalcLightOffDelay.BottomLiftHeight;
Program.SlicerFile.BottomLiftSpeed = (float)Operation.CalcLightOffDelay.BottomLiftSpeed;
Program.SlicerFile.BottomLayerOffTime = (float)Operation.CalcLightOffDelay.BottomLightOffDelay;
Program.FrmMain.CanSave = true;
lbLightOffDelayCurrentBottomValue.Text = $"Current value: {Program.SlicerFile.BottomLayerOffTime}";
return;
}
}
}
}
|