Small enhancements for Contour Scanner

This commit is contained in:
Mario Voigt 2020-09-05 00:54:03 +02:00
parent a58db0516b
commit 91c25713b7
2 changed files with 21 additions and 14 deletions

View File

@ -6,7 +6,7 @@
<page name="tab_active" gui-text="Active">
<param name="desc" type="description">This tool helps you to find nasty contours which might bug you and prevent your work from being ready for production. You can find the complete documentation at the Wiki space of https://fablabchemnitz.de</param>
<param name="help_general" type="description" appearance="header">General</param>
<param name="breakapart" type="bool" gui-text="Break apart contours">false</param>
<param name="breakapart" type="bool" gui-text="Break apart contours and groups">false</param>
<param name="removefillsetstroke" type="bool" gui-text="Remove fill and define stroke">false</param>
<param name="strokewidth" min="0.0" max="10000.0" gui-text="Stroke width (px)" type="float">1.0</param>
<param name="help_highlight" type="description" appearance="header">Highlight paths</param>
@ -24,11 +24,14 @@
<param name="remove_closed" type="bool" gui-text="Remove closed contours">false</param>
<param name="remove_selfintersecting" type="bool" gui-text="Remove self-intersecting contours">false</param>
</page>
<page name="tab_info" gui-text="License/Version">
<param name="desc1" type="description">Written by Mario Voigt (Stadtfabrikanten e.V. / FabLab Chemnitz) (https://gitea.fablabchemnitz.de)</param>
<param name="desc2" type="description">Last update: 09.08.2020</param>
<param name="desc3" type="description">This piece of software is part of the MightyScape for InkScape 1.0/1.1dev Extension Collection</param>
<param name="desc4" type="description" appearance="header">you found a bug or got some fresh code? Just report to mario.voigt@stadtfabrikanten.org. Thanks!</param>
<page name="tab_info" gui-text="About">
<label appearance="header">About</label>
<separator/>
<label>Contour Scanner by Mario Voigt / Stadtfabrikanten e.V. (2020)</label>
<label>This piece of software is part of the MightyScape for InkScape 1.0/1.1dev Extension Collection</label>
<label>you found a bug or got some fresh code? Just report to mario.voigt@stadtfabrikanten.org. Thanks!</label>
<label appearance="url">https://fablabchemnitz.de</label>
<label>License: GNU GPL v3</label>
</page>
</param>
<effect>

View File

@ -63,8 +63,9 @@ class ContourScanner(inkex.Effect):
self.arg_parser.add_argument("--main_tabs")
#split combined contours into single contours if enabled - this is exactly the same as "Path -> Break Apart"
def breakContours(self, node):
replacedNodes = []
def breakContours(self, node):
if node.tag == inkex.addNS('path','svg'):
parent = node.getparent()
idx = parent.index(node)
@ -84,11 +85,10 @@ class ContourScanner(inkex.Effect):
replacedNode.set('id', oldId + str(idSuffix).zfill(5))
parent.insert(idx, replacedNode)
idSuffix += 1
replacedNodes.append(replacedNode)
self.replacedNodes.append(replacedNode)
parent.remove(node)
for child in node:
self.breakContours(child)
return replacedNodes
def scanContours(self, node):
if node.tag == inkex.addNS('path','svg'):
@ -177,6 +177,11 @@ class ContourScanner(inkex.Effect):
except Exception as e: # we skip AssertionError
#inkex.utils.debug("Accuracy Error. Try to reduce the precision of the paths using the extension called Rounder to cutoff unrequired decimals.")
print(str(e))
#if the dot_group was created but nothing attached we delete it again to prevent messing the SVG XML tree
if len(dot_group.getchildren()) == 0:
dot_group.getparent().remove(dot_group)
else: #put the node into the dot_group to bundle the path with it's error markers
dot_group.insert(0, node)
for child in node:
self.scanContours(child)
@ -188,10 +193,9 @@ class ContourScanner(inkex.Effect):
else:
newContourSet = []
for id, item in self.svg.selected.items():
newContourSet.append(self.breakContours(item))
for newContours in newContourSet:
for newContour in newContours:
self.scanContours(newContour)
self.breakContours(item)
for newContours in self.replacedNodes:
self.scanContours(newContours)
else:
if len(self.svg.selected) == 0:
self.scanContours(self.document.getroot())