def draw_labels(self): self.label_items = {} # Тексты for s in self.shemetype.task["labels"]: self.draw_label( paintool.greek(s.text), ( s.pos[0]*self.labels_width_scale+self.labels_center.x(), s.pos[1]+self.labels_center.y() ), label=s)
def do_label(i, pnt=QPointF(0, 0), hint=None): text = self.shemetype.task["labels"][i].text x = self.shemetype.task["labels"][i].x y = self.shemetype.task["labels"][i].y item = TextItem(paintool.greek(text), font=self.font, center=pnt + QPointF(x, y), pen=self.pen) self.scene.addItem(item) self.hovers[hint] = item item.hint = hint
def draw_section_routine(self, hcenter, right, painter=None): if hasattr(self.shemetype, "section_enable"): section_enable = self.shemetype.section_enable.get() else: section_enable = True if section_enable and self.shemetype.section_container.section_type.get( ) in section_variant_base: section_width = draw_section( wdg=self, section_type=self.shemetype.section_container.section_type.get(), arg0=int(self.shemetype.section_container.base_section_widget.arg0. get()), arg1=int(self.shemetype.section_container.base_section_widget.arg1. get()), arg2=int(self.shemetype.section_container.base_section_widget.arg2. get()), txt0=paintool.greek(self.shemetype.section_container. base_section_widget.txt0.get()), txt1=paintool.greek(self.shemetype.section_container. base_section_widget.txt1.get()), txt2=paintool.greek(self.shemetype.section_container. base_section_widget.txt2.get()), arrow_size=self.shemetype.arrow_size.get(), right=right, hcenter=hcenter, painter=painter) elif section_enable: # небазовый список section_width = self.shemetype.section_container.draw( wdg=self, shemetype=self.shemetype, right=right, hcenter=hcenter, arrow_size=self.shemetype.arrow_size.get(), painter=painter) else: section_width = 0 return section_width
def paintEvent(self, ev): self.common_scene = QGraphicsScene() try: self.paintEventCommon() self.eval_hcenter() self.paintEventImplementation(ev) if self.common_mouse_events_enabled: self.common_scene.addRect(0,0,self.width(),self.height(), pen=QPen(Qt.NoPen)) self.common_scene.render(self.painter) if not self.no_text_render: addtext = self.shemetype.texteditor.toPlainText() self.painter.setPen(self.pen) self.painter.setFont(self.font) self.painter.setBrush(Qt.black) n = len(addtext.splitlines()) for i, l in enumerate(addtext.splitlines()): self.painter.drawText(QPoint( 40, self.height() - QFontMetrics(self.font).height()*(n-i)), paintool.greek(l)) self.painter.end() if self.resize_after_render_data is not None: common.PAINT_CONTAINER.resize( self.resize_after_render_data[0], self.resize_after_render_data[1] ) self.resize_after_render_data = None except Exception as ex: if EXIT_ON_EXCEPT: traceback.print_exc() exit(0) txt = traceback.format_exc() msg = QMessageBox() msg.setText("Возникла ошибка при отрисовке задачи:") msg.setInformativeText(txt) msg.setStandardButtons(QMessageBox.Ok) print(txt) msg.exec() self.painter.end()
def paintEventImplementation(self, ev): self.scene = QGraphicsScene() self.painter.setRenderHints(QPainter.Antialiasing) self.drawCube(0) if self.shemetype.second_cube.get(): self.drawCube(1, off=self.scene.itemsBoundingRect().width()) for k, h in self.hovers.items(): if self.selected_item == k: green70 = QColor(0, 255, 0) green70.setAlphaF(0.7) self.scene.addRect(h.boundingRect(), brush=green70) rect = self.scene.itemsBoundingRect() addtext = paintool.greek(self.shemetype.texteditor.toPlainText()) n = len(addtext.splitlines()) for i, l in enumerate(addtext.splitlines()): t = self.scene.addText(l, self.font) t.setPos( rect.x(), rect.height() + rect.y() + QFontMetrics(self.font).height() * i) WBORDER = self.shemetype.wborder.get() HBORDER = self.shemetype.hborder.get() #self.BORDER = BORDER rect = self.scene.itemsBoundingRect() br = QColor(0, 0, 0) br.setAlphaF(0) p = QPen() p.setColor(br) self.scene.addRect(QRectF(rect.x() - WBORDER, rect.y() - HBORDER, rect.width() + WBORDER * 2, rect.height() + HBORDER * 2), pen=p, brush=br) #self.scene.addEllipse(QRectF(self.track_point - QPointF(3,3), self.track_point + QPointF(3,3))) #self.rect = self.scene.itemsBoundingRect() self.offset = QPointF(rect.x() - WBORDER, rect.y() - HBORDER) #self.scene.setSceneRect(rect.x() - 1*BORDER, rect.y() - 1*BORDER, rect.width() + 2*BORDER, rect.height() + 2*BORDER) self.scene.render(self.painter) #if self.scene_bound() != self.last_size: self.resize_after_render(*self.scene_bound())
def draw_diameters(self, i, strt_height, fini_height): self.painter.setPen(self.default_pen) self.painter.setBrush(self.default_brush) d = self.task["sections"][i].d text = common.pretty_str(d, "d") if self.task["sections"][i].dtext: text = paintool.greek(self.task["sections"][i].dtext) paintool.draw_vertical_dimlines_with_text( painter=self.painter, upnt=QPointF((self.wsect(i) + self.wsect(i + 1)) / 2, strt_height), dpnt=QPointF((self.wsect(i) + self.wsect(i + 1)) / 2, fini_height), arrow_size=10, textpnt=QPointF(0, -QFontMetrics(self.font).height() / 4), text=text, font=self.font)
def draw_body(self, hcenter, left, right): painter = self.painter painter.setFont(self.font) prefix = 30 hsect = self.shemetype.base_section_height.get() flen = right - left - 2 * prefix lsum = self.lsum() step = flen / lsum cur = left + prefix wpnts = [cur] for sect in self.sections(): cur += sect.l * step wpnts.append(cur) painter.setPen(self.pen) for i in range(len(self.bsections())): fdown = False arrow_size = self.shemetype.arrow_size.get() rad = 60 if self.bsections()[i].M != "Нет": fdown = True pnt = QPoint(wpnts[i], hcenter) if self.bsections()[i].M == "+": paintool.half_moment_arrow_common(painter=painter, pnt=pnt, rad=rad, angle=deg(60), angle2=deg(120), arrow_size=arrow_size) if self.bsections()[i].M == "-": paintool.half_moment_arrow_common(painter=painter, pnt=pnt, rad=rad, angle=deg(120), angle2=deg(60), arrow_size=arrow_size) if self.bsections()[i].F != "Нет": apnt = QPoint(wpnts[i], hcenter - rad) bpnt = QPoint(wpnts[i], hcenter) if fdown: apnt = apnt + QPoint(0, rad + hsect / 2) bpnt = bpnt + QPoint(0, rad + hsect / 2) else: apnt = apnt + QPoint(0, -hsect / 2) bpnt = bpnt + QPoint(0, -hsect / 2) if self.bsections()[i].F == "-": paintool.common_arrow(painter, apnt, bpnt, arrow_size=arrow_size) if self.bsections()[i].F == "+": paintool.common_arrow( painter, bpnt, apnt, arrow_size=self.shemetype.arrow_size.get()) if self.bsections()[i].F == "влево" or self.bsections( )[i].F == "вправо": apnt = QPoint(wpnts[i], hcenter) d = 40 if i == 0: paintool.common_arrow( painter, apnt if self.bsections()[i].F == "влево" else apnt + QPointF(-d, 0), apnt + QPointF(-d, 0) if self.bsections()[i].F == "влево" else apnt, arrow_size=self.shemetype.arrow_size.get()) elif i == len(self.bsections()) - 1: paintool.common_arrow( painter, apnt + QPointF(d, 0) if self.bsections()[i].F == "влево" else apnt, apnt if self.bsections()[i].F == "влево" else apnt + QPointF(d, 0), arrow_size=self.shemetype.arrow_size.get()) else: d = 30 bpnt = apnt + QPointF(0, 25) cpnt = apnt - QPointF(0, 25) nnn = QPointF(-d, 0) if self.bsections( )[i].F == "влево" else QPointF(d, 0) paintool.common_arrow( painter, bpnt, bpnt + nnn, arrow_size=self.shemetype.arrow_size.get()) paintool.common_arrow( painter, cpnt, cpnt + nnn, arrow_size=self.shemetype.arrow_size.get()) self.painter.drawLine(bpnt, cpnt) if self.bsections()[i].M != "Нет": paintool.draw_text_centered( painter, pnt=QPoint(wpnts[i], hcenter - rad - 5), text=paintool.greek(self.bsections()[i].MT), font=self.font) if self.bsections()[i].F != "Нет": if (self.bsections()[i].F != "вправо" and self.bsections()[i].F != "влево"): if fdown == False: painter.drawText( QPoint(wpnts[i] + 10, hcenter - rad), paintool.greek(self.bsections()[i].FT)) if fdown == True: painter.drawText( QPoint(wpnts[i] + 10, hcenter + 25), paintool.greek(self.bsections()[i].FT)) else: painter.drawText(QPoint(wpnts[i] + 0, hcenter - 30), paintool.greek(self.bsections()[i].FT)) if self.bsections()[i].sectname != "": off = 11 if self.bsections()[i].sharn != "" else 5 painter.drawText( QPoint( wpnts[i] - off - QFontMetrics(self.font).width( self.bsections()[i].sectname), hcenter + 21), self.bsections()[i].sectname) rad2 = rad / 2 step = 10 # Отрисовка распределённых нагрузок: for i in range(len(self.sectforce())): #отрисовка распределённой силы. if self.sectforce()[i].Fr != "Нет": if self.sectforce()[i].Fr == "+": paintool.raspred_force_vertical( painter=painter, apnt=QPoint(wpnts[i], hcenter - 3), bpnt=QPoint(wpnts[i + 1], hcenter - 3), step=step, offset=QPoint(0, -rad2), dim=True, arrow_size=arrow_size / 3 * 2) elif self.sectforce()[i].Fr == "-": paintool.raspred_force_vertical( painter=painter, apnt=QPoint(wpnts[i], hcenter - 3), bpnt=QPoint(wpnts[i + 1], hcenter - 3), step=step, offset=QPoint(0, -rad2), dim=False, arrow_size=arrow_size / 3 * 2) paintool.draw_text_centered( painter, QPoint((wpnts[i] + wpnts[i + 1]) / 2, hcenter - 8 - rad2), paintool.greek(self.sectforce()[i].FrT), font=self.font) painter.setBrush(Qt.white) painter.setPen(self.pen) painter.drawRect( QRect( QPoint(left + prefix, hcenter - hsect / 2), QPoint(right - prefix, hcenter + hsect / 2), )) #dimlines for i in range(len(self.bsections()) - 1): paintool.dimlines(painter, QPoint(wpnts[i], hcenter), QPoint(wpnts[i + 1], hcenter), hcenter + 80) text = util.text_prepare_ltext(self.sections()[i].l) if self.shemetype.postfix.get()[0]: text += self.shemetype.postfix.get()[1] paintool.draw_text_centered( painter, QPoint((wpnts[i] + wpnts[i + 1]) / 2, hcenter + 80 - 5), text, self.font) self.draw_terminator(pos=wpnts[0], angle=math.pi, type=self.shemetype.left_node.get()) self.draw_terminator(pos=wpnts[-1], angle=0, type=self.shemetype.right_node.get()) for i in range(len(self.bsections())): if self.bsections()[i].sharn == "1": hoff = 0 if i == 0 or i == len(self.bsections()) - 1 else 8 ihoff = 8 if i == 0 or i == len(self.bsections()) - 1 else 0 paintool.draw_sharnir_1dim(painter, pnt=QPoint(wpnts[i], hcenter + hoff), angle=math.pi / 2, rad=5.5, termrad=25 + ihoff, termx=20, termy=10, pen=self.pen, halfpen=self.halfpen, doublepen=self.doublepen) elif self.bsections()[i].sharn == "2": hoff = 0 if i == 0 or i == len(self.bsections()) - 1 else 8 ihoff = 8 if i == 0 or i == len(self.bsections()) - 1 else 0 paintool.draw_sharnir_2dim(painter, pnt=QPoint(wpnts[i], hcenter + hoff), angle=math.pi / 2, rad=5.5, termrad=25 + ihoff, termx=20, termy=10, pen=self.pen, halfpen=self.halfpen)
def paintEventImplementation(self, ev): assert len(self.sections()) == len(self.bsections()) width = self.width() height = self.height() center = QPoint(width / 2, self.hcenter) self.labels_center = center font_size = self.shemetype.font_size.get() lwidth = self.shemetype.line_width.get() base_h = self.shemetype.base_h.get() zadelka = self.shemetype.zadelka.get() axis = self.shemetype.axis.get() zadelka_len = self.shemetype.zadelka_len.get() dimlines_step = self.shemetype.dimlines_step.get() dimlines_start_step = self.shemetype.dimlines_start_step.get() arrow_size = self.shemetype.arrow_size.get() font = self.painter.font() font.setItalic(True) font.setPointSize(font_size) self.painter.setFont(font) default_pen = QPen() default_pen.setWidth(lwidth) self.painter.setPen(default_pen) default_brush = QBrush(Qt.SolidPattern) default_brush.setColor(Qt.white) self.painter.setBrush(default_brush) font = self.painter.font() font.setItalic(True) font.setPointSize(font_size) self.painter.setFont(font) left_span = 50 right_span = 50 up_span = 100 down_span = 100 + len( self.sections()) * dimlines_step + dimlines_start_step if zadelka: left_span += base_h + zadelka_len right_span += base_h + zadelka_len width_span = left_span + right_span height_span = up_span + down_span center = center + QPoint(left_span - right_span, (up_span - down_span) / 2) maxd = 0 maxh = 0 for s in self.sections(): if s.d > maxd: maxd = s.d if s.h > maxh: maxh = s.h base_d = (width - width_span) / maxd self.labels_width_scale = base_d sprev = None for s in reversed(self.sections()): shtrih = s.shtrih w = s.d * base_d h = s.h * base_h if sprev: sprev_d = sprev.d * base_d sprev_h = sprev.h * base_h if s.intgran: self.painter.drawRect( QRect(center.x() - w / 2, center.y() - h / 2, w, h)) else: pen = QPen() pen.setWidth(lwidth) pen.setColor(Qt.white) self.painter.setPen(pen) brush = QBrush(Qt.SolidPattern) brush.setColor(Qt.white) self.painter.setBrush(brush) self.painter.drawRect( QRect(center.x() - w / 2, center.y() - (maxh * base_h) / 2, w, maxh * base_h)) pen.setColor(Qt.black) self.painter.setPen(pen) self.painter.drawLine( QPoint(center.x() - w / 2, center.y() - h / 2), QPoint(center.x() + w / 2, center.y() - h / 2)) self.painter.drawLine( QPoint(center.x() - w / 2, center.y() + h / 2), QPoint(center.x() + w / 2, center.y() + h / 2)) if sprev: self.painter.drawLine( QPoint(center.x() - w / 2, center.y() - h / 2), QPoint(center.x() - w / 2, center.y() - sprev_h / 2)) self.painter.drawLine( QPoint(center.x() - w / 2, center.y() + h / 2), QPoint(center.x() - w / 2, center.y() + sprev_h / 2)) self.painter.drawLine( QPoint(center.x() + w / 2, center.y() - h / 2), QPoint(center.x() + w / 2, center.y() - sprev_h / 2)) self.painter.drawLine( QPoint(center.x() + w / 2, center.y() + h / 2), QPoint(center.x() + w / 2, center.y() + sprev_h / 2)) if shtrih: pen = QPen(Qt.NoPen) pen.setWidth(lwidth) self.painter.setPen(pen) brush = QBrush(Qt.BDiagPattern) brush.setColor(Qt.black) self.painter.setBrush(brush) self.painter.drawRect( QRect(center.x() - w / 2 - lwidth / 2, center.y() - h / 2 - lwidth / 2, w + lwidth, h + lwidth)) self.painter.setPen(default_pen) self.painter.setBrush(default_brush) sprev = s if zadelka: fsect = self.sections()[-1] h = fsect.h * base_h w = zadelka_len c = base_h lx = center.x() - fsect.d * base_d / 2 llx = center.x() - fsect.d * base_d / 2 - w rx = center.x() + fsect.d * base_d / 2 rrx = center.x() + fsect.d * base_d / 2 + w uy = center.y() - h / 2 dy = center.y() + h / 2 pen = QPen(Qt.NoPen) pen.setWidth(lwidth) self.painter.setPen(pen) brush = QBrush(Qt.FDiagPattern) brush.setColor(Qt.black) self.painter.setBrush(brush) self.painter.drawRect(QRect(llx - c, uy - c, w + c, h + 2 * c)) self.painter.drawRect(QRect(rx, uy - c, w + c, h + 2 * c)) brush = QBrush(Qt.SolidPattern) brush.setColor(Qt.white) self.painter.setBrush(brush) self.painter.drawRect( QRect(llx - lwidth / 2, uy - lwidth / 2, w + lwidth, h + lwidth)) self.painter.drawRect( QRect(rx - lwidth / 2, uy - lwidth / 2, w + lwidth, h + lwidth)) self.painter.setBrush(default_brush) brush = QBrush(Qt.BDiagPattern) brush.setColor(Qt.black) self.painter.setBrush(brush) self.painter.drawRect( QRect(llx - lwidth / 2, uy - lwidth / 2, w + lwidth, h + lwidth)) self.painter.drawRect( QRect(rx - lwidth / 2, uy - lwidth / 2, w + lwidth, h + lwidth)) self.painter.setPen(default_pen) self.painter.drawLine(QPoint(llx, uy), QPoint(lx, uy)) self.painter.drawLine(QPoint(llx, uy), QPoint(llx, dy)) self.painter.drawLine(QPoint(llx, dy), QPoint(lx, dy)) self.painter.drawLine(QPoint(rx, uy), QPoint(rrx, uy)) self.painter.drawLine(QPoint(rrx, uy), QPoint(rrx, dy)) self.painter.drawLine(QPoint(rx, dy), QPoint(rrx, dy)) self.painter.setPen(default_pen) self.painter.setBrush(default_brush) if axis: pen = QPen(Qt.DashDotLine) pen.setWidth(lwidth) self.painter.setPen(pen) self.painter.drawLine( QPoint(center.x(), center.y() + (maxh) * base_h / 2 + 10), QPoint(center.x(), center.y() - (maxh) * base_h / 2 - 10)) i = 0 wprev = 0 for s in self.sections(): """Текстовые поля""" w = s.d * base_d h = s.h * base_h c = center i += 1 self.painter.setPen(default_pen) self.painter.setBrush(default_brush) pen = QPen() pen.setWidth(lwidth / 2) self.painter.setPen(pen) if s.dtext_en: p0 = QPoint(center.x() - s.d / 2 * base_d, center.y() + s.h / 2 * base_h) p1 = QPoint(center.x() + s.d / 2 * base_d, center.y() + s.h / 2 * base_h) level = center.y( ) + maxh / 2 * base_h + dimlines_start_step + dimlines_step * i if s.dtext == "": dtxt = paintool.greek( "\\diam{}d".format(s.d if s.d != 1 else "")) else: dtxt = paintool.greek(s.dtext) paintool.dimlines(self.painter, p0, p1, level) paintool.draw_text_centered( self.painter, QPoint((p0.x() + p1.x()) / 2, level - 5), dtxt, font) if s.htext_en: if s.htext == "": htxt = paintool.greek( "{}h".format(s.h if s.h != 1 else "")) else: htxt = paintool.greek(s.htext) paintool.draw_vertical_splashed_dimlines_with_text( self.painter, c + QPoint(wprev / 2 + (w - wprev) / 4, -h / 2), c + QPoint(wprev / 2 + (w - wprev) / 4, h / 2), 10, c, htxt, font) wprev = w wprev = 0 for i in range(len(self.sectforce())): """ Отрисовываем распределенную нагрузку.""" s = self.sections()[i] sf = self.sectforce()[i] distrib_step = 10 distrib_alen = 20 w = s.d * base_d h = s.h * base_h c = center if sf.distrib: apnt = center + QPointF(w / 2, -h / 2 - lwidth) bpnt = center + QPointF(wprev / 2, -h / 2 - lwidth) paintool.draw_distribload(self.painter, apnt, bpnt, distrib_step, arrow_size / 3 * 2, distrib_alen) apnt = center + QPointF(-wprev / 2, -h / 2 - lwidth) bpnt = center + QPointF(-w / 2, -h / 2 - lwidth) paintool.draw_distribload(self.painter, apnt, bpnt, distrib_step, arrow_size / 3 * 2, distrib_alen) apnt = center + QPointF(wprev / 2, -h / 2 - lwidth - distrib_alen) bpnt = center + QPointF(-wprev / 2, -h / 2 - lwidth - distrib_alen) self.painter.drawLine(apnt, bpnt) wprev = w for i in range(len(self.bsections())): b = self.bsections()[i] s = self.sections()[i] w = s.d * base_d h = s.h * base_h c = center alen = 40 moment_radius = 40 if b.fen != "нет": apnt0 = center + QPoint(w / 2, -h / 2 - lwidth) apnt1 = center + QPoint(-w / 2, -h / 2 - lwidth) if b.fen == "-": paintool.common_arrow(self.painter, apnt0 + QPoint(0, -alen), apnt0, arrow_size) paintool.common_arrow(self.painter, apnt1 + QPoint(0, -alen), apnt1, arrow_size) if b.fen == "+": paintool.common_arrow(self.painter, apnt0, apnt0 + QPoint(0, -alen), arrow_size) paintool.common_arrow(self.painter, apnt1, apnt1 + QPoint(0, -alen), arrow_size) self.painter.drawLine(apnt0 + QPoint(0, -alen), apnt1 + QPoint(0, -alen)) if b.men != "нет": direction = b.men == "+" arrow_size_pair = (arrow_size, 4) for apnt, direction in [ (center + QPoint(w / 2, 0), not direction), (center + QPoint(-w / 2, 0), direction) ]: self.common_scene.addItem( SquareMomentItem(apnt, moment_radius / 2, h / 2 + 32, inverse=direction, arrow_size=arrow_size_pair, brush=Qt.black)) if b.sharn != "нет": termrad = 20 for w in [w, -w]: if self.bsections()[i].sharn == "1": paintool.draw_sharnir_1dim(self.painter, pnt=center + QPoint(w / 2, h / 2 + 3), angle=math.pi / 2, rad=3.5, termrad=termrad, termx=15, termy=10, pen=self.pen, halfpen=self.halfpen, doublepen=self.doublepen) elif self.bsections()[i].sharn == "2": paintool.draw_sharnir_2dim(self.painter, pnt=center + QPoint(w / 2, h / 2 + 3), angle=math.pi / 2, rad=3.5, termrad=termrad, termx=15, termy=10, pen=self.pen, halfpen=self.halfpen) self.draw_labels()
def paintEventImplementation(self, ev): """Рисуем сцену согласно объекта задания""" subtype = self.shemetype.task_subtype.get() self.subtype = subtype font_size = self.shemetype.font_size.get() font = self.painter.font() font.setItalic(True) font.setPointSize(font_size) self.painter.setFont(font) self.font = font lwidth = self.shemetype.lwidth.get() axis = self.shemetype.axis.get() zleft = self.shemetype.zleft.get() self.zleft = zleft zright = self.shemetype.zright.get() self.zright = zright base_section_height = self.shemetype.base_section_height.get() arrow_size = self.shemetype.arrow_size.get() self.arrow_size = arrow_size arrow_head_size = self.shemetype.arrow_size.get() self.arrow_head_size = arrow_head_size razm = self.shemetype.razm.get() self.razm = razm task = self.shemetype.task self.task = task size = self.size() width = size.width() height = size.height() #kruch_flag = self.shemetype.kruch_flag.get() kruch_flag = False if subtype == SUBTYPE_RASTYAZHENIE_SJATIE else True addtext = self.shemetype.texteditor.toPlainText() arrow_line_size = 50 self.arrow_line_size = arrow_line_size hcenter = self.hcenter height_zone = base_section_height self.height_zone = height_zone self.strt_width = self.shemetype.left_zone.get() self.fini_width = width - self.shemetype.right_zone.get() if subtype == SUBTYPE_RASTYAZHENIE_SJATIE: if self.bsections()[0].Fstyle != "к узлу": if self.bsections()[0].F == "-": self.strt_width = self.strt_width + arrow_line_size if self.bsections()[-1].Fstyle != "к узлу": if self.bsections()[-1].F == "+": self.fini_width = self.fini_width - arrow_line_size if self.bsections()[0].Fstyle == "к узлу": if self.bsections()[0].F == "+": self.strt_width = self.strt_width + arrow_line_size if self.bsections()[-1].Fstyle == "к узлу": if self.bsections()[-1].F == "-": self.fini_width = self.fini_width - arrow_line_size br = QPen() br.setWidth(lwidth) self.painter.setPen(br) maxl = 0 maxA = 0 for s in self.sections(): if s.l > maxl: maxl = s.l if s.A > maxA: maxA = s.A dimlines_level = hcenter + base_section_height * math.sqrt( maxA) / 2 + self.shemetype.dimlines_start_step.get() self.dimlines_level = dimlines_level if razm is True: hcenter -= self.shemetype.dimlines_start_step.get() / 2 self.hcenter = hcenter if razm is False: pass # Длины и дистанции self.summary_length = 0 self.ll = [0] for i in range(len(task["sections"])): self.summary_length += task["sections"][i].l self.ll.append(self.ll[i] + task["sections"][i].l) # Отрисовка секций for i in range(len(task["sections"])): hkoeff = self.sectrad_koeff(i) strt_height = hcenter - height_zone * hkoeff / 2 fini_height = hcenter + height_zone * hkoeff / 2 self.draw_section(i, strt_height, fini_height) self.draw_dimlines(i, strt_height, fini_height) self.painter.setBrush(self.default_brush) self.painter.setPen(self.default_pen) if axis: pen = QPen(Qt.CustomDashLine) pen.setDashPattern([10, 3, 1, 3]) self.painter.setPen(pen) self.painter.drawLine(QPointF(5, hcenter), QPointF(width - 5, hcenter)) pen = QPen() self.painter.setPen(pen) # отрисовка сил if subtype == SUBTYPE_RASTYAZHENIE_SJATIE: self.force_drawing() else: self.torsion_drawing() for i in range(len(task["sections"])): hkoeff = self.sectrad_koeff(i) strt_height = hcenter - height_zone * hkoeff / 2 fini_height = hcenter + height_zone * hkoeff / 2 if self.subtype == SUBTYPE_KRUCHENIE_2: self.draw_diameters(i, strt_height, fini_height) self.painter.setBrush(self.default_brush) self.painter.setPen(self.default_pen) for i in range(len(task["betsect"])): if task["betsect"][i].label != "": self.painter.setPen(self.halfpen) if task["betsect"][i].label_off == "справа-сверху": elements.draw_text_by_points( self, strt=QPointF(self.wsect(i), hcenter - self.msectrad(i)), fini=QPointF(self.wsect(i), hcenter - self.msectrad(i) - 40), txt=task["betsect"][i].label, alttxt=False, off=14, polka=QPointF(self.wsect(i), hcenter)) elif task["betsect"][i].label_off == "справа": txt = task["betsect"][i].label self.painter.setPen(Qt.NoPen) self.painter.drawRect( QRectF( QPointF( self.wsect(i) - 3 + 6, hcenter - QFontMetrics(self.font).height() / 2), QPointF( self.wsect(i) + 3 + 6 + QFontMetrics(self.font).width(txt), hcenter + QFontMetrics(self.font).height() / 2))) self.painter.setPen(self.default_pen) elements.draw_text_by_points( self, strt=QPointF(self.wsect(i), hcenter + self.msectrad(i)), fini=QPointF(self.wsect(i), hcenter - self.msectrad(i)), txt=task["betsect"][i].label, alttxt=False, off=6, polka=None) elif task["betsect"][i].label_off == "слева-снизу": elements.draw_text_by_points( self, strt=QPointF(self.wsect(i), hcenter + self.msectrad(i)), fini=QPointF(self.wsect(i), hcenter + self.msectrad(i) + 40), txt=task["betsect"][i].label, alttxt=True, off=-24, polka=QPointF(self.wsect(i), hcenter)) # подсветка узла if self.highlited_node is not None: row = self.highlited_node[1] pen = QPen() pen.setColor(Qt.blue) pen.setWidth(5) p = QPoint(self.wsect(row), self.hcenter) self.painter.setBrush(Qt.green) self.painter.drawEllipse(QRect(p - QPoint(5, 5), p + QPoint(5, 5))) self.painter.setBrush(Qt.black) if zleft: y = self.sectrad(0) + 20 paintool.zadelka(self.painter, self.wsect(0) - 10, self.wsect(0), hcenter - y, hcenter + y, left_border=False, right_border=True) if zright: y = self.sectrad(-1) + 20 paintool.zadelka(self.painter, self.wsect(-1), self.wsect(-1) + 10, hcenter - y, hcenter + y, left_border=True, right_border=False) sects = task["sections"] for i in range(len(sects)): self.painter.setPen(self.halfpen) if sects[i].label != "": elements.draw_text_by_points( self, QPoint(self.wsect(i), hcenter - self.sectrad(i)), QPoint(self.wsect(i + 1), hcenter - self.sectrad(i)), txt=paintool.greek(sects[i].label) + ("" if sects[i].label_height > -20 else " "), alttxt=True, polka=QPointF((self.wsect(i + 1) + self.wsect(i)) / 2, hcenter))
def draw_dimlines(self, i, strt_height, fini_height): task = self.task A = task["sections"][i].A l = task["sections"][i].l E = task["sections"][i].E if self.subtype == SUBTYPE_RASTYAZHENIE_SJATIE: sechtext = "A" AA = task["sections"][i].A else: sechtext = "GIk" AA = task["sections"][i].GIk text_E = common.pretty_str(E, "E") if not self.is_delta(i): if abs(float(AA) - int(AA)) < 0.0001: text_A = "{}{}".format(int(AA + 0.1), sechtext) if AA != 1 else sechtext else: text_A = str(float(AA)) + sechtext if abs(float(l) - int(l)) < 0.0001: text_l = "{}l".format( int(task["sections"][i].l + 0.1)) if task["sections"][i].l != 1 else "l" else: text_l = str(float(l)) + "l" else: text_l = "" text_A = "" text_l = paintool.greek(text_l) text_A = paintool.greek(text_A) text_E = paintool.greek(text_E) self.painter.setPen(Qt.black) lW = QFontMetrics(self.font).width(text_l) AW = QFontMetrics(self.font).width(text_A) if task["sections"][i].text != "" or self.is_delta(i): text = paintool.greek(task["sections"][i].text) else: if self.subtype == SUBTYPE_KRUCHENIE_1: text = "{}, {}".format(text_l, text_A) elif self.subtype == SUBTYPE_RASTYAZHENIE_SJATIE: text = "{}, {}, {}".format(text_l, text_A, text_E) elif self.subtype == SUBTYPE_KRUCHENIE_2: text = "{}, G".format(text_l) if self.razm: self.painter.setPen(self.halfpen) splashed = self.wsect(i + 1) - self.wsect(i) < 20 paintool.draw_dimlines( self.painter, QPoint(self.wsect(i), fini_height), QPoint(self.wsect(i + 1), fini_height), offset=QPoint(0, self.dimlines_level - fini_height), textoff=QPoint(0, -3 - QFontMetrics(self.font).height() / 2), arrow_size=10, text=text, splashed=splashed)
def paintEventImplementation(self, ev): sects = self.shemetype.task["sections"] #firstdir = self.shemetype.first_dir.get() #angle = deg(180) if firstdir else deg(90) sharnrad = self.shemetype.sharnrad.get() width = self.width() height = self.height() font_size = self.shemetype.font_size.get() lwidth = self.shemetype.line_width.get() base_length = self.shemetype.base_length.get() self.base_length = base_length # Расчитываем центр. xmin, ymin = 0, 0 xmax, ymax = 0, 0 self.make_off_lists() for i in range(len(sects)): length = 0 sect = self.sections()[i] if sects[i].body == True: length = sect.l elif sects[i].body == False and (sects[i].force == "к" or sects[i].force == "от"): length = 40 / base_length elif sects[i].body == False and (sects[i].force == "нет" or sects[i].force == "вдоль"): continue angle = deg(sect.angle) point = ( math.cos(angle) * (length) + self.xoff(i), math.sin(angle) * (length) + self.yoff(i), ) xmin, xmax = min(xmin, point[0]), max(xmax, point[0]) ymin, ymax = min(ymin, point[1]), max(ymax, point[1]) center = QPointF(width/2, self.hcenter) + \ QPointF(-(xmax + xmin)* base_length, (ymax + ymin)* base_length)/2 self.c = center def get_coord(i): sect = self.sections()[i] angle = sect.angle length = sect.l * base_length strt = center + QPointF(base_length * self.xoff(i), base_length * self.yoff(i)) pnt = strt + QPoint( math.cos(angle) * length, -math.sin(angle) * length) return pnt def hasnode(pnt): jpnt = center diff = math.sqrt((pnt.x() - jpnt.x())**2 + (pnt.y() - jpnt.y())**2) if diff < 0.1: return True for i in range(len(self.sections())): if self.sections()[i].body == False or self.sections( )[i].sharn == "нет": continue jpnt = get_coord(i) diff = math.sqrt((pnt.x() - jpnt.x())**2 + (pnt.y() - jpnt.y())**2) if diff < 0.1: return True return False rad = 50 rad2 = 60 rad3 = 70 # Рисуем доб угол for i in range(len(sects)): sect = self.sections()[i] angle = sects[i].angle #strt = center + QPointF(base_length * sect.xoff, base_length * sect.yoff) strt = self.get_node_coordinate(sect.start_from) if sect.addangle != 0: tgtangle = sect.angle + sect.addangle if self.highlited_sect is not None and self.highlited_sect[ 1] == i: pen = self.dashgreen else: pen = QPen(Qt.DashDotLine) pen.setWidth(2) self.painter.setPen(pen) pnt1 = strt + rad2 * QPointF(math.cos(deg(angle)), -math.sin(deg(angle))) pnt2 = strt + rad2 * QPointF(math.cos(deg(tgtangle)), -math.sin(deg(tgtangle))) cpnt = strt + rad3 * QPointF( math.cos(deg(tgtangle + angle) / 2), -math.sin(deg(tgtangle + angle) / 2)) self.painter.drawLine(strt, pnt1) self.painter.drawLine(strt, pnt2) if self.highlited_sect is not None and self.highlited_sect[ 1] == i: pen = self.halfgreen else: pen = self.halfpen self.painter.setPen(pen) self.painter.drawArc(paintool.radrect(strt, rad), angle * 16, sect.addangle * 16) paintool.draw_text_centered( painter=self.painter, pnt=cpnt + QPointF(0, QFontMetrics(self.font).height() / 4), text=paintool.greek(str(abs(sect.addangle)) + "\\degree"), font=self.font) # Рисуем тело for i in range(len(sects)): sect = self.sections()[i] angle = deg(sect.angle) self.painter.setPen(self.pen) if self.highlited_sect is not None and self.highlited_sect[1] == i: self.painter.setPen(self.widegreen) else: self.painter.setPen(self.doublepen) if sect.body: length = sect.l * base_length strt = self.c + self.coordinate_of_start(i) if hasnode(strt): spnt = strt + QPoint( math.cos(angle) * 7, -math.sin(angle) * 7) else: spnt = strt pnt = self.c + self.coordinate_of_finish(i) if not sect.wide: self.painter.drawLine(strt, pnt) else: self.painter.drawLine(strt, pnt) self.painter.drawLine(strt + QPointF(0, 8), pnt + QPointF(0, 8)) self.painter.drawLine(strt, strt + QPointF(0, 8)) self.painter.drawLine(pnt, pnt + QPointF(0, 8)) if self.highlited_sect is not None and self.highlited_sect[ 1] == i: self.painter.setPen(self.green) else: self.painter.setPen(self.pen) self.painter.setBrush(Qt.white) if sect.sharn == "шарн+заделка": paintool.zadelka_sharnir(self.painter, pnt, -angle, 30, 10, sharnrad) elif sect.sharn == "шарн": self.painter.setBrush(Qt.white) self.painter.drawEllipse(paintool.radrect(pnt, sharnrad)) if sect.start_from != -1: if self.sections()[sect.start_from].sharn != "нет": self.painter.drawEllipse( paintool.radrect(strt, sharnrad)) ltxt = util.text_prepare_ltext(sect.l, suffix="l") Atxt = util.text_prepare_ltext(sect.A, suffix="A") txt = "{},{},E".format(ltxt, Atxt) elements.draw_text_by_points_angled(self, strt, pnt, off=14, txt=txt, alttxt=sect.alttxt) self.painter.setPen(self.default_pen) # риуем силы for i in range(len(sects)): sect = self.sections()[i] angle = deg(sect.angle) rad = 50 circrad = 0 strt = self.c + self.coordinate_of_start(i) for j in range(len(sects)): jsect = self.sections()[j] #length = jsect.l * base_length #pnt = strt + QPoint(math.cos(jsect.angle) * length, -math.sin(jsect.angle) * length) if hasnode(strt): circrad = 6 break else: circrad = 0 if self.highlited_sect is not None and self.highlited_sect[1] == i: self.painter.setPen(self.green) self.painter.setBrush(Qt.green) pen = self.green brush = Qt.green else: self.painter.setPen(self.pen) self.painter.setBrush(Qt.black) pen = None brush = Qt.black if sect.force != "нет": apnt = strt + QPointF( math.cos(angle) * circrad, -math.sin(angle) * circrad) bpnt = strt + QPointF( math.cos(angle) * rad, -math.sin(angle) * rad) cpnt = strt + QPointF( math.cos(angle) * rad / 2, -math.sin(angle) * rad / 2) if sect.force == "к": paintool.common_arrow(self.painter, bpnt, apnt, arrow_size=15, pen=pen, brush=brush) elif sect.force == "от": paintool.common_arrow(self.painter, apnt, bpnt, arrow_size=15, pen=pen, brush=brush) elif sect.force == "вдоль": rad = 20 vec = QPointF( math.cos(angle) * rad, -math.sin(angle) * rad) norm = QPointF(vec.y(), -vec.x()) apnt1 = strt + norm bpnt1 = strt - norm apnt2 = strt + norm + vec bpnt2 = strt - norm + vec cpnt1 = strt cpnt2 = strt + vec paintool.common_arrow(self.painter, apnt1, apnt2, arrow_size=10) paintool.common_arrow(self.painter, bpnt1, bpnt2, arrow_size=10, pen=pen, brush=brush) self.painter.drawLine(apnt1, bpnt1) if sect.force != "вдоль": elements.draw_text_by_points(self, cpnt, bpnt, paintool.greek(sect.ftxt), alttxt=sect.alttxt, off=12, polka=None) else: elements.draw_text_by_points(self, cpnt1, cpnt2, paintool.greek(sect.ftxt), alttxt=sect.alttxt, off=12 + 15, polka=None) self.c = center self.painter.setPen(self.pen) self.painter.setBrush(Qt.white) self.painter.drawEllipse( QRectF(center - QPointF(sharnrad, sharnrad), center + QPointF(sharnrad, sharnrad))) if self.grid_enabled: self.painter.setPen(self.pen) self.painter.setBrush(Qt.green) if self.mouse_pressed: i = self.pressed_point_index else: i = self.hovered_point_index if i is not None: if i > 0 and len(sects) > i and sects[i - 1].body: self.painter.drawEllipse( QRectF(-QPointF(5, 5) + self.nodes_numered()[i], +QPointF(5, 5) + self.nodes_numered()[i])) if i == 0: self.painter.drawEllipse( QRectF(-QPointF(5, 5) + self.nodes_numered()[0], +QPointF(5, 5) + self.nodes_numered()[0])) self.painter.setPen(self.pen) self.painter.setBrush(Qt.white) if self.mouse_pressed: strt = self.nodes_numered()[self.pressed_point_index] tgt = self.target_point xs = strt.x() ys = strt.y() xf = tgt.x() yf = tgt.y() ang = math.atan2(ys - yf, xf - xs) ang = ang * 180 / math.pi l = math.sqrt((xf - xs)**2 + (yf - ys)**2) / self.base_length ang = round((ang + 7.5) / 15) * 15 l = round((l + 0.25) / 0.5) * 0.5 angtxt = ang ang = ang * math.pi / 180 ltxt = str(l) l = l * self.base_length if self.pressed_point_index <= len( self.shemetype.task["sections"]): fini = strt + QPointF(math.cos(ang) * l, -math.sin(ang) * l) self.painter.drawLine(strt, fini) elements.draw_text_by_points_angled(self, strt, fini, off=14, txt=ltxt + "l", alttxt=False) self.painter.drawArc(paintool.radrect(strt, rad), 0 * 16, angtxt * 16) pnt1 = strt + rad2 * QPointF(math.cos(deg(0)), -math.sin(deg(0))) pnt2 = strt + rad2 * QPointF(math.cos(deg(angtxt)), -math.sin(deg(angtxt))) cpnt = strt + rad3 * QPointF(math.cos(deg(angtxt) / 2), -math.sin(deg(angtxt) / 2)) paintool.draw_text_centered( painter=self.painter, pnt=cpnt + QPointF(0, QFontMetrics(self.font).height() / 4), text=paintool.greek(str(abs(angtxt)) + "\\degree"), font=self.font)
def paintEventImplementation(self, ev): sects = self.shemetype.task["sections"] bsects = self.shemetype.task["betsect"] assert len(sects) + 1 == len(bsects) width = self.width() height = self.height() center = QPoint(width/2, self.hcenter) font_size = self.shemetype.font_size.get() lwidth = self.shemetype.line_width.get() base_height = self.shemetype.base_height.get() arrow_size = self.shemetype.arrow_size.get() dimlines_level = self.shemetype.dimlines_level.get() dimlines_level2 = self.shemetype.dimlines_level2.get() sterzn_off = self.shemetype.sterzn_off.get() font = self.painter.font() font.setItalic(True) font.setPointSize(font_size) self.painter.setFont(font) br = QPen() br.setWidth(lwidth) self.painter.setPen(br) br = QBrush(Qt.SolidPattern) br.setColor(Qt.white) self.painter.setBrush(br) hasnegative = False for b in bsects: if b.l < 0: hasnegative = True hasright = bsects[-1].l != 0 left_span = 60 right_span = 30 if not hasright else 10 + dimlines_level2 up_span = 30 down_span = 30 if hasnegative else 10 + dimlines_level down_span += self.text_height smax = 0 smin = 0 for b in bsects: if b.l > smax: smax = b.l if b.l < smin: smin = b.l fheight = height - up_span - down_span #hsum = 0 #for s in bsects: hsum += s.l if smax != smin: hkoeff = float(fheight) / (smax - smin) else: hkoeff = float(fheight) hbase = hkoeff * smax + up_span lu = QPoint(left_span, hbase) ru = QPoint(width - right_span, hbase) ld = QPoint(left_span, hbase+base_height) rd = QPoint(width - right_span, hbase+base_height) fsize = width - right_span - left_span lsum = 0 for s in sects: lsum += s.l lkoeff = float(fsize) / lsum def xnode(n): if n==-1: n = len(sects) x = 0 for i in range(n): x += sects[i].l * lkoeff return left_span + x # Размерные линии горизонтальные. for i in range(len(self.sections())): xl = xnode(i) xr = xnode(i+1) if sects[i].dims: paintool.dimlines(self.painter, QPoint(xl, hbase), QPoint(xr, hbase), hbase+dimlines_level) elements.draw_text_by_points( self, QPoint(xl, hbase+dimlines_level), QPoint(xr, hbase+dimlines_level), txt=util.text_prepare_ltext(self.sections()[i].l, "a"), alttxt=True, off = 8 ) self.painter.setBrush(Qt.white) self.painter.drawLine(lu, ru) self.painter.drawLine(lu, ld) self.painter.drawLine(ld, rd) self.painter.drawLine(rd, ru) self.painter.setPen(self.halfpen) for i in range(len(sects)): if sects[i].label != "": elements.draw_text_by_points( self, QPoint(xnode(i), hbase-sects[i].label_height), QPoint(xnode(i+1), hbase-sects[i].label_height), txt=paintool.greek(sects[i].label) + ("" if sects[i].label_height > -20 else " "), alttxt=True, polka=QPointF((xnode(i+1) + xnode(i)) / 2, hbase+base_height/2) ) self.painter.setPen(self.pen) #Рисуем стержни for i in range(len(bsects)): #Доп. Шарниры if bsects[i].sharn != "нет": if bsects[i].sharn == "1": sharn_type = "снизу врез1" elif bsects[i].sharn == "2": sharn_type = "снизу шарн2" elements.draw_element_sharn(self, pnt=QPoint(xnode(i), hbase+base_height), type=sharn_type, termrad=25, termx=25, termy=10, rad=4 ) # Рисуем стержень if bsects[i].l != 0: if bsects[i].l > 0: strt = QPointF(xnode(i), hbase) strt_z = QPointF(xnode(i), hbase - 20) fini = QPointF(xnode(i), hbase - bsects[i].l*hkoeff) else: strt = QPoint(xnode(i), hbase + base_height) strt_z = QPointF(xnode(i), hbase + base_height + 20) fini = QPointF(xnode(i), hbase - bsects[i].l*hkoeff) if bsects[i].zazor is False: self.painter.setPen(self.doublepen) if self.highlited_node and self.highlited_node[1] == i: self.painter.setPen(self.widegreen) self.painter.drawLine(strt, fini) self.painter.setPen(self.pen) if self.highlited_node and self.highlited_node[1] == i: self.painter.setPen(self.green) self.painter.drawEllipse(paintool.radrect(strt, 4)) else: self.painter.setPen(self.doublepen) if self.highlited_node and self.highlited_node[1] == i: self.painter.setPen(self.widegreen) self.painter.drawLine(strt_z, fini) self.painter.setPen(self.pen) self.painter.setPen(self.halfpen) if self.highlited_node and self.highlited_node[1] == i: self.painter.setPen(self.green) paintool.draw_dimlines( painter=self.painter, apnt=strt, bpnt=strt_z, offset=QPoint(-20,0), textoff=QPoint(-10-QFontMetrics(self.font).width(paintool.greek(bsects[i].zazor_txt))/2,0), text=paintool.greek(bsects[i].zazor_txt), arrow_size=10, splashed=True, textline_from=None) self.painter.setPen(self.pen) if (bsects[i].l < 0): angle = deg(90) else: angle = deg(-90) upnt = bsects[i].l*hkoeff paintool.zadelka_sharnir(self.painter, QPoint(xnode(i), hbase - upnt), angle, 30, 10, 5) ap = -upnt if bsects[i].l < 0 else 0 bp = 0 if bsects[i].l < 0 else -upnt txt = util.text_prepare_ltext(abs(bsects[i].l)) txt_var2 = util.text_prepare_ltext(abs(bsects[i].l/2)) txt2 = util.text_prepare_ltext(abs(bsects[i].A), "A") txt2 = txt2 + ",E" txt = txt+","+txt2 txt_var2 = txt_var2+","+txt2 txt_var1 = txt_var2 if bsects[i].sterzn_text1: txt = bsects[i].sterzn_text1 txt_var1 = txt if bsects[i].sterzn_text2: txt_var2 = bsects[i].sterzn_text2 dimlines_level2=0 center= QPointF(xnode(i)+dimlines_level2, hbase) alttxt = False if bsects[i].l < 0: ap = ap + base_height cp = (ap+bp)/2 offset = QPointF(0, -bsects[i].sterzn_text_off) if bsects[i].sterzn_text_horizontal: offfff = 10 if bsects[i].sterzn_text_alt: a = center + QPointF(0,(ap+bp)/2) + QPointF(-QFontMetrics(self.font).width(txt)-offfff, QFontMetrics(self.font).height()/2) + offset b = center + QPointF(0,(ap+bp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) + offset a1 = center + QPointF(0,(ap+cp)/2) + QPointF(-QFontMetrics(self.font).width(txt_var1)-offfff, QFontMetrics(self.font).height()/2) b1 = center + QPointF(0,(ap+cp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) a2 = center + QPointF(0,(cp+bp)/2) + QPointF(-QFontMetrics(self.font).width(txt_var2)-offfff, QFontMetrics(self.font).height()/2) b2 = center + QPointF(0,(cp+bp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) else: a = center + QPointF(0,(ap+bp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) + offset b = center + QPointF(0,(ap+bp)/2) + QPointF(QFontMetrics(self.font).width(txt)+offfff, QFontMetrics(self.font).height()/2) + offset a1 = center + QPointF(0,(ap+cp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) b1 = center + QPointF(0,(ap+cp)/2) + QPointF(QFontMetrics(self.font).width(txt_var1)+offfff, QFontMetrics(self.font).height()/2) a2 = center + QPointF(0,(cp+bp)/2) + QPointF(0, QFontMetrics(self.font).height()/2) b2 = center + QPointF(0,(cp+bp)/2) + QPointF(QFontMetrics(self.font).width(txt_var2)+offfff, QFontMetrics(self.font).height()/2) else: a = center + QPointF(0,ap) + offset b = center + QPointF(0,bp) + offset a1 = center + QPointF(0,ap) b1 = center + QPointF(0,cp) a2 = center + QPointF(0,cp) b2 = center + QPointF(0,bp) alttxt = not bsects[i].sterzn_text_alt if bsects[i].F2 == "нет": elements.draw_text_by_points_angled( self, a, b, txt=txt, alttxt=alttxt, off = 15 ) else: cp = (ap+bp)/2 elements.draw_text_by_points_angled( self, a1, b1, # QPoint(xnode(i)+dimlines_level2, hbase + ap), # QPoint(xnode(i)+dimlines_level2, hbase + cp), txt=txt_var1, alttxt=alttxt, off = 15 ) elements.draw_text_by_points_angled( self, a2, b2, # QPoint(xnode(i)+dimlines_level2, hbase + cp), # QPoint(xnode(i)+dimlines_level2, hbase + bp), txt=txt_var2, alttxt=alttxt, off = 15 ) self.painter.setPen(self.halfpen) if bp == 0: cp = ap/2 # рисуем метку if bsects[i].lbl != "": elements.draw_text_by_points( self, QPoint(xnode(i), hbase+cp), QPoint(xnode(i), hbase+bp), txt=paintool.greek(bsects[i].lbl), alttxt=False, polka=QPointF(xnode(i), hbase+cp/2+5) ) if ap == 0: cp = bp/2 if bsects[i].lbl != "": elements.draw_text_by_points( self, QPoint(xnode(i), hbase+ap), QPoint(xnode(i), hbase+cp), txt=paintool.greek(bsects[i].lbl), alttxt=False, polka=QPointF(xnode(i), hbase+cp/2+5) ) self.painter.setPen(self.pen) self.painter.setBrush(Qt.white) if bsects[i].l == 0: if bsects[i].lbl != "": self.painter.setPen(self.halfpen) elements.draw_text_by_points( self, QPoint(xnode(i), hbase), QPoint(xnode(i), hbase-60), txt=paintool.greek(bsects[i].lbl), alttxt=False, polka=QPointF(xnode(i), hbase) ) if self.highlited_node and self.highlited_node[1] == i: self.painter.setPen(self.green) self.painter.drawEllipse(paintool.radrect(QPoint(xnode(i), hbase), 4)) self.painter.setPen(self.pen) self.painter.setBrush(Qt.white) # Рисуем силы for i in range(len(bsects)): if bsects[i].F != "нет": if bsects[i].l > 0: type = "снизу к" if bsects[i].F == "+" else "снизу от" pnt = QPointF(xnode(i), hbase+base_height) arrow_length = (dimlines_level-base_height)*2/3 else: type = "сверху от" if bsects[i].F == "+" else "сверху к" pnt = QPointF(xnode(i), hbase) arrow_length = dimlines_level*2/3 elements.draw_element_force(self, pnt, type, arrow_length, arrow_size, bsects[i].Ftxt, True, pen=self.pen) if bsects[i].F2 != "нет": h = bsects[i].l * hkoeff arrow_size_2 = arrow_size arrow_size_3 = 28 if bsects[i].l != 0: if bsects[i].F2 == "+": paintool.common_arrow(self.painter, QPointF(xnode(i)+sterzn_off, hbase - h/2), QPointF(xnode(i)+sterzn_off, hbase - h/2 - arrow_size_3), arrow_size_2) paintool.common_arrow(self.painter, QPointF(xnode(i)-sterzn_off, hbase - h/2), QPointF(xnode(i)-sterzn_off, hbase - h/2 - arrow_size_3), arrow_size_2) self.painter.setPen(self.halfpen) self.painter.drawLine( QPointF(xnode(i)-sterzn_off, hbase - h/2), QPointF(xnode(i)+sterzn_off, hbase - h/2) ) else: paintool.common_arrow(self.painter, QPointF(xnode(i)+sterzn_off, hbase - h/2), QPointF(xnode(i)+sterzn_off, hbase - h/2 + arrow_size_3), arrow_size_2) paintool.common_arrow(self.painter, QPointF(xnode(i)-sterzn_off, hbase - h/2), QPointF(xnode(i)-sterzn_off, hbase - h/2 + arrow_size_3), arrow_size_2) self.painter.setPen(self.halfpen) self.painter.drawLine( QPointF(xnode(i)-sterzn_off, hbase - h/2), QPointF(xnode(i)+sterzn_off, hbase - h/2) ) if bsects[i].F2txt != "": elements.draw_text_by_points(self, QPointF(xnode(i)-sterzn_off, hbase - h/2 - dimlines_level/5), QPointF(xnode(i)-sterzn_off, hbase - h/2 + dimlines_level/5), txt = bsects[i].F2txt, alttxt = False, off = 10) # Рисуем заделку на левом крае self.painter.setPen(self.doublepen) if self.shemetype.zadelka1.get() == "2": #paintool.zadelka_sharnir_type2(self.painter, QPoint(xnode(0), hbase), deg(0), 30, 10, 5) elements.draw_element_sharn(self, pnt=QPoint(xnode(0), hbase+base_height/2), type="слева шарн2", termrad=25, termx=25, termy=10, rad=4) elif self.shemetype.zadelka1.get() == "1": elements.draw_element_sharn(self, pnt=QPoint(xnode(0), hbase+base_height/2), type="слева врез1", termrad=25, termx=25, termy=10, rad=4) if self.shemetype.zadelka2.get() == "2": #paintool.zadelka_sharnir_type2(self.painter, QPoint(xnode(0), hbase), deg(0), 30, 10, 5) elements.draw_element_sharn(self, pnt=QPoint(xnode(-1), hbase+base_height/2), type="справа шарн2", termrad=25, termx=25, termy=10, rad=4) elif self.shemetype.zadelka2.get() == "1": elements.draw_element_sharn(self, pnt=QPoint(xnode(-1), hbase+base_height/2), type="справа врез1", termrad=25, termx=25, termy=10, rad=4)
def paintEventImplementation(self, ev): self.scene = QGraphicsScene() self.painter.setRenderHints(QPainter.Antialiasing) camera_w = self.shemetype.camera_w.get() WIDTH = 500 if self.shemetype.socr.get(): wpoint1 = -WIDTH * 0.45 wpoint2 = -WIDTH * 0.1 wpoint3 = WIDTH * 0.1 wpoint4 = WIDTH * 0.45 else: wpoint1 = -WIDTH * 0.45 wpoint2 = -WIDTH * 0.2 wpoint3 = WIDTH * 0.2 wpoint4 = WIDTH * 0.45 wpoint2c = -WIDTH * 0.2 wpoint3c = WIDTH * 0.2 if len(self.shemetype.task["sections"]) == 2: ymax = self.shemetype.task["sections"][0].D if self.shemetype.task[ "sections"][0].D > self.shemetype.task["sections"][ 1].D else self.shemetype.task["sections"][1].D ymin = self.shemetype.task["sections"][0].D if self.shemetype.task[ "sections"][0].D < self.shemetype.task["sections"][ 1].D else self.shemetype.task["sections"][1].D else: ymax = self.shemetype.task["sections"][0].D ymin = self.shemetype.task["sections"][0].D R = self.shemetype.task["sections"][0].D # Метка давления: #if self.shemetype.external_camera.get(): self.scene.addItem( TextItem( text=self.shemetype.text_pressure.get(), font=self.font, center=QPointF(-(wpoint3 + 3 * wpoint2) / 4 + 15, -ymax - 18), pen=self.pen, )) # Рисуем моменты: if self.shemetype.invert_moment.get() != "нет": pos = (3 * wpoint1 + wpoint2) / 4 if self.shemetype.torc_moment.get(): pos = wpoint1 minr = self.shemetype.task["sections"][0].D maxr = self.shemetype.task["sections"][0].D + 30 self.scene.addLine(QLineF(QPointF(pos, minr), QPointF(pos, maxr))) self.scene.addLine(QLineF(QPointF(pos, -minr), QPointF(pos, -maxr))) self.scene.addLine(QLineF(QPointF(-pos, minr), QPointF(-pos, maxr))) self.scene.addLine( QLineF(QPointF(-pos, -minr), QPointF(-pos, -maxr))) point_or_crest = self.shemetype.invert_moment.get() == "-" self.set_crest_circle(QPointF(pos, -maxr), r=10, invert=point_or_crest) self.set_crest_circle(QPointF(-pos, -maxr), r=10, invert=not point_or_crest) self.set_crest_circle(QPointF(pos, maxr), r=10, invert=not point_or_crest) self.set_crest_circle(QPointF(-pos, maxr), r=10, invert=point_or_crest) self.scene.addItem( TextItem(text=self.shemetype.text_moment.get(), font=self.font, center=QPointF(pos - 15, -maxr), pen=self.pen, offset="left")) self.scene.addItem( TextItem(text=self.shemetype.text_moment.get(), font=self.font, center=QPointF(-pos + 15, -maxr), pen=self.pen, offset="right")) # изгиб. if self.shemetype.invert_izgmoment.get() != "нет": if self.shemetype.var_izgmoment.get() == "круговой": self.scene.addItem( CircMomentItem( center=QPointF(wpoint1, 0), angle=deg(180), rad=50, pen=self.pen, brush=Qt.black, inverse=self.shemetype.invert_izgmoment.get() == "-")) self.scene.addItem( CircMomentItem( center=QPointF(wpoint4, 0), angle=deg(0), rad=50, pen=self.pen, brush=Qt.black, inverse=self.shemetype.invert_izgmoment.get() == "+")) self.scene.addItem( TextItem(text=self.shemetype.text_izgmoment.get(), font=self.font, center=QPointF(wpoint1 - 56, 0), pen=self.pen, offset="left")) self.scene.addItem( TextItem(text=self.shemetype.text_izgmoment.get(), font=self.font, center=QPointF(wpoint4 + 56, 0), pen=self.pen, offset="right")) else: x = 35 y = self.shemetype.task["sections"][0].D + 15 self.scene.addItem( SquareMomentItem( center=QPointF(wpoint1, 0), x=x, y=y, pen=self.pen, brush=Qt.black, inverse=self.shemetype.invert_izgmoment.get() == "-")) self.scene.addItem( SquareMomentItem( center=QPointF(wpoint4, 0), x=x, y=y, pen=self.pen, brush=Qt.black, inverse=self.shemetype.invert_izgmoment.get() == "+")) y = y - 15 inv = self.shemetype.invert_izgmoment.get() == "+" self.scene.addItem( TextItem(text=self.shemetype.text_izgmoment.get(), font=self.font, center=QPointF(wpoint1 - 20, y if inv else -y), pen=self.pen, offset="left")) self.scene.addItem( TextItem(text=self.shemetype.text_izgmoment.get(), font=self.font, center=QPointF(wpoint4 + 20, y if inv else -y), pen=self.pen, offset="right")) # Рисуем силы if self.shemetype.uncentered_force.get() != "нет": RR = R if self.shemetype.is_uncentered_force.get() else 0 if RR == R: if self.shemetype.ztube.get() and len(self.sections()) == 1: RR = R - self.shemetype.tubewidth.get() / 2 if self.shemetype.is_uncentered_force_alternate.get(): RR = -RR inverse = self.shemetype.uncentered_force.get() == "-" self.scene.addItem( ArrowItem(QPointF(wpoint4 + 5, -RR), QPointF(wpoint4 + 50, -RR), arrow_size=(15, 5), pen=self.pen, brush=Qt.black, reverse=inverse, double=False)) self.scene.addItem( ArrowItem(QPointF(wpoint1 - 5, -RR), QPointF(wpoint1 - 50, -RR), arrow_size=(15, 5), pen=self.pen, brush=Qt.black, reverse=inverse, double=False)) self.scene.addItem( TextItem(text=self.shemetype.text_force.get(), font=self.font, center=(QPointF(wpoint1 - 5, -RR - 13) + QPointF(wpoint1 - 50, -RR - 13)) / 2, pen=self.pen)) self.scene.addItem( TextItem(text=self.shemetype.text_force.get(), font=self.font, center=(QPointF(wpoint4 + 5, -RR - 13) + QPointF(wpoint4 + 50, -RR - 13)) / 2, pen=self.pen)) # Рисуем трубы tpos = None if self.shemetype.socr.get(): tpos = (wpoint3 * 3 + wpoint4) / 4 else: tpos = (wpoint3 * 2 + wpoint4 * 2) / 4 if self.shemetype.has_central.get(): self.draw_tube(wpoint1, wpoint2, self.shemetype.task["sections"][0].D, False, text=self.shemetype.task["sections"][0].Dtext, notext=True, tpos=-tpos) self.draw_tube(wpoint2, wpoint3, self.shemetype.task["sections"][1].D, self.shemetype.ztube.get(), text=self.shemetype.task["sections"][1].Dtext, notext=True) self.draw_tube(wpoint3, wpoint4, self.shemetype.task["sections"][0].D, False, text=self.shemetype.task["sections"][0].Dtext, notext=True, tpos=tpos) else: self.draw_tube(wpoint1, wpoint4, self.shemetype.task["sections"][0].D, self.shemetype.ztube.get(), text=self.shemetype.task["sections"][0].Dtext, camera=self.shemetype.razrez.get() == "камера", notext=True) # Рисуем ось: self.scene.addLine(QLineF(QPointF(wpoint1 - 20, 0), QPointF(wpoint4 + 20, 0)), pen=self.axpen) # Внутренняя метка давления: self.scene.addItem( TextItem(text=self.shemetype.text_pressure_in.get(), font=self.font, center=QPointF(-(wpoint3 + 3 * wpoint2) / 4 + 15, -ymin + 25), pen=self.pen, clean=True)) # Текст диаметров: if self.shemetype.has_central.get(): self.draw_tube(wpoint1, wpoint2, self.shemetype.task["sections"][0].D, False, text=self.shemetype.task["sections"][0].Dtext, nobody=True, tpos=-tpos) self.draw_tube(wpoint2, wpoint3, self.shemetype.task["sections"][1].D, self.shemetype.ztube.get(), text=self.shemetype.task["sections"][1].Dtext, nobody=True) self.draw_tube(wpoint3, wpoint4, self.shemetype.task["sections"][0].D, False, text=self.shemetype.task["sections"][0].Dtext, nobody=True, tpos=tpos) else: self.draw_tube(wpoint1, wpoint4, self.shemetype.task["sections"][0].D, self.shemetype.ztube.get(), text=self.shemetype.task["sections"][0].Dtext, camera=self.shemetype.razrez.get() == "камера", nobody=True) # Рисуем камеру. if self.shemetype.external_camera.get(): self.draw_camera(wmax=wpoint3c + 20 + camera_w, wmin=wpoint3c + 20, hmax=ymax + 30 + camera_w, hmin=ymax + 30, hint=self.shemetype.task["sections"][0].D) # Толщина трубы: T = self.shemetype.tubewidth.get() if len(self.shemetype.task["sections"]) == 2: item = 1 else: item = 0 H = self.shemetype.task["sections"][item].D if self.shemetype.ztube.get(): self.scene.addItem( TextItem(text=self.shemetype.htext.get(), font=self.font, center=QPointF(45, H + 15), pen=self.pen, offset="right")) self.scene.addItem( ArrowItem(QPointF(40, H + 15), QPointF(40, H), arrow_size=(10, 3), pen=self.pen, brush=Qt.black)) self.scene.addItem( ArrowItem(QPointF(40, H - T - 15), QPointF(40, H - T), arrow_size=(10, 3), pen=self.pen, brush=Qt.black)) self.scene.addLine(QLineF(QPointF(40, H + 15), QPointF(40, H - T - 15)), pen=self.halfpen) # Рисуем разрезы на концах трубы if self.shemetype.razrez.get() == "разрез": line = [ QPointF(wpoint1 + 5, R), QPointF(wpoint1 + 0, R / 2), QPointF(wpoint1 + 10, -R / 2), QPointF(wpoint1 + 5, -R), ] R = self.shemetype.task["sections"][0].D self.scene.addPolygon(QPolygonF(line + [ QPointF(wpoint1 - 20, -R - 10), QPointF(wpoint1 - 20, R + 10) ]), pen=Qt.white, brush=Qt.white) for i in range(len(line) - 1): self.scene.addLine(QLineF(line[i], line[i + 1])) line = [ QPointF(wpoint4 - 5, R), QPointF(wpoint4 - 10, R / 2), QPointF(wpoint4 - 0, -R / 2), QPointF(wpoint4 - 5, -R), ] R = self.shemetype.task["sections"][0].D self.scene.addPolygon(QPolygonF(line + [ QPointF(wpoint4 + 20, -R - 10), QPointF(wpoint4 + 20, R + 10) ]), pen=Qt.white, brush=Qt.white) for i in range(len(line) - 1): self.scene.addLine(QLineF(line[i], line[i + 1])) #Размер расчётной секции: if self.shemetype.Ltext.get() != "": if self.shemetype.external_camera.get(): self.scene.addLine( QLineF( QPointF(wpoint2, 0), QPointF(wpoint2, ymax + 30 + camera_w + 33), )) self.scene.addLine( QLineF( QPointF(wpoint3, 0), QPointF(wpoint3, ymax + 30 + camera_w + 33), )) self.scene.addItem( ArrowItem(QPointF(wpoint2, ymax + 30 + camera_w + 30), QPointF(wpoint3, ymax + 30 + camera_w + 30), double=True, pen=self.halfpen, brush=Qt.black, arrow_size=(10, 3))) else: z = self.shemetype.tubewidth.get( ) if self.shemetype.razrez.get() == "камера" else 0 self.scene.addLine( QLineF( QPointF(wpoint1 + z, 0), QPointF(wpoint1 + z, ymax + 63), )) self.scene.addLine( QLineF( QPointF(wpoint4 - z, 0), QPointF(wpoint4 - z, ymax + 63), )) self.scene.addItem( ArrowItem(QPointF(wpoint1 + z, ymax + 60), QPointF(wpoint4 - z, ymax + 60), double=True, pen=self.halfpen, brush=Qt.black, arrow_size=(10, 3))) self.scene.addItem( TextItem(text=self.shemetype.Ltext.get(), font=self.font, center=QPointF(0, ymax + 30 + camera_w + 20), pen=self.pen)) br = QColor(0, 0, 0) br.setAlphaF(0) p = QPen() p.setColor(br) rect = self.scene.itemsBoundingRect() rect = self.scene.itemsBoundingRect() addtext = paintool.greek(self.shemetype.texteditor.toPlainText()) n = len(addtext.splitlines()) for i, l in enumerate(addtext.splitlines()): t = self.scene.addText(l, self.font) t.setPos( rect.x(), rect.height() + rect.y() + QFontMetrics(self.font).height() * i) WBORDER = self.shemetype.wborder.get() HBORDER = self.shemetype.hborder.get() if self.shemetype.uncentered_force.get() != "нет": WBORDER += 25 self.scene.addRect(QRectF(-rect.width() / 2 - WBORDER, -rect.height() / 2 - HBORDER, rect.width() + WBORDER * 2, rect.height() + HBORDER), pen=p, brush=br) self.scene.render(self.painter, target=QRectF( 0, 0, self.scene.itemsBoundingRect().width(), self.scene.itemsBoundingRect().height()), source=self.scene.itemsBoundingRect()) self.resize_after_render(*self.scene_bound())
def draw_tube(self, wmin, wmax, R, z=False, text="", camera=False, notext=False, nobody=False, tpos=None): S = self.shemetype.tubewidth.get() if tpos is None: tpos = (wmax + wmin) / 2 if not nobody: if not z: self.scene.addRect(QRectF(wmin, -R, -wmin + wmax, 2 * R), pen=self.pen) else: if camera: zbrush = QBrush(Qt.BDiagPattern) self.scene.addRect(QRectF(wmin, -R, -wmin + wmax, 2 * R), pen=self.pen, brush=zbrush) self.scene.addRect(QRectF(wmin + S, -R + S, -wmin + wmax - S * 2, 2 * R - S * 2), pen=self.pen, brush=Qt.white) else: zbrush = QBrush(Qt.BDiagPattern) self.scene.addRect(QRectF(wmin, -R, -wmin + wmax, S), pen=self.pen, brush=zbrush) self.scene.addRect(QRectF(wmin, -R + S, -wmin + wmax, 2 * R - S * 2), pen=self.pen) self.scene.addRect(QRectF(wmin, R, -wmin + wmax, -S), pen=self.pen) if z: self.scene.addLine(QLineF(QPointF(wmin, -R + S / 2), QPointF(wmax, -R + S / 2)), pen=self.axpen) self.scene.addLine(QLineF(QPointF(wmin, R - S / 2), QPointF(wmax, R - S / 2)), pen=self.axpen) if text != "": self.scene.addItem( items.arrow.ArrowItem(QPointF(tpos, R - S / 2), QPointF(tpos, -R + S / 2), arrow_size=(10, 3), pen=self.pen, brush=Qt.black, double=True)) else: if text != "": self.scene.addItem( items.arrow.ArrowItem(QPointF(tpos, R), QPointF(tpos, -R), arrow_size=(10, 3), pen=self.pen, brush=Qt.black, double=True)) if not notext: if text != "": self.scene.addItem( TextItem(text=paintool.greek(text), font=self.font, center=QPointF(tpos - 15, 0), pen=self.pen, rotate=deg(90), clean=True))
def paintEventImplementation(self, ev): self.selected_item = None self.scene = QGraphicsScene() self.painter.setRenderHints(QPainter.Antialiasing) proj = Projector() proj.set_yaw(deg(self.shemetype.zrot.get())) proj.set_pitch(-deg(self.shemetype.xrot.get())) proj.set_zmul(self.shemetype.zmul.get()) proj.set_iso_projection(not self.shemetype.axonom.get()) self.proj = proj rebro = self.shemetype.rebro.get() br = QColor(0, 0, 0) br.setAlphaF(0) p = QPen() p.setColor(br) if self.selected_label_id: for label_id, item in self.label_items.items(): if self.selected_label_id == label_id: green70 = QColor(0, 255, 0) green70.setAlphaF(0.7) self.scene.addRect(item.boundingRect(), brush=green70) # Рисуем линии. for s in self.shemetype.task["sections"]: self.scene.addLine(QLineF( proj(s.ax, s.ay, s.az) * rebro, proj(s.bx, s.by, s.bz) * rebro, ), pen=self.pen) self.draw_distrib_forces(s) # Кружки нодов. for n in self.shemetype.task["nodes"]: # self.draw_sharn(n) self.draw_forces(n) self.draw_torques(n) self.label_items = {} # Тексты for s in self.shemetype.task["labels"]: self.draw_text(paintool.greek(s.text), s.pos, label=s) #Сечение #section_width = sections.draw_section_routine( # self, # hcenter=0, # right=fini_width) rect = self.scene.itemsBoundingRect() sectitem = SectionItem(self) sectitem.setPos(rect.x() + rect.width(), rect.y() + rect.height() * (4 / 8)) self.scene.addItem(sectitem) # Отрисовка при наведении. if self.hovered_node: h = self.hovered_node pnt = self.proj(h.x, h.y, h.z) * rebro self.scene.addEllipse(QRectF(pnt + QPointF(-3, -3), pnt + QPointF(3, 3)), pen=self.green, brush=Qt.green) if self.mouse_pressed: self.pressed_nodes = [] def do(a, b, pen, force=False): if force or not self.has_section(self.point(a), self.point(b)): self.draw_point(b, pen) self.draw_line(a, b, pen) self.pressed_nodes.append(self.point(b[0], b[1], b[2])) do((h.x, h.y, h.z), (h.x + 1, h.y, h.z), self.green) do((h.x, h.y, h.z), (h.x - 1, h.y, h.z), self.green) do((h.x, h.y, h.z), (h.x, h.y + 1, h.z), self.green) do((h.x, h.y, h.z), (h.x, h.y - 1, h.z), self.green) do((h.x, h.y, h.z), (h.x, h.y, h.z + 1), self.green) do((h.x, h.y, h.z), (h.x, h.y, h.z - 1), self.green) if self.hovered_node_pressed is not None: do((h.x, h.y, h.z), self.hovered_node_pressed, self.blue, force=True) if self.hovered_sect: s = self.hovered_sect self.scene.addLine(QLineF( self.proj(s.ax, s.ay, s.az) * rebro, self.proj(s.bx, s.by, s.bz) * rebro, ), pen=self.blue) WBORDER = self.shemetype.wborder.get() HBORDER = self.shemetype.hborder.get() if len(self.shemetype.task["sections"]) == 0: self.scene.addRect(QRectF(QPointF(-20, -20), QPointF(20, 20)), brush=br, pen=p) rect = self.scene.itemsBoundingRect() addtext = paintool.greek(self.shemetype.texteditor.toPlainText()) n = len(addtext.splitlines()) for i, l in enumerate(addtext.splitlines()): t = self.scene.addText(l, self.font) t.setPos( rect.x(), rect.height() + rect.y() + QFontMetrics(self.font).height() * i) rect = self.scene.itemsBoundingRect() self.scene.addRect(QRectF(rect.x() - WBORDER, rect.y() - HBORDER, rect.width() + WBORDER * 2, rect.height() + HBORDER * 2), pen=p, brush=br) self.offset = QPointF(rect.x() - WBORDER, rect.y() - HBORDER) self.scene.render(self.painter) self.resize_after_render(*self.scene_bound())