Skip to content

Commit 95a37d3

Browse files
committed
Fix rectangles in angled footprints
Fixes #305
1 parent 356c4a2 commit 95a37d3

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,36 @@ def parse_shape(self, d):
102102
return None
103103
start = self.normalize(d.GetStart())
104104
end = self.normalize(d.GetEnd())
105-
if (shape == "segment" or shape == "rect" and
106-
not (hasattr(d, "IsFilled") and d.IsFilled())):
105+
if shape == "segment":
107106
return {
108107
"type": shape,
109108
"start": start,
110109
"end": end,
111110
"width": d.GetWidth() * 1e-6
112111
}
113-
if shape == "rect" and hasattr(d, "IsFilled") and d.IsFilled():
114-
return {
112+
113+
if shape == "rect":
114+
if hasattr(d, "GetRectCorners"):
115+
points = list(map(self.normalize, d.GetRectCorners()))
116+
else:
117+
points = [
118+
start,
119+
[end[0], start[1]],
120+
end,
121+
[start[0], end[1]]
122+
]
123+
shape_dict = {
115124
"type": "polygon",
116-
"pos": start,
125+
"pos": [0, 0],
117126
"angle": 0,
118-
"polygons": [[
119-
[0, 0],
120-
[end[0] - start[0], 0],
121-
[end[0] - start[0], end[1] - start[1]],
122-
[0, end[1] - start[1]]
123-
]]
127+
"polygons": [points],
128+
"width": d.GetWidth() * 1e-6,
129+
"filled": 0
124130
}
131+
if hasattr(d, "IsFilled") and d.IsFilled():
132+
shape_dict["filled"] = 1
133+
return shape_dict
134+
125135
if shape == "circle":
126136
shape_dict = {
127137
"type": shape,
@@ -132,6 +142,7 @@ def parse_shape(self, d):
132142
if hasattr(d, "IsFilled") and d.IsFilled():
133143
shape_dict["filled"] = 1
134144
return shape_dict
145+
135146
if shape == "arc":
136147
a1, a2 = self.get_arc_angles(d)
137148
if hasattr(d, "GetCenter"):
@@ -144,6 +155,7 @@ def parse_shape(self, d):
144155
"endangle": a2,
145156
"width": d.GetWidth() * 1e-6
146157
}
158+
147159
if shape == "polygon":
148160
if hasattr(d, "GetPolyShape"):
149161
polygons = self.parse_poly_set(d.GetPolyShape())
@@ -321,7 +333,8 @@ def parse_drawing(self, d):
321333
s = self.parse_shape(d)
322334
elif d.GetClass() in ["PTEXT", "MTEXT", "FP_TEXT", "PCB_TEXT"]:
323335
s = self.parse_text(d)
324-
elif d.GetClass().startswith("PCB_DIM") and hasattr(pcbnew, "VECTOR_SHAPEPTR"):
336+
elif (d.GetClass().startswith("PCB_DIM")
337+
and hasattr(pcbnew, "VECTOR_SHAPEPTR")):
325338
result.append(self.parse_dimension(d))
326339
s = self.parse_text(d.Text())
327340
else:

0 commit comments

Comments
 (0)