Command options (#2160)

* letters to font: add visual command import option

* add visual command option to stitch plan preview
pull/2185/head
Kaalleen 2023-03-31 17:10:40 +02:00 zatwierdzone przez GitHub
rodzic 98f4bc43de
commit 06b6f976a9
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 26 dodań i 11 usunięć

Wyświetl plik

@ -25,7 +25,7 @@ class LettersToFont(InkstitchExtension):
InkstitchExtension.__init__(self, *args, **kwargs)
self.arg_parser.add_argument("-d", "--font-dir", type=str, default="", dest="font_dir")
self.arg_parser.add_argument("-f", "--file-format", type=str, default="", dest="file_format")
self.arg_parser.add_argument("-c", "--import-commands", type=inkex.Boolean, default=False, dest="import_commands")
self.arg_parser.add_argument("-c", "--import-commands", type=str, default="params", dest="import_commands")
def effect(self):
font_dir = self.options.font_dir
@ -50,7 +50,7 @@ class LettersToFont(InkstitchExtension):
# remove color block groups if we import without commands
# there will only be one object per color block anyway
if not self.options.import_commands:
if self.options.import_commands == "none":
for element in letter.iter(SVG_PATH_TAG):
group.insert(0, element)
else:
@ -78,4 +78,4 @@ class LettersToFont(InkstitchExtension):
return stitch_plan
def insert_baseline(self, document):
document.namedview.new_guide(position=0.0, name="baseline")
document.namedview.add_guide(position=0.0, name="baseline")

Wyświetl plik

@ -22,6 +22,7 @@ class StitchPlanPreview(InkstitchExtension):
self.arg_parser.add_argument("-v", "--layer-visibility", type=int, default=0, dest="layer_visibility")
self.arg_parser.add_argument("-n", "--needle-points", type=Boolean, default=False, dest="needle_points")
self.arg_parser.add_argument("-i", "--insensitive", type=Boolean, default=False, dest="insensitive")
self.arg_parser.add_argument("-c", "--visual-commands", type=Boolean, default="symbols", dest="visual_commands")
def effect(self):
# delete old stitch plan
@ -33,7 +34,7 @@ class StitchPlanPreview(InkstitchExtension):
return
realistic = False
visual_commands = True
visual_commands = self.options.visual_commands
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
min_stitch_len = self.metadata['min_stitch_len_mm']

Wyświetl plik

@ -17,7 +17,7 @@ from .stitch import Stitch
from .stitch_plan import StitchPlan
def generate_stitch_plan(embroidery_file, import_commands=True): # noqa: C901
def generate_stitch_plan(embroidery_file, import_commands="symbols"): # noqa: C901
validate_file_path(embroidery_file)
pattern = pyembroidery.read(embroidery_file)
stitch_plan = StitchPlan()
@ -29,7 +29,7 @@ def generate_stitch_plan(embroidery_file, import_commands=True): # noqa: C901
if command == pyembroidery.STITCH:
color_block.add_stitch(Stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0))
if len(color_block) > 0:
if not import_commands and command in [pyembroidery.TRIM, pyembroidery.STOP]:
if import_commands == "none" and command in [pyembroidery.TRIM, pyembroidery.STOP]:
# Importing commands is not wanted:
# start a new color block without inserting the command
color_block = stitch_plan.new_color_block(thread)
@ -53,7 +53,9 @@ def generate_stitch_plan(embroidery_file, import_commands=True): # noqa: C901
"height": str(extents[1] * 2),
"viewBox": "0 0 %s %s" % (extents[0] * 2, extents[1] * 2),
})
render_stitch_plan(svg, stitch_plan)
visual_commands = True if import_commands == "symbols" else False
render_stitch_plan(svg, stitch_plan, visual_commands=visual_commands)
# rename the Stitch Plan layer so that it doesn't get overwritten by Embroider
layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")

Wyświetl plik

@ -195,6 +195,8 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
first = False
elif visual_commands:
add_commands(Stroke(destination[-1]), ["trim"])
else:
path.set(INKSTITCH_ATTRIBS['trim_after'], 'true')
color = color_block.color.visible_on_white.to_hex_str()
path = inkex.PathElement(attrib={
@ -206,12 +208,17 @@ def color_block_to_paths(color_block, svg, destination, visual_commands):
})
destination.append(path)
if path is not None and visual_commands:
if color_block.trim_after:
if path is not None and color_block.trim_after:
if visual_commands:
add_commands(Stroke(path), ["trim"])
else:
path.set(INKSTITCH_ATTRIBS['trim_after'], 'true')
if color_block.stop_after:
if path is not None and color_block.stop_after:
if visual_commands:
add_commands(Stroke(path), ["stop"])
else:
path.set(INKSTITCH_ATTRIBS['stop_after'], 'true')
def render_stitch_plan(svg, stitch_plan, realistic=False, visual_commands=True):

Wyświetl plik

@ -26,7 +26,11 @@
</param>
<param type="path" name="font-dir" gui-text="Font directory" indent="1" mode="folder" filetypes="svg"/>
<spacer />
<param type="boolean" name="import-commands" gui-text="Import commands" indent="1">false</param>
<param name="import-commands" type="optiongroup" appearance="combo" gui-text="Import commands" indent="1">
<option value="params">As param</option>
<option value="symbols">As symbol</option>
<option value="none">No</option>
</param>
<spacer />
<separator />
<param name="file-description" type="description" indent="1" >

Wyświetl plik

@ -20,6 +20,7 @@
<param name="needle-points" type="boolean" gui-text="Needle points">false</param>
<param name="insensitive" type="boolean" gui-text="Lock"
gui-description="Make stitch plan insensitive to mouse interactions">false</param>
<param name="visual-commands" type="boolean" gui-text="Display command symbols">false</param>
<spacer />
<script>
{{ command_tag | safe }}