summaryrefslogtreecommitdiff
path: root/gerber/render_svg.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2014-10-26 20:55:22 -0200
committerPaulo Henrique Silva <ph.silva@gmail.com>2014-10-26 20:55:22 -0200
commitd5c8d896d87e02d32d0c0758a09f051c141006f6 (patch)
tree50e2788e5dfc63db909a3613fff6934a0e80b153 /gerber/render_svg.py
parentd0eedf3dd7ee4fbf19f51de319e48dd964b93561 (diff)
parent4f076d7b769b0f488888d268a9a199b7545afdd7 (diff)
downloadgerbonara-d5c8d896d87e02d32d0c0758a09f051c141006f6.tar.gz
gerbonara-d5c8d896d87e02d32d0c0758a09f051c141006f6.tar.bz2
gerbonara-d5c8d896d87e02d32d0c0758a09f051c141006f6.zip
Merge pull request #4 from hamiltonkibbe/master
Many fixes in parsing, rendering and new features
Diffstat (limited to 'gerber/render_svg.py')
-rw-r--r--gerber/render_svg.py114
1 files changed, 0 insertions, 114 deletions
diff --git a/gerber/render_svg.py b/gerber/render_svg.py
deleted file mode 100644
index cb42371..0000000
--- a/gerber/render_svg.py
+++ /dev/null
@@ -1,114 +0,0 @@
-#! /usr/bin/env python
-# -*- coding: utf-8 -*-
-
-# Copyright 2013-2014 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, INTERPOLATION_LINEAR, INTERPOLATION_ARC
-import svgwrite
-
-
-class Shape(object):
- pass
-
-
-class Circle(Shape):
- def __init__(self, diameter=0.0):
- self.diameter = diameter
-
- def draw(self, ctx, x, y):
- return ctx.dwg.line(start=(ctx.x*300, ctx.y*300), end=(x*300, y*300), stroke="rgb(184, 115, 51)",
- stroke_width=2, stroke_linecap="round")
-
- def flash(self, ctx, x, y):
- return ctx.dwg.circle(center=(x*300, y*300), r=300*(self.diameter/2.0), fill="rgb(184, 115, 51)")
-
-
-class Rect(Shape):
- def __init__(self, size=(0, 0)):
- self.size = size
-
- def draw(self, ctx, x, y):
- return ctx.dwg.line(start=(ctx.x*300, ctx.y*300), end=(x*300, y*300), stroke="rgb(184, 115, 51)",
- stroke_width=2, stroke_linecap="butt")
-
- def flash(self, ctx, x, y):
- # Center the rectange on x,y
- x -= (self.size[0] / 2.0)
- y -= (self.size[0] / 2.0)
- return ctx.dwg.rect(insert=(300*x, 300*y), size=(300*float(self.size[0]), 300*float(self.size[1])),
- fill="rgb(184, 115, 51)")
-
-
-class GerberSvgContext(GerberContext):
- def __init__(self):
- GerberContext.__init__(self)
-
- self.apertures = {}
- self.dwg = svgwrite.Drawing()
- self.dwg.add(self.dwg.rect(insert=(0, 0), size=(2000, 2000), fill="black"))
-
- def define_aperture(self, d, shape, modifiers):
- aperture = None
- if shape == "C":
- aperture = Circle(diameter=float(modifiers[0][0]))
- elif shape == "R":
- aperture = Rect(size=modifiers[0][0:2])
-
- self.apertures[d] = aperture
-
- def stroke(self, x, y):
- super(GerberSvgContext, self).stroke(x, y)
-
- if self.interpolation == INTERPOLATION_LINEAR:
- self.line(x, y)
- elif self.interpolation == INTERPOLATION_ARC:
- self.arc(x, y)
-
- def line(self, x, y):
- super(GerberSvgContext, self).line(x, y)
-
- x, y = self.resolve(x, y)
-
- ap = self.apertures.get(str(self.aperture), None)
- if ap is None:
- return
-
- self.dwg.add(ap.draw(self, x, y))
-
- self.move(x, y, resolve=False)
-
- def arc(self, x, y):
- super(GerberSvgContext, self).arc(x, y)
-
- def flash(self, x, y):
- super(GerberSvgContext, self).flash(x, y)
-
- x, y = self.resolve(x, y)
-
- ap = self.apertures.get(str(self.aperture), None)
- if ap is None:
- return
-
- self.dwg.add(ap.flash(self, x, y))
-
- self.move(x, y, resolve=False)
-
- def drill(self, x, y, diameter):
- hit = self.dwg.circle(center=(x*300, y*300), r=300*(diameter/2.0), fill="gray")
- self.dwg.add(hit)
-
-
- def dump(self,filename='teste.svg'):
- self.dwg.saveas(filename)