summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/extensions/simulate.py20
-rw-r--r--lib/simulator.py28
-rw-r--r--lib/stitch_plan/__init__.py3
-rw-r--r--lib/stitch_plan/read_file.py21
-rw-r--r--messages.po30
5 files changed, 66 insertions, 36 deletions
diff --git a/lib/extensions/simulate.py b/lib/extensions/simulate.py
index dcb5e604..e23d391b 100644
--- a/lib/extensions/simulate.py
+++ b/lib/extensions/simulate.py
@@ -1,8 +1,6 @@
-import wx
-
from .base import InkstitchExtension
from ..i18n import _
-from ..simulator import EmbroiderySimulator
+from ..simulator import show_simulator
from ..stitch_plan import patches_to_stitch_plan
@@ -19,18 +17,4 @@ class Simulate(InkstitchExtension):
return
patches = self.elements_to_patches(self.elements)
stitch_plan = patches_to_stitch_plan(patches)
- app = wx.App()
- current_screen = wx.Display.GetFromPoint(wx.GetMousePosition())
- display = wx.Display(current_screen)
- screen_rect = display.GetClientArea()
-
- simulator_pos = (screen_rect[0], screen_rect[1])
-
- # subtract 1 because otherwise the window becomes maximized on Linux
- width = screen_rect[2] - 1
- height = screen_rect[3] - 1
-
- frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan)
- app.SetTopWindow(frame)
- frame.Show()
- app.MainLoop()
+ show_simulator(stitch_plan)
diff --git a/lib/simulator.py b/lib/simulator.py
index c797d221..8f316be3 100644
--- a/lib/simulator.py
+++ b/lib/simulator.py
@@ -4,8 +4,9 @@ from wx.lib.intctrl import IntCtrl
import time
from itertools import izip
-from .svg import color_block_to_point_lists, PIXELS_PER_MM
+from .svg import PIXELS_PER_MM
from .i18n import _
+from .stitch_plan import stitch_plan_from_file
# L10N command label at bottom of simulator window
COMMAND_NAMES = [_("STITCH"), _("JUMP"), _("TRIM"), _("STOP"), _("COLOR CHANGE")]
@@ -330,7 +331,8 @@ class DrawingPanel(wx.Panel):
canvas.SetPen(pen)
if stitch + len(stitches) < self.current_stitch:
stitch += len(stitches)
- canvas.DrawLines(stitches)
+ if len(stitches) > 1:
+ canvas.DrawLines(stitches)
last_stitch = stitches[-1]
else:
stitches = stitches[:self.current_stitch - stitch]
@@ -615,3 +617,25 @@ class EmbroiderySimulator(wx.Frame):
def clear(self):
self.simulator_panel.clear()
+
+def show_simulator(stitch_plan):
+ app = wx.App()
+ current_screen = wx.Display.GetFromPoint(wx.GetMousePosition())
+ display = wx.Display(current_screen)
+ screen_rect = display.GetClientArea()
+
+ simulator_pos = (screen_rect[0], screen_rect[1])
+
+ # subtract 1 because otherwise the window becomes maximized on Linux
+ width = screen_rect[2] - 1
+ height = screen_rect[3] - 1
+
+ frame = EmbroiderySimulator(None, -1, _("Embroidery Simulation"), pos=simulator_pos, size=(width, height), stitch_plan=stitch_plan)
+ app.SetTopWindow(frame)
+ frame.Show()
+ app.MainLoop()
+
+
+if __name__ == "__main__":
+ stitch_plan = stitch_plan_from_file(sys.argv[1])
+ show_simulator(stitch_plan)
diff --git a/lib/stitch_plan/__init__.py b/lib/stitch_plan/__init__.py
index 791a5f20..2aaa0ab9 100644
--- a/lib/stitch_plan/__init__.py
+++ b/lib/stitch_plan/__init__.py
@@ -1,2 +1,3 @@
-from stitch_plan import patches_to_stitch_plan, StitchPlan, ColorBlock
+from .stitch_plan import patches_to_stitch_plan, StitchPlan, ColorBlock
from .stitch import Stitch
+from .read_file import stitch_plan_from_file
diff --git a/lib/stitch_plan/read_file.py b/lib/stitch_plan/read_file.py
new file mode 100644
index 00000000..ff5a68ac
--- /dev/null
+++ b/lib/stitch_plan/read_file.py
@@ -0,0 +1,21 @@
+import pyembroidery
+from .stitch_plan import StitchPlan
+
+from ..svg import PIXELS_PER_MM
+
+
+def stitch_plan_from_file(embroidery_file):
+ """Read a machine embroidery file in any supported format and return a stitch plan."""
+ pattern = pyembroidery.read(embroidery_file)
+
+ stitch_plan = StitchPlan()
+ color_block = None
+
+ for raw_stitches, thread in pattern.get_as_colorblocks():
+ color_block = stitch_plan.new_color_block(thread)
+ for x, y, command in raw_stitches:
+ color_block.add_stitch(x * PIXELS_PER_MM / 10.0, y * PIXELS_PER_MM / 10.0,
+ jump=(command == pyembroidery.JUMP),
+ trim=(command == pyembroidery.TRIM))
+
+ return stitch_plan
diff --git a/messages.po b/messages.po
index f58a88ec..fb2d593f 100644
--- a/messages.po
+++ b/messages.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
-"POT-Creation-Date: 2018-08-27 21:56-0400\n"
+"POT-Creation-Date: 2018-09-01 13:35-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -659,10 +659,6 @@ msgstr ""
msgid "Ink/Stitch Print"
msgstr ""
-#: lib/extensions/simulate.py:33
-msgid "Embroidery Simulation"
-msgstr ""
-
#: lib/extensions/zip.py:49
msgid "No embroidery file formats selected."
msgstr ""
@@ -675,47 +671,51 @@ msgid "Generate INX files"
msgstr ""
#. command label at bottom of simulator window
-#: lib/simulator.py:11
+#: lib/simulator.py:12
msgid "STITCH"
msgstr ""
-#: lib/simulator.py:11
+#: lib/simulator.py:12
msgid "JUMP"
msgstr ""
-#: lib/simulator.py:11
+#: lib/simulator.py:12
msgid "TRIM"
msgstr ""
-#: lib/simulator.py:11
+#: lib/simulator.py:12
msgid "STOP"
msgstr ""
-#: lib/simulator.py:11
+#: lib/simulator.py:12
msgid "COLOR CHANGE"
msgstr ""
-#: lib/simulator.py:48 lib/simulator.py:207 lib/simulator.py:214
+#: lib/simulator.py:49 lib/simulator.py:208 lib/simulator.py:215
msgid "Pause"
msgstr ""
-#: lib/simulator.py:50
+#: lib/simulator.py:51
msgid "Restart"
msgstr ""
-#: lib/simulator.py:52
+#: lib/simulator.py:53
msgid "Quit"
msgstr ""
-#: lib/simulator.py:167
+#: lib/simulator.py:168
#, python-format
msgid "Speed: %d stitches/sec"
msgstr ""
-#: lib/simulator.py:210
+#: lib/simulator.py:211
msgid "Start"
msgstr ""
+#: lib/simulator.py:633
+msgid "Embroidery Simulation"
+msgstr ""
+
#: lib/stitches/auto_fill.py:167
msgid ""
"Unable to autofill. This most often happens because your shape is made "