Remove debug prints, add debug output

This commit is contained in:
jaseg 2025-12-17 12:47:06 +01:00
parent 57e8a52e1f
commit e54517544a
3 changed files with 12 additions and 15 deletions

View file

@ -90,15 +90,16 @@ def circle_center_to_tangents(center, a, b):
@click.option('--footprint-name', help="Name for the generated footprint. Default: Output file name sans extension.")
@click.option('--cell-name', help="Name for the generated cell when exporting GDSII. 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('--geometry-debug-file', type=click.Path(writable=True), help='Render geometry debug information to a PDF file with the given name')
@click.version_option()
@click.pass_context
def cli(ctx, footprint_name, cell_name, clipboard, single_layer, arc_tolerance, circle_segments, format, **kwargs):
def cli(ctx, footprint_name, cell_name, clipboard, single_layer, arc_tolerance, circle_segments, format, geometry_debug_file, **kwargs):
ctx.ensure_object(dict)
logger = logging.getLogger('kicoil')
logger.setLevel(logging.INFO)
def write(shape, outfile):
nonlocal footprint_name, clipboard, single_layer, arc_tolerance, circle_segments, format, cell_name
nonlocal footprint_name, clipboard, single_layer, arc_tolerance, circle_segments, format, cell_name, geometry_debug_file
logger = logging.getLogger('kicoil')
if single_layer:
@ -112,7 +113,7 @@ def cli(ctx, footprint_name, cell_name, clipboard, single_layer, arc_tolerance,
if footprint_name is None and outfile:
footprint_name = outfile.stem
footprint = model.render_footprint(footprint_name, arc_tolerance, circle_segments)
footprint = model.render_footprint(footprint_name, arc_tolerance, circle_segments, geometry_debug_file)
except ValueError as e:
#raise click.ClickException(*e.args)

View file

@ -119,7 +119,7 @@ class CircleShape(Shape):
return f'{self.outer_diameter:.2f} mm OD, {self.inner_diameter:.2f} mm ID circular'
def compute_spiral(self, a1, a2, fn=64):
def compute_spiral(self, a1, a2, fn=64, debug=False):
r1, r2 = self.outer_radius, self.inner_radius
fn = ceil(fn * abs(a2-a1)/(2*pi))
x0, y0 = cos(a1)*r1, sin(a1)*r1
@ -491,7 +491,7 @@ class PlanarInductor():
def default_footprint_name(self):
return f'planar-coil-{self.shape.slug}-n{self.turns}-k{self.twists}'
def render_footprint(self, name=None, arc_tolerance=0.02, circle_segments=64):
def render_footprint(self, name=None, arc_tolerance=0.02, circle_segments=64, geometry_debug_file=None):
if name is None:
name = self.default_footprint_name
@ -611,6 +611,7 @@ class PlanarInductor():
keepout=ZoneKeepout(copperpour_allowed=False),
polygon=ZonePolygon(pts=[XYCoord(x=x, y=y) for x, y in pts])))
self.shape.sk.dump_to_pdf('/tmp/test.pdf')
if geometry_debug_file:
self.shape.sk.dump_to_pdf(geometry_debug_file)
return footprint

View file

@ -194,10 +194,8 @@ class Skeletonator:
def iter_arcs(self, p):
i = 0
start = self.node_map[p]
#print('start', start, start in self.arc_map, start in self.divergent)
while start in self.arc_map and not start in self.divergent:
end = self.arc_map[start]
#print('end', i, end)
i += 1
yield start, end
start = end
@ -281,7 +279,6 @@ class Skeletonator:
point_angles.append(angle)
angle += edge_angle
point_angles += [a+1 for a in point_angles]
print(f'{t_start=} {point_angles=}')
for (p1, p2), (tp1, tp2) in zip(self.poly_edges * 2, itertools.pairwise(point_angles)):
rp1 = r_interpolate(tp1)
@ -319,7 +316,6 @@ class Skeletonator:
poly_x = [p[0] for p in self.poly] + [self.poly[0][0]]
poly_y = [p[1] for p in self.poly] + [self.poly[0][1]]
ax.plot(poly_x, poly_y, '-', color='black', linewidth=.5, label='Polygon')
ax.plot(poly_x, poly_y, 'o', color='black', markersize=4)
# skeleton edges
for node1, node2 in self.skeleton_edges:
@ -328,11 +324,11 @@ class Skeletonator:
# skeleton nodes
for n in self.skeleton_nodes:
if n in self.divergent:
ax.plot(n.x, n.y, 'go', markersize=6)
ax.plot(n.x, n.y, 'o', markerfacecolor='none', markeredgecolor='green', markersize=4)
elif n in self.arc_map:
ax.plot(n.x, n.y, 'ro', markersize=3, alpha=0.5)
ax.plot(n.x, n.y, 'o', color='black', markersize=3, alpha=0.5)
else:
ax.plot(n.x, n.y, 'o', color='magenta', markersize=6)
ax.plot(n.x, n.y, 'o', markerfacecolor='none', markeredgecolor='magenta', markersize=4)
count = {True: 0, False: 0}
for arm, direction, t1, t2 in self.debug_arms:
@ -342,7 +338,6 @@ class Skeletonator:
align = 'left' if direction else 'right'
ax.text(xs[-1], ys[-1], f'{count[direction]}', size=3, horizontalalignment=align)
ax.text(xs[0], ys[0], f'{count[direction]}', size=3, horizontalalignment=align, color='gray')
print(f'{count[direction]:03d}/{'A' if direction else 'B'}: {t1:.3f} {t2:.3f}')
count[direction] += 1
xs, ys = [], []
@ -351,7 +346,7 @@ class Skeletonator:
arc, (px, py) = self.project_arc(self.poly[0], r)
xs.append(px)
ys.append(py)
ax.plot(xs, ys, linewidth=.5, color='black')
ax.plot(xs, ys, '--', linewidth=.5, color='black')
ax.set_aspect('equal', adjustable='box')
ax.grid(True, alpha=0.3)