def draw_seg_dims_box(self, ctx, page_w, page_h): """ Draws an info box containing bend segment dimensions. Arguments: ctx -- a Pycairo context page_w, page_h -- width and height of the drawing area """ # Draw segment dimensions box ctx.set_line_width(self.drawing_line_width) if self.ex_dim_box or self.ex_dim_drg: if not self.ex_dim_box: dims = ["mean"] elif self.casing_type == "segmented": dims = ["cex", "lex", "mean", "lin", "cin"] else: dims = ["lex", "mean", "lin"] dpt = self.dos_dim_dp labels, fields = zip(*[(self.segdims[k].label, str(round(self.segdims[k].value, dpt))) for k in dims]) draw_text_box(ctx=ctx, topright=Point(page_w, 0), labels=labels, fields=fields, textinfo=self.text["dims"])
def draw_component(self, ctx, page_w, page_h): """ Draws the drawn component. Subclasses should override this method and not call this. Arguments: ctx -- a Pycairo context page_w, page_h -- width and height of drawing area """ ctx.save() notice = "Override this base class" draw_text_box(ctx=ctx, labels=[notice], textinfo=self.text["notice"], centerpoint=Point(page_w / 2, page_h / 2), noborder=True) ctx.restore()
def draw_base_page(self): """ Draws the base page. """ pw = self.page_width - self.page_margin * 2 ph = self.page_height - self.page_margin * 2 self.ctx.save() self.ctx.translate(self.page_margin, self.page_margin) self.ctx.set_line_width(self.page_line_width) self.ctx.set_source_rgb(*self.line_color) # Draw main margins self.ctx.rectangle(0, 0, pw, ph) self.ctx.stroke() # Draw dimension information and bounding box # pylint: disable=W0612 (bw, bh, fps) = draw_text_box(ctx=self.ctx, topright=Point(pw, 0), labels=["ALL DIMENSIONS ARE IN mm"], textinfo=self.text["notice"], noborder=True) # pylint: enable=W0612 self.ctx.move_to(pw - bw, 0) self.ctx.line_to(pw - bw, bh) self.ctx.line_to(pw, bh) self.ctx.stroke() self.page_inner_margin_y += bh self.ctx.restore()
def draw_drawing_info(self): """ Draws the information boxes. """ pw = self.page_width - self.page_margin * 2 ph = self.page_height - self.page_margin * 2 ibs = self.page_infoboxspacing self.ctx.save() self.ctx.translate(self.page_margin, self.page_margin) self.ctx.set_line_width(self.page_line_width) self.ctx.set_source_rgb(*self.line_color) # Calculate info box widths self.ctx.select_font_face(*self.text["client"].face) self.ctx.set_font_size(self.text["client"].size) # pylint: disable=W0612 (bx, by, w, h, dx, dy) = self.ctx.text_extents(self.client) # pylint: enable=W0612 cbw = w + self.text["client"].padding * 2 ibw = (pw - cbw - ibs * 5) / 3 # Draw main info boxes x = ibs y = ph - ibs keys = [["cust", "projno", "drgno", "qty"], ["mat", "bond", "finish", "svctemp"], ["date", "scale", "drwnby", "chkby"]] for k in keys: labels, fields = zip(*[(self.drg_info[j].label, self.drg_info[j].value) for j in k]) # pylint: disable=W0612 (bw, bh, fps) = draw_text_box(ctx=self.ctx, bottomleft=Point(x, y), labels=labels, fields=fields, textinfo=self.text["info"], width=ibw) # pylint: enable=W0612 if k[1] == "scale": self.scale_p = fps[1] x += (ibw + ibs) # Draw copyright box x = ibs y -= ibs + bh width = ibw * 3 + ibs * 2 (bw, bh, fps) = draw_text_box(ctx=self.ctx, bottomleft=Point(x, y), width=width, labels=["Industrial copyright " + self.client], textinfo=self.text["copyright"], center=True) # Draw title box y -= ibs + bh (bw, bh, fps) = draw_text_box(ctx=self.ctx, bottomleft=Point(x, y), width=width, labels=[self.drg_info["title"].value], textinfo=self.text["title"], center=True) # Set info box height self.page_infoboxheight = ph - (y - ibs - bh) ibh = self.page_infoboxheight # Draw Omegaslate box self.ctx.select_font_face(*self.text["client"].face) self.ctx.set_font_size(self.text["client"].size) (bx, by, w, h, dx, dy) = self.ctx.text_extents(self.client) x = pw - ibs - w - self.text["client"].padding y = ph - ibh + ibs + self.text["client"].padding + h self.ctx.move_to(x, y) self.ctx.set_source_rgb(*self.text["client"].color) self.ctx.show_text(self.client) self.ctx.set_source_rgb(*self.line_color) self.ctx.rectangle(x - self.text["client"].padding, y - h - self.text["client"].padding, cbw, ibh - ibs * 2) self.ctx.stroke() olabs = ["Address 1", "Address 2", "Company Tag Line", "Telephone and Fax"] self.ctx.select_font_face(*self.text["info"].face) self.ctx.set_font_size(self.text["info"].size) self.ctx.set_source_rgb(*self.text["info"].color) for row, lstr in zip(range(len(olabs)), olabs): if row == 2 or row == 3: mult = 2.5 else: mult = 1 y += (h + self.text["client"].padding) * mult (bx, by, w, h, dx, dy) = self.ctx.text_extents(lstr) x = pw - ibs - (cbw / 2) - (w / 2) self.ctx.move_to(x, y) self.ctx.show_text(lstr) # Draw infobox divider self.ctx.set_source_rgb(*self.line_color) self.ctx.move_to(0, ph - ibh) self.ctx.line_to(pw, ph - ibh) self.ctx.stroke() self.ctx.restore()