def __draw_link(self, name: str, points: List[int]): """Draw link function. The link color will be the default color. """ color = color_qt('Blue') pen = QPen(color) pen.setWidth(self.link_width) self.painter.setPen(pen) brush = QColor(226, 219, 190) brush.setAlphaF(0.70) self.painter.setBrush(brush) qpoints = tuple( QPointF(self.pos[i][0], -self.pos[i][1]) * self.zoom for i in points if self.pos[i] and (not isnan(self.pos[i][0])) ) if len(qpoints) == len(points): self.painter.drawPolygon(*qpoints) self.painter.setBrush(Qt.NoBrush) if self.show_point_mark and (name != 'ground') and qpoints: pen.setColor(Qt.darkGray) self.painter.setPen(pen) self.painter.setFont(QFont('Arial', self.font_size)) text = f"[{name}]" cen_x = sum(self.pos[i][0] for i in points if self.pos[i]) cen_y = sum(self.pos[i][1] for i in points if self.pos[i]) self.painter.drawText(QPointF(cen_x, -cen_y) * self.zoom / len(points), text)
def drawLink(self, name: str, points: Tuple[int]): """Draw linkage function. The link color will be the default color. """ color = colorQt('Blue') pen = QPen(color) pen.setWidth(self.linkWidth) self.painter.setPen(pen) brush = QColor(226, 219, 190) brush.setAlphaF(0.70) self.painter.setBrush(brush) qpoints = tuple( QPointF(self.Point[i][0] * self.zoom, self.Point[i][1] * -self.zoom) for i in points if self.Point[i] and not isnan(self.Point[i][0])) if len(qpoints) == len(points): self.painter.drawPolygon(*qpoints) self.painter.setBrush(Qt.NoBrush) if self.showPointMark and name != 'ground' and qpoints: pen.setColor(Qt.darkGray) self.painter.setPen(pen) self.painter.setFont(QFont('Arial', self.fontSize)) text = "[{}]".format(name) cenX = sum(self.Point[i][0] for i in points if self.Point[i]) cenY = sum(self.Point[i][1] for i in points if self.Point[i]) cenX *= self.zoom / len(points) cenY *= -self.zoom / len(points) self.painter.drawText(QPointF(cenX, cenY), text)
def __drawLink(self, vlink: VLink): """Draw a link.""" points = [] for i in vlink.points: vpoint = self.Points[i] if vpoint.type == 1 or vpoint.type == 2: coordinate = vpoint.c[0 if (vlink.name == vpoint.links[0]) else 1] x = coordinate[0] * self.zoom y = coordinate[1] * -self.zoom else: x = vpoint.cx * self.zoom y = vpoint.cy * -self.zoom points.append((x, y)) pen = QPen(vlink.color) pen.setWidth(self.linkWidth) self.painter.setPen(pen) brush = QColor(226, 219, 190) brush.setAlphaF(self.transparency) self.painter.setBrush(brush) #Rearrange: Put the nearest point to the next position. qpoints = convex_hull(points) if qpoints: self.painter.drawPolygon(*qpoints) self.painter.setBrush(Qt.NoBrush) if ((not self.showPointMark) or (vlink.name == 'ground') or (not qpoints)): return pen.setColor(Qt.darkGray) self.painter.setPen(pen) cenX = sum(p[0] for p in points) / len(points) cenY = sum(p[1] for p in points) / len(points) self.painter.drawText(QPointF(cenX, cenY), '[{}]'.format(vlink.name))
def __draw_link(self, vlink: VLink): """Draw a link.""" if vlink.name == 'ground' or (not vlink.points): return points = self.__points_pos(vlink) pen = QPen() # Rearrange: Put the nearest point to the next position. qpoints = convex_hull(points, as_qpoint=True) if (self.select_mode == SelectMode.Link and self.vlinks.index(vlink) in self.selections): pen.setWidth(self.link_width + 6) pen.setColor(Qt.black if self.monochrome else QColor(161, 16, 239)) self.painter.setPen(pen) self.painter.drawPolygon(*qpoints) pen.setWidth(self.link_width) pen.setColor(Qt.black if self.monochrome else QColor(*vlink.color)) self.painter.setPen(pen) brush = QColor(Qt.darkGray) if self.monochrome else QColor( 226, 219, 190) brush.setAlphaF(self.transparency) self.painter.setBrush(brush) self.painter.drawPolygon(*qpoints) self.painter.setBrush(Qt.NoBrush) if not self.show_point_mark: return pen.setColor(Qt.darkGray) self.painter.setPen(pen) p_count = len(points) cen_x = sum(p[0] for p in points) / p_count cen_y = sum(p[1] for p in points) / p_count self.painter.drawText(QRectF(cen_x - 50, cen_y - 50, 100, 100), Qt.AlignCenter, f'[{vlink.name}]')