-
Notifications
You must be signed in to change notification settings - Fork 1
/
pcbparse.py
152 lines (121 loc) · 4.65 KB
/
pcbparse.py
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
import sys, io, os
from parser_base import ParserBase
from module import Module
class Board(object):
def __init__(self):
self.Clear()
currentdir = os.path.dirname(os.path.realpath(__file__))
self.filename_default = os.path.join(currentdir, 'tests', 'leds.kicad_pcb')
def Load(self, filename = None):
if filename is None:
filename = self.filename_default
with io.open(filename, 'r', encoding='utf-8') as f:
self.pcb = ParserBase().parse_sexpression(f.read())
self.Parse()
def Clear(self):
self.general = ''
self.paper = ''
self.title_block = ''
# self.layers = Layers()
# self.layers = ''
self.setup = ''
self.property = ''
self.net = []
self.net_class = ''
self.gr_arc = []
self.gr_curve = []
self.gr_line = []
self.gr_poly = []
self.gr_circle = []
self.gr_rect = []
self.gr_text = []
self.gr_dimension = []
self.module = []
self.footprint = []
self.segment = []
self.arc = []
self.group = ''
self.via = []
self.zone = []
self.target = ''
self.metadata = []
def Parse(self):
for item in self.pcb:
if type(item) is str:
# print(item)
continue
else:
if item[0] == 'layers':
continue
self.layers = Layers()
self.layers.From_PCB(item)
elif item[0] == 'footprint':
# This is the new name of modules
# KiCad 6 supports "module" as a legacy option
# So that's what we will use.
module = Module()
module.From_PCB(item)
self.module.append(module)
elif item[0] == 'segment':
continue
segment = Segment()
segment.From_PCB(item)
self.segment.append(segment)
elif item[0] == 'arc':
continue
arc = Arc()
arc.From_PCB(item)
self.arc.append(arc)
elif item[0] == 'gr_arc':
continue
arc = Arc()
arc.From_PCB(item)
self.gr_arc.append(arc)
elif item[0] == 'gr_line':
continue
line = Line()
line.From_PCB(item)
self.gr_line.append(line)
elif item[0] == 'gr_circle':
continue
circle = Circle()
circle.From_PCB(item)
self.gr_circle.append(circle)
elif item[0] == 'gr_poly':
continue
poly = Poly()
poly.From_PCB(item)
self.gr_poly.append(poly)
elif item[0] == 'gr_curve':
continue
curve = Curve()
curve.From_PCB(item)
self.gr_curve.append(curve)
elif item[0] == 'gr_text':
continue
text = Text()
text.From_PCB(item)
self.gr_text.append(text)
# tag = BeautifulSoup(self.Convert_Gr_Text_To_SVG(item, i), 'html.parser')
# layer = tag.find('text')['layer']
# base.svg.find('g', {'inkscape:label': layer}, recursive=False).append(tag)
elif item[0] == 'zone':
continue
zone = Zone()
zone.From_PCB(item)
self.zone.append(zone)
elif item[0] == 'via':
continue
via = Via()
via.From_PCB(item)
self.via.append(via)
elif item[0] == 'net':
#net #, name, count
self.net.append([int(item[1]), item[2], 0])
else:
self.metadata.append(item)
for i_m, m in enumerate(self.module):
for i_p, p in enumerate(m.pad):
if len(p.net) > 0:
net_num = int(p.net[0])
self.net[net_num][2] += 1