Bases: ExtendedCommandToken
Wrapper for load scaling token.
LS Command: Scaling Graphics State Parameter
The LS
command is employed to establish the scaling graphics state parameter.
Functionality:
- The command dictates the scale factor utilized during object creation.
- The aperture undergoes scaling, anchored at its origin. It's crucial to note that
this origin might not always align with its geometric center.
Usage and Persistence:
- The LS
command can be invoked multiple times within a single file.
- Once set, the object scaling retains its value unless a subsequent LS
command
modifies it.
- The scaling gets adjusted based on the specific value mentioned in the command and
doesn't accumulate with the preceding scale factor.
The LS command was introduced in revision 2016.12.
See section 4.9.5 of The Gerber Layer Format Specification Revision 2023.03 - https://argmaster.github.io/pygerber/latest/gerber_specification/revision_2023_03.html
Source code in src/pygerber/gerberx3/tokenizer/tokens/ls_load_scaling.py
| class LoadScaling(ExtendedCommandToken):
"""Wrapper for load scaling token.
### LS Command: Scaling Graphics State Parameter
The `LS` command is employed to establish the scaling graphics state parameter.
Functionality:
- The command dictates the scale factor utilized during object creation.
- The aperture undergoes scaling, anchored at its origin. It's crucial to note that
this origin might not always align with its geometric center.
Usage and Persistence:
- The `LS` command can be invoked multiple times within a single file.
- Once set, the object scaling retains its value unless a subsequent `LS` command
modifies it.
- The scaling gets adjusted based on the specific value mentioned in the command and
doesn't accumulate with the preceding scale factor.
The LS command was introduced in revision 2016.12.
See section 4.9.5 of The Gerber Layer Format Specification Revision 2023.03 - https://argmaster.github.io/pygerber/latest/gerber_specification/revision_2023_03.html
"""
def __init__(
self,
string: str,
location: int,
scaling: Decimal,
) -> None:
super().__init__(string, location)
self.scaling = scaling
@classmethod
def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
"""Create instance of this class.
Created to be used as callback in `ParserElement.set_parse_action()`.
"""
scaling = Decimal(str(tokens["scaling"]))
return cls(string=string, location=location, scaling=scaling)
def update_drawing_state(
self,
state: State,
_backend: Backend,
) -> Tuple[State, Iterable[DrawCommand]]:
"""Set drawing polarity."""
return (
state.model_copy(
update={
"scaling": self.scaling,
},
),
(),
)
def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().load_scaling.pre_parser_visit_token(self, context)
context.get_hooks().load_scaling.on_parser_visit_token(self, context)
context.get_hooks().load_scaling.post_parser_visit_token(self, context)
def get_gerber_code(
self,
indent: str = "", # noqa: ARG002
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return f"LS{self.scaling}"
|
new
classmethod
new(
string: str, location: int, tokens: ParseResults
) -> Self
Create instance of this class.
Created to be used as callback in ParserElement.set_parse_action()
.
Source code in src/pygerber/gerberx3/tokenizer/tokens/ls_load_scaling.py
| @classmethod
def new(cls, string: str, location: int, tokens: ParseResults) -> Self:
"""Create instance of this class.
Created to be used as callback in `ParserElement.set_parse_action()`.
"""
scaling = Decimal(str(tokens["scaling"]))
return cls(string=string, location=location, scaling=scaling)
|
update_drawing_state
update_drawing_state(
state: State, _backend: Backend
) -> Tuple[State, Iterable[DrawCommand]]
Set drawing polarity.
Source code in src/pygerber/gerberx3/tokenizer/tokens/ls_load_scaling.py
| def update_drawing_state(
self,
state: State,
_backend: Backend,
) -> Tuple[State, Iterable[DrawCommand]]:
"""Set drawing polarity."""
return (
state.model_copy(
update={
"scaling": self.scaling,
},
),
(),
)
|
parser2_visit_token
parser2_visit_token(context: Parser2Context) -> None
Perform actions on the context implicated by this token.
Source code in src/pygerber/gerberx3/tokenizer/tokens/ls_load_scaling.py
| def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().load_scaling.pre_parser_visit_token(self, context)
context.get_hooks().load_scaling.on_parser_visit_token(self, context)
context.get_hooks().load_scaling.post_parser_visit_token(self, context)
|
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/ls_load_scaling.py
| def get_gerber_code(
self,
indent: str = "", # noqa: ARG002
endline: str = "\n", # noqa: ARG002
) -> str:
"""Get gerber code represented by this token."""
return f"LS{self.scaling}"
|