Skip to content

Commit

Permalink
Fix broken remapping
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Mar 15, 2022
1 parent 66c4ce2 commit 1071f3b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions pcbdraw/pcbdraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,22 +620,26 @@ def get_hole_mask(board, defs):
el.attrib["transform"] = "translate({} {}) rotate({})".format(
pos.x, pos.y, -padOrientation / 10)

def get_model_file(paths, lib, name, ref, remapping):
def resolve_remapping(lib, name, ref, remapping):
if ref in remapping:
lib, new_name = tuple(remapping[ref].split(":"))
if name.endswith(".back"):
name = new_name + ".back"
else:
name = new_name
return lib, name

def get_model_file(paths, lib, name, ref):
""" Find model file in library considering component remapping """
for path in paths:
if ref in remapping:
lib, new_name = tuple(remapping[ref].split(":"))
if name.endswith(".back"):
name = new_name + ".back"
else:
name = new_name
f = os.path.join(path, lib, name + ".svg")
if os.path.isfile(f):
return f
return None

def print_component(paths, lib, name, value, ref, pos, remapping={}):
f = get_model_file(paths, lib, name, ref, remapping)
name, lib = resolve_remapping(lib, name, ref, remapping)
f = get_model_file(paths, lib, name, ref)
msg = "{} with package {}:{} at [{},{},{}] -> {}".format(
ref, lib, name, pos[0], pos[1], math.degrees(pos[2]), f if f else "Not found")
print(msg)
Expand Down Expand Up @@ -710,12 +714,14 @@ def component_from_library(lib, name, value, ref, pos, usedComponents, comp,
if 'override_val' in tht_resistor_settings[ref]:
value = tht_resistor_settings[ref]['override_val']

lib, name = resolve_remapping(lib, name, ref, comp["remapping"])

unique_name = f"{lib}__{name}_{value}"
if unique_name in usedComponents:
componentInfo = usedComponents[unique_name]
componentElement = etree.Element("use", attrib={"{http://www.w3.org/1999/xlink}href": "#" + componentInfo["id"]})
else:
f = get_model_file(comp["libraries"], lib, name, ref, comp["remapping"])
f = get_model_file(comp["libraries"], lib, name, ref)
if not f:
if not silent:
if name[-5:] != '.back' or not no_warn_back:
Expand Down

0 comments on commit 1071f3b

Please sign in to comment.