begin DXF export of element lines
Stefan Schuermans

Stefan Schuermans commited on 2021-02-17 19:13:39
Showing 1 changed files, with 27 additions and 9 deletions.

... ...
@@ -24,6 +24,7 @@ class DxfFootprintWriter():
24 24
         self._addLayer('number', 7)  # white
25 25
         self._addLayer('pin_copper', 1)  # red
26 26
         self._addLayer('pin_drill', 5)  # blue
27
+        self._addLayer('silk_center', 2)  # yellow
27 28
 
28 29
     def _addCircle(self, x: pcb_types.Coordinate, y: pcb_types.Coordinate,
29 30
                    d: pcb_types.Coordinate, layer_name: str):
... ...
@@ -35,14 +36,10 @@ class DxfFootprintWriter():
35 36
                     size: pcb_types.Coordinate, layer_name: str):
36 37
         l = size.mm / 2
37 38
         s = l / (1 + 2**.5)
38
-        points = [(cx.mm - s, -cy.mm - l),
39
-                  (cx.mm + s, -cy.mm - l),
40
-                  (cx.mm + l, -cy.mm - s),
41
-                  (cx.mm + l, -cy.mm + s),
42
-                  (cx.mm + s, -cy.mm + l),
43
-                  (cx.mm - s, -cy.mm + l),
44
-                  (cx.mm - l, -cy.mm + s),
45
-                  (cx.mm - l, -cy.mm - s),
39
+        points = [(cx.mm - s, -cy.mm - l), (cx.mm + s, -cy.mm - l),
40
+                  (cx.mm + l, -cy.mm - s), (cx.mm + l, -cy.mm + s),
41
+                  (cx.mm + s, -cy.mm + l), (cx.mm - s, -cy.mm + l),
42
+                  (cx.mm - l, -cy.mm + s), (cx.mm - l, -cy.mm - s),
46 43
                   (cx.mm - s, -cy.mm - l)]
47 44
         self._msp.add_polyline2d(points, dxfattribs={'layer': layer_name})
48 45
 
... ...
@@ -64,6 +61,12 @@ class DxfFootprintWriter():
64 61
                                                       'color': color
65 62
                                                   })
66 63
 
64
+    def _addLine(self, x1: pcb_types.Coordinate, y1: pcb_types.Coordinate,
65
+                 x2: pcb_types.Coordinate, y2: pcb_types.Coordinate,
66
+                 layer_name: str):
67
+        self._msp.add_line((x1.mm, -y1.mm), (x2.mm, -y2.mm),
68
+                           dxfattribs={'layer': layer_name})
69
+
67 70
     def _addText(self,
68 71
                  x: pcb_types.Coordinate,
69 72
                  y: pcb_types.Coordinate,
... ...
@@ -141,6 +144,15 @@ class DxfFootprintWriter():
141 144
                              pin.number,
142 145
                              height=pin.drill / 2)
143 146
 
147
+    def drawElementLine(self, element_line: pcb_types.ElementLine):
148
+        """
149
+        Draw element line to DXF.
150
+        """
151
+        self._addLine(element_line.r_x1, element_line.r_y1, element_line.r_x2,
152
+                      element_line.r_y2, 'silk_center')
153
+        # TODO element_line.thickness
154
+        # TODO element_line.s_flags onsolder
155
+
144 156
     def drawFootprint(self, fp: pcb_types.Element):
145 157
         """
146 158
         Draw footprint to DXF.
... ...
@@ -148,7 +160,10 @@ class DxfFootprintWriter():
148 160
         # draw entities in header
149 161
         # TODO
150 162
         # draw entities in body
151
-        type2method = {pcb_types.Pin: self.drawPin}
163
+        type2method = {
164
+            pcb_types.ElementLine: self.drawElementLine,
165
+            pcb_types.Pin: self.drawPin
166
+        }
152 167
         for entity in fp.body:
153 168
             try:
154 169
                 method = type2method[type(entity)]
... ...
@@ -161,6 +176,9 @@ class DxfFootprintWriter():
161 176
                     file=sys.stderr)
162 177
 
163 178
     def drawPin(self, pin: pcb_types.Pin):
179
+        """
180
+        Draw pin to DXF.
181
+        """
164 182
         if 'hole' in pin.s_flags:
165 183
             return self._drawHole(pin)
166 184
         if 'octagon' in pin.s_flags:
167 185