kopia lustrzana https://github.com/inkstitch/inkstitch
add g-code output format (#336)
rodzic
6735077a0a
commit
1d55716f26
|
@ -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
|
||||
|
|
|
@ -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-
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 5dd6f5f460def25b47ec588603b7650188ff213e
|
||||
Subproject commit 03f6fded69fc431b28cade51f008de235b09390e
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
Ładowanie…
Reference in New Issue