Ejemplo n.º 1
0
def run():
    EMBROIDEPY_VERSION = "0.0.3"
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument("input", nargs="?", type=str, help="input file")
    parser.add_argument("-o", "--output", type=str, help="output file name")
    parser.add_argument("-V", "--version", action="store_true", help="version")
    parser.add_argument("-g",
                        "--graphics",
                        action="store_true",
                        help="view graphics")

    argv = sys.argv[1:]
    args = parser.parse_args(argv)
    if args.version:
        print("Embroidepy v%s" % EMBROIDEPY_VERSION)
        return
    if args.graphics:
        pattern = pyembroidery.EmbPattern(args.input)
        for data in pattern.extras:
            if str(data).startswith('pec_graphic_'):
                print(pyembroidery.get_graphic_as_string(pattern.extras[data]))
        return
    if args.output:
        pattern = pyembroidery.EmbPattern(args.input)
        pattern.write(args.output)
        return
    embroiderpy = Embroidepy(0)
    embroiderpy.read_file(args.input)
    embroiderpy.MainLoop()
Ejemplo n.º 2
0
def write_embroidery_file(file_path, stitch_plan, svg):
    origin = get_origin(svg)

    pattern = pyembroidery.EmbPattern()

    for color_block in stitch_plan:
        pattern.add_thread(color_block.color.pyembroidery_thread)

        for stitch in color_block:
            command = get_command(stitch)
            pattern.add_stitch_absolute(command, stitch.x, stitch.y)

    pattern.add_stitch_absolute(pyembroidery.END, stitch.x, stitch.y)

    # convert from pixels to millimeters
    # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
    scale = 10 / PIXELS_PER_MM

    settings = {
        # correct for the origin
        "translate": -origin,

        # convert from pixels to millimeters
        # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
        "scale": (scale, scale),

        # This forces a jump at the start of the design and after each trim,
        # even if we're close enough not to need one.
        "full_jump": True,
    }

    pyembroidery.write(pattern, file_path, settings)
Ejemplo n.º 3
0
def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
    origin = get_origin(svg, stitch_plan.bounding_box)

    pattern = pyembroidery.EmbPattern()
    stitch = Stitch(0, 0)

    for color_block in stitch_plan:
        pattern.add_thread(color_block.color.pyembroidery_thread)

        for stitch in color_block:
            if stitch.stop:
                jump_to_stop_point(pattern, svg)
            command = get_command(stitch)
            pattern.add_stitch_absolute(command, stitch.x, stitch.y)

    pattern.add_stitch_absolute(pyembroidery.END, stitch.x, stitch.y)

    # convert from pixels to millimeters
    # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
    scale = 10 / PIXELS_PER_MM

    settings.update({
        # correct for the origin
        "translate": -origin,

        # convert from pixels to millimeters
        # also multiply by 10 to get tenths of a millimeter as required by pyembroidery
        "scale": (scale, scale),

        # This forces a jump at the start of the design and after each trim,
        # even if we're close enough not to need one.
        "full_jump": True,
    })

    if file_path.endswith('.csv'):
        # Special treatment for CSV: instruct pyembroidery not to do any post-
        # processing.  This will allow the user to match up stitch numbers seen
        # in the simulator with commands in the CSV.
        settings['max_stitch'] = float('inf')
        settings['max_jump'] = float('inf')
        settings['explicit_trim'] = False

    try:
        pyembroidery.write(pattern, file_path, settings)
    except IOError as e:
        # L10N low-level file error.  %(error)s is (hopefully?) translated by
        # the user's system automatically.
        msg = _("Error writing to %(path)s: %(error)s") % dict(
            path=file_path, error=e.strerror)
        inkex.errormsg(msg)
        sys.exit(1)
Ejemplo n.º 4
0
def test_simple():

    pattern = pyembroidery.EmbPattern()

    pattern.add_thread({
        "rgb": 0x0000FF,
        "name": "Blue Test",
        "catalog": "0033",
        "brand": "PyEmbroidery Brand Thread"
    })

    pattern.add_thread({
        "rgb": 0x00FF00,
        "name": "Green",
        "catalog": "0034",
        "brand": "PyEmbroidery Brand Thread"
    })

    test_fractals.generate(pattern)

    settings = {
        "tie_on": True,
        "tie_off": True
    }
    
    temp_dir = "temp"
    if not os.path.isdir(temp_dir):
        os.mkdir(temp_dir)
    
    pyembroidery.write(pattern, temp_dir + "/generated.u01", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.pec", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.pes", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.exp", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.dst", settings)
    settings["extended header"] = True
    pyembroidery.write(pattern, temp_dir + "/generated-eh.dst", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.jef", settings)
    pyembroidery.write(pattern, temp_dir + "/generated.vp3", settings)
    settings["pes version"] = 1,
    pyembroidery.write(pattern, temp_dir + "/generatedv1.pes", settings)
    settings["truncated"] = True
    pyembroidery.write(pattern, temp_dir + "/generatedv1t.pes", settings)
    settings["pes version"] = 6,
    pyembroidery.write(pattern, temp_dir + "/generatedv6t.pes", settings)

    pyembroidery.convert(temp_dir + "/generated.exp", temp_dir + "/genconvert.dst", 
        {"stable": False, "encode": False})
    
    shutil.rmtree(temp_dir)
Ejemplo n.º 5
0
def create_pes():
    global mvp
    pattern = em.EmbPattern()

    vertices = [ world_space_to_screen_space(vert) for vert in scene.vertices ]

    def to_i4(l):
        return l[0] | l[1] << 8 | l[2] << 16 | l[3] << 24

    im = list(face_fbo.read(components=1, dtype='i4'))
    visible_faces = Counter([ to_i4(im[k:k+4]) for k in range(0,len(im),4) ])
    del visible_faces[0xFFFFFFFF]
    # TODO count pixels of visible faces and prune any with fewer than some number
    print(visible_faces)

    # faces = visible_faces
    threshold = 10
    faces = [ f for f,cnt in visible_faces.items() if cnt >= threshold ]

    G = nx.Graph()

    # go through all things in scene indices
    for idx in faces:
        face = scene.mesh_list[0].faces[idx]

        verts = [ tuple(vertices[p]) for p in face ]
        edges = list(zip(verts, islice(cycle(verts), 1, None)))

        G.add_edges_from(edges)

    stitches = []
    for C in [ G.subgraph(c) for c in nx.connected_components(G) ]:
        for (p0, p1) in nx.eulerian_circuit(nx.eulerize(C)):
            # needs to be at least 2
            for t in np.linspace(0, 1, 2):
                stitches.append(((1-t)*p0[0] + t*p1[0], (1-t)*p0[1] + t*p1[1]))

    stitches = [ k for k,g in groupby(stitches) ]

    for (x, y) in stitches:
        pattern.add_stitch_absolute(em.STITCH, x, y)

    # create dst format (pes doesn't work?)
    print("Saving file...")
    em.write_dst(pattern, 'file.dst')
    em.write_pes(pattern, 'file.pes')
    em.write_txt(pattern, 'file.txt')

    print("Done.")
Ejemplo n.º 6
0
    def RunScript(self, N):
        # default for N
        if N is None:
            N = 1

        # initialize output
        Pattern = System.Collections.Generic.List[object]()

        # create empty patterns
        for i in range(N):
            pat = pyembroidery.EmbPattern()
            Pattern.Add(pat)

        # return outputs if you have them; here I try it for you:
        return Pattern
Ejemplo n.º 7
0
    def __init__(self, *args, **kwds):

        # begin wxGlade: StitchPanel.__init__
        kwds["style"] = kwds.get("style", 0) | wx.WANTS_CHARS
        wx.Panel.__init__(self, *args, **kwds)

        self.name_dict = pyembroidery.get_common_name_dictionary()
        self.emb_pattern = pyembroidery.EmbPattern()
        self.emb_pattern.stitch_abs(0, 0)
        self.name = None
        self.max_stitch = 0
        self.current_stitch = -1
        self.scale = 1
        self.translate_x = 0
        self.translate_y = 0
        self.buffer = 0.1
        self.grid = None
        self.text_grid = None
        self.clicked_position = None

        self.drag_point = None
        self.selected_point = 0

        self.__set_properties()
        self.__do_layout()

        # end wxGlade
        self.Bind(wx.EVT_PAINT, self.on_paint)
        self.Bind(wx.EVT_SIZE, self.on_size)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.on_erase)
        self.Bind(wx.EVT_MOTION, self.on_mouse_move)
        self.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
        self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
        self.Bind(wx.EVT_LEFT_UP, self.on_mouse_up)
        self.Bind(wx.EVT_LEFT_DCLICK, self.on_left_double_click)
        self.Bind(wx.EVT_MIDDLE_DCLICK, self.on_left_double_click)
        self.Bind(wx.EVT_RIGHT_DCLICK, self.on_right_double_click)
        self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_mouse_down)
        self.Bind(wx.EVT_DROP_FILES, self.on_drop_file)
Ejemplo n.º 8
0
 def on_menu_new(self, event):
     pattern = pyembroidery.EmbPattern()
     pattern.extras["filename"] = "unnamed"
     self.add_embroidery(pattern)