From bfe14841604b6be403e7123e8b6667b1f0aff6f6 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 15 Feb 2015 03:29:47 -0500 Subject: Add cairo example code, and use example-generated image in readme --- examples/cairo_example.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/cairo_example.py (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py new file mode 100644 index 0000000..c243731 --- /dev/null +++ b/examples/cairo_example.py @@ -0,0 +1,68 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- + +# Copyright 2015 Hamilton Kibbe + +# 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. + +""" +This example demonstrates the use of pcb-tools with cairo to render a composite +image from a set of gerber files. Each layer is loaded and drawn using a +GerberCairoContext. The color and opacity of each layer can be set individually. +Once all thedesired layers are drawn on the context, the context is written to +a .png file. +""" + +import os +from gerber import read +from gerber.render import GerberCairoContext + +GERBER_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 'gerbers')) + + + + + +# Open the gerber files +copper = read(os.path.join(GERBER_FOLDER, 'copper.GTL')) +mask = read(os.path.join(GERBER_FOLDER, 'soldermask.GTS')) +silk = read(os.path.join(GERBER_FOLDER, 'silkscreen.GTO')) +drill = read(os.path.join(GERBER_FOLDER, 'ncdrill.DRD')) + + +# Create a new drawing context +ctx = GerberCairoContext() + +# Draw the copper layer +copper.render(ctx) + +# Set opacity and color for soldermask layer +ctx.alpha = 0.65 +ctx.color = (0.2, 0.2, 0.75) + +# Draw the soldermask layer +mask.render(ctx) + +# Set opacity and color for silkscreen layer +ctx.alpha = 0.9 +ctx.color = (1, 1, 1) + +# Draw the silkscreen layer +silk.render(ctx) + +# Set opacity for drill layer +ctx.alpha = 1. +drill.render(ctx) + +# Write output to png file +ctx.dump(os.path.join(os.path.dirname(__file__), 'cairo_example.png')) \ No newline at end of file -- cgit From b3e0ceb5c3ec755b09d2f005b8e3dcbed22d45a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Fri, 20 Feb 2015 22:24:34 -0500 Subject: Add IPC-D-356 Netlist Parsing --- examples/cairo_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index c243731..49c4d0c 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -47,14 +47,14 @@ ctx = GerberCairoContext() copper.render(ctx) # Set opacity and color for soldermask layer -ctx.alpha = 0.65 +ctx.alpha = 0.6 ctx.color = (0.2, 0.2, 0.75) # Draw the soldermask layer mask.render(ctx) # Set opacity and color for silkscreen layer -ctx.alpha = 0.9 +ctx.alpha = 0.85 ctx.color = (1, 1, 1) # Draw the silkscreen layer @@ -65,4 +65,4 @@ ctx.alpha = 1. drill.render(ctx) # Write output to png file -ctx.dump(os.path.join(os.path.dirname(__file__), 'cairo_example.png')) \ No newline at end of file +ctx.dump(os.path.join(os.path.dirname(__file__), 'cairo_example.png')) -- cgit From dd63b169f177389602e17bc6ced53bd0f1ba0de3 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 10 Oct 2015 16:51:21 -0400 Subject: Allow files to be read from strings per #37 Adds a loads() method to the top level module which generates a GerberFile or ExcellonFile from a string --- examples/cairo_example.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index 49c4d0c..a312e89 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -30,9 +30,6 @@ from gerber.render import GerberCairoContext GERBER_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 'gerbers')) - - - # Open the gerber files copper = read(os.path.join(GERBER_FOLDER, 'copper.GTL')) mask = read(os.path.join(GERBER_FOLDER, 'soldermask.GTS')) -- cgit 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 --- examples/cairo_example.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index a312e89..f2f6723 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -25,7 +25,7 @@ a .png file. import os from gerber import read -from gerber.render import GerberCairoContext +from gerber.render import GerberCairoContext, theme GERBER_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 'gerbers')) @@ -40,25 +40,30 @@ drill = read(os.path.join(GERBER_FOLDER, 'ncdrill.DRD')) # Create a new drawing context ctx = GerberCairoContext() +# Set opacity and color for copper layer +ctx.alpha = 1.0 +ctx.color = theme.COLORS['hasl copper'] + # Draw the copper layer copper.render(ctx) # Set opacity and color for soldermask layer -ctx.alpha = 0.6 -ctx.color = (0.2, 0.2, 0.75) +ctx.alpha = 0.75 +ctx.color = theme.COLORS['green soldermask'] # Draw the soldermask layer -mask.render(ctx) +mask.render(ctx, invert=True) # Set opacity and color for silkscreen layer -ctx.alpha = 0.85 -ctx.color = (1, 1, 1) +ctx.alpha = 1.0 +ctx.color = theme.COLORS['white'] # Draw the silkscreen layer silk.render(ctx) # Set opacity for drill layer -ctx.alpha = 1. +ctx.alpha = 1.0 +ctx.color = theme.COLORS['black'] drill.render(ctx) # Write output to png file -- 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 --- examples/cairo_example.py | 1 - 1 file changed, 1 deletion(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index f2f6723..14a7037 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -36,7 +36,6 @@ mask = read(os.path.join(GERBER_FOLDER, 'soldermask.GTS')) silk = read(os.path.join(GERBER_FOLDER, 'silkscreen.GTO')) drill = read(os.path.join(GERBER_FOLDER, 'ncdrill.DRD')) - # Create a new drawing context ctx = GerberCairoContext() -- 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 --- examples/cairo_example.py | 60 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 26 deletions(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index 14a7037..fcd7a44 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -24,46 +24,54 @@ a .png file. """ import os -from gerber import read -from gerber.render import GerberCairoContext, theme +from gerber import load_layer +from gerber.render import GerberCairoContext, RenderSettings, theme GERBER_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 'gerbers')) # Open the gerber files -copper = read(os.path.join(GERBER_FOLDER, 'copper.GTL')) -mask = read(os.path.join(GERBER_FOLDER, 'soldermask.GTS')) -silk = read(os.path.join(GERBER_FOLDER, 'silkscreen.GTO')) -drill = read(os.path.join(GERBER_FOLDER, 'ncdrill.DRD')) +copper = load_layer(os.path.join(GERBER_FOLDER, 'copper.GTL')) +mask = load_layer(os.path.join(GERBER_FOLDER, 'soldermask.GTS')) +silk = load_layer(os.path.join(GERBER_FOLDER, 'silkscreen.GTO')) +drill = load_layer(os.path.join(GERBER_FOLDER, 'ncdrill.DRD')) # Create a new drawing context ctx = GerberCairoContext() -# Set opacity and color for copper layer -ctx.alpha = 1.0 -ctx.color = theme.COLORS['hasl copper'] - -# Draw the copper layer -copper.render(ctx) - -# Set opacity and color for soldermask layer -ctx.alpha = 0.75 -ctx.color = theme.COLORS['green soldermask'] +# Draw the copper layer. render_layer() uses the default color scheme for the +# layer, based on the layer type. Copper layers are rendered as +ctx.render_layer(copper) # Draw the soldermask layer -mask.render(ctx, invert=True) +ctx.render_layer(mask) -# Set opacity and color for silkscreen layer -ctx.alpha = 1.0 -ctx.color = theme.COLORS['white'] -# Draw the silkscreen layer -silk.render(ctx) +# The default style can be overridden by passing a RenderSettings instance to +# render_layer(). +# First, create a settings object: +our_settings = RenderSettings(color=theme.COLORS['white'], alpha=0.85) -# Set opacity for drill layer -ctx.alpha = 1.0 -ctx.color = theme.COLORS['black'] -drill.render(ctx) +# Draw the silkscreen layer, and specify the rendering settings to use +ctx.render_layer(silk, settings=our_settings) + +# Draw the drill layer +ctx.render_layer(drill) # Write output to png file ctx.dump(os.path.join(os.path.dirname(__file__), 'cairo_example.png')) + +# Load the bottom layers +copper = load_layer(os.path.join(GERBER_FOLDER, 'bottom_copper.GBL')) +mask = load_layer(os.path.join(GERBER_FOLDER, 'bottom_mask.GBS')) + +# Clear the drawing +ctx.clear() + +# Render bottom layers +ctx.render_layer(copper) +ctx.render_layer(mask) +ctx.render_layer(drill) + +# Write png file +ctx.dump(os.path.join(os.path.dirname(__file__), 'cairo_bottom.png')) -- cgit From 5245fb925684b4ebe056e6509bfeca6b167903b5 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Tue, 5 Jun 2018 08:57:37 -0400 Subject: Fix hard requirement of cairo per #83, and add stubs for required subclass methods to GerberContext per #84 --- examples/cairo_example.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/cairo_example.py') diff --git a/examples/cairo_example.py b/examples/cairo_example.py index fcd7a44..ecfed4d 100644 --- a/examples/cairo_example.py +++ b/examples/cairo_example.py @@ -25,7 +25,8 @@ a .png file. import os from gerber import load_layer -from gerber.render import GerberCairoContext, RenderSettings, theme +from gerber.render import RenderSettings, theme +from gerber.render.cairo_backend import GerberCairoContext GERBER_FOLDER = os.path.abspath(os.path.join(os.path.dirname(__file__), 'gerbers')) -- cgit