Skip to content

state_tracking_visitor

The state_tracking_visitor module contains definition of StateTrackingVisitor class.

CoordinateFormat

Bases: _StateModel

Coordinate format information.

unpack_x

unpack_x(coordinate: PackedCoordinateStr) -> Double

Unpack X coordinate using the current coordinate format.

unpack_y

unpack_y(coordinate: PackedCoordinateStr) -> Double

Unpack X coordinate using the current coordinate format.

pack_x

pack_x(coordinate: Double) -> PackedCoordinateStr

Unpack X coordinate using the current coordinate format.

pack_y

pack_y(coordinate: Double) -> PackedCoordinateStr

Pack X coordinate using the current coordinate format.

Attributes

Bases: _StateModel

Attributes Gerber X3 of apertures, objects and file.

aperture_attributes class-attribute instance-attribute

aperture_attributes: Dict[str, TA] = Field(
    default_factory=dict
)

Object attributes created with TA extended command.

file_attributes class-attribute instance-attribute

file_attributes: Dict[str, TF] = Field(default_factory=dict)

Object attributes created with TF extended command.

object_attributes class-attribute instance-attribute

object_attributes: Dict[str, TO] = Field(
    default_factory=dict
)

Object attributes created with TO extended command.

ImageAttributes

Bases: _StateModel

Legacy attributes of the image.

polarity class-attribute instance-attribute

polarity: ImagePolarity = Field(default=None)

The name of the image. (Spec reference: 8.1.4)

rotation class-attribute instance-attribute

rotation: Double = Field(default=0.0)

The rotation of the image. (Spec reference: 8.1.5)

a_axis_mirroring class-attribute instance-attribute

a_axis_mirroring: int = Field(default=0)

The mirroring of A axis of the image. (Spec reference: 8.1.7)

b_axis_mirroring class-attribute instance-attribute

b_axis_mirroring: int = Field(default=0)

The mirroring of B axis of the image. (Spec reference: 8.1.7)

a_axis_offset class-attribute instance-attribute

a_axis_offset: Optional[Double] = Field(default=0)

The offset of A axis of the image. (Spec reference: 8.1.8)

b_axis_offset class-attribute instance-attribute

b_axis_offset: Optional[Double] = Field(default=0)

The offset of B axis of the image. (Spec reference: 8.1.8)

a_axis_scale class-attribute instance-attribute

a_axis_scale: Optional[Double] = Field(default=0)

The scale of A axis of the image. (Spec reference: 8.1.9)

b_axis_scale class-attribute instance-attribute

b_axis_scale: Optional[Double] = Field(default=0)

The scale of B axis of the image. (Spec reference: 8.1.9)

image_name class-attribute instance-attribute

image_name: Optional[str] = Field(default=None)

The name of the image. (Spec reference: 8.1.3)

file_name class-attribute instance-attribute

file_name: Optional[str] = Field(default=None)

The name of the file. (Spec reference: 8.1.6)

axis_correspondence class-attribute instance-attribute

axis_correspondence: AxisCorrespondence = Field(
    default=AX_BY
)

The axis correspondence. (Spec reference: 8.1.2)

Transform

Bases: _StateModel

Aperture transformations.

polarity class-attribute instance-attribute

polarity: Polarity = Field(default=Dark)

Aperture polarity set with LP command. (Spec reference: 4.9.2)

mirroring class-attribute instance-attribute

mirroring: Mirroring = Field(default=NONE)

Aperture mirroring set with LM command. (Spec reference: 4.9.3)

rotation class-attribute instance-attribute

rotation: Double = Field(default=0.0)

Aperture rotation set with LR command. (Spec reference: 4.9.4)

scaling class-attribute instance-attribute

scaling: Double = Field(default=1.0)

Aperture scaling set with LS command. (Spec reference: 4.9.5)

tag property

tag: str

Get string tag identifying the transformation.

PlotMode

Bases: Enum

Plot mode of the Gerber file.

LINEAR class-attribute instance-attribute

LINEAR = 'LINEAR'

Linear interpolation mode.

ARC class-attribute instance-attribute

ARC = 'ARC'

Clockwise circular interpolation mode.

CCW_ARC class-attribute instance-attribute

CCW_ARC = 'CCW_ARC'

Counter-clockwise circular interpolation mode.

ArcInterpolation

Bases: Enum

Arc interpolation mode.

SINGLE_QUADRANT class-attribute instance-attribute

SINGLE_QUADRANT = 'SINGLE_QUADRANT'

Single quadrant mode.

MULTI_QUADRANT class-attribute instance-attribute

MULTI_QUADRANT = 'MULTI_QUADRANT'

Multi quadrant mode.

ApertureStorage

Bases: _StateModel

Storage for apertures.

apertures class-attribute instance-attribute

apertures: Dict[ApertureIdStr, AD] = Field(
    default_factory=dict
)

Aperture storage.

blocks class-attribute instance-attribute

blocks: Dict[ApertureIdStr, AB] = Field(
    default_factory=dict
)

Block aperture storage.

macros class-attribute instance-attribute

macros: Dict[str, AM] = Field(default_factory=dict)

Macro definition storage.

per_aperture_attributes class-attribute instance-attribute

per_aperture_attributes: Dict[str, Dict[str, TA]] = Field(
    default_factory=dict
)

Attributes assigned to apertures during creation.

get_next_free_aperture_code

get_next_free_aperture_code() -> int

Get next free aperture code.

State

Bases: _StateModel

Internal state of the compiler.

unit_mode class-attribute instance-attribute

unit_mode: UnitMode = Field(default=METRIC)

The draw units used for the Gerber file. (Spec reference: 4.2.1)

coordinate_format class-attribute instance-attribute

coordinate_format: Optional[CoordinateFormat] = Field(
    default=None
)

The coordinate format specification, including the number of decimals. (Spec reference: 4.2.2)

plot_mode class-attribute instance-attribute

plot_mode: PlotMode = Field(default=LINEAR)

The plot mode. (Spec reference 4.7)

arc_interpolation class-attribute instance-attribute

arc_interpolation: ArcInterpolation = Field(
    default=SINGLE_QUADRANT
)

The arc interpolation mode. (Spec reference: 4.7.2)

current_aperture_id class-attribute instance-attribute

current_aperture_id: Optional[ApertureIdStr] = Field(
    default=None
)

The ID of currently selected aperture. (Spec reference: 8.6)

current_x class-attribute instance-attribute

current_x: Double = Field(default=0.0)

Current X coordinate value.

current_y class-attribute instance-attribute

current_y: Double = Field(default=0.0)

Current Y coordinate value.

coordinate_x class-attribute instance-attribute

coordinate_x: Optional[Double] = Field(default=None)

Last X coordinate value set by CoordinateX node.

coordinate_y class-attribute instance-attribute

coordinate_y: Optional[Double] = Field(default=None)

Last Y coordinate value set by CoordinateY node.

coordinate_i class-attribute instance-attribute

coordinate_i: Optional[Double] = Field(default=None)

Last I coordinate value set by CoordinateI node.

coordinate_j class-attribute instance-attribute

coordinate_j: Optional[Double] = Field(default=None)

Last J coordinate value set by CoordinateJ node.

transform class-attribute instance-attribute

transform: Transform = Field(default_factory=Transform)

Current aperture transformation parameters.

apertures class-attribute instance-attribute

apertures: ApertureStorage = Field(
    default_factory=ApertureStorage
)

Container for different types of apertures.

attributes class-attribute instance-attribute

attributes: Attributes = Field(default_factory=Attributes)

Container for holding currently active attributes.

image_attributes class-attribute instance-attribute

image_attributes: ImageAttributes = Field(
    default_factory=ImageAttributes
)

Container for holding legacy image attributes.

is_region class-attribute instance-attribute

is_region: bool = Field(default=False)

Flag indicating if visitor is in region mode.

current_aperture property

current_aperture: AD | AB

Get currently selected aperture.

ProgramStop

Bases: Exception

Exception raised when M00 or M02 command is encountered.

StateTrackingVisitor

Bases: AstVisitor

StateTrackingVisitor is a visitor class that tracks the internal state defined in the Gerber X3 specification and modifies it according to Gerber commands.

Additionally, it defines a set of higher level callback methods that extend interface of AstVisitor class.

coordinate_x property

coordinate_x: Double

Get X coordinate.

coordinate_y property

coordinate_y: Double

Get Y coordinate.

coordinate_i property

coordinate_i: Double

Get X coordinate.

coordinate_j property

coordinate_j: Double

Get Y coordinate.

is_negative property

is_negative: bool

Check if current aperture is negative.

on_ab

on_ab(node: AB) -> AB

Handle AB node.

on_ad

on_ad(node: AD) -> None

Handle AD node.

on_am

on_am(node: AM) -> AM

Handle AM root node.

on_ta

on_ta(node: TA) -> None

Handle TA_UserName node.

on_tf

on_tf(node: TF) -> None

Handle TF node.

on_to

on_to(node: TO) -> None

Handle TO node.

on_td

on_td(node: TD) -> TD

Handle TD node.

on_d01

on_d01(node: D01) -> D01

Handle D01 node.

on_draw_line

on_draw_line(node: D01) -> None

Handle D01 node in linear interpolation mode.

on_draw_cw_arc_sq

on_draw_cw_arc_sq(node: D01) -> None

Handle D01 node in clockwise circular interpolation single quadrant mode.

on_draw_cw_arc_mq

on_draw_cw_arc_mq(node: D01) -> None

Handle D01 node in clockwise circular interpolation multi quadrant mode.

on_draw_ccw_arc_sq

on_draw_ccw_arc_sq(node: D01) -> None

Handle D01 node in counter-clockwise circular interpolation single quadrant mode.

on_draw_ccw_arc_mq

on_draw_ccw_arc_mq(node: D01) -> None

Handle D01 node in counter-clockwise circular interpolation multi quadrant mode.

on_d02

on_d02(node: D02) -> D02

Handle D02 node.

on_d03

on_d03(node: D03) -> D03

Handle D03 node.

on_flash_circle

on_flash_circle(node: D03, aperture: ADC) -> None

Handle D03 node with ADC aperture.

on_flash_rectangle

on_flash_rectangle(node: D03, aperture: ADR) -> None

Handle D03 node with ADR aperture.

on_flash_obround

on_flash_obround(node: D03, aperture: ADO) -> None

Handle D03 node with ADO aperture.

on_flash_polygon

on_flash_polygon(node: D03, aperture: ADP) -> None

Handle D03 node with ADP aperture.

on_flash_macro

on_flash_macro(node: D03, aperture: ADmacro) -> None

Handle D03 node with ADM aperture.

on_flash_block

on_flash_block(node: D03, aperture: AB) -> None

Handle D03 node with AB aperture.

on_dnn

on_dnn(node: Dnn) -> Dnn

Handle Dnn node.

on_g01

on_g01(node: G01) -> G01

Handle G01 node.

on_g02

on_g02(node: G02) -> G02

Handle G02 node.

on_g03

on_g03(node: G03) -> G03

Handle G03 node.

on_g36

on_g36(node: G36) -> G36

Handle G36 node.

on_start_region

on_start_region() -> None

Handle start of region.

on_in_region_draw_line

on_in_region_draw_line(node: D01) -> None

Handle D01 node in linear interpolation mode in region.

on_in_region_draw_cw_arc_sq

on_in_region_draw_cw_arc_sq(node: D01) -> None

Handle D01 node in clockwise circular interpolation single quadrant mode within region statement.

on_in_region_draw_cw_arc_mq

on_in_region_draw_cw_arc_mq(node: D01) -> None

Handle D01 node in clockwise circular interpolation multi quadrant mode within region statement.

on_in_region_draw_ccw_arc_sq

on_in_region_draw_ccw_arc_sq(node: D01) -> None

Handle D01 node in counter-clockwise circular interpolation single quadrant mode within region statement.

on_in_region_draw_ccw_arc_mq

on_in_region_draw_ccw_arc_mq(node: D01) -> None

Handle D01 node in counter-clockwise circular interpolation multi quadrant mode within region statement.

on_g37

on_g37(node: G37) -> G37

Handle G37 node.

on_flush_region

on_flush_region() -> None

Handle flush region after D02 command or after G37.

on_end_region

on_end_region() -> None

Handle end of region.

on_g70

on_g70(node: G70) -> G70

Handle G70 node.

on_g71

on_g71(node: G71) -> G71

Handle G71 node.

on_g74

on_g74(node: G74) -> G74

Handle G74 node.

on_g75

on_g75(node: G75) -> G75

Handle G75 node.

on_g90

on_g90(node: G90) -> G90

Handle G90 node.

on_g91

on_g91(node: G91) -> G91

Handle G91 node.

on_lm

on_lm(node: LM) -> LM

Handle LM node.

on_ln

on_ln(node: LN) -> LN

Handle LN node.

on_lp

on_lp(node: LP) -> LP

Handle LP node.

on_lr

on_lr(node: LR) -> LR

Handle LR node.

on_ls

on_ls(node: LS) -> LS

Handle LS node.

on_m00

on_m00(node: M00) -> M00

Handle M00 node.

on_m02

on_m02(node: M02) -> M02

Handle M02 node.

on_coordinate_x

on_coordinate_x(node: CoordinateX) -> CoordinateX

Handle Coordinate node.

on_coordinate_y

on_coordinate_y(node: CoordinateY) -> CoordinateY

Handle Coordinate node.

on_coordinate_i

on_coordinate_i(node: CoordinateI) -> CoordinateI

Handle Coordinate node.

on_coordinate_j

on_coordinate_j(node: CoordinateJ) -> CoordinateJ

Handle Coordinate node.

on_as

on_as(node: AS) -> AS

Handle AS node.

on_fs

on_fs(node: FS) -> FS

Handle FS node.

on_in

on_in(node: IN) -> IN

Handle IN node.

on_ip

on_ip(node: IP) -> IP

Handle IP node.

on_ir

on_ir(node: IR) -> IR

Handle IR node.

on_mi

on_mi(node: MI) -> MI

Handle MI node.

on_mo

on_mo(node: MO) -> MO

Handle MO node.

on_of

on_of(node: OF) -> OF

Handle OF node.

on_sf

on_sf(node: SF) -> SF

Handle SF node.

on_file

on_file(node: File) -> File

Handle File node.

on_exception

on_exception(node: Node, exception: Exception) -> bool

Handle exception.