-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
120 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# Introduction | ||
|
||
Welcome to the Gerber Formatter documentation. This documentation is intended to provide | ||
a comprehensive overview of the Gerber Formatter including usage, options and examples. | ||
|
||
!!! info | ||
|
||
Please note that this API is lower-level than one offered by the `GerberFile` object you | ||
can find [here](../20_quick_start/01_single_file.md). In many cases `GerberFile` | ||
interface will be more intuitive and easier to use, hence it is usually better to stick | ||
with it unless you have specific needs that are not covered by it. | ||
|
||
## What is the Gerber Formatter? | ||
|
||
The Gerber Formatter is a tool that can be used to format Gerber files. It can be used | ||
to reformat Gerber files to make them more readable or the opposite, to compress them to | ||
save precious disk space. Technically, formatter includes also minor code modernization | ||
features although less powerful than the Optimizer. | ||
|
||
## Why? | ||
|
||
Gerber files are often used just as transfer format and rarely it is necessary to read | ||
them directly. However, in those rare cases when you have to look into them, it would be | ||
nice for them to be more readable than what your CAD software of choice happens to spit | ||
out. This is where the Gerber Formatter comes in handy. | ||
|
||
## How? | ||
|
||
The Gerber Formatter can be used both as a command line tool and as a library. The | ||
command line tool can be accessed via `pygerber gerber format` subcommand while library | ||
API is available through `pygerber.gerber.formatter` module. Command line usage is | ||
covered in [Gerber](../25_command_line/20_gerber.md) command line documentation while | ||
API usage and configuration options are covered in [API usage](./05_api_usage.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# API usage | ||
|
||
The Gerber Formatter can be used as a library. The main entry point is the | ||
`pygerber.gerber.formatter` module. | ||
|
||
## API | ||
|
||
The basic usage of the Gerber Formatter is to utilize `format` and `formats` functions | ||
available in `pygerber.gerber.formatter` module. Please have look at the following | ||
example: | ||
|
||
{{ include_code("test/examples/gerberx3/formatter/_10_basic_format.py", "docspygerberlexer", title="format_example.py", linenums="1") }} | ||
|
||
Please note that to format the code, we first had to parse it, and only then could the | ||
abstract syntax tree be passed to the formatter. `format` function writes formatted code | ||
directly to file-like object, while `formats` function returns formatted code as a | ||
string. | ||
|
||
## Configuration | ||
|
||
The formatter can be configured using `Options` object. The object can be passed to | ||
`format` and `formats` functions as a optional `options` argument. You can find full | ||
option reference [here](../reference/pygerber/gerber/formatter/options.html). | ||
|
||
{{ include_code("test/examples/gerberx3/formatter/_20_format_with_options.py", "docspygerberlexer", title="options_example.py", linenums="1") }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pathlib import Path | ||
from pygerber.gerber.parser import parse | ||
from pygerber.gerber.formatter import format | ||
from pygerber.examples import ExamplesEnum, load_example | ||
|
||
gerber_source_code = load_example(ExamplesEnum.UCAMCO_2_11_2) | ||
|
||
ast = parse(gerber_source_code) | ||
|
||
with Path("output.formatted.gbr").open("w") as output: | ||
format(ast, output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pygerber.gerber.parser import parse | ||
from pygerber.gerber.formatter import formats | ||
from pygerber.examples import ExamplesEnum, load_example | ||
|
||
gerber_source_code = load_example(ExamplesEnum.UCAMCO_2_11_2) | ||
|
||
ast = parse(gerber_source_code) | ||
|
||
print(formats(ast)) |
18 changes: 18 additions & 0 deletions
18
test/examples/gerberx3/formatter/_20_format_with_options.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
from pygerber.gerber.parser import parse | ||
from pygerber.gerber.formatter import format, Options, MacroSplitMode | ||
from pygerber.examples import ExamplesEnum, load_example | ||
|
||
gerber_source_code = load_example(ExamplesEnum.UCAMCO_2_11_2) | ||
|
||
ast = parse(gerber_source_code) | ||
|
||
with Path("output.formatted.gbr").open("w") as output: | ||
format( | ||
ast, | ||
output, | ||
options=Options( | ||
indent_character="\t", | ||
macro_split_mode=MacroSplitMode.NoSplit, | ||
), | ||
) |
Empty file.