Ejemplo n.º 1
0
 def draw_curve(self, path: Sequence[_Coord]):
     """Draw path as curve."""
     if len(set(path)) <= 2:
         return
     painter_path = QPainterPath()
     error = False
     for i, (x, y) in enumerate(path):
         if isnan(x):
             error = True
             self.painter.drawPath(painter_path)
             painter_path = QPainterPath()
         else:
             x *= self.zoom
             y *= -self.zoom
             if i == 0:
                 painter_path.moveTo(x, y)
                 self.painter.drawEllipse(QPointF(x, y), self.joint_size,
                                          self.joint_size)
                 continue
             if error:
                 painter_path.moveTo(x, y)
                 error = False
             else:
                 painter_path.lineTo(x, y)
     self.painter.drawPath(painter_path)
Ejemplo n.º 2
0
 def __drawCurve(self, path: Sequence[Tuple[float, float]]):
     """Draw path as curve."""
     pointPath = QPainterPath()
     error = False
     for i, (x, y) in enumerate(path):
         if isnan(x):
             error = True
             self.painter.drawPath(pointPath)
             pointPath = QPainterPath()
         else:
             x *= self.zoom
             y *= -self.zoom
             if i == 0:
                 pointPath.moveTo(x, y)
                 self.painter.drawEllipse(QPointF(x, y), RADIUS, RADIUS)
                 continue
             if error:
                 pointPath.moveTo(x, y)
                 error = False
             else:
                 pointPath.lineTo(x, y)
     self.painter.drawPath(pointPath)
Ejemplo n.º 3
0
 def drawCurve(self, path):
     pointPath = QPainterPath()
     for i, (x, y) in enumerate(path):
         if isnan(x):
             continue
         else:
             if i==0:
                 pointPath.moveTo(x*self.zoom, y*-self.zoom)
             else:
                 pointPath.lineTo(QPointF(x*self.zoom, y*-self.zoom))
     self.painter.drawPath(pointPath)
Ejemplo n.º 4
0
 def draw_target_path(self):
     """Draw solving path."""
     pen = QPen()
     pen.setWidth(self.path_width)
     for i, name in enumerate(sorted(self.target_path)):
         path = self.target_path[name]
         road, dot, brush = target_path_style(i)
         pen.setColor(road)
         self.painter.setPen(pen)
         self.painter.setBrush(brush)
         if len(path) == 1:
             x, y = path[0]
             p = QPointF(x, -y) * self.zoom
             self.painter.drawText(p + QPointF(6, -6), name)
             pen.setColor(dot)
             self.painter.setPen(pen)
             self.painter.drawEllipse(p, self.joint_size, self.joint_size)
         else:
             painter_path = QPainterPath()
             for j, (x, y) in enumerate(path):
                 p = QPointF(x, -y) * self.zoom
                 self.painter.drawEllipse(p, self.joint_size,
                                          self.joint_size)
                 if j == 0:
                     self.painter.drawText(p + QPointF(6, -6), name)
                     painter_path.moveTo(p)
                 else:
                     x2, y2 = path[j - 1]
                     self.__draw_arrow(x, -y, x2, -y2, zoom=True)
                     painter_path.lineTo(p)
             pen.setColor(road)
             self.painter.setPen(pen)
             self.painter.drawPath(painter_path)
             for x, y in path:
                 pen.setColor(dot)
                 self.painter.setPen(pen)
                 p = QPointF(x, -y) * self.zoom
                 self.painter.drawEllipse(p, self.joint_size,
                                          self.joint_size)
     self.painter.setBrush(Qt.NoBrush)
Ejemplo n.º 5
0
 def drawTargetPath(self):
     """Draw solving path."""
     pen = QPen()
     pen.setWidth(self.pathWidth)
     for i, name in enumerate(sorted(self.targetPath)):
         path = self.targetPath[name]
         Pen, Dot, Brush = colorPath(i)
         pen.setColor(Pen)
         self.painter.setPen(pen)
         self.painter.setBrush(Brush)
         if len(path)>1:
             pointPath = QPainterPath()
             for i, (x, y) in enumerate(path):
                 x *= self.zoom
                 y *= -self.zoom
                 self.painter.drawEllipse(QPointF(x, y), 4, 4)
                 if i==0:
                     self.painter.drawText(QPointF(x+6, y-6), name)
                     pointPath.moveTo(x, y)
                 else:
                     x2, y2 = path[i-1]
                     self.drawArrow(x, y, x2*self.zoom, y2*-self.zoom)
                     pointPath.lineTo(QPointF(x, y))
             self.painter.drawPath(pointPath)
             for x, y in path:
                 pen.setColor(Dot)
                 self.painter.setPen(pen)
                 self.painter.drawEllipse(
                     QPointF(x*self.zoom, y*-self.zoom), 3, 3
                 )
         elif len(path)==1:
             x = path[0][0]*self.zoom
             y = path[0][1]*-self.zoom
             self.painter.drawText(QPointF(x+6, y-6), name)
             pen.setColor(Dot)
             self.painter.setPen(pen)
             self.painter.drawEllipse(QPointF(x, y), 3, 3)
     self.painter.setBrush(Qt.NoBrush)
Ejemplo n.º 6
0
    def paintEvent(self, event):
        painter = QPainter()
        painter.begin(self)
        painter.fillRect(event.rect(), QBrush(Qt.white))
        painter.translate(self.width() / 2, self.height() / 2)

        if not self.parama['profile']:
            painter.end()
            return

        pen = QPen()

        # center circle
        pen.setColor(Qt.red)
        pen.setWidth(3)
        pen.setStyle(Qt.SolidLine)
        painter.setPen(pen)
        r = 10
        painter.drawEllipse(QPointF(0, 0), r, r)

        # Base circle
        if self.show_base:
            pen.setColor(Qt.cyan)
            pen.setWidth(3)
            pen.setStyle(Qt.DashLine)
            painter.setPen(pen)
            r = self.parama['rb'] * self.parama['rate']
            painter.drawEllipse(QPointF(0, 0), r, r)

        # rotate
        rotate = QTransform()
        rotate.translate(0, 0)
        rotate.rotate(self.rotate)

        # profile
        pen.setColor(Qt.blue)
        pen.setWidth(5)
        pen.setStyle(Qt.SolidLine)
        painter.setPen(pen)
        path_profile = QPainterPath()
        path_profile.moveTo(
            QPoint(self.parama['profile'][0]['Rx'] * self.parama['rate'],
                   self.parama['profile'][0]['Ry'] * self.parama['rate']))
        for i in range(len(self.parama['profile'])):
            e = self.parama['profile'][i]
            x = e['Rx'] * self.parama['rate']
            y = e['Ry'] * self.parama['rate']
            path_profile.lineTo(QPointF(x, y))
        painter.drawPath(rotate.map(path_profile))
        # route
        if self.show_cutter_route:
            pen.setColor(Qt.green)
            pen.setWidth(3)
            pen.setStyle(Qt.DashLine)
            painter.setPen(pen)
            painterpath_route = QPainterPath()
            painterpath_route.moveTo(
                QPoint(
                    self.parama['cutter_route'][0]['Rx'] * self.parama['rate'],
                    self.parama['cutter_route'][0]['Ry'] *
                    self.parama['rate']))
            for i in range(len(self.parama['cutter_route']) - self.rotate):
                e = self.parama['cutter_route'][i]
                x = e['Rx'] * self.parama['rate']
                y = e['Ry'] * self.parama['rate']
                painterpath_route.lineTo(QPointF(x, y))
            painter.drawPath(rotate.map(painterpath_route))
        # roll
        pen.setColor(Qt.darkGray)
        pen.setWidth(3)
        pen.setStyle(Qt.SolidLine)
        painter.setPen(pen)
        r = self.parama['rc'] * self.parama['rate']
        last_point = QPointF(
            self.parama['cutter_route'][-self.rotate]['Rx'] *
            self.parama['rate'],
            self.parama['cutter_route'][-self.rotate]['Ry'] *
            self.parama['rate'])
        path_roll = QPainterPath()
        path_roll.addEllipse(last_point, r, r)
        painter.drawPath(rotate.map(path_roll))
        painter.end()