diff options
| author | Lex Neva <github.com@lexneva.name> | 2018-07-25 21:39:39 -0400 |
|---|---|---|
| committer | Lex Neva <github.com@lexneva.name> | 2018-07-25 21:39:39 -0400 |
| commit | 6c5e256d73500be4674e8778d80b12c5b6228335 (patch) | |
| tree | 979795c683ae5dbf683cfe53c9eece4939955246 /lib/extensions/flip.py | |
| parent | 5b5188ef9918d196173a4a543532c497140e639c (diff) | |
| parent | d14880db5820ce2175bda7bbe761c21fd6c454d0 (diff) | |
Merge remote-tracking branch 'origin/master' into lexelby-mac-build-mk2
Diffstat (limited to 'lib/extensions/flip.py')
| -rw-r--r-- | lib/extensions/flip.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/extensions/flip.py b/lib/extensions/flip.py new file mode 100644 index 00000000..d8d78cb5 --- /dev/null +++ b/lib/extensions/flip.py @@ -0,0 +1,40 @@ +import sys +import inkex +import cubicsuperpath +from shapely import geometry as shgeo + +from .base import InkstitchExtension +from ..i18n import _ +from ..elements import SatinColumn + +class Flip(InkstitchExtension): + def subpath_to_linestring(self, subpath): + return shgeo.LineString() + + def flip(self, satin): + csp = satin.path + + if len(csp) > 1: + flattened = satin.flatten(csp) + + # find the rails (the two longest paths) and swap them + indices = range(len(csp)) + indices.sort(key=lambda i: shgeo.LineString(flattened[i]).length, 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) |
