diff options
author | jaseg <git@jaseg.de> | 2022-07-05 11:17:01 +0200 |
---|---|---|
committer | jaseg <git@jaseg.de> | 2023-11-14 21:52:12 +0100 |
commit | 2f5f7719c656d87d547ed9a24ba8a92364c1a456 (patch) | |
tree | f6cb5bba849e0c3f29635f07ea175afbd68b14cd | |
parent | cb1d3eb3fb1522506419aa19c18e09386c91365b (diff) | |
download | gerbonara-2f5f7719c656d87d547ed9a24ba8a92364c1a456.tar.gz gerbonara-2f5f7719c656d87d547ed9a24ba8a92364c1a456.tar.bz2 gerbonara-2f5f7719c656d87d547ed9a24ba8a92364c1a456.zip |
Split CLI into pretty svg and layer export sub-commands
-rw-r--r-- | gerbonara/__main__.py | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/gerbonara/__main__.py b/gerbonara/__main__.py index 69c55fb..a359a4e 100644 --- a/gerbonara/__main__.py +++ b/gerbonara/__main__.py @@ -1,8 +1,41 @@ #!/usr/bin/env python3 import click +from zipfile import is_zipfile +from pathlib import Path -from .cli import cli +from .layers import LayerStack +from .rs274x import GerberFile + + +@click.group() +def cli(): + pass + +@cli.command(help='Render a folder or zip of Gerber and Excellon files to a pretty, semi-photorealistic SVG.') +@click.option('-t' ,'--top', help='Render board top side.', is_flag=True) +@click.option('-b' ,'--bottom', help='Render board bottom side.', is_flag=True) +@click.argument('input_zip_or_dir', type=click.Path(exists=True, path_type=Path)) +@click.argument('output_svg', required=False, default='-', type=click.File('w')) +def pretty(input_zip_or_dir, output_svg, top, bottom): + if (bool(top) + bool(bottom)) != 1: + raise click.UsageError('Excactly one of --top or --bottom must be given when rendering a dir or zip of gerbers.') + + stack = LayerStack.open(input_zip_or_dir, lazy=True) + print(f'Loaded {stack}') + + svg = stack.to_pretty_svg(side=('top' if top else 'bottom')) + + output_svg.write(str(svg)) + +@cli.command(help='Render an individual Gerber or Excellon file to SVG') +@click.option('-f', '--foreground', default='black', help='Foreground color') +@click.option('-b', '--background', default='white', help='Background color used for "clear" areas.') +@click.argument('input_gerber', type=click.Path(exists=True, dir_okay=False, path_type=Path)) +@click.argument('output_svg', required=False, default='-', type=click.File('w')) +def render(input_gerber, output_svg, foreground, background): + layer = GerberFile.open(input_gerber) + output_svg.write(str(layer.to_svg(fg=foreground, bg=background))) if __name__ == '__main__': cli() |