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
|
using System.ComponentModel;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using UVtools.Core.Extensions;
using UVtools.Core.FileFormats;
using UVtools.Core.Operations;
using UVtools.WPF.Extensions;
using UVtools.WPF.Windows;
namespace UVtools.WPF.Controls.Tools
{
public class ToolEditParametersControl : ToolControl
{
public OperationEditParameters Operation => BaseOperation as OperationEditParameters;
public RowControl[] RowControls;
private Grid grid;
public sealed class RowControl
{
public FileFormat.PrintParameterModifier Modifier { get; }
public TextBlock Name { get; }
public TextBlock OldValue { get; }
public NumericUpDown NewValue { get; }
public TextBlock Unit { get; }
public Button ResetButton { get; }
public RowControl(FileFormat.PrintParameterModifier modifier)
{
Modifier = modifier;
modifier.NewValue = modifier.OldValue.Clamp(modifier.Minimum, modifier.Maximum);
Name = new TextBlock
{
Text = $"{modifier.Name}:",
VerticalAlignment = VerticalAlignment.Center,
Padding = new Thickness(15, 0),
Tag = this,
};
if(!string.IsNullOrWhiteSpace(modifier.Description)) ToolTip.SetTip(Name, modifier.Description);
OldValue = new TextBlock
{
Text = modifier.OldValue.ToString(CultureInfo.InvariantCulture),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Center,
//Padding = new Thickness(15, 0),
Tag = this
};
NewValue = new NumericUpDown
{
//DecimalPlaces = modifier.DecimalPlates,
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch,
Minimum = (double) modifier.Minimum,
Maximum = (double) modifier.Maximum,
Increment = modifier.DecimalPlates == 0 ? 1 : 0.5,
Value = (double)modifier.NewValue,
Tag = this,
//Width = 100,
ClipValueToMinMax = true
};
if (modifier.DecimalPlates > 0)
{
NewValue.FormatString = "F02";
}
Unit = new TextBlock
{
Text = modifier.ValueUnit,
VerticalAlignment = VerticalAlignment.Center,
Padding = new Thickness(10, 0, 15, 0),
Tag = this
};
ResetButton = new Button
{
IsVisible = false,
IsEnabled = false,
VerticalAlignment = VerticalAlignment.Center,
Tag = this,
Padding = new Thickness(5),
Content = new Image {Source = App.GetBitmapFromAsset("/Assets/Icons/undo-16x16.png")},
HorizontalAlignment = HorizontalAlignment.Stretch
};
ResetButton.Click += ResetButtonOnClick;
NewValue.ValueChanged += NewValueOnValueChanged;
}
private void NewValueOnValueChanged(object? sender, NumericUpDownValueChangedEventArgs e)
{
Modifier.NewValue = (decimal) NewValue.Value;
ResetButton.IsVisible = ResetButton.IsEnabled = Modifier.HasChanged;
}
private void ResetButtonOnClick(object? sender, RoutedEventArgs e)
{
NewValue.Value = (double) Modifier.OldValue;
NewValue.Focus();
}
}
public ToolEditParametersControl()
{
BaseOperation = new OperationEditParameters(SlicerFile);
if (!ValidateSpawn()) return;
InitializeComponent();
grid = this.FindControl<Grid>("grid");
}
public void PopulateGrid()
{
const byte cols = 5;
if (grid.Children.Count > cols)
{
grid.Children.RemoveRange(cols, grid.Children.Count - cols);
}
if (grid.RowDefinitions.Count > 1)
{
grid.RowDefinitions.RemoveRange(1, grid.RowDefinitions.Count-1);
}
int rowIndex = 1;
RowControls = new RowControl[Operation.Modifiers.Length];
//table.RowCount = Operation.Modifiers.Length+1;
foreach (var modifier in Operation.Modifiers)
{
grid.RowDefinitions.Add(new RowDefinition());
byte column = 0;
var rowControl = new RowControl(modifier);
grid.Children.Add(rowControl.Name);
grid.Children.Add(rowControl.OldValue);
grid.Children.Add(rowControl.NewValue);
grid.Children.Add(rowControl.Unit);
grid.Children.Add(rowControl.ResetButton);
Grid.SetRow(rowControl.Name, rowIndex);
Grid.SetColumn(rowControl.Name, column++);
Grid.SetRow(rowControl.OldValue, rowIndex);
Grid.SetColumn(rowControl.OldValue, column++);
Grid.SetRow(rowControl.NewValue, rowIndex);
Grid.SetColumn(rowControl.NewValue, column++);
Grid.SetRow(rowControl.Unit, rowIndex);
Grid.SetColumn(rowControl.Unit, column++);
Grid.SetRow(rowControl.ResetButton, rowIndex);
Grid.SetColumn(rowControl.ResetButton, column++);
/*table.Controls.Add(rowControl.Name, column++, rowIndex);
table.Controls.Add(rowControl.OldValue, column++, rowIndex);
table.Controls.Add(rowControl.NewValue, column++, rowIndex);
table.Controls.Add(rowControl.Unit, column++, rowIndex);
table.Controls.Add(rowControl.ResetButton, column++, rowIndex);
*/
RowControls[rowIndex - 1] = rowControl;
rowIndex++;
}
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public override void Callback(ToolWindow.Callbacks callback)
{
switch (callback)
{
case ToolWindow.Callbacks.Init:
case ToolWindow.Callbacks.Loaded:
if (callback is ToolWindow.Callbacks.Init)
{
ParentWindow.SelectCurrentLayer();
ParentWindow.LayerRangeSync = true;
}
PopulateGrid();
Operation.PropertyChanged += OperationOnPropertyChanged;
break;
}
}
private void OperationOnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Operation.LayerIndexStart) && Operation.PerLayerOverride)
{
SlicerFile.RefreshPrintParametersPerLayerModifiersValues(Operation.LayerIndexStart);
PopulateGrid();
return;
}
if (e.PropertyName == nameof(Operation.PerLayerOverride))
{
if (Operation.PerLayerOverride)
{
Operation.Modifiers = App.SlicerFile.PrintParameterPerLayerModifiers;
SlicerFile.RefreshPrintParametersPerLayerModifiersValues(Operation.LayerIndexStart);
}
else
{
Operation.Modifiers = App.SlicerFile.PrintParameterModifiers;
SlicerFile.RefreshPrintParametersModifiersValues();
}
ParentWindow.LayerRangeVisible = Operation.PerLayerOverride;
PopulateGrid();
return;
}
}
}
}
|