summaryrefslogtreecommitdiff
path: root/gerber/gerber_statements.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-18 04:31:23 -0500
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2015-02-18 04:31:23 -0500
commit288ac27084b47166ac662402ea340d0aa25d8f56 (patch)
tree792374b99932120fb08e1d689518eed69e0feccb /gerber/gerber_statements.py
parentbc532997aecc60f5a939f9ca6ba55dd3eae27a42 (diff)
downloadgerbonara-288ac27084b47166ac662402ea340d0aa25d8f56.tar.gz
gerbonara-288ac27084b47166ac662402ea340d0aa25d8f56.tar.bz2
gerbonara-288ac27084b47166ac662402ea340d0aa25d8f56.zip
Get unit conversion working for Gerber/Excellon files
Started operations module for file operations/transforms
Diffstat (limited to 'gerber/gerber_statements.py')
-rw-r--r--gerber/gerber_statements.py62
1 files changed, 51 insertions, 11 deletions
diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py
index a6feef6..b231cdb 100644
--- a/gerber/gerber_statements.py
+++ b/gerber/gerber_statements.py
@@ -20,7 +20,8 @@ Gerber (RS-274X) Statements
**Gerber RS-274X file statement classes**
"""
-from .utils import parse_gerber_value, write_gerber_value, decimal_string
+from .utils import (parse_gerber_value, write_gerber_value, decimal_string,
+ inch, metric)
from .am_statements import *
@@ -51,6 +52,15 @@ class Statement(object):
s = s.rstrip() + ">"
return s
+ def to_inch(self):
+ pass
+
+ def to_metric(self):
+ pass
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
class ParamStmt(Statement):
""" Gerber parameter statement Base class
@@ -180,6 +190,12 @@ class MOParamStmt(ParamStmt):
mode = 'MM' if self.mode == 'metric' else 'IN'
return '%MO{0}*%'.format(mode)
+ def to_inch(self):
+ self.mode = 'inch'
+
+ def to_metric(self):
+ self.mode = 'metric'
+
def __str__(self):
mode_str = 'millimeters' if self.mode == 'metric' else 'inches'
return ('<Mode: %s>' % mode_str)
@@ -267,10 +283,10 @@ class ADParamStmt(ParamStmt):
self.modifiers = []
def to_inch(self):
- self.modifiers = [tuple([x / 25.4 for x in modifier]) for modifier in self.modifiers]
+ self.modifiers = [tuple([inch(x) for x in modifier]) for modifier in self.modifiers]
def to_metric(self):
- self.modifiers = [tuple([x * 25.4 for x in modifier]) for modifier in self.modifiers]
+ self.modifiers = [tuple([metric(x) for x in modifier]) for modifier in self.modifiers]
def to_gerber(self, settings=None):
if len(self.modifiers):
@@ -599,6 +615,18 @@ class OFParamStmt(ParamStmt):
ret += 'B' + decimal_string(self.b, precision=5)
return ret + '*%'
+ def to_inch(self):
+ if self.a is not None:
+ self.a = inch(self.a)
+ if self.b is not None:
+ self.b = inch(self.b)
+
+ def to_metric(self):
+ if self.a is not None:
+ self.a = metric(self.a)
+ if self.b is not None:
+ self.b = metric(self.b)
+
def __str__(self):
offset_str = ''
if self.a is not None:
@@ -651,6 +679,18 @@ class SFParamStmt(ParamStmt):
ret += 'B' + decimal_string(self.b, precision=5)
return ret + '*%'
+ def to_inch(self):
+ if self.a is not None:
+ self.a = inch(self.a)
+ if self.b is not None:
+ self.b = inch(self.b)
+
+ def to_metric(self):
+ if self.a is not None:
+ self.a = metric(self.a)
+ if self.b is not None:
+ self.b = metric(self.b)
+
def __str__(self):
scale_factor = ''
if self.a is not None:
@@ -775,25 +815,25 @@ class CoordStmt(Statement):
def to_inch(self):
if self.x is not None:
- self.x = self.x / 25.4
+ self.x = inch(self.x)
if self.y is not None:
- self.y = self.y / 25.4
+ self.y = inch(self.y)
if self.i is not None:
- self.i = self.i / 25.4
+ self.i = inch(self.i)
if self.j is not None:
- self.j = self.j / 25.4
+ self.j = inch(self.j)
if self.function == "G71":
self.function = "G70"
def to_metric(self):
if self.x is not None:
- self.x = self.x * 25.4
+ self.x = metric(self.x)
if self.y is not None:
- self.y = self.y * 25.4
+ self.y = metric(self.y)
if self.i is not None:
- self.i = self.i * 25.4
+ self.i = metric(self.i)
if self.j is not None:
- self.j = self.j * 25.4
+ self.j = metric(self.j)
if self.function == "G70":
self.function = "G71"