Skip to content

Commit

Permalink
Merge pull request #2 from IridiumIO/dev_ignorehiddenlockedelements
Browse files Browse the repository at this point in the history
Add ability to ignore hidden and locked elements in SVG files
  • Loading branch information
Iridium-IO authored Jan 2, 2024
2 parents 911fe81 + abeab37 commit 700f0a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
10 changes: 8 additions & 2 deletions gcodeplot.inx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@

</page>
<page name="fitting" _gui-text="Fitting and Extracting">
<label appearance="header">Fitting</label>

<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)">
<item value="n">none (needed if tool offset&gt;0)</item>
<item value="n">none (needed if tool offset &gt; 0)</item>
<item value="f">fit</item>
<item value="d">down-only</item>
</param>
Expand All @@ -55,12 +57,16 @@
<item value="center">center</item>
<item value="top">right</item>
</param>

<separator />
<label appearance="header">Extracting</label>
<param name="ignore-hidden" type="bool" gui-text="Ignore hidden elements" _gui-description="If checked, hidden layers, groups and elements will be discarded"></param>
<param name="ignore-locked" type="bool" gui-text="Ignore locked elements" _gui-description="If checked, locked layers, groups and elements will be discarded"></param>
<hbox>
<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>
<spacer size="expand"/>
<param name="extract-color" type="color" gui-text=" " appearance="colorbutton" _gui-description="The color to extract. Alpha values are discarded"></param>
</hbox>

</page>
<page name="drawing" _gui-text="Drawing Settings">
<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>
Expand Down
16 changes: 15 additions & 1 deletion gcodeplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,23 @@ def parse_svg_file(data):
except:
return None


def remove_hidden_locked_SVGElements(svgTree, ignoreHidden=True, ignoreLocked=True):
prop_parents = svgTree.findall('*' + '/..')
for parent in prop_parents:
for prop in parent.findall('*'):
style = prop.get('style', None) #Hidden Elements
type = prop.get('{http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd}insensitive', None) # Locked Elements

if ( ignoreHidden and 'display:none' in str(style)) or (ignoreLocked and type is not None):
parent.remove(prop)
else:
remove_hidden_locked_SVGElements(prop)

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

if svgTree is not None:
remove_hidden_locked_SVGElements(svgTree, ignoreHidden=args.ignore_hidden, ignoreLocked=args.ignore_locked)
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)
else:
penData = parseHPGL(data, dpi=args.input_dpi)
Expand Down Expand Up @@ -805,6 +816,9 @@ def parse_arguments(argparser:cArgumentParser):
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)')
argparser.add_argument('-L', '--stroke-all', action=argparse.BooleanOptionalAction, default=False, help='stroke even regions specified by SVG to have no stroke')
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]')
argparser.add_argument('--ignore-hidden', action=CustomBooleanAction, default=True, help='ignore hidden SVG elements')
argparser.add_argument('--ignore-locked', action=CustomBooleanAction, default=True, help='ignore locked SVG elements (for Inkscape SVG only)')


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]')
argparser.add_argument('-d', '--sort', action=argparse.BooleanOptionalAction, default=False, help='sort paths from inside to outside for cutting [default off]')
Expand Down

0 comments on commit 700f0a9

Please sign in to comment.