simplify lasercheck
This commit is contained in:
parent
357d358e4d
commit
2787147b23
@ -7,6 +7,7 @@ import re
|
|||||||
import math
|
import math
|
||||||
from math import log
|
from math import log
|
||||||
import datetime
|
import datetime
|
||||||
|
from email.policy import default
|
||||||
|
|
||||||
class LaserCheck(inkex.EffectExtension):
|
class LaserCheck(inkex.EffectExtension):
|
||||||
|
|
||||||
@ -346,11 +347,9 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
inkex.utils.debug("\n---------- Stroke colors ({} are allowed)".format(so.stroke_colors_max))
|
inkex.utils.debug("\n---------- Stroke colors ({} are allowed)".format(so.stroke_colors_max))
|
||||||
strokeColors = []
|
strokeColors = []
|
||||||
for element in shapes:
|
for element in shapes:
|
||||||
style = element.get('style')
|
strokeColor = element.style.get('stroke')
|
||||||
if style is not None:
|
if strokeColor is None or strokeColor == "none":
|
||||||
stroke = re.search('(;|^)stroke:(.*?)(;|$)', style)
|
strokeColor = "none"
|
||||||
if stroke is not None:
|
|
||||||
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 so.show_issues_only is False:
|
if so.show_issues_only is False:
|
||||||
@ -368,11 +367,9 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
inkex.utils.debug("\n---------- Stroke widths ({} are allowed)".format(so.stroke_widths_max))
|
inkex.utils.debug("\n---------- Stroke widths ({} are allowed)".format(so.stroke_widths_max))
|
||||||
strokeWidths = []
|
strokeWidths = []
|
||||||
for element in shapes:
|
for element in shapes:
|
||||||
style = element.get('style')
|
strokeWidth = element.style.get('stroke-width')
|
||||||
if style is not None:
|
if strokeWidth is None or strokeWidth == "none":
|
||||||
stroke_width = re.search('stroke-width:(.*?)(;|$)', style)
|
strokeWidth = "none"
|
||||||
if stroke_width is not None:
|
|
||||||
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 so.show_issues_only is False:
|
if so.show_issues_only is False:
|
||||||
@ -395,11 +392,9 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
inkex.utils.debug("\n---------- Cosmetic dashes - should be converted to paths")
|
inkex.utils.debug("\n---------- Cosmetic dashes - should be converted to paths")
|
||||||
strokeDasharrays = []
|
strokeDasharrays = []
|
||||||
for element in shapes:
|
for element in shapes:
|
||||||
style = element.get('style')
|
strokeDasharray = element.style.get('stroke-dasharray')
|
||||||
if style is not None:
|
if strokeDasharray is None or strokeDasharray == "none":
|
||||||
stroke_dasharray = re.search('stroke-dasharray:(.*?)(;|$)', style)
|
strokeDasharray = "none"
|
||||||
if stroke_dasharray is not None:
|
|
||||||
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 so.show_issues_only is False:
|
if so.show_issues_only is False:
|
||||||
@ -412,36 +407,33 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
Shapes/paths with the same color like the background, 0% opacity, etc. lead to strange
|
Shapes/paths with the same color like the background, 0% opacity, etc. lead to strange
|
||||||
laser cutting results, like duplicated edges, enlarged laser times and more. Please double
|
laser cutting results, like duplicated edges, enlarged laser times and more. Please double
|
||||||
check for such occurences.
|
check for such occurences.
|
||||||
|
Please transfer styles from layers/groups level to element level! You can use "Cleanup Styles" extension to do that
|
||||||
'''
|
'''
|
||||||
if so.checks == "check_all" or so.invisible_shapes is True:
|
if so.checks == "check_all" or so.invisible_shapes is True:
|
||||||
inkex.utils.debug("\n---------- Invisible shapes")
|
inkex.utils.debug("\n---------- Invisible shapes")
|
||||||
invisibles = []
|
invisibles = []
|
||||||
for element in shapes:
|
for element in shapes:
|
||||||
if element.tag not in (inkex.addNS('tspan','svg')):
|
if element.tag not in (inkex.addNS('tspan','svg')) and element.get('inkscape:groupmode') != 'layer' and not isinstance(element, inkex.Group):
|
||||||
style = element.get('style')
|
stroke = element.style.get('stroke')
|
||||||
if style is not None:
|
if stroke is None or stroke == "none":
|
||||||
stroke = re.search('stroke:(.*?)(;|$)', style) #filter white on white (we guess the background color of the document is white too but we do not check)
|
|
||||||
if stroke is None:
|
|
||||||
strokeVis = 0
|
strokeVis = 0
|
||||||
elif stroke[0].split("stroke:")[1].split(";")[0] == 'none':
|
elif stroke in ('#ffffff', 'white', 'rgb(255,255,255)'):
|
||||||
strokeVis = 0
|
|
||||||
elif stroke[0].split("stroke:")[1].split(";")[0] in ('#ffffff', 'white', 'rgb(255,255,255)'):
|
|
||||||
strokeVis = 0
|
strokeVis = 0
|
||||||
else:
|
else:
|
||||||
strokeVis = 1
|
strokeVis = 1
|
||||||
|
|
||||||
stroke_width = re.search('stroke-width:(.*?)(;|$)', style)
|
stroke_width = element.style.get('stroke-width')
|
||||||
if stroke_width is None:
|
if stroke_width is None or stroke_width == "none":
|
||||||
widthVis = 0
|
widthVis = 0
|
||||||
elif self.svg.unittouu(stroke_width[0].split("stroke-width:")[1].split(";")[0]) < 0.005: #really thin (0,005pc = 0,080px)
|
elif self.svg.unittouu(stroke_width) < 0.005: #really thin (0,005pc = 0,080px)
|
||||||
widthVis = 0
|
widthVis = 0
|
||||||
else:
|
else:
|
||||||
widthVis = 1
|
widthVis = 1
|
||||||
|
|
||||||
stroke_opacity = re.search('stroke-opacity:(.*?)(;|$)', style)
|
stroke_opacity = element.style.get('stroke-opacity')
|
||||||
if stroke_opacity is None:
|
if stroke_opacity is None or stroke_opacity == "none":
|
||||||
strokeOpacityVis = 0
|
strokeOpacityVis = 0
|
||||||
elif float(stroke_opacity[0].split("stroke-opacity:")[1].split(";")[0]) < 0.05: #nearly invisible (<5% opacity)
|
elif float(stroke_opacity) < 0.05: #nearly invisible (<5% opacity)
|
||||||
strokeOpacityVis = 0
|
strokeOpacityVis = 0
|
||||||
else:
|
else:
|
||||||
strokeOpacityVis = 1
|
strokeOpacityVis = 1
|
||||||
@ -450,25 +442,25 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
invisColors = [pagecolor, 'white', 'rgb(255,255,255)']
|
invisColors = [pagecolor, 'white', 'rgb(255,255,255)']
|
||||||
else:
|
else:
|
||||||
invisColors = [pagecolor] #we could add some parser to convert pagecolor to rgb/hsl/cmyk
|
invisColors = [pagecolor] #we could add some parser to convert pagecolor to rgb/hsl/cmyk
|
||||||
fill = re.search('fill:(.*?)(;|$)', style)
|
|
||||||
if fill is None:
|
fill = element.style.get('fill')
|
||||||
|
if fill is None or fill == "none":
|
||||||
fillVis = 0
|
fillVis = 0
|
||||||
elif fill[0].split("fill:")[1].split(";")[0] == 'none':
|
elif fill in invisColors:
|
||||||
fillVis = 0
|
|
||||||
elif fill[0].split("fill:")[1].split(";")[0] in invisColors:
|
|
||||||
fillVis = 0
|
fillVis = 0
|
||||||
else:
|
else:
|
||||||
fillVis = 1
|
fillVis = 1
|
||||||
|
|
||||||
fill_opacity = re.search('fill-opacity:(.*?)(;|$)', style)
|
fill_opacity = element.style.get('fill-opacity')
|
||||||
if fill_opacity is None:
|
if fill_opacity is None or fill_opacity == "none": #always is opaque if not set, so set to 1
|
||||||
fillOpacityVis = 0
|
fillOpacityVis = 1
|
||||||
elif float(fill_opacity[0].split("fill-opacity:")[1].split(";")[0]) < 0.05: #nearly invisible (<5% opacity)
|
elif float(fill_opacity) < 0.05: #nearly invisible (<5% opacity)
|
||||||
fillOpacityVis = 0
|
fillOpacityVis = 0
|
||||||
else:
|
else:
|
||||||
fillOpacityVis = 1
|
fillOpacityVis = 1
|
||||||
|
|
||||||
#inkex.utils.debug("strokeVis={}, widthVis={}, strokeOpacityVis={}, fillVis={}, fillOpacityVis={}".format(strokeVis, widthVis, strokeOpacityVis, fillVis, fillOpacityVis))
|
inkex.utils.debug("id={}, strokeVis={}, widthVis={}, strokeOpacityVis={}, fillVis={}, fillOpacityVis={}".format(element.get('id'), strokeVis, widthVis, strokeOpacityVis, fillVis, fillOpacityVis))
|
||||||
|
if element.style is not None: #f if the style attribute is not set at all, the element will be visible with default black color fill and w/o stroke
|
||||||
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)
|
||||||
@ -486,12 +478,10 @@ class LaserCheck(inkex.EffectExtension):
|
|||||||
inkex.utils.debug("\n---------- Objects with stroke transparencies < 1.0 - should be set to 1.0")
|
inkex.utils.debug("\n---------- Objects with stroke transparencies < 1.0 - should be set to 1.0")
|
||||||
transparencies = []
|
transparencies = []
|
||||||
for element in shapes:
|
for element in shapes:
|
||||||
style = element.get('style')
|
stroke_opacity = element.style.get('stroke-opacity')
|
||||||
if style is not None:
|
if stroke_opacity is None or stroke_opacity == "none":
|
||||||
stroke_opacity = re.search('stroke-opacity:(.*?)(;|$)', style)
|
stroke_opacity = "none"
|
||||||
if stroke_opacity is not None:
|
if stroke_opacity not in transparencies:
|
||||||
if float(stroke_opacity[0].split("stroke-opacity:")[1].split(";")[0]) < 1.0:
|
|
||||||
if element not in transparencies:
|
|
||||||
transparencies.append(element)
|
transparencies.append(element)
|
||||||
if so.show_issues_only is False:
|
if so.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)))
|
||||||
|
Reference in New Issue
Block a user