Skip to content

Commit

Permalink
Support removing annular rings of unconnected vias
Browse files Browse the repository at this point in the history
Related #68
  • Loading branch information
realthunder committed Jul 3, 2023
1 parent 4a63cd4 commit a429bb2
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,17 @@ def _makeCustomPad(self, params):
return wires[0]
return Part.makeCompound(wires)

def getTrackPoints(self):
points = set()
for tp,ss in (('segment',self.pcb.segment), ('arc',getattr(self.pcb, 'arc', []))):
for s in ss:
if self.filterNets(s):
continue
if unquote(s.layer) == self.layer:
points.add((s.start[0], s.start[1]))
points.add((s.end[0], s.end[1]))
return points

def makePads(self,shape_type='face',thickness=0.05,holes=False,
fit_arcs=True,prefix=''):

Expand Down Expand Up @@ -1705,6 +1716,17 @@ def _face(obj,name,label=None):
raise ValueError('invalid shape type: {}'.format(shape_type))

objs = []
track_points = None

def filter_unconnected(v, at):
if 'remove_unused_layers' in v:
excludes = [self.findLayers(s)[0] for s in getattr(v, 'zone_layer_connections', [])]
if self.layer_type not in excludes:
nonlocal track_points
if track_points is None:
track_points = self.getTrackPoints()
if not at in track_points:
return True

count = 0
skip_count = 0
Expand Down Expand Up @@ -1777,6 +1799,7 @@ def _face(obj,name,label=None):
cut_non_closed = None

via_skip = 0
via_unconnected = 0
vias = []
if self.via_bound < 0:
via_skip = len(self.pcb.via)
Expand All @@ -1788,6 +1811,11 @@ def _face(obj,name,label=None):
or self.filterNets(v):
via_skip += 1
continue

if filter_unconnected(v, (v.at[0], v.at[1])):
via_unconnected += 1
continue

if self.via_bound:
w = make_rect(Vector(v.size*self.via_bound,v.size*self.via_bound))
else:
Expand All @@ -1806,9 +1834,9 @@ def _face(obj,name,label=None):

self._log('footprints: {}',len(self.pcb.module))
self._log('pads: {}, skipped: {}',count,skip_count)
self._log('vias: {}, skipped: {}',len(self.pcb.via),via_skip)
self._log('vias: {}, skipped: {}, unconnected: {}',len(self.pcb.via),via_skip,via_unconnected)
self._log('total pads added: {}',
count-skip_count+len(self.pcb.via)-via_skip)
count-skip_count+len(self.pcb.via)-via_skip-via_unconnected)

if objs:
objs = self._cutHoles(objs,holes,'pads',fit_arcs=fit_arcs)
Expand Down

0 comments on commit a429bb2

Please sign in to comment.