mpsys/cree-led-pcb

This circuit diagram depicts a compact LED driver module featuring a TPS923655DMTR LED driver IC, input filtering and storage components (capacitors, inductor, diode), sensing and control resistors, output filtering capacitors, and various support passive components arranged on a 2-layer PCB with mounting holes.

Version
1.0.2
License
unset
Stars
0

apply-edits.py

#!/usr/bin/env python3
"""Apply manual-edits.json positions to driver-board.circuit.tsx pcbX/pcbY values."""
import json, re, sys

# Read manual edits
with open("manual-edits.json") as f:
    edits = json.load(f)

# Read current source
with open("driver-board.circuit.tsx") as f:
    source = f.read()

placements = edits.get("pcb_placements", [])
updated = source

for p in placements:
    sel = p["selector"]
    x = round(p["center"]["x"], 3)
    y = round(p["center"]["y"], 3)
    
    # Find the component definition and update pcbX/pcbY
    # Pattern: name="SEL" ... pcbX={...} pcbY={...}
    # or: name="SEL" ... pcbX={...} ... pcbY={...}
    
    # Match the component block
    pattern = re.compile(
        rf'(name\s*=\s*"{re.escape(sel)}"[^>]*?pcbX\s*=\s*{{)[^}}]+?(}})([^>]*?pcbY\s*=\s*{{)[^}}]+?(}})',
        re.DOTALL
    )
    
    def replacer(m):
        return f'{m.group(1)}{x}{m.group(2)}{m.group(3)}{y}{m.group(4)}'
    
    new_source, count = pattern.subn(replacer, updated)
    if count > 0:
        updated = new_source
        print(f"  {sel:12s} -> pcbX={{{x}}}, pcbY={{{y}}}")
    else:
        print(f"  {sel:12s} -> NOT FOUND in source (may be an imported component)")

with open("driver-board.circuit.tsx", "w") as f:
    f.write(updated)

print(f"\nApplied {len(placements)} manual edits to driver-board.circuit.tsx")