Exemple #1
0
    def render(self, mat, pad, render_mode=RENDER_STANDARD, render_hint=RENDER_HINT_NORMAL):
        """
        :type pad: Pad
        :param mat:
        :param pad:
        :return:
        """


        textcol = self.parent.text_color()
        textcol_a = textcol + [1]

        color = self.parent.color_for_pad(pad)
        color_a = color + [1]
        if render_mode & RENDER_SELECTED:
            color_a = [1,1,1,1]


        if pad.is_through():
            self.parent.via_renderer.deferred(pad.center, pad.l/2, pad.th_diam/2, render_mode, render_hint)

            r = Rect.fromCenterSize(Point2(0,0), pad.l * 0.6, pad.w * 0.6)

            _text_to(self.view, pad,r, mat, textcol_a)
        else:
            t = pad.trace_repr
            self.parent.trace_renderer.deferred(t, render_mode, render_hint)
            r = Rect.fromCenterSize(Point2(0,0), pad.l*0.8, pad.w*0.8)
            _text_to(self.view, pad, r, mat, textcol_a)
Exemple #2
0
    def render(self,
               mat,
               pad,
               render_mode=RENDER_STANDARD,
               render_hint=RENDER_HINT_NORMAL):
        """
        :type pad: Pad
        :param mat:
        :param pad:
        :return:
        """

        textcol = self.parent.text_color()
        textcol_a = textcol + [1]

        color = self.parent.color_for_pad(pad)
        color_a = color + [1]
        if render_mode & RENDER_SELECTED:
            color_a = [1, 1, 1, 1]

        if pad.is_through():
            self.parent.via_renderer.deferred(pad.center, pad.l / 2,
                                              pad.th_diam / 2, render_mode,
                                              render_hint)

            r = Rect.fromCenterSize(Point2(0, 0), pad.l * 0.6, pad.w * 0.6)

            _text_to(self.view, pad, r, mat, textcol_a)
        else:
            t = pad.trace_repr
            self.parent.trace_renderer.deferred(t, render_mode, render_hint)
            r = Rect.fromCenterSize(Point2(0, 0), pad.l * 0.8, pad.w * 0.8)
            _text_to(self.view, pad, r, mat, textcol_a)
Exemple #3
0
    def get_keypoint_viewport_box(self, keypoint: AlignKeypoint) -> Rect:
        """
        Get a bbox rect in view coordinates for a keypoint
        :param keypoint:
        :return:
        """
        p = self.get_keypoint_viewport_center(keypoint)

        return Rect.from_center_size(p, width=self.d1 * 2, height=self.d1 * 2)
Exemple #4
0
    def get_keypoint_viewport_box(self, keypoint):
        """
        Get a bbox rect in view coordinates for a keypoint
        :param keypoint:
        :return:
        """
        p = self.get_keypoint_viewport_center(keypoint)

        return Rect.fromCenterSize(p, width=self.d1 * 2, height=self.d1 * 2)
Exemple #5
0
    def __init__(self, p0, p1, p0_layer, p1_layer, net):
        self.p0 = p0
        self.p1 = p1
        self.p0_layer = p0_layer
        self.p1_layer = p1_layer
        self.net = net

        self.bbox = Rect.fromPoints(self.p0, self.p1)

        self._project = None
Exemple #6
0
    def fit_point_cloud(self, points: List[Vec2]):
        new_points = [project_point(self.__rotate_flip, p) for p in points]
        if not new_points:
            return

        r = Rect.from_center_size(new_points.pop())
        for p in new_points:
            r.point_merge(p)

        self.__fit_postrotate_rect(r)
Exemple #7
0
    def __init__(self, p0, p1, p0_layer, p1_layer, net):
        self.p0 = p0
        self.p1 = p1
        self.p0_layer = p0_layer
        self.p1_layer = p1_layer
        self.net = net

        self.bbox = Rect.fromPoints(self.p0, self.p1)

        self._project = None
Exemple #8
0
    def __init__(self, pt, viapair, r, net=None):
        self.pt = pt
        self.r = r
        self.viapair = viapair
        self.net = net

        self.bbox = Rect.fromCenterSize(pt, r * 2, r * 2)

        self._project = None

        self.__poly_repr = ShapelyPoint(pt).buffer(self.r)
Exemple #9
0
    def __init__(self, pt, viapair, r, net = None):
        self.pt = pt
        self.r = r
        self.viapair = viapair
        self.net = net

        self.bbox = Rect.fromCenterSize(pt, r*2, r*2)

        self._project = None

        self.__poly_repr = ShapelyPoint(pt).buffer(self.r)
Exemple #10
0
    def theta_bbox(self):
        if self.side_pins[0] or self.side_pins[2]:
            x_axis = self.dim_2_pincenter + self.pin_contact_length + self.pin_contact_width * 2
        else:
            x_axis = self.dim_2_body

        if self.side_pins[1] or self.side_pins[3]:
            y_axis = self.dim_1_pincenter + self.pin_contact_length + self.pin_contact_width * 2
        else:
            y_axis = self.dim_1_body

        return Rect.fromCenterSize(Point2(0, 0), x_axis, y_axis)
Exemple #11
0
    def theta_bbox(self):
        if self.side_pins[0] or self.side_pins[2]:
            x_axis = self.dim_2_pincenter + self.pin_contact_length + self.pin_contact_width * 2
        else:
            x_axis = self.dim_2_body

        if self.side_pins[1] or self.side_pins[3]:
            y_axis = self.dim_1_pincenter + self.pin_contact_length + self.pin_contact_width * 2
        else:
            y_axis = self.dim_1_body

        return Rect.fromCenterSize(Point2(0,0), x_axis, y_axis)
Exemple #12
0
def _text_to(view: 'BoardViewWidget', pad: 'Pad', r: Rect, mat: 'ndt.NDArray[numpy.float64]', textcol_a: float) -> None:
    mat = mat.dot(pad.translate_mat)

    # zero-out rotation
    mat[0:2, 0:2] = view.viewState.glMatrix[0:2, 0:2]

    # Hack
    text_height_px = view.viewState.scale_factor * r.height

    # Hack
    pname = pad.pad_name

    if text_height_px < 14:
        alpha = 0
        textcol_a[3] = (text_height_px - 6) / 8

        if text_height_px < 6:
            return
    elif 14 <= text_height_px <= TRANSITION_POINT_1:
        alpha = 0
    elif text_height_px > TRANSITION_POINT_1:
        if pname != "":
            if text_height_px > TRANSITION_POINT_2:
                alpha = 1
            else:
                alpha = (text_height_px - TRANSITION_POINT_1) / (TRANSITION_POINT_2 - TRANSITION_POINT_1)
        else:
            alpha = 0

    h_delta_1 = r.height * (1 - RATIO * alpha)
    h_delta_2 = r.height * (RATIO - RGAP) * alpha

    r_top = Rect.fromRect(r)
    r_top.bottom = r_top.top - h_delta_1

    r.top = r.bottom + h_delta_2

    view.text_batch.submit_text_box(mat, "%s" % pad.pad_no, r_top, textcol_a, None)
    if alpha:
        view.text_batch.submit_text_box(mat, "%s" % pname, r, textcol_a, None)
Exemple #13
0
    def update_if_necessary(self):
        if not self.__needs_rebuild():
            return

        components = self.__project.artwork.components

        self.__top_side_pads.restart()
        self.__top_side_labels.restart()
        self.__bottom_side_labels.restart()
        self.__bottom_side_pads.restart()

        for cmp in components:
            if cmp.side == SIDE.Top:
                pad_batch = self.__top_side_pads
            else:
                pad_batch = self.__bottom_side_pads

            for pad in cmp.get_pads():
                if pad.is_through():
                    r = Rect.fromCenterSize(Point2(0, 0), pad.l * 0.6,
                                            pad.w * 0.6)

                else:
                    r = Rect.fromCenterSize(Point2(0, 0), pad.l * 0.8,
                                            pad.w * 0.8)

                mat = cmp.matrix.dot(pad.translate_mat)

                r_top = Rect.fromRect(r)

                s = "%s: %s" % (pad.pad_no, pad.pad_name)

                ti = pad_batch.get_string(s)
                text_mat = mat.dot(ti.get_render_to_mat(r_top))
                pad_batch.add(text_mat, ti)

        self.__top_side_pads.prepare()
        self.__top_side_labels.prepare()
        self.__bottom_side_labels.prepare()
        self.__bottom_side_pads.prepare()
Exemple #14
0
    def __init__(self, p0: Vec2, p1: Vec2, p0_layer: 'Layer',
                 p1_layer: 'Layer',
                 net: Optional['pcbre.model.net.Net']) -> None:
        super(Airwire, self).__init__()
        self.p0 = p0
        self.p1 = p1
        self.p0_layer = p0_layer
        self.p1_layer = p1_layer
        self._net = net

        self._bbox = Rect.from_points(self.p0, self.p1)

        self._project = None
Exemple #15
0
    def __init__(self, layer, exterior, interiors=[], net=None):
        # Buffer 0 forces geom cleanup
        self.__geometry = ShapelyPolygon(exterior, interiors).buffer(0)

        minx, miny, maxx, maxy = self.__geometry.bounds

        self.bbox = Rect.fromPoints(Point2(minx, miny), Point2(maxx, maxy))

        self.net = net
        self.layer = layer
        self._project = None

        self.__triangulation = None
Exemple #16
0
    def update_if_necessary(self):
        if not self.__needs_rebuild():
            return

        components = self.__project.artwork.components

        self.__top_side_pads.restart()
        self.__top_side_labels.restart()
        self.__bottom_side_labels.restart()
        self.__bottom_side_pads.restart()

        for cmp in components:
            if cmp.side == SIDE.Top:
                pad_batch = self.__top_side_pads
            else:
                pad_batch = self.__bottom_side_pads

            for pad in cmp.get_pads():
                if pad.is_through():
                    r = Rect.fromCenterSize(Point2(0,0), pad.l * 0.6, pad.w * 0.6)

                else:
                    r = Rect.fromCenterSize(Point2(0,0), pad.l*0.8, pad.w*0.8)

                mat = cmp.matrix.dot(pad.translate_mat)

                r_top = Rect.fromRect(r)

                s = "%s: %s" % (pad.pad_no, pad.pad_name)

                ti = pad_batch.get_string(s)
                text_mat = mat.dot(ti.get_render_to_mat(r_top))
                pad_batch.add(text_mat, ti)

        self.__top_side_pads.prepare()
        self.__top_side_labels.prepare()
        self.__bottom_side_labels.prepare()
        self.__bottom_side_pads.prepare()
Exemple #17
0
    def __init__(self, layer, exterior, interiors=[], net=None):
        # Buffer 0 forces geom cleanup
        self.__geometry = ShapelyPolygon(exterior, interiors).buffer(0)

        minx, miny, maxx, maxy = self.__geometry.bounds

        self.bbox = Rect.fromPoints(Point2(minx, miny), Point2(maxx, maxy))

        self.net = net
        self.layer = layer
        self._project = None


        self.__triangulation = None
Exemple #18
0
    def __init__(self, p0, p1, thickness, layer, net=None):
        self.p0 = p0
        self.p1 = p1

        self.thickness = thickness

        self.net = net
        self.layer = layer

        self._project = None

        self.bbox = Rect.fromPoints(self.p0, self.p1)
        self.bbox.feather(self.thickness, self.thickness)

        self.__poly_repr = ShapelyLineString([self.p0, self.p1]).buffer(self.thickness/2)
Exemple #19
0
    def __init__(self, p0, p1, thickness, layer, net=None):
        self.p0 = p0
        self.p1 = p1

        self.thickness = thickness

        self.net = net
        self.layer = layer

        self._project = None

        self.bbox = Rect.fromPoints(self.p0, self.p1)
        self.bbox.feather(self.thickness, self.thickness)

        self.__poly_repr = ShapelyLineString([self.p0, self.p1
                                              ]).buffer(self.thickness / 2)
Exemple #20
0
    def __init__(self,
                 pt: Vec2,
                 viapair: 'ViaPair',
                 r: float,
                 net: Optional['pcbre.model.net.Net'] = None) -> None:
        super(Via, self).__init__()
        self.pt = pt
        self.r = r
        self.viapair = viapair
        self._net = net

        self._bbox = Rect.from_center_size(pt, r * 2, r * 2)

        self._project = None

        self.__poly_repr = ShapelyPoint(pt).buffer(self.r)
Exemple #21
0
    def get_handle_index_for_mouse(self, pos: Vec2) -> Optional[int]:
        """ Returns the index of a handle (or None if one isn't present) given
            a MoveEvent"""
        for n, handle in enumerate(self.model.all_handles()):
            if handle is None:
                continue

            # get the pix-wise BBOX of the handle
            p = self.im2V(handle)

            # Rect encompassing the handle
            r = Rect.from_center_size(p, HANDLE_HALF_SIZE * 2, HANDLE_HALF_SIZE * 2)

            # If event inside the bbox
            if r.point_test(pos) != 0:
                return n
        return None
Exemple #22
0
    def make_active(self, world_to_point=False):
        self.__saved_point = self.current_point.save()

        if not world_to_point:
            pt = self.view.viewState.tfW2V(self.current_point.get())

            bounds = Rect.fromPoints(Point2(0,0), Point2(self.view.width(), self.view.height()))
            pt_clipped = clip_point_to_rect(pt, bounds)

            screen_pt = self.view.mapToGlobal(QtCore.QPoint(*pt_clipped.intTuple()))

            QtGui.QCursor.setPos(screen_pt)
        else:
            rect_pt = Point2(self.view.mapFromGlobal(QtGui.QCursor.pos()))
            world_pt = self.view.viewState.tfV2W(rect_pt)
            self.current_point.set(world_pt)

        self.__point_active = True
Exemple #23
0
    def __init__(self,
                 layer: 'Layer',
                 exterior: Sequence[Vec2],
                 interiors: Sequence[Sequence[Vec2]],
                 net: Optional['Net'] = None) -> None:
        super(Polygon, self).__init__()

        # Buffer 0 forces geom cleanup
        self.__geometry = ShapelyPolygon(exterior, interiors).buffer(0)

        minx, miny, maxx, maxy = self.__geometry.bounds

        self._bbox = Rect.from_points(Point2(minx, miny), Point2(maxx, maxy))

        self._net = net
        self._layer = layer
        self._project: Optional['Project'] = None

        self.__triangulation = None
Exemple #24
0
def _text_to(view, pad, r, mat, textcol_a):
    mat = mat.dot(pad.translate_mat)

    # zero-out rotation
    mat[0:2,0:2] = view.viewState.glMatrix[0:2,0:2]

    # Hack
    text_height_px = view.viewState.scale_factor * r.height

    # Hack
    pname = pad.pad_name

    if text_height_px < 14:
        alpha = 0
        textcol_a[3] = (text_height_px - 6) / 8

        if text_height_px < 6:
            return
    elif 14 <= text_height_px <= TRANSITION_POINT_1:
        alpha = 0
    elif text_height_px > TRANSITION_POINT_1:
        if pname != "":
            if text_height_px > TRANSITION_POINT_2:
                alpha = 1
            else:
                alpha = (text_height_px - TRANSITION_POINT_1) / (TRANSITION_POINT_2 - TRANSITION_POINT_1)
        else:
            alpha = 0

    h_delta_1 = r.height * (1 - RATIO * alpha)
    h_delta_2 = r.height * (RATIO - RGAP) * alpha

    r_top = Rect.fromRect(r)
    r_top.bottom = r_top.top - h_delta_1

    r.top = r.bottom + h_delta_2

    view.text_batch.submit_text_box(mat, "%s" % pad.pad_no, r_top, textcol_a, None)
    if alpha:
        view.text_batch.submit_text_box(mat, "%s" % pname, r, textcol_a, None)
Exemple #25
0
    def __init__(self,
                 p0: Vec2,
                 p1: Vec2,
                 thickness: float,
                 layer: 'Layer',
                 net: Optional['Net'] = None) -> None:
        super(Trace, self).__init__()
        self.p0 = p0
        self.p1 = p1

        self.thickness = thickness

        self._net = net
        self._layer = layer

        self._project = None

        self._bbox = Rect.from_points(self.p0, self.p1)
        self._bbox.feather(self.thickness, self.thickness)

        self.__poly_repr = ShapelyLineString([self.p0, self.p1
                                              ]).buffer(self.thickness / 2)
Exemple #26
0
 def bbox(self) -> Rect:
     longest_dim = max(self.width, self.length)
     return Rect.from_center_size(self.center, longest_dim, longest_dim)
Exemple #27
0
 def theta_bbox(self) -> Rect:
     return Rect.from_center_size(Point2(0, 0), self.body_width(), self.body_length())
Exemple #28
0
 def theta_bbox(self):
     return Rect.fromCenterSize(self.center, self.body_width(),
                                self.body_length())
Exemple #29
0
 def theta_bbox(self):
     l = max(self.pin_d + self.pin_corner_vec.x, self.body_corner_vec.x)
     w = max(self.pin_corner_vec.y, self.body_corner_vec.y)
     return Rect.fromCenterSize(self.center, l * 2, w * 2)
Exemple #30
0
 def bbox(self):
     longest_dim = max(self.w, self.l)
     return Rect.fromCenterSize(self.center, longest_dim, longest_dim)
Exemple #31
0
 def theta_bbox(self):
     l = max(self.pin_d + self.pin_corner_vec.x, self.body_corner_vec.x)
     w = max(self.pin_corner_vec.y, self.body_corner_vec.y)
     return Rect.fromCenterSize(self.center, l * 2, w * 2)
Exemple #32
0
 def theta_bbox(self):
     return Rect.fromCenterSize(self.center, self.body_width(), self.body_length())
Exemple #33
0
 def __init__(self, arr: 'VA_tex', metrics: Tuple[float, float, float,
                                                  float]) -> None:
     self.__rect = Rect()
     (self.__rect.left, self.__rect.right, self.__rect.bottom,
      self.__rect.top) = metrics
     self.arr = arr
Exemple #34
0
 def __init__(self, arr, metrics):
     self.__rect = Rect()
     (self.__rect.left, self.__rect.right, self.__rect.bottom,
      self.__rect.top) = metrics
     self.arr = arr
Exemple #35
0
 def theta_bbox(self) -> Rect:
     length = max(self.pin_d + self.pin_corner_vec.x, self.body_corner_vec.x)
     width = max(self.pin_corner_vec.y, self.body_corner_vec.y)
     return Rect.from_center_size(Point2(0, 0), length * 2, width * 2)
Exemple #36
0
 def bbox(self):
     longest_dim = max(self.w, self.l)
     return Rect.fromCenterSize(self.center, longest_dim, longest_dim)