Skip to content

Commit

Permalink
Change convinience API design
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Sep 23, 2024
1 parent aa78f19 commit a2a4918
Show file tree
Hide file tree
Showing 36 changed files with 488 additions and 894 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
- id: debug-statements

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.4.6"
rev: "v0.6.5"
hooks:
# Run the linter.
- id: ruff
Expand Down
135 changes: 0 additions & 135 deletions docs/70_gerber/00_api_v2_usage.md

This file was deleted.

3 changes: 0 additions & 3 deletions docs/70_gerber/01_api_v2_reference.md

This file was deleted.

2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 = "3.0.0a1"
version = "3.0.0a0"
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/backend/abstract/draw_commands/draw_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DrawArc(DrawCommand):
is_clockwise: bool
is_multi_quadrant: bool

def __init__( # noqa: PLR0913
def __init__(
self,
backend: Backend,
polarity: Polarity,
Expand Down
51 changes: 4 additions & 47 deletions src/pygerber/console/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@

from __future__ import annotations

from typing import Generator

import click

import pygerber
from pygerber.gerberx3.api.v2 import (
DEFAULT_ALPHA_COLOR_MAP,
DEFAULT_COLOR_MAP,
FileTypeEnum,
GerberFile,
ImageFormatEnum,
PixelFormatEnum,
Project,
)
from pygerber.gerberx3.api import FileTypeEnum


@click.group("pygerber")
Expand Down Expand Up @@ -92,25 +82,7 @@ def _raster(
quality: int,
) -> None:
"""Render Gerber file with API V2 as raster (PNG/JPEG) image."""
parsed_file = GerberFile.from_file(
source, file_type=FileTypeEnum(file_type)
).parse()

color_map = DEFAULT_COLOR_MAP

if pixel_format.upper() == "RGBA":
color_map = DEFAULT_ALPHA_COLOR_MAP

color_scheme = color_map[parsed_file.get_file_type()]

parsed_file.render_raster(
output,
color_scheme=color_scheme,
dpmm=dpmm,
pixel_format=PixelFormatEnum(pixel_format.upper()),
image_format=ImageFormatEnum(image_format.lower()),
quality=quality,
)
raise NotImplementedError


@_render.command("vector")
Expand Down Expand Up @@ -148,11 +120,7 @@ def _vector(
scale: float,
) -> None:
"""Render Gerber file with API V2 as vector (SVG) image."""
parsed_file = GerberFile.from_file(
source, file_type=FileTypeEnum(file_type)
).parse()
color_scheme = DEFAULT_COLOR_MAP[parsed_file.get_file_type()]
parsed_file.render_svg(output, color_scheme=color_scheme, scale=scale)
raise NotImplementedError


@_render.command("project")
Expand All @@ -170,15 +138,4 @@ def _project(files: str, output: str, dpmm: int) -> None:
Layers are merged from first to last, thus last layer will be on top.
"""

def _() -> Generator[GerberFile, None, None]:
for file in files:
file_path, *other = file.split("@")

file_type = FileTypeEnum.INFER
if len(other) != 0:
file_type = FileTypeEnum(other[0].upper())

yield GerberFile.from_file(file_path, file_type)

Project(list(_())).parse().render_raster(output, dpmm=dpmm)
raise NotImplementedError
2 changes: 1 addition & 1 deletion src/pygerber/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class ExamplesEnum(Enum):
"""Enumeration of all available examples."""

UCAMCO_ex_2_Shapes = "ucamco_ex_2_shapes.grb"
UCAMCO_2_11_2 = "ucamco_2_11_2.grb"
ShapeFlashes = "shape_flashes.grb"
simple_2layer_F_Cu = "simple_2layer-F_Cu.gbr" # noqa: N815
simple_2layer_F_Mask = "simple_2layer-F_Mask.gbr" # noqa: N815
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ G04 Ucamco ex. 2: Shapes* G04 Comment
%TF.FileFunction,Other,Sample*% G04 Attribute: the is not a PCB layer, it is just an *
G04 example *
G04 Define Apertures* G04 Comment *
%AMTHERMAL80* G04 Define the aperture macro 'THERMAL80' *
7,0,0,0.800,0.550,0.125,45*% G04 Use thermal primitive in the macro *
%AMTHERMAL80*
7,0,0,0.800,0.550,0.125,45*% G04 Define the aperture macro 'THERMAL80' *
G04 Use thermal primitive in the macro *
%ADD10C,0.1*% G04 Define aperture 10 as a circle with diameter 0.1 mm *
%ADD11C,0.6*% G04 Define aperture 11 as a circle with diameter 0.6 mm *
%ADD12R,0.6X0.6*% G04 Define aperture 12 as a rectangle with size 0.6 x 0.6 mm *
Expand Down
18 changes: 4 additions & 14 deletions src/pygerber/gerberx3/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@

from __future__ import annotations

from pygerber.backend.rasterized_2d.color_scheme import ColorScheme
from pygerber.common.rgba import RGBA
from pygerber.gerberx3.api._errors import (
GerberX3APIError,
MutuallyExclusiveViolationError,
RenderingResultNotReadyError,
)
from pygerber.gerberx3.api._enums import FileTypeEnum
from pygerber.gerberx3.api._gerber_file import GerberFile, GerberFileInfo
from pygerber.gerberx3.api._project import Project

__all__ = [
"RGBA",
"ColorScheme",
"GerberX3APIError",
"RenderingResultNotReadyError",
"MutuallyExclusiveViolationError",
]
__all__ = ["FileTypeEnum", "GerberFile", "Project", "GerberFileInfo"]
Loading

0 comments on commit a2a4918

Please sign in to comment.