From 5476da8aa3f4ee424f56f4f2491e7af1c4b7b758 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Fix a bunch of rendering bugs. - 'clear' polarity primitives no longer erase background - Added aperture macro support for polygons - Added aperture macro rendring support - Renderer now creates a new surface for each layer and merges them instead of working directly on a single surface - Updated examples accordingly --- gerber/layers.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gerber/layers.py') diff --git a/gerber/layers.py b/gerber/layers.py index 2b73893..29e452b 100644 --- a/gerber/layers.py +++ b/gerber/layers.py @@ -95,7 +95,8 @@ def sort_layers(layers): 'bottompaste', 'drill', ] output = [] drill_layers = [layer for layer in layers if layer.layer_class == 'drill'] - internal_layers = list(sorted([layer for layer in layers if layer.layer_class == 'internal'])) + internal_layers = list(sorted([layer for layer in layers + if layer.layer_class == 'internal'])) for layer_class in layer_order: if layer_class == 'internal': @@ -151,6 +152,8 @@ class PCBLayer(object): else: return None + def __repr__(self): + return ''.format(self.layer_class) class DrillLayer(PCBLayer): @classmethod @@ -163,6 +166,7 @@ class DrillLayer(PCBLayer): class InternalLayer(PCBLayer): + @classmethod def from_gerber(cls, camfile): filename = camfile.filename @@ -208,6 +212,7 @@ class InternalLayer(PCBLayer): class LayerSet(object): + def __init__(self, name, layers, **kwargs): super(LayerSet, self).__init__(**kwargs) self.name = name -- cgit From 5df38c014fd09792995b2b12b1982c535c962c9a Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 28 Jan 2016 12:19:03 -0500 Subject: Cleanup, rendering fixes. fixed rendering of tented vias fixed rendering of semi-transparent layers fixed file type detection issues added some examples --- gerber/layers.py | 66 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'gerber/layers.py') diff --git a/gerber/layers.py b/gerber/layers.py index 29e452b..93f0e36 100644 --- a/gerber/layers.py +++ b/gerber/layers.py @@ -19,8 +19,9 @@ import os import re from collections import namedtuple +from . import common from .excellon import ExcellonFile -from .ipc356 import IPC_D_356 +from .ipc356 import IPCNetlist Hint = namedtuple('Hint', 'layer ext name') @@ -73,9 +74,21 @@ hints = [ ext=['ipc'], name=[], ), + Hint(layer='drawing', + ext=['fab'], + name=['assembly drawing', 'assembly', 'fabrication', 'fab drawing'] + ), ] +def load_layer(filename): + return PCBLayer.from_cam(common.read(filename)) + + +def load_layer_data(data, filename=None): + return PCBLayer.from_cam(common.loads(data, filename)) + + def guess_layer_class(filename): try: directory, name = os.path.split(filename) @@ -89,24 +102,30 @@ def guess_layer_class(filename): return 'unknown' -def sort_layers(layers): +def sort_layers(layers, from_top=True): layer_order = ['outline', 'toppaste', 'topsilk', 'topmask', 'top', 'internal', 'bottom', 'bottommask', 'bottomsilk', - 'bottompaste', 'drill', ] + 'bottompaste'] + append_after = ['drill', 'drawing'] + output = [] - drill_layers = [layer for layer in layers if layer.layer_class == 'drill'] internal_layers = list(sorted([layer for layer in layers if layer.layer_class == 'internal'])) for layer_class in layer_order: if layer_class == 'internal': output += internal_layers - elif layer_class == 'drill': - output += drill_layers else: for layer in layers: if layer.layer_class == layer_class: output.append(layer) + if not from_top: + output = list(reversed(output)) + + for layer_class in append_after: + for layer in layers: + if layer.layer_class == layer_class: + output.append(layer) return output @@ -126,14 +145,14 @@ class PCBLayer(object): """ @classmethod - def from_gerber(cls, camfile): + def from_cam(cls, camfile): filename = camfile.filename layer_class = guess_layer_class(filename) if isinstance(camfile, ExcellonFile) or (layer_class == 'drill'): - return DrillLayer.from_gerber(camfile) + return DrillLayer.from_cam(camfile) elif layer_class == 'internal': - return InternalLayer.from_gerber(camfile) - if isinstance(camfile, IPC_D_356): + return InternalLayer.from_cam(camfile) + if isinstance(camfile, IPCNetlist): layer_class = 'ipc_netlist' return cls(filename, layer_class, camfile) @@ -155,9 +174,10 @@ class PCBLayer(object): def __repr__(self): return ''.format(self.layer_class) + class DrillLayer(PCBLayer): @classmethod - def from_gerber(cls, camfile): + def from_cam(cls, camfile): return cls(camfile.filename, camfile) def __init__(self, filename=None, cam_source=None, layers=None, **kwargs): @@ -168,11 +188,11 @@ class DrillLayer(PCBLayer): class InternalLayer(PCBLayer): @classmethod - def from_gerber(cls, camfile): + def from_cam(cls, camfile): filename = camfile.filename try: order = int(re.search(r'\d+', filename).group()) - except: + except AttributeError: order = 0 return cls(filename, camfile, order) @@ -209,23 +229,3 @@ class InternalLayer(PCBLayer): if not hasattr(other, 'order'): raise TypeError() return (self.order <= other.order) - - -class LayerSet(object): - - def __init__(self, name, layers, **kwargs): - super(LayerSet, self).__init__(**kwargs) - self.name = name - self.layers = list(layers) - - def __len__(self): - return len(self.layers) - - def __getitem__(self, item): - return self.layers[item] - - def to_render(self): - return self.layers - - def apply_theme(self, theme): - pass -- cgit From 0fedaedb6ebb8cc6abfc218d224a3ab69bb71b56 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 29 Sep 2016 19:43:28 -0400 Subject: Add more layer hints as seen in the wild --- gerber/layers.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'gerber/layers.py') diff --git a/gerber/layers.py b/gerber/layers.py index 93f0e36..c9e451a 100644 --- a/gerber/layers.py +++ b/gerber/layers.py @@ -29,46 +29,46 @@ Hint = namedtuple('Hint', 'layer ext name') hints = [ Hint(layer='top', ext=['gtl', 'cmp', 'top', ], - name=['art01', 'top', 'GTL', 'layer1', 'soldcom', 'comp', ] + name=['art01', 'top', 'GTL', 'layer1', 'soldcom', 'comp', 'F.Cu', ] ), Hint(layer='bottom', ext=['gbl', 'sld', 'bot', 'sol', 'bottom', ], - name=['art02', 'bottom', 'bot', 'GBL', 'layer2', 'soldsold', ] + name=['art02', 'bottom', 'bot', 'GBL', 'layer2', 'soldsold', 'B.Cu', ] ), Hint(layer='internal', ext=['in', 'gt1', 'gt2', 'gt3', 'gt4', 'gt5', 'gt6', 'g1', 'g2', 'g3', 'g4', 'g5', 'g6', ], name=['art', 'internal', 'pgp', 'pwr', 'gp1', 'gp2', 'gp3', 'gp4', - 'gt5', 'gp6', 'gnd', 'ground', ] + 'gt5', 'gp6', 'gnd', 'ground', 'In1.Cu', 'In2.Cu', 'In3.Cu', 'In4.Cu'] ), Hint(layer='topsilk', ext=['gto', 'sst', 'plc', 'ts', 'skt', 'topsilk', ], - name=['sst01', 'topsilk', 'silk', 'slk', 'sst', ] + name=['sst01', 'topsilk', 'silk', 'slk', 'sst', 'F.SilkS'] ), Hint(layer='bottomsilk', - ext=['gbo', 'ssb', 'pls', 'bs', 'skb', 'bottomsilk', ], + ext=['gbo', 'ssb', 'pls', 'bs', 'skb', 'bottomsilk', 'B.SilkS'], name=['bsilk', 'ssb', 'botsilk', ] ), Hint(layer='topmask', ext=['gts', 'stc', 'tmk', 'smt', 'tr', 'topmask', ], name=['sm01', 'cmask', 'tmask', 'mask1', 'maskcom', 'topmask', - 'mst', ] + 'mst', 'F.Mask',] ), Hint(layer='bottommask', ext=['gbs', 'sts', 'bmk', 'smb', 'br', 'bottommask', ], - name=['sm', 'bmask', 'mask2', 'masksold', 'botmask', 'msb', ] + name=['sm', 'bmask', 'mask2', 'masksold', 'botmask', 'msb', 'B.Mask',] ), Hint(layer='toppaste', ext=['gtp', 'tm', 'toppaste', ], - name=['sp01', 'toppaste', 'pst'] + name=['sp01', 'toppaste', 'pst', 'F.Paste'] ), Hint(layer='bottompaste', ext=['gbp', 'bm', 'bottompaste', ], - name=['sp02', 'botpaste', 'psb'] + name=['sp02', 'botpaste', 'psb', 'B.Paste', ] ), Hint(layer='outline', ext=['gko', 'outline', ], - name=['BDR', 'border', 'out', ] + name=['BDR', 'border', 'out', 'Edge.Cuts', ] ), Hint(layer='ipc_netlist', ext=['ipc'], -- cgit From 22e668c75f24174d2090443ed98e804b3737bd84 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 5 Nov 2016 18:30:21 -0400 Subject: Fix tests --- gerber/layers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gerber/layers.py') diff --git a/gerber/layers.py b/gerber/layers.py index c9e451a..212695a 100644 --- a/gerber/layers.py +++ b/gerber/layers.py @@ -46,8 +46,8 @@ hints = [ name=['sst01', 'topsilk', 'silk', 'slk', 'sst', 'F.SilkS'] ), Hint(layer='bottomsilk', - ext=['gbo', 'ssb', 'pls', 'bs', 'skb', 'bottomsilk', 'B.SilkS'], - name=['bsilk', 'ssb', 'botsilk', ] + ext=['gbo', 'ssb', 'pls', 'bs', 'skb', 'bottomsilk',], + name=['bsilk', 'ssb', 'botsilk', 'B.SilkS'] ), Hint(layer='topmask', ext=['gts', 'stc', 'tmk', 'smt', 'tr', 'topmask', ], -- cgit