added option to remove original paths generally instead after trimming only; adjusted styling option to sub split lines

This commit is contained in:
Mario Voigt 2021-06-23 11:09:08 +02:00
parent 87905b485a
commit 22f7860c21
2 changed files with 30 additions and 21 deletions

View File

@ -14,6 +14,7 @@
<param name="snap_tolerance" type="float" min="0.01" max="10.0" gui-text="Snap tolerance" gui-description="Snap tolerance for intersection points on paths (default: 0.1)">0.1</param>
<param name="draw_subsplit" type="bool" gui-text="Draw sub split lines (for debugging purposes)" gui-description="Draws polylines. Will be automatically enabled if any highlighting is activated.">false</param>
<param name="remove_subsplit_collinear" type="bool" gui-text="Remove collinear overlapping lines (experimental)" gui-description="Removes any duplicates by merging (multiple) overlapping line segments into longer lines. Not possible to apply for original paths because this routine does not support bezier type paths.">true</param>
<param name="keep_original_after_split_trim" type="bool" gui-text="Keep original paths after sub splitting / trimming">false</param>
</page>
<page name="tab_scanning" gui-text="Scanning and Trimming">
<hbox>
@ -53,7 +54,6 @@
<param name="remove_duplicates" type="bool" gui-text="Remove duplicate trim lines">true</param>
<param name="reverse_removal_order" type="bool" gui-text="Reverse removal order" gui-description="Reverses the order of removal. Relevant for keeping certain styles of elements">false</param>
<param name="bezier_trimming" type="bool" gui-text="Trim original beziers (not working yet)" gui-description="If enabled we try to split the original bezier paths at the intersections points by finding the correct bezier segments and calculating t parameters from trimmed sub split lines. Not working yet. Will just print debug info if debug is enabled.">true</param>
<param name="keep_original_after_trim" type="bool" gui-text="Keep original paths after trimming">false</param>
<label appearance="header">Bentley Ottmann Sweep Line Settings</label>
<param name="bent_ott_use_ignore_segment_endings" type="bool" gui-text="Ignore segment endings" gui-description="Whether to ignore intersections of line segments when both their end points form the intersection point">true</param>
<param name="bent_ott_use_debug" type="bool" gui-text="Debug">false</param>
@ -93,9 +93,12 @@
<param name="strokewidth" min="0.0" max="10000.0" precision="3" gui-text="Stroke width (px)" gui-description="Applies For sub split lines and trimmed lines" type="float">1.0</param>
<param name="dotsize_intersections" type="int" min="0" max="10000" gui-text="Dot size (px)" gui-description="For self-intersecting and global intersection points">30</param>
<param name="removefillsetstroke" type="bool" gui-text="Remove fill and define stroke" gui-description="Modifies original path style">false</param>
<param name="apply_style_to_subsplits" type="bool" gui-text="Highlighting styles for sub split lines" gui-description="Apply highlighting styles to sub split lines.">true</param>
<param name="subsplit_style" type="optiongroup" appearance="combo" gui-text="Sub split line style">
<option value="default">Use default sub split style</option>
<option value="apply_from_highlightings">Apply highlighting styles</option>
<option value="apply_from_original">Apply original path styles</option>
</param>
<param name="apply_style_to_trimmed" type="bool" gui-text="Original style for trimmed lines" gui-description="Apply original path style to trimmed lines.">true</param>
</vbox>
</hbox>
</page>

View File

@ -47,7 +47,7 @@ Extension for InkScape 1.0+
Author: Mario Voigt / FabLab Chemnitz
Mail: mario.voigt@stadtfabrikanten.org
Date: 09.08.2020 (extension originally called "Contour Scanner")
Last patch: 22.06.2021
Last patch: 23.06.2021
License: GNU GPL v3
'''
@ -376,7 +376,11 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
# collect segments, calculate their slopes, order their points left-to-right
for line in lineArray:
#csp = line.path.to_arrays()
csp = Path(line.path.transform(line.getparent().composed_transform())).to_arrays()
parent = line.getparent()
if parent is not None:
csp = Path(line.path.transform(parent.composed_transform())).to_arrays()
else:
csp = line.path.to_arrays()
#self.msg("csp = {}".format(csp))
x1, y1, x2, y2 = csp[0][1][0], csp[0][1][1], csp[1][1][0], csp[1][1][1]
# ensure p0 is left of p1
@ -431,7 +435,7 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
#we finally build a list which contains all overlapping elements we want to drop
dropped_ids = []
for input_id in input_ids: #if the working id is not in the output id we are going to drop it
for input_id in input_ids: #if the input_id id is not in the output ids we are going to drop it
if input_id not in output_ids:
dropped_ids.append(input_id)
@ -587,8 +591,9 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
pars.add_argument("--snap_tolerance", type=float, default=0.1, help="Snap tolerance for intersection points")
pars.add_argument("--draw_subsplit", type=inkex.Boolean, default=False, help="Draw sub split lines (polylines)")
pars.add_argument("--remove_subsplit_collinear", type=inkex.Boolean, default=True, help="Removes any duplicates by merging (multiple) overlapping line segments into longer lines. Not possible to apply for original paths because this routine does not support bezier type paths.")
pars.add_argument("--keep_original_after_split_trim", type=inkex.Boolean, default=False, help="Keep original paths after sub splitting / trimming")
#Scanning - Removing
#Scanning - Removing of original paths
pars.add_argument("--remove_relative", type=inkex.Boolean, default=False, help="relative cmd")
pars.add_argument("--remove_absolute", type=inkex.Boolean, default=False, help="absolute cmd")
pars.add_argument("--remove_mixed", type=inkex.Boolean, default=False, help="mixed cmd (relative + absolute)")
@ -598,7 +603,7 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
pars.add_argument("--remove_closed", type=inkex.Boolean, default=False, help="closed")
pars.add_argument("--remove_self_intersecting", type=inkex.Boolean, default=False, help="self-intersecting")
#Scanning - Highlighting
#Scanning - Highlighting of original paths (and sub split lines)
pars.add_argument("--highlight_relative", type=inkex.Boolean, default=False, help="relative cmd paths")
pars.add_argument("--highlight_absolute", type=inkex.Boolean, default=False, help="absolute cmd paths")
pars.add_argument("--highlight_mixed", type=inkex.Boolean, default=False, help="mixed cmd (relative + absolute) paths")
@ -610,12 +615,11 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
pars.add_argument("--visualize_self_intersections", type=inkex.Boolean, default=False, help="self-intersecting path points")
pars.add_argument("--visualize_global_intersections", type=inkex.Boolean, default=False, help="global intersection points")
#Settings - Trimming
#Settings - Trimming of sub split lines
pars.add_argument("--draw_trimmed", type=inkex.Boolean, default=False, help="Draw trimmed lines")
pars.add_argument("--combine_nonintersects", type=inkex.Boolean, default=True, help="Combine non-intersected lines")
pars.add_argument("--remove_duplicates", type=inkex.Boolean, default=True, help="Remove duplicate trim lines")
pars.add_argument("--reverse_removal_order", type=inkex.Boolean, default=False, help="Reverses the order of removal. Relevant for keeping certain styles of elements")
pars.add_argument("--keep_original_after_trim", type=inkex.Boolean, default=False, help="Keep original paths after trimming")
pars.add_argument("--bent_ott_use_ignore_segment_endings", type=inkex.Boolean, default=True, help="Whether to ignore intersections of line segments when both their end points form the intersection point")
pars.add_argument("--bent_ott_use_debug", type=inkex.Boolean, default=False)
@ -629,10 +633,10 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
pars.add_argument("--dotsize_intersections", type=int, default=30, help="Dot size (px) for self-intersecting and global intersection points")
pars.add_argument("--removefillsetstroke", type=inkex.Boolean, default=False, help="Remove fill and define stroke for original paths")
pars.add_argument("--bezier_trimming", type=inkex.Boolean, default=False, help="If true we try to use the calculated t parameters from intersection points to receive splitted bezier curves")
pars.add_argument("--apply_style_to_subsplits", type=inkex.Boolean, default=True, help="Apply highlighting styles to sub split lines.")
pars.add_argument("--subsplit_style", default="default", help="Sub split line style")
pars.add_argument("--apply_style_to_trimmed", type=inkex.Boolean, default=True, help="Apply original path style to trimmed lines")
#Style - Scanning Colors
#Style - Scanning Colors (Highlighting things)
pars.add_argument("--color_subsplit", type=Color, default='1630897151', help="sub split lines")
pars.add_argument("--color_relative", type=Color, default='3419879935', help="relative cmd paths")
pars.add_argument("--color_absolute", type=Color, default='1592519679', help="absolute cmd paths")
@ -645,7 +649,7 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
pars.add_argument("--color_self_intersections", type=Color, default='6320383', help="self-intersecting path points")
pars.add_argument("--color_global_intersections", type=Color, default='4239343359', help="global intersection points")
#Style - Trimming Color
#Style - Trimming Colors
pars.add_argument("--color_trimmed", type=Color, default='1923076095', help="trimmed lines")
pars.add_argument("--color_combined", type=Color, default='3227634687', help="non-intersected lines")
pars.add_argument("--color_nonintersected", type=Color, default='3045284607', help="non-intersected paths")
@ -792,7 +796,7 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
line.attrib['originalPathStyle'] = str(pathElement.style)
subSplitLineArray.append(line)
if so.apply_style_to_subsplits is True:
if so.subsplit_style == "apply_from_highlightings":
if line.attrib['originalPathIsRelative'] == 'True':
if so.highlight_relative is True:
line.style = relativePathStyle
@ -818,6 +822,8 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
else:
if so.highlight_opened is True:
line.style = openPathStyle
elif so.subsplit_style == "apply_from_original":
line.style = line.attrib['originalPathStyle']
if so.draw_subsplit is True:
subSplitLineGroup.add(line)
@ -997,12 +1003,6 @@ class ContourScannerAndTrimmer(inkex.EffectExtension):
if so.combine_nonintersects is True:
if so.show_debug is True: self.msg("glueing together all non-intersected sub split lines to larger path structures again (cleaning up)")
self. combine_nonintersects(allTrimGroups)
#clean original paths if selected. This option is explicitely independent from remove_open, remove_closed
if so.keep_original_after_trim is False:
if so.show_debug is True: self.msg("cleaning original paths")
for pathElement in pathElements:
pathElement.delete()
except AssertionError as e:
self.msg("Error calculating global intersections.\n\
@ -1010,7 +1010,13 @@ See https://github.com/ideasman42/isect_segments-bentley_ottmann.\n\n\
You can try to fix this by:\n\
- reduce or raise the 'decimals' setting (default is 3 but try to set to 6 for example)\n\
- reduce or raise the 'flatness' setting (if quantization option is used at all; default is 0.100).")
return
return
#clean original paths if selected.
if so.keep_original_after_split_trim is False:
if so.show_debug is True: self.msg("cleaning original paths after sub splitting / trimming")
for pathElement in pathElements:
pathElement.delete()
if __name__ == '__main__':
ContourScannerAndTrimmer().run()