Add some handling for weaking lines (good for laser cutting with bridges

at thick materials)
This commit is contained in:
Mario Voigt 2021-10-28 21:14:44 +02:00
parent c737a8e220
commit 33098180b4
2 changed files with 27 additions and 10 deletions

View File

@ -30,7 +30,8 @@
<param name="link_multiplicator" type="int" min="0" max="9999" gui-text="Link multiplicator" gui-description="If set, we create a set of multiple gaps of same size next to the main gap">0</param>
<param name="length_link" type="float" min="0.000" max="9999.000" precision="3" gui-text="Link length (the length of the gap)">1.000</param>
<param name="link_offset" type="float" min="-9999.000" max="9999.000" precision="3" appearance="full" gui-text="Link offset (+/-)" gui-description="If you selected '%' as creation unit, enter values 0..100. The link will be placed in the middle">0.000</param>
<param name="switch_pattern" type="bool" gui-text="Swap links with dashes" gui-description="If enabled, we use gap length as dash length (switches the dasharray pattern).">false</param>
<param name="switch_pattern" type="bool" gui-text="Swap links with dashes" gui-description="If enabled, we use gap length as dash length (switches the dasharray pattern).">false</param>
<param name="weakening_mode" type="bool" gui-text="Weakening mode" gui-description="If enabled, we colorize the swap links in #0000ff (blue) and disable the option 'Keep selected elements'">false</param>
<label appearance="header">Creation: Custom Dash Pattern Settings</label>
<param name="custom_dasharray_value" type="string" gui-text="Dash pattern" gui-description="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.">10 5.5 2.0 2.0</param>
<param name="custom_dashoffset_value" type="float" min="-9999.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param>
@ -54,7 +55,9 @@
<param name="show_info" type="bool" gui-text="Print length, pattern and filtering information/errors" gui-description="Warning: might freeze Inkscape forever if you have a lot of nodes because we create too much print output. Use for debugging only!">false</param>
<param name="skip_errors" type="bool" gui-text="Skip errors">false</param>
</vbox>
</hbox>
</hbox>
<separator/>
<label>Pro tip: Use 'Keep selected elements' to create links as usual (but with a copy). Then, as second step, work with the 'Swap links' and 'Weakening mode' options on the original element selection to create extra lasercutter weakening lines for better breaking out the parts later after processing.</label>
</page>
<page name="tab_about" gui-text="About">
<label appearance="header">Create Links</label>

View File

@ -27,7 +27,7 @@ Extension for InkScape 1.X
Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org
Date: 09.04.2021
Last patch: 26.10.2021
Last patch: 28.10.2021
License: GNU GPL v3
"""
@ -50,7 +50,8 @@ class LinksCreator(inkex.EffectExtension):
pars.add_argument("--link_multiplicator", type=int, default=1, help="If set, we create a set of multiple gaps of same size next to the main gap")
pars.add_argument("--length_link", type=float, default=1.000, help="Link length")
pars.add_argument("--link_offset", type=float, default=0.000, help="Link offset (+/-)")
pars.add_argument("--switch_pattern", type=inkex.Boolean, default=False, help="If enabled, we use gap length as dash length (switches the dasharray pattern")
pars.add_argument("--switch_pattern", type=inkex.Boolean, default=False, help="If enabled, we use gap length as dash length (switches the dasharray pattern")
pars.add_argument("--weakening_mode", type=inkex.Boolean, default=False, help="If enabled, we colorize the swap links in #0000ff (blue) and disable the option 'Keep selected elements'")
pars.add_argument("--custom_dasharray_value", default="", help="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.")
pars.add_argument("--custom_dashoffset_value", type=float, default=0.000, help="Link offset (+/-)")
pars.add_argument("--length_filter", type=inkex.Boolean, default=False, help="Enable path length filtering")
@ -113,7 +114,7 @@ class LinksCreator(inkex.EffectExtension):
pass
# if keeping is enabled we make of copy of the current element and insert it while modifying the original ones. We could also delete the original and modify a copy...
if self.options.keep_selected is True:
if self.options.keep_selected is True and self.options.weakening_mode is False:
parent = element.getparent()
idx = parent.index(element)
copyelement = copy.copy(element)
@ -238,6 +239,18 @@ class LinksCreator(inkex.EffectExtension):
style = 'fill:{};stroke:{};stroke-width:{};stroke-dasharray:{};stroke-dashoffset:{};'.format(default_fill, default_stroke, default_stroke_width, stroke_dasharray, stroke_dashoffset)
element.set('style', style)
#if enabled, we override stroke color with blue (now, as the element definitely has a style)
if self.options.weakening_mode is True and self.options.switch_pattern is True:
declarations = element.get('style').split(';')
for i, decl in enumerate(declarations):
parts = decl.split(':', 2)
if len(parts) == 2:
(prop, val) = parts
prop = prop.strip().lower()
if prop == 'stroke':
declarations[i] = prop + ':{}'.format("#0000ff")
element.set('style', ';'.join(declarations)) #apply new style to element
# Print some info about values
if self.options.show_info is True:
self.msg("element " + element.get('id') + ":")
@ -259,6 +272,7 @@ class LinksCreator(inkex.EffectExtension):
if self.options.no_convert is False:
style = element.style #get the style again, but this time as style class
gaps = []
new = []
for sub in element.path.to_superpath():
idash = 0
@ -286,17 +300,17 @@ class LinksCreator(inkex.EffectExtension):
new.append([sub[i]])
else:
new[-1].append(sub[i])
i += 1
i += 1
#filter pointy subpaths
final = []
final_new = []
for sub in new:
if len(sub) > 1:
final.append(sub)
final_new.append(sub)
style.pop('stroke-dasharray')
element.pop('sodipodi:type')
element.path = CubicSuperPath(final)
element.path = CubicSuperPath(final_new)
element.style = style
# break apart the combined path to have multiple elements