summaryrefslogtreecommitdiff
path: root/lib/extensions/embroider.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2021-03-04 18:40:53 +0100
committerGitHub <noreply@github.com>2021-03-04 18:40:53 +0100
commite84a86d4ac0caf29d6074728376ff0a594243fec (patch)
tree888c79ed0094ba2916a1d329861a85515959913c /lib/extensions/embroider.py
parentb39575a50191307b3b56eab6455626398eec6397 (diff)
Update for Inkscape 1.0 (#880)
* update for inkscape 1.0 * add about extension * Build improvements for the inkscape1.0 branch (#985) * zip: export real svg not stitch plan * #411 and #726 * Tools for Font Creators (#1018) * ignore very small holes in fills * remove embroider (#1026) * auto_fill: ignore shrink_or_grow if result is empty (#589) * break apart: do not ignore small fills Co-authored-by: Hagen Fritsch <rumpeltux-github@irgendwo.org> Co-authored-by: Lex Neva <github.com@lexneva.name>
Diffstat (limited to 'lib/extensions/embroider.py')
-rw-r--r--lib/extensions/embroider.py87
1 files changed, 0 insertions, 87 deletions
diff --git a/lib/extensions/embroider.py b/lib/extensions/embroider.py
deleted file mode 100644
index b9089612..00000000
--- a/lib/extensions/embroider.py
+++ /dev/null
@@ -1,87 +0,0 @@
-import os
-
-from ..i18n import _
-from ..output import write_embroidery_file
-from ..stitch_plan import patches_to_stitch_plan
-from ..svg import render_stitch_plan, PIXELS_PER_MM
-from .base import InkstitchExtension
-
-
-class Embroider(InkstitchExtension):
- def __init__(self, *args, **kwargs):
- InkstitchExtension.__init__(self, *args, **kwargs)
- 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("--hide_layers",
- action="store", type="choice",
- choices=["true", "false"],
- dest="hide_layers", default="true",
- help="Hide all other layers when the embroidery layer is generated")
- self.OptionParser.add_option("-O", "--output_format",
- action="store", type="string",
- dest="output_format", default="csv",
- help="Output file extenstion (default: csv)")
- self.OptionParser.add_option("-P", "--path",
- action="store", type="string",
- dest="path", default=".",
- help="Directory in which to store output file")
- self.OptionParser.add_option("-F", "--output-file",
- action="store", type="string",
- dest="output_file",
- help="Output filename.")
- self.OptionParser.add_option("-b", "--max-backups",
- action="store", type="int",
- dest="max_backups", default=5,
- help="Max number of backups of output files to keep.")
- self.OptionParser.usage += _("\n\nSeeing a 'no such option' message? Please restart Inkscape to fix.")
-
- def get_output_path(self):
- if self.options.output_file:
- # This is helpful for folks that run the embroider extension
- # manually from the command line (without Inkscape) for
- # debugging purposes.
- output_path = os.path.join(os.path.expanduser(os.path.expandvars(self.options.path.decode("UTF-8"))),
- self.options.output_file.decode("UTF-8"))
- else:
- csv_filename = '%s.%s' % (self.get_base_file_name(), self.options.output_format)
- output_path = os.path.join(self.options.path.decode("UTF-8"), csv_filename)
-
- def add_suffix(path, suffix):
- if suffix > 0:
- path = "%s.%s" % (path, suffix)
-
- return path
-
- def move_if_exists(path, suffix=0):
- source = add_suffix(path, suffix)
-
- if suffix >= self.options.max_backups:
- return
-
- dest = add_suffix(path, suffix + 1)
-
- if os.path.exists(source):
- move_if_exists(path, suffix + 1)
-
- if os.path.exists(dest):
- os.remove(dest)
-
- os.rename(source, dest)
-
- move_if_exists(output_path)
-
- return output_path
-
- def effect(self):
- if not self.get_elements():
- return
-
- if self.options.hide_layers:
- self.hide_all_layers()
-
- patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, self.options.collapse_length_mm * PIXELS_PER_MM)
- write_embroidery_file(self.get_output_path(), stitch_plan, self.document.getroot())
- render_stitch_plan(self.document.getroot(), stitch_plan)