Skip to content

Commit

Permalink
add ipc2581 primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltonkibbe committed Dec 6, 2014
1 parent ab69ee0 commit 29deffc
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 40 deletions.
38 changes: 38 additions & 0 deletions doc/source/about.rst
@@ -0,0 +1,38 @@
About PCB Tools
===============

PCB CAM Files
~~~~~~~~~~~~~

PCB design (artwork) files are most often stored in `Gerber` files. This is
a generic term that may refer to `RS-274X (Gerber) <http://en.wikipedia.org/wiki/Gerber_format>`_,
`ODB++ <http://en.wikipedia.org/wiki/ODB%2B%2B>`_ , or `Excellon <http://en.wikipedia.org/wiki/Excellon_format>`_
files. These file formats are used by the CNC equipment used to manufacutre PCBs.

PCB Tools provides a set of utilities for visualizing and working with PCB design files
in a variety of formats. PCB Tools currently supports the following file formats:

- Gerber (RS-274X)
- Excellon

with planned support for IPC-2581, IPC-D-356 Netlists, ODB++ and more.

Visualization
~~~~~~~~~~~~~~
.. image:: ../../examples/composite_top.png
:alt: Rendering Example

The PCB Tools module provides tools to visualize PCBs and export images in a variety of formats,
including SVG and PNG.


Future Plans
~~~~~~~~~~~~
We are working on adding the following features to PCB Tools:

- Design Rules Checking
- Editing
- Panelization



2 changes: 1 addition & 1 deletion doc/source/index.rst
Expand Up @@ -11,7 +11,7 @@ Contents:
.. toctree::
:maxdepth: 1

intro
about
documentation/index

Indices and tables
Expand Down
19 changes: 0 additions & 19 deletions doc/source/intro.rst

This file was deleted.

16 changes: 15 additions & 1 deletion gerber/gerber_statements.py
@@ -1,5 +1,19 @@
#! /usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# copyright 2014 Hamilton Kibbe <ham@hamiltonkib.be>
#
# 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.
"""
Gerber (RS-274X) Statements
===========================
Expand Down
94 changes: 77 additions & 17 deletions gerber/primitives.py
Expand Up @@ -19,10 +19,11 @@


class Primitive(object):
def __init__(self, level_polarity='dark'):

def __init__(self, level_polarity='dark', rotation=0):
self.level_polarity = level_polarity

self.rotation = rotation

def bounding_box(self):
""" Calculate bounding box
Expand All @@ -36,8 +37,8 @@ def bounding_box(self):
class Line(Primitive):
"""
"""
def __init__(self, start, end, width, level_polarity='dark'):
super(Line, self).__init__(level_polarity)
def __init__(self, start, end, width, **kwargs):
super(Line, self).__init__(**kwargs)
self.start = start
self.end = end
self.width = width
Expand All @@ -61,8 +62,8 @@ def bounding_box(self):
class Arc(Primitive):
"""
"""
def __init__(self, start, end, center, direction, width, level_polarity='dark'):
super(Arc, self).__init__(level_polarity)
def __init__(self, start, end, center, direction, width, **kwargs):
super(Arc, self).__init__(**kwargs)
self.start = start
self.end = end
self.center = center
Expand Down Expand Up @@ -139,8 +140,8 @@ def bounding_box(self):
class Circle(Primitive):
"""
"""
def __init__(self, position, diameter, level_polarity='dark'):
super(Circle, self).__init__(level_polarity)
def __init__(self, position, diameter, **kwargs):
super(Circle, self).__init__(**kwargs)
self.position = position
self.diameter = diameter

Expand All @@ -161,11 +162,29 @@ def stroke_width(self):
return self.diameter


class Ellipse(Primitive):
"""
"""
def __init__(self, position, width, height, **kwargs):
super(Ellipse, self).__init__(**kwargs)
self.position = position
self.width = width
self.height = height

@property
def bounding_box(self):
min_x = self.position[0] - (self.width / 2.0)
max_x = self.position[0] + (self.width / 2.0)
min_y = self.position[1] - (self.height / 2.0)
max_y = self.position[1] + (self.height / 2.0)
return ((min_x, max_x), (min_y, max_y))


class Rectangle(Primitive):
"""
"""
def __init__(self, position, width, height, level_polarity='dark'):
super(Rectangle, self).__init__(level_polarity)
def __init__(self, position, width, height, **kwargs):
super(Rectangle, self).__init__(**kwargs)
self.position = position
self.width = width
self.height = height
Expand Down Expand Up @@ -193,11 +212,23 @@ def stroke_width(self):
return max((self.width, self.height))


class Diamond(Primitive):
pass


class ChamferRectangle(Primitive):
pass


class RoundRectangle(Primitive):
pass


class Obround(Primitive):
"""
"""
def __init__(self, position, width, height, level_polarity='dark'):
super(Obround, self).__init__(level_polarity)
def __init__(self, position, width, height, **kwargs):
super(Obround, self).__init__(**kwargs)
self.position = position
self.width = width
self.height = height
Expand Down Expand Up @@ -242,11 +273,12 @@ def subshapes(self):
self.height)
return {'circle1': circle1, 'circle2': circle2, 'rectangle': rect}


class Polygon(Primitive):
"""
"""
def __init__(self, position, sides, radius, level_polarity='dark'):
super(Polygon, self).__init__(level_polarity)
def __init__(self, position, sides, radius, **kwargs):
super(Polygon, self).__init__(**kwargs)
self.position = position
self.sides = sides
self.radius = radius
Expand All @@ -263,8 +295,8 @@ def bounding_box(self):
class Region(Primitive):
"""
"""
def __init__(self, points, level_polarity='dark'):
super(Region, self).__init__(level_polarity)
def __init__(self, points, **kwargs):
super(Region, self).__init__(**kwargs)
self.points = points

@property
Expand All @@ -277,6 +309,34 @@ def bounding_box(self):
return ((min_x, max_x), (min_y, max_y))


class RoundButterfly(Primitive):
"""
"""
def __init__(self, position, diameter, **kwargs):
super(RoundButterfly, self).__init__(**kwargs)
self.position = position
self.diameter = diameter

@property
def radius(self):
return self.diameter / 2.

@property
def bounding_box(self):
min_x = self.position[0] - self.radius
max_x = self.position[0] + self.radius
min_y = self.position[1] - self.radius
max_y = self.position[1] + self.radius
return ((min_x, max_x), (min_y, max_y))

class SquareButterfly(Primitive):
pass


class Donut(Primitive):
pass


class Drill(Primitive):
"""
"""
Expand Down
4 changes: 2 additions & 2 deletions gerber/rs274x.py
Expand Up @@ -403,10 +403,10 @@ def _evaluate_coord(self, stmt):
end = (x, y)
width = self.apertures[self.aperture].stroke_width
if self.interpolation == 'linear':
self.primitives.append(Line(start, end, width, self.level_polarity))
self.primitives.append(Line(start, end, width, level_polarity=self.level_polarity))
else:
center = (start[0] + stmt.i, start[1] + stmt.j)
self.primitives.append(Arc(start, end, center, self.direction, width, self.level_polarity))
self.primitives.append(Arc(start, end, center, self.direction, width, level_polarity=self.level_polarity))

elif stmt.op == "D02":
pass
Expand Down

0 comments on commit 29deffc

Please sign in to comment.