"""
Exporting of GNU PCB files to DXF.
"""
import ezdxf
import sys
import pcb_types
class DxfFootprintWriter():
"""
Writer for DXF files from GNU PCB footprints.
"""
def __init__(self):
self._doc = ezdxf.new('R12')
self._msp = self._doc.modelspace()
self._layers = {}
self._addLayer('clearance', 8) # gray
self._addLayer('hole_drill', 3) # green
self._addLayer('mask', 16) # dark red
self._addLayer('name', 7) # white
self._addLayer('number', 7) # white
self._addLayer('pad_component', 1) # red
self._addLayer('pad_solder', 1) # red
self._addLayer('pin_copper', 1) # red
self._addLayer('pin_drill', 5) # blue
self._addLayer('silk_center', 2) # yellow
def _addCircle(self, x: pcb_types.Coordinate, y: pcb_types.Coordinate,
d: pcb_types.Coordinate, layer_name: str):
self._msp.add_circle((x.mm, -y.mm),
radius=d.mm / 2,
dxfattribs={'layer': layer_name})
def _addOctagon(self, cx: pcb_types.Coordinate, cy: pcb_types.Coordinate,
size: pcb_types.Coordinate, layer_name: str):
l = size.mm / 2
s = l / (1 + 2**.5)
points = [(cx.mm - s, -cy.mm - l), (cx.mm + s, -cy.mm - l),
(cx.mm + l, -cy.mm - s), (cx.mm + l, -cy.mm + s),
(cx.mm + s, -cy.mm + l), (cx.mm - s, -cy.mm + l),
(cx.mm - l, -cy.mm + s), (cx.mm - l, -cy.mm - s),
(cx.mm - s, -cy.mm - l)]
self._msp.add_polyline2d(points, dxfattribs={'layer': layer_name})
def _addRect(self, x1: pcb_types.Coordinate, y1: pcb_types.Coordinate,
x2: pcb_types.Coordinate, y2: pcb_types.Coordinate,
width: pcb_types.Coordinate, layer_name: str):
v1 = pcb_types.Vector(x1, y1)