summaryrefslogtreecommitdiff
path: root/lib/extensions/stitch_plan_preview.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2020-03-22 09:16:28 +0100
committerGitHub <noreply@github.com>2020-03-22 09:16:28 +0100
commit88ba830a991ae68ee1a11c989961da78fbb3ef5c (patch)
treeedbfff0d0282edf14a581cd64978c111ebb3b3ed /lib/extensions/stitch_plan_preview.py
parent660c3f2cfab8112b8b5999e7896e838f1eed9106 (diff)
add stitch plan extension (#640)
Diffstat (limited to 'lib/extensions/stitch_plan_preview.py')
-rw-r--r--lib/extensions/stitch_plan_preview.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/extensions/stitch_plan_preview.py b/lib/extensions/stitch_plan_preview.py
new file mode 100644
index 00000000..b89e24a7
--- /dev/null
+++ b/lib/extensions/stitch_plan_preview.py
@@ -0,0 +1,24 @@
+from ..stitch_plan import patches_to_stitch_plan
+from ..svg import render_stitch_plan
+from .base import InkstitchExtension
+
+
+class StitchPlanPreview(InkstitchExtension):
+
+ def effect(self):
+ # delete old stitch plan
+ svg = self.document.getroot()
+ layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
+ if layer is not None:
+ del layer[:]
+
+ # create new stitch plan
+ if not self.get_elements():
+ return
+ patches = self.elements_to_patches(self.elements)
+ stitch_plan = patches_to_stitch_plan(patches)
+ render_stitch_plan(svg, stitch_plan)
+
+ # translate stitch plan to the right side of the canvas
+ layer = svg.find(".//*[@id='__inkstitch_stitch_plan__']")
+ layer.set('transform', 'translate(%s)' % svg.get('viewBox', '0 0 800 0').split(' ')[2])