⭐ API V2 Reference¶
v2
¶
PyGerber hight level rendering API version 2.
This API utilizes Parser2 for parsing and SvgRenderer2, RasterRenderer2 for rendering output files. It is designed to be more limited and easier to use than the previous. For more advanced uses users will have to fall back to the lower level APIs and manual interaction with the parser and renderers.
ColorScheme
¶
Bases: FrozenGeneralModel
Set of colors which should be used for rendering.
ColorScheme class contains set of colors which should be used for different parts of rendered image. At the same time it also works as a container for predefined color schemes commonly used for parts of PCB.
Predefined colors
All predefined colors have two variants - normal one and one with "*_ALPHA" suffix. Those without suffix have solid background and are not intended for constructing multi-layer images out of them ie. they are not suitable for rendering a project consisting of separate copper, silk, pase mask and composing them into single image. For cases when rendered images are intended for stacking "*_ALPHA" schemes should be used, as background and transparent parts of image will be truly transparent.
Source code in src/pygerber/backend/rasterized_2d/color_scheme.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
SILK
class-attribute
¶
Default color of silk layer.
This schema provided non-transparent background, which results in images which can not be used for stacking on top of other layers, as they would completely obscure them.
SILK_ALPHA
class-attribute
¶
Default color of silk layer with alpha channel.
This schema provides transparent background. Images using this schema can be stacked on top of each other without obscuring layers below.
COPPER
class-attribute
¶
Default color of copper layer.
This schema provided non-transparent background, which results in images which can not be used for stacking on top of other layers, as they would completely obscure them.
COPPER_ALPHA
class-attribute
¶
Default color of copper layer with alpha channel.
This schema provides transparent background. Images using this schema can be stacked on top of each other without obscuring layers below.
PASTE_MASK
class-attribute
¶
Default color of paste mask layer.
This schema provided non-transparent background, which results in images which can not be used for stacking on top of other layers, as they would completely obscure them.
PASTE_MASK_ALPHA
class-attribute
¶
Default color of paste mask layer with alpha channel.
This schema provides transparent background. Images using this schema can be stacked on top of each other without obscuring layers below.
SOLDER_MASK
class-attribute
¶
Default color of solder mask layer.
This schema provided non-transparent background, which results in images which can not be used for stacking on top of other layers, as they would completely obscure them.
SOLDER_MASK_ALPHA
class-attribute
¶
Default color of solder mask layer with alpha channel.
This schema provides transparent background. Images using this schema can be stacked on top of each other without obscuring layers below.
DEFAULT_GRAYSCALE
class-attribute
¶
Default color scheme for files which were not assigned other color scheme.
debug_1_color
class-attribute
instance-attribute
¶
Color used for debug elements.
debug_2_color
class-attribute
instance-attribute
¶
Color used for debug elements.
get_grayscale_to_rgba_color_map
¶
Return grayscale to RGBA color map.
Source code in src/pygerber/backend/rasterized_2d/color_scheme.py
FileTypeEnum
¶
Bases: Enum
Enumeration of possible Gerber file types.
If file type is not listed here you can request adding it by creating an issue on https://github.com/Argmaster/pygerber/issues
Source code in src/pygerber/gerberx3/api/_v2.py
GerberFile
dataclass
¶
Generic representation of Gerber file.
This objects provides interface for loading and parsing Gerber files.
Source code in src/pygerber/gerberx3/api/_v2.py
from_file
classmethod
¶
Initialize object with Gerber source code loaded from file on disk.
Source code in src/pygerber/gerberx3/api/_v2.py
from_str
classmethod
¶
Initialize object with Gerber source code from string.
from_buffer
classmethod
¶
Initialize object with Gerber source code from readable buffer.
parse
¶
Parse Gerber file.
Source code in src/pygerber/gerberx3/api/_v2.py
GerberFileInfo
dataclass
¶
Container for information about Gerber file.
Source code in src/pygerber/gerberx3/api/_v2.py
from_readonly_command_buffer
classmethod
¶
Initialize object with information from command buffer.
Source code in src/pygerber/gerberx3/api/_v2.py
ImageFormatEnum
¶
OnParserErrorEnum
¶
Bases: Enum
Enumeration of possible actions to take on parser error.
Source code in src/pygerber/gerberx3/api/_v2.py
Ignore
class-attribute
instance-attribute
¶
Ignore parser errors. Errors which occurred will not be signaled. May yield unexpected results for broken files, with missing draw commands or even more significant errors.
Warn
class-attribute
instance-attribute
¶
Warn on parser error. Parser will log warning message about what went wrong. Best for supporting wide range of files without silently ignoring errors in code.
Raise
class-attribute
instance-attribute
¶
Raise exception whenever parser encounters error. Will completely break out of parsing process, making it impossible to render slightly malformed files.
ParsedFile
dataclass
¶
Wrapper around parsed Gerber file.
This objects allow actions like rendering and retrieving information about file contents.
Source code in src/pygerber/gerberx3/api/_v2.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
|
get_info
¶
get_file_type
¶
render_svg
¶
render_svg(
destination: BytesIO | Path | str,
*,
color_scheme: ColorScheme = ColorScheme.COPPER,
scale: float = 1.0
) -> None
Render Gerber file to SVG format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
destination |
BytesIO | Path | str
|
Destination to save file to. When BytesIO is provided, file will be saved to buffer. When Path or str is provided, they are treated as file path and will be used to open and save file on disk. |
required |
color_scheme |
ColorScheme
|
Color scheme of image, by default ColorScheme.COPPER |
COPPER
|
scale |
float
|
Scale of image, can be used to scale very large or very small images, by default 1.0 |
1.0
|
Source code in src/pygerber/gerberx3/api/_v2.py
render_raster
¶
render_raster(
destination: BytesIO | Path | str,
*,
color_scheme: ColorScheme = ColorScheme.COPPER,
dpmm: int = 20,
image_format: ImageFormatEnum = ImageFormatEnum.AUTO,
pixel_format: PixelFormatEnum = PixelFormatEnum.RGB
) -> None
Render Gerber file to raster image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
destination |
BytesIO | Path | str
|
Destination to save file to. When BytesIO is provided, file will be saved to buffer. When Path or str is provided, they are treated as file path and will be used to open and save file on disk. |
required |
color_scheme |
ColorScheme
|
Color scheme of image, by default ColorScheme.COPPER |
COPPER
|
dpmm |
int
|
Resolution of image in dots per millimeter, by default 96 |
20
|
image_format |
ImageFormatEnum
|
Image format to save, by default ImageFormatEnum.AUTO |
AUTO
|
pixel_format |
PixelFormatEnum
|
Pixel format, by default PixelFormatEnum.RGB |
RGB
|
Source code in src/pygerber/gerberx3/api/_v2.py
ParsedProject
¶
Multi file project representation.
This object can be used to render multiple Gerber files to single image. It automatically performs alignment and merging of files.
Source code in src/pygerber/gerberx3/api/_v2.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
render_raster
¶
render_raster(
destination: BytesIO | Path | str,
*,
color_map: COLOR_MAP_T = DEFAULT_COLOR_MAP,
dpmm: int = 20,
image_format: ImageFormatEnum = ImageFormatEnum.AUTO,
pixel_format: PixelFormatEnum = PixelFormatEnum.RGB
) -> None
Render all Gerber file, align them and merge into single file.
Resulting image will be saved to given destination
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
destination |
BytesIO | Path | str
|
Destination to save file to. When BytesIO is provided, file will be saved to buffer. When Path or str is provided, they are treated as file path and will be used to open and save file on disk. |
required |
color_map |
COLOR_MAP_T
|
Mapping from image type to color scheme, by default DEFAULT_COLOR_MAP |
DEFAULT_COLOR_MAP
|
dpmm |
int
|
Resolution of image in dots per millimeter, by default 96 |
20
|
image_format |
ImageFormatEnum
|
Image format to save, by default ImageFormatEnum.AUTO |
AUTO
|
pixel_format |
PixelFormatEnum
|
Pixel format, by default PixelFormatEnum.RGB |
RGB
|
Source code in src/pygerber/gerberx3/api/_v2.py
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
PixelFormatEnum
¶
Project
¶
Multi file project representation.
This object can be used to render multiple Gerber files to single image. It automatically performs alignment and merging of files. Files should be ordered bottom up, topmost layer last, like if adding one layer on top of previous.
Source code in src/pygerber/gerberx3/api/_v2.py
parse
¶
Parse all Gerber files one by one.