-
Notifications
You must be signed in to change notification settings - Fork 1
/
plate.go
113 lines (92 loc) · 1.95 KB
/
plate.go
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
package gen
import (
"bufio"
"io"
"strings"
)
func ReadPlate(r io.Reader) []*PartData {
s := bufio.NewScanner(r)
var generalData *GeneralData
s.Scan()
if s.Text() == "GENERAL_DATA" {
generalData = readGeneralData(s)
} else {
return nil
}
space := 1
if generalData.NoOfParts > 0 {
space = generalData.NoOfParts
}
parts := make([]*PartData, 0, space)
nameIndex := make(map[string]int, space)
var lastPartIdx int
for s.Scan() {
switch s.Text() {
case "PART_DATA":
pd := readPartData(s)
pd.Thickness = generalData.Thickness
pd.Quality = generalData.Quality
parts = append(parts, pd)
nameIndex[pd.Name] = len(parts) - 1
case "PART_INFORMATION":
for s.Scan() {
k, v, ok := strings.Cut(s.Text(), "=")
if !ok {
break
}
switch k {
case "PART_NAME":
lastPartIdx = nameIndex[v]
}
}
case "IDLE_DATA":
for s.Scan() {
switch s.Text() {
case "END_OF_IDLE_DATA":
break
}
}
case "MARKING_DATA":
md := readMarkingData(s)
parts[lastPartIdx].MarkingData = append(parts[lastPartIdx].MarkingData, md)
case "GEOMETRY_DATA":
gd := readGeometryData(s)
parts[lastPartIdx].GeometryData = append(parts[lastPartIdx].GeometryData, gd)
case "STRING_DATA":
sd := readStringData(s)
parts[lastPartIdx].StringData = append(parts[lastPartIdx].StringData, sd)
case "BUMP_DATA":
for s.Scan() {
switch s.Text() {
case "END_OF_BUMP_DATA":
break
}
}
case "LABELTEXT_DATA":
for s.Scan() {
switch s.Text() {
case "END_OF_LABELTEXT_DATA":
break
}
}
case "LABELSYMBOL_DATA":
for s.Scan() {
switch s.Text() {
case "END_OF_LABELSYMBOL_DATA":
break
}
}
case "BURNING_DATA":
b := readBurningData(s)
parts[lastPartIdx].BurningData = append(parts[lastPartIdx].BurningData, b)
case "EDGE_DATA":
for s.Scan() {
switch s.Text() {
case "END_OF_EDGE_DATA":
break
}
}
}
}
return parts
}