Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LockStitches and Centering #7

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ https://github.com/EmbroidePy/pyembroidery
* .u01
* .pec
* .xxx
* .tbf
* .gcode

### Read
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
click
vpype>=1.9,<2.0
numpy
pyembroidery
pyembroidery>=1.5.0
12 changes: 8 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup, find_packages
from setuptools import setup


with open("README.md") as f:
readme = f.read()

setup(
name="vpype-embroidery",
version="0.3.0",
version="0.3.2",
description="vpype embroidery plugin",
long_description=readme,
long_description_content_type="text/markdown",
Expand All @@ -15,16 +15,20 @@
url="https://github.com/embroidepy/vpype-embroidery/",
packages=["vpype_embroidery"],
classifiers=[
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
],
install_requires=[
"click",
"vpype>=1.9,<2.0",
"numpy",
"pyembroidery",
"pyembroidery>=1.5.0",
],
entry_points="""
[vpype.plugins]
Expand Down
30 changes: 25 additions & 5 deletions vpype_embroidery/ewrite.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from __future__ import annotations

import click
import pyembroidery
import vpype as vp
import vpype_cli
from pyembroidery import COLOR_BREAK, SEQUENCE_BREAK, STITCH, EmbPattern
Expand All @@ -19,20 +22,37 @@
type=vpype_cli.TextType(),
help="version of embroidery file to write",
)
@click.option(
"-k", "--lock", is_flag=True, help="provide lock-stitches."
)
@click.option(
"-c", "--center", is_flag=True, help="move design center to origin"
)
@vpype_cli.global_processor
def ewrite(document: vp.Document, filename: str, version: str):
def ewrite(document: vp.Document, filename: str, version: str, lock: bool, center: bool):
pattern = EmbPattern()
if lock:
pattern.add_command(pyembroidery.CONTINGENCY_TIE_ON_THREE_SMALL)
pattern.add_command(pyembroidery.CONTINGENCY_TIE_OFF_THREE_SMALL)
for layer in document.layers.values():
for p in layer:
m = p * _PX_PER_EMB
for v in m:
pattern.add_stitch_absolute(STITCH, int(v.real), int(v.imag))
pattern.add_command(SEQUENCE_BREAK)
pattern.add_command(COLOR_BREAK)
if version is not None:
pattern.write(filename, version=version)
else:
pattern.write(filename)
if center:
extends = pattern.bounds()
cx = round((extends[2] + extends[0]) / 2.0)
cy = round((extends[3] + extends[1]) / 2.0)
pattern.translate(-cx, -cy)
try:
if version is not None:
pattern.write(filename, version=version)
else:
pattern.write(filename)
except IOError as e:
print(e)
return document


Expand Down