-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_xy.py
37 lines (26 loc) · 1.24 KB
/
start_xy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from base import Processor, ProcessorsList, CollectorsSet, check_no_config
from collectors.first_coordinate import CollectFirstCoordinate, FirstCoordinate
import logger
if TYPE_CHECKING:
from base import Context
from gcode import Line
logger = logger.named_logger(__name__)
class ProcessStartXY(Processor):
finished = False
def process(self, context: Context, line: Line):
if line.command == self.config.macro.print_start:
if context[FirstCoordinate].x is None:
raise RuntimeError("missing start x")
if context[FirstCoordinate].y is None:
raise RuntimeError("missing start y")
line.params.START_X = context[FirstCoordinate].x
line.params.START_Y = context[FirstCoordinate].y
logger.info(f'Start coordinates set to {context[FirstCoordinate].x}, {context[FirstCoordinate].y} [{line.no}]: {line}')
self.finished = True
def load(collectors: CollectorsSet, processors: ProcessorsList, config: Optional[dict]) -> None:
check_no_config(logger, config)
collectors.add(CollectFirstCoordinate)
processors.append(ProcessStartXY)
__all__ = ['load']