예제 #1
0
 def updateRanges(self, ranges: Dict[str, Tuple[float, float, float]]):
     """Update the ranges of dimensional synthesis."""
     self.ranges.clear()
     self.ranges.update({tag: QRectF(
         QPointF(values[0] - values[2]/2, values[1] + values[2]/2),
         QSizeF(values[2], values[2])
     ) for tag, values in ranges.items()})
     self.update()
예제 #2
0
    def paintEvent(self, event):
        """Using a QPainter under 'self',
        so just change QPen or QBrush before painting.
        """
        self.painter.begin(self)
        self.painter.fillRect(event.rect(), QBrush(Qt.white))
        # Translation
        self.painter.translate(self.ox, self.oy)
        # Background
        if not self.background.isNull():
            rect = self.background.rect()
            self.painter.setOpacity(self.background_opacity)
            img_origin: QPointF = self.background_offset * self.zoom
            self.painter.drawImage(
                QRectF(img_origin, QSizeF(
                    rect.width() * self.background_scale * self.zoom,
                    rect.height() * self.background_scale * self.zoom
                )),
                self.background,
                QRectF(rect)
            )
            self.painter.setOpacity(1)
        # Show frame.
        pen = QPen(Qt.blue)
        pen.setWidth(1)
        self.painter.setPen(pen)
        self.painter.setFont(QFont("Arial", self.font_size))
        # Draw origin lines.
        pen.setColor(Qt.gray)
        self.painter.setPen(pen)
        x_l = -self.ox
        x_r = self.width() - self.ox
        self.painter.drawLine(QPointF(x_l, 0), QPointF(x_r, 0))
        y_t = self.height() - self.oy
        y_b = -self.oy
        self.painter.drawLine(QPointF(0, y_b), QPointF(0, y_t))

        def indexing(v):
            """Draw tick."""
            return int(v / self.zoom - v / self.zoom % 5)

        for x in range(indexing(x_l), indexing(x_r) + 1, 5):
            self.painter.drawLine(
                QPointF(x, 0) * self.zoom,
                QPointF(x * self.zoom, -10 if x % 10 == 0 else -5)
            )
        for y in range(indexing(y_b), indexing(y_t) + 1, 5):
            self.painter.drawLine(
                QPointF(0, y) * self.zoom,
                QPointF(10 if y % 10 == 0 else 5, y * self.zoom)
            )
예제 #3
0
    def __init__(self, mechanism: Dict[str, Any],
                 path: Sequence[Sequence[Tuple[float, float]]],
                 vpoints: List[VPoint], vlinks: List[VLink], parent: QWidget):
        """Input link and path data."""
        super(_DynamicCanvas, self).__init__(parent)
        self.mechanism = mechanism
        self.path.path = path
        self.vpoints = vpoints
        self.vlinks = vlinks
        ranges: Dict[int, Tuple[float, float,
                                float]] = self.mechanism['Placement']
        self.ranges.update({
            f"P{i}":
            QRectF(QPointF(values[0] - values[2], values[1] + values[2]),
                   QSizeF(values[2] * 2, values[2] * 2))
            for i, values in ranges.items()
        })
        same: Dict[int, int] = self.mechanism['same']
        target_path: Dict[int, List[Tuple[float,
                                          float]]] = self.mechanism['Target']
        for i, path in target_path.items():
            for j in range(i):
                if j in same:
                    i -= 1
            self.target_path[f"P{i}"] = path
        self.__index = 0
        self.__interval = 1
        self.__path_count = max(len(path) for path in self.path.path) - 1
        self.pos: List[Tuple[float, float]] = []

        # Error
        self.error = False
        self.__no_error = 0

        # Timer start.
        self.__timer = QTimer()
        self.__timer.timeout.connect(self.__change_index)
        self.__timer.start(18)
예제 #4
0
 def draw_slvs_ranges(self):
     """Draw solving range."""
     pen = QPen()
     pen.setWidth(5)
     for i, (tag, rect) in enumerate(self.ranges.items()):
         range_color = QColor(color_num(i + 1))
         range_color.setAlpha(30)
         self.painter.setBrush(range_color)
         range_color.setAlpha(255)
         pen.setColor(range_color)
         self.painter.setPen(pen)
         cx = rect.x() * self.zoom
         cy = rect.y() * -self.zoom
         if rect.width():
             self.painter.drawRect(
                 QRectF(QPointF(cx, cy),
                        QSizeF(rect.width(), rect.height()) * self.zoom))
         else:
             self.painter.drawEllipse(QPointF(cx, cy), 3, 3)
         range_color.setAlpha(255)
         pen.setColor(range_color)
         self.painter.setPen(pen)
         self.painter.drawText(QPointF(cx, cy) + QPointF(6, -6), tag)
         self.painter.setBrush(Qt.NoBrush)