summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2021-08-16 19:40:44 -0400
committerGitHub <noreply@github.com>2021-08-16 19:40:44 -0400
commit3ebc238561dd2403b19a56a0f3147c70eb4ebe3d (patch)
treec7e4c618335fac2196d42e03f26c3c2ad2a4251d /lib/extensions
parent5a7b7276759b6fb4c85891b13d9ee7a2da8150ab (diff)
parentb49f7d28314f30727f9f963bddb795b88a95f2bd (diff)
Merge pull request #1254 from inkstitch/kaalleen/satin-patterns
Satin pattern and split stitch
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py2
-rw-r--r--lib/extensions/base.py8
-rw-r--r--lib/extensions/lettering.py4
-rw-r--r--lib/extensions/output.py6
-rw-r--r--lib/extensions/params.py4
-rw-r--r--lib/extensions/print_pdf.py6
-rw-r--r--lib/extensions/selection_to_pattern.py63
-rw-r--r--lib/extensions/stitch_plan_preview.py6
-rw-r--r--lib/extensions/zip.py6
9 files changed, 88 insertions, 17 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 64e6af02..83a522f2 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -30,6 +30,7 @@ from .params import Params
from .print_pdf import Print
from .remove_embroidery_settings import RemoveEmbroiderySettings
from .reorder import Reorder
+from .selection_to_pattern import SelectionToPattern
from .simulator import Simulator
from .stitch_plan_preview import StitchPlanPreview
from .zip import Zip
@@ -42,6 +43,7 @@ __all__ = extensions = [StitchPlanPreview,
Output,
Zip,
Flip,
+ SelectionToPattern,
ObjectCommands,
LayerCommands,
GlobalCommands,
diff --git a/lib/extensions/base.py b/lib/extensions/base.py
index 057a0e63..828e3685 100644
--- a/lib/extensions/base.py
+++ b/lib/extensions/base.py
@@ -16,6 +16,7 @@ from ..commands import is_command, layer_commands
from ..elements import EmbroideryElement, nodes_to_elements
from ..elements.clone import is_clone
from ..i18n import _
+from ..patterns import is_pattern
from ..svg import generate_unique_id
from ..svg.tags import (CONNECTOR_TYPE, EMBROIDERABLE_TAGS, INKSCAPE_GROUPMODE,
NOT_EMBROIDERABLE_TAGS, SVG_DEFS_TAG, SVG_GROUP_TAG)
@@ -160,9 +161,10 @@ class InkstitchExtension(inkex.Effect):
if selected:
if node.tag == SVG_GROUP_TAG:
pass
- elif getattr(node, "get_path", None):
+ elif (node.tag in EMBROIDERABLE_TAGS or is_clone(node)) and not is_pattern(node):
nodes.append(node)
- elif troubleshoot and (node.tag in NOT_EMBROIDERABLE_TAGS or node.tag in EMBROIDERABLE_TAGS or is_clone(node)):
+ # add images, text and patterns for the troubleshoot extension
+ elif troubleshoot and (node.tag in NOT_EMBROIDERABLE_TAGS or is_pattern(node)):
nodes.append(node)
return nodes
@@ -186,7 +188,7 @@ class InkstitchExtension(inkex.Effect):
selected.append(node)
return selected
- def elements_to_patches(self, elements):
+ def elements_to_stitch_groups(self, elements):
patches = []
for element in elements:
if patches:
diff --git a/lib/extensions/lettering.py b/lib/extensions/lettering.py
index 875dea03..312a47ce 100644
--- a/lib/extensions/lettering.py
+++ b/lib/extensions/lettering.py
@@ -30,9 +30,11 @@ class LetteringFrame(wx.Frame):
def __init__(self, *args, **kwargs):
# This is necessary because of https://github.com/inkstitch/inkstitch/issues/1186
- if sys.platform.startswith('win'):
+ if sys.platform.startswith('win32'):
import locale
locale.setlocale(locale.LC_ALL, "C")
+ lc = wx.Locale()
+ lc.Init(wx.LANGUAGE_DEFAULT)
# begin wxGlade: MyFrame.__init__
self.group = kwargs.pop('group')
diff --git a/lib/extensions/output.py b/lib/extensions/output.py
index e621f1b6..7cc12ee0 100644
--- a/lib/extensions/output.py
+++ b/lib/extensions/output.py
@@ -8,7 +8,7 @@ import sys
import tempfile
from ..output import write_embroidery_file
-from ..stitch_plan import patches_to_stitch_plan
+from ..stitch_plan import stitch_groups_to_stitch_plan
from .base import InkstitchExtension
@@ -52,8 +52,8 @@ class Output(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
- patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False))
+ patches = self.elements_to_stitch_groups(self.elements)
+ stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len, disable_ties=self.settings.get('laser_mode', False))
temp_file = tempfile.NamedTemporaryFile(suffix=".%s" % self.file_extension, delete=False)
diff --git a/lib/extensions/params.py b/lib/extensions/params.py
index 82cc9be9..c96b9691 100644
--- a/lib/extensions/params.py
+++ b/lib/extensions/params.py
@@ -331,9 +331,11 @@ class ParamsTab(ScrolledPanel):
class SettingsFrame(wx.Frame):
def __init__(self, *args, **kwargs):
# This is necessary because of https://github.com/inkstitch/inkstitch/issues/1186
- if sys.platform.startswith('win'):
+ if sys.platform.startswith('win32'):
import locale
locale.setlocale(locale.LC_ALL, "C")
+ lc = wx.Locale()
+ lc.Init(wx.LANGUAGE_DEFAULT)
# begin wxGlade: MyFrame.__init__
self.tabs_factory = kwargs.pop('tabs_factory', [])
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index 0facdf92..e5cb25d8 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -23,7 +23,7 @@ from werkzeug.serving import make_server
from ..gui import open_url
from ..i18n import get_languages
from ..i18n import translation as inkstitch_translation
-from ..stitch_plan import patches_to_stitch_plan
+from ..stitch_plan import stitch_groups_to_stitch_plan
from ..svg import render_stitch_plan
from ..svg.tags import INKSCAPE_GROUPMODE
from ..threads import ThreadCatalog
@@ -302,8 +302,8 @@ class Print(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
- patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, collapse_len=collapse_len)
+ patches = self.elements_to_stitch_groups(self.elements)
+ stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
palette = ThreadCatalog().match_and_apply_palette(stitch_plan, self.get_inkstitch_metadata()['thread-palette'])
overview_svg, color_block_svgs = self.render_svgs(stitch_plan, realistic=False)
diff --git a/lib/extensions/selection_to_pattern.py b/lib/extensions/selection_to_pattern.py
new file mode 100644
index 00000000..41f89a83
--- /dev/null
+++ b/lib/extensions/selection_to_pattern.py
@@ -0,0 +1,63 @@
+# Authors: see git history
+#
+# Copyright (c) 2021 Authors
+# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
+
+import inkex
+from lxml import etree
+
+from ..i18n import _
+from ..svg.tags import EMBROIDERABLE_TAGS, SVG_DEFS_TAG
+from .base import InkstitchExtension
+
+
+class SelectionToPattern(InkstitchExtension):
+
+ def effect(self):
+ if not self.get_elements():
+ return
+
+ if not self.svg.selected:
+ inkex.errormsg(_("Please select at least one object to be marked as a pattern."))
+ return
+
+ for pattern in self.get_nodes():
+ if pattern.tag in EMBROIDERABLE_TAGS:
+ self.set_marker(pattern)
+
+ def set_marker(self, node):
+ xpath = ".//marker[@id='inkstitch-pattern-marker']"
+ pattern_marker = self.document.xpath(xpath)
+
+ if not pattern_marker:
+ # get or create def element
+ defs = self.document.find(SVG_DEFS_TAG)
+ if defs is None:
+ defs = etree.SubElement(self.document, SVG_DEFS_TAG)
+
+ # insert marker
+ marker = """<marker
+ refX="10"
+ refY="5"
+ orient="auto"
+ id="inkstitch-pattern-marker">
+ <g
+ id="inkstitch-pattern-group">
+ <path
+ style="fill:#fafafa;stroke:#ff5500;stroke-width:0.5;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:1, 1;stroke-dashoffset:0;stroke-opacity:1;fill-opacity:0.8;"
+ d="M 10.12911,5.2916678 A 4.8374424,4.8374426 0 0 1 5.2916656,10.12911 4.8374424,4.8374426 0 0 1 0.45422399,5.2916678 4.8374424,4.8374426 0 0 1 5.2916656,0.45422399 4.8374424,4.8374426 0 0 1 10.12911,5.2916678 Z"
+ id="inkstitch-pattern-marker-circle" />
+ <path
+ style="fill:none;stroke:#000000;stroke-width:0.4;stroke-linecap:round;stroke-miterlimit:4;"
+ id="inkstitch-pattern-marker-spiral"
+ d="M 4.9673651,5.7245662 C 4.7549848,5.7646159 4.6247356,5.522384 4.6430021,5.3419847 4.6765851,5.0103151 5.036231,4.835347 5.3381858,4.8987426 5.7863901,4.9928495 6.0126802,5.4853625 5.9002872,5.9065088 5.7495249,6.4714237 5.1195537,6.7504036 4.5799191,6.5874894 3.898118,6.3816539 3.5659013,5.6122905 3.7800789,4.9545192 4.0402258,4.1556558 4.9498996,3.7699484 5.7256318,4.035839 6.6416744,4.3498087 7.0810483,5.4003986 6.7631909,6.2939744 6.395633,7.3272552 5.2038143,7.8204128 4.1924535,7.4503931 3.0418762,7.0294421 2.4948761,5.6961604 2.9171752,4.567073 3.3914021,3.2991406 4.8663228,2.6982592 6.1130974,3.1729158 7.4983851,3.7003207 8.1531869,5.3169977 7.6260947,6.6814205 7.0456093,8.1841025 5.2870784,8.8928844 3.8050073,8.3132966 2.1849115,7.6797506 1.4221671,5.7793073 2.0542715,4.1796074 2.7408201,2.4420977 4.7832541,1.6253548 6.5005435,2.310012 8.3554869,3.0495434 9.2262638,5.2339874 8.4890181,7.0688861 8.4256397,7.2266036 8.3515789,7.379984 8.2675333,7.5277183" />
+ </g>
+ </marker>""" # noqa: E501
+ defs.append(etree.fromstring(marker))
+
+ # attach marker to node
+ style = node.get('style') or ''
+ style = style.split(";")
+ style = [i for i in style if not i.startswith('marker-start')]
+ style.append('marker-start:url(#inkstitch-pattern-marker)')
+ node.set('style', ";".join(style))
diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py
index 40ad6a2a..c50fa738 100644
--- a/lib/extensions/stitch_plan_preview.py
+++ b/lib/extensions/stitch_plan_preview.py
@@ -3,7 +3,7 @@
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
-from ..stitch_plan import patches_to_stitch_plan
+from ..stitch_plan import stitch_groups_to_stitch_plan
from ..svg import render_stitch_plan
from .base import InkstitchExtension
@@ -23,8 +23,8 @@ class StitchPlanPreview(InkstitchExtension):
realistic = False
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
- patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, collapse_len=collapse_len)
+ patches = self.elements_to_stitch_groups(self.elements)
+ stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
render_stitch_plan(svg, stitch_plan, realistic)
# translate stitch plan to the right side of the canvas
diff --git a/lib/extensions/zip.py b/lib/extensions/zip.py
index 605b4573..22654560 100644
--- a/lib/extensions/zip.py
+++ b/lib/extensions/zip.py
@@ -16,7 +16,7 @@ import pyembroidery
from ..i18n import _
from ..output import write_embroidery_file
-from ..stitch_plan import patches_to_stitch_plan
+from ..stitch_plan import stitch_groups_to_stitch_plan
from ..threads import ThreadCatalog
from .base import InkstitchExtension
@@ -43,8 +43,8 @@ class Zip(InkstitchExtension):
self.metadata = self.get_inkstitch_metadata()
collapse_len = self.metadata['collapse_len_mm']
- patches = self.elements_to_patches(self.elements)
- stitch_plan = patches_to_stitch_plan(patches, collapse_len=collapse_len)
+ patches = self.elements_to_stitch_groups(self.elements)
+ stitch_plan = stitch_groups_to_stitch_plan(patches, collapse_len=collapse_len)
base_file_name = self.get_base_file_name()
path = tempfile.mkdtemp()