Esempio n. 1
0
def write_embroidery_file(file_path, stitches):
    # Embroidery machines don't care about our canvas size, so we relocate the
    # design to the origin.  It might make sense to center it about the origin
    # instead.
    min_x = min(stitch.x for stitch in stitches)
    min_y = min(stitch.y for stitch in stitches)

    pattern = libembroidery.embPattern_create()
    last_color = None

    for stitch in stitches:
        if stitch.color != last_color:
            add_thread(pattern, make_thread(stitch.color))
            last_color = stitch.color

        flags = get_flags(stitch)
        libembroidery.embPattern_addStitchAbs(pattern, stitch.x - min_x,
                                              stitch.y - min_y, flags, 1)

    libembroidery.embPattern_addStitchAbs(pattern, stitch.x - min_x,
                                          stitch.y - min_y, libembroidery.END,
                                          1)

    # convert from pixels to millimeters
    libembroidery.embPattern_scale(pattern, 1 / PIXELS_PER_MM)

    # SVG and embroidery disagree on the direction of the Y axis
    libembroidery.embPattern_flipVertical(pattern)

    libembroidery.embPattern_write(pattern, file_path)
Esempio n. 2
0
def write_embroidery_file(file_path, stitch_plan, svg):
    origin = get_origin(svg)

    pattern = libembroidery.embPattern_create()

    for color_block in stitch_plan:
        add_thread(pattern, make_thread(color_block.color))

        for stitch in color_block:
            if stitch.stop and stitch is not color_block.last_stitch:
                # A STOP stitch that is not at the end of a color block
                # occurs when the user specified "STOP after".  "STOP" is the
                # same thing as a color change, and the user will assign a
                # special color at the machine that tells it to pause after.
                # We need to add another copy of the same color here so that
                # the stitches after the STOP are still the same color.
                add_thread(pattern, make_thread(color_block.color))

            flags = get_flags(stitch)
            libembroidery.embPattern_addStitchAbs(pattern, stitch.x - origin.x,
                                                  stitch.y - origin.y, flags,
                                                  1)

    libembroidery.embPattern_addStitchAbs(pattern, stitch.x - origin.x,
                                          stitch.y - origin.y,
                                          libembroidery.END, 1)

    # convert from pixels to millimeters
    libembroidery.embPattern_scale(pattern, 1 / PIXELS_PER_MM)

    # SVG and embroidery disagree on the direction of the Y axis
    libembroidery.embPattern_flipVertical(pattern)

    libembroidery.embPattern_write(pattern, file_path)
Esempio n. 3
0
def write_embroidery_file(file_path, stitch_plan, svg):
    origin = get_origin(svg)

    pattern = libembroidery.embPattern_create()

    for color_block in stitch_plan:
        add_thread(pattern, make_thread(color_block.color))

        for stitch in color_block:
            if stitch.stop:
                # This is the start of the extra color block added by the
                # "STOP after" handler (see stitch_plan/stop.py).  Assign it
                # the same color.
                add_thread(pattern, make_thread(color_block.color))

            flags = get_flags(stitch)
            libembroidery.embPattern_addStitchAbs(pattern, stitch.x - origin.x,
                                                  stitch.y - origin.y, flags,
                                                  1)

    libembroidery.embPattern_addStitchAbs(pattern, stitch.x - origin.x,
                                          stitch.y - origin.y,
                                          libembroidery.END, 1)

    # convert from pixels to millimeters
    libembroidery.embPattern_scale(pattern, 1 / PIXELS_PER_MM)

    # SVG and embroidery disagree on the direction of the Y axis
    libembroidery.embPattern_flipVertical(pattern)

    libembroidery.embPattern_write(pattern, file_path)