Skip to content

g70_set_unit_inch

g70_set_unit_inch

Wrapper for G70 token.

SetUnitInch

Bases: CommandToken

Wrapper for G70 token.

Set the Unit to inch.

This historic codes perform a function handled by the MO command. See 4.2.1. Sometimes used. Deprecated in 2012

See section 8.1 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/g70_set_unit_inch.py
class SetUnitInch(CommandToken):
    """Wrapper for G70 token.

    Set the `Unit` to inch.

    This historic codes perform a function handled by the MO command. See 4.2.1.
    Sometimes used. Deprecated in 2012

    See section 8.1 of The Gerber Layer Format Specification Revision 2023.03 - https://argmaster.github.io/pygerber/latest/gerber_specification/revision_2023_03.html
    """

    def update_drawing_state(
        self,
        state: State,
        _backend: Backend,
    ) -> Tuple[State, Iterable[DrawCommand]]:
        """Set drawing polarity."""
        warn_deprecated_code("G70", "8.1")
        logging.warning(
            "Detected use of imperial units. Using metric units is recommended. "
            "Imperial units will be deprecated in future. "
            "(See 4.2.1 in Gerber Layer Format Specification)",
        )
        if state.draw_units is not None:
            logging.warning(
                "Overriding coordinate units is illegal. "
                "(See section 4.2.2 of The Gerber Layer Format Specification "
                "Revision 2023.03 - https://argmaster.github.io/pygerber/latest/gerber_specification/revision_2023_03.html)",
            )
        return (
            state.model_copy(
                update={
                    "draw_units": Unit.Inches,
                },
            ),
            (),
        )

    def parser2_visit_token(self, context: Parser2Context) -> None:
        """Perform actions on the context implicated by this token."""
        context.get_hooks().set_unit_inch.pre_parser_visit_token(self, context)
        context.get_hooks().set_unit_inch.on_parser_visit_token(self, context)
        context.get_hooks().set_unit_inch.post_parser_visit_token(self, context)

    def get_gerber_code(
        self,
        indent: str = "",
        endline: str = "\n",  # noqa: ARG002
    ) -> str:
        """Get gerber code represented by this token."""
        return f"{indent}G70"

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/g70_set_unit_inch.py
def update_drawing_state(
    self,
    state: State,
    _backend: Backend,
) -> Tuple[State, Iterable[DrawCommand]]:
    """Set drawing polarity."""
    warn_deprecated_code("G70", "8.1")
    logging.warning(
        "Detected use of imperial units. Using metric units is recommended. "
        "Imperial units will be deprecated in future. "
        "(See 4.2.1 in Gerber Layer Format Specification)",
    )
    if state.draw_units is not None:
        logging.warning(
            "Overriding coordinate units is illegal. "
            "(See section 4.2.2 of The Gerber Layer Format Specification "
            "Revision 2023.03 - https://argmaster.github.io/pygerber/latest/gerber_specification/revision_2023_03.html)",
        )
    return (
        state.model_copy(
            update={
                "draw_units": Unit.Inches,
            },
        ),
        (),
    )

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/g70_set_unit_inch.py
def parser2_visit_token(self, context: Parser2Context) -> None:
    """Perform actions on the context implicated by this token."""
    context.get_hooks().set_unit_inch.pre_parser_visit_token(self, context)
    context.get_hooks().set_unit_inch.on_parser_visit_token(self, context)
    context.get_hooks().set_unit_inch.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/g70_set_unit_inch.py
def get_gerber_code(
    self,
    indent: str = "",
    endline: str = "\n",  # noqa: ARG002
) -> str:
    """Get gerber code represented by this token."""
    return f"{indent}G70"