From 3299b7450f847e9ecb0df9f8b8a5cd3da755a33b Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Sat, 30 Jun 2018 13:02:33 -0400 Subject: add extension to swap satin column rails --- lib/extensions/flip.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 lib/extensions/flip.py (limited to 'lib/extensions/flip.py') 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) -- cgit v1.2.3