small enhancements in contour scanner

This commit is contained in:
Mario Voigt 2021-06-05 16:39:54 +02:00
parent c50d034738
commit eb23a4100f
3 changed files with 14 additions and 11 deletions

View File

@ -7,7 +7,7 @@
<label appearance="header">General</label> <label appearance="header">General</label>
<param name="show_debug" type="bool" gui-text="Show debug infos">false</param> <param name="show_debug" type="bool" gui-text="Show debug infos">false</param>
<param name="break_apart" type="bool" gui-text="Break apart input" gui-description="Break apart input paths into sub paths. Modifies original paths: converts to absolute paths and might create additional new path elements.">false</param> <param name="break_apart" type="bool" gui-text="Break apart input" gui-description="Break apart input paths into sub paths. Modifies original paths: converts to absolute paths and might create additional new path elements.">false</param>
<param name="handle_groups" type="bool" gui-text="Handle groups" gui-description="Also looks for paths in groups which are in the current selection. Note: The generated results have a different structure (less granularity due to grouping) than directly selected paths. The colorization for non-intersected paths will be different too.">false</param> <param name="handle_groups" type="bool" gui-text="Handle groups" gui-description="Also looks for paths in groups which are in the current selection. Note: The generated results have a different structure (less granularity due to grouping and conversion of absolute paths to relative paths) than directly selected paths. The colorization for non-intersected paths will be different too.">false</param>
<param name="flattenbezier" type="bool" gui-text="Quantization (flatten bezier curves to polylines)" gui-description="Convert bezier curves to polylines.">true</param> <param name="flattenbezier" type="bool" gui-text="Quantization (flatten bezier curves to polylines)" gui-description="Convert bezier curves to polylines.">true</param>
<param name="flatness" type="float" min="0.001" max="99999.000" precision="3" gui-text="Flatness (tolerance)" gui-description="Minimum flatness = 0.001. The smaller the value the more fine segments you will get (quantization). Large values might destroy the line continuity.">0.100</param> <param name="flatness" type="float" min="0.001" max="99999.000" precision="3" gui-text="Flatness (tolerance)" gui-description="Minimum flatness = 0.001. The smaller the value the more fine segments you will get (quantization). Large values might destroy the line continuity.">0.100</param>
<param name="decimals" type="int" min="0" max="16" gui-text="Decimals" gui-description="Accuracy for sub split lines / lines trimmed by shapely (default: 3)">3</param> <param name="decimals" type="int" min="0" max="16" gui-text="Decimals" gui-description="Accuracy for sub split lines / lines trimmed by shapely (default: 3)">3</param>
@ -48,7 +48,7 @@
<option value="closed_paths">closed:closed paths</option> <option value="closed_paths">closed:closed paths</option>
</param> </param>
<param name="draw_trimmed" type="bool" gui-text="Draw trimmed lines">false</param> <param name="draw_trimmed" type="bool" gui-text="Draw trimmed lines">false</param>
<param name="combine_nonintersects" type="bool" gui-text="Chain + combine non-intersected lines">true</param> <param name="combine_nonintersects" type="bool" gui-text="Chain + combine non-intersected lines" gui-description="This will colorize all paths segments which were not intersected ('non-intersected lines'). If the whole path was not intersected at all, it will get another color ('non-intersected paths').">true</param>
<param name="remove_duplicates" type="bool" gui-text="Remove duplicate trim lines">true</param> <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="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="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>

View File

@ -75,31 +75,34 @@ intersectedVerb = "-intersected-"
class ContourScannerAndTrimmer(inkex.EffectExtension): class ContourScannerAndTrimmer(inkex.EffectExtension):
def breakContours(self, element, breakelements = None): def breakContours(self, element, breakelements = None):
''' this does the same as "CTRL + SHIFT + K" ''' '''
this does the same as "CTRL + SHIFT + K"
This functions honors the fact of absolute or relative paths!
'''
if breakelements == None: if breakelements == None:
breakelements = [] breakelements = []
if element.tag == inkex.addNS('path','svg'): if element.tag == inkex.addNS('path','svg'):
parent = element.getparent() parent = element.getparent()
idx = parent.index(element) idx = parent.index(element)
idSuffix = 0 idSuffix = 0
raw = element.path.to_arrays() raw = str(element.path).split()
subPaths, prev = [], 0 subPaths, prev = [], 0
for i in range(len(raw)): # Breaks compound paths into simple paths for i in range(len(raw)): # Breaks compound paths into simple paths
if raw[i][0] == 'M' and i != 0: if raw[i][0].upper() == 'M' and i != 0:
subPaths.append(raw[prev:i]) subPaths.append(raw[prev:i])
prev = i prev = i
subPaths.append(raw[prev:]) subPaths.append(raw[prev:])
for subpath in subPaths: for subpath in subPaths:
replacedelement = copy.copy(element) replacedelement = copy.copy(element)
oldId = replacedelement.get('id') oldId = replacedelement.get('id')
csp = CubicSuperPath(subpath) csp = CubicSuperPath(Path(" ".join(subpath)))
if len(subpath) > 1 and csp[0][0] != csp[0][1]: #avoids pointy paths like M "31.4794 57.6024 Z" if len(subpath) > 1 and csp[0][0] != csp[0][1]: #avoids pointy paths like M "31.4794 57.6024 Z"
replacedelement.set('d', csp) replacedelement.set('d', " ".join(subpath))
replacedelement.set('id', oldId + str(idSuffix)) replacedelement.set('id', oldId + str(idSuffix))
parent.insert(idx, replacedelement) parent.insert(idx, replacedelement)
idSuffix += 1 idSuffix += 1
breakelements.append(replacedelement) breakelements.append(replacedelement)
parent.remove(element) element.delete()
for child in element.getchildren(): for child in element.getchildren():
self.breakContours(child, breakelements) self.breakContours(child, breakelements)
return breakelements return breakelements

View File

@ -30,7 +30,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: 02.04.2021 Date: 02.04.2021
Last patch: 24.04.2021 Last patch: 05.06.2021
License: GNU GPL v3 License: GNU GPL v3
This piece of spaghetti-code, called "vpypetools", is a wrapper to pass (pipe) line elements from InkScape selection (or complete canvas) to vpype. This piece of spaghetti-code, called "vpypetools", is a wrapper to pass (pipe) line elements from InkScape selection (or complete canvas) to vpype.
@ -410,7 +410,7 @@ class vpypetools (inkex.EffectExtension):
if self.options.strokes_to_paths is True: if self.options.strokes_to_paths is True:
for line in element.iter("{http://www.w3.org/2000/svg}line"): for line in element.iter("{http://www.w3.org/2000/svg}line"):
newLine = PathElement() newLine = PathElement()
newLine.path = Path("M {},{}L {},{}".format(line.attrib['x1'], line.attrib['y1'], line.attrib['x2'], line.attrib['y2'])) newLine.path = Path("M {},{} L {},{}".format(line.attrib['x1'], line.attrib['y1'], line.attrib['x2'], line.attrib['y2']))
element.append(newLine) element.append(newLine)
line.delete() line.delete()