Ejemplo n.º 1
0
    def _convert_shape(self, shape):
        """ Convert a shape """
        if shape.type == 'circle':
            circle = specctraobj.Circle()
            circle.aperture_width = self._from_pixels(1)
            circle.diameter = self._from_pixels(float(shape.radius) * 2.0)
            circle.vertex = self._from_pixels((shape.x, shape.y))
            return [circle]
        elif shape.type == 'line':
            path = specctraobj.Path()
            path.aperture_width = self._from_pixels(1)
            path.vertex.append(self._from_pixels((shape.p1.x, shape.p1.y)))
            path.vertex.append(self._from_pixels((shape.p2.x, shape.p2.y)))
            return [path]
        elif shape.type == 'polygon':
            polygon = specctraobj.Polygon()
            polygon.aperture_width = self._from_pixels(1)
            for point in shape.points:
                polygon.vertex.append(self._from_pixels((point.x, point.y)))
            return [polygon]
        elif shape.type == 'arc':
            # Can't get freerouting.net to show qarc, replace it with multiple paths
            #
            #points = self._get_arc_qarcs(shape)
            #center = self._from_pixels((shape.x, shape.y))
            #
            #result = []
            #for start, end in points:
            #    qarc = specctraobj.QArc()
            #    qarc.vertex1 = self._from_pixels(start)
            #    qarc.vertex2 = self._from_pixels(end)
            #    qarc.vertex3 = center
            #    result.append(qarc)
            #return result

            points = [
                self._from_pixels(point)
                for point in self._get_arc_points(shape)
            ]
            return self._points_to_paths(points)

        elif shape.type == 'bezier':
            points = [
                self._from_pixels((point.x, point.y))
                for point in shape._line()
            ]
            return self._points_to_paths(points)

        elif shape.type == 'rectangle':
            rect = specctraobj.Rectangle()
            rect.aperture_width = self._from_pixels(1)
            rect.vertex1 = self._from_pixels((shape.x, shape.y))
            rect.vertex2 = self._from_pixels(
                (shape.x + shape.width, shape.y - shape.height))
            return [rect]
        else:
            assert shape.type is None  # Not reached
Ejemplo n.º 2
0
 def _convert_pin_to_outline(self, pin):
     pcbshape = specctraobj.Path()
     pcbshape.layer_id = 'Front'
     pcbshape.aperture_width = self._from_pixels(1)
     pcbshape.vertex.append(self._from_pixels((pin.p1.x, pin.p1.y)))
     pcbshape.vertex.append(self._from_pixels((pin.p2.x, pin.p2.y)))
     outline = specctraobj.Outline()
     outline.shape = pcbshape
     return outline
Ejemplo n.º 3
0
    def _make_pin(self, padstack_id):
        shape = specctraobj.Path()
        shape.layer_id = 'Front'
        shape.vertex.append((0, 0))
        shape.vertex.append((0, 0))

        padstack = specctraobj.Padstack()
        padstack.padstack_id = padstack_id
        padstack.shape.append(specctraobj.Shape())
        padstack.shape[-1].shape = shape
        self.pcb.library.padstack.append(padstack)
Ejemplo n.º 4
0
 def _points_to_paths(self, points):
     prev = points[0]
     result = []
     for point in points[1:]:
         path = specctraobj.Path()
         path.aperture_width = self._from_pixels(1)
         path.vertex.append(prev)
         path.vertex.append(point)
         result.append(path)
         prev = point
     return result
Ejemplo n.º 5
0
    def _convert_net(self, net):
        """ Convert a net """

        #TODO: Pins (padstack) and wires must be on the same layer!

        pcbnet = specctraobj.Net()
        pcbnet.net_id = net.net_id
        pcbnet.pins.append(specctraobj.Pins())

        wire = specctraobj.Wire()
        wire.net = specctraobj.Net()
        wire.net.net_id = net.net_id

        paths = set()
        for point in net.points.values():
            for cpt in point.connected_components:
                pcbnet.pins[-1].pin_reference.append(cpt.instance_id + '-' +
                                                     cpt.pin_number)

            for point2_id in point.connected_points:
                point2 = net.points.get(point2_id)
                if point2 is not None:
                    path = [(point.x, point.y), (point2.x, point2.y)]
                    path.sort()  # canonical order
                    paths.add(tuple(path))

        # Keep unique pins only
        pcbnet.pins[-1].pin_reference = dict.fromkeys(
            pcbnet.pins[-1].pin_reference).keys()
        self.pcb.network.net.append(pcbnet)

        for path in paths:
            wire = specctraobj.Wire()
            wire.net = specctraobj.Net()
            wire.net.net_id = net.net_id
            wire.shape = specctraobj.Path()
            wire.shape.layer_id = 'Front'

            point1, point2 = path
            wire.shape.vertex.append(self._from_pixels_abs(point1))
            wire.shape.vertex.append(self._from_pixels_abs(point2))
            self.pcb.wiring.wire.append(wire)