Exemplo n.º 1
0
class PassiveEditFlow(MultipointEditFlow):
    def __init__(self, view, model):
        self.view = view
        self.model = model

        self.first_point = EditablePoint(Point2(0, 0))

        self.theta = 0

        self.side = SIDE.Top

        def other_point():
            return Vec2.fromPolar(self.theta, self.model.pin_d)

        self.second_point = OffsetDefaultPoint(self.first_point, other_point)

        super(PassiveEditFlow,
              self).__init__(self.view, [self.first_point, self.second_point],
                             True)

    def updated(self, ep):
        v = (self.second_point.get() - self.first_point.get())
        self.theta = v.angle()
        self.model.pin_d = v.mag()

    @property
    def center(self):
        return self.first_point.get() / 2 + self.second_point.get() / 2
Exemplo n.º 2
0
class PassiveEditFlow(MultipointEditFlow):
    def __init__(self, view, model):
        self.view = view
        self.model = model
        
        self.first_point = EditablePoint(Point2(0,0))

        self.theta = 0

        self.side = SIDE.Top

        def other_point():
            return Vec2.fromPolar(self.theta, self.model.pin_d)

        self.second_point = OffsetDefaultPoint(self.first_point, other_point)

        super(PassiveEditFlow, self).__init__(self.view, [self.first_point, self.second_point], True)

    def updated(self, ep):
        v = (self.second_point.get() - self.first_point.get())
        self.theta = v.angle()
        self.model.pin_d = v.mag()

    @property
    def center(self):
        return self.first_point.get() / 2 + self.second_point.get() / 2
Exemplo n.º 3
0
class SIPEditFlow(MultipointEditFlow):
    def __init__(self, view, model, cmodel):
        self._model = model
        self._cmodel = cmodel

        self.p1_point = EditablePoint(Point2(0, 0))

        rmat = rotate(self._cmodel.theta)

        dy = -(model.pin_count / 2 - 1) * model.pin_space

        v_aligned = Vec2(0, dy)

        v_delta = project_point(rmat, v_aligned)

        # the pin on the end of the same row as P1
        self.p_bottom_corner = OffsetDefaultPoint(self.p1_point, v_delta)

        points = [self.p1_point, self.p_bottom_corner]

        super(SIPEditFlow, self).__init__(view, points, True)

        self.update_matrix()

    def updated(self, ep):

        if self.p_bottom_corner.is_set and self.p1_point.is_set:
            dv = self.p_bottom_corner.get() - self.p1_point.get()

            # Calculate theta from placement
            theta = math.atan2(dv.y, dv.x) + math.pi / 2
            self._cmodel.theta = theta

            # Calculate pin count
            self._model.pin_count = int(round(
                dv.mag() / self._model.pin_space)) + 1

        self.update_matrix()

    def update_matrix(self):

        rot = rotate(self._cmodel.theta)

        center_to_corner = Vec2(
            0,
            self._model.pin_space * (self._model.pin_count - 1) / 2)

        center_to_corner_w = project_point(rot, center_to_corner)

        self._cmodel.center = self.p1_point.get() - center_to_corner_w

        self.matrix = translate(self._cmodel.center.x,
                                self._cmodel.center.y).dot(
                                    rotate(self._cmodel.theta))
Exemplo n.º 4
0
class BasicSMDFlow(MultipointEditFlow):
    def __init__(self, view, model, cmodel):
        self._model = model
        self._cmodel = cmodel

        self.p1_point = EditablePoint()

        def corner_offset():
            mag = self._model.pin_spacing * (self._model.side1_pins - 1)
            return Vec2.from_polar(self._cmodel.theta, mag)

        self.p_bottom_corner = OffsetDefaultPoint(self.p1_point, corner_offset)

        def other_corner_offset():
            x = self._model.pin_spacing * ((self._model.side1_pins - 1) / 2 +
                                           (self._model.side3_pins - 1) / 2)
            y = self._model.dim_2_pincenter

            r = rotate(self._cmodel.theta)
            return project_point(r, Point2(x, y))

        self.p_side_3_1 = OffsetDefaultPoint(self.p1_point,
                                             other_corner_offset)

        def p2_corner_offset():
            x = self._model.pin_spacing * ((self._model.side1_pins - 1) /
                                           2) + self._model.dim_1_pincenter / 2
            y = self._model.dim_2_pincenter / 2 - (
                self._model.side2_pins - 1) / 2 * self._model.pin_spacing

            r = rotate(self._cmodel.theta)
            return project_point(r, Point2(x, y))

        def p2_corner_ena():
            return self._model.side2_pins or self._model.side4_pins

        self.p_side_2_1 = OffsetDefaultPoint(self.p1_point,
                                             p2_corner_offset,
                                             enabled=p2_corner_ena)

        self.p_body_corner = BodyCornerPoint(self)

        points = [
            self.p1_point, self.p_bottom_corner, self.p_side_3_1,
            self.p_side_2_1, self.p_body_corner
        ]
        super(BasicSMDFlow, self).__init__(view, points, True)

        self.__update_matrix()

    def updated(self, ep):
        if self.p1_point.is_set:
            if self.p_bottom_corner.is_set:
                v = (self.p_bottom_corner.get() - self.p1_point.get())
                mag = v.mag()
                v = v.norm()
                self._cmodel.theta = v.angle()

                self._model.pin_spacing = mag / (self._model.side1_pins - 1)

            self.v_base = Vec2.from_polar(self._cmodel.theta, 1)
            self.v_vert = Vec2(-self.v_base.y, self.v_base.x).norm()

            p_edge_center = self.v_base * self._model.pin_spacing * (
                self._model.side1_pins - 1) / 2

            if self.p_side_3_1.is_set:
                dv = self.p_side_3_1.get() - self.p1_point.get()

                v, _ = project_point_line(dv, Point2(0, 0), self.v_vert, False)
                self._model.dim_2_pincenter = v.mag()

            self._cmodel.center = self.v_vert * self._model.dim_2_pincenter / 2 + p_edge_center + self.p1_point.get(
            )

            if self.p_side_2_1.is_set:
                v, _ = project_point_line(
                    self.p_side_2_1.get() - self._cmodel.center, Point2(0, 0),
                    self.v_base, False)

                self._model.dim_1_pincenter = v.mag() * 2

    @property
    def side(self):
        return self.view.current_side

    def __update_matrix(self):
        rot = rotate(self._cmodel.theta)

        self.matrix = translate(self._cmodel.center.x,
                                self._cmodel.center.y).dot(
                                    rotate(self._cmodel.theta))
Exemplo n.º 5
0
class DIPEditFlow(MultipointEditFlow):
    def __init__(self, view, model):
        self._model = model

        self.p1_point = EditablePoint(Point2(0, 0))

        self.__theta = 0
        self.__corner = Point2(0, 0)

        rmat = rotate(self.theta)

        dy = -(model.pin_count / 2 - 1) * model.pin_space

        v_aligned = Vec2(0, dy)

        v_delta = projectPoint(rmat, v_aligned)

        # the pin on the end of the same row as P1
        self.p_bottom_corner = OffsetDefaultPoint(self.p1_point, v_delta)

        # Opposite corner point
        self.p_opposite = WidthProjectedPoint(self)

        points = [self.p1_point, self.p_bottom_corner, self.p_opposite]

        super(DIPEditFlow, self).__init__(view, points, True)

        if self.view.viewState.current_layer is None:
            self.side = SIDE.Top

        else:
            self.side = self.view.viewState.current_layer.side

        self.update_matrix()

    def updated(self, ep):

        if self.p_bottom_corner.is_set and self.p1_point.is_set:
            dv = self.p_bottom_corner.get() - self.p1_point.get()

            # Calculate theta from placement
            theta = math.atan2(dv.y, dv.x) + math.pi / 2
            self.__theta = theta

            # Calculate pin count
            self._model.pin_count = int(round(dv.mag() / self._model.pin_space)) * 2 + 2

        self.update_matrix()

    def update_matrix(self):

        rot = rotate(self.theta)

        if self.side == SIDE.Top:
            sign = -1
        else:
            sign = 1

        center_to_corner = Vec2(
            sign * self._model.pin_width / 2, self._model.pin_space * (self._model.pin_count / 2 - 1) / 2
        )

        center_to_corner_w = projectPoint(rot, center_to_corner)

        self.center = self.p1_point.get() - center_to_corner_w

        self.matrix = translate(self.center.x, self.center.y).dot(rotate(self.theta))

    @property
    def theta(self):
        return self.__theta
Exemplo n.º 6
0
class BasicSMDFlow(MultipointEditFlow):
    def __init__(self, view, model):
        self._model = model

        self.__theta = 0
        self.center = Point2(0,0)

        self.p1_point = EditablePoint()

        def corner_offset():
            mag = self._model.pin_spacing * (self._model.side1_pins - 1)
            return Vec2.fromPolar(self.__theta, mag)

        self.p_bottom_corner = OffsetDefaultPoint(self.p1_point, corner_offset)

        def other_corner_offset():
            x = self._model.pin_spacing * ((self._model.side1_pins - 1) / 2 + (self._model.side3_pins - 1) / 2)
            y = self._model.dim_2_pincenter

            r = rotate(self.__theta)
            return projectPoint(r, Point2(x, y))

        self.p_side_3_1 = OffsetDefaultPoint(self.p1_point, other_corner_offset)

        def p2_corner_offset():
            x = self._model.pin_spacing * ((self._model.side1_pins - 1) / 2) + self._model.dim_1_pincenter/2
            y = self._model.dim_2_pincenter / 2 - (self._model.side2_pins - 1) / 2 * self._model.pin_spacing

            r = rotate(self.__theta)
            return projectPoint(r, Point2(x, y))

        def p2_corner_ena():
            return self._model.side2_pins or self._model.side4_pins

        self.p_side_2_1 = OffsetDefaultPoint(self.p1_point, p2_corner_offset, enabled=p2_corner_ena)

        self.p_body_corner = BodyCornerPoint(self)

        points = [self.p1_point, self.p_bottom_corner, self.p_side_3_1, self.p_side_2_1, self.p_body_corner]
        super(BasicSMDFlow, self).__init__(view, points, True)

        self.__side = None
        self.__update_matrix()

    def updated(self, ep):
        if self.p1_point.is_set:
            if self.p_bottom_corner.is_set:
                v = (self.p_bottom_corner.get() - self.p1_point.get())
                mag = v.mag()
                v = v.norm()
                self.__theta = v.angle()

                self._model.pin_spacing = mag / (self._model.side1_pins - 1)


            self.v_base = Vec2.fromPolar(self.__theta, 1)
            self.v_vert = Vec2(-self.v_base.y, self.v_base.x).norm()

            p_edge_center = self.v_base * self._model.pin_spacing * (self._model.side1_pins - 1) / 2


            if self.p_side_3_1.is_set:
                dv = self.p_side_3_1.get() - self.p1_point.get()

                v, _ = project_point_line(dv, Point2(0,0), self.v_vert, False)
                self._model.dim_2_pincenter = v.mag()

            self.center = self.v_vert * self._model.dim_2_pincenter / 2 + p_edge_center + self.p1_point.get()

            if self.p_side_2_1.is_set:
                v, _ = project_point_line(self.p_side_2_1.get() - self.center, Point2(0,0), self.v_base, False)

                self._model.dim_1_pincenter = v.mag() * 2


    @property
    def theta(self):
        return self.__theta

    @theta.setter
    def theta(self, v):
        self.__theta = v
        # TODO: For each of the points, if set, rotate around center

    @property
    def side(self):
        if self.__side is None:
            if self.view.viewState.current_layer is None:
                return SIDE.Top
            else:
                return self.view.viewState.current_layer.side

        return self.__side

    def __update_matrix(self):
        rot = rotate(self.__theta)

        if self.side == SIDE.Top:
            sign = -1
        else:
            sign = 1

        self.matrix = translate(self.center.x, self.center.y).dot(rotate(self.__theta))
Exemplo n.º 7
0
Arquivo: dip.py Projeto: pcbre/pcbre
class DIPEditFlow(MultipointEditFlow):
    def __init__(self, view, model, cmodel):
        self._model = model
        self._cmodel = cmodel

        self.p1_point = EditablePoint(Point2(0, 0))

        rmat = rotate(self._cmodel.theta)

        dy = -(model.pin_count / 2 - 1) * model.pin_space

        v_aligned = Vec2(0, dy)

        v_delta = project_point(rmat, v_aligned)

        # the pin on the end of the same row as P1
        self.p_bottom_corner = OffsetDefaultPoint(self.p1_point, v_delta)

        # Opposite corner point
        self.p_opposite = WidthProjectedPoint(self)

        points = [self.p1_point, self.p_bottom_corner, self.p_opposite]

        super(DIPEditFlow, self).__init__(view, points, True)

        self.update_matrix()

    def updated(self, ep):

        if self.p_bottom_corner.is_set and self.p1_point.is_set:
            dv = self.p_bottom_corner.get() - self.p1_point.get()

            # Calculate theta from placement
            theta = math.atan2(dv.y, dv.x) + math.pi / 2
            self._cmodel.theta = theta

            # Calculate pin count
            self._model.pin_count = int(round(
                dv.mag() / self._model.pin_space)) * 2 + 2

        self.update_matrix()

    def get_cur_sign(self):
        if self.view.current_side() is SIDE.Top:
            sign = -1
        else:
            sign = 1
        return sign

    def update_matrix(self):

        rot = rotate(self._cmodel.theta)

        sign = self.get_cur_sign()

        center_to_corner = Vec2(
            sign * self._model.pin_width / 2,
            self._model.pin_space * (self._model.pin_count / 2 - 1) / 2)

        center_to_corner_w = project_point(rot, center_to_corner)

        self._cmodel.center = self.p1_point.get() - center_to_corner_w

        self.matrix = translate(self._cmodel.center.x,
                                self._cmodel.center.y).dot(
                                    rotate(self._cmodel.theta))