コード例 #1
0
    def __draw_point(self, i: int, vpoint: VPoint):
        """Draw a point."""
        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] == 'ground'
                # Slot point.
                if j == 0 or vpoint.type == VJoint.P:
                    pen.setColor(Qt.black if self.monochrome else QColor(
                        *vpoint.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)

            # 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)

        # 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)
コード例 #2
0
ファイル: main_canvas.py プロジェクト: s40523219/Pyslvs-PyQt5
 def __drawPoint(self, i: int, vpoint: VPoint):
     """Draw a point."""
     if vpoint.type == 1 or vpoint.type == 2:
         #Draw slider
         silder_points = vpoint.c
         for j, (cx, cy) in enumerate(silder_points):
             if vpoint.type == 1:
                 if j == 0:
                     self._BaseCanvas__drawPoint(
                         i, cx, cy, vpoint.links[j] == 'ground',
                         vpoint.color)
                 else:
                     pen = QPen(vpoint.color)
                     pen.setWidth(2)
                     self.painter.setPen(pen)
                     r = 5
                     self.painter.drawRect(
                         QRectF(
                             QPointF(cx * self.zoom + r,
                                     cy * -self.zoom + r),
                             QPointF(cx * self.zoom - r,
                                     cy * -self.zoom - r)))
             elif vpoint.type == 2:
                 if j == 0:
                     self._BaseCanvas__drawPoint(
                         i, cx, cy, vpoint.links[j] == 'ground',
                         vpoint.color)
                 else:
                     #Turn off point mark.
                     showPointMark = self.showPointMark
                     self.showPointMark = False
                     self._BaseCanvas__drawPoint(
                         i, cx, cy, vpoint.links[j] == 'ground',
                         vpoint.color)
                     self.showPointMark = showPointMark
         pen = QPen(vpoint.color.darker())
         pen.setWidth(2)
         self.painter.setPen(pen)
         x_all = tuple(cx for cx, cy in silder_points)
         if x_all:
             p_left = silder_points[x_all.index(min(x_all))]
             p_right = silder_points[x_all.index(max(x_all))]
             if p_left == p_right:
                 y_all = tuple(cy for cx, cy in silder_points)
                 p_left = silder_points[y_all.index(min(y_all))]
                 p_right = silder_points[y_all.index(max(y_all))]
             self.painter.drawLine(
                 QPointF(p_left[0] * self.zoom, p_left[1] * -self.zoom),
                 QPointF(p_right[0] * self.zoom, p_right[1] * -self.zoom))
     else:
         self._BaseCanvas__drawPoint(i, vpoint.cx, vpoint.cy,
                                     vpoint.grounded(), vpoint.color)
     #For selects function.
     if i in self.pointsSelection:
         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)