summaryrefslogtreecommitdiff
path: root/twisted_coil_gen_twolayer.py
diff options
context:
space:
mode:
Diffstat (limited to 'twisted_coil_gen_twolayer.py')
-rw-r--r--twisted_coil_gen_twolayer.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/twisted_coil_gen_twolayer.py b/twisted_coil_gen_twolayer.py
index d84b4db..4284e8a 100644
--- a/twisted_coil_gen_twolayer.py
+++ b/twisted_coil_gen_twolayer.py
@@ -130,6 +130,7 @@ def print_valid_twists(ctx, param, value):
@click.option('--footprint-name', help="Name for the generated footprint. Default: Output file name sans extension.")
@click.option('--layer-pair', default='F.Cu,B.Cu', help="Target KiCad layer pair for the generated footprint, comma-separated. Default: F.Cu/B.Cu.")
@click.option('--turns', type=int, default=5, help='Number of turns')
+@click.option('--pcb/--footprint', default=False, help='Generate a KiCad PCB instead of a footprint')
@click.option('--outer-diameter', type=float, default=50, help='Outer diameter [mm]')
@click.option('--inner-diameter', type=float, default=25, help='Inner diameter [mm]')
@click.option('--trace-width', type=float, default=None)
@@ -147,7 +148,7 @@ def print_valid_twists(ctx, param, value):
@click.version_option()
def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_drill, via_offset, trace_width, clearance,
footprint_name, layer_pair, twists, clipboard, counter_clockwise, keepout_zone, keepout_margin,
- arc_tolerance):
+ arc_tolerance, pcb):
if 'WAYLAND_DISPLAY' in os.environ:
copy, paste, cliputil = ['wl-copy'], ['wl-paste'], 'xclip'
else:
@@ -450,30 +451,40 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
else:
zones = []
- fp = kicad_fp.Footprint(
- name=name,
- generator=kicad_fp.Atom('GerbonaraTwistedCoilGenV1'),
- layer='F.Cu',
- descr=f"{turns} turn {outer_diameter:.2f} mm diameter twisted coil footprint, inductance approximately {L:.6f} µH. Generated by gerbonara'c Twisted Coil generator, version {__version__}.",
- clearance=clearance,
- zone_connect=0,
- lines=lines,
- arcs=arcs,
- pads=pads,
- zones=zones,
- )
+ if pcb:
+ obj = kicad_pcb.Board.empty_board(
+ zones=zones,
+ lines=[line.to_graphical_primitive() for line in lines],
+ arcs=[arc.to_graphical_primitive() for arc in arcs],
+ vias=[kicad_pcb.Via.from_pad(pad) for pad in pads if pad.type == kicad_pcb.Atom.thru_hole])
+
+ else:
+ obj = kicad_fp.Footprint(
+ name=name,
+ generator=kicad_fp.Atom('GerbonaraTwistedCoilGenV1'),
+ layer='F.Cu',
+ descr=f"{turns} turn {outer_diameter:.2f} mm diameter twisted coil footprint, inductance approximately {L:.6f} µH. Generated by gerbonara'c Twisted Coil generator, version {__version__}.",
+ clearance=clearance,
+ zone_connect=0,
+ lines=lines,
+ arcs=arcs,
+ pads=pads,
+ zones=zones,
+ )
if clipboard:
try:
+ data = obj.serialize()
print(f'Running {copy[0]}.', file=sys.stderr)
proc = subprocess.Popen(copy, stdin=subprocess.PIPE, text=True)
- proc.communicate(fp.serialize())
+ proc.communicate(data)
+ print('passed to wl-clip:', data)
except FileNotFoundError:
print(f'Error: --clipboard requires the {copy[0]} and {paste[0]} utilities from {cliputil} to be installed.', file=sys.stderr)
elif not outfile:
- print(fp.serialize())
+ print(obj.serialize())
else:
- fp.write(outfile)
+ obj.write(outfile)
if __name__ == '__main__':
generate()