1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
import os
import unittest
from gerbonara.gerber import panelize
from gerbonara.gerber.utils import inch, metric
class TestExcellon(unittest.TestCase):
@classmethod
def setUpClass(cls):
os.chdir(os.path.dirname(__file__))
cls.INDIR = 'data'
cls.OUTDIR = 'outputs'
cls.EXPECTSDIR = 'expects'
cls.OUTPREFIX = 'dxf_'
cls.METRIC_FILE = os.path.join(cls.INDIR, 'ref_dxf_metric.dxf')
cls.INCH_FILE = os.path.join(cls.INDIR, 'ref_dxf_inch.dxf')
cls.COMPLEX_FILE = os.path.join(cls.INDIR, 'ref_dxf_complex.dxf')
try:
os.mkdir(cls.OUTDIR)
except FileExistsError:
pass
def _checkResult(self, file):
with open(file, 'r') as f:
data = f.read()
with open(os.path.join(self.EXPECTSDIR, os.path.basename(file)), 'r') as f:
expect = f.read()
self.assertEqual(data, expect)
def test_save_line(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_line.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_LINE
dxf.width = 0.2
dxf.write(outfile)
self._checkResult(outfile)
def test_save_fill(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_fill.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_FILL
dxf.write(outfile)
self._checkResult(outfile)
def test_save_fill_simple(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_fill_simple.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_FILL
dxf.fill_mode = dxf.FM_SIMPLE
dxf.write(outfile)
self._checkResult(outfile)
def test_save_mousebites(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'save_mousebites.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_MOUSE_BITES
dxf.width = 0.5
dxf.pitch = 1.4
dxf.write(outfile)
self._checkResult(outfile)
def test_save_excellon(self):
outfile = os.path.join(
self.OUTDIR, self.OUTPREFIX + 'save_line.txt')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_LINE
dxf.format = (3,3)
dxf.width = 0.2
dxf.write(outfile, filetype=dxf.FT_EXCELLON)
self._checkResult(outfile)
def test_save_excellon_mousebites(self):
outfile = os.path.join(
self.OUTDIR, self.OUTPREFIX + 'save_mousebites.txt')
dxf = panelize.read(self.METRIC_FILE)
dxf.draw_mode = dxf.DM_MOUSE_BITES
dxf.format = (3, 3)
dxf.width = 0.5
dxf.pitch = 1.4
dxf.write(outfile, filetype=dxf.FT_EXCELLON)
self._checkResult(outfile)
def test_to_inch(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_inch.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.to_inch()
dxf.format = (2, 5)
dxf.write(outfile)
self._checkResult(outfile)
def _test_to_metric(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'to_metric.gtl')
dxf = panelize.read(self.INCH_FILE)
dxf.to_metric()
dxf.format = (3, 5)
dxf.write(outfile)
self._checkResult(outfile)
def test_offset(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'offset.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.offset(11, 5)
dxf.write(outfile)
self._checkResult(outfile)
def test_rotate(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rotate.gtl')
dxf = panelize.read(self.METRIC_FILE)
dxf.rotate(20, (10, 10))
dxf.write(outfile)
self._checkResult(outfile)
def test_rectangle_metric(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'rectangle_metric.gtl')
dxf = panelize.DxfFile.rectangle(width=10, height=10, units='metric')
dxf.write(outfile)
self._checkResult(outfile)
def test_rectangle_inch(self):
outfile = os.path.join(
self.OUTDIR, self.OUTPREFIX + 'rectangle_inch.gtl')
dxf = panelize.DxfFile.rectangle(width=inch(10), height=inch(10), units='inch')
dxf.write(outfile)
self._checkResult(outfile)
def test_complex_fill(self):
outfile = os.path.join(self.OUTDIR, self.OUTPREFIX + 'complex_fill.gtl')
dxf = panelize.read(self.COMPLEX_FILE)
dxf.draw_mode = dxf.DM_FILL
dxf.write(outfile)
self._checkResult(outfile)
def test_complex_fill_flip(self):
outfile = os.path.join(
self.OUTDIR, self.OUTPREFIX + 'complex_fill_flip.gtl')
ctx = panelize.GerberComposition()
base = panelize.rectangle(width=100, height=100, left=0, bottom=0, units='metric')
base.draw_mode = base.DM_FILL
ctx.merge(base)
dxf = panelize.read(self.COMPLEX_FILE)
dxf.negate_polarity()
dxf.draw_mode = dxf.DM_FILL
ctx.merge(dxf)
ctx.dump(outfile)
self._checkResult(outfile)
if __name__ == '__main__':
unittest.main()
|