summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/output.py8
-rw-r--r--lib/simulator.py77
-rw-r--r--lib/stitch_plan/stitch_plan.py6
-rw-r--r--messages.po61
4 files changed, 110 insertions, 42 deletions
diff --git a/lib/output.py b/lib/output.py
index d5c513e2..147d084e 100644
--- a/lib/output.py
+++ b/lib/output.py
@@ -84,4 +84,12 @@ def write_embroidery_file(file_path, stitch_plan, svg):
"full_jump": True,
}
+ if file_path.endswith('.csv'):
+ # Special treatment for CSV: instruct pyembroidery not to do any post-
+ # processing. This will allow the user to match up stitch numbers seen
+ # in the simulator with commands in the CSV.
+ settings['max_stitch'] = float('inf')
+ settings['max_jump'] = float('inf')
+ settings['explicit_trim'] = False
+
pyembroidery.write(pattern, file_path, settings)
diff --git a/lib/simulator.py b/lib/simulator.py
index 598d201b..18bf1d7e 100644
--- a/lib/simulator.py
+++ b/lib/simulator.py
@@ -7,6 +7,16 @@ from itertools import izip
from .svg import color_block_to_point_lists, PIXELS_PER_MM
from .i18n import _
+# L10N command label at bottom of simulator window
+COMMAND_NAMES = [_("STITCH"), _("JUMP"), _("TRIM"), _("STOP"), _("COLOR CHANGE")]
+
+STITCH = 0
+JUMP = 1
+TRIM = 2
+STOP = 3
+COLOR_CHANGE = 4
+
+
class ControlPanel(wx.Panel):
""""""
def __init__(self, parent, *args, **kwargs):
@@ -20,7 +30,7 @@ class ControlPanel(wx.Panel):
self.drawing_panel = None
self.num_stitches = 1
- self.current_stitch = 0
+ self.current_stitch = 1
self.speed = 1
# Widgets
@@ -36,12 +46,13 @@ class ControlPanel(wx.Panel):
self.restartBtn.Bind(wx.EVT_BUTTON, self.animation_restart)
self.quitBtn = wx.Button(self, -1, label='Quit')
self.quitBtn.Bind(wx.EVT_BUTTON, self.animation_quit)
- self.slider = wx.Slider(self, -1, value=0, minValue=0, maxValue=self.num_stitches,
+ self.slider = wx.Slider(self, -1, value=1, minValue=1, maxValue=self.num_stitches,
style=wx.SL_HORIZONTAL | wx.SL_LABELS)
self.slider.Bind(wx.EVT_SLIDER, self.on_slider)
- self.stitchBox = IntCtrl(self, -1, value=1, min=0, max=self.num_stitches, limited=True, allow_none=False)
+ self.stitchBox = IntCtrl(self, -1, value=1, min=1, max=self.num_stitches, limited=True, allow_none=False)
self.stitchBox.Bind(wx.EVT_TEXT, self.on_stitch_box)
self.speedST = wx.StaticText(self, -1, label='', style=wx.ALIGN_CENTER)
+ self.commandST = wx.StaticText(self, -1, label='', style=wx.ALIGN_CENTER)
# Layout
self.vbSizer = vbSizer = wx.BoxSizer(wx.VERTICAL)
@@ -52,6 +63,8 @@ class ControlPanel(wx.Panel):
vbSizer.Add(hbSizer1, 1, wx.EXPAND | wx.ALL, 3)
hbSizer2.Add(self.speedST, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
hbSizer2.AddStretchSpacer(prop=1)
+ hbSizer2.Add(self.commandST, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2)
+ hbSizer2.AddStretchSpacer(prop=1)
hbSizer2.Add(self.btnMinus, 0, wx.ALL, 2)
hbSizer2.Add(self.btnPlus, 0, wx.ALL, 2)
hbSizer2.Add(self.direction, 0, wx.EXPAND | wx.ALL, 2)
@@ -144,11 +157,12 @@ class ControlPanel(wx.Panel):
if self.drawing_panel:
self.drawing_panel.set_current_stitch(stitch)
- def on_current_stitch(self, stitch):
+ def on_current_stitch(self, stitch, command):
if self.current_stitch != stitch:
self.current_stitch = stitch
self.slider.SetValue(stitch)
self.stitchBox.SetValue(stitch)
+ self.commandST.SetLabel(COMMAND_NAMES[command])
def set_stitch_label(self, stitch):
self.st1.SetLabel("Stitch # %d/%d" % (stitch, self.num_stitches))
@@ -246,19 +260,19 @@ class DrawingPanel(wx.Panel):
wx.CallLater(50, self.load, self.stitch_plan)
def clamp_current_stitch(self):
- if self.current_stitch < 0:
- self.current_stitch = 0
+ if self.current_stitch < 1:
+ self.current_stitch = 1
elif self.current_stitch > self.num_stitches:
self.current_stitch = self.num_stitches
def stop_if_at_end(self):
- if self.direction == -1 and self.current_stitch == 0:
+ if self.direction == -1 and self.current_stitch == 1:
self.stop()
elif self.direction == 1 and self.current_stitch == self.num_stitches:
self.stop()
def start_if_not_at_end(self):
- if self.direction == -1 and self.current_stitch > 0:
+ if self.direction == -1 and self.current_stitch > 1:
self.go()
elif self.direction == 1 and self.current_stitch < self.num_stitches:
self.go()
@@ -307,7 +321,7 @@ class DrawingPanel(wx.Panel):
stitches = stitches[:self.current_stitch - stitch]
if len(stitches) > 1:
canvas.DrawLines(stitches)
- last_stitch = stitches[-1]
+ last_stitch = stitches[-1]
break
self.last_frame_duration = time.time() - start
@@ -326,8 +340,9 @@ class DrawingPanel(wx.Panel):
dc.Clear()
def load(self, stitch_plan):
- self.last_frame_duration = 0
+ self.current_stitch = 1
self.direction = 1
+ self.last_frame_duration = 0
self.num_stitches = stitch_plan.num_stitches
self.control_panel.set_num_stitches(self.num_stitches)
self.minx, self.miny, self.maxx, self.maxy = stitch_plan.bounding_box
@@ -378,20 +393,38 @@ class DrawingPanel(wx.Panel):
self.pens = []
self.stitch_blocks = []
+ # There is no 0th stitch, so add a place-holder.
+ self.commands = [None]
+
for color_block in stitch_plan:
pen = self.color_to_pen(color_block.color)
+ stitch_block = []
+
+ for stitch in color_block:
+ # trim any whitespace on the left and top and scale to the
+ # pixel density
+ stitch_block.append((self.PIXEL_DENSITY * (stitch.x - self.minx),
+ self.PIXEL_DENSITY * (stitch.y - self.miny)))
+
+ if stitch.trim:
+ self.commands.append(TRIM)
+ elif stitch.jump:
+ self.commands.append(JUMP)
+ elif stitch.stop:
+ self.commands.append(STOP)
+ elif stitch.color_change:
+ self.commands.append(COLOR_CHANGE)
+ else:
+ self.commands.append(STITCH)
+
+ if stitch.trim or stitch.stop or stitch.color_change:
+ self.pens.append(pen)
+ self.stitch_blocks.append(stitch_block)
+ stitch_block = []
- for point_list in color_block_to_point_lists(color_block):
+ if stitch_block:
self.pens.append(pen)
-
- points = []
- for x, y in point_list:
- # trim any whitespace on the left and top and scale to the
- # pixel density
- points.append((self.PIXEL_DENSITY * (x - self.minx),
- self.PIXEL_DENSITY * (y - self.miny)))
-
- self.stitch_blocks.append(points)
+ self.stitch_blocks.append(stitch_block)
def set_speed(self, speed):
self.speed = speed
@@ -407,13 +440,13 @@ class DrawingPanel(wx.Panel):
def set_current_stitch(self, stitch):
self.current_stitch = stitch
self.clamp_current_stitch()
- self.control_panel.on_current_stitch(self.current_stitch)
+ self.control_panel.on_current_stitch(self.current_stitch, self.commands[self.current_stitch])
self.stop_if_at_end()
self.Refresh()
def restart(self):
if self.direction == 1:
- self.current_stitch = 0
+ self.current_stitch = 1
elif self.direction == -1:
self.current_stitch = self.num_stitches
diff --git a/lib/stitch_plan/stitch_plan.py b/lib/stitch_plan/stitch_plan.py
index c713b42e..808fa626 100644
--- a/lib/stitch_plan/stitch_plan.py
+++ b/lib/stitch_plan/stitch_plan.py
@@ -36,6 +36,12 @@ def patches_to_stitch_plan(patches, collapse_len=3.0 * PIXELS_PER_MM):
# make a new block of our color
color_block = stitch_plan.new_color_block(color=patch.color)
+ # always start a color with a JUMP to the first stitch position
+ color_block.add_stitch(patch.stitches[0], jump=True)
+ else:
+ if len(color_block) and (patch.stitches[0] - color_block.stitches[-1]).length() > collapse_len:
+ color_block.add_stitch(patch.stitches[0], jump=True)
+
color_block.add_stitches(patch.stitches, no_ties=patch.stitch_as_is)
if patch.trim_after:
diff --git a/messages.po b/messages.po
index 5aa9ed59..19b09b05 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-26 23:50-0400\n"
+"POT-Creation-Date: 2018-08-27 15:36-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"
@@ -674,79 +674,100 @@ msgstr ""
msgid "Generate INX files"
msgstr ""
-#: lib/simulator.py:611
+#. command label at bottom of simulator window
+#: lib/simulator.py:11
+msgid "STITCH"
+msgstr ""
+
+#: lib/simulator.py:11
+msgid "JUMP"
+msgstr ""
+
+#: lib/simulator.py:11
+msgid "TRIM"
+msgstr ""
+
+#: lib/simulator.py:11
+msgid "STOP"
+msgstr ""
+
+#: lib/simulator.py:11
+msgid "COLOR CHANGE"
+msgstr ""
+
+#: lib/simulator.py:644
msgid "<<"
msgstr ""
-#: lib/simulator.py:611
+#: lib/simulator.py:644
msgid "Play reverse (arrow left)"
msgstr ""
-#: lib/simulator.py:612
+#: lib/simulator.py:645
msgid "-"
msgstr ""
-#: lib/simulator.py:612
+#: lib/simulator.py:645
msgid "Play one frame backward (+)"
msgstr ""
-#: lib/simulator.py:613
+#: lib/simulator.py:646
msgid "+"
msgstr ""
-#: lib/simulator.py:613
+#: lib/simulator.py:646
msgid "Play one frame forward (+)"
msgstr ""
-#: lib/simulator.py:614
+#: lib/simulator.py:647
msgid ">>"
msgstr ""
-#: lib/simulator.py:614
+#: lib/simulator.py:647
msgid "Play forward (arrow right)"
msgstr ""
-#: lib/simulator.py:615
+#: lib/simulator.py:648
msgid "^"
msgstr ""
-#: lib/simulator.py:615
+#: lib/simulator.py:648
msgid "Speed up (arrow up)"
msgstr ""
-#: lib/simulator.py:616
+#: lib/simulator.py:649
msgid "v"
msgstr ""
-#: lib/simulator.py:616
+#: lib/simulator.py:649
msgid "Slow down (arrow down)"
msgstr ""
-#: lib/simulator.py:617
+#: lib/simulator.py:650
msgid "Pause"
msgstr ""
-#: lib/simulator.py:617
+#: lib/simulator.py:650
msgid "Pause (P)"
msgstr ""
-#: lib/simulator.py:618
+#: lib/simulator.py:651
msgid "Restart"
msgstr ""
-#: lib/simulator.py:618
+#: lib/simulator.py:651
msgid "Restart (R)"
msgstr ""
-#: lib/simulator.py:619
+#: lib/simulator.py:652
msgid "Quit"
msgstr ""
-#: lib/simulator.py:619
+#: lib/simulator.py:652
msgid "Close (Q)"
msgstr ""
-#: lib/simulator.py:797
+#: lib/simulator.py:830
msgid "Stitch # "
msgstr ""