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

@ -31,6 +31,7 @@
<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="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="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> <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_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> <param name="custom_dashoffset_value" type="float" min="-9999.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param>
@ -55,6 +56,8 @@
<param name="skip_errors" type="bool" gui-text="Skip errors">false</param> <param name="skip_errors" type="bool" gui-text="Skip errors">false</param>
</vbox> </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>
<page name="tab_about" gui-text="About"> <page name="tab_about" gui-text="About">
<label appearance="header">Create Links</label> <label appearance="header">Create Links</label>

View File

@ -27,7 +27,7 @@ Extension for InkScape 1.X
Author: Mario Voigt / FabLab Chemnitz Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org Mail: mario.voigt@stadtfabrikanten.org
Date: 09.04.2021 Date: 09.04.2021
Last patch: 26.10.2021 Last patch: 28.10.2021
License: GNU GPL v3 License: GNU GPL v3
""" """
@ -51,6 +51,7 @@ class LinksCreator(inkex.EffectExtension):
pars.add_argument("--length_link", type=float, default=1.000, help="Link length") 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("--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_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("--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") pars.add_argument("--length_filter", type=inkex.Boolean, default=False, help="Enable path length filtering")
@ -113,7 +114,7 @@ class LinksCreator(inkex.EffectExtension):
pass 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 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() parent = element.getparent()
idx = parent.index(element) idx = parent.index(element)
copyelement = copy.copy(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) 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) 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 # Print some info about values
if self.options.show_info is True: if self.options.show_info is True:
self.msg("element " + element.get('id') + ":") self.msg("element " + element.get('id') + ":")
@ -259,6 +272,7 @@ class LinksCreator(inkex.EffectExtension):
if self.options.no_convert is False: if self.options.no_convert is False:
style = element.style #get the style again, but this time as style class style = element.style #get the style again, but this time as style class
gaps = []
new = [] new = []
for sub in element.path.to_superpath(): for sub in element.path.to_superpath():
idash = 0 idash = 0
@ -289,14 +303,14 @@ class LinksCreator(inkex.EffectExtension):
i += 1 i += 1
#filter pointy subpaths #filter pointy subpaths
final = [] final_new = []
for sub in new: for sub in new:
if len(sub) > 1: if len(sub) > 1:
final.append(sub) final_new.append(sub)
style.pop('stroke-dasharray') style.pop('stroke-dasharray')
element.pop('sodipodi:type') element.pop('sodipodi:type')
element.path = CubicSuperPath(final) element.path = CubicSuperPath(final_new)
element.style = style element.style = style
# break apart the combined path to have multiple elements # break apart the combined path to have multiple elements