Example #1
0
def draw_Or(image, x, y, construct, options, forward):
    if len(construct.constructs) == 1:
        return draw(image, x, y, construct.constructs[0], options, forward)
    width, height, line_position = size_of_Or(image, construct, options)
    constructs = construct.constructs
    sizes = [size_of(image, c, options) for c in constructs]
    max_width = max(sizes, key=lambda (w, h, l): w)[0]
    radius = options.raildraw_or_radius
    spacing = options.raildraw_or_spacing
    arrow_width, arrow_height = options.raildraw_size_of_arrow(options)
    before = options.raildraw_or_before
    after = options.raildraw_or_after
    if not forward:
        before, after = after, before
    current_y = y
    for index, (c, (w, h, l)) in enumerate(zip(constructs, sizes)):
        draw_arrows = not isinstance(c, rr.Nothing)
        # Don't draw arrows if c is a loop and its component is not Nothing;
        # the arrows tend to appear superfluous in such a case
        if isinstance(c, rr.Loop) and not isinstance(c.component, rr.Nothing):
            draw_arrows = False
        if index != 0:
            image.move_to(x + radius, current_y + l - radius)
            image.arc_negative(x + radius * 2, current_y + l - radius, radius, radians(180), radians(90))
            image.stroke()
        if not draw_arrows:
            draw_line(image, x + radius * 2, current_y + l, x + radius * 2 + arrow_width, current_y + l)
        else:
            options.raildraw_draw_arrow(image, x + radius * 2, current_y + l - (arrow_height / 2), options, forward)
        draw_line(image, x + radius * 2 + arrow_width, current_y + l, x + radius * 2 + arrow_width + before, current_y + l)
        construct_x = x + radius * 2 + arrow_width + before
        if isinstance(c, rr.Nothing):
            draw_line(image, construct_x, current_y + l, construct_x + max_width / 2 - w / 2, current_y + l)
            draw(image, construct_x + max_width / 2 - w / 2, current_y, c, options, forward)
            draw_line(image, construct_x + max_width / 2 + w / 2, current_y + l, construct_x + max_width + after, current_y + l)
        else:
            draw(image, construct_x, current_y, c, options, forward)
            draw_line(image, construct_x + w, current_y + l, construct_x + max_width + after, current_y + l)
        if not draw_arrows:
            draw_line(image, construct_x + max_width + after, current_y + l, construct_x + max_width + after + arrow_width, current_y + l)
        else:
            options.raildraw_draw_arrow(image, construct_x + max_width + after, current_y + l - (arrow_height / 2), options, forward)
        if index != 0:
            image.move_to(construct_x + max_width + after + arrow_width, current_y + l)
            image.arc_negative(construct_x + max_width + after + arrow_width, current_y + l - radius, radius, radians(90), radians(0))
            image.stroke()
        if index == len(constructs) - 1: # Last construct
            line_end_y = current_y + l - radius
        current_y += spacing + h
    image.move_to(x, y + line_position)
    image.arc(x, y + line_position + radius, radius, radians(270), radians(0))
    image.line_to(x + radius, line_end_y)
    image.stroke()
    draw_line(image, x, y + line_position, x + radius * 2, y + line_position)
    end_x = x + radius * 2 + arrow_width + before + max_width + after + arrow_width 
    draw_line(image, end_x, y + line_position, end_x + radius * 2, y + line_position)
    image.move_to(x + width, y + line_position)
    image.arc_negative(x + width, y + line_position + radius, radius, radians(270), radians(180))
    image.line_to(x + width - radius, line_end_y)
    image.stroke()
Example #2
0
def draw_arrow_or_line(image, x, y, arrow_width, arrow_height, options,
                       forward, arrow):
    if arrow:
        options.raildraw_draw_arrow(image, x, y, options, forward)
    else:
        draw_line(image, x, y + arrow_height / 2, x + arrow_width,
                  y + arrow_height / 2)
Example #3
0
def draw_Then(image, x, y, construct, options, forward):
    constructs = construct.constructs
    arrow_before = options.raildraw_then_before_arrow
    arrow_after = options.raildraw_then_after_arrow
    if not forward:
        constructs = list(reversed(constructs))
        arrow_before, arrow_after = arrow_after, arrow_before
    arrow_width, arrow_height = options.raildraw_size_of_arrow(options)
    width, height, line_position = size_of_Then(image, construct, options)
    current_x = x
    for index, c in enumerate(constructs):
        c_width, c_height, c_line_position = size_of(image, c, options)
        draw(image, current_x, y + (line_position - c_line_position), c,
             options, forward)
        current_x += c_width
        if index != (len(constructs) - 1):
            draw_line(image, current_x, y + line_position,
                      current_x + arrow_before, y + line_position)
            current_x += arrow_before
            options.raildraw_draw_arrow(image, current_x,
                                        y + line_position - (arrow_height / 2),
                                        options, forward)
            current_x += arrow_width
            draw_line(image, current_x, y + line_position,
                      current_x + arrow_after, y + line_position)
            current_x += arrow_after
Example #4
0
def draw_Then(image, x, y, construct, options, forward):
    constructs = construct.constructs
    arrow_before = options.raildraw_then_before_arrow
    arrow_after = options.raildraw_then_after_arrow
    if not forward:
        constructs = list(reversed(constructs))
        arrow_before, arrow_after = arrow_after, arrow_before
    arrow_width, arrow_height = options.raildraw_size_of_arrow(options)
    width, height, line_position = size_of_Then(image, construct, options)
    current_x = x
    for index, c in enumerate(constructs):
        c_width, c_height, c_line_position = size_of(image, c, options)
        draw(image, current_x, y + (line_position - c_line_position), c, options, forward)
        current_x += c_width
        if index != (len(constructs) - 1):
            draw_line(image, current_x, y + line_position, current_x + arrow_before, y + line_position)
            current_x += arrow_before
            options.raildraw_draw_arrow(image, current_x, y + line_position - (arrow_height / 2), options, forward)
            current_x += arrow_width
            draw_line(image, current_x, y + line_position, current_x + arrow_after, y + line_position)
            current_x += arrow_after
Example #5
0
def draw_Or(image, x, y, construct, options, forward):
    if len(construct.constructs) == 1:
        return draw(image, x, y, construct.constructs[0], options, forward)
    width, height, line_position = size_of_Or(image, construct, options)
    constructs = construct.constructs
    sizes = [size_of(image, c, options) for c in constructs]
    max_width = max(sizes, key=itemgetter(0))[0]
    radius = options.raildraw_or_radius
    spacing = options.raildraw_or_spacing
    arrow_width, arrow_height = options.raildraw_size_of_arrow(options)
    before = options.raildraw_or_before
    after = options.raildraw_or_after
    if not forward:
        before, after = after, before
    current_y = y
    for index, (c, (w, h, l)) in enumerate(zip(constructs, sizes)):
        draw_arrows = not isinstance(c, rr.Nothing)
        # Don't draw arrows if c is a loop and its component is not Nothing;
        # the arrows tend to appear superfluous in such a case
        if isinstance(c, rr.Loop) and not isinstance(c.component, rr.Nothing):
            draw_arrows = False
        if index != 0:
            image.move_to(x + radius, current_y + l - radius)
            image.arc_negative(x + radius * 2, current_y + l - radius, radius,
                               radians(180), radians(90))
            image.stroke()
        if not draw_arrows:
            draw_line(image, x + radius * 2, current_y + l,
                      x + radius * 2 + arrow_width, current_y + l)
        else:
            options.raildraw_draw_arrow(image, x + radius * 2,
                                        current_y + l - (arrow_height / 2),
                                        options, forward)
        draw_line(image, x + radius * 2 + arrow_width, current_y + l,
                  x + radius * 2 + arrow_width + before, current_y + l)
        construct_x = x + radius * 2 + arrow_width + before
        if isinstance(c, rr.Nothing):
            draw_line(image, construct_x, current_y + l,
                      construct_x + max_width / 2 - w / 2, current_y + l)
            draw(image, construct_x + max_width / 2 - w / 2, current_y, c,
                 options, forward)
            draw_line(image, construct_x + max_width / 2 + w / 2,
                      current_y + l, construct_x + max_width + after,
                      current_y + l)
        else:
            draw(image, construct_x, current_y, c, options, forward)
            draw_line(image, construct_x + w, current_y + l,
                      construct_x + max_width + after, current_y + l)
        if not draw_arrows:
            draw_line(image, construct_x + max_width + after, current_y + l,
                      construct_x + max_width + after + arrow_width,
                      current_y + l)
        else:
            options.raildraw_draw_arrow(image, construct_x + max_width + after,
                                        current_y + l - (arrow_height / 2),
                                        options, forward)
        if index != 0:
            image.move_to(construct_x + max_width + after + arrow_width,
                          current_y + l)
            image.arc_negative(construct_x + max_width + after + arrow_width,
                               current_y + l - radius, radius, radians(90),
                               radians(0))
            image.stroke()
        if index == len(constructs) - 1:  # Last construct
            line_end_y = current_y + l - radius
        current_y += spacing + h
    image.move_to(x, y + line_position)
    image.arc(x, y + line_position + radius, radius, radians(270), radians(0))
    image.line_to(x + radius, line_end_y)
    image.stroke()
    draw_line(image, x, y + line_position, x + radius * 2, y + line_position)
    end_x = x + radius * 2 + arrow_width + before + max_width + after + arrow_width
    draw_line(image, end_x, y + line_position, end_x + radius * 2,
              y + line_position)
    image.move_to(x + width, y + line_position)
    image.arc_negative(x + width, y + line_position + radius, radius,
                       radians(270), radians(180))
    image.line_to(x + width - radius, line_end_y)
    image.stroke()
Example #6
0
def draw_Nothing(image, x, y, construct, options, forward):
    return options.raildraw_draw_arrow(image, x, y, options, forward)
Example #7
0
def draw_arrow_or_line(image, x, y, arrow_width, arrow_height, options, forward, arrow):
    if arrow:
        options.raildraw_draw_arrow(image, x, y, options, forward)
    else:
        draw_line(image, x, y + arrow_height / 2, x + arrow_width, y + arrow_height / 2)
Example #8
0
def draw_Nothing(image, x, y, construct, options, forward):
    return options.raildraw_draw_arrow(image, x, y, options, forward)
Example #9
0
def draw_Nothing(context, x, y, construct, options, forward):
    return options.raildraw_draw_arrow(context, x, y, options, forward)