summaryrefslogtreecommitdiff
path: root/gerber
diff options
context:
space:
mode:
authorGarret Fick <garret@fickworkshop.com>2015-11-18 11:38:43 +0800
committerGarret Fick <garret@fickworkshop.com>2015-11-18 11:38:43 +0800
commitfc5d1898f55ce064a529b404abb8679212252f32 (patch)
tree6808c151fccc1789a5ba9709c8972c0bbb218096 /gerber
parent6e29b9bcae8167dbb9c75e5a79e09886b952e988 (diff)
parentba82d60cb8a886a82d4c4199473bb1189efc6419 (diff)
downloadgerbonara-fc5d1898f55ce064a529b404abb8679212252f32.tar.gz
gerbonara-fc5d1898f55ce064a529b404abb8679212252f32.tar.bz2
gerbonara-fc5d1898f55ce064a529b404abb8679212252f32.zip
Merge pull request #1 from curtacircuitos/master
Merge from upstream
Diffstat (limited to 'gerber')
-rw-r--r--gerber/__main__.py4
-rw-r--r--gerber/render/__init__.py1
-rw-r--r--gerber/render/svgwrite_backend.py130
3 files changed, 2 insertions, 133 deletions
diff --git a/gerber/__main__.py b/gerber/__main__.py
index 195973b..6643b54 100644
--- a/gerber/__main__.py
+++ b/gerber/__main__.py
@@ -17,14 +17,14 @@
if __name__ == '__main__':
from gerber.common import read
- from gerber.render import GerberSvgContext
+ from gerber.render import GerberCairoContext
import sys
if len(sys.argv) < 2:
sys.stderr.write("Usage: python -m gerber <filename> <filename>...\n")
sys.exit(1)
- ctx = GerberSvgContext()
+ ctx = GerberCairoContext()
ctx.alpha = 0.95
for filename in sys.argv[1:]:
print("parsing %s" % filename)
diff --git a/gerber/render/__init__.py b/gerber/render/__init__.py
index 1e60792..f76d28f 100644
--- a/gerber/render/__init__.py
+++ b/gerber/render/__init__.py
@@ -24,5 +24,4 @@ SVG is the only supported format.
"""
-from .svgwrite_backend import GerberSvgContext
from .cairo_backend import GerberCairoContext
diff --git a/gerber/render/svgwrite_backend.py b/gerber/render/svgwrite_backend.py
deleted file mode 100644
index f8136e0..0000000
--- a/gerber/render/svgwrite_backend.py
+++ /dev/null
@@ -1,130 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Copyright 2014 Hamilton Kibbe <ham@hamiltonkib.be>
-# Based on render_svg.py by Paulo Henrique Silva <ph.silva@gmail.com>
-
-# 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.
-
-from .render import GerberContext
-from operator import mul
-import math
-import svgwrite
-
-from ..primitives import *
-
-SCALE = 400.
-
-
-def svg_color(color):
- color = tuple([int(ch * 255) for ch in color])
- return 'rgb(%d, %d, %d)' % color
-
-
-class GerberSvgContext(GerberContext):
- def __init__(self):
- GerberContext.__init__(self)
- self.scale = (SCALE, -SCALE)
- self.dwg = svgwrite.Drawing()
- self.background = False
-
- def dump(self, filename):
- self.dwg.saveas(filename)
-
- def set_bounds(self, bounds):
- xbounds, ybounds = bounds
- size = (SCALE * (xbounds[1] - xbounds[0]),
- SCALE * (ybounds[1] - ybounds[0]))
- if not self.background:
- vbox = '%f, %f, %f, %f' % (SCALE * xbounds[0], -SCALE * ybounds[1],
- size[0], size[1])
- self.dwg = svgwrite.Drawing(viewBox=vbox)
- rect = self.dwg.rect(insert=(SCALE * xbounds[0],
- -SCALE * ybounds[1]),
- size=size,
- fill=svg_color(self.background_color))
- self.dwg.add(rect)
- self.background = True
-
- def _render_line(self, line, color):
- start = map(mul, line.start, self.scale)
- end = map(mul, line.end, self.scale)
- if isinstance(line.aperture, Circle):
- width = line.aperture.diameter if line.aperture.diameter != 0 else 0.001
- aline = self.dwg.line(start=start, end=end,
- stroke=svg_color(color),
- stroke_width=SCALE * width,
- stroke_linecap='round')
- aline.stroke(opacity=self.alpha)
- self.dwg.add(aline)
- elif isinstance(line.aperture, Rectangle):
- points = [tuple(map(mul, point, self.scale)) for point in line.vertices]
- path = self.dwg.path(d='M %f, %f' % points[0],
- fill=svg_color(color),
- stroke='none')
- path.fill(opacity=self.alpha)
- for point in points[1:]:
- path.push('L %f, %f' % point)
- self.dwg.add(path)
-
- def _render_arc(self, arc, color):
- start = tuple(map(mul, arc.start, self.scale))
- end = tuple(map(mul, arc.end, self.scale))
- radius = SCALE * arc.radius
- width = arc.aperture.diameter if arc.aperture.diameter != 0 else 0.001
- arc_path = self.dwg.path(d='M %f, %f' % start,
- stroke=svg_color(color),
- stroke_width=SCALE * width)
- large_arc = arc.sweep_angle >= 2 * math.pi
- direction = '-' if arc.direction == 'clockwise' else '+'
- arc_path.push_arc(end, 0, radius, large_arc, direction, True)
- self.dwg.add(arc_path)
-
- def _render_region(self, region, color):
- points = [tuple(map(mul, point, self.scale)) for point in region.points]
- region_path = self.dwg.path(d='M %f, %f' % points[0],
- fill=svg_color(color),
- stroke='none')
- region_path.fill(opacity=self.alpha)
- for point in points[1:]:
- region_path.push('L %f, %f' % point)
- self.dwg.add(region_path)
-
- def _render_circle(self, circle, color):
- center = map(mul, circle.position, self.scale)
- acircle = self.dwg.circle(center=center,
- r = SCALE * circle.radius,
- fill=svg_color(color))
- acircle.fill(opacity=self.alpha)
- self.dwg.add(acircle)
-
- def _render_rectangle(self, rectangle, color):
- center = tuple(map(mul, rectangle.position, self.scale))
- size = tuple(map(mul, (rectangle.width, rectangle.height), map(abs, self.scale)))
- insert = center[0] - size[0] / 2., center[1] - size[1] / 2.
- arect = self.dwg.rect(insert=insert, size=size,
- fill=svg_color(color))
- arect.fill(opacity=self.alpha)
- self.dwg.add(arect)
-
- def _render_obround(self, obround, color):
- self._render_circle(obround.subshapes['circle1'], color)
- self._render_circle(obround.subshapes['circle2'], color)
- self._render_rectangle(obround.subshapes['rectangle'], color)
-
-
- def _render_drill(self, circle, color):
- center = map(mul, circle.position, self.scale)
- hit = self.dwg.circle(center=center, r=SCALE * circle.radius,
- fill=svg_color(color))
- self.dwg.add(hit)