Skip to content

Commit

Permalink
Extract enums used by nodes into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
Argmaster committed Aug 19, 2024
1 parent bbe7be9 commit 7c31175
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 164 deletions.
44 changes: 1 addition & 43 deletions src/pygerber/gerberx3/ast/nodes/attribute/TA.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING, Callable, List, Literal, Optional

from pydantic import Field

from pygerber.gerberx3.ast.nodes.base import Node
from pygerber.gerberx3.ast.nodes.enums import AperFunction

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -36,48 +36,6 @@ def get_visitor_callback_function(
return visitor.on_ta_user_name


class AperFunction(Enum):
"""Enum representing possible AperFunction values."""

ViaDrill = "ViaDrill"
BackDrill = "BackDrill"
ComponentDrill = "ComponentDrill"
MechanicalDrill = "MechanicalDrill"
CastellatedDrill = "CastellatedDrill"
OtherDrill = "OtherDrill"
ComponentPad = "ComponentPad"
SMDPad = "SMDPad"
BGAPad = "BGAPad"
ConnectorPad = "ConnectorPad"
HeatsinkPad = "HeatsinkPad"
ViaPad = "ViaPad"
TestPad = "TestPad"
CastellatedPad = "CastellatedPad"
FiducialPad = "FiducialPad"
ThermalReliefPad = "ThermalReliefPad"
WasherPad = "WasherPad"
AntiPad = "AntiPad"
OtherPad = "OtherPad"
Conductor = "Conductor"
EtchedComponent = "EtchedComponent"
NonConductor = "NonConductor"
CopperBalancing = "CopperBalancing"
Border = "Border"
OtherCopper = "OtherCopper"
ComponentMain = "ComponentMain"
ComponentOutline = "ComponentOutline"
ComponentPin = "ComponentPin"
Profile = "Profile"
Material = "Material"
NonMaterial = "NonMaterial"
Other = "Other"

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class TA_AperFunction(TA): # noqa: N801
"""Represents TA .AperFunction Gerber attribute."""

Expand Down
48 changes: 1 addition & 47 deletions src/pygerber/gerberx3/ast/nodes/attribute/TF.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import datetime # noqa: TCH003
import hashlib
from enum import Enum
from typing import TYPE_CHECKING, Callable, List, Literal, Optional

from pydantic import Field

from pygerber.gerberx3.ast.nodes.base import Node
from pygerber.gerberx3.ast.nodes.enums import FileFunction, Part

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -38,16 +38,6 @@ def get_visitor_callback_function(
return visitor.on_tf_user_name


class Part(Enum):
"""Enumerate supported part types."""

Single = "Single"
Array = "Array"
FabricationPanel = "FabricationPanel"
Coupon = "Coupon"
Other = "Other"


class TF_Part(TF): # noqa: N801
"""Represents TF Gerber extended command with part attribute."""

Expand All @@ -65,42 +55,6 @@ def get_visitor_callback_function(
return visitor.on_tf_part


class FileFunction(Enum):
"""Enumerate supported file function types."""

Copper = "Copper"
Plated = "Plated"
NonPlated = "NonPlated"
Profile = "Profile"
Soldermask = "Soldermask"
Legend = "Legend"
Component = "Component"
Paste = "Paste"
Glue = "Glue"
Carbonmask = "Carbonmask"
Goldmask = "Goldmask"
Heatsinkmask = "Heatsinkmask"
Peelablemask = "Peelablemask"
Silvermask = "Silvermask"
Tinmask = "Tinmask"
Depthrout = "Depthrout"
Vcut = "Vcut"
Viafill = "Viafill"
Pads = "Pads"
Other = "Other"
Drillmap = "Drillmap"
FabricationDrawing = "FabricationDrawing"
Vcutmap = "Vcutmap"
AssemblyDrawing = "AssemblyDrawing"
ArrayDrawing = "ArrayDrawing"
OtherDrawing = "OtherDrawing"

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class TF_FileFunction(TF): # noqa: N801
"""Represents TF Gerber extended command with file function attribute."""

Expand Down
11 changes: 1 addition & 10 deletions src/pygerber/gerberx3/ast/nodes/attribute/TO.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING, Callable, List, Optional

from pydantic import Field

from pygerber.gerberx3.ast.nodes.base import Node
from pygerber.gerberx3.ast.nodes.enums import Mount
from pygerber.gerberx3.ast.nodes.types import Double

if TYPE_CHECKING:
Expand Down Expand Up @@ -151,15 +151,6 @@ def get_visitor_callback_function(
return visitor.on_to_cval


class Mount(Enum):
"""Mount type enumeration."""

SMD = "SMD"
TH = "TH"
Pressfit = "Pressfit"
Other = "Other"


class TO_CMnt(TO): # noqa: N801
"""Represents TO Gerber extended command with .CMnt attribute."""

Expand Down
3 changes: 2 additions & 1 deletion src/pygerber/gerberx3/ast/nodes/d_codes/Dnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING, Callable

from pygerber.gerberx3.ast.nodes.d_codes.D import D
from pygerber.gerberx3.ast.nodes.types import ApertureIdStr

if TYPE_CHECKING:
from typing_extensions import Self
Expand All @@ -15,7 +16,7 @@
class Dnn(D):
"""Represents DNN Gerber command."""

value: str
aperture_id: ApertureIdStr

def visit(self, visitor: AstVisitor) -> None:
"""Handle visitor call."""
Expand Down
177 changes: 177 additions & 0 deletions src/pygerber/gerberx3/ast/nodes/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
"""`pygerber.gerberx3.ast.nodes.enums` module contains definition of enums used in
GerberX3 AST nodes.
"""

from __future__ import annotations

from enum import Enum


class Zeros(Enum):
"""Zeros enumeration."""

SKIP_LEADING = "L"
"""Skip leading zeros mode."""

SKIP_TRAILING = "T"
"""Skip trailing zeros mode."""

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class CoordinateMode(Enum):
"""Coordinate mode enumeration."""

ABSOLUTE = "A"
"""Absolute coordinate mode."""

INCREMENTAL = "I"
"""Incremental coordinate mode."""

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class AperFunction(Enum):
"""Enum representing possible AperFunction values."""

ViaDrill = "ViaDrill"
BackDrill = "BackDrill"
ComponentDrill = "ComponentDrill"
MechanicalDrill = "MechanicalDrill"
CastellatedDrill = "CastellatedDrill"
OtherDrill = "OtherDrill"
ComponentPad = "ComponentPad"
SMDPad = "SMDPad"
BGAPad = "BGAPad"
ConnectorPad = "ConnectorPad"
HeatsinkPad = "HeatsinkPad"
ViaPad = "ViaPad"
TestPad = "TestPad"
CastellatedPad = "CastellatedPad"
FiducialPad = "FiducialPad"
ThermalReliefPad = "ThermalReliefPad"
WasherPad = "WasherPad"
AntiPad = "AntiPad"
OtherPad = "OtherPad"
Conductor = "Conductor"
EtchedComponent = "EtchedComponent"
NonConductor = "NonConductor"
CopperBalancing = "CopperBalancing"
Border = "Border"
OtherCopper = "OtherCopper"
ComponentMain = "ComponentMain"
ComponentOutline = "ComponentOutline"
ComponentPin = "ComponentPin"
Profile = "Profile"
Material = "Material"
NonMaterial = "NonMaterial"
Other = "Other"

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class Part(Enum):
"""Enumerate supported part types."""

Single = "Single"
Array = "Array"
FabricationPanel = "FabricationPanel"
Coupon = "Coupon"
Other = "Other"


class FileFunction(Enum):
"""Enumerate supported file function types."""

Copper = "Copper"
Plated = "Plated"
NonPlated = "NonPlated"
Profile = "Profile"
Soldermask = "Soldermask"
Legend = "Legend"
Component = "Component"
Paste = "Paste"
Glue = "Glue"
Carbonmask = "Carbonmask"
Goldmask = "Goldmask"
Heatsinkmask = "Heatsinkmask"
Peelablemask = "Peelablemask"
Silvermask = "Silvermask"
Tinmask = "Tinmask"
Depthrout = "Depthrout"
Vcut = "Vcut"
Viafill = "Viafill"
Pads = "Pads"
Other = "Other"
Drillmap = "Drillmap"
FabricationDrawing = "FabricationDrawing"
Vcutmap = "Vcutmap"
AssemblyDrawing = "AssemblyDrawing"
ArrayDrawing = "ArrayDrawing"
OtherDrawing = "OtherDrawing"

def __repr__(self) -> str:
return f"{self.__class__.__name__}.{self.name}"

__str__ = __repr__


class Mount(Enum):
"""Mount type enumeration."""

SMD = "SMD"
TH = "TH"
Pressfit = "Pressfit"
Fiducial = "Fiducial"
Other = "Other"


class Mirroring(Enum):
"""Mirroring enum."""

None_ = "N"
X = "X"
Y = "Y"
XY = "XY"


class Polarity(Enum):
"""Polarity enum."""

Clear = "C"
Dark = "D"


class AxisCorrespondence(Enum):
"""Represents axis correspondence."""

AX_BY = "AXBY"
AY_BX = "AYBX"


class UnitMode(Enum):
"""Unit mode enumeration."""

IMPERIAL = "IN"
"""Imperial unit mode. In this mode inches are used to express lengths."""
METRIC = "MM"
"""Metric unit mode. In this mode millimeters are used to express lengths."""


class ImagePolarity(Enum):
"""Image polarity enumeration."""

POSITIVE = "POS"
"""Positive image polarity."""

NEGATIVE = "NEG"
"""Negative image polarity."""
11 changes: 1 addition & 10 deletions src/pygerber/gerberx3/ast/nodes/load/LM.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,17 @@

from __future__ import annotations

from enum import Enum
from typing import TYPE_CHECKING, Callable

from pygerber.gerberx3.ast.nodes.base import Node
from pygerber.gerberx3.state_enums import Mirroring

if TYPE_CHECKING:
from typing_extensions import Self

from pygerber.gerberx3.ast.visitor import AstVisitor


class Mirroring(Enum):
"""Mirroring enum."""

None_ = "N"
X = "X"
Y = "Y"
XY = "XY"


class LM(Node):
"""Represents LM Gerber extended command."""

Expand Down
Loading

0 comments on commit 7c31175

Please sign in to comment.