Last active
May 3, 2016 19:47
-
-
Save pklaus/2a93d3cb17c107d2652d to your computer and use it in GitHub Desktop.
A tool to convert Gerber files to SVG. Uses pcb-tools.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Inspired by | |
# https://github.com/curtacircuitos/pcb-tools/blob/master/gerber/__main__.py | |
# Copyright 2013-2014 Paulo Henrique Silva <[email protected]> | |
# 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. | |
def main(): | |
from gerber.common import read | |
from gerber.render import GerberSvgContext | |
import gerber.render.svgwrite_backend as svgwrite_backend | |
import argparse | |
parser = argparse.ArgumentParser(description=__doc__) | |
parser.add_argument('filenames', metavar='FILENAME', nargs='+', | |
help='The Gerber files to convert') | |
parser.add_argument('--dpi', type=float, default=400., | |
help='The scale to use for the SVG output') | |
parser.add_argument('--alpha', type=float, default=.96, | |
help='The alpha value of traces (between 0.0 - 1.0, default: 0.95).') | |
parser.add_argument('--outfile', '-o', default='converted-from-gerber.svg', | |
help='The output file to write') | |
args = parser.parse_args() | |
if args.alpha > 1.0 or args.alpha < 0.0: parser.error('alpha must be in the range [0.0; 1.0]') | |
svgwrite_backend.SCALE = args.dpi | |
ctx = GerberSvgContext() | |
ctx.alpha = args.alpha | |
for filename in args.filenames: | |
print("parsing %s" % filename) | |
if 'GTO' in filename or 'GBO' in filename: | |
ctx.color = (1, 1, 1) | |
ctx.alpha = 0.8 | |
elif 'GTS' in filename or 'GBS' in filename: | |
ctx.color = (0.2, 0.2, 0.75) | |
ctx.alpha = 0.8 | |
gerberfile = read(filename) | |
gerberfile.render(ctx) | |
print('Saving image to {}'.format(args.outfile)) | |
ctx.dump(args.outfile) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment