-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGCodeObject.py
133 lines (106 loc) · 3.56 KB
/
GCodeObject.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
"""GCode Objects"""
import functools
def custom_coroutine_wrapper(func):
"""Initialzie automatically."""
@functools.wraps(func)
def init(*args, **kwargs):
"""Initialize wrapper"""
cr_obj = func(*args, **kwargs)
next(cr_obj)
return cr_obj
return init
# G-code element base class
class GCodeElementBase:
"G-code element base"
element = None
def __init__(self, element=None):
self.element = element
def __str__(self):
return self.element
def __repr__(self):
return '({}: {})'.format(self.__class__.__name__, repr(self.element))
# G-code parser elements
class GCodeParserElementBase(GCodeElementBase):
"""G-code parser element base"""
pass
class GCodeParserChar(GCodeParserElementBase):
"""G-code parser char element"""
pass
class GCodeParserNumberBase(GCodeParserElementBase):
"""G-code parser number element base"""
pass
class GCodeParserInt(GCodeParserNumberBase):
"""G-code parser int element"""
def __int__(self):
return self.element
class GCodeParserFloat(GCodeParserNumberBase):
"""G-code parser float element"""
def __float__(self):
return self.element
class GCodeParserSpace(GCodeParserElementBase):
"""G-code parser space element"""
pass
class GCodeParserMinus(GCodeParserElementBase):
"""G-code parser minus element"""
pass
class GCodeParserDot(GCodeParserElementBase):
"""G-code parser dot element"""
pass
class GCodeParserBracketBase(GCodeParserElementBase):
"""G-code parser bracket base"""
pass
class GCodeParserBracketLeft(GCodeParserBracketBase):
"""G-code parser left bracket element"""
pass
class GCodeParserBracketRight(GCodeParserBracketBase):
"""G-code parser right bracket element"""
pass
class GCodeParserSpecialCharacter(GCodeParserElementBase):
"""G-code parser special character element"""
pass
class GCodeParserDigitAfterDot(GCodeParserElementBase):
"""G-code parser element which shows how many zero(0)s are located after dot(.).
This class is special. It works distinctively."""
pass
# G-code result elements
class GCodeResultElementBase(GCodeElementBase):
"""G-code result element base"""
pass
class GCodePrefix(GCodeResultElementBase):
"""G-code prefix element"""
pass
class GCodeNumberElementBase(GCodeResultElementBase):
"""G-code number element base"""
pass
class GCodeInt(GCodeNumberElementBase):
"""G-code inteagr element"""
def __int__(self):
return self.element
class GCodeFloat(GCodeNumberElementBase):
"""G-code float element"""
def __float__(self):
return self.element
class GCode:
"G-code object"
element_prefix = None
element_num = None
def __init__(self, element_prefix, element_num):
self.element_prefix = element_prefix
self.element_num = element_num
def __str__(self):
return '{}{}'.format(str(self.element_prefix), str(self.element_num))
def __repr__(self):
return '({}: {}, {})'.format \
(self.__class__.__name__, repr(self.element_prefix), repr(self.element_num))
class GCodeExceptionBase(Exception):
"Basic exception class for G-code handling"
pass
class GCodeExceptionForError(GCodeExceptionBase):
"""Basic exception class for G-code error"""
class GCodeSyntaxError(GCodeExceptionForError):
"""G-code syntax error"""
pass
class GCodeExceptionForLogic(GCodeExceptionBase):
"""Basic exception class for programming logic"""
class GCodeDeliberateException(GCodeExceptionForLogic):
"""Deliberate exception"""