summaryrefslogtreecommitdiff
path: root/lib/extensions/flip.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2018-06-30 13:02:33 -0400
committerLex Neva <github.com@lexneva.name>2018-06-30 13:02:33 -0400
commit3299b7450f847e9ecb0df9f8b8a5cd3da755a33b (patch)
tree90d9c536908733e98dee3d8821a011483d5b62b1 /lib/extensions/flip.py
parent5a85cf4c3cec0c0d8e021fa807d4efc6a051b98d (diff)
add extension to swap satin column rails
Diffstat (limited to 'lib/extensions/flip.py')
-rw-r--r--lib/extensions/flip.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/extensions/flip.py b/lib/extensions/flip.py
new file mode 100644
index 00000000..75d8fe17
--- /dev/null
+++ b/lib/extensions/flip.py
@@ -0,0 +1,34 @@
+import sys
+import inkex
+import cubicsuperpath
+
+from .base import InkstitchExtension
+from ..i18n import _
+from ..elements import SatinColumn
+
+class Flip(InkstitchExtension):
+ def flip(self, satin):
+ csp = cubicsuperpath.parsePath(satin.node.get("d"))
+
+ if len(csp) > 1:
+ # find the rails (the two longest paths) and swap them
+ indices = range(len(csp))
+ indices.sort(key=lambda i: len(csp[i]), reverse=True)
+
+ first = indices[0]
+ second = indices[1]
+ csp[first], csp[second] = csp[second], csp[first]
+
+ satin.node.set("d", cubicsuperpath.formatPath(csp))
+
+ def effect(self):
+ if not self.get_elements():
+ return
+
+ if not self.selected:
+ inkex.errormsg(_("Please select one or more satin columns to flip."))
+ return
+
+ for element in self.elements:
+ if isinstance(element, SatinColumn):
+ self.flip(element)