summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi Murayama <opiopan@gmail.com>2019-08-25 20:16:53 +0900
committerHiroshi Murayama <opiopan@gmail.com>2019-08-25 20:16:53 +0900
commit13ab9db6e7571f3d0fcb406bfe6795eea9ce4e1c (patch)
treebfde3dd80471f36f8aae2896aeb9eb5863e5d191
parent36956f93fe1773229b6b7bb1b851adf169f97f79 (diff)
downloadgerbonara-13ab9db6e7571f3d0fcb406bfe6795eea9ce4e1c.tar.gz
gerbonara-13ab9db6e7571f3d0fcb406bfe6795eea9ce4e1c.tar.bz2
gerbonara-13ab9db6e7571f3d0fcb406bfe6795eea9ce4e1c.zip
support incremental coordinate for excellon
-rw-r--r--gerberex/composition.py27
-rw-r--r--gerberex/dxf.py31
-rw-r--r--gerberex/excellon.py17
-rw-r--r--tests/expects/dxf_save_mousebites.txt3
4 files changed, 16 insertions, 62 deletions
diff --git a/gerberex/composition.py b/gerberex/composition.py
index 7f691f5..7b1548e 100644
--- a/gerberex/composition.py
+++ b/gerberex/composition.py
@@ -124,8 +124,6 @@ class GerberComposition(Composition):
class DrillComposition(Composition):
def __init__(self, settings=None, comments=None):
super(DrillComposition, self).__init__(settings, comments)
- self.header1_statements = []
- self.header2_statements = []
self.tools = []
self.hits = []
self.dxf_statements = []
@@ -140,12 +138,6 @@ class DrillComposition(Composition):
def dump(self, path):
def statements():
- for s in self.header1_statements:
- yield s.to_excellon(self.settings)
- for t in self.tools:
- yield t.to_excellon(self.settings)
- for s in self.header2_statements:
- yield s.to_excellon(self.settings)
for t in self.tools:
yield ToolSelectionStmt(t.number).to_excellon(self.settings)
for h in self.hits:
@@ -157,6 +149,7 @@ class DrillComposition(Composition):
yield EndOfProgramStmt().to_excellon()
with open(path, 'w') as f:
+ gerberex.excellon.write_excellon_header(f, self.settings, self.tools)
for statement in statements():
f.write(statement + '\n')
@@ -171,20 +164,6 @@ class DrillComposition(Composition):
else:
file.to_inch()
- if not self.header1_statements:
- in_header1 = True
- for statement in file.statements:
- if not isinstance(statement, ToolSelectionStmt):
- if isinstance(statement, ExcellonTool):
- in_header1 = False
- else:
- if in_header1:
- self.header1_statements.append(statement)
- else:
- self.header2_statements.append(statement)
- else:
- break
-
for tool in iter(file.tools.values()):
num = tool.number
tool_map[num] = self._register_tool(tool)
@@ -202,10 +181,6 @@ class DrillComposition(Composition):
else:
file.to_inch()
- if not self.header1_statements:
- self.header1_statements = [file.header]
- self.header2_statements = [file.header2]
-
tool = self._register_tool(ExcellonTool(self.settings, number=1, diameter=file.width))
self.dxf_statements.append((tool.number, file.statements))
diff --git a/gerberex/dxf.py b/gerberex/dxf.py
index ba02f08..389cca9 100644
--- a/gerberex/dxf.py
+++ b/gerberex/dxf.py
@@ -13,6 +13,7 @@ from gerber.excellon_statements import ExcellonTool
from gerber.excellon_statements import CoordinateStmt
from gerberex.utility import is_equal_point, is_equal_value
from gerberex.dxf_path import generate_closed_paths
+from gerberex.excellon import write_excellon_header
ACCEPTABLE_ERROR = 0.001
@@ -465,31 +466,8 @@ class DxfHeaderStatement(object):
)
def to_excellon(self, settings):
- return 'M48\n'\
- 'FMAT,2\n'\
- 'ICI,{0}\n'\
- '{1},{2},{3}.{4}\n'\
- '{5}'.format(
- 'ON' if settings.notation == 'incremental' else 'OFF',
- 'INCH' if settings.units == 'inch' else 'METRIC',
- 'TZ' if settings.zero_suppression == 'leading' else 'LZ',
- '0' * settings.format[0], '0' * settings.format[1],
- 'M72' if settings.units == 'inch' else 'M71'
- )
-
- def to_inch(self):
- pass
-
- def to_metric(self):
pass
-class DxfHeader2Statement(object):
- def to_gerber(self, settings):
- pass
-
- def to_excellon(self, settings):
- return '%'
-
def to_inch(self):
pass
@@ -555,7 +533,6 @@ class DxfFile(CamFile):
self._draw_mode = draw_mode
self.header = DxfHeaderStatement()
- self.header2 = DxfHeader2Statement()
self.aperture = ADParamStmt.circle(dcode=10, diameter=0.0)
self.statements = DxfStatements(
statements, self.units, dcode=self.aperture.d, draw_mode=self.draw_mode)
@@ -607,10 +584,8 @@ class DxfFile(CamFile):
f.write(self.statements.to_gerber(self.settings) + '\n')
f.write('M02*\n')
else:
- tool = ExcellonTool(self.settings, number=1, diameter=self.width)
- f.write(self.header.to_excellon(self.settings) + '\n')
- f.write(tool.to_excellon(self.settings) + '\n')
- f.write(self.header2.to_excellon(self.settings) + '\n')
+ tools = [ExcellonTool(self.settings, number=1, diameter=self.width)]
+ write_excellon_header(f, self.settings, tools)
f.write('T01\n')
f.write(self.statements.to_excellon(self.settings) + '\n')
f.write('M30\n')
diff --git a/gerberex/excellon.py b/gerberex/excellon.py
index 7014a6e..a8c01c7 100644
--- a/gerberex/excellon.py
+++ b/gerberex/excellon.py
@@ -26,6 +26,13 @@ def loads(data, filename=None, settings=None, tools=None, format=None):
file = ExcellonParser(settings, tools).parse_raw(data, filename)
return ExcellonFileEx.from_file(file)
+def write_excellon_header(file, settings, tools):
+ file.write('M48\nFMAT,2\nICI,OFF\n%s\n' %
+ UnitStmtEx(settings.units, settings.zeros, settings.format).to_excellon(settings))
+ for tool in tools:
+ file.write(tool.to_excellon(settings) + '\n')
+ file.write('%%\nG90\n%s\n' % ('M72' if settings.units == 'inch' else 'M71'))
+
class ExcellonFileEx(ExcellonFile):
@classmethod
def from_file(cls, file):
@@ -180,6 +187,7 @@ class ExcellonFileEx(ExcellonFile):
self.tools[tool].to_inch()
for hit in self.hits:
hit.to_inch()
+ self.units = 'inch'
def to_metric(self):
if self.units == 'inch':
@@ -189,17 +197,12 @@ class ExcellonFileEx(ExcellonFile):
self.tools[tool].to_metric()
for hit in self.hits:
hit.to_metric()
+ self.units = 'metric'
def write(self, filename=None):
filename = filename if filename is not None else self.filename
with open(filename, 'w') as f:
-
- for statement in self.statements:
- if not isinstance(statement, ToolSelectionStmt):
- f.write(statement.to_excellon(self.settings) + '\n')
- else:
- break
-
+ write_excellon_header(f, self.settings, [self.tools[t] for t in self.tools])
for tool in iter(self.tools.values()):
f.write(ToolSelectionStmt(
tool.number).to_excellon(self.settings) + '\n')
diff --git a/tests/expects/dxf_save_mousebites.txt b/tests/expects/dxf_save_mousebites.txt
index 4a371ef..e82825a 100644
--- a/tests/expects/dxf_save_mousebites.txt
+++ b/tests/expects/dxf_save_mousebites.txt
@@ -2,9 +2,10 @@ M48
FMAT,2
ICI,OFF
METRIC,TZ,000.000
-M71
T01C0.500
%
+G90
+M71
T01
X1000Y9000
X1000Y8000