From 1cb269131bc52f0b1a1e69cef0466f2d994d52a8 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 19 Dec 2015 21:54:29 -0500 Subject: Allow negative render of soldermask per #50 Update example code and rendering to show change --- gerber/render/theme.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 gerber/render/theme.py (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py new file mode 100644 index 0000000..5d39bb6 --- /dev/null +++ b/gerber/render/theme.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2013-2014 Paulo Henrique Silva + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +COLORS = { + 'black': (0.0, 0.0, 0.0), + 'white': (1.0, 1.0, 1.0), + 'fr-4': (0.702, 0.655, 0.192), + 'green soldermask': (0.0, 0.612, 0.396), + 'blue soldermask': (0.059, 0.478, 0.651), + 'red soldermask': (0.968, 0.169, 0.165), + 'black soldermask': (0.298, 0.275, 0.282), + 'enig copper': (0.780, 0.588, 0.286), + 'hasl copper': (0.871, 0.851, 0.839) +} + + +class RenderSettings(object): + def __init__(self, color, alpha=1.0, invert=False): + self.color = color + self.alpha = alpha + self.invert = False + + +class Theme(object): + def __init__(self, **kwargs): + self.background = kwargs.get('background', RenderSettings(COLORS['black'], 0.0)) + self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) + self.topsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) + self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True)) + self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True)) + self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) + self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) + self.drill = kwargs.get('drill', self.background) + + -- cgit From af5541ac93b222c05229ee05c9def8dbae5f6e25 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 20 Dec 2015 23:54:20 -0500 Subject: Allow renderer to write to memory per #38 Some updates to rendering colors/themes --- gerber/render/theme.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 5d39bb6..eae3735 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -19,12 +19,13 @@ COLORS = { 'black': (0.0, 0.0, 0.0), 'white': (1.0, 1.0, 1.0), - 'fr-4': (0.702, 0.655, 0.192), + 'fr-4': (0.290, 0.345, 0.0), 'green soldermask': (0.0, 0.612, 0.396), 'blue soldermask': (0.059, 0.478, 0.651), 'red soldermask': (0.968, 0.169, 0.165), 'black soldermask': (0.298, 0.275, 0.282), - 'enig copper': (0.780, 0.588, 0.286), + 'purple soldermask': (0.2, 0.0, 0.334), + 'enig copper': (0.686, 0.525, 0.510), 'hasl copper': (0.871, 0.851, 0.839) } @@ -40,11 +41,19 @@ class Theme(object): def __init__(self, **kwargs): self.background = kwargs.get('background', RenderSettings(COLORS['black'], 0.0)) self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) - self.topsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) - self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True)) + self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True)) + self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], 0.8, True)) self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) self.drill = kwargs.get('drill', self.background) +THEMES = { + 'Default': Theme(), + 'Osh Park': Theme(top=COLORS['enig copper'], + bottom=COLORS['enig copper'], + topmask=COLORS['purple soldermask'], + bottommask=COLORS['purple soldermask']), +} + -- cgit From 6f876edd09d9b81649691e529f85653f14b8fd1c Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 22 Dec 2015 02:45:48 -0500 Subject: Add PCB interface this incorporates some of @chintal's layers.py changes PCB.from_directory() simplifies loading of multiple gerbers the PCB() class should be pretty helpful going forward... the context classes could use some cleaning up, although I'd like to wait until the freecad stuff gets merged, that way we can try to refactor the context base to support more use cases --- gerber/render/theme.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index eae3735..5978831 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -19,6 +19,9 @@ COLORS = { 'black': (0.0, 0.0, 0.0), 'white': (1.0, 1.0, 1.0), + 'red': (1.0, 0.0, 0.0), + 'green': (0.0, 1.0, 0.0), + 'blue' : (0.0, 0.0, 1.0), 'fr-4': (0.290, 0.345, 0.0), 'green soldermask': (0.0, 0.612, 0.396), 'blue soldermask': (0.059, 0.478, 0.651), @@ -31,29 +34,38 @@ COLORS = { class RenderSettings(object): - def __init__(self, color, alpha=1.0, invert=False): + def __init__(self, color, alpha=1.0, invert=False, mirror=False): self.color = color self.alpha = alpha - self.invert = False + self.invert = invert + self.mirror = mirror class Theme(object): - def __init__(self, **kwargs): - self.background = kwargs.get('background', RenderSettings(COLORS['black'], 0.0)) + def __init__(self, name=None, **kwargs): + self.name = 'Default' if name is None else name + self.background = kwargs.get('background', RenderSettings(COLORS['black'], alpha=0.0)) self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) - self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], 0.8, True)) - self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], 0.8, True)) + self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) + self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) - self.drill = kwargs.get('drill', self.background) + self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) + self.ipc_netlist = kwargs.get('ipc_netlist', RenderSettings(COLORS['red'])) + def __getitem__(self, key): + return getattr(self, key) THEMES = { 'Default': Theme(), - 'Osh Park': Theme(top=COLORS['enig copper'], - bottom=COLORS['enig copper'], - topmask=COLORS['purple soldermask'], - bottommask=COLORS['purple soldermask']), + 'OSH Park': Theme(name='OSH Park', + top=RenderSettings(COLORS['enig copper']), + bottom=RenderSettings(COLORS['enig copper']), + topmask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True), + bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True)), + 'Blue': Theme(name='Blue', + topmask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True), + bottommask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True)), } -- cgit From 6a005436b475e3517fd6a583473b60e601bcc661 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 1 Jan 2016 12:25:38 -0500 Subject: Refactor a little pulled all rendering stuff out of the pcb/layer objects --- gerber/render/theme.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 5978831..e538df8 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -16,6 +16,8 @@ # limitations under the License. +from .render import RenderSettings + COLORS = { 'black': (0.0, 0.0, 0.0), 'white': (1.0, 1.0, 1.0), @@ -33,14 +35,6 @@ COLORS = { } -class RenderSettings(object): - def __init__(self, color, alpha=1.0, invert=False, mirror=False): - self.color = color - self.alpha = alpha - self.invert = invert - self.mirror = mirror - - class Theme(object): def __init__(self, name=None, **kwargs): self.name = 'Default' if name is None else name @@ -57,8 +51,13 @@ class Theme(object): def __getitem__(self, key): return getattr(self, key) + def get(self, key, noneval=None): + val = getattr(self, key) + return val if val is not None else noneval + + THEMES = { - 'Default': Theme(), + 'default': Theme(), 'OSH Park': Theme(name='OSH Park', top=RenderSettings(COLORS['enig copper']), bottom=RenderSettings(COLORS['enig copper']), -- cgit 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/render/theme.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index e538df8..6135ccb 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -23,7 +23,7 @@ COLORS = { 'white': (1.0, 1.0, 1.0), 'red': (1.0, 0.0, 0.0), 'green': (0.0, 1.0, 0.0), - 'blue' : (0.0, 0.0, 1.0), + 'blue': (0.0, 0.0, 1.0), 'fr-4': (0.290, 0.345, 0.0), 'green soldermask': (0.0, 0.612, 0.396), 'blue soldermask': (0.059, 0.478, 0.651), @@ -36,6 +36,7 @@ COLORS = { class Theme(object): + def __init__(self, name=None, **kwargs): self.name = 'Default' if name is None else name self.background = kwargs.get('background', RenderSettings(COLORS['black'], alpha=0.0)) @@ -67,4 +68,3 @@ THEMES = { topmask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True), bottommask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True)), } - -- cgit From 66a0d09e72b078da5820820aa5c6a2a7d7430507 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 04:39:55 -0500 Subject: Add support for mirrored rendering - The default theme now renders the bottom layers mirrored. - see https://github.com/curtacircuitos/pcb-tools/blob/master/examples/pcb_bottom.png for an example. --- gerber/render/theme.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 6135ccb..4d325c5 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -41,11 +41,11 @@ class Theme(object): self.name = 'Default' if name is None else name self.background = kwargs.get('background', RenderSettings(COLORS['black'], alpha=0.0)) self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) - self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'])) + self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'], mirror=True)) self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) - self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) + self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True, mirror=True)) self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) - self.bottom = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) + self.bottom = kwargs.get('bottom', RenderSettings(COLORS['hasl copper'], mirror=True)) self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) self.ipc_netlist = kwargs.get('ipc_netlist', RenderSettings(COLORS['red'])) @@ -61,9 +61,10 @@ THEMES = { 'default': Theme(), 'OSH Park': Theme(name='OSH Park', top=RenderSettings(COLORS['enig copper']), - bottom=RenderSettings(COLORS['enig copper']), + bottom=RenderSettings(COLORS['enig copper'], mirror=True), topmask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True), - bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True)), + bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True, mirror=True)), + 'Blue': Theme(name='Blue', topmask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True), bottommask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True)), -- 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/render/theme.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 4d325c5..d382a8d 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -25,12 +25,12 @@ COLORS = { 'green': (0.0, 1.0, 0.0), 'blue': (0.0, 0.0, 1.0), 'fr-4': (0.290, 0.345, 0.0), - 'green soldermask': (0.0, 0.612, 0.396), + 'green soldermask': (0.0, 0.412, 0.278), 'blue soldermask': (0.059, 0.478, 0.651), 'red soldermask': (0.968, 0.169, 0.165), 'black soldermask': (0.298, 0.275, 0.282), 'purple soldermask': (0.2, 0.0, 0.334), - 'enig copper': (0.686, 0.525, 0.510), + 'enig copper': (0.694, 0.533, 0.514), 'hasl copper': (0.871, 0.851, 0.839) } @@ -39,11 +39,11 @@ class Theme(object): def __init__(self, name=None, **kwargs): self.name = 'Default' if name is None else name - self.background = kwargs.get('background', RenderSettings(COLORS['black'], alpha=0.0)) + self.background = kwargs.get('background', RenderSettings(COLORS['fr-4'])) self.topsilk = kwargs.get('topsilk', RenderSettings(COLORS['white'])) self.bottomsilk = kwargs.get('bottomsilk', RenderSettings(COLORS['white'], mirror=True)) - self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True)) - self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.8, invert=True, mirror=True)) + self.topmask = kwargs.get('topmask', RenderSettings(COLORS['green soldermask'], alpha=0.85, invert=True)) + self.bottommask = kwargs.get('bottommask', RenderSettings(COLORS['green soldermask'], alpha=0.85, invert=True, mirror=True)) self.top = kwargs.get('top', RenderSettings(COLORS['hasl copper'])) self.bottom = kwargs.get('bottom', RenderSettings(COLORS['hasl copper'], mirror=True)) self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) @@ -60,12 +60,21 @@ class Theme(object): THEMES = { 'default': Theme(), 'OSH Park': Theme(name='OSH Park', + background=RenderSettings(COLORS['purple soldermask']), top=RenderSettings(COLORS['enig copper']), bottom=RenderSettings(COLORS['enig copper'], mirror=True), - topmask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True), - bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.8, invert=True, mirror=True)), + topmask=RenderSettings(COLORS['purple soldermask'], alpha=0.85, invert=True), + bottommask=RenderSettings(COLORS['purple soldermask'], alpha=0.85, invert=True, mirror=True), + topsilk=RenderSettings(COLORS['white'], alpha=0.8), + bottomsilk=RenderSettings(COLORS['white'], alpha=0.8, mirror=True)), 'Blue': Theme(name='Blue', topmask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True), bottommask=RenderSettings(COLORS['blue soldermask'], alpha=0.8, invert=True)), + + 'Transparent Copper': Theme(name='Transparent', + background=RenderSettings((0.9, 0.9, 0.9)), + top=RenderSettings(COLORS['red'], alpha=0.5), + bottom=RenderSettings(COLORS['blue'], alpha=0.5), + drill=RenderSettings((0.3, 0.3, 0.3))), } -- 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/render/theme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index d382a8d..2887216 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -53,7 +53,7 @@ class Theme(object): return getattr(self, key) def get(self, key, noneval=None): - val = getattr(self, key) + val = getattr(self, key, None) return val if val is not None else noneval -- cgit From 0c862895651a1d5b7f13e42a1af94fd4418b0400 Mon Sep 17 00:00:00 2001 From: Chintalagiri Shashank Date: Sat, 11 May 2019 03:18:09 +0530 Subject: Add a new transparant theme for multilayer renders. --- gerber/render/theme.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'gerber/render/theme.py') diff --git a/gerber/render/theme.py b/gerber/render/theme.py index 2887216..2f558a1 100644 --- a/gerber/render/theme.py +++ b/gerber/render/theme.py @@ -23,6 +23,7 @@ COLORS = { 'white': (1.0, 1.0, 1.0), 'red': (1.0, 0.0, 0.0), 'green': (0.0, 1.0, 0.0), + 'yellow': (1.0, 1.0, 0), 'blue': (0.0, 0.0, 1.0), 'fr-4': (0.290, 0.345, 0.0), 'green soldermask': (0.0, 0.412, 0.278), @@ -35,6 +36,18 @@ COLORS = { } +SPECTRUM = [ + (0.804, 0.216, 0), + (0.78, 0.776, 0.251), + (0.545, 0.451, 0.333), + (0.545, 0.137, 0.137), + (0.329, 0.545, 0.329), + (0.133, 0.545, 0.133), + (0, 0.525, 0.545), + (0.227, 0.373, 0.804), +] + + class Theme(object): def __init__(self, name=None, **kwargs): @@ -48,10 +61,22 @@ class Theme(object): self.bottom = kwargs.get('bottom', RenderSettings(COLORS['hasl copper'], mirror=True)) self.drill = kwargs.get('drill', RenderSettings(COLORS['black'])) self.ipc_netlist = kwargs.get('ipc_netlist', RenderSettings(COLORS['red'])) + self._internal = kwargs.get('internal', [RenderSettings(x) for x in SPECTRUM]) + self._internal_gen = None def __getitem__(self, key): return getattr(self, key) + @property + def internal(self): + if not self._internal_gen: + self._internal_gen = self._internal_gen_func() + return next(self._internal_gen) + + def _internal_gen_func(self): + for setting in self._internal: + yield setting + def get(self, key, noneval=None): val = getattr(self, key, None) return val if val is not None else noneval @@ -77,4 +102,11 @@ THEMES = { top=RenderSettings(COLORS['red'], alpha=0.5), bottom=RenderSettings(COLORS['blue'], alpha=0.5), drill=RenderSettings((0.3, 0.3, 0.3))), + + 'Transparent Multilayer': Theme(name='Transparent Multilayer', + background=RenderSettings((0, 0, 0)), + top=RenderSettings(SPECTRUM[0], alpha=0.8), + bottom=RenderSettings(SPECTRUM[-1], alpha=0.8), + drill=RenderSettings((0.3, 0.3, 0.3)), + internal=[RenderSettings(x, alpha=0.5) for x in SPECTRUM[1:-1]]), } -- cgit