Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
Arquivo: dip.py Projeto: balr0g/pcbre
    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()
Exemplo n.º 3
0
        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))
Exemplo n.º 4
0
def fixed_center_dot(viewState, m, view_center=None):

    if view_center is None:
        view_center = Point2(viewState.width/2, viewState.height/2)

    world_center = viewState.tfV2W(view_center)

    proj_orig_center = projectPoint(viewState.transform, world_center)

    viewState.transform = viewState.transform.dot(m)

    proj_new_center = projectPoint(viewState.transform, world_center)

    dx = proj_new_center[0] - proj_orig_center[0]
    dy = proj_new_center[1] - proj_orig_center[1]

    viewState.transform = M.translate(-dx, -dy).dot(viewState.transform)
Exemplo n.º 5
0
        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))
Exemplo n.º 6
0
def fixed_center_dot(viewState, m, view_center=None):

    if view_center is None:
        view_center = Point2(viewState.width/2, viewState.height/2)

    world_center = viewState.tfV2W(view_center)

    proj_orig_center = projectPoint(viewState.transform, world_center)

    viewState.transform = viewState.transform.dot(m)

    proj_new_center = projectPoint(viewState.transform, world_center)

    dx = proj_new_center[0] - proj_orig_center[0]
    dy = proj_new_center[1] - proj_orig_center[1]

    viewState.transform = M.translate(-dx, -dy).dot(viewState.transform)
Exemplo n.º 7
0
    def im2V(self, pt):
        """Translate Image coordinates to viewport coordinates"""

        if self.model_overall.view_mode:
            ph = projectPoint(self.model.image_matrix, pt)
            return self.viewState.tfW2V(ph)
        else:
            return self.viewState.tfW2V(pt)
Exemplo n.º 8
0
    def im2V(self, pt):
        """Translate Image coordinates to viewport coordinates"""

        if self.model_overall.view_mode:
            ph = projectPoint(self.model.image_matrix, pt)
            return self.viewState.tfW2V(ph)
        else:
            return self.viewState.tfW2V(pt)
Exemplo n.º 9
0
    def mousePressEvent(self, event):
        handle = self.get_keypoint_for_mouse(event.pos())

        if event.button(
        ) == QtCore.Qt.LeftButton and event.modifiers() & ADD_MODIFIER:
            # If we're in world view mode, we need to figure out where this keypoint would be in image space as well
            if self.model.view_mode == 1:
                # World coords of event
                world = Point2(self.vs.tfV2W(event.pos()))
                # Normalized image coords of event
                im_norm = projectPoint(self.model.kp.image_matrix_inv, world)
                # Pixel coords of event
                im_px = self._parent.il.n2p(im_norm)

            # Do all ops as a single macro
            self._parent.undoStack.beginMacro("Add/Set Keypoint")

            cmd = cmd_add_keypoint(self.model.kp)
            self._parent.undoStack.push(cmd)

            # Since we added it manually, we want to use it as part of the alignment
            cmd2 = cmd_set_keypoint_used(self.model.kp, cmd.index, True)
            self._parent.undoStack.push(cmd2)

            # If adding a keypoint in world space, setup the im-space version as well
            if self.model.view_mode == 1:
                cmd2 = cmd_set_keypoint_px(self.model.kp, cmd.index, im_px)
                self._parent.undoStack.push(cmd2)

            # select the keypoint
            self.model.kp.selected_idx = cmd.index

            # and move it to where the click was
            self.do_set_cmd(event.pos(), True)

            self._parent.undoStack.endMacro()

            return

        elif event.button() == QtCore.Qt.LeftButton and event.modifiers(
        ) & DEL_MODIFIER and (handle is not None):
            cmd = cmd_del_keypoint(self.model.kp, self.model.kp.selected_idx)
            self._parent.undoStack.push(cmd)
            self.model.kp.selected_idx = None

        elif event.button() == QtCore.Qt.LeftButton:
            self.model.kp.selected_idx = handle
            if handle is not None:
                self.has_dragged = False
                self.behave_mode = MODE_DRAGGING

        else:
            return False

        return True
Exemplo n.º 10
0
    def mousePressEvent(self, event):
        handle = self.get_keypoint_for_mouse(event.pos())

        if event.button() == QtCore.Qt.LeftButton and event.modifiers() & ADD_MODIFIER:
            # If we're in world view mode, we need to figure out where this keypoint would be in image space as well
            if self.model.view_mode == 1:
                # World coords of event
                world = Point2(self.vs.tfV2W(event.pos()))
                # Normalized image coords of event
                im_norm = projectPoint(self.model.kp.image_matrix_inv, world)
                # Pixel coords of event
                im_px = self._parent.il.n2p(im_norm)

            # Do all ops as a single macro
            self._parent.undoStack.beginMacro("Add/Set Keypoint")

            cmd = cmd_add_keypoint(self.model.kp)
            self._parent.undoStack.push(cmd)

            # Since we added it manually, we want to use it as part of the alignment
            cmd2 = cmd_set_keypoint_used(self.model.kp, cmd.index, True)
            self._parent.undoStack.push(cmd2)

            # If adding a keypoint in world space, setup the im-space version as well
            if self.model.view_mode == 1:
                cmd2 = cmd_set_keypoint_px(self.model.kp, cmd.index, im_px)
                self._parent.undoStack.push(cmd2)

            # select the keypoint
            self.model.kp.selected_idx = cmd.index

            # and move it to where the click was
            self.do_set_cmd(event.pos(), True)

            self._parent.undoStack.endMacro()

            return

        elif event.button() == QtCore.Qt.LeftButton and event.modifiers() & DEL_MODIFIER and (
                        handle is not None):
            cmd = cmd_del_keypoint(self.model.kp, self.model.kp.selected_idx)
            self._parent.undoStack.push(cmd)
            self.model.kp.selected_idx = None

        elif event.button() == QtCore.Qt.LeftButton:
            self.model.kp.selected_idx = handle
            if handle is not None:
                self.has_dragged = False
                self.behave_mode = MODE_DRAGGING

        else:
            return False

        return True
Exemplo n.º 11
0
    def V2im(self, pt):
        """
        Translate viewport coordinates to image coordinates
        :param pt:
        :return:
        """
        world = self.viewState.tfV2W(pt)

        if self.model_overall.view_mode:
            inv = numpy.linalg.inv(self.model.image_matrix)
            return projectPoint(inv, world)
        else:
            return Vec2(world)
Exemplo n.º 12
0
    def V2im(self, pt):
        """
        Translate viewport coordinates to image coordinates
        :param pt:
        :return:
        """
        world = self.viewState.tfV2W(pt)

        if self.model_overall.view_mode:
            inv = numpy.linalg.inv(self.model.image_matrix)
            return projectPoint(inv, world)
        else:
            return Vec2(world)
Exemplo n.º 13
0
    def _build_points(self, dip):
        bx = dip.body_width() / 2
        by = dip.body_length() / 2

        points = []
        points.extend(projectPoints(dip.matrix, map(Point2, [(-bx, by), (-bx,-by),(bx,-by),(bx,by) ])))

        for i in range(28):
            theta = -math.pi * i / 27

            points.append(projectPoint(dip.matrix, Point2(math.cos(theta) * units.MM, math.sin(theta) * units.MM + by)))

        return list(zip(points, points[1:] + points[0:1]))
Exemplo n.º 14
0
    def _build_points(self, smd):
        lines = []

        by = smd.dim_1_body / 2
        bx = smd.dim_2_body / 2

        corners = [
            projectPoint(smd.matrix, Point2(t))
            for t in [(-bx, by), (-bx, -by), (bx, -by), (bx, by)]
        ]

        for p1, p2 in zip(corners, corners[1:] + corners[0:1]):
            lines.append((p1, p2))

        scale = min(smd.dim_1_body, smd.dim_2_body) / 5
        if scale > units.MM:
            scale = units.MM
        if scale < units.MM / 5:
            scale = units.MM / 5

        size = scale / 2
        offs = scale
        posx = -bx + offs
        posy = by - offs

        circle_points = []

        circ_center = projectPoint(smd.matrix, Point2(posx, posy))

        for i in range(28):
            theta = math.pi * 2 * i / 27
            d = Point2(math.cos(theta) * size, math.sin(theta) * size)
            circle_points.append(d + circ_center)

        for p1, p2 in zip(circle_points,
                          circle_points[1:] + circle_points[0:1]):
            lines.append((p1, p2))

        return lines
Exemplo n.º 15
0
    def _build_points(self, smd):
        lines =  []

        by = smd.dim_1_body/2
        bx = smd.dim_2_body/2

        corners = [projectPoint(smd.matrix, Point2(t)) for t in [(-bx, by), (-bx,-by),(bx,-by),(bx,by) ]]

        for p1, p2 in  zip(corners, corners[1:] + corners[0:1]):
            lines.append((p1, p2))

        scale = min(smd.dim_1_body, smd.dim_2_body) / 5
        if scale > units.MM:
            scale = units.MM
        if scale < units.MM/5:
            scale = units.MM/5

        size = scale/2
        offs = scale
        posx = -bx + offs
        posy = by - offs

        circle_points = []

        circ_center = projectPoint(smd.matrix, Point2(posx, posy))

        for i in range(28):
            theta = math.pi * 2 * i / 27
            d = Point2(math.cos(theta) * size, math.sin(theta) * size)
            circle_points.append(d + circ_center)



        for p1, p2 in zip(circle_points, circle_points[1:] + circle_points[0:1]):
            lines.append((p1, p2))

        return lines
Exemplo n.º 16
0
Arquivo: pad.py Projeto: balr0g/pcbre
    def __init__(self,
                 parent,
                 pad_no,
                 rel_center,
                 theta,
                 w,
                 l,
                 th_diam=0,
                 side=None):
        """
        :param parent: Parent
        :param rel_center:
        :type rel_center: Point2
        :param theta:
        :param w:
        :param l:
        :param r:
        :return:
        """
        self.parent = parent

        self.__rel_center = rel_center

        # Cached translation-only location matrix
        self.__translate_mat = translate(self.__rel_center.x,
                                         self.__rel_center.y)
        self.__theta = theta

        self.w = w
        self.l = l

        self.side = side

        # Throughhole diameter, 0 if not T/H
        self.th_diam = th_diam

        self.pad_no = pad_no

        if self.parent is not None:
            pmat = self.parent.matrix
        else:
            pmat = numpy.identity(3, dtype=numpy.float32)

        self.__pmat = pmat

        self.center = projectPoint(pmat, self.__rel_center)

        self.layer = self.parent._side_layer_oracle.stackup.layer_for_side(
            self.side)
Exemplo n.º 17
0
    def prepare(self):
        self.__text_render.updateTexture()

        clist = []

        for mat, str_info in self.__strs:
            for (x, y), (u, v) in str_info.arr:
                newpt = projectPoint(mat, Point2(x, y))
                clist.append(((newpt.x, newpt.y), (u, v)))

        arr = numpy.array(clist, dtype=self.__text_render.buffer_dtype)

        self.vbo.data = arr
        self.vbo.size = None
        self.vbo.copied = False
        self.vbo.bind()

        self.__elem_count = len(arr)
Exemplo n.º 18
0
    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))
Exemplo n.º 19
0
Arquivo: dip.py Projeto: balr0g/pcbre
    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))
Exemplo n.º 20
0
    def _build_points(self, dip):
        bx = dip.body_width() / 2
        by = dip.body_length() / 2

        points = []
        points.extend(
            projectPoints(
                dip.matrix,
                map(Point2, [(-bx, by), (-bx, -by), (bx, -by), (bx, by)])))

        for i in range(28):
            theta = -math.pi * i / 27

            points.append(
                projectPoint(
                    dip.matrix,
                    Point2(
                        math.cos(theta) * units.MM,
                        math.sin(theta) * units.MM + by)))

        return list(zip(points, points[1:] + points[0:1]))
Exemplo n.º 21
0
    def __init__(self, parent, pad_no, rel_center, theta, w, l, th_diam=0, side=None):
        """
        :param parent: Parent
        :param rel_center:
        :type rel_center: Point2
        :param theta:
        :param w:
        :param l:
        :param r:
        :return:
        """
        self.parent = parent

        self.__rel_center = rel_center

        # Cached translation-only location matrix
        self.__translate_mat = translate(self.__rel_center.x, self.__rel_center.y)
        self.__theta = theta

        self.w = w
        self.l = l

        self.side = side

        # Throughhole diameter, 0 if not T/H
        self.th_diam = th_diam

        self.pad_no = pad_no

        if self.parent is not None:
            pmat = self.parent.matrix
        else:
            pmat = numpy.identity(3, dtype=numpy.float32)

        self.__pmat = pmat

        self.center = projectPoint(pmat, self.__rel_center)

        self.layer = self.parent._side_layer_oracle.stackup.layer_for_side(self.side)
Exemplo n.º 22
0
 def point_inside(self, pt):
     v = pt - self.center
     v_in_cmp = projectPoint(rotate(-self.theta), v)
     return self.theta_bbox.point_test(v_in_cmp)
Exemplo n.º 23
0
 def tfV2P(self, pt):
     m = numpy.linalg.inv(self.__ndc2v.dot(self.__w2ndc))
     return projectPoint(m, pt)
Exemplo n.º 24
0
 def n2p(self, pt):
     return projectPoint(self.normalized_to_pixel, pt)
Exemplo n.º 25
0
 def set(self, val):
     r = rotate(-self.parent.theta)
     p = projectPoint(r, val - self.parent.center)
     self.parent._model.dim_1_body = abs(p.x) * 2
     self.parent._model.dim_2_body = abs(p.y) * 2
Exemplo n.º 26
0
        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))
Exemplo n.º 27
0
 def point_inside(self, pt):
     v = pt - self.center
     v_in_cmp = projectPoint(rotate(-self.theta), v)
     return self.theta_bbox.point_test(v_in_cmp)
Exemplo n.º 28
0
 def p2n(self, pt):
     return projectPoint(self.pixel_to_normalized, pt)
Exemplo n.º 29
0
 def tfP2V(self, pt):
     return projectPoint(self.__w2ndc, pt)
Exemplo n.º 30
0
 def tfV2P(self, pt):
     m = numpy.linalg.inv(self.__ndc2v.dot(self.__w2ndc))
     return projectPoint(m, pt)
Exemplo n.º 31
0
 def get(self):
     r = rotate(self.parent.theta)
     cv = Vec2(-self.parent._model.dim_1_body/2, -self.parent._model.dim_2_body/2)
     return self.parent.center + projectPoint(r, cv)
Exemplo n.º 32
0
 def tfW2V(self, pt):
     return projectPoint(self.__fwdMatrix, pt)
Exemplo n.º 33
0
 def p2n(self, pt):
     return projectPoint(self.pixel_to_normalized, pt)
Exemplo n.º 34
0
 def tfV2P(self, pt):
     return projectPoint(self.__v2w, pt)
Exemplo n.º 35
0
 def set(self, val):
     r = rotate(-self.parent.theta)
     p = projectPoint(r, val - self.parent.center)
     self.parent._model.dim_1_body = abs(p.x) * 2
     self.parent._model.dim_2_body = abs(p.y) * 2
Exemplo n.º 36
0
 def tfW2V(self, pt):
     return projectPoint(self.fwdMatrix, pt)
Exemplo n.º 37
0
        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))
Exemplo n.º 38
0
 def tfV2W(self, pt):
     return projectPoint(self.revMatrix, pt)
Exemplo n.º 39
0
 def tfV2P(self, pt):
     return projectPoint(self.__v2w, pt)
Exemplo n.º 40
0
 def n2p(self, pt):
     return projectPoint(self.normalized_to_pixel, pt)
Exemplo n.º 41
0
 def tfP2V(self, pt):
     return projectPoint(self.__w2ndc, pt)
Exemplo n.º 42
0
 def tfV2W(self, pt):
     return projectPoint(self.__revMatrix, pt)
Exemplo n.º 43
0
 def get(self):
     r = rotate(self.parent.theta)
     cv = Vec2(-self.parent._model.dim_1_body / 2,
               -self.parent._model.dim_2_body / 2)
     return self.parent.center + projectPoint(r, cv)