summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/gui/tartan/customize_panel.py10
-rw-r--r--lib/tartan/palette.py47
-rw-r--r--lib/tartan/utils.py33
3 files changed, 64 insertions, 26 deletions
diff --git a/lib/gui/tartan/customize_panel.py b/lib/gui/tartan/customize_panel.py
index 16d73416..a966bad1 100644
--- a/lib/gui/tartan/customize_panel.py
+++ b/lib/gui/tartan/customize_panel.py
@@ -121,9 +121,9 @@ class CustomizePanel(ScrolledPanel):
position.Bind(wx.EVT_LEFT_DOWN, self._move_stripe_start)
position.Bind(wx.EVT_LEFT_UP, self._move_stripe_end)
- visibility = wx.CheckBox(self)
- visibility.SetToolTip(_("Stitch this stripe"))
- visibility.SetValue(True)
+ visibility = wx.CheckBox(self, style=wx.CHK_3STATE | wx.CHK_ALLOW_3RD_STATE_FOR_USER)
+ visibility.SetToolTip(_("Checked: stitch this stripe | Minus: spacer for strokes only | Disabled: spacer for fill and stroke"))
+ visibility.Set3StateValue(1)
visibility.Bind(wx.EVT_CHECKBOX, self._update_stripes_event)
# hidden label used for linked colors
@@ -135,7 +135,7 @@ class CustomizePanel(ScrolledPanel):
colorpicker.SetToolTip(_("Select stripe color"))
colorpicker.Bind(wx.EVT_COLOURPICKER_CHANGED, self._update_color)
- stripe_width = wx.SpinCtrlDouble(self, min=0.01, max=500, initial=5, style=wx.SP_WRAP)
+ stripe_width = wx.SpinCtrlDouble(self, min=0.0, max=500, initial=5, style=wx.SP_WRAP)
stripe_width.SetDigits(2)
stripe_width.SetToolTip(_("Set stripe width (mm)"))
stripe_width.Bind(wx.EVT_SPINCTRLDOUBLE, self._update_stripes_event)
@@ -152,7 +152,7 @@ class CustomizePanel(ScrolledPanel):
stripesizer.Add(remove_button, 0, wx.CENTER | wx.TOP, 5)
if stripe is not None:
- visibility.SetValue(stripe['render'])
+ visibility.Set3StateValue(stripe['render'])
colorinfo.SetLabel(wx.Colour(stripe['color']).GetAsString(wx.C2S_HTML_SYNTAX))
colorpicker.SetColour(wx.Colour(stripe['color']))
stripe_width.SetValue(stripe['width'])
diff --git a/lib/tartan/palette.py b/lib/tartan/palette.py
index 6f29c9ae..2e33fbc8 100644
--- a/lib/tartan/palette.py
+++ b/lib/tartan/palette.py
@@ -58,14 +58,13 @@ class Palette:
for i, outer_sizer in enumerate(sizers):
stripes = []
for stripe_sizer in outer_sizer.Children:
- stripe = {'render': True, 'color': '#000000', 'width': '5'}
+ stripe = {'render': 1, 'color': '#000000', 'width': '5'}
stripe_info = stripe_sizer.GetSizer()
for color in stripe_info.GetChildren():
widget = color.GetWindow()
if isinstance(widget, wx.CheckBox):
# in embroidery it is ok to have gaps between the stripes
- if not widget.GetValue():
- stripe['render'] = False
+ stripe['render'] = widget.Get3StateValue()
elif isinstance(widget, wx.ColourPickerCtrl):
stripe['color'] = widget.GetColour().GetAsString(wx.C2S_HTML_SYNTAX)
elif isinstance(widget, wx.SpinCtrlDouble):
@@ -113,7 +112,12 @@ class Palette:
code = []
for i, direction in enumerate(self.palette_stripes):
for stripe in direction:
- render = '' if stripe['render'] else '?'
+ if stripe['render'] == 0:
+ render = '?'
+ elif stripe['render'] == 2:
+ render = '*'
+ else:
+ render = ''
code.append(f"({stripe['color']}){render}{stripe['width']}")
if i == 0 and self.equal_warp_weft is False:
code.append("|")
@@ -138,7 +142,7 @@ class Palette:
:param code: the tartan pattern code to apply
"""
stripes = []
- stripe_info = re.findall(r'([a-zA-Z]+)(\?)?([0-9.]*)', code)
+ stripe_info = re.findall(r'([a-zA-Z]+)(\?|\*)?([0-9.]*)', code)
for color, render, width in stripe_info:
if not width:
continue
@@ -146,8 +150,14 @@ class Palette:
width = float(width) * self.tt_unit
if not color:
color = '#000000'
- render = '?'
- stripes.append({'render': not bool(render), 'color': color, 'width': float(width)})
+ render = 0
+ elif render == '?':
+ render = 0
+ elif render == '*':
+ render = 2
+ else:
+ render = 1
+ stripes.append({'render': render, 'color': color, 'width': float(width)})
self.palette_stripes[0] = stripes
def parse_inkstitch_code(self, code_str: str) -> None:
@@ -163,7 +173,7 @@ class Palette:
code = code_str.split('|')
for i, direction in enumerate(code):
stripes = []
- stripe_info = re.findall(r'\(([0-9A-Za-z#]+)\)(\?)?([0-9.]+)', direction)
+ stripe_info = re.findall(r'\(([0-9A-Za-z#]+)\)(\?|\*)?([0-9.]+)', direction)
for color, render, width in stripe_info:
try:
# on macOS we need to run wxpython color method inside the app otherwise
@@ -174,8 +184,14 @@ class Palette:
color = str(Color(color).to_named())
if not color:
color = '#000000'
- render = False
- stripes.append({'render': not bool(render), 'color': color, 'width': float(width)})
+ render = 0
+ elif render == '?':
+ render = 0
+ elif render == '*':
+ render = 2
+ else:
+ render = 1
+ stripes.append({'render': render, 'color': color, 'width': float(width)})
self.palette_stripes[i] = stripes
def parse_threadcount_code(self, code: str) -> None:
@@ -216,12 +232,12 @@ class Palette:
stripe_info = re.findall(r'([a-zA-Z]+)([0-9.]*)', thread_code)
for color, width in stripe_info:
- render = True
+ render = 1
try:
color = f'#{color_dict[color]}'
except KeyError:
color = '#000000'
- render = False
+ render = 0
width = float(width) * self.tt_unit
stripes.append({'render': render, 'color': color, 'width': width})
@@ -237,8 +253,13 @@ class Palette:
:returns: the width of all tartan stripes in given direction
"""
width = 0
+ stroke_width = 0
for stripe in self.palette_stripes[direction]:
stripe_width = stripe['width'] * (scale / 100)
- if stripe_width >= min_width or not stripe['render']:
+ if stripe_width >= min_width and stripe['render'] != 2:
width += stripe_width
+ elif stripe_width < min_width and stripe['render'] != 0:
+ stroke_width += stripe_width
+ if width == 0:
+ width = stroke_width
return width
diff --git a/lib/tartan/utils.py b/lib/tartan/utils.py
index b71b0384..4f64fc6f 100644
--- a/lib/tartan/utils.py
+++ b/lib/tartan/utils.py
@@ -55,6 +55,8 @@ def stripes_to_shapes(
left = minx
top = miny
+ add_to_stroke = 0
+ add_to_fill = 0
i = -1
while True:
i += 1
@@ -68,24 +70,39 @@ def stripes_to_shapes(
right = left + width
bottom = top + width
- if (top > maxy and weft) or (left > maxx and not weft):
+ if ((top > maxy and weft) or (left > maxx and not weft) or
+ (add_to_stroke > maxy and weft) or (add_to_stroke > maxx and not weft)):
return _merge_polygons(shapes, outline, intersect_outline)
- if not stripe['render']:
- left = right
- top = bottom
+ if stripe['render'] == 0:
+ left = right + add_to_stroke
+ top = bottom + add_to_stroke
+ add_to_stroke = 0
+ continue
+ elif stripe['render'] == 2:
+ add_to_stroke += width
continue
shape_dimensions = [top, bottom, left, right, minx, miny, maxx, maxy]
if width <= min_stripe_width * PIXELS_PER_MM:
+ add_to_fill = add_to_stroke
+ shape_dimensions[0] += add_to_stroke
+ shape_dimensions[2] += add_to_stroke
linestrings = _get_linestrings(outline, shape_dimensions, rotation, rotation_center, weft)
shapes[stripe['color']].extend(linestrings)
+ add_to_stroke += width
continue
+ add_to_stroke = 0
+
+ # add the space of the lines to the following object to avoid bad symmetry
+ shape_dimensions[1] += add_to_fill
+ shape_dimensions[3] += add_to_fill
polygon = _get_polygon(shape_dimensions, rotation, rotation_center, weft)
shapes[stripe['color']].append(polygon)
- left = right
- top = bottom
+ left = right + add_to_fill
+ top = bottom + add_to_fill
+ add_to_fill = 0
def _merge_polygons(
@@ -252,9 +269,9 @@ def get_tartan_stripes(settings: dict) -> Tuple[list, list]:
warp = []
if palette.get_palette_width(settings['scale'], settings['min_stripe_width'], 1) == 0:
weft = []
- if len([stripe for stripe in warp if stripe['render'] is True]) == 0:
+ if len([stripe for stripe in warp if stripe['render'] == 1]) == 0:
warp = []
- if len([stripe for stripe in weft if stripe['render'] is True]) == 0:
+ if len([stripe for stripe in weft if stripe['render'] == 1]) == 0:
weft = []
if palette.equal_warp_weft: