add fixes for lasercheck and filter by length
This commit is contained in:
parent
609633c2b9
commit
04062e1841
@ -27,10 +27,6 @@ class FilterByLengthArea(inkex.EffectExtension):
|
|||||||
|
|
||||||
def effect(self):
|
def effect(self):
|
||||||
|
|
||||||
if len(self.svg.selected) == 0:
|
|
||||||
inkex.utils.debug("Your selection is empty.")
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.options.min_filter_enable is False and self.options.max_filter_enable is False:
|
if self.options.min_filter_enable is False and self.options.max_filter_enable is False:
|
||||||
inkex.utils.debug("You need to enabled at least one filter rule!")
|
inkex.utils.debug("You need to enabled at least one filter rule!")
|
||||||
return
|
return
|
||||||
@ -42,7 +38,12 @@ class FilterByLengthArea(inkex.EffectExtension):
|
|||||||
inkex.utils.debug("One or both tresholds are zero. Please adjust.")
|
inkex.utils.debug("One or both tresholds are zero. Please adjust.")
|
||||||
return
|
return
|
||||||
|
|
||||||
for element in self.document.xpath("//svg:path", namespaces=inkex.NSS):
|
if len(self.svg.selected) > 0:
|
||||||
|
elements = self.svg.selection.filter(inkex.PathElement).values()
|
||||||
|
else:
|
||||||
|
elements = self.document.xpath("//svg:path", namespaces=inkex.NSS)
|
||||||
|
|
||||||
|
for element in elements:
|
||||||
try:
|
try:
|
||||||
csp = element.path.transform(element.composed_transform()).to_superpath()
|
csp = element.path.transform(element.composed_transform()).to_superpath()
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<id>fablabchemnitz.de.laser_check</id>
|
<id>fablabchemnitz.de.laser_check</id>
|
||||||
<param name="tab" type="notebook">
|
<param name="tab" type="notebook">
|
||||||
<page name="tab_settings" gui-text="Checks">
|
<page name="tab_settings" gui-text="Checks">
|
||||||
|
<param name="show_issues_only" type="bool" gui-text="Show potential issues only" gui-description="Shortens the report a little bit">false</param>
|
||||||
<param name="checks" type="optiongroup" appearance="combo" gui-text="Select checks">
|
<param name="checks" type="optiongroup" appearance="combo" gui-text="Select checks">
|
||||||
<option value="check_all">Check all</option>
|
<option value="check_all">Check all</option>
|
||||||
<option value="check_section">Check selection</option>
|
<option value="check_section">Check selection</option>
|
||||||
|
@ -15,6 +15,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
def add_arguments(self, pars):
|
def add_arguments(self, pars):
|
||||||
pars.add_argument('--tab')
|
pars.add_argument('--tab')
|
||||||
pars.add_argument('--checks', default="check_all")
|
pars.add_argument('--checks', default="check_all")
|
||||||
|
pars.add_argument('--show_issues_only', type=inkex.Boolean, default=False)
|
||||||
pars.add_argument('--bbox', type=inkex.Boolean, default=False)
|
pars.add_argument('--bbox', type=inkex.Boolean, default=False)
|
||||||
pars.add_argument('--bbox_offset', type=float, default=5.000)
|
pars.add_argument('--bbox_offset', type=float, default=5.000)
|
||||||
pars.add_argument("--machine_size", default="812x508")
|
pars.add_argument("--machine_size", default="812x508")
|
||||||
@ -61,9 +62,11 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
parseChildren(element)
|
parseChildren(element)
|
||||||
namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi'))
|
namedView = self.document.getroot().find(inkex.addNS('namedview', 'sodipodi'))
|
||||||
doc_units = namedView.get(inkex.addNS('document-units', 'inkscape'))
|
doc_units = namedView.get(inkex.addNS('document-units', 'inkscape'))
|
||||||
|
user_units = namedView.get(inkex.addNS('units'))
|
||||||
pagecolor = namedView.get('pagecolor')
|
pagecolor = namedView.get('pagecolor')
|
||||||
inkex.utils.debug("---------- Default checks")
|
inkex.utils.debug("---------- Default checks")
|
||||||
inkex.utils.debug("Document units: {}".format(doc_units))
|
inkex.utils.debug("Document units: {}".format(doc_units))
|
||||||
|
inkex.utils.debug("User units: {}".format(user_units))
|
||||||
|
|
||||||
'''
|
'''
|
||||||
The SVG format is highly complex and offers a lot of possibilities. Most things of SVG we do not
|
The SVG format is highly complex and offers a lot of possibilities. Most things of SVG we do not
|
||||||
@ -77,6 +80,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
nonShapes.append(element)
|
nonShapes.append(element)
|
||||||
else:
|
else:
|
||||||
shapes.append(element)
|
shapes.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} shape elements in total".format(len(shapes)))
|
inkex.utils.debug("{} shape elements in total".format(len(shapes)))
|
||||||
inkex.utils.debug("{} non-shape elements in total".format(len(nonShapes)))
|
inkex.utils.debug("{} non-shape elements in total".format(len(nonShapes)))
|
||||||
for nonShape in nonShapes:
|
for nonShape in nonShapes:
|
||||||
@ -169,6 +173,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
layers.append(element)
|
layers.append(element)
|
||||||
else:
|
else:
|
||||||
groups.append(element)
|
groups.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} groups in total".format(len(groups)))
|
inkex.utils.debug("{} groups in total".format(len(groups)))
|
||||||
inkex.utils.debug("{} layers in total".format(len(layers)))
|
inkex.utils.debug("{} layers in total".format(len(layers)))
|
||||||
|
|
||||||
@ -191,6 +196,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in selected:
|
for element in selected:
|
||||||
if element.tag == inkex.addNS('use','svg'):
|
if element.tag == inkex.addNS('use','svg'):
|
||||||
uses.append(element)
|
uses.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} svg:use clones in total".format(len(uses)))
|
inkex.utils.debug("{} svg:use clones in total".format(len(uses)))
|
||||||
for use in uses:
|
for use in uses:
|
||||||
inkex.utils.debug("id={}".format(use.get('id')))
|
inkex.utils.debug("id={}".format(use.get('id')))
|
||||||
@ -206,6 +212,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in selected:
|
for element in selected:
|
||||||
if element.tag == inkex.addNS('clipPath','svg'):
|
if element.tag == inkex.addNS('clipPath','svg'):
|
||||||
clipPaths.append(element)
|
clipPaths.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} svg:clipPath in total".format(len(clipPaths)))
|
inkex.utils.debug("{} svg:clipPath in total".format(len(clipPaths)))
|
||||||
for clipPath in clipPaths:
|
for clipPath in clipPaths:
|
||||||
inkex.utils.debug("id={}".format(clipPath.get('id')))
|
inkex.utils.debug("id={}".format(clipPath.get('id')))
|
||||||
@ -221,6 +228,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in selected:
|
for element in selected:
|
||||||
if element.tag == inkex.addNS('image','svg'):
|
if element.tag == inkex.addNS('image','svg'):
|
||||||
images.append(element)
|
images.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} svg:image in total".format(len(images)))
|
inkex.utils.debug("{} svg:image in total".format(len(images)))
|
||||||
for image in images:
|
for image in images:
|
||||||
inkex.utils.debug("image id={}".format(image.get('id')))
|
inkex.utils.debug("image id={}".format(image.get('id')))
|
||||||
@ -235,6 +243,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in selected:
|
for element in selected:
|
||||||
if element.tag in (inkex.addNS('line','svg'), inkex.addNS('polyline','svg'), inkex.addNS('polygon','svg')):
|
if element.tag in (inkex.addNS('line','svg'), inkex.addNS('polyline','svg'), inkex.addNS('polygon','svg')):
|
||||||
lowlevels.append(element)
|
lowlevels.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} low level strokes in total".format(len(lowlevels)))
|
inkex.utils.debug("{} low level strokes in total".format(len(lowlevels)))
|
||||||
for lowlevel in lowlevels:
|
for lowlevel in lowlevels:
|
||||||
inkex.utils.debug("id={}".format(lowlevel.get('id')))
|
inkex.utils.debug("id={}".format(lowlevel.get('id')))
|
||||||
@ -251,6 +260,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in selected:
|
for element in selected:
|
||||||
if element.tag == inkex.addNS('text','svg'):
|
if element.tag == inkex.addNS('text','svg'):
|
||||||
texts.append(element)
|
texts.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} svg:text in total".format(len(texts)))
|
inkex.utils.debug("{} svg:text in total".format(len(texts)))
|
||||||
for text in texts:
|
for text in texts:
|
||||||
inkex.utils.debug("id={}".format(text.get('id')))
|
inkex.utils.debug("id={}".format(text.get('id')))
|
||||||
@ -272,6 +282,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
strokeColor = stroke[0].split("stroke:")[1].split(";")[0]
|
strokeColor = stroke[0].split("stroke:")[1].split(";")[0]
|
||||||
if strokeColor not in strokeColors:
|
if strokeColor not in strokeColors:
|
||||||
strokeColors.append(strokeColor)
|
strokeColors.append(strokeColor)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} different stroke colors in total".format(len(strokeColors)))
|
inkex.utils.debug("{} different stroke colors in total".format(len(strokeColors)))
|
||||||
for strokeColor in strokeColors:
|
for strokeColor in strokeColors:
|
||||||
inkex.utils.debug("stroke color {}".format(strokeColor))
|
inkex.utils.debug("stroke color {}".format(strokeColor))
|
||||||
@ -291,6 +302,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
strokeWidth = stroke_width[0].split("stroke-width:")[1].split(";")[0] #possibly w/o units. could contain units from css
|
strokeWidth = stroke_width[0].split("stroke-width:")[1].split(";")[0] #possibly w/o units. could contain units from css
|
||||||
if strokeWidth not in strokeWidths:
|
if strokeWidth not in strokeWidths:
|
||||||
strokeWidths.append(strokeWidth)
|
strokeWidths.append(strokeWidth)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} different stroke widths in total".format(len(strokeWidths)))
|
inkex.utils.debug("{} different stroke widths in total".format(len(strokeWidths)))
|
||||||
for strokeWidth in strokeWidths:
|
for strokeWidth in strokeWidths:
|
||||||
swConverted = self.svg.uutounit(float(self.svg.unittouu(strokeWidth))) #possibly w/o units. we unify to some internal float
|
swConverted = self.svg.uutounit(float(self.svg.unittouu(strokeWidth))) #possibly w/o units. we unify to some internal float
|
||||||
@ -316,6 +328,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
strokeDasharray = stroke_dasharray[0].split("stroke-dasharray:")[1].split(";")[0]
|
strokeDasharray = stroke_dasharray[0].split("stroke-dasharray:")[1].split(";")[0]
|
||||||
if strokeDasharray not in strokeDasharrays:
|
if strokeDasharray not in strokeDasharrays:
|
||||||
strokeDasharrays.append(strokeDasharray)
|
strokeDasharrays.append(strokeDasharray)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} different stroke dash arrays in total".format(len(strokeDasharrays)))
|
inkex.utils.debug("{} different stroke dash arrays in total".format(len(strokeDasharrays)))
|
||||||
for strokeDasharray in strokeDasharrays:
|
for strokeDasharray in strokeDasharrays:
|
||||||
inkex.utils.debug("stroke dash array {}".format(strokeDasharray))
|
inkex.utils.debug("stroke dash array {}".format(strokeDasharray))
|
||||||
@ -385,6 +398,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
if (strokeVis == 0 or widthVis == 0 or strokeOpacityVis == 0) and (fillVis == 0 or fillOpacityVis == 0):
|
if (strokeVis == 0 or widthVis == 0 or strokeOpacityVis == 0) and (fillVis == 0 or fillOpacityVis == 0):
|
||||||
if element not in invisibles:
|
if element not in invisibles:
|
||||||
invisibles.append(element)
|
invisibles.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} invisible shapes in total".format(len(invisibles)))
|
inkex.utils.debug("{} invisible shapes in total".format(len(invisibles)))
|
||||||
for invisible in invisibles:
|
for invisible in invisibles:
|
||||||
inkex.utils.debug("id={}".format(invisible.get('id')))
|
inkex.utils.debug("id={}".format(invisible.get('id')))
|
||||||
@ -405,6 +419,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
if float(stroke_opacity[0].split("stroke-opacity:")[1].split(";")[0]) < 1.0:
|
if float(stroke_opacity[0].split("stroke-opacity:")[1].split(";")[0]) < 1.0:
|
||||||
if element not in transparencies:
|
if element not in transparencies:
|
||||||
transparencies.append(element)
|
transparencies.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} objects with stroke transparencies < 1.0 in total".format(len(transparencies)))
|
inkex.utils.debug("{} objects with stroke transparencies < 1.0 in total".format(len(transparencies)))
|
||||||
for transparency in transparencies:
|
for transparency in transparencies:
|
||||||
inkex.utils.debug("id={}".format(transparency.get('id')))
|
inkex.utils.debug("id={}".format(transparency.get('id')))
|
||||||
@ -425,6 +440,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
(len(commandsCoords) == 2 and commandsCoords[-1][0] == 'Z') or \
|
(len(commandsCoords) == 2 and commandsCoords[-1][0] == 'Z') or \
|
||||||
(len(commandsCoords) == 3 and commandsCoords[0][1] == commandsCoords[1][1] and commandsCoords[2][1] == 'Z'):
|
(len(commandsCoords) == 3 and commandsCoords[0][1] == commandsCoords[1][1] and commandsCoords[2][1] == 'Z'):
|
||||||
pointyPaths.append(element)
|
pointyPaths.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} pointy paths in total".format(len(pointyPaths)))
|
inkex.utils.debug("{} pointy paths in total".format(len(pointyPaths)))
|
||||||
for pointyPath in pointyPaths:
|
for pointyPath in pointyPaths:
|
||||||
inkex.utils.debug("id={}".format(pointyPath.get('id')))
|
inkex.utils.debug("id={}".format(pointyPath.get('id')))
|
||||||
@ -441,6 +457,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in shapes:
|
for element in shapes:
|
||||||
if element.get('transform') is not None:
|
if element.get('transform') is not None:
|
||||||
transformations.append(element)
|
transformations.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} transformation in total".format(len(transformations)))
|
inkex.utils.debug("{} transformation in total".format(len(transformations)))
|
||||||
for transformation in transformations:
|
for transformation in transformations:
|
||||||
inkex.utils.debug("transformation in id={}".format(transformation.get('id')))
|
inkex.utils.debug("transformation in id={}".format(transformation.get('id')))
|
||||||
@ -459,13 +476,14 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
slengths, stotal = csplength(element.path.transform(element.composed_transform()).to_superpath())
|
slengths, stotal = csplength(element.path.transform(element.composed_transform()).to_superpath())
|
||||||
totalLength += stotal
|
totalLength += stotal
|
||||||
if stotal < self.svg.unittouu(str(so.short_paths_min) + "mm"):
|
if stotal < self.svg.unittouu(str(so.short_paths_min) + "mm"):
|
||||||
shortPaths.append(element)
|
shortPaths.append([element, stotal])
|
||||||
totalDropLength += stotal
|
totalDropLength += stotal
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} short paths in total".format(len(shortPaths)))
|
inkex.utils.debug("{} short paths in total".format(len(shortPaths)))
|
||||||
if totalLength > 0:
|
if totalLength > 0:
|
||||||
inkex.utils.debug("{:0.2f}% of total ({:0.2f} mm /{:0.2f} mm)".format(totalDropLength / totalLength, totalDropLength, totalLength))
|
inkex.utils.debug("{:0.2f}% of total ({:0.2f} mm /{:0.2f} mm)".format(totalDropLength / totalLength, self.svg.uutounit(str(totalDropLength), "mm"), self.svg.uutounit(str(totalLength), "mm")))
|
||||||
for shortPath in shortPaths:
|
for shortPath in shortPaths:
|
||||||
inkex.utils.debug("id={}".format(shortPath.get('id')))
|
inkex.utils.debug("id={}, length={}mm".format(shortPath[0].get('id'), round(self.svg.uutounit(str(shortPath[1]), "mm"), 3)))
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -478,6 +496,7 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
for element in shapes:
|
for element in shapes:
|
||||||
if not isinstance(element, inkex.PathElement) and not isinstance(element, inkex.Group):
|
if not isinstance(element, inkex.PathElement) and not isinstance(element, inkex.Group):
|
||||||
nonPathShapes.append(element)
|
nonPathShapes.append(element)
|
||||||
|
if self.options.show_issues_only is False:
|
||||||
inkex.utils.debug("{} non-path shapes in total".format(len(nonPathShapes)))
|
inkex.utils.debug("{} non-path shapes in total".format(len(nonPathShapes)))
|
||||||
for nonPathShape in nonPathShapes:
|
for nonPathShape in nonPathShapes:
|
||||||
inkex.utils.debug("id={}".format(nonPathShape.get('id')))
|
inkex.utils.debug("id={}".format(nonPathShape.get('id')))
|
||||||
|
Reference in New Issue
Block a user