Giter Site home page Giter Site logo

argmaster / pygerber Goto Github PK

View Code? Open in Web Editor NEW
30.0 4.0 8.0 42.33 MB

Python implementation of Gerber X3/X2 standard with 2D rendering engine.

Home Page: https://argmaster.github.io/pygerber/latest

License: MIT License

Python 100.00%
python python3 python-3 python-library gerber gerber-renderer gerber-x3 gerber-x2 gerber-files pillow

pygerber's Introduction

PyGerber

GitHub release GitHub Release Date - Published_At PyPI release PyPI Downloads Supported Python versions Supported Python implementations license_mit coverage GitHub tag checks state Pull requests Open issues GitHub repo size GitHub code size in bytes GitHub Repo stars Poetry Code Style

PyGerber is a Python implementation of Gerber X3/X2 format. It is based on Ucamco's The Gerber Layer Format Specification. Revision 2023.03 (Available on Ucamco's webpage and in this repository). The goal of this project is to provide support for wide variety of Gerber-like syntaxes, with support for most of deprecated features along with support for modern ones.

๐Ÿ“š See online documentation ๐Ÿ“š

Target set of tools:

  • Tokenizer
  • Parser
  • Optimizer
  • Introspection API
  • Rasterized 2D rendering engine (With Pillow)
  • Vector 2D rendering engine (With drawsvg)
  • Model 3D rendering engine (With Blender)
  • Formatter
  • Linter (eg. deprecated syntax detection)
  • Gerber X3/X2 Language Server (with language-server extras)

You can view progress of development in Gerber features support section down below. All Gerber source files which can be redistributed under MIT license and included in this repository for testing purposes will be greatly appreciated.

Installation

PyGerber can be installed with pip from PyPI:

pip install pygerber

Alternatively, it is also possible to install it directly from repository:

pip install git+https://github.com/Argmaster/pygerber

Command line usage

After installing pygerber, depending on your environment, it should become available in your command line:

pygerber --version

Output should be similar to one below โ‡ฉ, where x.y.z should match version of PyGerber installed.

$ pygerber --version
pygerber, version x.y.z

Use --help to display help messages with lists of subcommands and subcommand options:

pygerber raster-2d --help

To render 2D PNG image of some gerber file you can simply use:

pygerber raster-2d gerber-source.grb

Image will be saved to output.png in current working directory.

example_pcb_image

Programmatic usage

JPG

PyGerber can be used programmatically to render Gerber files. Below is an minimalistic example of how to render one of the example files included with PyGerber release to JPEG image:

from pygerber.examples import ExamplesEnum, get_example_path
from pygerber.gerberx3.api.v2 import GerberFile

GerberFile.from_file(
    get_example_path(ExamplesEnum.UCAMCO_ex_2_Shapes),
).parse().render_raster("output.jpg")

Running code above will create output.jpg file in current working directory which should look like this:

PNG

It is also possible to render Gerber files to PNG with custom resolution and different color schemes:

from pygerber.examples import ExamplesEnum, get_example_path
from pygerber.gerberx3.api.v2 import ColorScheme, GerberFile, PixelFormatEnum

GerberFile.from_file(
    get_example_path(ExamplesEnum.ShapeFlashes),
).parse().render_raster(
    "output.png",
    dpmm=100,
    color_scheme=ColorScheme.COPPER_ALPHA,
    pixel_format=PixelFormatEnum.RGBA,
)

Code above renders following image:

SVG

Finally you can also create SVG files with PyGerber:

from pygerber.examples import ExamplesEnum, load_example
from pygerber.gerberx3.api.v2 import GerberFile

source_code = load_example(ExamplesEnum.UCAMCO_ex_2_Shapes)
GerberFile.from_str(source_code).parse().render_svg("output.svg")

Multiple layers

PyGerber can also render multiple layers to single image. Below is an example of how to render four layers to single PNG image with use of Project class:

from pygerber.examples import ExamplesEnum, load_example
from pygerber.gerberx3.api.v2 import FileTypeEnum, GerberFile, Project

Project(
    [
        GerberFile.from_str(
            load_example(ExamplesEnum.simple_2layer_F_Cu),
            FileTypeEnum.COPPER,
        ),
        GerberFile.from_str(
            load_example(ExamplesEnum.simple_2layer_F_Mask),
            FileTypeEnum.MASK,
        ),
        GerberFile.from_str(
            load_example(ExamplesEnum.simple_2layer_F_Paste),
            FileTypeEnum.PASTE,
        ),
        GerberFile.from_str(
            load_example(ExamplesEnum.simple_2layer_F_Silkscreen),
            FileTypeEnum.SILK,
        ),
    ],
).parse().render_raster("output.png", dpmm=40)

Here is the result:

Advanced usage

Additionally to examples presented above which use high level API, PyGerber provides low level API which allows to directly access PyGerber internals and change behavior of parser, tokenizer and renderers. This can be used for code introspection and potentially other purposed. Check out documentation for more information.

Language Server

Since release 2.1.0 PyGerber provides Gerber X3/X2 Language Server with LSP support. It can be enabled by installing PyGerber extras set language-server with following command:

pip install pygerber[language-server]

Afterwards you can use pygerber is-language-server-available to check if language server was correctly enabled. Please report all issues in PyGerber Issues section.

You can utilize power of this language server with use of Visual Studio Code extension Gerber X3/X2 Format Support (argmaster.gerber-x3-x2-format-support).

Documentation

Official documentations is hosted on Github Pages and can be found here.

Gerber features support

For detailed list of features which are supported/not supported by each tool please refer to documentation:

Development

For development guidelines please visit documentation Development section here.

Gerber reference archive

This repository contains also archival reference files. Although new specs contain dedicated changelog section it may still be helpful in some rare cases to look through old Gerber specs. Archival files can be found here.

pygerber's People

Contributors

ajw287 avatar argmaster avatar dependabot[bot] avatar szachzuk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pygerber's Issues

Rasterized2DBackend

Rasterized2DBackend feature support

  • Aperture definition with circle
  • Aperture definition with rectangle
  • Aperture definition with obround
  • Aperture definition with polygon
  • Aperture definition with macro
  • Block aperture definition
  • Draw flash
    • circle aperture
    • rectangle aperture
    • obround aperture
    • polygon aperture
    • macro aperture
    • block aperture
  • Draw line
  • Draw clockwise arc
  • Draw counterclockwise arc
  • Global mirroring
  • Global rotation
  • Global scaling
  • Create region

Deprecated Gerber features:

  • Image polarity
  • Image rotation
  • Image mirroring

IMPORTANT This feature list is incomplete, it will get longer over time
...

Add file type recognition from file attributes

I have verified that this feature is not listed as implemented in README.md on main
branch
(yes/no) YES


Describe how this feature should work

Detect file attributes which indicate file type (copper/silk etc.)

Describe syntax of this feature

N/A

Describe why this supporting this feature is important

This would further simplify command line interface.

Visual effect screenshots

N/A

Additional context

N/A

Release 2.2.0

  • Added alternative parser implementation, pygerber.gerberx3.parser2.parser2.Parser2 class.
  • Added introspection interface based on new Parser2 class.
  • Added macro support to Parser2 class which was not previously available in Parser class.
  • Added API for customizing Token classes used by Tokenizer. Tokenizer class now accepts optional options parameter of class TokenizerOptions.
  • Added documentation for introspection.
  • Added experimental SVG backend for Gerber code with Parser2 generated command buffers.
  • Changed documentation layout to improve readability.
  • Fixed switching to single quadrant mode being ignored.
  • Refactored feature support documentation.

Difference in rendering between KiCAD gerber viewer and pygerber

I noticed this difference in rendering between the pygerber and the same gerber viewed in KiCAD gerber viewer. I don't know if the KiCAD gerber viewer is specifically removing these artifacts or something, but I thought I'd draw your attention to it as PCB designers look out for these kinds of artefacts (and remove them) as they can be caused during layout .

drawing_gerbers-highlght
drawing_gerbers

Add file type recognition from file extension

I have verified that this feature is not listed as implemented in README.md on main
branch
(yes/no) Yes


Describe how this feature should work

While given path to a file, pygerber should have option to enable automatic file format (style) detection based on file extension.

Describe syntax of this feature

N/A

Describe why this supporting this feature is important

It would make rendering multiple files with standard extensions much easier.

Additional context

Example extension mappings:

Image from Rasterized2DLayer.render/Layer

I've finally got around to setting up your v2.0 code - it looks really good! Thanks for your updated documents - I know its not exciting, but they really helped me to get going.

So I'm planning to sunset the multi-backend version that I've been developing of diffgerber and concentrate on using pygerber 2.0 (it reduced the import code length by ~90%!) and will let me build an application that caters to the API properly without lots of redevelopment.

For my purposes it would be better to just use an Image object in the GUI (since both tk and pygerber use pillow). I got this working by using:

            out =  Rasterized2DLayer(
                options=Rasterized2DLayerParams(
                        dpi=300,
                        source_path=file_path,
                        colors=cunning_scheme,
                ),
            )
            layerImage =  out.render()._result_handle.result

This code seems to work, but the images are flipped vertically. It's not a problem as I can flip it in my code, but it implies that I'm probably missing something.

Add public stable API for providing callbacks to Gerber parser

It would be grate if Gerber parser would have some API for providing per-token callbacks to allow for creation of more advanced tools without creating separate Gerber parser.

Feature was suggested by @Karel-Tavernier

Currently preferable approach would be to provide a subclass of a dedicated class, eg. ParserCallbacks which would have to provide overrides for special methods, representing callbacks. Each callback would receive a parser state, instance of backend and iterable of DrawCommands. It would have to return tuple containing state and iterable of DrawCommands. This way each callback would be able to both alter visuals of image and extract metadata about the file.

class ParserCallbacks:

    def on_d01_draw(self, state: State, backend: Backend, draws: Iterable[DrawCommand]) -> tuple[State, Iterable[DrawCommand]]:
        pass

It's important to note here that Iterable can be exhausted by iterating over it, so callback would be responsible for passing non-exhausted iterable if it want's to preserve draw commands after callback.

Additionally, It would be useful to provide additional higher level callback class, eg.

class ParserDrawCallbacks:

    on_draw_line(self, state: State, backend: Backend, draws: Iterable[DrawCommand]) -> tuple[State, Iterable[DrawCommand]]:
        pass

To reduce amount of required knowledge about Gerber format for those who want to make some simple project around it.

As a separate issue, it would be nice to have some Tokenizer (Token) level callback system for creating tools like optimizers.

Drawing with 0 surface apertures may still create lines

Describe the bug

PyGerber may be creating lines even if they are drawin with 0 surface may still be creating lines.

Gerber code sourced from issue #213 by @HelloDorwin

To Reproduce

Render main.zip with pygerber, you should get result similar to included screenshot.

Expected behavior

Lines between PCB pieces should not be visible, they are probably aperture repositioning.

Screenshots

image

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • PyGerber Version: 2.1.1.dev1694863493

Additional context

This happends probably because Pillow creates 1px/2px line even if it is asked to make it 0 width or it may be caused by rounding of aperture size.

Trouble getting started with 2D API

Hi,

I've installed both the pip repository version of pygerber (1.0.0) as well as the git version (1.1.0) and when trying to run the first example command for the 2D API I get the same error:

>>> from pygerber import pillow
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'pillow' from 'pygerber' (/home/j/.conda/envs/gerbers/lib/python3.9/site-packages/pygerber/__init__.py)

Again, I get this error whether I install pygerber as pip install pygerber, or if I get the latest github work from...

conda create -n "gerbers" python=3.9
conda activate gerbers
pip install git+https://github.com/Argmaster/pygerber.git

In case you think it could be my install, I've explicitly created a python 3.9 environment (it didn't want to install in 3.10), and have the following packages installed:

(gerbers) [j@DCAM03 MK18_ShortStave]$ pip freeze
asttokens==2.0.8
backcall==0.2.0
certifi @ file:///croot/certifi_1665076670883/work/certifi
charset-normalizer==2.1.1
click==8.1.3
commonmark==0.9.1
decorator==5.1.1
executing==1.1.0
idna==3.4
ipython==8.5.0
jedi==0.18.1
matplotlib-inline==0.1.6
numpy==1.23.3
packaging==21.3
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.2.0
prompt-toolkit==3.0.31
ptyprocess==0.7.0
pure-eval==0.2.2
pydantic==1.10.2
pygerber @ git+https://github.com/Argmaster/pygerber.git@4761a5aa60ff1d11512fb44aabd103246d9a3019
Pygments==2.13.0
pyparsing==3.0.9
PyR3==0.3.0
PyYAML==6.0
requests==2.28.1
rich==12.6.0
six==1.16.0
stack-data==0.5.1
toml==0.10.2
traitlets==5.4.0
typing_extensions==4.3.0
urllib3==1.26.12
wcwidth==0.2.5

Any ideas on what to do? This feels like a 'me error' but usually I can figure those out pretty quickly.

Unify visitor implementation for Parser2 with ASTVisitor

After careful consideration I have came to conclusion that current introspection API based on Parser2Hooks introduces too much unnecessary complexity in form of nested classes. I can't change it now, as it will break API compatibility in awful way. Therefore I will schedule this change for PyGerber 3.0.0. I will also provide some kind of adapter for current API to future API, allowing for transition by changing just inheritance or by some decorator, it was not decided yet.

Current approach:

class CustomHooks(Parser2Hooks):
    def __init__(self) -> None:
        super().__init__()
        self.comments: list[str] = []

    class CommentTokenHooks(Parser2Hooks.CommentTokenHooks):
        hooks: CustomHooks

        def on_parser_visit_token(
            self,
            token: Comment,
            context: Parser2Context,
        ) -> None:
            self.hooks.comments.append(token.content)
            return super().on_parser_visit_token(token, context)

Future approach:

class CustomHooks(Parser2Hooks):
    def __init__(self) -> None:
        super().__init__()
        self.comments: list[str] = []

    def visit_comment_token(self, token: Comment) -> None:
        self.hooks.comments.append(token.content)
        return super().visit_comment_token(token, context)

Parser2 - Feature support

Parser2 feature support

Introduction

Parser2 is an alternative implementation of Gerber AST parser redesigned to make process
of implementation of Gerber features easier and quicker in addition to much better
extension interface. Moreover it provides a easy way to introspect Gerber code with use
of hook based interface.

!!! tip "Contributing"

Community contributions are always welcome, they can speed up process of migrating
from Parser to Parser2.
Symbol Meaning
โœ… Feature implemented and usable.
๐Ÿšง Work in progress. Related APIs can change.
๐Ÿšซ Not planned, unless contributed or needed.
โŒ Not implemented, but planned.
๐Ÿ‘ฝ Partially implemented.
๐Ÿ‘พ Bugged.

Supported Gerber X3 features

General

  • โœ… MO - Mode - Sets the unit to mm or inch.
  • โœ… FS - Format specification:
    • โœ… absolute coordinates.
    • ๐Ÿšซ incremental coordinates
    • ๐Ÿšซ trailing zeros omission.
    • โœ… leading zeros omission.
  • ๐Ÿ‘ฝ AD - Aperture define - Defines a template-based aperture, assigns a D code to it.
    • โœ… circle.
    • โœ… rectangle.
    • โœ… obround.
    • โœ… polygon.
    • โœ… Define macro.
  • โœ… AM - Aperture macro - Defines a macro aperture template.
  • โœ… Dnn (nnโ‰ฅ10) - Sets the current aperture to D code nn.
  • โœ… G01 - Sets draw mode to linear.
    • โœ… Variable zero padding variants allowed.
  • โœ… G02 - Sets draw mode to clockwise circular.
    • โœ… Variable zero padding variants allowed.
  • โœ… G03 - Sets draw mode to counterclockwise circular.
    • โœ… Variable zero padding variants allowed.
  • โœ… LP - Load polarity.
  • โœ… LM - Load mirroring.
  • โœ… LR - Load rotation.
  • โœ… LS - Load scaling.
  • โœ… TF - Attribute on file.
  • โœ… TA - Attribute on aperture.
  • โœ… TO - Attribute on object.
  • โœ… TD - Attribute delete.
  • โœ… M02 - End of file.

D01, D02, D03

  • ๐Ÿ‘ฝ D01 - Plot operation, mode
    • ๐Ÿ‘ฝ Line, with:
      • โœ… circle,
      • ๐Ÿ‘ฝ rectangle,
      • ๐Ÿ‘ฝ obround,
      • ๐Ÿ‘ฝ polygon,
      • ๐Ÿ‘ฝ macro.
    • ๐Ÿ‘ฝ Arc, with:
      • โœ… circle,
      • ๐Ÿ‘ฝ rectangle,
      • ๐Ÿ‘ฝ obround,
      • ๐Ÿ‘ฝ polygon,
      • ๐Ÿ‘ฝ macro.
    • ๐Ÿ‘ฝ Counter clockwise arc, with:
      • โœ… circle,
      • ๐Ÿ‘ฝ rectangle,
      • ๐Ÿ‘ฝ obround,
      • ๐Ÿ‘ฝ polygon,
      • ๐Ÿ‘ฝ macro.
    • โœ… Variable zero padding variants allowed.
  • โœ… D02 - Move operation
    • โœ… Variable zero padding variants allowed.
  • ๐Ÿ‘ฝ D03 - Flash operation, with
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
    • โœ… Variable zero padding variants allowed.

Regions

  • โœ… G36 - Starts a region statement.
  • โœ… G37 - Ends the region statement.
  • โœ… Regions, with:
    • โœ… Line.
    • โœ… Arc.
    • โœ… Counter clockwise arc.

Macros

  • โœ… Parameters.
  • ๐Ÿ‘ฝ Primitives in definition:
    • โœ… Code 1, Circle
    • โŒ Code 2, Vector line
    • โœ… Code 4, Outline
    • โœ… Code 5, Polygon
    • โŒ Code 6, Moire
    • โœ… Code 7, Thermal
    • โœ… Code 20, Vector line
    • โœ… Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • ๐Ÿ‘ฝ Primitives in aperture instance:
    • โœ… Code 1, Circle
    • โŒ Code 2, Vector line
    • โœ… Code 4, Outline
    • โœ… Code 5, Polygon
    • โŒ Code 6, Moire
    • โŒ Code 7, Thermal
    • โœ… Code 20, Vector line
    • โœ… Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • โŒ Rotation around macro origin:
    • โŒ Code 1, Circle
    • โŒ Code 2, Vector line
    • โŒ Code 4, Outline
    • โŒ Code 5, Polygon
    • โŒ Code 6, Moire
    • โŒ Code 7, Thermal
    • โŒ Code 20, Vector line
    • โŒ Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • โœ… Expressions.
    • โœ… Constants.
    • โœ… Variables.
    • โœ… Addition.
    • โœ… Subtraction.
    • โœ… Multiplication.
    • โœ… Division.
    • โœ… Unary + operator.
    • โœ… Negation.
  • โœ… Variable definitions.

Aperture blocks

  • โœ… Nested Line, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Arc, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Counter clockwise arc, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Flash:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested regions.

Step and repeat

  • โœ… Nested Line, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Arc, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Counter clockwise arc, aperture:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested Flash:
    • โœ… circle,
    • โœ… rectangle,
    • โœ… obround,
    • โœ… polygon,
    • โœ… macro.
  • โœ… Nested regions.
  • โœ… Nested blocks.

Supported DEPRECATED Gerber features

  • ๐Ÿ‘ฝ G54 - Select aperture. (Spec. 8.1.1)

  • โŒ G55 - Prepare for flash. (Spec. 8.1.1)

  • โœ… G70 - Set the 'Unit' to inch. (Spec. 8.1.1)

  • โœ… G71 - Set the 'Unit' to mm. (Spec. 8.1.1)

  • โœ… G90 - Set the 'Coordinate format' to 'Absolute notation'. (Spec. 8.1.1)

  • โœ… G91 - Set the 'Coordinate format' to 'Incremental notation'. (Spec. 8.1.1)

    • Important: Incremental notation itself is not supported and is not planned
      due to lack of test assets and expected complications during implementation.
  • โœ… M00 - Program stop. (Spec. 8.1.1)

  • โœ… M01 - Optional stop. (Spec. 8.1.1)

  • ๐Ÿ‘ฝ AS - Sets the 'Axes correspondence'. (Spec. 8.1.2)

  • โœ… IN - Sets the name of the file image. (Spec. 8.1.3)

  • โœ… IP - Sets the 'Image polarity'. (Spec. 8.1.4)

  • โŒ IR - Sets 'Image rotation' graphics state parameter. (Spec. 8.1.5)

  • โœ… LN - Loads a name. (Spec. 8.1.6)

  • โŒ MI - Sets 'Image mirroring' graphics state parameter (Spec. 8.1.7)

  • ๐Ÿ‘ฝ OF - Sets 'Image offset' graphics state parameter (Spec. 8.1.8)

  • โŒ SF - Sets 'Scale factor' graphics state parameter (Spec. 8.1.9)

  • โœ… G74 - Sets single quadrant mode. (Spec. 8.1.10)

  • ๐Ÿšซ Format Specification (FS) Options. (Spec. 8.2.1)

  • ๐Ÿšซ Rectangular aperture hole in standard apertures. (Spec. 8.2.2)

  • โŒ Draws and arcs wit rectangular apertures. (Spec. 8.2.3)

  • โŒ Macro Primitive Code 2, Vector Line. (Spec 8.2.4)

  • โŒ Macro Primitive Code 22, Lower Left Line. (Spec 8.2.5)

  • โŒ Macro Primitive Code 6, Moirรฉ. (Spec 8.2.6)

  • โœ… Combining G01/G02/G03/G70/G71 and D01 in a single command. (Spec 8.3.1)

  • โœ… Combining G01/G02/G03/G70/G71 and D02 in a single command. (Spec 8.3.1)

  • โœ… Combining G01/G02/G03/G70/G71 and D03 in a single command. (Spec 8.3.1)

  • โœ… Coordinate Data without Operation Code. (Spec 8.3.2)

  • โœ… Style Variations in Command Codes. (Spec 8.3.3)

  • โŒ Deprecated usage of SR. (Spec 8.3.4)

  • โŒ Deprecated Attribute Values. (Spec 8.4)

    • Important: Incremental notation itself is not supported and is not planned
      due to lack of test assets and expected complications during implementation.

PS. I had great time adding emoji to this table.

Add support for moire primitives in macros

This primitive was deprecated in 2021. It is rarely used in legacy files.
The moirรฉ primitive is a cross hair centered on concentric rings. Exposure is always on!

image

We don't have examples of use in assets.

Add Gerber v3 to Gerber v2 automatic downgrade

It might be sometimes useful to downgrade your Gerber file version, similarily to how Babel in JavaScript works, by allowing user to write modern JavaScript code and translating it to older versions of JavaScript, so it can run on older browsers.

Incorrect rendering of single quadrant arc

Describe the bug

Following piece of code sourced from #230 is rendered incorrectly:

G04 Ucamco ex. 4.5.8: Single quadrant*
%FSLAX23Y23*%
%MOIN*%
%ADD10C,0.010*%
G74*
D10*
X1100Y600D02*
G03*
X700Y1000I400J0D01*
X300Y600I0J400D01*
X700Y200I400J0D01*
X1100Y600I0J400D01*
X300D02*
G01*
X1100D01*
X700Y200D02*
Y1000D01*
M02*

To Reproduce

Render provided code with PyGerber and Reference Gerber Viewer.

pygerber raster-2d sample-code.grb

Expected behavior

Images should be nearly identical.

Screenshots

Results in following image:

output

But the output should look like this:

image

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • PyGerber: 2.0.1
  • Python: 3.8.18

Additional context

N/A

No module named 'pygerber.gerberx3.api.color_scheme'

Thanks for the project, just starred.

copied code from README

โžœ pip3 install pip3 install pygerber
Defaulting to user installation because normal site-packages is not writeable
Collecting pygerber
  Downloading pygerber-1.0.0-py3-none-any.whl (55 kB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 55.3/55.3 KB 542.6 kB/s eta 0:00:00
Collecting PyR3>=0.2.2
  Downloading PyR3-0.2.3-py3-none-any.whl (23 kB)
Collecting toml>=0.10.0
  Downloading toml-0.10.2-py2.py3-none-any.whl (16 kB)
Requirement already satisfied: numpy>=1.21.0 in ./.local/lib/python3.10/site-packages (from pygerber) (1.25.0)
Collecting pillow>=8.3.0
  Downloading Pillow-10.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.4 MB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 3.4/3.4 MB 10.4 MB/s eta 0:00:00
Requirement already satisfied: PyYAML>=5.4.0 in /usr/lib/python3/dist-packages (from pygerber) (5.4.1)
Collecting requests>=2.26.0
  Downloading requests-2.31.0-py3-none-any.whl (62 kB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 62.6/62.6 KB 3.1 MB/s eta 0:00:00
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/lib/python3/dist-packages (from requests>=2.26.0->PyR3>=0.2.2->pygerber) (1.26.5)
Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3/dist-packages (from requests>=2.26.0->PyR3>=0.2.2->pygerber) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.26.0->PyR3>=0.2.2->pygerber) (2020.6.20)
Collecting charset-normalizer<4,>=2
  Downloading charset_normalizer-3.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (201 kB)
     โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 201.8/201.8 KB 9.3 MB/s eta 0:00:00
Installing collected packages: toml, pillow, charset-normalizer, requests, PyR3, pygerber
  WARNING: The script normalizer is installed in '/home/c2h2/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The script pygerber is installed in '/home/c2h2/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed PyR3-0.2.3 charset-normalizer-3.2.0 pillow-10.0.0 pygerber-1.0.0 requests-2.31.0 toml-0.10.2



โžœ  gits python3 gerber.py 
Traceback (most recent call last):
  File "/Users/c2h2/gits/gerber.py", line 1, in <module>
    from pygerber.gerberx3.api.color_scheme import ColorScheme
ModuleNotFoundError: No module named 'pygerber.gerberx3.api.color_scheme'

Any reasons?

Macro support

Parser support for macro features:

  • Primitives
    • Circle
    • Vector Line
    • Center Line
    • Outline
    • Polygon
    • Thermal
  • Rotation
  • Variables
  • Math expressions

Rasterized2DBackend support for macro features:

  • Primitives
    • Circle
    • Vector Line
    • Center Line
    • Outline
    • Polygon
    • Thermal
  • Rotation
  • Variables
  • Math expressions

Allocate memory error.

My gerber file see bellow

G04 Ucamco ex. 4.6.4: Simple contour*
%FSLAX25Y25*%
%MOIN*%
%ADD10C,0.010*%
G36*
X200000Y300000D02*
G01*
X700000D01*
Y100000D01*
X1100000Y500000D01*
X700000Y900000D01*
Y700000D01*
X200000D01*
Y300000D01*
G37*
M02*

code sample

from pygerber.gerberx3.api import (
      ColorScheme,
      Rasterized2DLayer,
      Rasterized2DLayerParams,
)

# Path to Gerber source file.
source_path = "./example/example_simple_contour.gbr"

Rasterized2DLayer(
      options=Rasterized2DLayerParams(
            source_path=source_path,
            colors=ColorScheme.COPPER_ALPHA,
      ),
).render().save("output.png")

console error

WARNING:root:Detected use of imperial units. Using metric units is recommended. Imperial units will be deprecated in future. (See 4.2.1 in Gerber Layer Format Specification)
Traceback (most recent call last):
  File "c:/Users/jekoi/Desktop/t/main.py", line 10, in <module>
    Rasterized2DLayer(
  File "c:\Users\jekoi\Desktop\t\pygerber\gerberx3\api\_layers.py", line 173, in render
    result_handle = draw_commands.draw()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\abstract\draw_commands_handle.py", line 21, in draw
    return self.backend.draw(self.draw_commands)
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\abstract\backend_cls.py", line 97, in draw
    self._post_drawing_hook()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\rasterized_2d\backend_cls.py", line 165, in _post_drawing_hook
    self._replace_image_colors()
  File "c:\Users\jekoi\Desktop\t\pygerber\backend\rasterized_2d\backend_cls.py", line 181, in _replace_image_colors
    rgba_img[np_img == gray_value] = rgba
numpy.core._exceptions.MemoryError: Unable to allocate 240. MiB for an array with shape (63007000,) and data type int32     
PS C:\Users\jekoi\Desktop\t> 

Another, I notice the pcb-tools nobody maintained, and you re-new a new gerber project.I use part of pcb-tools projects to draw PyQt/PySide graph.But I don't now how to use your code draw PyQt/PySdie shape.I had read small part of your code,but I not found the code that draw the shape(like cairo).

Incorrect bounding box prediction for displaced drawings

Describe the bug

When image is displaced, eg. starts at (190,80) and never draws over (0,0) image region is still predicted as if image included some empty draw on (0,0)

To Reproduce

Steps to reproduce the behavior:

python -m pygerber raster-2d "test/assets/gerberx3/A64-OLinuXino-rev-G/A64-OlinuXino_Rev_G-B_Cu.gbr" --style debug_1 --output "render-1703172985689.png" --dpi 1000

Expected behavior

Image should only cover minimal bounding box required to fit all the draw operations

render-1703172985689

Expected:

render-1703172985689

Positioning of rendered images

Hi. I am using this library to display rasterized png layers of Gerber file on uv screen.

I have encountered a problem: when rendering a layers of gerber file, the unoccupied part of the image is cut off.
In my script Pillow automatically sets the image to the corner of the screen, but because the images are cropped they don't fit together.

Is there any way to position the rendered images relative to each other?

gh-iss

Thank you very much!

Tokenizer - Deprecated Gerber Features

Symbol Meaning
โœ… Feature implemented and usable.
๐Ÿšง Work in progress. Related APIs can change.
๐Ÿšซ Not planned, unless contributed or needed.
โŒ Not implemented, but planned.
๐Ÿ‘ฝ Partially implemented.
๐Ÿ‘พ Bugged.
- -

Supported DEPRECATED Gerber features

  • โœ… G54 - Select aperture. (Spec. 8.1.1)

  • โœ… G55 - Prepare for flash. (Spec. 8.1.1)

  • โœ… G70 - Set the 'Unit' to inch. (Spec. 8.1.1)

  • โœ… G71 - Set the 'Unit' to mm. (Spec. 8.1.1)

  • โœ… G90 - Set the 'Coordinate format' to 'Absolute notation'. (Spec. 8.1.1)

  • โœ… G91 - Set the 'Coordinate format' to 'Incremental notation'. (Spec. 8.1.1)

    • Important: Incremental notation itself is not supported and is not planned
      due to lack of test assets and expected complications during implementation.
  • โœ… M00 - Program stop. (Spec. 8.1.1)

  • โœ… M01 - Optional stop. (Spec. 8.1.1)

  • โœ… AS - Sets the 'Axes correspondence'. (Spec. 8.1.2)

  • โœ… IN - Sets the name of the file image. (Spec. 8.1.3)

  • โœ… IP - Sets the 'Image polarity'. (Spec. 8.1.4)

  • โœ… IR - Sets 'Image rotation' graphics state parameter. (Spec. 8.1.5)

  • โœ… LN - Loads a name. (Spec. 8.1.6)

  • โŒ MI - Sets 'Image mirroring' graphics state parameter (Spec. 8.1.7)

  • ๐Ÿ‘ฝ OF - Sets 'Image offset' graphics state parameter (Spec. 8.1.8)

  • โŒ SF - Sets 'Scale factor' graphics state parameter (Spec. 8.1.9)

  • โœ… G74 - Sets single quadrant mode. (Spec. 8.1.10)

  • ๐Ÿšซ Format Specification (FS) Options. (Spec. 8.2.1)

  • ๐Ÿšซ Rectangular aperture hole in standard apertures. (Spec. 8.2.2)

  • โœ… Draws and arcs wit rectangular apertures. (Spec. 8.2.3)

  • โŒ Macro Primitive Code 2, Vector Line. (Spec 8.2.4)

  • โŒ Macro Primitive Code 22, Lower Left Line. (Spec 8.2.5)

  • โŒ Macro Primitive Code 6, Moirรฉ. (Spec 8.2.6)

  • โœ… Combining G01/G02/G03/G70/G71 and D01 in a single command. (Spec 8.3.1)

  • โœ… Combining G01/G02/G03/G70/G71 and D02 in a single command. (Spec 8.3.1)

  • โœ… Combining G01/G02/G03/G70/G71 and D03 in a single command. (Spec 8.3.1)

  • โœ… Coordinate Data without Operation Code. (Spec 8.3.2)

  • โœ… Style Variations in Command Codes. (Spec 8.3.3)

  • โŒ Deprecated usage of SR. (Spec 8.3.4)

  • โŒ Deprecated Attribute Values. (Spec 8.4)

    • Important: Incremental notation itself is not supported and is not planned
      due to lack of test assets and expected complications during implementation.

PS. I had great time adding emoji to this table.

%TF.SameCoordinates*% shown as "Invalid Syntax"

Describe the bug

The valid Gerber code %TF.SameCoordinates*% is reportted as "Invalid Syntax"

To Reproduce

Steps to reproduce the behavior:

  1. Type in %TF.SameCoordinates*%

Desktop (please complete the following information):

  • OS: Win10
  • Python version: [e.g. 3.8.13]
  • PyGerber version: [e.g. 2.0.0]
  • Visual Studio Code Version: 1.86.0 (user setup)

Parser - Deprecated Gerber Features

Supported DEPRECATED Gerber features:

  • G54 - Select aperture - This historic code optionally precedes an aperture
    selection Dnn command. It has no effect. Sometimes used. Deprecated in 2012.
  • G55 - Prepare for flash - This historic code optionally precedes D03 code. It has
    no effect. Very rarely used nowadays. Deprecated in 2012.
  • G70 - Set the 'Unit' to inch - These historic codes perform a function handled by
    the MO command. See 4.2.1. Sometimes used. Deprecated in 2012.
  • G71 - Set the 'Unit' to mm - This is part of the historic codes that perform a
    function handled by the MO command.
  • G90 - Set the 'Coordinate format' to 'Absolute notation' - These historic codes
    perform a function handled by the FS command. Very rarely used nowadays.
    Deprecated in 2012.
  • G91 - Set the 'Coordinate format' to 'Incremental notation' - Part of the historic
    codes handled by the FS command.
  • G74 - Sets single quadrant mode - Rarely used, and then typically without effect.
    Deprecated in 2020. (Spec. 8.1.10)
  • M00 - Program stop - This historic code has the same effect as M02. Very rarely,
    if ever, used nowadays. Deprecated in 2012.
  • M01 - Optional stop - This historic code has no effect. Very rarely, if ever, used
    nowadays. Deprecated in 2012.
  • IP - Sets the 'Image polarity' graphics state parameter - This command has no
    effect in CAD to CAM workflows. Sometimes used, and then usually as %IPPOS*% to
    confirm the default and then it then has no effect. Deprecated in 2013. (Spec.
    8.1.4)
  • AS - Sets the 'Axes correspondence' graphics state parameter - Deprecated in 2013.
    Rarely used nowadays. (Spec. 8.1.2)
  • IR - Sets 'Image rotation' graphics state parameter - Deprecated in 2013. Rarely
    used nowadays. (Spec. 8.1.5)
  • MI - Sets 'Image mirroring' graphics state parameter (Spec. 8.1.7)
  • OF - Sets 'Image offset' graphics state parameter (Spec. 8.1.8)
  • SF - Sets 'Scale factor' graphics state parameter (Spec. 8.1.9)
  • IN - Sets the name of the file image. Has no effect. It is comment. Sometimes
    used. Deprecated in 2013. (Spec. 8.1.3)
  • LN - Loads a name. Has no effect. It is a comment. Sometimes used. Deprecated
    in 2013. (Spec. 8.1.6)
  • Combining G01/G02/G03/G70/G71 and D01 in a single command. (Spec 8.3.1)
  • Combining G01/G02/G03/G70/G71 and D02 in a single command.
  • Combining G01/G02/G03/G70/G71 and D03 in a single command.
  • Coordinate Data without Operation Code. (Spec 8.3.2)
  • Style Variations in Command Codes. (Spec 8.3.3)
  • Deprecated usage of SR. (Spec 8.3.4)
  • Deprecated Attribute Values. (Spec 8.4)
  • Format Specification (FS) Options (Trailing Zero Omission, Incremental Notation).
    (Spec. 8.2)
  • Rectangular Hole in Standard Apertures (Spec. 8.2.2)
  • Draws and Arcs with Rectangular Apertures (Spec. 8.2.3)
  • Macro Primitive Code 2, Vector Line (Spec. 8.2.4)
  • Macro Primitive Code 22, Lower Left Line (Spec. 8.2.5)
  • Macro Primitive Code 6, Moirรฉ (Spec. 8.2.6)

Add basic Block Aperture (AB) support

See: 4.11 Block Aperture (AB) in Gerber Spec.
This should only include basic behavior, recording and stamping, without rotations and possibly other transformations as they require more challanging adjustments in code.

Plans for the future

I have started this project long time ago and since then my approach to managing Python project changed significantly. Therefore this project IMO needs deep refactor in CI/support tools set.
Another thing that should be changed is its monolytical architecture. I think that parser itself should be kept separately (probably will remain in this repo) when 2D and 3D backend should be migrated to two other repos (pygerber_backend_pillow, pygerber_backend_blender). My idea is to make it similar to how modularity is handled in my other project, CSSFinder.
As for source, aproach to parsing is a bit too complicated and contains a lot of unexpected behaviors, thanks to heavy use of metaclasses.
In general, it is quite likely that in some not so distant future updates to this software will arrive, hopefully bringing support for latest versions of blender and Python.
I might need some help with compiling blender as python module on windows and macos for use in this project, as I don't currently have access to machines with those OSes.

Is there a future for this project? TL;DR: there is.

Main purpose of this code is to parse gerber (v3) format and create image or 3D model showing content of the file. However, project was abandoned due to lack of time. It is worth mentioning that there are plenty of GUI/web based tools allowing for such visualization. I do not need such software myself and see no reason to use my time to support something that is not used by anyone.

Image coloring according to scheme

Currently image coloring is not implemented, only it's public interface is finished. It must be implemented before release 2.0.0 to make PyGerber functional.

Release 2.0.0 checklist

There are few things which have to be implemented before release 2.0.0:

  • region statements basic support (#27)
  • basic documentation
  • image coloring according to scheme

Unfortunately macro support (#23) will not be fully implemented in this release. Macros are parsed but not rendered. It is therefore possible to render Gerber files which contain macros, but macros do not appear on output images.
Similarly, block apertures are parsed but will not be rendered.

Progress with pygerber

I just wanted to check in (is there a better way to do this?) I see you are making lots of progress, let me know when I should start experimenting with pygerber 2.0!

I'm having trouble aligning the images when there are parts of a layer that go NW of the origin, in this case the images are generated correctly, but my program shows them misaligned? Is there a way to get the origin out of pygerber? Perhaps I could start writing some docs as I go along here?

Also, I was wondering if you had any good options for references on the gerber standard?

Tokenizer

Tokenizer support for Gerber X3 syntax:

  • G04 - Comment - A human readable comment, does not affect the image.
  • MO - Mode - Sets the unit to mm or inch.
  • FS - Format specification - Sets the coordinate format, e.g. the number of
    decimals.
  • FS (Deprecated modes)
  • AD - Aperture define - Defines a template-based aperture, assigns a D code to it.
  • AM - Aperture macro - Defines a macro aperture template.
  • Dnn (nnโ‰ฅ10) - Sets the current aperture to D code nn.
  • D01 - Plot operation - Outside a region statement D01 creates a draw or arc object
    with the current aperture. Inside it adds a draw/arc segment to the contour under
    construction. The current point is moved to draw/arc end point after the creation
    of the draw/arc.
  • D02 - Move operation - D02 moves the current point to the coordinate in the
    command. It does not create an object.
  • D03 - Flash operation - Creates a flash object with the current aperture. The
    current point is moved to the flash point.
  • G01 - Sets linear/circular mode to linear.
  • G02 - Sets linear/circular mode to clockwise circular.
  • G03 - Sets linear/circular mode to counterclockwise circular.
  • G75 - A G75 must be called before creating the first arc.
  • LP - Load polarity - Loads the polarity object transformation parameter.
  • LM - Load mirroring - Loads the mirror object transformation parameter.
  • LR - Load rotation - Loads the rotation object transformation parameter.
  • LS - Load scaling - Loads the scale object transformation parameter.
  • G36 - Starts a region statement which creates a region by defining its contours.
  • G37 - Ends the region statement.
  • AB - Aperture block - Opens a block aperture statement and assigns its aperture
    number or closes a block aperture statement.
  • SR - Step and repeat - Open or closes a step and repeat statement.
  • TF - Attribute on file - Set a file attribute.
  • TA - Attribute on aperture - Add an aperture attribute to the dictionary or modify
    it.
  • TO - Attribute on object - Add an object attribute to the dictionary or modify it.
  • TD - Attribute delete - Delete one or all attributes in the dictionary.
  • M02 - End of file.

Parser2 - Basic macro support

Macros

  • โœ… Parameters.
  • โŒ Primitives in definition:
    • โœ… Code 1, Circle
    • โŒ Code 2, Vector line
    • โœ… Code 4, Outline
    • โœ… Code 5, Polygon
    • โŒ Code 6, Moire
    • โœ… Code 7, Thermal
    • โœ… Code 20, Vector line
    • โœ… Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • โŒ Primitives in aperture instance:
    • โœ… Code 1, Circle
    • โŒ Code 2, Vector line
    • โœ… Code 4, Outline
    • โœ… Code 5, Polygon
    • โŒ Code 6, Moire
    • โŒ Code 7, Thermal
    • โœ… Code 20, Vector line
    • โœ… Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • โŒ Rotation around macro origin:
    • โŒ Code 1, Circle
    • โŒ Code 2, Vector line
    • โŒ Code 4, Outline
    • โŒ Code 5, Polygon
    • โŒ Code 6, Moire
    • โŒ Code 7, Thermal
    • โŒ Code 20, Vector line
    • โŒ Code 21, Center Line
    • โŒ Code 22, Lower Left Line
  • โœ… Expressions.
    • โœ… Constants.
    • โœ… Variables.
    • โœ… Addition.
    • โœ… Subtraction.
    • โœ… Multiplication.
    • โœ… Division.
    • โœ… Unary + operator.
    • โœ… Negation.
  • โœ… Variable definitions.

pygerber parsing gerber files from kicad

Hi,

I wanted to get some background on this issue. At the moment I get alot of bad tokens when I use gerbers from sources other than the demo gerber files in the package.

e.g.

$ python3 -m pygerber --pillow --toml "./specfile.yaml" -s "render.png"
Rendering /home/user/Documents/KiCAD/test_gerbers/specfile.yaml as TOML
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/__main__.py", line 18, in <module>
    main()
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/__main__.py", line 14, in main
    handle_pygerber_cli(sys.argv[1:])
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/cli.py", line 92, in handle_pygerber_cli
    handle_pillow_cli(args)
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/parser/pillow/cli.py", line 20, in handle_pillow_cli
    image = render_from_toml(args.specfile["filepath"])
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/API2D.py", line 53, in render_from_toml
    return PillowProjectSpec.from_toml(file_path).render()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/pygerber/parser/project_spec.py", line 56, in from_toml
    spec = toml.load(file)
           ^^^^^^^^^^^^^^^
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/toml/decoder.py", line 156, in load
    return loads(f.read(), _dict, decoder)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/software/gerber-venv/lib/python3.11/site-packages/toml/decoder.py", line 260, in loads
    raise TomlDecodeError("Found invalid character in key name: '" +
toml.decoder.TomlDecodeError: Found invalid character in key name: ':'. Try quoting the key name. (line 1 column 4 char 3)

test_gerbers.tar.gz

This is a basic 2 layer gerber file that has most of the basic components of a PCB (see image). I get similar token issues when using the API, I've played with deleteing much of the file, but need to get to grips with what is and isn't implemented. I was wondering if you have any advice on where to start and whether this is something caused by using 3.11 not 3.9?

Parser

Parser support for Gerber X3 features:

  • MO - Mode - Sets the unit to mm or inch.
  • FS - Format specification - Sets the coordinate format, e.g. the number of
    decimals.
  • AD - Aperture define - Defines a template-based aperture, assigns a D code to it.
    • Define circle.
    • Define rectangle.
    • Define obround.
    • Define polygon.
    • Define macro.
  • AM - Aperture macro - Defines a macro aperture template.
  • Dnn (nnโ‰ฅ10) - Sets the current aperture to D code nn.
  • D01 - Plot operation - Outside a region statement D01 creates a draw or arc object
    with the current aperture.
  • D01 - Plot operation - Inside region statement adds a draw/arc segment to the contour under
    construction. The current point is moved to draw/arc end point after the creation
    of the draw/arc.
  • D02 - Move operation - D02 moves the current point to the coordinate in the
    command. It does not create an object.
  • D03 - Flash operation - Creates a flash object with the current aperture. The
    current point is moved to the flash point.
  • G01 - Sets linear/circular mode to linear.
  • G02 - Sets linear/circular mode to clockwise circular.
  • G03 - Sets linear/circular mode to counterclockwise circular.
  • LP - Load polarity - Loads the polarity object transformation parameter.
  • LM - Load mirroring - Loads the mirror object transformation parameter.
  • LR - Load rotation - Loads the rotation object transformation parameter.
  • LS - Load scaling - Loads the scale object transformation parameter.
  • G36 - Starts a region statement which creates a region by defining its contours.
  • G37 - Ends the region statement.
  • AB - Aperture block - Opens a block aperture statement and assigns its aperture
    number or closes a block aperture statement.
  • SR - Step and repeat - Open or closes a step and repeat statement.
  • TF - Attribute on file - Set a file attribute.
  • TA - Attribute on aperture - Add an aperture attribute to the dictionary or modify
    it.
  • TO - Attribute on object - Add an object attribute to the dictionary or modify it.
  • TD - Attribute delete - Delete one or all attributes in the dictionary.
  • M02 - End of file.

Region support

Support for drawing region boundaries with:

  • lines
  • arcs (basic only, see #29)

Support for drawing region types:

  • convex
  • non-convex

For now selected approach is to implement regions as polygons drawn using Pillow ImageDraw.polygon().

Fix incorrect behavior of block aperture definitions.

According to Gerber spec, after aperture definition should remain as it was at the end of it, except for current point which is undefined.
Current behavior of PyGerber doesn't comply with that as state from before the aperture definition is fully restored.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.