def write_comparator(canvas, t=I): width = GS t = I.move((0.5 * width, 0.0)).transform(t) Line(COMPARATOR_POINTS, I.scale(0.3, 0.3).transform(t)).write(canvas) Line(COMPARATOR_POINTS, I.scale(-0.3, -0.3).transform(t)).write(canvas) Line(EQ_TRIANGLE, I.scale(-1.3, 1.3).transform(t)).write(canvas) return t.move(t.transform_vector((0.5 * GS, 0.0)))
def write_converter(labels, canvas, t=I): width = GS t = I.move((0.5 * width, 0.0)).transform(t) Square(I.scale(1.5, 1.5).transform(t)).write(canvas) Line(((-0.75, -0.75), (0.75, 0.75)), t).write(canvas) canvas.text(labels[0], t.transform_point((-0.35, 0.35))) canvas.text(labels[1], t.transform_point((0.35, -0.35))) return t.move(t.transform_vector((0.5 * width, 0.0)))
def write_temp_sensor(canvas, t = I): width = GS t = I.move((0.5 * width, 0.0)).transform(t) Square(I.scale(RESISTOR_RATIO, 1.0).move((0.0, 0.0)).transform(t)).write(canvas) Line(((0.4, 0.4), (-0.4, -0.4), (-0.7, -0.4)), t).write(canvas) # Square(I.scale(1.5, 1.5).transform(t)).write(canvas) canvas.text('$\\vartheta$', t.transform_point((-0.55, -0.4)), position='n') return I.move((0.2 * GS, 0.0)).transform(t)
def write_pump(canvas, transf=I): symbol = Circle(transf) symbol.write(canvas) t = I.scale(-0.6, 0.6).transform(transf) symbol = Line(EQ_TRIANGLE, t) symbol.write(canvas) return transf.move(transf.transform_vector((1.5, 0.0)))
def write_arrow(canvas, t=I): width = GS Line(((0.3, 0.0), (width - 0.3, 0.0)), t).write(canvas) Line(EQ_TRIANGLE, I.scale(-0.3, 0.3).move( (width - 0.3, 0.0)).transform(t)).write(canvas) return t.move(t.transform_vector((width, 0.0)))
def write_pump(canvas, transf=I): if canvas is not None: symbol = Circle(transf) symbol.write(canvas) t = I.scale(-0.6, 0.6).transform(transf) symbol = Line(EQ_TRIANGLE, t) symbol.write(canvas) return transf.r_move(-0.5, 0.0), transf.r_move(0.5, 0.0)
def write_join(canvas, t1, t2): x1, y1 = t1.get_offset() x2, y2 = t2.get_offset() x = max((x1, x2)) + 0.5 y = 0.5 * (y1 + y2) Line([(x1, y1), (x, y1), (x, y2), (x2, y2)]).write(canvas) Line([(x, y), (x + 0.5, y)]).write(canvas) return I.move_to((x + 0.5, y))
def clip_margins(canvas, left=0.0, top=0.0, right=0.0, bottom=0.0): width, height = canvas.clip_region.get_size() width -= left + right height -= top + bottom return LocalScheme( canvas=canvas, t=I.r_move(*canvas.clip_region.lb_point)\ .r_move(left, bottom)\ .r_move(0.5*width, 0.5*height), clip_region=ClipRegion((-0.5*width, -0.5*height), (0.5*width, 0.5*height)) )
def write_fork(canvas, t=I): width = GS Line(((0.3, 0.0), (width - 0.3, 0.0)), t).write(canvas) Line(((width - 0.3, 1.25 * GS), (0.5 * width, 1.25 * GS), (0.5 * width, -1.25 * GS), (width - 0.3, -1.25 * GS)), t).write(canvas) Line(EQ_TRIANGLE, I.scale(-0.3, 0.3).move( (width - 0.3, 1.25 * GS)).transform(t)).write(canvas) Line(EQ_TRIANGLE, I.scale(-0.3, 0.3).move( (width - 0.3, 0.0)).transform(t)).write(canvas) Line(EQ_TRIANGLE, I.scale(-0.3, 0.3).move( (width - 0.3, -1.25 * GS)).transform(t)).write(canvas) return [ I.move((width, 1.25 * GS)).transform(t), I.move((width, 0.0)).transform(t), I.move((width, -1.25 * GS)).transform(t) ]
def clip_rb(canvas, width, height): return LocalScheme(canvas=canvas, t=I.r_move(*canvas.clip_region.get_rb_point()).r_move( -0.5 * width, 0.5 * height), clip_region=ClipRegion((-0.5 * width, -0.5 * height), (0.5 * width, 0.5 * height)))
def move(self, offset): return LocalScheme(self, t=I.r_move(*offset), clip_region=self.clip_region.move(offset))
def move(self, offset=(0.0, 0.0)): return LocalScheme( canvas=self, t=I.r_move(*offset), clip_region=self.clip_region )
def write_radiator(canvas, transf=I): symbol = Square(I.scale(3.0, 4.0).transform(transf)) symbol.write(canvas) return transf.move(transf.transform_vector((4.0, 0.0)))
0), labels=['21', '', '14']) # paralelne ke kontaktum rele je ta spinaci svorka tsp = write_disconnect_terminal(canvas, t2) tj = write_join(canvas, tno, tsp) # civka solenoidu write_n(canvas, write_wire(canvas, write_coil(canvas, tj))) # civka rele tc = write_coil(canvas, t1.r_move(0.0, 1.5), labels=['A1', 'A2']) write_wire(canvas, tc.r_move(-2.5, 0.0)) tt = write_wire(canvas, tc) write_gnd(canvas, tt) # kontakt modulu quido tco, tnc, tno = write_change_over_switch(canvas, get_t(write_change_over_switch, tc.r_move(-2.5, 0.0), 2), labels=['C1', 'NC1', 'NO1']) write_wire(canvas, tco.r_move(-1.5, 0.0)) write_ref(canvas, tco.r_move(-1.5, 0.0), text='WD') tco, tc, to = write_change_over_switch(canvas, I.r_move(0.0, 7.0), labels=['c1', 'nc1', 'no1']) tc, tsc, tso = write_rele(canvas, write_wire(canvas, to), labels=['A1', 'A2', '21', '', '14']) write_gnd(canvas, write_wire(canvas, tc)) write_n(canvas, write_wire(canvas, write_coil(canvas, write_wire(canvas, tso)))) write_disconnect_terminal(canvas, tc.r_move(2.0, 0.0))
def get_t(write_fn, t1, i): t2 = write_fn(None)[i] x1, y1 = t1.get_offset() x2, y2 = t2.get_offset() dx, dy = x1 - x2, y1 - y2 return I.r_move(dx, dy)
def write_heater(canvas, transf=I): if canvas is not None: t = I.scale(2.0, 3.0).transform(transf) symbol = Square(t) symbol.write(canvas) return transf.r_move(-1.0, 0.0), transf.r_move(1.0, 0.0)
def write_heater(canvas, transf=I): t = I.scale(3.0, 4.0).transform(transf) symbol = Square(t) symbol.write(canvas) return transf.move(transf.transform_vector((3.0, 0.0)))
def write_radiator(canvas, transf=I): if canvas is not None: symbol = Square(I.scale(2.0, 3.0).transform(transf)) symbol.write(canvas) return transf.r_move(-1.0, 0.0), transf.r_move(1.0, 0.0)
def draw_frame(canvas, geometry): """ It draw a scheme frame on the given schema. """ #raw_size=canvas.get_size() # Vykresovy list drawing_frame_size = geometry['DRAWING_FRAME_SIZE'] grid_frame_size = geometry['GRID_FRAME_SIZE'] outer_frame_size = geometry['OUTER_FRAME_SIZE'] schema = canvas.move([0.5 * d for d in canvas.clip_region.get_size()]) schema.draw_rect(*outer_frame_size, style='tiny') # draw outer frame schema.draw_rect(*grid_frame_size, style='tiny') # schema.draw_rect(*drawing_frame_size, style='normal') frame_margin = 0.5 * (outer_frame_size[0] - drawing_frame_size[0]) # draw center marks x, y = grid_frame_size x, y = 0.5 * x, 0.5 * y size = grid_frame_size[0] - drawing_frame_size[0] schema.draw_hline(x, 0, -size) schema.draw_hline(-x, 0, size) schema.draw_vline(0, y, -size) schema.draw_vline(0, -y, size) # center triangles schema.draw_line( I.r_move(x - 5.0, 0.0).r_scale(-5.0, 5.0).transform_points(EQ_TRIANGLE)) schema.draw_line( I.r_move(0.0, -y + 5.0).r_scale( -5.0, 5.0).rotate_vect().transform_points(EQ_TRIANGLE)) # draw grid y = 0.5 * grid_frame_size[1] hgrid, vgrid = geometry['GRID'] size = 0.5 * size dist = 0.5 * grid_frame_size[0] / hgrid for i in range(hgrid - 1): x = (i + 1) * dist schema.draw_vline(x, y, -size) schema.draw_vline(-x, y, -size) schema.draw_vline(x, -y, size) schema.draw_vline(-x, -y, size) schema.text(GRID_NUMBERS[hgrid - 1 - i], (-x + 0.5 * dist, y - 0.5 * size), size='large') schema.text(GRID_NUMBERS[hgrid + i], (x - 0.5 * dist, y - 0.5 * size), size='large') schema.text(GRID_NUMBERS[hgrid - 1 - i], (-x + 0.5 * dist, -y + 0.5 * size), size='large') schema.text(GRID_NUMBERS[hgrid + i], (x - 0.5 * dist, -y + 0.5 * size), size='large') schema.text(GRID_NUMBERS[0], (-(hgrid - 0.5) * dist, y - 0.5 * size), size='large') schema.text(GRID_NUMBERS[hgrid * 2 - 1], ((hgrid - 0.5) * dist, y - 0.5 * size), size='large') schema.text(GRID_NUMBERS[0], (-(hgrid - 0.5) * dist, -y + 0.5 * size), size='large') schema.text(GRID_NUMBERS[hgrid * 2 - 1], ((hgrid - 0.5) * dist, -y + 0.5 * size), size='large') dist = 0.5 * grid_frame_size[1] / vgrid x = 0.5 * grid_frame_size[0] for i in range(vgrid - 1): x = 0.5 * grid_frame_size[0] y = (i + 1) * dist schema.draw_hline(x, y, -size) schema.draw_hline(x, -y, -size) schema.draw_hline(-x, y, size) schema.draw_hline(-x, -y, size) x = x - 0.5 * size y = (i + 0.5) * dist schema.text(GRID_LETTERS[vgrid - 1 - i], (x, y), size='large') schema.text(GRID_LETTERS[vgrid - 1 - i], (-x, y), size='large') schema.text(GRID_LETTERS[vgrid + i], (x, -y), size='large') schema.text(GRID_LETTERS[vgrid + i], (-x, -y), size='large') x = 0.5 * (grid_frame_size[0] - size) y = (vgrid - 0.5) * dist schema.text(GRID_LETTERS[0], (x, y), size='large') schema.text(GRID_LETTERS[0], (-x, y), size='large') schema.text(GRID_LETTERS[2 * vgrid - 1], (x, -y), size='large') schema.text(GRID_LETTERS[2 * vgrid - 1], (-x, -y), size='large') # draw cut marks cut_points = ((0.0, 0.0), (10.0, 0.0), (10.0, 2.0), (2.0, 2.0), (2.0, 10.0), (0.0, 10.0), (0.0, 0.0)) x = 0.5 * grid_frame_size[0] + 2.0 y = 0.5 * grid_frame_size[1] + 2.0 schema.draw_line( I.r_scale(1.0, 1.0).r_move(-x, -y).transform_points(cut_points)) schema.draw_line( I.r_scale(1.0, -1.0).r_move(-x, -y).transform_points(cut_points)) schema.draw_line( I.r_scale(-1.0, 1.0).r_move(-x, -y).transform_points(cut_points)) schema.draw_line( I.r_scale(-1.0, -1.0).r_move(-x, -y).transform_points(cut_points)) return LocalScheme( schema, I.r_move(frame_margin, frame_margin), schema.clip_region.margins(frame_margin).move( (frame_margin, frame_margin)))