gen: Add via stagger options

This commit is contained in:
jaseg 2024-10-25 12:48:10 +02:00
parent 8ba908c58e
commit 62f443c3d6

View file

@ -605,6 +605,8 @@ def print_valid_twists(ctx, param, value):
@click.option('--outer-diameter', type=float, default=50, help='Outer diameter [mm]')
@click.option('--svg-out', type=click.Path(writable=True, dir_okay=False, path_type=Path), help='Filename to output SVG illustration of the coil to')
@click.option('--inner-diameter', type=float, default=25, help='Inner diameter [mm]')
@click.option('--stagger-inner-vias/--no-stagger-inner-vias', default=False, help='Stagger inner via ring')
@click.option('--stagger-outer-vias/--no-stagger-outer-vias', default=False, help='Stagger outer via ring')
@click.option('--trace-width', type=float, default=None)
@click.option('--via-diameter', type=float, default=0.6)
@click.option('--two-layer/--single-layer', default=True)
@ -634,7 +636,7 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
footprint_name, layer_pair, twists, clipboard, counter_clockwise, keepout_zone, keepout_margin,
arc_tolerance, pcb, mesh_out, magneticalc_out, circle_segments, mesh_split_out, copper_thickness,
board_thickness, mesh_mutual_out, mutual_offset_x, mutual_offset_y, mutual_offset_z, mutual_rotation_z,
two_layer, svg_out):
two_layer, svg_out, stagger_inner_vias, stagger_outer_vias):
if 'WAYLAND_DISPLAY' in os.environ:
copy, paste, cliputil = ['wl-copy'], ['wl-paste'], 'xclip'
@ -642,7 +644,10 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
copy, paste, cliputil = ['xclip', '-i', '-sel', 'clipboard'], ['xclip', '-o', '-sel' 'clipboard'], 'wl-clipboard'
if gcd(twists, turns) != 1:
raise click.ClickException('For the geometry to work out, the --twists parameter must be co-prime to --turns, i.e. the two must have 1 as their greatest common divisor. You can print valid values for --twists by running this command with --show-twists [turns number].')
raise click.ClickException(f'For the geometry to work out, the --twists parameter must be co-prime to --turns, i.e. the two must have 1 as their greatest common divisor. You can print valid values for --twists by running this command with --show-twists [turns number]. Right now, both are divisible by {gcd(twists, turns)}.')
if (stagger_inner_vias or stagger_outer_vias) and twists%2 != 0:
raise click.ClickException('For --stagger-inner/outer-vias to work, --twists must be even and --turns must be odd.')
if (mesh_out or mesh_split_out or mesh_mutual_out) and not pcb:
raise click.ClickException('--pcb is required when --mesh-out, --mesh-mutual-out or --mesh-split-out are used.')
@ -707,8 +712,8 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
print(f' {degrees(outer_via_angle):.1f} deg / via', file=sys.stderr)
# Check if the vias of the inner ring are so large that they would overlap
if inner_via_angle*twists > 2*pi:
min_dia = 2*((via_diameter + clearance) / (2*sin(pi / twists)) + via_offset)
if inner_via_angle*twists > (4*pi if stagger_inner_vias else 2*pi):
min_dia = 2*((via_diameter + clearance) / (2*sin(pi / twists * (2 if stagger_inner_vias else 1))) + via_offset)
raise click.ClickException(f'Error: Overlapping vias in inner via ring. Calculated minimum inner diameter is {min_dia:.2f} mm.')
pitch = clearance + trace_width
@ -874,7 +879,11 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
path.move(xn, yn)
path.line(xq, yq)
xv, yv = inner_via_ring_radius*cos(fold_angle), inner_via_ring_radius*sin(fold_angle)
r = inner_via_ring_radius
if stagger_inner_vias:
if i%2 != 0:
r -= 2*via_offset
xv, yv = r*cos(fold_angle), r*sin(fold_angle)
pads.append(make_via(xv, yv, layer_pair))
if not isclose(via_offset, 0, abs_tol=1e-6):
lines.append(make_line(xn, yn, xv, yv, layer_pair[0]))
@ -883,7 +892,11 @@ def generate(outfile, turns, outer_diameter, inner_diameter, via_diameter, via_d
svg_vias.append(Tag('circle', cx=xv, cy=yv, r=via_drill/2, stroke='none', fill='black'))
if i > 0:
xv, yv = outer_via_ring_radius*cos(start_angle), outer_via_ring_radius*sin(start_angle)
r = outer_via_ring_radius
if stagger_outer_vias:
if i%2 != 0:
r += 2*via_offset
xv, yv = r*cos(start_angle), r*sin(start_angle)
pads.append(make_via(xv, yv, layer_pair))
if not isclose(via_offset, 0, abs_tol=1e-6):
lines.append(make_line(x0, y0, xv, yv, layer_pair[0]))