forked from gradientspace/gsGCode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GCodeLine.cs
109 lines (83 loc) · 1.8 KB
/
GCodeLine.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using g3;
namespace gs
{
public struct GCodeParam
{
public enum PType
{
Code,
DoubleValue,
IntegerValue,
TextValue,
NoValue,
Unknown
}
public PType type;
public string identifier;
public double doubleValue;
public int intValue {
get { return (int)doubleValue; } // we can store [-2^54, 2^54] precisely in a double
set { doubleValue = value; }
}
public string textValue;
}
// ugh..class...dangerous!!
public class GCodeLine
{
public enum LType
{
GCode,
MCode,
UnknownCode,
Comment,
UnknownString,
Blank,
If,
EndIf,
Else,
UnknownControl
}
public int lineNumber;
public LType type;
public string orig_string;
public int N; // N number of line
public int code; // G or M code
public GCodeParam[] parameters; // arguments/parameters
public string comment;
public GCodeLine(int num, LType type)
{
lineNumber = num;
this.type = type;
orig_string = null;
N = code = -1;
parameters = null;
comment = null;
}
public GCodeLine(int lineNum, LType type, string comment) {
lineNumber = lineNum;
this.type = type;
if ( type == LType.UnknownString ) {
this.orig_string = comment;
} else {
this.comment = comment;
}
}
public virtual GCodeLine Clone() {
GCodeLine clone = new GCodeLine(this.lineNumber, this.type);
clone.orig_string = this.orig_string;
clone.N = this.N;
clone.code = this.code;
if ( this.parameters != null ) {
clone.parameters = new GCodeParam[this.parameters.Length];
for (int i = 0; i < this.parameters.Length; ++i )
clone.parameters[i] = this.parameters[i];
}
clone.comment = this.comment;
return clone;
}
}
}