summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2018-10-20 17:50:39 -0600
committerGitHub <noreply@github.com>2018-10-20 17:50:39 -0600
commit1d55716f26ea08a61ebdb8488ae60fb010b91702 (patch)
tree9d92856cd137d319efd12ef377e4f216816dd3fb
parent6735077a0a83c42be47de0f2ebfa4f59384a17af (diff)
add g-code output format (#336)
-rw-r--r--lib/extensions/output.py50
-rw-r--r--lib/output.py6
m---------pyembroidery0
-rw-r--r--templates/output.inx2
-rw-r--r--templates/output_params_txt.xml4
5 files changed, 45 insertions, 17 deletions
diff --git a/lib/extensions/output.py b/lib/extensions/output.py
index 26fd4f2e..8b99c027 100644
--- a/lib/extensions/output.py
+++ b/lib/extensions/output.py
@@ -1,37 +1,59 @@
-import sys
import os
+import sys
import tempfile
-from .base import InkstitchExtension
from ..output import write_embroidery_file
from ..stitch_plan import patches_to_stitch_plan
-from ..svg import PIXELS_PER_MM
+from .base import InkstitchExtension
class Output(InkstitchExtension):
def __init__(self, *args, **kwargs):
- InkstitchExtension.__init__(self)
- self.OptionParser.add_option("-c", "--collapse_len_mm",
- action="store", type="float",
- dest="collapse_length_mm", default=3.0,
- help="max collapse length (mm)")
- self.OptionParser.add_option("-f", "--format",
- dest="file_extension",
- help="file extension to output (example: DST)")
+ InkstitchExtension.__init__(self, *args, **kwargs)
+
+ def getoptions(self, args=sys.argv[1:]):
+ # inkex's option parsing can't handle arbitrary command line arguments
+ # that may be passed for a given output format, so we'll just parse the
+ # args ourselves. :P
+ self.settings = {}
+ extra_args = []
+ for arg in args:
+ if arg.startswith('--') and not arg.startswith('--id='):
+ name, value = arg[2:].split('=')
+
+ try:
+ value = float(value)
+ except ValueError:
+ try:
+ value = {
+ "true": True,
+ "false": False
+ }[value]
+ except (KeyError):
+ pass
+
+ self.settings[name] = value
+ else:
+ extra_args.append(arg)
+
+ self.file_extension = self.settings.pop('format')
+ del sys.argv[1:]
+
+ InkstitchExtension.getoptions(self, extra_args)
def effect(self):
if not self.get_elements():
return
patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, self.options.collapse_length_mm * PIXELS_PER_MM)
+ stitch_plan = patches_to_stitch_plan(patches)
- temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.options.file_extension, delete=False)
+ temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.file_extension, delete=False)
# in windows, failure to close here will keep the file locked
temp_file.close()
- write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot())
+ write_embroidery_file(temp_file.name, stitch_plan, self.document.getroot(), self.settings)
if sys.platform == "win32":
import msvcrt
diff --git a/lib/output.py b/lib/output.py
index ed97ef04..5fa7791f 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -53,7 +53,7 @@ def jump_to_stop_point(pattern, svg):
pattern.add_stitch_absolute(pyembroidery.JUMP, stop_position.point.x, stop_position.point.y)
-def write_embroidery_file(file_path, stitch_plan, svg):
+def write_embroidery_file(file_path, stitch_plan, svg, settings={}):
origin = get_origin(svg)
pattern = pyembroidery.EmbPattern()
@@ -73,7 +73,7 @@ def write_embroidery_file(file_path, stitch_plan, svg):
# also multiply by 10 to get tenths of a millimeter as required by pyembroidery
scale = 10 / PIXELS_PER_MM
- settings = {
+ settings.update({
# correct for the origin
"translate": -origin,
@@ -84,7 +84,7 @@ def write_embroidery_file(file_path, stitch_plan, svg):
# 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-
diff --git a/pyembroidery b/pyembroidery
-Subproject 5dd6f5f460def25b47ec588603b7650188ff213
+Subproject 03f6fded69fc431b28cade51f008de235b09390
diff --git a/templates/output.inx b/templates/output.inx
index 2dc36d72..6899c5d3 100644
--- a/templates/output.inx
+++ b/templates/output.inx
@@ -13,6 +13,8 @@
</output>
<param name="extension" type="string" gui-hidden="true">output</param>
<param name="format" type="string" gui-hidden="true">{{ format }}</param>
+ {% set params = "output_params_" + format + ".xml" %}
+ {% include params ignore missing %}
<script>
<command reldir="extensions" interpreter="python">inkstitch.py</command>
</script>
diff --git a/templates/output_params_txt.xml b/templates/output_params_txt.xml
new file mode 100644
index 00000000..3b78df3b
--- /dev/null
+++ b/templates/output_params_txt.xml
@@ -0,0 +1,4 @@
+ {# these parameters are for g-code files (*.txt) #}
+ <param name="flip_x" type="boolean" gui-description="{{ _("Negate x coordinates") }}">false</param>
+ <param name="flip_y" type="boolean" gui-description="{{ _("Negate y coordinates") }}">false</param>
+ <param name="stitch_z_travel" type="float" gui-description="{{ _("increment z coordinate by this amount per stitch") }}">5.0</param>