-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdrc_driver.py
executable file
·71 lines (45 loc) · 1.34 KB
/
drc_driver.py
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
#!/usr/bin/python
import gerberDRC as GD
import gerberDRC.util as GU
import sys
path = sys.argv[1]
GD.setDebugLevel(GD.debug_level_t(0))
f = GD.parseFile(path)
if not f:
print "Could not parse file %s" % path
exit(1)
p = GD.runRS274XProgram(f)
if not p:
print "Could not run program"
exit(1)
for n, i in enumerate(p.layers):
print "Layer %d: '%s'" % (n,i.name)
print "\tpolarity: %s" %(i.polarity)
import cairo._cairo as cairo
def createCairoLineCenterLinePath(obj, cr):
cr.move_to (obj.sx, obj.sy);
cr.line_to (obj.ex, obj.ey);
def renderGerberFile(rep, cr):
cr.push_group()
cr.set_operator(cairo.OPERATOR_OVER)
for j in rep.layers:
if (j.polarity == "LP_C"):
cr.set_source_rgba(1,0,0, 1)
else:
cr.set_source_rgba(0,0,1, 1)
for k in j.draws:
GD.emitGerbObjectCairoPath(cr, k)
cr.stroke()
cr.pop_group_to_source()
cr.paint_with_alpha(1)
srcrect = GU.calculateBoundingRectFromPCBLayers([p], False)
print srcrect
# Calculate the image size and transform
(width, height), transform = GD.prepareCairoTransform(1024, srcrect, pad = 50, trim_to_ratio = True)
# Prepare a surface to render onto
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
cr = cairo.Context(surface)
# Apply the transform to the context
transform(cr)
renderGerberFile(p, cr)
surface.write_to_png(open("out.png", 'w'))