def create_svg(input_image_file, output_image_name, element_list, board_x,
               board_y, board_width, board_height):
    image_width, image_height = get_image_size(input_image_file)

    factor = (image_width / board_width + image_height / board_height) / 2

    # Fixed size for PCB image
    d = draw.Drawing(image_width,
                     image_height,
                     origin=(board_x * factor, board_y * factor))

    # Draw background
    d.append(
        draw.Image(board_x * factor, board_y * factor, image_width,
                   image_height, input_image_file))

    # draw_legend(d)

    for item in element_list.values():
        draw_via_pads(d, item.via_pads.items(), factor)
        draw_smd_pads(d, item.smd_pads.items(), factor)

    d.setRenderSize(image_width, image_height)
    d.savePng(output_image_name + ".png")
    d.saveSvg(output_image_name + ".svg")
def setup():
    if not os.path.exists(OUTPUT_DIR):
        os.makedirs(OUTPUT_DIR)
    if not os.path.exists(TEMP_DIR):
        os.makedirs(TEMP_DIR)

    background_top = INPUT_DIR + "axiom_beta_mixed_panel.top_rotated.png"
    background_bottom = INPUT_DIR + "axiom_beta_mixed_panel.bottom_rotated.png"

    board_x = 0
    board_y = 0

    board_outline = gerberex.read('output_stage1/axiom_beta_mixed_panel.boardoutline.ger')

    board_width = board_outline.size[1]
    board_height = board_outline.size[0]

    image_width, image_height = get_image_size(background_top)

    global drawing_top, drawing_bottom, factor, output_image_height

    output_image_width = image_width / 2
    output_image_height = image_height / 2

    factor = (output_image_width / board_width + output_image_height / board_height) / 2

    # Fixed size for PCB image
    drawing_top = draw.Drawing(output_image_width, output_image_height)
    drawing_bottom = draw.Drawing(output_image_width, output_image_height)

    # Draw background
    drawing_top.append(draw.Image(board_x * factor, board_y * factor,
                                  output_image_width, output_image_height, background_top))

    drawing_top.append(draw.Rectangle(0, 0, output_image_width, output_image_height, fill="black", opacity=0.5))

    drawing_bottom.append(draw.Image(board_x * factor, board_y * factor,
                                     output_image_width, output_image_height, background_bottom))

    drawing_bottom.append(draw.Rectangle(0, 0, output_image_width, output_image_height, fill="black", opacity=0.5))
def main():
    # Setup
    Path(OUTPUT_DIR).mkdir(parents=True, exist_ok=True)

    # Parse command line arguments
    parser = argparse.ArgumentParser(
        description='Generate preview of probed PCB data.')
    setup_args(parser)
    args = parser.parse_args()

    # Find board dimensions for visualization
    tree = ElementTree.parse(args.eagle_brd_file)
    xml_root = tree.getroot()

    board_x, board_y, board_width, board_height = get_board_dimensions(
        xml_root)

    # Load background image
    image = Image.open(args.background_image)
    factor = (image.width / board_width + image.height / board_height) / 2
    d = drawSvg.Drawing(image.width,
                        image.height,
                        origin=(board_x * factor, board_y * factor))
    d.append(
        drawSvg.Image(board_x * factor,
                      board_y * factor,
                      image.width,
                      image.height,
                      args.background_image,
                      embed=True))

    # Load measurement data
    df = pandas.read_csv(args.data_file, sep=';', header=3)
    data = prepare_data(df)

    # Load board data
    board_data = {}
    load_board_data(args, board_data)

    # Modify color values and apply factors
    data['MEAS_3_CLAMPED'] = data['MEAS_3'].apply(
        lambda x: (x - args.red_value) * args.red_factor)
    data['MEAS_5_CLAMPED'] = data['MEAS_5'].apply(
        lambda x: (x - args.green_value) * args.green_factor)
    data['MEAS_6_CLAMPED'] = data['MEAS_6'].apply(
        lambda x: (x - args.blue_value) * args.blue_factor)

    draw_pads(board_data, d, data, factor)

    d.savePng(OUTPUT_DIR + "measurement_result.png")
    d.saveSvg(OUTPUT_DIR + "measurement_result.svg")
Beispiel #4
0
 def _init_tile_images(self):
     for tile_id, path in self.TILES.items():
         img = draw.Image(0,
                          -1,
                          1,
                          1,
                          "../" + path,
                          mimeType=".png",
                          embed=True,
                          preserveAspectRatio="none")
         self.drawing.otherDefs.append(
             Pattern(children=[img],
                     id=tile_id,
                     height="100%",
                     width="100%",
                     patternContentUnits="objectBoundingBox"))
def create_svg(books, path):
    drawingWidth = 650
    drawingHeight = 350
    padding = 30
    svg = draw.Drawing(drawingWidth, drawingHeight)
    width = 100
    height = 150
    x = 0
    y = drawingHeight - height - padding
    text_padding = 10

    for book in books:
        svg.append(
            draw.Image(x,
                       y,
                       width,
                       height,
                       data=_get_image_from_url(book['imageUrl']),
                       embed=True,
                       mimeType=".jpg"))
        if 'nophoto' in book['imageUrl']:
            book_title_with_newlines = ""
            book_title_word_list = book['title'].split()
            for word in book_title_word_list:
                space = " "
                if len(word) > 3:
                    space = "\n"
                book_title_with_newlines = f"{book_title_with_newlines}{space}{word}"
            svg.append(
                draw.Text(book_title_with_newlines, 16, x + text_padding,
                          y + height - text_padding))
        x = x + width + padding
        y = y
        if x > (drawingWidth - width):
            x = 0
            y = y - height - padding
    svg.saveSvg(path)
Beispiel #6
0
        if shape.auto_shape_type == MSO_SHAPE.OVAL:
            r = shape.width/FACTOR
            c = shape.fill.fore_color.rgb
            line_color = shape.line.fill.fore_color.rgb
            line_width = shape.line.width/FACTOR
            g.append(draw.Circle(shape.left/FACTOR+r/2, shape.top/FACTOR+r/2, r/2, fill='#{}'.format(c), stroke='#{}'.format(line_color), stroke_width=line_width))
    elif shape.shape_type == MSO_SHAPE_TYPE.GROUP:
        print(shape, shape.name, "SHAPE len = {}".format(len(shape.shapes)))
        for shape in shape.shapes:
            print(shape.shape_type, shape.left, shape.top, shape.width, shape.height)
        g.append(draw.Rectangle(shape.left/FACTOR, shape.top/FACTOR, shape.width/FACTOR, shape.height/FACTOR, fill='#1248ff'))
    elif shape.shape_type == MSO_SHAPE_TYPE.LINE:
        line_color = shape.line.fill.fore_color.rgb
        line_width = shape.line.width/FACTOR
        g.append(draw.Line(shape.begin_x/FACTOR, shape.begin_y/FACTOR, shape.end_x/FACTOR, shape.end_y/FACTOR, stroke='#{}'.format(line_color), stroke_width=line_width))
    elif shape.shape_type == MSO_SHAPE_TYPE.PLACEHOLDER:
        print(shape.text)
        g.append(draw.Rectangle(shape.left/FACTOR, shape.top/FACTOR, shape.width/FACTOR, shape.height/FACTOR, fill='none', stroke='#1248ff', stroke_width=1000/FACTOR))
        g.append(draw.Text(shape.text, 400, 0, -400, text_anchor='start', transform='scale(1,-1) translate({},{})'.format(shape.left/FACTOR, shape.top/FACTOR)))
    elif shape.shape_type == MSO_SHAPE_TYPE.PICTURE:
        g.append(draw.Image(shape.left/FACTOR, shape.top/FACTOR, shape.width/FACTOR, shape.height/FACTOR, data=shape.image.blob))
    else:
        g.append(draw.Rectangle(shape.left/FACTOR, shape.top/FACTOR, shape.width/FACTOR, shape.height/FACTOR, fill='#1248ff'))
    # d.append(draw.Rectangle(shape.left/FACTOR, pres.slide_height/FACTOR-shape.top/FACTOR, shape.width/FACTOR, shape.height/FACTOR, fill='#1248ff'))
    # g.append(draw.Text('Text at (2,1)',0.5, 0,0, text_anchor='middle', transform='scale(1,-1) translate(2,1)'))

d.append(g)
d.setRenderSize(h=600)
d.saveSvg('out.svg')

from pathlib import Path

things = [("lsystems/leaf.json", 6), ("lsystems/leaf.json", 7),
          ("lsystems/leaf.json", 8), ("lsystems/bush1.json", 4),
          ("lsystems/bush1.json", 5), ("lsystems/bush2.json", 4),
          ("lsystems/bush2.json", 5), ("lsystems/bush3.json", 4),
          ("lsystems/bush3.json", 5), ("lsystems/bush4.json", 4),
          ("lsystems/bush5.json", 6), ("lsystems/bush5.json", 7),
          ("lsystems/bush5.json", 8)]

fnames_png = [
    comp.compile(l, n, True, "figs/" + Path(l).stem + "_transparent")
    for l, n in things
]
PATHS = [Path(x).with_suffix('.svg') for x in fnames_png]

N_TREES = 50

forest = draw.Drawing(1000, 1000)

forest.append(draw.Rectangle(0, 0, 1000, 1000, fill='white'))

for _ in range(N_TREES):
    x = random.randint(0, 1000)
    y = random.randint(0, 500)
    p = random.choice(PATHS)
    im = draw.Image(x, y, width=200, height=200, path=p, embed=True)
    forest.append(im)

forest.saveSvg("figs/forest.svg")