コード例 #1
0
    def DrawArrow(self, dc: DC, u: Tuple[float, float], v: Tuple[float,
                                                                 float]):
        """
        Draw an arrow at the end of the segment uv.

        @param dc
        @param  u: points of the segment
        @param  v: points of the segment
        """
        from math import pi, atan, cos, sin
        pi_6 = pi / 6
        points = []
        x1, y1 = u
        x2, y2 = v
        a = x2 - x1
        b = y2 - y1
        if abs(a) < 0.01:  # vertical segment
            if b > 0:
                alpha = -pi / 2
            else:
                alpha = pi / 2
        else:
            if a == 0:
                alpha = pi / 2  # TODO ?
            else:
                alpha = atan(b / a)
        if a > 0:
            alpha += pi
        alpha1 = alpha + pi_6
        alpha2 = alpha - pi_6
        size = self._arrowSize
        points.append((x2 + size * cos(alpha1), y2 + size * sin(alpha1)))
        points.append((x2, y2))
        points.append((x2 + size * cos(alpha2), y2 + size * sin(alpha2)))
        dc.DrawPolygon(points)
コード例 #2
0
    def drawLosange(self, dc: DC, filled: bool = False):
        """
        Draw an arrow at the beginning of the line.

        Args:
            dc:         The device context
            filled:     True if the losange must be filled, False otherwise

        Note:  Losange is French for 'diamond'
        """
        pi_6 = pi / 6
        points = []
        line = self.GetSegments()
        x1, y1 = line[1]
        x2, y2 = line[0]
        a = x2 - x1
        b = y2 - y1
        if abs(a) < 0.01:  # vertical segment
            if b > 0:
                alpha = -pi / 2
            else:
                alpha = pi / 2
        else:
            if a == 0:
                if b > 0:
                    alpha = pi / 2
                else:
                    alpha = 3 * pi / 2
            else:
                alpha = atan(b / a)
        if a > 0:
            alpha += pi
        alpha1 = alpha + pi_6
        alpha2 = alpha - pi_6
        size = 8
        points.append((x2 + size * cos(alpha1), y2 + size * sin(alpha1)))
        points.append((x2, y2))
        points.append((x2 + size * cos(alpha2), y2 + size * sin(alpha2)))
        points.append((x2 + 2 * size * cos(alpha), y2 + 2 * size * sin(alpha)))
        dc.SetPen(BLACK_PEN)
        if filled:
            dc.SetBrush(BLACK_BRUSH)
        else:
            dc.SetBrush(WHITE_BRUSH)
        dc.DrawPolygon(points)
        dc.SetBrush(WHITE_BRUSH)
コード例 #3
0
    def PaintHandle(self, dc: wx.DC, y_offset, value, left_edge, right_edge):
        pos = (value - self.min_value) * self._px_per_value + self.X_OFFSET
        dc.SetBrush(wx.BLACK_BRUSH)
        dc.DrawPolygon((
            wx.Point(pos, y_offset),
            wx.Point(pos - self.HANDLE_WIDTH / 2, y_offset + self.HANDLE_HEIGHT),
            wx.Point(pos + self.HANDLE_WIDTH / 2, y_offset + self.HANDLE_HEIGHT),
        ))

        label = "{:.3f}".format(value)
        label_width = dc.GetTextExtent(label).GetWidth()
        label_pos = pos - label_width / 2
        width = self.GetSize().x
        label_pos = max(min(width - label_width, label_pos), 0)

        if left_edge != -1:
            label_pos = max(left_edge, label_pos)
            edge = label_pos + label_width
        elif right_edge != -1:
            label_pos = min(right_edge - label_width, label_pos)
            edge = label_pos

        dc.DrawText(label, label_pos, y_offset + self.HANDLE_HEIGHT + self.LABEL_PADDING)
        return edge