blob: b6da2c213469e674b44d3c5bc8e09799eaed70df (
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
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
|
/*
* 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.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using UVtools.Core.FileFormats;
using UVtools.Core.Objects;
namespace UVtools.Core.Operations
{
[Serializable]
public class OperationEditParameters : Operation
{
#region Members
private bool _propagateModificationsToLayers = true;
private bool _perLayerOverride;
private uint _setNumberOfLayer = 1;
private uint _skipNumberOfLayer = 0;
#endregion
#region Overrides
public override Enumerations.LayerRangeSelection StartLayerRangeSelection => Enumerations.LayerRangeSelection.None;
public override bool CanROI => false;
public override string Title => "Edit print parameters";
public override string Description =>
"Edits the available print parameters.\n" +
"Note: Set global parameters will override all per layer settings when they are available.";
public override string ConfirmationText
{
get
{
var sb = new StringBuilder();
foreach (var modifier in Modifiers)
{
if(!modifier.HasChanged) continue;
sb.AppendLine($"{modifier.Name}: {modifier.OldValue}{modifier.ValueUnit} » {modifier.NewValue}{modifier.ValueUnit}");
}
var text = "commit print parameter changes";
if (_perLayerOverride)
{
if (LayerRangeCount == 1)
{
text += $" to layer {LayerIndexStart}";
}
else
{
text += $" from layer {LayerIndexStart} to {LayerIndexEnd}";
}
}
return $"{text}?\n{sb}";
}
}
public override string ProgressTitle => "Change print parameters";
public override string ProgressAction => "Changing print parameters";
public override bool CanHaveProfiles => false;
public override StringTag Validate(params object[] parameters)
{
var sb = new StringBuilder();
var changed = Modifiers.Any(modifier => modifier.HasChanged);
if (!changed)
{
sb.AppendLine("Nothing changed\nDo some changes or cancel the operation.");
}
return new StringTag(sb.ToString());
}
#endregion
#region Propertiers
[XmlIgnore]
public FileFormat.PrintParameterModifier[] Modifiers { get; set; }
public bool PropagateModificationsToLayers
{
get => _propagateModificationsToLayers;
set => RaiseAndSetIfChanged(ref _propagateModificationsToLayers, value);
}
/// <summary>
/// Gets or sets if parameters are global or per layer inside a layer range
/// </summary>
public bool PerLayerOverride
{
get => _perLayerOverride;
set => RaiseAndSetIfChanged(ref _perLayerOverride, value);
}
/// <summary>
/// Gets or sets the number of sequential layers to set the parameters
/// </summary>
public uint SetNumberOfLayer
{
get => _setNumberOfLayer;
set => RaiseAndSetIfChanged(ref _setNumberOfLayer, value);
}
/// <summary>
/// Gets or sets the number of sequential layers to skip after set a layer
/// </summary>
public uint SkipNumberOfLayer
{
get => _skipNumberOfLayer;
set => RaiseAndSetIfChanged(ref _skipNumberOfLayer, value);
}
#endregion
#region Constructor
public OperationEditParameters() { }
public OperationEditParameters(FileFormat slicerFile) : base(slicerFile) { }
public override void InitWithSlicerFile()
{
base.InitWithSlicerFile();
SlicerFile.RefreshPrintParametersModifiersValues();
Modifiers = SlicerFile.PrintParameterModifiers;
}
#endregion
#region Methods
protected override bool ExecuteInternally(OperationProgress progress)
{
if (PerLayerOverride)
{
uint setLayers = 0;
for (uint layerIndex = LayerIndexStart; layerIndex <= LayerIndexEnd; layerIndex++)
{
SlicerFile[layerIndex].SetValuesFromPrintParametersModifiers(Modifiers);
if (SkipNumberOfLayer <= 0) continue;
setLayers++;
if (setLayers >= SetNumberOfLayer)
{
setLayers = 0;
layerIndex += SkipNumberOfLayer;
}
}
foreach (var modifier in Modifiers)
{
modifier.OldValue = modifier.NewValue;
}
SlicerFile.RebuildGCode();
}
else
{
if (!_propagateModificationsToLayers)
{
SlicerFile.SuppressRebuildProperties = true;
}
SlicerFile.SetValuesFromPrintParametersModifiers();
if (!_propagateModificationsToLayers)
{
SlicerFile.SuppressRebuildProperties = false;
SlicerFile.RebuildGCode();
}
}
SlicerFile.RefreshPrintParametersModifiersValues();
return !progress.Token.IsCancellationRequested;
}
#endregion
}
}
|