API 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
infer_from_attributes
classmethod
¶
Infer file type from file extension.
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
141 142 143 144 145 146 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 |
|
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.
Source code in src\pygerber\gerberx3\api\_v2.py
from_buffer
classmethod
¶
Initialize object with Gerber source code from readable buffer.
Source code in src\pygerber\gerberx3\api\_v2.py
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
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
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,
quality: int = 85
) -> 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
|
quality |
int
|
Image quality for JPEG format, by default 85. |
85
|
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
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
|
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
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 |
|
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.