Ejemplo n.º 1
0
    def _add_hole(self, parent_attr, body_attr, shape):
        if not isinstance(shape, Circle):
            log.error('holes must be circular, found %s', shape)
            return
            #raise Unwritable('all holes must be circular')

        pos = Point(shape.x, shape.y)
        pos.shift(body_attr.x, body_attr.y)
        if parent_attr:
            if parent_attr.rotation != 0:
                pos.rotate(parent_attr.rotation)
            if parent_attr.flip_horizontal:
                pos.flip(parent_attr.flip_horizontal)
            pos.shift(parent_attr.x, parent_attr.y)

        if body_attr.rotation != 0:
            if parent_attr and parent_attr.flip_horizontal:
                pos.rotate(-body_attr.rotation, in_place=True)
            else:
                pos.rotate(body_attr.rotation, in_place=True)
        if body_attr.flip_horizontal:
            shape.flip(body_attr.flip_horizontal)

        log.debug('adding %d hole at %d, %d', shape.radius * 2, pos.x, pos.y)
        if shape.radius not in self._holes:
            self._holes[shape.radius] = Hole(shape)
        self._holes[shape.radius].locations.append(pos)
Ejemplo n.º 2
0
class Pin:
    """ Pins are the parts of Bodies (/symbols/components) that connect
    to nets. Basically a line segment, with a null end and a connect end
    """

    def __init__(self, pin_number, p1, p2, label=None):
        self.label = label  # is a Label
        self.p1 = Point(p1)  # null end
        self.p2 = Point(p2)  # connect end
        self.pin_number = pin_number
        self.attributes = dict()
        self.styles = dict()

    def add_attribute(self, key, value):
        """ Add attribute to a pin """
        self.attributes[key] = value

    def bounds(self):
        """ Return the min and max points of a pin """
        x_values = [self.p1.x, self.p2.x]
        y_values = [self.p1.y, self.p2.y]
        if self.label is not None:
            x_values.extend([pt.x for pt in self.label.bounds()])
            y_values.extend([pt.y for pt in self.label.bounds()])
        return [Point(min(x_values), min(y_values)), Point(max(x_values), max(y_values))]

    def scale(self, factor):
        """ Scale the x & y coordinates in the pin. """
        if self.label is not None:
            self.label.scale(factor)
        self.p1.scale(factor)
        self.p2.scale(factor)

    def shift(self, dx, dy):
        """ Shift the x & y coordinates in the pin. """
        if self.label is not None:
            self.label.shift(dx, dy)
        self.p1.shift(dx, dy)
        self.p2.shift(dx, dy)

    def rebase_y_axis(self, height):
        """ Rebase the y coordinate in the pin. """
        if self.label is not None:
            self.label.rebase_y_axis(height)
        self.p1.rebase_y_axis(height)
        self.p2.rebase_y_axis(height)

    def json(self):
        """ Return a pin as JSON """
        ret = {
            "pin_number": self.pin_number,
            "p1": self.p1.json(),
            "p2": self.p2.json(),
            "attributes": stringify_attributes(self.attributes),
            "styles": self.styles,
        }
        if self.label is not None:
            ret["label"] = self.label.json()
        return ret
Ejemplo n.º 3
0
class Pin:
    """ Pins are the parts of SBodies (/symbols/components) that connect
    to nets. Basically a line segment, with a null end and a connect end
    """
    def __init__(self, pin_number, p1, p2, label=None):
        self.label = label  # is a Label
        self.p1 = Point(p1)  # null end
        self.p2 = Point(p2)  # connect end
        self.pin_number = pin_number
        self.attributes = dict()
        self.styles = dict()

    def add_attribute(self, key, value):
        """ Add attribute to a pin """
        self.attributes[key] = value

    def bounds(self):
        """ Return the min and max points of a pin """
        x_values = [self.p1.x, self.p2.x]
        y_values = [self.p1.y, self.p2.y]
        if self.label is not None:
            x_values.extend([pt.x for pt in self.label.bounds()])
            y_values.extend([pt.y for pt in self.label.bounds()])
        return [
            Point(min(x_values), min(y_values)),
            Point(max(x_values), max(y_values))
        ]

    def scale(self, factor):
        """ Scale the x & y coordinates in the pin. """
        if self.label is not None:
            self.label.scale(factor)
        self.p1.scale(factor)
        self.p2.scale(factor)

    def shift(self, dx, dy):
        """ Shift the x & y coordinates in the pin. """
        if self.label is not None:
            self.label.shift(dx, dy)
        self.p1.shift(dx, dy)
        self.p2.shift(dx, dy)

    def rebase_y_axis(self, height):
        """ Rebase the y coordinate in the pin. """
        if self.label is not None:
            self.label.rebase_y_axis(height)
        self.p1.rebase_y_axis(height)
        self.p2.rebase_y_axis(height)

    def json(self):
        """ Return a pin as JSON """
        ret = {
            "pin_number": self.pin_number,
            "p1": self.p1.json(),
            "p2": self.p2.json(),
            "attributes": stringify_attributes(self.attributes),
            "styles": self.styles,
        }
        if self.label is not None:
            ret["label"] = self.label.json()
        return ret