Skip to content

Commit

Permalink
Improve pin1 detection
Browse files Browse the repository at this point in the history
If there are multiple pads that look like common first pad names only
the lexicographically smallest one will be considered first.
If no pads have common first pad name then all pads with
lexicographically smallest name will be considered first (previously
only one random pad with such name was chosen).

Fixes openscopeproject#172
  • Loading branch information
qu1ck committed Aug 15, 2020
1 parent 98a7305 commit 1d37950
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions InteractiveHtmlBom/ecad/kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def parse_pad(self, pad):
layers.append("B")
pos = self.normalize(pad.GetPosition())
size = self.normalize(pad.GetSize())
is_pin1 = pad.GetPadName() in ['1', 'A', 'A1', 'P1', 'PAD1']
angle = pad.GetOrientation() * -0.1
shape_lookup = {
pcbnew.PAD_SHAPE_RECT: "rect",
Expand All @@ -261,8 +260,6 @@ def parse_pad(self, pad):
"angle": angle,
"shape": shape
}
if is_pin1:
pad_dict['pin1'] = 1
if shape == "custom":
polygon_set = pad.GetCustomShapeAsPolygon()
if polygon_set.HasHoles():
Expand Down Expand Up @@ -332,14 +329,18 @@ def parse_modules(self, pcb_modules):
if pad_dict is not None:
pads.append((p.GetPadName(), pad_dict))

# If no pads have common 'first' pad name pick lexicographically.
pin1_pads = [p for p in pads if 'pin1' in p[1]]
if pads and not pin1_pads:
if pads:
# Try to guess first pin name.
pads = sorted(pads, key=lambda el: el[0])
pin1_pads = [p for p in pads if p[0] in ['1', 'A', 'A1', 'P1', 'PAD1']]
if pin1_pads:
pin1_pad_name = pin1_pads[0][0]
else:
# No pads have common first pin name, pick lexicographically smallest.
pin1_pad_name = pads[0][0]
for pad_name, pad_dict in pads:
if pad_name:
if pad_name == pin1_pad_name:
pad_dict['pin1'] = 1
break

pads = [p[1] for p in pads]

Expand Down

0 comments on commit 1d37950

Please sign in to comment.