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
|
/*
* 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 UVtools.Core.FileFormats;
namespace UVtools.Core.GCode
{
public class GCodeLayer
{
private float? _waitTimeBeforeCure;
private float? _exposureTime;
private float? _waitTimeAfterCure;
private float? _liftHeight;
private float? _liftSpeed;
private float? _waitTimeAfterLift;
private float? _retractSpeed;
public enum GCodeLastParsedLine : byte
{
LayerIndex,
}
public bool IsValid => LayerIndex.HasValue;
public FileFormat SlicerFile { get; }
public uint? LayerIndex { get; set; }
public float? PositionZ { get; set; }
public float? WaitTimeBeforeCure
{
get => _waitTimeBeforeCure;
set => _waitTimeBeforeCure = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? ExposureTime
{
get => _exposureTime;
set => _exposureTime = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? WaitTimeAfterCure
{
get => _waitTimeAfterCure;
set => _waitTimeAfterCure = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? LiftHeight
{
get => _liftHeight;
set => _liftHeight = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? LiftSpeed
{
get => _liftSpeed;
set => _liftSpeed = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? WaitTimeAfterLift
{
get => _waitTimeAfterLift;
set => _waitTimeAfterLift = value is null ? null : (float)Math.Round(value.Value, 2);
}
public float? RetractSpeed
{
get => _retractSpeed;
set => _retractSpeed = value is null ? null : (float)Math.Round(value.Value, 2);
}
public byte? LightPWM { get; set; }
public bool IsExposing => LightPWM.HasValue && !IsAfterLightOff;
public bool IsAfterLightOff { get; set; }
public GCodeLayer(FileFormat slicerFile)
{
SlicerFile = slicerFile;
}
public void Init()
{
LayerIndex = null;
PositionZ = null;
WaitTimeBeforeCure = null;
ExposureTime = null;
WaitTimeAfterCure = null;
LiftHeight = null;
LiftSpeed = null;
WaitTimeAfterLift = null;
RetractSpeed = null;
LightPWM = null;
IsAfterLightOff = false;
}
/// <summary>
/// Set gathered data to the layer
/// </summary>
public void SetLayer()
{
if (!IsValid) return;
uint layerIndex = LayerIndex.Value;
var layer = SlicerFile[layerIndex];
if(PositionZ.HasValue) layer.PositionZ = PositionZ.Value;
layer.WaitTimeBeforeCure = WaitTimeBeforeCure ?? 0;
layer.ExposureTime = ExposureTime ?? SlicerFile.GetInitialLayerValueOrNormal(layerIndex, SlicerFile.BottomExposureTime, SlicerFile.ExposureTime);
layer.WaitTimeAfterCure = WaitTimeAfterCure ?? 0;
layer.LiftHeight = LiftHeight ?? 0;
layer.LiftSpeed = LiftSpeed ?? SlicerFile.GetInitialLayerValueOrNormal(layerIndex, SlicerFile.BottomLiftSpeed, SlicerFile.LiftSpeed);
layer.WaitTimeAfterLift = WaitTimeAfterLift ?? 0;
layer.RetractSpeed = RetractSpeed ?? SlicerFile.RetractSpeed;
layer.LightPWM = LightPWM ?? SlicerFile.GetInitialLayerValueOrNormal(layerIndex, SlicerFile.BottomLightPWM, SlicerFile.LightPWM);
}
}
}
|