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
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. """
        self.label.scale(factor)
        self.p1.scale(factor)
        self.p2.scale(factor)

    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
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()


    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 json(self):
        """ Return a pin as JSON """
        ret = {
            "pin_number":self.pin_number,
            "p1":self.p1.json(),
            "p2":self.p2.json(),
            "attributes" : self.attributes,
            }
        if self.label is not None:
            ret["label"] = self.label.json()
        return ret
class Pad:
    """ Pads are the parts of FBodies (/footprints/components) that connect
    to traces. Basically a set of shapes.
    """

    def __init__(self, pin_number, p, shapes, label=None):
        self.label = label # is a Label
        self.p = Point(p)
        self.pin_number = pin_number
        self.shapes = shapes
        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 """
        pass


    def scale(self, factor):
        """ Scale the x & y coordinates in the pin. """
        pass


    def shift(self, dx, dy):
        """ Shift the x & y coordinates in the pin. """
        pass


    def rebase_y_axis(self, height):
        """ Rebase the y coordinate in the pin. """
        pass


    def json(self):
        """ Return a pin as JSON """
        ret = {
            "pin_number": self.pin_number,
            "p": self.p.json(),
            "shapes": [s.json() for s in self.shapes],
            "attributes": stringify_attributes(self.attributes),
            "styles": self.styles,
            }
        if self.label is not None:
            ret["label"] = self.label.json()
        return ret
Exemple #5
0
class Pad:
    """ Pads are the parts of FBodies (/footprints/components) that connect
    to traces. Basically a set of shapes.
    """
    def __init__(self, pin_number, p, shapes, label=None):
        self.label = label  # is a Label
        self.p = Point(p)
        self.pin_number = pin_number
        self.shapes = shapes
        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 """
        pass

    def scale(self, factor):
        """ Scale the x & y coordinates in the pin. """
        pass

    def shift(self, dx, dy):
        """ Shift the x & y coordinates in the pin. """
        pass

    def rebase_y_axis(self, height):
        """ Rebase the y coordinate in the pin. """
        pass

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