Skip to content

Commit 700f0a9

Browse files
authored
Merge pull request #2 from IridiumIO/dev_ignorehiddenlockedelements
Add ability to ignore hidden and locked elements in SVG files
2 parents 911fe81 + abeab37 commit 700f0a9

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

gcodeplot.inx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838

3939
</page>
4040
<page name="fitting" _gui-text="Fitting and Extracting">
41+
<label appearance="header">Fitting</label>
42+
4143
<param name="scale" type="enum" _gui-text="Scaling mode:" _gui-description="Method for scaling to print area (Default: none; should be 'none' if tool-offset option is set in cutter tab)">
42-
<item value="n">none (needed if tool offset&gt;0)</item>
44+
<item value="n">none (needed if tool offset &gt; 0)</item>
4345
<item value="f">fit</item>
4446
<item value="d">down-only</item>
4547
</param>
@@ -55,12 +57,16 @@
5557
<item value="center">center</item>
5658
<item value="top">right</item>
5759
</param>
58-
60+
<separator />
61+
<label appearance="header">Extracting</label>
62+
<param name="ignore-hidden" type="bool" gui-text="Ignore hidden elements" _gui-description="If checked, hidden layers, groups and elements will be discarded"></param>
63+
<param name="ignore-locked" type="bool" gui-text="Ignore locked elements" _gui-description="If checked, locked layers, groups and elements will be discarded"></param>
5964
<hbox>
6065
<param name="boolean-extract-color" type="bool" gui-text="Extract only one color from drawing" _gui-description="Uncheck to include all colors; otherwise, choose the color to extract."></param>
6166
<spacer size="expand"/>
6267
<param name="extract-color" type="color" gui-text=" " appearance="colorbutton" _gui-description="The color to extract. Alpha values are discarded"></param>
6368
</hbox>
69+
6470
</page>
6571
<page name="drawing" _gui-text="Drawing Settings">
6672
<param name="shading-threshold" type="float" min="0" max="1" precision="2" _gui-text="Shading threshold:" _gui-description="Shade whenever the shade is below this value, where 0=black and 1=white. To turn off shading, set to 0. (Default: 1, shade everything other than white).">1</param>

gcodeplot.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,12 +702,23 @@ def parse_svg_file(data):
702702
except:
703703
return None
704704

705-
705+
def remove_hidden_locked_SVGElements(svgTree, ignoreHidden=True, ignoreLocked=True):
706+
prop_parents = svgTree.findall('*' + '/..')
707+
for parent in prop_parents:
708+
for prop in parent.findall('*'):
709+
style = prop.get('style', None) #Hidden Elements
710+
type = prop.get('{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}insensitive', None) # Locked Elements
711+
712+
if ( ignoreHidden and 'display:none' in str(style)) or (ignoreLocked and type is not None):
713+
parent.remove(prop)
714+
else:
715+
remove_hidden_locked_SVGElements(prop)
706716

707717
def generate_pen_data(svgTree, data, args, shader:Shader):
708718
penData = {}
709719

710720
if svgTree is not None:
721+
remove_hidden_locked_SVGElements(svgTree, ignoreHidden=args.ignore_hidden, ignoreLocked=args.ignore_locked)
711722
penData = parseSVG(svgTree, tolerance=args.tolerance, shader=shader, strokeAll=args.stroke_all, pens=args.pens, extractColor=args.extract_color if args.boolean_extract_color else None)
712723
else:
713724
penData = parseHPGL(data, dpi=args.input_dpi)
@@ -805,6 +816,9 @@ def parse_arguments(argparser:cArgumentParser):
805816
argparser.add_argument('-R', '--extract-color', metavar='C', default=None, type=parser.rgbFromColor, help='extract color (specified in SVG format , e.g., rgb(1,0,0) or #ff0000 or red)')
806817
argparser.add_argument('-L', '--stroke-all', action=argparse.BooleanOptionalAction, default=False, help='stroke even regions specified by SVG to have no stroke')
807818
argparser.add_argument('-e', '--direction', metavar='ANGLE', default=None, type=lambda value: None if value.lower() == 'none' else float(value), help='for slanted pens: prefer to draw in given direction (degrees; 0=positive x, 90=positive y, none=no preferred direction) [default none]')
819+
argparser.add_argument('--ignore-hidden', action=CustomBooleanAction, default=True, help='ignore hidden SVG elements')
820+
argparser.add_argument('--ignore-locked', action=CustomBooleanAction, default=True, help='ignore locked SVG elements (for Inkscape SVG only)')
821+
808822

809823
argparser.add_argument('-o', '--optimization-time', metavar='T', default=60, type=int, help='max time to spend optimizing (seconds; set to 0 to turn off optimization) [default 60]')
810824
argparser.add_argument('-d', '--sort', action=argparse.BooleanOptionalAction, default=False, help='sort paths from inside to outside for cutting [default off]')

0 commit comments

Comments
 (0)