Bases: GerberCode
, FrozenGeneralModel
Coordinate data.
A number whose interpretation is determined by the FS command. It is used to specify
the X and Y coordinates of a point in the image plane and a distance
or offset in the X and Y direction.
Source code in src/pygerber/gerberx3/tokenizer/tokens/coordinate.py
| class Coordinate(GerberCode, FrozenGeneralModel):
"""## Coordinate data.
A number whose interpretation is determined by the FS command. It is used to specify
the X and Y coordinates of a point in the image plane and a distance
or offset in the X and Y direction.
"""
coordinate_type: CoordinateType
sign: CoordinateSign
offset: str
@classmethod
def new(cls, coordinate_type: CoordinateType, offset: Optional[str]) -> Self:
"""Create new Coordinate object."""
if offset is None:
coordinate_type = coordinate_type.to_missing()
offset = ""
sign = CoordinateSign.Positive
elif len(offset) > 0 and offset[0] in "+-":
sign = CoordinateSign(offset[0])
offset = offset[1:].ljust(1, "0")
else:
sign = CoordinateSign.Positive
return cls(coordinate_type=coordinate_type, sign=sign, offset=offset)
def get_gerber_code(
self,
indent: str = "",
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return (
""
if self.coordinate_type.is_missing()
else f"{indent}{self.coordinate_type}{self.sign}{self.offset}"
)
|
new
classmethod
new(
coordinate_type: CoordinateType, offset: Optional[str]
) -> Self
Create new Coordinate object.
Source code in src/pygerber/gerberx3/tokenizer/tokens/coordinate.py
| @classmethod
def new(cls, coordinate_type: CoordinateType, offset: Optional[str]) -> Self:
"""Create new Coordinate object."""
if offset is None:
coordinate_type = coordinate_type.to_missing()
offset = ""
sign = CoordinateSign.Positive
elif len(offset) > 0 and offset[0] in "+-":
sign = CoordinateSign(offset[0])
offset = offset[1:].ljust(1, "0")
else:
sign = CoordinateSign.Positive
return cls(coordinate_type=coordinate_type, sign=sign, offset=offset)
|
get_gerber_code
get_gerber_code(
indent: str = "", endline: str = "\n"
) -> str
Get gerber code represented by this token.
Source code in src/pygerber/gerberx3/tokenizer/tokens/coordinate.py
| def get_gerber_code(
self,
indent: str = "",
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return (
""
if self.coordinate_type.is_missing()
else f"{indent}{self.coordinate_type}{self.sign}{self.offset}"
)
|