Skip to content

Commit

Permalink
Release 2.0.1 (#58)
Browse files Browse the repository at this point in the history
## Release 2.0.1

- Fixed names of Gerber specification files (`.pdf.pdf` extension
replaced with `.pdf`)
- Added `draw_region_outlines` option (disabled by default) which
controls whether lines
which make up a region boundary should be drawn after region is filled.
KiCAD seem to
assume that those boundaries are not drawn and region outline is 1px
instead of
  thickness of aperture.
- Changed `Decimal` precision to 60 decimal places.
- Changed precision of `INCH_TO_MM_MULTIPLIER` (now its 25.4) and
`MM_TO_INCH_MULTIPLIER`
  (dynamically calculated with `Decimal`).
- Changed circle aperture to make result better match expectations and
`KiCAD` reference.
- Fixed warning message logged every time a valid region was created to
show up only
  when region is not valid.
- Added warnings for zero surface aperture draws.
  • Loading branch information
Argmaster authored Sep 12, 2023
2 parents ecfc6b9 + 8ef45bb commit 2c1fe02
Show file tree
Hide file tree
Showing 50 changed files with 402 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ updates:
schedule:
interval: "daily"

target-branch: "main"
target-branch: "dev"

labels:
- "dependencies"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build_n_deploy_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ jobs:
- name: Install Mike
run: poetry run pip install mike

- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Run build & deploy documentation
run: |
poetry run mike deploy --push --update-aliases $(poetry version | awk '{ print $2 }') latest -F mkdocs.yaml
2 changes: 2 additions & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**

pull_request:
branches:
Expand All @@ -21,6 +22,7 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**
types:
- opened
- reopened
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release_to_test_pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches:
- dev
- release/**
- maintenance/**

jobs:
deploy-to-pypi:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/type_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**

pull_request:
branches:
Expand All @@ -21,6 +22,7 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**
types:
- opened
- reopened
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/unit_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**
paths:
- src/**
- test/**
- .github/**
- pyproject.toml
- poetry.lock

pull_request:
branches:
Expand All @@ -21,6 +28,7 @@ on:
- feature/**
- release/**
- dependabot/**
- maintenance/**
types:
- opened
- reopened
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and
this project adheres to [Calendar Versioning](https://calver.org/).

## Release 2.0.1

- Fixed names of Gerber specification files (`.pdf.pdf` extension replaced with `.pdf`)
- Added `draw_region_outlines` option (disabled by default) which controls whether lines
which make up a region boundary should be drawn after region is filled. KiCAD seem to
assume that those boundaries are not drawn and region outline is 1px instead of
thickness of aperture.
- Changed `Decimal` precision to 60 decimal places.
- Changed precision of `INCH_TO_MM_MULTIPLIER` (now its 25.4) and
`MM_TO_INCH_MULTIPLIER` (dynamically calculated with `Decimal`).
- Changed circle aperture to make result better match expectations and `KiCAD`
reference.
- Fixed warning message logged every time a valid region was created to show up only
when region is not valid.
- Added warnings for zero surface aperture draws.

## Release 2.0.0

- Added Gerber X3 format tokenizer with support for selective feature support:
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@

<h1 align="center"> PyGerber </h1>

<p align="center">
<a href="https://github.com/Argmaster/pygerber/releases/"><img src="https://img.shields.io/github/v/release/Argmaster/pygerber?style=flat" alt="GitHub release"></a>
<a href="https://github.com/Argmaster/pygerber/releases"><img src="https://img.shields.io/github/release-date/Argmaster/pygerber" alt="GitHub Release Date - Published_At"></a>
<a href="https://pypi.org/project/pygerber"><img src="https://img.shields.io/pypi/v/pygerber?style=flat" alt="PyPI release"></a>
<a href="https://pypi.org/project/pygerber/"><img src="https://img.shields.io/pypi/dm/pygerber.svg?label=PyPI%20downloads" alt="PyPI Downloads"></a>
<a href="https://pypi.org/project/pygerber"><img src="https://img.shields.io/pypi/pyversions/pygerber?style=flat" alt="Supported Python versions"></a>
<a href="https://pypi.org/project/pygerber"><img src="https://img.shields.io/pypi/implementation/pygerber?style=flat" alt="Supported Python implementations"></a>
<a href="https://github.com/argmaster/pygerber/blob/main/LICENSE"><img src="https://img.shields.io/github/license/Argmaster/pygerber" alt="license_mit"></a>
<a href="https://codecov.io/gh/Argmaster/pygerber"><img src="https://codecov.io/gh/Argmaster/pygerber/branch/main/graph/badge.svg?token=VM09IHO13U" alt="coverage"></a>
<a href="https://img.shields.io/github/checks-status/Argmaster/pygerber/main"><img src="https://img.shields.io/github/checks-status/Argmaster/pygerber/main" alt="GitHub tag checks state"></a>
<a href="https://github.com/Argmaster/pygerber/pulls"><img src="https://img.shields.io/github/issues-pr/Argmaster/pygerber?style=flat" alt="Pull requests"></a>
<a href="https://github.com/Argmaster/pygerber/issues"><img src="https://img.shields.io/github/issues-raw/Argmaster/pygerber?style=flat" alt="Open issues"></a>
<a href="https://github.com/Argmaster/pygerber"><img src="https://img.shields.io/github/repo-size/Argmaster/pygerber" alt="GitHub repo size"></a>
<a href="https://github.com/Argmaster/pygerber"><img src="https://img.shields.io/github/languages/code-size/Argmaster/pygerber" alt="GitHub code size in bytes"></a>
<a href="https://github.com/Argmaster/pygerber"><img src="https://img.shields.io/github/stars/Argmaster/pygerber" alt="GitHub Repo stars"></a>
<a href="https://python-poetry.org/"><img src="https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json" alt="Poetry"></a>
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code Style"></a>
</p>

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](https://www.ucamco.com/files/downloads/file_en/456/gerber-layer-format-specification-revision-2023-03_en.pdf)
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
informational: true
target: 90%
threshold: 1%
patch:
default:
informational: true
78 changes: 0 additions & 78 deletions main.ipynb

This file was deleted.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pygerber"
version = "2.0.0"
version = "2.0.1"
description = "Parsing, formatting and rendering toolkit for Gerber X3 file format"
authors = ["Krzysztof Wisniewski <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/pygerber/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Package for PCB formats visualization."""
from __future__ import annotations

__version__ = "2.0.0"
__version__ = "2.0.1"
8 changes: 7 additions & 1 deletion src/pygerber/backend/abstract/backend_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@
class BackendOptions:
"""Additional configuration which can be passed to backend."""

def __init__(self, dump_apertures: Optional[Path] = None) -> None:
def __init__(
self,
dump_apertures: Optional[Path] = None,
*,
draw_region_outlines: bool = False,
) -> None:
"""Initialize options."""
self.dump_apertures = dump_apertures
self.draw_region_outlines = draw_region_outlines


class Backend(ABC):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ def get_bounding_box(self) -> BoundingBox:
"""Return bounding box of draw operation."""
vertex_box = BoundingBox.from_diameter(self.width)
return (vertex_box + self.start_position) + (vertex_box + self.end_position)

def __str__(self) -> str:
return (
f"{self.__class__.__qualname__}({self.polarity}) start: "
"{self.start_position} end: {self.end_position}"
)
8 changes: 6 additions & 2 deletions src/pygerber/backend/rasterized_2d/backend_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ def __init__( # noqa: PLR0913
*,
include_debug_padding: bool = False,
include_bounding_boxes: bool = False,
draw_region_outlines: bool = False,
) -> None:
"""Initialize options."""
self.dpi = dpi
self.color_scheme = color_scheme
self.color_mode = color_mode
self.include_debug_padding = include_debug_padding
self.include_bounding_boxes = include_bounding_boxes
super().__init__(dump_apertures=dump_apertures)
super().__init__(
dump_apertures=dump_apertures,
draw_region_outlines=draw_region_outlines,
)


class Rasterized2DBackend(Backend):
Expand Down Expand Up @@ -122,7 +126,7 @@ def _create_drawing_target(self) -> DrawingTarget:
raw_bbox = self.bounding_box

if self.options.include_debug_padding:
bbox = raw_bbox.scale(Decimal(1.25))
bbox = raw_bbox + Decimal(1.0)
else:
bbox = raw_bbox

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def draw(self, target: DrawingTarget) -> None:
image_space_box = box - target.coordinate_origin
pixel_box = image_space_box.as_pixel_box(self.backend.dpi, dx_max=-1, dy_max=-1)

# Here we are using the 'rectangle' method instead of 'ellipse'
(min_x, min_y, max_x, max_y) = pixel_box
if (max_x - min_x <= 0) or (max_y - min_y <= 0):
logging.warning("Drawing zero surface bounding box. DPI may be too low.")
return

target.image_draw.rectangle(
xy=pixel_box,
fill=None,
Expand Down
27 changes: 19 additions & 8 deletions src/pygerber/backend/rasterized_2d/draw_commands/draw_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,23 @@ def draw(self, target: DrawingTarget) -> None:
image_space_box = box - target.coordinate_origin
pixel_box = image_space_box.as_pixel_box(
self.backend.dpi,
dx_max=-2,
dy_max=-2,
dx_min=+1,
dy_min=+1,
)

target.image_draw.ellipse(
xy=pixel_box,
fill=self.polarity.get_2d_rasterized_color(),
outline=None,
width=0,
)
logging.debug("Adding %s to %s", self.__class__.__qualname__, target)
(min_x, min_y, max_x, max_y) = pixel_box
if (max_x - min_x <= 0) or (max_y - min_y <= 0):
logging.warning(
"Drawing zero surface circle. DPI may be too low. %s",
pixel_box,
)

else:
target.image_draw.ellipse(
xy=pixel_box,
fill=self.polarity.get_2d_rasterized_color(),
outline=None,
width=0,
)
logging.debug("Adding %s to %s", self.__class__.__qualname__, target)
18 changes: 18 additions & 0 deletions src/pygerber/backend/rasterized_2d/draw_commands/draw_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
from pygerber.backend.rasterized_2d.backend_cls import Rasterized2DBackend


NUMBER_OF_VERTICES_IN_TRIANGLE = 3


class Rasterized2DApertureDrawPolygon(DrawPolygon):
"""Description of polygon aperture component."""

Expand All @@ -36,6 +39,21 @@ def draw(self, target: DrawingTarget) -> None:
)
rotation = float(-self.rotation + Decimal("-90.0"))

if self.number_of_vertices < NUMBER_OF_VERTICES_IN_TRIANGLE:
logging.warning(
"Drawing invalid polygon, number of vertices < 3 (%s)",
self.number_of_vertices,
)
return

(_, __, radius) = bounding_circle
if radius == 0:
logging.warning(
"Drawing zero surface polygon. DPI may be too low. %s",
bounding_circle,
)
return

target.image_draw.regular_polygon(
bounding_circle=bounding_circle,
n_sides=self.number_of_vertices,
Expand Down
22 changes: 15 additions & 7 deletions src/pygerber/backend/rasterized_2d/draw_commands/draw_rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ def draw(self, target: DrawingTarget) -> None:
self.backend.dpi,
)

target.image_draw.rectangle(
xy=pixel_box,
fill=self.polarity.get_2d_rasterized_color(),
outline=None,
width=0,
)
logging.debug("Adding %s to %s", self.__class__.__qualname__, target)
(min_x, min_y, max_x, max_y) = pixel_box
if (max_x - min_x <= 0) or (max_y - min_y <= 0):
logging.warning(
"Drawing zero surface rectangle. DPI may be too low. %s",
pixel_box,
)

else:
target.image_draw.rectangle(
xy=pixel_box,
fill=self.polarity.get_2d_rasterized_color(),
outline=None,
width=0,
)
logging.debug("Adding %s to %s", self.__class__.__qualname__, target)
Loading

0 comments on commit 2c1fe02

Please sign in to comment.