Bases: ExtendedCommandToken
Wrapper for image polarity token.
The IP command is deprecated.
IP sets positive or negative polarity for the entire image. It can only be used
once, at the beginning of the file.
See section 8.1.4 of The Gerber Layer Format Specification Revision 2023.03 - https://argmaster.github.io/pygerber/stable/gerber_specification/revision_2023_03.html
Source code in src\pygerber\gerberx3\tokenizer\tokens\ip_image_polarity.py
| class ImagePolarity(ExtendedCommandToken):
"""Wrapper for image polarity token.
The IP command is deprecated.
IP sets positive or negative polarity for the entire image. It can only be used
once, at the beginning of the file.
See section 8.1.4 of The Gerber Layer Format Specification Revision 2023.03 - https://argmaster.github.io/pygerber/stable/gerber_specification/revision_2023_03.html
"""
def __init__(
self,
string: str,
location: int,
image_polarity: ImagePolarityEnum,
) -> None:
super().__init__(string, location)
self.image_polarity = image_polarity
@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()`.
"""
image_polarity = ImagePolarityEnum(tokens["image_polarity"])
return cls(
string=string,
location=location,
image_polarity=image_polarity,
)
def update_drawing_state(
self,
state: State,
_backend: Backend,
) -> Tuple[State, Iterable[DrawCommand]]:
"""Set drawing polarity."""
warn_deprecated_code("IP", "8.1.4")
return (
state.model_copy(
update={
"is_output_image_negation_required": (
self.image_polarity == ImagePolarityEnum.NEGATIVE
),
},
),
(),
)
def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().image_polarity.pre_parser_visit_token(self, context)
context.get_hooks().image_polarity.on_parser_visit_token(self, context)
context.get_hooks().image_polarity.post_parser_visit_token(self, context)
def get_gerber_code(
self,
indent: str = "",
endline: str = "\n",
) -> str:
"""Get gerber code represented by this token."""
return f"IP{self.image_polarity.get_gerber_code(indent, endline)}"
|
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\ip_image_polarity.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()`.
"""
image_polarity = ImagePolarityEnum(tokens["image_polarity"])
return cls(
string=string,
location=location,
image_polarity=image_polarity,
)
|
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\ip_image_polarity.py
| def update_drawing_state(
self,
state: State,
_backend: Backend,
) -> Tuple[State, Iterable[DrawCommand]]:
"""Set drawing polarity."""
warn_deprecated_code("IP", "8.1.4")
return (
state.model_copy(
update={
"is_output_image_negation_required": (
self.image_polarity == ImagePolarityEnum.NEGATIVE
),
},
),
(),
)
|
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\ip_image_polarity.py
| def parser2_visit_token(self, context: Parser2Context) -> None:
"""Perform actions on the context implicated by this token."""
context.get_hooks().image_polarity.pre_parser_visit_token(self, context)
context.get_hooks().image_polarity.on_parser_visit_token(self, context)
context.get_hooks().image_polarity.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\ip_image_polarity.py
| def get_gerber_code(
self,
indent: str = "",
endline: str = "\n",
) -> str:
"""Get gerber code represented by this token."""
return f"IP{self.image_polarity.get_gerber_code(indent, endline)}"
|