more options to lasercheck

This commit is contained in:
Mario Voigt 2021-11-02 02:41:57 +01:00
parent 40fd5db819
commit 314258bec2
2 changed files with 76 additions and 22 deletions

View File

@ -10,10 +10,11 @@
<option value="check_section">Check selection</option> <option value="check_section">Check selection</option>
</param> </param>
<separator/> <separator/>
<label appearance="header">Custom Checks</label>
<hbox> <hbox>
<vbox> <vbox>
<param name="bbox" type="bool" gui-text="Bounding box">false</param> <param name="bbox" type="bool" gui-text="Bounding box">false</param>
<param name="bbox_offset" type="float" min="0.000" max="9999.000" precision="3" gui-text=" > Minimum required offset (mm)">5.000</param> <param name="bbox_offset" type="float" min="0.000" max="9999.000" precision="3" gui-text="Minimum required offset (mm)">5.000</param>
<param name="machine_size" gui-text="Machine/Size (mm)" type="optiongroup" appearance="combo"> <param name="machine_size" gui-text="Machine/Size (mm)" type="optiongroup" appearance="combo">
<option value="406x305">406 x 305 mm (Zing 16)</option> <option value="406x305">406 x 305 mm (Zing 16)</option>
<option value="610x305">610 x 305 mm (Zing 24 / Fusion Edge 12)</option> <option value="610x305">610 x 305 mm (Zing 24 / Fusion Edge 12)</option>
@ -21,25 +22,35 @@
<option value="1016x711">1016 x 711 mm (Fusion M2 40)</option> <option value="1016x711">1016 x 711 mm (Fusion M2 40)</option>
<option value="1219x914">1219 x 914 mm (Fusion Pro 48)</option> <option value="1219x914">1219 x 914 mm (Fusion Pro 48)</option>
</param> </param>
<separator/>
<param name="groups_and_layers" type="bool" gui-text="Groups and layers">false</param> <param name="groups_and_layers" type="bool" gui-text="Groups and layers">false</param>
<param name="clones" type="bool" gui-text="Clones">false</param> <param name="clones" type="bool" gui-text="Clones">false</param>
<param name="clippaths" type="bool" gui-text="Clippings">false</param> <param name="clippaths" type="bool" gui-text="Clippings">false</param>
<param name="images" type="bool" gui-text="Images">false</param> <param name="images" type="bool" gui-text="Images">false</param>
<param name="texts" type="bool" gui-text="Texts">false</param> <param name="texts" type="bool" gui-text="Texts">false</param>
<param name="lowlevelstrokes" type="bool" gui-text="Low level strokes">false</param> <param name="lowlevelstrokes" type="bool" gui-text="Low level strokes">false</param>
<separator/>
<param name="stroke_colors" type="bool" gui-text="Stroke colors">false</param> <param name="stroke_colors" type="bool" gui-text="Stroke colors">false</param>
<param name="stroke_colors_max" type="int" gui-text="Max. allowed">3</param>
</vbox> </vbox>
<separator/> <separator/>
<vbox> <vbox>
<param name="stroke_widths" type="bool" gui-text="Stroke widths">false</param> <param name="stroke_widths" type="bool" gui-text="Stroke widths">false</param>
<param name="stroke_widths_max" type="int" gui-text="Max. allowed">1</param>
<separator/>
<param name="stroke_opacities" type="bool" gui-text="Stroke opacities">false</param> <param name="stroke_opacities" type="bool" gui-text="Stroke opacities">false</param>
<param name="cosmestic_dashes" type="bool" gui-text="Cosmetic dash styles">false</param> <param name="cosmestic_dashes" type="bool" gui-text="Cosmetic dash styles">false</param>
<param name="invisible_shapes" type="bool" gui-text="Invisible shapes">false</param> <param name="invisible_shapes" type="bool" gui-text="Invisible shapes">false</param>
<param name="non_path_shapes" type="bool" gui-text="Non-path shapes">false</param>
<param name="pointy_paths" type="bool" gui-text="Pointy paths">false</param> <param name="pointy_paths" type="bool" gui-text="Pointy paths">false</param>
<param name="transformations" type="bool" gui-text="Transformations">false</param> <param name="transformations" type="bool" gui-text="Transformations">false</param>
<separator/>
<param name="short_paths" type="bool" gui-text="Short paths">false</param> <param name="short_paths" type="bool" gui-text="Short paths">false</param>
<param name="short_paths_min" type="float" min="0.000" max="9999.000" precision="3" gui-text=" > Check below length (mm)">1.000</param> <param name="short_paths_min" type="float" min="0.000" max="9999.000" precision="3" gui-text="Check below length (mm)">1.000</param>
<param name="non_path_shapes" type="bool" gui-text="Non-path shapes">false</param> <separator/>
<param name="nodes_per_path" type="bool" gui-text="Max path nodes">false</param>
<param name="nodes_per_path_max" type="int" min="0" max="99999" gui-text="Max nodes/&lt;interval&gt; mm">2</param>
<param name="nodes_per_path_interval" type="float" min="0.000" max="99999.000" precision="3" gui-text="Interval">10.000</param>
</vbox> </vbox>
</hbox> </hbox>
</page> </page>

View File

@ -9,7 +9,9 @@ import math
class LaserCheck(inkex.EffectExtension): class LaserCheck(inkex.EffectExtension):
''' '''
check for old styles which should be upgraded ToDos:
- check for old styles which should be upgraded
- this code is horrible ugly stuff
''' '''
def add_arguments(self, pars): def add_arguments(self, pars):
@ -26,7 +28,9 @@ class LaserCheck(inkex.EffectExtension):
pars.add_argument('--texts', type=inkex.Boolean, default=False) pars.add_argument('--texts', type=inkex.Boolean, default=False)
pars.add_argument('--lowlevelstrokes', type=inkex.Boolean, default=False) pars.add_argument('--lowlevelstrokes', type=inkex.Boolean, default=False)
pars.add_argument('--stroke_colors', type=inkex.Boolean, default=False) pars.add_argument('--stroke_colors', type=inkex.Boolean, default=False)
pars.add_argument('--stroke_colors_max', type=int, default=3)
pars.add_argument('--stroke_widths', type=inkex.Boolean, default=False) pars.add_argument('--stroke_widths', type=inkex.Boolean, default=False)
pars.add_argument('--stroke_widths_max', type=int, default=1)
pars.add_argument('--stroke_opacities', type=inkex.Boolean, default=False) pars.add_argument('--stroke_opacities', type=inkex.Boolean, default=False)
pars.add_argument('--cosmestic_dashes', type=inkex.Boolean, default=False) pars.add_argument('--cosmestic_dashes', type=inkex.Boolean, default=False)
pars.add_argument('--invisible_shapes', type=inkex.Boolean, default=False) pars.add_argument('--invisible_shapes', type=inkex.Boolean, default=False)
@ -35,6 +39,9 @@ class LaserCheck(inkex.EffectExtension):
pars.add_argument('--short_paths', type=inkex.Boolean, default=False) pars.add_argument('--short_paths', type=inkex.Boolean, default=False)
pars.add_argument('--short_paths_min', type=float, default=1.000) pars.add_argument('--short_paths_min', type=float, default=1.000)
pars.add_argument('--non_path_shapes', type=inkex.Boolean, default=False) pars.add_argument('--non_path_shapes', type=inkex.Boolean, default=False)
pars.add_argument('--nodes_per_path', type=inkex.Boolean, default=False)
pars.add_argument('--nodes_per_path_max', type=int, default=2)
pars.add_argument('--nodes_per_path_interval', type=float, default=10.000)
def effect(self): def effect(self):
@ -133,33 +140,39 @@ class LaserCheck(inkex.EffectExtension):
bb_width = round(bbox.width, 3) bb_width = round(bbox.width, 3)
bb_height = round(bbox.height, 3) bb_height = round(bbox.height, 3)
if bb_left >= fmm: if bb_left >= fmm:
inkex.utils.debug("left border... ok") if self.options.show_issues_only is False:
inkex.utils.debug("left border... ok")
else: else:
inkex.utils.debug("left border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_left, "mm"))) inkex.utils.debug("left border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_left, "mm")))
if bb_top >= fmm: if bb_top >= fmm:
inkex.utils.debug("top border... ok") if self.options.show_issues_only is False:
inkex.utils.debug("top border... ok")
else: else:
inkex.utils.debug("top border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_top, "mm"))) inkex.utils.debug("top border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_top, "mm")))
if bb_right + fmm <= page_width: if bb_right + fmm <= page_width:
inkex.utils.debug("right border... ok") if self.options.show_issues_only is False:
inkex.utils.debug("right border... ok")
else: else:
inkex.utils.debug("right border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_right, "mm"))) inkex.utils.debug("right border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_right, "mm")))
if bb_bottom + fmm <= width_height: if bb_bottom + fmm <= width_height:
inkex.utils.debug("bottom border... ok") if self.options.show_issues_only is False:
inkex.utils.debug("bottom border... ok")
else: else:
inkex.utils.debug("bottom border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_bottom, "mm"))) inkex.utils.debug("bottom border... fail: {:0.3f} mm".format(self.svg.uutounit(bb_bottom, "mm")))
machineWidth = self.svg.unittouu(self.options.machine_size.split('x')[0] + "mm") machineWidth = self.svg.unittouu(self.options.machine_size.split('x')[0] + "mm")
if bb_width <= machineWidth: if bb_width <= machineWidth:
inkex.utils.debug("page width... ok") if self.options.show_issues_only is False:
inkex.utils.debug("page width... ok")
else: else:
inkex.utils.debug("page width... fail: {:0.3f} mm".format(bb_width)) inkex.utils.debug("page width... fail: {:0.3f} mm".format(bb_width))
machineHeight = self.svg.unittouu(self.options.machine_size.split('x')[1] + "mm") machineHeight = self.svg.unittouu(self.options.machine_size.split('x')[1] + "mm")
if bb_height <= machineHeight: if bb_height <= machineHeight:
inkex.utils.debug("page height... ok") if self.options.show_issues_only is False:
inkex.utils.debug("page height... ok")
else: else:
inkex.utils.debug("page height... fail: {:0.3f} mm".format(bb_height)) inkex.utils.debug("page height... fail: {:0.3f} mm".format(bb_height))
@ -175,7 +188,8 @@ class LaserCheck(inkex.EffectExtension):
for child in element: for child in element:
maxDepth(child, level + 1) maxDepth(child, level + 1)
maxDepth(self.document.getroot(), -1) maxDepth(self.document.getroot(), -1)
self.msg("Maximum group depth={}".format(md - 1)) if self.options.show_issues_only is False:
inkex.utils.debug("Maximum group depth={}".format(md - 1))
if md - 1 > 2: if md - 1 > 2:
self.msg("Warning: this group depth might cause issues!") self.msg("Warning: this group depth might cause issues!")
groups = [] groups = []
@ -285,7 +299,7 @@ class LaserCheck(inkex.EffectExtension):
to a minimum of stroke colors to be quicker to a minimum of stroke colors to be quicker
''' '''
if so.checks == "check_all" or so.stroke_colors is True: if so.checks == "check_all" or so.stroke_colors is True:
inkex.utils.debug("\n---------- Stroke colors") 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') style = element.get('style')
@ -297,15 +311,17 @@ class LaserCheck(inkex.EffectExtension):
strokeColors.append(strokeColor) strokeColors.append(strokeColor)
if self.options.show_issues_only is False: 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: if len(strokeColors) > so.stroke_colors_max:
inkex.utils.debug("stroke color {}".format(strokeColor)) for strokeColor in strokeColors:
inkex.utils.debug("stroke color {}".format(strokeColor))
''' '''
Different stroke widths might behave the same like different stroke colors. Reduce to a minimum set. Different stroke widths might behave the same like different stroke colors. Reduce to a minimum set.
Ideally all stroke widths are set to 1 pixel. Ideally all stroke widths are set to 1 pixel.
''' '''
if so.checks == "check_all" or so.stroke_widths is True: if so.checks == "check_all" or so.stroke_widths is True:
inkex.utils.debug("\n---------- Stroke widths") 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') style = element.get('style')
@ -317,13 +333,14 @@ class LaserCheck(inkex.EffectExtension):
strokeWidths.append(strokeWidth) strokeWidths.append(strokeWidth)
if self.options.show_issues_only is False: 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: if len(strokeWidths) > so.stroke_widths_max:
swConverted = self.svg.uutounit(float(self.svg.unittouu(strokeWidth))) #possibly w/o units. we unify to some internal float for strokeWidth in strokeWidths:
inkex.utils.debug("stroke width {}px ({}mm)".format( swConverted = self.svg.uutounit(float(self.svg.unittouu(strokeWidth))) #possibly w/o units. we unify to some internal float
round(self.svg.uutounit(swConverted, "px"),4), inkex.utils.debug("stroke width {}px ({}mm)".format(
round(self.svg.uutounit(swConverted, "mm"),4), round(self.svg.uutounit(swConverted, "px"),4),
round(self.svg.uutounit(swConverted, "mm"),4),
)
) )
)
''' '''
@ -493,11 +510,37 @@ class LaserCheck(inkex.EffectExtension):
totalDropLength += stotal totalDropLength += stotal
if self.options.show_issues_only is False: 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 totalDropLength > 0:
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"))) 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={}, length={}mm".format(shortPath[0].get('id'), round(self.svg.uutounit(str(shortPath[1]), "mm"), 3))) inkex.utils.debug("id={}, length={}mm".format(shortPath[0].get('id'), round(self.svg.uutounit(str(shortPath[1]), "mm"), 3)))
'''
Paths with a high amount of nodes will cause issues because each node means slowing down/speeding up the laser mechanics
'''
if so.checks == "check_all" or so.nodes_per_path is True:
inkex.utils.debug("\n---------- Heavy node-loaded paths (allowed: {} node(s) per {} mm) - should be simplified".format(so.nodes_per_path_max, round(so.nodes_per_path_interval, 3)))
heavyPaths = []
for element in shapes:
if isinstance(element, inkex.PathElement):
slengths, stotal = csplength(element.path.transform(element.composed_transform()).to_superpath())
nodes = len(element.path)
if nodes / stotal > so.nodes_per_path_max / self.svg.unittouu(str(so.nodes_per_path_interval) + "mm"):
heavyPaths.append([element, nodes, stotal])
if self.options.show_issues_only is False:
inkex.utils.debug("{} Heavy node-loaded paths in total".format(len(heavyPaths)))
for heavyPath in heavyPaths:
inkex.utils.debug("id={}, nodes={}, length={}mm, density={}nodes/mm".format(
heavyPath[0].get('id'),
heavyPath[1],
round(self.svg.uutounit(str(heavyPath[2]), "mm"), 3),
round(heavyPath[1] / self.svg.uutounit(str(heavyPath[2]), "mm"), 3)
)
)
''' '''
Shapes like rectangles, ellipses, arcs, spirals should be converted to svg:path to have more Shapes like rectangles, ellipses, arcs, spirals should be converted to svg:path to have more