summaryrefslogtreecommitdiff
path: root/lib/extensions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/extensions')
-rw-r--r--lib/extensions/__init__.py4
-rw-r--r--lib/extensions/cut_satin.py37
-rw-r--r--lib/extensions/flip.py13
3 files changed, 41 insertions, 13 deletions
diff --git a/lib/extensions/__init__.py b/lib/extensions/__init__.py
index 5b72ecb3..56cd774b 100644
--- a/lib/extensions/__init__.py
+++ b/lib/extensions/__init__.py
@@ -11,6 +11,7 @@ from object_commands import ObjectCommands
from layer_commands import LayerCommands
from global_commands import GlobalCommands
from convert_to_satin import ConvertToSatin
+from cut_satin import CutSatin
__all__ = extensions = [Embroider,
Install,
@@ -24,4 +25,5 @@ __all__ = extensions = [Embroider,
ObjectCommands,
LayerCommands,
GlobalCommands,
- ConvertToSatin]
+ ConvertToSatin,
+ CutSatin]
diff --git a/lib/extensions/cut_satin.py b/lib/extensions/cut_satin.py
new file mode 100644
index 00000000..0bef794e
--- /dev/null
+++ b/lib/extensions/cut_satin.py
@@ -0,0 +1,37 @@
+import inkex
+
+from .base import InkstitchExtension
+from ..i18n import _
+from ..elements import SatinColumn
+
+
+class CutSatin(InkstitchExtension):
+ def effect(self):
+ if not self.get_elements():
+ return
+
+ if not self.selected:
+ inkex.errormsg(_("Please select one or more satin columns to cut."))
+ return
+
+ for satin in self.elements:
+ if isinstance(satin, SatinColumn):
+ command = satin.get_command("satin_cut_point")
+
+ if command is None:
+ # L10N will have the satin's id prepended, like this:
+ # path12345: error: this satin column does not ...
+ satin.fatal(_('this satin column does not have a "satin column cut point" command attached to it. '
+ 'Please use the "Attach commands" extension and attach the "Satin Column cut point" command first.'))
+
+ split_point = command.target_point
+ command.use.getparent().remove(command.use)
+ command.connector.getparent().remove(command.connector)
+
+ new_satins = satin.split(split_point)
+ parent = satin.node.getparent()
+ index = parent.index(satin.node)
+ parent.remove(satin.node)
+ for new_satin in new_satins:
+ parent.insert(index, new_satin.node)
+ index += 1
diff --git a/lib/extensions/flip.py b/lib/extensions/flip.py
index 65dbdc1f..0864da85 100644
--- a/lib/extensions/flip.py
+++ b/lib/extensions/flip.py
@@ -1,6 +1,5 @@
import inkex
import cubicsuperpath
-from shapely import geometry as shgeo
from .base import InkstitchExtension
from ..i18n import _
@@ -8,21 +7,11 @@ 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]
+ first, second = satin.rail_indices
csp[first], csp[second] = csp[second], csp[first]
satin.node.set("d", cubicsuperpath.formatPath(csp))