summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/elements/satin_column.py83
-rw-r--r--lib/extensions/print_pdf.py8
-rw-r--r--lib/gui/simulator.py55
3 files changed, 98 insertions, 48 deletions
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py
index 4dea0534..bfa39384 100644
--- a/lib/elements/satin_column.py
+++ b/lib/elements/satin_column.py
@@ -590,7 +590,7 @@ class SatinColumn(EmbroideryElement):
return spacings, paths
- def plot_points_on_rails(self, spacing, offset):
+ def plot_points_on_rails(self, spacing, offset, compensation=True):
# Take a section from each rail in turn, and plot out an equal number
# of points on both rails. Return the points plotted. The points will
# be contracted or expanded by offset using self.offset_points().
@@ -625,43 +625,44 @@ class SatinColumn(EmbroideryElement):
pos0, index0 = self.walk(paths[0], pos0, index0, spacing0)
pos1, index1 = self.walk(paths[1], pos1, index1, spacing1)
- try:
- # Adjust for rails that contract or expand from each other.
- # Without any compensation, rail sections that spread out or come
- # together are longer than parallel rails, and we'll plot stitches
- # too densely as a result. We can compensate by using some trig,
- # as described here:
- #
- # https://github.com/inkstitch/inkstitch/issues/379#issuecomment-467262685
- stitch_direction = (pos1 - pos0).unit()
- peak_to_peak0 = pos0 - old_pos0
- peak_to_peak1 = pos1 - old_pos1
-
- # The dot product of two unit vectors is the cosine of the angle
- # between them. We want the cosine of the angle minus 90 degrees,
- # so we rotate left by 90 degrees first.
- #
- # We take the absolute value to correct for the different direction
- # of the angles on the opposing rails.
- cos1 = abs(peak_to_peak0.unit() * stitch_direction.rotate_left())
- cos2 = abs(peak_to_peak1.unit() * stitch_direction.rotate_left())
-
- # Use the smaller of the two angles to avoid spacing out
- # too far on the other rail. Note that the cosine of 0
- # is 1, so we use min here to mean a bigger angle.
- cos = min(cos1, cos2)
-
- # Beyond 0.55 (about 56 degrees), we end up distorting the
- # stitching and it looks bad.
- cos = max(cos, 0.55)
-
- pos0, index0 = self.walk(paths[0], pos0, index0, spacing0 / cos - spacing0)
- pos1, index1 = self.walk(paths[1], pos1, index1, spacing1 / cos - spacing1)
- except ZeroDivisionError:
- # These can occur in unit() if the vector has a length of zero,
- # which can happen in certain cases. We'll just skip the
- # compensation.
- continue
+ if compensation:
+ try:
+ # Adjust for rails that contract or expand from each other.
+ # Without any compensation, rail sections that spread out or come
+ # together are longer than parallel rails, and we'll plot stitches
+ # too densely as a result. We can compensate by using some trig,
+ # as described here:
+ #
+ # https://github.com/inkstitch/inkstitch/issues/379#issuecomment-467262685
+ stitch_direction = (pos1 - pos0).unit()
+ peak_to_peak0 = pos0 - old_pos0
+ peak_to_peak1 = pos1 - old_pos1
+
+ # The dot product of two unit vectors is the cosine of the angle
+ # between them. We want the cosine of the angle minus 90 degrees,
+ # so we rotate left by 90 degrees first.
+ #
+ # We take the absolute value to correct for the different direction
+ # of the angles on the opposing rails.
+ cos1 = abs(peak_to_peak0.unit() * stitch_direction.rotate_left())
+ cos2 = abs(peak_to_peak1.unit() * stitch_direction.rotate_left())
+
+ # Use the smaller of the two angles to avoid spacing out
+ # too far on the other rail. Note that the cosine of 0
+ # is 1, so we use min here to mean a bigger angle.
+ cos = min(cos1, cos2)
+
+ # Beyond 0.55 (about 56 degrees), we end up distorting the
+ # stitching and it looks bad.
+ cos = max(cos, 0.55)
+
+ pos0, index0 = self.walk(paths[0], pos0, index0, spacing0 / cos - spacing0)
+ pos1, index1 = self.walk(paths[1], pos1, index1, spacing1 / cos - spacing1)
+ except ZeroDivisionError:
+ # These can occur in unit() if the vector has a length of zero,
+ # which can happen in certain cases. We'll just skip the
+ # compensation.
+ continue
# We're off by one in the algorithm above, so we need one more
# pair of points. We'd like to add points at the very end to
@@ -678,7 +679,8 @@ class SatinColumn(EmbroideryElement):
# "contour walk" underlay: do stitches up one side and down the
# other.
forward, back = self.plot_points_on_rails(self.contour_underlay_stitch_length,
- -self.contour_underlay_inset)
+ -self.contour_underlay_inset,
+ compensation=False)
return Patch(color=self.color, stitches=(forward + list(reversed(back))))
def do_center_walk(self):
@@ -687,7 +689,8 @@ class SatinColumn(EmbroideryElement):
# Do it like contour underlay, but inset all the way to the center.
forward, back = self.plot_points_on_rails(self.center_walk_underlay_stitch_length,
- -100000)
+ -100000,
+ compensation=False)
return Patch(color=self.color, stitches=(forward + list(reversed(back))))
def do_zigzag_underlay(self):
diff --git a/lib/extensions/print_pdf.py b/lib/extensions/print_pdf.py
index c718fa09..4913a32a 100644
--- a/lib/extensions/print_pdf.py
+++ b/lib/extensions/print_pdf.py
@@ -353,7 +353,13 @@ class Print(InkstitchExtension):
template = env.get_template('index.html')
return template.render(
- view={'client_overview': False, 'client_detailedview': False, 'operator_overview': True, 'operator_detailedview': True},
+ view={
+ 'client_overview': False,
+ 'client_detailedview': False,
+ 'operator_overview': True,
+ 'operator_detailedview': True,
+ 'custom_page': False
+ },
logo={'src': '', 'title': 'LOGO'},
date=date.today(),
client="",
diff --git a/lib/gui/simulator.py b/lib/gui/simulator.py
index 6a2a08a9..25149149 100644
--- a/lib/gui/simulator.py
+++ b/lib/gui/simulator.py
@@ -68,14 +68,21 @@ class ControlPanel(wx.Panel):
self.restartBtn = wx.Button(self, -1, label=_('Restart'))
self.restartBtn.Bind(wx.EVT_BUTTON, self.animation_restart)
self.restartBtn.SetToolTip(_('Restart (R)'))
+ self.nppBtn = wx.ToggleButton(self, -1, label=_('O'))
+ self.nppBtn.Bind(wx.EVT_TOGGLEBUTTON, self.toggle_npp)
+ self.nppBtn.SetToolTip(_('Display needle penetration point (O)'))
self.quitBtn = wx.Button(self, -1, label=_('Quit'))
self.quitBtn.Bind(wx.EVT_BUTTON, self.animation_quit)
self.quitBtn.SetToolTip(_('Quit (Q)'))
self.slider = wx.Slider(self, -1, value=1, minValue=1, maxValue=2,
style=wx.SL_HORIZONTAL | wx.SL_LABELS)
self.slider.Bind(wx.EVT_SLIDER, self.on_slider)
- self.stitchBox = IntCtrl(self, -1, value=1, min=1, max=2, limited=True, allow_none=False)
- self.stitchBox.Bind(wx.EVT_TEXT, self.on_stitch_box)
+ self.stitchBox = IntCtrl(self, -1, value=1, min=1, max=2, limited=True, allow_none=True, style=wx.TE_PROCESS_ENTER)
+ self.stitchBox.Bind(wx.EVT_LEFT_DOWN, self.on_stitch_box_focus)
+ self.stitchBox.Bind(wx.EVT_SET_FOCUS, self.on_stitch_box_focus)
+ self.stitchBox.Bind(wx.EVT_TEXT_ENTER, self.on_stitch_box_focusout)
+ self.stitchBox.Bind(wx.EVT_KILL_FOCUS, self.on_stitch_box_focusout)
+ self.Bind(wx.EVT_LEFT_DOWN, self.on_stitch_box_focusout)
# Layout
self.vbSizer = vbSizer = wx.BoxSizer(wx.VERTICAL)
@@ -91,6 +98,7 @@ class ControlPanel(wx.Panel):
hbSizer2.Add(self.directionBtn, 0, wx.EXPAND | wx.ALL, 2)
hbSizer2.Add(self.pauseBtn, 0, wx.EXPAND | wx.ALL, 2)
hbSizer2.Add(self.restartBtn, 0, wx.EXPAND | wx.ALL, 2)
+ hbSizer2.Add(self.nppBtn, 0, wx.EXPAND | wx.ALL, 2)
hbSizer2.Add(self.quitBtn, 0, wx.EXPAND | wx.ALL, 2)
vbSizer.Add(hbSizer2, 0, wx.EXPAND | wx.ALL, 3)
self.SetSizerAndFit(vbSizer)
@@ -116,19 +124,20 @@ class ControlPanel(wx.Panel):
(wx.ACCEL_NORMAL, wx.WXK_SUBTRACT, self.animation_one_stitch_backward),
(wx.ACCEL_NORMAL, wx.WXK_NUMPAD_SUBTRACT, self.animation_one_stitch_backward),
(wx.ACCEL_NORMAL, ord('r'), self.animation_restart),
+ (wx.ACCEL_NORMAL, ord('o'), self.on_toggle_npp_shortcut),
(wx.ACCEL_NORMAL, ord('p'), self.on_pause_start_button),
(wx.ACCEL_NORMAL, wx.WXK_SPACE, self.on_pause_start_button),
(wx.ACCEL_NORMAL, ord('q'), self.animation_quit)]
- accel_entries = []
+ self.accel_entries = []
for shortcut_key in shortcut_keys:
eventId = wx.NewId()
- accel_entries.append((shortcut_key[0], shortcut_key[1], eventId))
+ self.accel_entries.append((shortcut_key[0], shortcut_key[1], eventId))
self.Bind(wx.EVT_MENU, shortcut_key[2], id=eventId)
- accel_table = wx.AcceleratorTable(accel_entries)
- self.SetAcceleratorTable(accel_table)
+ self.accel_table = wx.AcceleratorTable(self.accel_entries)
+ self.SetAcceleratorTable(self.accel_table)
self.SetFocus()
def set_drawing_panel(self, drawing_panel):
@@ -186,6 +195,8 @@ class ControlPanel(wx.Panel):
if self.drawing_panel:
self.drawing_panel.set_current_stitch(stitch)
+ self.parent.SetFocus()
+
def on_current_stitch(self, stitch, command):
if self.current_stitch != stitch:
self.current_stitch = stitch
@@ -193,8 +204,20 @@ class ControlPanel(wx.Panel):
self.stitchBox.SetValue(stitch)
self.statusbar.SetStatusText(COMMAND_NAMES[command], 1)
- def on_stitch_box(self, event):
+ def on_stitch_box_focus(self, event):
+ self.animation_pause()
+ self.SetAcceleratorTable(wx.AcceleratorTable([]))
+ event.Skip()
+
+ def on_stitch_box_focusout(self, event):
+ self.SetAcceleratorTable(self.accel_table)
stitch = self.stitchBox.GetValue()
+ self.parent.SetFocus()
+
+ if stitch is None:
+ stitch = 1
+ self.stitchBox.SetValue(1)
+
self.slider.SetValue(stitch)
if self.drawing_panel:
@@ -241,6 +264,15 @@ class ControlPanel(wx.Panel):
def animation_restart(self, event):
self.drawing_panel.restart()
+ def on_toggle_npp_shortcut(self, event):
+ self.nppBtn.SetValue(not self.nppBtn.GetValue())
+ self.toggle_npp(event)
+
+ def toggle_npp(self, event):
+ if self.pauseBtn.GetLabel() == _('Start'):
+ stitch = self.stitchBox.GetValue()
+ self.drawing_panel.set_current_stitch(stitch)
+
class DrawingPanel(wx.Panel):
""""""
@@ -346,11 +378,13 @@ class DrawingPanel(wx.Panel):
stitch += len(stitches)
if len(stitches) > 1:
canvas.DrawLines(stitches)
+ self.draw_needle_penetration_points(canvas, pen, stitches)
last_stitch = stitches[-1]
else:
stitches = stitches[:self.current_stitch - stitch]
if len(stitches) > 1:
canvas.DrawLines(stitches)
+ self.draw_needle_penetration_points(canvas, pen, stitches)
last_stitch = stitches[-1]
break
self.last_frame_duration = time.time() - start
@@ -365,6 +399,12 @@ class DrawingPanel(wx.Panel):
canvas.DrawLines(((x - crosshair_radius, y), (x + crosshair_radius, y)))
canvas.DrawLines(((x, y - crosshair_radius), (x, y + crosshair_radius)))
+ def draw_needle_penetration_points(self, canvas, pen, stitches):
+ if self.control_panel.nppBtn.GetValue():
+ npp_pen = wx.Pen(pen.GetColour(), width=int(0.3 * PIXELS_PER_MM * self.PIXEL_DENSITY))
+ canvas.SetPen(npp_pen)
+ canvas.StrokeLineSegments(stitches, stitches)
+
def clear(self):
dc = wx.ClientDC(self)
dc.Clear()
@@ -629,6 +669,7 @@ class EmbroiderySimulator(wx.Frame):
if self.on_close_hook:
self.on_close_hook()
+ self.SetFocus()
self.Destroy()
def go(self):