-
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
13 changed files
with
126 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
# Single file guide | ||
|
||
This guide shows how to use `GerberFile` object from `pygerber.gerber.api` to to render | ||
and format Gerber individual files. For overview of `pygerber.gerber.api` module, | ||
including `GerberFile` construction options check out | ||
[Introduction](./00_introduction.md). For guide on how to arrange multiple files into | ||
single image using `Project` class check out | ||
[Multi file project](./02_multi_file_project.md). | ||
|
||
## Rendering Gerber file | ||
|
||
`GerberFile` object exposes `render_with_pillow` method which renders Gerber file into | ||
Pillow image object. | ||
|
||
{{ include_code("test/examples/gerberx3/api/_00_single_file_render_with_pillow_defaults_str.example.py", "python", title="render_with_pillow.py", linenums="1") }} | ||
|
||
`render_with_pillow()` method accepts `dpmm` parameter which can be used to set custom | ||
dots-per-millimeter value, hence increase and decrease image resolution. By default this | ||
value is set to 20, which is a safe default, but quite low for small PCBs. | ||
|
||
`render_with_pillow()` returns `PillowImage` object which wraps actual image | ||
(`PIL.Image.Image` object) and additional information about image coordinate space. | ||
|
||
To retrieve image object, you can use `get_image()` method, then you can save it with | ||
[`save()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.save) | ||
method offered by `PIL.Image.Image` object or transform with other methods. To find out | ||
more please refer to [Pillow documentation](https://pillow.readthedocs.io/en/stable/). | ||
|
||
To retrieve information about image space you can use `get_image_space()` method. This | ||
method returns `ImageSpace` object which contains information about image coordinates, | ||
image size, etc, as presented below: | ||
|
||
{{ include_code("test/examples/gerberx3/api/_50_show_image_info.singlefile.py", "python", title="show_image_space.py", linenums="1") }} | ||
|
||
{{ run_capture_stdout("python test/examples/gerberx3/api/_50_show_image_info.singlefile.py", "python show_image_space.py") }} | ||
|
||
## Formatting Gerber file | ||
|
||
`GerberFile` object exposes `format()` and `formats()` methods which generate Gerber | ||
code formatted according to the specified configuration. For detailed documentation of | ||
formatting options, please refer to | ||
[Formatter -> Configuration](../60_formatter/05_configuration.md). | ||
|
||
The difference between `format()` and `formats()` methods is that `format()` method | ||
writes formatted code to `TextIO`-like object while `formats()` returns it as a `str` | ||
object. | ||
|
||
{{ include_code("test/examples/gerberx3/api/_51_single_file_format.singlefile.py", "python", title="format_file.py", linenums="1") }} | ||
|
||
{{ run_capture_stdout("python test/examples/gerberx3/api/_51_single_file_format.singlefile.py", "python format_file.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 @@ | ||
# Introduction |
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 @@ | ||
# Configuration |
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
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,8 @@ | ||
from pygerber.gerber.api import GerberFile | ||
|
||
from pygerber.examples import ExamplesEnum, load_example | ||
|
||
gerber_source_code = load_example(ExamplesEnum.UCAMCO_2_11_2) | ||
|
||
image = GerberFile.from_str(gerber_source_code).render_with_pillow() | ||
print(image.get_image_space()) |
10 changes: 10 additions & 0 deletions
10
test/examples/gerberx3/api/_51_single_file_format.singlefile.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,10 @@ | ||
from pygerber.gerber.api import GerberFile, Options | ||
|
||
source_code = """ | ||
%FSLAX26Y26*%%MOMM*%%ADD100C,1.5*%D100*X0Y0D03*M02* | ||
""" | ||
|
||
gerber_file = GerberFile.from_str(source_code) | ||
formatted_code = gerber_file.formats(Options(d03_indent=2)) | ||
|
||
print(formatted_code) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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