summaryrefslogtreecommitdiff
path: root/lib/extensions/apply_satin_pattern.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions/apply_satin_pattern.py')
-rw-r--r--lib/extensions/apply_satin_pattern.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/extensions/apply_satin_pattern.py b/lib/extensions/apply_satin_pattern.py
new file mode 100644
index 00000000..9da81075
--- /dev/null
+++ b/lib/extensions/apply_satin_pattern.py
@@ -0,0 +1,39 @@
+# 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 ..i18n import _
+from ..svg.tags import INKSTITCH_ATTRIBS
+from .base import InkstitchExtension
+from ..elements import SatinColumn
+
+
+class ApplySatinPattern(InkstitchExtension):
+ # Add inkstitch:pattern attribute to selected patterns. The patterns will be projected on a satin column, which must be in the selection too
+
+ def effect(self):
+ if not self.get_elements():
+ return
+
+ if not self.svg.selected or not any(isinstance(item, SatinColumn) for item in self.elements) or len(self.svg.selected) < 2:
+ inkex.errormsg(_("Please select at least one satin column and a pattern."))
+ return
+
+ if sum(isinstance(item, SatinColumn) for item in self.elements) > 1:
+ inkex.errormsg(_("Please select only one satin column."))
+ return
+
+ satin_id = self.get_satin_column().node.get('id', None)
+ patterns = self.get_patterns()
+
+ for pattern in patterns:
+ pattern.node.set(INKSTITCH_ATTRIBS['pattern'], satin_id)
+
+ def get_satin_column(self):
+ return list(filter(lambda satin: isinstance(satin, SatinColumn), self.elements))[0]
+
+ def get_patterns(self):
+ return list(filter(lambda satin: not isinstance(satin, SatinColumn), self.elements))