Skip to content

Commit cf3ac25

Browse files
committed
Added circle support outside of pads
1 parent 9be9565 commit cf3ac25

File tree

4 files changed

+65
-19
lines changed

4 files changed

+65
-19
lines changed

Stretch/kiplug/board.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ def To_SVG(self):
241241
# layer = item.layer
242242
base.svg.find('g', {'inkscape:label': 'Modules'}, recursive=False).append(tag)
243243

244-
for item in self.gr_line:
244+
for item in self.gr_poly:
245245
tag = BeautifulSoup(item.To_SVG(), 'html.parser')
246246
layer = item.layer
247247
base.svg.find('g', {'inkscape:label': layer}, recursive=False).append(tag)
248248

249-
for item in self.gr_poly:
249+
for item in self.gr_line:
250250
tag = BeautifulSoup(item.To_SVG(), 'html.parser')
251251
layer = item.layer
252252
base.svg.find('g', {'inkscape:label': layer}, recursive=False).append(tag)

Stretch/kiplug/circle.py

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ class Circle(object):
3333
def __init__(self):
3434
self.center = []
3535
self.end = []
36-
self.width = 0
37-
self.angle = 0
36+
self.width = '0'
3837
self.layer = ''
3938
self.fill = ''
4039
self.tstamp = ''
41-
self.status = 0
40+
self.status = ''
4241

4342

4443
def From_PCB(self, input):
@@ -59,9 +58,9 @@ def From_PCB(self, input):
5958
self.end.append(float(item[1]))
6059
self.end.append(float(item[2]))
6160

62-
if item[0] == 'angle':
63-
self.angle = item[1]
64-
assert False,"Gr_circle: Please report this! Never seen before."
61+
# if item[0] == 'angle':
62+
# self.angle = item[1]
63+
# assert False,"Gr_circle: Please report this! Never seen before."
6564

6665
if item[0] == 'layer':
6766
self.layer = item[1]
@@ -88,15 +87,20 @@ def To_PCB(self, fp = False):
8887
pcb.append(['center'] + self.center)
8988
pcb.append(['end'] + self.end)
9089
pcb.append(['width', self.width])
91-
pcb.append(['angle', self.angle])
90+
# pcb.append(['angle', self.angle])
9291
pcb.append(['layer', self.layer])
93-
pcb.append(['fill', self.fill])
92+
if self.fill != '':
93+
pcb.append(['fill', self.fill])
9494
pcb.append(['tstamp', self.tstamp])
9595
pcb.append(['status', self.status])
9696

9797
return pcb
9898

99-
def To_SVG(self):
99+
def To_SVG(self, fp = False):
100+
if fp:
101+
circletype = 'fp_circle'
102+
else:
103+
circletype = 'gr_circle'
100104
tstamp = ''
101105
status = ''
102106
fill = ''
@@ -118,11 +122,44 @@ def To_SVG(self):
118122
parameters += 'cy="' + str(self.center[1] * pxToMM) + '" '
119123
parameters += 'r="' + str(r * pxToMM) + '" '
120124
parameters += 'layer="' + self.layer + '" '
121-
parameters += 'type="gr_circle" '
125+
parameters += 'type="' + circletype + '" '
122126
parameters += fill
123127
parameters += tstamp
124128
parameters += status
125129
parameters += '/>'
126130

127131
return parameters
128132

133+
134+
135+
def From_SVG(self, tag):
136+
style = tag['style']
137+
138+
width = style[style.find('stroke-width:') + 13:]
139+
self.width = width[0:width.find('mm')]
140+
141+
if tag.has_attr('layer'):
142+
self.layer = tag['layer']
143+
elif tag.parent.has_attr('inkscape:label'):
144+
#XML metadata trashed, try to recover from parent tag
145+
self.layer = tag.parent['inkscape:label']
146+
else:
147+
assert False, "Circle not in layer"
148+
149+
150+
r = str((float(tag['r']) +float(tag['cx'] )) / pxToMM)
151+
x = str(float(tag['cx']) / pxToMM)
152+
y = str(float(tag['cy']) / pxToMM)
153+
self.center = [x, y]
154+
self.end = [r, y]
155+
156+
if tag.has_attr('fill') == True:
157+
self.fill = tag['fill']
158+
159+
if tag.has_attr('status') == True:
160+
self.status = tag['status']
161+
162+
if tag.has_attr('tstamp') == True:
163+
self.tstamp = tag['tstamp']
164+
165+

Stretch/kiplug/module.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ def From_PCB(self, pcblist):
200200
arc.From_PCB(item)
201201
self.fp_arc.append(arc)
202202

203+
if item[0] == 'fp_circle':
204+
circle = Circle()
205+
circle.From_PCB(item)
206+
self.fp_circle.append(circle)
207+
203208
# if item[0] == 'fp_circle':
204209
# if item[0] == 'fp_curve':
205210
# if item[0] == 'fp_rect':
@@ -573,6 +578,10 @@ def From_SVG(self, tag):
573578
pad = Pad()
574579
pad.From_SVG(tagpath, rotate)
575580
self.pad.append(pad)
581+
elif tagpath.has_attr('type') == True and tagpath['type'] == 'fp_circle':
582+
circle = Circle()
583+
circle.From_SVG(tagpath)
584+
self.fp_circle.append(circle)
576585

577586
for tagpath in tag.find_all('ellipse'):
578587
if tagpath.has_attr('type') == True and tagpath['type'] == 'pad':

Stretch/kiplug/pad.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,20 @@ def To_SVG(self, angle = 0.0):
207207
svgsize += 'width="' + str(float(self.size[0]) * pxToMM) + '" '
208208
svgsize += 'height="' + str(float(self.size[1]) * pxToMM) + '" '
209209

210-
elif self.shape == 'circle':
211-
parameters += '<circle style="stroke:none;stroke-linecap:round;stroke-linejoin:miter;fill-opacity:1'
212-
svgsize += 'cx="' + str(self.at[0] * pxToMM) + '" '
213-
svgsize += 'cy="' + str(self.at[1] * pxToMM) + '" '
214-
svgsize += 'r="' + str(float(self.size[0]) * (pxToMM / 2)) + '" '
215-
svgsize += 'height="' + str(float(self.size[1]) * pxToMM) + '" '
216-
217210
elif self.shape == 'oval':
218211
parameters += '<ellipse style="stroke:none;stroke-linecap:round;stroke-linejoin:miter;fill-opacity:1'
219212
svgsize += 'cx="' + str(self.at[0] * pxToMM) + '" '
220213
svgsize += 'cy="' + str(self.at[1] * pxToMM) + '" '
221214
svgsize += 'rx="' + str(float(self.size[0]) * (pxToMM / 2)) + '" '
222215
svgsize += 'ry="' + str(float(self.size[1]) * (pxToMM / 2)) + '" '
223216

217+
elif self.shape == 'circle':
218+
parameters += '<circle style="stroke:none;stroke-linecap:round;stroke-linejoin:miter;fill-opacity:1'
219+
svgsize += 'cx="' + str(self.at[0] * pxToMM) + '" '
220+
svgsize += 'cy="' + str(self.at[1] * pxToMM) + '" '
221+
svgsize += 'r="' + str(float(self.size[0]) * (pxToMM / 2)) + '" '
222+
svgsize += 'height="' + str(float(self.size[1]) * pxToMM) + '" '
223+
224224
elif self.shape == 'custom':
225225
parameters += '<rect style="stroke:none;stroke-linecap:round;stroke-linejoin:miter;fill-opacity:1'
226226
svgsize += 'x="' + str(x * pxToMM) + '" '

0 commit comments

Comments
 (0)