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 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 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)
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 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)))