diff options
| author | Lex Neva <lexelby@users.noreply.github.com> | 2018-07-10 19:48:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-07-10 19:48:40 -0400 |
| commit | b23f7358748f928e8b66d0e698677b489bee8405 (patch) | |
| tree | acb29d66cf710a5bade50ef787bc040b2c22074b /lib | |
| parent | 7a4b4b7e6c8e1746f724392bb74577adda64fe7b (diff) | |
| parent | c871193c94ed693f50071674656030a6c4c562ef (diff) | |
Merge pull request #219 from inkstitch/lexelby-flip-satin
add extension to swap satin column rails
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extensions/__init__.py | 1 | ||||
| -rw-r--r-- | lib/extensions/flip.py | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py index b8951e12..b11ba1a4 100644 --- a/lib/extensions/__init__.py +++ b/lib/extensions/__init__.py @@ -6,3 +6,4 @@ from simulate import Simulate from input import Input from output import Output from zip import Zip +from flip import Flip 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) |
