add stroke width unit to slicer stl import

This commit is contained in:
Mario Voigt 2021-12-16 12:55:06 +01:00
parent c129af2b80
commit f779f813d8
2 changed files with 15 additions and 2 deletions

View File

@ -60,6 +60,14 @@
<separator/> <separator/>
<vbox> <vbox>
<label appearance="header">Stroke Width</label> <label appearance="header">Stroke Width</label>
<param name="stroke_units" type="optiongroup" appearance="combo" gui-text="Units">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="in">in</option>
<option value="pt">pt</option>
<option value="px">px</option>
<option value="hairline">hairline</option>
</param>
<param name="min_stroke_width" type="float" precision="3" min="0.000" max="1000.000" gui-text="Min stroke width">1.0</param> <param name="min_stroke_width" type="float" precision="3" min="0.000" max="1000.000" gui-text="Min stroke width">1.0</param>
<param name="max_stroke_width" type="float" precision="3" min="0.000" max="1000.000" gui-text="Max stroke width">1.0</param> <param name="max_stroke_width" type="float" precision="3" min="0.000" max="1000.000" gui-text="Max stroke width">1.0</param>
<label>Per Layer Settings</label> <label>Per Layer Settings</label>

View File

@ -98,6 +98,7 @@ class SlicerSTLInput(inkex.EffectExtension):
pars.add_argument("--use_stroke_color", type=inkex.Boolean, default=True, help="Use stroke color") pars.add_argument("--use_stroke_color", type=inkex.Boolean, default=True, help="Use stroke color")
pars.add_argument('--stroke_color', type=Color, default='879076607', help="Stroke color") pars.add_argument('--stroke_color', type=Color, default='879076607', help="Stroke color")
pars.add_argument("--stroke_units", default="mm", help="Stroke width units")
pars.add_argument("--min_stroke_width", type=float, default=1.0, help="Min stroke width") pars.add_argument("--min_stroke_width", type=float, default=1.0, help="Min stroke width")
pars.add_argument("--max_stroke_width", type=float, default=1.0, help="Max stroke width") pars.add_argument("--max_stroke_width", type=float, default=1.0, help="Max stroke width")
pars.add_argument("--diffuse_stroke_width", default="regular", help="Diffuse stroke width per layer") pars.add_argument("--diffuse_stroke_width", default="regular", help="Diffuse stroke width per layer")
@ -255,8 +256,10 @@ class SlicerSTLInput(inkex.EffectExtension):
elif args.diffuse_stroke_width == "no_diffuse": elif args.diffuse_stroke_width == "no_diffuse":
stroke_width = args.max_stroke_width stroke_width = args.max_stroke_width
else: else:
inkex.utils.debug("Error: unkown diffuse fill opacity option") inkex.utils.debug("Error: unkown diffuse stroke width option")
exit(1) exit(1)
if self.options.stroke_units != "hairline":
stroke_width = self.svg.unittouu(str(stroke_width) + self.options.stroke_units)
if args.diffuse_stroke_opacity == "front_to_back": if args.diffuse_stroke_opacity == "front_to_back":
stroke_opacity = (args.max_stroke_opacity - (polygoncount / totalPolygoncount) * (args.max_stroke_opacity - args.min_stroke_opacity)) + args.min_stroke_opacity stroke_opacity = (args.max_stroke_opacity - (polygoncount / totalPolygoncount) * (args.max_stroke_opacity - args.min_stroke_opacity)) + args.min_stroke_opacity
@ -265,7 +268,7 @@ class SlicerSTLInput(inkex.EffectExtension):
elif args.diffuse_stroke_opacity == "no_diffuse": elif args.diffuse_stroke_opacity == "no_diffuse":
stroke_opacity = args.max_stroke_opacity stroke_opacity = args.max_stroke_opacity
else: else:
inkex.utils.debug("Error: unkown diffuse fill opacity option") inkex.utils.debug("Error: unkown diffuse stroke opacity option")
exit(1) exit(1)
if args.use_stroke_color is False: if args.use_stroke_color is False:
@ -278,6 +281,8 @@ class SlicerSTLInput(inkex.EffectExtension):
e.attrib['id'] = 'polygon%d' % polygoncount e.attrib['id'] = 'polygon%d' % polygoncount
e.attrib['{http://www.inkscape.org/namespaces/inkscape}connector-curvature'] = '0' e.attrib['{http://www.inkscape.org/namespaces/inkscape}connector-curvature'] = '0'
e.attrib['style'] = 'fill:{};fill-opacity:{};{};stroke-opacity:{};stroke-width:{}'.format(fill, fill_opacity, stroke, stroke_opacity, stroke_width) e.attrib['style'] = 'fill:{};fill-opacity:{};{};stroke-opacity:{};stroke-width:{}'.format(fill, fill_opacity, stroke, stroke_opacity, stroke_width)
if self.options.stroke_units == "hairline":
e.attrib['style'] = e.attrib.get('style') + ";vector-effect:non-scaling-stroke;-inkscape-stroke:hairline;"
e.attrib['d'] = 'M ' + re.sub(' ', ' L ', scale_points(e.attrib['points'], 1/scale)) + ' Z' e.attrib['d'] = 'M ' + re.sub(' ', ' L ', scale_points(e.attrib['points'], 1/scale)) + ' Z'
if args.mirrorx is True: if args.mirrorx is True: