Exemplo n.º 1
0
def _offset(p: VPoint) -> _Coord:
    """Make offset coordinate."""
    x, y = p.c[1]
    if p.has_offset() and p.true_offset() <= 0.1:
        if p.offset() > 0:
            x += 0.1
            y += 0.1
        else:
            x -= 0.1
            y -= 0.1
    return x, y
Exemplo n.º 2
0
def _args2vpoint(args: PointArgs) -> VPoint:
    """Make arguments as a VPoint object."""
    link = _no_empty(args.links.split(','))
    if args.type == '':
        return VPoint.HOLDER
    elif args.type == 'R':
        type_int = VJoint.R
        angle = 0.
    else:
        angle_pair = args.type.split(':')
        angle = float(angle_pair[1])
        type_int = VJoint.P if angle_pair[0] == 'P' else VJoint.RP
    return VPoint(link, type_int, angle, args.color, args.x, args.y, color_rgb)
Exemplo n.º 3
0
def _args2vpoint(args: Sequence[Union[str, float]]) -> Optional[VPoint]:
    """Make arguments as a VPoint object."""
    link = _no_empty(args[0].split(','))
    if args[1] == '':
        return None
    elif args[1] == 'R':
        type_int = VJoint.R
        angle = 0
    else:
        t, angle_str = args[1].split(':')
        angle = float(angle_str)
        if t == 'P':
            type_int = VJoint.P
        else:
            type_int = VJoint.RP
    return VPoint(link, type_int, angle, args[2], args[3], args[4], color_rgb)
Exemplo n.º 4
0
    def __draw_point(self, i: int, vpoint: VPoint) -> None:
        """Draw a point."""
        connected = len(vpoint.links) - 1
        if vpoint.type in {VJoint.P, VJoint.RP}:
            pen = QPen(QColor(*vpoint.color))
            pen.setWidth(2)
            # Draw slot point and pin point
            for j, (cx, cy) in enumerate(vpoint.c):
                if not vpoint.links:
                    grounded = False
                else:
                    grounded = vpoint.links[j] == VLink.FRAME
                # Slot point
                if j == 0 or vpoint.type == VJoint.P:
                    if self.monochrome:
                        color = Qt.black
                    else:
                        color = QColor(*vpoint.color)
                    pen.setColor(color)
                    self.painter.setPen(pen)
                    cp = QPointF(cx, -cy) * self.zoom
                    jr = self.joint_size * (2 if j == 0 else 1)
                    rp = QPointF(jr, -jr)
                    self.painter.drawRect(QRectF(cp + rp, cp - rp))
                    if self.show_point_mark:
                        pen.setColor(Qt.darkGray)
                        self.painter.setPen(pen)
                        text = f"[Point{i}]"
                        if self.show_dimension:
                            text += f":({cx:.02f}, {cy:.02f})"
                        self.painter.drawText(cp + rp, text)
                else:
                    self.draw_point(i, cx, cy, grounded, vpoint.color,
                                    connected)
            # Slider line
            pen.setColor(QColor(*vpoint.color).darker())
            self.painter.setPen(pen)
            qline_m = QLineF(
                QPointF(vpoint.c[1][0], -vpoint.c[1][1]) * self.zoom,
                QPointF(vpoint.c[0][0], -vpoint.c[0][1]) * self.zoom)
            nv = qline_m.normalVector()
            nv.setLength(self.joint_size)
            nv.setPoints(nv.p2(), nv.p1())
            qline_1 = nv.normalVector()
            qline_1.setLength(qline_m.length())
            self.painter.drawLine(qline_1)
            nv.setLength(nv.length() * 2)
            nv.setPoints(nv.p2(), nv.p1())
            qline_2 = nv.normalVector()
            qline_2.setLength(qline_m.length())
            qline_2.setAngle(qline_2.angle() + 180)
            self.painter.drawLine(qline_2)
        else:
            self.draw_point(i, vpoint.cx, vpoint.cy, vpoint.grounded(),
                            vpoint.color, connected)

        # For selects function
        if self.select_mode == SelectMode.JOINT and (i in self.selections):
            pen = QPen(QColor(161, 16, 239))
            pen.setWidth(3)
            self.painter.setPen(pen)
            self.painter.drawRect(vpoint.cx * self.zoom - 12,
                                  vpoint.cy * -self.zoom - 12, 24, 24)