diff options
| author | Kaalleen <36401965+kaalleen@users.noreply.github.com> | 2025-04-18 07:19:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-18 07:19:52 +0200 |
| commit | 37f3c57b9522f779a36e9e9a8d1f93db8f43e6fd (patch) | |
| tree | 82831e341d7babf533c434ce0e7b19b5ac6ff341 /lib | |
| parent | 6c67f67c0510f63e5f8ebd8e4bc8ec520eb335c3 (diff) | |
Multicolor satin (windows): apply settings in spinctrldouble when they hit enter (#3677)
* multicolor satin (windows): apply settings in spinctrldouble when they hit enter
* enable nearest points for multicolor satin
---------
Co-authored-by: CapellanCitizen
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/elements/satin_column.py | 19 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/color_panel.py | 6 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/colorize_panel.py | 26 | ||||
| -rw-r--r-- | lib/gui/satin_multicolor/main_panel.py | 23 |
4 files changed, 51 insertions, 23 deletions
diff --git a/lib/elements/satin_column.py b/lib/elements/satin_column.py index 05ba43ce..16e7b01f 100644 --- a/lib/elements/satin_column.py +++ b/lib/elements/satin_column.py @@ -602,6 +602,19 @@ class SatinColumn(EmbroideryElement): @property @cache + def compensated_shape(self): + pairs = self.plot_points_on_rails( + self.zigzag_spacing, + self.pull_compensation_px, + self.pull_compensation_percent/100, + True, + ) + rail1 = [point[0] for point in pairs] + rail2 = [point[1] for point in pairs] + return shgeo.MultiLineString((rail1, rail2)) + + @property + @cache def csp(self): paths = self.parse_path() # exclude subpaths which are just a point @@ -1820,17 +1833,17 @@ class SatinColumn(EmbroideryElement): def start_point(self, last_stitch_group): start_point = self._get_command_point('starting_point') if start_point is None and self.start_at_nearest_point and last_stitch_group is not None: - start_point = nearest_points(shgeo.Point(*last_stitch_group.stitches[-1]), self.center_line)[1] + start_point = nearest_points(shgeo.Point(*last_stitch_group.stitches[-1]), self.offset_center_line)[1] start_point = Point(*list(start_point.coords[0])) return start_point def end_point(self, next_stitch): end_point = self._get_command_point('ending_point') if end_point is None and self.end_at_nearest_point and next_stitch is not None: - end_point = nearest_points(next_stitch, self.shape)[1] + end_point = nearest_points(next_stitch, self.compensated_shape)[1] end_point = Point(*list(end_point.coords[0])) # if we are already near to the end, we won't need to specify an ending point - if end_point and shgeo.Point(self.center_line.coords[-1]).distance(shgeo.Point(end_point)) < 5: + if end_point and shgeo.Point(self.offset_center_line.coords[-1]).distance(shgeo.Point(end_point)) < 5: end_point = None return end_point diff --git a/lib/gui/satin_multicolor/color_panel.py b/lib/gui/satin_multicolor/color_panel.py index e4961064..66641ad7 100644 --- a/lib/gui/satin_multicolor/color_panel.py +++ b/lib/gui/satin_multicolor/color_panel.py @@ -23,15 +23,17 @@ class ColorPanel(wx.Panel): self.colorpicker.SetToolTip(_("Select color")) self.colorpicker.Bind(wx.EVT_COLOURPICKER_CHANGED, self.panel._update) - self.color_width = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, style=wx.SP_WRAP) + self.color_width = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.color_width.SetDigits(2) self.color_width.SetToolTip(_("Monochrome width. Can be changed individually when equidistance is disabled.")) self.color_width.Bind(wx.EVT_SPINCTRLDOUBLE, self.panel._update) + self.color_width.Bind(wx.EVT_TEXT_ENTER, self.panel._update) - self.color_margin_right = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, style=wx.SP_WRAP) + self.color_margin_right = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.color_margin_right.SetDigits(2) self.color_margin_right.SetToolTip(_("Margin right (bicolor section). Can be changed individually when equidistance is disabled.")) self.color_margin_right.Bind(wx.EVT_SPINCTRLDOUBLE, self.panel._update) + self.color_margin_right.Bind(wx.EVT_TEXT_ENTER, self.panel._update) self.remove_button = wx.Button(self, label='X') self.remove_button.SetToolTip(_("Remove color")) diff --git a/lib/gui/satin_multicolor/colorize_panel.py b/lib/gui/satin_multicolor/colorize_panel.py index d521bf2f..044defd5 100644 --- a/lib/gui/satin_multicolor/colorize_panel.py +++ b/lib/gui/satin_multicolor/colorize_panel.py @@ -35,24 +35,28 @@ class ColorizePanel(ScrolledPanel): self.monochrome_width_label = wx.StaticText(self, label=_("Monochrome color width")) self.monochrome_width_label.SetToolTip(_("Adapt color width here when equidistance is enabled.")) - self.monochrome_width = wx.SpinCtrlDouble(self, min=0, max=100, initial=100, inc=1, style=wx.SP_WRAP) + self.monochrome_width = wx.SpinCtrlDouble(self, min=0, max=100, initial=100, inc=1, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.monochrome_width.SetDigits(2) self.monochrome_width.Bind(wx.EVT_SPINCTRLDOUBLE, self._on_update_monochrome_width) + self.monochrome_width.Bind(wx.EVT_TEXT_ENTER, self._on_update_monochrome_width) overflow_left_label = wx.StaticText(self, label=_("Overflow left")) - self.overflow_left = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP) + self.overflow_left = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.overflow_left.SetDigits(2) self.overflow_left.Bind(wx.EVT_SPINCTRLDOUBLE, self._update) + self.overflow_left.Bind(wx.EVT_TEXT_ENTER, self._update) overflow_right_label = wx.StaticText(self, label=_("Overflow right")) - self.overflow_right = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP) + self.overflow_right = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.overflow_right.SetDigits(2) self.overflow_right.Bind(wx.EVT_SPINCTRLDOUBLE, self._update) + self.overflow_right.Bind(wx.EVT_TEXT_ENTER, self._update) pull_compensation_label = wx.StaticText(self, label=_("Pull compensation (mm)")) - self.pull_compensation = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP) + self.pull_compensation = wx.SpinCtrlDouble(self, min=0, max=100, initial=0, inc=0.1, style=wx.SP_WRAP | wx.TE_PROCESS_ENTER) self.pull_compensation.SetDigits(2) self.pull_compensation.Bind(wx.EVT_SPINCTRLDOUBLE, self._update) + self.pull_compensation.Bind(wx.EVT_TEXT_ENTER, self._update) seed_label = wx.StaticText(self, label=_("Random seed")) self.seed = wx.TextCtrl(self) @@ -116,11 +120,8 @@ class ColorizePanel(ScrolledPanel): equidistance = self.equististance.GetValue() if not equidistance: return - width = self.monochrome_width.GetValue() - num_colors = len(self.color_sizer.GetChildren()) - margin = (100 - width * num_colors) / max(num_colors - 1, 1) - self._set_widget_width_value(width, margin) - self._update() + self._update(event) + self._update_colors() def _add_color_event(self, event): self.add_color() @@ -223,6 +224,13 @@ class ColorizePanel(ScrolledPanel): return round(width, 2) def _update(self, event=None): + # Hack primarily for Windows: Make sure that the values of spin controls are updated + if event is not None and event.EventType == wx.EVT_TEXT_ENTER.typeId: + try: + event.EventObject.SetValue(event.String) + except Exception: + return + width = self.get_total_width() self.total_width.SetLabel(_("Total width: {width}%").format(width=width)) if width > 100: diff --git a/lib/gui/satin_multicolor/main_panel.py b/lib/gui/satin_multicolor/main_panel.py index f3f118bc..8c4bbaf9 100644 --- a/lib/gui/satin_multicolor/main_panel.py +++ b/lib/gui/satin_multicolor/main_panel.py @@ -9,7 +9,7 @@ import inkex import wx import wx.adv -from ...elements import SatinColumn +from ...elements.utils import nodes_to_elements from ...exceptions import InkstitchException, format_uncaught_exception from ...i18n import _ from ...stitch_plan import stitch_groups_to_stitch_plan @@ -107,12 +107,20 @@ class MultiColorSatinPanel(wx.Panel): return stitch_plan def _get_stitch_groups(self): + elements = nodes_to_elements(self.satin_elements) + stitch_groups = [] - for element in self.satin_elements: + last_stitch_group = None + next_elements = [None] + if len(elements) > 1: + next_elements = elements[1:] + next_elements + for element, next_element in zip(elements, next_elements): try: - # copy the embroidery element to drop the cache - stitch_group = copy(SatinColumn(element)).embroider(None) + stitch_group = element.embroider(last_stitch_group, next_element) stitch_groups.extend(stitch_group) + + if stitch_groups: + last_stitch_group = stitch_groups[-1] except (SystemExit, ExitThread): raise except InkstitchException as exc: @@ -166,11 +174,13 @@ class MultiColorSatinPanel(wx.Panel): new_satin.set('inkstitch:random_width_increase_percent', f'{ margin } 0') new_satin.set('inkstitch:random_width_decrease_percent', f'0 { -previous_margin }') new_satin.set('inkstitch:pull_compensation_percent', f'{ current_position + width - 100} { -current_position }') + new_satin.set('inkstitch:running_stitch_position', f'{100 - current_position - width / 2}') else: new_satin.set('inkstitch:swap_satin_rails', True) new_satin.set('inkstitch:random_width_increase_percent', f'0 { margin }') new_satin.set('inkstitch:random_width_decrease_percent', f'{ -previous_margin } 0') new_satin.set('inkstitch:pull_compensation_percent', f'{ -current_position } { current_position + width - 100}') + new_satin.set('inkstitch:running_stitch_position', f'{current_position + width / 2}') # underlay if self.colorize_panel.adjust_underlay_per_color.GetValue(): @@ -187,11 +197,6 @@ class MultiColorSatinPanel(wx.Panel): new_satin.set('inkstitch:contour_underlay', False) new_satin.set('inkstitch:zigzag_underlay', False) - # TODO: adapt start and end position, as well as running_stitch_position - # For now, turn start and end points off as they may produce bad looking output - new_satin.set('inkstitch:start_at_nearest_point', False) - new_satin.set('inkstitch:end_at_nearest_point', False) - previous_margin = margin current_position += width + margin |
